/** * Get array of output data to use in the template * * @param \SQ\ServerQuery $sq Main application object populated with server data * @return mixed[] */ public static function getTemplateData(ServerQuery $sq) { $servers = $sq->getServers(); $serverOutput = array(); foreach ($servers as $gs) { $serverOutput[] = self::getServerTemplateData($gs); } return array('servers' => $serverOutput, 'stylesheet' => Config::WEB_PATH . 'serverquery.css'); }
private function _queryServer($queries, $id = null) { if (empty($id)) { $servers = SBServer::model()->findAll(); } else { if (is_array($id)) { $servers = SBServer::model()->findAllByPk($id); } else { $servers = array(SBServer::model()->findByPk($id)); } } $results = array(); foreach ($servers as $server) { $query = new ServerQuery($server->host, $server->port); $result = array('id' => $server->id, 'host' => $server->host, 'port' => $server->port); if ($queries & self::QUERY_INFO) { $info = $query->getInfo(); if (empty($info)) { $result['error'] = array('code' => 'ERR_TIMEOUT', 'message' => Yii::t('sourcebans', 'components.ServerQuery.err_timeout') . ' (' . $server . ')'); } else { if ($info['hostname'] == "anned by server\n") { $result['error'] = array('code' => 'ERR_BLOCKED', 'message' => Yii::t('sourcebans', 'components.ServerQuery.err_blocked') . ' (' . $server . ')'); } else { $map_image = '/images/maps/' . $server->game->folder . '/' . $info['map'] . '.jpg'; $result['hostname'] = preg_replace('/[\\x00-\\x1F]/', null, $info['hostname']); // Strip UTF-8 characters $result['numplayers'] = $info['numplayers']; $result['maxplayers'] = $info['maxplayers']; $result['map'] = basename($info['map']); // Strip Steam Workshop folder $result['os'] = $info['os']; $result['secure'] = $info['secure']; $result['map_image'] = file_exists(Yii::getPathOfAlias('webroot') . $map_image) ? Yii::app()->baseUrl . $map_image : null; } } } if ($queries & self::QUERY_PLAYERS) { $result['players'] = $query->getPlayers(); usort($result['players'], array($this, '_sortPlayers')); foreach ($result['players'] as &$player) { if ($player['time'] > 60) { $player['time'] = floor($player['time'] / 60) * 60; } // Round off to minutes $player['time'] = Yii::app()->format->formatLength($player['time']); } } if ($queries & self::QUERY_RULES) { $result['rules'] = $query->getRules(); } $results[] = $result; } return empty($id) || is_array($id) ? $results : $results[0]; }
public function init() { $this->queryClass = ServerQuery::className(); parent::init(); }
* The MIT License * * Copyright 2015 Steve Guidetti. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace SQ; require __DIR__ . '/config.php'; require __DIR__ . '/lib/ServerQuery.class.php'; require __DIR__ . '/lib/Template.class.php'; header('Content-Type: text/plain; charset=UTF-8'); $sq = new ServerQuery(); $sq->exec(); var_dump(Template::getTemplateData($sq));
* The MIT License * * Copyright 2015 Steve Guidetti. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace SQ; require __DIR__ . '/config.php'; require __DIR__ . '/lib/ServerQuery.class.php'; require __DIR__ . '/lib/Template.class.php'; $sq = new ServerQuery(); $sq->exec(); $data = Template::getTemplateData($sq); require __DIR__ . '/template.php';
* * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace SQ; require __DIR__ . '/config.php'; require __DIR__ . '/lib/ServerQuery.class.php'; $sleepTime = Config::CACHE_TIME; $sq = new ServerQuery(); $startTime = time(); while (time() - $startTime < 60 - $sleepTime) { set_time_limit(60); $sq->cron(); sleep($sleepTime); }