Ejemplo n.º 1
0
 public function boot()
 {
     parent::boot();
     if (!$this->container->getParameter('bzion.miscellaneous.development')) {
         if ($this->getEnvironment() != 'prod' || $this->isDebug()) {
             throw new ForbiddenDeveloperAccessException('You are not allowed to access this page in a non-production ' . 'environment. Please change the "development" configuration ' . 'value and clear the cache before proceeding.');
         }
     }
     if (in_array($this->getEnvironment(), array('profile', 'dev'), true)) {
         Debug::enable();
     }
     Service::setGenerator($this->container->get('router')->getGenerator());
     Service::setEnvironment($this->getEnvironment());
     Service::setModelCache(new ModelCache());
     Service::setContainer($this->container);
     $this->setUpTwig();
     // Ratchet doesn't support PHP's native session storage, so use our own
     // if we need it
     if (Service::getParameter('bzion.features.websocket.enabled') && $this->getEnvironment() !== 'test') {
         $storage = new NativeSessionStorage(array(), new DatabaseSessionHandler());
         $session = new Session($storage);
         Service::getContainer()->set('session', $session);
     }
     Notification::initializeAdapters();
 }
Ejemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 public static function isEnabled()
 {
     if (!parent::isEnabled()) {
         return false;
     }
     return \Service::getParameter('bzion.features.websocket.enabled');
 }
Ejemplo n.º 3
0
 /**
  * Returns all the events that this subscriber handles, and which method
  * handles each one
  *
  * @return array
  */
 public static function getSubscribedEvents()
 {
     if (!\Service::getParameter('bzion.features.elasticsearch.enabled')) {
         // Don't subscribe to events if elasticsearch is disabled
         return array();
     }
     return array('group.abandon' => 'update', 'group.join' => 'update', 'group.kick' => 'update', 'message.new' => 'onNew');
 }
