2013-11-09 17:24:03 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl;
|
|
|
|
|
|
|
|
/**
|
2013-11-10 13:46:44 +01:00
|
|
|
* Chat utility class
|
2013-11-09 17:24:03 +01:00
|
|
|
*
|
2013-11-10 13:46:44 +01:00
|
|
|
* @author steeffeen & kremsy
|
2013-11-09 17:24:03 +01:00
|
|
|
*/
|
|
|
|
class Chat {
|
2013-11-10 13:46:44 +01:00
|
|
|
|
2013-11-09 17:24:03 +01:00
|
|
|
/**
|
|
|
|
* Private properties
|
|
|
|
*/
|
2013-11-10 13:46:44 +01:00
|
|
|
private $maniaControl = null;
|
2013-11-09 17:24:03 +01:00
|
|
|
|
2013-11-10 13:46:44 +01:00
|
|
|
/**
|
|
|
|
* Construct chat utility
|
|
|
|
*
|
|
|
|
* @param ManiaControl $maniaControl
|
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
|
|
|
}
|
2013-11-09 17:24:03 +01:00
|
|
|
|
|
|
|
/**
|
2013-11-10 13:46:44 +01:00
|
|
|
* Get prefix
|
|
|
|
*
|
|
|
|
* @param string|bool $prefix
|
|
|
|
* @return string
|
2013-11-09 17:24:03 +01:00
|
|
|
*/
|
2013-11-10 13:46:44 +01:00
|
|
|
private function getPrefix($prefix) {
|
|
|
|
if (is_string($prefix)) {
|
|
|
|
return $prefix;
|
|
|
|
}
|
|
|
|
if ($prefix === true) {
|
|
|
|
return $this->maniaControl->settingManager->getSetting($this, 'DefaultPrefix', 'ManiaControl>');
|
|
|
|
}
|
|
|
|
return '';
|
2013-11-09 17:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a chat message to the given login
|
|
|
|
*
|
|
|
|
* @param string $message
|
2013-11-10 13:46:44 +01:00
|
|
|
* @param string $login
|
|
|
|
* @param string|bool $prefix
|
|
|
|
* @return bool
|
2013-11-09 17:24:03 +01:00
|
|
|
*/
|
|
|
|
public function sendChat($message, $login = null, $prefix = false) {
|
2013-11-10 13:46:44 +01:00
|
|
|
if (!$this->maniaControl->client) {
|
|
|
|
return false;
|
2013-11-09 17:24:03 +01:00
|
|
|
}
|
2013-11-10 13:46:44 +01:00
|
|
|
$client = $this->maniaControl->client;
|
|
|
|
$chatMessage = '$z' . $this->getPrefix($prefix) . $message . '$z';
|
|
|
|
if ($login === null) {
|
|
|
|
return $client->query('ChatSendServerMessage', $chatMessage);
|
2013-11-09 17:24:03 +01:00
|
|
|
}
|
2013-11-10 13:46:44 +01:00
|
|
|
return $client->query('ChatSendServerMessageToLogin', $chatMessage, $login);
|
2013-11-09 17:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send an information message to the given login
|
|
|
|
*
|
|
|
|
* @param string $message
|
2013-11-10 13:46:44 +01:00
|
|
|
* @param string $login
|
|
|
|
* @param string|bool $prefix
|
|
|
|
* @return bool
|
2013-11-09 17:24:03 +01:00
|
|
|
*/
|
|
|
|
public function sendInformation($message, $login = null, $prefix = false) {
|
2013-11-10 13:46:44 +01:00
|
|
|
$format = $this->maniaControl->settingManager->getSetting($this, 'ErrorFormat', '$fff');
|
2013-11-09 17:24:03 +01:00
|
|
|
return $this->sendChat($format . $message, $login);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a success message to the given login
|
|
|
|
*
|
|
|
|
* @param string $message
|
|
|
|
* @param string $login
|
2013-11-10 13:46:44 +01:00
|
|
|
* @param string|bool $prefix
|
|
|
|
* @return bool
|
2013-11-09 17:24:03 +01:00
|
|
|
*/
|
|
|
|
public function sendSuccess($message, $login = null, $prefix = false) {
|
2013-11-10 13:46:44 +01:00
|
|
|
$format = $this->maniaControl->settingManager->getSetting($this, 'ErrorFormat', '$0f0');
|
2013-11-09 17:24:03 +01:00
|
|
|
return $this->sendChat($format . $message, $login);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send an error message to the given login
|
|
|
|
*
|
|
|
|
* @param string $message
|
2013-11-10 13:46:44 +01:00
|
|
|
* @param string $login
|
|
|
|
* @param string|bool $prefix
|
|
|
|
* @return bool
|
2013-11-09 17:24:03 +01:00
|
|
|
*/
|
|
|
|
public function sendError($message, $login = null, $prefix = false) {
|
2013-11-10 13:46:44 +01:00
|
|
|
$format = $this->maniaControl->settingManager->getSetting($this, 'ErrorFormat', '$f00');
|
2013-11-09 17:24:03 +01:00
|
|
|
return $this->sendChat($format . $message, $login);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|