2013-11-09 17:24:03 +01:00
|
|
|
<?php
|
|
|
|
|
2013-11-12 15:48:25 +01:00
|
|
|
namespace ManiaControl\Commands;
|
|
|
|
|
2023-11-25 16:07:35 +01:00
|
|
|
use ManiaControl\Admin\AuthenticationManager;
|
2013-11-12 15:48:25 +01:00
|
|
|
use ManiaControl\Callbacks\CallbackListener;
|
|
|
|
use ManiaControl\Callbacks\CallbackManager;
|
2023-11-25 16:07:35 +01:00
|
|
|
use ManiaControl\Callbacks\Callbacks;
|
2014-07-11 16:54:43 +02:00
|
|
|
use ManiaControl\Callbacks\Listening;
|
2017-03-26 19:44:55 +02:00
|
|
|
use ManiaControl\General\UsageInformationAble;
|
|
|
|
use ManiaControl\General\UsageInformationTrait;
|
2014-01-14 19:47:40 +01:00
|
|
|
use ManiaControl\ManiaControl;
|
2013-11-09 17:24:03 +01:00
|
|
|
|
|
|
|
/**
|
2014-01-06 16:51:57 +01:00
|
|
|
* Class for handling Chat Commands
|
2013-11-09 17:24:03 +01:00
|
|
|
*
|
2014-05-02 17:50:30 +02:00
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
2020-01-22 10:39:35 +01:00
|
|
|
* @copyright 2014-2020 ManiaControl Team
|
2014-05-02 17:50:30 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2013-11-09 17:24:03 +01:00
|
|
|
*/
|
2017-03-26 19:44:55 +02:00
|
|
|
class CommandManager implements CallbackListener, UsageInformationAble {
|
|
|
|
use UsageInformationTrait;
|
2023-11-25 16:07:35 +01:00
|
|
|
/*
|
|
|
|
* Constants
|
|
|
|
*/
|
|
|
|
const SETTING_PERMISSION_ADMIN_COMMANDS = "Minimum permissions level to use admin commands";
|
2017-03-26 19:44:55 +02:00
|
|
|
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2014-07-25 16:28:47 +02:00
|
|
|
* Private properties
|
2013-11-09 17:24:03 +01:00
|
|
|
*/
|
2014-08-02 22:31:46 +02:00
|
|
|
/** @var ManiaControl $maniaControl */
|
2013-11-10 14:56:37 +01:00
|
|
|
private $maniaControl = null;
|
2014-07-25 16:28:47 +02:00
|
|
|
/** @var HelpManager $helpManager */
|
2014-01-14 19:47:40 +01:00
|
|
|
private $helpManager = array();
|
2014-07-11 16:54:43 +02:00
|
|
|
/** @var Listening[][] $commandListenings */
|
|
|
|
private $commandListenings = array();
|
Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP
* fixed unregister-functions of CallbackManager
* Reducing menuItemHeight in Configurator to avoid overlapping of the menu items
* Fully rebuild the admins menu after a player rights changed
* Added function to FileUtil to improve realpath, so symbolic links can be resolved
* Fixed indentation
* Update FileUtil.php
Fixed error in case of an absolute path on Unix-like systems.
* New CallQueue which runs once inbetween the MC-loops
* Added important queued call to be executed earlier
* ErrorMethod made optional, as in some cases, there might be nothing to fail
* Clean up repository from unnecessary files
* Added easy installation script for DB on Unix-like systems
* Replaced deprecated is_real by is_float
* Add milliseconds with dot instead of double colon
* Resolved deprecated curly braces error
* gitignore all hidden files (except git and gitignore)
* Update MC-update-check-interval, so that a restart is not required
* Update gitignore to not ignore changes in MCTeam-Plugins
* Update gitignore again
* And another try
* fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting
* Increase version number of local records plugin
* Add Permission to delete any record
* Reworked notifications of locals, removed private only, added private at rank
* Fix formatting
* Allow AuthenticationManager to store Plugin Permissions
* Method to check, if a named function call is already queued
* Added command disable feature
* Reset timer if DeltaTime updated, so it does not try to catch up missed timings
* Added private notification setting
* To reduce load of multiple records (especially in rounds), queue call chat notifications
* Added internal function to plugin manager to return plugin menu
* restore .idea codestyle files
* Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
|
|
|
/** @var CommandListener[][] $disabledCommands */
|
|
|
|
private $disabledCommands = array();
|
2014-07-11 16:54:43 +02:00
|
|
|
/** @var Listening[][] $adminCommandListenings */
|
|
|
|
private $adminCommandListenings = array();
|
Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP
* fixed unregister-functions of CallbackManager
* Reducing menuItemHeight in Configurator to avoid overlapping of the menu items
* Fully rebuild the admins menu after a player rights changed
* Added function to FileUtil to improve realpath, so symbolic links can be resolved
* Fixed indentation
* Update FileUtil.php
Fixed error in case of an absolute path on Unix-like systems.
* New CallQueue which runs once inbetween the MC-loops
* Added important queued call to be executed earlier
* ErrorMethod made optional, as in some cases, there might be nothing to fail
* Clean up repository from unnecessary files
* Added easy installation script for DB on Unix-like systems
* Replaced deprecated is_real by is_float
* Add milliseconds with dot instead of double colon
* Resolved deprecated curly braces error
* gitignore all hidden files (except git and gitignore)
* Update MC-update-check-interval, so that a restart is not required
* Update gitignore to not ignore changes in MCTeam-Plugins
* Update gitignore again
* And another try
* fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting
* Increase version number of local records plugin
* Add Permission to delete any record
* Reworked notifications of locals, removed private only, added private at rank
* Fix formatting
* Allow AuthenticationManager to store Plugin Permissions
* Method to check, if a named function call is already queued
* Added command disable feature
* Reset timer if DeltaTime updated, so it does not try to catch up missed timings
* Added private notification setting
* To reduce load of multiple records (especially in rounds), queue call chat notifications
* Added internal function to plugin manager to return plugin menu
* restore .idea codestyle files
* Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
|
|
|
/** @var CommandListener[][] $disabledAdminCommands */
|
|
|
|
private $disabledAdminCommands = array();
|
2013-12-14 23:27:15 +01:00
|
|
|
|
2013-11-09 17:24:03 +01:00
|
|
|
/**
|
2014-01-06 16:51:57 +01:00
|
|
|
* Construct a new Commands Manager
|
2013-11-12 15:48:25 +01:00
|
|
|
*
|
2014-07-11 16:54:43 +02:00
|
|
|
* @param ManiaControl $maniaControl
|
2013-11-09 17:24:03 +01:00
|
|
|
*/
|
2013-11-10 14:56:37 +01:00
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
2014-01-14 19:47:40 +01:00
|
|
|
|
2014-07-25 16:28:47 +02:00
|
|
|
// Children
|
2014-01-14 20:02:35 +01:00
|
|
|
$this->helpManager = new HelpManager($this->maniaControl);
|
2014-01-14 19:47:40 +01:00
|
|
|
|
2014-07-25 16:28:47 +02:00
|
|
|
// Callbacks
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'handleChatCallback');
|
2023-11-25 16:07:35 +01:00
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handleAfterInit() {
|
|
|
|
// Permissions
|
|
|
|
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_ADMIN_COMMANDS, AuthenticationManager::AUTH_LEVEL_MODERATOR, AuthenticationManager::AUTH_LEVEL_PLAYER);
|
2013-11-09 17:24:03 +01:00
|
|
|
}
|
|
|
|
|
2014-07-25 16:28:47 +02:00
|
|
|
/**
|
|
|
|
* Return the help manager instance
|
|
|
|
*
|
|
|
|
* @return HelpManager
|
|
|
|
*/
|
|
|
|
public function getHelpManager() {
|
|
|
|
return $this->helpManager;
|
|
|
|
}
|
|
|
|
|
2013-11-09 17:24:03 +01:00
|
|
|
/**
|
2014-05-13 01:18:47 +02:00
|
|
|
* Register a Command Listener
|
2013-11-09 17:24:03 +01:00
|
|
|
*
|
2014-01-14 19:47:40 +01:00
|
|
|
* @param string $commandName
|
2014-01-06 16:51:57 +01:00
|
|
|
* @param CommandListener $listener
|
2014-01-14 19:47:40 +01:00
|
|
|
* @param string $method
|
|
|
|
* @param bool $adminCommand
|
2014-05-01 01:41:19 +02:00
|
|
|
* @param string $description
|
2013-11-10 14:56:37 +01:00
|
|
|
* @return bool
|
2013-11-09 17:24:03 +01:00
|
|
|
*/
|
2017-06-28 12:45:20 +02:00
|
|
|
public function registerCommandListener($commandName, CommandListener $listener, $method, $adminCommand = false, $description = "No Description.") {
|
2014-03-13 18:47:40 +01:00
|
|
|
if (is_array($commandName)) {
|
2014-07-11 16:54:43 +02:00
|
|
|
$success = false;
|
2014-05-02 17:50:30 +02:00
|
|
|
foreach ($commandName as $command) {
|
2014-07-11 16:54:43 +02:00
|
|
|
if ($this->registerCommandListener($command, $listener, $method, $adminCommand, $description)) {
|
|
|
|
$success = true;
|
2014-01-06 18:32:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $success;
|
|
|
|
}
|
2014-05-13 00:22:47 +02:00
|
|
|
|
2014-07-11 16:54:43 +02:00
|
|
|
if (!Listening::checkValidCallback($listener, $method)) {
|
|
|
|
$listenerClass = get_class($listener);
|
|
|
|
trigger_error("Given Listener '{$listenerClass}' can't handle Command '{$commandName}': No callable Method '{$method}'!");
|
2013-11-10 14:56:37 +01:00
|
|
|
return false;
|
2013-11-09 17:24:03 +01:00
|
|
|
}
|
2014-05-13 00:22:47 +02:00
|
|
|
|
2014-07-11 16:54:43 +02:00
|
|
|
$command = strtolower($commandName);
|
|
|
|
$listening = new Listening($listener, $method);
|
|
|
|
|
2014-03-13 18:47:40 +01:00
|
|
|
if ($adminCommand) {
|
2014-07-11 16:54:43 +02:00
|
|
|
$this->addListening($this->adminCommandListenings, $listening, $command);
|
2014-01-14 19:47:40 +01:00
|
|
|
} else {
|
2014-07-11 16:54:43 +02:00
|
|
|
$this->addListening($this->commandListenings, $listening, $command);
|
2013-11-09 17:24:03 +01:00
|
|
|
}
|
2014-01-14 19:47:40 +01:00
|
|
|
|
2014-05-15 15:13:58 +02:00
|
|
|
// TODO: description(?)
|
|
|
|
if ($description) {
|
|
|
|
$this->helpManager->registerCommand($command, $adminCommand, $description, get_class($listener) . '\\' . $method);
|
|
|
|
}
|
2014-01-14 19:47:40 +01:00
|
|
|
|
2013-11-10 14:56:37 +01:00
|
|
|
return true;
|
2013-11-09 17:24:03 +01:00
|
|
|
}
|
|
|
|
|
2014-05-13 00:22:47 +02:00
|
|
|
/**
|
2014-07-11 16:54:43 +02:00
|
|
|
* Add a Listening to the given Listenings Array
|
2014-05-13 00:22:47 +02:00
|
|
|
*
|
2014-07-11 16:54:43 +02:00
|
|
|
* @param array $listeningsArray
|
|
|
|
* @param Listening $listening
|
|
|
|
* @param string $command
|
2014-05-13 00:22:47 +02:00
|
|
|
*/
|
2014-07-11 16:54:43 +02:00
|
|
|
private function addListening(array &$listeningsArray, Listening $listening, $command) {
|
|
|
|
if (!array_key_exists($command, $listeningsArray) || !is_array($listeningsArray[$command])) {
|
|
|
|
// Init listenings array
|
|
|
|
$listeningsArray[$command] = array();
|
2014-05-13 00:22:47 +02:00
|
|
|
}
|
|
|
|
|
2014-07-11 16:54:43 +02:00
|
|
|
// Register command listening
|
|
|
|
array_push($listeningsArray[$command], $listening);
|
2014-05-13 00:22:47 +02:00
|
|
|
}
|
|
|
|
|
Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP
* fixed unregister-functions of CallbackManager
* Reducing menuItemHeight in Configurator to avoid overlapping of the menu items
* Fully rebuild the admins menu after a player rights changed
* Added function to FileUtil to improve realpath, so symbolic links can be resolved
* Fixed indentation
* Update FileUtil.php
Fixed error in case of an absolute path on Unix-like systems.
* New CallQueue which runs once inbetween the MC-loops
* Added important queued call to be executed earlier
* ErrorMethod made optional, as in some cases, there might be nothing to fail
* Clean up repository from unnecessary files
* Added easy installation script for DB on Unix-like systems
* Replaced deprecated is_real by is_float
* Add milliseconds with dot instead of double colon
* Resolved deprecated curly braces error
* gitignore all hidden files (except git and gitignore)
* Update MC-update-check-interval, so that a restart is not required
* Update gitignore to not ignore changes in MCTeam-Plugins
* Update gitignore again
* And another try
* fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting
* Increase version number of local records plugin
* Add Permission to delete any record
* Reworked notifications of locals, removed private only, added private at rank
* Fix formatting
* Allow AuthenticationManager to store Plugin Permissions
* Method to check, if a named function call is already queued
* Added command disable feature
* Reset timer if DeltaTime updated, so it does not try to catch up missed timings
* Added private notification setting
* To reduce load of multiple records (especially in rounds), queue call chat notifications
* Added internal function to plugin manager to return plugin menu
* restore .idea codestyle files
* Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
|
|
|
/**
|
|
|
|
* Disable the command(s) by the given listener.
|
|
|
|
* The specific listener has to also manually reenable the commands, before the command can be used again.
|
|
|
|
* @param mixed $commandName
|
|
|
|
* @param bool $adminCommand
|
|
|
|
* @param CommandListener $listener
|
|
|
|
*/
|
2020-02-25 17:48:27 +01:00
|
|
|
public function disableCommand($commandName, $adminCommand, CommandListener $listener) {
|
Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP
* fixed unregister-functions of CallbackManager
* Reducing menuItemHeight in Configurator to avoid overlapping of the menu items
* Fully rebuild the admins menu after a player rights changed
* Added function to FileUtil to improve realpath, so symbolic links can be resolved
* Fixed indentation
* Update FileUtil.php
Fixed error in case of an absolute path on Unix-like systems.
* New CallQueue which runs once inbetween the MC-loops
* Added important queued call to be executed earlier
* ErrorMethod made optional, as in some cases, there might be nothing to fail
* Clean up repository from unnecessary files
* Added easy installation script for DB on Unix-like systems
* Replaced deprecated is_real by is_float
* Add milliseconds with dot instead of double colon
* Resolved deprecated curly braces error
* gitignore all hidden files (except git and gitignore)
* Update MC-update-check-interval, so that a restart is not required
* Update gitignore to not ignore changes in MCTeam-Plugins
* Update gitignore again
* And another try
* fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting
* Increase version number of local records plugin
* Add Permission to delete any record
* Reworked notifications of locals, removed private only, added private at rank
* Fix formatting
* Allow AuthenticationManager to store Plugin Permissions
* Method to check, if a named function call is already queued
* Added command disable feature
* Reset timer if DeltaTime updated, so it does not try to catch up missed timings
* Added private notification setting
* To reduce load of multiple records (especially in rounds), queue call chat notifications
* Added internal function to plugin manager to return plugin menu
* restore .idea codestyle files
* Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
|
|
|
if (is_array($commandName)) {
|
|
|
|
foreach ($commandName as $command) {
|
|
|
|
$this->disableCommand($command, $adminCommand, $listener);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$command = strtolower(trim($commandName));
|
|
|
|
// first, check if the command actually exists
|
|
|
|
if (!array_key_exists($command, $this->commandListenings) && !array_key_exists($command, $this->adminCommandListenings)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$disabledCommands = null;
|
|
|
|
if ($adminCommand) {
|
|
|
|
$disabledCommands = &$this->disabledAdminCommands;
|
|
|
|
} else {
|
|
|
|
$disabledCommands = &$this->disabledCommands;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!array_key_exists($command, $disabledCommands)) {
|
|
|
|
$disabledCommands[$command] = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!in_array($listener, $disabledCommands[$command])) {
|
|
|
|
array_push($disabledCommands[$command], $listener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable the command(s) by the given listener.
|
|
|
|
* @param mixed $commandName
|
|
|
|
* @param bool $adminCommand
|
|
|
|
* @param CommandListener $listener
|
|
|
|
*/
|
2020-02-25 17:48:27 +01:00
|
|
|
public function enableCommand($commandName, $adminCommand, CommandListener $listener) {
|
Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP
* fixed unregister-functions of CallbackManager
* Reducing menuItemHeight in Configurator to avoid overlapping of the menu items
* Fully rebuild the admins menu after a player rights changed
* Added function to FileUtil to improve realpath, so symbolic links can be resolved
* Fixed indentation
* Update FileUtil.php
Fixed error in case of an absolute path on Unix-like systems.
* New CallQueue which runs once inbetween the MC-loops
* Added important queued call to be executed earlier
* ErrorMethod made optional, as in some cases, there might be nothing to fail
* Clean up repository from unnecessary files
* Added easy installation script for DB on Unix-like systems
* Replaced deprecated is_real by is_float
* Add milliseconds with dot instead of double colon
* Resolved deprecated curly braces error
* gitignore all hidden files (except git and gitignore)
* Update MC-update-check-interval, so that a restart is not required
* Update gitignore to not ignore changes in MCTeam-Plugins
* Update gitignore again
* And another try
* fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting
* Increase version number of local records plugin
* Add Permission to delete any record
* Reworked notifications of locals, removed private only, added private at rank
* Fix formatting
* Allow AuthenticationManager to store Plugin Permissions
* Method to check, if a named function call is already queued
* Added command disable feature
* Reset timer if DeltaTime updated, so it does not try to catch up missed timings
* Added private notification setting
* To reduce load of multiple records (especially in rounds), queue call chat notifications
* Added internal function to plugin manager to return plugin menu
* restore .idea codestyle files
* Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
|
|
|
if (is_array($commandName)) {
|
|
|
|
foreach ($commandName as $command) {
|
|
|
|
$this->enableCommand($command, $adminCommand, $listener);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$command = strtolower(trim($commandName));
|
|
|
|
|
|
|
|
$disabledCommands = null;
|
|
|
|
if ($adminCommand) {
|
|
|
|
$disabledCommands = &$this->disabledAdminCommands;
|
|
|
|
} else {
|
|
|
|
$disabledCommands = &$this->disabledCommands;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!array_key_exists($command, $disabledCommands)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (($key = array_search($listener, $disabledCommands[$command])) !== false) {
|
|
|
|
unset($disabledCommands[$command][$key]);
|
|
|
|
if (empty($disabledCommands[$command])) {
|
|
|
|
unset($disabledCommands[$command]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if a command is enabled.
|
|
|
|
* @param mixed $commandName
|
|
|
|
* @param bool $adminCommand
|
|
|
|
* @return bool|array
|
|
|
|
*/
|
2020-02-25 17:48:27 +01:00
|
|
|
public function isCommandEnabled($commandName, $adminCommand) {
|
Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP
* fixed unregister-functions of CallbackManager
* Reducing menuItemHeight in Configurator to avoid overlapping of the menu items
* Fully rebuild the admins menu after a player rights changed
* Added function to FileUtil to improve realpath, so symbolic links can be resolved
* Fixed indentation
* Update FileUtil.php
Fixed error in case of an absolute path on Unix-like systems.
* New CallQueue which runs once inbetween the MC-loops
* Added important queued call to be executed earlier
* ErrorMethod made optional, as in some cases, there might be nothing to fail
* Clean up repository from unnecessary files
* Added easy installation script for DB on Unix-like systems
* Replaced deprecated is_real by is_float
* Add milliseconds with dot instead of double colon
* Resolved deprecated curly braces error
* gitignore all hidden files (except git and gitignore)
* Update MC-update-check-interval, so that a restart is not required
* Update gitignore to not ignore changes in MCTeam-Plugins
* Update gitignore again
* And another try
* fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting
* Increase version number of local records plugin
* Add Permission to delete any record
* Reworked notifications of locals, removed private only, added private at rank
* Fix formatting
* Allow AuthenticationManager to store Plugin Permissions
* Method to check, if a named function call is already queued
* Added command disable feature
* Reset timer if DeltaTime updated, so it does not try to catch up missed timings
* Added private notification setting
* To reduce load of multiple records (especially in rounds), queue call chat notifications
* Added internal function to plugin manager to return plugin menu
* restore .idea codestyle files
* Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
|
|
|
if (is_array($commandName)) {
|
|
|
|
$results = array();
|
|
|
|
foreach ($commandName as $command) {
|
|
|
|
array_push($results, $this->isCommandEnabled($command, $adminCommand));
|
|
|
|
}
|
|
|
|
$resultsUnique = array_unique($results);
|
|
|
|
if (count($resultsUnique) === 1) {
|
|
|
|
return $resultsUnique[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
|
|
|
$command = strtolower(trim($commandName));
|
|
|
|
|
|
|
|
$disabledCommands = null;
|
|
|
|
if ($adminCommand) {
|
|
|
|
$disabledCommands = &$this->disabledAdminCommands;
|
|
|
|
} else {
|
|
|
|
$disabledCommands = &$this->disabledCommands;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!array_key_exists($command, $disabledCommands)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the command is disabled, there should be at least one listener in the array
|
|
|
|
assert(!empty($disabledCommands[$command]));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the given CommandListener blocking commands.
|
|
|
|
*
|
|
|
|
* @param array &$disabledCommands
|
|
|
|
* @param CommandListener $listener
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function removeDisabledCommandListener(array &$disabledCommands, CommandListener $listener) {
|
|
|
|
$removed = false;
|
|
|
|
foreach ($disabledCommands as $command => $disableListeners) {
|
|
|
|
if (($key = array_search($listener, $disableListeners)) !== false) {
|
|
|
|
unset($disabledCommands[$command][$key]);
|
|
|
|
$removed = true;
|
|
|
|
|
|
|
|
if (empty($disabledCommands[$command])) {
|
|
|
|
unset($disabledCommands[$command]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $removed;
|
|
|
|
}
|
|
|
|
|
2013-12-14 23:27:15 +01:00
|
|
|
/**
|
2014-05-13 01:18:47 +02:00
|
|
|
* Unregister a Command Listener
|
2014-01-06 16:51:57 +01:00
|
|
|
*
|
|
|
|
* @param CommandListener $listener
|
2013-12-14 23:27:15 +01:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function unregisterCommandListener(CommandListener $listener) {
|
|
|
|
$removed = false;
|
2014-07-11 16:54:43 +02:00
|
|
|
if ($this->removeCommandListener($this->commandListenings, $listener)) {
|
2014-05-13 00:22:47 +02:00
|
|
|
$removed = true;
|
2013-12-14 23:27:15 +01:00
|
|
|
}
|
2014-07-11 16:54:43 +02:00
|
|
|
if ($this->removeCommandListener($this->adminCommandListenings, $listener)) {
|
2014-05-13 00:22:47 +02:00
|
|
|
$removed = true;
|
|
|
|
}
|
Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP
* fixed unregister-functions of CallbackManager
* Reducing menuItemHeight in Configurator to avoid overlapping of the menu items
* Fully rebuild the admins menu after a player rights changed
* Added function to FileUtil to improve realpath, so symbolic links can be resolved
* Fixed indentation
* Update FileUtil.php
Fixed error in case of an absolute path on Unix-like systems.
* New CallQueue which runs once inbetween the MC-loops
* Added important queued call to be executed earlier
* ErrorMethod made optional, as in some cases, there might be nothing to fail
* Clean up repository from unnecessary files
* Added easy installation script for DB on Unix-like systems
* Replaced deprecated is_real by is_float
* Add milliseconds with dot instead of double colon
* Resolved deprecated curly braces error
* gitignore all hidden files (except git and gitignore)
* Update MC-update-check-interval, so that a restart is not required
* Update gitignore to not ignore changes in MCTeam-Plugins
* Update gitignore again
* And another try
* fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting
* Increase version number of local records plugin
* Add Permission to delete any record
* Reworked notifications of locals, removed private only, added private at rank
* Fix formatting
* Allow AuthenticationManager to store Plugin Permissions
* Method to check, if a named function call is already queued
* Added command disable feature
* Reset timer if DeltaTime updated, so it does not try to catch up missed timings
* Added private notification setting
* To reduce load of multiple records (especially in rounds), queue call chat notifications
* Added internal function to plugin manager to return plugin menu
* restore .idea codestyle files
* Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
|
|
|
if ($this->removeDisabledCommandListener($this->disabledCommands, $listener)) {
|
|
|
|
$removed = true;
|
|
|
|
}
|
|
|
|
if ($this->removeDisabledCommandListener($this->disabledAdminCommands, $listener)) {
|
|
|
|
$removed = true;
|
|
|
|
}
|
2014-05-13 00:22:47 +02:00
|
|
|
return $removed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-11 16:54:43 +02:00
|
|
|
* Remove the Command Listener from the given Listenings Array
|
2014-05-13 00:22:47 +02:00
|
|
|
*
|
2014-07-11 16:54:43 +02:00
|
|
|
* @param array $listeningsArray
|
2014-05-13 00:22:47 +02:00
|
|
|
* @param CommandListener $listener
|
|
|
|
* @return bool
|
|
|
|
*/
|
2014-07-11 16:54:43 +02:00
|
|
|
private function removeCommandListener(array &$listeningsArray, CommandListener $listener) {
|
2014-05-13 00:22:47 +02:00
|
|
|
$removed = false;
|
2014-07-11 16:54:43 +02:00
|
|
|
foreach ($listeningsArray as &$listenings) {
|
|
|
|
foreach ($listenings as $key => &$listening) {
|
|
|
|
if ($listening->listener === $listener) {
|
|
|
|
unset($listenings[$key]);
|
2013-12-14 23:27:15 +01:00
|
|
|
$removed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $removed;
|
|
|
|
}
|
|
|
|
|
2013-11-09 17:24:03 +01:00
|
|
|
/**
|
2014-01-06 16:51:57 +01:00
|
|
|
* Handle Chat Callback
|
2013-11-10 14:56:37 +01:00
|
|
|
*
|
2014-01-06 16:51:57 +01:00
|
|
|
* @param array $callback
|
2013-11-09 17:24:03 +01:00
|
|
|
*/
|
2013-11-10 14:56:37 +01:00
|
|
|
public function handleChatCallback(array $callback) {
|
2013-11-09 17:24:03 +01:00
|
|
|
// Check for command
|
2014-07-17 20:02:55 +02:00
|
|
|
if (!$this->isCommandMessage($callback)) {
|
2014-01-14 19:47:40 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-09 17:24:03 +01:00
|
|
|
// Check for valid player
|
2014-01-14 19:47:40 +01:00
|
|
|
$login = $callback[1][1];
|
2014-08-13 11:05:52 +02:00
|
|
|
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
2014-03-13 18:47:40 +01:00
|
|
|
if (!$player) {
|
2014-01-14 19:47:40 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-06 16:51:57 +01:00
|
|
|
// Parse command
|
2014-01-14 19:47:40 +01:00
|
|
|
$message = $callback[1][2];
|
2014-01-06 16:51:57 +01:00
|
|
|
$commandArray = explode(' ', $message);
|
2014-01-14 19:47:40 +01:00
|
|
|
$command = ltrim(strtolower($commandArray[0]), '/');
|
2014-03-13 18:47:40 +01:00
|
|
|
if (!$command) {
|
2014-01-14 19:47:40 +01:00
|
|
|
return;
|
|
|
|
}
|
Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP
* fixed unregister-functions of CallbackManager
* Reducing menuItemHeight in Configurator to avoid overlapping of the menu items
* Fully rebuild the admins menu after a player rights changed
* Added function to FileUtil to improve realpath, so symbolic links can be resolved
* Fixed indentation
* Update FileUtil.php
Fixed error in case of an absolute path on Unix-like systems.
* New CallQueue which runs once inbetween the MC-loops
* Added important queued call to be executed earlier
* ErrorMethod made optional, as in some cases, there might be nothing to fail
* Clean up repository from unnecessary files
* Added easy installation script for DB on Unix-like systems
* Replaced deprecated is_real by is_float
* Add milliseconds with dot instead of double colon
* Resolved deprecated curly braces error
* gitignore all hidden files (except git and gitignore)
* Update MC-update-check-interval, so that a restart is not required
* Update gitignore to not ignore changes in MCTeam-Plugins
* Update gitignore again
* And another try
* fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting
* Increase version number of local records plugin
* Add Permission to delete any record
* Reworked notifications of locals, removed private only, added private at rank
* Fix formatting
* Allow AuthenticationManager to store Plugin Permissions
* Method to check, if a named function call is already queued
* Added command disable feature
* Reset timer if DeltaTime updated, so it does not try to catch up missed timings
* Added private notification setting
* To reduce load of multiple records (especially in rounds), queue call chat notifications
* Added internal function to plugin manager to return plugin menu
* restore .idea codestyle files
* Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
|
|
|
|
|
|
|
$isAdminCommand = null;
|
2014-06-14 14:32:29 +02:00
|
|
|
if (substr($message, 0, 2) === '//' || $command === 'admin') {
|
2014-01-06 16:51:57 +01:00
|
|
|
// Admin command
|
Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP
* fixed unregister-functions of CallbackManager
* Reducing menuItemHeight in Configurator to avoid overlapping of the menu items
* Fully rebuild the admins menu after a player rights changed
* Added function to FileUtil to improve realpath, so symbolic links can be resolved
* Fixed indentation
* Update FileUtil.php
Fixed error in case of an absolute path on Unix-like systems.
* New CallQueue which runs once inbetween the MC-loops
* Added important queued call to be executed earlier
* ErrorMethod made optional, as in some cases, there might be nothing to fail
* Clean up repository from unnecessary files
* Added easy installation script for DB on Unix-like systems
* Replaced deprecated is_real by is_float
* Add milliseconds with dot instead of double colon
* Resolved deprecated curly braces error
* gitignore all hidden files (except git and gitignore)
* Update MC-update-check-interval, so that a restart is not required
* Update gitignore to not ignore changes in MCTeam-Plugins
* Update gitignore again
* And another try
* fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting
* Increase version number of local records plugin
* Add Permission to delete any record
* Reworked notifications of locals, removed private only, added private at rank
* Fix formatting
* Allow AuthenticationManager to store Plugin Permissions
* Method to check, if a named function call is already queued
* Added command disable feature
* Reset timer if DeltaTime updated, so it does not try to catch up missed timings
* Added private notification setting
* To reduce load of multiple records (especially in rounds), queue call chat notifications
* Added internal function to plugin manager to return plugin menu
* restore .idea codestyle files
* Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
|
|
|
$isAdminCommand = true;
|
2014-07-11 16:54:43 +02:00
|
|
|
$commandListenings = $this->adminCommandListenings;
|
2014-01-14 19:47:40 +01:00
|
|
|
|
2023-11-25 16:07:35 +01:00
|
|
|
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_ADMIN_COMMANDS)) {
|
|
|
|
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-14 14:32:29 +02:00
|
|
|
if ($command === 'admin') {
|
2014-01-06 16:51:57 +01:00
|
|
|
// Strip 'admin' keyword
|
2014-03-13 18:47:40 +01:00
|
|
|
if (isset($commandArray[1])) {
|
|
|
|
$command = $commandArray[1];
|
|
|
|
unset($commandArray[1]);
|
|
|
|
}
|
2013-12-09 22:12:57 +01:00
|
|
|
}
|
2014-01-06 16:51:57 +01:00
|
|
|
unset($commandArray[0]);
|
2014-01-14 19:47:40 +01:00
|
|
|
|
2014-01-06 16:51:57 +01:00
|
|
|
// Compose uniformed message
|
2014-07-11 16:54:43 +02:00
|
|
|
$message = '//' . $command . ' ' . implode(' ', $commandArray);
|
2014-01-06 16:51:57 +01:00
|
|
|
$callback[1][2] = $message;
|
2014-01-14 19:47:40 +01:00
|
|
|
} else {
|
2014-01-06 16:51:57 +01:00
|
|
|
// User command
|
Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP
* fixed unregister-functions of CallbackManager
* Reducing menuItemHeight in Configurator to avoid overlapping of the menu items
* Fully rebuild the admins menu after a player rights changed
* Added function to FileUtil to improve realpath, so symbolic links can be resolved
* Fixed indentation
* Update FileUtil.php
Fixed error in case of an absolute path on Unix-like systems.
* New CallQueue which runs once inbetween the MC-loops
* Added important queued call to be executed earlier
* ErrorMethod made optional, as in some cases, there might be nothing to fail
* Clean up repository from unnecessary files
* Added easy installation script for DB on Unix-like systems
* Replaced deprecated is_real by is_float
* Add milliseconds with dot instead of double colon
* Resolved deprecated curly braces error
* gitignore all hidden files (except git and gitignore)
* Update MC-update-check-interval, so that a restart is not required
* Update gitignore to not ignore changes in MCTeam-Plugins
* Update gitignore again
* And another try
* fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting
* Increase version number of local records plugin
* Add Permission to delete any record
* Reworked notifications of locals, removed private only, added private at rank
* Fix formatting
* Allow AuthenticationManager to store Plugin Permissions
* Method to check, if a named function call is already queued
* Added command disable feature
* Reset timer if DeltaTime updated, so it does not try to catch up missed timings
* Added private notification setting
* To reduce load of multiple records (especially in rounds), queue call chat notifications
* Added internal function to plugin manager to return plugin menu
* restore .idea codestyle files
* Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
|
|
|
$isAdminCommand = false;
|
2014-07-11 16:54:43 +02:00
|
|
|
$commandListenings = $this->commandListenings;
|
2013-12-09 22:12:57 +01:00
|
|
|
}
|
2014-01-14 19:47:40 +01:00
|
|
|
|
2014-07-11 16:54:43 +02:00
|
|
|
if (!array_key_exists($command, $commandListenings) || !is_array($commandListenings[$command])) {
|
2013-11-12 19:33:25 +01:00
|
|
|
// No command listener registered
|
2013-11-28 03:47:08 +01:00
|
|
|
return;
|
2013-11-09 17:24:03 +01:00
|
|
|
}
|
2014-01-14 19:47:40 +01:00
|
|
|
|
Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP
* fixed unregister-functions of CallbackManager
* Reducing menuItemHeight in Configurator to avoid overlapping of the menu items
* Fully rebuild the admins menu after a player rights changed
* Added function to FileUtil to improve realpath, so symbolic links can be resolved
* Fixed indentation
* Update FileUtil.php
Fixed error in case of an absolute path on Unix-like systems.
* New CallQueue which runs once inbetween the MC-loops
* Added important queued call to be executed earlier
* ErrorMethod made optional, as in some cases, there might be nothing to fail
* Clean up repository from unnecessary files
* Added easy installation script for DB on Unix-like systems
* Replaced deprecated is_real by is_float
* Add milliseconds with dot instead of double colon
* Resolved deprecated curly braces error
* gitignore all hidden files (except git and gitignore)
* Update MC-update-check-interval, so that a restart is not required
* Update gitignore to not ignore changes in MCTeam-Plugins
* Update gitignore again
* And another try
* fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting
* Increase version number of local records plugin
* Add Permission to delete any record
* Reworked notifications of locals, removed private only, added private at rank
* Fix formatting
* Allow AuthenticationManager to store Plugin Permissions
* Method to check, if a named function call is already queued
* Added command disable feature
* Reset timer if DeltaTime updated, so it does not try to catch up missed timings
* Added private notification setting
* To reduce load of multiple records (especially in rounds), queue call chat notifications
* Added internal function to plugin manager to return plugin menu
* restore .idea codestyle files
* Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
|
|
|
if (!$this->isCommandEnabled($command, $isAdminCommand)) {
|
|
|
|
$prefix = $isAdminCommand ? '//' : '/';
|
2020-05-26 21:56:00 +02:00
|
|
|
$message = $this->maniaControl->getChat()->formatMessage(
|
|
|
|
'The command %s%s is currently disabled!',
|
|
|
|
$prefix,
|
|
|
|
$command
|
|
|
|
);
|
|
|
|
$this->maniaControl->getChat()->sendError($message, $player);
|
Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP
* fixed unregister-functions of CallbackManager
* Reducing menuItemHeight in Configurator to avoid overlapping of the menu items
* Fully rebuild the admins menu after a player rights changed
* Added function to FileUtil to improve realpath, so symbolic links can be resolved
* Fixed indentation
* Update FileUtil.php
Fixed error in case of an absolute path on Unix-like systems.
* New CallQueue which runs once inbetween the MC-loops
* Added important queued call to be executed earlier
* ErrorMethod made optional, as in some cases, there might be nothing to fail
* Clean up repository from unnecessary files
* Added easy installation script for DB on Unix-like systems
* Replaced deprecated is_real by is_float
* Add milliseconds with dot instead of double colon
* Resolved deprecated curly braces error
* gitignore all hidden files (except git and gitignore)
* Update MC-update-check-interval, so that a restart is not required
* Update gitignore to not ignore changes in MCTeam-Plugins
* Update gitignore again
* And another try
* fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting
* Increase version number of local records plugin
* Add Permission to delete any record
* Reworked notifications of locals, removed private only, added private at rank
* Fix formatting
* Allow AuthenticationManager to store Plugin Permissions
* Method to check, if a named function call is already queued
* Added command disable feature
* Reset timer if DeltaTime updated, so it does not try to catch up missed timings
* Added private notification setting
* To reduce load of multiple records (especially in rounds), queue call chat notifications
* Added internal function to plugin manager to return plugin menu
* restore .idea codestyle files
* Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-12 19:33:25 +01:00
|
|
|
// Inform command listeners
|
2014-07-11 16:54:43 +02:00
|
|
|
foreach ($commandListenings[$command] as $listening) {
|
|
|
|
/** @var Listening $listening */
|
|
|
|
$listening->triggerCallback($callback, $player);
|
2013-11-09 17:24:03 +01:00
|
|
|
}
|
|
|
|
}
|
2014-07-11 16:54:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the given Chat Callback is a Command Message
|
|
|
|
*
|
|
|
|
* @param array $chatCallback
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function isCommandMessage(array $chatCallback) {
|
2017-03-26 19:44:55 +02:00
|
|
|
return (bool) $chatCallback[1][3];
|
2014-07-11 16:54:43 +02:00
|
|
|
}
|
2013-11-09 17:24:03 +01:00
|
|
|
}
|