- changed "xsuperadmin" to "masteradmin"

- added tm2 server config data
- various server admin commands
- minor other improvements
This commit is contained in:
Steffen Schröder 2013-11-24 23:55:54 +01:00
parent a9b1842a6f
commit 33001ef573
6 changed files with 172 additions and 41 deletions

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Configure authentication for players -->
<!-- Configure Server Administrators -->
<authentication-config>
<!-- SuperAdmins that can't be removed ingame -->
<xsuperadmins>
<!-- MasterAdmins that can't be removed ingame -->
<masteradmins>
<login>steeffeen</login>
<login>kremsy</login>
</xsuperadmins>
</masteradmins>
<!-- You can add other admins and operators ingame -->

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Configure the mysql database used by ManiaControl -->
<!-- Configure the MySQL Database used by ManiaControl -->
<database-config>
<!-- MySQL Server -->

View File

@ -21,7 +21,7 @@ class AuthenticationManager implements CommandListener {
const AUTH_LEVEL_OPERATOR = 1;
const AUTH_LEVEL_ADMIN = 2;
const AUTH_LEVEL_SUPERADMIN = 3;
const AUTH_LEVEL_XSUPERADMIN = 4;
const AUTH_LEVEL_MASTERADMIN = 4;
/**
* Private properties
@ -49,7 +49,7 @@ class AuthenticationManager implements CommandListener {
$config = FileUtil::loadConfig('authentication.xml');
$mysqli = $this->maniaControl->database->mysqli;
// Remove all XSuperadmins
// Remove all MasterAdmins
$adminQuery = "UPDATE `" . PlayerManager::TABLE_PLAYERS . "`
SET `authLevel` = ?
WHERE `authLevel` = ?;";
@ -59,7 +59,7 @@ class AuthenticationManager implements CommandListener {
return false;
}
$adminLevel = self::AUTH_LEVEL_SUPERADMIN;
$xAdminLevel = self::AUTH_LEVEL_XSUPERADMIN;
$xAdminLevel = self::AUTH_LEVEL_MASTERADMIN;
$adminStatement->bind_param('ii', $adminLevel, $xAdminLevel);
$adminStatement->execute();
if ($adminStatement->error) {
@ -67,8 +67,8 @@ class AuthenticationManager implements CommandListener {
}
$adminStatement->close();
// Set XSuperAdmins
$xAdmins = $config->xsuperadmins->xpath('login');
// Set MasterAdmins
$xAdmins = $config->masteradmins->xpath('login');
$adminQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` (
`login`,
`authLevel`
@ -103,7 +103,7 @@ class AuthenticationManager implements CommandListener {
* @return bool
*/
public function grantAuthLevel(Player $player, $authLevel) {
if (!$player || !is_int($authLevel) || $authLevel  >= self::AUTH_LEVEL_XSUPERADMIN) {
if (!$player || !is_int($authLevel) || $authLevel  >= self::AUTH_LEVEL_MASTERADMIN) {
return false;
}
$mysqli = $this->maniaControl->database->mysqli;

View File

@ -4,9 +4,11 @@ namespace ManiaControl;
use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Commands\CommandListener;
use ManiaControl\Commands\CommandManager;
use ManiaControl\Manialinks\ManialinkIdHandler;
use ManiaControl\Maps\MapManager;
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\PluginManager;
use ManiaControl\Server\Server;
@ -42,7 +44,7 @@ else {
*
* @author steeffeen & kremsy
*/
class ManiaControl {
class ManiaControl implements CommandListener {
/**
* Constants
*/
@ -86,6 +88,8 @@ class ManiaControl {
$this->playerManager = new PlayerManager($this);
$this->mapManager = new MapManager($this);
$this->pluginManager = new PluginManager($this);
$this->commandManager->registerCommandListener('version', $this, 'command_Version');
}
/**
@ -101,6 +105,17 @@ class ManiaControl {
return $this->client->getErrorMessage() . ' (' . $this->client->getErrorCode() . ')';
}
/**
* Send ManiaControl version
*
* @param array $chat
* @return bool
*/
public function command_Version(array $chat, Player $player) {
$message = 'This server is using ManiaControl v' . ManiaControl::VERSION . '!';
return $this->chat->sendInformation($message, $player->login);
}
/**
* Quit ManiaControl and log the given message
*
@ -211,7 +226,7 @@ class ManiaControl {
}
// Wait for server to be ready
if (!$this->server->waitForStatus($this->client, 4)) {
if (!$this->server->waitForStatus(4)) {
trigger_error("Server couldn't get ready!", E_USER_ERROR);
}

View File

@ -32,12 +32,15 @@ class ServerCommands implements CallbackListener, CommandListener {
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_5_SECOND, $this, 'each5Seconds');
$this->maniaControl->commandManager->registerCommandListener('version', $this, 'command_Version');
$this->maniaControl->commandManager->registerCommandListener('/setservername', $this, 'command_SetServerName');
$this->maniaControl->commandManager->registerCommandListener('/kick', $this, 'command_Kick');
$this->maniaControl->commandManager->registerCommandListener('/systeminfo', $this, 'command_SystemInfo');
$this->maniaControl->commandManager->registerCommandListener('/setpwd', $this, 'command_SetPwd');
$this->maniaControl->commandManager->registerCommandListener('/setservername', $this, 'command_SetServerName');
$this->maniaControl->commandManager->registerCommandListener('/setmaxplayers', $this, 'command_SetMaxPlayers');
$this->maniaControl->commandManager->registerCommandListener('/setmaxspectators', $this, 'command_SetMaxSpectators');
$this->maniaControl->commandManager->registerCommandListener('/setspecpwd', $this, 'command_SetSpecPwd');
$this->maniaControl->commandManager->registerCommandListener('/shutdown', $this, 'command_Shutdown');
$this->maniaControl->commandManager->registerCommandListener('/shutdownserver', $this, 'command_ShutdownServer');
$this->maniaControl->commandManager->registerCommandListener('/systeminfo', $this, 'command_SystemInfo');
}
/**
@ -64,19 +67,7 @@ class ServerCommands implements CallbackListener, CommandListener {
}
/**
* Send ManiaControl version
*
* @param array $chat
* @return bool
*/
public function command_Version(array $chat) {
$login = $chat[1][1];
$message = 'This server is using ManiaControl v' . ManiaControl::VERSION . '!';
return $this->maniaControl->chat->sendInformation($message, $login);
}
/**
* Handle systeminfo command
* Handle //systeminfo command
*
* @param array $chat
* @param Player $player
@ -94,7 +85,7 @@ class ServerCommands implements CallbackListener, CommandListener {
}
/**
* Handle shutdown command
* Handle //shutdown command
*
* @param array $chat
* @param Player $player
@ -109,7 +100,7 @@ class ServerCommands implements CallbackListener, CommandListener {
}
/**
* Handle server shutdown command
* Handle //shutdownserver command
*
* @param array $chat
* @param Player $player
@ -149,7 +140,7 @@ class ServerCommands implements CallbackListener, CommandListener {
}
/**
* Handle kick command
* Handle //kick command
*
* @param array $chat
* @param Player $player
@ -161,7 +152,7 @@ class ServerCommands implements CallbackListener, CommandListener {
return false;
}
$params = explode(' ', $chat[1][2], 3);
if (count($params) < 2) {
if (!isset($params[1])) {
$this->maniaControl->chat->sendUsageInfo('Usage example: //kick login', $player->login);
return false;
}
@ -179,7 +170,7 @@ class ServerCommands implements CallbackListener, CommandListener {
}
/**
* Handle setservername command
* Handle //setservername command
*
* @param array $chat
* @param Player $player
@ -197,12 +188,136 @@ class ServerCommands implements CallbackListener, CommandListener {
}
$serverName = $params[1];
if (!$this->maniaControl->client->query('SetServerName', $serverName)) {
trigger_error("Couldn't set server name. " . $this->maniaControl->getClientErrorText());
$this->maniaControl->chat->sendError("Error setting server name!", $player->login);
$this->maniaControl->chat->sendError('Error occured: ' . $this->maniaControl->getClientErrorText(), $player->login);
return false;
}
$serverName = $this->maniaControl->server->getName();
$this->maniaControl->chat->sendInformation("New Name: " . $serverName, $player->login);
$this->maniaControl->chat->sendSuccess("Server name changed to: '{$serverName}'!", $player->login);
return true;
}
/**
* Handle //setpwd command
*
* @param array $chatCallback
* @param Player $player
* @return bool
*/
public function command_SetPwd(array $chatCallback, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return false;
}
$messageParts = explode(' ', $chatCallback[1][2], 2);
$password = '';
$successMessage = 'Password removed!';
if (isset($messageParts[1])) {
$password = $messageParts[1];
$successMessage = "Password changed to: '{$password}'!";
}
$success = $this->maniaControl->client->query('SetServerPassword', $password);
if (!$success) {
$this->maniaControl->chat->sendError('Error occured: ' . $this->maniaControl->getClientErrorText(), $player->login);
return false;
}
$this->maniaControl->chat->sendSuccess($successMessage, $player->login);
return true;
}
/**
* Handle //setspecpwd command
*
* @param array $chatCallback
* @param Player $player
* @return bool
*/
public function command_SetSpecPwd(array $chatCallback, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return false;
}
$messageParts = explode(' ', $chatCallback[1][2], 2);
$password = '';
$successMessage = 'Spectator password removed!';
if (isset($messageParts[1])) {
$password = $messageParts[1];
$successMessage = "Spectator password changed to: '{$password}'!";
}
$success = $this->maniaControl->client->query('SetServerPasswordForSpectator', $password);
if (!$success) {
$this->maniaControl->chat->sendError('Error occured: ' . $this->maniaControl->getClientErrorText(), $player->login);
return false;
}
$this->maniaControl->chat->sendSuccess($successMessage, $player->login);
return true;
}
/**
* Handle //setmaxplayers command
*
* @param array $chatCallback
* @param Player $player
* @return bool
*/
public function command_SetMaxPlayers(array $chatCallback, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return false;
}
$messageParts = explode(' ', $chatCallback[1][2], 2);
if (!isset($messageParts[1])) {
$this->maniaControl->chat->sendUsageInfo('Usage example: //setmaxplayers 16', $player->login);
return false;
}
$amount = $messageParts[1];
if (!is_numeric($amount)) {
$this->maniaControl->chat->sendUsageInfo('Usage example: //setmaxplayers 16', $player->login);
return false;
}
$amount = (int) $amount;
if ($amount < 0) {
$amount = 0;
}
$success = $this->maniaControl->client->query('SetMaxPlayers', $amount);
if (!$success) {
$this->maniaControl->chat->sendError('Error occured: ' . $this->maniaControl->getClientErrorText(), $player->login);
return false;
}
$this->maniaControl->chat->sendSuccess("Changed max players to: {$amount}", $player->login);
return true;
}
/**
* Handle //setmaxspectators command
*
* @param array $chatCallback
* @param Player $player
* @return bool
*/
public function command_SetMaxSpectators(array $chatCallback, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return false;
}
$messageParts = explode(' ', $chatCallback[1][2], 2);
if (!isset($messageParts[1])) {
$this->maniaControl->chat->sendUsageInfo('Usage example: //setmaxspectators 16', $player->login);
return false;
}
$amount = $messageParts[1];
if (!is_numeric($amount)) {
$this->maniaControl->chat->sendUsageInfo('Usage example: //setmaxspectators 16', $player->login);
return false;
}
$amount = (int) $amount;
if ($amount < 0) {
$amount = 0;
}
$success = $this->maniaControl->client->query('SetMaxSpectators', $amount);
if (!$success) {
$this->maniaControl->chat->sendError('Error occured: ' . $this->maniaControl->getClientErrorText(), $player->login);
return false;
}
$this->maniaControl->chat->sendSuccess("Changed max spectators to: {$amount}", $player->login);
return true;
}

View File

@ -64,14 +64,15 @@ class FileUtil {
* @return \SimpleXMLElement
*/
public static function loadConfig($fileName) {
if (!$fileName) {
return null;
}
$fileLocation = ManiaControlDir . '/configs/' . $fileName;
if (!file_exists($fileLocation)) {
trigger_error("Config file doesn't exist! ({$fileName})");
return null;
}
if (!is_readable($fileLocation)) {
trigger_error("Config file isn't readable! ({$fileName})");
return null;
}
return simplexml_load_file($fileLocation);
}
}