- improved chat utility
- removed chat config file
This commit is contained in:
		@@ -1,12 +0,0 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<!-- Configure how ManiaControl sends chat message -->
 | 
			
		||||
<chat-config>
 | 
			
		||||
 | 
			
		||||
	<!-- Set which codes should be used to compose chat messages -->
 | 
			
		||||
	<messages>
 | 
			
		||||
		<information>$fff</information>
 | 
			
		||||
		<success>$0f0</success>
 | 
			
		||||
		<error>$f00</error>
 | 
			
		||||
	</messages>
 | 
			
		||||
 | 
			
		||||
</chat-config>
 | 
			
		||||
@@ -3,58 +3,72 @@
 | 
			
		||||
namespace ManiaControl;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Class for chat methods
 | 
			
		||||
 * Chat utility class
 | 
			
		||||
 *
 | 
			
		||||
 * @author steeffeen
 | 
			
		||||
 * @author steeffeen & kremsy
 | 
			
		||||
 */
 | 
			
		||||
class Chat {
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * Private properties
 | 
			
		||||
	 */
 | 
			
		||||
	private $mc = null;
 | 
			
		||||
 | 
			
		||||
	private $config = null;
 | 
			
		||||
 | 
			
		||||
	private $prefix = 'ManiaControl>';
 | 
			
		||||
	private $maniaControl = null;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Construct ManiaControl chat
 | 
			
		||||
	 * Construct chat utility
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param ManiaControl $maniaControl        	
 | 
			
		||||
	 */
 | 
			
		||||
	public function __construct($mc) {
 | 
			
		||||
		$this->mc = $mc;
 | 
			
		||||
		
 | 
			
		||||
		// Load config
 | 
			
		||||
		$this->config = Tools::loadConfig('chat.xml');
 | 
			
		||||
	public function __construct(ManiaControl $maniaControl) {
 | 
			
		||||
		$this->maniaControl = $maniaControl;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Get prefix
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param string|bool $prefix        	
 | 
			
		||||
	 * @return string
 | 
			
		||||
	 */
 | 
			
		||||
	private function getPrefix($prefix) {
 | 
			
		||||
		if (is_string($prefix)) {
 | 
			
		||||
			return $prefix;
 | 
			
		||||
		}
 | 
			
		||||
		if ($prefix === true) {
 | 
			
		||||
			return $this->maniaControl->settingManager->getSetting($this, 'DefaultPrefix', 'ManiaControl>');
 | 
			
		||||
		}
 | 
			
		||||
		return '';
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Send a chat message to the given login
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param string $login        	
 | 
			
		||||
	 * @param string $message        	
 | 
			
		||||
	 * @param bool $prefix        	
 | 
			
		||||
	 * @param string $login        	
 | 
			
		||||
	 * @param string|bool $prefix        	
 | 
			
		||||
	 * @return bool
 | 
			
		||||
	 */
 | 
			
		||||
	public function sendChat($message, $login = null, $prefix = false) {
 | 
			
		||||
		if (!$this->mc->client) return false;
 | 
			
		||||
		if (!$this->maniaControl->client) {
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		$client = $this->maniaControl->client;
 | 
			
		||||
		$chatMessage = '$z' . $this->getPrefix($prefix) . $message . '$z';
 | 
			
		||||
		if ($login === null) {
 | 
			
		||||
			return $this->mc->client->query('ChatSendServerMessage', '$z' . ($prefix ? $this->prefix : '') . $message . '$z');
 | 
			
		||||
		}
 | 
			
		||||
		else {
 | 
			
		||||
			return $this->mc->client->query('ChatSendServerMessageToLogin', '$z' . ($prefix ? $this->prefix : '') . $message . '$z', 
 | 
			
		||||
					$login);
 | 
			
		||||
			return $client->query('ChatSendServerMessage', $chatMessage);
 | 
			
		||||
		}
 | 
			
		||||
		return $client->query('ChatSendServerMessageToLogin', $chatMessage, $login);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Send an information message to the given login
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param string $login        	
 | 
			
		||||
	 * @param string $message        	
 | 
			
		||||
	 * @param bool $prefix        	
 | 
			
		||||
	 * @param string $login        	
 | 
			
		||||
	 * @param string|bool $prefix        	
 | 
			
		||||
	 * @return bool
 | 
			
		||||
	 */
 | 
			
		||||
	public function sendInformation($message, $login = null, $prefix = false) {
 | 
			
		||||
		$format = (string) $this->config->messages->information;
 | 
			
		||||
		$format = $this->maniaControl->settingManager->getSetting($this, 'ErrorFormat', '$fff');
 | 
			
		||||
		return $this->sendChat($format . $message, $login);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -63,22 +77,24 @@ class Chat {
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param string $message        	
 | 
			
		||||
	 * @param string $login        	
 | 
			
		||||
	 * @param bool $prefix        	
 | 
			
		||||
	 * @param string|bool $prefix        	
 | 
			
		||||
	 * @return bool
 | 
			
		||||
	 */
 | 
			
		||||
	public function sendSuccess($message, $login = null, $prefix = false) {
 | 
			
		||||
		$format = (string) $this->config->messages->success;
 | 
			
		||||
		$format = $this->maniaControl->settingManager->getSetting($this, 'ErrorFormat', '$0f0');
 | 
			
		||||
		return $this->sendChat($format . $message, $login);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Send an error message to the given login
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param string $login        	
 | 
			
		||||
	 * @param string $message        	
 | 
			
		||||
	 * @param bool $prefix        	
 | 
			
		||||
	 * @param string $login        	
 | 
			
		||||
	 * @param string|bool $prefix        	
 | 
			
		||||
	 * @return bool
 | 
			
		||||
	 */
 | 
			
		||||
	public function sendError($message, $login = null, $prefix = false) {
 | 
			
		||||
		$format = (string) $this->config->messages->error;
 | 
			
		||||
		$format = $this->maniaControl->settingManager->getSetting($this, 'ErrorFormat', '$f00');
 | 
			
		||||
		return $this->sendChat($format . $message, $login);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user