- changed "xsuperadmin" to "masteradmin"
- added tm2 server config data - various server admin commands - minor other improvements
This commit is contained in:
parent
a9b1842a6f
commit
33001ef573
@ -1,12 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!-- Configure authentication for players -->
|
<!-- Configure Server Administrators -->
|
||||||
<authentication-config>
|
<authentication-config>
|
||||||
|
|
||||||
<!-- SuperAdmins that can't be removed ingame -->
|
<!-- MasterAdmins that can't be removed ingame -->
|
||||||
<xsuperadmins>
|
<masteradmins>
|
||||||
<login>steeffeen</login>
|
<login>steeffeen</login>
|
||||||
<login>kremsy</login>
|
<login>kremsy</login>
|
||||||
</xsuperadmins>
|
</masteradmins>
|
||||||
|
|
||||||
<!-- You can add other admins and operators ingame -->
|
<!-- You can add other admins and operators ingame -->
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!-- Configure the mysql database used by ManiaControl -->
|
<!-- Configure the MySQL Database used by ManiaControl -->
|
||||||
<database-config>
|
<database-config>
|
||||||
|
|
||||||
<!-- MySQL Server -->
|
<!-- MySQL Server -->
|
||||||
|
@ -21,7 +21,7 @@ class AuthenticationManager implements CommandListener {
|
|||||||
const AUTH_LEVEL_OPERATOR = 1;
|
const AUTH_LEVEL_OPERATOR = 1;
|
||||||
const AUTH_LEVEL_ADMIN = 2;
|
const AUTH_LEVEL_ADMIN = 2;
|
||||||
const AUTH_LEVEL_SUPERADMIN = 3;
|
const AUTH_LEVEL_SUPERADMIN = 3;
|
||||||
const AUTH_LEVEL_XSUPERADMIN = 4;
|
const AUTH_LEVEL_MASTERADMIN = 4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private properties
|
* Private properties
|
||||||
@ -49,7 +49,7 @@ class AuthenticationManager implements CommandListener {
|
|||||||
$config = FileUtil::loadConfig('authentication.xml');
|
$config = FileUtil::loadConfig('authentication.xml');
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
|
|
||||||
// Remove all XSuperadmins
|
// Remove all MasterAdmins
|
||||||
$adminQuery = "UPDATE `" . PlayerManager::TABLE_PLAYERS . "`
|
$adminQuery = "UPDATE `" . PlayerManager::TABLE_PLAYERS . "`
|
||||||
SET `authLevel` = ?
|
SET `authLevel` = ?
|
||||||
WHERE `authLevel` = ?;";
|
WHERE `authLevel` = ?;";
|
||||||
@ -59,7 +59,7 @@ class AuthenticationManager implements CommandListener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$adminLevel = self::AUTH_LEVEL_SUPERADMIN;
|
$adminLevel = self::AUTH_LEVEL_SUPERADMIN;
|
||||||
$xAdminLevel = self::AUTH_LEVEL_XSUPERADMIN;
|
$xAdminLevel = self::AUTH_LEVEL_MASTERADMIN;
|
||||||
$adminStatement->bind_param('ii', $adminLevel, $xAdminLevel);
|
$adminStatement->bind_param('ii', $adminLevel, $xAdminLevel);
|
||||||
$adminStatement->execute();
|
$adminStatement->execute();
|
||||||
if ($adminStatement->error) {
|
if ($adminStatement->error) {
|
||||||
@ -67,8 +67,8 @@ class AuthenticationManager implements CommandListener {
|
|||||||
}
|
}
|
||||||
$adminStatement->close();
|
$adminStatement->close();
|
||||||
|
|
||||||
// Set XSuperAdmins
|
// Set MasterAdmins
|
||||||
$xAdmins = $config->xsuperadmins->xpath('login');
|
$xAdmins = $config->masteradmins->xpath('login');
|
||||||
$adminQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` (
|
$adminQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` (
|
||||||
`login`,
|
`login`,
|
||||||
`authLevel`
|
`authLevel`
|
||||||
@ -103,7 +103,7 @@ class AuthenticationManager implements CommandListener {
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function grantAuthLevel(Player $player, $authLevel) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
|
@ -4,9 +4,11 @@ namespace ManiaControl;
|
|||||||
|
|
||||||
use ManiaControl\Admin\AuthenticationManager;
|
use ManiaControl\Admin\AuthenticationManager;
|
||||||
use ManiaControl\Callbacks\CallbackManager;
|
use ManiaControl\Callbacks\CallbackManager;
|
||||||
|
use ManiaControl\Commands\CommandListener;
|
||||||
use ManiaControl\Commands\CommandManager;
|
use ManiaControl\Commands\CommandManager;
|
||||||
use ManiaControl\Manialinks\ManialinkIdHandler;
|
use ManiaControl\Manialinks\ManialinkIdHandler;
|
||||||
use ManiaControl\Maps\MapManager;
|
use ManiaControl\Maps\MapManager;
|
||||||
|
use ManiaControl\Players\Player;
|
||||||
use ManiaControl\Players\PlayerManager;
|
use ManiaControl\Players\PlayerManager;
|
||||||
use ManiaControl\Plugins\PluginManager;
|
use ManiaControl\Plugins\PluginManager;
|
||||||
use ManiaControl\Server\Server;
|
use ManiaControl\Server\Server;
|
||||||
@ -42,7 +44,7 @@ else {
|
|||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author steeffeen & kremsy
|
||||||
*/
|
*/
|
||||||
class ManiaControl {
|
class ManiaControl implements CommandListener {
|
||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
@ -86,6 +88,8 @@ class ManiaControl {
|
|||||||
$this->playerManager = new PlayerManager($this);
|
$this->playerManager = new PlayerManager($this);
|
||||||
$this->mapManager = new MapManager($this);
|
$this->mapManager = new MapManager($this);
|
||||||
$this->pluginManager = new PluginManager($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() . ')';
|
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
|
* Quit ManiaControl and log the given message
|
||||||
*
|
*
|
||||||
@ -211,7 +226,7 @@ class ManiaControl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Wait for server to be ready
|
// 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);
|
trigger_error("Server couldn't get ready!", E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,12 +32,15 @@ class ServerCommands implements CallbackListener, CommandListener {
|
|||||||
|
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_5_SECOND, $this, 'each5Seconds');
|
$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('/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('/shutdown', $this, 'command_Shutdown');
|
||||||
$this->maniaControl->commandManager->registerCommandListener('/shutdownserver', $this, 'command_ShutdownServer');
|
$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
|
* Handle //systeminfo command
|
||||||
*
|
|
||||||
* @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
|
|
||||||
*
|
*
|
||||||
* @param array $chat
|
* @param array $chat
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
@ -94,7 +85,7 @@ class ServerCommands implements CallbackListener, CommandListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle shutdown command
|
* Handle //shutdown command
|
||||||
*
|
*
|
||||||
* @param array $chat
|
* @param array $chat
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
@ -109,7 +100,7 @@ class ServerCommands implements CallbackListener, CommandListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle server shutdown command
|
* Handle //shutdownserver command
|
||||||
*
|
*
|
||||||
* @param array $chat
|
* @param array $chat
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
@ -149,7 +140,7 @@ class ServerCommands implements CallbackListener, CommandListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle kick command
|
* Handle //kick command
|
||||||
*
|
*
|
||||||
* @param array $chat
|
* @param array $chat
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
@ -161,7 +152,7 @@ class ServerCommands implements CallbackListener, CommandListener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$params = explode(' ', $chat[1][2], 3);
|
$params = explode(' ', $chat[1][2], 3);
|
||||||
if (count($params) < 2) {
|
if (!isset($params[1])) {
|
||||||
$this->maniaControl->chat->sendUsageInfo('Usage example: //kick login', $player->login);
|
$this->maniaControl->chat->sendUsageInfo('Usage example: //kick login', $player->login);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -179,7 +170,7 @@ class ServerCommands implements CallbackListener, CommandListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle setservername command
|
* Handle //setservername command
|
||||||
*
|
*
|
||||||
* @param array $chat
|
* @param array $chat
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
@ -197,12 +188,136 @@ class ServerCommands implements CallbackListener, CommandListener {
|
|||||||
}
|
}
|
||||||
$serverName = $params[1];
|
$serverName = $params[1];
|
||||||
if (!$this->maniaControl->client->query('SetServerName', $serverName)) {
|
if (!$this->maniaControl->client->query('SetServerName', $serverName)) {
|
||||||
trigger_error("Couldn't set server name. " . $this->maniaControl->getClientErrorText());
|
$this->maniaControl->chat->sendError('Error occured: ' . $this->maniaControl->getClientErrorText(), $player->login);
|
||||||
$this->maniaControl->chat->sendError("Error setting server name!", $player->login);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$serverName = $this->maniaControl->server->getName();
|
$this->maniaControl->chat->sendSuccess("Server name changed to: '{$serverName}'!", $player->login);
|
||||||
$this->maniaControl->chat->sendInformation("New Name: " . $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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,14 +64,15 @@ class FileUtil {
|
|||||||
* @return \SimpleXMLElement
|
* @return \SimpleXMLElement
|
||||||
*/
|
*/
|
||||||
public static function loadConfig($fileName) {
|
public static function loadConfig($fileName) {
|
||||||
if (!$fileName) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
$fileLocation = ManiaControlDir . '/configs/' . $fileName;
|
$fileLocation = ManiaControlDir . '/configs/' . $fileName;
|
||||||
if (!file_exists($fileLocation)) {
|
if (!file_exists($fileLocation)) {
|
||||||
trigger_error("Config file doesn't exist! ({$fileName})");
|
trigger_error("Config file doesn't exist! ({$fileName})");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (!is_readable($fileLocation)) {
|
||||||
|
trigger_error("Config file isn't readable! ({$fileName})");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return simplexml_load_file($fileLocation);
|
return simplexml_load_file($fileLocation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user