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)
|
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()
|
||||||
|
|
||||||
@ -309,7 +319,7 @@ public class Client
|
|||||||
/* TODO: Insert cast here to our custoim type */
|
/* TODO: Insert cast here to our custoim type */
|
||||||
IRCEvent ircEvent = cast(IRCEvent)e;
|
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
|
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());
|
logger.log("IRCEvent(message): "~ircEvent.getMessage().toString());
|
||||||
|
|
||||||
/* TODO: We should use a switch statement, imagine how nice */
|
/* TODO: We should use a switch statement, imagine how nice */
|
||||||
@ -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));
|
||||||
|
@ -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)
|
||||||
{
|
{
|
||||||
@ -212,22 +217,33 @@ public class Message
|
|||||||
/* Check if this is a command reply */
|
/* Check if this is a command reply */
|
||||||
if(isNumeric(command))
|
if(isNumeric(command))
|
||||||
{
|
{
|
||||||
/* Grab the code */
|
isResponse = true;
|
||||||
replyType = to!(ReplyType)(command);
|
|
||||||
// TODO: Add validity check on range of values here, if bad throw exception
|
//FIXME: SOmething is tripping it u, elts' see
|
||||||
// TODO: Add check for "6.3 Reserved numerics" or handling of SOME sorts atleast
|
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] */
|
/* Error codes are in range of [401, 502] */
|
||||||
if(replyType >= 401 && replyType <= 502)
|
if(replyType >= 401 && replyType <= 502)
|
||||||
{
|
{
|
||||||
// TODO: Call error handler
|
// TODO: Call error handler
|
||||||
isError = true;
|
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] */
|
catch(ConvException e)
|
||||||
else if(replyType >= 259 && replyType <= 395)
|
|
||||||
{
|
{
|
||||||
// TODO: Call command-reply handler
|
logger.log("<<< Unsupported response code (Error below) >>>");
|
||||||
isError = false;
|
logger.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user