try catches server.php

This commit is contained in:
kremsy 2014-01-18 21:46:42 +01:00 committed by Steffen Schröder
parent 3407fcaeee
commit 0f8a2d91ec

View File

@ -7,6 +7,7 @@ use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Structures\SystemInfos; use Maniaplanet\DedicatedServer\Structures\SystemInfos;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
require_once __DIR__ . '/ServerCommands.php'; require_once __DIR__ . '/ServerCommands.php';
@ -135,8 +136,10 @@ class Server implements CallbackListener {
*/ */
public function getDataDirectory() { public function getDataDirectory() {
if($this->dataDirectory == '') { if($this->dataDirectory == '') {
if(!$this->dataDirectory = $this->maniaControl->client->gameDataDirectory()) { try {
trigger_error("Couldn't get data directory. " . $this->maniaControl->getClientErrorText()); $this->dataDirectory = $this->maniaControl->client->gameDataDirectory();
} catch(Exception $e) {
trigger_error("Couldn't get data directory. " . $e->getMessage());
return null; return null;
} }
} }
@ -178,15 +181,18 @@ class Server implements CallbackListener {
public function getInfo($detailed = false) { public function getInfo($detailed = false) {
if($detailed) { if($detailed) {
$login = $this->login; $login = $this->login;
if(!$info = $this->maniaControl->client->getDetailedPlayerInfo($login)) { try {
trigger_error("Couldn't fetch detailed server info. " . $this->maniaControl->getClientErrorText()); $info = $this->maniaControl->client->getDetailedPlayerInfo($login);
} catch(Exception $e) {
trigger_error("Couldn't fetch detailed server info. " . $e->getMessage());
return null; return null;
} }
return $info; return $info;
} }
try {
if(!$info = $this->maniaControl->client->getMainServerPlayerInfo()) { $info = $this->maniaControl->client->getMainServerPlayerInfo();
trigger_error("Couldn't fetch server info. " . $this->maniaControl->getClientErrorText()); } catch(Exception $e) {
trigger_error("Couldn't fetch server info. " . $e->getMessage());
return null; return null;
} }
return $info; return $info;
@ -198,10 +204,13 @@ class Server implements CallbackListener {
* @return array * @return array
*/ */
public function getOptions() { public function getOptions() {
if(!$options = $this->maniaControl->client->getServerOptions()) { try {
trigger_error("Couldn't fetch server options. " . $this->maniaControl->getClientErrorText()); $options = $this->maniaControl->client->getServerOptions();
} catch(Exception $e) {
trigger_error("Couldn't fetch server options. " . $e->getMessage());
return null; return null;
} }
return $options; return $options;
} }
@ -211,21 +220,26 @@ class Server implements CallbackListener {
* @return string * @return string
*/ */
public function getName() { public function getName() {
if(!$name = $this->maniaControl->client->getServerName()) { try {
trigger_error("Couldn't fetch server name. " . $this->maniaControl->getClientErrorText()); $name = $this->maniaControl->client->getServerName();
} catch(Exception $e) {
trigger_error("Couldn't fetch server name. " . $e->getMessage());
return null; return null;
} }
return $name; return $name;
} }
/** /**
* Fetch Server Version * Fetch Server Version
* *
* @return string * @return string
*/ */
public function getVersion() { public function getVersion() {
if(!$version = $this->maniaControl->client->getVersion()) { try {
trigger_error("Couldn't fetch server version. " . $this->maniaControl->getClientErrorText()); $version = $this->maniaControl->client->getVersion();
} catch(Exception $e) {
trigger_error("Couldn't fetch server version. " . $e->getMessage());
return null; return null;
} }
return $version; return $version;
@ -237,10 +251,13 @@ class Server implements CallbackListener {
* @return SystemInfos * @return SystemInfos
*/ */
public function getSystemInfo() { public function getSystemInfo() {
if(!$systemInfo = $this->maniaControl->client->getSystemInfo()) { try {
trigger_error("Couldn't fetch server system info. " . $this->maniaControl->getClientErrorText()); $systemInfo = $this->maniaControl->client->getSystemInfo();
} catch(Exception $e) {
trigger_error("Couldn't fetch server system info. " . $e->getMessage());
return null; return null;
} }
return $systemInfo; return $systemInfo;
} }
@ -255,12 +272,12 @@ class Server implements CallbackListener {
if(is_int($parseValue)) { if(is_int($parseValue)) {
$gameMode = $parseValue; $gameMode = $parseValue;
} else { } else {
$gameMode = $this->maniaControl->client->getGameMode(); try {
$gameMode = $this->maniaControl->client->getGameMode();
/*if(!$gameMode = $this->maniaControl->client->getGameMode()){ } catch(Exception $e) {
trigger_error("Couldn't fetch current game mode. " . $this->maniaControl->getClientErrorText()); trigger_error("Couldn't fetch current game mode. " . $this->maniaControl->getClientErrorText());
return null; return null;
}*/ }
} }
if($stringValue) { if($stringValue) {
switch($gameMode) { switch($gameMode) {
@ -292,7 +309,9 @@ class Server implements CallbackListener {
* @return string * @return string
*/ */
public function getValidationReplay(Player $player) { public function getValidationReplay(Player $player) {
if(!$replay = $this->maniaControl->client->getValidationReplay($player->login)) { try {
$replay = $this->maniaControl->client->getValidationReplay($player->login);
} catch(Exception $e) {
trigger_error("Couldn't get validation replay of '{$player->login}'. " . $this->maniaControl->getClientErrorText()); trigger_error("Couldn't get validation replay of '{$player->login}'. " . $this->maniaControl->getClientErrorText());
return null; return null;
} }
@ -312,14 +331,16 @@ class Server implements CallbackListener {
} }
// Build file name // Build file name
$map = $this->getMap(); //TODO does that workm, where is the method?= $map = $this->maniaControl->mapManager->getCurrentMap();
$gameMode = $this->getGameMode(); $gameMode = $this->getGameMode();
$time = time(); $time = time();
$fileName = "GhostReplays/Ghost.{$player->login}.{$gameMode}.{$time}.{$map['UId']}.Replay.Gbx"; $fileName = "GhostReplays/Ghost.{$player->login}.{$gameMode}.{$time}.{$map->uid}.Replay.Gbx";
// Save ghost replay // Save ghost replay
if(!$this->maniaControl->client->saveBestGhostsReplay($player->login, $fileName)) { try {
trigger_error("Couldn't save ghost replay. " . $this->maniaControl->getClientErrorText()); $this->maniaControl->client->saveBestGhostsReplay($player->login, $fileName);
} catch(Exception $e) {
trigger_error("Couldn't save ghost replay. " . $e->getMessage());
return null; return null;
} }