/**
  * Create a TimeDate object from another one, ignoring its timezone
  *
  * @param  \TimeDate   $from     The original timestamp
  * @param  string|null $timezone The timezone to add to the object (defaults
  *                               to the PHP's default)
  * @return \TimeDate
  */
 private function createTimeDate($from, $timezone = null)
 {
     if ($from === null) {
         return null;
     }
     // Make sure it's a TimeDate instance
     $time = \TimeDate::from($from);
     return \TimeDate::create($time->year, $time->month, $time->day, $time->hour, $time->minute, $time->second, $timezone);
 }
Example #2
0
 /**
  * Store a conversation event in the database
  *
  * @param  int        $conversation     The ID of the conversation
  * @param  Event      $event     The event
  * @param  string     $type      The type of the event
  * @param  mixed      $timestamp The timestamp when the event took place
  * @param  string     $status    The status of the event, can be 'visible', 'hidden', 'deleted' or 'reported'
  * @return ConversationEvent
  */
 public static function storeEvent($conversation, $event, $type, $timestamp = 'now', $status = 'visible')
 {
     return self::create(array("conversation_to" => $conversation, "message" => serialize($event), "event_type" => $type, "timestamp" => TimeDate::from($timestamp)->toMysql(), "status" => $status), 'issss');
 }
Example #3
0
 /**
  * Enter a new notification into the database
  * @param  int          $receiver  The receiver's ID
  * @param  string       $type      The type of the notification
  * @param  Event        $event     The event of the notification
  * @param  string       $timestamp The timestamp of the notification
  * @param  string       $status    The status of the notification (unread, read, deleted)
  * @return Notification An object representing the notification that was just entered
  */
 public static function newNotification($receiver, $type, $event, $timestamp = "now", $status = "unread")
 {
     $notification = self::create(array("receiver" => $receiver, "type" => $type, "event" => serialize($event), "timestamp" => TimeDate::from($timestamp)->toMysql(), "status" => $status), 'issss');
     return $notification;
 }
Example #4
0
 /**
  * Enter a new match to the database
  * @param  int             $a          Team A's ID
  * @param  int             $b          Team B's ID
  * @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
  * @param  int|null        $entered_by The ID of the player reporting the match
  * @param  string|DateTime $timestamp  When the match was played
  * @param  int[]           $a_players  The IDs of the first team's players
  * @param  int[]           $b_players  The IDs of the second team's players
  * @param  string|null     $server     The address of the server where the match was played
  * @param  int|null        $port       The port of the server where the match was played
  * @param  string          $replayFile The name of the replay file of the match
  * @param  string          $mapPlayed  The name of the map where the map was played, only for rotational leagues
  * @return Match           An object representing the match that was just entered
  */
 public static function enterMatch($a, $b, $a_points, $b_points, $duration, $entered_by, $timestamp = "now", $a_players = array(), $b_players = array(), $server = null, $port = null, $replayFile = null, $mapPlayed = null)
 {
     $team_a = Team::get($a);
     $team_b = Team::get($b);
     $a_elo = $team_a->getElo();
     $b_elo = $team_b->getElo();
     $diff = self::calculateEloDiff($a_elo, $b_elo, $a_points, $b_points, $duration);
     // Update team ELOs
     $team_a->changeElo($diff);
     $team_b->changeElo(-$diff);
     $match = self::create(array('team_a' => $a, 'team_b' => $b, 'team_a_points' => $a_points, 'team_b_points' => $b_points, 'team_a_players' => implode(',', $a_players), 'team_b_players' => implode(',', $b_players), 'team_a_elo_new' => $team_a->getElo(), 'team_b_elo_new' => $team_b->getElo(), 'elo_diff' => $diff, 'timestamp' => TimeDate::from($timestamp)->toMysql(), 'duration' => $duration, 'entered_by' => $entered_by, 'server' => $server, 'port' => $port, 'replay_file' => $replayFile, 'map_played' => $mapPlayed, 'status' => 'entered'), 'iiiissiiisiisisss', 'updated');
     $match->updateMatchCount();
     return $match;
 }
