This backend is based on Sails Framework. So you can use any sails's features in this project. It is a free online chess game server focused on realtime gameplay and ease of use.
- Usage
- API reference (v1.0.0)
- Models
git clone https://github.com/ildar-icoosoft/chess-backend.git
cd chess-backend
npm install
sails lift
sails lift
takes the following options:
- --prod - in production environment
- --port - on the port specified by portNum instead of the default (1337)
- --verbose - with verbose logging enabled
- --silly - with insane logging enabled
Login
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
body | body | User credentials | Yes | LoginInput |
Code | Description | Schema |
---|---|---|
200 | successful operation | User |
401 | The provided email and password combination does not match any user in the database |
Sign up
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
body | body | User's credentials and full name | Yes | SignUpInput |
Code | Description | Schema |
---|---|---|
200 | successful operation | User |
400 | The provided fullName, password and/or email address are invalid | |
409 | The provided email address is already in use |
Log out of this app
Name | Located in | Description | Required | Schema |
---|
Code | Description |
---|---|
200 | successful operation |
302 | The requesting user agent looks to be a web browser |
Get current user data
Name | Located in | Description | Required | Schema |
---|
Code | Description | Schema |
---|---|---|
200 | successful operation | User |
401 | User is not authenticated |
Get users list
Name | Located in | Description | Required | Schema |
---|
Code | Description | Schema |
---|---|---|
200 | successful operation | [ User ] |
Get games list
Name | Located in | Description | Required | Schema |
---|
Code | Description | Schema |
---|---|---|
200 | successful operation | [ Game ] |
Get single game
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
gameId | path | ID of the game | Yes | integer |
Code | Description | Schema |
---|---|---|
200 | successful operation | Game |
Make a board move
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
gameId | path | ID of the game | Yes | integer |
move | path | The move to play, in UCI format (for example e2e4) | Yes | string |
Code | Description | Schema |
---|---|---|
200 | successful operation | Game |
401 | User is not authenticated | |
403 | Invalid move | |
404 | Game not found |
Abort a game
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
gameId | path | ID of the game | Yes | integer |
Code | Description | Schema |
---|---|---|
200 | successful operation | Game |
401 | User is not authenticated | |
404 | Game not found |
Resign a game
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
gameId | path | ID of the game | Yes | integer |
Code | Description | Schema |
---|---|---|
200 | successful operation | Game |
401 | User is not authenticated | |
404 | Game not found |
Create or accept a draw offer
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
gameId | path | ID of the game | Yes | integer |
Code | Description | Schema |
---|---|---|
200 | successful operation | Game |
401 | User is not authenticated | |
404 | Game not found |
Decline a draw offer
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
gameId | path | ID of the game | Yes | integer |
Code | Description | Schema |
---|---|---|
200 | successful operation | Game |
401 | User is not authenticated | |
404 | Game not found |
Start a game with AI
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
body | body | ChallengeInput object | Yes | ChallengeAiInput |
Code | Description | Schema |
---|---|---|
200 | successful operation | Game |
401 | User is not authenticated |
Get seeks list
Name | Located in | Description | Required | Schema |
---|
Code | Description | Schema |
---|---|---|
200 | successful operation | [ Seek ] |
Create a public seek, to start a game with a random player
The response is streamed but doesn't contain any information.
Keep the connection open to keep the seek active.
If the client closes the connection, the seek is canceled.
If the seek is accepted, or expires, the server closes the connection.
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
body | body | ChallengeInput object | Yes | CreateSeekInput |
Code | Description | Schema |
---|---|---|
200 | successful operation | Game |
401 | User is not authenticated | |
404 | Seek not found. The connection may have been aborted by the client |
Accept a seek
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
seekId | path | ID of seek to accept | Yes | integer |
Code | Description | Schema |
---|---|---|
200 | successful operation | Seek |
401 | User is not authenticated | |
404 | Seek not found |
Get chat messages
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
gameId | path | ID of the game | Yes | integer |
Code | Description | Schema |
---|---|---|
200 | successful operation | [ ChatMessage ] |
404 | Game not found |
Create a chat message
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
gameId | path | ID of the game | Yes | integer |
body | body | CreateChatMessageInput object | Yes | CreateChatMessageInput |
Code | Description | Schema |
---|---|---|
200 | successful operation | ChatMessage |
401 | User is not authenticated | |
404 | Game not found |
Name | Type | Description | Required |
---|---|---|---|
emailAddress | string (email) | The email to try in this attempt, e.g. "irl@example.com" | Yes |
password | string | The unencrypted password to try in this attempt, e.g. "passwordlol" | Yes |
rememberMe | boolean | Note that this is NOT SUPPORTED when using virtual requests (e.g. sending requests over WebSockets instead of HTTP) | No |
Name | Type | Description | Required |
---|---|---|---|
fullName | string | The user's full name Example: "Frida Kahlo de Rivera" |
Yes |
string (email) | The email to try in this attempt, e.g. "irl@example.com" | No | |
password | string | The unencrypted password to try in this attempt, e.g. "passwordlol" | Yes |
Name | Type | Description | Required |
---|---|---|---|
level | integer | AI strength (1 - 4) | Yes |
clockLimit | integer | Clock initial time in seconds (60 - 10800) | Yes |
clockIncrement | integer | Clock increment in seconds (0 - 60) | Yes |
color | string | Which color you get to play Enum: "random" , "white" , "black" |
Yes |
Name | Type | Description | Required |
---|---|---|---|
clockLimit | integer | Clock initial time in seconds (60 - 10800) | Yes |
clockIncrement | integer | Clock increment in seconds (0 - 60) | Yes |
color | string | Which color you get to play Enum: "random" , "white" , "black" |
Yes |
Name | Type | Description | Required |
---|---|---|---|
text | string | Text of the message | Yes |
Name | Type | Description | Required |
---|---|---|---|
id | integer | No | |
createdAt | integer | Creation date in unix timestamp format | No |
fullName | string | Full representation of the user's name Example: "Mary Sue van der McHenst" |
No |
isOnline | boolean | true if user is online | No |
Name | Type | Description | Required |
---|---|---|---|
id | integer | No | |
createdAt | integer | Creation date in unix timestamp format | No |
clockLimit | integer | Clock initial time in seconds (60 - 10800) | No |
clockIncrement | integer | Clock increment in seconds (0 - 60) | No |
color | string | Which color you get to play Enum: "random" , "white" , "black" |
No |
createdBy | User | No | |
game | Game | No |
Name | Type | Description | Required |
---|---|---|---|
id | integer | No | |
createdBy | User | No | |
game | integer | game ID | No |
text | string | Text of the message | No |
Name | Type | Description | Required |
---|---|---|---|
id | number | No | |
initialFen | string | \'startpos\' or position in FEN format Example: "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1" |
No |
wtime | integer | White time in msec Example: 300000 |
No |
btime | integer | Black time in msec Example: 300000 |
No |
clockLimit | integer | Clock initial time in seconds (60 - 10800) | No |
clockIncrement | integer | Clock increment in seconds (0 - 60) | No |
aiLevel | integer | AI strength (1 - 4). If game is not against AI then value is NULl | No |
moves | string | Example: "e2e4 e7e5 g1f3" |
No |
status | string | Game status Enum: "started" , "resign" , "stalemate" , "mate" , "draw" , "aborted" , "outoftime" |
No |
turn | string | Turn to move Enum: "white" , "black" |
No |
winner | string | Winner of the game Enum: "white" , "black" |
No |
drawOffer | string | draw offer from white or black Enum: "white" , "black" |
No |
lastMoveAt | integer | A JS timestamp (epoch ms) representing the moment at which the last move was made | No |
white | User | No | |
black | User | No |