some minor things

This commit is contained in:
kremsy 2013-11-10 19:50:24 +01:00
parent 5a7246a791
commit 07c009bea0
3 changed files with 57 additions and 55 deletions

View File

@ -64,16 +64,16 @@ class map {
$this->name = 'undefined'; $this->name = 'undefined';
} }
$mapFetcher = new \GBXChallMapFetcher(true); /* $mapFetcher = new \GBXChallMapFetcher(true);
try{ try{
$mapFetcher->processFile($this->server->mapdir . $this->filename); $mapFetcher->processFile($this->mc->server->mapdir . $this->filename);
} catch (Exception $e){ } catch (Exception $e){
trigger_error($e->getMessage(), E_USER_WARNING); trigger_error($e->getMessage(), E_USER_WARNING);
} }
$this->authorNick = $mapFetcher->authorNick; $this->authorNick = $mapFetcher->authorNick;
$this->authorEInfo = $mapFetcher->authorEInfo; $this->authorEInfo = $mapFetcher->authorEInfo;
$this->authorZone = $mapFetcher->authorZone; $this->authorZone = $mapFetcher->authorZone;
*/
$this->mx = new \MXInfoFetcher('SM', $this->uid, false); //SM -> change to gameerkennung $this->mx = new \MXInfoFetcher('SM', $this->uid, false); //SM -> change to gameerkennung
} }
} }

View File

