Skip to content

Commit

Permalink
Fixed the /start command
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed Mar 27, 2024
1 parent 77acc03 commit f56ed31
Showing 1 changed file with 15 additions and 28 deletions.
43 changes: 15 additions & 28 deletions src/Command/StartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,36 +307,23 @@ public function run(ChesslaBlabSocket $socket, array $argv, int $id)
],
]);
} elseif (StockfishMode::NAME === $argv[2]) {
if ($argv[3] === Color::W || $argv[3] === Color::B) {
$stockfishMode = new StockfishMode(
new Game($argv[1], $argv[2], $socket->getGm()),
[$id]
);
$socket->getGameModeStorage()->set($stockfishMode);
return $socket->getClientStorage()->sendToOne($id, [
$this->name => [
'variant' => $argv[1],
'mode' => $argv[2],
'color' => $argv[3],
],
]);
} else {
$board = (new ClassicalFenStrToBoard($argv[3]))->create();
$settings = (object) json_decode(stripslashes($argv[3]), true);
if (isset($settings->fen)) {
$board = (new ClassicalFenStrToBoard($settings->fen))->create();
$game = (new Game($argv[1], $argv[2]))->setBoard($board);
$stockfishMode = new StockfishMode(
$game,
[$id],
);
$socket->getGameModeStorage()->set($stockfishMode);
return $socket->getClientStorage()->sendToOne($id, [
$this->name => [
'variant' => $argv[1],
'mode' => $argv[2],
'color' => $game->getBoard()->getTurn(),
'fen' => $game->getBoard()->toFen(),
],
]);
} else {
$game = new Game($argv[1], $argv[2], $socket->getGm());
}
$stockfishMode = new StockfishMode($game, [$id]);
$socket->getGameModeStorage()->set($stockfishMode);
return $socket->getClientStorage()->sendToOne($id, [
$this->name => [
'variant' => $argv[1],
'mode' => $argv[2],
'color' => $settings->color,
'fen' => $game->getBoard()->toFen(),
],
]);
}
}
}

0 comments on commit f56ed31

Please sign in to comment.