Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented the /ascii command #429

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Implemented the /ascii command
programarivm committed Nov 15, 2024
commit 6eb922e8e29658089cb795d2014c5daae2c76b88
2 changes: 2 additions & 0 deletions src/Command/Game/Cli.php
Original file line number Diff line number Diff line change
@@ -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());
29 changes: 29 additions & 0 deletions src/Command/Game/Sync/AsciiCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace ChessServer\Command\Game\Sync;

use ChessServer\Command\AbstractSyncCommand;
use ChessServer\Socket\AbstractSocket;

class AsciiCommand extends AbstractSyncCommand
{
public function __construct()
{
$this->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(),
]);
}
}