@ -10,13 +10,12 @@ namespace ManiaControl;
class mapHandler { class mapHandler {
/** /**
* Private properties * Private properties
*/ */
private $maniaControl = null; private $maniaControl = null;
private $mapList = array(); private $mapList = array();
/** /**
* Construct map handler * Construct map handler
* @param ManiaControl $maniaControl * @param ManiaControl $maniaControl
@ -53,6 +52,8 @@ class mapHandler {
* @param array $callback * @param array $callback
*/ */
public function onInit(){ public function onInit(){
$this->maniaControl->client->query('GetMapList', 300, 0); $this->maniaControl->client->query('GetMapList', 300, 0);
$mapList = $this->maniaControl->client->getResponse(); $mapList = $this->maniaControl->client->getResponse();
foreach ($mapList as $map) { foreach ($mapList as $map) {

View File

@ -22,19 +22,19 @@ class Server {
/** /**
* Private properties * Private properties
*/ */
private $mc = null; private $maniaConnect = null;
/** /**
* Construct server * Construct server
*/ */
public function __construct($mc) { public function __construct($maniaConnect) {
$this->mc = $mc; $this->maniaConnect = $maniaConnect;
// Load config // Load config
$this->config = FileUtil::loadConfig('server.xml'); $this->config = FileUtil::loadConfig('server.xml');
// Register for callbacks // Register for callbacks
$this->mc->callbacks->registerCallbackHandler(Callbacks::CB_MC_1_SECOND, $this, 'eachSecond'); $this->maniaConnect->callbacks->registerCallbackHandler(Callbacks::CB_maniaConnect_1_SECOND, $this, 'eachSecond');
} }
/** /**
@ -51,11 +51,11 @@ class Server {
* @return string * @return string
*/ */
public function getDataDirectory() { public function getDataDirectory() {
if (!$this->mc->client->query('GameDataDirectory')) { if (!$this->maniaConnect->client->query('GameDataDirectory')) {
trigger_error("Couldn't get data directory. " . $this->mc->getClientErrorText()); trigger_error("Couldn't get data directory. " . $this->maniaConnect->getClientErrorText());
return null; return null;
} }
return $this->mc->client->getResponse(); return $this->maniaConnect->client->getResponse();
} }
/** /**
@ -86,54 +86,54 @@ class Server {
public function getInfo($detailed = false) { public function getInfo($detailed = false) {
if ($detailed) { if ($detailed) {
$login = $this->getLogin(); $login = $this->getLogin();
if (!$this->mc->client->query('GetDetailedPlayerInfo', $login)) { if (!$this->maniaConnect->client->query('GetDetailedPlayerInfo', $login)) {
trigger_error("Couldn't fetch detailed server player info. " . $this->mc->getClientErrorText()); trigger_error("Couldn't fetch detailed server player info. " . $this->maniaConnect->getClientErrorText());
return null; return null;
} }
} }
else { else {
if (!$this->mc->client->query('GetMainServerPlayerInfo')) { if (!$this->maniaConnect->client->query('GetMainServerPlayerInfo')) {
trigger_error("Couldn't fetch server player info. " . $this->mc->getClientErrorText()); trigger_error("Couldn't fetch server player info. " . $this->maniaConnect->getClientErrorText());
return null; return null;
} }
} }
return $this->mc->client->getResponse(); return $this->maniaConnect->client->getResponse();
} }
/** /**
* Get server options * Get server options
*/ */
public function getOptions() { public function getOptions() {
if (!$this->mc->client->query('GetServerOptions')) { if (!$this->maniaConnect->client->query('GetServerOptions')) {
trigger_error("Couldn't fetch server options. " . $this->mc->getClientErrorText()); trigger_error("Couldn't fetch server options. " . $this->maniaConnect->getClientErrorText());
return null; return null;
} }
return $this->mc->client->getResponse(); return $this->maniaConnect->client->getResponse();
} }
/** /**
* Fetch server name * Fetch server name
*/ */
public function getName() { public function getName() {
if (!$this->mc->client->query('GetServerName')) { if (!$this->maniaConnect->client->query('GetServerName')) {
trigger_error("Couldn't fetch server name. " . $this->mc->getClientErrorText()); trigger_error("Couldn't fetch server name. " . $this->maniaConnect->getClientErrorText());
return null; return null;
} }
return $this->mc->client->getResponse(); return $this->maniaConnect->client->getResponse();
} }
/** /**
* Fetch server version * Fetch server version
*/ */
public function getVersion($forceRefresh = false) { public function getVersion($forceRefresh = false) {
if (isset($this->mc->client->version) && !$forceRefresh) return $this->mc->client->version; if (isset($this->maniaConnect->client->version) && !$forceRefresh) return $this->maniaConnect->client->version;
if (!$this->mc->client->query('GetVersion')) { if (!$this->maniaConnect->client->query('GetVersion')) {
trigger_error("Couldn't fetch server version. " . $this->mc->getClientErrorText()); trigger_error("Couldn't fetch server version. " . $this->maniaConnect->getClientErrorText());
return null; return null;
} }
else { else {
$this->mc->client->version = $this->mc->client->getResponse(); $this->maniaConnect->client->version = $this->maniaConnect->client->getResponse();
return $this->mc->client->version; return $this->maniaConnect->client->version;
} }
} }
@ -141,11 +141,11 @@ class Server {
* Fetch server system info * Fetch server system info
*/ */
public function getSystemInfo($forceRefresh = false, &$client = null) { public function getSystemInfo($forceRefresh = false, &$client = null) {
if (!$this->mc->client && !$client) return null; if (!$this->maniaConnect->client && !$client) return null;
if (!$client) $client = $this->mc->client; if (!$client) $client = $this->maniaConnect->client;
if (isset($client->systemInfo) && !$forceRefresh) return $client->systemInfo; if (isset($client->systemInfo) && !$forceRefresh) return $client->systemInfo;
if (!$client->query('GetSystemInfo')) { if (!$client->query('GetSystemInfo')) {
trigger_error("Couldn't fetch server system info. " . $this->mc->getClientErrorText($client)); trigger_error("Couldn't fetch server system info. " . $this->maniaConnect->getClientErrorText($client));
return null; return null;
} }
else { else {
@ -158,14 +158,14 @@ class Server {
* Fetch network status * Fetch network status
*/ */
public function getNetworkStats($forceRefresh = false) { public function getNetworkStats($forceRefresh = false) {
if (isset($this->mc->client->networkStats) && !$forceRefresh) return $this->mc->client->networkStats; if (isset($this->maniaConnect->client->networkStats) && !$forceRefresh) return $this->maniaConnect->client->networkStats;
if (!$this->mc->client->query('GetNetworkStats')) { if (!$this->maniaConnect->client->query('GetNetworkStats')) {
trigger_error("Couldn't fetch network stats. " . $this->mc->getClientErrorText()); trigger_error("Couldn't fetch network stats. " . $this->maniaConnect->getClientErrorText());
return null; return null;
} }
else { else {
$this->mc->client->networkStats = $this->mc->client->getResponse(); $this->maniaConnect->client->networkStats = $this->maniaConnect->client->getResponse();
return $this->mc->client->networkStats; return $this->maniaConnect->client->networkStats;
} }
} }
@ -181,11 +181,11 @@ class Server {
$gameMode = $parseValue; $gameMode = $parseValue;
} }
else { else {
if (!$this->mc->client->query('GetGameMode')) { if (!$this->maniaConnect->client->query('GetGameMode')) {
trigger_error("Couldn't fetch current game mode. " . $this->mc->getClientErrorText()); trigger_error("Couldn't fetch current game mode. " . $this->maniaConnect->getClientErrorText());
return null; return null;
} }
$gameMode = $this->mc->client->getResponse(); $gameMode = $this->maniaConnect->client->getResponse();
} }
if ($stringValue) { if ($stringValue) {
switch ($gameMode) { switch ($gameMode) {
@ -236,19 +236,19 @@ class Server {
public function getPlayer($login, $detailed = false) { public function getPlayer($login, $detailed = false) {
if (!$login) return null; if (!$login) return null;
$command = ($detailed ? 'GetDetailedPlayerInfo' : 'GetPlayerInfo'); $command = ($detailed ? 'GetDetailedPlayerInfo' : 'GetPlayerInfo');
if (!$this->mc->client->query($command, $login)) { if (!$this->maniaConnect->client->query($command, $login)) {
trigger_error("Couldn't player info for '" . $login . "'. " . $this->mc->getClientErrorText()); trigger_error("Couldn't player info for '" . $login . "'. " . $this->maniaConnect->getClientErrorText());
return null; return null;
} }
return $this->mc->client->getResponse(); return $this->maniaConnect->client->getResponse();
} }
/** /**
* Fetch all players * Fetch all players
*/ */
public function getPlayers(&$client = null, &$purePlayers = null, &$pureSpectators = null) { public function getPlayers(&$client = null, &$purePlayers = null, &$pureSpectators = null) {
if (!$this->mc->client && !$client) return null; if (!$this->maniaConnect->client && !$client) return null;
if (!$client) $client = $this->mc->client; if (!$client) $client = $this->maniaConnect->client;
$fetchLength = 30; $fetchLength = 30;
$offset = 0; $offset = 0;
$players = array(); $players = array();
@ -257,7 +257,7 @@ class Server {
$tries = 0; $tries = 0;
while ($tries < 10) { while ($tries < 10) {
if (!$client->query('GetPlayerList', $fetchLength, $offset)) { if (!$client->query('GetPlayerList', $fetchLength, $offset)) {
trigger_error("Couldn't get player list. " . $this->mc->getClientErrorText($client)); trigger_error("Couldn't get player list. " . $this->maniaConnect->getClientErrorText($client));
$tries++; $tries++;
} }
else { else {
@ -297,11 +297,11 @@ class Server {
*/ */
public function getValidationReplay($login) { public function getValidationReplay($login) {
if (!$login) return null; if (!$login) return null;
if (!$this->mc->client->query('GetValidationReplay', $login)) { if (!$this->maniaConnect->client->query('GetValidationReplay', $login)) {
trigger_error("Couldn't get validation replay of '" . $login . "'. " . $this->mc->getClientErrorText()); trigger_error("Couldn't get validation replay of '" . $login . "'. " . $this->maniaConnect->getClientErrorText());
return null; return null;
} }
return $this->mc->client->getResponse(); return $this->maniaConnect->client->getResponse();
} }
public function getGhostReplay($login) { public function getGhostReplay($login) {
@ -317,8 +317,8 @@ class Server {
$fileName = 'Ghost.' . $login . '.' . $gameMode . '.' . $time . '.' . $map['UId'] . '.Replay.Gbx'; $fileName = 'Ghost.' . $login . '.' . $gameMode . '.' . $time . '.' . $map['UId'] . '.Replay.Gbx';
// Save ghost replay // Save ghost replay
if (!$this->mc->client->query('SaveBestGhostsReplay', $login, self::GHOSTREPLAYDIR . $fileName)) { if (!$this->maniaConnect->client->query('SaveBestGhostsReplay', $login, self::GHOSTREPLAYDIR . $fileName)) {
trigger_error("Couldn't save ghost replay. " . $this->mc->getClientErrorText()); trigger_error("Couldn't save ghost replay. " . $this->maniaConnect->getClientErrorText());
return null; return null;
} }
@ -331,16 +331,17 @@ class Server {
return $ghostReplay; return $ghostReplay;
} }
//TODO: remove getMap
/** /**
* Fetch current map * Fetch current map
*/ */
public function getMap() { public function getMap() {
if (!$this->mc->client) return null; if (!$this->maniaConnect->client) return null;
if (!$this->mc->client->query('GetCurrentMapInfo')) { if (!$this->maniaConnect->client->query('GetCurrentMapInfo')) {
trigger_error("Couldn't fetch map info. " . $this->mc->getClientErrorText()); trigger_error("Couldn't fetch map info. " . $this->maniaConnect->getClientErrorText());
return null; return null;
} }
return $this->mc->client->getResponse(); return $this->maniaConnect->client->getResponse();
} }
/** /**
@ -369,7 +370,7 @@ class Server {
// It took too long to reach the status // It took too long to reach the status
trigger_error( trigger_error(
"Server couldn't reach status " . $statusCode . " after " . $maxWaitTime . " seconds! " . "Server couldn't reach status " . $statusCode . " after " . $maxWaitTime . " seconds! " .
$this->mc->getClientErrorText()); $this->maniaConnect->getClientErrorText());
return false; return false;
} }
} }