dedi improve
This commit is contained in:
parent
5728381093
commit
bfde33e388
@ -26,7 +26,7 @@ class MapManager implements CallbackListener {
|
||||
*/
|
||||
const TABLE_MAPS = 'mc_maps';
|
||||
const CB_BEGINMAP = 'MapManager.BeginMap';
|
||||
const CB_ENDMAP = 'MapManager.EndMap';
|
||||
const CB_ENDMAP = 'MapManager.EndMap';
|
||||
const CB_MAPS_UPDATED = 'MapManager.MapsUpdated';
|
||||
const CB_KARMA_UPDATED = 'MapManager.KarmaUpdated';
|
||||
const SETTING_PERMISSION_ADD_MAP = 'Add Maps';
|
||||
@ -330,11 +330,11 @@ class MapManager implements CallbackListener {
|
||||
$mapsDirectory = $this->maniaControl->server->getMapsDirectory();
|
||||
if (is_readable($mapsDirectory . $map->fileName)) {
|
||||
$mapFetcher = new \GBXChallMapFetcher(true);
|
||||
$mapFetcher->processFile($mapsDirectory . $map->fileName);
|
||||
$map->authorNick = FORMATTER::stripDirtyCodes($mapFetcher->authorNick);
|
||||
$map->authorEInfo = $mapFetcher->authorEInfo;
|
||||
$map->authorZone = $mapFetcher->authorZone;
|
||||
$map->comment = $mapFetcher->comment;
|
||||
$mapFetcher->processFile($mapsDirectory . $map->fileName);
|
||||
$map->authorNick = FORMATTER::stripDirtyCodes($mapFetcher->authorNick);
|
||||
$map->authorEInfo = $mapFetcher->authorEInfo;
|
||||
$map->authorZone = $mapFetcher->authorZone;
|
||||
$map->comment = $mapFetcher->comment;
|
||||
}
|
||||
return $map;
|
||||
}
|
||||
@ -373,7 +373,6 @@ class MapManager implements CallbackListener {
|
||||
|
||||
if (array_key_exists($rpcMap->uId, $this->maps)) {
|
||||
$this->currentMap = $this->maps[$rpcMap->uId];
|
||||
// TODO: why set numbers? shouldn't they be set already?
|
||||
$this->currentMap->nbCheckpoints = $rpcMap->nbCheckpoints;
|
||||
$this->currentMap->nbLaps = $rpcMap->nbLaps;
|
||||
return $this->currentMap;
|
||||
@ -437,17 +436,22 @@ class MapManager implements CallbackListener {
|
||||
|
||||
if (!isset($callback[1][0]["UId"])) {
|
||||
// TODO: why can this even happen?
|
||||
$this->maniaControl->errorHandler->triggerDebugNotice('map uid not set! '.print_r($callback, true));
|
||||
$this->maniaControl->errorHandler->triggerDebugNotice('map uid not set! ' . print_r($callback, true));
|
||||
return;
|
||||
}
|
||||
if (array_key_exists($callback[1][0]["UId"], $this->maps)) {
|
||||
// Map already exists, only update index
|
||||
$this->currentMap = $this->maps[$callback[1][0]["UId"]];
|
||||
if (!$this->currentMap->nbCheckpoints || !$this->currentMap->nbLaps) {
|
||||
$rpcMap = $this->maniaControl->client->getCurrentMapInfo();
|
||||
$this->currentMap->nbLaps = $rpcMap->nbLaps;
|
||||
$this->currentMap->nbCheckpoints = $rpcMap->nbCheckpoints;
|
||||
}
|
||||
} else {
|
||||
$rpcMap = \Maniaplanet\DedicatedServer\Structures\Map::fromArray($callback[1][0]);
|
||||
$rpcMap = \Maniaplanet\DedicatedServer\Structures\Map::fromArray($callback[1][0]);
|
||||
$this->currentMap = $this->initializeMap($rpcMap);
|
||||
// TODO: can this ever happen?
|
||||
$this->maniaControl->errorHandler->triggerDebugNotice("new map wasn't fetched yet! ".$callback[1][0]["UId"]);
|
||||
$this->maniaControl->errorHandler->triggerDebugNotice("new map wasn't fetched yet! " . $callback[1][0]["UId"]);
|
||||
}
|
||||
|
||||
// Restructure MapList if id is over 15
|
||||
|
@ -208,6 +208,7 @@ class PlayerManager implements CallbackListener {
|
||||
|
||||
//Check if Player finished joining the game
|
||||
if ($player->hasJoinedGame && !$prevJoinState) {
|
||||
var_dump("test1234");
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer()) {
|
||||
$string = array(0 => '$0f0Player', 1 => '$0f0Moderator', 2 => '$0f0Admin', 3 => '$0f0SuperAdmin', 4 => '$0f0MasterAdmin');
|
||||
$chatMessage = '$s$0f0' . $string[$player->authLevel] . ' $fff' . $player->nickname . '$z$s$0f0 Nation:$fff ' . $player->getCountry() . ' $z$s$0f0joined!';
|
||||
|
@ -79,7 +79,7 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_POSY, 7);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_WIDTH, 40);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_LINEHEIGHT, 4);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_LINESCOUNT, 15);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_LINESCOUNT, 12);
|
||||
|
||||
//TODO what was CB_IC_ClientUpdated?
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'handleBeginMap');
|
||||
@ -167,10 +167,14 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
|
||||
if (!$this->updateManialink) {
|
||||
return;
|
||||
}
|
||||
$this->updateManialink = false;
|
||||
var_dump($this->dedimaniaData->records);
|
||||
if (!$this->dedimaniaData->records) {
|
||||
return;
|
||||
}
|
||||
var_dump("update");
|
||||
|
||||
$this->updateManialink = false;
|
||||
|
||||
$manialink = $this->buildManialink();
|
||||
$this->maniaControl->manialinkManager->sendManialink($manialink);
|
||||
}
|
||||
@ -181,8 +185,9 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
|
||||
* @param null $callback
|
||||
*/
|
||||
public function handleEveryMinute($callback = null) {
|
||||
if (!$this->init)
|
||||
if (!$this->init) {
|
||||
return;
|
||||
}
|
||||
$this->checkDedimaniaSession();
|
||||
}
|
||||
|
||||
@ -270,8 +275,9 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
|
||||
* @param $callback
|
||||
*/
|
||||
public function handleMapEnd($callback) {
|
||||
if (!$this->dedimaniaData->records)
|
||||
if (!$this->dedimaniaData->records) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Send dedimania records
|
||||
$gameMode = $this->getGameModeString();
|
||||
@ -399,6 +405,7 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
|
||||
* @param $callback
|
||||
*/
|
||||
public function handlePlayerFinished($callback) {
|
||||
//var_dump($callback);
|
||||
$data = $callback[1];
|
||||
if ($data[0] <= 0 || $data[2] <= 0) {
|
||||
return;
|
||||
@ -419,35 +426,49 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
|
||||
if ($oldRecord['Best'] <= $time) {
|
||||
$save = false;
|
||||
}
|
||||
|
||||
if ($save) {
|
||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||
// Save time
|
||||
$newRecord = array('Login' => $login, 'NickName' => $player->nickname, 'Best' => $data[2], 'Checks' => $this->getCheckpoints($login), 'New' => true);
|
||||
$inserted = $this->insertDedimaniaRecord($newRecord, $oldRecord);
|
||||
if ($inserted) {
|
||||
// Get newly saved record
|
||||
foreach($this->dedimaniaData['records']['Records'] as &$record) {
|
||||
if ($record['Login'] !== $newRecord['Login']) {
|
||||
continue;
|
||||
}
|
||||
$newRecord = $record;
|
||||
break;
|
||||
}
|
||||
|
||||
// Announce record
|
||||
if (!$oldRecord || $newRecord['Rank'] < $oldRecord['Rank']) {
|
||||
// Gained rank
|
||||
$improvement = 'gained the';
|
||||
} else {
|
||||
// Only improved time
|
||||
$improvement = 'improved her/his';
|
||||
}
|
||||
$message = '$<' . $player['NickName'] . '$> ' . $improvement . ' $<$o' . $newRecord['Rank'] . '.$> Dedimania Record: ' . Formatter::formatTime($newRecord['Best']);
|
||||
$this->maniaControl->chat->sendInformation($message);
|
||||
$this->updateManialink = true;
|
||||
if ($this->insertDedimaniaRecord($newRecord, $oldRecord)) {
|
||||
$this->displayRecordData($player, $oldRecord, $newRecord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the Record Data
|
||||
*
|
||||
* @param $player
|
||||
* @param $oldRecord
|
||||
* @param $newRecord
|
||||
*/
|
||||
private function displayRecordData($player, $oldRecord, $newRecord) {
|
||||
// Get newly saved record
|
||||
foreach($this->dedimaniaData['records']['Records'] as &$record) {
|
||||
if ($record['Login'] !== $newRecord['Login']) {
|
||||
continue;
|
||||
}
|
||||
$newRecord = $record;
|
||||
break;
|
||||
}
|
||||
|
||||
// Announce record
|
||||
if (!$oldRecord || $newRecord['Rank'] < $oldRecord['Rank']) {
|
||||
// Gained rank
|
||||
$improvement = 'gained the';
|
||||
} else {
|
||||
// Only improved time
|
||||
$improvement = 'improved her/his';
|
||||
}
|
||||
$message = '$<' . $player['NickName'] . '$> ' . $improvement . ' $<$o' . $newRecord['Rank'] . '.$> Dedimania Record: ' . Formatter::formatTime($newRecord['Best']);
|
||||
$this->maniaControl->chat->sendInformation($message);
|
||||
|
||||
$this->updateManialink = true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -473,7 +494,6 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
|
||||
if (!$serverInfo || !$playerInfo || !$mapInfo || !$gameMode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = array($this->dedimaniaData->sessionId, $mapInfo, $gameMode, $serverInfo, $playerInfo);
|
||||
$content = $this->encode_request(self::DEDIMANIA_GETRECORDS, $data);
|
||||
|
||||
@ -483,6 +503,7 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
|
||||
}
|
||||
|
||||
$data = $this->decode($data);
|
||||
|
||||
if (is_array($data)) {
|
||||
foreach($data as $index => $methodResponse) {
|
||||
if (xmlrpc_is_fault($methodResponse)) {
|
||||
@ -543,7 +564,7 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
|
||||
* @return bool
|
||||
*/
|
||||
private function insertDedimaniaRecord(&$newRecord, $oldRecord) {
|
||||
if (!$newRecord || !isset($this->dedimaniaData->records) || !isset($this->dedimaniaData->records['Records'])) {
|
||||
if (!$newRecord || !$this->dedimaniaData->records || !isset($this->dedimaniaData->records['Records'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -581,8 +602,9 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
|
||||
if ($oldRecord) {
|
||||
// Remove old record
|
||||
foreach($this->dedimaniaData->records['Records'] as $key2 => $record2) {
|
||||
if ($record2['Login'] !== $oldRecord['Login'])
|
||||
if ($record2['Login'] !== $oldRecord['Login']) {
|
||||
continue;
|
||||
}
|
||||
unset($this->dedimaniaData->records['Records'][$key2]);
|
||||
break;
|
||||
}
|
||||
@ -604,8 +626,9 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
|
||||
|
||||
// Save replays
|
||||
foreach($this->dedimaniaData->records['Records'] as &$record) {
|
||||
if ($record['Login'] !== $newRecord['Login'])
|
||||
if ($record['Login'] !== $newRecord['Login']) {
|
||||
continue;
|
||||
}
|
||||
$this->setRecordReplays($record);
|
||||
break;
|
||||
}
|
||||
@ -620,8 +643,9 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
|
||||
* Update the sorting and the ranks of all dedimania records
|
||||
*/
|
||||
private function updateDedimaniaRecordRanks() {
|
||||
if (!isset($this->dedimaniaData->records) || !isset($this->dedimaniaData->records['Records']))
|
||||
if (!$this->dedimaniaData->records|| !isset($this->dedimaniaData->records['Records'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Sort records
|
||||
usort($this->dedimaniaData->records['Records'], array($this, 'compareRecords'));
|
||||
@ -663,8 +687,9 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
|
||||
private function setRecordReplays(&$record) {
|
||||
// Set validation replay
|
||||
$validationReplay = $this->maniaControl->server->getValidationReplay($record['Login']);
|
||||
if ($validationReplay)
|
||||
if ($validationReplay) {
|
||||
$record['VReplay'] = $validationReplay;
|
||||
}
|
||||
|
||||
// Set ghost replay
|
||||
if ($record['Rank'] <= 1) {
|
||||
@ -678,8 +703,9 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
|
||||
}
|
||||
if ($this->dedimaniaData->directoryAccessChecked) {
|
||||
$ghostReplay = $this->maniaControl->server->getGhostReplay($record['Login']);
|
||||
if ($ghostReplay)
|
||||
if ($ghostReplay) {
|
||||
$record['Top1GReplay'] = $ghostReplay;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -688,14 +714,16 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
|
||||
* Get max rank for given login
|
||||
*/
|
||||
private function getMaxRank($login) {
|
||||
if (!isset($this->dedimaniaData->records))
|
||||
if (!isset($this->dedimaniaData->records)) {
|
||||
return null;
|
||||
}
|
||||
$records = $this->dedimaniaData->records;
|
||||
$maxRank = $records['ServerMaxRank'];
|
||||
foreach($records['Players'] as $player) {
|
||||
if ($player['Login'] === $login) {
|
||||
if ($player['MaxRank'] > $maxRank)
|
||||
if ($player['MaxRank'] > $maxRank) {
|
||||
$maxRank = $player['MaxRank'];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -781,12 +809,14 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
|
||||
* @return array $record
|
||||
*/
|
||||
private function getDedimaniaRecord($login) {
|
||||
if (!isset($this->dedimaniaData->records))
|
||||
if (!$this->dedimaniaData->records) {
|
||||
return null;
|
||||
}
|
||||
$records = $this->dedimaniaData->records['Records'];
|
||||
foreach($records as $record) {
|
||||
if ($record['Login'] === $login)
|
||||
if ($record['Login'] === $login) {
|
||||
return $record;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -825,14 +855,16 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
|
||||
* @return string
|
||||
*/
|
||||
private function getCheckpoints($login) {
|
||||
if (!$login || !isset($this->checkpoints[$login]))
|
||||
if (!$login || !isset($this->checkpoints[$login])) {
|
||||
return null;
|
||||
}
|
||||
$string = '';
|
||||
$count = count($this->checkpoints[$login]);
|
||||
foreach($this->checkpoints[$login] as $index => $check) {
|
||||
$string .= $check;
|
||||
if ($index < $count - 1)
|
||||
if ($index < $count - 1) {
|
||||
$string .= ',';
|
||||
}
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
@ -899,8 +931,9 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
|
||||
$titleLabel->setTranslate(true);
|
||||
|
||||
foreach($records as $index => $record) {
|
||||
if ($index >= $lines)
|
||||
if ($index >= $lines) {
|
||||
break;
|
||||
}
|
||||
|
||||
$y = -8. - $index * $lineHeight;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user