Skip to content
Permalink
Browse files

0.63.0 Fix loading and adding maps, remove map checksum

 -Fix updating map pool
 -Fix map-list crashes for unloaded maps
 -Add MapFavorite model
  • Loading branch information...
brakerb committed Apr 17, 2019
1 parent 067b293 commit c6b8198eb6241b72327be6081421cd79067085e9
@@ -27,7 +27,6 @@ public function up(Builder $schemaBuilder)
$table->integer('cooldown')->default(0);
$table->dateTime('last_played')->nullable();
$table->boolean('enabled')->default(0);
$table->string('checksum')->nullable();
});
}
@@ -12,13 +12,15 @@
use esc\Classes\Server;
use esc\Interfaces\ControllerInterface;
use esc\Models\AccessRight;
use esc\Models\Dedi;
use esc\Models\LocalRecord;
use esc\Models\Map;
use esc\Models\MapFavorite;
use esc\Models\MapQueue;
use esc\Models\Player;
use esc\Modules\KeyBinds;
use esc\Modules\MxMapDetails;
use esc\Modules\QuickButtons;
use mysql_xdevapi\Exception;
/**
* Class MapController
@@ -45,14 +47,16 @@ class MapController implements ControllerInterface
private static $mapsPath;
private static $addedTime = 0;
private static $timeLimit;
private static $originalTimeLimit;
/**
* Initialize MapController
*/
public static function init()
{
self::$mapsPath = Server::getMapsDirectory();
self::$timeLimit = self::getTimeLimitFromMatchSettings();
self::$mapsPath = Server::getMapsDirectory();
self::$timeLimit = self::getTimeLimitFromMatchSettings();
self::$originalTimeLimit = self::getTimeLimitFromMatchSettings();
self::loadMaps();
@@ -116,6 +120,7 @@ private static function getTimeLimitFromMatchSettings(): int
public static function resetTime()
{
self::$addedTime = 0;
self::$timeLimit = self::getTimeLimitFromMatchSettings();
self::setTimelimit(self::$timeLimit);
}
@@ -173,12 +178,6 @@ public static function setTimelimit(int $seconds)
*/
public static function beginMap(Map $map)
{
if (self::$nextMap && self::$nextMap->uid != $map->uid) {
QueueController::dropMapSilent(self::$nextMap->uid);
Log::logAddLine('ERROR', sprintf('Expected map %s, got %s', self::$nextMap->uid, $map->uid));
exit(3);
}
QueueController::dropMapSilent($map->uid);
self::$nextMap = null;
@@ -265,11 +264,14 @@ public static function deleteMap(Player $player, Map $map)
}
$map->locals()->delete();
$map->dedis()->delete();
MapFavorite::whereMapId($map->id)->delete();
$deleted = File::delete(self::$mapsPath . $map->filename);
if ($deleted) {
try {
$map->delete();
Log::logAddLine('MapController', $player . ' deleted map ' . $map->filename);
} catch (\Exception $e) {
Log::logAddLine('MapController', 'Failed to remove map "' . $map->uid . '" from database: ' . $e->getMessage(), isVerbose());
}
@@ -299,11 +301,12 @@ public static function disableMap(Player $player, Map $map)
try {
Server::removeMap($map->filename);
infoMessage($player, ' disabled map ', secondary($map))->sendAll();
Log::logAddLine('MapController', $player . ' disabled map ' . $map->filename);
} catch (\Exception $e) {
Log::error($e);
}
$map->update(['enabled' => false]);
$map->update(['enabled' => 0]);
Server::saveMatchSettings('MatchSettings/' . config('server.default-matchsettings'));
Hook::fire('MapPoolUpdated');
@@ -364,55 +367,68 @@ public static function loadMaps()
//Get loaded matchsettings maps
$maps = collect(Server::getMapList());
//get array with the uids
$enabledMapsuids = $maps->pluck('uId');
foreach ($maps as $mapInfo) {
$mapFile = self::$mapsPath . $mapInfo->fileName;
$filename = $mapInfo->fileName;
$uid = $mapInfo->uId;
$mapFile = self::$mapsPath . $filename;
if (!File::exists($mapFile)) {
throw new Exception("File $mapFile not found.");
Log::error("File $mapFile not found.");
if (Map::whereFilename($filename)->exists()) {
Map::whereFilename($filename)->update(['enabled' => 0]);
}
continue;
}
$map = Map::whereUid($mapInfo->uId)->first();
if (Map::whereFilename($filename)->exists()) {
$map = Map::whereFilename($filename)->first();
if (!$map) {
if (Map::whereFilename($mapInfo->fileName)->exists()) {
Map::whereFilename($mapInfo->fileName)->delete();
}
if ($map->uid != $uid) {
Log::logAddLine('MapController', 'UID changed for map: ' . $map, isVerbose());
if (Player::where('Login', $mapInfo->author)->exists()) {
$authorId = Player::where('Login', $mapInfo->author)->first()->id;
} else {
$authorId = Player::insertGetId([
'Login' => $mapInfo->author,
'NickName' => $mapInfo->author,
LocalRecord::whereMap($map->id)->delete();
Dedi::whereMap($map->id)->delete();
MapFavorite::whereMapId($map->id)->delete();
MapQueue::whereMapUid($map->uid)->delete();
$map->update([
'gbx' => self::getGbxInformation($mapFile),
'uid' => $uid,
'mx_details' => null,
'mx_world_record' => null,
]);
}
} else {
if (Map::whereUid($uid)->exists()) {
$map = Map::whereUid($uid)->first();
$gbxInfo = self::getGbxInformation(self::$mapsPath . $mapInfo->fileName);
$map = Map::updateOrCreate([
'author' => $authorId,
'gbx' => preg_replace("(\n|[ ]{2,})", '', $gbxInfo),
'filename' => $mapInfo->fileName,
'uid' => json_decode($gbxInfo)->MapUid,
]);
}
Log::logAddLine('MapController', "Filename changed for map: $map (" . $map->filename . " -> $filename)", isVerbose());
if (!$map->checksum) {
$map->update([
'checksum' => md5_file($mapFile),
]);
$map->update([
'filename' => $filename,
]);
} else {
if (Player::where('Login', $mapInfo->author)->exists()) {
$authorId = Player::find($mapInfo->author)->id;
} else {
$authorId = Player::insertGetId([
'Login' => $mapInfo->author,
'NickName' => $mapInfo->author,
]);
}
$map = Map::create([
'author' => $authorId,
'filename' => $mapInfo->fileName,
'gbx' => self::getGbxInformation($mapFile),
'uid' => $uid,
]);
}
}
if (!$map->gbx) {
$gbxInfo = self::getGbxInformation(self::$mapsPath . $mapInfo->fileName);
$map->update([
'gbx' => preg_replace("(\n|[ ]{2,})", '', $gbxInfo),
'uid' => json_decode($gbxInfo)->MapUid,
]);
}
$map->update(['enabled' => 1]);
if (isVerbose()) {
printf("Loaded: %60s -> %s\n", $mapInfo->fileName, stripAll($map->gbx->Name));
@@ -423,6 +439,9 @@ public static function loadMaps()
echo "\n";
//get array with the uids
$enabledMapsuids = $maps->pluck('uId');
//Disable maps
Map::whereNotIn('uid', $enabledMapsuids)
->update(['enabled' => false]);
@@ -445,7 +464,7 @@ public static function getTimeLimit(): int
*/
public static function getOriginalTimeLimit(): int
{
return self::$timeLimit;
return self::$originalTimeLimit;
}
/**
@@ -9,7 +9,7 @@ class Map extends Model
{
protected $table = 'maps';
protected $fillable = ['uid', 'filename', 'plays', 'author', 'last_played', 'enabled', 'mx_details', 'mx_world_record', 'gbx', 'cooldown', 'checksum'];
protected $fillable = ['uid', 'filename', 'plays', 'author', 'last_played', 'enabled', 'mx_details', 'mx_world_record', 'gbx', 'cooldown'];
protected $dates = ['last_played'];
@@ -64,11 +64,6 @@ private static function getMapFavoritesJson(Player $player): string
public static function beginMap(Map $map)
{
$map->update([
'cooldown' => 0,
'last_played' => now(),
]);
self::sendUpdatedMaplist();
}
@@ -146,7 +141,11 @@ private static function getMapList(): Collection
//max length ~65762
//length 60088 is ok
return Map::whereEnabled(true)->get()->map(function (Map $map) {
return Map::whereEnabled(1)->get()->map(function (Map $map) {
if (!$map->id || !$map->gbx->MapUid) {
return null;
}
return [
'id' => (string)$map->id,
'name' => $map->gbx->Name,
@@ -155,7 +154,7 @@ private static function getMapList(): Collection
'uid' => $map->gbx->MapUid,
'c' => $map->cooldown,
];
});
})->filter();
}
private static function getMapAuthors($authorIds): Collection
@@ -0,0 +1,19 @@
<?php
namespace esc\Models;
use Illuminate\Database\Eloquent\Model;
class MapFavorite extends Model
{
protected $table = 'map-favorites';
protected $fillable = [
'player_id',
'map_id',
];
public $timestamps = false;
}
Oops, something went wrong.

0 comments on commit c6b8198

Please sign in to comment.
You can’t perform that action at this time.