diff --git a/application/core/Admin/AuthenticationManager.php b/application/core/Admin/AuthenticationManager.php index db697345..2855dea0 100644 --- a/application/core/Admin/AuthenticationManager.php +++ b/application/core/Admin/AuthenticationManager.php @@ -197,15 +197,18 @@ class AuthenticationManager implements CallbackListener { /** * Get a List of all Admins * - * @param $authLevel + * @param int $authLevel * @return array null */ - public function getAdmins($authLevel = -1) { + public function getAdmins($authLevel = null) { $mysqli = $this->maniaControl->database->mysqli; - if ($authLevel < 0) { - $query = "SELECT * FROM `" . PlayerManager::TABLE_PLAYERS . "` WHERE `authLevel` > 0 ORDER BY `authLevel` DESC;"; + if ($authLevel === null) { + $query = "SELECT * FROM `" . PlayerManager::TABLE_PLAYERS . "` + WHERE `authLevel` > 0 + ORDER BY `authLevel` DESC;"; } else { - $query = "SELECT * FROM `" . PlayerManager::TABLE_PLAYERS . "` WHERE `authLevel` = " . $authLevel . ";"; + $query = "SELECT * FROM `" . PlayerManager::TABLE_PLAYERS . "` + WHERE `authLevel` = {$authLevel};"; } $result = $mysqli->query($query); if (!$result) { @@ -289,7 +292,7 @@ class AuthenticationManager implements CallbackListener { } /** - * Check if the Player has enough Rights + * Check whether the Player has enough Rights * * @param Player $player * @param int|Setting $neededAuthLevel @@ -303,10 +306,10 @@ class AuthenticationManager implements CallbackListener { } /** - * Defines a Minimum Right Level needed for an action + * Define a Minimum Right Level needed for an Action * - * @param $rightName - * @param $authLevelNeeded + * @param string $rightName + * @param int $authLevelNeeded */ public function definePermissionLevel($rightName, $authLevelNeeded) { $this->maniaControl->settingManager->initSetting($this, $rightName, $authLevelNeeded); diff --git a/application/core/Bills/BillManager.php b/application/core/Bills/BillManager.php index f07b0785..7f7ecdcc 100644 --- a/application/core/Bills/BillManager.php +++ b/application/core/Bills/BillManager.php @@ -64,22 +64,15 @@ class BillManager implements CallbackListener { /** * Send Planets from the server to a Player * - * @param $function - * @param $receiverLogin - * @param $amount - * @param $message + * @param callable $function + * @param string $receiverLogin + * @param int $amount + * @param string $message * @return bool */ - public function sendPlanets($function, $receiverLogin, $amount, $message) { - if (!is_callable($function)) { - trigger_error("Function is not callable"); - return false; - } - + public function sendPlanets(callable $function, $receiverLogin, $amount, $message) { $bill = $this->maniaControl->client->pay($receiverLogin, $amount, $message); - $this->openBills[$bill] = new BillData($function, $receiverLogin, $amount, true); - return true; } diff --git a/application/core/Commands/HelpManager.php b/application/core/Commands/HelpManager.php index ab2ef474..9c9b036b 100644 --- a/application/core/Commands/HelpManager.php +++ b/application/core/Commands/HelpManager.php @@ -124,12 +124,12 @@ class HelpManager implements CommandListener, CallbackListener { } /** - * Prepares the commands for the HelpAll ManiaLink. + * Prepare the commands for the HelpAll ManiaLink. * - * @param $commands - * @param $player + * @param array $commands + * @param mixed $player */ - private function prepareHelpAll($commands, $player) { + private function prepareHelpAll(array $commands, $player) { $showCommands = array(); $registeredMethods = array(); foreach (array_reverse($commands) as $command) { @@ -157,10 +157,10 @@ class HelpManager implements CommandListener, CallbackListener { /** * Shows the HelpAll list to the player. * - * @param $commands - * @param $player + * @param array $commands + * @param mixed $player */ - private function showHelpAllList($commands, $player) { + private function showHelpAllList(array $commands, $player) { $width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth(); $height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight(); diff --git a/application/core/Configurators/Configurator.php b/application/core/Configurators/Configurator.php index 27b2fcfc..946239df 100644 --- a/application/core/Configurators/Configurator.php +++ b/application/core/Configurators/Configurator.php @@ -340,14 +340,14 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn /** * Gets the Menu Id * - * @param $name + * @param string $title * @return int */ - public function getMenuId($name) { + public function getMenuId($title) { $i = 0; foreach ($this->menus as $menu) { /** @var ConfiguratorMenu $menu */ - if ($menu == $name || $menu->getTitle() == $name) { + if ($menu === $title || $menu->getTitle() === $title) { return $i; } $i++; diff --git a/application/core/ManiaControl.php b/application/core/ManiaControl.php index e9922607..c5d50c08 100644 --- a/application/core/ManiaControl.php +++ b/application/core/ManiaControl.php @@ -164,11 +164,9 @@ class ManiaControl implements CommandListener, TimerListener { } /** - * Checks connection every xxx Minutes - * - * @param $time + * Check Connection */ - public function checkConnection($time) { + public function checkConnection() { if ($this->client->getIdleTime() > 180) { $this->client->getServerName(); } diff --git a/application/core/ManiaExchange/ManiaExchangeManager.php b/application/core/ManiaExchange/ManiaExchangeManager.php index e7e4f228..29666758 100644 --- a/application/core/ManiaExchange/ManiaExchangeManager.php +++ b/application/core/ManiaExchange/ManiaExchangeManager.php @@ -60,7 +60,7 @@ class ManiaExchangeManager { /** * Unset Map by Mx Id * - * @param $mxId + * @param int $mxId */ public function unsetMap($mxId) { if (isset($this->mxIdUidVector[$mxId])) { @@ -142,7 +142,7 @@ class ManiaExchangeManager { /** * Get the Whole MapList from MX by Mixed Uid and Id String fetch * - * @param $string + * @param string $string * @return array|null */ public function getMaplistByMixedUidIdString($string) { @@ -187,11 +187,11 @@ class ManiaExchangeManager { } /** - * Store Map Info from MX and store the mxid in the database and the mx info in the map object + * Store MX Map Info in the Database and the MX Info in the Map Object * - * @param $mxMapInfos + * @param array $mxMapInfos */ - public function updateMapObjectsWithManiaExchangeIds($mxMapInfos) { + public function updateMapObjectsWithManiaExchangeIds(array $mxMapInfos) { $mysqli = $this->maniaControl->database->mysqli; // Save map data $saveMapQuery = "UPDATE `" . MapManager::TABLE_MAPS . "` @@ -231,11 +231,11 @@ class ManiaExchangeManager { /** * Get Map Info Asynchronously * - * @param $id - * @param $function + * @param int $id + * @param callable $function * @return bool */ - public function getMapInfo($id, $function) { + public function getMapInfo($id, callable $function) { // Get Title Prefix $titlePrefix = $this->maniaControl->mapManager->getCurrentMap()->getGame(); @@ -344,9 +344,9 @@ class ManiaExchangeManager { } /** - * Gets the Current Environment by String + * Get the Current Environment by String * - * @param $env + * @param string $env * @return int */ private function getEnvironment($env) { diff --git a/application/core/Manialinks/CustomUIManager.php b/application/core/Manialinks/CustomUIManager.php index 43a9f156..4e3d022c 100644 --- a/application/core/Manialinks/CustomUIManager.php +++ b/application/core/Manialinks/CustomUIManager.php @@ -52,11 +52,9 @@ class CustomUIManager implements CallbackListener, TimerListener { } /** - * Handle 1Second - * - * @param $time + * Handle 1 Second Callback */ - public function handle1Second($time) { + public function handle1Second() { if (!$this->updateManialink) { return; } diff --git a/application/core/Manialinks/IconManager.php b/application/core/Manialinks/IconManager.php index c7f0198b..8d81d565 100644 --- a/application/core/Manialinks/IconManager.php +++ b/application/core/Manialinks/IconManager.php @@ -76,9 +76,9 @@ class IconManager implements CallbackListener { } /** - * Get an Icon by its name + * Get an Icon by its Name * - * @param $iconName + * @param string $iconName * @return string */ public function getIcon($iconName) { diff --git a/application/core/Maps/Map.php b/application/core/Maps/Map.php index f30d8a53..dc8003f5 100644 --- a/application/core/Maps/Map.php +++ b/application/core/Maps/Map.php @@ -2,8 +2,8 @@ namespace ManiaControl\Maps; -use ManiaControl\Utils\Formatter; use ManiaControl\ManiaExchange\MXMapInfo; +use ManiaControl\Utils\Formatter; /** * Map Model Class diff --git a/application/core/Maps/MapActions.php b/application/core/Maps/MapActions.php index 89a1eef9..14093411 100644 --- a/application/core/Maps/MapActions.php +++ b/application/core/Maps/MapActions.php @@ -1,4 +1,10 @@ maps[$uid])) { @@ -417,7 +417,7 @@ class MapManager implements CallbackListener { /** * Initializes a Map * - * @param $rpcMap + * @param mixed $rpcMap * @return Map */ public function initializeMap($rpcMap) { diff --git a/application/core/Maps/MapQueue.php b/application/core/Maps/MapQueue.php index eee7ee06..73038e3c 100644 --- a/application/core/Maps/MapQueue.php +++ b/application/core/Maps/MapQueue.php @@ -7,9 +7,9 @@ use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\Callbacks; use ManiaControl\Commands\CommandListener; -use ManiaControl\Utils\Formatter; use ManiaControl\ManiaControl; use ManiaControl\Players\Player; +use ManiaControl\Utils\Formatter; use Maniaplanet\DedicatedServer\Xmlrpc\NextMapException; /** @@ -45,13 +45,6 @@ class MapQueue implements CallbackListener, CommandListener { private $buffer = array(); private $nextNoQueue = false; - /** - * Don't queue on the next MapChange - */ - public function dontQueueNextMapChange() { - $this->nextNoQueue = true; - } - /** * Create a new server MapQueue * @@ -80,6 +73,13 @@ class MapQueue implements CallbackListener, CommandListener { $this->maniaControl->commandManager->registerCommandListener(array('jb', 'jukebox', 'mapqueue'), $this, 'command_MapQueue', false, 'Shows current maps in Map-Queue.'); } + /** + * Don't queue on the next MapChange + */ + public function dontQueueNextMapChange() { + $this->nextNoQueue = true; + } + /** * Adds current map to buffer on startup */ @@ -201,7 +201,7 @@ class MapQueue implements CallbackListener, CommandListener { * Adds map as first map in queue (for /replay) * * @param Player $player - * @param Map $map + * @param Map $map */ public function addFirstMapToMapQueue(Player $player, Map $map) { if ($map) { @@ -303,7 +303,7 @@ class MapQueue implements CallbackListener, CommandListener { */ public function endMap(Map $map = null) { //Don't queue next map (for example on skip to map) - if($this->nextNoQueue){ + if ($this->nextNoQueue) { $this->nextNoQueue = false; return; } @@ -316,7 +316,7 @@ class MapQueue implements CallbackListener, CommandListener { $player = $queuedMap[0]; // Check if map is added via replay vote/command - if(isset($queuedMap[2]) && $queuedMap[2] === true) { + if (isset($queuedMap[2]) && $queuedMap[2] === true) { break; } @@ -352,9 +352,9 @@ class MapQueue implements CallbackListener, CommandListener { /** @var Map $map */ $this->maniaControl->chat->sendInformation('$fa0Next map will be $<$fff' . $map->name . '$> as requested by $<' . $this->nextMap[0]->nickname . '$>.'); - try{ + try { $this->maniaControl->client->setNextMapIdent($map->uid); - }catch (NextMapException $e){ + } catch (NextMapException $e) { } } @@ -415,9 +415,9 @@ class MapQueue implements CallbackListener, CommandListener { } /** - * Returns the Queuer of a Map + * Return the Queuer of a Map * - * @param $uid + * @param string $uid * @return mixed */ public function getQueuer($uid) { diff --git a/application/core/Players/Player.php b/application/core/Players/Player.php index 618610be..9cd2398f 100644 --- a/application/core/Players/Player.php +++ b/application/core/Players/Player.php @@ -2,9 +2,9 @@ namespace ManiaControl\Players; +use ManiaControl\ManiaControl; use ManiaControl\Utils\ClassUtil; use ManiaControl\Utils\Formatter; -use ManiaControl\ManiaControl; /** * Player Model Class @@ -80,6 +80,19 @@ class Player { } } + /** + * Get the Login of the Player + * + * @param mixed $player + * @return string + */ + public static function parseLogin($player) { + if (is_object($player) && property_exists($player, 'login')) { + return (string)$player->login; + } + return (string)$player; + } + /** * Get the Escaped Nickname * @@ -263,7 +276,7 @@ class Player { /** * Set the Cache Data for the given Name * - * @param $object + * @param mixed $object * @param string $cacheName * @param mixed $data */ @@ -273,10 +286,10 @@ class Player { } /** - * Destroys a Cache + * Destroy a Cache * - * @param mixed $object - * @param $cacheName + * @param mixed $object + * @param string $cacheName */ public function destroyCache($object, $cacheName) { $className = ClassUtil::getClass($object); @@ -290,14 +303,13 @@ class Player { $this->cache = array(); } - /** * Gets the Player Data * - * @param $object - * @param $dataName - * @param $serverIndex - * @return mixed|null + * @param mixed $object + * @param string $dataName + * @param int $serverIndex + * @return mixed */ public function getPlayerData($object, $dataName, $serverIndex = -1) { return $this->maniaControl->playerManager->playerDataManager->getPlayerData($object, $dataName, $this, $serverIndex); @@ -306,10 +318,10 @@ class Player { /** * Sets the Player Data * - * @param $object - * @param $dataName - * @param $value - * @param $serverIndex + * @param mixed $object + * @param string $dataName + * @param mixed $value + * @param int $serverIndex * @return bool */ public function setPlayerData($object, $dataName, $value, $serverIndex = -1) { @@ -324,7 +336,7 @@ class Player { } /** - * Dump the Players Cache + * Var_Dump the Players Cache */ public function dumpCache() { var_dump($this->cache); diff --git a/application/core/Players/PlayerDataManager.php b/application/core/Players/PlayerDataManager.php index fdba975d..6b385ecc 100644 --- a/application/core/Players/PlayerDataManager.php +++ b/application/core/Players/PlayerDataManager.php @@ -129,10 +129,10 @@ class PlayerDataManager { /** * Defines the Player-Data MetaData * - * @param $object - * @param $dataName - * @param $default - * @param $dataDescription (optional) + * @param mixed $object + * @param string $dataName + * @param mixed $default + * @param string $dataDescription (optional) * @return bool */ public function defineMetaData($object, $dataName, $default, $dataDescription = '') { @@ -198,11 +198,11 @@ class PlayerDataManager { /** * Gets the Player Data * - * @param mixed $object - * @param string $dataName - * @param Player $player - * @param int $serverIndex - * @return mixed|null + * @param mixed $object + * @param string $dataName + * @param Player $player + * @param int $serverIndex + * @return mixed */ public function getPlayerData($object, $dataName, Player $player, $serverIndex = -1) { $className = ClassUtil::getClass($object); @@ -254,11 +254,11 @@ class PlayerDataManager { /** * Set a PlayerData to a specific defined statMetaData * - * @param mixed $object - * @param string $dataName - * @param Player $player - * @param mixed $value - * @param int $serverIndex (let it empty if its global) + * @param mixed $object + * @param string $dataName + * @param Player $player + * @param mixed $value + * @param int $serverIndex (empty if it's global) * @return bool */ public function setPlayerData($object, $dataName, Player $player, $value, $serverIndex = -1) { diff --git a/application/core/Plugins/PluginManager.php b/application/core/Plugins/PluginManager.php index ce046166..6043428a 100644 --- a/application/core/Plugins/PluginManager.php +++ b/application/core/Plugins/PluginManager.php @@ -19,8 +19,8 @@ class PluginManager { /* * Constants */ - const TABLE_PLUGINS = 'mc_plugins'; - const CB_PLUGIN_LOADED = 'PluginManager.PluginLoaded'; + const TABLE_PLUGINS = 'mc_plugins'; + const CB_PLUGIN_LOADED = 'PluginManager.PluginLoaded'; const CB_PLUGIN_UNLOADED = 'PluginManager.PluginUnloaded'; /* @@ -400,9 +400,9 @@ class PluginManager { /** * Fetch the Plugins List from the ManiaControl Website * - * @param $function + * @param callable $function */ - public function fetchPluginList($function) { + public function fetchPluginList(callable $function) { $url = ManiaControl::URL_WEBSERVICE . 'plugins'; $this->maniaControl->fileReader->loadFile($url, function ($dataJson, $error) use (&$function) { diff --git a/application/core/Server/RankingManager.php b/application/core/Server/RankingManager.php index 27e84f9c..3828a548 100644 --- a/application/core/Server/RankingManager.php +++ b/application/core/Server/RankingManager.php @@ -71,7 +71,7 @@ class RankingManager implements CallbackListener { /** * Update Game Rankings (never call this Method) * - * @param $data + * @param string $data */ public function updateRankings($data) { if (!is_string($data)) { diff --git a/application/core/Server/Server.php b/application/core/Server/Server.php index 9130db9f..5500b230 100644 --- a/application/core/Server/Server.php +++ b/application/core/Server/Server.php @@ -4,8 +4,9 @@ namespace ManiaControl\Server; use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackManager; -use ManiaControl\Utils\CommandLineHelper; use ManiaControl\ManiaControl; +use ManiaControl\Players\Player; +use ManiaControl\Utils\CommandLineHelper; use Maniaplanet\DedicatedServer\Xmlrpc\Exception; /** @@ -260,10 +261,11 @@ class Server implements CallbackListener { /** * Retrieve Validation Replay for the given Player * - * @param $login + * @param string $login * @return string */ public function getValidationReplay($login) { + $login = Player::parseLogin($login); try { $replay = $this->maniaControl->client->getValidationReplay($login); } catch (Exception $e) { @@ -279,7 +281,7 @@ class Server implements CallbackListener { /** * Retrieve Ghost Replay for the given Player * - * @param $login + * @param string $login * @return string */ public function getGhostReplay($login) { @@ -289,6 +291,7 @@ class Server implements CallbackListener { } // Build file name + $login = Player::parseLogin($login); $map = $this->maniaControl->mapManager->getCurrentMap(); $gameMode = $this->getGameMode(); $time = time(); diff --git a/application/core/Server/ServerCommands.php b/application/core/Server/ServerCommands.php index 6a1d7309..f9063b18 100644 --- a/application/core/Server/ServerCommands.php +++ b/application/core/Server/ServerCommands.php @@ -210,12 +210,9 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage } /** - * Check stuff each 5 seconds - * - * @param $timer - * @return bool + * Check Stuff each 5 Seconds */ - public function each5Seconds($timer) { + public function each5Seconds() { // Empty shutdown if ($this->serverShutdownEmpty) { $players = $this->maniaControl->playerManager->getPlayers(); diff --git a/application/core/Statistics/StatisticManager.php b/application/core/Statistics/StatisticManager.php index 59201ff3..ed5fc458 100644 --- a/application/core/Statistics/StatisticManager.php +++ b/application/core/Statistics/StatisticManager.php @@ -313,7 +313,7 @@ class StatisticManager { /** * Return the Stat Id * - * @param $statName + * @param string $statName * @return int */ private function getStatId($statName) { diff --git a/application/plugins/MCTeam/ChatMessagePlugin.php b/application/plugins/MCTeam/ChatMessagePlugin.php index 2f7b7a9d..74a89709 100644 --- a/application/plugins/MCTeam/ChatMessagePlugin.php +++ b/application/plugins/MCTeam/ChatMessagePlugin.php @@ -142,14 +142,14 @@ class ChatMessagePlugin implements CommandListener, Plugin { * Checks if a Player is in the PlayerList and returns the nickname if he is, can be called per login, pid or nickname or lj for * (last joined) * - * @param $login + * @param mixed $login * @return mixed */ private function getTarget($login) { /** @var Player $player */ $player = null; foreach ($this->maniaControl->playerManager->getPlayers() as $player) { - if ($login == $player->login || $login == $player->pid || $login == $player->nickname) { + if ($login == $player && $login == $player->login || $login == $player->pid || $login == $player->nickname) { return $player->nickname; } } diff --git a/application/plugins/MCTeam/CustomVotesPlugin.php b/application/plugins/MCTeam/CustomVotesPlugin.php index 6f6af8a4..d1613ddb 100644 --- a/application/plugins/MCTeam/CustomVotesPlugin.php +++ b/application/plugins/MCTeam/CustomVotesPlugin.php @@ -486,8 +486,8 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP /** * Handle Standard Votes * - * @param $voteName - * @param $voteResult + * @param string $voteName + * @param float $voteResult */ public function handleVoteFinished($voteName, $voteResult) { if ($voteResult >= $this->currentVote->neededRatio) { @@ -563,9 +563,9 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP } /** - * Undefines a Vote + * Undefine a Vote * - * @param $voteIndex + * @param int $voteIndex */ public function undefineVote($voteIndex) { unset($this->voteCommands[$voteIndex]); @@ -600,11 +600,9 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP } /** - * Handle ManiaControl 1 Second callback - * - * @param $time + * Handle ManiaControl 1 Second Callback */ - public function handle1Second($time) { + public function handle1Second() { if (!isset($this->currentVote)) { return; } @@ -774,10 +772,10 @@ class VoteCommand { /** * Construct a new Vote Command * - * @param $index - * @param $name - * @param $idBased - * @param $neededRatio + * @param int $index + * @param string $name + * @param bool $idBased + * @param float $neededRatio */ public function __construct($index, $name, $idBased, $neededRatio) { $this->index = $index; diff --git a/application/plugins/MCTeam/Dedimania/DedimaniaData.php b/application/plugins/MCTeam/Dedimania/DedimaniaData.php index 509795c2..43c2bfdc 100644 --- a/application/plugins/MCTeam/Dedimania/DedimaniaData.php +++ b/application/plugins/MCTeam/Dedimania/DedimaniaData.php @@ -3,6 +3,7 @@ namespace MCTeam\Dedimania; use ManiaControl\ManiaControl; +use ManiaControl\Players\Player; use Maniaplanet\DedicatedServer\Structures\Version; /** @@ -52,6 +53,11 @@ class DedimaniaData { $this->serverBuild = $serverVersion->build; } + /** + * Build the Data Array + * + * @return array + */ public function toArray() { $array = array(); foreach (get_object_vars($this) as $key => $value) { @@ -63,6 +69,11 @@ class DedimaniaData { return $array; } + /** + * Get the Number of Records + * + * @return int + */ public function getRecordCount() { return count($this->records); } @@ -70,10 +81,11 @@ class DedimaniaData { /** * Get Max Rank for a certain Player * - * @param $login + * @param mixed $login * @return int */ public function getPlayerMaxRank($login) { + $login = Player::parseLogin($login); $maxRank = $this->serverMaxRank; foreach ($this->players as $player) { /** @var DedimaniaPlayer $player */ diff --git a/application/plugins/MCTeam/Dedimania/DedimaniaPlugin.php b/application/plugins/MCTeam/Dedimania/DedimaniaPlugin.php index 798ab982..2730cd2a 100644 --- a/application/plugins/MCTeam/Dedimania/DedimaniaPlugin.php +++ b/application/plugins/MCTeam/Dedimania/DedimaniaPlugin.php @@ -14,12 +14,12 @@ use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\Callbacks; use ManiaControl\Callbacks\TimerListener; use ManiaControl\Commands\CommandListener; -use ManiaControl\Utils\Formatter; use ManiaControl\ManiaControl; use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Players\Player; use ManiaControl\Players\PlayerManager; use ManiaControl\Plugins\Plugin; +use ManiaControl\Utils\Formatter; /** * ManiaControl Dedimania Plugin @@ -226,11 +226,11 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene /** * Handle xml rpc fault * - * @param $fault - * @param $method + * @param array $fault + * @param string $method */ - private function handleXmlRpcFault($fault, $method) { - trigger_error('XmlRpc Fault on ' . $method . ': ' . $fault['faultString'] . ' (' . $fault['faultCode'] . ')'); + private function handleXmlRpcFault(array $fault, $method) { + trigger_error("XmlRpc Fault on '{$method}': '{$fault['faultString']} ({$fault['faultCode']})!"); } /** @@ -505,11 +505,9 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene } /** - * Check if the session is alive every minute - * - * @param null $callback + * Handle 1 Minute Callback */ - public function handleEveryMinute($callback = null) { + public function handleEveryMinute() { if (!$this->init) { return; } @@ -633,21 +631,17 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene } /** - * Handle Begin Map - * - * @param $callback + * Handle Begin Map Callback */ - public function handleBeginMap($callback) { + public function handleBeginMap() { unset($this->dedimaniaData->records); $this->fetchDedimaniaRecords(true); } /** - * Handle EndMap callback - * - * @param $callback + * Handle EndMap Callback */ - public function handleMapEnd($callback) { + public function handleMapEnd() { if (!$this->dedimaniaData || !$this->dedimaniaData->records) { return; } @@ -714,11 +708,9 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene } /** - * Update the Playerlist every 3 Minutes - * - * @param $callback + * Update the PlayerList every 3 Minutes */ - public function updatePlayerList($callback) { + public function updatePlayerList() { $serverInfo = $this->getServerInfo(); $playerList = $this->getPlayerList(); $votesInfo = $this->getVotesInfo(); @@ -769,11 +761,11 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene } /** - * Handle PlayerCheckpoint callback + * Handle PlayerCheckpoint Callback * - * @param $callback + * @param array $callback */ - public function handlePlayerCheckpoint($callback) { + public function handlePlayerCheckpoint(array $callback) { $data = $callback[1]; $login = $data[1]; $time = $data[2]; @@ -786,11 +778,11 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene } /** - * Player finished callback + * Handle Player Finished Callback * - * @param $callback + * @param array $callback */ - public function handlePlayerFinished($callback) { + public function handlePlayerFinished(array $callback) { //var_dump($callback); $data = $callback[1]; if ($data[0] <= 0 || $data[2] <= 0) { diff --git a/application/plugins/MCTeam/KarmaPlugin.php b/application/plugins/MCTeam/KarmaPlugin.php index 5dfc69fe..cf4ac6a7 100644 --- a/application/plugins/MCTeam/KarmaPlugin.php +++ b/application/plugins/MCTeam/KarmaPlugin.php @@ -11,7 +11,6 @@ use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\Callbacks; use ManiaControl\Callbacks\TimerListener; -use ManiaControl\Utils\ColorUtil; use ManiaControl\ManiaControl; use ManiaControl\Maps\Map; use ManiaControl\Players\Player; @@ -20,6 +19,7 @@ use ManiaControl\Plugins\Plugin; use ManiaControl\Plugins\PluginMenu; use ManiaControl\Settings\Setting; use ManiaControl\Settings\SettingManager; +use ManiaControl\Utils\ColorUtil; /** * ManiaControl Karma Plugin @@ -280,7 +280,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { /** * Activates the MX-Karma Session * - * @param $mxKarmaCode + * @param string $mxKarmaCode */ private function activateSession($mxKarmaCode) { $hash = $this->buildActivationHash($this->mxKarma['session']->sessionSeed, $mxKarmaCode); @@ -323,8 +323,8 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { /** * Builds a sha512 activation Hash for the MX-Karma * - * @param $sessionSeed - * @param $mxKey + * @param string $sessionSeed + * @param string $mxKey * @return string */ private function buildActivationHash($sessionSeed, $mxKey) { @@ -756,11 +756,9 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { } /** - * Handle ManiaControl 1 Second callback - * - * @param $time + * Handle ManiaControl 1 Second Callback */ - public function handle1Second($time) { + public function handle1Second() { if (!$this->updateManialink) { return; } diff --git a/application/plugins/MCTeam/LocalRecordsPlugin.php b/application/plugins/MCTeam/LocalRecordsPlugin.php index 60894a68..c17f5440 100644 --- a/application/plugins/MCTeam/LocalRecordsPlugin.php +++ b/application/plugins/MCTeam/LocalRecordsPlugin.php @@ -15,7 +15,6 @@ use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\Callbacks; use ManiaControl\Callbacks\TimerListener; use ManiaControl\Commands\CommandListener; -use ManiaControl\Utils\Formatter; use ManiaControl\ManiaControl; use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Maps\Map; @@ -24,6 +23,7 @@ use ManiaControl\Players\PlayerManager; use ManiaControl\Plugins\Plugin; use ManiaControl\Settings\Setting; use ManiaControl\Settings\SettingManager; +use ManiaControl\Utils\Formatter; /** * ManiaControl Local Records Plugin @@ -182,11 +182,9 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList } /** - * Handle 1Second callback - * - * @param $time + * Handle 1 Second Callback */ - public function handle1Second($time) { + public function handle1Second() { if (!$this->updateManialink) { return; } @@ -352,12 +350,13 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList /** * Handle PlayerCheckpoint callback * - * @param $callback + * @param array $callback */ - public function handlePlayerCheckpoint($callback) { + public function handlePlayerCheckpoint(array $callback) { $data = $callback[1]; $login = $data[1]; $time = $data[2]; + // TODO: lap // $lap = $data[3]; $cpIndex = $data[4]; if (!isset($this->checkpoints[$login]) || $cpIndex <= 0) { diff --git a/application/plugins/TheM/QueuePlugin.php b/application/plugins/TheM/QueuePlugin.php index a8b3d009..1b393616 100644 --- a/application/plugins/TheM/QueuePlugin.php +++ b/application/plugins/TheM/QueuePlugin.php @@ -34,6 +34,8 @@ class QueuePlugin implements CallbackListener, ManialinkPageAnswerListener, Time */ const ID = 22; const VERSION = 0.12; + const AUTHOR = 'TheM'; + const NAME = 'Queue Plugin'; const ML_ID = 'Queue.Widget'; const ML_ADDTOQUEUE = 'Queue.Add'; const ML_REMOVEFROMQUEUE = 'Queue.Remove'; @@ -55,65 +57,49 @@ class QueuePlugin implements CallbackListener, ManialinkPageAnswerListener, Time private $maxPlayers = 0; /** - * Prepares the Plugin - * - * @param ManiaControl $maniaControl - * @return mixed + * @see \ManiaControl\Plugins\Plugin::prepare() */ public static function prepare(ManiaControl $maniaControl) { // TODO: Implement prepare() method. } /** - * Get plugin id - * - * @return int + * @see \ManiaControl\Plugins\Plugin::getId() */ public static function getId() { return self::ID; } /** - * Get Plugin Name - * - * @return string + * @see \ManiaControl\Plugins\Plugin::getName() */ public static function getName() { - return 'Queue Plugin'; + return self::NAME; } /** - * Get Plugin Version - * - * @return float + * @see \ManiaControl\Plugins\Plugin::getVersion() */ public static function getVersion() { return self::VERSION; } /** - * Get Plugin Author - * - * @return string + * @see \ManiaControl\Plugins\Plugin::getAuthor() */ public static function getAuthor() { - return 'TheM'; + return self::AUTHOR; } /** - * Get Plugin Description - * - * @return string + * @see \ManiaControl\Plugins\Plugin::getDescription() */ public static function getDescription() { return 'Plugin offers the known AutoQueue/SpecJam options.'; } /** - * Load the plugin - * - * @param ManiaControl $maniaControl - * @return bool + * @see \ManiaControl\Plugins\Plugin::load() */ public function load(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; @@ -156,7 +142,7 @@ class QueuePlugin implements CallbackListener, ManialinkPageAnswerListener, Time $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle(); - $maxQueue = $this->maniaControl->settingManager->getSettingValue($this, self::QUEUE_MAX); + $maxQueue = $this->maniaControl->settingManager->getSettingValue($this, self::QUEUE_MAX); // Main frame $frame = new Frame(); @@ -237,7 +223,7 @@ class QueuePlugin implements CallbackListener, ManialinkPageAnswerListener, Time } /** - * Unload the plugin and its resources + * @see \ManiaControl\Plugins\Plugin::unload() */ public function unload() { foreach ($this->spectators as $spectator) { @@ -299,9 +285,9 @@ class QueuePlugin implements CallbackListener, ManialinkPageAnswerListener, Time } /** - * Function removes a player from the queue. + * Remove a Player from the Queue * - * @param $login + * @param string $login */ private function removePlayerFromQueue($login) { $count = 0; @@ -317,6 +303,9 @@ class QueuePlugin implements CallbackListener, ManialinkPageAnswerListener, Time $this->showQueueWidgetSpectators(); } + /** + * Show the Queue Widgets to Spectators + */ public function showQueueWidgetSpectators() { foreach ($this->spectators as $login) { $player = $this->maniaControl->playerManager->getPlayer($login); @@ -445,7 +434,7 @@ class QueuePlugin implements CallbackListener, ManialinkPageAnswerListener, Time /** * Function sends (or not depending on setting) chatmessages for the queue. * - * @param $message + * @param string $message */ private function sendChatMessage($message) { if ($this->maniaControl->settingManager->getSettingValue($this, self::QUEUE_CHATMESSAGES)) { @@ -526,10 +515,8 @@ class QueuePlugin implements CallbackListener, ManialinkPageAnswerListener, Time /** * Checks for being of new map to retrieve maximum number of players. - * - * @param $currentMap */ - public function handleBeginMap($currentMap) { + public function handleBeginMap() { if ($this->maniaControl->client->getServerPassword() != false && $this->maniaControl->settingManager->getSettingValue($this, self::QUEUE_ACTIVE_ON_PASS) == false) { return; } diff --git a/application/plugins/TheM/TeamSpeakPlugin.php b/application/plugins/TheM/TeamSpeakPlugin.php index 9f0e9974..96fe5c5e 100644 --- a/application/plugins/TheM/TeamSpeakPlugin.php +++ b/application/plugins/TheM/TeamSpeakPlugin.php @@ -11,12 +11,12 @@ use FML\ManiaLink; use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\TimerListener; use ManiaControl\Commands\CommandListener; -use ManiaControl\Utils\Formatter; use ManiaControl\ManiaControl; use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Players\Player; use ManiaControl\Plugins\Plugin; +use ManiaControl\Utils\Formatter; /** * TeamSpeak Info plugin @@ -70,66 +70,6 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag $maniaControl->settingManager->initSetting(get_class(), self::TEAMSPEAK_QUERYPASS, ''); } - /** - * Load the plugin - * - * @param \ManiaControl\ManiaControl $maniaControl - * @return bool - */ - public function load(ManiaControl $maniaControl) { - $this->maniaControl = $maniaControl; - $this->checkConfig(); - - $this->refreshTime = time(); - - $this->maniaControl->manialinkManager->iconManager->addIcon(self::TS_ICON); - $this->maniaControl->manialinkManager->iconManager->addIcon(self::TS_ICON_MOVER); - - $this->maniaControl->timerManager->registerTimerListening($this, 'ts3_queryServer', 1000); - - $this->addToMenu(); - } - - - /** - * Function used to check certain configuration options to check if they can be used. - * - * @throws \Exception - */ - private function checkConfig() { - if ($this->maniaControl->settingManager->getSettingValue($this, self::TEAMSPEAK_SERVERHOST) == 'ts3.somehoster.com') { - $error = 'Missing the required serverhost, please set it up before enabling the TeamSpeak plugin!'; - throw new \Exception($error); - } - - $this->ts3_queryServer(); // Get latest information from the TeamSpeak server - if (!isset($this->serverData['channels']) || count($this->serverData['channels']) == 0) { - $error = 'Could not make proper connections with the server!'; - throw new \Exception($error); - } - } - - /** - * Function used insert the icon into the menu. - */ - private function addToMenu() { - $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_TSVIEWER, $this, 'command_tsViewer'); - $itemQuad = new Quad(); - $itemQuad->setImage($this->maniaControl->manialinkManager->iconManager->getIcon(self::TS_ICON)); - $itemQuad->setImageFocus($this->maniaControl->manialinkManager->iconManager->getIcon(self::TS_ICON_MOVER)); - $itemQuad->setAction(self::ACTION_OPEN_TSVIEWER); - $this->maniaControl->actionsMenu->addMenuItem($itemQuad, true, 1, 'Open TeamSpeak Viewer'); - } - - /** - * Unload the plugin and its resources - */ - public function unload() { - $this->serverData = array(); - - $this->maniaControl->actionsMenu->removeMenuItem(1, true); - } - /** * Get plugin id * @@ -175,6 +115,215 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag return 'Plugin offers a connection with a TeamSpeak server (via widgets).'; } + /** + * Load the plugin + * + * @param \ManiaControl\ManiaControl $maniaControl + * @return bool + */ + public function load(ManiaControl $maniaControl) { + $this->maniaControl = $maniaControl; + $this->checkConfig(); + + $this->refreshTime = time(); + + $this->maniaControl->manialinkManager->iconManager->addIcon(self::TS_ICON); + $this->maniaControl->manialinkManager->iconManager->addIcon(self::TS_ICON_MOVER); + + $this->maniaControl->timerManager->registerTimerListening($this, 'ts3_queryServer', 1000); + + $this->addToMenu(); + } + + /** + * Function used to check certain configuration options to check if they can be used. + * + * @throws \Exception + */ + private function checkConfig() { + if ($this->maniaControl->settingManager->getSettingValue($this, self::TEAMSPEAK_SERVERHOST) == 'ts3.somehoster.com') { + $error = 'Missing the required serverhost, please set it up before enabling the TeamSpeak plugin!'; + throw new \Exception($error); + } + + $this->ts3_queryServer(); // Get latest information from the TeamSpeak server + if (!isset($this->serverData['channels']) || count($this->serverData['channels']) == 0) { + $error = 'Could not make proper connections with the server!'; + throw new \Exception($error); + } + } + + /** + * TeamSpeak related functions + * The functions are based upon tsstatus.php from http://tsstatus.sebastien.me/ + * and were optimized by SilentStorm. + * Functions originally from the TeamSpeakInfo plugin made by undef.de for XAseco(2) and MPAseco. + */ + + public function ts3_queryServer() { + if (time() >= $this->refreshTime) { + $this->refreshTime = (time() + $this->refreshInterval); + + $queryHost = $this->maniaControl->settingManager->getSettingValue($this, self::TEAMSPEAK_QUERYHOST); + $host = $this->maniaControl->settingManager->getSettingValue($this, self::TEAMSPEAK_SERVERHOST); + + $host = ($queryHost != '') ? $queryHost : $host; + $queryPort = $this->maniaControl->settingManager->getSettingValue($this, self::TEAMSPEAK_QUERYPORT); + + $socket = fsockopen(@$host, $queryPort, $errno, $errstr, 2); + if ($socket) { + socket_set_timeout($socket, 2); + $is_ts3 = trim(fgets($socket)) == 'TS3'; + if (!$is_ts3) { + trigger_error('[TeamSpeakPlugin] Server at "' . $host . '" is not a Teamspeak3-Server or you have setup a bad query-port!', E_USER_WARNING); + } + + $queryuser = $this->maniaControl->settingManager->getSettingValue($this, self::TEAMSPEAK_QUERYUSER); + $querypass = $this->maniaControl->settingManager->getSettingValue($this, self::TEAMSPEAK_QUERYPASS); + if (($queryuser != '') && !is_numeric($queryuser) && $queryuser != false && ($querypass != '') && !is_numeric($querypass) && $querypass != false) { + $ret = $this->ts3_sendCommand($socket, 'login client_login_name=' . $this->ts3_escape($queryuser) . ' client_login_password=' . $this->ts3_escape($querypass)); + if (stripos($ret, "error id=0") === false) { + trigger_error("[TeamSpeakPlugin] Failed to authenticate with TS3 Server! Make sure you put the correct username & password in teamspeak.xml", E_USER_WARNING); + return; + } + } + + $response = ''; + $response .= $this->ts3_sendCommand($socket, 'use sid=' . $this->maniaControl->settingManager->getSettingValue($this, self::TEAMSPEAK_SID)); + $this->ts3_sendCommand($socket, 'clientupdate client_nickname=' . $this->ts3_escape('ManiaControl Viewer')); + $response .= $this->ts3_sendCommand($socket, 'serverinfo'); + $response .= $this->ts3_sendCommand($socket, 'channellist -topic -flags -voice -limits'); + $response .= $this->ts3_sendCommand($socket, 'clientlist -uid -away -voice -groups'); + + fputs($socket, "quit\n"); + fclose($socket); + + $lines = explode("error id=0 msg=ok\n\r", $response); + if (count($lines) == 5) { + $serverdata = $this->ts3_parseLine($lines[1]); + $this->serverData['server'] = $serverdata[0]; + $this->serverData['channels'] = $this->ts3_parseLine($lines[2]); + + $users = $this->ts3_parseLine($lines[3]); + $this->serverData['users'] = array(); // reset userslist + foreach ($users as $user) { + if ($user['client_nickname'] != 'ManiaControl Viewer') { + $this->serverData['users'][] = $user; + } + } + + // Subtract reserved slots + $this->serverData['server']['virtualserver_maxclients'] -= $this->serverData['server']['virtualserver_reserved_slots']; + + // Make ping value int + $this->serverData['server']['virtualserver_total_ping'] = intval($this->serverData['server']['virtualserver_total_ping']); + + // Format the Date of server startup + $this->serverData['server']['virtualserver_uptime'] = date('Y-m-d H:i:s', (time() - $this->serverData['server']['virtualserver_uptime'])); + + // Always subtract all Query Clients + $this->serverData['server']['virtualserver_clientsonline'] -= $this->serverData['server']['virtualserver_queryclientsonline']; + } + } else { + trigger_error("[TeamSpeakPlugin] Failed to connect with TS3 server; socket error: " . $errstr . " [" . $errno . "]", E_USER_WARNING); + } + } + } + + /** + * TS Function to send a command to the TeamSpeak server. + * + * @param resource $socket + * @param string $cmd + * @return string + */ + private function ts3_sendCommand($socket, $cmd) { + fputs($socket, "$cmd\n"); + + $response = ''; + /*while(strpos($response, 'error id=') === false) { + $response .= fread($socket, 8096); + }*/ + + /*while (!feof($socket)) { + $response .= fread($socket, 8192); + }*/ + + $info = array('timed_out' => false); + while (!feof($socket) && !$info['timed_out'] && strpos($response, 'error id=') === false) { + $response .= fread($socket, 1024); + $info = stream_get_meta_data($socket); + } + + return $response; + } + + /** + * TS Function used to escape characters in channelnames. + * + * @param string $str + * @return mixed + */ + private function ts3_escape($str) { + return str_replace(array(chr(92), chr(47), chr(32), chr(124), chr(7), chr(8), chr(12), chr(10), chr(3), chr(9), chr(11)), array('\\\\', "\/", "\s", "\p", "\a", "\b", "\f", "\n", "\r", "\t", "\v"), $str); + } + + /** + * TS Function used to parse lines in the serverresponse. + * + * @param string $rawLine + * @return array + */ + private function ts3_parseLine($rawLine) { + + $datas = array(); + $rawItems = explode('|', $rawLine); + + foreach ($rawItems as &$rawItem) { + $rawDatas = explode(' ', $rawItem); + $tempDatas = array(); + foreach ($rawDatas as &$rawData) { + $ar = explode("=", $rawData, 2); + $tempDatas[$ar[0]] = isset($ar[1]) ? $this->ts3_unescape($ar[1]) : ''; + } + $datas[] = $tempDatas; + } + unset($rawItem, $rawData); + + return $datas; + } + + /** + * TS Function used to unescape characters in channelnames. + * + * @param string $str + * @return mixed + */ + private function ts3_unescape($str) { + return str_replace(array('\\\\', "\/", "\s", "\p", "\a", "\b", "\f", "\n", "\r", "\t", "\v"), array(chr(92), chr(47), chr(32), chr(124), chr(7), chr(8), chr(12), chr(10), chr(3), chr(9), chr(11)), $str); + } + + /** + * Function used insert the icon into the menu. + */ + private function addToMenu() { + $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_TSVIEWER, $this, 'command_tsViewer'); + $itemQuad = new Quad(); + $itemQuad->setImage($this->maniaControl->manialinkManager->iconManager->getIcon(self::TS_ICON)); + $itemQuad->setImageFocus($this->maniaControl->manialinkManager->iconManager->getIcon(self::TS_ICON_MOVER)); + $itemQuad->setAction(self::ACTION_OPEN_TSVIEWER); + $this->maniaControl->actionsMenu->addMenuItem($itemQuad, true, 1, 'Open TeamSpeak Viewer'); + } + + /** + * Unload the plugin and its resources + */ + public function unload() { + $this->serverData = array(); + + $this->maniaControl->actionsMenu->removeMenuItem(1, true); + } + /** * Function handling the pressing of the icon. * @@ -188,7 +337,7 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag /** * Function showing the TeamSpeak widget to the player. * - * @param $player + * @param mixed $player */ private function showWidget($player) { $width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth(); @@ -256,7 +405,7 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag $channels->setHAlign('left'); $channels->setTextSize(1); $nochannels = 0; - foreach($this->serverData['channels'] as $channel) { + foreach ($this->serverData['channels'] as $channel) { if ($channel['channel_maxclients'] == 0 || strpos($channel['channel_name'], 'spacer') > 0) { continue; } @@ -288,51 +437,51 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag $userid = 0; $i = 0; $startx = -69.5; - foreach($this->serverData['channels'] as $channel) { + foreach ($this->serverData['channels'] as $channel) { if ($channel['channel_maxclients'] == 0 || strpos($channel['channel_name'], 'spacer') > 0) { continue; } $channelLabel = new Label_Text(); $frame->add($channelLabel); $y = 17.5 + ($i * 2.5); - $channelLabel->setY($height / 2 - $y); + $channelLabel->setY($height / 2 - $y); $x = $startx; if ($channel['pid'] != 0) { $x = $startx + 5; } - $channelLabel->setX($x); - $channelLabel->setStyle($channelLabel::STYLE_TextCardMedium); - $channelLabel->setHAlign('left'); - $channelLabel->setTextSize(1); - $channelLabel->setScale(0.9); + $channelLabel->setX($x); + $channelLabel->setStyle($channelLabel::STYLE_TextCardMedium); + $channelLabel->setHAlign('left'); + $channelLabel->setTextSize(1); + $channelLabel->setScale(0.9); if ($channel['channel_flag_default'] == 1) { $channel['total_clients'] = ($channel['total_clients'] - 1); } // remove query client - $channelLabel->setText('$o' . $channel['channel_name'] . '$o (' . $channel['total_clients'] . ')'); - $channelLabel->setTextColor('fff'); + $channelLabel->setText('$o' . $channel['channel_name'] . '$o (' . $channel['total_clients'] . ')'); + $channelLabel->setTextColor('fff'); - $channels[$i] = $channelLabel; + $channels[$i] = $channelLabel; $i++; - foreach($this->serverData['users'] as $user) { + foreach ($this->serverData['users'] as $user) { if ($user['cid'] == $channel['cid']) { - $userLabel = new Label_Text(); + $userLabel = new Label_Text(); $frame->add($userLabel); $y = 17.5 + ($i * 2.5); - $userLabel->setY($height / 2 - $y); + $userLabel->setY($height / 2 - $y); if ($channel['pid'] != 0) { $x = $startx + 7; } else { $x = $startx + 2; } - $userLabel->setX($x); - $userLabel->setStyle($userLabel::STYLE_TextCardMedium); - $userLabel->setHAlign('left'); - $userLabel->setTextSize(1); - $userLabel->setScale(0.9); - $userLabel->setText($user['client_nickname']); - $userLabel->setTextColor('fff'); - $users[$userid] = $userLabel; + $userLabel->setX($x); + $userLabel->setStyle($userLabel::STYLE_TextCardMedium); + $userLabel->setHAlign('left'); + $userLabel->setTextSize(1); + $userLabel->setScale(0.9); + $userLabel->setText($user['client_nickname']); + $userLabel->setTextColor('fff'); + $users[$userid] = $userLabel; $userid++; $i++; @@ -359,156 +508,4 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag $this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'TSViewer'); } - - /** - * TeamSpeak related functions - * The functions are based upon tsstatus.php from http://tsstatus.sebastien.me/ - * and were optimized by SilentStorm. - * Functions originally from the TeamSpeakInfo plugin made by undef.de for XAseco(2) and MPAseco. - */ - - public function ts3_queryServer() { - if (time() >= $this->refreshTime) { - $this->refreshTime = (time() + $this->refreshInterval); - - $queryHost = $this->maniaControl->settingManager->getSettingValue($this, self::TEAMSPEAK_QUERYHOST); - $host = $this->maniaControl->settingManager->getSettingValue($this, self::TEAMSPEAK_SERVERHOST); - - $host = ($queryHost != '') ? $queryHost : $host; - $queryPort = $this->maniaControl->settingManager->getSettingValue($this, self::TEAMSPEAK_QUERYPORT); - - $socket = fsockopen(@$host, $queryPort, $errno, $errstr, 2); - if ($socket) { - socket_set_timeout($socket, 2); - $is_ts3 = trim(fgets($socket)) == 'TS3'; - if (!$is_ts3) { - trigger_error('[TeamSpeakPlugin] Server at "' . $host . '" is not a Teamspeak3-Server or you have setup a bad query-port!', E_USER_WARNING); - } - - $queryuser = $this->maniaControl->settingManager->getSettingValue($this, self::TEAMSPEAK_QUERYUSER); - $querypass = $this->maniaControl->settingManager->getSettingValue($this, self::TEAMSPEAK_QUERYPASS); - if (($queryuser != '') && !is_numeric($queryuser) && $queryuser != false && ($querypass != '') && !is_numeric($querypass) && $querypass != false) { - $ret = $this->ts3_sendCommand($socket, 'login client_login_name=' . $this->ts3_escape($queryuser) . ' client_login_password=' . $this->ts3_escape($querypass)); - if (stripos($ret, "error id=0") === false) { - trigger_error("[TeamSpeakPlugin] Failed to authenticate with TS3 Server! Make sure you put the correct username & password in teamspeak.xml", E_USER_WARNING); - return; - } - } - - $response = ''; - $response .= $this->ts3_sendCommand($socket, 'use sid=' . $this->maniaControl->settingManager->getSettingValue($this, self::TEAMSPEAK_SID)); - $this->ts3_sendCommand($socket, 'clientupdate client_nickname=' . $this->ts3_escape('ManiaControl Viewer')); - $response .= $this->ts3_sendCommand($socket, 'serverinfo'); - $response .= $this->ts3_sendCommand($socket, 'channellist -topic -flags -voice -limits'); - $response .= $this->ts3_sendCommand($socket, 'clientlist -uid -away -voice -groups'); - - fputs($socket, "quit\n"); - fclose($socket); - - $lines = explode("error id=0 msg=ok\n\r", $response); - if (count($lines) == 5) { - $serverdata = $this->ts3_parseLine($lines[1]); - $this->serverData['server'] = $serverdata[0]; - $this->serverData['channels'] = $this->ts3_parseLine($lines[2]); - - $users = $this->ts3_parseLine($lines[3]); - $this->serverData['users'] = array(); // reset userslist - foreach($users as $user) { - if ($user['client_nickname'] != 'ManiaControl Viewer') { - $this->serverData['users'][] = $user; - } - } - - // Subtract reserved slots - $this->serverData['server']['virtualserver_maxclients'] -= $this->serverData['server']['virtualserver_reserved_slots']; - - // Make ping value int - $this->serverData['server']['virtualserver_total_ping'] = intval($this->serverData['server']['virtualserver_total_ping']); - - // Format the Date of server startup - $this->serverData['server']['virtualserver_uptime'] = date('Y-m-d H:i:s', (time() - $this->serverData['server']['virtualserver_uptime'])); - - // Always subtract all Query Clients - $this->serverData['server']['virtualserver_clientsonline'] -= $this->serverData['server']['virtualserver_queryclientsonline']; - } - } else { - trigger_error("[TeamSpeakPlugin] Failed to connect with TS3 server; socket error: " . $errstr . " [" . $errno . "]", E_USER_WARNING); - } - } - } - - /** - * TS Function to send a command to the TeamSpeak server. - * - * @param $socket - * @param $cmd - * @return string - */ - private function ts3_sendCommand($socket, $cmd) { - - fputs($socket, "$cmd\n"); - - $response = ''; - /*while(strpos($response, 'error id=') === false) { - $response .= fread($socket, 8096); - }*/ - - /*while (!feof($socket)) { - $response .= fread($socket, 8192); - }*/ - - $info = array('timed_out' => false); - while(!feof($socket) && !$info['timed_out'] && strpos($response, 'error id=') === false) { - $response .= fread($socket, 1024); - $info = stream_get_meta_data($socket); - } - - return $response; - } - - /** - * TS Function used to parse lines in the serverresponse. - * - * @param $rawLine - * @return array - */ - private function ts3_parseLine($rawLine) { - - $datas = array(); - $rawItems = explode('|', $rawLine); - - foreach($rawItems as &$rawItem) { - $rawDatas = explode(' ', $rawItem); - $tempDatas = array(); - foreach($rawDatas as &$rawData) { - $ar = explode("=", $rawData, 2); - $tempDatas[$ar[0]] = isset($ar[1]) ? $this->ts3_unescape($ar[1]) : ''; - } - $datas[] = $tempDatas; - } - unset($rawItem, $rawData); - - return $datas; - } - - /** - * TS Function used to escape characters in channelnames. - * - * @param $str - * @return mixed - */ - private function ts3_escape($str) { - return str_replace(array(chr(92), chr(47), chr(32), chr(124), chr(7), chr(8), chr(12), chr(10), chr(3), chr(9), chr(11)), array('\\\\', "\/", "\s", "\p", "\a", "\b", "\f", "\n", "\r", "\t", "\v"), $str); - } - - /** - * TS Function used to unescape characters in channelnames. - * - * @param $str - * @return mixed - */ - private function ts3_unescape($str) { - return str_replace(array('\\\\', "\/", "\s", "\p", "\a", "\b", "\f", "\n", "\r", "\t", "\v"), array(chr(92), chr(47), chr(32), chr(124), chr(7), chr(8), chr(12), chr(10), chr(3), chr(9), chr(11)), $str); - } - -} \ No newline at end of file +}