diff --git a/application/core/Players/PlayerManager.php b/application/core/Players/PlayerManager.php index ea9ce1e9..0137aa1c 100644 --- a/application/core/Players/PlayerManager.php +++ b/application/core/Players/PlayerManager.php @@ -255,7 +255,7 @@ class PlayerManager implements CallbackListener { * Save player in database and fill up object properties * * @param Player $player - * @param int $joinCount + * @internal param int $joinCount * @return bool */ private function savePlayer(Player &$player) { @@ -308,7 +308,7 @@ class PlayerManager implements CallbackListener { $playerStatement->close(); // Increment the Player Join Count - $this->maniaControl->statisticManager->incrementStat(self::STAT_JOIN_COUNT, $player, $this->maniaControl->server->getLogin()); + $this->maniaControl->statisticManager->incrementStat(self::STAT_JOIN_COUNT, $player, $this->maniaControl->server->getServerId()); return true; } @@ -325,6 +325,6 @@ 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->getServerId(), $playedTime); } } diff --git a/application/core/Server/Server.php b/application/core/Server/Server.php index 03e25be3..1c22b4f2 100644 --- a/application/core/Server/Server.php +++ b/application/core/Server/Server.php @@ -51,8 +51,6 @@ class Server implements CallbackListener { $this->serverCommands = new ServerCommands($maniaControl); $this->initTables(); - - //$this->initServer(); } /** @@ -398,4 +396,11 @@ class Server implements CallbackListener { } return true; } + + /** + * @return int + */ + public function getServerId() { + return $this->serverId; + } } diff --git a/application/core/Statistics/StatisticCollector.php b/application/core/Statistics/StatisticCollector.php index a6cea06e..f8993b88 100644 --- a/application/core/Statistics/StatisticCollector.php +++ b/application/core/Statistics/StatisticCollector.php @@ -90,9 +90,9 @@ class StatisticCollector implements CallbackListener { //Write Shoot Data into database if($this->onShootArray[$login] > $this->maniaControl->settingManager->getSetting($this, self::SETTING_ON_SHOOT_PRESTORE)) { - $serverLogin = $this->maniaControl->server->getLogin(); + $serverId = $this->maniaControl->server->getServerId(); $player = $this->maniaControl->playerManager->getPlayer($login); - $this->maniaControl->statisticManager->insertStat(self::STAT_ON_SHOOT, $player, $serverLogin, $this->onShootArray[$login]); + $this->maniaControl->statisticManager->insertStat(self::STAT_ON_SHOOT, $player, $serverId, $this->onShootArray[$login]); $this->onShootArray[$login] = 0; } } @@ -114,8 +114,8 @@ class StatisticCollector implements CallbackListener { //Insert Data into Database, and destroy player if(isset($this->onShootArray[$player->login])) { if($this->onShootArray[$player->login] > 0) { - $serverLogin = $this->maniaControl->server->getLogin(); - $this->maniaControl->statisticManager->insertStat(self::STAT_ON_SHOOT, $player, $serverLogin, $this->onShootArray[$player->login]); + $serverId = $this->maniaControl->server->getServerId(); + $this->maniaControl->statisticManager->insertStat(self::STAT_ON_SHOOT, $player, $serverId, $this->onShootArray[$player->login]); } unset($this->onShootArray[$player->login]); } diff --git a/application/core/Statistics/StatisticManager.php b/application/core/Statistics/StatisticManager.php index 759720cd..f3977b4a 100644 --- a/application/core/Statistics/StatisticManager.php +++ b/application/core/Statistics/StatisticManager.php @@ -55,19 +55,18 @@ class StatisticManager { * * @param $statName * @param $playerId - * @param bool $serverLogin + * @param int $serverId * @return int */ - public function getStatisticData($statName, $playerId, $serverLogin = false) { - $serverId = 0; //Temporary - $mysqli = $this->maniaControl->database->mysqli; - $statId = $this->getStatId($statName); + public function getStatisticData($statName, $playerId, $serverId = -1) { + $mysqli = $this->maniaControl->database->mysqli; + $statId = $this->getStatId($statName); if($statId == null) { return -1; } - if(!$serverLogin) { + if($serverId == -1) { $query = "SELECT SUM(value) as value FROM `" . self::TABLE_STATISTICS . "` WHERE `statId` = " . $statId . " AND `playerId` = " . $playerId . ";"; } else { $query = "SELECT value FROM `" . self::TABLE_STATISTICS . "` WHERE `statId` = " . $statId . " AND `playerId` = " . $playerId . " AND `serverLogin` = '" . $serverId . "';"; @@ -123,12 +122,13 @@ class StatisticManager { * Get all statistics of a certain palyer * * @param Player $player + * @param int $serverId * @return array */ - public function getAllPlayerStats(Player $player) { + public function getAllPlayerStats(Player $player, $serverId = -1) { $playerStats = array(); //TODO improve performence foreach($this->stats as $stat) { - $value = $this->getStatisticData($stat->name, $player->index); + $value = $this->getStatisticData($stat->name, $player->index, $serverId); $playerStats[$stat->name] = array($stat, $value); } @@ -140,14 +140,14 @@ class StatisticManager { * * @param $statName * @param Player $player - * @param string $serverLogin + * @param int $serverId * @param $value , value to Add * @param string $statType + * @internal param string $serverLogin * @return bool */ - public function insertStat($statName, $player, $serverLogin = '', $value, $statType = self::STAT_TYPE_INT) { - $serverId = 0; //Temporary - $statId = $this->getStatId($statName); + public function insertStat($statName, $player, $serverId = -1, $value, $statType = self::STAT_TYPE_INT) { + $statId = $this->getStatId($statName); if($player == null) { return false; @@ -161,8 +161,8 @@ class StatisticManager { return true; } - if($serverLogin == '') { - $serverLogin = $this->maniaControl->server->getLogin(); + if($serverId == -1) { + $serverId = $this->maniaControl->server->getServerId(); } @@ -201,12 +201,13 @@ class StatisticManager { * * @param $statName * @param \ManiaControl\Players\Player $player - * @param string $serverLogin + * @param int $serverId + * @internal param string $serverLogin * @internal param \ManiaControl\Players\Player $playerId * @return bool */ - public function incrementStat($statName, $player, $serverLogin = '') { - return $this->insertStat($statName, $player, $serverLogin, 1); + public function incrementStat($statName, $player, $serverId = -1) { + return $this->insertStat($statName, $player, $serverId, 1); } diff --git a/application/plugins/Donations.php b/application/plugins/Donations.php index d6282bbd..06a18a72 100644 --- a/application/plugins/Donations.php +++ b/application/plugins/Donations.php @@ -325,7 +325,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin { $message = 'Donation successful! Thanks.'; } $this->maniaControl->chat->sendSuccess($message, $login); - $this->maniaControl->statisticManager->insertStat(self::STAT_PLAYER_DONATIONS, $player, $this->maniaControl->server->getLogin(), $amount); + $this->maniaControl->statisticManager->insertStat(self::STAT_PLAYER_DONATIONS, $player, $this->maniaControl->server->getServerId(), $amount); } } else { // Payout diff --git a/application/plugins/Karma.php b/application/plugins/Karma.php index 9d69e639..5568daa5 100644 --- a/application/plugins/Karma.php +++ b/application/plugins/Karma.php @@ -272,8 +272,7 @@ class KarmaPlugin implements CallbackListener, Plugin { $voted = $this->getPlayerVote($player, $map); var_dump($voted); if(!$voted){ - var_dump("test"); - $this->maniaControl->statisticManager->incrementStat(self::STAT_PLAYER_MAPVOTES, $player, $this->maniaControl->server->getLogin()); + $this->maniaControl->statisticManager->incrementStat(self::STAT_PLAYER_MAPVOTES, $player, $this->maniaControl->server->getServerId()); } $success = $this->savePlayerVote($player, $map, $vote);