Giter Site home page Giter Site logo

chess-server's Introduction

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:

chess-server's People

Contributors

ctzxvulkan avatar pen-y-fan avatar programarivm avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.