2013-11-09 20:18:49 +01:00
|
|
|
<?php
|
|
|
|
|
2013-11-12 15:48:25 +01:00
|
|
|
namespace ManiaControl\Players;
|
2014-01-01 18:53:19 +01:00
|
|
|
|
2013-12-24 13:27:59 +01:00
|
|
|
use ManiaControl\Formatter;
|
2013-11-09 20:18:49 +01:00
|
|
|
|
2013-11-10 02:55:08 +01:00
|
|
|
/**
|
2014-01-01 18:53:19 +01:00
|
|
|
* Player Model Class
|
2013-11-10 02:55:08 +01:00
|
|
|
*
|
2013-11-10 17:23:00 +01:00
|
|
|
* @author kremsy & steeffeen
|
2013-11-10 02:55:08 +01:00
|
|
|
*/
|
2013-11-09 20:18:49 +01:00
|
|
|
class Player {
|
2013-11-10 02:55:08 +01:00
|
|
|
/**
|
|
|
|
* Public properties
|
|
|
|
*/
|
|
|
|
public $index = -1;
|
|
|
|
public $pid = -1;
|
|
|
|
public $login = '';
|
|
|
|
public $nickname = '';
|
2014-02-24 20:20:17 +01:00
|
|
|
public $rawNickname = '';
|
2013-11-10 17:23:00 +01:00
|
|
|
public $path = '';
|
2013-11-10 19:30:14 +01:00
|
|
|
public $authLevel = 0;
|
2013-11-10 02:55:08 +01:00
|
|
|
public $language = '';
|
|
|
|
public $avatar = '';
|
2013-11-10 17:23:00 +01:00
|
|
|
public $allies = array();
|
|
|
|
public $clubLink = '';
|
|
|
|
public $teamId = -1;
|
|
|
|
public $isOfficial = false;
|
|
|
|
public $ladderScore = -1.;
|
2013-11-10 02:55:08 +01:00
|
|
|
public $ladderRank = -1;
|
2014-01-23 16:15:41 +01:00
|
|
|
public $ladderStats = null;
|
2013-11-10 17:23:00 +01:00
|
|
|
public $joinTime = -1;
|
2013-12-09 19:31:55 +01:00
|
|
|
public $ipAddress = '';
|
2014-01-23 16:15:41 +01:00
|
|
|
public $isConnected = true;
|
|
|
|
public $clientVersion = '';
|
|
|
|
public $downloadRate = -1;
|
|
|
|
public $uploadRate = -1;
|
|
|
|
public $skins = null;
|
2014-01-29 09:29:02 +01:00
|
|
|
public $daysSinceZoneInscription = -1;
|
2014-01-23 16:15:41 +01:00
|
|
|
|
|
|
|
//Flags details
|
|
|
|
public $forcedSpectatorState = 0;
|
|
|
|
public $isReferee = false;
|
|
|
|
public $isPodiumReady = false;
|
|
|
|
public $isUsingStereoscopy = false;
|
|
|
|
public $isManagedByAnOtherServer = false;
|
|
|
|
public $isServer = false;
|
|
|
|
public $hasPlayerSlot = false;
|
|
|
|
public $isBroadcasting = false;
|
|
|
|
public $hasJoinedGame = false;
|
|
|
|
|
|
|
|
//SpectatorStatus details
|
|
|
|
public $isSpectator = false;
|
|
|
|
public $isTemporarySpectator = false;
|
|
|
|
public $isPureSpectator = false;
|
|
|
|
public $autoTarget = false;
|
|
|
|
public $currentTargetId = 0;
|
|
|
|
|
2014-01-01 18:53:19 +01:00
|
|
|
|
2013-11-10 02:55:08 +01:00
|
|
|
/**
|
2014-01-24 15:38:30 +01:00
|
|
|
* Construct a player from ManiaPlanet Player structure
|
2013-11-10 02:55:08 +01:00
|
|
|
*
|
2014-01-16 19:07:00 +01:00
|
|
|
* @param \Maniaplanet\DedicatedServer\Structures\Player $mpPlayer
|
2013-11-10 02:55:08 +01:00
|
|
|
*/
|
2014-01-16 19:07:00 +01:00
|
|
|
public function __construct($mpPlayer) {
|
2014-01-28 17:12:23 +01:00
|
|
|
if (!$mpPlayer) {
|
2014-01-23 16:15:41 +01:00
|
|
|
$this->isConnected = false;
|
2013-11-10 02:55:08 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-01-03 16:24:35 +01:00
|
|
|
|
2014-01-29 09:29:02 +01:00
|
|
|
$this->pid = $mpPlayer->playerId;
|
|
|
|
$this->login = $mpPlayer->login;
|
|
|
|
$this->nickname = Formatter::stripDirtyCodes($mpPlayer->nickName);
|
2014-02-24 20:20:17 +01:00
|
|
|
$this->rawNickname = $mpPlayer->nickName;
|
2014-01-29 09:29:02 +01:00
|
|
|
$this->path = $mpPlayer->path;
|
|
|
|
$this->language = $mpPlayer->language;
|
|
|
|
$this->avatar = $mpPlayer->avatar['FileName'];
|
|
|
|
$this->allies = $mpPlayer->allies;
|
|
|
|
$this->clubLink = $mpPlayer->clubLink;
|
|
|
|
$this->teamId = $mpPlayer->teamId;
|
|
|
|
$this->isOfficial = $mpPlayer->isInOfficialMode;
|
|
|
|
$this->ladderScore = $mpPlayer->ladderStats['PlayerRankings'][0]['Score'];
|
|
|
|
$this->ladderRank = $mpPlayer->ladderStats['PlayerRankings'][0]['Ranking'];
|
|
|
|
$this->ladderStats = $mpPlayer->ladderStats;
|
|
|
|
$this->daysSinceZoneInscription = $mpPlayer->hoursSinceZoneInscription / 24;
|
|
|
|
$this->ipAddress = $mpPlayer->iPAddress;
|
|
|
|
$this->clientVersion = $mpPlayer->clientVersion;
|
|
|
|
$this->downloadRate = $mpPlayer->downloadRate;
|
|
|
|
$this->uploadRate = $mpPlayer->uploadRate;
|
|
|
|
$this->skins = $mpPlayer->skins;
|
2014-01-23 16:15:41 +01:00
|
|
|
|
|
|
|
//Flag Details
|
|
|
|
$this->forcedSpectatorState = $mpPlayer->forceSpectator;
|
|
|
|
$this->isReferee = $mpPlayer->isReferee;
|
|
|
|
$this->isPodiumReady = $mpPlayer->isPodiumReady;
|
|
|
|
$this->isUsingStereoscopy = $mpPlayer->isUsingStereoscopy;
|
|
|
|
$this->isServer = $mpPlayer->isServer;
|
|
|
|
$this->isManagedByAnOtherServer = $mpPlayer->isManagedByAnOtherServer;
|
|
|
|
$this->hasPlayerSlot = $mpPlayer->hasPlayerSlot;
|
|
|
|
$this->hasJoinedGame = $mpPlayer->hasJoinedGame;
|
|
|
|
$this->isBroadcasting = $mpPlayer->isBroadcasting;
|
|
|
|
|
|
|
|
//Spectator Status
|
|
|
|
$this->isSpectator = $mpPlayer->spectator;
|
|
|
|
$this->isTemporarySpectator = $mpPlayer->temporarySpectator;
|
|
|
|
$this->isPureSpectator = $mpPlayer->pureSpectator;
|
|
|
|
$this->autoTarget = $mpPlayer->autoTarget;
|
|
|
|
$this->currentTargetId = $mpPlayer->currentTargetId;
|
|
|
|
|
2013-11-10 17:23:00 +01:00
|
|
|
$this->joinTime = time();
|
2014-02-02 13:31:35 +01:00
|
|
|
|
2014-03-31 21:54:51 +02:00
|
|
|
if (!$this->nickname) {
|
2014-01-02 14:35:00 +01:00
|
|
|
$this->nickname = $this->login;
|
2014-01-02 16:37:52 +01:00
|
|
|
}
|
2013-12-29 12:13:45 +01:00
|
|
|
}
|
2013-12-19 21:59:10 +01:00
|
|
|
|
2014-01-02 16:37:52 +01:00
|
|
|
|
2013-11-10 17:23:00 +01:00
|
|
|
/**
|
|
|
|
* Check if player is not a real player
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2013-12-29 12:13:45 +01:00
|
|
|
public function isFakePlayer() {
|
|
|
|
return ($this->pid <= 0 || $this->path == "");
|
2013-11-10 17:23:00 +01:00
|
|
|
}
|
|
|
|
|
2013-12-18 15:48:33 +01:00
|
|
|
/**
|
|
|
|
* Get province
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getProvince() {
|
|
|
|
$pathParts = explode('|', $this->path);
|
2014-01-28 17:12:23 +01:00
|
|
|
if (isset($pathParts[3])) {
|
2013-12-18 15:48:33 +01:00
|
|
|
return $pathParts[3];
|
|
|
|
}
|
2013-12-23 16:14:03 +01:00
|
|
|
return $this->getCountry();
|
2013-12-18 15:48:33 +01:00
|
|
|
}
|
|
|
|
|
2013-11-10 17:23:00 +01:00
|
|
|
/**
|
|
|
|
* Get country
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getCountry() {
|
|
|
|
$pathParts = explode('|', $this->path);
|
2014-01-28 17:12:23 +01:00
|
|
|
if (isset($pathParts[2])) {
|
2013-11-10 17:23:00 +01:00
|
|
|
return $pathParts[2];
|
|
|
|
}
|
2014-01-28 17:12:23 +01:00
|
|
|
if (isset($pathParts[1])) {
|
2013-11-10 17:23:00 +01:00
|
|
|
return $pathParts[1];
|
|
|
|
}
|
2014-01-28 17:12:23 +01:00
|
|
|
if (isset($pathParts[0])) {
|
2013-11-10 17:23:00 +01:00
|
|
|
return $pathParts[0];
|
|
|
|
}
|
|
|
|
return $this->path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get continent
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getContinent() {
|
|
|
|
$pathParts = explode('|', $this->path);
|
2014-01-28 17:12:23 +01:00
|
|
|
if (isset($pathParts[1])) {
|
2013-11-10 17:23:00 +01:00
|
|
|
return $pathParts[1];
|
|
|
|
}
|
2014-01-28 17:12:23 +01:00
|
|
|
if (isset($pathParts[0])) {
|
2013-11-10 17:23:00 +01:00
|
|
|
return $pathParts[0];
|
|
|
|
}
|
|
|
|
return $this->path;
|
2013-11-10 02:55:08 +01:00
|
|
|
}
|
2014-01-23 16:15:41 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the Flags of the Player
|
|
|
|
*
|
|
|
|
* @param $flags
|
|
|
|
*/
|
|
|
|
public function updatePlayerFlags($flags) {
|
|
|
|
//Detail flags
|
|
|
|
$this->forcedSpectatorState = $flags % 10; // 0, 1 or 2
|
|
|
|
$this->isReferee = (bool)(intval($flags / 10) % 10);
|
|
|
|
$this->isPodiumReady = (bool)(intval($flags / 100) % 10);
|
|
|
|
$this->isUsingStereoscopy = (bool)(intval($flags / 1000) % 10);
|
|
|
|
$this->isManagedByAnOtherServer = (bool)(intval($flags / 10000) % 10);
|
|
|
|
$this->isServer = (bool)(intval($flags / 100000) % 10);
|
|
|
|
$this->hasPlayerSlot = (bool)(intval($flags / 1000000) % 10);
|
|
|
|
$this->isBroadcasting = (bool)(intval($flags / 10000000) % 10);
|
|
|
|
$this->hasJoinedGame = (bool)(intval($flags / 100000000) % 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the Spectator Status of the player
|
|
|
|
*
|
|
|
|
* @param $spectatorStatus
|
|
|
|
*/
|
|
|
|
public function updateSpectatorStatus($spectatorStatus) {
|
|
|
|
//Details spectatorStatus
|
|
|
|
$this->isSpectator = (bool)($spectatorStatus % 10);
|
|
|
|
$this->isTemporarySpectator = (bool)(intval($spectatorStatus / 10) % 10);
|
|
|
|
$this->isPureSpectator = (bool)(intval($spectatorStatus / 100) % 10);
|
|
|
|
$this->autoTarget = (bool)(intval($spectatorStatus / 1000) % 10);
|
|
|
|
$this->currentTargetId = intval($spectatorStatus / 10000);
|
|
|
|
}
|
2013-11-09 20:18:49 +01:00
|
|
|
}
|