diff --git a/src/Command/Game/Cli.php b/src/Command/Game/Cli.php index f435e973..133964af 100644 --- a/src/Command/Game/Cli.php +++ b/src/Command/Game/Cli.php @@ -14,6 +14,7 @@ use ChessServer\Command\Game\Async\StockfishCommand; use ChessServer\Command\Game\Async\TutorFenCommand; use ChessServer\Command\Game\Sync\AcceptPlayRequestCommand; +use ChessServer\Command\Game\Sync\AsciiCommand; use ChessServer\Command\Game\Sync\DrawCommand; use ChessServer\Command\Game\Sync\EvalNamesCommand; use ChessServer\Command\Game\Sync\LegalCommand; @@ -32,6 +33,7 @@ public function __construct(Pool $pool) parent::__construct(); // text-based commands + $this->commands->attach(new AsciiCommand()); $this->commands->attach(new EvalNamesCommand()); $this->commands->attach(new OnlineGamesCommand()); $this->commands->attach(new UndoCommand()); diff --git a/src/Command/Game/Sync/AsciiCommand.php b/src/Command/Game/Sync/AsciiCommand.php new file mode 100644 index 00000000..fc68adf4 --- /dev/null +++ b/src/Command/Game/Sync/AsciiCommand.php @@ -0,0 +1,29 @@ +name = '/ascii'; + $this->description = 'Returns an ASCII representation of the board.'; + } + + public function validate(array $argv) + { + return count($argv) - 1 === 0; + } + + public function run(AbstractSocket $socket, array $argv, int $id) + { + $gameMode = $socket->getGameModeStorage()->getById($id); + + return $socket->getClientStorage()->send([$id], [ + $this->name => $gameMode->getGame()->getBoard()->toString(), + ]); + } +}