Skip to content

Commit

Permalink
Filter the params
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed Jan 16, 2025
1 parent a71ca86 commit 37fc6c1
Show file tree
Hide file tree
Showing 24 changed files with 28 additions and 23 deletions.
5 changes: 5 additions & 0 deletions src/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public function __get($property)
}
}

protected function params(string $params)
{
return json_decode(stripslashes(str_replace(['\r', '\n'], '', $params)), true);
}

abstract public function validate(array $command);

abstract public function run(AbstractSocket $socket, array $argv, int $id);
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Auth/Blocking/TotpRefreshCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function validate(array $argv)

public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);
$params = $this->params($argv[1]);

$this->pool->add(new TotpRefreshTask($params))
->then(function ($result) use ($socket, $id) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Auth/Blocking/TotpSignInCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function validate(array $argv)

public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);
$params = $this->params($argv[1]);

$this->pool->add(new TotpSignInTask($params))
->then(function ($result) use ($socket, $id) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Binary/Blocking/ImageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function validate(array $argv)

public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);
$params = $this->params($argv[1]);

$this->pool->add(new ImageTask($params), 128000)
->then(function ($result) use ($socket, $id) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Data/Blocking/AutocompleteBlackCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function validate(array $argv)

public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);
$params = $this->params($argv[1]);

$this->pool->add(new AutocompleteBlackTask($params))
->then(function ($result) use ($socket, $id) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Data/Blocking/AutocompleteEventCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function validate(array $argv)

public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);
$params = $this->params($argv[1]);

$this->pool->add(new AutocompleteEventTask($params))
->then(function ($result) use ($socket, $id) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Data/Blocking/AutocompleteWhiteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function validate(array $argv)

public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);
$params = $this->params($argv[1]);

$this->pool->add(new AutocompleteWhiteTask($params))
->then(function ($result) use ($socket, $id) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Data/Blocking/OpeningCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function validate(array $argv)

public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);
$params = $this->params($argv[1]);

$this->pool->add(new OpeningTask($params), 128000)
->then(function ($result) use ($socket, $id) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Data/Blocking/SearchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function validate(array $argv)

public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);
$params = $this->params($argv[1]);

$this->pool->add(new SearchTask($params), 128000)
->then(function ($result) use ($socket, $id) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Game/Blocking/ExtractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function validate(array $argv)

public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);
$params = $this->params($argv[1]);

$this->pool->add(new ExtractTask($params))
->then(function ($result) use ($socket, $id) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Game/Blocking/HeuristicCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function validate(array $argv)

public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);
$params = $this->params($argv[1]);

$this->pool->add(new HeuristicTask($params))
->then(function ($result) use ($socket, $id) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Game/Blocking/LeaveCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function validate(array $argv)
public function run(AbstractSocket $socket, array $argv, int $id)
{
if ($gameMode = $socket->getGameModeStorage()->getById($id)) {
$params = json_decode(stripslashes($argv[1]), true);
$params = $this->params($argv[1]);

$gameMode->getGame()->setResignation($params['color']);

Expand Down
2 changes: 1 addition & 1 deletion src/Command/Game/Blocking/PlayCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function validate(array $argv)

public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);
$params = $this->params($argv[1]);
$gameMode = $socket->getGameModeStorage()->getById($id);

if (get_class($gameMode) === PlayMode::class) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Game/Blocking/PlayLanCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function validate(array $argv)

public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);
$params = $this->params($argv[1]);
$gameMode = $socket->getGameModeStorage()->getById($id);

if (get_class($gameMode) === PlayMode::class) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Game/Blocking/PlayRavCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function validate(array $argv)

public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);
$params = $this->params($argv[1]);

$this->pool->add(new PlayRavTask($params), 128000)
->then(function ($result) use ($socket, $id) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Game/Blocking/RecognizerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function validate(array $argv)

public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);
$params = $this->params($argv[1]);

$this->pool->add(new RecognizerTask($params))
->then(function ($result) use ($socket, $id) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Game/Blocking/ResignCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function validate(array $argv)

public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);
$params = $this->params($argv[1]);

$gameMode = $socket->getGameModeStorage()->getById($id);
$gameMode->getGame()->setResignation($params['color']);
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Game/Blocking/RestartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function validate(array $argv)

public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);
$params = $this->params($argv[1]);
$gameMode = $socket->getGameModeStorage()->getByJwt($params['jwt']);

$this->pool->add(new RestartTask([
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Game/Blocking/StockfishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function validate(array $argv)

public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);
$params = $this->params($argv[1]);
$game = $socket->getGameModeStorage()->getById($id)->getGame();

if (!isset($game->state()->end)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Game/Blocking/TutorFenCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function validate(array $argv)

public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);
$params = $this->params($argv[1]);

$this->pool->add(new TutorFenTask($params))
->then(function ($result) use ($socket, $id) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Game/NonBlocking/AcceptPlayRequestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function validate(array $argv)

public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);
$params = $this->params($argv[1]);

$gameMode = $socket->getGameModeStorage()->getByUid($params['uid']);

Expand Down
2 changes: 1 addition & 1 deletion src/Command/Game/NonBlocking/LegalCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function validate(array $argv)

public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);
$params = $this->params($argv[1]);
$gameMode = $socket->getGameModeStorage()->getById($id);

return $socket->getClientStorage()->send([$id],
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Game/NonBlocking/RandomizerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function validate(array $argv)

public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);
$params = $this->params($argv[1]);

try {
if (count($params['items']) === 1) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Game/NonBlocking/StartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function validate(array $argv)

public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);
$params = $this->params($argv[1]);

if (AnalysisMode::NAME === $params['mode']) {
try {
Expand Down

0 comments on commit 37fc6c1

Please sign in to comment.