diff --git a/.env.example b/.env.example index 3505012a..1c6cdbba 100644 --- a/.env.example +++ b/.env.example @@ -12,6 +12,7 @@ WSS_ADDRESS=0.0.0.0 WSS_DATA_PORT=9443 WSS_GAME_PORT=8443 WSS_BINARY_PORT=7443 +WSS_AUTH_PORT=6443 # cli/ratchet/ws_game.php # WS_ADDRESS=0.0.0.0 diff --git a/cli/workerman/auth.php b/cli/workerman/auth.php new file mode 100644 index 00000000..2c6e03b7 --- /dev/null +++ b/cli/workerman/auth.php @@ -0,0 +1,46 @@ +load(); + +$db = new Db([ + 'driver' => $_ENV['DB_DRIVER'], + 'host' => $_ENV['DB_HOST'], + 'database' => $_ENV['DB_DATABASE'], + 'username' => $_ENV['DB_USERNAME'], + 'password' => $_ENV['DB_PASSWORD'], +]); + +$logger = new Logger('auth'); +$logger->pushHandler(new StreamHandler(DataWebSocket::STORAGE_FOLDER . '/auth.log', Logger::INFO)); + +$parser = new Parser(new Cli($db)); + +$clientStorage = new ClientStorage($logger); + +$socketName = "websocket://{$_ENV['WSS_ADDRESS']}:{$_ENV['WSS_AUTH_PORT']}"; + +$context = [ + 'ssl' => [ + 'local_cert' => __DIR__ . '/../../ssl/fullchain.pem', + 'local_pk' => __DIR__ . '/../../ssl/privkey.pem', + 'verify_peer' => false, + ], +]; + +$webSocket = (new DataWebSocket($socketName, $context, $parser))->init($clientStorage); + +$webSocket->getWorker()->runAll(); diff --git a/docker-compose.workerman.yml b/docker-compose.workerman.yml index 19e68906..508a7733 100644 --- a/docker-compose.workerman.yml +++ b/docker-compose.workerman.yml @@ -44,3 +44,18 @@ services: - ./docker/php/php.ini:/usr/local/etc/php/php.ini working_dir: /usr/share/chess-server command: ["php", "cli/workerman/binary.php", "start", "--d"] + auth: + build: + context: . + dockerfile: Dockerfile + user: 1000:1000 + container_name: chess_server_auth + ports: + - ${WSS_AUTH_PORT}:${WSS_AUTH_PORT} + restart: always + volumes: + - ./:/usr/share/chess-server + - /usr/share/chess-server/vendor + - ./docker/php/php.ini:/usr/local/etc/php/php.ini + working_dir: /usr/share/chess-server + command: ["php", "cli/workerman/auth.php", "start", "--d"] diff --git a/docs/index.md b/docs/index.md index d7002bff..764cbc92 100644 --- a/docs/index.md +++ b/docs/index.md @@ -3,7 +3,14 @@ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/license/mit/) [![Contributors](https://img.shields.io/github/contributors/chesslablab/chess-server)](https://github.com/chesslablab/chess-server/graphs/contributors) -PHP Chess Server is an asynchronous PHP server that provides services of chess data and chess functionality to play online over a WebSocket connection. +PHP Chess Server is an asynchronous PHP server that provides services of data and chess functionality to play online over a WebSocket connection. + +| Port | Service Name | Description | +| ---- | ------------ | ----------- | +| 9443 | data | JSON-formatted data | +| 8443 | game | Chess functionality | +| 7443 | binary | Binary data | +| 6443 | auth | Authentication functionality | ## Object-Oriented diff --git a/docs/installation.md b/docs/installation.md index a9569c53..1f30327b 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -6,16 +6,13 @@ Clone the `chesslablab/chess-server` repo into your projects folder. Then `cd` t cp .env.example .env ``` -Create an empty `data.log` file: +Create empty log files for each service as described next. ```txt touch storage/data.log -``` - -Create an empty `game.log` file: - -```txt touch storage/game.log +touch storage/binary.log +touch storage/auth.log ``` Make sure to have installed the `fullchain.pem` and `privkey.pem` files in the `ssl` folder, and run the Docker container in detached mode in the background: diff --git a/src/Command/Auth/Cli.php b/src/Command/Auth/Cli.php new file mode 100644 index 00000000..395b54d8 --- /dev/null +++ b/src/Command/Auth/Cli.php @@ -0,0 +1,26 @@ +db = $db; + $this->commands->attach(new TotpRefreshCommand($db)); + $this->commands->attach(new TotpSignInCommand($db)); + $this->commands->attach(new TotpSignUpCommand($db)); + } + + public function getDb(): Db + { + return $this->db; + } +} diff --git a/src/Command/Data/TotpRefreshCommand.php b/src/Command/Auth/TotpRefreshCommand.php similarity index 98% rename from src/Command/Data/TotpRefreshCommand.php rename to src/Command/Auth/TotpRefreshCommand.php index 3ea3a2a7..7fe1796a 100644 --- a/src/Command/Data/TotpRefreshCommand.php +++ b/src/Command/Auth/TotpRefreshCommand.php @@ -1,6 +1,6 @@ commands->attach(new ResultPlayerCommand($db)); $this->commands->attach(new ResultCommand($db)); $this->commands->attach(new SearchCommand($db)); - $this->commands->attach(new TotpRefreshCommand($db)); - $this->commands->attach(new TotpSignInCommand($db)); - $this->commands->attach(new TotpSignUpCommand($db)); } public function getDb(): Db