TrackManiaControl/application/core/chat.php

87 lines
2.0 KiB
PHP
Raw Normal View History

2013-11-09 17:24:03 +01:00
<?php
namespace ManiaControl;
/**
* Class for chat methods
*
* @author steeffeen
*/
class Chat {
/**
* Private properties
*/
2013-11-09 19:26:57 +01:00
private $mc = null;
2013-11-09 17:24:03 +01:00
private $config = null;
private $prefix = 'ManiaControl>';
/**
* Construct ManiaControl chat
*/
2013-11-09 19:26:57 +01:00
public function __construct($mc) {
$this->mc = $mc;
2013-11-09 17:24:03 +01:00
// Load config
$this->config = Tools::loadConfig('chat.xml');
2013-11-09 17:24:03 +01:00
}
/**
* Send a chat message to the given login
*
* @param string $login
* @param string $message
* @param bool $prefix
*/
public function sendChat($message, $login = null, $prefix = false) {
2013-11-09 19:26:57 +01:00
if (!$this->mc->client) return false;
2013-11-09 17:24:03 +01:00
if ($login === null) {
2013-11-09 21:35:43 +01:00
return $this->mc->client->query('ChatSendServerMessage', '$z' . ($prefix ? $this->prefix : '') . $message . '$z');
2013-11-09 17:24:03 +01:00
}
else {
return $this->mc->client->query('ChatSendServerMessageToLogin', '$z' . ($prefix ? $this->prefix : '') . $message . '$z',
$login);
2013-11-09 17:24:03 +01:00
}
}
/**
* Send an information message to the given login
*
* @param string $login
* @param string $message
* @param bool $prefix
*/
public function sendInformation($message, $login = null, $prefix = false) {
$format = (string) $this->config->messages->information;
return $this->sendChat($format . $message, $login);
}
/**
* Send a success message to the given login
*
* @param string $message
* @param string $login
* @param bool $prefix
*/
public function sendSuccess($message, $login = null, $prefix = false) {
$format = (string) $this->config->messages->success;
return $this->sendChat($format . $message, $login);
}
/**
* Send an error message to the given login
*
* @param string $login
* @param string $message
* @param bool $prefix
*/
public function sendError($message, $login = null, $prefix = false) {
$format = (string) $this->config->messages->error;
return $this->sendChat($format . $message, $login);
}
}
?>