Permalink
Browse files

Move elo adjustment code to scala

  • Loading branch information...
1 parent df8304d commit 5a9013d5f855fc9a345dcd33f1a37c9eab855f6f @ornicar committed Apr 19, 2012
@@ -9,12 +9,7 @@ class CheatController extends Controller
{
public function adjustAction($username)
{
- $user = $this->container->get('fos_user.user_manager')->findUserByUsername($username);
- if (!$user) {
- throw new NotFoundHttpException('No user with username '.$username);
- }
- $this->get('lichess.cheat.punisher')->punish($user);
- $this->get('doctrine.odm.mongodb.document_manager')->flush();
+ $this->get('lila')->adjust($username);
return new RedirectResponse($this->generateUrl("fos_user_user_show", array("username" => $username)));
}
@@ -1,43 +0,0 @@
-<?php
-
-namespace Bundle\LichessBundle\Cheat;
-
-use Bundle\LichessBundle\Document\GameRepository;
-use Bundle\LichessBundle\Document\Game;
-use Bundle\LichessBundle\Elo\Updater;
-use Application\UserBundle\Document\User;
-
-class Punisher
-{
- protected $gameRepository;
- protected $eloUpdater;
- protected $logger;
-
- public function __construct(GameRepository $gameRepository, Updater $eloUpdater)
- {
- $this->gameRepository = $gameRepository;
- $this->eloUpdater = $eloUpdater;
- }
-
- public function setLogger(\Closure $logger)
- {
- $this->logger = $logger;
- }
-
- public function punish(User $user)
- {
- $this->log(sprintf('Reset %s elo to %d', $user->getUsername(), User::STARTING_ELO));
- if ($user->getElo() > User::STARTING_ELO) {
- $this->eloUpdater->adjustElo($user, User::STARTING_ELO);
- }
- $user->setEngine(true);
- }
-
- protected function log($message)
- {
- if($this->logger) {
- $logger = $this->logger;
- $logger($message);
- }
- }
-}
@@ -1,48 +0,0 @@
-<?php
-
-namespace Bundle\LichessBundle\Command;
-
-use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
-use Symfony\Component\Console\Input\InputArgument;
-use Symfony\Component\Console\Input\InputOption;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Output\Output;
-
-/**
- * Redistributes a cheater ELO to his victims
- */
-class CheatAdjustCommand extends ContainerAwareCommand
-{
- /**
- * @see Command
- */
- protected function configure()
- {
- $this
- ->setDefinition(array(
- new InputArgument('username', InputArgument::REQUIRED, 'Username of the cheater'),
- ))
- ->setName('lichess:cheat:adjust')
- ;
- }
-
- /**
- * @see Command
- */
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $username = $input->getArgument('username');
- $user = $this->getContainer()->get('fos_user.repository.user')->findOneByUsername($username);
- if(!$user) {
- throw new \InvalidArgumentException(sprintf('The user "%s" does not exist', $username));
- }
- $punisher = $this->getContainer()->get('lichess.cheat.punisher');
- $punisher->setLogger(function($message) use ($output)
- {
- $output->writeLn($message);
- });
- $punisher->punish($user);
- $this->getContainer()->get('doctrine.odm.mongodb.document_manager')->flush();
- }
-}
@@ -39,9 +39,7 @@ public function getConfigTree()
->end()
->arrayNode('feature')->addDefaultsIfNotSet()
->children()
- ->booleanNode('cheat')->defaultTrue()->end()
->booleanNode('listener')->defaultTrue()->end()
- ->booleanNode('elo')->defaultTrue()->end()
->booleanNode('chess')->defaultTrue()->end()
->booleanNode('config')->defaultTrue()->end()
->booleanNode('cache')->defaultTrue()->end()
@@ -118,6 +118,11 @@ public function talk(Game $game, $message)
$this->post('talk/' . $game->getId(), $message);
}
+ public function adjust($username)
+ {
+ $this->post('adjust/' . $username);
+ }
+
public function join(Player $player, array $messages)
{
$this->post('join/' . $player->getFullId(), array(
@@ -1,15 +0,0 @@
-<?xml version="1.0" ?>
-
-<container xmlns="http://symfony.com/schema/dic/services"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
-
- <services>
-
- <service id="lichess.cheat.punisher" class="Bundle\LichessBundle\Cheat\Punisher">
- <argument type="service" id="lichess.repository.game" />
- <argument type="service" id="lichess.elo.updater" />
- </service>
-
- </services>
-</container>
@@ -5,6 +5,7 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
+ <service id="lichess.elo.calculator" class="Bundle\LichessBundle\Elo\Calculator" public="false" />
<service id="lichess.blamer.player" class="Bundle\LichessBundle\Blamer\PlayerBlamer" public="false">
<argument type="service" id="security.context" />
</service>
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-
-<container xmlns="http://symfony.com/schema/dic/services"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
-
- <services>
-
- <service id="lichess.elo.calculator" class="Bundle\LichessBundle\Elo\Calculator" public="false" />
-
- <service id="lichess.elo.updater" class="Bundle\LichessBundle\Elo\Updater" public="false">
- <argument type="service" id="lichess.repository.history" />
- </service>
-
- </services>
-
-</container>

0 comments on commit 5a9013d

Please sign in to comment.