From fedc58c0774644d6b2ba8e9f5e29baad66bacbde Mon Sep 17 00:00:00 2001 From: kremsy Date: Fri, 3 Jan 2014 18:37:51 +0100 Subject: [PATCH] some changes, but endless loop timeout --- application/core/Players/PlayerDetailed.php | 23 ++++++++++- application/core/Players/PlayerManager.php | 4 +- .../core/Statistics/StatisticCollector.php | 18 ++++----- .../core/Statistics/StatisticManager.php | 40 ++++++++++++------- application/plugins/Donations.php | 2 +- 5 files changed, 60 insertions(+), 27 deletions(-) diff --git a/application/core/Players/PlayerDetailed.php b/application/core/Players/PlayerDetailed.php index fbe1cc79..ff881778 100644 --- a/application/core/Players/PlayerDetailed.php +++ b/application/core/Players/PlayerDetailed.php @@ -218,8 +218,29 @@ class PlayerDetailed { $mainLabel->setHAlign(Control::LEFT); $mainLabel->setText("Statistics");*/ - var_dump($this->maniaControl->statisticManager->getAllPlayerStats($player)); + $playerStats = $this->maniaControl->statisticManager->getAllPlayerStats($player); + $y = $this->height / 2 - 15; + foreach($playerStats as $stat){ + $statProperties = $stat[0]; + $value = $stat[1]; + + $label = new Label_Text(); + $frame->add($label); + $label->setPosition(-$this->width / 2 + 70, $y); + $label->setText($statProperties->name); + $label->setHAlign(Control::LEFT); + $label->setTextSize(1.5); + + $label = new Label_Text(); + $frame->add($label); + $label->setPosition(-$this->width / 2 + 100, $y); + $label->setText($value); + $label->setHAlign(Control::LEFT); + $label->setTextSize(1.5); + + $y -= 4; + } return $frame; } } \ No newline at end of file diff --git a/application/core/Players/PlayerManager.php b/application/core/Players/PlayerManager.php index 0b4c0287..10bc3458 100644 --- a/application/core/Players/PlayerManager.php +++ b/application/core/Players/PlayerManager.php @@ -26,8 +26,8 @@ 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'; + const STAT_JOIN_COUNT = 'Joins'; + const STAT_PLAYTIME = 'Playtime'; /** * Public Properties diff --git a/application/core/Statistics/StatisticCollector.php b/application/core/Statistics/StatisticCollector.php index 93c684c5..395f97ac 100644 --- a/application/core/Statistics/StatisticCollector.php +++ b/application/core/Statistics/StatisticCollector.php @@ -22,14 +22,14 @@ class StatisticCollector implements CallbackListener { /* * Statistics */ - const STAT_ON_SHOOT = 'onShoot'; - const STAT_ON_NEARMISS = 'onNearMiss'; - const STAT_ON_CAPTURE = 'onCapture'; - const STAT_ON_HIT = 'onHit'; - const STAT_ON_GOT_HIT = 'onGotHit'; - const STAT_ON_DEATH = 'onDeath'; - const STAT_ON_PLAYER_REQUEST_RESPAWN = 'onPlayerRequestRespawn'; - const STAT_ON_KILL = 'onKill'; + const STAT_ON_SHOOT = 'Shoots'; + const STAT_ON_NEARMISS = 'Near Misses'; + const STAT_ON_CAPTURE = 'Captures'; + const STAT_ON_HIT = 'Hits'; + const STAT_ON_GOT_HIT = 'Got Hits'; + const STAT_ON_DEATH = 'Deaths'; + const STAT_ON_PLAYER_REQUEST_RESPAWN = 'Respawns'; + const STAT_ON_KILL = 'Kills'; /** * Private Properties */ @@ -52,7 +52,7 @@ class StatisticCollector implements CallbackListener { //Initialize Settings $this->maniaControl->settingManager->initSetting($this, self::SETTING_COLLECT_STATS_ENABLED, true); - $this->maniaControl->settingManager->initSetting($this, self::SETTING_COLLECT_STATS_MINPLAYERS, 3); + $this->maniaControl->settingManager->initSetting($this, self::SETTING_COLLECT_STATS_MINPLAYERS, 1); //TODO TEMP on 1, normally 3 or 4 $this->maniaControl->settingManager->initSetting($this, self::SETTING_ON_SHOOT_PRESTORE, 30); } diff --git a/application/core/Statistics/StatisticManager.php b/application/core/Statistics/StatisticManager.php index aafb273f..1b74523c 100644 --- a/application/core/Statistics/StatisticManager.php +++ b/application/core/Statistics/StatisticManager.php @@ -58,6 +58,7 @@ class StatisticManager { * @return int */ public function getStatisticData($statName, $playerId, $serverLogin = false) { + $serverId = 0; //Temporary $mysqli = $this->maniaControl->database->mysqli; $statId = $this->getStatId($statName); @@ -68,7 +69,7 @@ class StatisticManager { if(!$serverLogin) { $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` = '" . $serverLogin . "';"; + $query = "SELECT value FROM `" . self::TABLE_STATISTICS . "` WHERE `statId` = " . $statId . " AND `playerId` = " . $playerId . " AND `serverLogin` = '" . $serverId . "';"; } $result = $mysqli->query($query); @@ -116,16 +117,23 @@ class StatisticManager { } } - public function getAllPlayerStats(Player $player){ - $playerStats = array(); //TODO improve performant - foreach($this->stats as $stat){ -// $value = $this->getStatisticData($stat['name'], $player->index); - // var_dump($value); - //$playerStats[$stat] = $value; + + /** + * Get all statistics of a certain palyer + * + * @param Player $player + * @return array + */ + public function getAllPlayerStats(Player $player) { + $playerStats = array(); //TODO improve performence + foreach($this->stats as $stat) { + $value = $this->getStatisticData($stat->name, $player->index); + $playerStats[$stat->name] = array($stat, $value); } return $playerStats; } + /** * Inserts a Stat into the database * @@ -137,6 +145,7 @@ class StatisticManager { * @return bool */ public function insertStat($statName, $player, $serverLogin = '', $value, $statType = self::STAT_TYPE_INT) { + $serverId = 0; //Temporary $statId = $this->getStatId($statName); if($player == null) { @@ -159,7 +168,7 @@ class StatisticManager { $mysqli = $this->maniaControl->database->mysqli; $query = "INSERT INTO `" . self::TABLE_STATISTICS . "` ( - `serverLogin`, + `serverId`, `playerId`, `statId`, `value` @@ -173,7 +182,7 @@ class StatisticManager { trigger_error($mysqli->error); return false; } - $statement->bind_param('siii', $serverLogin, $player->index, $statId, $value); + $statement->bind_param('iiii', $serverId, $player->index, $statId, $value); $statement->execute(); if($statement->error) { trigger_error($statement->error); @@ -203,22 +212,24 @@ class StatisticManager { * * @param string $statName * @param string $statDescription + * @param string $type * @return bool */ - public function defineStatMetaData($statName, $statDescription = '') { + public function defineStatMetaData($statName, $statDescription = '', $type = self::STAT_TYPE_INT) { $mysqli = $this->maniaControl->database->mysqli; $query = "INSERT IGNORE INTO `" . self::TABLE_STATMETADATA . "` ( `name`, + `type`, `description` ) VALUES ( - ?, ? + ?, ?, ? );"; $statement = $mysqli->prepare($query); if($mysqli->error) { trigger_error($mysqli->error); return false; } - $statement->bind_param('ss', $statName, $statDescription); + $statement->bind_param('sss', $statName, $type, $statDescription); $statement->execute(); if($statement->error) { trigger_error($statement->error); @@ -242,6 +253,7 @@ class StatisticManager { $query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_STATMETADATA . "` ( `index` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) COLLATE utf8_unicode_ci NOT NULL, + `type` varchar(100) COLLATE utf8_unicode_ci NOT NULL, `description` varchar(150) COLLATE utf8_unicode_ci, PRIMARY KEY (`index`), UNIQUE KEY `name` (`name`) @@ -263,12 +275,12 @@ class StatisticManager { $query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_STATISTICS . "` ( `index` int(11) NOT NULL AUTO_INCREMENT, - `serverLogin` varchar(50) NOT NULL, + `serverId` int(11) NOT NULL, `playerId` int(11) NOT NULL, `statId` int(11) NOT NULL, `value` int(20) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`index`), - UNIQUE KEY `unique` (`statId`,`playerId`,`serverLogin`) + UNIQUE KEY `unique` (`statId`,`playerId`,`serverId`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Statistics' AUTO_INCREMENT=1;"; $statement = $mysqli->prepare($query); diff --git a/application/plugins/Donations.php b/application/plugins/Donations.php index 83eb3639..d6282bbd 100644 --- a/application/plugins/Donations.php +++ b/application/plugins/Donations.php @@ -25,7 +25,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin { const ID = 3; const VERSION = 0.1; const SETTING_ANNOUNCE_SERVERDONATION = 'Enable Server-Donation Announcements'; - const STAT_PLAYER_DONATIONS = 'donatedPlanets'; + const STAT_PLAYER_DONATIONS = 'Donated Planets'; // DonateWidget Properties const MLID_DONATE_WIDGET = 'DonationPlugin.DonateWidget';