1
0
mirror of https://github.com/deavmi/birchwood synced 2024-09-20 08:43:05 +02:00

- Fixed a bug whereby an unsupported response code would cause a crash in the event handler

- Added a default response type (in case an unspported one comes in)
This commit is contained in:
Tristan B. Velloza Kildaire 2022-11-03 17:05:27 +02:00
parent e2ba0bdb27
commit 15d2fa2deb
2 changed files with 50 additions and 24 deletions

View File

@ -221,18 +221,22 @@ public class Client
public void onChannelMessage(Message fullMessage, string channel, string msgBody) public void onChannelMessage(Message fullMessage, string channel, string msgBody)
{ {
/* Default implementation */ /* Default implementation */
logger.log("Channel("~channel~"): "~msgBody);
} }
public void onDirectMessage(Message fullMessage, string nickname, string msgBody) public void onDirectMessage(Message fullMessage, string nickname, string msgBody)
{ {
/* Default implementation */ /* Default implementation */
logger.log("DirectMessage("~nickname~"): "~msgBody);
} }
public void onGenericCommand(Message message) public void onGenericCommand(Message message)
{ {
/* Default implementation */ /* Default implementation */
logger.log("Generic("~message.getCommand()~"): "~message.getParams());
} }
public void onCommandReply(Message commandReply) public void onCommandReply(Message commandReply)
{ {
/* Default implementation */ /* Default implementation */
logger.log("Response("~to!(string)(commandReply.replyType)~"): "~commandReply.toString());
} }
@ -247,11 +251,17 @@ public class Client
*/ */
public void joinChannel(string channel) public void joinChannel(string channel)
{ {
/* TODO: Expect a reply here with some queuing mechanism */
/* Join the channel */ /* Join the channel */
sendMessage("JOIN "~channel); sendMessage("JOIN "~channel);
} }
public void directMessage(string[] recipients)
{
//TODO: Implement
}
public void channelMessage(string channel)
{
//TODO: Implement
}
// private void makeRequest() // private void makeRequest()
@ -317,6 +327,7 @@ public class Client
string command = ircMessage.getCommand(); string command = ircMessage.getCommand();
string params = ircMessage.getParams(); string params = ircMessage.getParams();
if(cmp(command, "PRIVMSG") == 0) if(cmp(command, "PRIVMSG") == 0)
{ {
/* Split up into (channel/nick) and (message)*/ /* Split up into (channel/nick) and (message)*/
@ -330,7 +341,7 @@ public class Client
string message; string message;
} }
// If the command is numeric then it is a reply of some sorts // If the command is numeric then it is a reply of some sorts
else if(isNumeric(command)) else if(ircMessage.isResponse)
{ {
/* Call the command reply handler */ /* Call the command reply handler */
onCommandReply(ircMessage); onCommandReply(ircMessage);
@ -342,7 +353,6 @@ public class Client
} }
//TODO: add more commands //TODO: add more commands
} }
} }
engine.addSignalHandler(new GenericSignal(this)); engine.addSignalHandler(new GenericSignal(this));

View File

@ -3,7 +3,7 @@ module birchwood.messages;
import dlog; import dlog;
import std.string; import std.string;
import std.conv : to; import std.conv : to, ConvException;
// TODO: Before release we should remove this import // TODO: Before release we should remove this import
import std.stdio : writeln; import std.stdio : writeln;
@ -185,7 +185,10 @@ public static string decodeMessage(ubyte[] messageIn)
RPL_KILLDONE = 361, RPL_KILLDONE = 361,
RPL_CLOSEEND = 363, RPL_CLOSEEND = 363,
RPL_MYPORTIS = 384, RPL_MYPORTIS = 384,
ERR_BADCHANMASK = 476 ERR_BADCHANMASK = 476,
BIRCHWOOD_UNKNOWN_RESP_CODE = 0
} }
/** /**
@ -199,9 +202,11 @@ public class Message
/* Whether this numeric reply is an error type */ /* Whether this numeric reply is an error type */
public bool isError = false; public bool isError = false;
/* Whether this is a response message */
public bool isResponse = false;
/* The numeric reply */ /* The numeric reply */
public ReplyType replyType; public ReplyType replyType = ReplyType.BIRCHWOOD_UNKNOWN_RESP_CODE;
this(string from, string command, string params) this(string from, string command, string params)
{ {
@ -211,9 +216,14 @@ public class Message
/* Check if this is a command reply */ /* Check if this is a command reply */
if(isNumeric(command)) if(isNumeric(command))
{
isResponse = true;
//FIXME: SOmething is tripping it u, elts' see
try
{ {
/* Grab the code */ /* Grab the code */
replyType = to!(ReplyType)(command); replyType = to!(ReplyType)(to!(ulong)(command));
// TODO: Add validity check on range of values here, if bad throw exception // TODO: Add validity check on range of values here, if bad throw exception
// TODO: Add check for "6.3 Reserved numerics" or handling of SOME sorts atleast // TODO: Add check for "6.3 Reserved numerics" or handling of SOME sorts atleast
@ -230,6 +240,12 @@ public class Message
isError = false; isError = false;
} }
} }
catch(ConvException e)
{
logger.log("<<< Unsupported response code (Error below) >>>");
logger.log(e);
}
}
} }
/* TODO: Implement encoder function */ /* TODO: Implement encoder function */
@ -265,7 +281,7 @@ public class Message
{ {
from = message[1..firstSpace]; from = message[1..firstSpace];
logger.log("from: "~from); // logger.log("from: "~from);
/* TODO: Find next space (what follows `from` is `' ' { ' ' }`) */ /* TODO: Find next space (what follows `from` is `' ' { ' ' }`) */
ulong i = firstSpace; ulong i = firstSpace;
@ -285,7 +301,7 @@ public class Message
/* Extract the command */ /* Extract the command */
command = rem[0..idx]; command = rem[0..idx];
logger.log("command: "~command); // logger.log("command: "~command);
/* Params are everything till the end */ /* Params are everything till the end */
i = idx; i = idx;
@ -297,7 +313,7 @@ public class Message
} }
} }
params = rem[i..rem.length]; params = rem[i..rem.length];
logger.log("params: "~params); // logger.log("params: "~params);
} }
else else
{ {