From 17b7e4249ffb46ac983c4144604b75f6e8eeb922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Mon, 14 Apr 2014 13:17:00 +0200 Subject: [PATCH] exception chat message method --- application/core/Chat.php | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/application/core/Chat.php b/application/core/Chat.php index c5b922fc..39f3bf48 100644 --- a/application/core/Chat.php +++ b/application/core/Chat.php @@ -3,6 +3,7 @@ namespace ManiaControl; use Maniaplanet\DedicatedServer\Xmlrpc\Exception; +use ManiaControl\Players\Player; /** * Chat Utility Class @@ -48,7 +49,7 @@ class Chat { * @param string|bool $prefix * @return string */ - private function getPrefix($prefix) { + private function getPrefix($prefix) { if (is_string($prefix)) { return $prefix; } @@ -57,7 +58,7 @@ class Chat { } return ''; } - + /** * Send a chat message to the given login * @@ -71,11 +72,14 @@ class Chat { return false; } $chatMessage = '$z$<' . $this->getPrefix($prefix) . $message . '$>$z'; - if ($login === null) { + if (!$login) { $this->maniaControl->client->chatSendServerMessage($chatMessage); } else { + if ($login instanceof Player) { + $login = $login->login; + } try{ - $this->maniaControl->client->chatSendServerMessage($chatMessage, $login); + $this->maniaControl->client->chatSendServerMessage($chatMessage, $login); } catch(Exception $e){ if($e->getMessage() != "Login unknown."){ 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 $login @@ -123,6 +127,18 @@ class Chat { $format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_ERROR); 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