(irc) Proper newline use, sending unicode messages

This commit is contained in:
Jaidyn Ann 2021-08-12 13:55:32 -05:00
parent c3994e4a73
commit d16f397fe6

View File

@ -63,7 +63,7 @@ status_t
IrcProtocol::Shutdown() IrcProtocol::Shutdown()
{ {
BString cmd = "QUIT :"; BString cmd = "QUIT :";
cmd << fPartText << "\n"; cmd << fPartText;
_SendIrc(cmd); _SendIrc(cmd);
kill_thread(fRecvThread); kill_thread(fRecvThread);
@ -90,16 +90,16 @@ IrcProtocol::UpdateSettings(BMessage* settings)
if (password != NULL) { if (password != NULL) {
BString passMsg = "PASS "; BString passMsg = "PASS ";
passMsg << password << "\n"; passMsg << password;
_SendIrc(passMsg); _SendIrc(passMsg);
} }
BString userMsg = "USER "; BString userMsg = "USER ";
userMsg << fUser << " * 0 :" << real_name << "\n"; userMsg << fUser << " * 0 :" << real_name;
_SendIrc(userMsg); _SendIrc(userMsg);
BString nickMsg = "NICK "; BString nickMsg = "NICK ";
nickMsg << fNick << "\n"; nickMsg << fNick;
_SendIrc(nickMsg); _SendIrc(nickMsg);
fRecvThread = spawn_thread(connect_thread, "what_a_tangled_web_we_weave", fRecvThread = spawn_thread(connect_thread, "what_a_tangled_web_we_weave",
@ -128,7 +128,7 @@ IrcProtocol::Process(BMessage* msg)
for (int i = 0; i < lines.CountStrings(); i++) { for (int i = 0; i < lines.CountStrings(); i++) {
BString cmd = "PRIVMSG "; BString cmd = "PRIVMSG ";
cmd << chat_id << " :" << lines.StringAt(i) << "\n"; cmd << chat_id << " :" << lines.StringAt(i);
_SendIrc(cmd); _SendIrc(cmd);
BMessage sent(IM_MESSAGE); BMessage sent(IM_MESSAGE);
@ -147,7 +147,7 @@ IrcProtocol::Process(BMessage* msg)
BString chat_id; BString chat_id;
if (msg->FindString("chat_id", &chat_id) == B_OK) { if (msg->FindString("chat_id", &chat_id) == B_OK) {
BString cmd = "JOIN "; BString cmd = "JOIN ";
cmd << chat_id << "\n"; cmd << chat_id;
_SendIrc(cmd); _SendIrc(cmd);
} }
break; break;
@ -158,7 +158,7 @@ IrcProtocol::Process(BMessage* msg)
if (msg->FindString("chat_id", &chat_id) == B_OK) { if (msg->FindString("chat_id", &chat_id) == B_OK) {
if (_IsChannelName(chat_id) == true) { if (_IsChannelName(chat_id) == true) {
BString cmd = "PART "; BString cmd = "PART ";
cmd << chat_id << " * :" << fPartText << "\n"; cmd << chat_id << " * :" << fPartText;
_SendIrc(cmd); _SendIrc(cmd);
} }
else { else {
@ -189,7 +189,7 @@ IrcProtocol::Process(BMessage* msg)
BString user_id = msg->FindString("user_id"); BString user_id = msg->FindString("user_id");
if (chat_id.IsEmpty() == false || user_id.IsEmpty() == false) { if (chat_id.IsEmpty() == false || user_id.IsEmpty() == false) {
BString cmd("INVITE "); BString cmd("INVITE ");
cmd << _IdentNick(user_id) << " " << chat_id << "\n"; cmd << _IdentNick(user_id) << " " << chat_id;
_SendIrc(cmd); _SendIrc(cmd);
} }
break; break;
@ -199,7 +199,7 @@ IrcProtocol::Process(BMessage* msg)
BString user_name; BString user_name;
if (msg->FindString("user_name", &user_name) == B_OK) { if (msg->FindString("user_name", &user_name) == B_OK) {
BString cmd("NICK "); BString cmd("NICK ");
cmd << user_name << "\n"; cmd << user_name;
_SendIrc(cmd); _SendIrc(cmd);
} }
break; break;
@ -591,11 +591,12 @@ IrcProtocol::_SendMsg(BMessage* msg)
void void
IrcProtocol::_SendIrc(BString cmd) IrcProtocol::_SendIrc(BString cmd)
{ {
cmd << "\r\n";
if (fSocket != NULL && fSocket->IsConnected() == true) { if (fSocket != NULL && fSocket->IsConnected() == true) {
while (fWriteLocked == true) while (fWriteLocked == true)
snooze(1000); snooze(1000);
fWriteLocked = true; fWriteLocked = true;
fSocket->Write(cmd.String(), cmd.CountChars()); fSocket->Write(cmd.String(), cmd.CountBytes(0, cmd.CountChars()));
fWriteLocked = false; fWriteLocked = false;
} }
else { else {