function onInit() { $this->setVersion('4.0.0'); $this->addDependency(new \ManiaLive\PluginHandler\Dependency('ManiaLive', '4.0.0')); //Load MatchMaker and helpers for GUI $this->config = Config::getInstance(); $this->scriptName = \ManiaLivePlugins\MatchMakingLobby\Config::getInstance()->script ?: preg_replace('~(?:.*?[\\\\/])?(.*?)\\.Script\\.txt~ui', '$1', $this->storage->gameInfos->scriptName); $matchMakerClassName = $this->config->getMatchMakerClassName($this->scriptName); if (!class_exists($matchMakerClassName)) { throw new \Exception(sprintf("Can't find class %s. You should either set up the config : ManiaLivePlugins\\MatchMakingLobby\\Config.matchMakerClassName or the script name", $matchMakerClassName)); } $guiClassName = $this->config->getGuiClassName($this->scriptName); if (!class_exists($guiClassName)) { throw new \Exception(sprintf("Can't find class %s. You should either set up the config : ManiaLivePlugins\\MatchMakingLobby\\Config.guiClassName or the script name", $guiClassName)); } $this->matchMakingService = new Services\MatchMakingService(); $this->matchMakingService->createTables(); $this->setGui(new $guiClassName()); $this->gui->lobbyBoxPosY = 45; $this->setMatchMaker($matchMakerClassName::getInstance()); $this->dictionary = \ManiaLivePlugins\MatchMakingLobby\Utils\Dictionary::getInstance($this->config->getDictionnary($this->scriptName)); $this->allyService = Services\AllyService::getInstance($this->storage->serverLogin, $this->scriptName, $this->connection->getSystemInfo()->titleId); return true; }
function onModeScriptCallback($param1, $param2) { switch ($param1) { case 'Master': $login = $param2[0]; $player = $this->storage->getPlayerObject($login); if ($player !== null) { $service = new Services\MatchMakingService(); $service->addMaster($login, $player->nickName, $player->ladderStats['PlayerRankings'][0]['Score'], $this->lobby->login, $this->scriptName, $this->titleIdString); } break; case 'MatchmakingGetOrder': if ($this->match) { $allyService = Services\AllyService::getInstance($this->lobby->login, $this->scriptName, $this->titleIdString); $alliesList = array(); foreach ($this->match->players as $login) { $alliesList = array_merge($alliesList, $allyService->get($login)); } $alliesList = array_unique($alliesList); $this->connection->triggerModeScriptEvent('MatchmakingSetTempAllies', implode(',', $alliesList)); } break; case 'LibXmlRpc_Scores': if ($this->matchId) { $this->scores['match'][0] = $param2[0]; $this->scores['match'][1] = $param2[1]; $this->scores['map'][0] = $param2[2]; $this->scores['map'][1] = $param2[3]; $this->matchMakingService->updateMatchScores($this->matchId, $this->scores['match'][0], $this->scores['match'][1], $this->scores['map'][0], $this->scores['map'][1]); } break; case 'LibXmlRpc_EndRound': $this->connection->triggerModeScriptEvent('LibXmlRpc_GetScores', ''); break; case 'LibXmlRpc_EndTurn': $this->connection->triggerModeScriptEvent('LibXmlRpc_GetScores', ''); break; case 'LibXmlRpc_EndMap': $this->connection->triggerModeScriptEvent('LibXmlRpc_GetScores', ''); break; case 'LibXmlRpc_EndMatch': $this->connection->triggerModeScriptEvent('LibXmlRpc_GetScores', ''); break; } }
/** * update the Player list * @param string $login * @param string[] $blockedPlayerList */ final function updatePlayerList(array $blockedPlayerList, $setLocalAllyAction, $unsetLocalAllyAction, $maxAllyCount, $player = '') { if ($player) { $playerLists = Windows\PlayerList::Get($player); } else { $playerLists = Windows\PlayerList::GetAll(); } foreach ($playerLists as $playerList) { $recipient = $playerList->getRecipient(); $allies = \ManiaLivePlugins\MatchMakingLobby\Services\AllyService::getInstance()->getAll($recipient); $loginsWithUnsetAction = array_map(function (\ManiaLivePlugins\MatchMakingLobby\Services\Ally $a) { if ($a->type == \ManiaLivePlugins\MatchMakingLobby\Services\Ally::TYPE_LOCAL) { return $a->login; } }, $allies); $loginsWithNoAction = array_map(function (\ManiaLivePlugins\MatchMakingLobby\Services\Ally $a) { if ($a->type == \ManiaLivePlugins\MatchMakingLobby\Services\Ally::TYPE_GENERAL) { return $a->login; } }, $allies); $bilateralAllies = array_map(function (\ManiaLivePlugins\MatchMakingLobby\Services\Ally $a) { if ($a->isBilateral) { return $a->login; } }, $allies); $storage = Storage::getInstance(); foreach (array_merge($storage->players, $storage->spectators) as $player) { if (PlayerInfo::Get($player->login)->isAway()) { continue; } $ladderPoints = $player->ladderStats['PlayerRankings'][0]['Score']; $playerInfo = PlayerInfo::Get($player->login); $state = Player::STATE_NOT_READY; if ($playerInfo->isReady()) { $state = Player::STATE_READY; } if ($playerInfo->isInMatch) { $state = Player::STATE_IN_MATCH; } if (array_key_exists($player->login, $blockedPlayerList)) { $state = Player::STATE_BLOCKED; } if ($player->login == $recipient) { $action = null; $isAlly = false; } elseif (in_array($player->login, $loginsWithNoAction)) { $action = null; $isAlly = true; } elseif (in_array($player->login, $loginsWithUnsetAction)) { $action = $unsetLocalAllyAction; $isAlly = true; } else { $action = count($allies) >= $maxAllyCount ? null : $setLocalAllyAction; $isAlly = false; } $isBilateral = in_array($player->login, $bilateralAllies); $playerList->setPlayer($player->login, $player->nickName, $ladderPoints, $state, $action, $isAlly, $isBilateral); } } Windows\PlayerList::RedrawAll(); }