2013-11-09 20:18:49 +01:00
|
|
|
<?php
|
|
|
|
|
2013-11-12 15:48:25 +01:00
|
|
|
namespace ManiaControl\Players;
|
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
|
|
|
/**
|
|
|
|
* Class representing players
|
|
|
|
*
|
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 = '';
|
2013-11-10 17:23:00 +01:00
|
|
|
public $path = '';
|
2013-11-10 19:30:14 +01:00
|
|
|
public $authLevel = 0;
|
2013-11-10 17:23:00 +01:00
|
|
|
public $joinCount = 0;
|
|
|
|
public $totalPlayed = 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 $isSpectator = false;
|
|
|
|
public $isOfficial = false;
|
|
|
|
public $isReferee = false;
|
|
|
|
public $ladderScore = -1.;
|
2013-11-10 02:55:08 +01:00
|
|
|
public $ladderRank = -1;
|
2013-11-10 17:23:00 +01:00
|
|
|
public $joinTime = -1;
|
2013-12-09 19:31:55 +01:00
|
|
|
public $ipAddress = '';
|
2013-11-10 02:55:08 +01:00
|
|
|
/**
|
2013-11-10 17:23:00 +01:00
|
|
|
* Construct a player from XmlRpc data
|
2013-11-10 02:55:08 +01:00
|
|
|
*
|
|
|
|
* @param array $rpcInfos
|
|
|
|
*/
|
2013-11-10 17:23:00 +01:00
|
|
|
public function __construct(array $rpcInfos) {
|
2013-11-10 02:55:08 +01:00
|
|
|
if (!$rpcInfos) {
|
|
|
|
return;
|
|
|
|
}
|
2013-11-10 17:23:00 +01:00
|
|
|
$this->pid = $rpcInfos['PlayerId'];
|
2013-11-10 02:55:08 +01:00
|
|
|
$this->login = $rpcInfos['Login'];
|
2013-12-26 11:25:10 +01:00
|
|
|
$this->nickname = Formatter::stripCodesWithoutColors($rpcInfos['NickName']); //TODO don't remove $s, $i
|
2013-11-10 17:23:00 +01:00
|
|
|
$this->path = $rpcInfos['Path'];
|
|
|
|
$this->language = $rpcInfos['Language'];
|
|
|
|
$this->avatar = $rpcInfos['Avatar']['FileName'];
|
|
|
|
$this->allies = $rpcInfos['Allies'];
|
|
|
|
$this->clubLink = $rpcInfos['ClubLink'];
|
2013-11-10 02:55:08 +01:00
|
|
|
$this->teamId = $rpcInfos['TeamId'];
|
|
|
|
$this->isSpectator = $rpcInfos['IsSpectator'];
|
|
|
|
$this->isOfficial = $rpcInfos['IsInOfficialMode'];
|
2013-11-10 17:23:00 +01:00
|
|
|
$this->isReferee = $rpcInfos['IsReferee'];
|
|
|
|
$this->ladderScore = $rpcInfos['LadderStats']['PlayerRankings'][0]['Score'];
|
2013-11-10 02:55:08 +01:00
|
|
|
$this->ladderRank = $rpcInfos['LadderStats']['PlayerRankings'][0]['Ranking'];
|
2013-12-09 19:31:55 +01:00
|
|
|
|
|
|
|
$this->ipAddress = $rpcInfos['IPAddress'];
|
|
|
|
|
2013-11-10 17:23:00 +01:00
|
|
|
$this->joinTime = time();
|
2013-12-19 21:59:10 +01:00
|
|
|
|
2013-12-29 12:13:45 +01:00
|
|
|
}
|
2013-12-19 21:59:10 +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);
|
|
|
|
if (isset($pathParts[3])) {
|
|
|
|
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);
|
|
|
|
if (isset($pathParts[2])) {
|
|
|
|
return $pathParts[2];
|
|
|
|
}
|
|
|
|
if (isset($pathParts[1])) {
|
|
|
|
return $pathParts[1];
|
|
|
|
}
|
|
|
|
if (isset($pathParts[0])) {
|
|
|
|
return $pathParts[0];
|
|
|
|
}
|
|
|
|
return $this->path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get continent
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getContinent() {
|
|
|
|
$pathParts = explode('|', $this->path);
|
|
|
|
if (isset($pathParts[1])) {
|
|
|
|
return $pathParts[1];
|
|
|
|
}
|
|
|
|
if (isset($pathParts[0])) {
|
|
|
|
return $pathParts[0];
|
|
|
|
}
|
|
|
|
return $this->path;
|
2013-11-10 02:55:08 +01:00
|
|
|
}
|
2013-11-09 20:18:49 +01:00
|
|
|
}
|