(irc) Faster readying of protocol

This commit is contained in:
Jaidyn Ann 2021-08-10 10:00:26 -05:00
parent 723d6c1950
commit 8ac73ca50e
2 changed files with 31 additions and 17 deletions

View File

@ -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)
{

View File

@ -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);