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
This commit is contained in:
13
core/Callbacks/CallQueueListener.php
Executable file
13
core/Callbacks/CallQueueListener.php
Executable file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Callbacks;
|
||||
|
||||
/**
|
||||
* Interface for CallQueueListener
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014-2019 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
interface CallQueueListener {
|
||||
}
|
69
core/Callbacks/CallQueueListening.php
Executable file
69
core/Callbacks/CallQueueListening.php
Executable file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Callbacks;
|
||||
|
||||
use ManiaControl\General\UsageInformationAble;
|
||||
use ManiaControl\General\UsageInformationTrait;
|
||||
|
||||
/**
|
||||
* Model Class for a Call Queue Listening
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014-2019 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class CallQueueListening extends Listening implements UsageInformationAble {
|
||||
use UsageInformationTrait;
|
||||
|
||||
private $errorMethod = null;
|
||||
|
||||
/**
|
||||
* Construct a new Call Queue Listening
|
||||
*
|
||||
* @param CallQueueListener $listener
|
||||
* @param mixed $method
|
||||
* @param mixed $errorMethod
|
||||
*/
|
||||
public function __construct(CallQueueListener $listener, $method, $errorMethod) {
|
||||
parent::__construct($listener, $method);
|
||||
if ($errorMethod != null) {
|
||||
$this->errorMethod = array($listener, $errorMethod);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger the Listener's Method
|
||||
* @return bool
|
||||
*/
|
||||
public function triggerCallback() {
|
||||
$params = func_get_args();
|
||||
if ($this->triggerCallbackWithParams($params, false) === false) {
|
||||
if ($this->$errorMethod != null) {
|
||||
call_user_func($this->errorMethod, $this->method);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger the Listener's Method with the given Array of Params
|
||||
*
|
||||
* @param array $params
|
||||
* @return mixed
|
||||
*/
|
||||
public function triggerCallbackWithParams(array $params, bool $callErrorMethod = true) {
|
||||
$result = call_user_func_array($this->getUserFunction(), $params);
|
||||
if ($callErrorMethod && $result === false) {
|
||||
if ($this->errorMethod != null) {
|
||||
call_user_func($this->errorMethod, $this->getUserFunction());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
117
core/Callbacks/CallQueueManager.php
Executable file
117
core/Callbacks/CallQueueManager.php
Executable file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Callbacks;
|
||||
|
||||
use ManiaControl\General\UsageInformationAble;
|
||||
use ManiaControl\General\UsageInformationTrait;
|
||||
use ManiaControl\ManiaControl;
|
||||
|
||||
/**
|
||||
* Class for managing queued calls.
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014-2019 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class CallQueueManager implements UsageInformationAble {
|
||||
use UsageInformationTrait;
|
||||
|
||||
/*
|
||||
* Private properties
|
||||
*/
|
||||
/** @var ManiaControl $maniaControl */
|
||||
private $maniaControl = null;
|
||||
/** @var CallQueueListening[] $queueListenings */
|
||||
private $queueListenings = array();
|
||||
|
||||
/**
|
||||
* Construct a new Call Queue Manager
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a Call Queue Listening
|
||||
*
|
||||
* @param CallQueueListener $listener
|
||||
* @param mixed $methods
|
||||
* @param mixed $errorMethod
|
||||
* @return bool
|
||||
*/
|
||||
public function registerListening(CallQueueListener $listener, $methods, $errorMethod = null, bool $important = false) {
|
||||
if ($errorMethod != null && !CallQueueListening::checkValidCallback($listener, $errorMethod)) {
|
||||
trigger_error("Given Listener (" . get_class($listener) . ") can't handle Queue Call Callback (No Error Method '{$errorMethod}')!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!is_array($methods)) {
|
||||
$methods = array($methods);
|
||||
}
|
||||
|
||||
foreach ($methods as $method) {
|
||||
if (!CallQueueListening::checkValidCallback($listener, $method)) {
|
||||
trigger_error("Given Listener (" . get_class($listener) . ") can't handle Queue Call Callback (No Method '{$method}')!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($methods as $method) {
|
||||
// Build Call Queue Listening
|
||||
$listening = new CallQueueListening($listener, $method, $errorMethod);
|
||||
if ($important) {
|
||||
$this->addImportantListening($listening);
|
||||
} else {
|
||||
$this->addListening($listening);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an important Listening to the current list of managed queue calls at the front
|
||||
*
|
||||
* @param CallQueueListening $queueListening
|
||||
*/
|
||||
public function addImportantListening(CallQueueListening $queueListening) {
|
||||
array_unshift($this->queueListenings, $queueListening);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a Listening to the current list of managed queue calls at the end
|
||||
*
|
||||
* @param CallQueueListening $queueListening
|
||||
*/
|
||||
public function addListening(CallQueueListening $queueListening) {
|
||||
array_push($this->queueListenings, $queueListening);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks, if one specific listening already has been queued for a call.
|
||||
* Can only check for named functions.
|
||||
* @param CallQueueListener $listener
|
||||
* @param string $method
|
||||
* @return bool
|
||||
*/
|
||||
public function hasListening(CallQueueListener $listener, string $method) {
|
||||
foreach ($this->queueListenings as $listening) {
|
||||
if ($listening->listener === $listener && $listening->method === $method) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage one of the queued calls
|
||||
*/
|
||||
public function manageCallQueue() {
|
||||
if (!empty($this->queueListenings)) {
|
||||
$listening = array_shift($this->queueListenings);
|
||||
$listening->triggerCallback();
|
||||
}
|
||||
}
|
||||
}
|
@ -57,6 +57,16 @@ class TimerListening extends Listening implements UsageInformationAble {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the deltaTime
|
||||
*
|
||||
* @param float $milliSeconds
|
||||
*/
|
||||
public function setDeltaTime($milliSeconds) {
|
||||
$this->deltaTime = $milliSeconds / 1000.;
|
||||
$this->lastTrigger = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the desired Time is reached
|
||||
*
|
||||
|
@ -75,6 +75,24 @@ class TimerManager implements UsageInformationAble {
|
||||
array_push($this->timerListenings, $timerListening);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the deltaTime of a Timer Listening
|
||||
*
|
||||
* @param TimerListener $listener
|
||||
* @param string|callable $method
|
||||
* @param float $milliSeconds
|
||||
*/
|
||||
public function updateTimerListening(TimerListener $listener, $method, $milliSeconds) {
|
||||
$updated = false;
|
||||
foreach ($this->timerListenings as $key => &$listening) {
|
||||
if ($listening->listener === $listener && $listening->method === $method) {
|
||||
$listening->setDeltaTime($milliSeconds);
|
||||
$updated = true;
|
||||
}
|
||||
}
|
||||
return $updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister a Timer Listening
|
||||
*
|
||||
|
Reference in New Issue
Block a user