TrackManiaControl/core/Maps/Map.php

160 lines
3.9 KiB
PHP
Raw Permalink Normal View History

<?php
namespace ManiaControl\Maps;
use ManiaControl\General\Dumpable;
use ManiaControl\General\DumpTrait;
use ManiaControl\General\UsageInformationAble;
use ManiaControl\General\UsageInformationTrait;
2014-01-28 16:54:23 +01:00
use ManiaControl\ManiaExchange\MXMapInfo;
use ManiaControl\Utils\Formatter;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
/**
* ManiaControl Map Model Class
*
2014-05-02 17:50:30 +02:00
* @author ManiaControl Team <mail@maniacontrol.com>
2020-01-22 10:39:35 +01:00
* @copyright 2014-2020 ManiaControl Team
2014-04-18 01:29:36 +02:00
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class Map implements Dumpable, UsageInformationAble {
use DumpTrait, UsageInformationTrait;
//Minimum Lightmap Version for the Update Check
const MIN_LIGHTMAP_VERSION = 7;
/*
* Public properties
*/
public $index = -1;
public $name = 'undefined';
public $rawName = null;
public $uid = null;
public $fileName = null;
public $environment = null;
public $authorTime = -1;
public $goldTime = -1;
public $silverTime = -1;
public $bronzeTime = -1;
public $copperPrice = -1;
public $mapType = null;
public $mapStyle = null;
public $nbCheckpoints = -1;
public $nbLaps = -1;
2014-01-09 23:21:44 +01:00
/** @var MXMapInfo $mx */
public $mx = null;
2014-05-15 15:13:18 +02:00
public $authorLogin = null;
public $authorNick = null;
public $authorZone = null;
2014-05-15 15:13:18 +02:00
public $authorEInfo = null;
public $comment = null;
public $titleUid = null;
public $startTime = -1;
public $lastUpdate = 0;
public $karma = null;
2014-04-18 01:29:36 +02:00
/*
* Private properties
*/
/** @var ManiaControl $maniaControl */
private $maniaControl = null;
/**
* Construct a new map instance from xmlrpc data
*
2014-01-16 18:08:32 +01:00
* @param \Maniaplanet\DedicatedServer\Structures\Map $mpMap
*/
public function __construct(ManiaControl $maniaControl, $mpMap = null) {
$this->maniaControl = $maniaControl;
2014-01-12 20:56:25 +01:00
$this->startTime = time();
2014-01-08 21:52:42 +01:00
2014-02-16 00:51:30 +01:00
if (!$mpMap) {
2014-01-08 21:52:42 +01:00
return;
}
$this->name = Formatter::stripDirtyCodes($mpMap->name);
2014-03-12 13:07:02 +01:00
$this->rawName = $mpMap->name;
2014-02-16 00:51:30 +01:00
$this->uid = $mpMap->uId;
$this->fileName = $mpMap->fileName;
$this->authorLogin = $mpMap->author;
$this->environment = $mpMap->environnement;
2014-04-18 01:29:36 +02:00
$this->authorTime = $mpMap->authorTime;
2014-02-16 00:51:30 +01:00
$this->goldTime = $mpMap->goldTime;
$this->silverTime = $mpMap->silverTime;
$this->bronzeTime = $mpMap->bronzeTime;
2014-02-16 00:51:30 +01:00
$this->copperPrice = $mpMap->copperPrice;
$this->mapType = $mpMap->mapType;
$this->mapStyle = $mpMap->mapStyle;
$this->nbCheckpoints = $mpMap->nbCheckpoints;
2014-02-16 22:38:14 +01:00
$this->nbLaps = $mpMap->nbLaps;
2014-01-08 21:52:42 +01:00
2023-01-17 10:06:56 +01:00
$this->authorNick = $mpMap->authorNickname;
$player = $this->maniaControl->getPlayerManager()->getPlayer($this->authorLogin);
if ($player) {
$this->authorNick = $player->nickname;
2023-01-17 10:06:56 +01:00
} else if ($mpMap->authorNickname !== "") {
$this->authorNick = $mpMap->authorNickname;
} else {
$this->authorNick = $this->authorLogin;
}
2014-01-09 23:21:44 +01:00
}
2014-01-08 21:52:42 +01:00
2014-05-09 18:42:17 +02:00
/**
* Get the escaped map name
2014-05-09 18:42:17 +02:00
*
* @return string
*/
public function getEscapedName() {
return Formatter::escapeText($this->name);
}
2014-03-12 13:07:02 +01:00
/**
* Get the game type of the map
2014-03-12 13:07:02 +01:00
*
* @return string
*/
public function getGame() {
2014-05-02 17:50:30 +02:00
switch ($this->environment) {
2014-03-12 13:07:02 +01:00
case 'Storm':
return 'sm';
2014-03-12 13:07:02 +01:00
case 'Canyon':
case 'Stadium':
case 'Valley':
2017-05-22 21:43:44 +02:00
case 'Lagoon':
return 'tm';
2014-03-12 13:07:02 +01:00
}
return null;
2014-03-12 13:07:02 +01:00
}
2014-01-09 23:21:44 +01:00
/**
* Check whether a map update is available
2014-01-09 23:21:44 +01:00
*
* @return bool
*/
public function updateAvailable() {
//Check if MX Object is existing
if (!$this->mx) {
return false;
}
//Check if the Lightmap verison on MX surpasses the min Lightmap version
if ($this->mx->lightmap < self::MIN_LIGHTMAP_VERSION) {
return false;
}
//Check if last Map update is older than the MX Maptime
if ($this->lastUpdate < strtotime($this->mx->updated)) {
return true;
}
//Check if UIDs are different
if ($this->uid !== $this->mx->uid) {
return true;
}
return false;
}
2014-05-11 20:33:57 +02:00
}