Removed stats from Player Class
This commit is contained in:
parent
31fdecafa5
commit
6c56938ddd
@ -1,10 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Players;
|
||||
|
||||
use ManiaControl\Formatter;
|
||||
|
||||
/**
|
||||
* Class representing players
|
||||
* Player Model Class
|
||||
*
|
||||
* @author kremsy & steeffeen
|
||||
*/
|
||||
@ -18,8 +19,6 @@ class Player {
|
||||
public $nickname = '';
|
||||
public $path = '';
|
||||
public $authLevel = 0;
|
||||
public $joinCount = 0;
|
||||
public $totalPlayed = 0;
|
||||
public $language = '';
|
||||
public $avatar = '';
|
||||
public $allies = array();
|
||||
@ -32,6 +31,7 @@ class Player {
|
||||
public $ladderRank = -1;
|
||||
public $joinTime = -1;
|
||||
public $ipAddress = '';
|
||||
|
||||
/**
|
||||
* Construct a player from XmlRpc data
|
||||
*
|
||||
@ -59,10 +59,8 @@ class Player {
|
||||
$this->ipAddress = $rpcInfos['IPAddress'];
|
||||
|
||||
$this->joinTime = time();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if player is not a real player
|
||||
*
|
||||
@ -72,7 +70,6 @@ class Player {
|
||||
return ($this->pid <= 0 || $this->path == "");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get province
|
||||
*
|
||||
|
@ -25,24 +25,23 @@ class PlayerManager implements CallbackListener {
|
||||
const CB_PLAYERINFOCHANGED = 'PlayerManagerCallback.PlayerInfoChanged';
|
||||
const TABLE_PLAYERS = 'mc_players';
|
||||
const SETTING_JOIN_LEAVE_MESSAGES = 'Enable Join & Leave Messages';
|
||||
|
||||
const STAT_JOIN_COUNT = 'joinCount';
|
||||
const STAT_PLAYTIME = 'playTime';
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
private $playerCommands = null;
|
||||
private $playerList = array();
|
||||
|
||||
/**
|
||||
* Public properties
|
||||
* Public Properties
|
||||
*/
|
||||
public $playerActions = null;
|
||||
public $playerCommands = null;
|
||||
public $playerList = array();
|
||||
|
||||
/**
|
||||
* Construct player manager
|
||||
* Private Properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
|
||||
/**
|
||||
* Construct a new Player Manager
|
||||
*
|
||||
* @param \ManiaControl\ManiaControl $maniaControl
|
||||
*/
|
||||
@ -59,9 +58,12 @@ class PlayerManager implements CallbackListener {
|
||||
// Register for callbacks
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'onInit');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCONNECT, $this, 'playerConnect');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this, 'playerDisconnect');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERINFOCHANGED, $this, 'playerInfoChanged');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this,
|
||||
'playerDisconnect');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERINFOCHANGED, $this,
|
||||
'playerInfoChanged');
|
||||
|
||||
// Define player stats
|
||||
$this->maniaControl->statisticManager->defineStatMetaData(self::STAT_JOIN_COUNT);
|
||||
$this->maniaControl->statisticManager->defineStatMetaData(self::STAT_PLAYTIME);
|
||||
}
|
||||
@ -79,12 +81,10 @@ class PlayerManager implements CallbackListener {
|
||||
`nickname` varchar(150) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`path` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`authLevel` int(11) NOT NULL DEFAULT '0',
|
||||
`joinCount` int(11) NOT NULL DEFAULT '0',
|
||||
`totalPlayed` int(11) NOT NULL DEFAULT '0' COMMENT 'Seconds',
|
||||
`changed` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`index`),
|
||||
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);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error, E_USER_ERROR);
|
||||
@ -137,12 +137,14 @@ class PlayerManager implements CallbackListener {
|
||||
|
||||
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!';
|
||||
$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}";
|
||||
$logMessage = "Player joined: {$player->login} / " . Formatter::stripCodes($player->nickname) . " Nation: " .
|
||||
$player->getCountry() . " IP: {$player->ipAddress}";
|
||||
$this->maniaControl->log($logMessage);
|
||||
|
||||
// Trigger own PlayerJoined callback
|
||||
@ -166,7 +168,8 @@ class PlayerManager implements CallbackListener {
|
||||
}
|
||||
|
||||
$played = Formatter::formatTimeH(time() - $player->joinTime);
|
||||
$this->maniaControl->log("Player left: " . $player->login . " / " . Formatter::stripCodes($player->nickname) . " Playtime: " . $played);
|
||||
$logMessage = "Player left: {$player->login} / {$player->nickname} Playtime: {$played}";
|
||||
$this->maniaControl->log(Formatter::stripCodes($logMessage));
|
||||
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES)) {
|
||||
$this->maniaControl->chat->sendChat('$<' . $player->nickname . '$> $s$0f0has left the game');
|
||||
@ -180,8 +183,7 @@ class PlayerManager implements CallbackListener {
|
||||
*/
|
||||
public function playerInfoChanged(array $callback) {
|
||||
$player = $this->getPlayer($callback[1][0]['Login']);
|
||||
if($player == null)
|
||||
return;
|
||||
if ($player == null) return;
|
||||
|
||||
$player->teamId = $callback[1][0]["TeamId"];
|
||||
$player->isSpectator = $callback[1][0]["SpectatorStatus"];
|
||||
@ -254,34 +256,26 @@ class PlayerManager implements CallbackListener {
|
||||
* @param int $joinCount
|
||||
* @return bool
|
||||
*/
|
||||
private function savePlayer(Player &$player, $joinCount = 1) {
|
||||
if(!$player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private function savePlayer(Player &$player) {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
|
||||
//TODO delete joincount from the following things
|
||||
// Save player
|
||||
$playerQuery = "INSERT INTO `" . self::TABLE_PLAYERS . "` (
|
||||
`login`,
|
||||
`nickname`,
|
||||
`path`,
|
||||
`joinCount`
|
||||
`path`
|
||||
) VALUES (
|
||||
?, ?, ?, ?
|
||||
?, ?, ?
|
||||
) ON DUPLICATE KEY UPDATE
|
||||
`index` = LAST_INSERT_ID(`index`),
|
||||
`nickname` = VALUES(`nickname`),
|
||||
`path` = VALUES(`path`),
|
||||
`joinCount` = `joinCount` + VALUES(`joinCount`);";
|
||||
`path` = VALUES(`path`);";
|
||||
$playerStatement = $mysqli->prepare($playerQuery);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error);
|
||||
return false;
|
||||
}
|
||||
$playerStatement->bind_param('sssi', $player->login, $player->nickname, $player->path, $joinCount);
|
||||
$playerStatement->bind_param('sss', $player->login, $player->nickname, $player->path);
|
||||
$playerStatement->execute();
|
||||
if ($playerStatement->error) {
|
||||
trigger_error($playerStatement->error);
|
||||
@ -291,9 +285,8 @@ class PlayerManager implements CallbackListener {
|
||||
$player->index = $playerStatement->insert_id;
|
||||
$playerStatement->close();
|
||||
|
||||
// Fill up properties
|
||||
$playerQuery = "SELECT `authLevel`, `joinCount`, `totalPlayed` FROM `" . self::TABLE_PLAYERS . "`
|
||||
WHERE `index` = ?;";
|
||||
// Get Player Auth Level from DB
|
||||
$playerQuery = "SELECT `authLevel` FROM `" . self::TABLE_PLAYERS . "` WHERE `index` = ?;";
|
||||
$playerStatement = $mysqli->prepare($playerQuery);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error);
|
||||
@ -307,17 +300,18 @@ class PlayerManager implements CallbackListener {
|
||||
return false;
|
||||
}
|
||||
$playerStatement->store_result();
|
||||
$playerStatement->bind_result($player->authLevel, $player->joinCount, $player->totalPlayed);
|
||||
$playerStatement->bind_result($player->authLevel);
|
||||
$playerStatement->fetch();
|
||||
$playerStatement->free_result();
|
||||
$playerStatement->close();
|
||||
|
||||
|
||||
// Increment the Player Join Count
|
||||
$success = $this->maniaControl->statisticManager->incrementStat(self::STAT_JOIN_COUNT, $player, $this->maniaControl->server->getLogin());
|
||||
$success = $this->maniaControl->statisticManager->incrementStat(self::STAT_JOIN_COUNT, $player,
|
||||
$this->maniaControl->server->getLogin());
|
||||
|
||||
if(!$success)
|
||||
if (!$success) {
|
||||
trigger_error("Error while setting the JoinCount");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -334,6 +328,7 @@ class PlayerManager implements CallbackListener {
|
||||
}
|
||||
$playedTime = time() - $player->joinTime;
|
||||
|
||||
return $this->maniaControl->statisticManager->insertStat(self::STAT_PLAYTIME, $player, $this->maniaControl->server->getLogin(), $playedTime);
|
||||
return $this->maniaControl->statisticManager->insertStat(self::STAT_PLAYTIME, $player, $this->maniaControl->server->getLogin(),
|
||||
$playedTime);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user