From 11dbd1a96fb0f95a6242f79078a73c8e7de71f8f Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Wed, 15 Mar 2023 08:24:56 +0200 Subject: [PATCH] Client - Fixed compilation error by adding missing `encodeMessage(string)` call - If the encoded message (CRLF included) is over 512 bytes then throw an exception Exceptions - Added new `ErrorType` enum member --- source/birchwood/client/client.d | 15 ++++++++++++--- source/birchwood/client/exceptions.d | 3 ++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index aca2845..db03d94 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -652,10 +652,19 @@ public class Client : Thread private void sendMessage(Message message) { /* Encode the message */ - ubyte[] encodedMessage = message.encode(); + ubyte[] encodedMessage = encodeMessage(message.encode()); - /* Enqueue the message to the send queue */ - sender.sq(encodedMessage); + /* If the message is 512 bytes or less then send */ + if(encodedMessage.length <= 512) + { + /* Enqueue the message to the send queue */ + sender.sq(encodedMessage); + } + /* If above then throw an exception */ + else + { + throw new BirchwoodException(BirchwoodException.ErrorType.COMMAND_TOO_LONG); + } } /** diff --git a/source/birchwood/client/exceptions.d b/source/birchwood/client/exceptions.d index 816e154..4aaac53 100644 --- a/source/birchwood/client/exceptions.d +++ b/source/birchwood/client/exceptions.d @@ -13,7 +13,8 @@ public class BirchwoodException : Exception EMPTY_PARAMS, INVALID_CHANNEL_NAME, INVALID_NICK_NAME, - ILLEGAL_CHARACTERS + ILLEGAL_CHARACTERS, + COMMAND_TOO_LONG } private ErrorType errType;