removed old timed callbacks

This commit is contained in:
kremsy 2014-01-31 00:04:40 +01:00 committed by Steffen Schröder
parent 620807c419
commit 1c0dd7e83d
12 changed files with 138 additions and 163 deletions

View File

@ -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));
}
}

View File

@ -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;
}

View File

@ -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
@ -125,10 +126,10 @@ 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) {
$players = $this->maniaControl->playerManager->getPlayers();

View File

@ -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,19 +29,22 @@ 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) {
/**
* 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++;
if($this->minuteCount >= self::UPDATE_MINUTE_COUNT) {
$properties = array();
$properties['MC_Version'] = ManiaControl::VERSION;
$properties['OperatingSystem'] = php_uname();
@ -58,7 +59,5 @@ class UsageReporter implements CallbackListener {
$info = base64_encode($json);
//TODO send Info
$this->minuteCount = 0;
}
}
}

View File

@ -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

View File

@ -15,6 +15,7 @@ use FML\ManiaLink;
use FML\Script\Script;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\TimerListener;
use ManiaControl\ColorUtil;
use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl;
@ -31,7 +32,7 @@ use Maniaplanet\DedicatedServer\Structures\VoteRatio;
*
* @author kremsy and steeffeen
*/
class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkPageAnswerListener, Plugin {
class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkPageAnswerListener, TimerListener, Plugin {
/**
* Constants
*/
@ -104,7 +105,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$this->maniaControl = $maniaControl;
$this->maniaControl->commandManager->registerCommandListener('vote', $this, 'chat_vote');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_1_SECOND, $this, 'handle1Second');
$this->maniaControl->timerManager->registerTimerListening($this, 'handle1Second', 1000);
$this->maniaControl->callbackManager->registerCallbackListener(ServerCommands::CB_VOTE_CANCELED, $this, 'handleVoteCanceled');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_POSITIVE_VOTE, $this, 'handlePositiveVote');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_NEGATIVE_VOTE, $this, 'handleNegativeVote');
@ -449,9 +450,9 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
/**
* Handle ManiaControl 1 Second callback
*
* @param array $callback
* @param $time
*/
public function handle1Second(array $callback) {
public function handle1Second($time) {
if ($this->currentVote == null) {
return;
}
@ -706,7 +707,6 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
foreach($menuItems as $menuItem) {
$menuQuad = $menuItem[0];
/**
*
* @var Quad $menuQuad
*/
$popoutFrame->add($menuQuad);

View File

@ -6,6 +6,7 @@ use FML\Controls\Quad;
use FML\ManiaLink;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\TimerListener;
use ManiaControl\ColorUtil;
use ManiaControl\ManiaControl;
use ManiaControl\Maps\Map;
@ -17,7 +18,7 @@ use ManiaControl\Plugins\Plugin;
*
* @author steeffeen
*/
class KarmaPlugin implements CallbackListener, Plugin {
class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
/**
* Constants
*/
@ -74,8 +75,8 @@ class KarmaPlugin implements CallbackListener, Plugin {
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_HEIGHT, 12.);
// Register for callbacks
$this->maniaControl->timerManager->registerTimerListening($this, 'handle1Second', 1000);
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_BEGINMAP, $this, 'handleBeginMap');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_1_SECOND, $this, 'handle1Second');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'handlePlayerChat');
@ -144,9 +145,9 @@ class KarmaPlugin implements CallbackListener, Plugin {
/**
* Handle ManiaControl 1 Second callback
*
* @param array $callback
* @param $time
*/
public function handle1Second(array $callback) {
public function handle1Second($time) {
if(!$this->updateManialink) {
return;
}

View File

@ -1,4 +1,5 @@
<?php
use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Formatter;
use ManiaControl\ManiaControl;
use ManiaControl\Callbacks\CallbackListener;
@ -18,7 +19,7 @@ use FML\Controls\Quad;
*
* @author steeffeen
*/
class LocalRecordsPlugin implements CallbackListener, Plugin {
class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
/**
* Constants
*/
@ -74,8 +75,8 @@ class LocalRecordsPlugin implements CallbackListener, Plugin {
$this->maniaControl->settingManager->initSetting($this, self::SETTING_NOTIFY_BEST_RECORDS, -1);
// Register for callbacks
$this->maniaControl->timerManager->registerTimerListening($this, 'handle1Second', 1000);
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_1_SECOND, $this, 'handle1Second');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_BEGINMAP, $this, 'handleMapBegin');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_CLIENTUPDATED, $this,
'handleClientUpdated');
@ -166,9 +167,9 @@ class LocalRecordsPlugin implements CallbackListener, Plugin {
/**
* Handle 1Second callback
*
* @param array $callback
* @param $time
*/
public function handle1Second(array $callback) {
public function handle1Second($time) {
if (!$this->updateManialink) return;
$this->updateManialink = false;
$manialink = $this->buildManialink();

View File

@ -7,6 +7,7 @@ use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\ManiaLink;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
@ -23,7 +24,7 @@ use ManiaControl\Plugins\Plugin;
// TODO: worst kick function
// TODO: idlekick function (?)
class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAnswerListener, Plugin {
class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAnswerListener, TimerListener , Plugin {
/**
* Constants
*/
@ -63,10 +64,10 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
public function load(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
$this->maniaControl->timerManager->registerTimerListening($this, 'handleEverySecond', 1000);
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECTED, $this, 'handlePlayerDisconnect');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERINFOCHANGED, $this, 'handlePlayerInfoChanged');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_1_SECOND, $this, 'handleEverySecond');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ML_ADDTOQUEUE, $this, 'handleManiaLinkAnswerAdd');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ML_REMOVEFROMQUEUE, $this, 'handleManiaLinkAnswerRemove');

View File

@ -9,6 +9,7 @@ use FML\ManiaLink;
use ManiaControl\Admin\ActionsMenu;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\TimerListener;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player;
@ -16,7 +17,7 @@ use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
class SlotMachinePlugin implements Plugin, CallbackListener, ManialinkPageAnswerListener {
class SlotMachinePlugin implements Plugin, CallbackListener, ManialinkPageAnswerListener, TimerListener {
/**
* Constants
*/
@ -92,9 +93,10 @@ class SlotMachinePlugin implements Plugin, CallbackListener, ManialinkPageAnswer
public function load(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
$this->maniaControl->timerManager->registerTimerListening($this, 'onEverySecond', 1000);
$this->maniaControl->timerManager->registerTimerListening($this, 'updateDatabaseEveryMinute', 1000 * 60);
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_BILLUPDATED, $this, 'handleBillUpdated');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_1_SECOND, $this, 'onEverySecond');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_1_MINUTE, $this, 'updateDatabaseEveryMinute');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECTED, $this, 'handlePlayerDisconnect');

View File

@ -7,6 +7,7 @@ use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\ManiaLink;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager;
@ -21,7 +22,7 @@ use ManiaControl\Plugins\Plugin;
*
* @author TheM
*/
class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPageAnswerListener, Plugin {
class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPageAnswerListener, TimerListener, Plugin {
/**
* Constants
*/
@ -76,7 +77,7 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag
$this->maniaControl->manialinkManager->iconManager->addIcon(self::TS_ICON);
$this->maniaControl->manialinkManager->iconManager->addIcon(self::TS_ICON_MOVER);
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_1_SECOND, $this, 'ts3_queryServer');
$this->maniaControl->timerManager->registerTimerListening($this, 'ts3_queryServer', 1000);
$this->addToMenu();
}

View File

@ -9,6 +9,7 @@ use FML\ManiaLink;
use FML\Script\Script;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Formatter;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\IconManager;
@ -21,7 +22,7 @@ use ManiaControl\Plugins\Plugin;
*
* @author kremsy
*/
class WidgetPlugin implements CallbackListener, Plugin {
class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
/**
* Constants
@ -67,7 +68,6 @@ class WidgetPlugin implements CallbackListener, Plugin {
* Private Properties
*/
/**
*
* @var maniaControl $maniaControl
*/
private $maniaControl = null;
@ -99,7 +99,8 @@ class WidgetPlugin implements CallbackListener, Plugin {
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ENDMAP, $this, 'handleOnEndMap');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECTED, $this, 'handlePlayerDisconnect');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_1_MINUTE, $this, 'handleEveryMinute');
$this->maniaControl->timerManager->registerTimerListening($this, 'handleEveryMinute', 1000 * 60);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED, true);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MAP_WIDGET_POSX, 160 - 20);
@ -310,7 +311,6 @@ class WidgetPlugin implements CallbackListener, Plugin {
$playerCount = 0;
$spectatorCount = 0;
/**
*
* @var Player $player
*/
foreach($players as $player) {
@ -446,7 +446,6 @@ class WidgetPlugin implements CallbackListener, Plugin {
$queuedMap = $this->maniaControl->mapManager->mapQueue->getNextMap();
/**
*
* @var Player $requester
*/
$requester = null;
@ -545,11 +544,11 @@ class WidgetPlugin implements CallbackListener, Plugin {
}
/**
* Aktualize the clock widget every minute
* Actualize the clock widget every minute
*
* @param array $callback
* @param $time
*/
public function handleEveryMinute(array $callback) {
public function handleEveryMinute($time) {
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)) {
$this->displayClockWidget();
}