Example #5
0
 /**
  * Create a new team
  *
  * @param  string           $name        The name of the team
  * @param  int              $leader      The ID of the person creating the team, also the leader
  * @param  string           $avatar      The URL to the team's avatar
  * @param  string           $description The team's description
  * @param  string           $status      The team's status (open, closed, disabled or deleted)
  * @param  string|\TimeDate $created     The date the team was created
  *
  * @return Team   An object that represents the newly created team
  */
 public static function createTeam($name, $leader, $avatar, $description, $status = 'closed', $created = "now")
 {
     $created = TimeDate::from($created);
     $team = self::create(array('name' => $name, 'alias' => self::generateAlias($name), 'description' => $description, 'elo' => 1200, 'activity' => 0.0, 'matches_won' => 0, 'matches_draw' => 0, 'matches_lost' => 0, 'members' => 0, 'avatar' => $avatar, 'leader' => $leader, 'status' => $status, 'created' => $created->toMysql()));
     $team->addMember($leader);
     $team->getIdenticon($team->getId());
     return $team;
 }
Example #6
0
 /**
  * Enter a new match to the database
  * @param  int             $a          Team A's ID
  * @param  int             $b          Team B's ID
  * @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
  * @param  int|null        $entered_by The ID of the player reporting the match
  * @param  string|DateTime $timestamp  When the match was played
  * @param  int[]           $a_players  The IDs of the first team's players
  * @param  int[]           $b_players  The IDs of the second team's players
  * @param  string|null     $server     The address of the server where the match was played
  * @param  int|null        $port       The port of the server where the match was played
  * @param  string          $replayFile The name of the replay file of the match
  * @param  int             $map        The ID of the map where the match was played, only for rotational leagues
  * @param  string          $matchType  The type of match (e.g. official, fm, special)
  * @param  string          $a_color    Team A's color
  * @param  string          $b_color    Team b's color
  * @return Match           An object representing the match that was just entered
  */
 public static function enterMatch($a, $b, $a_points, $b_points, $duration, $entered_by, $timestamp = "now", $a_players = array(), $b_players = array(), $server = null, $replayFile = null, $map = null, $matchType = "official", $a_color = null, $b_color = null)
 {
     $matchData = array('team_a_color' => strtolower($a_color), 'team_b_color' => strtolower($b_color), 'team_a_points' => $a_points, 'team_b_points' => $b_points, 'team_a_players' => implode(',', $a_players), 'team_b_players' => implode(',', $b_players), 'timestamp' => TimeDate::from($timestamp)->toMysql(), 'duration' => $duration, 'entered_by' => $entered_by, 'server' => $server, 'replay_file' => $replayFile, 'map' => $map, 'status' => 'entered', 'match_type' => $matchType);
     if ($matchType === self::OFFICIAL) {
         $team_a = Team::get($a);
         $team_b = Team::get($b);
         $a_elo = $team_a->getElo();
         $b_elo = $team_b->getElo();
         $diff = self::calculateEloDiff($a_elo, $b_elo, $a_points, $b_points, $duration);
         // Update team ELOs
         $team_a->changeElo($diff);
         $team_b->changeElo(-$diff);
         $matchData = array_merge($matchData, array('team_a' => $a, 'team_b' => $b, 'team_a_elo_new' => $team_a->getElo(), 'team_b_elo_new' => $team_b->getElo(), 'elo_diff' => $diff));
     }
     $match = self::create($matchData, 'updated');
     if ($matchType === self::OFFICIAL) {
         $match->updateMatchCount();
     }
     $players = $match->getPlayers();
     Database::getInstance()->startTransaction();
     foreach ($players as $player) {
         $player->setLastMatch($match->getId());
     }
     Database::getInstance()->finishTransaction();
     return $match;
 }
Example #7
0
File: Ban.php Project: allejo/bzion
 /**
  * Add a new ban
  *
  * @param int         $playerID        The ID of the victim of the ban
  * @param int         $authorID        The ID of the player responsible for the ban
  * @param mixed|null $expiration      The expiration of the ban (set to NULL so that it never expires)
  * @param string      $reason          The full reason for the ban
  * @param string      $srvmsg          A summary of the ban to be displayed on server banlists (max 150 characters)
  * @param string[]    $ipAddresses     An array of IPs that have been banned
  * @param bool        $allowServerJoin Whether or not the player is allowed to join match servers
  *
  * @return Ban An object representing the ban that was just entered or false if the ban was not created
  */
 public static function addBan($playerID, $authorID, $expiration, $reason, $srvmsg = "", $ipAddresses = array(), $allowServerJoin = false)
 {
     $player = Player::get($playerID);
     if ($expiration !== null) {
         $expiration = TimeDate::from($expiration)->toMysql();
     } else {
         $player->markAsBanned();
     }
     // If there are no IPs to banned or no server ban message, then we'll allow the players to join as observers
     if (empty($srvmsg) || empty($ipAddresses)) {
         $allowServerJoin = true;
     }
     $ban = self::create(array('player' => $playerID, 'expiration' => $expiration, 'server_message' => $srvmsg, 'reason' => $reason, 'allow_server_join' => $allowServerJoin, 'author' => $authorID), array('created', 'updated'));
     if (is_array($ipAddresses)) {
         foreach ($ipAddresses as $ip) {
             $ban->addIP($ip);
         }
     } else {
         $ban->addIP($ipAddresses);
     }
     return $ban;
 }
