function open() { $config = Config::getInstance(); try { $this->server = TeamSpeak3::factory('serverquery://' . $config->queryLogin . ':' . $config->queryPassword . '@' . $config->queryHost . ':' . $config->queryPort . '/?server_port=' . $config->voicePort . '&blocking=0#no_query_clients'); $this->server->execute('instanceedit', array('serverinstance_serverquery_flood_commands' => 20, 'serverinstance_serverquery_flood_time' => 1, 'serverinstance_serverquery_flood_ban_time' => 1)); } catch (\Exception $e) { $this->server = null; return; } // Threading is really useful for this plugin !!! $this->processHandler = ThreadHandler::getInstance(); $this->processId = $this->processHandler->launchThread(); // Enable events (from ML and from TS) Dispatcher::register(AppEvent::getClass(), $this, AppEvent::ON_PRE_LOOP); Dispatcher::register(TickEvent::getClass(), $this); $this->server->notifyRegister('channel'); // Find players group id or create a new group for privilege keys foreach ($this->server->serverGroupList() as $group) { if ($group['name'] == 'ManiaPlanet Player') { $this->playersGroupId = $group['sgid']; break; } } $this->server->serverGroupListReset(); if (!$this->playersGroupId) { $this->playersGroupId = $this->server->serverGroupCreate('ManiaPlanet Player'); foreach ($config->groupPermissions as $permission => $value) { $this->server->serverGroupPermAssign($this->playersGroupId, $permission, $value); } } else { // Find existing tokens to avoid duplicates try { foreach ($this->server->privilegeKeyList() as $token => $tokenInfo) { if (!$tokenInfo['token_type'] && $tokenInfo['token_id1'] == $this->playersGroupId && preg_match('/`([a-z\\._-]{1,25})`$/', $tokenInfo['token_description'], $matches)) { $this->privilegeKeys[$matches[1]] = $token; } } } catch (\ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Adapter\ServerQuery\Exception $e) { /* thanks for launching exception instead of just returning an empty array... */ } } // Populate foreach ($this->server->channelList() as $channel) { new Channel($channel, $this->getChannelPermissionList($channel)); } foreach ($this->server->clientList() as $client) { new Client($client, $this->getCustomInfo($client)); } // Handle default channels $this->createChannelsIFN(); }
protected function init() { new \ManiaLive\Features\Tick\Ticker(); $config = \ManiaLive\DedicatedApi\Config::getInstance(); $this->connection = Connection::factory($config->host, $config->port, $config->timeout, $config->user, $config->password); $this->connection->enableCallbacks(true); \ManiaLive\Data\Storage::getInstance(); \ManiaLive\Features\ChatCommand\Interpreter::getInstance(); \ManiaLive\Features\EchoHandler::getInstance(); \ManiaLive\Gui\GuiHandler::getInstance(); \ManiaLive\PluginHandler\PluginHandler::getInstance(); \ManiaLive\Threading\ThreadHandler::getInstance(); Dispatcher::dispatch(new Event(Event::ON_INIT)); }
function onDraw() { // statistics for memory usage $memory = memory_get_usage(); $text = '$oPHP Memory$z' . "\n" . 'Current Memory Usage: ' . round($memory / 1024) . " kb\n" . 'Total Peak Memory: ' . round(memory_get_peak_usage() / 1024) . " kb\n" . 'PHP Memory Limit: ' . round($this->memoryLimit / 1024) . " kb\n" . 'Amount Used: ' . round(100 * $memory / $this->memoryLimit, 2) . "%\n" . '$oPHP Speed$z' . "\n"; if (empty($this->cpuStats)) { $text .= '$iRetrieving information...$z' . "\n"; } else { $text .= 'Current Cycles per Second: ' . end($this->cpuStats) . "\n" . 'Avg Reaction Time: ' . round(1000 * count($this->cpuStats) / (array_sum($this->cpuStats) ?: 1)) . " msecs\n"; } // manialive specific stats $text .= '$oManiaLive$z' . "\n"; // runtime $diff = time() - \ManiaLive\Application\AbstractApplication::$startTime; $seconds = $diff % 60; $minutes = floor($diff % 3600 / 60); $hours = floor($diff % 86400 / 3600); $days = floor($diff / 86400); $text .= "ManiaLive Uptime:\n{$days} days and {$hours} hours\n{$minutes} min and {$seconds} seconds\n"; // threading $text .= '$oThreading$z' . "\n"; $processHandler = ThreadHandler::getInstance(); if ($processHandler->isEnabled()) { $text .= 'Enabled; Running:' . $processHandler->countThreads() . '; Restarted:' . $processHandler->countRestartedThreads() . "\n" . $processHandler->countFinishedCommands() . ' commands finished at avg ' . round($processHandler->getAverageResponseTime(), 3) . ' ms'; } else { $text .= "Disabled\n"; } // update left side of the page $this->leftLabel->setText($text); // database $text = '$oDatabase$z' . "\n"; $times = Connection::getMeasuredAverageTimes(); if (count($times)) { $i = 0; foreach ($times as $time) { $text .= 'Connection #' . ++$i . ":\n" . 'Avg Query Time: ' . round($time, 3) . ' sec' . "\n"; } } else { $text .= "No Database connections running.\n"; } // network $text .= '$oNetwork$z' . "\n" . 'Total Bytes Sent: ' . round(Client::$sent / 1024) . "kb\n" . 'Total Bytes Received: ' . round(Client::$received / 1024) . "kb\n" . '$oInterface Drawing$z' . "\n" . 'Avg Drawing Time: ' . round(GuiHandler::getInstance()->getAverageSendingTimes() * 1000) . " msec\n" . '$oPlugins$z' . "\n" . 'Currently loaded: ' . count(PluginHandler::getInstance()->getLoadedPluginsList()); // update right side of the page $this->rightLabel->setText($text); }
function onUnload() { parent::onUnload(); Manager::ErasePlugins(); if ($this->threadId) { ThreadHandler::getInstance()->killThread($this->threadId); } }