function close($onPurpose = true) { if ($this->server) { if ($onPurpose) { $this->server->notifyUnregister(); foreach ($this->privilegeKeys as $key) { $this->server->privilegeKeyDelete($key); } } $this->server->clientListReset(); $this->server->channelListReset(); $this->server = null; $this->playersGroupId = 0; $this->privilegeKeys = array(); } if ($this->processHandler && $this->processId) { $this->processHandler->killThread($this->processId); $this->processId = null; } Dispatcher::unregister(AppEvent::getClass(), $this); Dispatcher::unregister(TickEvent::getClass(), $this); // TODO something to avoid memory leaks when unloading the plugin // but the TS framework is f*cked up (plenty of circular references // which can't be unset from outside...) }
protected function __construct() { $this->identifier = 'ManiaLive ' . \ManiaLiveApplication\Version; $config = Config::getInstance(); $this->connection = Connection::factory($config->host, $config->port, $config->timeout, $config->user, $config->password); Dispatcher::register(Event::getClass(), $this, Event::ON_ECHO); }
protected function __construct() { Dispatcher::register(ServerEvent::getClass(), $this, ServerEvent::ON_PLAYER_CHAT); $command = new Command('help', 0); $command->addLoginAsFirstParameter = true; $command->log = false; $command->help = 'Display all visible commands to a player it takes no parameter'; $command->callback = array($this, 'help'); $this->register($command); $command = new Command('man', 1); $command->addLoginAsFirstParameter = true; $command->help = 'Display help for every commands you give as parameter' . "\n" . 'exemple of usage: /man man'; $command->isPublic = true; $command->log = false; $command->callback = array($this, 'man'); $this->register($command); $command = new Command('man', 2); $command->addLoginAsFirstParameter = true; $command->help = 'Display help for the command with the corresponding parameters' . "\n" . 'exemple of usage: /man man 2'; $command->isPublic = true; $command->log = false; $command->callback = array($this, 'man'); $this->register($command); $config = \ManiaLive\DedicatedApi\Config::getInstance(); $this->connection = Connection::factory($config->host, $config->port, $config->timeout, $config->user, $config->password); }
public function onLoad() { $this->enableDedicatedEvents(); \ManiaLive\Event\Dispatcher::register(\ManiaLivePlugins\NadeoLive\XmlRpcScript\Event::getClass(), $this); $this->connection->setModeScriptSettings(array('S_UseScriptCallbacks' => true)); $this->postTwitterMessage(sprintf('Now following %s', $this->storage->server->name)); }
function onPreLoop() { $time = time(); if ($time - $this->time >= 1) { $this->time = $time; Dispatcher::dispatch(new Event()); } }
function onTick() { ++$this->tickCount; $time = microtime(true); Dispatcher::dispatch(new Event(Event::ON_NEW_CPU_VALUE, round($this->loopCount / ($time - $this->loopStart), 2))); if ($this->tickCount % 3 == 0) { Dispatcher::dispatch(new Event(Event::ON_NEW_MEMORY_VALUE, memory_get_usage())); } Dispatcher::dispatch(new Event(Event::ON_NEW_NETWORK_VALUE, array(Client::$received - $this->lastNetwork[0], Client::$sent - $this->lastNetwork[1]))); $this->loopCount = 0; $this->loopStart = $time; $this->lastNetwork = array(Client::$received, Client::$sent); }
protected function __construct() { $this->modalBg = new Bgs1(340, 200); $this->modalBg->setSubStyle(Bgs1::BgDialogBlur); $this->modalBg->setAlign('center', 'center'); $this->modalBg->setPosZ(Window::Z_MODAL); $this->modalBg->setScriptEvents(); $this->nextLoop = microtime(true); Dispatcher::register(AppEvent::getClass(), $this, AppEvent::ALL & ~AppEvent::ON_POST_LOOP); Dispatcher::register(PlayerEvent::getClass(), $this, PlayerEvent::ON_PLAYER_CHANGE_SIDE); Dispatcher::register(ServerEvent::getClass(), $this, ServerEvent::ON_PLAYER_CONNECT | ServerEvent::ON_PLAYER_DISCONNECT); $config = \ManiaLive\DedicatedApi\Config::getInstance(); $this->connection = Connection::factory($config->host, $config->port, $config->timeout, $config->user, $config->password); }
function destroy() { Dispatcher::unregister(MonitorEvent::getClass(), $this); $this->barsFrame->destroy(); $this->linesFrame->destroy(); $this->bars = array(); $this->lines = array(); $this->networkStats = array(); $this->networkSums = array(); parent::destroy(); }
function destroy() { Dispatcher::unregister(PluginEvent::getClass(), $this); parent::destroy(); }
function onLoad() { //Check if Lobby is not running with the match plugin if ($this->isPluginLoaded('\\ManiaLivePlugins\\MatchMakingLobby\\Match\\Plugin')) { throw new \Exception('Lobby and match cannot be one the same server.'); } $this->enableDedicatedEvents(ServerEvent::ON_PLAYER_CONNECT | ServerEvent::ON_PLAYER_DISCONNECT | ServerEvent::ON_MODE_SCRIPT_CALLBACK | ServerEvent::ON_BEGIN_MAP); $this->enableStorageEvents(StorageEvent::ON_PLAYER_CHANGE_SIDE | StorageEvent::ON_PLAYER_JOIN_GAME); /** Register to Ally Service Event */ \ManiaLive\Event\Dispatcher::register(Services\AllyEvent::getClass(), $this); $matchSettingsClass = $this->config->getMatchSettingsClassName($this->scriptName); /* @var $matchSettings \ManiaLivePlugins\MatchMakingLobby\MatchSettings\MatchSettings */ if (!class_exists($matchSettingsClass)) { throw new \Exception(sprintf("Can't find class %s. You should set up the config : ManiaLivePlugins\\MatchMakingLobby\\Config.matchSettingsClassName", $matchSettingsClass)); } $this->titleIdString = $this->connection->getSystemInfo()->titleId; $this->backLink = $this->storage->serverLogin . ':' . $this->storage->server->password . '@' . $this->titleIdString; $this->registerLobby(); $this->setLobbyInfo(); $partySize = $this->matchMaker->getNumberOfTeam() ? (int) $this->matchMaker->getPlayersPerMatch() / $this->matchMaker->getNumberOfTeam() : 1; $this->gui->createWaitingScreen(\ManiaLive\Gui\ActionHandler::getInstance()->createAction(array($this, 'onPlayerReady')), $this->scriptName, $partySize, $this->config->rulesManialink, $this->config->logoURL, $this->config->logoLink); $this->gui->configurePlayerList($partySize > 1 ? true : false); foreach (array_merge($this->storage->players, $this->storage->spectators) as $login => $obj) { //Simulate player connection $this->onPlayerConnect($login, null); } $this->updatePlayerList = true; $matchSettings = new $matchSettingsClass(); $settings = $matchSettings->getLobbyScriptSettings(); $this->connection->setModeScriptSettings($settings); $this->enableTickerEvent(); $this->connection->setCallVoteRatiosEx(false, array(new Structures\VoteRatio('SetModeScriptSettingsAndCommands', -1.0), new Structures\VoteRatio('NextMap', -1.0), new Structures\VoteRatio('JumpToMapIndex', -1.0), new Structures\VoteRatio('SetNextMapIndex', -1.0), new Structures\VoteRatio('RestartMap', -1.0))); $this->updateLobbyWindow(); //$this->gui->showHelp($this->scriptName); if ($this->config->showMasters) { $this->gui->createMasterList(); $this->updateMasterList(); } $this->connection->disableServiceAnnounces(true); $this->registerChatCommand('setAllReady', 'onSetAllReady', 0, true, \ManiaLive\Features\Admin\AdminGroup::get()); $this->registerChatCommand('kickNonReady', 'onKickNotReady', 0, true, \ManiaLive\Features\Admin\AdminGroup::get()); $this->registerChatCommand('resetPenalty', 'onResetPenalty', 1, true, \ManiaLive\Features\Admin\AdminGroup::get()); $this->registerChatCommand('resetAllPenalties', 'onResetAllPenalties', 0, true, \ManiaLive\Features\Admin\AdminGroup::get()); $this->registerChatCommand('maintenance', 'onMaintenance', 1, true, \ManiaLive\Features\Admin\AdminGroup::get()); $this->connection->restartMap(); $this->setLocalAllyAction = \ManiaLive\Gui\ActionHandler::getInstance()->createAction(array($this, 'onPlayerSetLocalAlly')); $this->unsetLocalAllyAction = \ManiaLive\Gui\ActionHandler::getInstance()->createAction(array($this, 'onPlayerUnsetLocalAlly')); }
/** * (non-PHPdoc) * @see libraries/ManiaLive/Features/Tick/ManiaLive\Features\Tick.Listener::onTick() */ public function onTick() { if (time() >= $this->timeout) { $this->timeout = false; $this->hide(); Dispatcher::unregister(TickEvent::getClass(), $this); } }
protected function __construct() { Dispatcher::register(ServerEvent::getClass(), $this, ServerEvent::ON_PLAYER_MANIALINK_PAGE_ANSWER); }
private function restartThread($threadId) { if (!$this->enabled || !isset($this->threads[$threadId])) { return; } $commandDiscarded = false; if (empty($this->pendings[$threadId])) { Logger::debug('Thread #' . $threadId . ' died...', true, array('Process #' . getmypid())); Dispatcher::dispatch(new Event(Event::ON_THREAD_DIES, $threadId)); } else { Logger::debug('Thread #' . $threadId . ' timed out...', true, array('Process #' . getmypid())); Dispatcher::dispatch(new Event(Event::ON_THREAD_TIMES_OUT, $threadId)); // If we already tried this command too many times, we discard it... $command = reset($this->pendings[$threadId]); $lastCommandId = $command->getId(); if (++$this->tries[$lastCommandId] > Config::getInstance()->maxTries) { $this->database->execute('DELETE FROM ThreadingCommands WHERE commandId=%d AND parentId=%d', $lastCommandId, getmypid()); unset($this->pendings[$threadId][$lastCommandId]); unset($this->tries[$lastCommandId]); Logger::debug('Command #' . $lastCommandId . ' has been discarded after ' . Config::getInstance()->maxTries . ' unsuccessful tries...', true, array('Process #' . getmypid())); $commandDiscarded = true; } } // Respawning the thread $threadHandle = $this->threads[$threadId]; proc_terminate($threadHandle); proc_close($threadHandle); ++$this->deadThreadsCount; $this->threads[$threadId] = $this->spawnThread($threadId); $this->lastTick[$threadId] = $this->tick; Dispatcher::dispatch(new Event(Event::ON_THREAD_RESTART, $threadId)); Logger::debug('Thread #' . $threadId . ' restarted!', true, array('Process #' . getmypid())); if ($commandDiscarded) { $command->fail(); } }
private function prepare($plugin) { $this->checkDependencies($plugin); $plugin->onLoad(); Dispatcher::dispatch(new Event(Event::ON_PLUGIN_LOADED, $plugin->getId())); }
protected function fireEvent($playerLogin) { Dispatcher::dispatch(new AllyEvent($playerLogin)); }
protected function __construct() { $this->lastDisplayed = 0; Dispatcher::register(TickEvent::getClass(), $this); }
function destroy() { Dispatcher::unregister(MonitorEvent::getClass(), $this); unset($this->cpuStats); parent::destroy(); }
/** * stop to listen for plugin events. */ protected final function disablePluginEvents($events = PluginEvent::ALL) { $this->restrictIfUnloaded(); Dispatcher::unregister(PluginEvent::getClass(), $this, $events & $this->eventsPlugins); $this->eventsPlugins &= ~$events; }
function disconnect() { if (!mysql_close($this->connection)) { throw new DisconnectionException(); } $this->connection = null; Dispatcher::unregister(TickEvent::getClass(), $this); }
protected function dispatch($event, $param) { \ManiaLive\Event\Dispatcher::dispatch(new Event($event, $param)); }
final function run() { try { $this->init(); Dispatcher::dispatch(new Event(Event::ON_RUN)); self::$startTime = microtime(true); $nextCycleStart = self::$startTime; $cycleTime = 1 / static::CYCLES_PER_SECOND; } catch (\Exception $e) { ErrorHandling::processRuntimeException($e); } try { while ($this->running) { Dispatcher::dispatch(new Event(Event::ON_PRE_LOOP)); $calls = $this->connection->executeCallbacks(); if (!empty($calls)) { foreach ($calls as $call) { $method = preg_replace('/^[[:alpha:]]+\\./', '', $call[0]); // remove trailing "Whatever." $params = (array) $call[1]; Dispatcher::dispatch(new \ManiaLive\DedicatedApi\Callback\Event($method, $params)); } } $this->connection->executeMulticall(); Dispatcher::dispatch(new Event(Event::ON_POST_LOOP)); $endCycleTime = microtime(true) + $cycleTime / 10; do { $nextCycleStart += $cycleTime; } while ($nextCycleStart < $endCycleTime); @time_sleep_until($nextCycleStart); } } catch (\Exception $e) { ErrorHandling::processRuntimeException($e); } Dispatcher::dispatch(new Event(Event::ON_TERMINATE)); }
protected function updateRanking($rankings) { foreach ($rankings as $ranking) { if ($ranking->rank == 0) { continue; } $player = $this->getPlayerObject($ranking->login); if (!$player) { continue; } $rankOld = $player->rank; $player->rank = $ranking->rank; $player->bestTime = $ranking->bestTime; $player->bestCheckpoints = $ranking->bestCheckpoints; $player->score = $ranking->score; $player->nbrLapsFinished = $ranking->nbrLapsFinished; $player->ladderScore = $ranking->ladderScore; if (!$player->isSpectator && $rankOld != $player->rank) { Dispatcher::dispatch(new Event(Event::ON_PLAYER_NEW_RANK, $player, $rankOld, $player->rank)); } } }
function destroy() { Dispatcher::unregister(MonitorEvent::getClass(), $this); $this->barsFrame->destroy(); $this->criticalLineFrame->destroy(); $this->optimalLineFrame->destroy(); $this->bars = array(); $this->cpuStats = array(); parent::destroy(); }