Added function 'getConnectionScope' to get the connections scope

This commit is contained in:
Tristan B. Kildaire 2020-04-26 13:50:13 +02:00
parent d9f0e1fc1b
commit 91bffd61a4
1 changed files with 23 additions and 1 deletions

View File

@ -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)