2019-04-01 20:11:03 +02:00
# Ultimate TicTacToe Server
2019-03-07 11:29:35 +01:00
2019-03-10 00:29:52 +01:00
a python server backend for ultimate tic-tac-toe.
communication with the web client is done by a (far from any standard and almost random) json protocol:
2019-04-01 20:05:57 +02:00
## setup server
2019-03-10 00:29:52 +01:00
2019-04-01 20:05:57 +02:00
setup the database connection settings in `settings.py` . If files for a certificate are given, the websocket connection will be use the secured `wss://` websocket protocol instead of `ws://` (which is necessary if the client is accessed by `https://` ). To create the necessary tables, the script `./create_database.py` can be used
## communication protocol with client
2019-03-14 00:01:02 +01:00
**json match state:**
```json
{
2019-04-01 20:11:03 +02:00
"complete_field": '[[...],[...],...]',
"global_field": '[[...],[...],...]',
"last_move": {
"sub_x": < int: xcoord of subfield of last move > ,
"sub_y": < int: ycoord of subfield of last move > ,
"x": < int: local xcoord in subfield of last move > ,
"y": < int: local ycoord in subfield of last move >
2019-03-14 00:01:02 +01:00
}
2019-04-01 20:11:03 +02:00
"game_over": < true | false > ,
"is_draw": < true | false > ,
"player_won": < null | < player_name > >,
"current_player": < null | < player_name > >,
"player_a": "...",
"player_b": "..."
2019-03-14 00:01:02 +01:00
}
```
2019-04-01 20:11:03 +02:00
`complete_field` is of dimension 9x9, `global_field` of 3x3 (indicating the status of each subfield).
The possible values for a single field are
2019-03-21 12:06:22 +01:00
2019-04-01 20:11:03 +02:00
```
FIELD_EMPTY = 0
FIELD_USER_A = 1
FIELD_USER_B = 2
FIELD_DRAW = 3
```
2019-03-21 12:06:22 +01:00
**match**:
2019-04-01 20:05:57 +02:00
server sends this to every user which is participating in a match if it's updated
2019-03-21 12:06:22 +01:00
```json
{
"type": "match_update",
"data": {
"id": "...",
2019-04-01 16:13:44 +02:00
"revoke_time": < revoke_time > ,
2019-03-21 12:06:22 +01:00
"match_state": < null | < match_state > >
}
}
```
2019-04-01 20:05:57 +02:00
**new temp session**
2019-03-21 12:06:22 +01:00
2019-04-01 20:05:57 +02:00
NOT IMPLEMENTED YET (and maybe never will be)
2019-03-21 12:06:22 +01:00
2019-04-01 20:05:57 +02:00
give the possibility to temporary login without a password
2019-03-14 00:01:02 +01:00
client
```json
{
"type": "temp_session",
"data": {
"name": "< player_name > "
}
}
```
server response:
```json
{
2019-03-21 12:06:22 +01:00
"type": "login_response",
2019-03-14 00:01:02 +01:00
"data": {
"success": < true | false > ,
"id": "< session-id > ",
2019-03-21 12:06:22 +01:00
"msg": "..."
2019-03-14 00:01:02 +01:00
}
}
```
**connect by session id**
2019-04-01 20:05:57 +02:00
reconnect with the session id from the last session
2019-03-14 00:01:02 +01:00
client
```json
{
"type": "reconnect",
"data": {
"id": "< session-id > ",
}
}
```
server response:
```json
{
"type": "reconnect_response",
"data": {
"success": < true | false > ,
"msg": "..."
}
}
```
2019-03-21 12:06:22 +01:00
**login or register**:
2019-04-01 20:05:57 +02:00
login with username and password. If the username does not exist yet, a new account
is created automatically. After a successful login the server sends an elo update, friends update and match updates for each open match,.
client:
2019-03-21 12:06:22 +01:00
```json
{
"type": "login",
"data": {
"name": "< player_name > ",
"pw": "< password > "
}
}
```
2019-04-01 20:05:57 +02:00
server response:
2019-03-21 12:06:22 +01:00
```json
{
"type": "login_response",
"data": {
"success": < true | false > ,
"id": "< session-id > ",
"msg": "..."
}
}
```
2019-03-14 00:01:02 +01:00
**match_request**:
2019-04-01 20:05:57 +02:00
will be send by clients. If `player` is `null` the player will be matched with the next (or previous)
player which sent a request without a player name
client:
2019-03-14 00:01:02 +01:00
```json
{
"type": "match_request",
"data": {
"player": < null | < opponent_name > >
}
}
```
server_response:
```json
{
"type": "match_request_response",
"data": {
"success": < true | false >
"msg": "..."
}
}
```
**match_move**:
2019-04-01 20:05:57 +02:00
sending moves to the server. The server will answer with a match update.
2019-03-14 00:01:02 +01:00
client
```json
{
"type": "move",
"data": {
2019-03-21 12:06:22 +01:00
"id": "match_id",
2019-03-14 00:01:02 +01:00
"sub_x": "...",
"sub_y": "...",
"x": "...",
"y": "..."
}
}
```
**match update**
2019-04-01 20:05:57 +02:00
(is also sent on match start and send for all matches after login)
2019-03-14 00:01:02 +01:00
server:
```json
{
"type": "match_update",
"data": {
"id": "< match_id > ",
"match_state": "< json match state > "
}
}
```
**match close**
client:
```json
{
"type": "end_match",
"data": {
"id": "< match_id > "
}
}
```
2019-03-21 12:06:22 +01:00
2019-03-24 16:44:20 +01:00
**friend request**:
```json
{
"type": "friend_request",
"data" : {
"user": "< friend > "
}
}
```
response:
```json
{
"type": "friend_request_response",
"data": {
"success": < true | false >
"msg": "..."
}
}
```
**unfriend**:
```json
{
"type": "unfriend_request",
"data" : {
"user": "< friend > "
}
}
```
response:
```json
{
"type": "unfriend_request_response",
"data": {
"success": < true | false >
"msg": "..."
}
}
```
**friend update**:
2019-04-01 20:05:57 +02:00
is sent by server after a login or reconnect
2019-03-24 16:44:20 +01:00
```json
{
"type": "friends_update",
"data": {
2019-03-29 12:52:03 +01:00
"friends": "< list of friends > ",
"elos": "< list of elo values > "
}
}
```
**elo rank update**:
2019-04-01 20:05:57 +02:00
is sent by server after login, reconnect or a finished match
2019-03-29 12:52:03 +01:00
```json
{
"type": "elo_update",
"data": {
2019-03-29 14:50:38 +01:00
"elo": < elo_value > ,
"rank": < rank > ,
"top_names": < list of top 100 names > ,
"top_elos": < list of top 100 elos >
2019-03-24 16:44:20 +01:00
}
}
```