Backend for CodeNames digital game with the rules of the "CodeNames: Pictures" 2-player version.
Teams arrangement:
- Enemy - 7
- Teammate - 8
- Neutral - 4
- Bomb - 1
npm i
npm start
.env file can contain PORT
You can use already hosted server (https://codenamesback.herokuapp.com
) or host it yourself.
-
Connect to the WebSocket
Response:
{ userId: "string", }
After that every request to the server API needs userId in the header
-
Send to the WebSocket
Request:
{ roomId: "number", }
Response:
{ guide: "bool", // Wheter a player is a guide words: [ // Array of 20 words { word: "string", // Word team: "TEAM", // Team: enemy | teammate | neutral | bomb; Only shown to the guide or after word has been activated (clicked) active: "bool", // Wheter word has been activated (clicked) }, // ... ], currentKey: { word: "string", // Key word count: "number", // Key count // Or empty object if no key has been given (at the start of the match) }, isActivePlayer: "bool", // Wheter it's a player's turn gameOver: "bool", // If the game is over win: "bool", // If the game is won }
After this, server will automatically respond with the same template on every change
-
-
Send to the Server (Guide)
/room/:roomId/keys
Request:
{ word: "string", // Key word count: "number", // Key count >0 }
Response: Empty
-
Send to the Server (Guesser)
/room/:roomId/guess
Request:{ wordIndex: "number", // Guessed word index }
Response:
{ team: "TEAM", // TEAM of the guessed word isActivePlayer: "bool", // Wheter a player is still active enemyIndex: "number", // Newly opened enemy index (only shown when the turn is over) }
-
-
Send to the Server (Guesser)
/room/:roomId/endturn
Request: Empty
Response:
{ enemyIndex: "number", // Newly opened enemy index }
-
Send to the Server
/room/:roomId/refresh
Request: Empty
Response: Empty (Socket sends settings of the new room)
Errors are sent as simple plain texts
Status | Text |
---|---|
Defaults | |
400 | 400 Bad Request |
401 | 401 Not Authorized |
403 | 403 Forbidden |
404 | 404 Not Found |
500 | 500 Internal Server Error |
Specifics | |
400 | Key count is zero |
400 | RoomId is NaN |
400 | RoomId is not different |
400 | Word is already active |
400 | Word not found |
403 | Game is over |
403 | Not source's turn |
403 | Room is already refreshing |
403 | Room is full |
403 | Source is already joining a room |
403 | Source is not a guesser |
403 | Source is not a guide |
404 | Room not found |