Skip to content

PHP Ratchet WebSocket server using PHP Chess.

Notifications You must be signed in to change notification settings

vikeng/chess-server

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Chess Server

PHP Ratchet WebSocket server using PHP Chess. The chess server is intended to connect to a Redux Chess app.

Setup

Clone the chesslablab/chess-server repo into your projects folder as it is described in the following example:

$ git clone [email protected]:chesslablab/chess-server.git

Then cd the chess-server directory and install the Composer dependencies:

$ composer install

Create an .env file:

$ cp .env.example .env

WebSocket Server

Start the server:

$ php cli/ws-server.php
Welcome to PHP Chess Server
Commands available:
/accept {"id":"id"} Accepts a friend request to play a game.
/ascii Prints the ASCII representation of the game.
/castling Gets the castling status.
/captures Gets the pieces captured by both players.
/fen Prints the FEN string representation of the game.
/heuristicpicture Takes a balanced heuristic picture of the current game.
/history The current game's history.
/ischeck Finds out if the game is in check.
/ismate Finds out if the game is over.
/piece {"position":"string"} Gets a piece by its position on the board.
/pieces {"color":["w","b"]} Gets the pieces on the board by color.
/playfen {"fen":"string"} Plays a chess move in shortened FEN format.
/quit Quits a game.
/start {"mode":["analysis","loadfen","playfriend"],"fen":"string","color":["w","b"],"min":"int"} Starts a new game.
/status The current game status.
/takeback {"action":["accept","decline","propose"]} Allows to manage a takeback.
/undomove Undoes the last move.

Listening to commands...

Open a console in your favorite browser and run commands:

const ws = new WebSocket('ws://127.0.0.1:8080');
ws.onmessage = (res) => { console.log(res.data) };
ws.send('/start analysis');

Secure WebSocket Server

Before starting the secure WebSocket server for the first time, make sure to copy the certificate.crt and private.key files into the ssl folder as explained in A Simple Example of SSL/TLS WebSocket With ReactPHP and Ratchet.

Start the server:

$ php cli/wss-server.php

Open a console in your favorite browser and run commands:

const ws = new WebSocket('wss://pchess.net:8443');
ws.onmessage = (res) => { console.log(res.data) };
ws.send('/start analysis');

License

The MIT License.

Contributions

See the contributing guidelines.

Happy learning and coding! Thank you, and keep it up.


For further information you're invited to read my learning journey:

About

PHP Ratchet WebSocket server using PHP Chess.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 99.8%
  • Shell 0.2%