dedi improve

This commit is contained in:
kremsy 2014-02-20 13:06:11 +01:00 committed by Steffen Schröder
parent 5728381093
commit bfde33e388
3 changed files with 99 additions and 61 deletions

View File

@ -26,7 +26,7 @@ class MapManager implements CallbackListener {
*/ */
const TABLE_MAPS = 'mc_maps'; const TABLE_MAPS = 'mc_maps';
const CB_BEGINMAP = 'MapManager.BeginMap'; const CB_BEGINMAP = 'MapManager.BeginMap';
const CB_ENDMAP = 'MapManager.EndMap'; const CB_ENDMAP = 'MapManager.EndMap';
const CB_MAPS_UPDATED = 'MapManager.MapsUpdated'; const CB_MAPS_UPDATED = 'MapManager.MapsUpdated';
const CB_KARMA_UPDATED = 'MapManager.KarmaUpdated'; const CB_KARMA_UPDATED = 'MapManager.KarmaUpdated';
const SETTING_PERMISSION_ADD_MAP = 'Add Maps'; const SETTING_PERMISSION_ADD_MAP = 'Add Maps';
@ -330,11 +330,11 @@ class MapManager implements CallbackListener {
$mapsDirectory = $this->maniaControl->server->getMapsDirectory(); $mapsDirectory = $this->maniaControl->server->getMapsDirectory();
if (is_readable($mapsDirectory . $map->fileName)) { if (is_readable($mapsDirectory . $map->fileName)) {
$mapFetcher = new \GBXChallMapFetcher(true); $mapFetcher = new \GBXChallMapFetcher(true);
$mapFetcher->processFile($mapsDirectory . $map->fileName); $mapFetcher->processFile($mapsDirectory . $map->fileName);
$map->authorNick = FORMATTER::stripDirtyCodes($mapFetcher->authorNick); $map->authorNick = FORMATTER::stripDirtyCodes($mapFetcher->authorNick);
$map->authorEInfo = $mapFetcher->authorEInfo; $map->authorEInfo = $mapFetcher->authorEInfo;
$map->authorZone = $mapFetcher->authorZone; $map->authorZone = $mapFetcher->authorZone;
$map->comment = $mapFetcher->comment; $map->comment = $mapFetcher->comment;
} }
return $map; return $map;
} }
@ -373,12 +373,11 @@ class MapManager implements CallbackListener {
if (array_key_exists($rpcMap->uId, $this->maps)) { if (array_key_exists($rpcMap->uId, $this->maps)) {
$this->currentMap = $this->maps[$rpcMap->uId]; $this->currentMap = $this->maps[$rpcMap->uId];
// TODO: why set numbers? shouldn't they be set already?
$this->currentMap->nbCheckpoints = $rpcMap->nbCheckpoints; $this->currentMap->nbCheckpoints = $rpcMap->nbCheckpoints;
$this->currentMap->nbLaps = $rpcMap->nbLaps; $this->currentMap->nbLaps = $rpcMap->nbLaps;
return $this->currentMap; return $this->currentMap;
} }
$this->currentMap = $this->initializeMap($rpcMap); $this->currentMap = $this->initializeMap($rpcMap);
$this->maps[$this->currentMap->uid] = $this->currentMap; $this->maps[$this->currentMap->uid] = $this->currentMap;
return $this->currentMap; return $this->currentMap;
@ -434,32 +433,37 @@ class MapManager implements CallbackListener {
} }
$this->mapBegan = true; $this->mapBegan = true;
$this->mapEnded = false; $this->mapEnded = false;
if (!isset($callback[1][0]["UId"])) { if (!isset($callback[1][0]["UId"])) {
// TODO: why can this even happen? // 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; return;
} }
if (array_key_exists($callback[1][0]["UId"], $this->maps)) { if (array_key_exists($callback[1][0]["UId"], $this->maps)) {
// Map already exists, only update index // Map already exists, only update index
$this->currentMap = $this->maps[$callback[1][0]["UId"]]; $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 { } else {
$rpcMap = \Maniaplanet\DedicatedServer\Structures\Map::fromArray($callback[1][0]); $rpcMap = \Maniaplanet\DedicatedServer\Structures\Map::fromArray($callback[1][0]);
$this->currentMap = $this->initializeMap($rpcMap); $this->currentMap = $this->initializeMap($rpcMap);
// TODO: can this ever happen? // 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 // Restructure MapList if id is over 15
$this->restructureMapList(); $this->restructureMapList();
// Update the mx of the map (for update checks, etc.) // Update the mx of the map (for update checks, etc.)
$this->mxManager->fetchManiaExchangeMapInformations($this->currentMap); $this->mxManager->fetchManiaExchangeMapInformations($this->currentMap);
// Trigger own BeginMap callback // Trigger own BeginMap callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_BEGINMAP, $this->currentMap); $this->maniaControl->callbackManager->triggerCallback(self::CB_BEGINMAP, $this->currentMap);
} }
/** /**
* Handle Script BeginMap callback * Handle Script BeginMap callback
* *
@ -468,10 +472,10 @@ class MapManager implements CallbackListener {
public function handleScriptBeginMap(array $callback) { public function handleScriptBeginMap(array $callback) {
// ignored // ignored
} }
/** /**
* Handle EndMap Callback * Handle EndMap Callback
* *
* @param array $callback * @param array $callback
*/ */
public function handleEndMap(array $callback) { public function handleEndMap(array $callback) {
@ -484,10 +488,10 @@ class MapManager implements CallbackListener {
// Trigger own EndMap callback // Trigger own EndMap callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_ENDMAP, $this->currentMap); $this->maniaControl->callbackManager->triggerCallback(self::CB_ENDMAP, $this->currentMap);
} }
/** /**
* Handle Script EndMap Callback * Handle Script EndMap Callback
* *
* @param array $callback * @param array $callback
*/ */
public function handleScriptEndMap(array $callback) { public function handleScriptEndMap(array $callback) {
@ -512,7 +516,7 @@ class MapManager implements CallbackListener {
/** /**
* Get all Maps * Get all Maps
* *
* @return array * @return array
*/ */
public function getMaps() { public function getMaps() {

View File

@ -208,6 +208,7 @@ class PlayerManager implements CallbackListener {
//Check if Player finished joining the game //Check if Player finished joining the game
if ($player->hasJoinedGame && !$prevJoinState) { if ($player->hasJoinedGame && !$prevJoinState) {
var_dump("test1234");
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer()) { 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'); $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!'; $chatMessage = '$s$0f0' . $string[$player->authLevel] . ' $fff' . $player->nickname . '$z$s$0f0 Nation:$fff ' . $player->getCountry() . ' $z$s$0f0joined!';

View File

@ -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_POSY, 7);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_WIDTH, 40); $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_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? //TODO what was CB_IC_ClientUpdated?
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'handleBeginMap'); $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'handleBeginMap');
@ -167,10 +167,14 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
if (!$this->updateManialink) { if (!$this->updateManialink) {
return; return;
} }
$this->updateManialink = false; var_dump($this->dedimaniaData->records);
if (!$this->dedimaniaData->records) { if (!$this->dedimaniaData->records) {
return; return;
} }
var_dump("update");
$this->updateManialink = false;
$manialink = $this->buildManialink(); $manialink = $this->buildManialink();
$this->maniaControl->manialinkManager->sendManialink($manialink); $this->maniaControl->manialinkManager->sendManialink($manialink);
} }
@ -181,8 +185,9 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
* @param null $callback * @param null $callback
*/ */
public function handleEveryMinute($callback = null) { public function handleEveryMinute($callback = null) {
if (!$this->init) if (!$this->init) {
return; return;
}
$this->checkDedimaniaSession(); $this->checkDedimaniaSession();
} }
@ -270,8 +275,9 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
* @param $callback * @param $callback
*/ */
public function handleMapEnd($callback) { public function handleMapEnd($callback) {
if (!$this->dedimaniaData->records) if (!$this->dedimaniaData->records) {
return; return;
}
// Send dedimania records // Send dedimania records
$gameMode = $this->getGameModeString(); $gameMode = $this->getGameModeString();
@ -399,6 +405,7 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
* @param $callback * @param $callback
*/ */
public function handlePlayerFinished($callback) { public function handlePlayerFinished($callback) {
//var_dump($callback);
$data = $callback[1]; $data = $callback[1];
if ($data[0] <= 0 || $data[2] <= 0) { if ($data[0] <= 0 || $data[2] <= 0) {
return; return;
@ -419,35 +426,49 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
if ($oldRecord['Best'] <= $time) { if ($oldRecord['Best'] <= $time) {
$save = false; $save = false;
} }
if ($save) { if ($save) {
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
// Save time // Save time
$newRecord = array('Login' => $login, 'NickName' => $player->nickname, 'Best' => $data[2], 'Checks' => $this->getCheckpoints($login), 'New' => true); $newRecord = array('Login' => $login, 'NickName' => $player->nickname, 'Best' => $data[2], 'Checks' => $this->getCheckpoints($login), 'New' => true);
$inserted = $this->insertDedimaniaRecord($newRecord, $oldRecord); if ($this->insertDedimaniaRecord($newRecord, $oldRecord)) {
if ($inserted) { $this->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;
} }
} }
} }
}
/**
* 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) { if (!$serverInfo || !$playerInfo || !$mapInfo || !$gameMode) {
return false; return false;
} }
$data = array($this->dedimaniaData->sessionId, $mapInfo, $gameMode, $serverInfo, $playerInfo); $data = array($this->dedimaniaData->sessionId, $mapInfo, $gameMode, $serverInfo, $playerInfo);
$content = $this->encode_request(self::DEDIMANIA_GETRECORDS, $data); $content = $this->encode_request(self::DEDIMANIA_GETRECORDS, $data);
@ -483,6 +503,7 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
} }
$data = $this->decode($data); $data = $this->decode($data);
if (is_array($data)) { if (is_array($data)) {
foreach($data as $index => $methodResponse) { foreach($data as $index => $methodResponse) {
if (xmlrpc_is_fault($methodResponse)) { if (xmlrpc_is_fault($methodResponse)) {
@ -543,7 +564,7 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
* @return bool * @return bool
*/ */
private function insertDedimaniaRecord(&$newRecord, $oldRecord) { 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; return false;
} }
@ -581,8 +602,9 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
if ($oldRecord) { if ($oldRecord) {
// Remove old record // Remove old record
foreach($this->dedimaniaData->records['Records'] as $key2 => $record2) { foreach($this->dedimaniaData->records['Records'] as $key2 => $record2) {
if ($record2['Login'] !== $oldRecord['Login']) if ($record2['Login'] !== $oldRecord['Login']) {
continue; continue;
}
unset($this->dedimaniaData->records['Records'][$key2]); unset($this->dedimaniaData->records['Records'][$key2]);
break; break;
} }
@ -604,8 +626,9 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
// Save replays // Save replays
foreach($this->dedimaniaData->records['Records'] as &$record) { foreach($this->dedimaniaData->records['Records'] as &$record) {
if ($record['Login'] !== $newRecord['Login']) if ($record['Login'] !== $newRecord['Login']) {
continue; continue;
}
$this->setRecordReplays($record); $this->setRecordReplays($record);
break; break;
} }
@ -620,8 +643,9 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
* Update the sorting and the ranks of all dedimania records * Update the sorting and the ranks of all dedimania records
*/ */
private function updateDedimaniaRecordRanks() { private function updateDedimaniaRecordRanks() {
if (!isset($this->dedimaniaData->records) || !isset($this->dedimaniaData->records['Records'])) if (!$this->dedimaniaData->records|| !isset($this->dedimaniaData->records['Records'])) {
return; return;
}
// Sort records // Sort records
usort($this->dedimaniaData->records['Records'], array($this, 'compareRecords')); usort($this->dedimaniaData->records['Records'], array($this, 'compareRecords'));
@ -663,8 +687,9 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
private function setRecordReplays(&$record) { private function setRecordReplays(&$record) {
// Set validation replay // Set validation replay
$validationReplay = $this->maniaControl->server->getValidationReplay($record['Login']); $validationReplay = $this->maniaControl->server->getValidationReplay($record['Login']);
if ($validationReplay) if ($validationReplay) {
$record['VReplay'] = $validationReplay; $record['VReplay'] = $validationReplay;
}
// Set ghost replay // Set ghost replay
if ($record['Rank'] <= 1) { if ($record['Rank'] <= 1) {
@ -678,8 +703,9 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
} }
if ($this->dedimaniaData->directoryAccessChecked) { if ($this->dedimaniaData->directoryAccessChecked) {
$ghostReplay = $this->maniaControl->server->getGhostReplay($record['Login']); $ghostReplay = $this->maniaControl->server->getGhostReplay($record['Login']);
if ($ghostReplay) if ($ghostReplay) {
$record['Top1GReplay'] = $ghostReplay; $record['Top1GReplay'] = $ghostReplay;
}
} }
} }
} }
@ -688,14 +714,16 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
* Get max rank for given login * Get max rank for given login
*/ */
private function getMaxRank($login) { private function getMaxRank($login) {
if (!isset($this->dedimaniaData->records)) if (!isset($this->dedimaniaData->records)) {
return null; return null;
}
$records = $this->dedimaniaData->records; $records = $this->dedimaniaData->records;
$maxRank = $records['ServerMaxRank']; $maxRank = $records['ServerMaxRank'];
foreach($records['Players'] as $player) { foreach($records['Players'] as $player) {
if ($player['Login'] === $login) { if ($player['Login'] === $login) {
if ($player['MaxRank'] > $maxRank) if ($player['MaxRank'] > $maxRank) {
$maxRank = $player['MaxRank']; $maxRank = $player['MaxRank'];
}
break; break;
} }
} }
@ -781,12 +809,14 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
* @return array $record * @return array $record
*/ */
private function getDedimaniaRecord($login) { private function getDedimaniaRecord($login) {
if (!isset($this->dedimaniaData->records)) if (!$this->dedimaniaData->records) {
return null; return null;
}
$records = $this->dedimaniaData->records['Records']; $records = $this->dedimaniaData->records['Records'];
foreach($records as $record) { foreach($records as $record) {
if ($record['Login'] === $login) if ($record['Login'] === $login) {
return $record; return $record;
}
} }
return null; return null;
} }
@ -825,14 +855,16 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
* @return string * @return string
*/ */
private function getCheckpoints($login) { private function getCheckpoints($login) {
if (!$login || !isset($this->checkpoints[$login])) if (!$login || !isset($this->checkpoints[$login])) {
return null; return null;
}
$string = ''; $string = '';
$count = count($this->checkpoints[$login]); $count = count($this->checkpoints[$login]);
foreach($this->checkpoints[$login] as $index => $check) { foreach($this->checkpoints[$login] as $index => $check) {
$string .= $check; $string .= $check;
if ($index < $count - 1) if ($index < $count - 1) {
$string .= ','; $string .= ',';
}
} }
return $string; return $string;
} }
@ -899,8 +931,9 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
$titleLabel->setTranslate(true); $titleLabel->setTranslate(true);
foreach($records as $index => $record) { foreach($records as $index => $record) {
if ($index >= $lines) if ($index >= $lines) {
break; break;
}
$y = -8. - $index * $lineHeight; $y = -8. - $index * $lineHeight;