map add over mx fixed
This commit is contained in:
parent
0f78148fe4
commit
904b4eb6e1
@ -12,9 +12,10 @@ abstract class FileUtil {
|
|||||||
* Load a remote file
|
* Load a remote file
|
||||||
*
|
*
|
||||||
* @param string $url
|
* @param string $url
|
||||||
|
* @param string $contentType
|
||||||
* @return string || null
|
* @return string || null
|
||||||
*/
|
*/
|
||||||
public static function loadFile($url) {
|
public static function loadFile($url, $contentType = 'UTF-8') {
|
||||||
if (!$url) {
|
if (!$url) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -26,7 +27,7 @@ abstract class FileUtil {
|
|||||||
|
|
||||||
$query = 'GET ' . $urlData['path'] . ' HTTP/1.0' . PHP_EOL;
|
$query = 'GET ' . $urlData['path'] . ' HTTP/1.0' . PHP_EOL;
|
||||||
$query .= 'Host: ' . $urlData['host'] . PHP_EOL;
|
$query .= 'Host: ' . $urlData['host'] . PHP_EOL;
|
||||||
$query .= 'Content-Type: UTF-8' . PHP_EOL;
|
$query .= 'Content-Type: ' . $contentType . PHP_EOL;
|
||||||
$query .= 'User-Agent: ManiaControl v' . ManiaControl::VERSION . PHP_EOL;
|
$query .= 'User-Agent: ManiaControl v' . ManiaControl::VERSION . PHP_EOL;
|
||||||
$query .= PHP_EOL;
|
$query .= PHP_EOL;
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ class Map {
|
|||||||
$this->comment = $this->mapFetcher->comment;
|
$this->comment = $this->mapFetcher->comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: define timeout if mx is down
|
// TODO: define timeout if mx is down,todo fetch all map infos at once (maybe way faster)
|
||||||
$serverInfo = $this->maniaControl->server->getSystemInfo();
|
$serverInfo = $this->maniaControl->server->getSystemInfo();
|
||||||
$title = strtoupper(substr($serverInfo['TitleId'], 0, 2));
|
$title = strtoupper(substr($serverInfo['TitleId'], 0, 2));
|
||||||
$this->mx = new \MXInfoFetcher($title, $this->uid, false);
|
$this->mx = new \MXInfoFetcher($title, $this->uid, false);
|
||||||
|
@ -9,6 +9,7 @@ use ManiaControl\FileUtil;
|
|||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Callbacks\CallbackListener;
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
use ManiaControl\Callbacks\CallbackManager;
|
use ManiaControl\Callbacks\CallbackManager;
|
||||||
|
use MXInfoFetcher;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,7 +22,7 @@ class MapManager implements CallbackListener {
|
|||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const TABLE_MAPS = 'mc_maps';
|
const TABLE_MAPS = 'mc_maps';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private properties
|
* Private properties
|
||||||
*/
|
*/
|
||||||
@ -34,14 +35,14 @@ class MapManager implements CallbackListener {
|
|||||||
/**
|
/**
|
||||||
* Construct map manager
|
* Construct map manager
|
||||||
*
|
*
|
||||||
* @param \ManiaControl\ManiaControl $maniaControl
|
* @param \ManiaControl\ManiaControl $maniaControl
|
||||||
*/
|
*/
|
||||||
public function __construct(ManiaControl $maniaControl) {
|
public function __construct(ManiaControl $maniaControl) {
|
||||||
$this->maniaControl = $maniaControl;
|
$this->maniaControl = $maniaControl;
|
||||||
|
|
||||||
// Init database tables
|
// Init database tables
|
||||||
$this->initTables();
|
$this->initTables();
|
||||||
|
|
||||||
// Create map commands instance
|
// Create map commands instance
|
||||||
$this->mapCommands = new MapCommands($maniaControl);
|
$this->mapCommands = new MapCommands($maniaControl);
|
||||||
|
|
||||||
@ -81,7 +82,7 @@ class MapManager implements CallbackListener {
|
|||||||
/**
|
/**
|
||||||
* Save map to the database
|
* Save map to the database
|
||||||
*
|
*
|
||||||
* @param \ManiaControl\Maps\Map $map
|
* @param \ManiaControl\Maps\Map $map
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
private function saveMap(Map &$map) {
|
private function saveMap(Map &$map) {
|
||||||
@ -117,7 +118,7 @@ class MapManager implements CallbackListener {
|
|||||||
/**
|
/**
|
||||||
* Add a map to the MapList
|
* Add a map to the MapList
|
||||||
*
|
*
|
||||||
* @param \ManiaControl\Maps\Map $map
|
* @param \ManiaControl\Maps\Map $map
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function addMap(Map $map) { //TODO needed?
|
private function addMap(Map $map) { //TODO needed?
|
||||||
@ -192,7 +193,7 @@ class MapManager implements CallbackListener {
|
|||||||
/**
|
/**
|
||||||
* Handle OnInit callback
|
* Handle OnInit callback
|
||||||
*
|
*
|
||||||
* @param array $callback
|
* @param array $callback
|
||||||
*/
|
*/
|
||||||
public function handleOnInit(array $callback) {
|
public function handleOnInit(array $callback) {
|
||||||
$this->updateFullMapList();
|
$this->updateFullMapList();
|
||||||
@ -211,7 +212,7 @@ class MapManager implements CallbackListener {
|
|||||||
/**
|
/**
|
||||||
* Handle BeginMap callback
|
* Handle BeginMap callback
|
||||||
*
|
*
|
||||||
* @param array $callback
|
* @param array $callback
|
||||||
*/
|
*/
|
||||||
public function handleBeginMap(array $callback) {
|
public function handleBeginMap(array $callback) {
|
||||||
if(array_key_exists($callback[1][0]["UId"], $this->mapListUids)){ //Map already exists, only update index
|
if(array_key_exists($callback[1][0]["UId"], $this->mapListUids)){ //Map already exists, only update index
|
||||||
@ -272,13 +273,18 @@ class MapManager implements CallbackListener {
|
|||||||
|
|
||||||
// Check if map exists
|
// Check if map exists
|
||||||
$url = "http://api.mania-exchange.com/{$title}/maps/{$mapId}?format=json";
|
$url = "http://api.mania-exchange.com/{$title}/maps/{$mapId}?format=json";
|
||||||
$mapInfo = FileUtil::loadFile($url);
|
|
||||||
|
$mapInfo = FileUtil::loadFile($url, "application/json");
|
||||||
|
|
||||||
if (!$mapInfo || strlen($mapInfo) <= 0) {
|
if (!$mapInfo || strlen($mapInfo) <= 0) {
|
||||||
// Invalid id
|
// Invalid id
|
||||||
$this->maniaControl->chat->sendError('Invalid MX-Id!', $login);
|
$this->maniaControl->chat->sendError('Invalid MX-Id!', $login);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$mapInfo = json_decode($mapInfo, true);
|
$mapInfo = json_decode($mapInfo, true);
|
||||||
|
$mapInfo = $mapInfo[0];
|
||||||
|
|
||||||
$url = "http://{$title}.mania-exchange.com/tracks/download/{$mapId}";
|
$url = "http://{$title}.mania-exchange.com/tracks/download/{$mapId}";
|
||||||
$file = FileUtil::loadFile($url);
|
$file = FileUtil::loadFile($url);
|
||||||
if (!$file) {
|
if (!$file) {
|
||||||
@ -287,7 +293,7 @@ class MapManager implements CallbackListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Save map
|
// Save map
|
||||||
$fileName = $mapInfo['TrackID'] . '_' . $mapInfo['Name'] . '.Map.Gbx';
|
$fileName = $mapId . '_' . $mapInfo['Name'] . '.Map.Gbx';
|
||||||
$fileName = FileUtil::getClearedFileName($fileName);
|
$fileName = FileUtil::getClearedFileName($fileName);
|
||||||
if (!file_put_contents($mapDir . $fileName, $file)) {
|
if (!file_put_contents($mapDir . $fileName, $file)) {
|
||||||
// Save error
|
// Save error
|
||||||
@ -296,6 +302,7 @@ class MapManager implements CallbackListener {
|
|||||||
}
|
}
|
||||||
// Check for valid map
|
// Check for valid map
|
||||||
$mapFileName = $downloadDirectory . '/' . $fileName;
|
$mapFileName = $downloadDirectory . '/' . $fileName;
|
||||||
|
|
||||||
if (!$this->maniaControl->client->query('CheckMapForCurrentServerParams', $mapFileName)) {
|
if (!$this->maniaControl->client->query('CheckMapForCurrentServerParams', $mapFileName)) {
|
||||||
trigger_error("Couldn't check if map is valid ('{$mapFileName}'). " . $this->maniaControl->getClientErrorText());
|
trigger_error("Couldn't check if map is valid ('{$mapFileName}'). " . $this->maniaControl->getClientErrorText());
|
||||||
$this->maniaControl->chat->sendError('Error checking map!', $login);
|
$this->maniaControl->chat->sendError('Error checking map!', $login);
|
||||||
|
@ -213,7 +213,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
case authenticationManager::AUTH_LEVEL_MASTERADMIN:
|
case authenticationManager::AUTH_LEVEL_MASTERADMIN:
|
||||||
case authenticationManager::AUTH_LEVEL_SUPERADMIN: $rightLabel->setText("MA"); break;
|
case authenticationManager::AUTH_LEVEL_SUPERADMIN: $rightLabel->setText("MA"); break;
|
||||||
case authenticationManager::AUTH_LEVEL_ADMIN: $rightLabel->setText("AD"); break;
|
case authenticationManager::AUTH_LEVEL_ADMIN: $rightLabel->setText("AD"); break;
|
||||||
case authenticationManager::AUTH_LEVEL_OPERATOR: $rightLabel->setText("OP");
|
case authenticationManager::AUTH_LEVEL_OPERATOR: $rightLabel->setText("MOD");
|
||||||
}
|
}
|
||||||
|
|
||||||
$rightLabel->setTextColor("fff");
|
$rightLabel->setTextColor("fff");
|
||||||
|
Loading…
Reference in New Issue
Block a user