Chess-Socket is an open-source socket-io server primarily made for the chessdom project live chess game-play functionality. It maintains the state of game for reconciliation in case of accidental disconnects. It'll recursively sent the responses untill it recieve a acknowledgement from the respective client.
To run the project in your local machine, you must have
- Node.js : Volta recommended
Once you finish installation Node.js, follow the commands to setup the project locally on your machine
-
clone the project
git clone https://github.com/Sandstorm831/chessSocket.git
-
enter the project
cd chessSocket -
Install NPM packages
npm install
-
Create .env file at the root of the folder.
touch .env
-
Setup the
DATABASE_URLin.envfileDATABASE_URL=
You can get a hosted SQL database from Aiven
-
Establish link between
schema.prismaand.envnpx prisma generate
-
Apply the migrations to the DB.
npx prisma migrate deploy
-
build the project
npm run build
-
Start the server
npm run start
This completes the set-up for this project, all the functionalities present in the application will now be live at
port: 8080, remember to bypassCORSsetting present in theserver.tsfile to connect to alocalhost.
chessSocket
┃
┣ prisma
┃ ┣ migrations // various migrations files
┃ ┃ ┃ // for DB schema
┃ ┃ ┣ 20250206074038_init
┃ ┃ ┃ ┗ migration.sql
┃ ┃ ┣ 20250206074554_pgn_long_string
┃ ┃ ┃ ┗ migration.sql
┃ ┃ ┣ 20250206075112_storing_pgs_as_text
┃ ┃ ┃ ┗ migration.sql
┃ ┃ ┗ migration_lock.toml
┃ ┗ schema.prisma // DB schema
┃
┣ src
┃ ┣ websockets
┃ ┃ ┗ server.ts // Complete web-socket server
┃ ┣ DBQueries.ts // All DB queries definition
┃ ┗ queue.ts // Custom Queue data structure
┃
┣ .gitignore
┣ README.md
┣ package-lock.json
┣ package.json
┣ tsconfig.json
┗ tsconfig.tsbuildinfo
- Server will Ban any user, from whom any unexpected response came back to the server. The ban last for 15 minures
- Server maintains the state of game, thus for any accidental disconnects, the original game will be restored if the game exists and user joins before 10 seconds
- A valid game end will prompt the server to save the game to database automatically, any valid game ending includes resignation, checkmate or draw
- Any user leaving in between the game, is dealt by prompting the same to the opponent user
- Rematch functionality is also given, therefore, if both users clicks rematch a rematch will start immediately
Distributed under the GPL-3.0 license. See LICENSE for more information.