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
@ -71,9 +72,12 @@ 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){
@ -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
@ -124,6 +128,18 @@ class Chat {
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
* *