From 1487fe559d47d934d4c28792de4af3639310376e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 11 Mar 2013 17:17:58 +0100 Subject: [PATCH] Bugfixes in Command Handling (MuteCommand) --- file/lib/data/message/MessageAction.class.php | 9 +++++--- .../system/command/CommandHandler.class.php | 21 +++++++++++++++++-- .../command/commands/MuteCommand.class.php | 2 +- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/file/lib/data/message/MessageAction.class.php b/file/lib/data/message/MessageAction.class.php index 495bc25..c59f675 100644 --- a/file/lib/data/message/MessageAction.class.php +++ b/file/lib/data/message/MessageAction.class.php @@ -41,7 +41,7 @@ public function prune() { } /** - * + * Validates message sending. */ public function validateSend() { // read parameters @@ -77,10 +77,10 @@ public function validateSend() { if (!isset($cache[$this->parameters['userData']['roomID']])) throw new \wcf\system\exception\IllegalLinkException(); $this->parameters['room'] = $cache[$this->parameters['userData']['roomID']]; - if (!$this->parameters['room']->canEnter() || !$this->parameters['room']->canWrite()) throw new PermissionDeniedException(); + if (!$this->parameters['room']->canEnter() || !$this->parameters['room']->canWrite()) throw new \wcf\system\exception\PermissionDeniedException(); // handle commands - $commandHandler = new \chat\system\command\CommandHandler($this->parameters['text']); + $commandHandler = new \chat\system\command\CommandHandler($this->parameters['text'], $this->parameters['room']); if ($commandHandler->isCommand()) { try { $command = $commandHandler->loadCommand(); @@ -105,6 +105,9 @@ public function validateSend() { } } + /** + * Creates sent message. + */ public function send() { \chat\util\ChatUtil::writeUserData(array('away' => null)); diff --git a/file/lib/system/command/CommandHandler.class.php b/file/lib/system/command/CommandHandler.class.php index baa92bc..d8a60c6 100644 --- a/file/lib/system/command/CommandHandler.class.php +++ b/file/lib/system/command/CommandHandler.class.php @@ -24,13 +24,21 @@ final class CommandHandler { */ private $text = ''; + /** + * current room + * @var \chat\data\room\Room + */ + private $room = null; + /** * Initialises the CommandHandler * - * @param string $text + * @param string $text + * @param \chat\data\room\Room $room */ - public function __construct($text) { + public function __construct($text, \chat\data\room\Room $room = null) { $this->text = $text; + $this->room = $room; } /** @@ -51,6 +59,15 @@ public function getText() { return $this->text; } + /** + * Returns the current room. + * + * @return \chat\data\room\Room + */ + public function getRoom() { + return $this->room; + } + /** * Returns the parameter-string. * diff --git a/file/lib/system/command/commands/MuteCommand.class.php b/file/lib/system/command/commands/MuteCommand.class.php index 2c767f5..bef3fb8 100644 --- a/file/lib/system/command/commands/MuteCommand.class.php +++ b/file/lib/system/command/commands/MuteCommand.class.php @@ -76,7 +76,7 @@ public function executeAction() { public function checkPermission() { parent::checkPermission(); - $this->room = \wcf\system\request\RequestHandler::getInstance()->getActiveRequest()->getRequestObject()->request->room; + $this->room = $this->commandHandler->getRoom(); $ph = new \chat\system\permission\PermissionHandler(); if (!$ph->getPermission($this->room, 'mod.can'.str_replace(array('chat\system\command\commands\\', 'Command'), '', get_class($this)))) throw new \wcf\system\exception\PermissionDeniedException(); }