Example #8
0
 /**
  * Get a list of changes that will be shown to the user
  *
  * @param  array[] $changelog The parsed changelog.yml file
  * @return array[] The changes to show to the user
  */
 private function parseChangelog($changelog)
 {
     $listed = array();
     $firstEntry = true;
     $lastChangeDate = \TimeDate::now()->startOfDay();
     $lastChanges = array();
     foreach ($changelog as $date => $changes) {
         $date = \TimeDate::from($date);
         if ($firstEntry) {
             // The array has been sorted, the first entry represents the
             // most recent change. Store its date so that we don't show the
             // same entry many times
             $firstEntry = false;
             if ($lastChangeDate >= $date) {
                 $lastChangeDate = $date;
                 $lastChanges = $changes;
             }
         }
         // Don't list changes that we've listed before
         if ($date == $this->lastUpdateDate) {
             $this->filterAlreadyListedChanges($changes);
         } elseif ($this->lastUpdateDate && $date < $this->lastUpdateDate) {
             break;
         }
         $listed = array_merge_recursive($listed, $changes);
     }
     $this->alreadyListedChanges = $lastChanges;
     $this->lastUpdateDate = $lastChangeDate;
     return $listed;
 }
Example #9
0
 /**
  * Sort the parsed changelog array before saving it
  *
  * @param array $changelog The parsed changelog
  */
 public static function sort(&$changelog)
 {
     uksort($changelog, function ($first, $second) {
         $a = \TimeDate::from($first);
         $b = \TimeDate::from($second);
         if ($a == $b) {
             return 0;
         }
         return $a > $b ? -1 : 1;
     });
 }
Example #10
0
 /**
  * Enter a new player to the database
  * @param  int              $bzid        The player's bzid
  * @param  string           $username    The player's username
  * @param  int              $team        The player's team
  * @param  string           $status      The player's status
  * @param  int              $role_id     The player's role when they are first created
  * @param  string           $avatar      The player's profile avatar
  * @param  string           $description The player's profile description
  * @param  int              $country     The player's country
  * @param  string           $timezone    The player's timezone
  * @param  string|\TimeDate $joined      The date the player joined
  * @param  string|\TimeDate $last_login  The timestamp of the player's last login
  * @return Player           An object representing the player that was just entered
  */
 public static function newPlayer($bzid, $username, $team = null, $status = "active", $role_id = self::PLAYER, $avatar = "", $description = "", $country = 1, $timezone = null, $joined = "now", $last_login = "******")
 {
     $joined = TimeDate::from($joined);
     $last_login = TimeDate::from($last_login);
     $timezone = $timezone ?: date_default_timezone_get();
     $player = self::create(array('bzid' => $bzid, 'team' => $team, 'username' => $username, 'alias' => self::generateAlias($username), 'status' => $status, 'avatar' => $avatar, 'description' => $description, 'country' => $country, 'timezone' => $timezone, 'joined' => $joined->toMysql(), 'last_login' => $last_login->toMysql()), 'iisssssisss');
     $player->addRole($role_id);
     $player->getIdenticon($player->getId());
     return $player;
 }
Example #11
0
 /**
  * Enter a new visit into the database
  * @param  int    $visitor    The visitor's id
  * @param  string $ip         The visitor's ip address
  * @param  string $host       The visitor's host
  * @param  string $user_agent The visitor's user agent
  * @param  string $referrer   The HTTP_REFERRER of the visit
  * @param  string $timestamp  The timestamp of the visit
  * @return Visit  An object representing the visit that was just entered
  */
 public static function enterVisit($visitor, $ip, $host, $user_agent, $referrer, $timestamp = "now")
 {
     $timestamp = TimeDate::from($timestamp);
     return self::create(array('player' => $visitor, 'ip' => $ip, 'host' => $host, 'user_agent' => $user_agent, 'referer' => $referrer, 'timestamp' => $timestamp->toMysql()));
 }
Example #12
0
 public function listAction()
 {
     Team::$cachedMatches = $this->getQueryBuilder('Match')->where('time')->isAfter(TimeDate::from('45 days ago'))->active()->getModels($fast = true);
     $teams = $this->getQueryBuilder()->sortBy('elo')->reverse()->getModels($fast = true);
     return array("teams" => $teams);
 }