Ejemplo n.º 1
0
 /**
  * @param string $filename
  * @param string $path
  * @return Map
  * @throws \InvalidArgumentException
  */
 function get($filename, $path)
 {
     if (mb_detect_encoding($filename, 'UTF-8', true) === false) {
         $utf8Filename = utf8_encode($filename);
     } else {
         $utf8Filename = $filename;
     }
     if (!file_exists($this->mapDirectory . $path . $filename)) {
         $this->db()->execute('DELETE FROM Maps WHERE path=%s AND filename=%s', $this->db()->quote($path), $this->db()->quote($utf8Filename));
         throw new \InvalidArgumentException($this->mapDirectory . $path . $utf8Filename . ': file does not exist');
     }
     $fileStats = stat($this->mapDirectory . $path . $filename);
     $result = $this->db()->execute('SELECT * FROM Maps WHERE path=%s AND filename=%s AND size=%d AND mTime=FROM_UNIXTIME(%d)', $this->db()->quote($path), $this->db()->quote($utf8Filename), $fileStats['size'], $fileStats['mtime']);
     if (!$result->recordCount()) {
         $mapInfo = \DedicatedManager\Utils\GbxReader\Map::read($this->mapDirectory . $path . $filename);
         $map = new Map();
         $fields = array('uid', 'name', 'environment', 'mood', 'type', 'displayCost', 'nbLaps', 'authorLogin', 'authorNick', 'authorZone', 'authorTime', 'goldTime', 'silverTime', 'bronzeTime', 'authorScore', 'size', 'mTime');
         $this->db()->execute('INSERT INTO Maps(path, filename, %s) ' . 'VALUES (%s,%s,%s,%s,%s,%s,%s,%d,%d,%s,%s,%s,%d,%d,%d,%d,%d,%d,FROM_UNIXTIME(%d)) ' . 'ON DUPLICATE KEY UPDATE ' . \ManiaLib\Database\Tools::getOnDuplicateKeyUpdateValuesString($fields), implode(',', $fields), $this->db()->quote($map->path = $path), $this->db()->quote($map->filename = $utf8Filename), $this->db()->quote($map->uid = $mapInfo->uid), $this->db()->quote($map->name = $mapInfo->name), $this->db()->quote($map->environment = $mapInfo->environment), $this->db()->quote($map->mood = $mapInfo->mood), $this->db()->quote($map->type = $mapInfo->type), $map->displayCost = $mapInfo->displayCost, $map->nbLaps = $mapInfo->nbLaps, $this->db()->quote($map->authorLogin = $mapInfo->author->login), $this->db()->quote($map->authorNick = $mapInfo->author->nickname), $this->db()->quote($map->authorZone = $mapInfo->author->zone), $map->authorTime = $mapInfo->authorTime, $map->goldTime = $mapInfo->goldTime, $map->silverTime = $mapInfo->silverTime, $map->bronzeTime = $mapInfo->bronzeTime, $map->authorScore = $mapInfo->authorScore, $fileStats['size'], $fileStats['mtime']);
         if ($mapInfo->thumbnail) {
             imagejpeg($mapInfo->thumbnail, MANIALIB_APP_PATH . '/www/media/images/thumbnails/' . $map->uid . '.jpg', 100);
         }
     } else {
         $map = Map::fromRecordSet($result);
     }
     return $map;
 }
Ejemplo n.º 2
0
 /**
  * @param string $login
  * @param int $offset
  * @param int $length
  * @return Rent[]
  * @throws \InvalidArgumentException
  */
 function getCurrents($login, $offset = null, $length = null)
 {
     if (!preg_match('/^[a-zA-Z0-9-_\\.]{1,25}$/', $login)) {
         throw new \InvalidArgumentException();
     }
     $quotedLogin = $this->db()->quote($login);
     $result = $this->db()->execute('SELECT R.*, S.login FROM Rents R ' . 'LEFT JOIN Servers S ON R.id = S.idRent ' . 'WHERE playerLogin = %s ' . 'AND rentDate < NOW() ' . 'AND DATE_ADD(rentDate, INTERVAL duration HOUR) > NOW() ' . 'ORDER BY DATE_ADD(rentDate, INTERVAL duration HOUR) DESC %s', $quotedLogin, \ManiaLib\Database\Tools::getLimitString($offset, $length));
     return Rent::arrayFromRecordSet($result);
 }
Ejemplo n.º 3
0
 /**
  * @return Server[]
  */
 function getList($offset = null, $length = null)
 {
     $result = $this->db()->execute('SELECT S.* FROM Servers S %s', \ManiaLib\Database\Tools::getLimitString($offset, $length));
     return Server::arrayFromRecordSet($result);
 }
Ejemplo n.º 4
0
 protected function getKeys($path, array $excludePath = array(), $environment = null, $nbLaps = null, $type = null, $mapType = null, $recursive = false, $offset = null, $length = null)
 {
     $path .= $recursive ? '%' : '';
     $path = str_replace('\\', '/', $path);
     $excludePath = array_map(array($this->db(), 'quote'), $excludePath);
     return $this->db()->execute('SELECT CONCAT(path,filename) FROM Maps ' . 'WHERE path LIKE %s ' . ($excludePath ? 'AND path NOT IN (%3$s) ' : '') . ($environment ? 'AND environment = %4$s ' : '') . ($nbLaps ? 'AND nbLaps != 0 ' : '') . ($type ? 'AND type = %5$s ' : '') . ($mapType ? 'AND mapType = %6$s ' : '') . 'ORDER BY name ASC %s', $this->db()->quote($path), \ManiaLib\Database\Tools::getLimitString($offset, $length), implode($excludePath), $this->db()->quote($environment), $this->db()->quote($type), $this->db()->quote($mapType))->fetchArrayOfSingleValues();
 }
 function getServerList($offset = 0, $length = 7)
 {
     return $this->db()->execute('SELECT serverLogin FROM Analytics GROUP BY serverLogin %s', \ManiaLib\Database\Tools::getLimitString($offset, $length))->fetchArrayOfSingleValues();
 }