From 8ac73ca50e651f8fae6ecb059bd1ee658b2e11d6 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Tue, 10 Aug 2021 10:00:26 -0500 Subject: [PATCH] (irc) Faster readying of protocol --- protocols/irc/IrcProtocol.cpp | 46 ++++++++++++++++++++++------------- protocols/irc/IrcProtocol.h | 2 ++ 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/protocols/irc/IrcProtocol.cpp b/protocols/irc/IrcProtocol.cpp index fa5bb3e..f43ce71 100644 --- a/protocols/irc/IrcProtocol.cpp +++ b/protocols/irc/IrcProtocol.cpp @@ -256,24 +256,9 @@ IrcProtocol::_ProcessNumeric(int32 numeric, BString sender, BStringList params) ident << "@" << host; // Contains the user's contact info― protocol ready! - if (fReady == false) { + if (fReady == false && nick == fNick) { fUser = user.String(); - fIdent = ident; - - fReady = true; - BMessage ready(IM_MESSAGE); - ready.AddInt32("im_what", IM_PROTOCOL_READY); - ready.PrintToStream(); - _SendMsg(&ready); - - BMessage self(IM_MESSAGE); - self.AddInt32("im_what", IM_OWN_CONTACT_INFO); - self.AddString("user_id", fIdent); - self.AddString("user_name", fNick); - self.PrintToStream(); - _SendMsg(&self); - - _SendIrc("MOTD\n"); + _MakeReady(nick, ident); } // Used to populate a room's userlist @@ -344,6 +329,10 @@ void IrcProtocol::_ProcessCommand(BString command, BString sender, BStringList params) { + // If protocol uninitialized and the user's ident is mentioned― use it! + if (fReady == false && _SenderNick(sender) == fNick) + _MakeReady(_SenderNick(sender), _SenderIdent(sender)); + if (command == "PING") { BString cmd = "PONG "; @@ -441,6 +430,29 @@ IrcProtocol::_ProcessCommand(BString command, BString sender, } +void +IrcProtocol::_MakeReady(BString nick, BString ident) +{ + fNick = nick; + fIdent = ident; + + fReady = true; + BMessage ready(IM_MESSAGE); + ready.AddInt32("im_what", IM_PROTOCOL_READY); + ready.PrintToStream(); + _SendMsg(&ready); + + BMessage self(IM_MESSAGE); + self.AddInt32("im_what", IM_OWN_CONTACT_INFO); + self.AddString("user_id", fIdent); + self.AddString("user_name", fNick); + self.PrintToStream(); + _SendMsg(&self); + + _SendIrc("MOTD\n"); +} + + BString IrcProtocol::_LineSender(BStringList words) { diff --git a/protocols/irc/IrcProtocol.h b/protocols/irc/IrcProtocol.h index 4b7f64f..2edbae9 100644 --- a/protocols/irc/IrcProtocol.h +++ b/protocols/irc/IrcProtocol.h @@ -61,6 +61,8 @@ private: void _ProcessCommand(BString command, BString sender, BStringList params); + void _MakeReady(BString nick, BString ident); + BString _LineSender(BStringList words); BString _LineCode(BStringList words); BStringList _LineParameters(BStringList words, BString line);