mirror of
https://github.com/deavmi/birchwood
synced 2024-09-20 06:23:15 +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:
parent
e2ba0bdb27
commit
15d2fa2deb
@ -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()
|
||||
|
||||
@ -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));
|
||||
|
@ -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)
|
||||
{
|
||||
@ -211,9 +216,14 @@ public class Message
|
||||
|
||||
/* Check if this is a command reply */
|
||||
if(isNumeric(command))
|
||||
{
|
||||
isResponse = true;
|
||||
|
||||
//FIXME: SOmething is tripping it u, elts' see
|
||||
try
|
||||
{
|
||||
/* 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 check for "6.3 Reserved numerics" or handling of SOME sorts atleast
|
||||
|
||||
@ -230,6 +240,12 @@ public class Message
|
||||
isError = false;
|
||||
}
|
||||
}
|
||||
catch(ConvException e)
|
||||
{
|
||||
logger.log("<<< Unsupported response code (Error below) >>>");
|
||||
logger.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: Implement encoder function */
|
||||
@ -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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user