From 66cd409234297b465e1ec31d8b82d7bc6f10d69b Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Wed, 15 Mar 2023 21:29:07 +0200 Subject: [PATCH 1/3] Package (protocol) - Make `ReplyType` available --- source/birchwood/protocol/package.d | 1 + 1 file changed, 1 insertion(+) diff --git a/source/birchwood/protocol/package.d b/source/birchwood/protocol/package.d index 0853c26..733ce7a 100644 --- a/source/birchwood/protocol/package.d +++ b/source/birchwood/protocol/package.d @@ -1,6 +1,7 @@ module birchwood.protocol; public import birchwood.protocol.messages : Message; +public import birchwood.protocol.constants : ReplyType; // TODO: Look how to neaten up (if any) public import birchwood.protocol.formatting; \ No newline at end of file From 66c3a02d6e0ef810ec2f20ad147d8b5588786f01 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Thu, 16 Mar 2023 08:17:56 +0200 Subject: [PATCH 2/3] Client - Added missing documentation for `onDirectMessage`, `onChannelMessage`, `onGenericCommand` and `onCommandReply` --- source/birchwood/client/client.d | 36 +++++++++++++++----------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index 5e9fb27..30d2de5 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -71,23 +71,19 @@ public class Client : Thread //TODO: Do something here, tare downs } + // TODO: Investigate public ConnectionInfo getConnInfo() { return connInfo; } - - /** - * User overridable handler functions below - */ - - // TODO: comment /** - * + * Called on reception of a channel message + * * Params: - * fullMessage = - * channel = - * msgBody = + * fullMessage = the channel message in its entirety + * channel = the channel + * msgBody = the body of the message */ public void onChannelMessage(Message fullMessage, string channel, string msgBody) { @@ -95,11 +91,13 @@ public class Client : Thread logger.log("Channel("~channel~"): "~msgBody); } - // TODO: comment /** - * + * Called on reception of a direct message + * * Params: - * message = + * fullMessage = the direct message in its entirety + * nickname = the sender + * msgBody = the body of the message */ public void onDirectMessage(Message fullMessage, string nickname, string msgBody) { @@ -107,11 +105,11 @@ public class Client : Thread logger.log("DirectMessage("~nickname~"): "~msgBody); } - // TODO: comment /** - * + * Called on generic commands + * * Params: - * commandReply = + * commandReply = the generic message */ public void onGenericCommand(Message message) { @@ -119,11 +117,11 @@ public class Client : Thread logger.log("Generic("~message.getCommand()~", "~message.getFrom()~"): "~message.getParams()); } - // TODO: comment /** - * + * Called on command replies + * * Params: - * commandReply = + * commandReply = the command's reply */ public void onCommandReply(Message commandReply) { From 93fecfaad57a98fc2f6adfd77797d8b059f3d798 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Thu, 16 Mar 2023 08:26:03 +0200 Subject: [PATCH 3/3] Client - Removed now-completed TODO - Implemented `joinChannel(string[])` Unit tests - Use BNET test server - Added test calls to `joinChannel(string[])` --- source/birchwood/client/client.d | 83 +++++++++++++++++++++++++++++--- 1 file changed, 76 insertions(+), 7 deletions(-) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index 30d2de5..31b78fb 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -133,8 +133,6 @@ public class Client : Thread * User operations (request-response type) */ - // TODO: Add joinChannels(strung[]) - /** * Joins the requested channel * @@ -166,6 +164,75 @@ public class Client : Thread } } + /** + * Joins the requested channels + * + * Params: + * channels = the channels to join + * Throws: + * BirchwoodException on invalid channel name + */ + public void joinChannel(string[] channels) + { + /* If single channel */ + if(channels.length == 1) + { + /* Join the channel */ + joinChannel(channels[0]); + } + /* If multiple channels */ + else if(channels.length > 1) + { + string channelLine = channels[0]; + + /* Ensure valid characters in first channel */ + if(isValidText(channelLine)) + { + //TODO: Add check for # + + /* Append on a trailing `,` */ + channelLine ~= ","; + + for(ulong i = 1; i < channels.length; i++) + { + string currentChannel = channels[i]; + + /* Ensure the character channel is valid */ + if(isValidText(currentChannel)) + { + //TODO: Add check for # + + if(i == channels.length-1) + { + channelLine~=currentChannel; + } + else + { + channelLine~=currentChannel~","; + } + } + else + { + throw new BirchwoodException(BirchwoodException.ErrorType.ILLEGAL_CHARACTERS); + } + } + + /* Join multiple channels */ + Message joinMessage = new Message("", "JOIN", channelLine); + sendMessage(joinMessage); + } + else + { + throw new BirchwoodException(BirchwoodException.ErrorType.ILLEGAL_CHARACTERS); + } + } + /* If no channels provided at all (error) */ + else + { + throw new BirchwoodException(BirchwoodException.ErrorType.EMPTY_PARAMS); + } + } + /** * Parts from a list of channel(s) in one go * @@ -902,11 +969,11 @@ public class Client : Thread unittest { /* FIXME: Get domaina name resolution support */ - ConnectionInfo connInfo = ConnectionInfo.newConnection("irc.freenode.net", 6667, "testBirchwood"); + // ConnectionInfo connInfo = ConnectionInfo.newConnection("irc.freenode.net", 6667, "testBirchwood"); //freenode: 149.28.246.185 //snootnet: 178.62.125.123 //bonobonet: fd08:8441:e254::5 - // ConnectionInfo connInfo = ConnectionInfo.newConnection("worcester.community.networks.deavmi.assigned.network", 6667, "testBirchwood"); + ConnectionInfo connInfo = ConnectionInfo.newConnection("worcester.community.networks.deavmi.assigned.network", 6667, "testBirchwood"); // // Set the fakelag to 1 second // connInfo.setFakeLag(1); @@ -928,9 +995,11 @@ public class Client : Thread client.joinChannel("#birchwood"); // TODO: Add a joinChannels(string[]) client.joinChannel("#birchwood2"); - client.joinChannel("#birchwoodLeave1"); - client.joinChannel("#birchwoodLeave2"); - client.joinChannel("#birchwoodLeave3"); + + client.joinChannel(["#birchwoodLeave1", "#birchwoodLeave2", "#birchwoodLeave3"]); + // client.joinChannel("#birchwoodLeave1"); + // client.joinChannel("#birchwoodLeave2"); + // client.joinChannel("#birchwoodLeave3"); Thread.sleep(dur!("seconds")(2)); client.command(new Message("", "NAMES", "")); // TODO: add names commdn