Skip to content

Commit

Permalink
Call to a member function getResourceIds() on null
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed Oct 10, 2024
1 parent 82e00fe commit 6c5d04a
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions src/Command/Game/RestartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,38 @@ public function validate(array $argv)
public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);
$gameMode = $socket->getGameModeStorage()->getByJwt($params['jwt']);

$this->pool->add(new RestartAsyncTask([
'decoded' => $gameMode->getJwtDecoded(),
]))->then(function ($result) use ($socket, $gameMode) {
if ($result->variant === Game::VARIANT_960) {
$startPos = str_split($result->startPos);
$board = (new Chess960FenStrToBoard($result->fen, $startPos))->create();
$game = (new Game($result->variant, Game::MODE_PLAY))->setBoard($board);
} 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(), [
$this->name => [
'jwt' => $newGameMode->getJwt(),
'timer' => $newGameMode->getTimer(),
],
]);
});
if ($gameMode = $socket->getGameModeStorage()->getByJwt($params['jwt'])) {
$this->pool->add(new RestartAsyncTask([
'decoded' => $gameMode->getJwtDecoded(),
]))->then(function ($result) use ($socket, $gameMode) {
if ($result->variant === Game::VARIANT_960) {
$startPos = str_split($result->startPos);
$board = (new Chess960FenStrToBoard($result->fen, $startPos))->create();
$game = (new Game($result->variant, Game::MODE_PLAY))->setBoard($board);
} 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(), [
$this->name => [
'jwt' => $newGameMode->getJwt(),
'timer' => $newGameMode->getTimer(),
],
]);
});
}
}
}

0 comments on commit 6c5d04a

Please sign in to comment.