TrackManiaControl/application/core/Players/Player.php

131 lines
2.9 KiB
PHP
Raw Normal View History

2013-11-09 20:18:49 +01:00
<?php
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
/**
2014-01-01 18:53:19 +01:00
* Player Model Class
*
* @author kremsy & steeffeen
*/
2013-11-09 20:18:49 +01:00
class Player {
/**
* Public properties
*/
public $index = -1;
public $pid = -1;
public $login = '';
public $nickname = '';
public $path = '';
public $authLevel = 0;
public $language = '';
public $avatar = '';
public $allies = array();
public $clubLink = '';
public $teamId = -1;
public $isSpectator = false;
public $isOfficial = false;
public $isReferee = false;
public $ladderScore = -1.;
public $ladderRank = -1;
public $joinTime = -1;
public $ipAddress = '';
2014-01-03 17:09:24 +01:00
public $maniaPlanetPlayDays = 0;
2014-01-01 18:53:19 +01:00
/**
* Construct a player from XmlRpc data
*
2014-01-16 19:07:00 +01:00
* @param \Maniaplanet\DedicatedServer\Structures\Player $mpPlayer
*/
2014-01-16 19:07:00 +01:00
public function __construct($mpPlayer) {
if(!$mpPlayer) {
return;
}
2014-01-03 16:24:35 +01:00
2014-01-16 19:07:00 +01:00
$rpcInfos = (array)$mpPlayer; //Temporary
2014-01-02 16:37:52 +01:00
2014-01-16 19:07:00 +01:00
$this->pid = $mpPlayer->playerId;
$this->login = $mpPlayer->login;
$this->nickname = Formatter::stripDirtyCodes($mpPlayer->nickName);
$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->isSpectator = $mpPlayer->isSpectator;
$this->isOfficial = $mpPlayer->isInOfficialMode;
$this->isReferee = $mpPlayer->isReferee;
$this->ladderScore = $mpPlayer->ladderStats['PlayerRankings'][0]['Score'];
$this->ladderRank = $mpPlayer->ladderStats['PlayerRankings'][0]['Ranking'];
$this->maniaPlanetPlayDays = $mpPlayer->hoursSinceZoneInscription / 24;
$this->ipAddress = $mpPlayer->iPAddress;
2014-01-02 16:37:52 +01:00
$this->joinTime = time();
2014-01-02 16:37:52 +01:00
if($this->nickname == '') {
$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
/**
* 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-12-18 15:48:33 +01:00
/**
* Get province
*
* @return string
*/
public function getProvince() {
$pathParts = explode('|', $this->path);
2014-01-02 16:37:52 +01:00
if(isset($pathParts[3])) {
2013-12-18 15:48:33 +01:00
return $pathParts[3];
}
return $this->getCountry();
2013-12-18 15:48:33 +01:00
}
/**
* Get country
*
* @return string
*/
public function getCountry() {
$pathParts = explode('|', $this->path);
2014-01-02 16:37:52 +01:00
if(isset($pathParts[2])) {
return $pathParts[2];
}
2014-01-02 16:37:52 +01:00
if(isset($pathParts[1])) {
return $pathParts[1];
}
2014-01-02 16:37:52 +01:00
if(isset($pathParts[0])) {
return $pathParts[0];
}
return $this->path;
}
/**
* Get continent
*
* @return string
*/
public function getContinent() {
$pathParts = explode('|', $this->path);
2014-01-02 16:37:52 +01:00
if(isset($pathParts[1])) {
return $pathParts[1];
}
2014-01-02 16:37:52 +01:00
if(isset($pathParts[0])) {
return $pathParts[0];
}
return $this->path;
}
2013-11-09 20:18:49 +01:00
}