diff --git a/doc/DESIGN.gmi b/doc/DESIGN.gmi new file mode 100644 index 0000000..1d4becc --- /dev/null +++ b/doc/DESIGN.gmi @@ -0,0 +1,51 @@ +# DESIGN +This document describes the design of this project. The main purpose is to describe the interface between the client and the server, but I might document other useful information here, too. + +## Client/Server Communication +All communication is done through JSON. + +### Client Requests +Clients can make requests to the server by sending a JSON object containing two fields: +* "request", which is a string of name of the request being made +* "parameters", which is an object whose structure depends on the request. It contains a named list of the request's parameters + +### Server Responses +Upon receiving and handling a request, the server will send a response object with the following fields: +* "success", a boolean that indicates whether the request succeeded +* "response", an object whose structure depends on the request. It contains data relevant to the request + +### Example Request and Response +An example request might look as follows: +``` +{ + "request": "create-world", + "parameters": { + "name": "test world", + "size": { + "height": 10, + "width": 15, + } + } +} +``` + +A success response might look like: +``` +{ + "success": true, + "response": { + "world-id": 69420 + } +} +``` + +Or, in the case of an error: +``` +{ + "success": false, + "response": { + "code": 69 + "message": "A world with this name already exists" + } +} +``` diff --git a/TODO.gmi b/doc/TODO.gmi similarity index 100% rename from TODO.gmi rename to doc/TODO.gmi diff --git a/build.sh b/scripts/build.sh similarity index 88% rename from build.sh rename to scripts/build.sh index 0c2d9ad..eb06c98 100755 --- a/build.sh +++ b/scripts/build.sh @@ -8,7 +8,7 @@ if [ "$1" = "run" ]; then run_exe=1 fi -if ! [ -f ".gitignore" ]; then +if ! [ -d ".git" ]; then echo "Run in the project root" exit 1 fi diff --git a/run.sh b/scripts/run.sh similarity index 67% rename from run.sh rename to scripts/run.sh index ab5a5ef..c4b9132 100755 --- a/run.sh +++ b/scripts/run.sh @@ -1,6 +1,13 @@ #!/bin/sh -./build.sh +set -e + +if ! [ -d ".git" ]; then + echo "Run in the project root" + exit 1 +fi + +./scripts/build.sh echo "### DAEMON ###" ./build/server/simworld-daemon &