From b403ceef31921fdfe6e45946ca41db1ce488a3d5 Mon Sep 17 00:00:00 2001 From: kremsy Date: Mon, 24 Feb 2014 20:20:17 +0100 Subject: [PATCH] cleanup --- DatabaseConverter.php | 5 +-- application/core/Maps/Map.php | 2 + application/core/Maps/MapManager.php | 2 +- application/core/Players/Player.php | 2 + application/core/Players/PlayerManager.php | 28 ++++++------ application/plugins/Dedimania/Dedimania.php | 4 +- .../plugins/Dedimania/DedimaniaPlayer.php | 7 +-- application/plugins/Karma.php | 43 ++++++++++++++----- 8 files changed, 59 insertions(+), 34 deletions(-) diff --git a/DatabaseConverter.php b/DatabaseConverter.php index 0473aafb..07ee7f9a 100644 --- a/DatabaseConverter.php +++ b/DatabaseConverter.php @@ -144,10 +144,7 @@ class DatabaseConverter { //TODO move bind param before loop everywhere, convert //Loop through all the players while($row = $result->fetch_object()) { - //Strip links and dirty codes - $name = preg_replace('/(?Name); - $name = preg_replace('/(?]/iu', '$1', $name); - $statement->bind_param('ssss', $row->Uid, $name, $row->Author, $row->Environment); + $statement->bind_param('ssss', $row->Uid, $row->Name, $row->Author, $row->Environment); $statement->execute(); if ($statement->error) { trigger_error($statement->error); diff --git a/application/core/Maps/Map.php b/application/core/Maps/Map.php index 8627752c..5682996d 100644 --- a/application/core/Maps/Map.php +++ b/application/core/Maps/Map.php @@ -16,6 +16,7 @@ class Map { */ public $index = -1; public $name = 'undefined'; + public $rawName = ''; public $uid = ''; public $fileName = ''; public $environment = ''; @@ -49,6 +50,7 @@ class Map { return; } $this->name = FORMATTER::stripDirtyCodes($mpMap->name); + $this->rawName = $mpMap->name; $this->uid = $mpMap->uId; $this->fileName = $mpMap->fileName; $this->authorLogin = $mpMap->author; diff --git a/application/core/Maps/MapManager.php b/application/core/Maps/MapManager.php index cdbdb64a..6021a594 100644 --- a/application/core/Maps/MapManager.php +++ b/application/core/Maps/MapManager.php @@ -140,7 +140,7 @@ class MapManager implements CallbackListener { trigger_error($mysqli->error); return false; } - $mapStatement->bind_param('ssssss', $map->uid, $map->name, $map->authorLogin, $map->fileName, $map->environment, $map->mapType); + $mapStatement->bind_param('ssssss', $map->uid, $map->rawName, $map->authorLogin, $map->fileName, $map->environment, $map->mapType); $mapStatement->execute(); if ($mapStatement->error) { trigger_error($mapStatement->error); diff --git a/application/core/Players/Player.php b/application/core/Players/Player.php index 53b01c5d..938f36d4 100644 --- a/application/core/Players/Player.php +++ b/application/core/Players/Player.php @@ -17,6 +17,7 @@ class Player { public $pid = -1; public $login = ''; public $nickname = ''; + public $rawNickname = ''; public $path = ''; public $authLevel = 0; public $language = ''; @@ -70,6 +71,7 @@ class Player { $this->pid = $mpPlayer->playerId; $this->login = $mpPlayer->login; $this->nickname = Formatter::stripDirtyCodes($mpPlayer->nickName); + $this->rawNickname = $mpPlayer->nickName; $this->path = $mpPlayer->path; $this->language = $mpPlayer->language; $this->avatar = $mpPlayer->avatar['FileName']; diff --git a/application/core/Players/PlayerManager.php b/application/core/Players/PlayerManager.php index 63a6593b..ea5ae351 100644 --- a/application/core/Players/PlayerManager.php +++ b/application/core/Players/PlayerManager.php @@ -360,12 +360,13 @@ class PlayerManager implements CallbackListener { return null; } - $player = new Player(false); - $player->index = $playerIndex; - $player->login = $row->login; - $player->nickname = $row->nickname; - $player->path = $row->path; - $player->authLevel = $row->authLevel; + $player = new Player(false); + $player->index = $playerIndex; + $player->login = $row->login; + $player->rawNickname = $row->nickname; + $player->nickname = Formatter::stripDirtyCodes($player->rawNickname); + $player->path = $row->path; + $player->authLevel = $row->authLevel; return $player; } @@ -394,12 +395,13 @@ class PlayerManager implements CallbackListener { return null; } - $player = new Player(false); - $player->index = $row->index; - $player->login = $row->login; - $player->nickname = $row->nickname; - $player->path = $row->path; - $player->authLevel = $row->authLevel; + $player = new Player(false); + $player->index = $row->index; + $player->login = $row->login; + $player->rawNickname = $row->nickname; + $player->nickname = Formatter::stripDirtyCodes($player->rawNickname); + $player->path = $row->path; + $player->authLevel = $row->authLevel; return $player; } @@ -429,7 +431,7 @@ class PlayerManager implements CallbackListener { trigger_error($mysqli->error); return false; } - $playerStatement->bind_param('sss', $player->login, $player->nickname, $player->path); + $playerStatement->bind_param('sss', $player->login, $player->rawNickname, $player->path); $playerStatement->execute(); if ($playerStatement->error) { trigger_error($playerStatement->error); diff --git a/application/plugins/Dedimania/Dedimania.php b/application/plugins/Dedimania/Dedimania.php index d6750299..119ab7cf 100644 --- a/application/plugins/Dedimania/Dedimania.php +++ b/application/plugins/Dedimania/Dedimania.php @@ -181,7 +181,7 @@ class Dedimania implements CallbackListener, TimerListener, Plugin { */ public function handlePlayerConnect(Player $player) { // Send Dedimania request - $data = array($this->dedimaniaData->sessionId, $player->login, $player->nickname, $player->path, $player->isSpectator); + $data = array($this->dedimaniaData->sessionId, $player->login, $player->rawNickname, $player->path, $player->isSpectator); $content = $this->encode_request(self::DEDIMANIA_PLAYERCONNECT, $data); $this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) use (&$player) { @@ -738,7 +738,7 @@ class Dedimania implements CallbackListener, TimerListener, Plugin { } $mapInfo = array(); $mapInfo['UId'] = $map->uid; - $mapInfo['Name'] = $map->name; + $mapInfo['Name'] = $map->rawName; $mapInfo['Author'] = $map->authorLogin; $mapInfo['Environment'] = $map->environment; $mapInfo['NbCheckpoints'] = $map->nbCheckpoints; diff --git a/application/plugins/Dedimania/DedimaniaPlayer.php b/application/plugins/Dedimania/DedimaniaPlayer.php index 9348257d..23ae3566 100644 --- a/application/plugins/Dedimania/DedimaniaPlayer.php +++ b/application/plugins/Dedimania/DedimaniaPlayer.php @@ -25,16 +25,17 @@ class DedimaniaPlayer { $this->maxRank = $player['MaxRank']; $this->banned = $player['Banned']; $this->optionsEnabled = $player['OptionsEnabled']; - $this->options = $player['Options']; + $this->options = $player['Options']; } /** * Construct a new Player by its login and maxRank + * * @param $login * @param $maxRank */ - public function constructNewPlayer($login, $maxRank){ - $this->login = $login; + public function constructNewPlayer($login, $maxRank) { + $this->login = $login; $this->maxRank = $maxRank; } } \ No newline at end of file diff --git a/application/plugins/Karma.php b/application/plugins/Karma.php index 09e1f27a..90a708a0 100644 --- a/application/plugins/Karma.php +++ b/application/plugins/Karma.php @@ -41,6 +41,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { */ const SETTING_MX_KARMA_ACTIVATED = 'Aktivate MX-Karma'; //const MX_KARMA_SETTING_CODE = '$l[http://karma.mania-exchange.com/auth/getapikey?server={serverlogin}]MX Karma Code for '; + const MX_IMPORT_TABLE = 'mc_karma_mximport'; const MX_KARMA_URL = 'http://karma.mania-exchange.com/api2/'; const MX_KARMA_STARTSESSION = 'startSession'; const MX_KARMA_ACTIVATESESSION = 'activateSession'; @@ -341,6 +342,20 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { if ($mysqli->error) { trigger_error($mysqli->error, E_USER_ERROR); } + + if (!$this->maniaControl->settingManager->getSetting($this, self::SETTING_MX_KARMA_ACTIVATED)) { + return; + } + + $query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_KARMA . "` ( + `index` int(11) NOT NULL AUTO_INCREMENT, + `mapIndex` int(11) NOT NULL, + `playerIndex` int(11) NOT NULL, + `vote` float NOT NULL DEFAULT '-1', + `changed` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`index`), + UNIQUE KEY `player_map_vote` (`mapIndex`, `playerIndex`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Save players map votes' AUTO_INCREMENT=1;"; } /** @@ -590,6 +605,12 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { }, "application/json", 1000); } + public function importVotes(Map $map) { + if (!$this->maniaControl->settingManager->getSetting($this, self::SETTING_MX_KARMA_ACTIVATED)) { + return; + } + } + /** * Save Mx Karma Votes at Mapend */ @@ -619,29 +640,29 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { $properties['titleid'] = $this->maniaControl->server->titleId; - $properties['mapname'] = $map->name; + $properties['mapname'] = $map->rawName; $properties['mapuid'] = $map->uid; $properties['mapauthor'] = $map->authorLogin; $properties['votes'] = array(); foreach($this->mxKarma['votes'] as $login => $value) { $player = $this->maniaControl->playerManager->getPlayer($login); - array_push($properties['votes'], array("login" => $login, "nickname" => $player->nickname, "vote" => $value)); + array_push($properties['votes'], array("login" => $login, "nickname" => $player->rawNickname, "vote" => $value)); } $content = json_encode($properties); $this->maniaControl->fileReader->postData(self::MX_KARMA_URL . self::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($data, $error) { - if (!$error) { - $data = json_decode($data); - if ($data->success) { - $this->maniaControl->log("Votes successfully permitted"); - } else { - $this->maniaControl->log("Error while updating votes"); - } + if (!$error) { + $data = json_decode($data); + if ($data->success) { + $this->maniaControl->log("Votes successfully permitted"); } else { - $this->maniaControl->log($error); + $this->maniaControl->log("Error while updating votes"); } - }, $content, false, 'application/json'); + } else { + $this->maniaControl->log($error); + } + }, $content, false, 'application/json'); } /**