diff --git a/source/connection/connection.d b/source/connection/connection.d index 59b20ff..feea5e1 100644 --- a/source/connection/connection.d +++ b/source/connection/connection.d @@ -285,9 +285,6 @@ public final class BesterConnection : Thread { /* TODO: Remove me */ debugPrint("fhjhfsdjhfdjhgsdkjh UUUUH:" ~e.toString()); - // dispatchStatus = false; - - /* TODO: Add call to `sendStatus` here as the handler failed */ /* Send error message to client */ sendErrorReport(payloadTag); @@ -309,6 +306,46 @@ public final class BesterConnection : Thread return true; } + public enum StatusType + { + SUCCESS, + FAILURE + } + + /** + * Send a status report for the message with id + * `id` of type `StatusType`. + */ + public void sendStatusReport(StatusType statusType, string id) + { + /* Construct the response */ + JSONValue statusMessage; + + /* Construct the haeder block */ + JSONValue headerBlock; + headerBlock["status"] = statusType == 0 ? "good" : "bad"; + + /* Attach the header block */ + statusMessage["header"] = headerBlock; + + /* Create the payload block */ + JSONValue payloadBlock; + payloadBlock["id"] = id; + + /* Attach the payload block */ + statusMessage["payload"] = payloadBlock; + + try + { + /* Send the message */ + sendMessage(clientConnection, statusMessage); + } + catch(NetworkException e) + { + debugPrint("Error sending status message"); + } + } + /* Send an error report */ public void sendErrorReport(string id) { diff --git a/source/handlers/response.d b/source/handlers/response.d index 98698ad..ea87dba 100644 --- a/source/handlers/response.d +++ b/source/handlers/response.d @@ -225,6 +225,13 @@ public final class HandlerResponse } debugPrint("SEND_CLIENTS: Completed run"); + + /** + * Send a status report here. + */ + + /* TODO: Implement me */ + sendErrorReport } else if (commandType == CommandType.SEND_SERVERS) { diff --git a/testing/testSuite.py b/testing/testSuite.py index c22822f..d1bf74e 100644 --- a/testing/testSuite.py +++ b/testing/testSuite.py @@ -20,6 +20,12 @@ def sendAs(username): d.send(len(bys).to_bytes(4, "little")) d.send(bys.encode()) + length=int.from_bytes(list(d.recv(4)), "little") + print(length) + receivedDataBytes = d.recv(length) + receivedData = list(receivedDataBytes) + print(receivedDataBytes.decode()) + # Now we can do it again (without authentication)