small improvements
This commit is contained in:
parent
6b62932ead
commit
769147e7c7
@ -10,6 +10,7 @@ use ManiaControl\Formatter;
|
|||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\ManiaExchange\ManiaExchangeList;
|
use ManiaControl\ManiaExchange\ManiaExchangeList;
|
||||||
use ManiaControl\ManiaExchange\ManiaExchangeManager;
|
use ManiaControl\ManiaExchange\ManiaExchangeManager;
|
||||||
|
use ManiaControl\ManiaExchange\MXMapInfo;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,10 +35,6 @@ class Player {
|
|||||||
public $downloadRate = -1;
|
public $downloadRate = -1;
|
||||||
public $uploadRate = -1;
|
public $uploadRate = -1;
|
||||||
public $skins = null;
|
public $skins = null;
|
||||||
public $stateUpdateLatency; //TODO format?
|
|
||||||
public $stateUpdatePeriod; //TODO format?
|
|
||||||
public $latestNetworkActivity; //TODO format?
|
|
||||||
public $packetLossRate; //TODO format?
|
|
||||||
public $maniaPlanetPlayDays = -1;
|
public $maniaPlanetPlayDays = -1;
|
||||||
|
|
||||||
//Flags details
|
//Flags details
|
||||||
@ -66,7 +62,7 @@ class Player {
|
|||||||
* @param \Maniaplanet\DedicatedServer\Structures\Player $mpPlayer
|
* @param \Maniaplanet\DedicatedServer\Structures\Player $mpPlayer
|
||||||
*/
|
*/
|
||||||
public function __construct($mpPlayer) {
|
public function __construct($mpPlayer) {
|
||||||
if(!$mpPlayer) {
|
if (!$mpPlayer) {
|
||||||
$this->isConnected = false;
|
$this->isConnected = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -90,11 +86,6 @@ class Player {
|
|||||||
$this->downloadRate = $mpPlayer->downloadRate;
|
$this->downloadRate = $mpPlayer->downloadRate;
|
||||||
$this->uploadRate = $mpPlayer->uploadRate;
|
$this->uploadRate = $mpPlayer->uploadRate;
|
||||||
$this->skins = $mpPlayer->skins;
|
$this->skins = $mpPlayer->skins;
|
||||||
$this->stateUpdateLatency = $mpPlayer->stateUpdateLatency;
|
|
||||||
$this->stateUpdatePeriod = $mpPlayer->stateUpdatePeriod;
|
|
||||||
$this->latestNetworkActivity = $mpPlayer->latestNetworkActivity;
|
|
||||||
$this->packetLossRate = $mpPlayer->packetLossRate;
|
|
||||||
|
|
||||||
|
|
||||||
//Flag Details
|
//Flag Details
|
||||||
$this->forcedSpectatorState = $mpPlayer->forceSpectator;
|
$this->forcedSpectatorState = $mpPlayer->forceSpectator;
|
||||||
@ -114,10 +105,8 @@ class Player {
|
|||||||
$this->autoTarget = $mpPlayer->autoTarget;
|
$this->autoTarget = $mpPlayer->autoTarget;
|
||||||
$this->currentTargetId = $mpPlayer->currentTargetId;
|
$this->currentTargetId = $mpPlayer->currentTargetId;
|
||||||
|
|
||||||
|
|
||||||
$this->joinTime = time();
|
$this->joinTime = time();
|
||||||
|
if ($this->nickname == '') {
|
||||||
if($this->nickname == '') {
|
|
||||||
$this->nickname = $this->login;
|
$this->nickname = $this->login;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -139,7 +128,7 @@ class Player {
|
|||||||
*/
|
*/
|
||||||
public function getProvince() {
|
public function getProvince() {
|
||||||
$pathParts = explode('|', $this->path);
|
$pathParts = explode('|', $this->path);
|
||||||
if(isset($pathParts[3])) {
|
if (isset($pathParts[3])) {
|
||||||
return $pathParts[3];
|
return $pathParts[3];
|
||||||
}
|
}
|
||||||
return $this->getCountry();
|
return $this->getCountry();
|
||||||
@ -152,13 +141,13 @@ class Player {
|
|||||||
*/
|
*/
|
||||||
public function getCountry() {
|
public function getCountry() {
|
||||||
$pathParts = explode('|', $this->path);
|
$pathParts = explode('|', $this->path);
|
||||||
if(isset($pathParts[2])) {
|
if (isset($pathParts[2])) {
|
||||||
return $pathParts[2];
|
return $pathParts[2];
|
||||||
}
|
}
|
||||||
if(isset($pathParts[1])) {
|
if (isset($pathParts[1])) {
|
||||||
return $pathParts[1];
|
return $pathParts[1];
|
||||||
}
|
}
|
||||||
if(isset($pathParts[0])) {
|
if (isset($pathParts[0])) {
|
||||||
return $pathParts[0];
|
return $pathParts[0];
|
||||||
}
|
}
|
||||||
return $this->path;
|
return $this->path;
|
||||||
@ -171,10 +160,10 @@ class Player {
|
|||||||
*/
|
*/
|
||||||
public function getContinent() {
|
public function getContinent() {
|
||||||
$pathParts = explode('|', $this->path);
|
$pathParts = explode('|', $this->path);
|
||||||
if(isset($pathParts[1])) {
|
if (isset($pathParts[1])) {
|
||||||
return $pathParts[1];
|
return $pathParts[1];
|
||||||
}
|
}
|
||||||
if(isset($pathParts[0])) {
|
if (isset($pathParts[0])) {
|
||||||
return $pathParts[0];
|
return $pathParts[0];
|
||||||
}
|
}
|
||||||
return $this->path;
|
return $this->path;
|
||||||
|
@ -86,12 +86,12 @@ class PlayerManager implements CallbackListener {
|
|||||||
UNIQUE KEY `login` (`login`)
|
UNIQUE KEY `login` (`login`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Player Data' AUTO_INCREMENT=1;";
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Player Data' AUTO_INCREMENT=1;";
|
||||||
$playerTableStatement = $mysqli->prepare($playerTableQuery);
|
$playerTableStatement = $mysqli->prepare($playerTableQuery);
|
||||||
if($mysqli->error) {
|
if ($mysqli->error) {
|
||||||
trigger_error($mysqli->error, E_USER_ERROR);
|
trigger_error($mysqli->error, E_USER_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$playerTableStatement->execute();
|
$playerTableStatement->execute();
|
||||||
if($playerTableStatement->error) {
|
if ($playerTableStatement->error) {
|
||||||
trigger_error($playerTableStatement->error, E_USER_ERROR);
|
trigger_error($playerTableStatement->error, E_USER_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -108,7 +108,7 @@ class PlayerManager implements CallbackListener {
|
|||||||
// Add all players
|
// Add all players
|
||||||
$players = $this->maniaControl->client->getPlayerList(300, 0, 2);
|
$players = $this->maniaControl->client->getPlayerList(300, 0, 2);
|
||||||
foreach($players as $playerItem) {
|
foreach($players as $playerItem) {
|
||||||
if($playerItem->playerId <= 0) {
|
if ($playerItem->playerId <= 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,6 +120,8 @@ class PlayerManager implements CallbackListener {
|
|||||||
$playerItem->isSpectator = $detailedPlayerInfo->isSpectator;
|
$playerItem->isSpectator = $detailedPlayerInfo->isSpectator;
|
||||||
$playerItem->avatar = $detailedPlayerInfo->avatar;
|
$playerItem->avatar = $detailedPlayerInfo->avatar;
|
||||||
$playerItem->ladderStats = $detailedPlayerInfo->ladderStats;
|
$playerItem->ladderStats = $detailedPlayerInfo->ladderStats;
|
||||||
|
$playerItem->downloadRate = $detailedPlayerInfo->downloadRate;
|
||||||
|
$playerItem->uploadRate = $detailedPlayerInfo->uploadRate;
|
||||||
|
|
||||||
$playerItem->hoursSinceZoneInscription = $detailedPlayerInfo->hoursSinceZoneInscription;
|
$playerItem->hoursSinceZoneInscription = $detailedPlayerInfo->hoursSinceZoneInscription;
|
||||||
|
|
||||||
@ -157,7 +159,7 @@ class PlayerManager implements CallbackListener {
|
|||||||
// Trigger own callback
|
// Trigger own callback
|
||||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERDISCONNECTED, array(self::CB_PLAYERDISCONNECTED, $player));
|
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERDISCONNECTED, array(self::CB_PLAYERDISCONNECTED, $player));
|
||||||
|
|
||||||
if($player == null || $player->isFakePlayer()) {
|
if ($player == null || $player->isFakePlayer()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,7 +167,7 @@ class PlayerManager implements CallbackListener {
|
|||||||
$logMessage = "Player left: {$player->login} / {$player->nickname} Playtime: {$played}";
|
$logMessage = "Player left: {$player->login} / {$player->nickname} Playtime: {$played}";
|
||||||
$this->maniaControl->log(Formatter::stripCodes($logMessage));
|
$this->maniaControl->log(Formatter::stripCodes($logMessage));
|
||||||
|
|
||||||
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES)) {
|
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES)) {
|
||||||
$this->maniaControl->chat->sendChat('$<' . $player->nickname . '$> $s$0f0has left the game');
|
$this->maniaControl->chat->sendChat('$<' . $player->nickname . '$> $s$0f0has left the game');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -177,7 +179,7 @@ class PlayerManager implements CallbackListener {
|
|||||||
*/
|
*/
|
||||||
public function playerInfoChanged(array $callback) {
|
public function playerInfoChanged(array $callback) {
|
||||||
$player = $this->getPlayer($callback[1][0]['Login']);
|
$player = $this->getPlayer($callback[1][0]['Login']);
|
||||||
if($player == null) {
|
if ($player == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,8 +192,8 @@ class PlayerManager implements CallbackListener {
|
|||||||
$player->updateSpectatorStatus($callback[1][0]["SpectatorStatus"]);
|
$player->updateSpectatorStatus($callback[1][0]["SpectatorStatus"]);
|
||||||
|
|
||||||
//Check if Player finished joining the game
|
//Check if Player finished joining the game
|
||||||
if($player->hasJoinedGame && !$prevJoinState) {
|
if ($player->hasJoinedGame && !$prevJoinState) {
|
||||||
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer()) {
|
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');
|
$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!';
|
$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->sendChat($chatMessage);
|
||||||
@ -231,7 +233,7 @@ class PlayerManager implements CallbackListener {
|
|||||||
public function getPlayerByIndex($index) {
|
public function getPlayerByIndex($index) {
|
||||||
foreach($this->players as $player) {
|
foreach($this->players as $player) {
|
||||||
/** @var Player $player */
|
/** @var Player $player */
|
||||||
if($player->index == $index) {
|
if ($player->index == $index) {
|
||||||
|
|
||||||
return $player;
|
return $player;
|
||||||
}
|
}
|
||||||
@ -247,7 +249,7 @@ class PlayerManager implements CallbackListener {
|
|||||||
* @return \ManiaControl\Players\Player
|
* @return \ManiaControl\Players\Player
|
||||||
*/
|
*/
|
||||||
public function getPlayer($login) {
|
public function getPlayer($login) {
|
||||||
if(!isset($this->players[$login])) {
|
if (!isset($this->players[$login])) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return $this->players[$login];
|
return $this->players[$login];
|
||||||
@ -273,12 +275,12 @@ class PlayerManager implements CallbackListener {
|
|||||||
* @return Player $player
|
* @return Player $player
|
||||||
*/
|
*/
|
||||||
private function removePlayer($login, $savePlayedTime = true) {
|
private function removePlayer($login, $savePlayedTime = true) {
|
||||||
if(!isset($this->players[$login])) {
|
if (!isset($this->players[$login])) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$player = $this->players[$login];
|
$player = $this->players[$login];
|
||||||
unset($this->players[$login]);
|
unset($this->players[$login]);
|
||||||
if($savePlayedTime) {
|
if ($savePlayedTime) {
|
||||||
$this->updatePlayedTime($player);
|
$this->updatePlayedTime($player);
|
||||||
}
|
}
|
||||||
return $player;
|
return $player;
|
||||||
@ -294,13 +296,13 @@ class PlayerManager implements CallbackListener {
|
|||||||
private function getPlayerFromDatabaseByIndex($playerIndex) {
|
private function getPlayerFromDatabaseByIndex($playerIndex) {
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
|
|
||||||
if(!is_numeric($playerIndex)) {
|
if (!is_numeric($playerIndex)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = "SELECT * FROM `" . self::TABLE_PLAYERS . "` WHERE `index` = " . $playerIndex . ";";
|
$query = "SELECT * FROM `" . self::TABLE_PLAYERS . "` WHERE `index` = " . $playerIndex . ";";
|
||||||
$result = $mysqli->query($query);
|
$result = $mysqli->query($query);
|
||||||
if(!$result) {
|
if (!$result) {
|
||||||
trigger_error($mysqli->error);
|
trigger_error($mysqli->error);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -340,13 +342,13 @@ class PlayerManager implements CallbackListener {
|
|||||||
`nickname` = VALUES(`nickname`),
|
`nickname` = VALUES(`nickname`),
|
||||||
`path` = VALUES(`path`);";
|
`path` = VALUES(`path`);";
|
||||||
$playerStatement = $mysqli->prepare($playerQuery);
|
$playerStatement = $mysqli->prepare($playerQuery);
|
||||||
if($mysqli->error) {
|
if ($mysqli->error) {
|
||||||
trigger_error($mysqli->error);
|
trigger_error($mysqli->error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$playerStatement->bind_param('sss', $player->login, $player->nickname, $player->path);
|
$playerStatement->bind_param('sss', $player->login, $player->nickname, $player->path);
|
||||||
$playerStatement->execute();
|
$playerStatement->execute();
|
||||||
if($playerStatement->error) {
|
if ($playerStatement->error) {
|
||||||
trigger_error($playerStatement->error);
|
trigger_error($playerStatement->error);
|
||||||
$playerStatement->close();
|
$playerStatement->close();
|
||||||
return false;
|
return false;
|
||||||
@ -357,13 +359,13 @@ class PlayerManager implements CallbackListener {
|
|||||||
// Get Player Auth Level from DB
|
// Get Player Auth Level from DB
|
||||||
$playerQuery = "SELECT `authLevel` FROM `" . self::TABLE_PLAYERS . "` WHERE `index` = ?;";
|
$playerQuery = "SELECT `authLevel` FROM `" . self::TABLE_PLAYERS . "` WHERE `index` = ?;";
|
||||||
$playerStatement = $mysqli->prepare($playerQuery);
|
$playerStatement = $mysqli->prepare($playerQuery);
|
||||||
if($mysqli->error) {
|
if ($mysqli->error) {
|
||||||
trigger_error($mysqli->error);
|
trigger_error($mysqli->error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$playerStatement->bind_param('i', $player->index);
|
$playerStatement->bind_param('i', $player->index);
|
||||||
$playerStatement->execute();
|
$playerStatement->execute();
|
||||||
if($playerStatement->error) {
|
if ($playerStatement->error) {
|
||||||
trigger_error($playerStatement->error);
|
trigger_error($playerStatement->error);
|
||||||
$playerStatement->close();
|
$playerStatement->close();
|
||||||
return false;
|
return false;
|
||||||
@ -384,7 +386,7 @@ class PlayerManager implements CallbackListener {
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function updatePlayedTime(Player $player) {
|
private function updatePlayedTime(Player $player) {
|
||||||
if(!$player) {
|
if (!$player) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$playedTime = time() - $player->joinTime;
|
$playedTime = time() - $player->joinTime;
|
||||||
|
Loading…
Reference in New Issue
Block a user