applied common formatting
This commit is contained in:
parent
ba720f46bf
commit
a0f5421bea
@ -4,7 +4,7 @@
|
|||||||
define('LOG_WRITE_CURRENT_FILE', 'ManiaControl.log'); // Write current log to extra file in base dir
|
define('LOG_WRITE_CURRENT_FILE', 'ManiaControl.log'); // Write current log to extra file in base dir
|
||||||
define('LOG_NAME_USE_DATE', true); // Use current date as suffix for log file name in logs folder
|
define('LOG_NAME_USE_DATE', true); // Use current date as suffix for log file name in logs folder
|
||||||
define('LOG_NAME_USE_PID', true); // Use current process id as suffix for log file name in logs folder
|
define('LOG_NAME_USE_PID', true); // Use current process id as suffix for log file name in logs folder
|
||||||
|
|
||||||
// Define base dir
|
// Define base dir
|
||||||
define('ManiaControlDir', __DIR__);
|
define('ManiaControlDir', __DIR__);
|
||||||
|
|
||||||
@ -51,8 +51,7 @@ logMessage('Starting ManiaControl ...');
|
|||||||
logMessage('Checking for installed MySQLi ... ', false);
|
logMessage('Checking for installed MySQLi ... ', false);
|
||||||
if (extension_loaded('mysqli')) {
|
if (extension_loaded('mysqli')) {
|
||||||
logMessage('FOUND!');
|
logMessage('FOUND!');
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
logMessage('NOT FOUND!');
|
logMessage('NOT FOUND!');
|
||||||
logMessage(' -- You don\'t have MySQLi installed, make sure to check: http://www.php.net/manual/en/mysqli.installation.php');
|
logMessage(' -- You don\'t have MySQLi installed, make sure to check: http://www.php.net/manual/en/mysqli.installation.php');
|
||||||
exit();
|
exit();
|
||||||
@ -61,8 +60,7 @@ else {
|
|||||||
logMessage('Checking for installed cURL ... ', false);
|
logMessage('Checking for installed cURL ... ', false);
|
||||||
if (extension_loaded('curl')) {
|
if (extension_loaded('curl')) {
|
||||||
logMessage('FOUND!');
|
logMessage('FOUND!');
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
logMessage('NOT FOUND!');
|
logMessage('NOT FOUND!');
|
||||||
logMessage('You don\'t have cURL installed, make sure to check: http://www.php.net/manual/en/curl.installation.php');
|
logMessage('You don\'t have cURL installed, make sure to check: http://www.php.net/manual/en/curl.installation.php');
|
||||||
exit();
|
exit();
|
||||||
@ -70,12 +68,12 @@ else {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Log and echo the given text
|
* Log and echo the given text
|
||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param bool $eol
|
* @param bool $eol
|
||||||
*/
|
*/
|
||||||
function logMessage($message, $eol = true) {
|
function logMessage($message, $eol = true) {
|
||||||
$date = date("d.M y H:i:s");
|
$date = date("d.M y H:i:s");
|
||||||
$message = $date . ' ' . $message;
|
$message = $date . ' ' . $message;
|
||||||
if ($eol) {
|
if ($eol) {
|
||||||
$message .= PHP_EOL;
|
$message .= PHP_EOL;
|
||||||
@ -94,15 +92,15 @@ function logMessage($message, $eol = true) {
|
|||||||
// Autoload Function that loads ManiaControl Class Files on Demand
|
// Autoload Function that loads ManiaControl Class Files on Demand
|
||||||
spl_autoload_register(function ($className) {
|
spl_autoload_register(function ($className) {
|
||||||
$classPath = str_replace('\\', DIRECTORY_SEPARATOR, $className);
|
$classPath = str_replace('\\', DIRECTORY_SEPARATOR, $className);
|
||||||
|
|
||||||
// Core file
|
// Core file
|
||||||
$classDirectoryPath = preg_replace('/ManiaControl/', 'core', $classPath, 1);
|
$classDirectoryPath = preg_replace('/ManiaControl/', 'core', $classPath, 1);
|
||||||
$filePath = ManiaControlDir . DIRECTORY_SEPARATOR . $classDirectoryPath . '.php';
|
$filePath = ManiaControlDir . DIRECTORY_SEPARATOR . $classDirectoryPath . '.php';
|
||||||
if (file_exists($filePath)) {
|
if (file_exists($filePath)) {
|
||||||
require_once $filePath;
|
require_once $filePath;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plugin file
|
// Plugin file
|
||||||
$filePath = ManiaControlDir . DIRECTORY_SEPARATOR . 'plugins/' . $classPath . '.php';
|
$filePath = ManiaControlDir . DIRECTORY_SEPARATOR . 'plugins/' . $classPath . '.php';
|
||||||
if (file_exists($filePath)) {
|
if (file_exists($filePath)) {
|
||||||
|
@ -3,11 +3,11 @@
|
|||||||
namespace ManiaControl\Callbacks;
|
namespace ManiaControl\Callbacks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for CallbackListener
|
* Interface for Callback Listener
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
interface CallbackListener {
|
interface CallbackListener {
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,8 @@ use ManiaControl\ManiaControl;
|
|||||||
/**
|
/**
|
||||||
* Class for managing Server and ManiaControl Callbacks
|
* Class for managing Server and ManiaControl Callbacks
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class CallbackManager {
|
class CallbackManager {
|
||||||
@ -118,8 +118,8 @@ class CallbackManager {
|
|||||||
*/
|
*/
|
||||||
public function unregisterCallbackListener(CallbackListener $listener) {
|
public function unregisterCallbackListener(CallbackListener $listener) {
|
||||||
$removed = false;
|
$removed = false;
|
||||||
foreach($this->callbackListeners as &$listeners) {
|
foreach ($this->callbackListeners as &$listeners) {
|
||||||
foreach($listeners as $key => &$listenerCallback) {
|
foreach ($listeners as $key => &$listenerCallback) {
|
||||||
if ($listenerCallback[0] != $listener) {
|
if ($listenerCallback[0] != $listener) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -138,8 +138,8 @@ class CallbackManager {
|
|||||||
*/
|
*/
|
||||||
public function unregisterScriptCallbackListener(CallbackListener $listener) {
|
public function unregisterScriptCallbackListener(CallbackListener $listener) {
|
||||||
$removed = false;
|
$removed = false;
|
||||||
foreach($this->scriptCallbackListener as &$listeners) {
|
foreach ($this->scriptCallbackListener as &$listeners) {
|
||||||
foreach($listeners as $key => &$listenerCallback) {
|
foreach ($listeners as $key => &$listenerCallback) {
|
||||||
if ($listenerCallback[0] != $listener) {
|
if ($listenerCallback[0] != $listener) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -150,38 +150,6 @@ class CallbackManager {
|
|||||||
return $removed;
|
return $removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Trigger a specific Callback
|
|
||||||
*
|
|
||||||
* @param string $callbackName
|
|
||||||
*/
|
|
||||||
public function triggerCallback($callbackName) {
|
|
||||||
if (!array_key_exists($callbackName, $this->callbackListeners)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$params = func_get_args();
|
|
||||||
$params = array_slice($params, 1, count($params), true);
|
|
||||||
foreach($this->callbackListeners[$callbackName] as $listener) {
|
|
||||||
call_user_func_array(array($listener[0], $listener[1]), $params);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Trigger a specific Script Callback
|
|
||||||
*
|
|
||||||
* @param string $callbackName
|
|
||||||
*/
|
|
||||||
public function triggerScriptCallback($callbackName) {
|
|
||||||
if (!array_key_exists($callbackName, $this->scriptCallbackListener)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$params = func_get_args();
|
|
||||||
$params = array_slice($params, 1, count($params), true);
|
|
||||||
foreach($this->scriptCallbackListener[$callbackName] as $listener) {
|
|
||||||
call_user_func_array(array($listener[0], $listener[1]), $params);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trigger internal Callbacks and manage Server Callbacks
|
* Trigger internal Callbacks and manage Server Callbacks
|
||||||
*/
|
*/
|
||||||
@ -197,7 +165,7 @@ class CallbackManager {
|
|||||||
$callbacks = $this->maniaControl->client->executeCallbacks();
|
$callbacks = $this->maniaControl->client->executeCallbacks();
|
||||||
|
|
||||||
// Handle callbacks
|
// Handle callbacks
|
||||||
foreach($callbacks as $callback) {
|
foreach ($callbacks as $callback) {
|
||||||
$this->handleCallback($callback);
|
$this->handleCallback($callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -209,12 +177,12 @@ class CallbackManager {
|
|||||||
*/
|
*/
|
||||||
private function handleCallback(array $callback) {
|
private function handleCallback(array $callback) {
|
||||||
$callbackName = $callback[0];
|
$callbackName = $callback[0];
|
||||||
switch($callbackName) {
|
switch ($callbackName) {
|
||||||
case 'ManiaPlanet.BeginMatch':
|
case 'ManiaPlanet.BeginMatch':
|
||||||
if ($this->maniaControl->mapManager->getCurrentMap()->getGame() == 'sm') {
|
if ($this->maniaControl->mapManager->getCurrentMap()->getGame() == 'sm') {
|
||||||
$this->triggerCallback($callbackName, $callback);
|
$this->triggerCallback($callbackName, $callback);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'ManiaPlanet.BeginMap':
|
case 'ManiaPlanet.BeginMap':
|
||||||
$this->maniaControl->mapManager->handleBeginMap($callback);
|
$this->maniaControl->mapManager->handleBeginMap($callback);
|
||||||
$this->triggerCallback($callbackName, $callback);
|
$this->triggerCallback($callbackName, $callback);
|
||||||
@ -223,7 +191,7 @@ class CallbackManager {
|
|||||||
if ($this->maniaControl->mapManager->getCurrentMap()->getGame() == 'sm') {
|
if ($this->maniaControl->mapManager->getCurrentMap()->getGame() == 'sm') {
|
||||||
$this->triggerCallback($callbackName, $callback);
|
$this->triggerCallback($callbackName, $callback);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'ManiaPlanet.EndMap':
|
case 'ManiaPlanet.EndMap':
|
||||||
$this->maniaControl->mapManager->handleEndMap($callback);
|
$this->maniaControl->mapManager->handleEndMap($callback);
|
||||||
$this->triggerCallback($callbackName, $callback);
|
$this->triggerCallback($callbackName, $callback);
|
||||||
@ -242,6 +210,22 @@ class CallbackManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trigger a specific Callback
|
||||||
|
*
|
||||||
|
* @param string $callbackName
|
||||||
|
*/
|
||||||
|
public function triggerCallback($callbackName) {
|
||||||
|
if (!array_key_exists($callbackName, $this->callbackListeners)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$params = func_get_args();
|
||||||
|
$params = array_slice($params, 1, count($params), true);
|
||||||
|
foreach ($this->callbackListeners[$callbackName] as $listener) {
|
||||||
|
call_user_func_array(array($listener[0], $listener[1]), $params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle the given Script Callback
|
* Handle the given Script Callback
|
||||||
*
|
*
|
||||||
@ -253,4 +237,20 @@ class CallbackManager {
|
|||||||
$this->triggerScriptCallback($scriptCallbackName, $scriptCallbackData);
|
$this->triggerScriptCallback($scriptCallbackName, $scriptCallbackData);
|
||||||
$this->triggerCallback(Callbacks::SCRIPTCALLBACK, $scriptCallbackName, $scriptCallbackData[1]);
|
$this->triggerCallback(Callbacks::SCRIPTCALLBACK, $scriptCallbackName, $scriptCallbackData[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trigger a specific Script Callback
|
||||||
|
*
|
||||||
|
* @param string $callbackName
|
||||||
|
*/
|
||||||
|
public function triggerScriptCallback($callbackName) {
|
||||||
|
if (!array_key_exists($callbackName, $this->scriptCallbackListener)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$params = func_get_args();
|
||||||
|
$params = array_slice($params, 1, count($params), true);
|
||||||
|
foreach ($this->scriptCallbackListener[$callbackName] as $listener) {
|
||||||
|
call_user_func_array(array($listener[0], $listener[1]), $params);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace ManiaControl\Callbacks;
|
namespace ManiaControl\Callbacks;
|
||||||
|
|
||||||
//TODO method class for all the libxmlrpc get Methods, to fetch the callback asnyc
|
//TODO method class for all the libxmlrpc get Methods, to fetch the callback asnyc
|
||||||
/**
|
/**
|
||||||
* Callbacks Interface
|
* Callbacks Interface
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
interface Callbacks {
|
interface Callbacks {
|
||||||
|
@ -8,9 +8,9 @@ use ManiaControl\ManiaControl;
|
|||||||
/**
|
/**
|
||||||
* Class managing & converting LibXmlRpc Callbacks
|
* Class managing & converting LibXmlRpc Callbacks
|
||||||
*
|
*
|
||||||
* @author ManiaControl Team
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class LibXmlRpcCallbackManager implements CallbackListener {
|
class LibXmlRpcCallbackManager implements CallbackListener {
|
||||||
/*
|
/*
|
||||||
@ -21,7 +21,7 @@ class LibXmlRpcCallbackManager implements CallbackListener {
|
|||||||
/**
|
/**
|
||||||
* Create a new LibXmlRpc Callbacks Instance
|
* Create a new LibXmlRpc Callbacks Instance
|
||||||
*
|
*
|
||||||
* @param ManiaControl $maniaControl
|
* @param ManiaControl $maniaControl
|
||||||
* @param CallbackManager $callbackManager
|
* @param CallbackManager $callbackManager
|
||||||
*/
|
*/
|
||||||
public function __construct(ManiaControl $maniaControl, CallbackManager $callbackManager) {
|
public function __construct(ManiaControl $maniaControl, CallbackManager $callbackManager) {
|
||||||
@ -33,10 +33,10 @@ class LibXmlRpcCallbackManager implements CallbackListener {
|
|||||||
* Handle Script Callbacks
|
* Handle Script Callbacks
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*/
|
*/
|
||||||
public function handleScriptCallbacks($name, array $data) {
|
public function handleScriptCallbacks($name, array $data) {
|
||||||
switch($name) {
|
switch ($name) {
|
||||||
case 'LibXmlRpc_BeginMatch':
|
case 'LibXmlRpc_BeginMatch':
|
||||||
$this->maniaControl->callbackManager->triggerCallback(Callbacks::BEGINMATCH, $data[0]);
|
$this->maniaControl->callbackManager->triggerCallback(Callbacks::BEGINMATCH, $data[0]);
|
||||||
break;
|
break;
|
||||||
|
@ -7,8 +7,8 @@ use ManiaControl\ManiaControl;
|
|||||||
/**
|
/**
|
||||||
* Class handling and parsing ShootMania Callbacks
|
* Class handling and parsing ShootMania Callbacks
|
||||||
*
|
*
|
||||||
* @author steeffeen
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class ShootManiaCallbacks implements CallbackListener {
|
class ShootManiaCallbacks implements CallbackListener {
|
||||||
@ -28,7 +28,7 @@ class ShootManiaCallbacks implements CallbackListener {
|
|||||||
/**
|
/**
|
||||||
* Create a new ShootMania Callbacks Instance
|
* Create a new ShootMania Callbacks Instance
|
||||||
*
|
*
|
||||||
* @param ManiaControl $maniaControl
|
* @param ManiaControl $maniaControl
|
||||||
* @param CallbackManager $callbackManager
|
* @param CallbackManager $callbackManager
|
||||||
*/
|
*/
|
||||||
public function __construct(ManiaControl $maniaControl, CallbackManager $callbackManager) {
|
public function __construct(ManiaControl $maniaControl, CallbackManager $callbackManager) {
|
||||||
@ -43,11 +43,11 @@ class ShootManiaCallbacks implements CallbackListener {
|
|||||||
/**
|
/**
|
||||||
* Handle Script Callbacks
|
* Handle Script Callbacks
|
||||||
*
|
*
|
||||||
* @param $name
|
* @param string $name
|
||||||
* @param $data
|
* @param array $data
|
||||||
*/
|
*/
|
||||||
public function handleScriptCallbacks($name, $data) {
|
public function handleScriptCallbacks($name, $data) {
|
||||||
switch($name) {
|
switch ($name) {
|
||||||
case 'LibXmlRpc_Rankings':
|
case 'LibXmlRpc_Rankings':
|
||||||
$this->maniaControl->server->rankingManager->updateRankings($data[0]);
|
$this->maniaControl->server->rankingManager->updateRankings($data[0]);
|
||||||
break;
|
break;
|
||||||
@ -63,7 +63,7 @@ class ShootManiaCallbacks implements CallbackListener {
|
|||||||
/**
|
/**
|
||||||
* Triggers the AFK Status of an Player
|
* Triggers the AFK Status of an Player
|
||||||
*
|
*
|
||||||
* @param $login
|
* @param string $login
|
||||||
*/
|
*/
|
||||||
private function triggerAfkStatus($login) {
|
private function triggerAfkStatus($login) {
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
|
@ -5,9 +5,9 @@ namespace ManiaControl\Callbacks;
|
|||||||
/**
|
/**
|
||||||
* Interface for TimerListener
|
* Interface for TimerListener
|
||||||
*
|
*
|
||||||
* @author kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
interface TimerListener {
|
interface TimerListener {
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,9 @@ use ManiaControl\ManiaControl;
|
|||||||
/**
|
/**
|
||||||
* Class for managing Timers
|
* Class for managing Timers
|
||||||
*
|
*
|
||||||
* @author kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class TimerManager {
|
class TimerManager {
|
||||||
/*
|
/*
|
||||||
@ -38,29 +38,13 @@ class TimerManager {
|
|||||||
$this->registerTimerListening($listener, $method, $time, true);
|
$this->registerTimerListening($listener, $method, $time, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Unregister a Timer Listening
|
|
||||||
* @param TimerListener $listener
|
|
||||||
* @param $method
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function unregisterTimerListening(TimerListener $listener, $method){
|
|
||||||
foreach($this->timerListenings as $key => $listening){
|
|
||||||
if($listening->listener == $listener && $listening->method == $method){
|
|
||||||
unset($this->timerListenings[$key]);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a Timer Listening, note < 10ms it can get inaccurate
|
* Register a Timer Listening, note < 10ms it can get inaccurate
|
||||||
*
|
*
|
||||||
* @param TimerListener $listener
|
* @param TimerListener $listener
|
||||||
* @param string $method
|
* @param string $method
|
||||||
* @param float $time
|
* @param float $time
|
||||||
* @param bool $oneTime
|
* @param bool $oneTime
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function registerTimerListening(TimerListener $listener, $method, $time, $oneTime = false) {
|
public function registerTimerListening(TimerListener $listener, $method, $time, $oneTime = false) {
|
||||||
@ -71,14 +55,14 @@ class TimerManager {
|
|||||||
|
|
||||||
//Init the Timer Listening
|
//Init the Timer Listening
|
||||||
// TODO: extra model class
|
// TODO: extra model class
|
||||||
$listening = new \stdClass();
|
$listening = new \stdClass();
|
||||||
$listening->listener = $listener;
|
$listening->listener = $listener;
|
||||||
$listening->method = $method;
|
$listening->method = $method;
|
||||||
$listening->deltaTime = $time / 1000;
|
$listening->deltaTime = $time / 1000;
|
||||||
$listening->oneTime = $oneTime;
|
$listening->oneTime = $oneTime;
|
||||||
if($oneTime){
|
if ($oneTime) {
|
||||||
$listening->lastTrigger = microtime(true);
|
$listening->lastTrigger = microtime(true);
|
||||||
}else{
|
} else {
|
||||||
$listening->lastTrigger = -1;
|
$listening->lastTrigger = -1;
|
||||||
}
|
}
|
||||||
array_push($this->timerListenings, $listening);
|
array_push($this->timerListenings, $listening);
|
||||||
@ -86,6 +70,23 @@ class TimerManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unregister a Timer Listening
|
||||||
|
*
|
||||||
|
* @param TimerListener $listener
|
||||||
|
* @param $method
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function unregisterTimerListening(TimerListener $listener, $method) {
|
||||||
|
foreach ($this->timerListenings as $key => $listening) {
|
||||||
|
if ($listening->listener == $listener && $listening->method == $method) {
|
||||||
|
unset($this->timerListenings[$key]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a Timer Listener
|
* Remove a Timer Listener
|
||||||
*
|
*
|
||||||
@ -94,7 +95,7 @@ class TimerManager {
|
|||||||
*/
|
*/
|
||||||
public function unregisterTimerListenings(TimerListener $listener) {
|
public function unregisterTimerListenings(TimerListener $listener) {
|
||||||
$removed = false;
|
$removed = false;
|
||||||
foreach($this->timerListenings as $key => &$listening) {
|
foreach ($this->timerListenings as $key => &$listening) {
|
||||||
if ($listening->listener != $listener) {
|
if ($listening->listener != $listener) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -109,7 +110,7 @@ class TimerManager {
|
|||||||
*/
|
*/
|
||||||
public function manageTimings() {
|
public function manageTimings() {
|
||||||
$time = microtime(true);
|
$time = microtime(true);
|
||||||
foreach($this->timerListenings as $key => &$listening) {
|
foreach ($this->timerListenings as $key => &$listening) {
|
||||||
|
|
||||||
if (($listening->lastTrigger + $listening->deltaTime) <= $time) {
|
if (($listening->lastTrigger + $listening->deltaTime) <= $time) {
|
||||||
//Increase the lastTrigger time manually (to improve accuracy)
|
//Increase the lastTrigger time manually (to improve accuracy)
|
||||||
|
@ -4,10 +4,10 @@ namespace ManiaControl\Commands;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for Command Listeners
|
* Interface for Command Listeners
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
interface CommandListener {
|
interface CommandListener {
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,9 @@ use ManiaControl\ManiaControl;
|
|||||||
/**
|
/**
|
||||||
* Class for handling Chat Commands
|
* Class for handling Chat Commands
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class CommandManager implements CallbackListener {
|
class CommandManager implements CallbackListener {
|
||||||
/*
|
/*
|
||||||
@ -50,7 +50,7 @@ class CommandManager implements CallbackListener {
|
|||||||
public function registerCommandListener($commandName, CommandListener $listener, $method, $adminCommand = false, $description = '') {
|
public function registerCommandListener($commandName, CommandListener $listener, $method, $adminCommand = false, $description = '') {
|
||||||
if (is_array($commandName)) {
|
if (is_array($commandName)) {
|
||||||
$success = true;
|
$success = true;
|
||||||
foreach($commandName as $command) {
|
foreach ($commandName as $command) {
|
||||||
if (!$this->registerCommandListener($command, $listener, $method, $adminCommand, $description)) {
|
if (!$this->registerCommandListener($command, $listener, $method, $adminCommand, $description)) {
|
||||||
$success = false;
|
$success = false;
|
||||||
}
|
}
|
||||||
@ -92,16 +92,16 @@ class CommandManager implements CallbackListener {
|
|||||||
*/
|
*/
|
||||||
public function unregisterCommandListener(CommandListener $listener) {
|
public function unregisterCommandListener(CommandListener $listener) {
|
||||||
$removed = false;
|
$removed = false;
|
||||||
foreach($this->commandListeners as &$listeners) {
|
foreach ($this->commandListeners as &$listeners) {
|
||||||
foreach($listeners as $key => &$listenerCallback) {
|
foreach ($listeners as $key => &$listenerCallback) {
|
||||||
if ($listenerCallback[0] == $listener) {
|
if ($listenerCallback[0] == $listener) {
|
||||||
unset($listeners[$key]);
|
unset($listeners[$key]);
|
||||||
$removed = true;
|
$removed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach($this->adminCommandListeners as &$listeners) {
|
foreach ($this->adminCommandListeners as &$listeners) {
|
||||||
foreach($listeners as $key => &$listenerCallback) {
|
foreach ($listeners as $key => &$listenerCallback) {
|
||||||
if ($listenerCallback[0] == $listener) {
|
if ($listenerCallback[0] == $listener) {
|
||||||
unset($listeners[$key]);
|
unset($listeners[$key]);
|
||||||
$removed = true;
|
$removed = true;
|
||||||
@ -152,7 +152,7 @@ class CommandManager implements CallbackListener {
|
|||||||
|
|
||||||
// Compose uniformed message
|
// Compose uniformed message
|
||||||
$message = '//' . $command;
|
$message = '//' . $command;
|
||||||
foreach($commandArray as $commandPart) {
|
foreach ($commandArray as $commandPart) {
|
||||||
$message .= ' ' . $commandPart;
|
$message .= ' ' . $commandPart;
|
||||||
}
|
}
|
||||||
$callback[1][2] = $message;
|
$callback[1][2] = $message;
|
||||||
@ -167,7 +167,7 @@ class CommandManager implements CallbackListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Inform command listeners
|
// Inform command listeners
|
||||||
foreach($commandListeners[$command] as $listener) {
|
foreach ($commandListeners[$command] as $listener) {
|
||||||
call_user_func(array($listener[0], $listener[1]), $callback, $player);
|
call_user_func(array($listener[0], $listener[1]), $callback, $player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,19 +7,18 @@ use FML\Controls\Label;
|
|||||||
use FML\Controls\Quads\Quad_BgsPlayerCard;
|
use FML\Controls\Quads\Quad_BgsPlayerCard;
|
||||||
use FML\ManiaLink;
|
use FML\ManiaLink;
|
||||||
use FML\Script\Features\Paging;
|
use FML\Script\Features\Paging;
|
||||||
|
|
||||||
use ManiaControl\Callbacks\CallbackListener;
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
use ManiaControl\Callbacks\CallbackManager;
|
use ManiaControl\Callbacks\CallbackManager;
|
||||||
use ManiaControl\Manialinks\ManialinkManager;
|
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
|
use ManiaControl\Manialinks\ManialinkManager;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Help Manager
|
* Help Manager
|
||||||
*
|
*
|
||||||
* @author kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class HelpManager implements CommandListener, CallbackListener {
|
class HelpManager implements CommandListener, CallbackListener {
|
||||||
/*
|
/*
|
||||||
@ -59,24 +58,24 @@ class HelpManager implements CommandListener, CallbackListener {
|
|||||||
* @param Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
public function command_adminHelp(array $chat, Player $player) {
|
public function command_adminHelp(array $chat, Player $player) {
|
||||||
$showCommands = array();
|
$showCommands = array();
|
||||||
$registeredMethods = array();
|
$registeredMethods = array();
|
||||||
foreach(array_reverse($this->adminCommands) as $command) {
|
foreach (array_reverse($this->adminCommands) as $command) {
|
||||||
if(array_key_exists($command['Method'], $registeredMethods) && $showCommands[$registeredMethods[$command['Method']]]['Description'] == $command['Description']) {
|
if (array_key_exists($command['Method'], $registeredMethods) && $showCommands[$registeredMethods[$command['Method']]]['Description'] == $command['Description']) {
|
||||||
$name = $registeredMethods[$command['Method']];
|
$name = $registeredMethods[$command['Method']];
|
||||||
$showCommands[$name]['Name'] .= '|'.$command['Name'];
|
$showCommands[$name]['Name'] .= '|' . $command['Name'];
|
||||||
} else {
|
} else {
|
||||||
$showCommands[$command['Name']] = $command;
|
$showCommands[$command['Name']] = $command;
|
||||||
$registeredMethods[$command['Method']] = $command['Name'];
|
$registeredMethods[$command['Method']] = $command['Name'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
usort($showCommands, function($a, $b) {
|
usort($showCommands, function ($a, $b) {
|
||||||
return strcmp($a["Name"], $b["Name"]);
|
return strcmp($a["Name"], $b["Name"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
$message = 'Supported Admin Commands: ';
|
$message = 'Supported Admin Commands: ';
|
||||||
foreach($showCommands as $command) {
|
foreach ($showCommands as $command) {
|
||||||
$message .= $command['Name'] . ',';
|
$message .= $command['Name'] . ',';
|
||||||
}
|
}
|
||||||
$message = substr($message, 0, -1);
|
$message = substr($message, 0, -1);
|
||||||
@ -90,24 +89,24 @@ class HelpManager implements CommandListener, CallbackListener {
|
|||||||
* @param Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
public function command_playerHelp(array $chat, Player $player) {
|
public function command_playerHelp(array $chat, Player $player) {
|
||||||
$showCommands = array();
|
$showCommands = array();
|
||||||
$registeredMethods = array();
|
$registeredMethods = array();
|
||||||
foreach(array_reverse($this->playerCommands) as $command) {
|
foreach (array_reverse($this->playerCommands) as $command) {
|
||||||
if(array_key_exists($command['Method'], $registeredMethods) && $showCommands[$registeredMethods[$command['Method']]]['Description'] == $command['Description']) {
|
if (array_key_exists($command['Method'], $registeredMethods) && $showCommands[$registeredMethods[$command['Method']]]['Description'] == $command['Description']) {
|
||||||
$name = $registeredMethods[$command['Method']];
|
$name = $registeredMethods[$command['Method']];
|
||||||
$showCommands[$name]['Name'] .= '|'.$command['Name'];
|
$showCommands[$name]['Name'] .= '|' . $command['Name'];
|
||||||
} else {
|
} else {
|
||||||
$showCommands[$command['Name']] = $command;
|
$showCommands[$command['Name']] = $command;
|
||||||
$registeredMethods[$command['Method']] = $command['Name'];
|
$registeredMethods[$command['Method']] = $command['Name'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
usort($showCommands, function($a, $b) {
|
usort($showCommands, function ($a, $b) {
|
||||||
return strcmp($a["Name"], $b["Name"]);
|
return strcmp($a["Name"], $b["Name"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
$message = 'Supported Player Commands: ';
|
$message = 'Supported Player Commands: ';
|
||||||
foreach($showCommands as $command) {
|
foreach ($showCommands as $command) {
|
||||||
$message .= $command['Name'] . ',';
|
$message .= $command['Name'] . ',';
|
||||||
}
|
}
|
||||||
$message = substr($message, 0, -1);
|
$message = substr($message, 0, -1);
|
||||||
@ -124,16 +123,6 @@ class HelpManager implements CommandListener, CallbackListener {
|
|||||||
$this->prepareHelpAll($this->playerCommands, $player);
|
$this->prepareHelpAll($this->playerCommands, $player);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Shows a ManiaLink list of Admin Commands
|
|
||||||
*
|
|
||||||
* @param array $chat
|
|
||||||
* @param Player $player
|
|
||||||
*/
|
|
||||||
public function command_adminHelpAll(array $chat, Player $player) {
|
|
||||||
$this->prepareHelpAll($this->adminCommands, $player);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares the commands for the HelpAll ManiaLink.
|
* Prepares the commands for the HelpAll ManiaLink.
|
||||||
*
|
*
|
||||||
@ -141,24 +130,24 @@ class HelpManager implements CommandListener, CallbackListener {
|
|||||||
* @param $player
|
* @param $player
|
||||||
*/
|
*/
|
||||||
private function prepareHelpAll($commands, $player) {
|
private function prepareHelpAll($commands, $player) {
|
||||||
$showCommands = array();
|
$showCommands = array();
|
||||||
$registeredMethods = array();
|
$registeredMethods = array();
|
||||||
foreach(array_reverse($commands) as $command) {
|
foreach (array_reverse($commands) as $command) {
|
||||||
if(array_key_exists($command['Method'], $registeredMethods)) {
|
if (array_key_exists($command['Method'], $registeredMethods)) {
|
||||||
if($showCommands[$registeredMethods[$command['Method']]]['Description'] == $command['Description']) {
|
if ($showCommands[$registeredMethods[$command['Method']]]['Description'] == $command['Description']) {
|
||||||
$name = $registeredMethods[$command['Method']];
|
$name = $registeredMethods[$command['Method']];
|
||||||
$showCommands[$name]['Name'] .= '|'.$command['Name'];
|
$showCommands[$name]['Name'] .= '|' . $command['Name'];
|
||||||
} else {
|
} else {
|
||||||
$showCommands[$command['Name']] = $command;
|
$showCommands[$command['Name']] = $command;
|
||||||
$registeredMethods[$command['Method']] = $command['Name'];
|
$registeredMethods[$command['Method']] = $command['Name'];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$showCommands[$command['Name']] = $command;
|
$showCommands[$command['Name']] = $command;
|
||||||
$registeredMethods[$command['Method']] = $command['Name'];
|
$registeredMethods[$command['Method']] = $command['Name'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
usort($showCommands, function($a, $b) {
|
usort($showCommands, function ($a, $b) {
|
||||||
return strcmp($a["Name"], $b["Name"]);
|
return strcmp($a["Name"], $b["Name"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -177,8 +166,8 @@ class HelpManager implements CommandListener, CallbackListener {
|
|||||||
|
|
||||||
// create manialink
|
// create manialink
|
||||||
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
||||||
$script = $maniaLink->getScript();
|
$script = $maniaLink->getScript();
|
||||||
$paging = new Paging();
|
$paging = new Paging();
|
||||||
$script->addFeature($paging);
|
$script->addFeature($paging);
|
||||||
|
|
||||||
// Main frame
|
// Main frame
|
||||||
@ -203,7 +192,7 @@ class HelpManager implements CommandListener, CallbackListener {
|
|||||||
$i = 1;
|
$i = 1;
|
||||||
$y = $y - 10;
|
$y = $y - 10;
|
||||||
$pageFrames = array();
|
$pageFrames = array();
|
||||||
foreach($commands as $command) {
|
foreach ($commands as $command) {
|
||||||
if (!isset($pageFrame)) {
|
if (!isset($pageFrame)) {
|
||||||
$pageFrame = new Frame();
|
$pageFrame = new Frame();
|
||||||
$frame->add($pageFrame);
|
$frame->add($pageFrame);
|
||||||
@ -227,7 +216,7 @@ class HelpManager implements CommandListener, CallbackListener {
|
|||||||
$lineQuad->setZ(0.001);
|
$lineQuad->setZ(0.001);
|
||||||
}
|
}
|
||||||
|
|
||||||
$array = array($command['Name'] => $x + 5, $command['Description'] => $x + 50);
|
$array = array($command['Name'] => $x + 5, $command['Description'] => $x + 50);
|
||||||
$labels = $this->maniaControl->manialinkManager->labelLine($playerFrame, $array);
|
$labels = $this->maniaControl->manialinkManager->labelLine($playerFrame, $array);
|
||||||
|
|
||||||
/** @var Label $label */
|
/** @var Label $label */
|
||||||
@ -245,6 +234,16 @@ class HelpManager implements CommandListener, CallbackListener {
|
|||||||
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'HelpAllList');
|
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'HelpAllList');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows a ManiaLink list of Admin Commands
|
||||||
|
*
|
||||||
|
* @param array $chat
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
public function command_adminHelpAll(array $chat, Player $player) {
|
||||||
|
$this->prepareHelpAll($this->adminCommands, $player);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a new Command
|
* Registers a new Command
|
||||||
*
|
*
|
||||||
@ -254,7 +253,7 @@ class HelpManager implements CommandListener, CallbackListener {
|
|||||||
* @param $method
|
* @param $method
|
||||||
*/
|
*/
|
||||||
public function registerCommand($name, $adminCommand = false, $description = '', $method) {
|
public function registerCommand($name, $adminCommand = false, $description = '', $method) {
|
||||||
if($adminCommand) {
|
if ($adminCommand) {
|
||||||
array_push($this->adminCommands, array("Name" => $name, "Description" => $description, "Method" => $method));
|
array_push($this->adminCommands, array("Name" => $name, "Description" => $description, "Method" => $method));
|
||||||
} else {
|
} else {
|
||||||
array_push($this->playerCommands, array("Name" => $name, "Description" => $description, "Method" => $method));
|
array_push($this->playerCommands, array("Name" => $name, "Description" => $description, "Method" => $method));
|
||||||
|
@ -23,23 +23,23 @@ use ManiaControl\Players\Player;
|
|||||||
/**
|
/**
|
||||||
* Class managing ingame ManiaControl Configuration
|
* Class managing ingame ManiaControl Configuration
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class Configurator implements CallbackListener, CommandListener, ManialinkPageAnswerListener {
|
class Configurator implements CallbackListener, CommandListener, ManialinkPageAnswerListener {
|
||||||
/*
|
/*
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const ACTION_TOGGLEMENU = 'Configurator.ToggleMenuAction';
|
const ACTION_TOGGLEMENU = 'Configurator.ToggleMenuAction';
|
||||||
const ACTION_SAVECONFIG = 'Configurator.SaveConfigAction';
|
const ACTION_SAVECONFIG = 'Configurator.SaveConfigAction';
|
||||||
const ACTION_SELECTMENU = 'Configurator.SelectMenu';
|
const ACTION_SELECTMENU = 'Configurator.SelectMenu';
|
||||||
const SETTING_MENU_POSX = 'Menu Widget Position: X';
|
const SETTING_MENU_POSX = 'Menu Widget Position: X';
|
||||||
const SETTING_MENU_POSY = 'Menu Widget Position: Y';
|
const SETTING_MENU_POSY = 'Menu Widget Position: Y';
|
||||||
const SETTING_MENU_WIDTH = 'Menu Widget Width';
|
const SETTING_MENU_WIDTH = 'Menu Widget Width';
|
||||||
const SETTING_MENU_HEIGHT = 'Menu Widget Height';
|
const SETTING_MENU_HEIGHT = 'Menu Widget Height';
|
||||||
const SETTING_MENU_STYLE = 'Menu Widget BackgroundQuad Style';
|
const SETTING_MENU_STYLE = 'Menu Widget BackgroundQuad Style';
|
||||||
const SETTING_MENU_SUBSTYLE = 'Menu Widget BackgroundQuad Substyle';
|
const SETTING_MENU_SUBSTYLE = 'Menu Widget BackgroundQuad Substyle';
|
||||||
const SETTING_PERMISSION_OPEN_CONFIGURATOR = 'Open Configurator';
|
const SETTING_PERMISSION_OPEN_CONFIGURATOR = 'Open Configurator';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -100,18 +100,13 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle Config Admin Command
|
* Add Menu Item to the Actions Menu
|
||||||
*
|
|
||||||
* @param array $callback
|
|
||||||
* @param Player $player
|
|
||||||
*/
|
*/
|
||||||
public function handleConfigCommand(array $callback, Player $player) {
|
private function addActionsMenuItem() {
|
||||||
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_OPEN_CONFIGURATOR)) {
|
$itemQuad = new Quad_UIConstruction_Buttons();
|
||||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Tools);
|
||||||
return;
|
$itemQuad->setAction(self::ACTION_TOGGLEMENU);
|
||||||
}
|
$this->maniaControl->actionsMenu->addAdminMenuItem($itemQuad, 100, 'Settings');
|
||||||
|
|
||||||
$this->showMenu($player);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -124,46 +119,18 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reopen the Menu
|
* Handle Config Admin Command
|
||||||
*
|
|
||||||
* @param Player $player
|
|
||||||
* @param int $menuId
|
|
||||||
*/
|
|
||||||
public function reopenMenu(Player $player, $menuId = 0) {
|
|
||||||
$this->showMenu($player, $menuId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle toggle menu action
|
|
||||||
*
|
*
|
||||||
* @param array $callback
|
* @param array $callback
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
public function handleToggleMenuAction(array $callback, Player $player) {
|
public function handleConfigCommand(array $callback, Player $player) {
|
||||||
$this->toggleMenu($player);
|
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_OPEN_CONFIGURATOR)) {
|
||||||
}
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||||
|
return;
|
||||||
/**
|
|
||||||
* Save the config data received from the manialink
|
|
||||||
*
|
|
||||||
* @param array $callback
|
|
||||||
* @param Player $player
|
|
||||||
*/
|
|
||||||
public function handleSaveConfigAction(array $callback, Player $player) {
|
|
||||||
foreach($this->menus as $menu) {
|
|
||||||
/** @var ConfiguratorMenu $menu */
|
|
||||||
$menu->saveConfigData($callback[1], $player);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$this->showMenu($player);
|
||||||
* Handle PlayerDisconnect callback
|
|
||||||
*
|
|
||||||
* @param array $callback
|
|
||||||
*/
|
|
||||||
public function handlePlayerDisconnect(array $callback) {
|
|
||||||
$login = $callback[1][0];
|
|
||||||
unset($this->playersMenuShown[$login]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -178,73 +145,10 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
|||||||
$this->playersMenuShown[$player->login] = true;
|
$this->playersMenuShown[$player->login] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Unset the player if he opened another Main Widget
|
|
||||||
*
|
|
||||||
* @param Player $player
|
|
||||||
* @param $openedWidget
|
|
||||||
*/
|
|
||||||
public function handleWidgetOpened(Player $player, $openedWidget) {
|
|
||||||
//unset when another main widget got opened
|
|
||||||
if ($openedWidget != 'Configurator') {
|
|
||||||
unset($this->playersMenuShown[$player->login]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Widget get closed -> unset player
|
|
||||||
*
|
|
||||||
* @param \ManiaControl\Players\Player $player
|
|
||||||
*/
|
|
||||||
public function closeWidget(Player $player) {
|
|
||||||
unset($this->playersMenuShown[$player->login]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hide the Menu for the Player
|
|
||||||
*
|
|
||||||
* @param Player $player
|
|
||||||
*/
|
|
||||||
public function hideMenu(Player $player) {
|
|
||||||
unset($this->playersMenuShown[$player->login]);
|
|
||||||
$this->maniaControl->manialinkManager->closeWidget($player);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Toggle the Menu for the Player
|
|
||||||
*
|
|
||||||
* @param Player $player
|
|
||||||
*/
|
|
||||||
public function toggleMenu(Player $player) {
|
|
||||||
if (isset($this->playersMenuShown[$player->login])) {
|
|
||||||
$this->hideMenu($player);
|
|
||||||
} else {
|
|
||||||
$this->showMenu($player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the Menu Id
|
|
||||||
*
|
|
||||||
* @param $name
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getMenuId($name) {
|
|
||||||
$i = 0;
|
|
||||||
foreach($this->menus as $menu) {
|
|
||||||
/** @var ConfiguratorMenu $menu */
|
|
||||||
if ($menu == $name || $menu->getTitle() == $name) {
|
|
||||||
return $i;
|
|
||||||
}
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build Menu ManiaLink if necessary
|
* Build Menu ManiaLink if necessary
|
||||||
*
|
*
|
||||||
* @param int $menuIdShown
|
* @param int $menuIdShown
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
* @return \FML\ManiaLink
|
* @return \FML\ManiaLink
|
||||||
*/
|
*/
|
||||||
@ -287,13 +191,13 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
|||||||
$menusFrame->setX($menuWidth * -0.5 + $menuListWidth + $subMenuWidth * 0.5);
|
$menusFrame->setX($menuWidth * -0.5 + $menuListWidth + $subMenuWidth * 0.5);
|
||||||
|
|
||||||
// Create script and features
|
// Create script and features
|
||||||
$script = $manialink->getScript();
|
$script = $manialink->getScript();
|
||||||
$menuScript = new Menu();
|
$menuScript = new Menu();
|
||||||
$script->addFeature($menuScript);
|
$script->addFeature($menuScript);
|
||||||
|
|
||||||
$menuItemY = $menuHeight * 0.42;
|
$menuItemY = $menuHeight * 0.42;
|
||||||
$menuId = 0;
|
$menuId = 0;
|
||||||
foreach($this->menus as $menu) {
|
foreach ($this->menus as $menu) {
|
||||||
/** @var ConfiguratorMenu $menu */
|
/** @var ConfiguratorMenu $menu */
|
||||||
|
|
||||||
// Add title
|
// Add title
|
||||||
@ -309,7 +213,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
|||||||
if ($menuId == $menuIdShown) {
|
if ($menuId == $menuIdShown) {
|
||||||
$menuControl = $menu->getMenu($subMenuWidth, $subMenuHeight, $script, $player);
|
$menuControl = $menu->getMenu($subMenuWidth, $subMenuHeight, $script, $player);
|
||||||
$menusFrame->add($menuControl);
|
$menusFrame->add($menuControl);
|
||||||
$menuScript->addElement($menuItemLabel, $menuControl);
|
$menuScript->addElement($menuItemLabel, $menuControl);
|
||||||
}
|
}
|
||||||
|
|
||||||
$menuItemY -= $menuItemHeight * 1.1;
|
$menuItemY -= $menuItemHeight * 1.1;
|
||||||
@ -345,10 +249,116 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
|||||||
$saveButton->setTranslate(true);
|
$saveButton->setTranslate(true);
|
||||||
$saveButton->setText('$zSave$z');
|
$saveButton->setText('$zSave$z');
|
||||||
$saveButton->setAction(self::ACTION_SAVECONFIG);
|
$saveButton->setAction(self::ACTION_SAVECONFIG);
|
||||||
|
|
||||||
return $manialink;
|
return $manialink;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reopen the Menu
|
||||||
|
*
|
||||||
|
* @param Player $player
|
||||||
|
* @param int $menuId
|
||||||
|
*/
|
||||||
|
public function reopenMenu(Player $player, $menuId = 0) {
|
||||||
|
$this->showMenu($player, $menuId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle toggle menu action
|
||||||
|
*
|
||||||
|
* @param array $callback
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
public function handleToggleMenuAction(array $callback, Player $player) {
|
||||||
|
$this->toggleMenu($player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggle the Menu for the Player
|
||||||
|
*
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
public function toggleMenu(Player $player) {
|
||||||
|
if (isset($this->playersMenuShown[$player->login])) {
|
||||||
|
$this->hideMenu($player);
|
||||||
|
} else {
|
||||||
|
$this->showMenu($player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hide the Menu for the Player
|
||||||
|
*
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
public function hideMenu(Player $player) {
|
||||||
|
unset($this->playersMenuShown[$player->login]);
|
||||||
|
$this->maniaControl->manialinkManager->closeWidget($player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the config data received from the manialink
|
||||||
|
*
|
||||||
|
* @param array $callback
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
public function handleSaveConfigAction(array $callback, Player $player) {
|
||||||
|
foreach ($this->menus as $menu) {
|
||||||
|
/** @var ConfiguratorMenu $menu */
|
||||||
|
$menu->saveConfigData($callback[1], $player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle PlayerDisconnect callback
|
||||||
|
*
|
||||||
|
* @param array $callback
|
||||||
|
*/
|
||||||
|
public function handlePlayerDisconnect(array $callback) {
|
||||||
|
$login = $callback[1][0];
|
||||||
|
unset($this->playersMenuShown[$login]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unset the player if he opened another Main Widget
|
||||||
|
*
|
||||||
|
* @param Player $player
|
||||||
|
* @param $openedWidget
|
||||||
|
*/
|
||||||
|
public function handleWidgetOpened(Player $player, $openedWidget) {
|
||||||
|
//unset when another main widget got opened
|
||||||
|
if ($openedWidget != 'Configurator') {
|
||||||
|
unset($this->playersMenuShown[$player->login]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Widget get closed -> unset player
|
||||||
|
*
|
||||||
|
* @param \ManiaControl\Players\Player $player
|
||||||
|
*/
|
||||||
|
public function closeWidget(Player $player) {
|
||||||
|
unset($this->playersMenuShown[$player->login]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the Menu Id
|
||||||
|
*
|
||||||
|
* @param $name
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getMenuId($name) {
|
||||||
|
$i = 0;
|
||||||
|
foreach ($this->menus as $menu) {
|
||||||
|
/** @var ConfiguratorMenu $menu */
|
||||||
|
if ($menu == $name || $menu->getTitle() == $name) {
|
||||||
|
return $i;
|
||||||
|
}
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle ManialinkPageAnswer Callback
|
* Handle ManialinkPageAnswer Callback
|
||||||
*
|
*
|
||||||
@ -367,14 +377,4 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
|||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
$this->showMenu($player, intval($actionArray[2]));
|
$this->showMenu($player, intval($actionArray[2]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Add Menu Item to the Actions Menu
|
|
||||||
*/
|
|
||||||
private function addActionsMenuItem() {
|
|
||||||
$itemQuad = new Quad_UIConstruction_Buttons();
|
|
||||||
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Tools);
|
|
||||||
$itemQuad->setAction(self::ACTION_TOGGLEMENU);
|
|
||||||
$this->maniaControl->actionsMenu->addAdminMenuItem($itemQuad, 100, 'Settings');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ namespace ManiaControl\Configurators;
|
|||||||
use FML\Controls\Control;
|
use FML\Controls\Control;
|
||||||
use FML\Controls\Entry;
|
use FML\Controls\Entry;
|
||||||
use FML\Controls\Frame;
|
use FML\Controls\Frame;
|
||||||
|
use FML\Controls\Labels\Label_Button;
|
||||||
use FML\Controls\Labels\Label_Text;
|
use FML\Controls\Labels\Label_Text;
|
||||||
use FML\Controls\Quads\Quad_Icons64x64_1;
|
use FML\Controls\Quads\Quad_Icons64x64_1;
|
||||||
use FML\Script\Features\Paging;
|
use FML\Script\Features\Paging;
|
||||||
@ -15,27 +16,26 @@ use ManiaControl\Callbacks\CallbackManager;
|
|||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
use ManiaControl\Players\PlayerManager;
|
use ManiaControl\Players\PlayerManager;
|
||||||
use FML\Controls\Labels\Label_Button;
|
|
||||||
use ManiaControl\Settings\SettingManager;
|
use ManiaControl\Settings\SettingManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class offering a Configurator for ManiaControl Settings
|
* Class offering a Configurator for ManiaControl Settings
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
|
class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
|
||||||
/*
|
/*
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const TITLE = 'ManiaControl Settings';
|
const TITLE = 'ManiaControl Settings';
|
||||||
const ACTION_PREFIX_SETTING = 'MCSetting.';
|
const ACTION_PREFIX_SETTING = 'MCSetting.';
|
||||||
const ACTION_PREFIX_SETTINGCLASS = 'MCSettingClass.';
|
const ACTION_PREFIX_SETTINGCLASS = 'MCSettingClass.';
|
||||||
const ACTION_SETTINGCLASS_BACK = 'MCSettingClassBack';
|
const ACTION_SETTINGCLASS_BACK = 'MCSettingClassBack';
|
||||||
const ACTION_SETTING_BOOL = 'MCSettings.ActionBoolSetting.';
|
const ACTION_SETTING_BOOL = 'MCSettings.ActionBoolSetting.';
|
||||||
const SETTING_PERMISSION_CHANGE_MC_SETTINGS = 'Change ManiaControl Settings';
|
const SETTING_PERMISSION_CHANGE_MC_SETTINGS = 'Change ManiaControl Settings';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Private Properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
@ -44,22 +44,22 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Script Settings Instance
|
* Create a new Script Settings Instance
|
||||||
*
|
*
|
||||||
* @param ManiaControl $maniaControl
|
* @param ManiaControl $maniaControl
|
||||||
*/
|
*/
|
||||||
public function __construct(ManiaControl $maniaControl) {
|
public function __construct(ManiaControl $maniaControl) {
|
||||||
$this->maniaControl = $maniaControl;
|
$this->maniaControl = $maniaControl;
|
||||||
|
|
||||||
// Register for callbacks
|
// Register for callbacks
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
|
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
|
||||||
|
|
||||||
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_MC_SETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_MC_SETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle Player Disconnect Callback
|
* Handle Player Disconnect Callback
|
||||||
*
|
*
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
public function handlePlayerDisconnect(Player $player) {
|
public function handlePlayerDisconnect(Player $player) {
|
||||||
@ -67,76 +67,191 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Menu Title
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getTitle() {
|
|
||||||
return self::TITLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
||||||
*/
|
*/
|
||||||
public function getMenu($width, $height, Script $script, Player $player) {
|
public function getMenu($width, $height, Script $script, Player $player) {
|
||||||
if (isset($this->playersSettingCategoryOpened[$player->login]) && strlen($this->playersSettingCategoryOpened[$player->login]) > 0) {
|
if (isset($this->playersSettingCategoryOpened[$player->login]) && strlen($this->playersSettingCategoryOpened[$player->login]) > 0) {
|
||||||
return $this->getMenuSettingsForClass($this->playersSettingCategoryOpened[$player->login], $width, $height, $script, $player);
|
return $this->getMenuSettingsForClass($this->playersSettingCategoryOpened[$player->login], $width, $height, $script, $player);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return $this->getMenuSettingClasses($width, $height, $script, $player);
|
return $this->getMenuSettingClasses($width, $height, $script, $player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Menu showing all possible Classes
|
* Get the Menu showing the Settings for the given Class
|
||||||
*
|
*
|
||||||
* @param float $width
|
* @param string $settingClass
|
||||||
* @param float $height
|
* @param float $width
|
||||||
|
* @param float $height
|
||||||
* @param Script $script
|
* @param Script $script
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
* @return \FML\Controls\Frame
|
* @return \FML\Controls\Frame
|
||||||
*/
|
*/
|
||||||
private function getMenuSettingClasses($width, $height, Script $script, Player $player) {
|
private function getMenuSettingsForClass($settingClass, $width, $height, Script $script, Player $player) {
|
||||||
$settingClasses = $this->maniaControl->settingManager->getSettingClasses(true);
|
$settings = $this->maniaControl->settingManager->getSettingsByClass($settingClass);
|
||||||
|
|
||||||
$paging = new Paging();
|
$paging = new Paging();
|
||||||
$script->addFeature($paging);
|
$script->addFeature($paging);
|
||||||
$frame = new Frame();
|
$frame = new Frame();
|
||||||
|
|
||||||
// Config
|
// Config
|
||||||
$pagerSize = 9.;
|
$pagerSize = 9.;
|
||||||
$settingHeight = 5.;
|
$settingHeight = 5.;
|
||||||
$pageMaxCount = 13;
|
$labelTextSize = 2;
|
||||||
$y = 0;
|
$pageMaxCount = 13;
|
||||||
|
|
||||||
// Pagers
|
// Pagers
|
||||||
$pagerPrev = new Quad_Icons64x64_1();
|
$pagerPrev = new Quad_Icons64x64_1();
|
||||||
$frame->add($pagerPrev);
|
$frame->add($pagerPrev);
|
||||||
$pagerPrev->setPosition($width * 0.39, $height * -0.44, 2);
|
$pagerPrev->setPosition($width * 0.39, $height * -0.44, 2);
|
||||||
$pagerPrev->setSize($pagerSize, $pagerSize);
|
$pagerPrev->setSize($pagerSize, $pagerSize);
|
||||||
$pagerPrev->setSubStyle($pagerPrev::SUBSTYLE_ArrowPrev);
|
$pagerPrev->setSubStyle($pagerPrev::SUBSTYLE_ArrowPrev);
|
||||||
|
|
||||||
$pagerNext = new Quad_Icons64x64_1();
|
$pagerNext = new Quad_Icons64x64_1();
|
||||||
$frame->add($pagerNext);
|
$frame->add($pagerNext);
|
||||||
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2);
|
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2);
|
||||||
$pagerNext->setSize($pagerSize, $pagerSize);
|
$pagerNext->setSize($pagerSize, $pagerSize);
|
||||||
$pagerNext->setSubStyle($pagerNext::SUBSTYLE_ArrowNext);
|
$pagerNext->setSubStyle($pagerNext::SUBSTYLE_ArrowNext);
|
||||||
|
|
||||||
$paging->addButton($pagerNext);
|
$paging->addButton($pagerNext);
|
||||||
$paging->addButton($pagerPrev);
|
$paging->addButton($pagerPrev);
|
||||||
|
|
||||||
|
$pageCountLabel = new Label_Text();
|
||||||
|
$frame->add($pageCountLabel);
|
||||||
|
$pageCountLabel->setHAlign($pageCountLabel::RIGHT);
|
||||||
|
$pageCountLabel->setPosition($width * 0.35, $height * -0.44);
|
||||||
|
$pageCountLabel->setStyle($pageCountLabel::STYLE_TextTitle1);
|
||||||
|
$pageCountLabel->setTextSize(2);
|
||||||
|
|
||||||
|
$paging->setLabel($pageCountLabel);
|
||||||
|
|
||||||
|
$backLabel = new Label_Button();
|
||||||
|
$frame->add($backLabel);
|
||||||
|
$backLabel->setPosition($width * -0.49, $height * -0.44);
|
||||||
|
$backLabel->setHAlign($backLabel::LEFT);
|
||||||
|
$backLabel->setTextSize(2);
|
||||||
|
$backLabel->setText('Back');
|
||||||
|
$backLabel->setAction(self::ACTION_SETTINGCLASS_BACK);
|
||||||
|
|
||||||
|
$pageFrame = null;
|
||||||
|
$index = 0;
|
||||||
|
$y = 0;
|
||||||
|
foreach ($settings as $setting) {
|
||||||
|
if (!$pageFrame) {
|
||||||
|
$pageFrame = new Frame();
|
||||||
|
$frame->add($pageFrame);
|
||||||
|
$y = $height * 0.41;
|
||||||
|
$paging->addPage($pageFrame);
|
||||||
|
}
|
||||||
|
|
||||||
|
$settingFrame = new Frame();
|
||||||
|
$pageFrame->add($settingFrame);
|
||||||
|
$settingFrame->setY($y);
|
||||||
|
|
||||||
|
// TODO: display currently select setting class
|
||||||
|
|
||||||
|
// Headline Label
|
||||||
|
if (false) {
|
||||||
|
$headLabel = new Label_Text();
|
||||||
|
$settingFrame->add($headLabel);
|
||||||
|
$headLabel->setHAlign(Control::LEFT);
|
||||||
|
$headLabel->setX($width * -0.46);
|
||||||
|
$headLabel->setSize($width * 0.6, $settingHeight);
|
||||||
|
$headLabel->setStyle($headLabel::STYLE_TextCardSmall);
|
||||||
|
$headLabel->setTextSize($labelTextSize);
|
||||||
|
$headLabel->setText($setting->class);
|
||||||
|
$headLabel->setTextColor("F00");
|
||||||
|
} // Headline
|
||||||
|
|
||||||
|
$nameLabel = new Label_Text();
|
||||||
|
$settingFrame->add($nameLabel);
|
||||||
|
$nameLabel->setHAlign(Control::LEFT);
|
||||||
|
$nameLabel->setX($width * -0.46);
|
||||||
|
$nameLabel->setSize($width * 0.6, $settingHeight);
|
||||||
|
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
|
||||||
|
$nameLabel->setTextSize($labelTextSize);
|
||||||
|
$nameLabel->setText($setting->setting);
|
||||||
|
$nameLabel->setTextColor("FFF");
|
||||||
|
|
||||||
|
if ($setting->type === SettingManager::TYPE_BOOL) {
|
||||||
|
$quad = new Quad_Icons64x64_1();
|
||||||
|
$settingFrame->add($quad);
|
||||||
|
$quad->setX($width / 2 * 0.6);
|
||||||
|
$quad->setZ(-0.01);
|
||||||
|
$quad->setSubStyle(($setting->value ? $quad::SUBSTYLE_LvlGreen : $quad::SUBSTYLE_LvlRed));
|
||||||
|
$quad->setSize(4, 4);
|
||||||
|
$quad->setAction(self::ACTION_SETTING_BOOL . $setting->index);
|
||||||
|
} else {
|
||||||
|
$entry = new Entry();
|
||||||
|
$settingFrame->add($entry);
|
||||||
|
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
|
||||||
|
$entry->setX($width / 2 * 0.65);
|
||||||
|
$entry->setTextSize(1);
|
||||||
|
$entry->setSize($width * 0.3, $settingHeight * 0.9);
|
||||||
|
$entry->setName(self::ACTION_PREFIX_SETTING . $setting->index);
|
||||||
|
$entry->setDefault($setting->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
$y -= $settingHeight;
|
||||||
|
if ($index % $pageMaxCount == $pageMaxCount - 1) {
|
||||||
|
$pageFrame = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Menu showing all possible Classes
|
||||||
|
*
|
||||||
|
* @param float $width
|
||||||
|
* @param float $height
|
||||||
|
* @param Script $script
|
||||||
|
* @param Player $player
|
||||||
|
* @return \FML\Controls\Frame
|
||||||
|
*/
|
||||||
|
private function getMenuSettingClasses($width, $height, Script $script, Player $player) {
|
||||||
|
$settingClasses = $this->maniaControl->settingManager->getSettingClasses(true);
|
||||||
|
|
||||||
|
$paging = new Paging();
|
||||||
|
$script->addFeature($paging);
|
||||||
|
$frame = new Frame();
|
||||||
|
|
||||||
|
// Config
|
||||||
|
$pagerSize = 9.;
|
||||||
|
$settingHeight = 5.;
|
||||||
|
$pageMaxCount = 13;
|
||||||
|
$y = 0;
|
||||||
|
|
||||||
|
// Pagers
|
||||||
|
$pagerPrev = new Quad_Icons64x64_1();
|
||||||
|
$frame->add($pagerPrev);
|
||||||
|
$pagerPrev->setPosition($width * 0.39, $height * -0.44, 2);
|
||||||
|
$pagerPrev->setSize($pagerSize, $pagerSize);
|
||||||
|
$pagerPrev->setSubStyle($pagerPrev::SUBSTYLE_ArrowPrev);
|
||||||
|
|
||||||
|
$pagerNext = new Quad_Icons64x64_1();
|
||||||
|
$frame->add($pagerNext);
|
||||||
|
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2);
|
||||||
|
$pagerNext->setSize($pagerSize, $pagerSize);
|
||||||
|
$pagerNext->setSubStyle($pagerNext::SUBSTYLE_ArrowNext);
|
||||||
|
|
||||||
|
$paging->addButton($pagerNext);
|
||||||
|
$paging->addButton($pagerPrev);
|
||||||
|
|
||||||
$pageCountLabel = new Label_Text();
|
$pageCountLabel = new Label_Text();
|
||||||
$frame->add($pageCountLabel);
|
$frame->add($pageCountLabel);
|
||||||
$pageCountLabel->setHAlign($pageCountLabel::RIGHT);
|
$pageCountLabel->setHAlign($pageCountLabel::RIGHT);
|
||||||
$pageCountLabel->setPosition($width * 0.35, $height * -0.44, 1);
|
$pageCountLabel->setPosition($width * 0.35, $height * -0.44, 1);
|
||||||
$pageCountLabel->setStyle($pageCountLabel::STYLE_TextTitle1);
|
$pageCountLabel->setStyle($pageCountLabel::STYLE_TextTitle1);
|
||||||
$pageCountLabel->setTextSize(2);
|
$pageCountLabel->setTextSize(2);
|
||||||
|
|
||||||
$paging->setLabel($pageCountLabel);
|
$paging->setLabel($pageCountLabel);
|
||||||
|
|
||||||
$pageFrame = null;
|
$pageFrame = null;
|
||||||
$index = 0;
|
$index = 0;
|
||||||
foreach ($settingClasses as $settingClass) {
|
foreach ($settingClasses as $settingClass) {
|
||||||
if (!$pageFrame) {
|
if (!$pageFrame) {
|
||||||
$pageFrame = new Frame();
|
$pageFrame = new Frame();
|
||||||
@ -144,12 +259,12 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$y = $height * 0.41;
|
$y = $height * 0.41;
|
||||||
$paging->addPage($pageFrame);
|
$paging->addPage($pageFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
$classLabel = new Label_Text();
|
$classLabel = new Label_Text();
|
||||||
|
|
||||||
$settingClassArray = explode('\\', $settingClass);
|
$settingClassArray = explode('\\', $settingClass);
|
||||||
$className = "";
|
$className = "";
|
||||||
for($i = 1; $i < count($settingClassArray); $i++){
|
for ($i = 1; $i < count($settingClassArray); $i++) {
|
||||||
$className .= $settingClassArray[$i] . " - ";
|
$className .= $settingClassArray[$i] . " - ";
|
||||||
}
|
}
|
||||||
$className = substr($className, 0, -3);
|
$className = substr($className, 0, -3);
|
||||||
@ -163,150 +278,92 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$classLabel->setText($className);
|
$classLabel->setText($className);
|
||||||
$classLabel->setTextColor('fff');
|
$classLabel->setTextColor('fff');
|
||||||
$classLabel->setAction(self::ACTION_PREFIX_SETTINGCLASS . $settingClass);
|
$classLabel->setAction(self::ACTION_PREFIX_SETTINGCLASS . $settingClass);
|
||||||
|
|
||||||
$y -= $settingHeight;
|
$y -= $settingHeight;
|
||||||
|
|
||||||
if ($index % $pageMaxCount == $pageMaxCount - 1) {
|
if ($index % $pageMaxCount == $pageMaxCount - 1) {
|
||||||
$pageFrame = null;
|
$pageFrame = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$index++;
|
$index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $frame;
|
return $frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Menu showing the Settings for the given Class
|
* Handle ManialinkPageAnswer Callback
|
||||||
*
|
*
|
||||||
* @param string $settingClass
|
* @param array $callback
|
||||||
* @param float $width
|
|
||||||
* @param float $height
|
|
||||||
* @param Script $script
|
|
||||||
* @param Player $player
|
|
||||||
* @return \FML\Controls\Frame
|
|
||||||
*/
|
*/
|
||||||
private function getMenuSettingsForClass($settingClass, $width, $height, Script $script, Player $player) {
|
public function handleManialinkPageAnswer(array $callback) {
|
||||||
$settings = $this->maniaControl->settingManager->getSettingsByClass($settingClass);
|
$actionId = $callback[1][2];
|
||||||
|
if ($actionId === self::ACTION_SETTINGCLASS_BACK) {
|
||||||
$paging = new Paging();
|
// Back to classes list
|
||||||
$script->addFeature($paging);
|
$login = $callback[1][1];
|
||||||
$frame = new Frame();
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
|
unset($this->playersSettingCategoryOpened[$player->login]);
|
||||||
// Config
|
$menuId = $this->maniaControl->configurator->getMenuId($this);
|
||||||
$pagerSize = 9.;
|
$this->maniaControl->configurator->showMenu($player, $menuId);
|
||||||
$settingHeight = 5.;
|
} else if (strpos($actionId, self::ACTION_SETTING_BOOL) === 0) {
|
||||||
$labelTextSize = 2;
|
// Bool setting change
|
||||||
$pageMaxCount = 13;
|
$settingIndex = (int)substr($actionId, strlen(self::ACTION_SETTING_BOOL));
|
||||||
|
|
||||||
// Pagers
|
$login = $callback[1][1];
|
||||||
$pagerPrev = new Quad_Icons64x64_1();
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
$frame->add($pagerPrev);
|
|
||||||
$pagerPrev->setPosition($width * 0.39, $height * -0.44, 2);
|
// Toggle the Boolean Setting
|
||||||
$pagerPrev->setSize($pagerSize, $pagerSize);
|
$this->toggleBooleanSetting($settingIndex, $player);
|
||||||
$pagerPrev->setSubStyle($pagerPrev::SUBSTYLE_ArrowPrev);
|
|
||||||
|
if ($callback[1][3]) {
|
||||||
$pagerNext = new Quad_Icons64x64_1();
|
// Save all Changes
|
||||||
$frame->add($pagerNext);
|
$this->saveConfigData($callback[1], $player);
|
||||||
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2);
|
} else {
|
||||||
$pagerNext->setSize($pagerSize, $pagerSize);
|
// Reopen menu directly
|
||||||
$pagerNext->setSubStyle($pagerNext::SUBSTYLE_ArrowNext);
|
$menuId = $this->maniaControl->configurator->getMenuId($this);
|
||||||
|
$this->maniaControl->configurator->reopenMenu($player, $menuId);
|
||||||
$paging->addButton($pagerNext);
|
|
||||||
$paging->addButton($pagerPrev);
|
|
||||||
|
|
||||||
$pageCountLabel = new Label_Text();
|
|
||||||
$frame->add($pageCountLabel);
|
|
||||||
$pageCountLabel->setHAlign($pageCountLabel::RIGHT);
|
|
||||||
$pageCountLabel->setPosition($width * 0.35, $height * -0.44);
|
|
||||||
$pageCountLabel->setStyle($pageCountLabel::STYLE_TextTitle1);
|
|
||||||
$pageCountLabel->setTextSize(2);
|
|
||||||
|
|
||||||
$paging->setLabel($pageCountLabel);
|
|
||||||
|
|
||||||
$backLabel = new Label_Button();
|
|
||||||
$frame->add($backLabel);
|
|
||||||
$backLabel->setPosition($width * -0.49, $height * -0.44);
|
|
||||||
$backLabel->setHAlign($backLabel::LEFT);
|
|
||||||
$backLabel->setTextSize(2);
|
|
||||||
$backLabel->setText('Back');
|
|
||||||
$backLabel->setAction(self::ACTION_SETTINGCLASS_BACK);
|
|
||||||
|
|
||||||
$pageFrame = null;
|
|
||||||
$index = 0;
|
|
||||||
$y = 0;
|
|
||||||
foreach ($settings as $setting) {
|
|
||||||
if (!$pageFrame) {
|
|
||||||
$pageFrame = new Frame();
|
|
||||||
$frame->add($pageFrame);
|
|
||||||
$y = $height * 0.41;
|
|
||||||
$paging->addPage($pageFrame);
|
|
||||||
}
|
}
|
||||||
|
} else if (strpos($actionId, self::ACTION_PREFIX_SETTINGCLASS) === 0) {
|
||||||
$settingFrame = new Frame();
|
// Setting class selected
|
||||||
$pageFrame->add($settingFrame);
|
$settingClass = substr($actionId, strlen(self::ACTION_PREFIX_SETTINGCLASS));
|
||||||
$settingFrame->setY($y);
|
|
||||||
|
$login = $callback[1][1];
|
||||||
// TODO: display currently select setting class
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
|
|
||||||
// Headline Label
|
$this->playersSettingCategoryOpened[$player->login] = $settingClass;
|
||||||
if (false) {
|
|
||||||
$headLabel = new Label_Text();
|
$menuId = $this->maniaControl->configurator->getMenuId($this);
|
||||||
$settingFrame->add($headLabel);
|
$this->maniaControl->configurator->showMenu($player, $menuId);
|
||||||
$headLabel->setHAlign(Control::LEFT);
|
|
||||||
$headLabel->setX($width * -0.46);
|
|
||||||
$headLabel->setSize($width * 0.6, $settingHeight);
|
|
||||||
$headLabel->setStyle($headLabel::STYLE_TextCardSmall);
|
|
||||||
$headLabel->setTextSize($labelTextSize);
|
|
||||||
$headLabel->setText($setting->class);
|
|
||||||
$headLabel->setTextColor("F00");
|
|
||||||
} // Headline
|
|
||||||
|
|
||||||
$nameLabel = new Label_Text();
|
|
||||||
$settingFrame->add($nameLabel);
|
|
||||||
$nameLabel->setHAlign(Control::LEFT);
|
|
||||||
$nameLabel->setX($width * -0.46);
|
|
||||||
$nameLabel->setSize($width * 0.6, $settingHeight);
|
|
||||||
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
|
|
||||||
$nameLabel->setTextSize($labelTextSize);
|
|
||||||
$nameLabel->setText($setting->setting);
|
|
||||||
$nameLabel->setTextColor("FFF");
|
|
||||||
|
|
||||||
if ($setting->type === SettingManager::TYPE_BOOL) {
|
|
||||||
$quad = new Quad_Icons64x64_1();
|
|
||||||
$settingFrame->add($quad);
|
|
||||||
$quad->setX($width / 2 * 0.6);
|
|
||||||
$quad->setZ(-0.01);
|
|
||||||
$quad->setSubStyle(($setting->value ? $quad::SUBSTYLE_LvlGreen : $quad::SUBSTYLE_LvlRed));
|
|
||||||
$quad->setSize(4, 4);
|
|
||||||
$quad->setAction(self::ACTION_SETTING_BOOL . $setting->index);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$entry = new Entry();
|
|
||||||
$settingFrame->add($entry);
|
|
||||||
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
|
|
||||||
$entry->setX($width / 2 * 0.65);
|
|
||||||
$entry->setTextSize(1);
|
|
||||||
$entry->setSize($width * 0.3, $settingHeight * 0.9);
|
|
||||||
$entry->setName(self::ACTION_PREFIX_SETTING . $setting->index);
|
|
||||||
$entry->setDefault($setting->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
$y -= $settingHeight;
|
|
||||||
if ($index % $pageMaxCount == $pageMaxCount - 1) {
|
|
||||||
$pageFrame = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$index++;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return $frame;
|
|
||||||
|
/**
|
||||||
|
* Toggles a Boolean Value
|
||||||
|
*
|
||||||
|
* @param int $settingIndex
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
public function toggleBooleanSetting($settingIndex, Player $player) {
|
||||||
|
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_CHANGE_MC_SETTINGS)) {
|
||||||
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$oldSetting = $this->maniaControl->settingManager->getSettingByIndex($settingIndex);
|
||||||
|
|
||||||
|
if (!isset($oldSetting)) {
|
||||||
|
var_dump('no setting ' . $settingIndex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Toggle value
|
||||||
|
$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, !$oldSetting->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the Config Data
|
* Save the Config Data
|
||||||
*
|
*
|
||||||
* @param array $configData
|
* @param array $configData
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
public function saveConfigData(array $configData, Player $player) {
|
public function saveConfigData(array $configData, Player $player) {
|
||||||
@ -318,96 +375,33 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
// TODO: improve needed, this won't save configData passed by boolean setting change
|
// TODO: improve needed, this won't save configData passed by boolean setting change
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$maniaControlSettings = $this->maniaControl->settingManager->getSettings();
|
$maniaControlSettings = $this->maniaControl->settingManager->getSettings();
|
||||||
|
|
||||||
$prefixLength = strlen(self::ACTION_PREFIX_SETTING);
|
$prefixLength = strlen(self::ACTION_PREFIX_SETTING);
|
||||||
|
|
||||||
foreach ($configData[3] as $setting) {
|
foreach ($configData[3] as $setting) {
|
||||||
$settingName = substr($setting['Name'], $prefixLength);
|
$settingName = substr($setting['Name'], $prefixLength);
|
||||||
|
|
||||||
$oldSetting = $maniaControlSettings[$settingName];
|
$oldSetting = $maniaControlSettings[$settingName];
|
||||||
if ($setting['Value'] == $oldSetting->value || $oldSetting->type == 'bool') {
|
if ($setting['Value'] == $oldSetting->value || $oldSetting->type == 'bool') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, $setting['Value']);
|
$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, $setting['Value']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reopen the Menu
|
// Reopen the Menu
|
||||||
$menuId = $this->maniaControl->configurator->getMenuId($this->getTitle());
|
$menuId = $this->maniaControl->configurator->getMenuId($this->getTitle());
|
||||||
$this->maniaControl->configurator->reopenMenu($player, $menuId);
|
$this->maniaControl->configurator->reopenMenu($player, $menuId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle ManialinkPageAnswer Callback
|
* Get the Menu Title
|
||||||
*
|
*
|
||||||
* @param array $callback
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function handleManialinkPageAnswer(array $callback) {
|
public function getTitle() {
|
||||||
$actionId = $callback[1][2];
|
return self::TITLE;
|
||||||
if ($actionId === self::ACTION_SETTINGCLASS_BACK) {
|
|
||||||
// Back to classes list
|
|
||||||
$login = $callback[1][1];
|
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
|
||||||
unset($this->playersSettingCategoryOpened[$player->login]);
|
|
||||||
$menuId = $this->maniaControl->configurator->getMenuId($this);
|
|
||||||
$this->maniaControl->configurator->showMenu($player, $menuId);
|
|
||||||
}
|
|
||||||
else if (strpos($actionId, self::ACTION_SETTING_BOOL) === 0) {
|
|
||||||
// Bool setting change
|
|
||||||
$settingIndex = (int) substr($actionId, strlen(self::ACTION_SETTING_BOOL));
|
|
||||||
|
|
||||||
$login = $callback[1][1];
|
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
|
||||||
|
|
||||||
// Toggle the Boolean Setting
|
|
||||||
$this->toggleBooleanSetting($settingIndex, $player);
|
|
||||||
|
|
||||||
if ($callback[1][3]) {
|
|
||||||
// Save all Changes
|
|
||||||
$this->saveConfigData($callback[1], $player);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Reopen menu directly
|
|
||||||
$menuId = $this->maniaControl->configurator->getMenuId($this);
|
|
||||||
$this->maniaControl->configurator->reopenMenu($player, $menuId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (strpos($actionId, self::ACTION_PREFIX_SETTINGCLASS) === 0) {
|
|
||||||
// Setting class selected
|
|
||||||
$settingClass = substr($actionId, strlen(self::ACTION_PREFIX_SETTINGCLASS));
|
|
||||||
|
|
||||||
$login = $callback[1][1];
|
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
|
||||||
|
|
||||||
$this->playersSettingCategoryOpened[$player->login] = $settingClass;
|
|
||||||
|
|
||||||
$menuId = $this->maniaControl->configurator->getMenuId($this);
|
|
||||||
$this->maniaControl->configurator->showMenu($player, $menuId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Toggles a Boolean Value
|
|
||||||
*
|
|
||||||
* @param int $settingIndex
|
|
||||||
* @param Player $player
|
|
||||||
*/
|
|
||||||
public function toggleBooleanSetting($settingIndex, Player $player) {
|
|
||||||
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_CHANGE_MC_SETTINGS)) {
|
|
||||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$oldSetting = $this->maniaControl->settingManager->getSettingByIndex($settingIndex);
|
|
||||||
|
|
||||||
if (!isset($oldSetting)) {
|
|
||||||
var_dump('no setting ' . $settingIndex);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Toggle value
|
|
||||||
$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, !$oldSetting->value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,8 @@ use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
|
|||||||
/**
|
/**
|
||||||
* Class offering a Configurator for Script Settings
|
* Class offering a Configurator for Script Settings
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||||
@ -100,17 +100,6 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$this->loadSettingsFromDatabase();
|
$this->loadSettingsFromDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle OnBegin Map Callback
|
|
||||||
*
|
|
||||||
* @param Map $map
|
|
||||||
*/
|
|
||||||
public function onBeginMap(Map $map) {
|
|
||||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN)) {
|
|
||||||
$this->loadSettingsFromDatabase();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load Settings from Database
|
* Load Settings from Database
|
||||||
*
|
*
|
||||||
@ -119,7 +108,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
public function loadSettingsFromDatabase() {
|
public function loadSettingsFromDatabase() {
|
||||||
try {
|
try {
|
||||||
$scriptSettings = $this->maniaControl->client->getModeScriptSettings();
|
$scriptSettings = $this->maniaControl->client->getModeScriptSettings();
|
||||||
} catch(NotInScriptModeException $e) {
|
} catch (NotInScriptModeException $e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +122,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$loadedSettings = array();
|
$loadedSettings = array();
|
||||||
while($row = $result->fetch_object()) {
|
while ($row = $result->fetch_object()) {
|
||||||
if (!isset($scriptSettings[$row->settingName])) {
|
if (!isset($scriptSettings[$row->settingName])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -147,7 +136,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->setModeScriptSettings($loadedSettings);
|
$this->maniaControl->client->setModeScriptSettings($loadedSettings);
|
||||||
} catch(Exception $e) {
|
} catch (Exception $e) {
|
||||||
trigger_error('Error occurred: ' . $e->getMessage());
|
trigger_error('Error occurred: ' . $e->getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -155,23 +144,27 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getTitle()
|
* Handle OnBegin Map Callback
|
||||||
|
*
|
||||||
|
* @param Map $map
|
||||||
*/
|
*/
|
||||||
public function getTitle() {
|
public function onBeginMap(Map $map) {
|
||||||
return 'Script Settings';
|
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN)) {
|
||||||
|
$this->loadSettingsFromDatabase();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
||||||
*/
|
*/
|
||||||
public function getMenu($width, $height, Script $script, Player $player) {
|
public function getMenu($width, $height, Script $script, Player $player) {
|
||||||
$paging = new Paging();
|
$paging = new Paging();
|
||||||
$script->addFeature($paging);
|
$script->addFeature($paging);
|
||||||
$frame = new Frame();
|
$frame = new Frame();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$scriptInfo = $this->maniaControl->client->getModeScriptInfo();
|
$scriptInfo = $this->maniaControl->client->getModeScriptInfo();
|
||||||
} catch(NotInScriptModeException $e) {
|
} catch (NotInScriptModeException $e) {
|
||||||
$label = new Label();
|
$label = new Label();
|
||||||
$frame->add($label);
|
$frame->add($label);
|
||||||
$label->setText($e->getMessage());
|
$label->setText($e->getMessage());
|
||||||
@ -182,7 +175,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$scriptSettings = $this->maniaControl->client->getModeScriptSettings();
|
$scriptSettings = $this->maniaControl->client->getModeScriptSettings();
|
||||||
} catch(NotInScriptModeException $e) {
|
} catch (NotInScriptModeException $e) {
|
||||||
//do nothing
|
//do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,8 +198,8 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$pagerNext->setSize($pagerSize, $pagerSize);
|
$pagerNext->setSize($pagerSize, $pagerSize);
|
||||||
$pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext);
|
$pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext);
|
||||||
|
|
||||||
$paging->addButton($pagerNext);
|
$paging->addButton($pagerNext);
|
||||||
$paging->addButton($pagerPrev);
|
$paging->addButton($pagerPrev);
|
||||||
|
|
||||||
$pageCountLabel = new Label();
|
$pageCountLabel = new Label();
|
||||||
$frame->add($pageCountLabel);
|
$frame->add($pageCountLabel);
|
||||||
@ -215,12 +208,12 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$pageCountLabel->setStyle('TextTitle1');
|
$pageCountLabel->setStyle('TextTitle1');
|
||||||
$pageCountLabel->setTextSize(2);
|
$pageCountLabel->setTextSize(2);
|
||||||
|
|
||||||
$paging->setLabel($pageCountLabel);
|
$paging->setLabel($pageCountLabel);
|
||||||
|
|
||||||
// Setting pages
|
// Setting pages
|
||||||
$pageFrames = array();
|
$pageFrames = array();
|
||||||
$y = 0.;
|
$y = 0.;
|
||||||
foreach($scriptParams as $index => $scriptParam) {
|
foreach ($scriptParams as $index => $scriptParam) {
|
||||||
/** @var \Maniaplanet\DedicatedServer\Structures\ScriptSettings $scriptParam */
|
/** @var \Maniaplanet\DedicatedServer\Structures\ScriptSettings $scriptParam */
|
||||||
$settingName = $scriptParam->name;
|
$settingName = $scriptParam->name;
|
||||||
|
|
||||||
@ -236,7 +229,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
}
|
}
|
||||||
array_push($pageFrames, $pageFrame);
|
array_push($pageFrames, $pageFrame);
|
||||||
$y = $height * 0.41;
|
$y = $height * 0.41;
|
||||||
$paging->addPage($pageFrame);
|
$paging->addPage($pageFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
$settingFrame = new Frame();
|
$settingFrame = new Frame();
|
||||||
@ -290,7 +283,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$descriptionLabel->setTextSize($labelTextSize);
|
$descriptionLabel->setTextSize($labelTextSize);
|
||||||
$descriptionLabel->setTranslate(true);
|
$descriptionLabel->setTranslate(true);
|
||||||
$descriptionLabel->setText($scriptParam->desc);
|
$descriptionLabel->setText($scriptParam->desc);
|
||||||
$nameLabel->addTooltipFeature($descriptionLabel);
|
$nameLabel->addTooltipFeature($descriptionLabel);
|
||||||
|
|
||||||
$y -= $settingHeight;
|
$y -= $settingHeight;
|
||||||
if ($index % $pageMaxCount == $pageMaxCount - 1) {
|
if ($index % $pageMaxCount == $pageMaxCount - 1) {
|
||||||
@ -301,50 +294,6 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
return $frame;
|
return $frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
|
|
||||||
*/
|
|
||||||
public function saveConfigData(array $configData, Player $player) {
|
|
||||||
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_CHANGE_SCRIPT_SETTINGS)) {
|
|
||||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING) !== 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$scriptSettings = $this->maniaControl->client->getModeScriptSettings();
|
|
||||||
} catch(NotInScriptModeException $e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$prefixLength = strlen(self::ACTION_PREFIX_SETTING);
|
|
||||||
|
|
||||||
$newSettings = array();
|
|
||||||
foreach($configData[3] as $setting) {
|
|
||||||
$settingName = substr($setting['Name'], $prefixLength + 1);
|
|
||||||
if (!isset($scriptSettings[$settingName])) {
|
|
||||||
var_dump('no setting ' . $settingName);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($setting['Value'] == $scriptSettings[$settingName]) {
|
|
||||||
// Not changed
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$newSettings[$settingName] = $setting['Value'];
|
|
||||||
settype($newSettings[$settingName], gettype($scriptSettings[$settingName]));
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->applyNewScriptSettings($newSettings, $player);
|
|
||||||
|
|
||||||
//Reopen the Menu
|
|
||||||
$menuId = $this->maniaControl->configurator->getMenuId($this->getTitle());
|
|
||||||
$this->maniaControl->configurator->reopenMenu($player, $menuId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle ManialinkPageAnswer Callback
|
* Handle ManialinkPageAnswer Callback
|
||||||
*
|
*
|
||||||
@ -379,7 +328,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
public function toggleBooleanSetting($setting, Player $player) {
|
public function toggleBooleanSetting($setting, Player $player) {
|
||||||
try {
|
try {
|
||||||
$scriptSettings = $this->maniaControl->client->getModeScriptSettings();
|
$scriptSettings = $this->maniaControl->client->getModeScriptSettings();
|
||||||
} catch(NotInScriptModeException $e) {
|
} catch (NotInScriptModeException $e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,7 +357,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->setModeScriptSettings($newSettings);
|
$this->maniaControl->client->setModeScriptSettings($newSettings);
|
||||||
} catch(Exception $e) {
|
} catch (Exception $e) {
|
||||||
//TODO temp added 19.04.2014
|
//TODO temp added 19.04.2014
|
||||||
$this->maniaControl->errorHandler->triggerDebugNotice("Exception line 416 ScriptSettings.php" . $e->getMessage());
|
$this->maniaControl->errorHandler->triggerDebugNotice("Exception line 416 ScriptSettings.php" . $e->getMessage());
|
||||||
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
||||||
@ -436,7 +385,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$settingIndex = 0;
|
$settingIndex = 0;
|
||||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($player->authLevel);
|
$title = $this->maniaControl->authenticationManager->getAuthLevelName($player->authLevel);
|
||||||
$chatMessage = '$ff0' . $title . ' $<' . $player->nickname . '$> set ScriptSetting' . ($settingsCount > 1 ? 's' : '') . ' ';
|
$chatMessage = '$ff0' . $title . ' $<' . $player->nickname . '$> set ScriptSetting' . ($settingsCount > 1 ? 's' : '') . ' ';
|
||||||
foreach($newSettings as $setting => $value) {
|
foreach ($newSettings as $setting => $value) {
|
||||||
$chatMessage .= '$<' . '$fff' . preg_replace('/^S_/', '', $setting) . '$z$s$ff0 ';
|
$chatMessage .= '$<' . '$fff' . preg_replace('/^S_/', '', $setting) . '$z$s$ff0 ';
|
||||||
$chatMessage .= 'to $fff' . $this->parseSettingValue($value) . '$>';
|
$chatMessage .= 'to $fff' . $this->parseSettingValue($value) . '$>';
|
||||||
|
|
||||||
@ -478,4 +427,55 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
}
|
}
|
||||||
return (string)$value;
|
return (string)$value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
|
||||||
|
*/
|
||||||
|
public function saveConfigData(array $configData, Player $player) {
|
||||||
|
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_CHANGE_SCRIPT_SETTINGS)) {
|
||||||
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING) !== 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$scriptSettings = $this->maniaControl->client->getModeScriptSettings();
|
||||||
|
} catch (NotInScriptModeException $e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$prefixLength = strlen(self::ACTION_PREFIX_SETTING);
|
||||||
|
|
||||||
|
$newSettings = array();
|
||||||
|
foreach ($configData[3] as $setting) {
|
||||||
|
$settingName = substr($setting['Name'], $prefixLength + 1);
|
||||||
|
if (!isset($scriptSettings[$settingName])) {
|
||||||
|
var_dump('no setting ' . $settingName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($setting['Value'] == $scriptSettings[$settingName]) {
|
||||||
|
// Not changed
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$newSettings[$settingName] = $setting['Value'];
|
||||||
|
settype($newSettings[$settingName], gettype($scriptSettings[$settingName]));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->applyNewScriptSettings($newSettings, $player);
|
||||||
|
|
||||||
|
//Reopen the Menu
|
||||||
|
$menuId = $this->maniaControl->configurator->getMenuId($this->getTitle());
|
||||||
|
$this->maniaControl->configurator->reopenMenu($player, $menuId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see \ManiaControl\Configurators\ConfiguratorMenu::getTitle()
|
||||||
|
*/
|
||||||
|
public function getTitle() {
|
||||||
|
return 'Script Settings';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,8 @@ use Maniaplanet\DedicatedServer\Xmlrpc\LadderModeUnknownException;
|
|||||||
/**
|
/**
|
||||||
* Class offering a Configurator for Server Settings
|
* Class offering a Configurator for Server Settings
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
||||||
@ -109,7 +109,7 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
}
|
}
|
||||||
$serverSettings = $this->maniaControl->client->getServerOptions()->toArray();
|
$serverSettings = $this->maniaControl->client->getServerOptions()->toArray();
|
||||||
$applySettings = false;
|
$applySettings = false;
|
||||||
while($row = $result->fetch_object()) {
|
while ($row = $result->fetch_object()) {
|
||||||
if (!isset($serverSettings[$row->settingName])) {
|
if (!isset($serverSettings[$row->settingName])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -127,20 +127,13 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getTitle()
|
|
||||||
*/
|
|
||||||
public function getTitle() {
|
|
||||||
return 'Server Settings';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
||||||
*/
|
*/
|
||||||
public function getMenu($width, $height, Script $script, Player $player) {
|
public function getMenu($width, $height, Script $script, Player $player) {
|
||||||
$paging = new Paging();
|
$paging = new Paging();
|
||||||
$script->addFeature($paging);
|
$script->addFeature($paging);
|
||||||
$frame = new Frame();
|
$frame = new Frame();
|
||||||
|
|
||||||
$serverSettings = $this->maniaControl->client->getServerOptions()->toArray();
|
$serverSettings = $this->maniaControl->client->getServerOptions()->toArray();
|
||||||
|
|
||||||
@ -163,8 +156,8 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$pagerNext->setSize($pagerSize, $pagerSize);
|
$pagerNext->setSize($pagerSize, $pagerSize);
|
||||||
$pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext);
|
$pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext);
|
||||||
|
|
||||||
$paging->addButton($pagerNext);
|
$paging->addButton($pagerNext);
|
||||||
$paging->addButton($pagerPrev);
|
$paging->addButton($pagerPrev);
|
||||||
|
|
||||||
$pageCountLabel = new Label();
|
$pageCountLabel = new Label();
|
||||||
$frame->add($pageCountLabel);
|
$frame->add($pageCountLabel);
|
||||||
@ -173,13 +166,13 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$pageCountLabel->setStyle('TextTitle1');
|
$pageCountLabel->setStyle('TextTitle1');
|
||||||
$pageCountLabel->setTextSize(2);
|
$pageCountLabel->setTextSize(2);
|
||||||
|
|
||||||
$paging->setLabel($pageCountLabel);
|
$paging->setLabel($pageCountLabel);
|
||||||
|
|
||||||
// Setting pages
|
// Setting pages
|
||||||
$pageFrames = array();
|
$pageFrames = array();
|
||||||
$y = 0.;
|
$y = 0.;
|
||||||
$id = 0;
|
$id = 0;
|
||||||
foreach($serverSettings as $name => $value) {
|
foreach ($serverSettings as $name => $value) {
|
||||||
// Continue on CurrentMaxPlayers...
|
// Continue on CurrentMaxPlayers...
|
||||||
$pos = strpos($name, "Current"); // TODO maybe display current somewhere
|
$pos = strpos($name, "Current"); // TODO maybe display current somewhere
|
||||||
if ($pos !== false) {
|
if ($pos !== false) {
|
||||||
@ -194,7 +187,7 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
}
|
}
|
||||||
array_push($pageFrames, $pageFrame);
|
array_push($pageFrames, $pageFrame);
|
||||||
$y = $height * 0.41;
|
$y = $height * 0.41;
|
||||||
$paging->addPage($pageFrame);
|
$paging->addPage($pageFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
$settingFrame = new Frame();
|
$settingFrame = new Frame();
|
||||||
@ -261,6 +254,25 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
return $frame;
|
return $frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle ManialinkPageAnswer Callback
|
||||||
|
*
|
||||||
|
* @param array $callback
|
||||||
|
*/
|
||||||
|
public function handleManialinkPageAnswer(array $callback) {
|
||||||
|
$actionId = $callback[1][2];
|
||||||
|
$boolSetting = (strpos($actionId, self::ACTION_SETTING_BOOL) === 0);
|
||||||
|
if (!$boolSetting) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$login = $callback[1][1];
|
||||||
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
|
|
||||||
|
// Save all Changes
|
||||||
|
$this->saveConfigData($callback[1], $player);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
|
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
|
||||||
*/
|
*/
|
||||||
@ -285,7 +297,7 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$newSettings = array();
|
$newSettings = array();
|
||||||
foreach($configData[3] as $setting) {
|
foreach ($configData[3] as $setting) {
|
||||||
// Check if it was a boolean button
|
// Check if it was a boolean button
|
||||||
if ($setting['Name'] == $boolSettingName) {
|
if ($setting['Name'] == $boolSettingName) {
|
||||||
$setting['Value'] = ($setting['Value'] ? false : true);
|
$setting['Value'] = ($setting['Value'] ? false : true);
|
||||||
@ -304,25 +316,6 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$this->maniaControl->configurator->reopenMenu($player, $menuId);
|
$this->maniaControl->configurator->reopenMenu($player, $menuId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle ManialinkPageAnswer Callback
|
|
||||||
*
|
|
||||||
* @param array $callback
|
|
||||||
*/
|
|
||||||
public function handleManialinkPageAnswer(array $callback) {
|
|
||||||
$actionId = $callback[1][2];
|
|
||||||
$boolSetting = (strpos($actionId, self::ACTION_SETTING_BOOL) === 0);
|
|
||||||
if (!$boolSetting) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$login = $callback[1][1];
|
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
|
||||||
|
|
||||||
// Save all Changes
|
|
||||||
$this->saveConfigData($callback[1], $player);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply the Array of new Server Settings
|
* Apply the Array of new Server Settings
|
||||||
*
|
*
|
||||||
@ -337,7 +330,7 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->setServerOptions($newSettings);
|
$this->maniaControl->client->setServerOptions($newSettings);
|
||||||
} catch(LadderModeUnknownException $e) {
|
} catch (LadderModeUnknownException $e) {
|
||||||
$this->maniaControl->chat->sendError("Unknown Ladder-Mode");
|
$this->maniaControl->chat->sendError("Unknown Ladder-Mode");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -359,7 +352,7 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($newSettings as $setting => $value) {
|
foreach ($newSettings as $setting => $value) {
|
||||||
if ($value === null) {
|
if ($value === null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -382,4 +375,11 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see \ManiaControl\Configurators\ConfiguratorMenu::getTitle()
|
||||||
|
*/
|
||||||
|
public function getTitle() {
|
||||||
|
return 'Server Settings';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,10 @@ use ManiaControl\Formatter;
|
|||||||
/**
|
/**
|
||||||
* Mania Exchange Map Info Object
|
* Mania Exchange Map Info Object
|
||||||
*
|
*
|
||||||
* @author Xymph
|
* @author Xymph
|
||||||
* @updated kremsy
|
* @updated kremsy <kremsy@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class MXMapInfo {
|
class MXMapInfo {
|
||||||
public $prefix, $id, $uid, $name, $userid, $author, $uploaded, $updated, $type, $maptype;
|
public $prefix, $id, $uid, $name, $userid, $author, $uploaded, $updated, $type, $maptype;
|
||||||
@ -19,6 +19,7 @@ class MXMapInfo {
|
|||||||
public $replaytyp, $replayid, $replaycnt, $acomment, $awards, $comments;
|
public $replaytyp, $replayid, $replaycnt, $acomment, $awards, $comments;
|
||||||
public $pageurl, $replayurl, $imageurl, $thumburl, $downloadurl, $dir;
|
public $pageurl, $replayurl, $imageurl, $thumburl, $downloadurl, $dir;
|
||||||
public $ratingVoteCount, $ratingVoteAverage;
|
public $ratingVoteCount, $ratingVoteAverage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns map object with all available data from MX map data
|
* Returns map object with all available data from MX map data
|
||||||
*
|
*
|
||||||
@ -76,7 +77,7 @@ class MXMapInfo {
|
|||||||
$this->comments = $mx->CommentCount;
|
$this->comments = $mx->CommentCount;
|
||||||
|
|
||||||
$this->ratingVoteCount = isset($mx->RatingVoteCount) ? $mx->RatingVoteCount : 0;
|
$this->ratingVoteCount = isset($mx->RatingVoteCount) ? $mx->RatingVoteCount : 0;
|
||||||
$this->ratingVoteAverage = isset($mx->RatingVoteAverage) ? $mx->RatingVoteAverage : 0;
|
$this->ratingVoteAverage = isset($mx->RatingVoteAverage) ? $mx->RatingVoteAverage : 0;
|
||||||
|
|
||||||
if ($this->trkvalue == 0 && $this->lbrating > 0) {
|
if ($this->trkvalue == 0 && $this->lbrating > 0) {
|
||||||
$this->trkvalue = $this->lbrating;
|
$this->trkvalue = $this->lbrating;
|
||||||
|
@ -29,9 +29,9 @@ use ManiaControl\Players\Player;
|
|||||||
/**
|
/**
|
||||||
* ManiaExchange List Widget Class
|
* ManiaExchange List Widget Class
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener {
|
class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener {
|
||||||
/*
|
/*
|
||||||
@ -66,6 +66,33 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
|||||||
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SEARCH_AUTHOR, $this, 'showList');
|
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SEARCH_AUTHOR, $this, 'showList');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle ManialinkPageAnswer Callback
|
||||||
|
*
|
||||||
|
* @param array $callback
|
||||||
|
*/
|
||||||
|
public function handleManialinkPageAnswer(array $callback) {
|
||||||
|
$actionId = $callback[1][2];
|
||||||
|
$actionArray = explode('.', $actionId);
|
||||||
|
if (count($actionArray) <= 2) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$action = $actionArray[0] . '.' . $actionArray[1];
|
||||||
|
$login = $callback[1][1];
|
||||||
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
|
$mapId = (int)$actionArray[2];
|
||||||
|
|
||||||
|
switch ($action) {
|
||||||
|
case self::ACTION_GET_MAPS_FROM_AUTHOR:
|
||||||
|
$callback[1][2] = 'auth:' . $actionArray[2];
|
||||||
|
$this->showList($callback, $player);
|
||||||
|
break;
|
||||||
|
case self::ACTION_ADD_MAP:
|
||||||
|
$this->maniaControl->mapManager->addMapFromMx($mapId, $player->login);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows the List
|
* Shows the List
|
||||||
@ -80,7 +107,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
|||||||
$author = '';
|
$author = '';
|
||||||
$environment = '';
|
$environment = '';
|
||||||
if (count($params) >= 1) {
|
if (count($params) >= 1) {
|
||||||
foreach($params as $param) {
|
foreach ($params as $param) {
|
||||||
if ($param == '/xlist' || $param == MapCommands::ACTION_OPEN_XLIST) {
|
if ($param == '/xlist' || $param == MapCommands::ACTION_OPEN_XLIST) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -130,8 +157,8 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
|||||||
//Create ManiaLink
|
//Create ManiaLink
|
||||||
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
||||||
$script = $maniaLink->getScript();
|
$script = $maniaLink->getScript();
|
||||||
$paging = new Paging();
|
$paging = new Paging();
|
||||||
$script->addFeature($paging);
|
$script->addFeature($paging);
|
||||||
|
|
||||||
// Main frame
|
// Main frame
|
||||||
$frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $paging);
|
$frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $paging);
|
||||||
@ -151,7 +178,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
|||||||
$i = 0;
|
$i = 0;
|
||||||
$y = $height / 2 - 16;
|
$y = $height / 2 - 16;
|
||||||
$pageFrames = array();
|
$pageFrames = array();
|
||||||
foreach($maps as $map) { //TODO order possibilities
|
foreach ($maps as $map) { //TODO order possibilities
|
||||||
/** @var MxMapInfo $map */
|
/** @var MxMapInfo $map */
|
||||||
if (!isset($pageFrame)) {
|
if (!isset($pageFrame)) {
|
||||||
$pageFrame = new Frame();
|
$pageFrame = new Frame();
|
||||||
@ -162,7 +189,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
|||||||
array_push($pageFrames, $pageFrame);
|
array_push($pageFrames, $pageFrame);
|
||||||
$y = $height / 2 - 16;
|
$y = $height / 2 - 16;
|
||||||
|
|
||||||
$paging->addPage($pageFrame);
|
$paging->addPage($pageFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map Frame
|
// Map Frame
|
||||||
@ -179,7 +206,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
|||||||
|
|
||||||
/** @var MxMapInfo $map */
|
/** @var MxMapInfo $map */
|
||||||
$time = Formatter::time_elapsed_string(strtotime($map->updated));
|
$time = Formatter::time_elapsed_string(strtotime($map->updated));
|
||||||
$array = array('$s'. $map->id => $x + 3.5, '$s'. $map->name => $x + 12.5, '$s'. $map->author => $x + 59, '$s'. str_replace("Arena", "", $map->maptype) => $x + 103, '$s'. $map->mood => $x + 118, '$s'. $time => $x + 130);
|
$array = array('$s' . $map->id => $x + 3.5, '$s' . $map->name => $x + 12.5, '$s' . $map->author => $x + 59, '$s' . str_replace("Arena", "", $map->maptype) => $x + 103, '$s' . $map->mood => $x + 118, '$s' . $time => $x + 130);
|
||||||
$labels = $this->maniaControl->manialinkManager->labelLine($mapFrame, $array);
|
$labels = $this->maniaControl->manialinkManager->labelLine($mapFrame, $array);
|
||||||
/** @var Label_Text $authorLabel */
|
/** @var Label_Text $authorLabel */
|
||||||
$authorLabel = $labels[2];
|
$authorLabel = $labels[2];
|
||||||
@ -195,8 +222,8 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
|||||||
$mxQuad->setX($x + 56);
|
$mxQuad->setX($x + 56);
|
||||||
$mxQuad->setUrl($map->pageurl);
|
$mxQuad->setUrl($map->pageurl);
|
||||||
$mxQuad->setZ(0.01);
|
$mxQuad->setZ(0.01);
|
||||||
$description = 'View $<' . $map->name . '$> on Mania-Exchange';
|
$description = 'View $<' . $map->name . '$> on Mania-Exchange';
|
||||||
$mxQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
$mxQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||||
|
|
||||||
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
|
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
|
||||||
$addQuad = new Quad_Icons64x64_1();
|
$addQuad = new Quad_Icons64x64_1();
|
||||||
@ -208,8 +235,8 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
|||||||
$addQuad->setAction(self::ACTION_ADD_MAP . '.' . $map->id);
|
$addQuad->setAction(self::ACTION_ADD_MAP . '.' . $map->id);
|
||||||
$addQuad->setZ(0.01);
|
$addQuad->setZ(0.01);
|
||||||
|
|
||||||
$description = 'Add-Map: $<' . $map->name . '$>';
|
$description = 'Add-Map: $<' . $map->name . '$>';
|
||||||
$addQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
$addQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Award Quad
|
//Award Quad
|
||||||
@ -230,7 +257,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Map Karma
|
//Map Karma
|
||||||
$karma = $map->ratingVoteAverage / 100;
|
$karma = $map->ratingVoteAverage / 100;
|
||||||
$voteCount = $map->ratingVoteCount;
|
$voteCount = $map->ratingVoteCount;
|
||||||
if (is_numeric($karma) && $voteCount > 0) {
|
if (is_numeric($karma) && $voteCount > 0) {
|
||||||
$karmaGauge = new Gauge();
|
$karmaGauge = new Gauge();
|
||||||
@ -312,35 +339,6 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
|||||||
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'ManiaExchangeList');
|
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'ManiaExchangeList');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle ManialinkPageAnswer Callback
|
|
||||||
*
|
|
||||||
* @param array $callback
|
|
||||||
*/
|
|
||||||
public function handleManialinkPageAnswer(array $callback) {
|
|
||||||
$actionId = $callback[1][2];
|
|
||||||
$actionArray = explode('.', $actionId);
|
|
||||||
if (count($actionArray) <= 2) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$action = $actionArray[0] . '.' . $actionArray[1];
|
|
||||||
$login = $callback[1][1];
|
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
|
||||||
$mapId = (int)$actionArray[2];
|
|
||||||
|
|
||||||
switch($action) {
|
|
||||||
case self::ACTION_GET_MAPS_FROM_AUTHOR:
|
|
||||||
$callback[1][2] = 'auth:' . $actionArray[2];
|
|
||||||
$this->showList($callback, $player);
|
|
||||||
break;
|
|
||||||
case self::ACTION_ADD_MAP:
|
|
||||||
$this->maniaControl->mapManager->addMapFromMx($mapId, $player->login);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unset the player if he opened another Main Widget
|
* Unset the player if he opened another Main Widget
|
||||||
*
|
*
|
||||||
@ -364,5 +362,4 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
|||||||
unset($this->mapListShown[$player->login]);
|
unset($this->mapListShown[$player->login]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
|
@ -10,8 +10,8 @@ use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
|
|||||||
/**
|
/**
|
||||||
* Mania Exchange Info Searcher Class
|
* Mania Exchange Info Searcher Class
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class ManiaExchangeManager {
|
class ManiaExchangeManager {
|
||||||
@ -57,49 +57,6 @@ class ManiaExchangeManager {
|
|||||||
$this->maniaControl = $maniaControl;
|
$this->maniaControl = $maniaControl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store Map Info from MX and store the mxid in the database and the mx info in the map object
|
|
||||||
*
|
|
||||||
* @param $mxMapInfos
|
|
||||||
*/
|
|
||||||
public function updateMapObjectsWithManiaExchangeIds($mxMapInfos) {
|
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
|
||||||
// Save map data
|
|
||||||
$saveMapQuery = "UPDATE `" . MapManager::TABLE_MAPS . "`
|
|
||||||
SET `mxid` = ?
|
|
||||||
WHERE `uid` = ?;";
|
|
||||||
$saveMapStatement = $mysqli->prepare($saveMapQuery);
|
|
||||||
if ($mysqli->error) {
|
|
||||||
trigger_error($mysqli->error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$saveMapStatement->bind_param('is', $mapMxId, $mapUId);
|
|
||||||
foreach($mxMapInfos as $mxMapInfo) {
|
|
||||||
/** @var MXMapInfo $mxMapInfo */
|
|
||||||
$mapMxId = $mxMapInfo->id;
|
|
||||||
$mapUId = $mxMapInfo->uid;
|
|
||||||
$saveMapStatement->execute();
|
|
||||||
if ($saveMapStatement->error) {
|
|
||||||
trigger_error($saveMapStatement->error);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Take the uid out of the vector
|
|
||||||
if (isset($this->mxIdUidVector[$mxMapInfo->id])) {
|
|
||||||
$uid = $this->mxIdUidVector[$mxMapInfo->id];
|
|
||||||
} else {
|
|
||||||
$uid = $mxMapInfo->uid;
|
|
||||||
}
|
|
||||||
$map = $this->maniaControl->mapManager->getMapByUid($uid);
|
|
||||||
if ($map) {
|
|
||||||
// TODO: how does it come that $map can be empty here? we got an error report for that
|
|
||||||
/** @var Map $map */
|
|
||||||
$map->mx = $mxMapInfo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$saveMapStatement->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unset Map by Mx Id
|
* Unset Map by Mx Id
|
||||||
*
|
*
|
||||||
@ -138,7 +95,7 @@ class ManiaExchangeManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$id = 0;
|
$id = 0;
|
||||||
foreach($maps as $map) {
|
foreach ($maps as $map) {
|
||||||
/** @var Map $map */
|
/** @var Map $map */
|
||||||
$fetchMapStatement->bind_param('i', $map->index);
|
$fetchMapStatement->bind_param('i', $map->index);
|
||||||
$fetchMapStatement->execute();
|
$fetchMapStatement->execute();
|
||||||
@ -182,37 +139,6 @@ class ManiaExchangeManager {
|
|||||||
$fetchMapStatement->close();
|
$fetchMapStatement->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Map Info Asynchronously
|
|
||||||
*
|
|
||||||
* @param $id
|
|
||||||
* @param $function
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function getMapInfo($id, $function) {
|
|
||||||
// Get Title Prefix
|
|
||||||
$titlePrefix = $this->maniaControl->mapManager->getCurrentMap()->getGame();
|
|
||||||
|
|
||||||
// compile search URL
|
|
||||||
$url = 'http://api.mania-exchange.com/' . $titlePrefix . '/maps/?ids=' . $id;
|
|
||||||
|
|
||||||
return $this->maniaControl->fileReader->loadFile($url, function ($mapInfo, $error) use (&$function, $titlePrefix, $url) {
|
|
||||||
$mxMapInfo = null;
|
|
||||||
if ($error) {
|
|
||||||
trigger_error($error);
|
|
||||||
} else {
|
|
||||||
$mxMapList = json_decode($mapInfo);
|
|
||||||
if ($mxMapList === null) {
|
|
||||||
trigger_error('Cannot decode searched JSON data from ' . $url);
|
|
||||||
} else {
|
|
||||||
$mxMapInfo = new MXMapInfo($titlePrefix, $mxMapList[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
call_user_func($function, $mxMapInfo);
|
|
||||||
}, "application/json");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Whole MapList from MX by Mixed Uid and Id String fetch
|
* Get the Whole MapList from MX by Mixed Uid and Id String fetch
|
||||||
*
|
*
|
||||||
@ -244,7 +170,7 @@ class ManiaExchangeManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$maps = array();
|
$maps = array();
|
||||||
foreach($mxMapList as $map) {
|
foreach ($mxMapList as $map) {
|
||||||
if ($map) {
|
if ($map) {
|
||||||
$mxMapObject = new MXMapInfo($titlePrefix, $map);
|
$mxMapObject = new MXMapInfo($titlePrefix, $map);
|
||||||
if ($mxMapObject) {
|
if ($mxMapObject) {
|
||||||
@ -260,6 +186,78 @@ class ManiaExchangeManager {
|
|||||||
return $success;
|
return $success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store Map Info from MX and store the mxid in the database and the mx info in the map object
|
||||||
|
*
|
||||||
|
* @param $mxMapInfos
|
||||||
|
*/
|
||||||
|
public function updateMapObjectsWithManiaExchangeIds($mxMapInfos) {
|
||||||
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
|
// Save map data
|
||||||
|
$saveMapQuery = "UPDATE `" . MapManager::TABLE_MAPS . "`
|
||||||
|
SET `mxid` = ?
|
||||||
|
WHERE `uid` = ?;";
|
||||||
|
$saveMapStatement = $mysqli->prepare($saveMapQuery);
|
||||||
|
if ($mysqli->error) {
|
||||||
|
trigger_error($mysqli->error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$saveMapStatement->bind_param('is', $mapMxId, $mapUId);
|
||||||
|
foreach ($mxMapInfos as $mxMapInfo) {
|
||||||
|
/** @var MXMapInfo $mxMapInfo */
|
||||||
|
$mapMxId = $mxMapInfo->id;
|
||||||
|
$mapUId = $mxMapInfo->uid;
|
||||||
|
$saveMapStatement->execute();
|
||||||
|
if ($saveMapStatement->error) {
|
||||||
|
trigger_error($saveMapStatement->error);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Take the uid out of the vector
|
||||||
|
if (isset($this->mxIdUidVector[$mxMapInfo->id])) {
|
||||||
|
$uid = $this->mxIdUidVector[$mxMapInfo->id];
|
||||||
|
} else {
|
||||||
|
$uid = $mxMapInfo->uid;
|
||||||
|
}
|
||||||
|
$map = $this->maniaControl->mapManager->getMapByUid($uid);
|
||||||
|
if ($map) {
|
||||||
|
// TODO: how does it come that $map can be empty here? we got an error report for that
|
||||||
|
/** @var Map $map */
|
||||||
|
$map->mx = $mxMapInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$saveMapStatement->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Map Info Asynchronously
|
||||||
|
*
|
||||||
|
* @param $id
|
||||||
|
* @param $function
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getMapInfo($id, $function) {
|
||||||
|
// Get Title Prefix
|
||||||
|
$titlePrefix = $this->maniaControl->mapManager->getCurrentMap()->getGame();
|
||||||
|
|
||||||
|
// compile search URL
|
||||||
|
$url = 'http://api.mania-exchange.com/' . $titlePrefix . '/maps/?ids=' . $id;
|
||||||
|
|
||||||
|
return $this->maniaControl->fileReader->loadFile($url, function ($mapInfo, $error) use (&$function, $titlePrefix, $url) {
|
||||||
|
$mxMapInfo = null;
|
||||||
|
if ($error) {
|
||||||
|
trigger_error($error);
|
||||||
|
} else {
|
||||||
|
$mxMapList = json_decode($mapInfo);
|
||||||
|
if ($mxMapList === null) {
|
||||||
|
trigger_error('Cannot decode searched JSON data from ' . $url);
|
||||||
|
} else {
|
||||||
|
$mxMapInfo = new MXMapInfo($titlePrefix, $mxMapList[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
call_user_func($function, $mxMapInfo);
|
||||||
|
}, "application/json");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch a MapList Asynchronously
|
* Fetch a MapList Asynchronously
|
||||||
*
|
*
|
||||||
@ -302,13 +300,13 @@ class ManiaExchangeManager {
|
|||||||
if ($titlePrefix != "tm") {
|
if ($titlePrefix != "tm") {
|
||||||
$url .= '&minexebuild=' . self::MIN_EXE_BUILD;
|
$url .= '&minexebuild=' . self::MIN_EXE_BUILD;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get MapTypes
|
// Get MapTypes
|
||||||
try {
|
try {
|
||||||
$scriptInfos = $this->maniaControl->client->getModeScriptInfo();
|
$scriptInfos = $this->maniaControl->client->getModeScriptInfo();
|
||||||
$mapTypes = $scriptInfos->compatibleMapTypes;
|
$mapTypes = $scriptInfos->compatibleMapTypes;
|
||||||
$url .= '&mtype=' . $mapTypes;
|
$url .= '&mtype=' . $mapTypes;
|
||||||
} catch(NotInScriptModeException $e) {
|
} catch (NotInScriptModeException $e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$success = $this->maniaControl->fileReader->loadFile($url, function ($mapInfo, $error) use (&$function, $titlePrefix) {
|
$success = $this->maniaControl->fileReader->loadFile($url, function ($mapInfo, $error) use (&$function, $titlePrefix) {
|
||||||
@ -332,7 +330,7 @@ class ManiaExchangeManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$maps = array();
|
$maps = array();
|
||||||
foreach($mxMapList as $map) {
|
foreach ($mxMapList as $map) {
|
||||||
if (!empty($map)) {
|
if (!empty($map)) {
|
||||||
array_push($maps, new MXMapInfo($titlePrefix, $map));
|
array_push($maps, new MXMapInfo($titlePrefix, $map));
|
||||||
}
|
}
|
||||||
@ -352,7 +350,7 @@ class ManiaExchangeManager {
|
|||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
private function getEnvironment($env) {
|
private function getEnvironment($env) {
|
||||||
switch($env) {
|
switch ($env) {
|
||||||
case 'TMCanyon':
|
case 'TMCanyon':
|
||||||
return 1;
|
return 1;
|
||||||
case 'TMStadium':
|
case 'TMStadium':
|
||||||
|
@ -12,9 +12,9 @@ use ManiaControl\Players\PlayerManager;
|
|||||||
/**
|
/**
|
||||||
* Class managing the Custom UI Settings
|
* Class managing the Custom UI Settings
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class CustomUIManager implements CallbackListener, TimerListener {
|
class CustomUIManager implements CallbackListener, TimerListener {
|
||||||
/*
|
/*
|
||||||
@ -51,19 +51,6 @@ class CustomUIManager implements CallbackListener, TimerListener {
|
|||||||
$this->customUI = new CustomUI();
|
$this->customUI = new CustomUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the CustomUI Manialink
|
|
||||||
*
|
|
||||||
* @param Player $player
|
|
||||||
*/
|
|
||||||
private function updateManialink(Player $player = null) {
|
|
||||||
if ($player) {
|
|
||||||
$this->maniaControl->manialinkManager->sendManialink($this->customUI, $player->login);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$this->maniaControl->manialinkManager->sendManialink($this->customUI);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle 1Second
|
* Handle 1Second
|
||||||
*
|
*
|
||||||
@ -77,6 +64,19 @@ class CustomUIManager implements CallbackListener, TimerListener {
|
|||||||
$this->updateManialink();
|
$this->updateManialink();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the CustomUI Manialink
|
||||||
|
*
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
private function updateManialink(Player $player = null) {
|
||||||
|
if ($player) {
|
||||||
|
$this->maniaControl->manialinkManager->sendManialink($this->customUI, $player->login);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->maniaControl->manialinkManager->sendManialink($this->customUI);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle PlayerJoined Callback
|
* Handle PlayerJoined Callback
|
||||||
*
|
*
|
||||||
@ -87,9 +87,9 @@ class CustomUIManager implements CallbackListener, TimerListener {
|
|||||||
|
|
||||||
//send it again after 500ms
|
//send it again after 500ms
|
||||||
$self = $this;
|
$self = $this;
|
||||||
$this->maniaControl->timerManager->registerOneTimeListening($this, function($time) use (&$self, &$player){
|
$this->maniaControl->timerManager->registerOneTimeListening($this, function ($time) use (&$self, &$player) {
|
||||||
$self->updateManialink($player);
|
$self->updateManialink($player);
|
||||||
},500);
|
}, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,15 +8,15 @@ use FML\ManiaLink;
|
|||||||
use ManiaControl\Callbacks\CallbackListener;
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
use ManiaControl\Callbacks\CallbackManager;
|
use ManiaControl\Callbacks\CallbackManager;
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Players\PlayerManager;
|
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
|
use ManiaControl\Players\PlayerManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class managing Icons
|
* Class managing Icons
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class IconManager implements CallbackListener {
|
class IconManager implements CallbackListener {
|
||||||
/*
|
/*
|
||||||
@ -95,15 +95,6 @@ class IconManager implements CallbackListener {
|
|||||||
$this->preloadIcons();
|
$this->preloadIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle PlayerConnect Callback
|
|
||||||
*
|
|
||||||
* @param Player $player
|
|
||||||
*/
|
|
||||||
public function handlePlayerConnect(Player $player) {
|
|
||||||
$this->preloadIcons($player);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preload Icons
|
* Preload Icons
|
||||||
*
|
*
|
||||||
@ -115,7 +106,7 @@ class IconManager implements CallbackListener {
|
|||||||
$maniaLink->add($frame);
|
$maniaLink->add($frame);
|
||||||
$frame->setPosition(500, 500);
|
$frame->setPosition(500, 500);
|
||||||
|
|
||||||
foreach($this->icons as $iconUrl) {
|
foreach ($this->icons as $iconUrl) {
|
||||||
$iconQuad = new Quad();
|
$iconQuad = new Quad();
|
||||||
$iconQuad->setImage($iconUrl);
|
$iconQuad->setImage($iconUrl);
|
||||||
$iconQuad->setSize(1, 1);
|
$iconQuad->setSize(1, 1);
|
||||||
@ -125,4 +116,13 @@ class IconManager implements CallbackListener {
|
|||||||
// Send manialink
|
// Send manialink
|
||||||
$this->maniaControl->manialinkManager->sendManialink($maniaLink, $player);
|
$this->maniaControl->manialinkManager->sendManialink($maniaLink, $player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle PlayerConnect Callback
|
||||||
|
*
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
public function handlePlayerConnect(Player $player) {
|
||||||
|
$this->preloadIcons($player);
|
||||||
|
}
|
||||||
}
|
}
|
@ -15,27 +15,27 @@ use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Manialink Manager Class
|
* Manialink Manager Class
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener {
|
class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener {
|
||||||
/*
|
/*
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const MAIN_MLID = 'Main.ManiaLinkId';
|
const MAIN_MLID = 'Main.ManiaLinkId';
|
||||||
const ACTION_CLOSEWIDGET = 'ManiaLinkManager.CloseWidget';
|
const ACTION_CLOSEWIDGET = 'ManiaLinkManager.CloseWidget';
|
||||||
const CB_MAIN_WINDOW_CLOSED = 'ManialinkManagerCallback.MainWindowClosed';
|
const CB_MAIN_WINDOW_CLOSED = 'ManialinkManagerCallback.MainWindowClosed';
|
||||||
const CB_MAIN_WINDOW_OPENED = 'ManialinkManagerCallback.MainWindowOpened';
|
const CB_MAIN_WINDOW_OPENED = 'ManialinkManagerCallback.MainWindowOpened';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Public Properties
|
* Public Properties
|
||||||
*/
|
*/
|
||||||
public $styleManager = null;
|
public $styleManager = null;
|
||||||
public $customUIManager = null;
|
public $customUIManager = null;
|
||||||
public $iconManager = null;
|
public $iconManager = null;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Private Properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
@ -45,15 +45,15 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new manialink manager
|
* Create a new manialink manager
|
||||||
*
|
*
|
||||||
* @param ManiaControl $maniaControl
|
* @param ManiaControl $maniaControl
|
||||||
*/
|
*/
|
||||||
public function __construct(ManiaControl $maniaControl) {
|
public function __construct(ManiaControl $maniaControl) {
|
||||||
$this->maniaControl = $maniaControl;
|
$this->maniaControl = $maniaControl;
|
||||||
$this->styleManager = new StyleManager($maniaControl);
|
$this->styleManager = new StyleManager($maniaControl);
|
||||||
$this->customUIManager = new CustomUIManager($maniaControl);
|
$this->customUIManager = new CustomUIManager($maniaControl);
|
||||||
$this->iconManager = new IconManager($maniaControl);
|
$this->iconManager = new IconManager($maniaControl);
|
||||||
|
|
||||||
// Register for callbacks
|
// Register for callbacks
|
||||||
$this->registerManialinkPageAnswerListener(self::ACTION_CLOSEWIDGET, $this, 'closeWidgetCallback');
|
$this->registerManialinkPageAnswerListener(self::ACTION_CLOSEWIDGET, $this, 'closeWidgetCallback');
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||||
@ -61,10 +61,10 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a new manialink page answer listener
|
* Register a new manialink page answer listener
|
||||||
*
|
*
|
||||||
* @param string $actionId
|
* @param string $actionId
|
||||||
* @param ManialinkPageAnswerListener $listener
|
* @param ManialinkPageAnswerListener $listener
|
||||||
* @param string $method
|
* @param string $method
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function registerManialinkPageAnswerListener($actionId, ManialinkPageAnswerListener $listener, $method) {
|
public function registerManialinkPageAnswerListener($actionId, ManialinkPageAnswerListener $listener, $method) {
|
||||||
@ -72,24 +72,24 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
|||||||
trigger_error("Given listener for actionId '{$actionId}' doesn't have callback method '{$method}'!");
|
trigger_error("Given listener for actionId '{$actionId}' doesn't have callback method '{$method}'!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!array_key_exists($actionId, $this->pageAnswerListeners) || !is_array($this->pageAnswerListeners[$actionId])) {
|
if (!array_key_exists($actionId, $this->pageAnswerListeners) || !is_array($this->pageAnswerListeners[$actionId])) {
|
||||||
// Init listeners array
|
// Init listeners array
|
||||||
$this->pageAnswerListeners[$actionId] = array();
|
$this->pageAnswerListeners[$actionId] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register page answer listener
|
// Register page answer listener
|
||||||
array_push($this->pageAnswerListeners[$actionId], array($listener, $method));
|
array_push($this->pageAnswerListeners[$actionId], array($listener, $method));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a new manialink page answer reg ex listener
|
* Register a new manialink page answer reg ex listener
|
||||||
*
|
*
|
||||||
* @param string $actionIdRegex
|
* @param string $actionIdRegex
|
||||||
* @param ManialinkPageAnswerListener $listener
|
* @param ManialinkPageAnswerListener $listener
|
||||||
* @param string $method
|
* @param string $method
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function registerManialinkPageAnswerRegexListener($actionIdRegex, ManialinkPageAnswerListener $listener, $method) {
|
public function registerManialinkPageAnswerRegexListener($actionIdRegex, ManialinkPageAnswerListener $listener, $method) {
|
||||||
@ -97,26 +97,26 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
|||||||
trigger_error("Given listener for actionIdRegex '{$actionIdRegex}' doesn't have callback method '{$method}'!");
|
trigger_error("Given listener for actionIdRegex '{$actionIdRegex}' doesn't have callback method '{$method}'!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!array_key_exists($actionIdRegex, $this->pageAnswerRegexListener) || !is_array($this->pageAnswerRegexListener[$actionIdRegex])) {
|
if (!array_key_exists($actionIdRegex, $this->pageAnswerRegexListener) || !is_array($this->pageAnswerRegexListener[$actionIdRegex])) {
|
||||||
// Init regex listeners array
|
// Init regex listeners array
|
||||||
$this->pageAnswerRegexListener[$actionIdRegex] = array();
|
$this->pageAnswerRegexListener[$actionIdRegex] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register page answer reg exlistener
|
// Register page answer reg exlistener
|
||||||
array_push($this->pageAnswerRegexListener[$actionIdRegex], array($listener, $method));
|
array_push($this->pageAnswerRegexListener[$actionIdRegex], array($listener, $method));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a Manialink Page Answer Listener
|
* Remove a Manialink Page Answer Listener
|
||||||
*
|
*
|
||||||
* @param ManialinkPageAnswerListener $listener
|
* @param ManialinkPageAnswerListener $listener
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function unregisterManialinkPageAnswerListener(ManialinkPageAnswerListener $listener) {
|
public function unregisterManialinkPageAnswerListener(ManialinkPageAnswerListener $listener) {
|
||||||
$removed = false;
|
$removed = false;
|
||||||
$allListeners = array_merge($this->pageAnswerListeners, $this->pageAnswerRegexListener);
|
$allListeners = array_merge($this->pageAnswerListeners, $this->pageAnswerRegexListener);
|
||||||
foreach ($allListeners as &$listeners) {
|
foreach ($allListeners as &$listeners) {
|
||||||
foreach ($listeners as $key => &$listenerCallback) {
|
foreach ($listeners as $key => &$listenerCallback) {
|
||||||
@ -132,21 +132,21 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle ManialinkPageAnswer callback
|
* Handle ManialinkPageAnswer callback
|
||||||
*
|
*
|
||||||
* @param array $callback
|
* @param array $callback
|
||||||
*/
|
*/
|
||||||
public function handleManialinkPageAnswer(array $callback) {
|
public function handleManialinkPageAnswer(array $callback) {
|
||||||
$actionId = $callback[1][2];
|
$actionId = $callback[1][2];
|
||||||
$login = $callback[1][1];
|
$login = $callback[1][1];
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
|
|
||||||
if (array_key_exists($actionId, $this->pageAnswerListeners) && is_array($this->pageAnswerListeners[$actionId])) {
|
if (array_key_exists($actionId, $this->pageAnswerListeners) && is_array($this->pageAnswerListeners[$actionId])) {
|
||||||
// Inform page answer listeners
|
// Inform page answer listeners
|
||||||
foreach ($this->pageAnswerListeners[$actionId] as $listener) {
|
foreach ($this->pageAnswerListeners[$actionId] as $listener) {
|
||||||
call_user_func($listener, $callback, $player);
|
call_user_func($listener, $callback, $player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check regex listeners
|
// Check regex listeners
|
||||||
foreach ($this->pageAnswerRegexListener as $actionIdRegex => $pageAnswerRegexListeners) {
|
foreach ($this->pageAnswerRegexListener as $actionIdRegex => $pageAnswerRegexListeners) {
|
||||||
if (preg_match($actionIdRegex, $actionId)) {
|
if (preg_match($actionIdRegex, $actionId)) {
|
||||||
@ -160,7 +160,7 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Hide the Manialink with the given Id
|
* Hide the Manialink with the given Id
|
||||||
*
|
*
|
||||||
* @param mixed $manialinkId
|
* @param mixed $manialinkId
|
||||||
* @param mixed $logins
|
* @param mixed $logins
|
||||||
*/
|
*/
|
||||||
@ -174,23 +174,23 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
|||||||
$this->sendManialink($emptyManialink, $logins);
|
$this->sendManialink($emptyManialink, $logins);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send the given manialink to players
|
* Send the given manialink to players
|
||||||
*
|
*
|
||||||
* @param string $manialinkText
|
* @param string $manialinkText
|
||||||
* @param mixed $logins
|
* @param mixed $logins
|
||||||
* @param int $timeout
|
* @param int $timeout
|
||||||
* @param bool $hideOnClick
|
* @param bool $hideOnClick
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function sendManialink($manialinkText, $logins = null, $timeout = 0, $hideOnClick = false) {
|
public function sendManialink($manialinkText, $logins = null, $timeout = 0, $hideOnClick = false) {
|
||||||
$manialinkText = (string) $manialinkText;
|
$manialinkText = (string)$manialinkText;
|
||||||
|
|
||||||
if (!$manialinkText) {
|
if (!$manialinkText) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!$logins) {
|
if (!$logins) {
|
||||||
return $this->maniaControl->client->sendDisplayManialinkPage(null, $manialinkText, $timeout, $hideOnClick);
|
return $this->maniaControl->client->sendDisplayManialinkPage(null, $manialinkText, $timeout, $hideOnClick);
|
||||||
@ -211,60 +211,27 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
|||||||
$success = false;
|
$success = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $success;
|
return $success;
|
||||||
}
|
}
|
||||||
}
|
} catch (LoginUnknownException $e) {
|
||||||
catch (LoginUnknownException $e) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Enable the alt menu for the player
|
|
||||||
*
|
|
||||||
* @param Player $player
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function enableAltMenu(Player $player) {
|
|
||||||
try {
|
|
||||||
$success = $this->maniaControl->client->triggerModeScriptEvent('LibXmlRpc_EnableAltMenu', $player->login);
|
|
||||||
}
|
|
||||||
catch (NotInScriptModeException $e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return $success;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disable the alt menu for the player
|
|
||||||
*
|
|
||||||
* @param Player $player
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function disableAltMenu(Player $player) {
|
|
||||||
try {
|
|
||||||
$success = $this->maniaControl->client->triggerModeScriptEvent('LibXmlRpc_DisableAltMenu', $player->login);
|
|
||||||
}
|
|
||||||
catch (NotInScriptModeException $e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return $success;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays a ManiaLink Widget to a certain Player (Should only be used on Main Widgets)
|
* Displays a ManiaLink Widget to a certain Player (Should only be used on Main Widgets)
|
||||||
*
|
*
|
||||||
* @param mixed $maniaLink
|
* @param mixed $maniaLink
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
* @param string $widgetName
|
* @param string $widgetName
|
||||||
*/
|
*/
|
||||||
public function displayWidget($maniaLink, Player $player, $widgetName = '') {
|
public function displayWidget($maniaLink, Player $player, $widgetName = '') {
|
||||||
// render and display xml
|
// render and display xml
|
||||||
$this->sendManialink($maniaLink, $player->login);
|
$this->sendManialink($maniaLink, $player->login);
|
||||||
|
|
||||||
if ($widgetName != '') {
|
if ($widgetName != '') {
|
||||||
// TODO make check by manialinkId, getter is needed to avoid uses on non main widgets
|
// TODO make check by manialinkId, getter is needed to avoid uses on non main widgets
|
||||||
$this->disableAltMenu($player);
|
$this->disableAltMenu($player);
|
||||||
@ -273,10 +240,25 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable the alt menu for the player
|
||||||
|
*
|
||||||
|
* @param Player $player
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function disableAltMenu(Player $player) {
|
||||||
|
try {
|
||||||
|
$success = $this->maniaControl->client->triggerModeScriptEvent('LibXmlRpc_DisableAltMenu', $player->login);
|
||||||
|
} catch (NotInScriptModeException $e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return $success;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes a widget via the callback
|
* Closes a widget via the callback
|
||||||
*
|
*
|
||||||
* @param array $callback
|
* @param array $callback
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
public function closeWidgetCallback(array $callback, Player $player) {
|
public function closeWidgetCallback(array $callback, Player $player) {
|
||||||
@ -285,28 +267,42 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes a Manialink Widget
|
* Closes a Manialink Widget
|
||||||
*
|
*
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
* @param bool $widgetId
|
* @param bool $widgetId
|
||||||
*/
|
*/
|
||||||
public function closeWidget(Player $player, $widgetId = false) {
|
public function closeWidget(Player $player, $widgetId = false) {
|
||||||
if (!$widgetId) {
|
if (!$widgetId) {
|
||||||
$emptyManialink = new ManiaLink(self::MAIN_MLID);
|
$emptyManialink = new ManiaLink(self::MAIN_MLID);
|
||||||
$this->sendManialink($emptyManialink, $player->login);
|
$this->sendManialink($emptyManialink, $player->login);
|
||||||
$this->enableAltMenu($player);
|
$this->enableAltMenu($player);
|
||||||
|
|
||||||
// Trigger callback
|
// Trigger callback
|
||||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAIN_WINDOW_CLOSED, $player);
|
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAIN_WINDOW_CLOSED, $player);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$emptyManialink = new ManiaLink($widgetId);
|
$emptyManialink = new ManiaLink($widgetId);
|
||||||
$this->sendManialink($emptyManialink, $player->login);
|
$this->sendManialink($emptyManialink, $player->login);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable the alt menu for the player
|
||||||
|
*
|
||||||
|
* @param Player $player
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function enableAltMenu(Player $player) {
|
||||||
|
try {
|
||||||
|
$success = $this->maniaControl->client->triggerModeScriptEvent('LibXmlRpc_EnableAltMenu', $player->login);
|
||||||
|
} catch (NotInScriptModeException $e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return $success;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a line of labels
|
* Adds a line of labels
|
||||||
*
|
*
|
||||||
* @param Frame $frame
|
* @param Frame $frame
|
||||||
* @param array $labelStrings
|
* @param array $labelStrings
|
||||||
* @param array $properties
|
* @param array $properties
|
||||||
@ -314,12 +310,12 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
|||||||
*/
|
*/
|
||||||
public function labelLine(Frame $frame, array $labelStrings, array $properties = array()) {
|
public function labelLine(Frame $frame, array $labelStrings, array $properties = array()) {
|
||||||
// define standard properties
|
// define standard properties
|
||||||
$hAlign = (isset($properties['hAlign']) ? $properties['hAlign'] : Control::LEFT);
|
$hAlign = (isset($properties['hAlign']) ? $properties['hAlign'] : Control::LEFT);
|
||||||
$style = (isset($properties['style']) ? $properties['style'] : Label_Text::STYLE_TextCardSmall);
|
$style = (isset($properties['style']) ? $properties['style'] : Label_Text::STYLE_TextCardSmall);
|
||||||
$textSize = (isset($properties['textSize']) ? $properties['textSize'] : 1.5);
|
$textSize = (isset($properties['textSize']) ? $properties['textSize'] : 1.5);
|
||||||
$textColor = (isset($properties['textColor']) ? $properties['textColor'] : 'FFF');
|
$textColor = (isset($properties['textColor']) ? $properties['textColor'] : 'FFF');
|
||||||
$profile = (isset($properties['profile']) ? $properties['profile'] : false);
|
$profile = (isset($properties['profile']) ? $properties['profile'] : false);
|
||||||
|
|
||||||
$labels = array();
|
$labels = array();
|
||||||
foreach ($labelStrings as $text => $x) {
|
foreach ($labelStrings as $text => $x) {
|
||||||
$label = new Label_Text();
|
$label = new Label_Text();
|
||||||
@ -330,14 +326,14 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
|||||||
$label->setTextSize($textSize);
|
$label->setTextSize($textSize);
|
||||||
$label->setText($text);
|
$label->setText($text);
|
||||||
$label->setTextColor($textColor);
|
$label->setTextColor($textColor);
|
||||||
|
|
||||||
if ($profile) {
|
if ($profile) {
|
||||||
$label->addPlayerProfileFeature($profile);
|
$label->addPlayerProfileFeature($profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
$labels[] = $label; // add Label to the labels array
|
$labels[] = $label; // add Label to the labels array
|
||||||
}
|
}
|
||||||
|
|
||||||
return $labels;
|
return $labels;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,9 @@ namespace ManiaControl\Manialinks;
|
|||||||
/**
|
/**
|
||||||
* Interface for Manialink Page Answer Listeners
|
* Interface for Manialink Page Answer Listeners
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
interface ManialinkPageAnswerListener {
|
interface ManialinkPageAnswerListener {
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,9 @@ use ManiaControl\ManiaControl;
|
|||||||
/**
|
/**
|
||||||
* Class managing default Control Styles
|
* Class managing default Control Styles
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class StyleManager {
|
class StyleManager {
|
||||||
/*
|
/*
|
||||||
@ -97,43 +97,6 @@ class StyleManager {
|
|||||||
return $this->maniaControl->settingManager->getSetting($this, self::SETTING_QUAD_DEFAULT_SUBSTYLE);
|
return $this->maniaControl->settingManager->getSetting($this, self::SETTING_QUAD_DEFAULT_SUBSTYLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the default main window style
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getDefaultMainWindowStyle() {
|
|
||||||
return $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAIN_WIDGET_DEFAULT_STYLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the default main window substyle
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getDefaultMainWindowSubStyle() {
|
|
||||||
return $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAIN_WIDGET_DEFAULT_SUBSTYLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the default list widget width
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getListWidgetsWidth() {
|
|
||||||
return $this->maniaControl->settingManager->getSetting($this, self::SETTING_LIST_WIDGETS_WIDTH);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the default list widget height
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getListWidgetsHeight() {
|
|
||||||
return $this->maniaControl->settingManager->getSetting($this, self::SETTING_LIST_WIDGETS_HEIGHT);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the Default Description Label
|
* Gets the Default Description Label
|
||||||
*
|
*
|
||||||
@ -154,13 +117,31 @@ class StyleManager {
|
|||||||
return $descriptionLabel;
|
return $descriptionLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the default list widget width
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getListWidgetsWidth() {
|
||||||
|
return $this->maniaControl->settingManager->getSetting($this, self::SETTING_LIST_WIDGETS_WIDTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the default list widget height
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getListWidgetsHeight() {
|
||||||
|
return $this->maniaControl->settingManager->getSetting($this, self::SETTING_LIST_WIDGETS_HEIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the Default List Frame
|
* Builds the Default List Frame
|
||||||
*
|
*
|
||||||
* @return Frame $frame
|
* @return Frame $frame
|
||||||
*/
|
*/
|
||||||
public function getDefaultListFrame() {
|
public function getDefaultListFrame() {
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
$script = null;
|
$script = null;
|
||||||
$paging = null;
|
$paging = null;
|
||||||
foreach ($args as $arg) {
|
foreach ($args as $arg) {
|
||||||
@ -171,7 +152,7 @@ class StyleManager {
|
|||||||
$paging = $arg;
|
$paging = $arg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$width = $this->getListWidgetsWidth();
|
$width = $this->getListWidgetsWidth();
|
||||||
$height = $this->getListWidgetsHeight();
|
$height = $this->getListWidgetsHeight();
|
||||||
$quadStyle = $this->getDefaultMainWindowStyle();
|
$quadStyle = $this->getDefaultMainWindowStyle();
|
||||||
@ -210,10 +191,10 @@ class StyleManager {
|
|||||||
$pagerNext->setSize($pagerSize, $pagerSize);
|
$pagerNext->setSize($pagerSize, $pagerSize);
|
||||||
$pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext);
|
$pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext);
|
||||||
|
|
||||||
if ($paging) {
|
if ($paging) {
|
||||||
$paging->addButton($pagerNext);
|
$paging->addButton($pagerNext);
|
||||||
$paging->addButton($pagerPrev);
|
$paging->addButton($pagerPrev);
|
||||||
}
|
}
|
||||||
|
|
||||||
$pageCountLabel = new Label_Text();
|
$pageCountLabel = new Label_Text();
|
||||||
$frame->add($pageCountLabel);
|
$frame->add($pageCountLabel);
|
||||||
@ -221,11 +202,29 @@ class StyleManager {
|
|||||||
$pageCountLabel->setPosition($width * 0.40, $height * -0.44, 1);
|
$pageCountLabel->setPosition($width * 0.40, $height * -0.44, 1);
|
||||||
$pageCountLabel->setStyle($pageCountLabel::STYLE_TextTitle1);
|
$pageCountLabel->setStyle($pageCountLabel::STYLE_TextTitle1);
|
||||||
$pageCountLabel->setTextSize(1.3);
|
$pageCountLabel->setTextSize(1.3);
|
||||||
if ($paging) {
|
if ($paging) {
|
||||||
$paging->setLabel($pageCountLabel);
|
$paging->setLabel($pageCountLabel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $frame;
|
return $frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the default main window style
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDefaultMainWindowStyle() {
|
||||||
|
return $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAIN_WIDGET_DEFAULT_STYLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the default main window substyle
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDefaultMainWindowSubStyle() {
|
||||||
|
return $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAIN_WIDGET_DEFAULT_SUBSTYLE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,10 @@ use ManiaControl\Formatter;
|
|||||||
use ManiaControl\ManiaExchange\MXMapInfo;
|
use ManiaControl\ManiaExchange\MXMapInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map Class
|
* Map Model Class
|
||||||
*
|
*
|
||||||
* @author kremsy & steeffeen
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class Map {
|
class Map {
|
||||||
@ -76,7 +76,7 @@ class Map {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getGame() {
|
public function getGame() {
|
||||||
switch($this->environment) {
|
switch ($this->environment) {
|
||||||
case 'Storm':
|
case 'Storm':
|
||||||
return "sm";
|
return "sm";
|
||||||
case 'Canyon':
|
case 'Canyon':
|
||||||
|
@ -5,8 +5,8 @@ namespace ManiaControl\Maps;
|
|||||||
use FML\Controls\Quad;
|
use FML\Controls\Quad;
|
||||||
use FML\Controls\Quads\Quad_Icons64x64_1;
|
use FML\Controls\Quads\Quad_Icons64x64_1;
|
||||||
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
|
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
|
||||||
use ManiaControl\Callbacks\CallbackManager;
|
|
||||||
use ManiaControl\Callbacks\CallbackListener;
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
|
use ManiaControl\Callbacks\CallbackManager;
|
||||||
use ManiaControl\Commands\CommandListener;
|
use ManiaControl\Commands\CommandListener;
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Manialinks\IconManager;
|
use ManiaControl\Manialinks\IconManager;
|
||||||
@ -18,8 +18,8 @@ use Maniaplanet\DedicatedServer\Xmlrpc\FaultException;
|
|||||||
/**
|
/**
|
||||||
* Class offering Commands to manage Maps
|
* Class offering Commands to manage Maps
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class MapCommands implements CommandListener, ManialinkPageAnswerListener, CallbackListener {
|
class MapCommands implements CommandListener, ManialinkPageAnswerListener, CallbackListener {
|
||||||
@ -194,7 +194,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->nextMap();
|
$this->maniaControl->client->nextMap();
|
||||||
} catch(ChangeInProgressException $e) {
|
} catch (ChangeInProgressException $e) {
|
||||||
}
|
}
|
||||||
$message = '$<' . $player->nickname . '$> skipped the current Map!';
|
$message = '$<' . $player->nickname . '$> skipped the current Map!';
|
||||||
$this->maniaControl->chat->sendSuccess($message);
|
$this->maniaControl->chat->sendSuccess($message);
|
||||||
@ -218,7 +218,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->restartMap();
|
$this->maniaControl->client->restartMap();
|
||||||
} catch(ChangeInProgressException $e) {
|
} catch (ChangeInProgressException $e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,25 +254,25 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
|
|||||||
}
|
}
|
||||||
|
|
||||||
$chatCommand = explode(' ', $chat[1][2]);
|
$chatCommand = explode(' ', $chat[1][2]);
|
||||||
if(isset($chatCommand[1])) {
|
if (isset($chatCommand[1])) {
|
||||||
if(strstr($chatCommand[1], '.txt')) {
|
if (strstr($chatCommand[1], '.txt')) {
|
||||||
$maplist = $chatCommand[1];
|
$maplist = $chatCommand[1];
|
||||||
} else {
|
} else {
|
||||||
$maplist = $chatCommand.'.txt';
|
$maplist = $chatCommand . '.txt';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$maplist = 'maplist.txt';
|
$maplist = 'maplist.txt';
|
||||||
}
|
}
|
||||||
|
|
||||||
$maplist = 'MatchSettings/'.$maplist;
|
$maplist = 'MatchSettings/' . $maplist;
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->saveMatchSettings($maplist);
|
$this->maniaControl->client->saveMatchSettings($maplist);
|
||||||
|
|
||||||
$message = 'Maplist $<$fff'.$maplist.'$> written.';
|
$message = 'Maplist $<$fff' . $maplist . '$> written.';
|
||||||
$this->maniaControl->chat->sendSuccess($message, $player);
|
$this->maniaControl->chat->sendSuccess($message, $player);
|
||||||
$this->maniaControl->log($message, true);
|
$this->maniaControl->log($message, true);
|
||||||
} catch(FaultException $e) {
|
} catch (FaultException $e) {
|
||||||
$this->maniaControl->chat->sendError('Cannot write maplist $<$fff'.$maplist.'$>!', $player);
|
$this->maniaControl->chat->sendError('Cannot write maplist $<$fff' . $maplist . '$>!', $player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,26 +289,26 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
|
|||||||
}
|
}
|
||||||
|
|
||||||
$chatCommand = explode(' ', $chat[1][2]);
|
$chatCommand = explode(' ', $chat[1][2]);
|
||||||
if(isset($chatCommand[1])) {
|
if (isset($chatCommand[1])) {
|
||||||
if(strstr($chatCommand[1], '.txt')) {
|
if (strstr($chatCommand[1], '.txt')) {
|
||||||
$maplist = $chatCommand[1];
|
$maplist = $chatCommand[1];
|
||||||
} else {
|
} else {
|
||||||
$maplist = $chatCommand[1].'.txt';
|
$maplist = $chatCommand[1] . '.txt';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$maplist = 'maplist.txt';
|
$maplist = 'maplist.txt';
|
||||||
}
|
}
|
||||||
|
|
||||||
$maplist = 'MatchSettings/'.$maplist;
|
$maplist = 'MatchSettings/' . $maplist;
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->loadMatchSettings($maplist);
|
$this->maniaControl->client->loadMatchSettings($maplist);
|
||||||
|
|
||||||
$message = 'Maplist $<$fff'.$maplist.'$> loaded.';
|
$message = 'Maplist $<$fff' . $maplist . '$> loaded.';
|
||||||
$this->maniaControl->mapManager->restructureMapList();
|
$this->maniaControl->mapManager->restructureMapList();
|
||||||
$this->maniaControl->chat->sendSuccess($message, $player);
|
$this->maniaControl->chat->sendSuccess($message, $player);
|
||||||
$this->maniaControl->log($message, true);
|
$this->maniaControl->log($message, true);
|
||||||
} catch(FaultException $e) {
|
} catch (FaultException $e) {
|
||||||
$this->maniaControl->chat->sendError('Cannot load maplist $<$fff'.$maplist.'$>!', $player);
|
$this->maniaControl->chat->sendError('Cannot load maplist $<$fff' . $maplist . '$>!', $player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,7 +320,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
|
|||||||
public function handleManialinkPageAnswer(array $callback) {
|
public function handleManialinkPageAnswer(array $callback) {
|
||||||
$actionId = $callback[1][2];
|
$actionId = $callback[1][2];
|
||||||
|
|
||||||
$login = $callback[1][1];
|
$login = $callback[1][1];
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
|
|
||||||
if (strstr($actionId, self::ACTION_SHOW_AUTHOR)) {
|
if (strstr($actionId, self::ACTION_SHOW_AUTHOR)) {
|
||||||
@ -330,6 +330,30 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the Player a List of Maps from the given Author
|
||||||
|
*
|
||||||
|
* @param string $author
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
private function showMapListAuthor($author, Player $player) {
|
||||||
|
$maps = $this->maniaControl->mapManager->getMaps();
|
||||||
|
$mapList = array();
|
||||||
|
/** @var Map $map */
|
||||||
|
foreach ($maps as $map) {
|
||||||
|
if ($map->authorLogin == $author) {
|
||||||
|
$mapList[] = $map;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($mapList) == 0) {
|
||||||
|
$this->maniaControl->chat->sendError('There are no maps to show!', $player->login);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->maniaControl->mapManager->mapList->showMapList($player, $mapList);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle /maps command
|
* Handle /maps command
|
||||||
*
|
*
|
||||||
@ -339,19 +363,19 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
|
|||||||
public function command_List(array $chatCallback, Player $player) {
|
public function command_List(array $chatCallback, Player $player) {
|
||||||
$chatCommands = explode(' ', $chatCallback[1][2]);
|
$chatCommands = explode(' ', $chatCallback[1][2]);
|
||||||
$this->maniaControl->mapManager->mapList->playerCloseWidget($player);
|
$this->maniaControl->mapManager->mapList->playerCloseWidget($player);
|
||||||
if(isset($chatCommands[1])) {
|
if (isset($chatCommands[1])) {
|
||||||
if($chatCommands[1] == ' ' || $chatCommands[1] == 'all') {
|
if ($chatCommands[1] == ' ' || $chatCommands[1] == 'all') {
|
||||||
$this->maniaControl->mapManager->mapList->showMapList($player);
|
$this->maniaControl->mapManager->mapList->showMapList($player);
|
||||||
} elseif($chatCommands[1] == 'best') {
|
} elseif ($chatCommands[1] == 'best') {
|
||||||
$this->showMapListKarma(true, $player);
|
$this->showMapListKarma(true, $player);
|
||||||
} elseif($chatCommands[1] == 'worst') {
|
} elseif ($chatCommands[1] == 'worst') {
|
||||||
$this->showMapListKarma(false, $player);
|
$this->showMapListKarma(false, $player);
|
||||||
} elseif($chatCommands[1] == 'newest') {
|
} elseif ($chatCommands[1] == 'newest') {
|
||||||
$this->showMapListDate(true, $player);
|
$this->showMapListDate(true, $player);
|
||||||
} elseif($chatCommands[1] == 'oldest') {
|
} elseif ($chatCommands[1] == 'oldest') {
|
||||||
$this->showMapListDate(false, $player);
|
$this->showMapListDate(false, $player);
|
||||||
} elseif($chatCommands[1] == 'author') {
|
} elseif ($chatCommands[1] == 'author') {
|
||||||
if(isset($chatCommands[2])) {
|
if (isset($chatCommands[2])) {
|
||||||
$this->showMaplistAuthor($chatCommands[2], $player);
|
$this->showMaplistAuthor($chatCommands[2], $player);
|
||||||
} else {
|
} else {
|
||||||
$this->maniaControl->chat->sendError('There are no maps to show!', $player->login);
|
$this->maniaControl->chat->sendError('There are no maps to show!', $player->login);
|
||||||
@ -362,69 +386,46 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Show the Player a List of Maps from the given Author
|
|
||||||
* @param string $author
|
|
||||||
* @param Player $player
|
|
||||||
*/
|
|
||||||
private function showMapListAuthor($author, Player $player) {
|
|
||||||
$maps = $this->maniaControl->mapManager->getMaps();
|
|
||||||
$mapList = array();
|
|
||||||
/** @var Map $map */
|
|
||||||
foreach($maps as $map) {
|
|
||||||
if($map->authorLogin == $author) {
|
|
||||||
$mapList[] = $map;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(count($mapList) == 0) {
|
|
||||||
$this->maniaControl->chat->sendError('There are no maps to show!', $player->login);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->maniaControl->mapManager->mapList->showMapList($player, $mapList);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show a Karma based MapList
|
* Show a Karma based MapList
|
||||||
*
|
*
|
||||||
* @param bool $best
|
* @param bool $best
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
private function showMapListKarma($best, Player $player) {
|
private function showMapListKarma($best, Player $player) {
|
||||||
/** @var \MCTeam\KarmaPlugin $karmaPlugin */
|
/** @var \MCTeam\KarmaPlugin $karmaPlugin */
|
||||||
$karmaPlugin = $this->maniaControl->pluginManager->getPlugin(MapList::DEFAULT_KARMA_PLUGIN);
|
$karmaPlugin = $this->maniaControl->pluginManager->getPlugin(MapList::DEFAULT_KARMA_PLUGIN);
|
||||||
if($karmaPlugin) {
|
if ($karmaPlugin) {
|
||||||
$maps = $this->maniaControl->mapManager->getMaps();
|
$maps = $this->maniaControl->mapManager->getMaps();
|
||||||
$mapList = array();
|
$mapList = array();
|
||||||
foreach($maps as $map) {
|
foreach ($maps as $map) {
|
||||||
if($map instanceof Map) {
|
if ($map instanceof Map) {
|
||||||
if($this->maniaControl->settingManager->getSetting($karmaPlugin, $karmaPlugin::SETTING_NEWKARMA) === true) {
|
if ($this->maniaControl->settingManager->getSetting($karmaPlugin, $karmaPlugin::SETTING_NEWKARMA) === true) {
|
||||||
$karma = $karmaPlugin->getMapKarma($map);
|
$karma = $karmaPlugin->getMapKarma($map);
|
||||||
$map->karma = round($karma * 100.);
|
$map->karma = round($karma * 100.);
|
||||||
} else {
|
} else {
|
||||||
$votes = $karmaPlugin->getMapVotes($map);
|
$votes = $karmaPlugin->getMapVotes($map);
|
||||||
$min = 0;
|
$min = 0;
|
||||||
$plus = 0;
|
$plus = 0;
|
||||||
foreach($votes as $vote) {
|
foreach ($votes as $vote) {
|
||||||
if(isset($vote->vote)) {
|
if (isset($vote->vote)) {
|
||||||
if($vote->vote != 0.5) {
|
if ($vote->vote != 0.5) {
|
||||||
if($vote->vote < 0.5) {
|
if ($vote->vote < 0.5) {
|
||||||
$min = $min+$vote->count;
|
$min = $min + $vote->count;
|
||||||
} else {
|
} else {
|
||||||
$plus = $plus+$vote->count;
|
$plus = $plus + $vote->count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$map->karma = $plus-$min;
|
$map->karma = $plus - $min;
|
||||||
}
|
}
|
||||||
$mapList[] = $map;
|
$mapList[] = $map;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
usort($mapList, array($this, 'sortByKarma'));
|
usort($mapList, array($this, 'sortByKarma'));
|
||||||
if($best) {
|
if ($best) {
|
||||||
$mapList = array_reverse($mapList);
|
$mapList = array_reverse($mapList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -434,31 +435,20 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper Function to sort Maps by Karma
|
|
||||||
*
|
|
||||||
* @param Map $a
|
|
||||||
* @param Map $b
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
private function sortByKarma($a, $b) {
|
|
||||||
return ($a->karma - $b->karma);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show a Date based MapList
|
* Show a Date based MapList
|
||||||
*
|
*
|
||||||
* @param bool $newest
|
* @param bool $newest
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
private function showMapListDate($newest, Player $player) {
|
private function showMapListDate($newest, Player $player) {
|
||||||
$maps = $this->maniaControl->mapManager->getMaps();
|
$maps = $this->maniaControl->mapManager->getMaps();
|
||||||
|
|
||||||
usort($maps, function($a, $b) {
|
usort($maps, function ($a, $b) {
|
||||||
return ($a->index - $b->index);
|
return ($a->index - $b->index);
|
||||||
});
|
});
|
||||||
|
|
||||||
if($newest) {
|
if ($newest) {
|
||||||
$maps = array_reverse($maps);
|
$maps = array_reverse($maps);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -474,4 +464,15 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
|
|||||||
public function command_xList(array $chatCallback, Player $player) {
|
public function command_xList(array $chatCallback, Player $player) {
|
||||||
$this->maniaControl->mapManager->mxList->showList($chatCallback, $player);
|
$this->maniaControl->mapManager->mxList->showList($chatCallback, $player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper Function to sort Maps by Karma
|
||||||
|
*
|
||||||
|
* @param Map $a
|
||||||
|
* @param Map $b
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
private function sortByKarma($a, $b) {
|
||||||
|
return ($a->karma - $b->karma);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace ManiaControl\Maps;
|
namespace ManiaControl\Maps;
|
||||||
|
|
||||||
use MCTeam\CustomVotesPlugin;
|
|
||||||
use FML\Controls\Control;
|
use FML\Controls\Control;
|
||||||
use FML\Controls\Frame;
|
use FML\Controls\Frame;
|
||||||
use FML\Controls\Gauge;
|
use FML\Controls\Gauge;
|
||||||
@ -25,33 +24,34 @@ use ManiaControl\Manialinks\ManialinkManager;
|
|||||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||||
|
use MCTeam\CustomVotesPlugin;
|
||||||
use MCTeam\KarmaPlugin;
|
use MCTeam\KarmaPlugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MapList Widget Class
|
* MapList Widget Class
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||||
/*
|
/*
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const ACTION_UPDATE_MAP = 'MapList.UpdateMap';
|
const ACTION_UPDATE_MAP = 'MapList.UpdateMap';
|
||||||
const ACTION_ERASE_MAP = 'MapList.EraseMap';
|
const ACTION_ERASE_MAP = 'MapList.EraseMap';
|
||||||
const ACTION_SWITCH_MAP = 'MapList.SwitchMap';
|
const ACTION_SWITCH_MAP = 'MapList.SwitchMap';
|
||||||
const ACTION_START_SWITCH_VOTE = 'MapList.StartMapSwitchVote';
|
const ACTION_START_SWITCH_VOTE = 'MapList.StartMapSwitchVote';
|
||||||
const ACTION_QUEUED_MAP = 'MapList.QueueMap';
|
const ACTION_QUEUED_MAP = 'MapList.QueueMap';
|
||||||
const ACTION_UNQUEUE_MAP = 'MapList.UnQueueMap';
|
const ACTION_UNQUEUE_MAP = 'MapList.UnQueueMap';
|
||||||
const ACTION_CHECK_UPDATE = 'MapList.CheckUpdate';
|
const ACTION_CHECK_UPDATE = 'MapList.CheckUpdate';
|
||||||
const ACTION_CLEAR_MAPQUEUE = 'MapList.ClearMapQueue';
|
const ACTION_CLEAR_MAPQUEUE = 'MapList.ClearMapQueue';
|
||||||
const ACTION_PAGING_CHUNKS = 'MapList.PagingChunk.';
|
const ACTION_PAGING_CHUNKS = 'MapList.PagingChunk.';
|
||||||
const MAX_MAPS_PER_PAGE = 15;
|
const MAX_MAPS_PER_PAGE = 15;
|
||||||
const MAX_PAGES_PER_CHUNK = 2;
|
const MAX_PAGES_PER_CHUNK = 2;
|
||||||
const DEFAULT_KARMA_PLUGIN = 'MCTeam\KarmaPlugin';
|
const DEFAULT_KARMA_PLUGIN = 'MCTeam\KarmaPlugin';
|
||||||
const DEFAULT_CUSTOM_VOTE_PLUGIN = 'MCTeam\CustomVotesPlugin';
|
const DEFAULT_CUSTOM_VOTE_PLUGIN = 'MCTeam\CustomVotesPlugin';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Private Properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
@ -61,12 +61,12 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new MapList Instance
|
* Create a new MapList Instance
|
||||||
*
|
*
|
||||||
* @param ManiaControl $maniaControl
|
* @param ManiaControl $maniaControl
|
||||||
*/
|
*/
|
||||||
public function __construct(ManiaControl $maniaControl) {
|
public function __construct(ManiaControl $maniaControl) {
|
||||||
$this->maniaControl = $maniaControl;
|
$this->maniaControl = $maniaControl;
|
||||||
|
|
||||||
// Register for Callbacks
|
// Register for Callbacks
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
|
$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
|
$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
|
||||||
@ -75,15 +75,15 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_MAPS_UPDATED, $this, 'updateWidget');
|
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_MAPS_UPDATED, $this, 'updateWidget');
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_KARMA_UPDATED, $this, 'updateWidget');
|
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_KARMA_UPDATED, $this, 'updateWidget');
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'updateWidget');
|
$this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'updateWidget');
|
||||||
|
|
||||||
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CHECK_UPDATE, $this, 'checkUpdates');
|
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CHECK_UPDATE, $this, 'checkUpdates');
|
||||||
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CLEAR_MAPQUEUE, $this, 'clearMapQueue');
|
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CLEAR_MAPQUEUE, $this, 'clearMapQueue');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the Map Queue
|
* Clears the Map Queue
|
||||||
*
|
*
|
||||||
* @param array $chatCallback
|
* @param array $chatCallback
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
public function clearMapQueue(array $chatCallback, Player $player) {
|
public function clearMapQueue(array $chatCallback, Player $player) {
|
||||||
@ -93,66 +93,66 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for Map Updates
|
* Check for Map Updates
|
||||||
*
|
*
|
||||||
* @param array $chatCallback
|
* @param array $chatCallback
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
public function checkUpdates(array $chatCallback, Player $player) {
|
public function checkUpdates(array $chatCallback, Player $player) {
|
||||||
// Update Mx Infos
|
// Update Mx Infos
|
||||||
$this->maniaControl->mapManager->mxManager->fetchManiaExchangeMapInformations();
|
$this->maniaControl->mapManager->mxManager->fetchManiaExchangeMapInformations();
|
||||||
|
|
||||||
// Reshow the Maplist
|
// Reshow the Maplist
|
||||||
$this->showMapList($player);
|
$this->showMapList($player);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a MapList on the Screen
|
* Display a MapList on the Screen
|
||||||
*
|
*
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
* @param array $maps
|
* @param array $maps
|
||||||
* @param int $chunk
|
* @param int $chunk
|
||||||
* @param int $startPage
|
* @param int $startPage
|
||||||
*/
|
*/
|
||||||
public function showMapList(Player $player, $maps = null, $chunk = 0, $startPage = null) {
|
public function showMapList(Player $player, $maps = null, $chunk = 0, $startPage = null) {
|
||||||
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
|
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
|
||||||
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
|
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
|
||||||
|
|
||||||
$this->mapListShown[$player->login] = true;
|
$this->mapListShown[$player->login] = true;
|
||||||
$queueBuffer = $this->maniaControl->mapManager->mapQueue->getQueueBuffer();
|
$queueBuffer = $this->maniaControl->mapManager->mapQueue->getQueueBuffer();
|
||||||
|
|
||||||
// Get Maps
|
// Get Maps
|
||||||
$mapList = null;
|
$mapList = null;
|
||||||
$pageCount = null;
|
$pageCount = null;
|
||||||
if (is_array($maps)) {
|
if (is_array($maps)) {
|
||||||
$mapList = array_slice($maps, $chunk, self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE);
|
$mapList = array_slice($maps, $chunk, self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE);
|
||||||
$this->mapsInListShown[$player->login] = $maps;
|
$this->mapsInListShown[$player->login] = $maps;
|
||||||
$pageCount = ceil(count($maps) / self::MAX_MAPS_PER_PAGE);
|
$pageCount = ceil(count($maps) / self::MAX_MAPS_PER_PAGE);
|
||||||
}
|
} else if (array_key_exists($player->login, $this->mapsInListShown)) {
|
||||||
else if (array_key_exists($player->login, $this->mapsInListShown)) {
|
$completeList = $this->mapsInListShown[$player->login];
|
||||||
$completeList = $this->mapsInListShown[$player->login];
|
|
||||||
$this->mapsInListShown[$player->login] = $completeList;
|
$this->mapsInListShown[$player->login] = $completeList;
|
||||||
$mapList = array_slice($completeList, $chunk * self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE, self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE);
|
$mapList = array_slice($completeList, $chunk * self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE, self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE);
|
||||||
$pageCount = ceil(count($completeList) / self::MAX_MAPS_PER_PAGE);
|
$pageCount = ceil(count($completeList) / self::MAX_MAPS_PER_PAGE);
|
||||||
}
|
} else {
|
||||||
else {
|
$mapList = $this->maniaControl->mapManager->getMaps($chunk * self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE, self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE);
|
||||||
$mapList = $this->maniaControl->mapManager->getMaps($chunk * self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE, self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE);
|
$pageCount = ceil($this->maniaControl->mapManager->getMapsCount() / self::MAX_MAPS_PER_PAGE);
|
||||||
$pageCount = ceil($this->maniaControl->mapManager->getMapsCount() / self::MAX_MAPS_PER_PAGE);
|
|
||||||
$this->mapsInListShown[$player->login] = $this->maniaControl->mapManager->getMaps();
|
$this->mapsInListShown[$player->login] = $this->maniaControl->mapManager->getMaps();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create ManiaLink
|
// Create ManiaLink
|
||||||
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
||||||
$script = $maniaLink->getScript();
|
$script = $maniaLink->getScript();
|
||||||
$paging = new Paging();
|
$paging = new Paging();
|
||||||
$script->addFeature($paging);
|
$script->addFeature($paging);
|
||||||
if (!is_null($pageCount)) $paging->setCustomMaxPageNumber($pageCount);
|
if (!is_null($pageCount)) {
|
||||||
|
$paging->setCustomMaxPageNumber($pageCount);
|
||||||
|
}
|
||||||
$paging->setChunkActionAppendsPageNumber(true);
|
$paging->setChunkActionAppendsPageNumber(true);
|
||||||
$paging->setChunkActions(self::ACTION_PAGING_CHUNKS);
|
$paging->setChunkActions(self::ACTION_PAGING_CHUNKS);
|
||||||
|
|
||||||
// Main frame
|
// Main frame
|
||||||
$frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $paging);
|
$frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $paging);
|
||||||
$maniaLink->add($frame);
|
$maniaLink->add($frame);
|
||||||
|
|
||||||
// Admin Buttons
|
// Admin Buttons
|
||||||
if ($this->maniaControl->authenticationManager->checkPermission($player, MapQueue::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
|
if ($this->maniaControl->authenticationManager->checkPermission($player, MapQueue::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
|
||||||
// Clear Map-Queue
|
// Clear Map-Queue
|
||||||
@ -162,7 +162,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$label->setTextSize(1);
|
$label->setTextSize(1);
|
||||||
$label->setPosition($width / 2 - 8, -$height / 2 + 9);
|
$label->setPosition($width / 2 - 8, -$height / 2 + 9);
|
||||||
$label->setHAlign(Control::RIGHT);
|
$label->setHAlign(Control::RIGHT);
|
||||||
|
|
||||||
$quad = new Quad_BgsPlayerCard();
|
$quad = new Quad_BgsPlayerCard();
|
||||||
$frame->add($quad);
|
$frame->add($quad);
|
||||||
$quad->setPosition($width / 2 - 5, -$height / 2 + 9, 0.01);
|
$quad->setPosition($width / 2 - 5, -$height / 2 + 9, 0.01);
|
||||||
@ -171,7 +171,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$quad->setSize(29, 4);
|
$quad->setSize(29, 4);
|
||||||
$quad->setAction(self::ACTION_CLEAR_MAPQUEUE);
|
$quad->setAction(self::ACTION_CLEAR_MAPQUEUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_CHECK_UPDATE)) {
|
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_CHECK_UPDATE)) {
|
||||||
// Check Update
|
// Check Update
|
||||||
$label = new Label_Button();
|
$label = new Label_Button();
|
||||||
@ -180,7 +180,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$label->setTextSize(1);
|
$label->setTextSize(1);
|
||||||
$label->setPosition($width / 2 - 41, -$height / 2 + 9, 0.01);
|
$label->setPosition($width / 2 - 41, -$height / 2 + 9, 0.01);
|
||||||
$label->setHAlign(Control::RIGHT);
|
$label->setHAlign(Control::RIGHT);
|
||||||
|
|
||||||
$quad = new Quad_BgsPlayerCard();
|
$quad = new Quad_BgsPlayerCard();
|
||||||
$frame->add($quad);
|
$frame->add($quad);
|
||||||
$quad->setPosition($width / 2 - 37, -$height / 2 + 9, 0.01);
|
$quad->setPosition($width / 2 - 37, -$height / 2 + 9, 0.01);
|
||||||
@ -188,7 +188,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$quad->setHAlign(Control::RIGHT);
|
$quad->setHAlign(Control::RIGHT);
|
||||||
$quad->setSize(35, 4);
|
$quad->setSize(35, 4);
|
||||||
$quad->setAction(self::ACTION_CHECK_UPDATE);
|
$quad->setAction(self::ACTION_CHECK_UPDATE);
|
||||||
|
|
||||||
$mxQuad = new Quad();
|
$mxQuad = new Quad();
|
||||||
$frame->add($mxQuad);
|
$frame->add($mxQuad);
|
||||||
$mxQuad->setSize(3, 3);
|
$mxQuad->setSize(3, 3);
|
||||||
@ -198,44 +198,41 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$mxQuad->setZ(0.01);
|
$mxQuad->setZ(0.01);
|
||||||
$mxQuad->setAction(self::ACTION_CHECK_UPDATE);
|
$mxQuad->setAction(self::ACTION_CHECK_UPDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Headline
|
// Headline
|
||||||
$headFrame = new Frame();
|
$headFrame = new Frame();
|
||||||
$frame->add($headFrame);
|
$frame->add($headFrame);
|
||||||
$headFrame->setY($height / 2 - 5);
|
$headFrame->setY($height / 2 - 5);
|
||||||
$x = -$width / 2;
|
$x = -$width / 2;
|
||||||
$array = array('Id' => $x + 5, 'Mx Id' => $x + 10, 'Map Name' => $x + 20, 'Author' => $x + 68, 'Karma' => $x + 115,
|
$array = array('Id' => $x + 5, 'Mx Id' => $x + 10, 'Map Name' => $x + 20, 'Author' => $x + 68, 'Karma' => $x + 115, 'Actions' => $width / 2 - 15);
|
||||||
'Actions' => $width / 2 - 15);
|
|
||||||
$this->maniaControl->manialinkManager->labelLine($headFrame, $array);
|
$this->maniaControl->manialinkManager->labelLine($headFrame, $array);
|
||||||
|
|
||||||
// Predefine description Label
|
// Predefine description Label
|
||||||
$descriptionLabel = $this->maniaControl->manialinkManager->styleManager->getDefaultDescriptionLabel();
|
$descriptionLabel = $this->maniaControl->manialinkManager->styleManager->getDefaultDescriptionLabel();
|
||||||
$frame->add($descriptionLabel);
|
$frame->add($descriptionLabel);
|
||||||
|
|
||||||
$queuedMaps = $this->maniaControl->mapManager->mapQueue->getQueuedMapsRanking();
|
$queuedMaps = $this->maniaControl->mapManager->mapQueue->getQueuedMapsRanking();
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @var KarmaPlugin $karmaPlugin
|
* @var KarmaPlugin $karmaPlugin
|
||||||
*/
|
*/
|
||||||
$karmaPlugin = $this->maniaControl->pluginManager->getPlugin(self::DEFAULT_KARMA_PLUGIN);
|
$karmaPlugin = $this->maniaControl->pluginManager->getPlugin(self::DEFAULT_KARMA_PLUGIN);
|
||||||
|
|
||||||
$pageNumber = 1 + $chunk * self::MAX_PAGES_PER_CHUNK;
|
$pageNumber = 1 + $chunk * self::MAX_PAGES_PER_CHUNK;
|
||||||
$startPageNumber = (is_int($startPage) ? $startPage : $pageNumber);
|
$startPageNumber = (is_int($startPage) ? $startPage : $pageNumber);
|
||||||
$paging->setStartPageNumber($startPageNumber);
|
$paging->setStartPageNumber($startPageNumber);
|
||||||
|
|
||||||
$id = 1 + $chunk * self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE;
|
$id = 1 + $chunk * self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE;
|
||||||
$y = $height / 2 - 10;
|
$y = $height / 2 - 10;
|
||||||
$pageFrames = array();
|
$pageFrames = array();
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @var Map $map
|
* @var Map $map
|
||||||
*/
|
*/
|
||||||
$currentMap = $this->maniaControl->mapManager->getCurrentMap();
|
$currentMap = $this->maniaControl->mapManager->getCurrentMap();
|
||||||
$mxIcon = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON);
|
$mxIcon = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON);
|
||||||
$mxIconHover = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_MOVER);
|
$mxIconHover = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_MOVER);
|
||||||
$mxIconGreen = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_GREEN);
|
$mxIconGreen = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_GREEN);
|
||||||
$mxIconGreenHover = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_GREEN_MOVER);
|
$mxIconGreenHover = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_GREEN_MOVER);
|
||||||
|
|
||||||
foreach ($mapList as $map) {
|
foreach ($mapList as $map) {
|
||||||
if (!isset($pageFrame)) {
|
if (!isset($pageFrame)) {
|
||||||
$pageFrame = new Frame();
|
$pageFrame = new Frame();
|
||||||
@ -245,17 +242,17 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
}
|
}
|
||||||
array_push($pageFrames, $pageFrame);
|
array_push($pageFrames, $pageFrame);
|
||||||
$y = $height / 2 - 10;
|
$y = $height / 2 - 10;
|
||||||
|
|
||||||
$paging->addPage($pageFrame, $pageNumber);
|
$paging->addPage($pageFrame, $pageNumber);
|
||||||
$pageNumber++;
|
$pageNumber++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map Frame
|
// Map Frame
|
||||||
$mapFrame = new Frame();
|
$mapFrame = new Frame();
|
||||||
$pageFrame->add($mapFrame);
|
$pageFrame->add($mapFrame);
|
||||||
$mapFrame->setZ(0.1);
|
$mapFrame->setZ(0.1);
|
||||||
$mapFrame->setY($y);
|
$mapFrame->setY($y);
|
||||||
|
|
||||||
if ($id % 2 != 0) {
|
if ($id % 2 != 0) {
|
||||||
$lineQuad = new Quad_BgsPlayerCard();
|
$lineQuad = new Quad_BgsPlayerCard();
|
||||||
$mapFrame->add($lineQuad);
|
$mapFrame->add($lineQuad);
|
||||||
@ -263,7 +260,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
|
$lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
|
||||||
$lineQuad->setZ(0.001);
|
$lineQuad->setZ(0.001);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($currentMap === $map) {
|
if ($currentMap === $map) {
|
||||||
$currentQuad = new Quad_Icons64x64_1();
|
$currentQuad = new Quad_Icons64x64_1();
|
||||||
$mapFrame->add($currentQuad);
|
$mapFrame->add($currentQuad);
|
||||||
@ -272,11 +269,11 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$currentQuad->setSize(4, 4);
|
$currentQuad->setSize(4, 4);
|
||||||
$currentQuad->setSubStyle($currentQuad::SUBSTYLE_ArrowBlue);
|
$currentQuad->setSubStyle($currentQuad::SUBSTYLE_ArrowBlue);
|
||||||
}
|
}
|
||||||
|
|
||||||
$mxId = '-';
|
$mxId = '-';
|
||||||
if (isset($map->mx->id)) {
|
if (isset($map->mx->id)) {
|
||||||
$mxId = $map->mx->id;
|
$mxId = $map->mx->id;
|
||||||
|
|
||||||
$mxQuad = new Quad();
|
$mxQuad = new Quad();
|
||||||
$mapFrame->add($mxQuad);
|
$mapFrame->add($mxQuad);
|
||||||
$mxQuad->setSize(3, 3);
|
$mxQuad->setSize(3, 3);
|
||||||
@ -287,7 +284,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$mxQuad->setZ(0.01);
|
$mxQuad->setZ(0.01);
|
||||||
$description = 'View $<' . $map->name . '$> on Mania-Exchange';
|
$description = 'View $<' . $map->name . '$> on Mania-Exchange';
|
||||||
$mxQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
$mxQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||||
|
|
||||||
if ($map->updateAvailable()) {
|
if ($map->updateAvailable()) {
|
||||||
$mxQuad = new Quad();
|
$mxQuad = new Quad();
|
||||||
$mapFrame->add($mxQuad);
|
$mapFrame->add($mxQuad);
|
||||||
@ -299,30 +296,29 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$mxQuad->setZ(0.01);
|
$mxQuad->setZ(0.01);
|
||||||
$description = 'Update for $<' . $map->name . '$> available on Mania-Exchange!';
|
$description = 'Update for $<' . $map->name . '$> available on Mania-Exchange!';
|
||||||
$mxQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
$mxQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||||
|
|
||||||
// Update Button
|
// Update Button
|
||||||
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
|
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
|
||||||
$mxQuad->setAction(self::ACTION_UPDATE_MAP . '.' . $map->uid);
|
$mxQuad->setAction(self::ACTION_UPDATE_MAP . '.' . $map->uid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display Maps
|
// Display Maps
|
||||||
$array = array($id => $x + 5, $mxId => $x + 10, Formatter::stripDirtyCodes($map->name) => $x + 20, $map->authorNick => $x + 68);
|
$array = array($id => $x + 5, $mxId => $x + 10, Formatter::stripDirtyCodes($map->name) => $x + 20, $map->authorNick => $x + 68);
|
||||||
$labels = $this->maniaControl->manialinkManager->labelLine($mapFrame, $array);
|
$labels = $this->maniaControl->manialinkManager->labelLine($mapFrame, $array);
|
||||||
if (isset($labels[3])) {
|
if (isset($labels[3])) {
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @var Label $label
|
* @var Label $label
|
||||||
*/
|
*/
|
||||||
$label = $labels[3];
|
$label = $labels[3];
|
||||||
$description = 'Click to checkout all maps by $<' . $map->authorLogin . '$>!';
|
$description = 'Click to checkout all maps by $<' . $map->authorLogin . '$>!';
|
||||||
$label->setAction(MapCommands::ACTION_SHOW_AUTHOR . $map->authorLogin);
|
$label->setAction(MapCommands::ACTION_SHOW_AUTHOR . $map->authorLogin);
|
||||||
$label->addTooltipLabelFeature($descriptionLabel, $description);
|
$label->addTooltipLabelFeature($descriptionLabel, $description);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO action detailed map info including mx info
|
// TODO action detailed map info including mx info
|
||||||
|
|
||||||
// Map-Queue-Map-Label
|
// Map-Queue-Map-Label
|
||||||
if (isset($queuedMaps[$map->uid])) {
|
if (isset($queuedMaps[$map->uid])) {
|
||||||
$label = new Label_Text();
|
$label = new Label_Text();
|
||||||
@ -333,20 +329,18 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$label->setTextSize(1.5);
|
$label->setTextSize(1.5);
|
||||||
$label->setText($queuedMaps[$map->uid]);
|
$label->setText($queuedMaps[$map->uid]);
|
||||||
$label->setTextColor('fff');
|
$label->setTextColor('fff');
|
||||||
|
|
||||||
// Checks if the Player who openend the Widget has queued the map
|
// Checks if the Player who openend the Widget has queued the map
|
||||||
$queuer = $this->maniaControl->mapManager->mapQueue->getQueuer($map->uid);
|
$queuer = $this->maniaControl->mapManager->mapQueue->getQueuer($map->uid);
|
||||||
if ($queuer->login == $player->login) {
|
if ($queuer->login == $player->login) {
|
||||||
$description = 'Remove $<' . $map->name . '$> from the Map Queue';
|
$description = 'Remove $<' . $map->name . '$> from the Map Queue';
|
||||||
$label->addTooltipLabelFeature($descriptionLabel, $description);
|
$label->addTooltipLabelFeature($descriptionLabel, $description);
|
||||||
$label->setAction(self::ACTION_UNQUEUE_MAP . '.' . $map->uid);
|
$label->setAction(self::ACTION_UNQUEUE_MAP . '.' . $map->uid);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$description = '$<' . $map->name . '$> is on Map-Queue Position: ' . $queuedMaps[$map->uid];
|
$description = '$<' . $map->name . '$> is on Map-Queue Position: ' . $queuedMaps[$map->uid];
|
||||||
$label->addTooltipLabelFeature($descriptionLabel, $description);
|
$label->addTooltipLabelFeature($descriptionLabel, $description);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Map-Queue-Map-Button
|
// Map-Queue-Map-Button
|
||||||
$queueLabel = new Label_Button();
|
$queueLabel = new Label_Button();
|
||||||
$mapFrame->add($queueLabel);
|
$mapFrame->add($queueLabel);
|
||||||
@ -355,7 +349,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$queueLabel->setSize(3, 3);
|
$queueLabel->setSize(3, 3);
|
||||||
$queueLabel->setText('+');
|
$queueLabel->setText('+');
|
||||||
|
|
||||||
if(in_array($map->uid, $queueBuffer)) {
|
if (in_array($map->uid, $queueBuffer)) {
|
||||||
if ($this->maniaControl->authenticationManager->checkPermission($player, MapQueue::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
|
if ($this->maniaControl->authenticationManager->checkPermission($player, MapQueue::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
|
||||||
$queueLabel->setAction(self::ACTION_QUEUED_MAP . '.' . $map->uid);
|
$queueLabel->setAction(self::ACTION_QUEUED_MAP . '.' . $map->uid);
|
||||||
}
|
}
|
||||||
@ -369,7 +363,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$queueLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
$queueLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_REMOVE_MAP)) {
|
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_REMOVE_MAP)) {
|
||||||
// erase map quad
|
// erase map quad
|
||||||
$eraseLabel = new Label_Button();
|
$eraseLabel = new Label_Button();
|
||||||
@ -380,13 +374,13 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$eraseLabel->setTextSize(1);
|
$eraseLabel->setTextSize(1);
|
||||||
$eraseLabel->setText('x');
|
$eraseLabel->setText('x');
|
||||||
$eraseLabel->setTextColor('a00');
|
$eraseLabel->setTextColor('a00');
|
||||||
|
|
||||||
$confirmFrame = $this->buildConfirmFrame($maniaLink, $y, $id, $map->uid);
|
$confirmFrame = $this->buildConfirmFrame($maniaLink, $y, $id, $map->uid);
|
||||||
$eraseLabel->addToggleFeature($confirmFrame);
|
$eraseLabel->addToggleFeature($confirmFrame);
|
||||||
$description = 'Remove Map: $<' . $map->name . '$>';
|
$description = 'Remove Map: $<' . $map->name . '$>';
|
||||||
$eraseLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
$eraseLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
|
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
|
||||||
// Switch to map
|
// Switch to map
|
||||||
$switchLabel = new Label_Button();
|
$switchLabel = new Label_Button();
|
||||||
@ -397,14 +391,13 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$switchLabel->setTextSize(2);
|
$switchLabel->setTextSize(2);
|
||||||
$switchLabel->setText('»');
|
$switchLabel->setText('»');
|
||||||
$switchLabel->setTextColor('0f0');
|
$switchLabel->setTextColor('0f0');
|
||||||
|
|
||||||
$confirmFrame = $this->buildConfirmFrame($maniaLink, $y, $id);
|
$confirmFrame = $this->buildConfirmFrame($maniaLink, $y, $id);
|
||||||
$switchLabel->addToggleFeature($confirmFrame);
|
$switchLabel->addToggleFeature($confirmFrame);
|
||||||
|
|
||||||
$description = 'Switch Directly to Map: $<' . $map->name . '$>';
|
$description = 'Switch Directly to Map: $<' . $map->name . '$>';
|
||||||
$switchLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
$switchLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
||||||
}
|
} else if ($this->maniaControl->pluginManager->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)) {
|
||||||
else if ($this->maniaControl->pluginManager->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)) {
|
|
||||||
// Switch Map Voting
|
// Switch Map Voting
|
||||||
$switchLabel = new Label_Button();
|
$switchLabel = new Label_Button();
|
||||||
$mapFrame->add($switchLabel);
|
$mapFrame->add($switchLabel);
|
||||||
@ -414,35 +407,35 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$switchLabel->setTextSize(2);
|
$switchLabel->setTextSize(2);
|
||||||
$switchLabel->setText('»');
|
$switchLabel->setText('»');
|
||||||
$switchLabel->setTextColor('0f0');
|
$switchLabel->setTextColor('0f0');
|
||||||
|
|
||||||
$switchLabel->setAction(self::ACTION_START_SWITCH_VOTE . '.' . ($id - 1));
|
$switchLabel->setAction(self::ACTION_START_SWITCH_VOTE . '.' . ($id - 1));
|
||||||
|
|
||||||
$description = 'Start Map-Switch Vote: $<' . $map->name . '$>';
|
$description = 'Start Map-Switch Vote: $<' . $map->name . '$>';
|
||||||
$switchLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
$switchLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display Karma bar
|
// Display Karma bar
|
||||||
if ($karmaPlugin) {
|
if ($karmaPlugin) {
|
||||||
$karma = $karmaPlugin->getMapKarma($map);
|
$karma = $karmaPlugin->getMapKarma($map);
|
||||||
$votes = $karmaPlugin->getMapVotes($map);
|
$votes = $karmaPlugin->getMapVotes($map);
|
||||||
if (is_numeric($karma)) {
|
if (is_numeric($karma)) {
|
||||||
if($this->maniaControl->settingManager->getSetting($karmaPlugin, $karmaPlugin::SETTING_NEWKARMA)) {
|
if ($this->maniaControl->settingManager->getSetting($karmaPlugin, $karmaPlugin::SETTING_NEWKARMA)) {
|
||||||
$karmaText = ' ' . round($karma * 100.) . '% (' . $votes['count'] . ')';
|
$karmaText = ' ' . round($karma * 100.) . '% (' . $votes['count'] . ')';
|
||||||
} else {
|
} else {
|
||||||
$min = 0;
|
$min = 0;
|
||||||
$plus = 0;
|
$plus = 0;
|
||||||
foreach($votes as $vote) {
|
foreach ($votes as $vote) {
|
||||||
if(isset($vote->vote)) {
|
if (isset($vote->vote)) {
|
||||||
if($vote->vote != 0.5) {
|
if ($vote->vote != 0.5) {
|
||||||
if($vote->vote < 0.5) {
|
if ($vote->vote < 0.5) {
|
||||||
$min = $min+$vote->count;
|
$min = $min + $vote->count;
|
||||||
} else {
|
} else {
|
||||||
$plus = $plus+$vote->count;
|
$plus = $plus + $vote->count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$endKarma = $plus-$min;
|
$endKarma = $plus - $min;
|
||||||
$karmaText = ' ' . $endKarma . ' (' . $votes['count'] . 'x / ' . round($karma * 100.) . '%)';
|
$karmaText = ' ' . $endKarma . ' (' . $votes['count'] . 'x / ' . round($karma * 100.) . '%)';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -456,7 +449,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$karmaGauge->setRatio($karma + 0.15 - $karma * 0.15);
|
$karmaGauge->setRatio($karma + 0.15 - $karma * 0.15);
|
||||||
$karmaColor = ColorUtil::floatToStatusColor($karma);
|
$karmaColor = ColorUtil::floatToStatusColor($karma);
|
||||||
$karmaGauge->setColor($karmaColor . '9');
|
$karmaGauge->setColor($karmaColor . '9');
|
||||||
|
|
||||||
$karmaLabel = new Label();
|
$karmaLabel = new Label();
|
||||||
$mapFrame->add($karmaLabel);
|
$mapFrame->add($karmaLabel);
|
||||||
$karmaLabel->setZ(2);
|
$karmaLabel->setZ(2);
|
||||||
@ -468,46 +461,46 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$karmaLabel->setText($karmaText);
|
$karmaLabel->setText($karmaText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$y -= 4;
|
$y -= 4;
|
||||||
if ($id % self::MAX_MAPS_PER_PAGE == 0) {
|
if ($id % self::MAX_MAPS_PER_PAGE == 0) {
|
||||||
unset($pageFrame);
|
unset($pageFrame);
|
||||||
}
|
}
|
||||||
$id++;
|
$id++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'MapList');
|
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'MapList');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the confirmation frame
|
* Builds the confirmation frame
|
||||||
*
|
*
|
||||||
* @param ManiaLink $maniaLink
|
* @param ManiaLink $maniaLink
|
||||||
* @param $y
|
* @param $y
|
||||||
* @param $id
|
* @param $id
|
||||||
* @param bool $mapUid
|
* @param bool $mapUid
|
||||||
* @return Frame
|
* @return Frame
|
||||||
*/
|
*/
|
||||||
public function buildConfirmFrame(Manialink $maniaLink, $y, $id, $mapUid = false) {
|
public function buildConfirmFrame(Manialink $maniaLink, $y, $id, $mapUid = false) {
|
||||||
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
|
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
|
||||||
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle();
|
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle();
|
||||||
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle();
|
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle();
|
||||||
|
|
||||||
$confirmFrame = new Frame();
|
$confirmFrame = new Frame();
|
||||||
$maniaLink->add($confirmFrame);
|
$maniaLink->add($confirmFrame);
|
||||||
$confirmFrame->setPosition($width / 2 + 6, $y);
|
$confirmFrame->setPosition($width / 2 + 6, $y);
|
||||||
$confirmFrame->setVisible(false);
|
$confirmFrame->setVisible(false);
|
||||||
|
|
||||||
$quad = new Quad();
|
$quad = new Quad();
|
||||||
$confirmFrame->add($quad);
|
$confirmFrame->add($quad);
|
||||||
$quad->setStyles($quadStyle, $quadSubstyle);
|
$quad->setStyles($quadStyle, $quadSubstyle);
|
||||||
$quad->setSize(12, 4);
|
$quad->setSize(12, 4);
|
||||||
|
|
||||||
$quad = new Quad_BgsPlayerCard();
|
$quad = new Quad_BgsPlayerCard();
|
||||||
$confirmFrame->add($quad);
|
$confirmFrame->add($quad);
|
||||||
$quad->setSubStyle($quad::SUBSTYLE_BgCardSystem);
|
$quad->setSubStyle($quad::SUBSTYLE_BgCardSystem);
|
||||||
$quad->setSize(11, 3.5);
|
$quad->setSize(11, 3.5);
|
||||||
|
|
||||||
$label = new Label_Button();
|
$label = new Label_Button();
|
||||||
$confirmFrame->add($label);
|
$confirmFrame->add($label);
|
||||||
$label->setAlign(Control::CENTER, Control::CENTER);
|
$label->setAlign(Control::CENTER, Control::CENTER);
|
||||||
@ -515,20 +508,19 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$label->setTextSize(1);
|
$label->setTextSize(1);
|
||||||
$label->setScale(0.90);
|
$label->setScale(0.90);
|
||||||
$label->setX(-1.3);
|
$label->setX(-1.3);
|
||||||
|
|
||||||
$buttLabel = new Label_Button();
|
$buttLabel = new Label_Button();
|
||||||
$confirmFrame->add($buttLabel);
|
$confirmFrame->add($buttLabel);
|
||||||
$buttLabel->setPosition(3.2, 0.4, 0.2);
|
$buttLabel->setPosition(3.2, 0.4, 0.2);
|
||||||
$buttLabel->setSize(3, 3);
|
$buttLabel->setSize(3, 3);
|
||||||
$buttLabel->setAlign(Control::CENTER, Control::CENTER);
|
$buttLabel->setAlign(Control::CENTER, Control::CENTER);
|
||||||
|
|
||||||
if (!$mapUid) {
|
if (!$mapUid) {
|
||||||
$quad->setAction(self::ACTION_SWITCH_MAP . '.' . ($id - 1));
|
$quad->setAction(self::ACTION_SWITCH_MAP . '.' . ($id - 1));
|
||||||
$buttLabel->setText('»');
|
$buttLabel->setText('»');
|
||||||
$buttLabel->setTextColor('0f0');
|
$buttLabel->setTextColor('0f0');
|
||||||
$buttLabel->setTextSize(2);
|
$buttLabel->setTextSize(2);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$buttLabel->setTextSize(1);
|
$buttLabel->setTextSize(1);
|
||||||
$buttLabel->setText('x');
|
$buttLabel->setText('x');
|
||||||
$buttLabel->setTextColor('a00');
|
$buttLabel->setTextColor('a00');
|
||||||
@ -539,9 +531,9 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Unset the player if he opened another Main Widget
|
* Unset the player if he opened another Main Widget
|
||||||
*
|
*
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
* @param $openedWidget
|
* @param $openedWidget
|
||||||
*/
|
*/
|
||||||
public function handleWidgetOpened(Player $player, $openedWidget) {
|
public function handleWidgetOpened(Player $player, $openedWidget) {
|
||||||
// unset when another main widget got opened
|
// unset when another main widget got opened
|
||||||
@ -552,7 +544,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the widget
|
* Closes the widget
|
||||||
*
|
*
|
||||||
* @param \ManiaControl\Players\Player $player
|
* @param \ManiaControl\Players\Player $player
|
||||||
*/
|
*/
|
||||||
public function closeWidget(Player $player) {
|
public function closeWidget(Player $player) {
|
||||||
@ -560,35 +552,24 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
unset($this->mapsInListShown[$player->login]);
|
unset($this->mapsInListShown[$player->login]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Closes the widget
|
|
||||||
*
|
|
||||||
* @param Player $player
|
|
||||||
*/
|
|
||||||
public function playerCloseWidget(Player $player) {
|
|
||||||
unset($this->mapListShown[$player->login]);
|
|
||||||
unset($this->mapsInListShown[$player->login]);
|
|
||||||
$this->maniaControl->manialinkManager->closeWidget($player);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle ManialinkPageAnswer Callback
|
* Handle ManialinkPageAnswer Callback
|
||||||
*
|
*
|
||||||
* @param array $callback
|
* @param array $callback
|
||||||
*/
|
*/
|
||||||
public function handleManialinkPageAnswer(array $callback) {
|
public function handleManialinkPageAnswer(array $callback) {
|
||||||
$actionId = $callback[1][2];
|
$actionId = $callback[1][2];
|
||||||
$actionArray = explode('.', $actionId);
|
$actionArray = explode('.', $actionId);
|
||||||
|
|
||||||
if (count($actionArray) <= 2) {
|
if (count($actionArray) <= 2) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$action = $actionArray[0] . '.' . $actionArray[1];
|
$action = $actionArray[0] . '.' . $actionArray[1];
|
||||||
$login = $callback[1][1];
|
$login = $callback[1][1];
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
$mapId = (int) $actionArray[2];
|
$mapId = (int)$actionArray[2];
|
||||||
|
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
case self::ACTION_UPDATE_MAP:
|
case self::ACTION_UPDATE_MAP:
|
||||||
$mapUid = $actionArray[2];
|
$mapUid = $actionArray[2];
|
||||||
@ -602,51 +583,47 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
case self::ACTION_SWITCH_MAP:
|
case self::ACTION_SWITCH_MAP:
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->jumpToMapIndex($mapId);
|
$this->maniaControl->client->jumpToMapIndex($mapId);
|
||||||
}
|
} catch (Exception $e) {
|
||||||
catch (Exception $e) {
|
|
||||||
// TODO: is it even possible that an exception other than connection errors will be thrown? - remove try-catch?
|
// TODO: is it even possible that an exception other than connection errors will be thrown? - remove try-catch?
|
||||||
$this->maniaControl->chat->sendError("Error while Jumping to Map Index");
|
$this->maniaControl->chat->sendError("Error while Jumping to Map Index");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$mapList = $this->maniaControl->mapManager->getMaps();
|
$mapList = $this->maniaControl->mapManager->getMaps();
|
||||||
$map = $mapList[$mapId];
|
$map = $mapList[$mapId];
|
||||||
|
|
||||||
$message = '$<' . $player->nickname . '$> skipped to Map $z$<' . $map->name . '$>!';
|
$message = '$<' . $player->nickname . '$> skipped to Map $z$<' . $map->name . '$>!';
|
||||||
$this->maniaControl->chat->sendSuccess($message);
|
$this->maniaControl->chat->sendSuccess($message);
|
||||||
$this->maniaControl->log($message, true);
|
$this->maniaControl->log($message, true);
|
||||||
|
|
||||||
$this->playerCloseWidget($player);
|
$this->playerCloseWidget($player);
|
||||||
break;
|
break;
|
||||||
case self::ACTION_START_SWITCH_VOTE:
|
case self::ACTION_START_SWITCH_VOTE:
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @var $votesPlugin CustomVotesPlugin
|
* @var $votesPlugin CustomVotesPlugin
|
||||||
*/
|
*/
|
||||||
$votesPlugin = $this->maniaControl->pluginManager->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN);
|
$votesPlugin = $this->maniaControl->pluginManager->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN);
|
||||||
$mapList = $this->maniaControl->mapManager->getMaps();
|
$mapList = $this->maniaControl->mapManager->getMaps();
|
||||||
$map = $mapList[$mapId];
|
$map = $mapList[$mapId];
|
||||||
|
|
||||||
$message = '$<' . $player->nickname . '$>$s started a vote to switch to $<' . $map->name . '$>!';
|
$message = '$<' . $player->nickname . '$>$s started a vote to switch to $<' . $map->name . '$>!';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @var Map $map
|
* @var Map $map
|
||||||
*/
|
*/
|
||||||
$votesPlugin->defineVote('switchmap', "Goto " . $map->name, true, $message);
|
$votesPlugin->defineVote('switchmap', "Goto " . $map->name, true, $message);
|
||||||
|
|
||||||
$self = $this;
|
$self = $this;
|
||||||
$votesPlugin->startVote($player, 'switchmap', function ($result) use(&$self, &$votesPlugin, &$map) {
|
$votesPlugin->startVote($player, 'switchmap', function ($result) use (&$self, &$votesPlugin, &$map) {
|
||||||
$self->maniaControl->chat->sendInformation('$sVote Successfully -> Map switched!');
|
$self->maniaControl->chat->sendInformation('$sVote Successfully -> Map switched!');
|
||||||
$votesPlugin->undefineVote('switchmap');
|
$votesPlugin->undefineVote('switchmap');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$index = $self->maniaControl->mapManager->getMapIndex($map);
|
$index = $self->maniaControl->mapManager->getMapIndex($map);
|
||||||
$self->maniaControl->client->jumpToMapIndex($index);
|
$self->maniaControl->client->jumpToMapIndex($index);
|
||||||
}
|
} catch (Exception $e) {
|
||||||
catch (Exception $e) {
|
|
||||||
// TODO temp added 19.04.2014
|
// TODO temp added 19.04.2014
|
||||||
$self->maniaControl->errorHandler->triggerDebugNotice("Exception line 557 MapList.php" . $e->getMessage());
|
$self->maniaControl->errorHandler->triggerDebugNotice("Exception line 557 MapList.php" . $e->getMessage());
|
||||||
|
|
||||||
$self->maniaControl->chat->sendError("Error while Switching Map");
|
$self->maniaControl->chat->sendError("Error while Switching Map");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -662,14 +639,25 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
default:
|
default:
|
||||||
if (substr($actionId, 0, strlen(self::ACTION_PAGING_CHUNKS)) === self::ACTION_PAGING_CHUNKS) {
|
if (substr($actionId, 0, strlen(self::ACTION_PAGING_CHUNKS)) === self::ACTION_PAGING_CHUNKS) {
|
||||||
// Paging chunks
|
// Paging chunks
|
||||||
$neededPage = (int) substr($actionId, strlen(self::ACTION_PAGING_CHUNKS));
|
$neededPage = (int)substr($actionId, strlen(self::ACTION_PAGING_CHUNKS));
|
||||||
$chunk = (int) ($neededPage / self::MAX_PAGES_PER_CHUNK - 0.5);
|
$chunk = (int)($neededPage / self::MAX_PAGES_PER_CHUNK - 0.5);
|
||||||
$this->showMapList($player, null, $chunk, $neededPage);
|
$this->showMapList($player, null, $chunk, $neededPage);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the widget
|
||||||
|
*
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
public function playerCloseWidget(Player $player) {
|
||||||
|
unset($this->mapListShown[$player->login]);
|
||||||
|
unset($this->mapsInListShown[$player->login]);
|
||||||
|
$this->maniaControl->manialinkManager->closeWidget($player);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reopen the widget on Map Begin, MapListChanged, etc.
|
* Reopen the widget on Map Begin, MapListChanged, etc.
|
||||||
*/
|
*/
|
||||||
@ -679,8 +667,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
if ($player) {
|
if ($player) {
|
||||||
$this->showMapList($player);
|
$this->showMapList($player);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
unset($this->mapListShown[$login]);
|
unset($this->mapListShown[$login]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -696,8 +683,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
if ($player) {
|
if ($player) {
|
||||||
$this->showMapList($player);
|
$this->showMapList($player);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
unset($this->mapListShown[$login]);
|
unset($this->mapListShown[$login]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,8 @@ use Maniaplanet\DedicatedServer\Xmlrpc\StartIndexOutOfBoundException;
|
|||||||
/**
|
/**
|
||||||
* Manager for Maps
|
* Manager for Maps
|
||||||
*
|
*
|
||||||
* @author kremsy & steeffeen
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class MapManager implements CallbackListener {
|
class MapManager implements CallbackListener {
|
||||||
@ -129,44 +129,26 @@ class MapManager implements CallbackListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save a Map in the Database
|
* Update a Map from Mania Exchange
|
||||||
*
|
*
|
||||||
* @param \ManiaControl\Maps\Map $map
|
* @param Player $admin
|
||||||
* @return bool
|
* @param string $uid
|
||||||
*/
|
*/
|
||||||
private function saveMap(Map &$map) {
|
public function updateMap(Player $admin, $uid) {
|
||||||
//TODO saveMaps for whole maplist at once (usage of prepared statements)
|
$this->updateMapTimestamp($uid);
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
|
||||||
$mapQuery = "INSERT INTO `" . self::TABLE_MAPS . "` (
|
|
||||||
`uid`,
|
|
||||||
`name`,
|
|
||||||
`authorLogin`,
|
|
||||||
`fileName`,
|
|
||||||
`environment`,
|
|
||||||
`mapType`
|
|
||||||
) VALUES (
|
|
||||||
?, ?, ?, ?, ?, ?
|
|
||||||
) ON DUPLICATE KEY UPDATE
|
|
||||||
`index` = LAST_INSERT_ID(`index`),
|
|
||||||
`fileName` = VALUES(`fileName`),
|
|
||||||
`environment` = VALUES(`environment`),
|
|
||||||
`mapType` = VALUES(`mapType`);";
|
|
||||||
|
|
||||||
$mapStatement = $mysqli->prepare($mapQuery);
|
if (!isset($uid) || !isset($this->maps[$uid])) {
|
||||||
if ($mysqli->error) {
|
trigger_error("Error while updating Map, unknown UID: " . $uid);
|
||||||
trigger_error($mysqli->error);
|
$this->maniaControl->chat->sendError("Error while updating Map.", $admin->login);
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
$mapStatement->bind_param('ssssss', $map->uid, $map->rawName, $map->authorLogin, $map->fileName, $map->environment, $map->mapType);
|
|
||||||
$mapStatement->execute();
|
/** @var Map $map */
|
||||||
if ($mapStatement->error) {
|
$map = $this->maps[$uid];
|
||||||
trigger_error($mapStatement->error);
|
|
||||||
$mapStatement->close();
|
$mxId = $map->mx->id;
|
||||||
return false;
|
$this->removeMap($admin, $uid, true, false);
|
||||||
}
|
$this->addMapFromMx($mxId, $admin->login, true);
|
||||||
$map->index = $mapStatement->insert_id;
|
|
||||||
$mapStatement->close();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -198,29 +180,6 @@ class MapManager implements CallbackListener {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Update a Map from Mania Exchange
|
|
||||||
*
|
|
||||||
* @param Player $admin
|
|
||||||
* @param string $uid
|
|
||||||
*/
|
|
||||||
public function updateMap(Player $admin, $uid) {
|
|
||||||
$this->updateMapTimestamp($uid);
|
|
||||||
|
|
||||||
if (!isset($uid) || !isset($this->maps[$uid])) {
|
|
||||||
trigger_error("Error while updating Map, unknown UID: " . $uid);
|
|
||||||
$this->maniaControl->chat->sendError("Error while updating Map.", $admin->login);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var Map $map */
|
|
||||||
$map = $this->maps[$uid];
|
|
||||||
|
|
||||||
$mxId = $map->mx->id;
|
|
||||||
$this->removeMap($admin, $uid, true, false);
|
|
||||||
$this->addMapFromMx($mxId, $admin->login, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a Map
|
* Remove a Map
|
||||||
*
|
*
|
||||||
@ -247,7 +206,7 @@ class MapManager implements CallbackListener {
|
|||||||
// Remove map
|
// Remove map
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->removeMap($map->fileName);
|
$this->maniaControl->client->removeMap($map->fileName);
|
||||||
} catch(MapNotInCurrentSelectionException $e) {
|
} catch (MapNotInCurrentSelectionException $e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -273,330 +232,6 @@ class MapManager implements CallbackListener {
|
|||||||
unset($this->maps[$uid]);
|
unset($this->maps[$uid]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Restructures the Maplist
|
|
||||||
*/
|
|
||||||
public function restructureMapList() {
|
|
||||||
$currentIndex = $this->getMapIndex($this->currentMap);
|
|
||||||
|
|
||||||
// No RestructureNeeded
|
|
||||||
if ($currentIndex < Maplist::MAX_MAPS_PER_PAGE - 1) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$lowerMapArray = array();
|
|
||||||
$higherMapArray = array();
|
|
||||||
|
|
||||||
$i = 0;
|
|
||||||
foreach($this->maps as $map) {
|
|
||||||
if ($i < $currentIndex) {
|
|
||||||
$lowerMapArray[] = $map->fileName;
|
|
||||||
} else {
|
|
||||||
$higherMapArray[] = $map->fileName;
|
|
||||||
}
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
$mapArray = array_merge($higherMapArray, $lowerMapArray);
|
|
||||||
array_shift($mapArray);
|
|
||||||
|
|
||||||
try {
|
|
||||||
$this->maniaControl->client->chooseNextMapList($mapArray);
|
|
||||||
} catch(Exception $e) {
|
|
||||||
trigger_error("Error while restructuring the Maplist. " . $e->getMessage());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shuffles the MapList
|
|
||||||
*
|
|
||||||
* @param Player $admin
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function shuffleMapList($admin = null) {
|
|
||||||
$shuffledMaps = $this->maps;
|
|
||||||
shuffle($shuffledMaps);
|
|
||||||
|
|
||||||
$mapArray = array();
|
|
||||||
|
|
||||||
foreach($shuffledMaps as $map) {
|
|
||||||
/**
|
|
||||||
* @var Map $map
|
|
||||||
*/
|
|
||||||
$mapArray[] = $map->fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$this->maniaControl->client->chooseNextMapList($mapArray);
|
|
||||||
} catch(Exception $e) {
|
|
||||||
//TODO temp added 19.04.2014
|
|
||||||
$this->maniaControl->errorHandler->triggerDebugNotice("Exception line 331 MapManager" . $e->getMessage());
|
|
||||||
trigger_error("Couldn't shuffle mapList. " . $e->getMessage());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->fetchCurrentMap();
|
|
||||||
|
|
||||||
if ($admin) {
|
|
||||||
$message = '$<' . $admin->nickname . '$> shuffled the Maplist!';
|
|
||||||
$this->maniaControl->chat->sendSuccess($message);
|
|
||||||
$this->maniaControl->log($message, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restructure if needed
|
|
||||||
$this->restructureMapList();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes a Map
|
|
||||||
*
|
|
||||||
* @param $rpcMap
|
|
||||||
* @return Map
|
|
||||||
*/
|
|
||||||
public function initializeMap($rpcMap) {
|
|
||||||
$map = new Map($rpcMap);
|
|
||||||
$this->saveMap($map);
|
|
||||||
|
|
||||||
/*$mapsDirectory = $this->maniaControl->server->getMapsDirectory();
|
|
||||||
if (is_readable($mapsDirectory . $map->fileName)) {
|
|
||||||
$mapFetcher = new \GBXChallMapFetcher(true);
|
|
||||||
$mapFetcher->processFile($mapsDirectory . $map->fileName);
|
|
||||||
$map->authorNick = FORMATTER::stripDirtyCodes($mapFetcher->authorNick);
|
|
||||||
$map->authorEInfo = $mapFetcher->authorEInfo;
|
|
||||||
$map->authorZone = $mapFetcher->authorZone;
|
|
||||||
$map->comment = $mapFetcher->comment;
|
|
||||||
}*/
|
|
||||||
return $map;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the full Map list, needed on Init, addMap and on ShuffleMaps
|
|
||||||
*/
|
|
||||||
private function updateFullMapList() {
|
|
||||||
$tempList = array();
|
|
||||||
|
|
||||||
try {
|
|
||||||
$i = 0;
|
|
||||||
while(true) {
|
|
||||||
$maps = $this->maniaControl->client->getMapList(150, $i);
|
|
||||||
|
|
||||||
foreach($maps as $rpcMap) {
|
|
||||||
if (array_key_exists($rpcMap->uId, $this->maps)) {
|
|
||||||
// Map already exists, only update index
|
|
||||||
$tempList[$rpcMap->uId] = $this->maps[$rpcMap->uId];
|
|
||||||
} else { // Insert Map Object
|
|
||||||
$map = $this->initializeMap($rpcMap);
|
|
||||||
$tempList[$map->uid] = $map;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$i += 150;
|
|
||||||
}
|
|
||||||
} catch(StartIndexOutOfBoundException $e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
// restore Sorted MapList
|
|
||||||
$this->maps = $tempList;
|
|
||||||
|
|
||||||
// Trigger own callback
|
|
||||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAPS_UPDATED);
|
|
||||||
|
|
||||||
// Write MapList
|
|
||||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_AUTOSAVE_MAPLIST)) {
|
|
||||||
try {
|
|
||||||
$this->maniaControl->client->saveMatchSettings($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAPLIST_FILE));
|
|
||||||
} catch(CouldNotWritePlaylistFileException $e) {
|
|
||||||
$this->maniaControl->log("Unable to write the playlist file, please checkout your MX-Folders File permissions!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Freshly fetch current Map
|
|
||||||
*
|
|
||||||
* @return Map
|
|
||||||
*/
|
|
||||||
private function fetchCurrentMap() {
|
|
||||||
$rpcMap = $this->maniaControl->client->getCurrentMapInfo();
|
|
||||||
|
|
||||||
if (array_key_exists($rpcMap->uId, $this->maps)) {
|
|
||||||
$this->currentMap = $this->maps[$rpcMap->uId];
|
|
||||||
$this->currentMap->nbCheckpoints = $rpcMap->nbCheckpoints;
|
|
||||||
$this->currentMap->nbLaps = $rpcMap->nbLaps;
|
|
||||||
return $this->currentMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->currentMap = $this->initializeMap($rpcMap);
|
|
||||||
$this->maps[$this->currentMap->uid] = $this->currentMap;
|
|
||||||
return $this->currentMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle OnInit callback
|
|
||||||
*/
|
|
||||||
public function handleOnInit() {
|
|
||||||
$this->updateFullMapList();
|
|
||||||
$this->fetchCurrentMap();
|
|
||||||
|
|
||||||
// Restructure Maplist
|
|
||||||
$this->restructureMapList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle AfterInit callback
|
|
||||||
*/
|
|
||||||
public function handleAfterInit() {
|
|
||||||
// Fetch MX infos
|
|
||||||
$this->mxManager->fetchManiaExchangeMapInformations();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Current Map
|
|
||||||
*
|
|
||||||
* @return Map currentMap
|
|
||||||
*/
|
|
||||||
public function getCurrentMap() {
|
|
||||||
if (!$this->currentMap) {
|
|
||||||
return $this->fetchCurrentMap();
|
|
||||||
}
|
|
||||||
return $this->currentMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns map By UID
|
|
||||||
*
|
|
||||||
* @param $uid
|
|
||||||
* @return Map array
|
|
||||||
*/
|
|
||||||
public function getMapByUid($uid) {
|
|
||||||
if (!isset($this->maps[$uid])) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return $this->maps[$uid];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle BeginMap callback
|
|
||||||
*
|
|
||||||
* @param array $callback
|
|
||||||
*/
|
|
||||||
public function handleBeginMap(array $callback) {
|
|
||||||
if ($this->mapBegan) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$this->mapBegan = true;
|
|
||||||
$this->mapEnded = false;
|
|
||||||
|
|
||||||
if (!isset($callback[1][0]["UId"])) {
|
|
||||||
$this->currentMap = $this->fetchCurrentMap();
|
|
||||||
} else if (array_key_exists($callback[1][0]["UId"], $this->maps)) {
|
|
||||||
// Map already exists, only update index
|
|
||||||
$this->currentMap = $this->maps[$callback[1][0]["UId"]];
|
|
||||||
if (!$this->currentMap->nbCheckpoints || !$this->currentMap->nbLaps) {
|
|
||||||
$rpcMap = $this->maniaControl->client->getCurrentMapInfo();
|
|
||||||
$this->currentMap->nbLaps = $rpcMap->nbLaps;
|
|
||||||
$this->currentMap->nbCheckpoints = $rpcMap->nbCheckpoints;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restructure MapList if id is over 15
|
|
||||||
$this->restructureMapList();
|
|
||||||
|
|
||||||
// Update the mx of the map (for update checks, etc.)
|
|
||||||
$this->mxManager->fetchManiaExchangeMapInformations($this->currentMap);
|
|
||||||
|
|
||||||
// Trigger own BeginMap callback (
|
|
||||||
//TODO remove deprecated callback later
|
|
||||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_BEGINMAP, $this->currentMap);
|
|
||||||
$this->maniaControl->callbackManager->triggerCallback(Callbacks::BEGINMAP, $this->currentMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle Script BeginMap callback
|
|
||||||
*
|
|
||||||
* @param int $mapNumber
|
|
||||||
*/
|
|
||||||
public function handleScriptBeginMap($mapNumber) {
|
|
||||||
$this->handleBeginMap(array());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle EndMap Callback
|
|
||||||
*
|
|
||||||
* @param array $callback
|
|
||||||
*/
|
|
||||||
public function handleEndMap(array $callback) {
|
|
||||||
if ($this->mapEnded) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$this->mapEnded = true;
|
|
||||||
$this->mapBegan = false;
|
|
||||||
|
|
||||||
// Trigger own EndMap callback
|
|
||||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_ENDMAP, $this->currentMap);
|
|
||||||
//TODO remove deprecated callback later
|
|
||||||
$this->maniaControl->callbackManager->triggerCallback(Callbacks::ENDMAP, $this->currentMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle Script EndMap Callback
|
|
||||||
*
|
|
||||||
* @param int $mapNumber
|
|
||||||
*/
|
|
||||||
public function handleScriptEndMap($mapNumber) {
|
|
||||||
$this->handleEndMap(array());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle Maps Modified Callback
|
|
||||||
*
|
|
||||||
* @param array $callback
|
|
||||||
*/
|
|
||||||
public function mapsModified(array $callback) {
|
|
||||||
$this->updateFullMapList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all Maps
|
|
||||||
*
|
|
||||||
* @param int $offset
|
|
||||||
* @param int $length
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getMaps($offset = null, $length = null) {
|
|
||||||
if ($offset === null) {
|
|
||||||
return array_values($this->maps);
|
|
||||||
}
|
|
||||||
if ($length === null) {
|
|
||||||
return array_slice($this->maps, $offset);
|
|
||||||
}
|
|
||||||
return array_slice($this->maps, $offset, $length);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the Number of Maps
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getMapsCount() {
|
|
||||||
return count($this->maps);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the MapIndex of a given map
|
|
||||||
*
|
|
||||||
* @param Map $map
|
|
||||||
* @internal param $uid
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function getMapIndex(Map $map) {
|
|
||||||
$maps = $this->getMaps();
|
|
||||||
return array_search($map, $maps);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a Map from Mania Exchange
|
* Adds a Map from Mania Exchange
|
||||||
*
|
*
|
||||||
@ -672,7 +307,7 @@ class MapManager implements CallbackListener {
|
|||||||
// Write map via write file method
|
// Write map via write file method
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->writeFileFromString($relativeMapFileName, $file);
|
$this->maniaControl->client->writeFileFromString($relativeMapFileName, $file);
|
||||||
} catch(InvalidArgumentException $e) {
|
} catch (InvalidArgumentException $e) {
|
||||||
if ($e->getMessage() == 'data are too big') {
|
if ($e->getMessage() == 'data are too big') {
|
||||||
$this->maniaControl->chat->sendError("Map is too big for a remote save.", $login);
|
$this->maniaControl->chat->sendError("Map is too big for a remote save.", $login);
|
||||||
return;
|
return;
|
||||||
@ -684,7 +319,7 @@ class MapManager implements CallbackListener {
|
|||||||
// Check for valid map
|
// Check for valid map
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->checkMapForCurrentServerParams($relativeMapFileName);
|
$this->maniaControl->client->checkMapForCurrentServerParams($relativeMapFileName);
|
||||||
} catch(MapNotCompatibleOrCompleteException $e) {
|
} catch (MapNotCompatibleOrCompleteException $e) {
|
||||||
trigger_error("Couldn't check if map is valid ('{$relativeMapFileName}'). " . $e->getMessage());
|
trigger_error("Couldn't check if map is valid ('{$relativeMapFileName}'). " . $e->getMessage());
|
||||||
$this->maniaControl->chat->sendError('Wrong MapType or not validated!', $login);
|
$this->maniaControl->chat->sendError('Wrong MapType or not validated!', $login);
|
||||||
return;
|
return;
|
||||||
@ -719,5 +354,370 @@ class MapManager implements CallbackListener {
|
|||||||
$this->maniaControl->log($message, true);
|
$this->maniaControl->log($message, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns map By UID
|
||||||
|
*
|
||||||
|
* @param $uid
|
||||||
|
* @return Map array
|
||||||
|
*/
|
||||||
|
public function getMapByUid($uid) {
|
||||||
|
if (!isset($this->maps[$uid])) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return $this->maps[$uid];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the full Map list, needed on Init, addMap and on ShuffleMaps
|
||||||
|
*/
|
||||||
|
private function updateFullMapList() {
|
||||||
|
$tempList = array();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$i = 0;
|
||||||
|
while (true) {
|
||||||
|
$maps = $this->maniaControl->client->getMapList(150, $i);
|
||||||
|
|
||||||
|
foreach ($maps as $rpcMap) {
|
||||||
|
if (array_key_exists($rpcMap->uId, $this->maps)) {
|
||||||
|
// Map already exists, only update index
|
||||||
|
$tempList[$rpcMap->uId] = $this->maps[$rpcMap->uId];
|
||||||
|
} else { // Insert Map Object
|
||||||
|
$map = $this->initializeMap($rpcMap);
|
||||||
|
$tempList[$map->uid] = $map;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$i += 150;
|
||||||
|
}
|
||||||
|
} catch (StartIndexOutOfBoundException $e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// restore Sorted MapList
|
||||||
|
$this->maps = $tempList;
|
||||||
|
|
||||||
|
// Trigger own callback
|
||||||
|
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAPS_UPDATED);
|
||||||
|
|
||||||
|
// Write MapList
|
||||||
|
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_AUTOSAVE_MAPLIST)) {
|
||||||
|
try {
|
||||||
|
$this->maniaControl->client->saveMatchSettings($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAPLIST_FILE));
|
||||||
|
} catch (CouldNotWritePlaylistFileException $e) {
|
||||||
|
$this->maniaControl->log("Unable to write the playlist file, please checkout your MX-Folders File permissions!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes a Map
|
||||||
|
*
|
||||||
|
* @param $rpcMap
|
||||||
|
* @return Map
|
||||||
|
*/
|
||||||
|
public function initializeMap($rpcMap) {
|
||||||
|
$map = new Map($rpcMap);
|
||||||
|
$this->saveMap($map);
|
||||||
|
|
||||||
|
/*$mapsDirectory = $this->maniaControl->server->getMapsDirectory();
|
||||||
|
if (is_readable($mapsDirectory . $map->fileName)) {
|
||||||
|
$mapFetcher = new \GBXChallMapFetcher(true);
|
||||||
|
$mapFetcher->processFile($mapsDirectory . $map->fileName);
|
||||||
|
$map->authorNick = FORMATTER::stripDirtyCodes($mapFetcher->authorNick);
|
||||||
|
$map->authorEInfo = $mapFetcher->authorEInfo;
|
||||||
|
$map->authorZone = $mapFetcher->authorZone;
|
||||||
|
$map->comment = $mapFetcher->comment;
|
||||||
|
}*/
|
||||||
|
return $map;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save a Map in the Database
|
||||||
|
*
|
||||||
|
* @param \ManiaControl\Maps\Map $map
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function saveMap(Map &$map) {
|
||||||
|
//TODO saveMaps for whole maplist at once (usage of prepared statements)
|
||||||
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
|
$mapQuery = "INSERT INTO `" . self::TABLE_MAPS . "` (
|
||||||
|
`uid`,
|
||||||
|
`name`,
|
||||||
|
`authorLogin`,
|
||||||
|
`fileName`,
|
||||||
|
`environment`,
|
||||||
|
`mapType`
|
||||||
|
) VALUES (
|
||||||
|
?, ?, ?, ?, ?, ?
|
||||||
|
) ON DUPLICATE KEY UPDATE
|
||||||
|
`index` = LAST_INSERT_ID(`index`),
|
||||||
|
`fileName` = VALUES(`fileName`),
|
||||||
|
`environment` = VALUES(`environment`),
|
||||||
|
`mapType` = VALUES(`mapType`);";
|
||||||
|
|
||||||
|
$mapStatement = $mysqli->prepare($mapQuery);
|
||||||
|
if ($mysqli->error) {
|
||||||
|
trigger_error($mysqli->error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$mapStatement->bind_param('ssssss', $map->uid, $map->rawName, $map->authorLogin, $map->fileName, $map->environment, $map->mapType);
|
||||||
|
$mapStatement->execute();
|
||||||
|
if ($mapStatement->error) {
|
||||||
|
trigger_error($mapStatement->error);
|
||||||
|
$mapStatement->close();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$map->index = $mapStatement->insert_id;
|
||||||
|
$mapStatement->close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shuffles the MapList
|
||||||
|
*
|
||||||
|
* @param Player $admin
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function shuffleMapList($admin = null) {
|
||||||
|
$shuffledMaps = $this->maps;
|
||||||
|
shuffle($shuffledMaps);
|
||||||
|
|
||||||
|
$mapArray = array();
|
||||||
|
|
||||||
|
foreach ($shuffledMaps as $map) {
|
||||||
|
/**
|
||||||
|
* @var Map $map
|
||||||
|
*/
|
||||||
|
$mapArray[] = $map->fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->maniaControl->client->chooseNextMapList($mapArray);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
//TODO temp added 19.04.2014
|
||||||
|
$this->maniaControl->errorHandler->triggerDebugNotice("Exception line 331 MapManager" . $e->getMessage());
|
||||||
|
trigger_error("Couldn't shuffle mapList. " . $e->getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->fetchCurrentMap();
|
||||||
|
|
||||||
|
if ($admin) {
|
||||||
|
$message = '$<' . $admin->nickname . '$> shuffled the Maplist!';
|
||||||
|
$this->maniaControl->chat->sendSuccess($message);
|
||||||
|
$this->maniaControl->log($message, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restructure if needed
|
||||||
|
$this->restructureMapList();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Freshly fetch current Map
|
||||||
|
*
|
||||||
|
* @return Map
|
||||||
|
*/
|
||||||
|
private function fetchCurrentMap() {
|
||||||
|
$rpcMap = $this->maniaControl->client->getCurrentMapInfo();
|
||||||
|
|
||||||
|
if (array_key_exists($rpcMap->uId, $this->maps)) {
|
||||||
|
$this->currentMap = $this->maps[$rpcMap->uId];
|
||||||
|
$this->currentMap->nbCheckpoints = $rpcMap->nbCheckpoints;
|
||||||
|
$this->currentMap->nbLaps = $rpcMap->nbLaps;
|
||||||
|
return $this->currentMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->currentMap = $this->initializeMap($rpcMap);
|
||||||
|
$this->maps[$this->currentMap->uid] = $this->currentMap;
|
||||||
|
return $this->currentMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restructures the Maplist
|
||||||
|
*/
|
||||||
|
public function restructureMapList() {
|
||||||
|
$currentIndex = $this->getMapIndex($this->currentMap);
|
||||||
|
|
||||||
|
// No RestructureNeeded
|
||||||
|
if ($currentIndex < Maplist::MAX_MAPS_PER_PAGE - 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$lowerMapArray = array();
|
||||||
|
$higherMapArray = array();
|
||||||
|
|
||||||
|
$i = 0;
|
||||||
|
foreach ($this->maps as $map) {
|
||||||
|
if ($i < $currentIndex) {
|
||||||
|
$lowerMapArray[] = $map->fileName;
|
||||||
|
} else {
|
||||||
|
$higherMapArray[] = $map->fileName;
|
||||||
|
}
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$mapArray = array_merge($higherMapArray, $lowerMapArray);
|
||||||
|
array_shift($mapArray);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->maniaControl->client->chooseNextMapList($mapArray);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
trigger_error("Error while restructuring the Maplist. " . $e->getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the MapIndex of a given map
|
||||||
|
*
|
||||||
|
* @param Map $map
|
||||||
|
* @internal param $uid
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getMapIndex(Map $map) {
|
||||||
|
$maps = $this->getMaps();
|
||||||
|
return array_search($map, $maps);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all Maps
|
||||||
|
*
|
||||||
|
* @param int $offset
|
||||||
|
* @param int $length
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getMaps($offset = null, $length = null) {
|
||||||
|
if ($offset === null) {
|
||||||
|
return array_values($this->maps);
|
||||||
|
}
|
||||||
|
if ($length === null) {
|
||||||
|
return array_slice($this->maps, $offset);
|
||||||
|
}
|
||||||
|
return array_slice($this->maps, $offset, $length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle OnInit callback
|
||||||
|
*/
|
||||||
|
public function handleOnInit() {
|
||||||
|
$this->updateFullMapList();
|
||||||
|
$this->fetchCurrentMap();
|
||||||
|
|
||||||
|
// Restructure Maplist
|
||||||
|
$this->restructureMapList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle AfterInit callback
|
||||||
|
*/
|
||||||
|
public function handleAfterInit() {
|
||||||
|
// Fetch MX infos
|
||||||
|
$this->mxManager->fetchManiaExchangeMapInformations();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Current Map
|
||||||
|
*
|
||||||
|
* @return Map currentMap
|
||||||
|
*/
|
||||||
|
public function getCurrentMap() {
|
||||||
|
if (!$this->currentMap) {
|
||||||
|
return $this->fetchCurrentMap();
|
||||||
|
}
|
||||||
|
return $this->currentMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle Script BeginMap callback
|
||||||
|
*
|
||||||
|
* @param int $mapNumber
|
||||||
|
*/
|
||||||
|
public function handleScriptBeginMap($mapNumber) {
|
||||||
|
$this->handleBeginMap(array());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle BeginMap callback
|
||||||
|
*
|
||||||
|
* @param array $callback
|
||||||
|
*/
|
||||||
|
public function handleBeginMap(array $callback) {
|
||||||
|
if ($this->mapBegan) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->mapBegan = true;
|
||||||
|
$this->mapEnded = false;
|
||||||
|
|
||||||
|
if (!isset($callback[1][0]["UId"])) {
|
||||||
|
$this->currentMap = $this->fetchCurrentMap();
|
||||||
|
} else if (array_key_exists($callback[1][0]["UId"], $this->maps)) {
|
||||||
|
// Map already exists, only update index
|
||||||
|
$this->currentMap = $this->maps[$callback[1][0]["UId"]];
|
||||||
|
if (!$this->currentMap->nbCheckpoints || !$this->currentMap->nbLaps) {
|
||||||
|
$rpcMap = $this->maniaControl->client->getCurrentMapInfo();
|
||||||
|
$this->currentMap->nbLaps = $rpcMap->nbLaps;
|
||||||
|
$this->currentMap->nbCheckpoints = $rpcMap->nbCheckpoints;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restructure MapList if id is over 15
|
||||||
|
$this->restructureMapList();
|
||||||
|
|
||||||
|
// Update the mx of the map (for update checks, etc.)
|
||||||
|
$this->mxManager->fetchManiaExchangeMapInformations($this->currentMap);
|
||||||
|
|
||||||
|
// Trigger own BeginMap callback (
|
||||||
|
//TODO remove deprecated callback later
|
||||||
|
$this->maniaControl->callbackManager->triggerCallback(self::CB_BEGINMAP, $this->currentMap);
|
||||||
|
$this->maniaControl->callbackManager->triggerCallback(Callbacks::BEGINMAP, $this->currentMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle Script EndMap Callback
|
||||||
|
*
|
||||||
|
* @param int $mapNumber
|
||||||
|
*/
|
||||||
|
public function handleScriptEndMap($mapNumber) {
|
||||||
|
$this->handleEndMap(array());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle EndMap Callback
|
||||||
|
*
|
||||||
|
* @param array $callback
|
||||||
|
*/
|
||||||
|
public function handleEndMap(array $callback) {
|
||||||
|
if ($this->mapEnded) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->mapEnded = true;
|
||||||
|
$this->mapBegan = false;
|
||||||
|
|
||||||
|
// Trigger own EndMap callback
|
||||||
|
$this->maniaControl->callbackManager->triggerCallback(self::CB_ENDMAP, $this->currentMap);
|
||||||
|
//TODO remove deprecated callback later
|
||||||
|
$this->maniaControl->callbackManager->triggerCallback(Callbacks::ENDMAP, $this->currentMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle Maps Modified Callback
|
||||||
|
*
|
||||||
|
* @param array $callback
|
||||||
|
*/
|
||||||
|
public function mapsModified(array $callback) {
|
||||||
|
$this->updateFullMapList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Number of Maps
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getMapsCount() {
|
||||||
|
return count($this->maps);
|
||||||
|
}
|
||||||
// TODO: add local map by filename
|
// TODO: add local map by filename
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,9 @@ use ManiaControl\Players\Player;
|
|||||||
/**
|
/**
|
||||||
* MapQueue Class
|
* MapQueue Class
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class MapQueue implements CallbackListener, CommandListener {
|
class MapQueue implements CallbackListener, CommandListener {
|
||||||
/*
|
/*
|
||||||
@ -34,7 +34,7 @@ class MapQueue implements CallbackListener, CommandListener {
|
|||||||
|
|
||||||
const ADMIN_COMMAND_CLEAR_MAPQUEUE = 'clearmapqueue';
|
const ADMIN_COMMAND_CLEAR_MAPQUEUE = 'clearmapqueue';
|
||||||
const ADMIN_COMMAND_CLEAR_JUKEBOX = 'clearjukebox';
|
const ADMIN_COMMAND_CLEAR_JUKEBOX = 'clearjukebox';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Private Properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
@ -75,7 +75,7 @@ class MapQueue implements CallbackListener, CommandListener {
|
|||||||
* Adds current map to buffer on startup
|
* Adds current map to buffer on startup
|
||||||
*/
|
*/
|
||||||
public function handleAfterInit() {
|
public function handleAfterInit() {
|
||||||
$currentMap = $this->maniaControl->mapManager->getCurrentMap();
|
$currentMap = $this->maniaControl->mapManager->getCurrentMap();
|
||||||
$this->buffer[] = $currentMap->uid;
|
$this->buffer[] = $currentMap->uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,6 +90,34 @@ class MapQueue implements CallbackListener, CommandListener {
|
|||||||
$this->clearMapQueue($admin);
|
$this->clearMapQueue($admin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the Map Queue
|
||||||
|
*
|
||||||
|
* @param $admin
|
||||||
|
*/
|
||||||
|
public function clearMapQueue($admin) {
|
||||||
|
if (!$this->maniaControl->authenticationManager->checkPermission($admin, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
|
||||||
|
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($this->queuedMaps) == 0) {
|
||||||
|
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $admin->login);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
||||||
|
|
||||||
|
//Destroy map - queue list
|
||||||
|
$this->queuedMaps = array();
|
||||||
|
|
||||||
|
$this->maniaControl->chat->sendInformation('$fa0' . $title . ' $<$fff' . $admin->nickname . '$> cleared the Queued-Map list!');
|
||||||
|
$this->maniaControl->log($title . ' ' . Formatter::stripCodes($admin->nickname) . ' cleared the Queued-Map list!');
|
||||||
|
|
||||||
|
// Trigger callback
|
||||||
|
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('clear'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the mapqueue/jukebox command
|
* Handles the mapqueue/jukebox command
|
||||||
*
|
*
|
||||||
@ -99,12 +127,12 @@ class MapQueue implements CallbackListener, CommandListener {
|
|||||||
public function command_MapQueue(array $chat, Player $player) {
|
public function command_MapQueue(array $chat, Player $player) {
|
||||||
$chatCommands = explode(' ', $chat[1][2]);
|
$chatCommands = explode(' ', $chat[1][2]);
|
||||||
|
|
||||||
if(isset($chatCommands[1])) {
|
if (isset($chatCommands[1])) {
|
||||||
if($chatCommands[1] == ' ' || $chatCommands[1] == 'list') {
|
if ($chatCommands[1] == ' ' || $chatCommands[1] == 'list') {
|
||||||
$this->showMapQueue($player);
|
$this->showMapQueue($player);
|
||||||
} elseif($chatCommands[1] == 'display') {
|
} elseif ($chatCommands[1] == 'display') {
|
||||||
$this->showMapQueueManialink($player);
|
$this->showMapQueueManialink($player);
|
||||||
} elseif($chatCommands[1] == 'clear') {
|
} elseif ($chatCommands[1] == 'clear') {
|
||||||
$this->clearMapQueue($player);
|
$this->clearMapQueue($player);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -118,15 +146,15 @@ class MapQueue implements CallbackListener, CommandListener {
|
|||||||
* @param $player
|
* @param $player
|
||||||
*/
|
*/
|
||||||
public function showMapQueue($player) {
|
public function showMapQueue($player) {
|
||||||
if(count($this->queuedMaps) == 0) {
|
if (count($this->queuedMaps) == 0) {
|
||||||
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $player->login);
|
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $player->login);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$message = '$fa0Upcoming maps in the Map-Queue:';
|
$message = '$fa0Upcoming maps in the Map-Queue:';
|
||||||
$i = 1;
|
$i = 1;
|
||||||
foreach($this->queuedMaps as $queuedMap) {
|
foreach ($this->queuedMaps as $queuedMap) {
|
||||||
$message .= ' $<$fff'.$i.'$>. [$<$fff'.Formatter::stripCodes($queuedMap[1]->name).'$>]';
|
$message .= ' $<$fff' . $i . '$>. [$<$fff' . Formatter::stripCodes($queuedMap[1]->name) . '$>]';
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,13 +167,13 @@ class MapQueue implements CallbackListener, CommandListener {
|
|||||||
* @param $player
|
* @param $player
|
||||||
*/
|
*/
|
||||||
public function showMapQueueManialink($player) {
|
public function showMapQueueManialink($player) {
|
||||||
if(count($this->queuedMaps) == 0) {
|
if (count($this->queuedMaps) == 0) {
|
||||||
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $player->login);
|
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $player->login);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$maps = array();
|
$maps = array();
|
||||||
foreach($this->queuedMaps as $queuedMap) {
|
foreach ($this->queuedMaps as $queuedMap) {
|
||||||
$maps[] = $queuedMap[1];
|
$maps[] = $queuedMap[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,34 +189,6 @@ class MapQueue implements CallbackListener, CommandListener {
|
|||||||
return $this->buffer;
|
return $this->buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Clears the Map Queue
|
|
||||||
*
|
|
||||||
* @param $admin
|
|
||||||
*/
|
|
||||||
public function clearMapQueue($admin) {
|
|
||||||
if (!$this->maniaControl->authenticationManager->checkPermission($admin, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
|
|
||||||
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(count($this->queuedMaps) == 0) {
|
|
||||||
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $admin->login);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
|
||||||
|
|
||||||
//Destroy map - queue list
|
|
||||||
$this->queuedMaps = array();
|
|
||||||
|
|
||||||
$this->maniaControl->chat->sendInformation('$fa0'. $title . ' $<$fff' . $admin->nickname . '$> cleared the Queued-Map list!');
|
|
||||||
$this->maniaControl->log($title . ' ' . Formatter::stripCodes($admin->nickname) . ' cleared the Queued-Map list!');
|
|
||||||
|
|
||||||
// Trigger callback
|
|
||||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('clear'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds map as first map in queue (for /replay)
|
* Adds map as first map in queue (for /replay)
|
||||||
*
|
*
|
||||||
@ -216,15 +216,13 @@ class MapQueue implements CallbackListener, CommandListener {
|
|||||||
|
|
||||||
//Check if player is allowed to add (another) map
|
//Check if player is allowed to add (another) map
|
||||||
$admin = false;
|
$admin = false;
|
||||||
if($this->maniaControl->authenticationManager->checkRight($player, 2) ||
|
if ($this->maniaControl->authenticationManager->checkRight($player, 2) || $this->maniaControl->authenticationManager->checkRight($player, 3) || $this->maniaControl->authenticationManager->checkRight($player, 4)) {
|
||||||
$this->maniaControl->authenticationManager->checkRight($player, 3) ||
|
|
||||||
$this->maniaControl->authenticationManager->checkRight($player, 4)) {
|
|
||||||
$admin = true;
|
$admin = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$mapsForPlayer = 0;
|
$mapsForPlayer = 0;
|
||||||
foreach($this->queuedMaps as $queuedMap) {
|
foreach ($this->queuedMaps as $queuedMap) {
|
||||||
if($queuedMap[0]->login == $login) {
|
if ($queuedMap[0]->login == $login) {
|
||||||
$mapsForPlayer++;
|
$mapsForPlayer++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -232,14 +230,14 @@ class MapQueue implements CallbackListener, CommandListener {
|
|||||||
$maxPlayer = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAPLIMIT_PLAYER);
|
$maxPlayer = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAPLIMIT_PLAYER);
|
||||||
$maxAdmin = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAPLIMIT_ADMIN);
|
$maxAdmin = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAPLIMIT_ADMIN);
|
||||||
|
|
||||||
if($admin && $maxAdmin != -1) {
|
if ($admin && $maxAdmin != -1) {
|
||||||
if($mapsForPlayer == $maxAdmin) {
|
if ($mapsForPlayer == $maxAdmin) {
|
||||||
$this->maniaControl->chat->sendError('You already have $<$fff'.$maxAdmin.'$> map(s) in the Map-Queue!', $login);
|
$this->maniaControl->chat->sendError('You already have $<$fff' . $maxAdmin . '$> map(s) in the Map-Queue!', $login);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} elseif(!$admin && $maxPlayer != -1) {
|
} elseif (!$admin && $maxPlayer != -1) {
|
||||||
if($mapsForPlayer == $maxPlayer) {
|
if ($mapsForPlayer == $maxPlayer) {
|
||||||
$this->maniaControl->chat->sendError('You already have $<$fff'.$maxPlayer.'$> map(s) in the Map-Queue!', $login);
|
$this->maniaControl->chat->sendError('You already have $<$fff' . $maxPlayer . '$> map(s) in the Map-Queue!', $login);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -252,7 +250,7 @@ class MapQueue implements CallbackListener, CommandListener {
|
|||||||
|
|
||||||
//TODO recently maps not able to add to queue-amps setting, and management
|
//TODO recently maps not able to add to queue-amps setting, and management
|
||||||
// Check if map is in the buffer
|
// Check if map is in the buffer
|
||||||
if(in_array($uid, $this->buffer)) {
|
if (in_array($uid, $this->buffer)) {
|
||||||
$this->maniaControl->chat->sendError('That map has recently been played!', $login);
|
$this->maniaControl->chat->sendError('That map has recently been played!', $login);
|
||||||
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
|
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
|
||||||
return;
|
return;
|
||||||
@ -297,10 +295,10 @@ class MapQueue implements CallbackListener, CommandListener {
|
|||||||
*/
|
*/
|
||||||
public function endMap(Map $map) {
|
public function endMap(Map $map) {
|
||||||
$this->nextMap = null;
|
$this->nextMap = null;
|
||||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_SKIP_MAP_ON_LEAVE) == TRUE) {
|
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_SKIP_MAP_ON_LEAVE) == true) {
|
||||||
|
|
||||||
//Skip Map if requester has left
|
//Skip Map if requester has left
|
||||||
foreach($this->queuedMaps as $queuedMap) {
|
foreach ($this->queuedMaps as $queuedMap) {
|
||||||
$player = $queuedMap[0];
|
$player = $queuedMap[0];
|
||||||
|
|
||||||
//found player, so play this map
|
//found player, so play this map
|
||||||
@ -308,7 +306,7 @@ class MapQueue implements CallbackListener, CommandListener {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_SKIP_MAPQUEUE_ADMIN) == FALSE) {
|
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_SKIP_MAPQUEUE_ADMIN) == false) {
|
||||||
//Check if the queuer is a admin
|
//Check if the queuer is a admin
|
||||||
if ($player->authLevel > 0) {
|
if ($player->authLevel > 0) {
|
||||||
break;
|
break;
|
||||||
@ -321,7 +319,7 @@ class MapQueue implements CallbackListener, CommandListener {
|
|||||||
//Player not found, so remove the map from the mapqueue
|
//Player not found, so remove the map from the mapqueue
|
||||||
array_shift($this->queuedMaps);
|
array_shift($this->queuedMaps);
|
||||||
|
|
||||||
$this->maniaControl->chat->sendInformation('$fa0$<$fff' . $queuedMap[0]->name .'$> is skipped because $<' . $player->nickname . '$> left the game!');
|
$this->maniaControl->chat->sendInformation('$fa0$<$fff' . $queuedMap[0]->name . '$> is skipped because $<' . $player->nickname . '$> left the game!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,7 +330,7 @@ class MapQueue implements CallbackListener, CommandListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$map = $this->nextMap[1];
|
$map = $this->nextMap[1];
|
||||||
$this->maniaControl->chat->sendInformation('$fa0Next map will be $<$fff' . $map->name .'$> as requested by $<' . $this->nextMap[0]->nickname . '$>.');
|
$this->maniaControl->chat->sendInformation('$fa0Next map will be $<$fff' . $map->name . '$> as requested by $<' . $this->nextMap[0]->nickname . '$>.');
|
||||||
|
|
||||||
$this->maniaControl->client->chooseNextMap($map->fileName);
|
$this->maniaControl->client->chooseNextMap($map->fileName);
|
||||||
}
|
}
|
||||||
@ -343,11 +341,11 @@ class MapQueue implements CallbackListener, CommandListener {
|
|||||||
* @param Map $map
|
* @param Map $map
|
||||||
*/
|
*/
|
||||||
public function beginMap(Map $map) {
|
public function beginMap(Map $map) {
|
||||||
if(in_array($map->uid, $this->buffer)) {
|
if (in_array($map->uid, $this->buffer)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(count($this->buffer) >= $this->maniaControl->settingManager->getSetting($this, self::SETTING_BUFFERSIZE)) {
|
if (count($this->buffer) >= $this->maniaControl->settingManager->getSetting($this, self::SETTING_BUFFERSIZE)) {
|
||||||
array_shift($this->buffer);
|
array_shift($this->buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -370,7 +368,7 @@ class MapQueue implements CallbackListener, CommandListener {
|
|||||||
* @return array(Player $player, Map $map)
|
* @return array(Player $player, Map $map)
|
||||||
*/
|
*/
|
||||||
public function getNextQueuedMap() {
|
public function getNextQueuedMap() {
|
||||||
foreach($this->queuedMaps as $queuedMap) {
|
foreach ($this->queuedMaps as $queuedMap) {
|
||||||
//return the first Queued Map
|
//return the first Queued Map
|
||||||
return $queuedMap;
|
return $queuedMap;
|
||||||
}
|
}
|
||||||
@ -385,7 +383,7 @@ class MapQueue implements CallbackListener, CommandListener {
|
|||||||
public function getQueuedMapsRanking() {
|
public function getQueuedMapsRanking() {
|
||||||
$i = 1;
|
$i = 1;
|
||||||
$queuedMaps = array();
|
$queuedMaps = array();
|
||||||
foreach($this->queuedMaps as $queuedMap) {
|
foreach ($this->queuedMaps as $queuedMap) {
|
||||||
$map = $queuedMap[1];
|
$map = $queuedMap[1];
|
||||||
$queuedMaps[$map->uid] = $i;
|
$queuedMaps[$map->uid] = $i;
|
||||||
$i++;
|
$i++;
|
||||||
@ -407,7 +405,7 @@ class MapQueue implements CallbackListener, CommandListener {
|
|||||||
* Dummy Function for testing
|
* Dummy Function for testing
|
||||||
*/
|
*/
|
||||||
public function printAllMaps() {
|
public function printAllMaps() {
|
||||||
foreach($this->queuedMaps as $map) {
|
foreach ($this->queuedMaps as $map) {
|
||||||
$map = $map[1];
|
$map = $map[1];
|
||||||
var_dump($map->name);
|
var_dump($map->name);
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,9 @@ use ManiaControl\Formatter;
|
|||||||
/**
|
/**
|
||||||
* Player Model Class
|
* Player Model Class
|
||||||
*
|
*
|
||||||
* @author kremsy & steeffeen
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class Player {
|
class Player {
|
||||||
/*
|
/*
|
||||||
@ -72,7 +72,7 @@ class Player {
|
|||||||
$this->pid = $mpPlayer->playerId;
|
$this->pid = $mpPlayer->playerId;
|
||||||
$this->login = $mpPlayer->login;
|
$this->login = $mpPlayer->login;
|
||||||
$this->nickname = Formatter::stripDirtyCodes($mpPlayer->nickName);
|
$this->nickname = Formatter::stripDirtyCodes($mpPlayer->nickName);
|
||||||
$this->rawNickname = $mpPlayer->nickName;
|
$this->rawNickname = $mpPlayer->nickName;
|
||||||
$this->path = $mpPlayer->path;
|
$this->path = $mpPlayer->path;
|
||||||
$this->language = $mpPlayer->language;
|
$this->language = $mpPlayer->language;
|
||||||
$this->avatar = $mpPlayer->avatar['FileName'];
|
$this->avatar = $mpPlayer->avatar['FileName'];
|
||||||
|
@ -21,8 +21,8 @@ use Maniaplanet\DedicatedServer\Xmlrpc\PlayerNotIgnoredException;
|
|||||||
/**
|
/**
|
||||||
* Player Actions Class
|
* Player Actions Class
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class PlayerActions {
|
class PlayerActions {
|
||||||
@ -70,50 +70,6 @@ class PlayerActions {
|
|||||||
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_FORCE_PLAYER_SPEC, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_FORCE_PLAYER_SPEC, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Force a Player to Play
|
|
||||||
*
|
|
||||||
* @param string $adminLogin
|
|
||||||
* @param string $targetLogin
|
|
||||||
* @param bool $userIsAbleToSelect
|
|
||||||
* @param bool $displayAnnouncement
|
|
||||||
* @internal param int $type
|
|
||||||
*/
|
|
||||||
public function forcePlayerToPlay($adminLogin, $targetLogin, $userIsAbleToSelect = true, $displayAnnouncement = true) {
|
|
||||||
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
|
|
||||||
if (!$this->maniaControl->authenticationManager->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_PLAY)) {
|
|
||||||
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
|
|
||||||
if (!$target) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_PLAYER);
|
|
||||||
} catch(FaultException $e) {
|
|
||||||
//TODO exception 'There are too many players' appeared 28.04.2014, wait for more before add to faultexception
|
|
||||||
$this->maniaControl->chat->sendException($e, $admin->login);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($userIsAbleToSelect) {
|
|
||||||
try {
|
|
||||||
$this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_USER_SELECTABLE);
|
|
||||||
} catch(Exception $e) {
|
|
||||||
$this->maniaControl->chat->sendException($e, $admin->login);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Announce force
|
|
||||||
if ($displayAnnouncement) {
|
|
||||||
$chatMessage = '$<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> to Play!';
|
|
||||||
$this->maniaControl->chat->sendInformation($chatMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Force a Player to a certain Team
|
* Force a Player to a certain Team
|
||||||
*
|
*
|
||||||
@ -138,7 +94,7 @@ class PlayerActions {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->forcePlayerTeam($target->login, $teamId);
|
$this->maniaControl->client->forcePlayerTeam($target->login, $teamId);
|
||||||
} catch(NotInTeamModeException $e) {
|
} catch (NotInTeamModeException $e) {
|
||||||
$this->forcePlayerToPlay($adminLogin, $targetLogin);
|
$this->forcePlayerToPlay($adminLogin, $targetLogin);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -157,6 +113,50 @@ class PlayerActions {
|
|||||||
$this->maniaControl->log($chatMessage, true);
|
$this->maniaControl->log($chatMessage, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Force a Player to Play
|
||||||
|
*
|
||||||
|
* @param string $adminLogin
|
||||||
|
* @param string $targetLogin
|
||||||
|
* @param bool $userIsAbleToSelect
|
||||||
|
* @param bool $displayAnnouncement
|
||||||
|
* @internal param int $type
|
||||||
|
*/
|
||||||
|
public function forcePlayerToPlay($adminLogin, $targetLogin, $userIsAbleToSelect = true, $displayAnnouncement = true) {
|
||||||
|
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
|
||||||
|
if (!$this->maniaControl->authenticationManager->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_PLAY)) {
|
||||||
|
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
|
||||||
|
if (!$target) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_PLAYER);
|
||||||
|
} catch (FaultException $e) {
|
||||||
|
//TODO exception 'There are too many players' appeared 28.04.2014, wait for more before add to faultexception
|
||||||
|
$this->maniaControl->chat->sendException($e, $admin->login);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($userIsAbleToSelect) {
|
||||||
|
try {
|
||||||
|
$this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_USER_SELECTABLE);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->maniaControl->chat->sendException($e, $admin->login);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Announce force
|
||||||
|
if ($displayAnnouncement) {
|
||||||
|
$chatMessage = '$<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> to Play!';
|
||||||
|
$this->maniaControl->chat->sendInformation($chatMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Force a Player to Spectator
|
* Force a Player to Spectator
|
||||||
*
|
*
|
||||||
@ -179,7 +179,7 @@ class PlayerActions {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->forceSpectator($target->login, $spectatorState);
|
$this->maniaControl->client->forceSpectator($target->login, $spectatorState);
|
||||||
} catch(Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->maniaControl->chat->sendException($e, $admin->login);
|
$this->maniaControl->chat->sendException($e, $admin->login);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -193,7 +193,7 @@ class PlayerActions {
|
|||||||
// Free player slot
|
// Free player slot
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->spectatorReleasePlayerSlot($target->login);
|
$this->maniaControl->client->spectatorReleasePlayerSlot($target->login);
|
||||||
} catch(PlayerIsNotSpectatorException $e) {
|
} catch (PlayerIsNotSpectatorException $e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -217,9 +217,9 @@ class PlayerActions {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try {
|
||||||
$this->maniaControl->client->unIgnore($targetLogin);
|
$this->maniaControl->client->unIgnore($targetLogin);
|
||||||
}catch(PlayerNotIgnoredException $e){
|
} catch (PlayerNotIgnoredException $e) {
|
||||||
$this->maniaControl->chat->sendError("Player is not ignored!");
|
$this->maniaControl->chat->sendError("Player is not ignored!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -249,9 +249,9 @@ class PlayerActions {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try {
|
||||||
$this->maniaControl->client->ignore($targetLogin);
|
$this->maniaControl->client->ignore($targetLogin);
|
||||||
}catch(PlayerAlreadyIgnoredException $e){
|
} catch (PlayerAlreadyIgnoredException $e) {
|
||||||
$this->maniaControl->chat->sendError("Player already ignored!");
|
$this->maniaControl->chat->sendError("Player already ignored!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -322,7 +322,7 @@ class PlayerActions {
|
|||||||
$label->setTextColor('f00');
|
$label->setTextColor('f00');
|
||||||
|
|
||||||
$y = $height / 2 - 15;
|
$y = $height / 2 - 15;
|
||||||
foreach($message as $line) {
|
foreach ($message as $line) {
|
||||||
// Message lines
|
// Message lines
|
||||||
$label = new Label_Text();
|
$label = new Label_Text();
|
||||||
$frame->add($label);
|
$frame->add($label);
|
||||||
@ -368,7 +368,7 @@ class PlayerActions {
|
|||||||
} else {
|
} else {
|
||||||
$this->maniaControl->client->kick($target->login, $message);
|
$this->maniaControl->client->kick($target->login, $message);
|
||||||
}
|
}
|
||||||
} catch(Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->maniaControl->chat->sendException($e, $admin->login);
|
$this->maniaControl->chat->sendException($e, $admin->login);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -495,7 +495,7 @@ class PlayerActions {
|
|||||||
*/
|
*/
|
||||||
public function isPlayerMuted($login) {
|
public function isPlayerMuted($login) {
|
||||||
$ignoreList = $this->maniaControl->client->getIgnoreList(100, 0);
|
$ignoreList = $this->maniaControl->client->getIgnoreList(100, 0);
|
||||||
foreach($ignoreList as $ignoredPlayers) {
|
foreach ($ignoreList as $ignoredPlayers) {
|
||||||
if ($ignoredPlayers->login == $login) {
|
if ($ignoredPlayers->login == $login) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,9 @@ use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
|||||||
/**
|
/**
|
||||||
* Class offering various Admin Commands related to Players
|
* Class offering various Admin Commands related to Players
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, CallbackListener {
|
class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, CallbackListener {
|
||||||
/*
|
/*
|
||||||
@ -74,7 +74,7 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle TeamStatusChanged
|
* Handle TeamStatusChanged
|
||||||
*
|
*
|
||||||
* @param bool $teamMode
|
* @param bool $teamMode
|
||||||
*/
|
*/
|
||||||
public function teamStatusChanged($teamMode) {
|
public function teamStatusChanged($teamMode) {
|
||||||
@ -103,7 +103,7 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->autoTeamBalance();
|
$this->maniaControl->client->autoTeamBalance();
|
||||||
} catch(Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->maniaControl->errorHandler->triggerDebugNotice("PlayerCommands Debug Line 112: " . $e->getMessage());
|
$this->maniaControl->errorHandler->triggerDebugNotice("PlayerCommands Debug Line 112: " . $e->getMessage());
|
||||||
// TODO: only catch 'not in team mode' exception - throw others (like connection error)
|
// TODO: only catch 'not in team mode' exception - throw others (like connection error)
|
||||||
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
||||||
|
@ -8,8 +8,8 @@ use ManiaControl\ManiaControl;
|
|||||||
/**
|
/**
|
||||||
* Player Data Manager
|
* Player Data Manager
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class PlayerDataManager {
|
class PlayerDataManager {
|
||||||
@ -42,6 +42,80 @@ class PlayerDataManager {
|
|||||||
$this->storeMetaData();
|
$this->storeMetaData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize necessary database tables
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function initTables() {
|
||||||
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
|
$defaultType = "'" . self::TYPE_STRING . "'";
|
||||||
|
$typeSet = $defaultType . ",'" . self::TYPE_INT . "','" . self::TYPE_REAL . "','" . self::TYPE_BOOL . "','" . self::TYPE_ARRAY . "'";
|
||||||
|
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_PLAYERDATAMETADATA . "` (
|
||||||
|
`dataId` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`class` varchar(100) NOT NULL,
|
||||||
|
`dataName` varchar(100) NOT NULL,
|
||||||
|
`type` set({$typeSet}) NOT NULL DEFAULT {$defaultType},
|
||||||
|
`defaultValue` varchar(150) NOT NULL,
|
||||||
|
`description` varchar(150) NOT NULL,
|
||||||
|
PRIMARY KEY (`dataId`),
|
||||||
|
UNIQUE KEY `name` (`class`, `dataName`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Player-Data MetaData' AUTO_INCREMENT=1;";
|
||||||
|
$statement = $mysqli->prepare($query);
|
||||||
|
if ($mysqli->error) {
|
||||||
|
trigger_error($mysqli->error, E_USER_ERROR);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$statement->execute();
|
||||||
|
if ($statement->error) {
|
||||||
|
trigger_error($statement->error, E_USER_ERROR);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$statement->close();
|
||||||
|
|
||||||
|
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_PLAYERDATA . "` (
|
||||||
|
`index` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`serverIndex` int(11) NOT NULL,
|
||||||
|
`playerId` int(11) NOT NULL,
|
||||||
|
`dataId` int(11) NOT NULL,
|
||||||
|
`value` varchar(150) NOT NULL,
|
||||||
|
`changed` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (`index`),
|
||||||
|
UNIQUE KEY `unique` (`dataId`,`playerId`,`serverIndex`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Player Data' AUTO_INCREMENT=1;";
|
||||||
|
$statement = $mysqli->prepare($query);
|
||||||
|
if ($mysqli->error) {
|
||||||
|
trigger_error($mysqli->error, E_USER_ERROR);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$statement->execute();
|
||||||
|
if ($statement->error) {
|
||||||
|
trigger_error($statement->error, E_USER_ERROR);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$statement->close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store Meta Data from the Database in the Ram
|
||||||
|
*/
|
||||||
|
private function storeMetaData() {
|
||||||
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
|
|
||||||
|
$query = "SELECT * FROM `" . self::TABLE_PLAYERDATAMETADATA . "`;";
|
||||||
|
$result = $mysqli->query($query);
|
||||||
|
if (!$result) {
|
||||||
|
trigger_error($mysqli->error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ($row = $result->fetch_object()) {
|
||||||
|
$this->metaData[$row->class . $row->dataName] = $row;
|
||||||
|
}
|
||||||
|
$result->close();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroys the stored PlayerData (Method get called by PlayerManager, so don't call it anywhere else)
|
* Destroys the stored PlayerData (Method get called by PlayerManager, so don't call it anywhere else)
|
||||||
*
|
*
|
||||||
@ -95,31 +169,55 @@ class PlayerDataManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store Meta Data from the Database in the Ram
|
* Get Class Name of a Parameter
|
||||||
|
*
|
||||||
|
* @param mixed $param
|
||||||
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function storeMetaData() {
|
private function getClassName($param) {
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
if (is_object($param)) {
|
||||||
|
return get_class($param);
|
||||||
$query = "SELECT * FROM `" . self::TABLE_PLAYERDATAMETADATA . "`;";
|
|
||||||
$result = $mysqli->query($query);
|
|
||||||
if (!$result) {
|
|
||||||
trigger_error($mysqli->error);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
if (is_string($param)) {
|
||||||
while($row = $result->fetch_object()) {
|
return $param;
|
||||||
$this->metaData[$row->class . $row->dataName] = $row;
|
|
||||||
}
|
}
|
||||||
$result->close();
|
trigger_error('Invalid class param. ' . $param);
|
||||||
|
return (string)$param;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Type of a Parameter
|
||||||
|
*
|
||||||
|
* @param mixed $param
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function getType($param) {
|
||||||
|
if (is_int($param)) {
|
||||||
|
return self::TYPE_INT;
|
||||||
|
}
|
||||||
|
if (is_real($param)) {
|
||||||
|
return self::TYPE_REAL;
|
||||||
|
}
|
||||||
|
if (is_bool($param)) {
|
||||||
|
return self::TYPE_BOOL;
|
||||||
|
}
|
||||||
|
if (is_string($param)) {
|
||||||
|
return self::TYPE_STRING;
|
||||||
|
}
|
||||||
|
if (is_array($param)) {
|
||||||
|
return self::TYPE_ARRAY;
|
||||||
|
}
|
||||||
|
trigger_error('Unsupported setting type. ' . print_r($param, true));
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the Player Data
|
* Gets the Player Data
|
||||||
*
|
*
|
||||||
* @param mixed $object
|
* @param mixed $object
|
||||||
* @param string $dataName
|
* @param string $dataName
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
* @param int $serverIndex
|
* @param int $serverIndex
|
||||||
* @return mixed|null
|
* @return mixed|null
|
||||||
*/
|
*/
|
||||||
public function getPlayerData($object, $dataName, Player $player, $serverIndex = -1) {
|
public function getPlayerData($object, $dataName, Player $player, $serverIndex = -1) {
|
||||||
@ -172,10 +270,10 @@ class PlayerDataManager {
|
|||||||
/**
|
/**
|
||||||
* Set a PlayerData to a specific defined statMetaData
|
* Set a PlayerData to a specific defined statMetaData
|
||||||
*
|
*
|
||||||
* @param mixed $object
|
* @param mixed $object
|
||||||
* @param string $dataName
|
* @param string $dataName
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param int $serverIndex (let it empty if its global)
|
* @param int $serverIndex (let it empty if its global)
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -237,87 +335,6 @@ class PlayerDataManager {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize necessary database tables
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function initTables() {
|
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
|
||||||
$defaultType = "'" . self::TYPE_STRING . "'";
|
|
||||||
$typeSet = $defaultType . ",'" . self::TYPE_INT . "','" . self::TYPE_REAL . "','" . self::TYPE_BOOL . "','" . self::TYPE_ARRAY . "'";
|
|
||||||
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_PLAYERDATAMETADATA . "` (
|
|
||||||
`dataId` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`class` varchar(100) NOT NULL,
|
|
||||||
`dataName` varchar(100) NOT NULL,
|
|
||||||
`type` set({$typeSet}) NOT NULL DEFAULT {$defaultType},
|
|
||||||
`defaultValue` varchar(150) NOT NULL,
|
|
||||||
`description` varchar(150) NOT NULL,
|
|
||||||
PRIMARY KEY (`dataId`),
|
|
||||||
UNIQUE KEY `name` (`class`, `dataName`)
|
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Player-Data MetaData' AUTO_INCREMENT=1;";
|
|
||||||
$statement = $mysqli->prepare($query);
|
|
||||||
if ($mysqli->error) {
|
|
||||||
trigger_error($mysqli->error, E_USER_ERROR);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$statement->execute();
|
|
||||||
if ($statement->error) {
|
|
||||||
trigger_error($statement->error, E_USER_ERROR);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$statement->close();
|
|
||||||
|
|
||||||
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_PLAYERDATA . "` (
|
|
||||||
`index` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`serverIndex` int(11) NOT NULL,
|
|
||||||
`playerId` int(11) NOT NULL,
|
|
||||||
`dataId` int(11) NOT NULL,
|
|
||||||
`value` varchar(150) NOT NULL,
|
|
||||||
`changed` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
PRIMARY KEY (`index`),
|
|
||||||
UNIQUE KEY `unique` (`dataId`,`playerId`,`serverIndex`)
|
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Player Data' AUTO_INCREMENT=1;";
|
|
||||||
$statement = $mysqli->prepare($query);
|
|
||||||
if ($mysqli->error) {
|
|
||||||
trigger_error($mysqli->error, E_USER_ERROR);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$statement->execute();
|
|
||||||
if ($statement->error) {
|
|
||||||
trigger_error($statement->error, E_USER_ERROR);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$statement->close();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Type of a Parameter
|
|
||||||
*
|
|
||||||
* @param mixed $param
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function getType($param) {
|
|
||||||
if (is_int($param)) {
|
|
||||||
return self::TYPE_INT;
|
|
||||||
}
|
|
||||||
if (is_real($param)) {
|
|
||||||
return self::TYPE_REAL;
|
|
||||||
}
|
|
||||||
if (is_bool($param)) {
|
|
||||||
return self::TYPE_BOOL;
|
|
||||||
}
|
|
||||||
if (is_string($param)) {
|
|
||||||
return self::TYPE_STRING;
|
|
||||||
}
|
|
||||||
if (is_array($param)) {
|
|
||||||
return self::TYPE_ARRAY;
|
|
||||||
}
|
|
||||||
trigger_error('Unsupported setting type. ' . print_r($param, true));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cast a Setting to the given Type
|
* Cast a Setting to the given Type
|
||||||
*
|
*
|
||||||
@ -344,21 +361,4 @@ class PlayerDataManager {
|
|||||||
trigger_error('Unsupported setting type. ' . print_r($type, true));
|
trigger_error('Unsupported setting type. ' . print_r($type, true));
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Class Name of a Parameter
|
|
||||||
*
|
|
||||||
* @param mixed $param
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function getClassName($param) {
|
|
||||||
if (is_object($param)) {
|
|
||||||
return get_class($param);
|
|
||||||
}
|
|
||||||
if (is_string($param)) {
|
|
||||||
return $param;
|
|
||||||
}
|
|
||||||
trigger_error('Invalid class param. ' . $param);
|
|
||||||
return (string)$param;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -19,9 +19,9 @@ use Maniaplanet\DedicatedServer\Structures\Player;
|
|||||||
/**
|
/**
|
||||||
* Player Detailed Page
|
* Player Detailed Page
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class PlayerDetailed {
|
class PlayerDetailed {
|
||||||
/*
|
/*
|
||||||
@ -230,7 +230,7 @@ class PlayerDetailed {
|
|||||||
$x = -$this->width / 2 + 52;
|
$x = -$this->width / 2 + 52;
|
||||||
$id = 1;
|
$id = 1;
|
||||||
|
|
||||||
foreach($playerStats as $stat) {
|
foreach ($playerStats as $stat) {
|
||||||
$statProperties = $stat[0];
|
$statProperties = $stat[0];
|
||||||
$value = $stat[1];
|
$value = $stat[1];
|
||||||
|
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace ManiaControl\Players;
|
namespace ManiaControl\Players;
|
||||||
|
|
||||||
use Maniaplanet\DedicatedServer\Structures\Player;
|
|
||||||
use MCTeam\CustomVotesPlugin;
|
|
||||||
use FML\Controls\Control;
|
use FML\Controls\Control;
|
||||||
use FML\Controls\Frame;
|
use FML\Controls\Frame;
|
||||||
use FML\Controls\Labels\Label_Button;
|
use FML\Controls\Labels\Label_Button;
|
||||||
@ -24,14 +22,16 @@ use ManiaControl\Formatter;
|
|||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Manialinks\ManialinkManager;
|
use ManiaControl\Manialinks\ManialinkManager;
|
||||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||||
|
use Maniaplanet\DedicatedServer\Structures\Player;
|
||||||
use Maniaplanet\DedicatedServer\Xmlrpc\LoginUnknownException;
|
use Maniaplanet\DedicatedServer\Xmlrpc\LoginUnknownException;
|
||||||
use Maniaplanet\DedicatedServer\Xmlrpc\PlayerIsNotSpectatorException;
|
use Maniaplanet\DedicatedServer\Xmlrpc\PlayerIsNotSpectatorException;
|
||||||
|
use MCTeam\CustomVotesPlugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlayerList Widget Class
|
* PlayerList Widget Class
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class PlayerList implements ManialinkPageAnswerListener, CallbackListener, TimerListener {
|
class PlayerList implements ManialinkPageAnswerListener, CallbackListener, TimerListener {
|
||||||
@ -97,6 +97,39 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
$this->playersListShown[$player->login] = $showStatus;
|
$this->playersListShown[$player->login] = $showStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unset the player if he opened another Main Widget
|
||||||
|
*
|
||||||
|
* @param Player $player
|
||||||
|
* @param $openedWidget
|
||||||
|
*/
|
||||||
|
public function handleWidgetOpened(Player $player, $openedWidget) {
|
||||||
|
//unset when another main widget got opened
|
||||||
|
if ($openedWidget != 'PlayerList') {
|
||||||
|
unset($this->playersListShown[$player->login]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the widget
|
||||||
|
*
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
public function closeWidget(Player $player) {
|
||||||
|
unset($this->playersListShown[$player->login]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the player advanced widget widget
|
||||||
|
*
|
||||||
|
* @param array $callback
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
public function closePlayerAdvancedWidget(array $callback, Player $player) {
|
||||||
|
$this->playersListShown[$player->login] = self::SHOWN_MAIN_WINDOW;
|
||||||
|
$this->showPlayerList($player); // overwrite the manialink
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the PlayerList Widget to the Player
|
* Show the PlayerList Widget to the Player
|
||||||
*
|
*
|
||||||
@ -116,8 +149,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
//create manialink
|
//create manialink
|
||||||
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
||||||
$script = $maniaLink->getScript();
|
$script = $maniaLink->getScript();
|
||||||
$paging = new Paging();
|
$paging = new Paging();
|
||||||
$script->addFeature($paging);
|
$script->addFeature($paging);
|
||||||
|
|
||||||
// Main frame
|
// Main frame
|
||||||
$frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $pagesId);
|
$frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $pagesId);
|
||||||
@ -145,7 +178,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
$i = 1;
|
$i = 1;
|
||||||
$y = $height / 2 - 10;
|
$y = $height / 2 - 10;
|
||||||
$pageFrames = array();
|
$pageFrames = array();
|
||||||
foreach($players as $listPlayer) {
|
foreach ($players as $listPlayer) {
|
||||||
/** @var Player $listPlayer * */
|
/** @var Player $listPlayer * */
|
||||||
if (!isset($pageFrame)) {
|
if (!isset($pageFrame)) {
|
||||||
$pageFrame = new Frame();
|
$pageFrame = new Frame();
|
||||||
@ -155,7 +188,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
}
|
}
|
||||||
array_push($pageFrames, $pageFrame);
|
array_push($pageFrames, $pageFrame);
|
||||||
$y = $height / 2 - 10;
|
$y = $height / 2 - 10;
|
||||||
$paging->addPage($pageFrame);
|
$paging->addPage($pageFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
$path = $listPlayer->getProvince();
|
$path = $listPlayer->getProvince();
|
||||||
@ -194,7 +227,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
$teamQuad->setZ(0.1);
|
$teamQuad->setZ(0.1);
|
||||||
$teamQuad->setSize(3.8, 3.8);
|
$teamQuad->setSize(3.8, 3.8);
|
||||||
|
|
||||||
switch($listPlayer->teamId) {
|
switch ($listPlayer->teamId) {
|
||||||
case 0:
|
case 0:
|
||||||
$teamQuad->setSubStyle($teamQuad::SUBSTYLE_1);
|
$teamQuad->setSubStyle($teamQuad::SUBSTYLE_1);
|
||||||
break;
|
break;
|
||||||
@ -222,7 +255,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
$countryQuad->setSize(4, 4);
|
$countryQuad->setSize(4, 4);
|
||||||
$countryQuad->setZ(1);
|
$countryQuad->setZ(1);
|
||||||
|
|
||||||
$countryQuad->addTooltipLabelFeature($descriptionLabel, '$<' . $listPlayer->nickname . '$> from ' . $listPlayer->path);
|
$countryQuad->addTooltipLabelFeature($descriptionLabel, '$<' . $listPlayer->nickname . '$> from ' . $listPlayer->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Level Quad
|
// Level Quad
|
||||||
@ -241,8 +274,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
$rightLabel->setText($this->maniaControl->authenticationManager->getAuthLevelAbbreviation($listPlayer->authLevel));
|
$rightLabel->setText($this->maniaControl->authenticationManager->getAuthLevelAbbreviation($listPlayer->authLevel));
|
||||||
$rightLabel->setTextColor("fff");
|
$rightLabel->setTextColor("fff");
|
||||||
|
|
||||||
$description = $this->maniaControl->authenticationManager->getAuthLevelName($listPlayer) . " " . $listPlayer->nickname;
|
$description = $this->maniaControl->authenticationManager->getAuthLevelName($listPlayer) . " " . $listPlayer->nickname;
|
||||||
$rightLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
$rightLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
||||||
|
|
||||||
// Player Statistics
|
// Player Statistics
|
||||||
$playerQuad = new Quad_Icons64x64_1();
|
$playerQuad = new Quad_Icons64x64_1();
|
||||||
@ -252,8 +285,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
$playerQuad->setSubStyle($playerQuad::SUBSTYLE_TrackInfo);
|
$playerQuad->setSubStyle($playerQuad::SUBSTYLE_TrackInfo);
|
||||||
$playerQuad->setSize(2.7, 2.7);
|
$playerQuad->setSize(2.7, 2.7);
|
||||||
$playerQuad->setAction(self::ACTION_OPEN_PLAYER_DETAILED . "." . $listPlayer->login);
|
$playerQuad->setAction(self::ACTION_OPEN_PLAYER_DETAILED . "." . $listPlayer->login);
|
||||||
$description = 'View Statistics of $<'.$listPlayer->nickname. '$>';
|
$description = 'View Statistics of $<' . $listPlayer->nickname . '$>';
|
||||||
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||||
|
|
||||||
// Camera Quad
|
// Camera Quad
|
||||||
$playerQuad = new Quad_UIConstruction_Buttons();
|
$playerQuad = new Quad_UIConstruction_Buttons();
|
||||||
@ -262,8 +295,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
$playerQuad->setZ(3);
|
$playerQuad->setZ(3);
|
||||||
$playerQuad->setSubStyle($playerQuad::SUBSTYLE_Camera);
|
$playerQuad->setSubStyle($playerQuad::SUBSTYLE_Camera);
|
||||||
$playerQuad->setSize(3.8, 3.8);
|
$playerQuad->setSize(3.8, 3.8);
|
||||||
$description = 'Spectate $<'.$listPlayer->nickname.'$>';
|
$description = 'Spectate $<' . $listPlayer->nickname . '$>';
|
||||||
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||||
$playerQuad->setAction(self::ACTION_SPECTATE_PLAYER . "." . $listPlayer->login);
|
$playerQuad->setAction(self::ACTION_SPECTATE_PLAYER . "." . $listPlayer->login);
|
||||||
|
|
||||||
// Player Profile Quad
|
// Player Profile Quad
|
||||||
@ -273,11 +306,11 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
$playerQuad->setZ(3);
|
$playerQuad->setZ(3);
|
||||||
$playerQuad->setSubStyle($playerQuad::SUBSTYLE_Author);
|
$playerQuad->setSubStyle($playerQuad::SUBSTYLE_Author);
|
||||||
$playerQuad->setSize(3.8, 3.8);
|
$playerQuad->setSize(3.8, 3.8);
|
||||||
$playerQuad->addPlayerProfileFeature($listPlayer->login);
|
$playerQuad->addPlayerProfileFeature($listPlayer->login);
|
||||||
|
|
||||||
// Description Label
|
// Description Label
|
||||||
$description = 'View Player Profile of $<' . $listPlayer->nickname.'$>';
|
$description = 'View Player Profile of $<' . $listPlayer->nickname . '$>';
|
||||||
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||||
|
|
||||||
if ($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
|
if ($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
|
||||||
// Further Player actions Quad
|
// Further Player actions Quad
|
||||||
@ -290,8 +323,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
$playerQuad->setAction(self::ACTION_PLAYER_ADV . "." . $listPlayer->login);
|
$playerQuad->setAction(self::ACTION_PLAYER_ADV . "." . $listPlayer->login);
|
||||||
|
|
||||||
// Description Label
|
// Description Label
|
||||||
$description = 'Advanced Player Actions for $<' . $listPlayer->nickname.'$>';
|
$description = 'Advanced Player Actions for $<' . $listPlayer->nickname . '$>';
|
||||||
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->maniaControl->server->isTeamMode()) {
|
if ($this->maniaControl->server->isTeamMode()) {
|
||||||
@ -306,8 +339,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
$redQuad->setAction(self::ACTION_FORCE_RED . "." . $listPlayer->login);
|
$redQuad->setAction(self::ACTION_FORCE_RED . "." . $listPlayer->login);
|
||||||
|
|
||||||
// Force to Red-Team Description Label
|
// Force to Red-Team Description Label
|
||||||
$description = 'Force $<' . $listPlayer->nickname . '$> to Red Team!';
|
$description = 'Force $<' . $listPlayer->nickname . '$> to Red Team!';
|
||||||
$redQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
$redQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||||
|
|
||||||
// Force to Blue-Team Quad
|
// Force to Blue-Team Quad
|
||||||
$blueQuad = new Quad_Emblems();
|
$blueQuad = new Quad_Emblems();
|
||||||
@ -319,8 +352,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
$blueQuad->setAction(self::ACTION_FORCE_BLUE . "." . $listPlayer->login);
|
$blueQuad->setAction(self::ACTION_FORCE_BLUE . "." . $listPlayer->login);
|
||||||
|
|
||||||
// Force to Blue-Team Description Label
|
// Force to Blue-Team Description Label
|
||||||
$description = 'Force $<' . $listPlayer->nickname . '$> to Blue Team!';
|
$description = 'Force $<' . $listPlayer->nickname . '$> to Blue Team!';
|
||||||
$blueQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
$blueQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||||
|
|
||||||
} else if ($this->maniaControl->pluginManager->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)) {
|
} else if ($this->maniaControl->pluginManager->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)) {
|
||||||
// Kick Player Vote
|
// Kick Player Vote
|
||||||
@ -332,8 +365,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
$kickQuad->setSize(3.8, 3.8);
|
$kickQuad->setSize(3.8, 3.8);
|
||||||
$kickQuad->setAction(self::ACTION_KICK_PLAYER_VOTE . "." . $listPlayer->login);
|
$kickQuad->setAction(self::ACTION_KICK_PLAYER_VOTE . "." . $listPlayer->login);
|
||||||
|
|
||||||
$description = 'Start a Kick Vote on $<' . $listPlayer->nickname . '$>!';
|
$description = 'Start a Kick Vote on $<' . $listPlayer->nickname . '$>!';
|
||||||
$kickQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
$kickQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($this->maniaControl->authenticationManager->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_PLAY)) {
|
if ($this->maniaControl->authenticationManager->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_PLAY)) {
|
||||||
@ -346,8 +379,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
$playQuad->setSize(3.8, 3.8);
|
$playQuad->setSize(3.8, 3.8);
|
||||||
$playQuad->setAction(self::ACTION_FORCE_PLAY . "." . $listPlayer->login);
|
$playQuad->setAction(self::ACTION_FORCE_PLAY . "." . $listPlayer->login);
|
||||||
|
|
||||||
$description = 'Force $<' . $listPlayer->nickname . '$> to Play!';
|
$description = 'Force $<' . $listPlayer->nickname . '$> to Play!';
|
||||||
$playQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
$playQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,8 +395,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
$spectatorQuad->setAction(self::ACTION_FORCE_SPEC . "." . $listPlayer->login);
|
$spectatorQuad->setAction(self::ACTION_FORCE_SPEC . "." . $listPlayer->login);
|
||||||
|
|
||||||
// Force to Spectator Description Label
|
// Force to Spectator Description Label
|
||||||
$description = 'Force $<' . $listPlayer->nickname . '$> to Spectator!';
|
$description = 'Force $<' . $listPlayer->nickname . '$> to Spectator!';
|
||||||
$spectatorQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
$spectatorQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||||
} else if ($this->maniaControl->pluginManager->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)) {
|
} else if ($this->maniaControl->pluginManager->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)) {
|
||||||
// Force to Spectator Quad
|
// Force to Spectator Quad
|
||||||
$spectatorQuad = new Quad_BgRaceScore2();
|
$spectatorQuad = new Quad_BgRaceScore2();
|
||||||
@ -375,8 +408,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
$spectatorQuad->setAction(self::ACTION_FORCE_SPEC_VOTE . "." . $listPlayer->login);
|
$spectatorQuad->setAction(self::ACTION_FORCE_SPEC_VOTE . "." . $listPlayer->login);
|
||||||
|
|
||||||
// Force to Spectator Description Label
|
// Force to Spectator Description Label
|
||||||
$description = 'Start a Vote to force $<' . $listPlayer->nickname . '$> to Spectator!';
|
$description = 'Start a Vote to force $<' . $listPlayer->nickname . '$> to Spectator!';
|
||||||
$spectatorQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
$spectatorQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||||
}
|
}
|
||||||
|
|
||||||
$y -= 4;
|
$y -= 4;
|
||||||
@ -396,20 +429,6 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'PlayerList');
|
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'PlayerList');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Displays the Advanced Player Window
|
|
||||||
*
|
|
||||||
* @param Player $caller
|
|
||||||
* @param $login
|
|
||||||
*/
|
|
||||||
public function advancedPlayerWidget(Player $caller, $login) {
|
|
||||||
// Set status to target player login
|
|
||||||
$this->playersListShown[$caller->login] = $login;
|
|
||||||
|
|
||||||
// Reopen playerlist
|
|
||||||
$this->showPlayerList($caller);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extra window with special actions on players like warn,kick, ban, authorization levels...
|
* Extra window with special actions on players like warn,kick, ban, authorization levels...
|
||||||
*
|
*
|
||||||
@ -610,39 +629,6 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
return $frame;
|
return $frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Unset the player if he opened another Main Widget
|
|
||||||
*
|
|
||||||
* @param Player $player
|
|
||||||
* @param $openedWidget
|
|
||||||
*/
|
|
||||||
public function handleWidgetOpened(Player $player, $openedWidget) {
|
|
||||||
//unset when another main widget got opened
|
|
||||||
if ($openedWidget != 'PlayerList') {
|
|
||||||
unset($this->playersListShown[$player->login]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Closes the widget
|
|
||||||
*
|
|
||||||
* @param Player $player
|
|
||||||
*/
|
|
||||||
public function closeWidget(Player $player) {
|
|
||||||
unset($this->playersListShown[$player->login]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Closes the player advanced widget widget
|
|
||||||
*
|
|
||||||
* @param array $callback
|
|
||||||
* @param Player $player
|
|
||||||
*/
|
|
||||||
public function closePlayerAdvancedWidget(array $callback, Player $player) {
|
|
||||||
$this->playersListShown[$player->login] = self::SHOWN_MAIN_WINDOW;
|
|
||||||
$this->showPlayerList($player); // overwrite the manialink
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called on ManialinkPageAnswer
|
* Called on ManialinkPageAnswer
|
||||||
*
|
*
|
||||||
@ -659,12 +645,12 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
$adminLogin = $callback[1][1];
|
$adminLogin = $callback[1][1];
|
||||||
$targetLogin = $actionArray[2];
|
$targetLogin = $actionArray[2];
|
||||||
|
|
||||||
switch($action) {
|
switch ($action) {
|
||||||
case self::ACTION_SPECTATE_PLAYER:
|
case self::ACTION_SPECTATE_PLAYER:
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->forceSpectator($adminLogin, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
|
$this->maniaControl->client->forceSpectator($adminLogin, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
|
||||||
$this->maniaControl->client->forceSpectatorTarget($adminLogin, $targetLogin, 1);
|
$this->maniaControl->client->forceSpectatorTarget($adminLogin, $targetLogin, 1);
|
||||||
} catch(PlayerIsNotSpectatorException $e) {
|
} catch (PlayerIsNotSpectatorException $e) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case self::ACTION_OPEN_PLAYER_DETAILED:
|
case self::ACTION_OPEN_PLAYER_DETAILED:
|
||||||
@ -736,7 +722,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
try {
|
try {
|
||||||
$self->maniaControl->client->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
|
$self->maniaControl->client->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
|
||||||
$self->maniaControl->client->spectatorReleasePlayerSlot($target->login);
|
$self->maniaControl->client->spectatorReleasePlayerSlot($target->login);
|
||||||
} catch(PlayerIsNotSpectatorException $e) {
|
} catch (PlayerIsNotSpectatorException $e) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@ -760,20 +746,34 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
$message = '$39F You got kicked due a Public vote!$z ';
|
$message = '$39F You got kicked due a Public vote!$z ';
|
||||||
try {
|
try {
|
||||||
$self->maniaControl->client->kick($target->login, $message);
|
$self->maniaControl->client->kick($target->login, $message);
|
||||||
} catch(LoginUnknownException $e) {
|
} catch (LoginUnknownException $e) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays the Advanced Player Window
|
||||||
|
*
|
||||||
|
* @param Player $caller
|
||||||
|
* @param $login
|
||||||
|
*/
|
||||||
|
public function advancedPlayerWidget(Player $caller, $login) {
|
||||||
|
// Set status to target player login
|
||||||
|
$this->playersListShown[$caller->login] = $login;
|
||||||
|
|
||||||
|
// Reopen playerlist
|
||||||
|
$this->showPlayerList($caller);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reopen the widget on PlayerInfoChanged / Player Connect and Disconnect
|
* Reopen the widget on PlayerInfoChanged / Player Connect and Disconnect
|
||||||
*
|
*
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
public function updateWidget(Player $player) {
|
public function updateWidget(Player $player) {
|
||||||
foreach($this->playersListShown as $login => $shown) {
|
foreach ($this->playersListShown as $login => $shown) {
|
||||||
if (!$shown) {
|
if (!$shown) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,8 @@ use Maniaplanet\DedicatedServer\Xmlrpc\LoginUnknownException;
|
|||||||
/**
|
/**
|
||||||
* Class managing Players
|
* Class managing Players
|
||||||
*
|
*
|
||||||
* @author kremsy & steeffeen
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class PlayerManager implements CallbackListener, TimerListener {
|
class PlayerManager implements CallbackListener, TimerListener {
|
||||||
@ -112,7 +112,7 @@ class PlayerManager implements CallbackListener, TimerListener {
|
|||||||
public function onInit() {
|
public function onInit() {
|
||||||
// Add all players
|
// Add all players
|
||||||
$players = $this->maniaControl->client->getPlayerList(300, 0, 2);
|
$players = $this->maniaControl->client->getPlayerList(300, 0, 2);
|
||||||
foreach($players as $playerItem) {
|
foreach ($players as $playerItem) {
|
||||||
if ($playerItem->playerId <= 0) {
|
if ($playerItem->playerId <= 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -141,183 +141,6 @@ class PlayerManager implements CallbackListener, TimerListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle playerConnect callback
|
|
||||||
*
|
|
||||||
* @param array $callback
|
|
||||||
*/
|
|
||||||
public function playerConnect(array $callback) {
|
|
||||||
$login = $callback[1][0];
|
|
||||||
try {
|
|
||||||
$playerInfo = $this->maniaControl->client->getDetailedPlayerInfo($login);
|
|
||||||
$player = new Player($playerInfo);
|
|
||||||
|
|
||||||
$this->addPlayer($player);
|
|
||||||
} catch(LoginUnknownException $e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle playerDisconnect callback
|
|
||||||
*
|
|
||||||
* @param array $callback
|
|
||||||
*/
|
|
||||||
public function playerDisconnect(array $callback) {
|
|
||||||
$login = $callback[1][0];
|
|
||||||
$player = $this->removePlayer($login);
|
|
||||||
if (!$player) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trigger own callback
|
|
||||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERDISCONNECT, $player);
|
|
||||||
|
|
||||||
if ($player->isFakePlayer()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$played = Formatter::formatTimeH(time() - $player->joinTime);
|
|
||||||
$logMessage = "Player left: {$player->login} / {$player->nickname} Playtime: {$played}";
|
|
||||||
$this->maniaControl->log(Formatter::stripCodes($logMessage));
|
|
||||||
|
|
||||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES)) {
|
|
||||||
$this->maniaControl->chat->sendChat('$0f0$<$fff' . $player->nickname . '$> has left the game');
|
|
||||||
}
|
|
||||||
|
|
||||||
//Destroys stored PlayerData, after all Disconnect Callbacks got Handled
|
|
||||||
$this->playerDataManager->destroyPlayerData($player);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update PlayerInfo
|
|
||||||
*
|
|
||||||
* @param array $callback
|
|
||||||
*/
|
|
||||||
public function playerInfoChanged(array $callback) {
|
|
||||||
$player = $this->getPlayer($callback[1][0]['Login']);
|
|
||||||
if (!$player) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$player->ladderRank = $callback[1][0]["LadderRanking"];
|
|
||||||
$player->teamId = $callback[1][0]["TeamId"];
|
|
||||||
|
|
||||||
//Check if the Player is in a Team, to notify if its a TeamMode or not
|
|
||||||
if ($player->teamId != -1) {
|
|
||||||
$this->maniaControl->server->setTeamMode(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
$prevJoinState = $player->hasJoinedGame;
|
|
||||||
|
|
||||||
$player->updatePlayerFlags($callback[1][0]["Flags"]);
|
|
||||||
$player->updateSpectatorStatus($callback[1][0]["SpectatorStatus"]);
|
|
||||||
|
|
||||||
//Check if Player finished joining the game
|
|
||||||
if ($player->hasJoinedGame && !$prevJoinState) {
|
|
||||||
|
|
||||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer()) {
|
|
||||||
$string = array(0 => '$0f0Player', 1 => '$0f0Moderator', 2 => '$0f0Admin', 3 => '$0f0SuperAdmin', 4 => '$0f0MasterAdmin');
|
|
||||||
$chatMessage = '$0f0' . $string[$player->authLevel] . ' $<$fff' . $player->nickname . '$> Nation: $<$fff' . $player->getCountry() . '$> joined!';
|
|
||||||
$this->maniaControl->chat->sendChat($chatMessage);
|
|
||||||
$this->maniaControl->chat->sendInformation('This server uses ManiaControl v' . ManiaControl::VERSION . '!', $player->login);
|
|
||||||
}
|
|
||||||
|
|
||||||
$logMessage = "Player joined: {$player->login} / " . Formatter::stripCodes($player->nickname) . " Nation: " . $player->getCountry() . " IP: {$player->ipAddress}";
|
|
||||||
$this->maniaControl->log($logMessage);
|
|
||||||
|
|
||||||
// Increment the Player Join Count
|
|
||||||
$this->maniaControl->statisticManager->incrementStat(self::STAT_JOIN_COUNT, $player, $this->maniaControl->server->index);
|
|
||||||
|
|
||||||
// Trigger own PlayerJoined callback
|
|
||||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERCONNECT, $player);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trigger own callback
|
|
||||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERINFOCHANGED, $player);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all Players
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getPlayers() {
|
|
||||||
return $this->players;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the Count of all Player
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getPlayerCount() {
|
|
||||||
$count = 0;
|
|
||||||
foreach($this->players as $player) {
|
|
||||||
/** @var Player $player */
|
|
||||||
if (!$player->isSpectator) {
|
|
||||||
$count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $count;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the Count of all Spectators
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getSpectatorCount() {
|
|
||||||
$count = 0;
|
|
||||||
foreach($this->players as $player) {
|
|
||||||
/** @var Player $player */
|
|
||||||
if ($player->isSpectator) {
|
|
||||||
$count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $count;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a Player by his index
|
|
||||||
*
|
|
||||||
* @param $index
|
|
||||||
* @param bool $connectedPlayersOnly
|
|
||||||
* @return Player|null
|
|
||||||
*/
|
|
||||||
public function getPlayerByIndex($index, $connectedPlayersOnly = false) {
|
|
||||||
foreach($this->players as $player) {
|
|
||||||
/** @var Player $player */
|
|
||||||
if ($player->index == $index) {
|
|
||||||
return $player;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($connectedPlayersOnly) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
//Player is not online -> get Player from Database
|
|
||||||
return $this->getPlayerFromDatabaseByIndex($index);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a Player by Login
|
|
||||||
*
|
|
||||||
* @param string $login
|
|
||||||
* @param bool $connectedPlayersOnly
|
|
||||||
* @return Player
|
|
||||||
*/
|
|
||||||
public function getPlayer($login, $connectedPlayersOnly = false) {
|
|
||||||
if (!isset($this->players[$login])) {
|
|
||||||
if ($connectedPlayersOnly) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return $this->getPlayerFromDatabaseByLogin($login);
|
|
||||||
}
|
|
||||||
return $this->players[$login];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a player
|
* Add a player
|
||||||
*
|
*
|
||||||
@ -330,99 +153,6 @@ class PlayerManager implements CallbackListener, TimerListener {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove a Player
|
|
||||||
*
|
|
||||||
* @param string $login
|
|
||||||
* @param bool $savePlayedTime
|
|
||||||
* @return Player $player
|
|
||||||
*/
|
|
||||||
private function removePlayer($login, $savePlayedTime = true) {
|
|
||||||
if (!isset($this->players[$login])) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
$player = $this->players[$login];
|
|
||||||
unset($this->players[$login]);
|
|
||||||
if ($savePlayedTime) {
|
|
||||||
$this->updatePlayedTime($player);
|
|
||||||
}
|
|
||||||
return $player;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get's a Player out of the database
|
|
||||||
*
|
|
||||||
* @param $playerIndex
|
|
||||||
* @return Player $player
|
|
||||||
*/
|
|
||||||
private function getPlayerFromDatabaseByIndex($playerIndex) {
|
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
|
||||||
|
|
||||||
if (!is_numeric($playerIndex)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = "SELECT * FROM `" . self::TABLE_PLAYERS . "` WHERE `index` = " . $playerIndex . ";";
|
|
||||||
$result = $mysqli->query($query);
|
|
||||||
if (!$result) {
|
|
||||||
trigger_error($mysqli->error);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$row = $result->fetch_object();
|
|
||||||
$result->close();
|
|
||||||
|
|
||||||
if (!isset($row)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$player = new Player(null);
|
|
||||||
$player->index = $playerIndex;
|
|
||||||
$player->login = $row->login;
|
|
||||||
$player->rawNickname = $row->nickname;
|
|
||||||
$player->nickname = Formatter::stripDirtyCodes($player->rawNickname);
|
|
||||||
$player->path = $row->path;
|
|
||||||
$player->authLevel = $row->authLevel;
|
|
||||||
|
|
||||||
return $player;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a Player from the Database
|
|
||||||
*
|
|
||||||
* @param string $playerLogin
|
|
||||||
* @return Player
|
|
||||||
*/
|
|
||||||
private function getPlayerFromDatabaseByLogin($playerLogin) {
|
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
|
||||||
|
|
||||||
$query = "SELECT * FROM `" . self::TABLE_PLAYERS . "` WHERE `login` LIKE '" . $mysqli->escape_string($playerLogin) . "';";
|
|
||||||
$result = $mysqli->query($query);
|
|
||||||
if (!$result) {
|
|
||||||
trigger_error($mysqli->error);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$row = $result->fetch_object();
|
|
||||||
$result->close();
|
|
||||||
|
|
||||||
if (!isset($row)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$player = new Player(null);
|
|
||||||
$player->index = $row->index;
|
|
||||||
$player->login = $row->login;
|
|
||||||
$player->rawNickname = $row->nickname;
|
|
||||||
$player->nickname = Formatter::stripDirtyCodes($player->rawNickname);
|
|
||||||
$player->path = $row->path;
|
|
||||||
$player->authLevel = $row->authLevel;
|
|
||||||
|
|
||||||
return $player;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save player in Database and fill up Object Properties
|
* Save player in Database and fill up Object Properties
|
||||||
*
|
*
|
||||||
@ -481,6 +211,72 @@ class PlayerManager implements CallbackListener, TimerListener {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle playerConnect callback
|
||||||
|
*
|
||||||
|
* @param array $callback
|
||||||
|
*/
|
||||||
|
public function playerConnect(array $callback) {
|
||||||
|
$login = $callback[1][0];
|
||||||
|
try {
|
||||||
|
$playerInfo = $this->maniaControl->client->getDetailedPlayerInfo($login);
|
||||||
|
$player = new Player($playerInfo);
|
||||||
|
|
||||||
|
$this->addPlayer($player);
|
||||||
|
} catch (LoginUnknownException $e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle playerDisconnect callback
|
||||||
|
*
|
||||||
|
* @param array $callback
|
||||||
|
*/
|
||||||
|
public function playerDisconnect(array $callback) {
|
||||||
|
$login = $callback[1][0];
|
||||||
|
$player = $this->removePlayer($login);
|
||||||
|
if (!$player) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trigger own callback
|
||||||
|
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERDISCONNECT, $player);
|
||||||
|
|
||||||
|
if ($player->isFakePlayer()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$played = Formatter::formatTimeH(time() - $player->joinTime);
|
||||||
|
$logMessage = "Player left: {$player->login} / {$player->nickname} Playtime: {$played}";
|
||||||
|
$this->maniaControl->log(Formatter::stripCodes($logMessage));
|
||||||
|
|
||||||
|
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES)) {
|
||||||
|
$this->maniaControl->chat->sendChat('$0f0$<$fff' . $player->nickname . '$> has left the game');
|
||||||
|
}
|
||||||
|
|
||||||
|
//Destroys stored PlayerData, after all Disconnect Callbacks got Handled
|
||||||
|
$this->playerDataManager->destroyPlayerData($player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a Player
|
||||||
|
*
|
||||||
|
* @param string $login
|
||||||
|
* @param bool $savePlayedTime
|
||||||
|
* @return Player $player
|
||||||
|
*/
|
||||||
|
private function removePlayer($login, $savePlayedTime = true) {
|
||||||
|
if (!isset($this->players[$login])) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$player = $this->players[$login];
|
||||||
|
unset($this->players[$login]);
|
||||||
|
if ($savePlayedTime) {
|
||||||
|
$this->updatePlayedTime($player);
|
||||||
|
}
|
||||||
|
return $player;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update total played time of the player
|
* Update total played time of the player
|
||||||
*
|
*
|
||||||
@ -495,4 +291,205 @@ class PlayerManager implements CallbackListener, TimerListener {
|
|||||||
|
|
||||||
return $this->maniaControl->statisticManager->insertStat(self::STAT_SERVERTIME, $player, $this->maniaControl->server->index, $playedTime);
|
return $this->maniaControl->statisticManager->insertStat(self::STAT_SERVERTIME, $player, $this->maniaControl->server->index, $playedTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update PlayerInfo
|
||||||
|
*
|
||||||
|
* @param array $callback
|
||||||
|
*/
|
||||||
|
public function playerInfoChanged(array $callback) {
|
||||||
|
$player = $this->getPlayer($callback[1][0]['Login']);
|
||||||
|
if (!$player) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$player->ladderRank = $callback[1][0]["LadderRanking"];
|
||||||
|
$player->teamId = $callback[1][0]["TeamId"];
|
||||||
|
|
||||||
|
//Check if the Player is in a Team, to notify if its a TeamMode or not
|
||||||
|
if ($player->teamId != -1) {
|
||||||
|
$this->maniaControl->server->setTeamMode(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$prevJoinState = $player->hasJoinedGame;
|
||||||
|
|
||||||
|
$player->updatePlayerFlags($callback[1][0]["Flags"]);
|
||||||
|
$player->updateSpectatorStatus($callback[1][0]["SpectatorStatus"]);
|
||||||
|
|
||||||
|
//Check if Player finished joining the game
|
||||||
|
if ($player->hasJoinedGame && !$prevJoinState) {
|
||||||
|
|
||||||
|
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer()) {
|
||||||
|
$string = array(0 => '$0f0Player', 1 => '$0f0Moderator', 2 => '$0f0Admin', 3 => '$0f0SuperAdmin', 4 => '$0f0MasterAdmin');
|
||||||
|
$chatMessage = '$0f0' . $string[$player->authLevel] . ' $<$fff' . $player->nickname . '$> Nation: $<$fff' . $player->getCountry() . '$> joined!';
|
||||||
|
$this->maniaControl->chat->sendChat($chatMessage);
|
||||||
|
$this->maniaControl->chat->sendInformation('This server uses ManiaControl v' . ManiaControl::VERSION . '!', $player->login);
|
||||||
|
}
|
||||||
|
|
||||||
|
$logMessage = "Player joined: {$player->login} / " . Formatter::stripCodes($player->nickname) . " Nation: " . $player->getCountry() . " IP: {$player->ipAddress}";
|
||||||
|
$this->maniaControl->log($logMessage);
|
||||||
|
|
||||||
|
// Increment the Player Join Count
|
||||||
|
$this->maniaControl->statisticManager->incrementStat(self::STAT_JOIN_COUNT, $player, $this->maniaControl->server->index);
|
||||||
|
|
||||||
|
// Trigger own PlayerJoined callback
|
||||||
|
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERCONNECT, $player);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trigger own callback
|
||||||
|
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERINFOCHANGED, $player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a Player by Login
|
||||||
|
*
|
||||||
|
* @param string $login
|
||||||
|
* @param bool $connectedPlayersOnly
|
||||||
|
* @return Player
|
||||||
|
*/
|
||||||
|
public function getPlayer($login, $connectedPlayersOnly = false) {
|
||||||
|
if (!isset($this->players[$login])) {
|
||||||
|
if ($connectedPlayersOnly) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return $this->getPlayerFromDatabaseByLogin($login);
|
||||||
|
}
|
||||||
|
return $this->players[$login];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a Player from the Database
|
||||||
|
*
|
||||||
|
* @param string $playerLogin
|
||||||
|
* @return Player
|
||||||
|
*/
|
||||||
|
private function getPlayerFromDatabaseByLogin($playerLogin) {
|
||||||
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
|
|
||||||
|
$query = "SELECT * FROM `" . self::TABLE_PLAYERS . "` WHERE `login` LIKE '" . $mysqli->escape_string($playerLogin) . "';";
|
||||||
|
$result = $mysqli->query($query);
|
||||||
|
if (!$result) {
|
||||||
|
trigger_error($mysqli->error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$row = $result->fetch_object();
|
||||||
|
$result->close();
|
||||||
|
|
||||||
|
if (!isset($row)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$player = new Player(null);
|
||||||
|
$player->index = $row->index;
|
||||||
|
$player->login = $row->login;
|
||||||
|
$player->rawNickname = $row->nickname;
|
||||||
|
$player->nickname = Formatter::stripDirtyCodes($player->rawNickname);
|
||||||
|
$player->path = $row->path;
|
||||||
|
$player->authLevel = $row->authLevel;
|
||||||
|
|
||||||
|
return $player;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all Players
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getPlayers() {
|
||||||
|
return $this->players;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the Count of all Player
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getPlayerCount() {
|
||||||
|
$count = 0;
|
||||||
|
foreach ($this->players as $player) {
|
||||||
|
/** @var Player $player */
|
||||||
|
if (!$player->isSpectator) {
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the Count of all Spectators
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getSpectatorCount() {
|
||||||
|
$count = 0;
|
||||||
|
foreach ($this->players as $player) {
|
||||||
|
/** @var Player $player */
|
||||||
|
if ($player->isSpectator) {
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a Player by his index
|
||||||
|
*
|
||||||
|
* @param $index
|
||||||
|
* @param bool $connectedPlayersOnly
|
||||||
|
* @return Player|null
|
||||||
|
*/
|
||||||
|
public function getPlayerByIndex($index, $connectedPlayersOnly = false) {
|
||||||
|
foreach ($this->players as $player) {
|
||||||
|
/** @var Player $player */
|
||||||
|
if ($player->index == $index) {
|
||||||
|
return $player;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($connectedPlayersOnly) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
//Player is not online -> get Player from Database
|
||||||
|
return $this->getPlayerFromDatabaseByIndex($index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get's a Player out of the database
|
||||||
|
*
|
||||||
|
* @param $playerIndex
|
||||||
|
* @return Player $player
|
||||||
|
*/
|
||||||
|
private function getPlayerFromDatabaseByIndex($playerIndex) {
|
||||||
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
|
|
||||||
|
if (!is_numeric($playerIndex)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = "SELECT * FROM `" . self::TABLE_PLAYERS . "` WHERE `index` = " . $playerIndex . ";";
|
||||||
|
$result = $mysqli->query($query);
|
||||||
|
if (!$result) {
|
||||||
|
trigger_error($mysqli->error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$row = $result->fetch_object();
|
||||||
|
$result->close();
|
||||||
|
|
||||||
|
if (!isset($row)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$player = new Player(null);
|
||||||
|
$player->index = $playerIndex;
|
||||||
|
$player->login = $row->login;
|
||||||
|
$player->rawNickname = $row->nickname;
|
||||||
|
$player->nickname = Formatter::stripDirtyCodes($player->rawNickname);
|
||||||
|
$player->path = $row->path;
|
||||||
|
$player->authLevel = $row->authLevel;
|
||||||
|
|
||||||
|
return $player;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,9 @@ namespace ManiaControl\Server;
|
|||||||
/**
|
/**
|
||||||
* Model Class holding the Server Config
|
* Model Class holding the Server Config
|
||||||
*
|
*
|
||||||
* @author steeffeen
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class Config {
|
class Config {
|
||||||
/*
|
/*
|
||||||
@ -22,17 +22,17 @@ class Config {
|
|||||||
/**
|
/**
|
||||||
* Create a new Server Config Instance
|
* Create a new Server Config Instance
|
||||||
*
|
*
|
||||||
* @param string $id Config Id
|
* @param string $id Config Id
|
||||||
* @param string $host Server Ip
|
* @param string $host Server Ip
|
||||||
* @param string $port Server Port
|
* @param string $port Server Port
|
||||||
* @param string $login XmlRpc Login
|
* @param string $login XmlRpc Login
|
||||||
* @param string $pass XmlRpc Password
|
* @param string $pass XmlRpc Password
|
||||||
*/
|
*/
|
||||||
public function __construct($id = null, $host = null, $port = null, $login = null, $pass = null) {
|
public function __construct($id = null, $host = null, $port = null, $login = null, $pass = null) {
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
$this->host = $host;
|
$this->host = $host;
|
||||||
$this->port = $port;
|
$this->port = $port;
|
||||||
$this->login = $login;
|
$this->login = $login;
|
||||||
$this->pass = $pass;
|
$this->pass = $pass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,8 @@ use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
|
|||||||
/**
|
/**
|
||||||
* Class managing Rankings
|
* Class managing Rankings
|
||||||
*
|
*
|
||||||
* @author kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class RankingManager implements CallbackListener {
|
class RankingManager implements CallbackListener {
|
||||||
@ -42,20 +42,10 @@ class RankingManager implements CallbackListener {
|
|||||||
public function onInit() {
|
public function onInit() {
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->triggerModeScriptEvent('LibXmlRpc_GetRankings', '');
|
$this->maniaControl->client->triggerModeScriptEvent('LibXmlRpc_GetRankings', '');
|
||||||
} catch(NotInScriptModeException $e) {
|
} catch (NotInScriptModeException $e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Rankings
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getRankings() {
|
|
||||||
return $this->rankings;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle stats on callbacks (never call this Method)
|
* Handle stats on callbacks (never call this Method)
|
||||||
*
|
*
|
||||||
@ -65,7 +55,7 @@ class RankingManager implements CallbackListener {
|
|||||||
$callbackName = $callback[1][0];
|
$callbackName = $callback[1][0];
|
||||||
|
|
||||||
//TODO not tested in TrackMania
|
//TODO not tested in TrackMania
|
||||||
switch($callbackName) {
|
switch ($callbackName) {
|
||||||
case 'updateRankings':
|
case 'updateRankings':
|
||||||
$this->updateRankings($callback[1][1][0]);
|
$this->updateRankings($callback[1][1][0]);
|
||||||
break;
|
break;
|
||||||
@ -89,7 +79,7 @@ class RankingManager implements CallbackListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$scores = explode(';', $data);
|
$scores = explode(';', $data);
|
||||||
foreach($scores as $player) {
|
foreach ($scores as $player) {
|
||||||
if (strpos($player, ':') !== false) {
|
if (strpos($player, ':') !== false) {
|
||||||
$tmp = explode(':', $player);
|
$tmp = explode(':', $player);
|
||||||
$this->rankings[$tmp[0]] = $tmp[1];
|
$this->rankings[$tmp[0]] = $tmp[1];
|
||||||
@ -101,6 +91,15 @@ class RankingManager implements CallbackListener {
|
|||||||
$this->maniaControl->callbackManager->triggerCallback(Callbacks::RANKINGSUPDATED, $this->getRankings());
|
$this->maniaControl->callbackManager->triggerCallback(Callbacks::RANKINGSUPDATED, $this->getRankings());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Rankings
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getRankings() {
|
||||||
|
return $this->rankings;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Current Leading Players (as Login Array)
|
* Get the Current Leading Players (as Login Array)
|
||||||
*
|
*
|
||||||
@ -109,7 +108,7 @@ class RankingManager implements CallbackListener {
|
|||||||
public function getLeaders() {
|
public function getLeaders() {
|
||||||
$leaders = array();
|
$leaders = array();
|
||||||
$prev = -1;
|
$prev = -1;
|
||||||
foreach($this->rankings as $score) {
|
foreach ($this->rankings as $score) {
|
||||||
if ($prev != -1 && $prev < $score) {
|
if ($prev != -1 && $prev < $score) {
|
||||||
return $leaders;
|
return $leaders;
|
||||||
}
|
}
|
||||||
|
@ -4,29 +4,28 @@ namespace ManiaControl\Server;
|
|||||||
|
|
||||||
use ManiaControl\Callbacks\CallbackListener;
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
use ManiaControl\Callbacks\CallbackManager;
|
use ManiaControl\Callbacks\CallbackManager;
|
||||||
|
use ManiaControl\CommandLineHelper;
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||||
use ManiaControl\CommandLineHelper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class providing Access to the connected ManiaPlanet Server
|
* Class providing Access to the connected ManiaPlanet Server
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class Server implements CallbackListener {
|
class Server implements CallbackListener {
|
||||||
/*
|
/*
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const TABLE_SERVERS = 'mc_servers';
|
const TABLE_SERVERS = 'mc_servers';
|
||||||
const CB_TEAM_MODE_CHANGED = 'ServerCallback.TeamModeChanged';
|
const CB_TEAM_MODE_CHANGED = 'ServerCallback.TeamModeChanged';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Public Properties
|
* Public Properties
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @var Config $config
|
* @var Config $config
|
||||||
*/
|
*/
|
||||||
public $config = null;
|
public $config = null;
|
||||||
@ -40,7 +39,7 @@ class Server implements CallbackListener {
|
|||||||
public $serverCommands = null;
|
public $serverCommands = null;
|
||||||
public $usageReporter = null;
|
public $usageReporter = null;
|
||||||
public $rankingManager = null;
|
public $rankingManager = null;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Private Properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
@ -49,28 +48,55 @@ class Server implements CallbackListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new Server
|
* Construct a new Server
|
||||||
*
|
*
|
||||||
* @param ManiaControl $maniaControl
|
* @param ManiaControl $maniaControl
|
||||||
*/
|
*/
|
||||||
public function __construct(ManiaControl $maniaControl) {
|
public function __construct(ManiaControl $maniaControl) {
|
||||||
$this->maniaControl = $maniaControl;
|
$this->maniaControl = $maniaControl;
|
||||||
$this->initTables();
|
$this->initTables();
|
||||||
|
|
||||||
$this->serverCommands = new ServerCommands($maniaControl);
|
$this->serverCommands = new ServerCommands($maniaControl);
|
||||||
$this->usageReporter = new UsageReporter($maniaControl);
|
$this->usageReporter = new UsageReporter($maniaControl);
|
||||||
$this->rankingManager = new RankingManager($maniaControl);
|
$this->rankingManager = new RankingManager($maniaControl);
|
||||||
|
|
||||||
// Register for callbacks
|
// Register for callbacks
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'onInit');
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'onInit');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize necessary Database Tables
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function initTables() {
|
||||||
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
|
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_SERVERS . "` (
|
||||||
|
`index` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`login` varchar(100) NOT NULL,
|
||||||
|
PRIMARY KEY (`index`),
|
||||||
|
UNIQUE KEY `login` (`login`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Servers' AUTO_INCREMENT=1;";
|
||||||
|
$statement = $mysqli->prepare($query);
|
||||||
|
if ($mysqli->error) {
|
||||||
|
trigger_error($mysqli->error, E_USER_ERROR);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$statement->execute();
|
||||||
|
if ($statement->error) {
|
||||||
|
trigger_error($statement->error, E_USER_ERROR);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$statement->close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the Server Configuration from the Config XML
|
* Load the Server Configuration from the Config XML
|
||||||
*/
|
*/
|
||||||
public function loadConfig() {
|
public function loadConfig() {
|
||||||
// Server id parameter
|
// Server id parameter
|
||||||
$serverId = CommandLineHelper::getParameter('-id');
|
$serverId = CommandLineHelper::getParameter('-id');
|
||||||
|
|
||||||
// Xml server tag with given id
|
// Xml server tag with given id
|
||||||
$serverTag = null;
|
$serverTag = null;
|
||||||
if ($serverId) {
|
if ($serverId) {
|
||||||
@ -81,8 +107,7 @@ class Server implements CallbackListener {
|
|||||||
if (!$serverTag) {
|
if (!$serverTag) {
|
||||||
trigger_error("No Server configured with the ID '{$serverId}'!", E_USER_ERROR);
|
trigger_error("No Server configured with the ID '{$serverId}'!", E_USER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$serverTags = $this->maniaControl->config->xpath('server');
|
$serverTags = $this->maniaControl->config->xpath('server');
|
||||||
if ($serverTags) {
|
if ($serverTags) {
|
||||||
$serverTag = $serverTags[0];
|
$serverTag = $serverTags[0];
|
||||||
@ -91,62 +116,92 @@ class Server implements CallbackListener {
|
|||||||
trigger_error('No Server configured!', E_USER_ERROR);
|
trigger_error('No Server configured!', E_USER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Host
|
// Host
|
||||||
$host = $serverTag->xpath('host');
|
$host = $serverTag->xpath('host');
|
||||||
if ($host) {
|
if ($host) {
|
||||||
$host = (string) $host[0];
|
$host = (string)$host[0];
|
||||||
}
|
}
|
||||||
if (!$host) {
|
if (!$host) {
|
||||||
trigger_error("Invalid server configuration (host).", E_USER_ERROR);
|
trigger_error("Invalid server configuration (host).", E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Port
|
// Port
|
||||||
$port = $serverTag->xpath('port');
|
$port = $serverTag->xpath('port');
|
||||||
if ($port) {
|
if ($port) {
|
||||||
$port = (string) $port[0];
|
$port = (string)$port[0];
|
||||||
}
|
}
|
||||||
if (!$port) {
|
if (!$port) {
|
||||||
trigger_error("Invalid server configuration (port).", E_USER_ERROR);
|
trigger_error("Invalid server configuration (port).", E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Login
|
// Login
|
||||||
$login = $serverTag->xpath('login');
|
$login = $serverTag->xpath('login');
|
||||||
if ($login) {
|
if ($login) {
|
||||||
$login = (string) $login[0];
|
$login = (string)$login[0];
|
||||||
}
|
}
|
||||||
if (!$login) {
|
if (!$login) {
|
||||||
trigger_error("Invalid server configuration (login).", E_USER_ERROR);
|
trigger_error("Invalid server configuration (login).", E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Password
|
// Password
|
||||||
$pass = $serverTag->xpath('pass');
|
$pass = $serverTag->xpath('pass');
|
||||||
if ($pass) {
|
if ($pass) {
|
||||||
$pass = (string) $pass[0];
|
$pass = (string)$pass[0];
|
||||||
}
|
}
|
||||||
if (!$pass) {
|
if (!$pass) {
|
||||||
trigger_error("Invalid server configuration (password).", E_USER_ERROR);
|
trigger_error("Invalid server configuration (password).", E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create config object
|
// Create config object
|
||||||
$this->config = new Config($serverId, $host, $port, $login, $pass);
|
$this->config = new Config($serverId, $host, $port, $login, $pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all Servers from the Database
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getAllServers() {
|
||||||
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
|
$query = "SELECT * FROM `" . self::TABLE_SERVERS . "`";
|
||||||
|
$result = $mysqli->query($query);
|
||||||
|
if (!$result) {
|
||||||
|
trigger_error($mysqli->error);
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$servers = array();
|
||||||
|
while ($row = $result->fetch_object()) {
|
||||||
|
array_push($servers, $row);
|
||||||
|
}
|
||||||
|
$result->close();
|
||||||
|
|
||||||
|
return $servers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle OnInit Callback
|
||||||
|
*/
|
||||||
|
public function onInit() {
|
||||||
|
$this->updateProperties();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refetch the Server Properties
|
* Refetch the Server Properties
|
||||||
*/
|
*/
|
||||||
private function updateProperties() {
|
private function updateProperties() {
|
||||||
// System info
|
// System info
|
||||||
$systemInfo = $this->maniaControl->client->getSystemInfo();
|
$systemInfo = $this->maniaControl->client->getSystemInfo();
|
||||||
$this->ip = $systemInfo->publishedIp;
|
$this->ip = $systemInfo->publishedIp;
|
||||||
$this->port = $systemInfo->port;
|
$this->port = $systemInfo->port;
|
||||||
$this->p2pPort = $systemInfo->p2PPort;
|
$this->p2pPort = $systemInfo->p2PPort;
|
||||||
$this->login = $systemInfo->serverLogin;
|
$this->login = $systemInfo->serverLogin;
|
||||||
$this->titleId = $systemInfo->titleId;
|
$this->titleId = $systemInfo->titleId;
|
||||||
|
|
||||||
// Database index
|
// Database index
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$query = "INSERT INTO `" . self::TABLE_SERVERS . "` (
|
$query = "INSERT INTO `" . self::TABLE_SERVERS . "` (
|
||||||
`login`
|
`login`
|
||||||
) VALUES (
|
) VALUES (
|
||||||
?
|
?
|
||||||
@ -168,72 +223,15 @@ class Server implements CallbackListener {
|
|||||||
$statement->close();
|
$statement->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize necessary Database Tables
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function initTables() {
|
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
|
||||||
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_SERVERS . "` (
|
|
||||||
`index` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`login` varchar(100) NOT NULL,
|
|
||||||
PRIMARY KEY (`index`),
|
|
||||||
UNIQUE KEY `login` (`login`)
|
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Servers' AUTO_INCREMENT=1;";
|
|
||||||
$statement = $mysqli->prepare($query);
|
|
||||||
if ($mysqli->error) {
|
|
||||||
trigger_error($mysqli->error, E_USER_ERROR);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$statement->execute();
|
|
||||||
if ($statement->error) {
|
|
||||||
trigger_error($statement->error, E_USER_ERROR);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$statement->close();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets all Servers from the Database
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getAllServers() {
|
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
|
||||||
$query = "SELECT * FROM `" . self::TABLE_SERVERS . "`";
|
|
||||||
$result = $mysqli->query($query);
|
|
||||||
if (!$result) {
|
|
||||||
trigger_error($mysqli->error);
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$servers = array();
|
|
||||||
while ($row = $result->fetch_object()) {
|
|
||||||
array_push($servers, $row);
|
|
||||||
}
|
|
||||||
$result->close();
|
|
||||||
|
|
||||||
return $servers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle OnInit Callback
|
|
||||||
*/
|
|
||||||
public function onInit() {
|
|
||||||
$this->updateProperties();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set if the Server Runs a Team-Mode or not
|
* Set if the Server Runs a Team-Mode or not
|
||||||
*
|
*
|
||||||
* @param bool $teamMode
|
* @param bool $teamMode
|
||||||
*/
|
*/
|
||||||
public function setTeamMode($teamMode = true) {
|
public function setTeamMode($teamMode = true) {
|
||||||
$oldStatus = $this->teamMode;
|
$oldStatus = $this->teamMode;
|
||||||
$this->teamMode = $teamMode;
|
$this->teamMode = $teamMode;
|
||||||
|
|
||||||
// Trigger callback
|
// Trigger callback
|
||||||
if ($oldStatus != $this->teamMode) {
|
if ($oldStatus != $this->teamMode) {
|
||||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_TEAM_MODE_CHANGED, $teamMode);
|
$this->maniaControl->callbackManager->triggerCallback(self::CB_TEAM_MODE_CHANGED, $teamMode);
|
||||||
@ -242,28 +240,16 @@ class Server implements CallbackListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the Server Runs a TeamMode
|
* Check if the Server Runs a TeamMode
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isTeamMode() {
|
public function isTeamMode() {
|
||||||
return $this->teamMode;
|
return $this->teamMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch Game Data Directory
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getDataDirectory() {
|
|
||||||
if ($this->dataDirectory == '') {
|
|
||||||
$this->dataDirectory = $this->maniaControl->client->gameDataDirectory();
|
|
||||||
}
|
|
||||||
return $this->dataDirectory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch Maps Directory
|
* Fetch Maps Directory
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getMapsDirectory() {
|
public function getMapsDirectory() {
|
||||||
@ -274,9 +260,87 @@ class Server implements CallbackListener {
|
|||||||
return "{$dataDirectory}Maps/";
|
return "{$dataDirectory}Maps/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch Game Data Directory
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDataDirectory() {
|
||||||
|
if ($this->dataDirectory == '') {
|
||||||
|
$this->dataDirectory = $this->maniaControl->client->gameDataDirectory();
|
||||||
|
}
|
||||||
|
return $this->dataDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Server Player Info
|
||||||
|
*
|
||||||
|
* @return \Maniaplanet\DedicatedServer\Structures\Player
|
||||||
|
*/
|
||||||
|
public function getInfo() {
|
||||||
|
return $this->maniaControl->client->getMainServerPlayerInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve Validation Replay for the given Player
|
||||||
|
*
|
||||||
|
* @param $login
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getValidationReplay($login) {
|
||||||
|
try {
|
||||||
|
$replay = $this->maniaControl->client->getValidationReplay($login);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// TODO temp added 19.04.2014
|
||||||
|
$this->maniaControl->errorHandler->triggerDebugNotice("Exception line 330 Server.php" . $e->getMessage());
|
||||||
|
|
||||||
|
trigger_error("Couldn't get validation replay of '{$login}'. " . $e->getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return $replay;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve Ghost Replay for the given Player
|
||||||
|
*
|
||||||
|
* @param $login
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getGhostReplay($login) {
|
||||||
|
$dataDir = $this->getDataDirectory();
|
||||||
|
if (!$this->checkAccess($dataDir)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build file name
|
||||||
|
$map = $this->maniaControl->mapManager->getCurrentMap();
|
||||||
|
$gameMode = $this->getGameMode();
|
||||||
|
$time = time();
|
||||||
|
$fileName = "GhostReplays/Ghost.{$login}.{$gameMode}.{$time}.{$map->uid}.Replay.Gbx";
|
||||||
|
|
||||||
|
// Save ghost replay
|
||||||
|
try {
|
||||||
|
$this->maniaControl->client->saveBestGhostsReplay($login, $fileName);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// TODO temp added 19.04.2014
|
||||||
|
$this->maniaControl->errorHandler->triggerDebugNotice("Exception line 360 Server.php" . $e->getMessage());
|
||||||
|
|
||||||
|
trigger_error("Couldn't save ghost replay. " . $e->getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load replay file
|
||||||
|
$ghostReplay = file_get_contents("{$dataDir}Replays/{$fileName}");
|
||||||
|
if (!$ghostReplay) {
|
||||||
|
trigger_error("Couldn't retrieve saved ghost replay.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return $ghostReplay;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if ManiaControl has Access to the given Directory
|
* Checks if ManiaControl has Access to the given Directory
|
||||||
*
|
*
|
||||||
* @param string $directory
|
* @param string $directory
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -287,27 +351,17 @@ class Server implements CallbackListener {
|
|||||||
return (is_dir($directory) && is_writable($directory));
|
return (is_dir($directory) && is_writable($directory));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Server Player Info
|
|
||||||
*
|
|
||||||
* @return \Maniaplanet\DedicatedServer\Structures\Player
|
|
||||||
*/
|
|
||||||
public function getInfo() {
|
|
||||||
return $this->maniaControl->client->getMainServerPlayerInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch current Game Mode
|
* Fetch current Game Mode
|
||||||
*
|
*
|
||||||
* @param bool $stringValue
|
* @param bool $stringValue
|
||||||
* @param int $parseValue
|
* @param int $parseValue
|
||||||
* @return int | string
|
* @return int | string
|
||||||
*/
|
*/
|
||||||
public function getGameMode($stringValue = false, $parseValue = null) {
|
public function getGameMode($stringValue = false, $parseValue = null) {
|
||||||
if (is_int($parseValue)) {
|
if (is_int($parseValue)) {
|
||||||
$gameMode = $parseValue;
|
$gameMode = $parseValue;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$gameMode = $this->maniaControl->client->getGameMode();
|
$gameMode = $this->maniaControl->client->getGameMode();
|
||||||
}
|
}
|
||||||
if ($stringValue) {
|
if ($stringValue) {
|
||||||
@ -333,68 +387,9 @@ class Server implements CallbackListener {
|
|||||||
return $gameMode;
|
return $gameMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve Validation Replay for the given Player
|
|
||||||
*
|
|
||||||
* @param $login
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getValidationReplay($login) {
|
|
||||||
try {
|
|
||||||
$replay = $this->maniaControl->client->getValidationReplay($login);
|
|
||||||
}
|
|
||||||
catch (Exception $e) {
|
|
||||||
// TODO temp added 19.04.2014
|
|
||||||
$this->maniaControl->errorHandler->triggerDebugNotice("Exception line 330 Server.php" . $e->getMessage());
|
|
||||||
|
|
||||||
trigger_error("Couldn't get validation replay of '{$login}'. " . $e->getMessage());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return $replay;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve Ghost Replay for the given Player
|
|
||||||
*
|
|
||||||
* @param $login
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getGhostReplay($login) {
|
|
||||||
$dataDir = $this->getDataDirectory();
|
|
||||||
if (!$this->checkAccess($dataDir)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build file name
|
|
||||||
$map = $this->maniaControl->mapManager->getCurrentMap();
|
|
||||||
$gameMode = $this->getGameMode();
|
|
||||||
$time = time();
|
|
||||||
$fileName = "GhostReplays/Ghost.{$login}.{$gameMode}.{$time}.{$map->uid}.Replay.Gbx";
|
|
||||||
|
|
||||||
// Save ghost replay
|
|
||||||
try {
|
|
||||||
$this->maniaControl->client->saveBestGhostsReplay($login, $fileName);
|
|
||||||
}
|
|
||||||
catch (Exception $e) {
|
|
||||||
// TODO temp added 19.04.2014
|
|
||||||
$this->maniaControl->errorHandler->triggerDebugNotice("Exception line 360 Server.php" . $e->getMessage());
|
|
||||||
|
|
||||||
trigger_error("Couldn't save ghost replay. " . $e->getMessage());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load replay file
|
|
||||||
$ghostReplay = file_get_contents("{$dataDir}Replays/{$fileName}");
|
|
||||||
if (!$ghostReplay) {
|
|
||||||
trigger_error("Couldn't retrieve saved ghost replay.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return $ghostReplay;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wait for the Server to have the given Status
|
* Wait for the Server to have the given Status
|
||||||
*
|
*
|
||||||
* @param int $statusCode
|
* @param int $statusCode
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -405,9 +400,9 @@ class Server implements CallbackListener {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Server not yet in given status - Wait for it...
|
// Server not yet in given status - Wait for it...
|
||||||
$waitBegin = time();
|
$waitBegin = time();
|
||||||
$maxWaitTime = 50;
|
$maxWaitTime = 50;
|
||||||
$lastStatus = $response->name;
|
$lastStatus = $response->name;
|
||||||
$this->maniaControl->log("Waiting for server to reach status {$statusCode}...");
|
$this->maniaControl->log("Waiting for server to reach status {$statusCode}...");
|
||||||
$this->maniaControl->log("Current Status: {$lastStatus}");
|
$this->maniaControl->log("Current Status: {$lastStatus}");
|
||||||
while ($response->code !== 4) {
|
while ($response->code !== 4) {
|
||||||
|
@ -18,8 +18,8 @@ use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
|
|||||||
/**
|
/**
|
||||||
* Class offering various Commands related to the Dedicated Server
|
* Class offering various Commands related to the Dedicated Server
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class ServerCommands implements CallbackListener, CommandListener, ManialinkPageAnswerListener, TimerListener {
|
class ServerCommands implements CallbackListener, CommandListener, ManialinkPageAnswerListener, TimerListener {
|
||||||
@ -106,11 +106,11 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
|
|||||||
//Check if Pause exists in current GameMode
|
//Check if Pause exists in current GameMode
|
||||||
try {
|
try {
|
||||||
$scriptInfos = $this->maniaControl->client->getModeScriptInfo();
|
$scriptInfos = $this->maniaControl->client->getModeScriptInfo();
|
||||||
} catch(NotInScriptModeException $e) {
|
} catch (NotInScriptModeException $e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$pauseExists = false;
|
$pauseExists = false;
|
||||||
foreach($scriptInfos->commandDescs as $param) {
|
foreach ($scriptInfos->commandDescs as $param) {
|
||||||
if ($param->name == "Command_ForceWarmUp") {
|
if ($param->name == "Command_ForceWarmUp") {
|
||||||
$pauseExists = true;
|
$pauseExists = true;
|
||||||
break;
|
break;
|
||||||
@ -161,7 +161,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->triggerModeScriptEvent('WarmUp_Extend', '10');
|
$this->maniaControl->client->triggerModeScriptEvent('WarmUp_Extend', '10');
|
||||||
} catch(NotInScriptModeException $e) {
|
} catch (NotInScriptModeException $e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,7 +182,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->triggerModeScriptEvent('WarmUp_Stop', '');
|
$this->maniaControl->client->triggerModeScriptEvent('WarmUp_Stop', '');
|
||||||
} catch(NotInScriptModeException $e) {
|
} catch (NotInScriptModeException $e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,7 +192,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
|
|||||||
/**
|
/**
|
||||||
* Pause the current game
|
* Pause the current game
|
||||||
*
|
*
|
||||||
* @param array $callback
|
* @param array $callback
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
public function setPause(array $callback, Player $player) {
|
public function setPause(array $callback, Player $player) {
|
||||||
@ -201,8 +201,8 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->sendModeScriptCommands(array('Command_ForceWarmUp' => True));
|
$this->maniaControl->client->sendModeScriptCommands(array('Command_ForceWarmUp' => true));
|
||||||
} catch(NotInScriptModeException $e) {
|
} catch (NotInScriptModeException $e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,6 +232,16 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform server shutdown
|
||||||
|
*
|
||||||
|
* @param string $login
|
||||||
|
*/
|
||||||
|
private function shutdownServer($login = '#') {
|
||||||
|
$this->maniaControl->client->stopServer();
|
||||||
|
$this->maniaControl->quit("Server shutdown requested by '{$login}'");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle //systeminfo command
|
* Handle //systeminfo command
|
||||||
*
|
*
|
||||||
@ -411,14 +421,4 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
|
|||||||
$this->maniaControl->client->setMaxSpectators($amount);
|
$this->maniaControl->client->setMaxSpectators($amount);
|
||||||
$this->maniaControl->chat->sendSuccess("Changed max spectators to: {$amount}", $player->login);
|
$this->maniaControl->chat->sendSuccess("Changed max spectators to: {$amount}", $player->login);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform server shutdown
|
|
||||||
*
|
|
||||||
* @param string $login
|
|
||||||
*/
|
|
||||||
private function shutdownServer($login = '#') {
|
|
||||||
$this->maniaControl->client->stopServer();
|
|
||||||
$this->maniaControl->quit("Server shutdown requested by '{$login}'");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,9 @@ use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
|||||||
/**
|
/**
|
||||||
* Class reporting ManiaControl Usage for the Server
|
* Class reporting ManiaControl Usage for the Server
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class UsageReporter implements TimerListener {
|
class UsageReporter implements TimerListener {
|
||||||
/*
|
/*
|
||||||
@ -58,9 +58,9 @@ class UsageReporter implements TimerListener {
|
|||||||
$properties['TitleId'] = $this->maniaControl->server->titleId;
|
$properties['TitleId'] = $this->maniaControl->server->titleId;
|
||||||
$properties['ServerName'] = Formatter::stripDirtyCodes($this->maniaControl->client->getServerName());
|
$properties['ServerName'] = Formatter::stripDirtyCodes($this->maniaControl->client->getServerName());
|
||||||
|
|
||||||
$properties['PlayerCount'] = $this->maniaControl->playerManager->getPlayerCount();
|
$properties['PlayerCount'] = $this->maniaControl->playerManager->getPlayerCount();
|
||||||
$properties['MemoryUsage'] = memory_get_usage();
|
$properties['MemoryUsage'] = memory_get_usage();
|
||||||
$properties['MemoryPeakUsage'] = memory_get_peak_usage();
|
$properties['MemoryPeakUsage'] = memory_get_peak_usage();
|
||||||
|
|
||||||
$maxPlayers = $this->maniaControl->client->getMaxPlayers();
|
$maxPlayers = $this->maniaControl->client->getMaxPlayers();
|
||||||
$properties['MaxPlayers'] = $maxPlayers["CurrentValue"];
|
$properties['MaxPlayers'] = $maxPlayers["CurrentValue"];
|
||||||
@ -68,7 +68,7 @@ class UsageReporter implements TimerListener {
|
|||||||
try {
|
try {
|
||||||
$scriptName = $this->maniaControl->client->getScriptName();
|
$scriptName = $this->maniaControl->client->getScriptName();
|
||||||
$properties['ScriptName'] = $scriptName["CurrentValue"];
|
$properties['ScriptName'] = $scriptName["CurrentValue"];
|
||||||
} catch(Exception $e) {
|
} catch (Exception $e) {
|
||||||
if ($e->getMessage() == 'Not in script mode.') {
|
if ($e->getMessage() == 'Not in script mode.') {
|
||||||
$properties['ScriptName'] = '';
|
$properties['ScriptName'] = '';
|
||||||
} else {
|
} else {
|
||||||
@ -79,7 +79,7 @@ class UsageReporter implements TimerListener {
|
|||||||
$activePlugins = array();
|
$activePlugins = array();
|
||||||
|
|
||||||
if (is_array($this->maniaControl->pluginManager->getActivePlugins())) {
|
if (is_array($this->maniaControl->pluginManager->getActivePlugins())) {
|
||||||
foreach($this->maniaControl->pluginManager->getActivePlugins() as $plugin) {
|
foreach ($this->maniaControl->pluginManager->getActivePlugins() as $plugin) {
|
||||||
/** @var Plugin $plugin */
|
/** @var Plugin $plugin */
|
||||||
if (!is_null($plugin::getId()) && is_numeric($plugin::getId())) {
|
if (!is_null($plugin::getId()) && is_numeric($plugin::getId())) {
|
||||||
$activePlugins[] = $plugin::getId();
|
$activePlugins[] = $plugin::getId();
|
||||||
@ -93,7 +93,7 @@ class UsageReporter implements TimerListener {
|
|||||||
$info = base64_encode($json);
|
$info = base64_encode($json);
|
||||||
|
|
||||||
$self = $this;
|
$self = $this;
|
||||||
$this->maniaControl->fileReader->loadFile(ManiaControl::URL_WEBSERVICE . "/usagereport?info=" . urlencode($info), function ($response, $error) use(&$self){
|
$this->maniaControl->fileReader->loadFile(ManiaControl::URL_WEBSERVICE . "/usagereport?info=" . urlencode($info), function ($response, $error) use (&$self) {
|
||||||
$response = json_decode($response);
|
$response = json_decode($response);
|
||||||
if ($error || !$response) {
|
if ($error || !$response) {
|
||||||
$self->maniaControl->log("Error while Sending data: " . $error);
|
$self->maniaControl->log("Error while Sending data: " . $error);
|
||||||
|
@ -9,23 +9,23 @@ use ManiaControl\Plugins\PluginManager;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Class managing Settings and Configurations
|
* Class managing Settings and Configurations
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class SettingManager implements CallbackListener {
|
class SettingManager implements CallbackListener {
|
||||||
/*
|
/*
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const TABLE_SETTINGS = 'mc_settings';
|
const TABLE_SETTINGS = 'mc_settings';
|
||||||
const TYPE_STRING = 'string';
|
const TYPE_STRING = 'string';
|
||||||
const TYPE_INT = 'int';
|
const TYPE_INT = 'int';
|
||||||
const TYPE_REAL = 'real';
|
const TYPE_REAL = 'real';
|
||||||
const TYPE_BOOL = 'bool';
|
const TYPE_BOOL = 'bool';
|
||||||
const TYPE_ARRAY = 'array';
|
const TYPE_ARRAY = 'array';
|
||||||
const CB_SETTINGS_CHANGED = 'SettingManager.SettingsChanged';
|
const CB_SETTINGS_CHANGED = 'SettingManager.SettingsChanged';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Private Properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
@ -35,32 +35,25 @@ class SettingManager implements CallbackListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new Setting Manager
|
* Construct a new Setting Manager
|
||||||
*
|
*
|
||||||
* @param ManiaControl $maniaControl
|
* @param ManiaControl $maniaControl
|
||||||
*/
|
*/
|
||||||
public function __construct(ManiaControl $maniaControl) {
|
public function __construct(ManiaControl $maniaControl) {
|
||||||
$this->maniaControl = $maniaControl;
|
$this->maniaControl = $maniaControl;
|
||||||
$this->initTables();
|
$this->initTables();
|
||||||
|
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_AFTERINIT, $this, 'handleAfterInit');
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_AFTERINIT, $this, 'handleAfterInit');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle After Init Callback
|
|
||||||
*/
|
|
||||||
public function handleAfterInit() {
|
|
||||||
$this->deleteUnusedSettings();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize necessary Database Tables
|
* Initialize necessary Database Tables
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function initTables() {
|
private function initTables() {
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$defaultType = "'" . self::TYPE_STRING . "'";
|
$defaultType = "'" . self::TYPE_STRING . "'";
|
||||||
$typeSet = $defaultType . ",'" . self::TYPE_INT . "','" . self::TYPE_REAL . "','" . self::TYPE_BOOL . "','" . self::TYPE_ARRAY . "'";
|
$typeSet = $defaultType . ",'" . self::TYPE_INT . "','" . self::TYPE_REAL . "','" . self::TYPE_BOOL . "','" . self::TYPE_ARRAY . "'";
|
||||||
$settingTableQuery = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_SETTINGS . "` (
|
$settingTableQuery = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_SETTINGS . "` (
|
||||||
`index` int(11) NOT NULL AUTO_INCREMENT,
|
`index` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`class` varchar(100) NOT NULL,
|
`class` varchar(100) NOT NULL,
|
||||||
@ -72,121 +65,63 @@ class SettingManager implements CallbackListener {
|
|||||||
PRIMARY KEY (`index`),
|
PRIMARY KEY (`index`),
|
||||||
UNIQUE KEY `settingId` (`class`,`setting`)
|
UNIQUE KEY `settingId` (`class`,`setting`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Settings and Configurations' AUTO_INCREMENT=1;";
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Settings and Configurations' AUTO_INCREMENT=1;";
|
||||||
$result = $mysqli->query($settingTableQuery);
|
$result = $mysqli->query($settingTableQuery);
|
||||||
if ($mysqli->error) {
|
if ($mysqli->error) {
|
||||||
trigger_error($mysqli->error, E_USER_ERROR);
|
trigger_error($mysqli->error, E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Class Name of a Parameter
|
* Handle After Init Callback
|
||||||
*
|
|
||||||
* @param mixed $param
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
private function getClassName($param) {
|
public function handleAfterInit() {
|
||||||
if (is_object($param)) {
|
$this->deleteUnusedSettings();
|
||||||
return get_class($param);
|
|
||||||
}
|
|
||||||
if (is_string($param)) {
|
|
||||||
return $param;
|
|
||||||
}
|
|
||||||
trigger_error('Invalid class param. ' . $param);
|
|
||||||
return (string) $param;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Type of a Parameter
|
* Delete all unused Settings that haven't been initialized during the current Startup
|
||||||
*
|
*
|
||||||
* @param mixed $param
|
* @return bool
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
private function getType($param) {
|
private function deleteUnusedSettings() {
|
||||||
if (is_int($param)) {
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
return self::TYPE_INT;
|
$settingQuery = "DELETE FROM `" . self::TABLE_SETTINGS . "`
|
||||||
|
WHERE `changed` < NOW() - INTERVAL 1 HOUR;";
|
||||||
|
$settingStatement = $mysqli->prepare($settingQuery);
|
||||||
|
if ($mysqli->error) {
|
||||||
|
trigger_error($mysqli->error);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (is_real($param)) {
|
$success = $settingStatement->execute();
|
||||||
return self::TYPE_REAL;
|
if ($settingStatement->error) {
|
||||||
|
trigger_error($settingStatement->error);
|
||||||
|
$settingStatement->close();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (is_bool($param)) {
|
$settingStatement->close();
|
||||||
return self::TYPE_BOOL;
|
$this->storedSettings = array();
|
||||||
}
|
return $success;
|
||||||
if (is_string($param)) {
|
|
||||||
return self::TYPE_STRING;
|
|
||||||
}
|
|
||||||
if (is_array($param)) {
|
|
||||||
return self::TYPE_ARRAY;
|
|
||||||
}
|
|
||||||
trigger_error('Unsupported setting type. ' . print_r($param, true));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cast a Setting to the given Type
|
|
||||||
*
|
|
||||||
* @param string $type
|
|
||||||
* @param mixed $value
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
private function castSetting($type, $value) {
|
|
||||||
if ($type === self::TYPE_INT) {
|
|
||||||
return (int) $value;
|
|
||||||
}
|
|
||||||
if ($type === self::TYPE_REAL) {
|
|
||||||
return (float) $value;
|
|
||||||
}
|
|
||||||
if ($type === self::TYPE_BOOL) {
|
|
||||||
return (bool) $value;
|
|
||||||
}
|
|
||||||
if ($type === self::TYPE_STRING) {
|
|
||||||
return (string) $value;
|
|
||||||
}
|
|
||||||
if ($type === self::TYPE_ARRAY) {
|
|
||||||
return explode($this->arrayDelimiter, $value);
|
|
||||||
}
|
|
||||||
trigger_error('Unsupported setting type. ' . print_r($type, true));
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Format a Setting for saving it to the Database
|
|
||||||
*
|
|
||||||
* @param mixed $value
|
|
||||||
* @param string $type
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
private function formatSetting($value, $type = null) {
|
|
||||||
if ($type === null) {
|
|
||||||
$type = $this->getType($value);
|
|
||||||
}
|
|
||||||
if ($type === self::TYPE_ARRAY) {
|
|
||||||
return implode($this->arrayDelimiter, $value);
|
|
||||||
}
|
|
||||||
if ($type === self::TYPE_BOOL) {
|
|
||||||
return ($value ? 1 : 0);
|
|
||||||
}
|
|
||||||
return $value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize a Setting for the given Object
|
* Initialize a Setting for the given Object
|
||||||
*
|
*
|
||||||
* @param mixed $object
|
* @param mixed $object
|
||||||
* @param string $settingName
|
* @param string $settingName
|
||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function initSetting($object, $settingName, $default) {
|
public function initSetting($object, $settingName, $default) {
|
||||||
if (is_null($default) || is_object($default)) {
|
if (is_null($default) || is_object($default)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$className = $this->getClassName($object);
|
$className = $this->getClassName($object);
|
||||||
$type = $this->getType($default);
|
$type = $this->getType($default);
|
||||||
$default = $this->formatSetting($default, $type);
|
$default = $this->formatSetting($default, $type);
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$settingQuery = "INSERT INTO `" . self::TABLE_SETTINGS . "` (
|
$settingQuery = "INSERT INTO `" . self::TABLE_SETTINGS . "` (
|
||||||
`class`,
|
`class`,
|
||||||
`setting`,
|
`setting`,
|
||||||
`type`,
|
`type`,
|
||||||
@ -217,18 +152,81 @@ class SettingManager implements CallbackListener {
|
|||||||
return $success;
|
return $success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Class Name of a Parameter
|
||||||
|
*
|
||||||
|
* @param mixed $param
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function getClassName($param) {
|
||||||
|
if (is_object($param)) {
|
||||||
|
return get_class($param);
|
||||||
|
}
|
||||||
|
if (is_string($param)) {
|
||||||
|
return $param;
|
||||||
|
}
|
||||||
|
trigger_error('Invalid class param. ' . $param);
|
||||||
|
return (string)$param;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Type of a Parameter
|
||||||
|
*
|
||||||
|
* @param mixed $param
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function getType($param) {
|
||||||
|
if (is_int($param)) {
|
||||||
|
return self::TYPE_INT;
|
||||||
|
}
|
||||||
|
if (is_real($param)) {
|
||||||
|
return self::TYPE_REAL;
|
||||||
|
}
|
||||||
|
if (is_bool($param)) {
|
||||||
|
return self::TYPE_BOOL;
|
||||||
|
}
|
||||||
|
if (is_string($param)) {
|
||||||
|
return self::TYPE_STRING;
|
||||||
|
}
|
||||||
|
if (is_array($param)) {
|
||||||
|
return self::TYPE_ARRAY;
|
||||||
|
}
|
||||||
|
trigger_error('Unsupported setting type. ' . print_r($param, true));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format a Setting for saving it to the Database
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @param string $type
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
private function formatSetting($value, $type = null) {
|
||||||
|
if ($type === null) {
|
||||||
|
$type = $this->getType($value);
|
||||||
|
}
|
||||||
|
if ($type === self::TYPE_ARRAY) {
|
||||||
|
return implode($this->arrayDelimiter, $value);
|
||||||
|
}
|
||||||
|
if ($type === self::TYPE_BOOL) {
|
||||||
|
return ($value ? 1 : 0);
|
||||||
|
}
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a Setting by its Index
|
* Get a Setting by its Index
|
||||||
*
|
*
|
||||||
* @param int $settingIndex
|
* @param int $settingIndex
|
||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function getSettingByIndex($settingIndex, $default = false) {
|
public function getSettingByIndex($settingIndex, $default = false) {
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$settingQuery = "SELECT * FROM `" . self::TABLE_SETTINGS . "`
|
$settingQuery = "SELECT * FROM `" . self::TABLE_SETTINGS . "`
|
||||||
WHERE `index` = {$settingIndex};";
|
WHERE `index` = {$settingIndex};";
|
||||||
$result = $mysqli->query($settingQuery);
|
$result = $mysqli->query($settingQuery);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
trigger_error($mysqli->error);
|
trigger_error($mysqli->error);
|
||||||
return null;
|
return null;
|
||||||
@ -244,22 +242,22 @@ class SettingManager implements CallbackListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Setting by Name for the given Object
|
* Get Setting by Name for the given Object
|
||||||
*
|
*
|
||||||
* @param mixed $object
|
* @param mixed $object
|
||||||
* @param string $settingName
|
* @param string $settingName
|
||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function getSetting($object, $settingName, $default = null) {
|
public function getSetting($object, $settingName, $default = null) {
|
||||||
$className = $this->getClassName($object);
|
$className = $this->getClassName($object);
|
||||||
|
|
||||||
// Check if setting is already in the ram
|
// Check if setting is already in the ram
|
||||||
if (isset($this->storedSettings[$className . $settingName])) {
|
if (isset($this->storedSettings[$className . $settingName])) {
|
||||||
return $this->storedSettings[$className . $settingName];
|
return $this->storedSettings[$className . $settingName];
|
||||||
}
|
}
|
||||||
|
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$settingQuery = "SELECT `type`, `value` FROM `" . self::TABLE_SETTINGS . "`
|
$settingQuery = "SELECT `type`, `value` FROM `" . self::TABLE_SETTINGS . "`
|
||||||
WHERE `class` = ?
|
WHERE `class` = ?
|
||||||
AND `setting` = ?;";
|
AND `setting` = ?;";
|
||||||
$settingStatement = $mysqli->prepare($settingQuery);
|
$settingStatement = $mysqli->prepare($settingQuery);
|
||||||
@ -283,7 +281,7 @@ class SettingManager implements CallbackListener {
|
|||||||
$settingStatement->free_result();
|
$settingStatement->free_result();
|
||||||
$settingStatement->close();
|
$settingStatement->close();
|
||||||
$setting = $this->castSetting($type, $value);
|
$setting = $this->castSetting($type, $value);
|
||||||
|
|
||||||
// Store setting in the ram
|
// Store setting in the ram
|
||||||
$this->storedSettings[$className . $settingName] = $setting;
|
$this->storedSettings[$className . $settingName] = $setting;
|
||||||
return $setting;
|
return $setting;
|
||||||
@ -291,17 +289,17 @@ class SettingManager implements CallbackListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a Setting for the given Object
|
* Set a Setting for the given Object
|
||||||
*
|
*
|
||||||
* @param mixed $object
|
* @param mixed $object
|
||||||
* @param string $settingName
|
* @param string $settingName
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function setSetting($object, $settingName, $value) {
|
public function setSetting($object, $settingName, $value) {
|
||||||
$className = $this->getClassName($object);
|
$className = $this->getClassName($object);
|
||||||
|
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$settingQuery = "UPDATE `" . self::TABLE_SETTINGS . "`
|
$settingQuery = "UPDATE `" . self::TABLE_SETTINGS . "`
|
||||||
SET `value` = ?
|
SET `value` = ?
|
||||||
WHERE `class` = ?
|
WHERE `class` = ?
|
||||||
AND `setting` = ?;";
|
AND `setting` = ?;";
|
||||||
@ -319,25 +317,52 @@ class SettingManager implements CallbackListener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$settingStatement->close();
|
$settingStatement->close();
|
||||||
|
|
||||||
$this->storedSettings[$className . $settingName] = $value;
|
$this->storedSettings[$className . $settingName] = $value;
|
||||||
|
|
||||||
// Trigger settings changed Callback
|
// Trigger settings changed Callback
|
||||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_SETTINGS_CHANGED, $className, $settingName, $value);
|
$this->maniaControl->callbackManager->triggerCallback(self::CB_SETTINGS_CHANGED, $className, $settingName, $value);
|
||||||
return $success;
|
return $success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cast a Setting to the given Type
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param mixed $value
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
private function castSetting($type, $value) {
|
||||||
|
if ($type === self::TYPE_INT) {
|
||||||
|
return (int)$value;
|
||||||
|
}
|
||||||
|
if ($type === self::TYPE_REAL) {
|
||||||
|
return (float)$value;
|
||||||
|
}
|
||||||
|
if ($type === self::TYPE_BOOL) {
|
||||||
|
return (bool)$value;
|
||||||
|
}
|
||||||
|
if ($type === self::TYPE_STRING) {
|
||||||
|
return (string)$value;
|
||||||
|
}
|
||||||
|
if ($type === self::TYPE_ARRAY) {
|
||||||
|
return explode($this->arrayDelimiter, $value);
|
||||||
|
}
|
||||||
|
trigger_error('Unsupported setting type. ' . print_r($type, true));
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset a Setting to its default Value
|
* Reset a Setting to its default Value
|
||||||
*
|
*
|
||||||
* @param mixed $object
|
* @param mixed $object
|
||||||
* @param string $settingName
|
* @param string $settingName
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function resetSetting($object, $settingName) {
|
public function resetSetting($object, $settingName) {
|
||||||
$className = $this->getClassName($object);
|
$className = $this->getClassName($object);
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$settingQuery = "UPDATE `" . self::TABLE_SETTINGS . "`
|
$settingQuery = "UPDATE `" . self::TABLE_SETTINGS . "`
|
||||||
SET `value` = `default`
|
SET `value` = `default`
|
||||||
WHERE `class` = ?
|
WHERE `class` = ?
|
||||||
AND `setting` = ?;";
|
AND `setting` = ?;";
|
||||||
@ -362,15 +387,15 @@ class SettingManager implements CallbackListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a Setting
|
* Delete a Setting
|
||||||
*
|
*
|
||||||
* @param mixed $object
|
* @param mixed $object
|
||||||
* @param string $settingName
|
* @param string $settingName
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function deleteSetting($object, $settingName) {
|
public function deleteSetting($object, $settingName) {
|
||||||
$className = $this->getClassName($object);
|
$className = $this->getClassName($object);
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$settingQuery = "DELETE FROM `" . self::TABLE_SETTINGS . "`
|
$settingQuery = "DELETE FROM `" . self::TABLE_SETTINGS . "`
|
||||||
WHERE `class` = ?
|
WHERE `class` = ?
|
||||||
AND `setting` = ?;";
|
AND `setting` = ?;";
|
||||||
$settingStatement = $mysqli->prepare($settingQuery);
|
$settingStatement = $mysqli->prepare($settingQuery);
|
||||||
@ -394,16 +419,16 @@ class SettingManager implements CallbackListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all Settings for the given Class
|
* Get all Settings for the given Class
|
||||||
*
|
*
|
||||||
* @param mixed $object
|
* @param mixed $object
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getSettingsByClass($object) {
|
public function getSettingsByClass($object) {
|
||||||
$className = $this->getClassName($object);
|
$className = $this->getClassName($object);
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$query = "SELECT * FROM `" . self::TABLE_SETTINGS . "` WHERE `class` = '" . $mysqli->escape_string($className) . "'
|
$query = "SELECT * FROM `" . self::TABLE_SETTINGS . "` WHERE `class` = '" . $mysqli->escape_string($className) . "'
|
||||||
ORDER BY `setting` ASC;";
|
ORDER BY `setting` ASC;";
|
||||||
$result = $mysqli->query($query);
|
$result = $mysqli->query($query);
|
||||||
if ($mysqli->error) {
|
if ($mysqli->error) {
|
||||||
trigger_error($mysqli->error);
|
trigger_error($mysqli->error);
|
||||||
return null;
|
return null;
|
||||||
@ -418,12 +443,12 @@ class SettingManager implements CallbackListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all settings
|
* Get all settings
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getSettings() {
|
public function getSettings() {
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$query = "SELECT * FROM `" . self::TABLE_SETTINGS . "`
|
$query = "SELECT * FROM `" . self::TABLE_SETTINGS . "`
|
||||||
ORDER BY `class` ASC, `setting` ASC;";
|
ORDER BY `class` ASC, `setting` ASC;";
|
||||||
$result = $mysqli->query($query);
|
$result = $mysqli->query($query);
|
||||||
if ($mysqli->error) {
|
if ($mysqli->error) {
|
||||||
@ -446,7 +471,7 @@ class SettingManager implements CallbackListener {
|
|||||||
*/
|
*/
|
||||||
public function getSettingClasses($hidePluginClasses = false) {
|
public function getSettingClasses($hidePluginClasses = false) {
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$query = "SELECT DISTINCT `class` FROM `" . self::TABLE_SETTINGS . "`
|
$query = "SELECT DISTINCT `class` FROM `" . self::TABLE_SETTINGS . "`
|
||||||
ORDER BY `class` ASC;";
|
ORDER BY `class` ASC;";
|
||||||
$result = $mysqli->query($query);
|
$result = $mysqli->query($query);
|
||||||
if ($mysqli->error) {
|
if ($mysqli->error) {
|
||||||
@ -462,29 +487,4 @@ class SettingManager implements CallbackListener {
|
|||||||
$result->free();
|
$result->free();
|
||||||
return $settingClasses;
|
return $settingClasses;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete all unused Settings that haven't been initialized during the current Startup
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function deleteUnusedSettings() {
|
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
|
||||||
$settingQuery = "DELETE FROM `" . self::TABLE_SETTINGS . "`
|
|
||||||
WHERE `changed` < NOW() - INTERVAL 1 HOUR;";
|
|
||||||
$settingStatement = $mysqli->prepare($settingQuery);
|
|
||||||
if ($mysqli->error) {
|
|
||||||
trigger_error($mysqli->error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$success = $settingStatement->execute();
|
|
||||||
if ($settingStatement->error) {
|
|
||||||
trigger_error($settingStatement->error);
|
|
||||||
$settingStatement->close();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$settingStatement->close();
|
|
||||||
$this->storedSettings = array();
|
|
||||||
return $success;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,10 @@ use ManiaControl\Players\PlayerManager;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple Stats List Class
|
* Simple Stats List Class
|
||||||
*
|
*
|
||||||
* @author kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener, CommandListener {
|
class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener, CommandListener {
|
||||||
/*
|
/*
|
||||||
@ -82,17 +82,6 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
|
|||||||
$this->registerStat(StatisticManager::SPECIAL_STAT_HITS_PH, 85, "H/h", 15, StatisticManager::STAT_TYPE_FLOAT);
|
$this->registerStat(StatisticManager::SPECIAL_STAT_HITS_PH, 85, "H/h", 15, StatisticManager::STAT_TYPE_FLOAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Show the stat List
|
|
||||||
*
|
|
||||||
* @param array $callback
|
|
||||||
* @param Player $player
|
|
||||||
*/
|
|
||||||
public function command_ShowStatsList(array $callback, Player $player) {
|
|
||||||
$this->showStatsList($player);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a Certain Stat
|
* Register a Certain Stat
|
||||||
*
|
*
|
||||||
@ -111,6 +100,15 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
|
|||||||
$this->statsWidth += $width;
|
$this->statsWidth += $width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the stat List
|
||||||
|
*
|
||||||
|
* @param array $callback
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
public function command_ShowStatsList(array $callback, Player $player) {
|
||||||
|
$this->showStatsList($player);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the StatsList Widget to the Player
|
* Show the StatsList Widget to the Player
|
||||||
@ -174,7 +172,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
|
|||||||
//Compute Headline
|
//Compute Headline
|
||||||
$x = $xStart + 55;
|
$x = $xStart + 55;
|
||||||
$statRankings = array();
|
$statRankings = array();
|
||||||
foreach($this->statArray as $key => $stat) {
|
foreach ($this->statArray as $key => $stat) {
|
||||||
$ranking = $this->maniaControl->statisticManager->getStatsRanking($stat["Name"]);
|
$ranking = $this->maniaControl->statisticManager->getStatsRanking($stat["Name"]);
|
||||||
if (!empty($ranking)) {
|
if (!empty($ranking)) {
|
||||||
$statRankings[$stat["Name"]] = $ranking;
|
$statRankings[$stat["Name"]] = $ranking;
|
||||||
@ -189,16 +187,16 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
|
|||||||
|
|
||||||
//Description Label
|
//Description Label
|
||||||
$i = 2;
|
$i = 2;
|
||||||
foreach($this->statArray as $statArray) {
|
foreach ($this->statArray as $statArray) {
|
||||||
if (!isset($labels[$i])) {
|
if (!isset($labels[$i])) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var Label_Text $label [] */
|
/** @var Label_Text $label [] */
|
||||||
$label = $labels[$i];
|
$label = $labels[$i];
|
||||||
|
|
||||||
$label->setAction(self::ACTION_SORT_STATS . '.' . $statArray["Name"]);
|
$label->setAction(self::ACTION_SORT_STATS . '.' . $statArray["Name"]);
|
||||||
$label->addTooltipLabelFeature($descriptionLabel, '$o '.$statArray["Name"]);
|
$label->addTooltipLabelFeature($descriptionLabel, '$o ' . $statArray["Name"]);
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,7 +212,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($statRankings[$order] as $playerId => $value) {
|
foreach ($statRankings[$order] as $playerId => $value) {
|
||||||
$listPlayer = $this->maniaControl->playerManager->getPlayerByIndex($playerId);
|
$listPlayer = $this->maniaControl->playerManager->getPlayerByIndex($playerId);
|
||||||
if ($i == 15) {
|
if ($i == 15) {
|
||||||
break;
|
break;
|
||||||
@ -235,7 +233,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
|
|||||||
|
|
||||||
$displayArray = array();
|
$displayArray = array();
|
||||||
|
|
||||||
foreach($this->statArray as $stat) {
|
foreach ($this->statArray as $stat) {
|
||||||
$statValue = 0;
|
$statValue = 0;
|
||||||
if (isset($statRankings[$stat['Name']][$playerId])) {
|
if (isset($statRankings[$stat['Name']][$playerId])) {
|
||||||
$statValue = $statRankings[$stat['Name']][$playerId];
|
$statValue = $statRankings[$stat['Name']][$playerId];
|
||||||
@ -254,7 +252,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
|
|||||||
|
|
||||||
|
|
||||||
$x = $xStart + 55;
|
$x = $xStart + 55;
|
||||||
foreach($displayArray as $key => $array) {
|
foreach ($displayArray as $key => $array) {
|
||||||
$label = new Label_Text();
|
$label = new Label_Text();
|
||||||
$playerFrame->add($label);
|
$playerFrame->add($label);
|
||||||
$label->setHAlign($hAlign);
|
$label->setHAlign($hAlign);
|
||||||
@ -263,7 +261,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
|
|||||||
$label->setTextSize($textSize);
|
$label->setTextSize($textSize);
|
||||||
$label->setText($array['Value']);
|
$label->setText($array['Value']);
|
||||||
$label->setTextColor($textColor);
|
$label->setTextColor($textColor);
|
||||||
$label->addTooltipLabelFeature($descriptionLabel, '$o '.$key);
|
$label->addTooltipLabelFeature($descriptionLabel, '$o ' . $key);
|
||||||
$x += $array['Width'];
|
$x += $array['Width'];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,7 +299,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
|
|||||||
|
|
||||||
$action = $actionArray[0] . "." . $actionArray[1];
|
$action = $actionArray[0] . "." . $actionArray[1];
|
||||||
|
|
||||||
switch($action) {
|
switch ($action) {
|
||||||
case self::ACTION_SORT_STATS:
|
case self::ACTION_SORT_STATS:
|
||||||
$playerLogin = $callback[1][1];
|
$playerLogin = $callback[1][1];
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($playerLogin);
|
$player = $this->maniaControl->playerManager->getPlayer($playerLogin);
|
||||||
|
@ -11,9 +11,9 @@ use ManiaControl\Players\PlayerManager;
|
|||||||
/**
|
/**
|
||||||
* Statistic Collector Class
|
* Statistic Collector Class
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class StatisticCollector implements CallbackListener {
|
class StatisticCollector implements CallbackListener {
|
||||||
/*
|
/*
|
||||||
@ -115,93 +115,12 @@ class StatisticCollector implements CallbackListener {
|
|||||||
|
|
||||||
$leaders = $this->maniaControl->server->rankingManager->getLeaders();
|
$leaders = $this->maniaControl->server->rankingManager->getLeaders();
|
||||||
|
|
||||||
foreach($leaders as $leaderLogin) {
|
foreach ($leaders as $leaderLogin) {
|
||||||
$leader = $this->maniaControl->playerManager->getPlayer($leaderLogin);
|
$leader = $this->maniaControl->playerManager->getPlayer($leaderLogin);
|
||||||
$this->maniaControl->statisticManager->incrementStat(self::STAT_MAP_WINS, $leader);
|
$this->maniaControl->statisticManager->incrementStat(self::STAT_MAP_WINS, $leader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle Player Shots
|
|
||||||
*
|
|
||||||
* @param string $login
|
|
||||||
* @param int $weaponNumber
|
|
||||||
*/
|
|
||||||
private function handleOnShoot($login, $weaponNumber) {
|
|
||||||
if (!isset($this->onShootArray[$login])) {
|
|
||||||
$this->onShootArray[$login] = array(self::WEAPON_ROCKET => 0, self::WEAPON_ARROW => 0, self::WEAPON_NUCLEUS => 0, self::WEAPON_LASER => 0);
|
|
||||||
$this->onShootArray[$login][$weaponNumber]++;
|
|
||||||
} else {
|
|
||||||
$this->onShootArray[$login][$weaponNumber]++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Write Shoot Data into database
|
|
||||||
if (array_sum($this->onShootArray[$login]) > $this->maniaControl->settingManager->getSetting($this, self::SETTING_ON_SHOOT_PRESTORE)) {
|
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
|
||||||
|
|
||||||
$rocketShots = $this->onShootArray[$login][self::WEAPON_ROCKET];
|
|
||||||
$laserShots = $this->onShootArray[$login][self::WEAPON_LASER];
|
|
||||||
$arrowShots = $this->onShootArray[$login][self::WEAPON_ARROW];
|
|
||||||
$nucleusShots = $this->onShootArray[$login][self::WEAPON_NUCLEUS];
|
|
||||||
|
|
||||||
if ($rocketShots > 0) {
|
|
||||||
$this->maniaControl->statisticManager->insertStat(self::STAT_ROCKET_SHOT, $player, $this->maniaControl->server->index, $rocketShots);
|
|
||||||
$this->onShootArray[$login][self::WEAPON_ROCKET] = 0;
|
|
||||||
}
|
|
||||||
if ($laserShots > 0) {
|
|
||||||
$this->maniaControl->statisticManager->insertStat(self::STAT_LASER_SHOT, $player, $this->maniaControl->server->index, $laserShots);
|
|
||||||
$this->onShootArray[$login][self::WEAPON_LASER] = 0;
|
|
||||||
}
|
|
||||||
if ($arrowShots > 0) {
|
|
||||||
$this->maniaControl->statisticManager->insertStat(self::STAT_ARROW_SHOT, $player, $this->maniaControl->server->index, $arrowShots);
|
|
||||||
$this->onShootArray[$login][self::WEAPON_ARROW] = 0;
|
|
||||||
}
|
|
||||||
if ($nucleusShots > 0) {
|
|
||||||
$this->maniaControl->statisticManager->insertStat(self::STAT_NUCLEUS_SHOT, $player, $this->maniaControl->server->index, $nucleusShots);
|
|
||||||
$this->onShootArray[$login][self::WEAPON_NUCLEUS] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->maniaControl->statisticManager->insertStat(self::STAT_ON_SHOOT, $player, $this->maniaControl->server->index, $rocketShots + $laserShots + $arrowShots + $nucleusShots);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the Weapon stat
|
|
||||||
*
|
|
||||||
* @param int $weaponNumber
|
|
||||||
* @param bool $shot
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function getWeaponStat($weaponNumber, $shot = true) {
|
|
||||||
if ($shot) {
|
|
||||||
switch($weaponNumber) {
|
|
||||||
case self::WEAPON_ROCKET:
|
|
||||||
return self::STAT_ROCKET_SHOT;
|
|
||||||
case self::WEAPON_LASER:
|
|
||||||
return self::STAT_LASER_SHOT;
|
|
||||||
case self::WEAPON_ARROW:
|
|
||||||
return self::STAT_ARROW_SHOT;
|
|
||||||
case self::WEAPON_NUCLEUS:
|
|
||||||
return self::STAT_NUCLEUS_SHOT;
|
|
||||||
default:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
switch($weaponNumber) {
|
|
||||||
case self::WEAPON_ROCKET:
|
|
||||||
return self::STAT_ROCKET_HIT;
|
|
||||||
case self::WEAPON_LASER:
|
|
||||||
return self::STAT_LASER_HIT;
|
|
||||||
case self::WEAPON_ARROW:
|
|
||||||
return self::STAT_ARROW_HIT;
|
|
||||||
case self::WEAPON_NUCLEUS:
|
|
||||||
return self::STAT_NUCLEUS_HIT;
|
|
||||||
default:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert OnShoot Statistic when a player leaves
|
* Insert OnShoot Statistic when a player leaves
|
||||||
*
|
*
|
||||||
@ -240,7 +159,7 @@ class StatisticCollector implements CallbackListener {
|
|||||||
|
|
||||||
$callbackName = $callback[1][0];
|
$callbackName = $callback[1][0];
|
||||||
|
|
||||||
switch($callbackName) {
|
switch ($callbackName) {
|
||||||
case 'LibXmlRpc_OnShoot':
|
case 'LibXmlRpc_OnShoot':
|
||||||
$this->handleOnShoot($callback[1][1][0], $callback[1][1][1]);
|
$this->handleOnShoot($callback[1][1][0], $callback[1][1][1]);
|
||||||
break;
|
break;
|
||||||
@ -263,7 +182,7 @@ class StatisticCollector implements CallbackListener {
|
|||||||
case 'LibXmlRpc_OnCapture':
|
case 'LibXmlRpc_OnCapture':
|
||||||
$logins = $callback[1][1][0];
|
$logins = $callback[1][1][0];
|
||||||
$logins = explode(';', $logins);
|
$logins = explode(';', $logins);
|
||||||
foreach($logins as $login) {
|
foreach ($logins as $login) {
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
if (!$player) {
|
if (!$player) {
|
||||||
continue;
|
continue;
|
||||||
@ -335,11 +254,92 @@ class StatisticCollector implements CallbackListener {
|
|||||||
$paramsObject = json_decode($callback[1][1]);
|
$paramsObject = json_decode($callback[1][1]);
|
||||||
$durationTime = (int)(($paramsObject->EndTime - $paramsObject->StartTime) / 1000);
|
$durationTime = (int)(($paramsObject->EndTime - $paramsObject->StartTime) / 1000);
|
||||||
$scoresTable = $paramsObject->ScoresTable;
|
$scoresTable = $paramsObject->ScoresTable;
|
||||||
foreach($scoresTable as $score) {
|
foreach ($scoresTable as $score) {
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($score->Login);
|
$player = $this->maniaControl->playerManager->getPlayer($score->Login);
|
||||||
$this->maniaControl->statisticManager->insertStat(self::STAT_PLAYTIME, $player, -1, $durationTime);
|
$this->maniaControl->statisticManager->insertStat(self::STAT_PLAYTIME, $player, -1, $durationTime);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle Player Shots
|
||||||
|
*
|
||||||
|
* @param string $login
|
||||||
|
* @param int $weaponNumber
|
||||||
|
*/
|
||||||
|
private function handleOnShoot($login, $weaponNumber) {
|
||||||
|
if (!isset($this->onShootArray[$login])) {
|
||||||
|
$this->onShootArray[$login] = array(self::WEAPON_ROCKET => 0, self::WEAPON_ARROW => 0, self::WEAPON_NUCLEUS => 0, self::WEAPON_LASER => 0);
|
||||||
|
$this->onShootArray[$login][$weaponNumber]++;
|
||||||
|
} else {
|
||||||
|
$this->onShootArray[$login][$weaponNumber]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Write Shoot Data into database
|
||||||
|
if (array_sum($this->onShootArray[$login]) > $this->maniaControl->settingManager->getSetting($this, self::SETTING_ON_SHOOT_PRESTORE)) {
|
||||||
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
|
|
||||||
|
$rocketShots = $this->onShootArray[$login][self::WEAPON_ROCKET];
|
||||||
|
$laserShots = $this->onShootArray[$login][self::WEAPON_LASER];
|
||||||
|
$arrowShots = $this->onShootArray[$login][self::WEAPON_ARROW];
|
||||||
|
$nucleusShots = $this->onShootArray[$login][self::WEAPON_NUCLEUS];
|
||||||
|
|
||||||
|
if ($rocketShots > 0) {
|
||||||
|
$this->maniaControl->statisticManager->insertStat(self::STAT_ROCKET_SHOT, $player, $this->maniaControl->server->index, $rocketShots);
|
||||||
|
$this->onShootArray[$login][self::WEAPON_ROCKET] = 0;
|
||||||
|
}
|
||||||
|
if ($laserShots > 0) {
|
||||||
|
$this->maniaControl->statisticManager->insertStat(self::STAT_LASER_SHOT, $player, $this->maniaControl->server->index, $laserShots);
|
||||||
|
$this->onShootArray[$login][self::WEAPON_LASER] = 0;
|
||||||
|
}
|
||||||
|
if ($arrowShots > 0) {
|
||||||
|
$this->maniaControl->statisticManager->insertStat(self::STAT_ARROW_SHOT, $player, $this->maniaControl->server->index, $arrowShots);
|
||||||
|
$this->onShootArray[$login][self::WEAPON_ARROW] = 0;
|
||||||
|
}
|
||||||
|
if ($nucleusShots > 0) {
|
||||||
|
$this->maniaControl->statisticManager->insertStat(self::STAT_NUCLEUS_SHOT, $player, $this->maniaControl->server->index, $nucleusShots);
|
||||||
|
$this->onShootArray[$login][self::WEAPON_NUCLEUS] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->maniaControl->statisticManager->insertStat(self::STAT_ON_SHOOT, $player, $this->maniaControl->server->index, $rocketShots + $laserShots + $arrowShots + $nucleusShots);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Weapon stat
|
||||||
|
*
|
||||||
|
* @param int $weaponNumber
|
||||||
|
* @param bool $shot
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function getWeaponStat($weaponNumber, $shot = true) {
|
||||||
|
if ($shot) {
|
||||||
|
switch ($weaponNumber) {
|
||||||
|
case self::WEAPON_ROCKET:
|
||||||
|
return self::STAT_ROCKET_SHOT;
|
||||||
|
case self::WEAPON_LASER:
|
||||||
|
return self::STAT_LASER_SHOT;
|
||||||
|
case self::WEAPON_ARROW:
|
||||||
|
return self::STAT_ARROW_SHOT;
|
||||||
|
case self::WEAPON_NUCLEUS:
|
||||||
|
return self::STAT_NUCLEUS_SHOT;
|
||||||
|
default:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch ($weaponNumber) {
|
||||||
|
case self::WEAPON_ROCKET:
|
||||||
|
return self::STAT_ROCKET_HIT;
|
||||||
|
case self::WEAPON_LASER:
|
||||||
|
return self::STAT_LASER_HIT;
|
||||||
|
case self::WEAPON_ARROW:
|
||||||
|
return self::STAT_ARROW_HIT;
|
||||||
|
case self::WEAPON_NUCLEUS:
|
||||||
|
return self::STAT_NUCLEUS_HIT;
|
||||||
|
default:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -8,9 +8,9 @@ use ManiaControl\Players\Player;
|
|||||||
/**
|
/**
|
||||||
* Statistic Manager Class
|
* Statistic Manager Class
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class StatisticManager {
|
class StatisticManager {
|
||||||
/*
|
/*
|
||||||
@ -59,229 +59,55 @@ class StatisticManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the value of an statistic
|
* Initialize necessary database tables
|
||||||
*
|
*
|
||||||
* @param $statName
|
* @return bool
|
||||||
* @param $playerId
|
|
||||||
* @param int $serverIndex
|
|
||||||
* @return int
|
|
||||||
*/
|
*/
|
||||||
public function getStatisticData($statName, $playerId, $serverIndex = -1) {
|
private function initTables() {
|
||||||
//Handle Special Stats
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
switch($statName) {
|
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_STATMETADATA . "` (
|
||||||
case self::SPECIAL_STAT_KD_RATIO:
|
`index` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
$kills = $this->getStatisticData(StatisticCollector::STAT_ON_KILL, $playerId, $serverIndex);
|
`name` varchar(100) NOT NULL,
|
||||||
$deaths = $this->getStatisticData(StatisticCollector::STAT_ON_DEATH, $playerId, $serverIndex);
|
`type` int(5) NOT NULL,
|
||||||
if ($deaths == 0) {
|
`description` varchar(150) NOT NULL,
|
||||||
return -1;
|
PRIMARY KEY (`index`),
|
||||||
}
|
UNIQUE KEY `name` (`name`)
|
||||||
return intval($kills) / intval($deaths);
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Statistics Meta Data' AUTO_INCREMENT=1;";
|
||||||
case self::SPECIAL_STAT_HITS_PH:
|
$statement = $mysqli->prepare($query);
|
||||||
$hits = $this->getStatisticData(StatisticCollector::STAT_ON_HIT, $playerId, $serverIndex);
|
if ($mysqli->error) {
|
||||||
$time = $this->getStatisticData(StatisticCollector::STAT_PLAYTIME, $playerId, $serverIndex);
|
trigger_error($mysqli->error, E_USER_ERROR);
|
||||||
if ($time == 0) {
|
return false;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return intval($hits) / (intval($time) / 3600);
|
|
||||||
case self::SPECIAL_STAT_ARROW_ACC:
|
|
||||||
$hits = $this->getStatisticData(StatisticCollector::STAT_ARROW_HIT, $playerId, $serverIndex);
|
|
||||||
$shots = $this->getStatisticData(StatisticCollector::STAT_ARROW_SHOT, $playerId, $serverIndex);
|
|
||||||
if ($shots == 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return intval($hits) / intval($shots);
|
|
||||||
case self::SPECIAL_STAT_LASER_ACC:
|
|
||||||
$hits = $this->getStatisticData(StatisticCollector::STAT_LASER_HIT, $playerId, $serverIndex);
|
|
||||||
$shots = $this->getStatisticData(StatisticCollector::STAT_LASER_SHOT, $playerId, $serverIndex);
|
|
||||||
if ($shots == 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return intval($hits) / intval($shots);
|
|
||||||
case self::SPECIAL_STAT_NUCLEUS_ACC:
|
|
||||||
$hits = $this->getStatisticData(StatisticCollector::STAT_NUCLEUS_HIT, $playerId, $serverIndex);
|
|
||||||
$shots = $this->getStatisticData(StatisticCollector::STAT_NUCLEUS_SHOT, $playerId, $serverIndex);
|
|
||||||
if ($shots == 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return intval($hits) / intval($shots);
|
|
||||||
case self::SPECIAL_STAT_ROCKET_ACC:
|
|
||||||
$hits = $this->getStatisticData(StatisticCollector::STAT_ROCKET_HIT, $playerId, $serverIndex);
|
|
||||||
$shots = $this->getStatisticData(StatisticCollector::STAT_ROCKET_SHOT, $playerId, $serverIndex);
|
|
||||||
if ($shots == 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return intval($hits) / intval($shots);
|
|
||||||
}
|
}
|
||||||
|
$statement->execute();
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
if ($statement->error) {
|
||||||
$statId = $this->getStatId($statName);
|
trigger_error($statement->error, E_USER_ERROR);
|
||||||
|
return false;
|
||||||
if (!$statId) return -1;
|
|
||||||
|
|
||||||
if ($serverIndex == -1) {
|
|
||||||
$query = "SELECT SUM(value) as value FROM `" . self::TABLE_STATISTICS . "` WHERE `statId` = " . $statId . " AND `playerId` = " . $playerId . ";";
|
|
||||||
} else {
|
|
||||||
$query = "SELECT value FROM `" . self::TABLE_STATISTICS . "` WHERE `statId` = " . $statId . " AND `playerId` = " . $playerId . " AND `serverIndex` = '" . $serverIndex . "';";
|
|
||||||
}
|
}
|
||||||
|
$statement->close();
|
||||||
|
|
||||||
$result = $mysqli->query($query);
|
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_STATISTICS . "` (
|
||||||
if (!$result) {
|
`index` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
trigger_error($mysqli->error);
|
`serverIndex` int(11) NOT NULL,
|
||||||
return -1;
|
`playerId` int(11) NOT NULL,
|
||||||
|
`statId` int(11) NOT NULL,
|
||||||
|
`value` int(20) NOT NULL DEFAULT '0',
|
||||||
|
PRIMARY KEY (`index`),
|
||||||
|
UNIQUE KEY `unique` (`statId`,`playerId`,`serverIndex`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Statistics' AUTO_INCREMENT=1;";
|
||||||
|
$statement = $mysqli->prepare($query);
|
||||||
|
if ($mysqli->error) {
|
||||||
|
trigger_error($mysqli->error, E_USER_ERROR);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
$statement->execute();
|
||||||
$row = $result->fetch_object();
|
if ($statement->error) {
|
||||||
|
trigger_error($statement->error, E_USER_ERROR);
|
||||||
$result->close();
|
return false;
|
||||||
return $row->value;
|
}
|
||||||
|
$statement->close();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get All statistics ordered by an given name
|
|
||||||
*
|
|
||||||
* @param string $statName
|
|
||||||
* @param $serverIndex
|
|
||||||
* @param $minValue
|
|
||||||
* @internal param $orderedBy
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getStatsRanking($statName = '', $serverIndex = -1, $minValue = -1) {
|
|
||||||
if (isset($this->specialStats[$statName])) {
|
|
||||||
return $this->getStatsRankingOfSpecialStat($statName, $serverIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
|
||||||
$statId = $this->getStatId($statName);
|
|
||||||
|
|
||||||
if ($minValue == -1) {
|
|
||||||
$query = "SELECT playerId, serverIndex, value FROM `" . self::TABLE_STATISTICS . "` WHERE statId = " . $statId . " ORDER BY value DESC;";
|
|
||||||
} else {
|
|
||||||
$query = "SELECT playerId, serverIndex, value FROM `" . self::TABLE_STATISTICS . "` WHERE statId = " . $statId . " AND value >= " . $minValue . " ORDER BY value DESC;";
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = $mysqli->query($query);
|
|
||||||
if (!$result) {
|
|
||||||
trigger_error($mysqli->error);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$stats = array();
|
|
||||||
while($row = $result->fetch_object()) {
|
|
||||||
if ($serverIndex == -1) {
|
|
||||||
if (!isset($stats[$row->playerId])) {
|
|
||||||
$stats[$row->playerId] = $row->value;
|
|
||||||
} else {
|
|
||||||
$stats[$row->playerId] += $row->value;
|
|
||||||
}
|
|
||||||
} else if ($serverIndex == $row->serverIndex) {
|
|
||||||
$stats[$row->playerId] = $row->value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
arsort($stats);
|
|
||||||
$result->close();
|
|
||||||
return $stats;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets The Ranking of an Special Stat
|
|
||||||
*
|
|
||||||
* @param string $statName
|
|
||||||
* @param $serverIndex
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getStatsRankingOfSpecialStat($statName = '', $serverIndex = -1) {
|
|
||||||
$statsArray = array();
|
|
||||||
switch($statName) {
|
|
||||||
case self::SPECIAL_STAT_KD_RATIO:
|
|
||||||
$kills = $this->getStatsRanking(StatisticCollector::STAT_ON_KILL, $serverIndex);
|
|
||||||
$deaths = $this->getStatsRanking(StatisticCollector::STAT_ON_DEATH, $serverIndex);
|
|
||||||
if(!$kills || !$deaths){
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
foreach($deaths as $key => $death) {
|
|
||||||
if ($death == 0 || !isset($kills[$key])) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$statsArray[$key] = intval($kills[$key]) / intval($death);
|
|
||||||
}
|
|
||||||
arsort($statsArray);
|
|
||||||
break;
|
|
||||||
case self::SPECIAL_STAT_HITS_PH:
|
|
||||||
$hits = $this->getStatsRanking(StatisticCollector::STAT_ON_HIT, $serverIndex);
|
|
||||||
$times = $this->getStatsRanking(StatisticCollector::STAT_PLAYTIME, $serverIndex);
|
|
||||||
if(!$hits || !$times){
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
foreach($times as $key => $time) {
|
|
||||||
if ($time == 0 || !isset($hits[$key])) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$statsArray[$key] = intval($hits[$key]) / (intval($time) / 3600);
|
|
||||||
}
|
|
||||||
arsort($statsArray);
|
|
||||||
break;
|
|
||||||
case self::SPECIAL_STAT_ARROW_ACC:
|
|
||||||
$hits = $this->getStatsRanking(StatisticCollector::STAT_ARROW_HIT, $serverIndex);
|
|
||||||
$shots = $this->getStatsRanking(StatisticCollector::STAT_ARROW_SHOT, $serverIndex);
|
|
||||||
if(!$hits || !$shots){
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
foreach($shots as $key => $shot) {
|
|
||||||
if ($shot == 0 || !isset($hits[$key])) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$statsArray[$key] = intval($hits[$key]) / (intval($shot));
|
|
||||||
}
|
|
||||||
arsort($statsArray);
|
|
||||||
break;
|
|
||||||
case self::SPECIAL_STAT_LASER_ACC:
|
|
||||||
$hits = $this->getStatsRanking(StatisticCollector::STAT_LASER_HIT, $serverIndex);
|
|
||||||
$shots = $this->getStatsRanking(StatisticCollector::STAT_LASER_SHOT, $serverIndex);
|
|
||||||
if(!$hits || !$shots){
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
foreach($shots as $key => $shot) {
|
|
||||||
if ($shot == 0 || !isset($hits[$key])) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$statsArray[$key] = intval($hits[$key]) / (intval($shot));
|
|
||||||
}
|
|
||||||
arsort($statsArray);
|
|
||||||
break;
|
|
||||||
case self::SPECIAL_STAT_ROCKET_ACC:
|
|
||||||
$hits = $this->getStatsRanking(StatisticCollector::STAT_ROCKET_HIT, $serverIndex);
|
|
||||||
$shots = $this->getStatsRanking(StatisticCollector::STAT_ROCKET_SHOT, $serverIndex);
|
|
||||||
if(!$hits || !$shots){
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
foreach($shots as $key => $shot) {
|
|
||||||
if ($shot == 0 || !isset($hits[$key])) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$statsArray[$key] = intval($hits[$key]) / (intval($shot));
|
|
||||||
}
|
|
||||||
arsort($statsArray);
|
|
||||||
break;
|
|
||||||
case self::SPECIAL_STAT_NUCLEUS_ACC:
|
|
||||||
$hits = $this->getStatsRanking(StatisticCollector::STAT_NUCLEUS_HIT, $serverIndex);
|
|
||||||
$shots = $this->getStatsRanking(StatisticCollector::STAT_NUCLEUS_SHOT, $serverIndex);
|
|
||||||
if(!$hits || !$shots){
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
foreach($shots as $key => $shot) {
|
|
||||||
if ($shot == 0 || !isset($hits[$key])) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$statsArray[$key] = intval($hits[$key]) / (intval($shot));
|
|
||||||
}
|
|
||||||
arsort($statsArray);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return $statsArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store Stats Meta Data from the Database
|
* Store Stats Meta Data from the Database
|
||||||
*/
|
*/
|
||||||
@ -295,13 +121,13 @@ class StatisticManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while($row = $result->fetch_object()) {
|
while ($row = $result->fetch_object()) {
|
||||||
$this->stats[$row->name] = $row;
|
$this->stats[$row->name] = $row;
|
||||||
}
|
}
|
||||||
$result->close();
|
$result->close();
|
||||||
|
|
||||||
// TODO: own model class
|
// TODO: own model class
|
||||||
|
|
||||||
//Define Special Stat Kill / Death Ratio
|
//Define Special Stat Kill / Death Ratio
|
||||||
$stat = new \stdClass();
|
$stat = new \stdClass();
|
||||||
$stat->name = self::SPECIAL_STAT_KD_RATIO;
|
$stat->name = self::SPECIAL_STAT_KD_RATIO;
|
||||||
@ -339,6 +165,151 @@ class StatisticManager {
|
|||||||
$this->specialStats[self::SPECIAL_STAT_ROCKET_ACC] = $stat;
|
$this->specialStats[self::SPECIAL_STAT_ROCKET_ACC] = $stat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get All statistics ordered by an given name
|
||||||
|
*
|
||||||
|
* @param string $statName
|
||||||
|
* @param $serverIndex
|
||||||
|
* @param $minValue
|
||||||
|
* @internal param $orderedBy
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getStatsRanking($statName = '', $serverIndex = -1, $minValue = -1) {
|
||||||
|
if (isset($this->specialStats[$statName])) {
|
||||||
|
return $this->getStatsRankingOfSpecialStat($statName, $serverIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
|
$statId = $this->getStatId($statName);
|
||||||
|
|
||||||
|
if ($minValue == -1) {
|
||||||
|
$query = "SELECT playerId, serverIndex, value FROM `" . self::TABLE_STATISTICS . "` WHERE statId = " . $statId . " ORDER BY value DESC;";
|
||||||
|
} else {
|
||||||
|
$query = "SELECT playerId, serverIndex, value FROM `" . self::TABLE_STATISTICS . "` WHERE statId = " . $statId . " AND value >= " . $minValue . " ORDER BY value DESC;";
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $mysqli->query($query);
|
||||||
|
if (!$result) {
|
||||||
|
trigger_error($mysqli->error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$stats = array();
|
||||||
|
while ($row = $result->fetch_object()) {
|
||||||
|
if ($serverIndex == -1) {
|
||||||
|
if (!isset($stats[$row->playerId])) {
|
||||||
|
$stats[$row->playerId] = $row->value;
|
||||||
|
} else {
|
||||||
|
$stats[$row->playerId] += $row->value;
|
||||||
|
}
|
||||||
|
} else if ($serverIndex == $row->serverIndex) {
|
||||||
|
$stats[$row->playerId] = $row->value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
arsort($stats);
|
||||||
|
$result->close();
|
||||||
|
return $stats;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets The Ranking of an Special Stat
|
||||||
|
*
|
||||||
|
* @param string $statName
|
||||||
|
* @param $serverIndex
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getStatsRankingOfSpecialStat($statName = '', $serverIndex = -1) {
|
||||||
|
$statsArray = array();
|
||||||
|
switch ($statName) {
|
||||||
|
case self::SPECIAL_STAT_KD_RATIO:
|
||||||
|
$kills = $this->getStatsRanking(StatisticCollector::STAT_ON_KILL, $serverIndex);
|
||||||
|
$deaths = $this->getStatsRanking(StatisticCollector::STAT_ON_DEATH, $serverIndex);
|
||||||
|
if (!$kills || !$deaths) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
foreach ($deaths as $key => $death) {
|
||||||
|
if ($death == 0 || !isset($kills[$key])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$statsArray[$key] = intval($kills[$key]) / intval($death);
|
||||||
|
}
|
||||||
|
arsort($statsArray);
|
||||||
|
break;
|
||||||
|
case self::SPECIAL_STAT_HITS_PH:
|
||||||
|
$hits = $this->getStatsRanking(StatisticCollector::STAT_ON_HIT, $serverIndex);
|
||||||
|
$times = $this->getStatsRanking(StatisticCollector::STAT_PLAYTIME, $serverIndex);
|
||||||
|
if (!$hits || !$times) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
foreach ($times as $key => $time) {
|
||||||
|
if ($time == 0 || !isset($hits[$key])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$statsArray[$key] = intval($hits[$key]) / (intval($time) / 3600);
|
||||||
|
}
|
||||||
|
arsort($statsArray);
|
||||||
|
break;
|
||||||
|
case self::SPECIAL_STAT_ARROW_ACC:
|
||||||
|
$hits = $this->getStatsRanking(StatisticCollector::STAT_ARROW_HIT, $serverIndex);
|
||||||
|
$shots = $this->getStatsRanking(StatisticCollector::STAT_ARROW_SHOT, $serverIndex);
|
||||||
|
if (!$hits || !$shots) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
foreach ($shots as $key => $shot) {
|
||||||
|
if ($shot == 0 || !isset($hits[$key])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$statsArray[$key] = intval($hits[$key]) / (intval($shot));
|
||||||
|
}
|
||||||
|
arsort($statsArray);
|
||||||
|
break;
|
||||||
|
case self::SPECIAL_STAT_LASER_ACC:
|
||||||
|
$hits = $this->getStatsRanking(StatisticCollector::STAT_LASER_HIT, $serverIndex);
|
||||||
|
$shots = $this->getStatsRanking(StatisticCollector::STAT_LASER_SHOT, $serverIndex);
|
||||||
|
if (!$hits || !$shots) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
foreach ($shots as $key => $shot) {
|
||||||
|
if ($shot == 0 || !isset($hits[$key])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$statsArray[$key] = intval($hits[$key]) / (intval($shot));
|
||||||
|
}
|
||||||
|
arsort($statsArray);
|
||||||
|
break;
|
||||||
|
case self::SPECIAL_STAT_ROCKET_ACC:
|
||||||
|
$hits = $this->getStatsRanking(StatisticCollector::STAT_ROCKET_HIT, $serverIndex);
|
||||||
|
$shots = $this->getStatsRanking(StatisticCollector::STAT_ROCKET_SHOT, $serverIndex);
|
||||||
|
if (!$hits || !$shots) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
foreach ($shots as $key => $shot) {
|
||||||
|
if ($shot == 0 || !isset($hits[$key])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$statsArray[$key] = intval($hits[$key]) / (intval($shot));
|
||||||
|
}
|
||||||
|
arsort($statsArray);
|
||||||
|
break;
|
||||||
|
case self::SPECIAL_STAT_NUCLEUS_ACC:
|
||||||
|
$hits = $this->getStatsRanking(StatisticCollector::STAT_NUCLEUS_HIT, $serverIndex);
|
||||||
|
$shots = $this->getStatsRanking(StatisticCollector::STAT_NUCLEUS_SHOT, $serverIndex);
|
||||||
|
if (!$hits || !$shots) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
foreach ($shots as $key => $shot) {
|
||||||
|
if ($shot == 0 || !isset($hits[$key])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$statsArray[$key] = intval($hits[$key]) / (intval($shot));
|
||||||
|
}
|
||||||
|
arsort($statsArray);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return $statsArray;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the Stat Id
|
* Return the Stat Id
|
||||||
*
|
*
|
||||||
@ -363,13 +334,13 @@ class StatisticManager {
|
|||||||
public function getAllPlayerStats(Player $player, $serverIndex = -1) {
|
public function getAllPlayerStats(Player $player, $serverIndex = -1) {
|
||||||
// TODO improve performance of the foreach
|
// TODO improve performance of the foreach
|
||||||
$playerStats = array();
|
$playerStats = array();
|
||||||
foreach($this->stats as $stat) {
|
foreach ($this->stats as $stat) {
|
||||||
$value = $this->getStatisticData($stat->name, $player->index, $serverIndex);
|
$value = $this->getStatisticData($stat->name, $player->index, $serverIndex);
|
||||||
$playerStats[$stat->name] = array($stat, $value);
|
$playerStats[$stat->name] = array($stat, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($this->specialStats as $stat) {
|
foreach ($this->specialStats as $stat) {
|
||||||
switch($stat->name) {
|
switch ($stat->name) {
|
||||||
case self::SPECIAL_STAT_KD_RATIO:
|
case self::SPECIAL_STAT_KD_RATIO:
|
||||||
if (!isset($playerStats[StatisticCollector::STAT_ON_KILL]) || !isset($playerStats[StatisticCollector::STAT_ON_DEATH])) {
|
if (!isset($playerStats[StatisticCollector::STAT_ON_KILL]) || !isset($playerStats[StatisticCollector::STAT_ON_DEATH])) {
|
||||||
continue;
|
continue;
|
||||||
@ -441,6 +412,98 @@ class StatisticManager {
|
|||||||
return $playerStats;
|
return $playerStats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of an statistic
|
||||||
|
*
|
||||||
|
* @param $statName
|
||||||
|
* @param $playerId
|
||||||
|
* @param int $serverIndex
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getStatisticData($statName, $playerId, $serverIndex = -1) {
|
||||||
|
//Handle Special Stats
|
||||||
|
switch ($statName) {
|
||||||
|
case self::SPECIAL_STAT_KD_RATIO:
|
||||||
|
$kills = $this->getStatisticData(StatisticCollector::STAT_ON_KILL, $playerId, $serverIndex);
|
||||||
|
$deaths = $this->getStatisticData(StatisticCollector::STAT_ON_DEATH, $playerId, $serverIndex);
|
||||||
|
if ($deaths == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return intval($kills) / intval($deaths);
|
||||||
|
case self::SPECIAL_STAT_HITS_PH:
|
||||||
|
$hits = $this->getStatisticData(StatisticCollector::STAT_ON_HIT, $playerId, $serverIndex);
|
||||||
|
$time = $this->getStatisticData(StatisticCollector::STAT_PLAYTIME, $playerId, $serverIndex);
|
||||||
|
if ($time == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return intval($hits) / (intval($time) / 3600);
|
||||||
|
case self::SPECIAL_STAT_ARROW_ACC:
|
||||||
|
$hits = $this->getStatisticData(StatisticCollector::STAT_ARROW_HIT, $playerId, $serverIndex);
|
||||||
|
$shots = $this->getStatisticData(StatisticCollector::STAT_ARROW_SHOT, $playerId, $serverIndex);
|
||||||
|
if ($shots == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return intval($hits) / intval($shots);
|
||||||
|
case self::SPECIAL_STAT_LASER_ACC:
|
||||||
|
$hits = $this->getStatisticData(StatisticCollector::STAT_LASER_HIT, $playerId, $serverIndex);
|
||||||
|
$shots = $this->getStatisticData(StatisticCollector::STAT_LASER_SHOT, $playerId, $serverIndex);
|
||||||
|
if ($shots == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return intval($hits) / intval($shots);
|
||||||
|
case self::SPECIAL_STAT_NUCLEUS_ACC:
|
||||||
|
$hits = $this->getStatisticData(StatisticCollector::STAT_NUCLEUS_HIT, $playerId, $serverIndex);
|
||||||
|
$shots = $this->getStatisticData(StatisticCollector::STAT_NUCLEUS_SHOT, $playerId, $serverIndex);
|
||||||
|
if ($shots == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return intval($hits) / intval($shots);
|
||||||
|
case self::SPECIAL_STAT_ROCKET_ACC:
|
||||||
|
$hits = $this->getStatisticData(StatisticCollector::STAT_ROCKET_HIT, $playerId, $serverIndex);
|
||||||
|
$shots = $this->getStatisticData(StatisticCollector::STAT_ROCKET_SHOT, $playerId, $serverIndex);
|
||||||
|
if ($shots == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return intval($hits) / intval($shots);
|
||||||
|
}
|
||||||
|
|
||||||
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
|
$statId = $this->getStatId($statName);
|
||||||
|
|
||||||
|
if (!$statId) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($serverIndex == -1) {
|
||||||
|
$query = "SELECT SUM(value) as value FROM `" . self::TABLE_STATISTICS . "` WHERE `statId` = " . $statId . " AND `playerId` = " . $playerId . ";";
|
||||||
|
} else {
|
||||||
|
$query = "SELECT value FROM `" . self::TABLE_STATISTICS . "` WHERE `statId` = " . $statId . " AND `playerId` = " . $playerId . " AND `serverIndex` = '" . $serverIndex . "';";
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $mysqli->query($query);
|
||||||
|
if (!$result) {
|
||||||
|
trigger_error($mysqli->error);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$row = $result->fetch_object();
|
||||||
|
|
||||||
|
$result->close();
|
||||||
|
return $row->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increments a Statistic by one
|
||||||
|
*
|
||||||
|
* @param string $statName
|
||||||
|
* @param Player $player
|
||||||
|
* @param int $serverIndex
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function incrementStat($statName, Player $player, $serverIndex = -1) {
|
||||||
|
return $this->insertStat($statName, $player, $serverIndex, 1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts a Stat into the database
|
* Inserts a Stat into the database
|
||||||
*
|
*
|
||||||
@ -496,18 +559,6 @@ class StatisticManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Increments a Statistic by one
|
|
||||||
*
|
|
||||||
* @param string $statName
|
|
||||||
* @param Player $player
|
|
||||||
* @param int $serverIndex
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function incrementStat($statName, Player $player, $serverIndex = -1) {
|
|
||||||
return $this->insertStat($statName, $player, $serverIndex, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines a Stat
|
* Defines a Stat
|
||||||
*
|
*
|
||||||
@ -542,54 +593,4 @@ class StatisticManager {
|
|||||||
$statement->close();
|
$statement->close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize necessary database tables
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function initTables() {
|
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
|
||||||
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_STATMETADATA . "` (
|
|
||||||
`index` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`name` varchar(100) NOT NULL,
|
|
||||||
`type` int(5) NOT NULL,
|
|
||||||
`description` varchar(150) NOT NULL,
|
|
||||||
PRIMARY KEY (`index`),
|
|
||||||
UNIQUE KEY `name` (`name`)
|
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Statistics Meta Data' AUTO_INCREMENT=1;";
|
|
||||||
$statement = $mysqli->prepare($query);
|
|
||||||
if ($mysqli->error) {
|
|
||||||
trigger_error($mysqli->error, E_USER_ERROR);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$statement->execute();
|
|
||||||
if ($statement->error) {
|
|
||||||
trigger_error($statement->error, E_USER_ERROR);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$statement->close();
|
|
||||||
|
|
||||||
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_STATISTICS . "` (
|
|
||||||
`index` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`serverIndex` int(11) NOT NULL,
|
|
||||||
`playerId` int(11) NOT NULL,
|
|
||||||
`statId` int(11) NOT NULL,
|
|
||||||
`value` int(20) NOT NULL DEFAULT '0',
|
|
||||||
PRIMARY KEY (`index`),
|
|
||||||
UNIQUE KEY `unique` (`statId`,`playerId`,`serverIndex`)
|
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Statistics' AUTO_INCREMENT=1;";
|
|
||||||
$statement = $mysqli->prepare($query);
|
|
||||||
if ($mysqli->error) {
|
|
||||||
trigger_error($mysqli->error, E_USER_ERROR);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$statement->execute();
|
|
||||||
if ($statement->error) {
|
|
||||||
trigger_error($statement->error, E_USER_ERROR);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$statement->close();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,10 @@ namespace ManiaControl\Update;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin Update Data Structure
|
* Plugin Update Data Structure
|
||||||
*
|
*
|
||||||
* @author ManiaControl Team
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class PluginUpdateData {
|
class PluginUpdateData {
|
||||||
/*
|
/*
|
||||||
@ -24,25 +24,25 @@ class PluginUpdateData {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct new Plugin Update Data
|
* Construct new Plugin Update Data
|
||||||
*
|
*
|
||||||
* @param object $updateData
|
* @param object $updateData
|
||||||
*/
|
*/
|
||||||
public function __construct($updateData) {
|
public function __construct($updateData) {
|
||||||
$this->pluginId = $updateData->id;
|
$this->pluginId = $updateData->id;
|
||||||
$this->pluginName = $updateData->name;
|
$this->pluginName = $updateData->name;
|
||||||
$this->pluginAuthor = $updateData->author;
|
$this->pluginAuthor = $updateData->author;
|
||||||
$this->pluginDescription = $updateData->description;
|
$this->pluginDescription = $updateData->description;
|
||||||
if ($updateData->currentVersion) {
|
if ($updateData->currentVersion) {
|
||||||
$this->id = $updateData->currentVersion->id;
|
$this->id = $updateData->currentVersion->id;
|
||||||
$this->version = $updateData->currentVersion->version;
|
$this->version = $updateData->currentVersion->version;
|
||||||
$this->zipfile = $updateData->currentVersion->zipfile;
|
$this->zipfile = $updateData->currentVersion->zipfile;
|
||||||
$this->url = $updateData->currentVersion->url;
|
$this->url = $updateData->currentVersion->url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the Plugin Update Data is newer than the given Plugin Version
|
* Check if the Plugin Update Data is newer than the given Plugin Version
|
||||||
*
|
*
|
||||||
* @param float $version
|
* @param float $version
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@ -6,21 +6,21 @@ use ManiaControl\Callbacks\CallbackListener;
|
|||||||
use ManiaControl\Callbacks\CallbackManager;
|
use ManiaControl\Callbacks\CallbackManager;
|
||||||
use ManiaControl\Callbacks\TimerListener;
|
use ManiaControl\Callbacks\TimerListener;
|
||||||
use ManiaControl\Commands\CommandListener;
|
use ManiaControl\Commands\CommandListener;
|
||||||
|
use ManiaControl\Files\BackupUtil;
|
||||||
use ManiaControl\Files\FileUtil;
|
use ManiaControl\Files\FileUtil;
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
use ManiaControl\Plugins\Plugin;
|
use ManiaControl\Plugins\Plugin;
|
||||||
use ManiaControl\Plugins\PluginInstallMenu;
|
use ManiaControl\Plugins\PluginInstallMenu;
|
||||||
use ManiaControl\Plugins\PluginMenu;
|
|
||||||
use ManiaControl\Plugins\PluginManager;
|
use ManiaControl\Plugins\PluginManager;
|
||||||
use ManiaControl\Files\BackupUtil;
|
use ManiaControl\Plugins\PluginMenu;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manager checking for ManiaControl Plugin Updates
|
* Manager checking for ManiaControl Plugin Updates
|
||||||
*
|
*
|
||||||
* @author ManiaControl Team
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class PluginUpdateManager implements CallbackListener, CommandListener, TimerListener {
|
class PluginUpdateManager implements CallbackListener, CommandListener, TimerListener {
|
||||||
/*
|
/*
|
||||||
@ -30,15 +30,15 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Plugin Update Manager
|
* Create a new Plugin Update Manager
|
||||||
*
|
*
|
||||||
* @param ManiaControl $maniaControl
|
* @param ManiaControl $maniaControl
|
||||||
*/
|
*/
|
||||||
public function __construct(ManiaControl $maniaControl) {
|
public function __construct(ManiaControl $maniaControl) {
|
||||||
$this->maniaControl = $maniaControl;
|
$this->maniaControl = $maniaControl;
|
||||||
|
|
||||||
// Register for callbacks
|
// Register for callbacks
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||||
|
|
||||||
// Register for chat commands
|
// Register for chat commands
|
||||||
$this->maniaControl->commandManager->registerCommandListener('checkpluginsupdate', $this, 'handle_CheckPluginsUpdate', true, 'Check for Plugin Updates.');
|
$this->maniaControl->commandManager->registerCommandListener('checkpluginsupdate', $this, 'handle_CheckPluginsUpdate', true, 'Check for Plugin Updates.');
|
||||||
$this->maniaControl->commandManager->registerCommandListener('pluginsupdate', $this, 'handle_PluginsUpdate', true, 'Perform the Plugin Updates.');
|
$this->maniaControl->commandManager->registerCommandListener('pluginsupdate', $this, 'handle_PluginsUpdate', true, 'Perform the Plugin Updates.');
|
||||||
@ -46,8 +46,8 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle //checkpluginsupdate command
|
* Handle //checkpluginsupdate command
|
||||||
*
|
*
|
||||||
* @param array $chatCallback
|
* @param array $chatCallback
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
public function handle_CheckPluginsUpdate(array $chatCallback, Player $player) {
|
public function handle_CheckPluginsUpdate(array $chatCallback, Player $player) {
|
||||||
@ -55,14 +55,98 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
|
|||||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->checkPluginsUpdate($player);
|
$this->checkPluginsUpdate($player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if there are Outdated Plugins installed
|
||||||
|
*
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
public function checkPluginsUpdate(Player $player = null) {
|
||||||
|
$message = 'Checking Plugins for newer Versions...';
|
||||||
|
if ($player) {
|
||||||
|
$this->maniaControl->chat->sendInformation($message, $player);
|
||||||
|
}
|
||||||
|
$this->maniaControl->log($message);
|
||||||
|
|
||||||
|
$self = $this;
|
||||||
|
$this->maniaControl->pluginManager->fetchPluginList(function ($data, $error) use (&$self, &$player) {
|
||||||
|
|
||||||
|
if (!$data || $error) {
|
||||||
|
$message = 'Error while checking Plugins for newer Versions!';
|
||||||
|
if ($player) {
|
||||||
|
$self->maniaControl->chat->sendError($message, $player);
|
||||||
|
}
|
||||||
|
$self->maniaControl->log($message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pluginsData = $self->parsePluginsData($data);
|
||||||
|
$pluginClasses = $self->maniaControl->pluginManager->getPluginClasses();
|
||||||
|
$pluginUpdates = array();
|
||||||
|
|
||||||
|
foreach ($pluginClasses as $pluginClass) {
|
||||||
|
/**
|
||||||
|
* @var Plugin $pluginClass
|
||||||
|
*/
|
||||||
|
$pluginId = $pluginClass::getId();
|
||||||
|
if (!isset($pluginsData[$pluginId])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
/** @var PluginUpdateData $pluginData */
|
||||||
|
$pluginData = $pluginsData[$pluginId];
|
||||||
|
$pluginVersion = $pluginClass::getVersion();
|
||||||
|
if ($pluginData->isNewerThan($pluginVersion)) {
|
||||||
|
$pluginUpdates[$pluginId] = $pluginData;
|
||||||
|
$message = "There is an Update of '{$pluginData->pluginName}' available! ('{$pluginClass}' - Version {$pluginData->version})";
|
||||||
|
if ($player) {
|
||||||
|
$self->maniaControl->chat->sendSuccess($message, $player);
|
||||||
|
}
|
||||||
|
$self->maniaControl->log($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($pluginUpdates)) {
|
||||||
|
$message = 'Plugins Update Check completed: All Plugins are up-to-date!';
|
||||||
|
if ($player) {
|
||||||
|
$self->maniaControl->chat->sendSuccess($message, $player);
|
||||||
|
}
|
||||||
|
$self->maniaControl->log($message);
|
||||||
|
} else {
|
||||||
|
$updatesCount = count($pluginUpdates);
|
||||||
|
$message = "Plugins Update Check completed: There are {$updatesCount} Updates available!";
|
||||||
|
if ($player) {
|
||||||
|
$self->maniaControl->chat->sendSuccess($message, $player);
|
||||||
|
}
|
||||||
|
$self->maniaControl->log($message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an Array of Plugin Update Data from the given Web Service Result
|
||||||
|
*
|
||||||
|
* @param mixed $webServiceResult
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function parsePluginsData($webServiceResult) {
|
||||||
|
if (!$webServiceResult || !is_array($webServiceResult)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$pluginsData = array();
|
||||||
|
foreach ($webServiceResult as $pluginResult) {
|
||||||
|
$pluginData = new PluginUpdateData($pluginResult);
|
||||||
|
$pluginsData[$pluginData->pluginId] = $pluginData;
|
||||||
|
}
|
||||||
|
return $pluginsData;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle //pluginsupdate command
|
* Handle //pluginsupdate command
|
||||||
*
|
*
|
||||||
* @param array $chatCallback
|
* @param array $chatCallback
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
public function handle_PluginsUpdate(array $chatCallback, Player $player) {
|
public function handle_PluginsUpdate(array $chatCallback, Player $player) {
|
||||||
@ -70,48 +154,200 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
|
|||||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->performPluginsUpdate($player);
|
$this->performPluginsUpdate($player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform an Update of all outdated Plugins
|
||||||
|
*
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
public function performPluginsUpdate(Player $player = null) {
|
||||||
|
$pluginsUpdates = $this->getPluginsUpdates();
|
||||||
|
if (empty($pluginsUpdates)) {
|
||||||
|
$message = 'There are no Plugin Updates available!';
|
||||||
|
if ($player) {
|
||||||
|
$this->maniaControl->chat->sendInformation($message, $player);
|
||||||
|
}
|
||||||
|
$this->maniaControl->log($message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$message = "Starting Plugins Updating...";
|
||||||
|
if ($player) {
|
||||||
|
$this->maniaControl->chat->sendInformation($message, $player);
|
||||||
|
}
|
||||||
|
$this->maniaControl->log($message);
|
||||||
|
|
||||||
|
$performBackup = $this->maniaControl->settingManager->getSetting($this->maniaControl->updateManager, UpdateManager::SETTING_PERFORM_BACKUPS);
|
||||||
|
if ($performBackup && !BackupUtil::performPluginsBackup()) {
|
||||||
|
$message = 'Creating Backup before Plugins Update failed!';
|
||||||
|
if ($player) {
|
||||||
|
$this->maniaControl->chat->sendError($message, $player);
|
||||||
|
}
|
||||||
|
$this->maniaControl->log($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($pluginsUpdates as $pluginUpdateData) {
|
||||||
|
$this->installPlugin($pluginUpdateData, $player, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for Plugin Updates
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getPluginsUpdates() {
|
||||||
|
$url = ManiaControl::URL_WEBSERVICE . 'plugins';
|
||||||
|
$dataJson = FileUtil::loadFile($url);
|
||||||
|
$pluginData = json_decode($dataJson);
|
||||||
|
if (!$pluginData || empty($pluginData)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pluginsUpdates = $this->parsePluginsData($pluginData);
|
||||||
|
|
||||||
|
$updates = array();
|
||||||
|
$pluginClasses = $this->maniaControl->pluginManager->getPluginClasses();
|
||||||
|
foreach ($pluginClasses as $pluginClass) {
|
||||||
|
/**
|
||||||
|
* @var Plugin $pluginClass
|
||||||
|
*/
|
||||||
|
$pluginId = $pluginClass::getId();
|
||||||
|
if (isset($pluginsUpdates[$pluginId])) {
|
||||||
|
/** @var PluginUpdateData $pluginUpdateData */
|
||||||
|
$pluginUpdateData = $pluginsUpdates[$pluginId];
|
||||||
|
$pluginVersion = $pluginClass::getVersion();
|
||||||
|
if ($pluginUpdateData->isNewerThan($pluginVersion)) {
|
||||||
|
$updates[$pluginId] = $pluginUpdateData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($updates)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return $updates;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the given Plugin Update Data
|
||||||
|
*
|
||||||
|
* @param PluginUpdateData $pluginUpdateData
|
||||||
|
* @param Player $player
|
||||||
|
* @param bool $update
|
||||||
|
*/
|
||||||
|
private function installPlugin(PluginUpdateData $pluginUpdateData, Player $player = null, $update = false) {
|
||||||
|
$self = $this;
|
||||||
|
$this->maniaControl->fileReader->loadFile($pluginUpdateData->url, function ($updateFileContent, $error) use (&$self, &$pluginUpdateData, &$player, &$update) {
|
||||||
|
$actionNoun = ($update ? 'Update' : 'Install');
|
||||||
|
$actionVerb = ($update ? 'Updating' : 'Installing');
|
||||||
|
$actionVerbDone = ($update ? 'updated' : 'installed');
|
||||||
|
|
||||||
|
$message = "Now {$actionVerb} '{$pluginUpdateData->pluginName}'...";
|
||||||
|
if ($player) {
|
||||||
|
$self->maniaControl->chat->sendInformation($message, $player);
|
||||||
|
}
|
||||||
|
$self->maniaControl->log($message);
|
||||||
|
|
||||||
|
$tempDir = FileUtil::getTempFolder();
|
||||||
|
$updateFileName = $tempDir . $pluginUpdateData->zipfile;
|
||||||
|
|
||||||
|
$bytes = file_put_contents($updateFileName, $updateFileContent);
|
||||||
|
if (!$bytes || $bytes <= 0) {
|
||||||
|
$message = "Plugin {$actionNoun} failed: Couldn't save {$actionNoun} Zip!";
|
||||||
|
if ($player) {
|
||||||
|
$self->maniaControl->chat->sendError($message, $player);
|
||||||
|
}
|
||||||
|
trigger_error($message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$zip = new \ZipArchive();
|
||||||
|
$result = $zip->open($updateFileName);
|
||||||
|
if ($result !== true) {
|
||||||
|
$message = "Plugin {$actionNoun} failed: Couldn't open {$actionNoun} Zip! ({$result})";
|
||||||
|
if ($player) {
|
||||||
|
$self->maniaControl->chat->sendError($message, $player);
|
||||||
|
}
|
||||||
|
trigger_error($message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$zip->extractTo(ManiaControlDir . '/plugins/');
|
||||||
|
$zip->close();
|
||||||
|
unlink($updateFileName);
|
||||||
|
FileUtil::removeTempFolder();
|
||||||
|
|
||||||
|
$messageExtra = '';
|
||||||
|
if ($update) {
|
||||||
|
$messageExtra = ' (Restart ManiaControl to load the new Version!)';
|
||||||
|
}
|
||||||
|
$message = "Successfully {$actionVerbDone} '{$pluginUpdateData->pluginName}'!{$messageExtra}";
|
||||||
|
if ($player) {
|
||||||
|
$self->maniaControl->chat->sendSuccess($message, $player);
|
||||||
|
}
|
||||||
|
$self->maniaControl->log($message);
|
||||||
|
|
||||||
|
if (!$update) {
|
||||||
|
$newPluginClasses = $self->maniaControl->pluginManager->loadPlugins();
|
||||||
|
if (empty($newPluginClasses)) {
|
||||||
|
$message = "Loading fresh installed Plugin '{$pluginUpdateData->pluginName}' failed!";
|
||||||
|
if ($player) {
|
||||||
|
$self->maniaControl->chat->sendError($message, $player);
|
||||||
|
}
|
||||||
|
$self->maniaControl->log($message);
|
||||||
|
} else {
|
||||||
|
$message = "Successfully loaded fresh installed Plugin '{$pluginUpdateData->pluginName}'!";
|
||||||
|
if ($player) {
|
||||||
|
$self->maniaControl->chat->sendSuccess($message, $player);
|
||||||
|
}
|
||||||
|
$self->maniaControl->log($message);
|
||||||
|
|
||||||
|
$menuId = $self->maniaControl->configurator->getMenuId('Install Plugins');
|
||||||
|
$self->maniaControl->configurator->reopenMenu($player, $menuId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle PlayerManialinkPageAnswer callback
|
* Handle PlayerManialinkPageAnswer callback
|
||||||
*
|
*
|
||||||
* @param array $callback
|
* @param array $callback
|
||||||
*/
|
*/
|
||||||
public function handleManialinkPageAnswer(array $callback) {
|
public function handleManialinkPageAnswer(array $callback) {
|
||||||
$actionId = $callback[1][2];
|
$actionId = $callback[1][2];
|
||||||
$update = (strpos($actionId, PluginMenu::ACTION_PREFIX_UPDATEPLUGIN) === 0);
|
$update = (strpos($actionId, PluginMenu::ACTION_PREFIX_UPDATEPLUGIN) === 0);
|
||||||
$install = (strpos($actionId, PluginInstallMenu::ACTION_PREFIX_INSTALLPLUGIN) === 0);
|
$install = (strpos($actionId, PluginInstallMenu::ACTION_PREFIX_INSTALLPLUGIN) === 0);
|
||||||
if (!$update && !$install) {
|
if (!$update && !$install) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$login = $callback[1][1];
|
$login = $callback[1][1];
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
|
|
||||||
if ($update) {
|
if ($update) {
|
||||||
$pluginClass = substr($actionId, strlen(PluginMenu::ACTION_PREFIX_UPDATEPLUGIN));
|
$pluginClass = substr($actionId, strlen(PluginMenu::ACTION_PREFIX_UPDATEPLUGIN));
|
||||||
if ($pluginClass == 'All') {
|
if ($pluginClass == 'All') {
|
||||||
$this->performPluginsUpdate($player);
|
$this->performPluginsUpdate($player);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$pluginUpdateData = $this->getPluginUpdate($pluginClass);
|
$pluginUpdateData = $this->getPluginUpdate($pluginClass);
|
||||||
if ($pluginUpdateData) {
|
if ($pluginUpdateData) {
|
||||||
$this->installPlugin($pluginUpdateData, $player, true);
|
$this->installPlugin($pluginUpdateData, $player, true);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$message = 'Error loading Plugin Update Data!';
|
$message = 'Error loading Plugin Update Data!';
|
||||||
$this->maniaControl->chat->sendError($message, $player);
|
$this->maniaControl->chat->sendError($message, $player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$pluginId = substr($actionId, strlen(PluginInstallMenu::ACTION_PREFIX_INSTALLPLUGIN));
|
$pluginId = substr($actionId, strlen(PluginInstallMenu::ACTION_PREFIX_INSTALLPLUGIN));
|
||||||
|
|
||||||
$url = ManiaControl::URL_WEBSERVICE . 'plugins?id=' . $pluginId;
|
$url = ManiaControl::URL_WEBSERVICE . 'plugins?id=' . $pluginId;
|
||||||
$self = $this;
|
$self = $this;
|
||||||
$this->maniaControl->fileReader->loadFile($url, function ($data, $error) use(&$self, &$player) {
|
$this->maniaControl->fileReader->loadFile($url, function ($data, $error) use (&$self, &$player) {
|
||||||
if ($error || !$data) {
|
if ($error || !$data) {
|
||||||
$message = "Error loading Plugin Install Data! {$error}";
|
$message = "Error loading Plugin Install Data! {$error}";
|
||||||
$self->maniaControl->chat->sendError($message, $player);
|
$self->maniaControl->chat->sendError($message, $player);
|
||||||
@ -129,273 +365,29 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if there are Outdated Plugins installed
|
|
||||||
*
|
|
||||||
* @param Player $player
|
|
||||||
*/
|
|
||||||
public function checkPluginsUpdate(Player $player = null) {
|
|
||||||
$message = 'Checking Plugins for newer Versions...';
|
|
||||||
if ($player) {
|
|
||||||
$this->maniaControl->chat->sendInformation($message, $player);
|
|
||||||
}
|
|
||||||
$this->maniaControl->log($message);
|
|
||||||
|
|
||||||
$self = $this;
|
|
||||||
$this->maniaControl->pluginManager->fetchPluginList(function ($data, $error) use(&$self, &$player) {
|
|
||||||
|
|
||||||
if (!$data || $error) {
|
|
||||||
$message = 'Error while checking Plugins for newer Versions!';
|
|
||||||
if ($player) {
|
|
||||||
$self->maniaControl->chat->sendError($message, $player);
|
|
||||||
}
|
|
||||||
$self->maniaControl->log($message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$pluginsData = $self->parsePluginsData($data);
|
|
||||||
$pluginClasses = $self->maniaControl->pluginManager->getPluginClasses();
|
|
||||||
$pluginUpdates = array();
|
|
||||||
|
|
||||||
foreach ($pluginClasses as $pluginClass) {
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @var Plugin $pluginClass
|
|
||||||
*/
|
|
||||||
$pluginId = $pluginClass::getId();
|
|
||||||
if (!isset($pluginsData[$pluginId])) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/** @var PluginUpdateData $pluginData */
|
|
||||||
$pluginData = $pluginsData[$pluginId];
|
|
||||||
$pluginVersion = $pluginClass::getVersion();
|
|
||||||
if ($pluginData->isNewerThan($pluginVersion)) {
|
|
||||||
$pluginUpdates[$pluginId] = $pluginData;
|
|
||||||
$message = "There is an Update of '{$pluginData->pluginName}' available! ('{$pluginClass}' - Version {$pluginData->version})";
|
|
||||||
if ($player) {
|
|
||||||
$self->maniaControl->chat->sendSuccess($message, $player);
|
|
||||||
}
|
|
||||||
$self->maniaControl->log($message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($pluginUpdates)) {
|
|
||||||
$message = 'Plugins Update Check completed: All Plugins are up-to-date!';
|
|
||||||
if ($player) {
|
|
||||||
$self->maniaControl->chat->sendSuccess($message, $player);
|
|
||||||
}
|
|
||||||
$self->maniaControl->log($message);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$updatesCount = count($pluginUpdates);
|
|
||||||
$message = "Plugins Update Check completed: There are {$updatesCount} Updates available!";
|
|
||||||
if ($player) {
|
|
||||||
$self->maniaControl->chat->sendSuccess($message, $player);
|
|
||||||
}
|
|
||||||
$self->maniaControl->log($message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform an Update of all outdated Plugins
|
|
||||||
*
|
|
||||||
* @param Player $player
|
|
||||||
*/
|
|
||||||
public function performPluginsUpdate(Player $player = null) {
|
|
||||||
$pluginsUpdates = $this->getPluginsUpdates();
|
|
||||||
if (empty($pluginsUpdates)) {
|
|
||||||
$message = 'There are no Plugin Updates available!';
|
|
||||||
if ($player) {
|
|
||||||
$this->maniaControl->chat->sendInformation($message, $player);
|
|
||||||
}
|
|
||||||
$this->maniaControl->log($message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$message = "Starting Plugins Updating...";
|
|
||||||
if ($player) {
|
|
||||||
$this->maniaControl->chat->sendInformation($message, $player);
|
|
||||||
}
|
|
||||||
$this->maniaControl->log($message);
|
|
||||||
|
|
||||||
$performBackup = $this->maniaControl->settingManager->getSetting($this->maniaControl->updateManager, UpdateManager::SETTING_PERFORM_BACKUPS);
|
|
||||||
if ($performBackup && !BackupUtil::performPluginsBackup()) {
|
|
||||||
$message = 'Creating Backup before Plugins Update failed!';
|
|
||||||
if ($player) {
|
|
||||||
$this->maniaControl->chat->sendError($message, $player);
|
|
||||||
}
|
|
||||||
$this->maniaControl->log($message);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($pluginsUpdates as $pluginUpdateData) {
|
|
||||||
$this->installPlugin($pluginUpdateData, $player, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check given Plugin Class for Update
|
* Check given Plugin Class for Update
|
||||||
*
|
*
|
||||||
* @param string $pluginClass
|
* @param string $pluginClass
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function getPluginUpdate($pluginClass) {
|
public function getPluginUpdate($pluginClass) {
|
||||||
$pluginClass = PluginManager::getPluginClass($pluginClass);
|
$pluginClass = PluginManager::getPluginClass($pluginClass);
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @var Plugin $pluginClass
|
* @var Plugin $pluginClass
|
||||||
*/
|
*/
|
||||||
$pluginId = $pluginClass::getId();
|
$pluginId = $pluginClass::getId();
|
||||||
$url = ManiaControl::URL_WEBSERVICE . 'plugins?id=' . $pluginId;
|
$url = ManiaControl::URL_WEBSERVICE . 'plugins?id=' . $pluginId;
|
||||||
$dataJson = FileUtil::loadFile($url);
|
$dataJson = FileUtil::loadFile($url);
|
||||||
$pluginVersions = json_decode($dataJson);
|
$pluginVersions = json_decode($dataJson);
|
||||||
if (!$pluginVersions || !isset($pluginVersions[0])) {
|
if (!$pluginVersions || !isset($pluginVersions[0])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$pluginUpdateData = new PluginUpdateData($pluginVersions[0]);
|
$pluginUpdateData = new PluginUpdateData($pluginVersions[0]);
|
||||||
$pluginVersion = $pluginClass::getVersion();
|
$pluginVersion = $pluginClass::getVersion();
|
||||||
if ($pluginUpdateData->isNewerThan($pluginVersion)) {
|
if ($pluginUpdateData->isNewerThan($pluginVersion)) {
|
||||||
return $pluginUpdateData;
|
return $pluginUpdateData;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an Array of Plugin Update Data from the given Web Service Result
|
|
||||||
*
|
|
||||||
* @param mixed $webServiceResult
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function parsePluginsData($webServiceResult) {
|
|
||||||
if (!$webServiceResult || !is_array($webServiceResult)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$pluginsData = array();
|
|
||||||
foreach ($webServiceResult as $pluginResult) {
|
|
||||||
$pluginData = new PluginUpdateData($pluginResult);
|
|
||||||
$pluginsData[$pluginData->pluginId] = $pluginData;
|
|
||||||
}
|
|
||||||
return $pluginsData;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check for Plugin Updates
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function getPluginsUpdates() {
|
|
||||||
$url = ManiaControl::URL_WEBSERVICE . 'plugins';
|
|
||||||
$dataJson = FileUtil::loadFile($url);
|
|
||||||
$pluginData = json_decode($dataJson);
|
|
||||||
if (!$pluginData || empty($pluginData)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$pluginsUpdates = $this->parsePluginsData($pluginData);
|
|
||||||
|
|
||||||
$updates = array();
|
|
||||||
$pluginClasses = $this->maniaControl->pluginManager->getPluginClasses();
|
|
||||||
foreach ($pluginClasses as $pluginClass) {
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @var Plugin $pluginClass
|
|
||||||
*/
|
|
||||||
$pluginId = $pluginClass::getId();
|
|
||||||
if (isset($pluginsUpdates[$pluginId])) {
|
|
||||||
/** @var PluginUpdateData $pluginUpdateData */
|
|
||||||
$pluginUpdateData = $pluginsUpdates[$pluginId];
|
|
||||||
$pluginVersion = $pluginClass::getVersion();
|
|
||||||
if ($pluginUpdateData->isNewerThan($pluginVersion)) {
|
|
||||||
$updates[$pluginId] = $pluginUpdateData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($updates)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return $updates;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load the given Plugin Update Data
|
|
||||||
*
|
|
||||||
* @param PluginUpdateData $pluginUpdateData
|
|
||||||
* @param Player $player
|
|
||||||
* @param bool $update
|
|
||||||
*/
|
|
||||||
private function installPlugin(PluginUpdateData $pluginUpdateData, Player $player = null, $update = false) {
|
|
||||||
$self = $this;
|
|
||||||
$this->maniaControl->fileReader->loadFile($pluginUpdateData->url, function ($updateFileContent, $error) use(&$self, &$pluginUpdateData, &$player, &$update) {
|
|
||||||
$actionNoun = ($update ? 'Update' : 'Install');
|
|
||||||
$actionVerb = ($update ? 'Updating' : 'Installing');
|
|
||||||
$actionVerbDone = ($update ? 'updated' : 'installed');
|
|
||||||
|
|
||||||
$message = "Now {$actionVerb} '{$pluginUpdateData->pluginName}'...";
|
|
||||||
if ($player) {
|
|
||||||
$self->maniaControl->chat->sendInformation($message, $player);
|
|
||||||
}
|
|
||||||
$self->maniaControl->log($message);
|
|
||||||
|
|
||||||
$tempDir = FileUtil::getTempFolder();
|
|
||||||
$updateFileName = $tempDir . $pluginUpdateData->zipfile;
|
|
||||||
|
|
||||||
$bytes = file_put_contents($updateFileName, $updateFileContent);
|
|
||||||
if (!$bytes || $bytes <= 0) {
|
|
||||||
$message = "Plugin {$actionNoun} failed: Couldn't save {$actionNoun} Zip!";
|
|
||||||
if ($player) {
|
|
||||||
$self->maniaControl->chat->sendError($message, $player);
|
|
||||||
}
|
|
||||||
trigger_error($message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$zip = new \ZipArchive();
|
|
||||||
$result = $zip->open($updateFileName);
|
|
||||||
if ($result !== true) {
|
|
||||||
$message = "Plugin {$actionNoun} failed: Couldn't open {$actionNoun} Zip! ({$result})";
|
|
||||||
if ($player) {
|
|
||||||
$self->maniaControl->chat->sendError($message, $player);
|
|
||||||
}
|
|
||||||
trigger_error($message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$zip->extractTo(ManiaControlDir . '/plugins/');
|
|
||||||
$zip->close();
|
|
||||||
unlink($updateFileName);
|
|
||||||
FileUtil::removeTempFolder();
|
|
||||||
|
|
||||||
$messageExtra = '';
|
|
||||||
if ($update) {
|
|
||||||
$messageExtra = ' (Restart ManiaControl to load the new Version!)';
|
|
||||||
}
|
|
||||||
$message = "Successfully {$actionVerbDone} '{$pluginUpdateData->pluginName}'!{$messageExtra}";
|
|
||||||
if ($player) {
|
|
||||||
$self->maniaControl->chat->sendSuccess($message, $player);
|
|
||||||
}
|
|
||||||
$self->maniaControl->log($message);
|
|
||||||
|
|
||||||
if (!$update) {
|
|
||||||
$newPluginClasses = $self->maniaControl->pluginManager->loadPlugins();
|
|
||||||
if (empty($newPluginClasses)) {
|
|
||||||
$message = "Loading fresh installed Plugin '{$pluginUpdateData->pluginName}' failed!";
|
|
||||||
if ($player) {
|
|
||||||
$self->maniaControl->chat->sendError($message, $player);
|
|
||||||
}
|
|
||||||
$self->maniaControl->log($message);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$message = "Successfully loaded fresh installed Plugin '{$pluginUpdateData->pluginName}'!";
|
|
||||||
if ($player) {
|
|
||||||
$self->maniaControl->chat->sendSuccess($message, $player);
|
|
||||||
}
|
|
||||||
$self->maniaControl->log($message);
|
|
||||||
|
|
||||||
$menuId = $self->maniaControl->configurator->getMenuId('Install Plugins');
|
|
||||||
$self->maniaControl->configurator->reopenMenu($player, $menuId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,10 @@ namespace ManiaControl\Update;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Update Data Structure
|
* Update Data Structure
|
||||||
*
|
*
|
||||||
* @author ManiaControl Team
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class UpdateData {
|
class UpdateData {
|
||||||
/*
|
/*
|
||||||
@ -21,20 +21,20 @@ class UpdateData {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct new Update Data
|
* Construct new Update Data
|
||||||
*
|
*
|
||||||
* @param object $updateData
|
* @param object $updateData
|
||||||
*/
|
*/
|
||||||
public function __construct($updateData) {
|
public function __construct($updateData) {
|
||||||
$this->version = $updateData->version;
|
$this->version = $updateData->version;
|
||||||
$this->channel = $updateData->channel;
|
$this->channel = $updateData->channel;
|
||||||
$this->url = $updateData->url;
|
$this->url = $updateData->url;
|
||||||
$this->releaseDate = $updateData->release_date;
|
$this->releaseDate = $updateData->release_date;
|
||||||
$this->minDedicatedBuild = $updateData->min_dedicated_build;
|
$this->minDedicatedBuild = $updateData->min_dedicated_build;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the Update Data is newer than the given Date
|
* Check if the Update Data is newer than the given Date
|
||||||
*
|
*
|
||||||
* @param string $compareDate
|
* @param string $compareDate
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@ -6,45 +6,44 @@ use ManiaControl\Admin\AuthenticationManager;
|
|||||||
use ManiaControl\Callbacks\CallbackListener;
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
use ManiaControl\Callbacks\TimerListener;
|
use ManiaControl\Callbacks\TimerListener;
|
||||||
use ManiaControl\Commands\CommandListener;
|
use ManiaControl\Commands\CommandListener;
|
||||||
|
use ManiaControl\Files\BackupUtil;
|
||||||
use ManiaControl\Files\FileUtil;
|
use ManiaControl\Files\FileUtil;
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
use ManiaControl\Players\PlayerManager;
|
use ManiaControl\Players\PlayerManager;
|
||||||
use ManiaControl\Files\BackupUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manager checking for ManiaControl Core Updates
|
* Manager checking for ManiaControl Core Updates
|
||||||
*
|
*
|
||||||
* @author ManiaControl Team
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class UpdateManager implements CallbackListener, CommandListener, TimerListener {
|
class UpdateManager implements CallbackListener, CommandListener, TimerListener {
|
||||||
/*
|
/*
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const SETTING_ENABLEUPDATECHECK = 'Enable Automatic Core Update Check';
|
const SETTING_ENABLEUPDATECHECK = 'Enable Automatic Core Update Check';
|
||||||
const SETTING_UPDATECHECK_INTERVAL = 'Core Update Check Interval (Hours)';
|
const SETTING_UPDATECHECK_INTERVAL = 'Core Update Check Interval (Hours)';
|
||||||
const SETTING_UPDATECHECK_CHANNEL = 'Core Update Channel (release, beta, nightly)';
|
const SETTING_UPDATECHECK_CHANNEL = 'Core Update Channel (release, beta, nightly)';
|
||||||
const SETTING_PERFORM_BACKUPS = 'Perform Backup before Updating';
|
const SETTING_PERFORM_BACKUPS = 'Perform Backup before Updating';
|
||||||
const SETTING_AUTO_UPDATE = 'Perform update automatically';
|
const SETTING_AUTO_UPDATE = 'Perform update automatically';
|
||||||
const SETTING_PERMISSION_UPDATE = 'Update Core';
|
const SETTING_PERMISSION_UPDATE = 'Update Core';
|
||||||
const SETTING_PERMISSION_UPDATECHECK = 'Check Core Update';
|
const SETTING_PERMISSION_UPDATECHECK = 'Check Core Update';
|
||||||
const CHANNEL_RELEASE = 'release';
|
const CHANNEL_RELEASE = 'release';
|
||||||
const CHANNEL_BETA = 'beta';
|
const CHANNEL_BETA = 'beta';
|
||||||
const CHANNEL_NIGHTLY = 'nightly';
|
const CHANNEL_NIGHTLY = 'nightly';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Public Properties
|
* Public Properties
|
||||||
*/
|
*/
|
||||||
public $pluginUpdateManager = null;
|
public $pluginUpdateManager = null;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Private Properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
private $maniaControl = null;
|
private $maniaControl = null;
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @var UpdateData $coreUpdateData
|
* @var UpdateData $coreUpdateData
|
||||||
*/
|
*/
|
||||||
private $coreUpdateData = null;
|
private $coreUpdateData = null;
|
||||||
@ -52,47 +51,40 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Update Manager
|
* Create a new Update Manager
|
||||||
*
|
*
|
||||||
* @param ManiaControl $maniaControl
|
* @param ManiaControl $maniaControl
|
||||||
*/
|
*/
|
||||||
public function __construct(ManiaControl $maniaControl) {
|
public function __construct(ManiaControl $maniaControl) {
|
||||||
$this->maniaControl = $maniaControl;
|
$this->maniaControl = $maniaControl;
|
||||||
|
|
||||||
// Init settings
|
// Init settings
|
||||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_ENABLEUPDATECHECK, true);
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_ENABLEUPDATECHECK, true);
|
||||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_AUTO_UPDATE, true);
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_AUTO_UPDATE, true);
|
||||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_UPDATECHECK_INTERVAL, 1);
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_UPDATECHECK_INTERVAL, 1);
|
||||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_UPDATECHECK_CHANNEL, self::CHANNEL_BETA);
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_UPDATECHECK_CHANNEL, self::CHANNEL_BETA);
|
||||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_PERFORM_BACKUPS, true);
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_PERFORM_BACKUPS, true);
|
||||||
|
|
||||||
// Register for callbacks
|
// Register for callbacks
|
||||||
$updateInterval = $this->maniaControl->settingManager->getSetting($this, self::SETTING_UPDATECHECK_INTERVAL);
|
$updateInterval = $this->maniaControl->settingManager->getSetting($this, self::SETTING_UPDATECHECK_INTERVAL);
|
||||||
$this->maniaControl->timerManager->registerTimerListening($this, 'hourlyUpdateCheck', 1000 * 60 * 60 * $updateInterval);
|
$this->maniaControl->timerManager->registerTimerListening($this, 'hourlyUpdateCheck', 1000 * 60 * 60 * $updateInterval);
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined');
|
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined');
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
|
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
|
||||||
|
|
||||||
// define Permissions
|
// define Permissions
|
||||||
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_UPDATE, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_UPDATE, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||||
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_UPDATECHECK, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_UPDATECHECK, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
||||||
|
|
||||||
// Register for chat commands
|
// Register for chat commands
|
||||||
$this->maniaControl->commandManager->registerCommandListener('checkupdate', $this, 'handle_CheckUpdate', true, 'Checks if there is a core update.');
|
$this->maniaControl->commandManager->registerCommandListener('checkupdate', $this, 'handle_CheckUpdate', true, 'Checks if there is a core update.');
|
||||||
$this->maniaControl->commandManager->registerCommandListener('coreupdate', $this, 'handle_CoreUpdate', true, 'Performs the core update.');
|
$this->maniaControl->commandManager->registerCommandListener('coreupdate', $this, 'handle_CoreUpdate', true, 'Performs the core update.');
|
||||||
|
|
||||||
// Plugin update manager
|
// Plugin update manager
|
||||||
$this->pluginUpdateManager = new PluginUpdateManager($maniaControl);
|
$this->pluginUpdateManager = new PluginUpdateManager($maniaControl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Start an Update Check
|
|
||||||
*/
|
|
||||||
public function checkUpdate() {
|
|
||||||
$this->checkCoreUpdateAsync(array($this, 'handleUpdateCheck'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform Hourly Update Check
|
* Perform Hourly Update Check
|
||||||
*
|
*
|
||||||
* @param $time
|
* @param $time
|
||||||
*/
|
*/
|
||||||
public function hourlyUpdateCheck($time) {
|
public function hourlyUpdateCheck($time) {
|
||||||
@ -104,9 +96,59 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
$this->checkUpdate();
|
$this->checkUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Core Update Data
|
||||||
|
*
|
||||||
|
* @param UpdateData $coreUpdateData
|
||||||
|
*/
|
||||||
|
public function setCoreUpdateData(UpdateData $coreUpdateData = null) {
|
||||||
|
$this->coreUpdateData = $coreUpdateData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start an Update Check
|
||||||
|
*/
|
||||||
|
public function checkUpdate() {
|
||||||
|
$this->checkCoreUpdateAsync(array($this, 'handleUpdateCheck'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks a Core Update asynchronously
|
||||||
|
*
|
||||||
|
* @param callable $function
|
||||||
|
*/
|
||||||
|
private function checkCoreUpdateAsync($function) {
|
||||||
|
$updateChannel = $this->getCurrentUpdateChannelSetting();
|
||||||
|
$url = ManiaControl::URL_WEBSERVICE . 'versions?current=1&channel=' . $updateChannel;
|
||||||
|
|
||||||
|
$this->maniaControl->fileReader->loadFile($url, function ($dataJson, $error) use (&$function) {
|
||||||
|
$versions = json_decode($dataJson);
|
||||||
|
if (!$versions || !isset($versions[0])) {
|
||||||
|
call_user_func($function, null);
|
||||||
|
} else {
|
||||||
|
$updateData = new UpdateData($versions[0]);
|
||||||
|
call_user_func($function, $updateData);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the Update Channel Setting
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function getCurrentUpdateChannelSetting() {
|
||||||
|
$updateChannel = $this->maniaControl->settingManager->getSetting($this, self::SETTING_UPDATECHECK_CHANNEL);
|
||||||
|
$updateChannel = strtolower($updateChannel);
|
||||||
|
if (!in_array($updateChannel, array(self::CHANNEL_RELEASE, self::CHANNEL_BETA, self::CHANNEL_NIGHTLY))) {
|
||||||
|
$updateChannel = self::CHANNEL_RELEASE;
|
||||||
|
}
|
||||||
|
return $updateChannel;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle the fetched Update Data
|
* Handle the fetched Update Data
|
||||||
*
|
*
|
||||||
* @param UpdateData $updateData
|
* @param UpdateData $updateData
|
||||||
*/
|
*/
|
||||||
public function handleUpdateCheck(UpdateData $updateData) {
|
public function handleUpdateCheck(UpdateData $updateData) {
|
||||||
@ -119,21 +161,20 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
$this->maniaControl->log("Please update Your Server to '{$updateData->minDedicatedBuild}' in order to receive further Updates!");
|
$this->maniaControl->log("Please update Your Server to '{$updateData->minDedicatedBuild}' in order to receive further Updates!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->isNightlyUpdateChannel()) {
|
if ($this->isNightlyUpdateChannel()) {
|
||||||
$this->maniaControl->log("New Nightly Build ({$updateData->releaseDate}) available!");
|
$this->maniaControl->log("New Nightly Build ({$updateData->releaseDate}) available!");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$this->maniaControl->log("New ManiaControl Version {$updateData->version} available!");
|
$this->maniaControl->log("New ManiaControl Version {$updateData->version} available!");
|
||||||
}
|
}
|
||||||
$this->setCoreUpdateData($updateData);
|
$this->setCoreUpdateData($updateData);
|
||||||
|
|
||||||
$this->checkAutoUpdate();
|
$this->checkAutoUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the given Update Data has a new Version and fits for the Server
|
* Check if the given Update Data has a new Version and fits for the Server
|
||||||
*
|
*
|
||||||
* @param UpdateData $updateData
|
* @param UpdateData $updateData
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -142,20 +183,48 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
// Data corrupted
|
// Data corrupted
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$isNightly = $this->isNightlyUpdateChannel();
|
$isNightly = $this->isNightlyUpdateChannel();
|
||||||
$buildDate = $this->getNightlyBuildDate();
|
$buildDate = $this->getNightlyBuildDate();
|
||||||
|
|
||||||
if ($isNightly || $buildDate) {
|
if ($isNightly || $buildDate) {
|
||||||
return $updateData->isNewerThan($buildDate);
|
return $updateData->isNewerThan($buildDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ($updateData->version > ManiaControl::VERSION);
|
return ($updateData->version > ManiaControl::VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if ManiaControl is running the Nightly Update Channel
|
||||||
|
*
|
||||||
|
* @param string $updateChannel
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isNightlyUpdateChannel($updateChannel = null) {
|
||||||
|
if (!$updateChannel) {
|
||||||
|
$updateChannel = $this->getCurrentUpdateChannelSetting();
|
||||||
|
}
|
||||||
|
return ($updateChannel === self::CHANNEL_NIGHTLY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Build Date of the local Nightly Build Version
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getNightlyBuildDate() {
|
||||||
|
if (!$this->currentBuildDate) {
|
||||||
|
$nightlyBuildDateFile = ManiaControlDir . '/core/nightly_build.txt';
|
||||||
|
if (file_exists($nightlyBuildDateFile)) {
|
||||||
|
$this->currentBuildDate = file_get_contents($nightlyBuildDateFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->currentBuildDate;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the Update Data is compatible with the Server
|
* Check if the Update Data is compatible with the Server
|
||||||
*
|
*
|
||||||
* @param UpdateData $updateData
|
* @param UpdateData $updateData
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -164,56 +233,16 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
// Data corrupted
|
// Data corrupted
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$version = $this->maniaControl->client->getVersion();
|
$version = $this->maniaControl->client->getVersion();
|
||||||
if ($updateData->minDedicatedBuild > $version->build) {
|
if ($updateData->minDedicatedBuild > $version->build) {
|
||||||
// Server not compatible
|
// Server not compatible
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set Core Update Data
|
|
||||||
*
|
|
||||||
* @param UpdateData $coreUpdateData
|
|
||||||
*/
|
|
||||||
public function setCoreUpdateData(UpdateData $coreUpdateData = null) {
|
|
||||||
$this->coreUpdateData = $coreUpdateData;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle ManiaControl PlayerJoined callback
|
|
||||||
*
|
|
||||||
* @param Player $player
|
|
||||||
*/
|
|
||||||
public function handlePlayerJoined(Player $player) {
|
|
||||||
if (!$this->coreUpdateData) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Announce available update
|
|
||||||
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_UPDATE)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->isNightlyUpdateChannel()) {
|
|
||||||
$this->maniaControl->chat->sendSuccess('New Nightly Build (' . $this->coreUpdateData->releaseDate . ') available!', $player->login);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$this->maniaControl->chat->sendInformation('New ManiaControl Version ' . $this->coreUpdateData->version . ' available!', $player->login);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle Player Disconnect Callback
|
|
||||||
*
|
|
||||||
* @param Player $player
|
|
||||||
*/
|
|
||||||
public function handlePlayerDisconnect(Player $player) {
|
|
||||||
$this->checkAutoUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if an automatic Update should be performed
|
* Check if an automatic Update should be performed
|
||||||
*/
|
*/
|
||||||
@ -231,145 +260,13 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
// Server not empty
|
// Server not empty
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->performCoreUpdate();
|
$this->performCoreUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle //checkupdate command
|
|
||||||
*
|
|
||||||
* @param array $chatCallback
|
|
||||||
* @param Player $player
|
|
||||||
*/
|
|
||||||
public function handle_CheckUpdate(array $chatCallback, Player $player) {
|
|
||||||
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_UPDATECHECK)) {
|
|
||||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$self = $this;
|
|
||||||
$this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use(&$self, &$player) {
|
|
||||||
if (!$self->checkUpdateData($updateData)) {
|
|
||||||
$self->maniaControl->chat->sendInformation('No Update available!', $player->login);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$self->checkUpdateDataBuildVersion($updateData)) {
|
|
||||||
$self->maniaControl->chat->sendError("Please update Your Server to '{$updateData->minDedicatedBuild}' in order to receive further Updates!", $player->login);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$isNightly = $self->isNightlyUpdateChannel();
|
|
||||||
if ($isNightly) {
|
|
||||||
$buildDate = $self->getNightlyBuildDate();
|
|
||||||
if ($buildDate) {
|
|
||||||
if ($updateData->isNewerThan($buildDate)) {
|
|
||||||
$self->maniaControl->chat->sendInformation("No new Build available! (Current Build: '{$buildDate}')", $player->login);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$self->maniaControl->chat->sendSuccess("New Nightly Build ({$updateData->releaseDate}) available! (Current Build: '{$buildDate}')", $player->login);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$self->maniaControl->chat->sendSuccess("New Nightly Build ('{$updateData->releaseDate}') available!", $player->login);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$self->maniaControl->chat->sendSuccess('Update for Version ' . $updateData->version . ' available!', $player->login);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the Build Date of the local Nightly Build Version
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getNightlyBuildDate() {
|
|
||||||
if (!$this->currentBuildDate) {
|
|
||||||
$nightlyBuildDateFile = ManiaControlDir . '/core/nightly_build.txt';
|
|
||||||
if (file_exists($nightlyBuildDateFile)) {
|
|
||||||
$this->currentBuildDate = file_get_contents($nightlyBuildDateFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $this->currentBuildDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the Build Date of the local Nightly Build Version
|
|
||||||
*
|
|
||||||
* @param string $date
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function setNightlyBuildDate($date) {
|
|
||||||
$nightlyBuildDateFile = ManiaControlDir . '/core/nightly_build.txt';
|
|
||||||
$success = (bool) file_put_contents($nightlyBuildDateFile, $date);
|
|
||||||
$this->currentBuildDate = $date;
|
|
||||||
return $success;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle //coreupdate command
|
|
||||||
*
|
|
||||||
* @param array $chatCallback
|
|
||||||
* @param Player $player
|
|
||||||
*/
|
|
||||||
public function handle_CoreUpdate(array $chatCallback, Player $player) {
|
|
||||||
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_UPDATE)) {
|
|
||||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$self = $this;
|
|
||||||
$this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use(&$self, &$player) {
|
|
||||||
if (!$updateData) {
|
|
||||||
$self->maniaControl->chat->sendError('Update is currently not possible!', $player->login);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!$self->checkUpdateDataBuildVersion($updateData)) {
|
|
||||||
$self->maniaControl->chat->sendError("The Next ManiaControl Update requires a newer Dedicated Server Version!", $player->login);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$message = "Starting Update to Version v{$updateData->version}...";
|
|
||||||
$self->maniaControl->chat->sendInformation($message, $player->login);
|
|
||||||
$self->maniaControl->log($message);
|
|
||||||
|
|
||||||
$performBackup = $self->maniaControl->settingManager->getSetting($self, UpdateManager::SETTING_PERFORM_BACKUPS);
|
|
||||||
if ($performBackup && !BackupUtil::performFullBackup()) {
|
|
||||||
$message = 'Creating Backup failed!';
|
|
||||||
$self->maniaControl->chat->sendError($message, $player->login);
|
|
||||||
$self->maniaControl->log($message);
|
|
||||||
}
|
|
||||||
|
|
||||||
$self->performCoreUpdate($player);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks a Core Update asynchronously
|
|
||||||
*
|
|
||||||
* @param callable $function
|
|
||||||
*/
|
|
||||||
private function checkCoreUpdateAsync($function) {
|
|
||||||
$updateChannel = $this->getCurrentUpdateChannelSetting();
|
|
||||||
$url = ManiaControl::URL_WEBSERVICE . 'versions?current=1&channel=' . $updateChannel;
|
|
||||||
|
|
||||||
$this->maniaControl->fileReader->loadFile($url, function ($dataJson, $error) use(&$function) {
|
|
||||||
$versions = json_decode($dataJson);
|
|
||||||
if (!$versions || !isset($versions[0])) {
|
|
||||||
call_user_func($function, null);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$updateData = new UpdateData($versions[0]);
|
|
||||||
call_user_func($function, $updateData);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform a Core Update
|
* Perform a Core Update
|
||||||
*
|
*
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -382,9 +279,9 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
$this->maniaControl->log($message);
|
$this->maniaControl->log($message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->maniaControl->log("Starting Update to Version v{$this->coreUpdateData->version}...");
|
$this->maniaControl->log("Starting Update to Version v{$this->coreUpdateData->version}...");
|
||||||
|
|
||||||
$directories = array('/core/', '/plugins/');
|
$directories = array('/core/', '/plugins/');
|
||||||
if (!FileUtil::checkWritePermissions($directories)) {
|
if (!FileUtil::checkWritePermissions($directories)) {
|
||||||
$message = 'Update not possible: Incorrect File System Permissions!';
|
$message = 'Update not possible: Incorrect File System Permissions!';
|
||||||
@ -394,7 +291,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
$this->maniaControl->log($message);
|
$this->maniaControl->log($message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$performBackup = $this->maniaControl->settingManager->getSetting($this, self::SETTING_PERFORM_BACKUPS);
|
$performBackup = $this->maniaControl->settingManager->getSetting($this, self::SETTING_PERFORM_BACKUPS);
|
||||||
if ($performBackup && !BackupUtil::performFullBackup()) {
|
if ($performBackup && !BackupUtil::performFullBackup()) {
|
||||||
$message = 'Creating Backup before Update failed!';
|
$message = 'Creating Backup before Update failed!';
|
||||||
@ -403,12 +300,12 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
}
|
}
|
||||||
$this->maniaControl->log($message);
|
$this->maniaControl->log($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
$self = $this;
|
$self = $this;
|
||||||
$this->maniaControl->fileReader->loadFile($this->coreUpdateData->url, function ($updateFileContent, $error) use(&$self, &$updateData, &$player) {
|
$this->maniaControl->fileReader->loadFile($this->coreUpdateData->url, function ($updateFileContent, $error) use (&$self, &$updateData, &$player) {
|
||||||
$tempDir = FileUtil::getTempFolder();
|
$tempDir = FileUtil::getTempFolder();
|
||||||
$updateFileName = $tempDir . basename($updateData->url);
|
$updateFileName = $tempDir . basename($updateData->url);
|
||||||
|
|
||||||
$bytes = file_put_contents($updateFileName, $updateFileContent);
|
$bytes = file_put_contents($updateFileName, $updateFileContent);
|
||||||
if (!$bytes || $bytes <= 0) {
|
if (!$bytes || $bytes <= 0) {
|
||||||
$message = "Update failed: Couldn't save Update zip!";
|
$message = "Update failed: Couldn't save Update zip!";
|
||||||
@ -418,8 +315,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
logMessage($message);
|
logMessage($message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$zip = new \ZipArchive();
|
$zip = new \ZipArchive();
|
||||||
$result = $zip->open($updateFileName);
|
$result = $zip->open($updateFileName);
|
||||||
if ($result !== true) {
|
if ($result !== true) {
|
||||||
trigger_error("Couldn't open Update Zip. ({$result})");
|
trigger_error("Couldn't open Update Zip. ({$result})");
|
||||||
@ -428,51 +325,147 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$zip->extractTo(ManiaControlDir);
|
$zip->extractTo(ManiaControlDir);
|
||||||
$zip->close();
|
$zip->close();
|
||||||
unlink($updateFileName);
|
unlink($updateFileName);
|
||||||
FileUtil::removeTempFolder();
|
FileUtil::removeTempFolder();
|
||||||
|
|
||||||
// Set the Nightly Build Date
|
// Set the Nightly Build Date
|
||||||
$self->setNightlyBuildDate($updateData->releaseDate);
|
$self->setNightlyBuildDate($updateData->releaseDate);
|
||||||
|
|
||||||
$message = 'Update finished!';
|
$message = 'Update finished!';
|
||||||
if ($player) {
|
if ($player) {
|
||||||
$self->maniaControl->chat->sendSuccess($message, $player);
|
$self->maniaControl->chat->sendSuccess($message, $player);
|
||||||
}
|
}
|
||||||
$self->maniaControl->log($message);
|
$self->maniaControl->log($message);
|
||||||
|
|
||||||
$self->maniaControl->restart();
|
$self->maniaControl->restart();
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if ManiaControl is running the Nightly Update Channel
|
* Set the Build Date of the local Nightly Build Version
|
||||||
*
|
*
|
||||||
* @param string $updateChannel
|
* @param string $date
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isNightlyUpdateChannel($updateChannel = null) {
|
private function setNightlyBuildDate($date) {
|
||||||
if (!$updateChannel) {
|
$nightlyBuildDateFile = ManiaControlDir . '/core/nightly_build.txt';
|
||||||
$updateChannel = $this->getCurrentUpdateChannelSetting();
|
$success = (bool)file_put_contents($nightlyBuildDateFile, $date);
|
||||||
}
|
$this->currentBuildDate = $date;
|
||||||
return ($updateChannel === self::CHANNEL_NIGHTLY);
|
return $success;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the Update Channel Setting
|
* Handle ManiaControl PlayerJoined callback
|
||||||
*
|
*
|
||||||
* @return string
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
private function getCurrentUpdateChannelSetting() {
|
public function handlePlayerJoined(Player $player) {
|
||||||
$updateChannel = $this->maniaControl->settingManager->getSetting($this, self::SETTING_UPDATECHECK_CHANNEL);
|
if (!$this->coreUpdateData) {
|
||||||
$updateChannel = strtolower($updateChannel);
|
return;
|
||||||
if (!in_array($updateChannel, array(self::CHANNEL_RELEASE, self::CHANNEL_BETA, self::CHANNEL_NIGHTLY))) {
|
|
||||||
$updateChannel = self::CHANNEL_RELEASE;
|
|
||||||
}
|
}
|
||||||
return $updateChannel;
|
// Announce available update
|
||||||
|
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_UPDATE)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->isNightlyUpdateChannel()) {
|
||||||
|
$this->maniaControl->chat->sendSuccess('New Nightly Build (' . $this->coreUpdateData->releaseDate . ') available!', $player->login);
|
||||||
|
} else {
|
||||||
|
$this->maniaControl->chat->sendInformation('New ManiaControl Version ' . $this->coreUpdateData->version . ' available!', $player->login);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle Player Disconnect Callback
|
||||||
|
*
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
public function handlePlayerDisconnect(Player $player) {
|
||||||
|
$this->checkAutoUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle //checkupdate command
|
||||||
|
*
|
||||||
|
* @param array $chatCallback
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
public function handle_CheckUpdate(array $chatCallback, Player $player) {
|
||||||
|
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_UPDATECHECK)) {
|
||||||
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$self = $this;
|
||||||
|
$this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$self, &$player) {
|
||||||
|
if (!$self->checkUpdateData($updateData)) {
|
||||||
|
$self->maniaControl->chat->sendInformation('No Update available!', $player->login);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$self->checkUpdateDataBuildVersion($updateData)) {
|
||||||
|
$self->maniaControl->chat->sendError("Please update Your Server to '{$updateData->minDedicatedBuild}' in order to receive further Updates!", $player->login);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$isNightly = $self->isNightlyUpdateChannel();
|
||||||
|
if ($isNightly) {
|
||||||
|
$buildDate = $self->getNightlyBuildDate();
|
||||||
|
if ($buildDate) {
|
||||||
|
if ($updateData->isNewerThan($buildDate)) {
|
||||||
|
$self->maniaControl->chat->sendInformation("No new Build available! (Current Build: '{$buildDate}')", $player->login);
|
||||||
|
} else {
|
||||||
|
$self->maniaControl->chat->sendSuccess("New Nightly Build ({$updateData->releaseDate}) available! (Current Build: '{$buildDate}')", $player->login);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$self->maniaControl->chat->sendSuccess("New Nightly Build ('{$updateData->releaseDate}') available!", $player->login);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$self->maniaControl->chat->sendSuccess('Update for Version ' . $updateData->version . ' available!', $player->login);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle //coreupdate command
|
||||||
|
*
|
||||||
|
* @param array $chatCallback
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
public function handle_CoreUpdate(array $chatCallback, Player $player) {
|
||||||
|
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_UPDATE)) {
|
||||||
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$self = $this;
|
||||||
|
$this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$self, &$player) {
|
||||||
|
if (!$updateData) {
|
||||||
|
$self->maniaControl->chat->sendError('Update is currently not possible!', $player->login);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!$self->checkUpdateDataBuildVersion($updateData)) {
|
||||||
|
$self->maniaControl->chat->sendError("The Next ManiaControl Update requires a newer Dedicated Server Version!", $player->login);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$message = "Starting Update to Version v{$updateData->version}...";
|
||||||
|
$self->maniaControl->chat->sendInformation($message, $player->login);
|
||||||
|
$self->maniaControl->log($message);
|
||||||
|
|
||||||
|
$performBackup = $self->maniaControl->settingManager->getSetting($self, UpdateManager::SETTING_PERFORM_BACKUPS);
|
||||||
|
if ($performBackup && !BackupUtil::performFullBackup()) {
|
||||||
|
$message = 'Creating Backup failed!';
|
||||||
|
$self->maniaControl->chat->sendError($message, $player->login);
|
||||||
|
$self->maniaControl->log($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->performCoreUpdate($player);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user