(irc) Command support

Now raw IRC commands can be sent with a "//" command, like this:
	// HELP
… to print the server's HELP message to system buffer.
So on and so forth.
This commit is contained in:
Jaidyn Ann 2021-08-16 01:25:30 -05:00
parent 03556d674e
commit 60ad595d5d
2 changed files with 62 additions and 6 deletions

View File

@ -29,6 +29,9 @@
#define B_TRANSLATION_CONTEXT "IrcProtocol" #define B_TRANSLATION_CONTEXT "IrcProtocol"
const int32 IRC_CMD = 'ICmd';
status_t status_t
connect_thread(void* data) connect_thread(void* data)
{ {
@ -104,6 +107,21 @@ IrcProtocol::Process(BMessage* msg)
{ {
int32 im_what = msg->FindInt32("im_what"); int32 im_what = msg->FindInt32("im_what");
switch (im_what) { switch (im_what) {
case IRC_CMD:
{
BStringList words;
BString line = msg->GetString("misc_str", "");
line.Split(" ", true, words);
BString command = words.First();
if (command.ICompare("WHOIS") == 0)
fWhoIsRequested = true;
else if (command.ICompare("WHO") == 0)
fWhoRequested = true;
_SendIrc(line);
break;
}
case IM_SET_OWN_STATUS: case IM_SET_OWN_STATUS:
{ {
int32 status = msg->FindInt32("status"); int32 status = msg->FindInt32("status");
@ -315,6 +333,26 @@ IrcProtocol::SettingsTemplate(const char* name)
} }
BObjectList<BMessage>
IrcProtocol::Commands()
{
BMessage handle(IM_MESSAGE);
handle.AddInt32("im_what", IRC_CMD);
handle.AddString("cmd_name", "/");
BMessage* cmd = new BMessage();
cmd->AddString("_name", "/");
cmd->AddString("_desc", B_TRANSLATE("Send a raw IRC command to the server. E.g., '// HELP' or '// WHOIS'."));
cmd->AddBool("_proto", true);
cmd->AddMessage("_msg", &handle);
cmd->AddString("class", "ChatCommand");
BObjectList<BMessage> cmds;
cmds.AddItem(cmd);
return cmds;
}
BBitmap* BBitmap*
IrcProtocol::Icon() const IrcProtocol::Icon() const
{ {
@ -385,6 +423,7 @@ IrcProtocol::_ProcessNumeric(int32 numeric, BString sender, BStringList params,
return; return;
} }
// Act on the numeric as appropriate
switch (numeric) { switch (numeric) {
case RPL_WELCOME: case RPL_WELCOME:
{ {
@ -435,9 +474,6 @@ IrcProtocol::_ProcessNumeric(int32 numeric, BString sender, BStringList params,
} }
break; break;
} }
case RPL_ENDOFWHOIS:
fWhoIsRequested = false;
break;
case RPL_WHOREPLY: case RPL_WHOREPLY:
{ {
BString channel = params.StringAt(1); BString channel = params.StringAt(1);
@ -461,9 +497,6 @@ IrcProtocol::_ProcessNumeric(int32 numeric, BString sender, BStringList params,
} }
break; break;
} }
case RPL_ENDOFWHO:
fWhoRequested = false;
break;
case RPL_TOPIC: case RPL_TOPIC:
{ {
BString chat_id = params.StringAt(1); BString chat_id = params.StringAt(1);
@ -476,6 +509,16 @@ IrcProtocol::_ProcessNumeric(int32 numeric, BString sender, BStringList params,
_SendMsg(&topic); _SendMsg(&topic);
break; break;
} }
}
// Now, to determine if the line should be sent to system buffer
switch (numeric) {
case RPL_ENDOFWHO:
fWhoRequested = false;
break;
case RPL_ENDOFWHOIS:
fWhoIsRequested = false;
break;
case RPL_MOTDSTART: case RPL_MOTDSTART:
case RPL_MOTD: case RPL_MOTD:
case RPL_ENDOFMOTD: case RPL_ENDOFMOTD:
@ -491,6 +534,17 @@ IrcProtocol::_ProcessNumeric(int32 numeric, BString sender, BStringList params,
_SendMsg(&send); _SendMsg(&send);
break; break;
} }
case RPL_WHOREPLY:
if (fWhoRequested == false)
break;
case RPL_WHOISUSER:
if (fWhoIsRequested == false)
break;
default:
BMessage send(IM_MESSAGE);
send.AddInt32("im_what", IM_MESSAGE_RECEIVED);
send.AddString("body", line);
_SendMsg(&send);
} }
} }

View File

@ -34,6 +34,8 @@ public:
virtual status_t Process(BMessage* msg); virtual status_t Process(BMessage* msg);
virtual BMessage SettingsTemplate(const char* name); virtual BMessage SettingsTemplate(const char* name);
virtual BObjectList<BMessage>
Commands();
virtual const char* Signature() const { return "irc"; } virtual const char* Signature() const { return "irc"; }
virtual const char* FriendlySignature() const { return "IRC"; } virtual const char* FriendlySignature() const { return "IRC"; }