From 91bffd61a4e6216b20ee6e44105439b54986ce7d Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Sun, 26 Apr 2020 13:50:13 +0200 Subject: [PATCH] Added function 'getConnectionScope' to get the connections scope --- source/connection/connection.d | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/source/connection/connection.d b/source/connection/connection.d index c1f1b20..da01da7 100644 --- a/source/connection/connection.d +++ b/source/connection/connection.d @@ -638,6 +638,26 @@ public final class BesterConnection : Thread } + private Scope getConnectionScope(JSONValue headerBlock) + { + /* TODO: Type checking and bounds checking */ + + /* Get the identification block */ + JSONValue identifyBlock = headerBlock["identify"]; + + /* Check what type of connection this is */ + if(cmp(headerBlock["identify"]["type"].str(), "client") == 0) + { + return Scope.CLIENT; + } + else if(cmp(headerBlock["identify"]["type"].str(), "server") == 0) + { + return Scope.SERVER; + } + + return Scope.UNKNOWN; + } + /* Process the received message */ private void processMessage(byte[] messageBuffer) { @@ -653,10 +673,12 @@ public final class BesterConnection : Thread debugPrint("<<< Received JSON >>>\n\n" ~ jsonMessage.toPrettyString()); /* TODO: Bounds checking, type checking */ - + /* Get the header */ JSONValue headerBlock = jsonMessage["header"]; + /* Get the scope of this connection */ + /* Get the scope of the message */ Scope scopeField; if(cmp(headerBlock["scope"].str, "client") == 0)