# Client-Server Protocol ## 1. Start a connection To start a connection you have to check the versions, generate the sessonID and verify the login. Only if step 1.1 is accomplished and the sessionID of the client was valid or if step 1.1 and 1.2 have been accomplished a usable connection is negotiated. ### 1.1 Version check Client: ``` { "version": string, "sid": string } ``` Only sends `sid` if client has an old sessionID. Server: ``` { "version": string, "accept": bool, "sid": string } ``` If `accept` is `true` the connection is valid. Else the connection will be terminated. `sid` can be set if accept is `true` and must be set if the `sid` of the client is invalid. So the server gives a new `sid` if the session is invalid. The server can as well use no `sid`. If the server forbids `sid`s but the client is offering one then the connection is to be immediately closed! ### 1.2 Login Client: ``` { "user": string, "pass": string, "sid": string } ``` Server: ``` { "accept": bool } ``` If `accept` is `true` the connection is valid and the user is logged in. Else the connection will be terminated. The server is not obligated to send `sid` back. ## 2. Sending commands Commands can be sent by the client after a connection has been negotiated (See 1). Commands can be used unrelated to each other. ### 2.1 Status command Client: ``` { "command": "status" } ``` Server: ``` { "command": "status", "response": string } ``` ### TODO ## 3. Close connection ### 3.1 Close command Client: ``` { "command": "close", "remembersID": bool } ``` `remembersID` is optional. If it's `true` then the sID shall be remembered by the server. Else it shall be forgotten. Server: ``` { "command": "close", "response": "bye" } ```