Skip to content

Repository files navigation

CodeNames Back

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

Setup

npm i
npm start

.env file can contain PORT


Usage

You can use already hosted server (https://codenamesback.herokuapp.com) or host it yourself.

  1. Connect to the WebSocket

    Response:

    {userId: "string",}

    After that every request to the server API needs userId in the header

  2. Send to the WebSocket

    Request:

    {roomId: "number",}

    Response:

    {guide: "bool",// Wheter a player is a guidewords: [// Array of 20 words{word: "string",// Wordteam: "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 wordcount: "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 turngameOver: "bool",// If the game is overwin: "bool",// If the game is won}

    After this, server will automatically respond with the same template on every change

    1. Send to the Server (Guide) /room/:roomId/keys

      Request:

      {word: "string",// Key wordcount: "number",// Key count >0}

      Response: Empty

    2. Send to the Server (Guesser) /room/:roomId/guess Request:

      {wordIndex: "number",// Guessed word index}

      Response:

      {team: "TEAM",// TEAM of the guessed wordisActivePlayer: "bool",// Wheter a player is still activeenemyIndex: "number",// Newly opened enemy index (only shown when the turn is over)}
  3. Send to the Server (Guesser) /room/:roomId/endturn

    Request: Empty

    Response:

    {enemyIndex: "number",// Newly opened enemy index}
  4. Send to the Server /room/:roomId/refresh

    Request: Empty

    Response: Empty (Socket sends settings of the new room)

Errors

Errors are sent as simple plain texts

StatusText
Defaults
400400 Bad Request
401401 Not Authorized
403403 Forbidden
404404 Not Found
500500 Internal Server Error
Specifics
400Key count is zero
400RoomId is NaN
400RoomId is not different
400Word is already active
400Word not found
403Game is over
403Not source's turn
403Room is already refreshing
403Room is full
403Source is already joining a room
403Source is not a guesser
403Source is not a guide
404Room not found

Projects using this API

About

CodeNames digital backend with "CodeNames: Pictures" 2-player rules

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages