improved chat message prefixing

This commit is contained in:
Steffen Schröder 2014-08-11 19:51:46 +02:00
parent 08a4710c1d
commit 44cc71c328

View File

@ -71,42 +71,42 @@ class Chat {
return false; return false;
} }
if (!$login) { $prefix = $this->buildPrefix($prefix, $login);
if ($prefix === true) {
//use double prefix
$prefix = $this->getPrefix($prefix);
$chatMessage = '$<$z$ff0' . str_replace(' ', '', $prefix) . $prefix . $message . '$>';
} else {
//don't use double Prefix, when a custom Prefix is set
$prefix = $this->getPrefix($prefix);
$chatMessage = '$<$z$ff0' . $prefix . $message . '$>'; $chatMessage = '$<$z$ff0' . $prefix . $message . '$>';
}
$this->maniaControl->getClient()->chatSendServerMessage($chatMessage); if ($login) {
} else {
$chatMessage = '$<$z$ff0' . $this->getPrefix($prefix) . $message . '$>';
if (!is_array($login)) { if (!is_array($login)) {
$login = Player::parseLogin($login); $login = Player::parseLogin($login);
} }
try { try {
$this->maniaControl->getClient()->chatSendServerMessage($chatMessage, $login); return $this->maniaControl->getClient()->chatSendServerMessage($chatMessage, $login);
} catch (UnknownPlayerException $e) { } catch (UnknownPlayerException $e) {
return false;
} }
} }
return true;
return $this->maniaControl->getClient()->chatSendServerMessage($chatMessage);
} }
/** /**
* Get prefix * Build the chat message prefix
* *
* @param string|bool $prefix * @param string|bool $prefixParam
* @param string|array $login
* @return string * @return string
*/ */
private function getPrefix($prefix) { private function buildPrefix($prefixParam, $login = null) {
if (is_string($prefix)) { if (is_string($prefixParam)) {
return $prefix; return $prefixParam;
} }
if ($prefix === true) { if ($prefixParam === true) {
return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PREFIX); $prefix = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PREFIX);
if ($login) {
// Private - Doubled default prefix
$prefix .= $prefix;
// TODO: validate whether to use specific private & public prefixes instead of just doubling a default one
}
return $prefix;
} }
return ''; return '';
} }