removed old timed callbacks
This commit is contained in:
committed by
Steffen Schröder
parent
620807c419
commit
1c0dd7e83d
@ -15,9 +15,6 @@ class CallbackManager {
|
||||
* Constants
|
||||
*/
|
||||
// ManiaControl callbacks
|
||||
const CB_MC_1_SECOND = 'ManiaControl.1Second';
|
||||
const CB_MC_5_SECOND = 'ManiaControl.5Second';
|
||||
const CB_MC_1_MINUTE = 'ManiaControl.1Minute';
|
||||
const CB_MC_ONINIT = 'ManiaControl.OnInit';
|
||||
const CB_MC_ONSHUTDOWN = 'ManiaControl.OnShutdown';
|
||||
const CB_MC_CLIENTUPDATED = 'ManiaControl.ClientUpdated';
|
||||
@ -186,9 +183,8 @@ class CallbackManager {
|
||||
* Trigger internal Callbacks and manage Server Callbacks
|
||||
*/
|
||||
public function manageCallbacks() {
|
||||
// Timed callbacks
|
||||
// Manage Timings
|
||||
$this->maniaControl->timerManager->manageTimings();
|
||||
$this->manageTimedCallbacks();
|
||||
|
||||
// Server Callbacks
|
||||
if (!$this->maniaControl->client) {
|
||||
@ -267,30 +263,4 @@ class CallbackManager {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage recurring timed Callbacks
|
||||
*/
|
||||
private function manageTimedCallbacks() {
|
||||
// 1 second
|
||||
if ($this->last1Second > time() - 1) {
|
||||
return;
|
||||
}
|
||||
$this->last1Second = time();
|
||||
$this->triggerCallback(self::CB_MC_1_SECOND, array(self::CB_MC_1_SECOND));
|
||||
|
||||
// 5 second
|
||||
if ($this->last5Second > time() - 5) {
|
||||
return;
|
||||
}
|
||||
$this->last5Second = time();
|
||||
$this->triggerCallback(self::CB_MC_5_SECOND, array(self::CB_MC_5_SECOND));
|
||||
|
||||
// 1 minute
|
||||
if ($this->last1Minute > time() - 60) {
|
||||
return;
|
||||
}
|
||||
$this->last1Minute = time();
|
||||
$this->triggerCallback(self::CB_MC_1_MINUTE, array(self::CB_MC_1_MINUTE));
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ namespace ManiaControl\Manialinks;
|
||||
|
||||
use FML\CustomUI;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\Callbacks\TimerListener;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Players\PlayerManager;
|
||||
@ -14,7 +14,7 @@ use ManiaControl\Players\PlayerManager;
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
*/
|
||||
class CustomUIManager implements CallbackListener {
|
||||
class CustomUIManager implements CallbackListener, TimerListener {
|
||||
|
||||
/**
|
||||
* Constants
|
||||
@ -38,7 +38,7 @@ class CustomUIManager implements CallbackListener {
|
||||
$this->prepareManialink();
|
||||
|
||||
// Register for callbacks
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_1_SECOND, $this, 'handle1Second');
|
||||
$this->maniaControl->timerManager->registerTimerListening($this, 'handle1Second', 1000);
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'handlePlayerJoined');
|
||||
}
|
||||
|
||||
@ -64,11 +64,11 @@ class CustomUIManager implements CallbackListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle 1Second Callback
|
||||
* Handle 1Second
|
||||
*
|
||||
* @param array $callback
|
||||
* @param $time
|
||||
*/
|
||||
public function handle1Second(array $callback) {
|
||||
public function handle1Second($time) {
|
||||
if (!$this->updateManialink) {
|
||||
return;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ use FML\Controls\Quads\Quad_Icons64x64_1;
|
||||
use ManiaControl\Admin\AuthenticationManager;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\Callbacks\TimerListener;
|
||||
use ManiaControl\Commands\CommandListener;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
@ -18,7 +19,7 @@ use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
*/
|
||||
class ServerCommands implements CallbackListener, CommandListener, ManialinkPageAnswerListener {
|
||||
class ServerCommands implements CallbackListener, CommandListener, ManialinkPageAnswerListener, TimerListener {
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
@ -42,7 +43,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Register for callbacks
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_5_SECOND, $this, 'each5Seconds');
|
||||
$this->maniaControl->timerManager->registerTimerListening($this, 'each5Seconds', 5000);
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit');
|
||||
|
||||
// Register for commands
|
||||
@ -69,14 +70,14 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
|
||||
|
||||
$pauseExists = false;
|
||||
foreach($scriptInfos->commandDescs as $param) {
|
||||
if($param->name == "Command_ForceWarmUp") {
|
||||
if ($param->name == "Command_ForceWarmUp") {
|
||||
$pauseExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Set Pause
|
||||
if($pauseExists) {
|
||||
if ($pauseExists) {
|
||||
$itemQuad = new Quad_Icons128x32_1();
|
||||
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ManiaLinkSwitch);
|
||||
$itemQuad->setAction(self::ACTION_SET_PAUSE);
|
||||
@ -98,7 +99,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_CancelVote(array $chatCallback, Player $player) {
|
||||
if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
|
||||
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
@ -117,7 +118,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
|
||||
*/
|
||||
public function setPause(array $callback) {
|
||||
$success = $this->maniaControl->client->sendModeScriptCommands(array('Command_ForceWarmUp' => True));
|
||||
if(!$success) {
|
||||
if (!$success) {
|
||||
$this->maniaControl->chat->sendError("Error while setting the pause");
|
||||
}
|
||||
}
|
||||
@ -125,21 +126,21 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
|
||||
/**
|
||||
* Check stuff each 5 seconds
|
||||
*
|
||||
* @param array $callback
|
||||
* @param $timer
|
||||
* @return bool
|
||||
*/
|
||||
public function each5Seconds(array $callback) {
|
||||
public function each5Seconds($timer) {
|
||||
// Empty shutdown
|
||||
if($this->serverShutdownEmpty) {
|
||||
if ($this->serverShutdownEmpty) {
|
||||
$players = $this->maniaControl->playerManager->getPlayers();
|
||||
if(count($players) <= 0) {
|
||||
if (count($players) <= 0) {
|
||||
$this->shutdownServer('empty');
|
||||
}
|
||||
}
|
||||
|
||||
// Delayed shutdown
|
||||
if($this->serverShutdownTime > 0) {
|
||||
if(time() >= $this->serverShutdownTime) {
|
||||
if ($this->serverShutdownTime > 0) {
|
||||
if (time() >= $this->serverShutdownTime) {
|
||||
$this->shutdownServer('delayed');
|
||||
}
|
||||
}
|
||||
@ -152,7 +153,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_SystemInfo(array $chat, Player $player) {
|
||||
if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_SUPERADMIN)) {
|
||||
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_SUPERADMIN)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
@ -168,17 +169,17 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_ShutdownServer(array $chat, Player $player) {
|
||||
if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_SUPERADMIN)) {
|
||||
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_SUPERADMIN)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
// Check for delayed shutdown
|
||||
$params = explode(' ', $chat[1][2]);
|
||||
if(count($params) >= 2) {
|
||||
if (count($params) >= 2) {
|
||||
$param = $params[1];
|
||||
if($param == 'empty') {
|
||||
if ($param == 'empty') {
|
||||
$this->serverShutdownEmpty = !$this->serverShutdownEmpty;
|
||||
if($this->serverShutdownEmpty) {
|
||||
if ($this->serverShutdownEmpty) {
|
||||
$this->maniaControl->chat->sendInformation("The server will shutdown as soon as it's empty!", $player->login);
|
||||
return;
|
||||
}
|
||||
@ -186,7 +187,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
|
||||
return;
|
||||
}
|
||||
$delay = (int)$param;
|
||||
if($delay <= 0) {
|
||||
if ($delay <= 0) {
|
||||
// Cancel shutdown
|
||||
$this->serverShutdownTime = -1;
|
||||
$this->maniaControl->chat->sendInformation("Delayed shutdown cancelled!", $player->login);
|
||||
@ -207,12 +208,12 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_SetServerName(array $chat, Player $player) {
|
||||
if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
|
||||
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
$params = explode(' ', $chat[1][2], 2);
|
||||
if(count($params) < 2) {
|
||||
if (count($params) < 2) {
|
||||
$this->maniaControl->chat->sendUsageInfo('Usage example: //setservername ManiaPlanet Server', $player->login);
|
||||
return;
|
||||
}
|
||||
@ -233,14 +234,14 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_SetPwd(array $chatCallback, Player $player) {
|
||||
if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
|
||||
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
$messageParts = explode(' ', $chatCallback[1][2], 2);
|
||||
$password = '';
|
||||
$successMessage = 'Password removed!';
|
||||
if(isset($messageParts[1])) {
|
||||
if (isset($messageParts[1])) {
|
||||
$password = $messageParts[1];
|
||||
$successMessage = "Password changed to: '{$password}'!";
|
||||
}
|
||||
@ -260,14 +261,14 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_SetSpecPwd(array $chatCallback, Player $player) {
|
||||
if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
|
||||
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
$messageParts = explode(' ', $chatCallback[1][2], 2);
|
||||
$password = '';
|
||||
$successMessage = 'Spectator password removed!';
|
||||
if(isset($messageParts[1])) {
|
||||
if (isset($messageParts[1])) {
|
||||
$password = $messageParts[1];
|
||||
$successMessage = "Spectator password changed to: '{$password}'!";
|
||||
}
|
||||
@ -287,22 +288,22 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_SetMaxPlayers(array $chatCallback, Player $player) {
|
||||
if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
|
||||
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
$messageParts = explode(' ', $chatCallback[1][2], 2);
|
||||
if(!isset($messageParts[1])) {
|
||||
if (!isset($messageParts[1])) {
|
||||
$this->maniaControl->chat->sendUsageInfo('Usage example: //setmaxplayers 16', $player->login);
|
||||
return;
|
||||
}
|
||||
$amount = $messageParts[1];
|
||||
if(!is_numeric($amount)) {
|
||||
if (!is_numeric($amount)) {
|
||||
$this->maniaControl->chat->sendUsageInfo('Usage example: //setmaxplayers 16', $player->login);
|
||||
return;
|
||||
}
|
||||
$amount = (int)$amount;
|
||||
if($amount < 0) {
|
||||
if ($amount < 0) {
|
||||
$amount = 0;
|
||||
}
|
||||
|
||||
@ -323,22 +324,22 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_SetMaxSpectators(array $chatCallback, Player $player) {
|
||||
if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
|
||||
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
$messageParts = explode(' ', $chatCallback[1][2], 2);
|
||||
if(!isset($messageParts[1])) {
|
||||
if (!isset($messageParts[1])) {
|
||||
$this->maniaControl->chat->sendUsageInfo('Usage example: //setmaxspectators 16', $player->login);
|
||||
return;
|
||||
}
|
||||
$amount = $messageParts[1];
|
||||
if(!is_numeric($amount)) {
|
||||
if (!is_numeric($amount)) {
|
||||
$this->maniaControl->chat->sendUsageInfo('Usage example: //setmaxspectators 16', $player->login);
|
||||
return;
|
||||
}
|
||||
$amount = (int)$amount;
|
||||
if($amount < 0) {
|
||||
if ($amount < 0) {
|
||||
$amount = 0;
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,7 @@
|
||||
|
||||
namespace ManiaControl\Server;
|
||||
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\Callbacks\TimerListener;
|
||||
use ManiaControl\ManiaControl;
|
||||
|
||||
/**
|
||||
@ -11,7 +10,7 @@ use ManiaControl\ManiaControl;
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
*/
|
||||
class UsageReporter implements CallbackListener {
|
||||
class UsageReporter implements TimerListener {
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
@ -21,7 +20,6 @@ class UsageReporter implements CallbackListener {
|
||||
* Private Properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
private $minuteCount = 0;
|
||||
|
||||
/**
|
||||
* Create a new Server Settings Instance
|
||||
@ -31,34 +29,35 @@ class UsageReporter implements CallbackListener {
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
//TODO setting
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_1_MINUTE, $this, 'handleEveryMinute');
|
||||
|
||||
$this->maniaControl->timerManager->registerTimerListening($this, 'reportUsage', 1000 * 60 * self::UPDATE_MINUTE_COUNT);
|
||||
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_DISABLE_USAGE_REPORTING, false);
|
||||
}
|
||||
|
||||
public function handleEveryMinute(array $callback) {
|
||||
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_DISABLE_USAGE_REPORTING)) {
|
||||
/**
|
||||
* Reports Usage every xx Minutes
|
||||
*
|
||||
* @param $time
|
||||
*/
|
||||
public function reportUsage($time) {
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_DISABLE_USAGE_REPORTING)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->minuteCount++;
|
||||
$properties = array();
|
||||
$properties['MC_Version'] = ManiaControl::VERSION;
|
||||
$properties['OperatingSystem'] = php_uname();
|
||||
$properties['PHPVersion'] = phpversion();
|
||||
$properties['ServerLogin'] = $this->maniaControl->server->login;
|
||||
$properties['TitleId'] = $this->maniaControl->server->titleId;
|
||||
$properties['ServerName'] = $this->maniaControl->server->getName();
|
||||
$properties['PlayerCount'] = count($this->maniaControl->playerManager->getPlayers());
|
||||
$properties['MaxPlayers'] = $this->maniaControl->client->getMaxPlayers();
|
||||
|
||||
if($this->minuteCount >= self::UPDATE_MINUTE_COUNT) {
|
||||
$properties = array();
|
||||
$properties['MC_Version'] = ManiaControl::VERSION;
|
||||
$properties['OperatingSystem'] = php_uname();
|
||||
$properties['PHPVersion'] = phpversion();
|
||||
$properties['ServerLogin'] = $this->maniaControl->server->login;
|
||||
$properties['TitleId'] = $this->maniaControl->server->titleId;
|
||||
$properties['ServerName'] = $this->maniaControl->server->getName();
|
||||
$properties['PlayerCount'] = count($this->maniaControl->playerManager->getPlayers());
|
||||
$properties['MaxPlayers'] = $this->maniaControl->client->getMaxPlayers();
|
||||
$json = json_encode($properties);
|
||||
$info = base64_encode($json);
|
||||
|
||||
$json = json_encode($properties);
|
||||
$info = base64_encode($json);
|
||||
|
||||
//TODO send Info
|
||||
$this->minuteCount = 0;
|
||||
}
|
||||
//TODO send Info
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ namespace ManiaControl;
|
||||
|
||||
use ManiaControl\Admin\AuthenticationManager;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\Callbacks\TimerListener;
|
||||
use ManiaControl\Commands\CommandListener;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Players\PlayerManager;
|
||||
@ -15,7 +15,7 @@ use ManiaControl\Plugins\Plugin;
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
*/
|
||||
class UpdateManager implements CallbackListener, CommandListener {
|
||||
class UpdateManager implements CallbackListener, CommandListener, TimerListener {
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
@ -54,7 +54,7 @@ class UpdateManager implements CallbackListener, CommandListener {
|
||||
|
||||
|
||||
// Register for callbacks
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_1_MINUTE, $this, 'handle1Minute');
|
||||
$this->maniaControl->timerManager->registerTimerListening($this, 'handle1Minute', 1000 * 60);
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'handlePlayerJoined');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECTED, $this, 'handlePlayerDisconnected');
|
||||
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_UPDATE, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||
@ -68,9 +68,9 @@ class UpdateManager implements CallbackListener, CommandListener {
|
||||
/**
|
||||
* Handle ManiaControl 1Minute callback
|
||||
*
|
||||
* @param array $callback
|
||||
* @param $time
|
||||
*/
|
||||
public function handle1Minute(array $callback) {
|
||||
public function handle1Minute($time) {
|
||||
$updateCheckEnabled = $this->maniaControl->settingManager->getSetting($this, self::SETTING_ENABLEUPDATECHECK);
|
||||
if (!$updateCheckEnabled) {
|
||||
// Automatic update check disabled
|
||||
|
Reference in New Issue
Block a user