updated player object
This commit is contained in:
parent
bb28e72f79
commit
8a193fe7ee
@ -24,14 +24,41 @@ class Player {
|
||||
public $allies = array();
|
||||
public $clubLink = '';
|
||||
public $teamId = -1;
|
||||
public $isSpectator = false;
|
||||
public $isOfficial = false;
|
||||
public $isReferee = false;
|
||||
public $ladderScore = -1.;
|
||||
public $ladderRank = -1;
|
||||
public $ladderStats = null;
|
||||
public $joinTime = -1;
|
||||
public $ipAddress = '';
|
||||
public $maniaPlanetPlayDays = 0;
|
||||
public $isConnected = true;
|
||||
public $clientVersion = '';
|
||||
public $downloadRate = -1;
|
||||
public $uploadRate = -1;
|
||||
public $skins = null;
|
||||
public $stateUpdateLatency; //TODO format?
|
||||
public $stateUpdatePeriod; //TODO format?
|
||||
public $latestNetworkActivity; //TODO format?
|
||||
public $packetLossRate; //TODO format?
|
||||
public $maniaPlanetPlayDays = -1;
|
||||
|
||||
//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;
|
||||
|
||||
|
||||
/**
|
||||
* Construct a player from XmlRpc data
|
||||
@ -40,11 +67,10 @@ class Player {
|
||||
*/
|
||||
public function __construct($mpPlayer) {
|
||||
if(!$mpPlayer) {
|
||||
$this->isConnected = false;
|
||||
return;
|
||||
}
|
||||
|
||||
$rpcInfos = (array)$mpPlayer; //Temporary
|
||||
|
||||
$this->pid = $mpPlayer->playerId;
|
||||
$this->login = $mpPlayer->login;
|
||||
$this->nickname = Formatter::stripDirtyCodes($mpPlayer->nickName);
|
||||
@ -54,14 +80,40 @@ class Player {
|
||||
$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->ladderStats = $mpPlayer->ladderStats;
|
||||
$this->maniaPlanetPlayDays = $mpPlayer->hoursSinceZoneInscription / 24; //TODO change
|
||||
$this->ipAddress = $mpPlayer->iPAddress;
|
||||
$this->clientVersion = $mpPlayer->clientVersion;
|
||||
$this->downloadRate = $mpPlayer->downloadRate;
|
||||
$this->uploadRate = $mpPlayer->uploadRate;
|
||||
$this->skins = $mpPlayer->skins;
|
||||
$this->stateUpdateLatency = $mpPlayer->stateUpdateLatency;
|
||||
$this->stateUpdatePeriod = $mpPlayer->stateUpdatePeriod;
|
||||
$this->latestNetworkActivity = $mpPlayer->latestNetworkActivity;
|
||||
$this->packetLossRate = $mpPlayer->packetLossRate;
|
||||
|
||||
|
||||
//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;
|
||||
|
||||
|
||||
$this->joinTime = time();
|
||||
|
||||
@ -127,4 +179,37 @@ class Player {
|
||||
}
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -119,6 +119,7 @@ class PlayerManager implements CallbackListener {
|
||||
}
|
||||
$playerInfo = $this->maniaControl->client->getDetailedPlayerInfo($playerItem->login);
|
||||
$player = new Player($playerInfo);
|
||||
$player->hasJoinedGame = true;
|
||||
$this->addPlayer($player);
|
||||
}
|
||||
|
||||
@ -137,19 +138,6 @@ class PlayerManager implements CallbackListener {
|
||||
$player = new Player($playerInfo);
|
||||
|
||||
$this->addPlayer($player);
|
||||
|
||||
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer()) {
|
||||
$string = array(0 => '$0f0Player', 1 => '$0f0Moderator', 2 => '$0f0Admin', 3 => '$0f0MasterAdmin', 4 => '$0f0MasterAdmin');
|
||||
$chatMessage = '$s$0f0' . $string[$player->authLevel] . ' $fff' . $player->nickname . '$z$s$0f0 Nation:$fff ' . $player->getCountry() . ' $z$s$0f0joined!';
|
||||
$this->maniaControl->chat->sendChat($chatMessage);
|
||||
$this->maniaControl->chat->sendInformation('This server uses ManiaControl v' . ManiaControl::VERSION . '!', $player->login);
|
||||
}
|
||||
|
||||
$logMessage = "Player joined: {$player->login} / " . Formatter::stripCodes($player->nickname) . " Nation: " . $player->getCountry() . " IP: {$player->ipAddress}";
|
||||
$this->maniaControl->log($logMessage);
|
||||
|
||||
// Trigger own PlayerJoined callback
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERJOINED, array(self::CB_PLAYERJOINED, $player));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -192,10 +180,31 @@ class PlayerManager implements CallbackListener {
|
||||
$player->isSpectator = $callback[1][0]["SpectatorStatus"];
|
||||
$player->ladderRank = $callback[1][0]["LadderRanking"];
|
||||
|
||||
$prevJoinState = $player->hasJoinedGame;
|
||||
|
||||
$player->updatePlayerFlags($callback[1][0]["Flags"]);
|
||||
$player->updateSpectatorStatus($callback[1][0]["SpectatorStatus"]);
|
||||
|
||||
//Check if Player finished joining the game
|
||||
if($player->hasJoinedGame && !$prevJoinState) {
|
||||
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer()) {
|
||||
$string = array(0 => '$0f0Player', 1 => '$0f0Moderator', 2 => '$0f0Admin', 3 => '$0f0SuperAdmin', 4 => '$0f0MasterAdmin');
|
||||
$chatMessage = '$s$0f0' . $string[$player->authLevel] . ' $fff' . $player->nickname . '$z$s$0f0 Nation:$fff ' . $player->getCountry() . ' $z$s$0f0joined!';
|
||||
$this->maniaControl->chat->sendChat($chatMessage);
|
||||
$this->maniaControl->chat->sendInformation('This server uses ManiaControl v' . ManiaControl::VERSION . '!', $player->login);
|
||||
}
|
||||
|
||||
$logMessage = "Player joined: {$player->login} / " . Formatter::stripCodes($player->nickname) . " Nation: " . $player->getCountry() . " IP: {$player->ipAddress}";
|
||||
$this->maniaControl->log($logMessage);
|
||||
|
||||
// Trigger own PlayerJoined callback
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERJOINED, array(self::CB_PLAYERJOINED, $player));
|
||||
}
|
||||
// Trigger own callback
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERINFOCHANGED, array(self::CB_PLAYERINFOCHANGED));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all Players
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user