diff --git a/besterd-test-library b/besterd-test-library new file mode 100755 index 0000000..f81f266 Binary files /dev/null and b/besterd-test-library differ diff --git a/server.conf b/server.conf index 1394741..3706ba9 100644 --- a/server.conf +++ b/server.conf @@ -1,14 +1,15 @@ { "network" : { + "types" : ["unix", "tcp4", "tcp6"], "unix" : { "address" : "besterUNIXSock" }, "tcp4" : { - "port" : "2228", + "port" : "2220", "address" : "0.0.0.0" }, "tcp6" : { - "port" : "2229", + "port" : "2221", "address" : "::" } }, diff --git a/source/server/types.d b/source/server/types.d index 44066d0..6e68b3c 100644 --- a/source/server/types.d +++ b/source/server/types.d @@ -679,52 +679,63 @@ private class BesterConnection : Thread JSONValue headerBlock = handlerResponse["header"]; /* Get the status */ - ulong statusCode = to!(ulong)(headerBlock["status"].str); + ulong statusCode = to!(ulong)(headerBlock["status"].str()); debugPrint("Status code: " ~ to!(string)(statusCode)); - /* The command block */ - JSONValue commandBlock = headerBlock["command"]; - - /** - * Get the command that the message handler wants the - * server to run. - */ - string serverCommand = commandBlock["type"].str; - debugPrint("Handler->Server command: \"" ~ serverCommand ~ "\""); - - /* Check the command to be run */ - if(cmp(serverCommand, "sendClients") == 0) + /* If the status is 0, then it is all fine */ + if(statusCode == 0) { - /* Get the list of clients to send to */ - string[] clients; - JSONValue[] clientList = commandBlock["data"].array(); - for(ulong i = 0; i < clientList.length; i++) - { - clients ~= clientList[i].str(); - } - - /* TODO: Implement me */ - writeln("Users wanting to send to ", clients); - } - else if(cmp(serverCommand, "sendServers") == 0) - { - /* Get the list of clients to send to */ - string[] clients; - JSONValue[] clientList = commandBlock["data"].array(); - for(ulong i = 0; i < clientList.length; i++) - { - clients ~= clientList[i].str(); - } + debugPrint("Status is fine, the handler ran correctly"); - /* TODO: Implement me */ - writeln("Users wanting to send to ", clients); + /* The command block */ + JSONValue commandBlock = headerBlock["command"]; + + /** + * Get the command that the message handler wants the + * server to run. + */ + string serverCommand = commandBlock["type"].str; + debugPrint("Handler->Server command: \"" ~ serverCommand ~ "\""); + + /* Check the command to be run */ + if(cmp(serverCommand, "sendClients") == 0) + { + /* Get the list of clients to send to */ + string[] clients; + JSONValue[] clientList = commandBlock["data"].array(); + for(ulong i = 0; i < clientList.length; i++) + { + clients ~= clientList[i].str(); + } + + /* TODO: Implement me */ + writeln("Users wanting to send to ", clients); + } + else if(cmp(serverCommand, "sendServers") == 0) + { + /* Get the list of clients to send to */ + string[] clients; + JSONValue[] clientList = commandBlock["data"].array(); + for(ulong i = 0; i < clientList.length; i++) + { + clients ~= clientList[i].str(); + } + + /* TODO: Implement me */ + writeln("Users wanting to send to ", clients); + } + else + { + /* TODO: Error handling */ + debugPrint("The message handler is using an invalid command"); + } } else { - /* TODO: Error handling */ - debugPrint("The message handler is using an invalid command"); + /* If the message handler returned a response in error */ + debugPrint("Message handler returned an error code: " ~ to!(string)(statusCode)); + return false; } - } catch(JSONException exception) { @@ -732,6 +743,7 @@ private class BesterConnection : Thread return false; } + /* If the handling went through fine */ return true; } @@ -832,7 +844,15 @@ private class BesterConnection : Thread debugPrint("<<< Message Handler [" ~ chosenHandler.getPluginName() ~ "] response >>>\n\n" ~ response.toPrettyString()); /* TODO: Handle response */ - handleResponse(response); + bool handleStatus = handleResponse(response); + + /* Check if the response was handled unsuccessfully */ + if(!handleStatus) + { + debugPrint("Response from message handler was erroneous, sending error to user..."); + + /* TODO: Implement this */ + } } else { diff --git a/testing/testSuite.py b/testing/testSuite.py index b502619..f4247f1 100644 --- a/testing/testSuite.py +++ b/testing/testSuite.py @@ -4,7 +4,7 @@ import json def basicTest(): d=socket.socket(socket.AF_INET, socket.SOCK_STREAM) - d.connect(("127.0.0.1",2229)) + d.connect(("127.0.0.1",2221)) bys=json.dumps({"header":{"authentication":{"username":"tbk", "password":"passwd"}, "scope":"client"},"payload":{"data":"ABBA","type":"type1"}}) print(bys) d.send(bytes([len(bys),0,0,0])) @@ -13,7 +13,7 @@ def basicTest(): def commandBuiltInClose(): d=socket.socket(socket.AF_INET, socket.SOCK_STREAM) - d.connect(("127.0.0.1",2229)) + d.connect(("127.0.0.1",2221)) bys=json.dumps({"header": {"scope" : "client"},"payload": { "data": { "command" : {"type" : "close", "args" : None} @@ -25,7 +25,7 @@ def commandBuiltInClose(): def commandAuthTest(): d=socket.socket(socket.AF_INET, socket.SOCK_STREAM) - d.connect(("127.0.0.1",2229)) + d.connect(("127.0.0.1",2221)) bys=json.dumps({"header": {"scope" : "client"},"payload": { "data": { "command" : {"type" : "login", "args" : {"username" :"1", "password":"2"}}