diff --git a/src/Command/Data/Cli.php b/src/Command/Data/Cli.php index de24d45..5d39b54 100644 --- a/src/Command/Data/Cli.php +++ b/src/Command/Data/Cli.php @@ -18,9 +18,10 @@ public function __construct(Db $db) $this->commands->attach(new AutocompleteBlackCommand($db)); $this->commands->attach(new AutocompleteEventCommand($db)); $this->commands->attach(new AutocompleteWhiteCommand($db)); + $this->commands->attach(new RankingCommand($db)); + $this->commands->attach(new ResultCommand($db)); $this->commands->attach(new ResultEventCommand($db)); $this->commands->attach(new ResultPlayerCommand($db)); - $this->commands->attach(new ResultCommand($db)); $this->commands->attach(new SearchCommand($db)); } diff --git a/src/Command/Data/RankingCommand.php b/src/Command/Data/RankingCommand.php new file mode 100644 index 0000000..f7f2b02 --- /dev/null +++ b/src/Command/Data/RankingCommand.php @@ -0,0 +1,34 @@ +name = '/ranking'; + $this->description = 'Top players by ELO.'; + } + + public function validate(array $argv) + { + return count($argv) - 1 === 0; + } + + public function run(AbstractSocket $socket, array $argv, int $id) + { + $sql = "SELECT username, elo FROM users WHERE lastLoginAt IS NOT NULL ORDER BY elo DESC LIMIT 100"; + + $arr = $this->db->query($sql)->fetchAll(\PDO::FETCH_ASSOC); + + return $socket->getClientStorage()->send([$id], [ + $this->name => $arr, + ]); + } +}