Skip to content

ildar-icoosoft/chess-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chess-backend

Chess Backend used by Chess-PWA

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

Installation

git clone https://github.com/ildar-icoosoft/chess-backend.git
cd chess-backend
npm install

Start server

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

API reference (v1.0.0)

Users

/api/v1/entrance/login

PUT

Summary

Login

Parameters
Name Located in Description Required Schema
body body User credentials Yes LoginInput
Responses
Code Description Schema
200 successful operation User
401 The provided email and password combination does not match any user in the database

/api/v1/entrance/signup

POST

Summary

Sign up

Parameters
Name Located in Description Required Schema
body body User's credentials and full name Yes SignUpInput
Responses
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

/api/v1/account/logout

POST

Summary

Log out of this app

Parameters
Name Located in Description Required Schema
Responses
Code Description
200 successful operation
302 The requesting user agent looks to be a web browser

/api/v1/account/me

GET

Summary

Get current user data

Parameters
Name Located in Description Required Schema
Responses
Code Description Schema
200 successful operation User
401 User is not authenticated

/api/v1/user

GET

Summary

Get users list

Parameters
Name Located in Description Required Schema
Responses
Code Description Schema
200 successful operation [ User ]

Games

/api/v1/game

GET

Summary

Get games list

Parameters
Name Located in Description Required Schema
Responses
Code Description Schema
200 successful operation [ Game ]

/api/v1/game/{gameId}

GET

Summary

Get single game

Parameters
Name Located in Description Required Schema
gameId path ID of the game Yes integer
Responses
Code Description Schema
200 successful operation Game

/api/v1/board/game/{gameId}/move/{move}

POST

Summary

Make a board move

Parameters
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
Responses
Code Description Schema
200 successful operation Game
401 User is not authenticated
403 Invalid move
404 Game not found

/api/v1/board/game/{gameId}/abort

POST

Summary

Abort a game

Parameters
Name Located in Description Required Schema
gameId path ID of the game Yes integer
Responses
Code Description Schema
200 successful operation Game
401 User is not authenticated
404 Game not found

/api/v1/board/game/{gameId}/resign

POST

Summary

Resign a game

Parameters
Name Located in Description Required Schema
gameId path ID of the game Yes integer
Responses
Code Description Schema
200 successful operation Game
401 User is not authenticated
404 Game not found

/api/v1/board/game/{gameId}/draw/yes

POST

Summary

Create or accept a draw offer

Parameters
Name Located in Description Required Schema
gameId path ID of the game Yes integer
Responses
Code Description Schema
200 successful operation Game
401 User is not authenticated
404 Game not found

/api/v1/board/game/{gameId}/draw/no

POST

Summary

Decline a draw offer

Parameters
Name Located in Description Required Schema
gameId path ID of the game Yes integer
Responses
Code Description Schema
200 successful operation Game
401 User is not authenticated
404 Game not found

Challenges

/api/v1/challenge/ai

POST

Summary

Start a game with AI

Parameters
Name Located in Description Required Schema
body body ChallengeInput object Yes ChallengeAiInput
Responses
Code Description Schema
200 successful operation Game
401 User is not authenticated

Seeks

/api/v1/seek

GET

Summary

Get seeks list

Parameters
Name Located in Description Required Schema
Responses
Code Description Schema
200 successful operation [ Seek ]

/api/v1/board/seek

POST

Summary

Create a public seek, to start a game with a random player

Description

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.

Parameters
Name Located in Description Required Schema
body body ChallengeInput object Yes CreateSeekInput
Responses
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

/api/v1/board/seek/{seekId}/accept

POST

Summary

Accept a seek

Parameters
Name Located in Description Required Schema
seekId path ID of seek to accept Yes integer
Responses
Code Description Schema
200 successful operation Seek
401 User is not authenticated
404 Seek not found

Chat messages

/api/v1/board/game/{gameId}/chat

GET

Summary

Get chat messages

Parameters
Name Located in Description Required Schema
gameId path ID of the game Yes integer
Responses
Code Description Schema
200 successful operation [ ChatMessage ]
404 Game not found

POST

Summary

Create a chat message

Parameters
Name Located in Description Required Schema
gameId path ID of the game Yes integer
body body CreateChatMessageInput object Yes CreateChatMessageInput
Responses
Code Description Schema
200 successful operation ChatMessage
401 User is not authenticated
404 Game not found

Models

LoginInput

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

SignUpInput

Name Type Description Required
fullName string The user's full name
Example: "Frida Kahlo de Rivera"
Yes
email 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

ChallengeAiInput

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

CreateSeekInput

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

CreateChatMessageInput

Name Type Description Required
text string Text of the message Yes

User

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

Seek

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

ChatMessage

Name Type Description Required
id integer No
createdBy User No
game integer game ID No
text string Text of the message No

Game

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published