mirror of
https://github.com/besterprotocol/besterd
synced 2023-12-13 21:00:32 +01:00
Moved block of code into correct position
This commit is contained in:
parent
839b9545d4
commit
02812b3171
1 changed files with 60 additions and 62 deletions
|
@ -173,89 +173,87 @@ private class BesterConnection : Thread
|
|||
if(payloadType.type == JSONType.string)
|
||||
{
|
||||
/* TODO: Move everything into this block */
|
||||
}
|
||||
/* The header must contain a scope block */
|
||||
JSONValue scopeBlock;
|
||||
|
||||
/* TODO: Add bounds check */
|
||||
scopeBlock = besterHeader["scope"];
|
||||
|
||||
|
||||
|
||||
/* The header must contain a scope block */
|
||||
JSONValue scopeBlock;
|
||||
|
||||
/* TODO: Add bounds check */
|
||||
scopeBlock = besterHeader["scope"];
|
||||
|
||||
/* Make sure the type of the JSON value is string */
|
||||
if(scopeBlock.type == JSONType.string)
|
||||
{
|
||||
/* Get the scope */
|
||||
string scopeString = scopeBlock.str;
|
||||
|
||||
/* If the message is for client<->server */
|
||||
if(cmp(scopeString, "client"))
|
||||
/* Make sure the type of the JSON value is string */
|
||||
if(scopeBlock.type == JSONType.string)
|
||||
{
|
||||
debugPrint("Scope: client<->server");
|
||||
/* Get the scope */
|
||||
string scopeString = scopeBlock.str;
|
||||
|
||||
/* The header must contain a authentication JSON object */
|
||||
JSONValue authenticationBlock;
|
||||
|
||||
/* TODO: Check for out of bounds here */
|
||||
authenticationBlock = besterHeader["authentication"];
|
||||
|
||||
/* TODO: Bounds check for both below */
|
||||
JSONValue username, password;
|
||||
username = authenticationBlock["username"];
|
||||
password = authenticationBlock["password"];
|
||||
|
||||
|
||||
|
||||
|
||||
if(username.type == JSONType.string && password.type == JSONType.string)
|
||||
/* If the message is for client<->server */
|
||||
if(cmp(scopeString, "client"))
|
||||
{
|
||||
/* TODO: Now do some stuff */
|
||||
debugPrint("Scope: client<->server");
|
||||
|
||||
/* TODO: Authenticate the user */
|
||||
string usernameString = username.str;
|
||||
string passwordString = password.str;
|
||||
bool isAuthenticated = server.authenticate(usernameString, passwordString);
|
||||
/* The header must contain a authentication JSON object */
|
||||
JSONValue authenticationBlock;
|
||||
|
||||
if(isAuthenticated)
|
||||
/* TODO: Check for out of bounds here */
|
||||
authenticationBlock = besterHeader["authentication"];
|
||||
|
||||
/* TODO: Bounds check for both below */
|
||||
JSONValue username, password;
|
||||
username = authenticationBlock["username"];
|
||||
password = authenticationBlock["password"];
|
||||
|
||||
|
||||
|
||||
|
||||
if(username.type == JSONType.string && password.type == JSONType.string)
|
||||
{
|
||||
debugPrint("Authenticated");
|
||||
/* TODO: Now do some stuff */
|
||||
|
||||
/* TODO: Dispatch to the correct message handler */
|
||||
dispatch(jsonMessage);
|
||||
/* TODO: Authenticate the user */
|
||||
string usernameString = username.str;
|
||||
string passwordString = password.str;
|
||||
bool isAuthenticated = server.authenticate(usernameString, passwordString);
|
||||
|
||||
if(isAuthenticated)
|
||||
{
|
||||
debugPrint("Authenticated");
|
||||
|
||||
/* TODO: Dispatch to the correct message handler */
|
||||
dispatch(jsonMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* TODO: Add error handling here */
|
||||
debugPrint("Authentication failure");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* TODO: Add error handling here */
|
||||
debugPrint("Authentication failure");
|
||||
debugPrint("Username or password is not a JSON string");
|
||||
}
|
||||
}
|
||||
/* If the message is for server<->server */
|
||||
else if(cmp(scopeString, "server"))
|
||||
{
|
||||
debugPrint("Scope: server<->server");
|
||||
}
|
||||
else
|
||||
{
|
||||
/* TODO: Add error handling here */
|
||||
debugPrint("Username or password is not a JSON string");
|
||||
/* TODO: Error handling */
|
||||
debugPrint("Unknown scope provided");
|
||||
}
|
||||
}
|
||||
/* If the message is for server<->server */
|
||||
else if(cmp(scopeString, "server"))
|
||||
{
|
||||
debugPrint("Scope: server<->server");
|
||||
}
|
||||
else
|
||||
{
|
||||
/* TODO: Error handling */
|
||||
debugPrint("Unknown scope provided");
|
||||
/* TODO: Handle error */
|
||||
debugPrint("Scope block JSON value not a string");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* TODO: Handle error */
|
||||
debugPrint("Scope block JSON value not a string");
|
||||
/* TODO: Add error handling */
|
||||
debugPrint("Type is not of type JSON string");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue