diff --git a/source/birchwood/client.d b/source/birchwood/client.d index 0b55793..e5cb7e1 100644 --- a/source/birchwood/client.d +++ b/source/birchwood/client.d @@ -221,18 +221,22 @@ public class Client public void onChannelMessage(Message fullMessage, string channel, string msgBody) { /* Default implementation */ + logger.log("Channel("~channel~"): "~msgBody); } public void onDirectMessage(Message fullMessage, string nickname, string msgBody) { /* Default implementation */ + logger.log("DirectMessage("~nickname~"): "~msgBody); } public void onGenericCommand(Message message) { /* Default implementation */ + logger.log("Generic("~message.getCommand()~"): "~message.getParams()); } public void onCommandReply(Message commandReply) { /* Default implementation */ + logger.log("Response("~to!(string)(commandReply.replyType)~"): "~commandReply.toString()); } @@ -247,11 +251,17 @@ public class Client */ public void joinChannel(string channel) { - /* TODO: Expect a reply here with some queuing mechanism */ - /* Join the channel */ sendMessage("JOIN "~channel); } + public void directMessage(string[] recipients) + { + //TODO: Implement + } + public void channelMessage(string channel) + { + //TODO: Implement + } // private void makeRequest() @@ -309,7 +319,7 @@ public class Client /* TODO: Insert cast here to our custoim type */ IRCEvent ircEvent = cast(IRCEvent)e; assert(ircEvent); //Should never fail, unless some BOZO regged multiple handles for 1 - wait idk does eventy do that even mmm - + logger.log("IRCEvent(message): "~ircEvent.getMessage().toString()); /* TODO: We should use a switch statement, imagine how nice */ @@ -317,6 +327,7 @@ public class Client string command = ircMessage.getCommand(); string params = ircMessage.getParams(); + if(cmp(command, "PRIVMSG") == 0) { /* Split up into (channel/nick) and (message)*/ @@ -330,7 +341,7 @@ public class Client string message; } // 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 */ onCommandReply(ircMessage); @@ -342,7 +353,6 @@ public class Client } //TODO: add more commands - } } engine.addSignalHandler(new GenericSignal(this)); diff --git a/source/birchwood/messages.d b/source/birchwood/messages.d index 4fc4575..6681e0d 100644 --- a/source/birchwood/messages.d +++ b/source/birchwood/messages.d @@ -3,7 +3,7 @@ module birchwood.messages; import dlog; import std.string; -import std.conv : to; +import std.conv : to, ConvException; // TODO: Before release we should remove this import import std.stdio : writeln; @@ -185,7 +185,10 @@ public static string decodeMessage(ubyte[] messageIn) RPL_KILLDONE = 361, RPL_CLOSEEND = 363, 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 */ public bool isError = false; + /* Whether this is a response message */ + public bool isResponse = false; /* The numeric reply */ - public ReplyType replyType; + public ReplyType replyType = ReplyType.BIRCHWOOD_UNKNOWN_RESP_CODE; this(string from, string command, string params) { @@ -212,22 +217,33 @@ public class Message /* Check if this is a command reply */ if(isNumeric(command)) { - /* Grab the code */ - replyType = to!(ReplyType)(command); - // 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 + isResponse = true; + + //FIXME: SOmething is tripping it u, elts' see + try + { + /* Grab the code */ + replyType = to!(ReplyType)(to!(ulong)(command)); + // 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 - /* Error codes are in range of [401, 502] */ - if(replyType >= 401 && replyType <= 502) - { - // TODO: Call error handler - isError = true; + /* Error codes are in range of [401, 502] */ + if(replyType >= 401 && replyType <= 502) + { + // TODO: Call error handler + isError = true; + } + /* Command replies are in range of [259, 395] */ + else if(replyType >= 259 && replyType <= 395) + { + // TODO: Call command-reply handler + isError = false; + } } - /* Command replies are in range of [259, 395] */ - else if(replyType >= 259 && replyType <= 395) + catch(ConvException e) { - // TODO: Call command-reply handler - isError = false; + logger.log("<<< Unsupported response code (Error below) >>>"); + logger.log(e); } } } @@ -265,7 +281,7 @@ public class Message { from = message[1..firstSpace]; - logger.log("from: "~from); + // logger.log("from: "~from); /* TODO: Find next space (what follows `from` is `' ' { ' ' }`) */ ulong i = firstSpace; @@ -285,7 +301,7 @@ public class Message /* Extract the command */ command = rem[0..idx]; - logger.log("command: "~command); + // logger.log("command: "~command); /* Params are everything till the end */ i = idx; @@ -297,7 +313,7 @@ public class Message } } params = rem[i..rem.length]; - logger.log("params: "~params); + // logger.log("params: "~params); } else {