Ejemplo n.º 4
0
 /**
  * {@inheritDoc}
  */
 protected function build($builder)
 {
     $durations = \Service::getParameter('bzion.league.duration');
     foreach ($durations as $duration => &$value) {
         $durations[$duration] = $duration;
     }
     return $builder->add('first_team', new MatchTeamType())->add('second_team', new MatchTeamType())->add('duration', 'choice', array('choices' => $durations, 'constraints' => new NotBlank(), 'expanded' => true))->add('server_address', 'text', array('required' => false, 'attr' => array('placeholder' => 'brad.guleague.org:5100')))->add('time', new DatetimeWithTimezoneType(), array('constraints' => array(new NotBlank(), new LessThan(array('value' => \TimeDate::now()->addMinutes(10), 'message' => 'The timestamp of the match must not be in the future'))), 'data' => \TimeDate::now(\Controller::getMe()->getTimezone())))->add('enter', 'submit');
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 protected function build($builder)
 {
     $durations = \Service::getParameter('bzion.league.duration');
     foreach ($durations as $duration => &$value) {
         $durations[$duration] = $duration;
     }
     return $builder->add('first_team', new MatchTeamType(), array('disableTeam' => $this->isEdit() && $this->editing->isOfficial()))->add('second_team', new MatchTeamType(), array('disableTeam' => $this->isEdit() && $this->editing->isOfficial()))->add('duration', 'choice', array('choices' => $durations, 'constraints' => new NotBlank(), 'expanded' => true))->add('server_address', 'text', array('required' => false, 'attr' => array('placeholder' => 'brad.guleague.org:5100')))->add('time', new DatetimeWithTimezoneType(), array('constraints' => array(new NotBlank(), new LessThan(array('value' => \TimeDate::now()->addMinutes(10), 'message' => 'The timestamp of the match must not be in the future'))), 'data' => $this->isEdit() ? $this->editing->getTimestamp()->setTimezone(\Controller::getMe()->getTimezone()) : \TimeDate::now(\Controller::getMe()->getTimezone()), 'with_seconds' => $this->isEdit()))->add('map', new ModelType('Map'), array('required' => false))->add('type', 'choice', array('choices' => array(\Match::OFFICIAL => 'Official', \Match::FUN => 'Fun match', \Match::SPECIAL => 'Special event match'), 'disabled' => $this->editing && $this->editing->isOfficial(), 'label' => 'Match Type'))->add('enter', 'submit');
 }
Ejemplo n.º 6
0
 /**
  * Constructor for our extension of Parsedown
  */
 function __construct()
 {
     $this->camo = array();
     $this->camo['enabled'] = \Service::getParameter('bzion.features.camo.enabled');
     if ($this->camo['enabled']) {
         $this->camo['key'] = \Service::getParameter('bzion.features.camo.key');
         $this->camo['base_url'] = \Service::getParameter('bzion.features.camo.base_url');
         $this->camo['whitelisted_domains'] = \Service::getParameter('bzion.features.camo.whitelisted_domains');
     }
 }
Ejemplo n.º 7
0
 /**
  * Perform a search on messages and get the results
  *
  * @param  string    $query The query string
  * @return Message[] The results of the search
  */
 public function search($query)
 {
     Debug::startStopwatch('search.messages');
     if (\Service::getParameter('bzion.features.elasticsearch.enabled')) {
         $results = $this->elasticSearch($query);
     } else {
         $results = $this->mysqlSearch($query);
     }
     Debug::finishStopwatch('search.messages');
     return $results;
 }
Ejemplo n.º 8
0
 /**
  * Get an instance of the Database object
  *
  * This should be the main way to acquire access to the database
  *
  * @todo Move this to the Service class
  *
  * @return Database The Database object
  */
 public static function getInstance()
 {
     if (!self::$Database) {
         if (Service::getEnvironment() == 'test') {
             if (!Service::getParameter('bzion.testing.enabled')) {
                 throw new Exception('You have to specify a MySQL database for testing in the bzion.testing section of your configuration file.');
             }
             self::$Database = new self(Service::getParameter('bzion.testing.host'), Service::getParameter('bzion.testing.username'), Service::getParameter('bzion.testing.password'), Service::getParameter('bzion.testing.database'));
         } else {
             self::$Database = new self(Service::getParameter('bzion.mysql.host'), Service::getParameter('bzion.mysql.username'), Service::getParameter('bzion.mysql.password'), Service::getParameter('bzion.mysql.database'));
         }
     }
     return self::$Database;
 }
Ejemplo n.º 9
0
$autoreport = Player::newPlayer(55976, "AutoReport", null, "test");
$blast = Player::newPlayer(180, "blast", null, "active", Player::S_ADMIN);
$kierra = Player::newPlayer(2229, "kierra", null, "active", Player::ADMIN, "", "", 174);
$mdskpr = Player::newPlayer(8312, "mdskpr");
$snake = Player::newPlayer(54497, "Snake12534");
$tw1sted = Player::newPlayer(9736, "tw1sted", null, "active", Player::DEVELOPER);
$brad = Player::newPlayer(3030, "brad", null, "active", Player::S_ADMIN, "", "I keep nagging about when this project will be done");
$constitution = Player::newPlayer(9972, "Constitution", null, "active", Player::S_ADMIN);
$themap = Player::newPlayer(57422, "the map", null, "active", Player::COP);
$oldSnake = Player::newPlayer(54498, "Snake12534");
$oldSnake->setOutdated(true);
$allPlayers = array($alezakos, $allejo, $ashvala, $autoreport, $blast, $kierra, $mdskpr, $snake, $tw1sted, $brad, $constitution, $themap);
echo " done!";
echo "\nSending notifications...";
foreach (Player::getPlayers() as $player) {
    $event = new WelcomeEvent('Welcome to ' . Service::getParameter('bzion.site.name') . '!', $player);
    Notification::newNotification($player->getId(), 'welcome', $event);
}
echo " done!";
echo "\nAdding deleted objects...";
Team::createTeam("Amphibians", $snake->getId(), "", "")->delete();
$snake->refresh();
Team::createTeam("Serpents", $snake->getId(), "", "")->delete();
$snake->refresh();
Page::addPage("Test", "<p>This is a deleted page</p>", $tw1sted->getId())->delete();
echo " done!";
echo "\nAdding teams...";
$olfm = Team::createTeam("OpenLeague FM?", $kierra->getId(), "", "");
$reptitles = Team::createTeam("Reptitles", $snake->getId(), "", "", "open");
$fflood = Team::createTeam("Formal Flood", $allejo->getId(), "", "");
$lweak = Team::createTeam("[LakeWeakness]", $mdskpr->getId(), "", "");
Ejemplo n.º 10
0
 /**
  * Checks if the last update is older than or equal to the update interval
  * @return bool Whether the information is older than the update interval
  */
 public function staleInfo()
 {
     $update_time = $this->updated->copy();
     $update_time->modify(Service::getParameter('bzion.miscellaneous.update_interval'));
     return TimeDate::now() >= $update_time;
 }
Ejemplo n.º 11
0
 /**
  * Calculate the ELO score difference
  *
  * Computes the absolute value of the ELO score difference on each team
  * after a match, based on GU League's rules.
  *
  * @param  int $a_elo    Team A's current ELO score
  * @param  int $b_elo    Team B's current ELO score
  * @param  int $a_points Team A's match points
  * @param  int $b_points Team B's match points
  * @param  int $duration The match duration in minutes
  * @return int The ELO score difference
  */
 public static function calculateEloDiff($a_elo, $b_elo, $a_points, $b_points, $duration)
 {
     $prob = 1.0 / (1 + pow(10, ($b_elo - $a_elo) / 400.0));
     if ($a_points > $b_points) {
         $diff = 50 * (1 - $prob);
     } elseif ($a_points == $b_points) {
         $diff = 50 * (0.5 - $prob);
     } else {
         $diff = 50 * (0 - $prob);
     }
     // Apply ELO modifiers from `config.yml`
     $durations = Service::getParameter('bzion.league.duration');
     $diff *= isset($durations[$duration]) ? $durations[$duration] : 1;
     if (abs($diff) < 1 && $diff != 0) {
         // ELOs such as 0.75 should round up to 1...
         return $diff > 0 ? 1 : -1;
     }
     // ...everything else is rounded down (-3.7 becomes -3 and 48.1 becomes 48)
     return intval($diff);
 }
Ejemplo n.º 12
0
 /**
  * {@inheritdoc}
  *
  * @todo Redirect models with wrong alias when bzion.site.url_type === 'permalink'
  */
 public function getURL($action = 'show', $absolute = false, $params = array(), $vanity = false)
 {
     if (!$this->isValid()) {
         return "";
     }
     $forbiddenAliases = array('edit', 'delete', 'kick', 'invite', 'change-leader', 'matches', 'members');
     if (Service::getParameter('bzion.site.url_type') === 'permalink' && $this instanceof DuplexUrlInterface && !$vanity) {
         // Add both the alias and the ID to the URL if the model supports them
         // Make sure the alias is not forbidden
         if (in_array(strtolower($action), $forbiddenAliases)) {
             $alias = $this->getId();
         } else {
             $alias = $this->alias;
         }
         // Add the alias to the query parameters
         $params = $params + array('alias' => $alias);
         $alias = $this->getId();
     } else {
         if (in_array(strtolower($action), $forbiddenAliases)) {
             $alias = $this->getId();
         } else {
             $alias = $this->getAlias();
         }
     }
     return $this->getLink($alias, $action, $absolute, $params);
 }
Ejemplo n.º 13
0
 /**
  * Check whether or not a player been in a match or has logged on in the specified amount of time to be considered
  * active
  *
  * @return bool True if the player has been active
  */
 public function hasBeenActive()
 {
     $this->lazyLoad();
     $interval = Service::getParameter('bzion.miscellaneous.active_interval');
     $lastLogin = $this->last_login->copy()->modify($interval);
     $hasBeenActive = TimeDate::now() <= $lastLogin;
     if ($this->last_match->isValid()) {
         $lastMatch = $this->last_match->getTimestamp()->copy()->modify($interval);
         $hasBeenActive = $hasBeenActive || TimeDate::now() <= $lastMatch;
     }
     return $hasBeenActive;
 }