exception chat message method

This commit is contained in:
Steffen Schröder 2014-04-14 13:17:00 +02:00
parent 8a6726dad1
commit 17b7e4249f

View File

@ -3,6 +3,7 @@
namespace ManiaControl; namespace ManiaControl;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception; use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
use ManiaControl\Players\Player;
/** /**
* Chat Utility Class * Chat Utility Class
@ -48,7 +49,7 @@ class Chat {
* @param string|bool $prefix * @param string|bool $prefix
* @return string * @return string
*/ */
private function getPrefix($prefix) { private function getPrefix($prefix) {
if (is_string($prefix)) { if (is_string($prefix)) {
return $prefix; return $prefix;
} }
@ -57,7 +58,7 @@ class Chat {
} }
return ''; return '';
} }
/** /**
* Send a chat message to the given login * Send a chat message to the given login
* *
@ -71,11 +72,14 @@ class Chat {
return false; return false;
} }
$chatMessage = '$z$<' . $this->getPrefix($prefix) . $message . '$>$z'; $chatMessage = '$z$<' . $this->getPrefix($prefix) . $message . '$>$z';
if ($login === null) { if (!$login) {
$this->maniaControl->client->chatSendServerMessage($chatMessage); $this->maniaControl->client->chatSendServerMessage($chatMessage);
} else { } else {
if ($login instanceof Player) {
$login = $login->login;
}
try{ try{
$this->maniaControl->client->chatSendServerMessage($chatMessage, $login); $this->maniaControl->client->chatSendServerMessage($chatMessage, $login);
} catch(Exception $e){ } catch(Exception $e){
if($e->getMessage() != "Login unknown."){ if($e->getMessage() != "Login unknown."){
throw $e; throw $e;
@ -112,7 +116,7 @@ class Chat {
} }
/** /**
* Send an error message to the given login * Send an Error Message to the Chat
* *
* @param string $message * @param string $message
* @param string $login * @param string $login
@ -123,6 +127,18 @@ class Chat {
$format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_ERROR); $format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_ERROR);
return $this->sendChat($format . $message, $login); return $this->sendChat($format . $message, $login);
} }
/**
* Send the Exception Information to the Chat
*
* @param Exception $exception
* @param string $login
* @return bool
*/
public function sendException(\Exception $exception, $login = null) {
$message = "Exception occured: '{$exception->getMessage()}' ({$exception->getCode()})";
$this->sendError($message, $login);
}
/** /**
* Send an usage info message to the given login * Send an usage info message to the given login