Skip to content

Commit

Permalink
Refactored RestartCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed Oct 10, 2024
1 parent 6c5d04a commit f503132
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/Command/Game/RestartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
use Chess\Variant\Classical\PGN\AN\Color;
use ChessServer\Command\AbstractCommand;
use ChessServer\Command\Game\Game;
use ChessServer\Command\Game\Mode\PlayMode;
use ChessServer\Socket\AbstractSocket;
use Firebase\JWT\JWT;

class RestartCommand extends AbstractCommand
{
Expand Down Expand Up @@ -41,23 +39,19 @@ public function run(AbstractSocket $socket, array $argv, int $id)
} else {
$game = new Game($result->variant, Game::MODE_PLAY);
}
$newGameMode = (new PlayMode(
$game,
$gameMode->getResourceIds(),
JWT::encode((array) $result, $_ENV['JWT_SECRET'], 'HS256')
))
->setStatus(PlayMode::STATUS_ACCEPTED)
->setStartedAt(time())
->setUpdatedAt(time())
->setTimer([
Color::W => $result->min * 60,
Color::B => $result->min * 60,
]);
$socket->getGameModeStorage()->set($newGameMode);
return $socket->getClientStorage()->send($newGameMode->getResourceIds(), [
$gameMode->setGame($game)
->setJwt((array) $result)
->setStartedAt(time())
->setUpdatedAt(time())
->setTimer([
Color::W => $result->min * 60,
Color::B => $result->min * 60,
]);
$socket->getGameModeStorage()->set($gameMode);
return $socket->getClientStorage()->send($gameMode->getResourceIds(), [
$this->name => [
'jwt' => $newGameMode->getJwt(),
'timer' => $newGameMode->getTimer(),
'jwt' => $gameMode->getJwt(),
'timer' => $gameMode->getTimer(),
],
]);
});
Expand Down

0 comments on commit f503132

Please sign in to comment.