mapmanager cleanup
This commit is contained in:
parent
be4d96fa22
commit
02b0a0dec0
@ -15,6 +15,10 @@ class FaultException extends Exception
|
|||||||
{
|
{
|
||||||
case 'Login unknown.':
|
case 'Login unknown.':
|
||||||
return new LoginUnknownException($faultString, $faultCode);
|
return new LoginUnknownException($faultString, $faultCode);
|
||||||
|
case 'Unable to write the playlist file.':
|
||||||
|
return new CouldNotWritePlaylistFileException($faultString, $faultCode);
|
||||||
|
case 'Start index out of bound.':
|
||||||
|
return new StartIndexOutOfBoundException($faultString, $faultCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new self($faultString, $faultCode);
|
return new self($faultString, $faultCode);
|
||||||
@ -22,5 +26,6 @@ class FaultException extends Exception
|
|||||||
}
|
}
|
||||||
|
|
||||||
class LoginUnknownException extends FaultException {}
|
class LoginUnknownException extends FaultException {}
|
||||||
|
class CouldNotWritePlaylistFileException extends FaultException {}
|
||||||
|
class StartIndexOutOfBoundException extends FaultException {}
|
||||||
?>
|
?>
|
||||||
|
@ -6,39 +6,40 @@ use ManiaControl\Admin\AuthenticationManager;
|
|||||||
use ManiaControl\Callbacks\CallbackListener;
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
use ManiaControl\Callbacks\CallbackManager;
|
use ManiaControl\Callbacks\CallbackManager;
|
||||||
use ManiaControl\Files\FileUtil;
|
use ManiaControl\Files\FileUtil;
|
||||||
use ManiaControl\Formatter;
|
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\ManiaExchange\ManiaExchangeList;
|
use ManiaControl\ManiaExchange\ManiaExchangeList;
|
||||||
use ManiaControl\ManiaExchange\ManiaExchangeManager;
|
use ManiaControl\ManiaExchange\ManiaExchangeManager;
|
||||||
use ManiaControl\ManiaExchange\MXMapInfo;
|
use ManiaControl\ManiaExchange\MXMapInfo;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
use Maniaplanet\DedicatedServer\InvalidArgumentException;
|
use Maniaplanet\DedicatedServer\InvalidArgumentException;
|
||||||
|
use Maniaplanet\DedicatedServer\Xmlrpc\CouldNotWritePlaylistFileException;
|
||||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||||
|
use Maniaplanet\DedicatedServer\Xmlrpc\StartIndexOutOfBoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manager for Maps
|
* Manager for Maps
|
||||||
*
|
*
|
||||||
* @author kremsy & steeffeen
|
* @author kremsy & steeffeen
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class MapManager implements CallbackListener {
|
class MapManager implements CallbackListener {
|
||||||
/*
|
/*
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
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';
|
||||||
const SETTING_PERMISSION_REMOVE_MAP = 'Remove Maps';
|
const SETTING_PERMISSION_REMOVE_MAP = 'Remove Maps';
|
||||||
const SETTING_PERMISSION_SHUFFLE_MAPS = 'Shuffle Maps';
|
const SETTING_PERMISSION_SHUFFLE_MAPS = 'Shuffle Maps';
|
||||||
const SETTING_PERMISSION_CHECK_UPDATE = 'Check Map Update';
|
const SETTING_PERMISSION_CHECK_UPDATE = 'Check Map Update';
|
||||||
const SETTING_PERMISSION_SKIP_MAP = 'Skip Map';
|
const SETTING_PERMISSION_SKIP_MAP = 'Skip Map';
|
||||||
const SETTING_PERMISSION_RESTART_MAP = 'Restart Map';
|
const SETTING_PERMISSION_RESTART_MAP = 'Restart Map';
|
||||||
const SETTING_AUTOSAVE_MAPLIST = 'Autosave Maplist file';
|
const SETTING_AUTOSAVE_MAPLIST = 'Autosave Maplist file';
|
||||||
const SETTING_MAPLIST_FILE = 'File to write Maplist in';
|
const SETTING_MAPLIST_FILE = 'File to write Maplist in';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Public Properties
|
* Public Properties
|
||||||
@ -71,11 +72,11 @@ class MapManager implements CallbackListener {
|
|||||||
$this->initTables();
|
$this->initTables();
|
||||||
|
|
||||||
// Create map commands instance
|
// Create map commands instance
|
||||||
$this->mxManager = new ManiaExchangeManager($this->maniaControl);
|
$this->mxManager = new ManiaExchangeManager($this->maniaControl);
|
||||||
$this->mapList = new MapList($this->maniaControl);
|
$this->mapList = new MapList($this->maniaControl);
|
||||||
$this->mxList = new ManiaExchangeList($this->maniaControl);
|
$this->mxList = new ManiaExchangeList($this->maniaControl);
|
||||||
$this->mapCommands = new MapCommands($maniaControl);
|
$this->mapCommands = new MapCommands($maniaControl);
|
||||||
$this->mapQueue = new MapQueue($this->maniaControl);
|
$this->mapQueue = new MapQueue($this->maniaControl);
|
||||||
|
|
||||||
// Register for callbacks
|
// Register for callbacks
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'handleOnInit');
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'handleOnInit');
|
||||||
@ -84,16 +85,11 @@ class MapManager implements CallbackListener {
|
|||||||
|
|
||||||
// Define Rights
|
// Define Rights
|
||||||
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_ADD_MAP, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_ADD_MAP, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||||
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_REMOVE_MAP,
|
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_REMOVE_MAP, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||||
AuthenticationManager::AUTH_LEVEL_ADMIN);
|
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_SHUFFLE_MAPS, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||||
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_SHUFFLE_MAPS,
|
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_CHECK_UPDATE, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
||||||
AuthenticationManager::AUTH_LEVEL_ADMIN);
|
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_SKIP_MAP, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
||||||
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_CHECK_UPDATE,
|
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_RESTART_MAP, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
||||||
AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
|
||||||
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_SKIP_MAP,
|
|
||||||
AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
|
||||||
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_RESTART_MAP,
|
|
||||||
AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
|
||||||
|
|
||||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_AUTOSAVE_MAPLIST, true);
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_AUTOSAVE_MAPLIST, true);
|
||||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MAPLIST_FILE, "MatchSettings/tracklist.txt");
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MAPLIST_FILE, "MatchSettings/tracklist.txt");
|
||||||
@ -106,7 +102,7 @@ class MapManager implements CallbackListener {
|
|||||||
*/
|
*/
|
||||||
private function initTables() {
|
private function initTables() {
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_MAPS . "` (
|
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_MAPS . "` (
|
||||||
`index` int(11) NOT NULL AUTO_INCREMENT,
|
`index` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`mxid` int(11),
|
`mxid` int(11),
|
||||||
`uid` varchar(50) NOT NULL,
|
`uid` varchar(50) NOT NULL,
|
||||||
@ -134,7 +130,8 @@ class MapManager implements CallbackListener {
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function saveMap(Map &$map) {
|
private function saveMap(Map &$map) {
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
//TODO saveMaps for whole maplist at once (usage of prepared statements)
|
||||||
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$mapQuery = "INSERT INTO `" . self::TABLE_MAPS . "` (
|
$mapQuery = "INSERT INTO `" . self::TABLE_MAPS . "` (
|
||||||
`uid`,
|
`uid`,
|
||||||
`name`,
|
`name`,
|
||||||
@ -174,7 +171,7 @@ class MapManager implements CallbackListener {
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function updateMapTimestamp($uid) {
|
private function updateMapTimestamp($uid) {
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$mapQuery = "UPDATE `" . self::TABLE_MAPS . "` SET mxid = 0, changed = NOW() WHERE 'uid' = ?";
|
$mapQuery = "UPDATE `" . self::TABLE_MAPS . "` SET mxid = 0, changed = NOW() WHERE 'uid' = ?";
|
||||||
|
|
||||||
$mapStatement = $mysqli->prepare($mapQuery);
|
$mapStatement = $mysqli->prepare($mapQuery);
|
||||||
@ -197,8 +194,8 @@ class MapManager implements CallbackListener {
|
|||||||
* Updates a Map from Mania Exchange
|
* Updates a Map from Mania Exchange
|
||||||
*
|
*
|
||||||
* @param Player $admin
|
* @param Player $admin
|
||||||
* @param $mxId
|
* @param $mxId
|
||||||
* @param $uid
|
* @param $uid
|
||||||
*/
|
*/
|
||||||
public function updateMap(Player $admin, $uid) {
|
public function updateMap(Player $admin, $uid) {
|
||||||
$this->updateMapTimestamp($uid);
|
$this->updateMapTimestamp($uid);
|
||||||
@ -222,12 +219,12 @@ class MapManager implements CallbackListener {
|
|||||||
* Remove a Map
|
* Remove a Map
|
||||||
*
|
*
|
||||||
* @param \ManiaControl\Players\Player $admin
|
* @param \ManiaControl\Players\Player $admin
|
||||||
* @param string $uid
|
* @param string $uid
|
||||||
* @param bool $eraseFile
|
* @param bool $eraseFile
|
||||||
* @param bool $message
|
* @param bool $message
|
||||||
*/
|
*/
|
||||||
public function removeMap(Player $admin, $uid, $eraseFile = false, $message = true) {
|
public function removeMap(Player $admin, $uid, $eraseFile = false, $message = true) {
|
||||||
if(!isset($this->maps[$uid])){
|
if (!isset($this->maps[$uid])) {
|
||||||
$this->maniaControl->chat->sendError("Map is not existing!", $admin->login);
|
$this->maniaControl->chat->sendError("Map is not existing!", $admin->login);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -277,15 +274,14 @@ class MapManager implements CallbackListener {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$lowerMapArray = array();
|
$lowerMapArray = array();
|
||||||
$higherMapArray = array();
|
$higherMapArray = array();
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ($this->maps as $map) {
|
foreach($this->maps as $map) {
|
||||||
if ($i < $currentIndex) {
|
if ($i < $currentIndex) {
|
||||||
$lowerMapArray[] = $map->fileName;
|
$lowerMapArray[] = $map->fileName;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$higherMapArray[] = $map->fileName;
|
$higherMapArray[] = $map->fileName;
|
||||||
}
|
}
|
||||||
$i++;
|
$i++;
|
||||||
@ -296,8 +292,7 @@ class MapManager implements CallbackListener {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->chooseNextMapList($mapArray);
|
$this->maniaControl->client->chooseNextMapList($mapArray);
|
||||||
}
|
} catch(Exception $e) {
|
||||||
catch (Exception $e) {
|
|
||||||
trigger_error("Error while restructuring the Maplist. " . $e->getMessage());
|
trigger_error("Error while restructuring the Maplist. " . $e->getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -316,7 +311,7 @@ class MapManager implements CallbackListener {
|
|||||||
|
|
||||||
$mapArray = array();
|
$mapArray = array();
|
||||||
|
|
||||||
foreach ($shuffledMaps as $map) {
|
foreach($shuffledMaps as $map) {
|
||||||
/**
|
/**
|
||||||
* @var Map $map
|
* @var Map $map
|
||||||
*/
|
*/
|
||||||
@ -325,8 +320,9 @@ class MapManager implements CallbackListener {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->chooseNextMapList($mapArray);
|
$this->maniaControl->client->chooseNextMapList($mapArray);
|
||||||
}
|
} catch(Exception $e) {
|
||||||
catch (Exception $e) {
|
//TODO temp added 19.04.2014
|
||||||
|
$this->maniaControl->errorHandler->triggerDebugNotice("Exception line 331 MapManager" . $e->getMessage());
|
||||||
trigger_error("Couldn't shuffle mapList. " . $e->getMessage());
|
trigger_error("Couldn't shuffle mapList. " . $e->getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -370,20 +366,29 @@ class MapManager implements CallbackListener {
|
|||||||
* Updates the full Map list, needed on Init, addMap and on ShuffleMaps
|
* Updates the full Map list, needed on Init, addMap and on ShuffleMaps
|
||||||
*/
|
*/
|
||||||
private function updateFullMapList() {
|
private function updateFullMapList() {
|
||||||
$maps = $this->maniaControl->client->getMapList(150, 0);
|
|
||||||
$tempList = array();
|
$tempList = array();
|
||||||
foreach ($maps as $rpcMap) {
|
|
||||||
if (array_key_exists($rpcMap->uId, $this->maps)) {
|
try {
|
||||||
// Map already exists, only update index
|
$i = 0;
|
||||||
$tempList[$rpcMap->uId] = $this->maps[$rpcMap->uId];
|
while(true) {
|
||||||
}
|
$maps = $this->maniaControl->client->getMapList(150, $i);
|
||||||
else { // Insert Map Object
|
|
||||||
$map = $this->initializeMap($rpcMap);
|
foreach($maps as $rpcMap) {
|
||||||
$tempList[$map->uid] = $map;
|
if (array_key_exists($rpcMap->uId, $this->maps)) {
|
||||||
|
// Map already exists, only update index
|
||||||
|
$tempList[$rpcMap->uId] = $this->maps[$rpcMap->uId];
|
||||||
|
} else { // Insert Map Object
|
||||||
|
$map = $this->initializeMap($rpcMap);
|
||||||
|
$tempList[$map->uid] = $map;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$i += 150;
|
||||||
}
|
}
|
||||||
|
} catch(StartIndexOutOfBoundException $e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// restore Sorted Maplist
|
// restore Sorted MapList
|
||||||
$this->maps = $tempList;
|
$this->maps = $tempList;
|
||||||
|
|
||||||
// Trigger own callback
|
// Trigger own callback
|
||||||
@ -393,14 +398,8 @@ class MapManager implements CallbackListener {
|
|||||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_AUTOSAVE_MAPLIST)) {
|
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_AUTOSAVE_MAPLIST)) {
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->saveMatchSettings($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAPLIST_FILE));
|
$this->maniaControl->client->saveMatchSettings($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAPLIST_FILE));
|
||||||
}
|
} catch(CouldNotWritePlaylistFileException $e) {
|
||||||
catch (Exception $e) {
|
$this->maniaControl->log("Unable to write the playlist file, please checkout your MX-Folders File permissions!");
|
||||||
if ($e->getMessage() == 'Unable to write the playlist file.') {
|
|
||||||
$this->maniaControl->log("Unable to write the playlist file, please checkout your MX-Folders File permissions!");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -414,13 +413,13 @@ class MapManager implements CallbackListener {
|
|||||||
$rpcMap = $this->maniaControl->client->getCurrentMapInfo();
|
$rpcMap = $this->maniaControl->client->getCurrentMapInfo();
|
||||||
|
|
||||||
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];
|
||||||
$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;
|
||||||
}
|
}
|
||||||
@ -490,17 +489,11 @@ class MapManager implements CallbackListener {
|
|||||||
// 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) {
|
if (!$this->currentMap->nbCheckpoints || !$this->currentMap->nbLaps) {
|
||||||
$rpcMap = $this->maniaControl->client->getCurrentMapInfo();
|
$rpcMap = $this->maniaControl->client->getCurrentMapInfo();
|
||||||
$this->currentMap->nbLaps = $rpcMap->nbLaps;
|
$this->currentMap->nbLaps = $rpcMap->nbLaps;
|
||||||
$this->currentMap->nbCheckpoints = $rpcMap->nbCheckpoints;
|
$this->currentMap->nbCheckpoints = $rpcMap->nbCheckpoints;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
$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"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restructure MapList if id is over 15
|
// Restructure MapList if id is over 15
|
||||||
$this->restructureMapList();
|
$this->restructureMapList();
|
||||||
@ -586,48 +579,46 @@ class MapManager implements CallbackListener {
|
|||||||
/**
|
/**
|
||||||
* Adds a Map from Mania Exchange
|
* Adds a Map from Mania Exchange
|
||||||
*
|
*
|
||||||
* @param $mapId
|
* @param $mapId
|
||||||
* @param $login
|
* @param $login
|
||||||
* @param bool $update
|
* @param bool $update
|
||||||
*/
|
*/
|
||||||
public function addMapFromMx($mapId, $login, $update = false) {
|
public function addMapFromMx($mapId, $login, $update = false) {
|
||||||
if (is_numeric($mapId)) {
|
if (is_numeric($mapId)) {
|
||||||
// Check if map exists
|
// Check if map exists
|
||||||
$this->maniaControl->mapManager->mxManager->getMapInfo($mapId,
|
$this->maniaControl->mapManager->mxManager->getMapInfo($mapId, function (MXMapInfo $mapInfo) use (&$login, &$update) {
|
||||||
function (MXMapInfo $mapInfo) use(&$login, &$update) {
|
if (!$mapInfo || !isset($mapInfo->uploaded)) {
|
||||||
if (!$mapInfo || !isset($mapInfo->uploaded)) {
|
// Invalid id
|
||||||
// Invalid id
|
$this->maniaControl->chat->sendError('Invalid MX-Id!', $login);
|
||||||
$this->maniaControl->chat->sendError('Invalid MX-Id!', $login);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// TODO hardcoded during closed beta, later take just $mapInfo->url again
|
// TODO hardcoded during closed beta, later take just $mapInfo->url again
|
||||||
$url = 'http://' . $mapInfo->prefix . '.mania-exchange.com/' . $mapInfo->dir . '/download/' . $mapInfo->id;
|
$url = 'http://' . $mapInfo->prefix . '.mania-exchange.com/' . $mapInfo->dir . '/download/' . $mapInfo->id;
|
||||||
if ($this->maniaControl->settingManager->getSetting($this->mxManager, ManiaExchangeManager::SETTING_MP3_BETA_TESTING)) {
|
if ($this->maniaControl->settingManager->getSetting($this->mxManager, ManiaExchangeManager::SETTING_MP3_BETA_TESTING)) {
|
||||||
$url .= '?key=t42kEMjzH7xpAjBFHAvEkC7rqAlw';
|
$url .= '?key=t42kEMjzH7xpAjBFHAvEkC7rqAlw';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Download the file
|
// Download the file
|
||||||
$this->maniaControl->fileReader->loadFile($url,
|
$this->maniaControl->fileReader->loadFile($url, function ($file, $error) use (&$login, &$mapInfo, &$update) {
|
||||||
function ($file, $error) use(&$login, &$mapInfo, &$update) {
|
if (!$file) {
|
||||||
if (!$file) {
|
// Download error
|
||||||
// Download error
|
$this->maniaControl->chat->sendError('Download failed!', $login);
|
||||||
$this->maniaControl->chat->sendError('Download failed!', $login);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
$this->processMapFile($file, $mapInfo, $login, $update);
|
||||||
$this->processMapFile($file, $mapInfo, $login, $update);
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process the MapFile
|
* Process the MapFile
|
||||||
*
|
*
|
||||||
* @param $file
|
* @param $file
|
||||||
* @param MXMapInfo $mapInfo
|
* @param MXMapInfo $mapInfo
|
||||||
* @param $login
|
* @param $login
|
||||||
* @param $update
|
* @param $update
|
||||||
*/
|
*/
|
||||||
private function processMapFile($file, MXMapInfo $mapInfo, $login, $update) {
|
private function processMapFile($file, MXMapInfo $mapInfo, $login, $update) {
|
||||||
// Check if map is already on the server
|
// Check if map is already on the server
|
||||||
@ -641,11 +632,11 @@ class MapManager implements CallbackListener {
|
|||||||
$fileName = $mapInfo->id . '_' . $mapInfo->name . '.Map.Gbx';
|
$fileName = $mapInfo->id . '_' . $mapInfo->name . '.Map.Gbx';
|
||||||
$fileName = FileUtil::getClearedFileName($fileName);
|
$fileName = FileUtil::getClearedFileName($fileName);
|
||||||
|
|
||||||
$downloadFolderName = $this->maniaControl->settingManager->getSetting($this, 'MapDownloadDirectory', 'MX');
|
$downloadFolderName = $this->maniaControl->settingManager->getSetting($this, 'MapDownloadDirectory', 'MX');
|
||||||
$relativeMapFileName = $downloadFolderName . '/' . $fileName;
|
$relativeMapFileName = $downloadFolderName . '/' . $fileName;
|
||||||
$mapDir = $this->maniaControl->client->getMapsDirectory();
|
$mapDir = $this->maniaControl->client->getMapsDirectory();
|
||||||
$downloadDirectory = $mapDir . '/' . $downloadFolderName . '/';
|
$downloadDirectory = $mapDir . '/' . $downloadFolderName . '/';
|
||||||
$fullMapFileName = $downloadDirectory . $fileName;
|
$fullMapFileName = $downloadDirectory . $fileName;
|
||||||
|
|
||||||
// Check if it can get written locally
|
// Check if it can get written locally
|
||||||
if (is_dir($mapDir)) {
|
if (is_dir($mapDir)) {
|
||||||
@ -661,13 +652,11 @@ class MapManager implements CallbackListener {
|
|||||||
$this->maniaControl->chat->sendError('Saving map failed!', $login);
|
$this->maniaControl->chat->sendError('Saving map failed!', $login);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Write map via write file method
|
// Write map via write file method
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->writeFileFromString($relativeMapFileName, $file);
|
$this->maniaControl->client->writeFileFromString($relativeMapFileName, $file);
|
||||||
}
|
} catch(InvalidArgumentException $e) {
|
||||||
catch (InvalidArgumentException $e) {
|
|
||||||
if ($e->getMessage() == 'data are too big') {
|
if ($e->getMessage() == 'data are too big') {
|
||||||
$this->maniaControl->chat->sendError("Map is too big for a remote save.", $login);
|
$this->maniaControl->chat->sendError("Map is too big for a remote save.", $login);
|
||||||
return;
|
return;
|
||||||
@ -679,8 +668,10 @@ class MapManager implements CallbackListener {
|
|||||||
// Check for valid map
|
// Check for valid map
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->checkMapForCurrentServerParams($relativeMapFileName);
|
$this->maniaControl->client->checkMapForCurrentServerParams($relativeMapFileName);
|
||||||
}
|
} catch(Exception $e) {
|
||||||
catch (Exception $e) {
|
//TODO temp added 19.04.2014
|
||||||
|
$this->maniaControl->errorHandler->triggerDebugNotice("Exception line 331 MapManager" . $e->getMessage());
|
||||||
|
|
||||||
trigger_error("Couldn't check if map is valid ('{$relativeMapFileName}'). " . $e->getMessage());
|
trigger_error("Couldn't check if map is valid ('{$relativeMapFileName}'). " . $e->getMessage());
|
||||||
$this->maniaControl->chat->sendError('Wrong MapType or not validated!', $login);
|
$this->maniaControl->chat->sendError('Wrong MapType or not validated!', $login);
|
||||||
return;
|
return;
|
||||||
@ -709,8 +700,7 @@ class MapManager implements CallbackListener {
|
|||||||
$this->maniaControl->log($message, true);
|
$this->maniaControl->log($message, true);
|
||||||
// Queue requested Map
|
// Queue requested Map
|
||||||
$this->maniaControl->mapManager->mapQueue->addMapToMapQueue($login, $mapInfo->uid);
|
$this->maniaControl->mapManager->mapQueue->addMapToMapQueue($login, $mapInfo->uid);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$message = '$<' . $player->nickname . '$> updated $<' . $mapInfo->name . '$>!';
|
$message = '$<' . $player->nickname . '$> updated $<' . $mapInfo->name . '$>!';
|
||||||
$this->maniaControl->chat->sendSuccess($message);
|
$this->maniaControl->chat->sendSuccess($message);
|
||||||
$this->maniaControl->log($message, true);
|
$this->maniaControl->log($message, true);
|
||||||
|
Loading…
Reference in New Issue
Block a user