1
0
mirror of https://github.com/deavmi/birchwood synced 2024-09-20 15:22:53 +02:00
- Updated `command(Message)` to use `sendMessage(Message)`
- Updated the `PongSignal` event handler to use `sendMessage(Message)` when sending the pong back
- Make `quit()` use the new `sendMessage(Message)`
- Disabled old `sendMessage(string)`
This commit is contained in:
Tristan B. Velloza Kildaire 2023-03-15 08:43:45 +02:00
parent 2b25f4933a
commit 75155795fa

View File

@ -440,13 +440,8 @@ public class Client : Thread
*/ */
public void command(Message message) public void command(Message message)
{ {
/* Encode according to EBNF format */
// TODO: Validty check
// TODO: Make `Message.encode()` actually encode instead of empty string
string stringToSend = message.encode();
/* Send the message */ /* Send the message */
sendMessage(stringToSend); sendMessage(message);
} }
@ -553,8 +548,9 @@ public class Client : Thread
PongEvent pongEvent = cast(PongEvent)e; PongEvent pongEvent = cast(PongEvent)e;
assert(pongEvent); assert(pongEvent);
string messageToSend = "PONG "~pongEvent.getID(); // string messageToSend = "PONG "~pongEvent.getID();
client.sendMessage(messageToSend); Message pongMessage = new Message("", "PONG", pongEvent.getID());
client.sendMessage(pongMessage);
logger.log("Ponged back with "~pongEvent.getID()); logger.log("Ponged back with "~pongEvent.getID());
} }
} }
@ -632,24 +628,24 @@ public class Client : Thread
receiver.rq(message); receiver.rq(message);
} }
/** // /**
* Sends a message to the server by enqueuing it on // * Sends a message to the server by enqueuing it on
* the client-side send queue // * the client-side send queue
* // *
* Params: // * Params:
* messageOut = the message to send // * messageOut = the message to send
*/ // */
private void sendMessage(string messageOut) // private void sendMessage(string messageOut)
{ // {
// TODO: Do message splits here // // TODO: Do message splits here
/* Encode the mesage */ // /* Encode the mesage */
ubyte[] encodedMessage = encodeMessage(messageOut); // ubyte[] encodedMessage = encodeMessage(messageOut);
/* Enqueue the message to the send queue */ // /* Enqueue the message to the send queue */
sender.sq(encodedMessage); // sender.sq(encodedMessage);
} // }
/** /**
* Sends a message to the server by enqueuing it on * Sends a message to the server by enqueuing it on
@ -685,7 +681,7 @@ public class Client : Thread
{ {
/* Generate the quit command using the custom quit message */ /* Generate the quit command using the custom quit message */
Message quitCommand = new Message("", "QUIT", connInfo.quitMessage); Message quitCommand = new Message("", "QUIT", connInfo.quitMessage);
sendMessage(quitCommand.encode()); sendMessage(quitCommand);
/* TODO: I don't know how long we should wait here */ /* TODO: I don't know how long we should wait here */
Thread.sleep(dur!("seconds")(1)); Thread.sleep(dur!("seconds")(1));