improved send message, error, exception to admin
get connected admins method
This commit is contained in:
parent
6ca5decdb4
commit
33b86cdca0
@ -194,22 +194,49 @@ class AuthenticationManager implements CallbackListener {
|
|||||||
return $success;
|
return $success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all connected Players with at least the given Auth Level
|
||||||
|
*
|
||||||
|
* @param int $authLevel
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getConnectedAdmins($authLevel = self::AUTH_LEVEL_MODERATOR) {
|
||||||
|
$players = $this->maniaControl->playerManager->getPlayers();
|
||||||
|
$admins = array();
|
||||||
|
foreach ($players as $player) {
|
||||||
|
if (self::checkRight($player, $authLevel)) {
|
||||||
|
array_push($admins, $player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $admins;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the Player has enough Rights
|
||||||
|
*
|
||||||
|
* @param Player $player
|
||||||
|
* @param int|Setting $neededAuthLevel
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function checkRight(Player $player, $neededAuthLevel) {
|
||||||
|
if ($neededAuthLevel instanceof Setting) {
|
||||||
|
$neededAuthLevel = $neededAuthLevel->value;
|
||||||
|
}
|
||||||
|
return ($player->authLevel >= $neededAuthLevel);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a List of all Admins
|
* Get a List of all Admins
|
||||||
*
|
*
|
||||||
* @param int $authLevel
|
* @param int $authLevel
|
||||||
* @return array null
|
* @return array null
|
||||||
*/
|
*/
|
||||||
public function getAdmins($authLevel = null) {
|
public function getAdmins($authLevel = self::AUTH_LEVEL_MODERATOR) {
|
||||||
|
// TODO: return Player objects
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
if ($authLevel === null) {
|
$query = "SELECT * FROM `" . PlayerManager::TABLE_PLAYERS . "`
|
||||||
$query = "SELECT * FROM `" . PlayerManager::TABLE_PLAYERS . "`
|
WHERE `authLevel` > " . $authLevel . "
|
||||||
WHERE `authLevel` > 0
|
ORDER BY `authLevel` DESC;";
|
||||||
ORDER BY `authLevel` DESC;";
|
|
||||||
} else {
|
|
||||||
$query = "SELECT * FROM `" . PlayerManager::TABLE_PLAYERS . "`
|
|
||||||
WHERE `authLevel` = {$authLevel};";
|
|
||||||
}
|
|
||||||
$result = $mysqli->query($query);
|
$result = $mysqli->query($query);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
trigger_error($mysqli->error);
|
trigger_error($mysqli->error);
|
||||||
@ -219,6 +246,7 @@ class AuthenticationManager implements CallbackListener {
|
|||||||
while ($row = $result->fetch_object()) {
|
while ($row = $result->fetch_object()) {
|
||||||
array_push($admins, $row);
|
array_push($admins, $row);
|
||||||
}
|
}
|
||||||
|
$result->free();
|
||||||
return $admins;
|
return $admins;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,20 +319,6 @@ class AuthenticationManager implements CallbackListener {
|
|||||||
return $this->checkRight($player, $right);
|
return $this->checkRight($player, $right);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check whether the Player has enough Rights
|
|
||||||
*
|
|
||||||
* @param Player $player
|
|
||||||
* @param int|Setting $neededAuthLevel
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function checkRight(Player $player, $neededAuthLevel) {
|
|
||||||
if ($neededAuthLevel instanceof Setting) {
|
|
||||||
$neededAuthLevel = $neededAuthLevel->value;
|
|
||||||
}
|
|
||||||
return ($player->authLevel >= $neededAuthLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define a Minimum Right Level needed for an Action
|
* Define a Minimum Right Level needed for an Action
|
||||||
*
|
*
|
||||||
|
@ -76,7 +76,9 @@ class Chat {
|
|||||||
$this->maniaControl->client->chatSendServerMessage($chatMessage);
|
$this->maniaControl->client->chatSendServerMessage($chatMessage);
|
||||||
} else {
|
} else {
|
||||||
$chatMessage = '$<$z$ff0' . $this->getPrefix($prefix) . $message . '$>';
|
$chatMessage = '$<$z$ff0' . $this->getPrefix($prefix) . $message . '$>';
|
||||||
$login = Player::parseLogin($login);
|
if (!is_array($login)) {
|
||||||
|
$login = Player::parseLogin($login);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->chatSendServerMessage($chatMessage, $login);
|
$this->maniaControl->client->chatSendServerMessage($chatMessage, $login);
|
||||||
} catch (UnknownPlayerException $e) {
|
} catch (UnknownPlayerException $e) {
|
||||||
@ -102,32 +104,27 @@ class Chat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a Error Message to all Connected Admins
|
* Send an Error Message to all Connected Admins
|
||||||
*
|
*
|
||||||
* @param $message
|
* @param string $message
|
||||||
* @param int $minLevel (Constant from AuthenticationManager)
|
* @param int $minLevel
|
||||||
* @param bool $prefix
|
* @param bool $prefix
|
||||||
*/
|
*/
|
||||||
public function sendErrorToAdmins($message, $minLevel = AuthenticationManager::AUTH_LEVEL_MODERATOR, $prefix = true) {
|
public function sendErrorToAdmins($message, $minLevel = AuthenticationManager::AUTH_LEVEL_MODERATOR, $prefix = true) {
|
||||||
$format = $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_FORMAT_ERROR);
|
$format = $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_FORMAT_ERROR);
|
||||||
$this->sendMessageToAdmins($format . $message, $prefix);
|
$this->sendMessageToAdmins($format . $message, $minLevel, $prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a Message to all Connected Admins
|
* Sends a Message to all Connected Admins
|
||||||
*
|
*
|
||||||
* @param $message
|
* @param string $message
|
||||||
* @param int $minLevel (Constant from AuthenticationManager)
|
* @param int $minLevel
|
||||||
* @param bool $prefix
|
* @param bool|string $prefix
|
||||||
*/
|
*/
|
||||||
public function sendMessageToAdmins($message, $minLevel = AuthenticationManager::AUTH_LEVEL_MODERATOR, $prefix = true) {
|
public function sendMessageToAdmins($message, $minLevel = AuthenticationManager::AUTH_LEVEL_MODERATOR, $prefix = true) {
|
||||||
//TODO specifiy in player or adminmanager a getAdmins() with minlevel function
|
$admins = $this->maniaControl->authenticationManager->getConnectedAdmins($minLevel);
|
||||||
foreach ($this->maniaControl->playerManager->getPlayers() as $player) {
|
$this->sendChat($message, $admins, $prefix);
|
||||||
/** @var Player $player */
|
|
||||||
if ($this->maniaControl->authenticationManager->checkRight($player, $minLevel)) {
|
|
||||||
$this->sendChat($message, $player->login, $prefix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -135,7 +132,7 @@ class Chat {
|
|||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param string $login
|
* @param string $login
|
||||||
* @param string|bool $prefix
|
* @param bool|string $prefix
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function sendSuccess($message, $login = null, $prefix = true) {
|
public function sendSuccess($message, $login = null, $prefix = true) {
|
||||||
@ -168,6 +165,19 @@ class Chat {
|
|||||||
return $this->sendChat($format . $message, $login, $prefix);
|
return $this->sendChat($format . $message, $login, $prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a Exception Message to all Connected Admins
|
||||||
|
*
|
||||||
|
* @param \Exception $exception
|
||||||
|
* @param int $minLevel
|
||||||
|
* @param bool|string $prefix
|
||||||
|
*/
|
||||||
|
public function sendExceptionToAdmins(\Exception $exception, $minLevel = AuthenticationManager::AUTH_LEVEL_MODERATOR, $prefix = true) {
|
||||||
|
$format = $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_FORMAT_ERROR);
|
||||||
|
$message = $format . "Exception: '{$exception->getMessage()}' ({$exception->getCode()})";
|
||||||
|
$this->sendMessageToAdmins($message, $minLevel, $prefix);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send an usage info message to the given login
|
* Send an usage info message to the given login
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user