2014-05-04 00:36:20 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MCTeam\Dedimania;
|
|
|
|
|
|
|
|
use ManiaControl\ManiaControl;
|
2014-05-13 16:40:05 +02:00
|
|
|
use ManiaControl\Players\Player;
|
2014-05-04 00:36:20 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Structures\Version;
|
|
|
|
|
|
|
|
/**
|
2014-05-24 20:19:41 +02:00
|
|
|
* ManiaControl Dedimania Plugin Data Structure
|
2014-05-04 00:36:20 +02:00
|
|
|
*
|
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
|
|
|
* @copyright 2014 ManiaControl Team
|
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
|
|
|
*/
|
|
|
|
class DedimaniaData {
|
|
|
|
/*
|
|
|
|
* Constants
|
|
|
|
*/
|
|
|
|
public $game;
|
|
|
|
public $path;
|
|
|
|
public $packmask;
|
|
|
|
public $serverVersion;
|
|
|
|
public $serverBuild;
|
|
|
|
public $tool;
|
|
|
|
public $version;
|
|
|
|
public $login;
|
|
|
|
public $code;
|
|
|
|
public $sessionId = '';
|
|
|
|
public $records = array();
|
|
|
|
public $players = array();
|
|
|
|
public $directoryAccessChecked = false;
|
|
|
|
public $serverMaxRank = 30;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a new Dedimania Data Model
|
|
|
|
*
|
|
|
|
* @param string $serverLogin
|
|
|
|
* @param string $dedimaniaCode
|
|
|
|
* @param string $path
|
|
|
|
* @param string $packmask
|
|
|
|
* @param Version $serverVersion
|
|
|
|
*/
|
|
|
|
public function __construct($serverLogin, $dedimaniaCode, $path, $packmask, Version $serverVersion) {
|
|
|
|
$this->game = "TM2";
|
|
|
|
$this->login = $serverLogin;
|
|
|
|
$this->code = $dedimaniaCode;
|
|
|
|
$this->version = ManiaControl::VERSION;
|
|
|
|
$this->tool = "ManiaControl";
|
|
|
|
$this->path = $path;
|
|
|
|
$this->packmask = $packmask;
|
|
|
|
$this->serverVersion = $serverVersion->version;
|
|
|
|
$this->serverBuild = $serverVersion->build;
|
|
|
|
}
|
|
|
|
|
2014-05-13 16:40:05 +02:00
|
|
|
/**
|
|
|
|
* Build the Data Array
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2014-05-04 00:36:20 +02:00
|
|
|
public function toArray() {
|
|
|
|
$array = array();
|
|
|
|
foreach (get_object_vars($this) as $key => $value) {
|
2014-06-14 14:32:29 +02:00
|
|
|
if ($key === 'records' || $key === 'sessionId' || $key === 'directoryAccessChecked' || $key === 'serverMaxRank' || $key === 'players') {
|
2014-05-04 00:36:20 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$array[ucfirst($key)] = $value;
|
|
|
|
}
|
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
|
2014-05-13 16:40:05 +02:00
|
|
|
/**
|
|
|
|
* Get the Number of Records
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
2014-05-04 00:36:20 +02:00
|
|
|
public function getRecordCount() {
|
|
|
|
return count($this->records);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Max Rank for a certain Player
|
|
|
|
*
|
2014-05-13 16:40:05 +02:00
|
|
|
* @param mixed $login
|
2014-05-04 00:36:20 +02:00
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getPlayerMaxRank($login) {
|
2014-05-13 16:40:05 +02:00
|
|
|
$login = Player::parseLogin($login);
|
2014-05-04 00:36:20 +02:00
|
|
|
$maxRank = $this->serverMaxRank;
|
|
|
|
foreach ($this->players as $player) {
|
|
|
|
/** @var DedimaniaPlayer $player */
|
|
|
|
if ($player->login === $login) {
|
|
|
|
if ($player->maxRank > $maxRank) {
|
|
|
|
$maxRank = $player->maxRank;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $maxRank;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-09 17:31:29 +02:00
|
|
|
* Add a Player to the Players array
|
2014-05-04 00:36:20 +02:00
|
|
|
*
|
|
|
|
* @param DedimaniaPlayer $player
|
|
|
|
*/
|
|
|
|
public function addPlayer(DedimaniaPlayer $player) {
|
|
|
|
$this->players[$player->login] = $player;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-09 17:31:29 +02:00
|
|
|
* Remove a Dedimania Player by its login
|
2014-05-04 00:36:20 +02:00
|
|
|
*
|
2014-05-09 17:31:29 +02:00
|
|
|
* @param string $login
|
2014-05-04 00:36:20 +02:00
|
|
|
*/
|
|
|
|
public function removePlayer($login) {
|
|
|
|
unset($this->players[$login]);
|
|
|
|
}
|
|
|
|
}
|