This commit is contained in:
kremsy 2014-02-24 20:20:17 +01:00 committed by Steffen Schröder
parent ae53958b37
commit b403ceef31
8 changed files with 59 additions and 34 deletions

View File

@ -144,10 +144,7 @@ class DatabaseConverter { //TODO move bind param before loop everywhere, convert
//Loop through all the players //Loop through all the players
while($row = $result->fetch_object()) { while($row = $result->fetch_object()) {
//Strip links and dirty codes $statement->bind_param('ssss', $row->Uid, $row->Name, $row->Author, $row->Environment);
$name = preg_replace('/(?<!\$)((?:\$\$)*)\$[hlp](?:\[.*?\])?(.*?)(?:\$[hlp]|(\$z)|$)/iu', '$1$2$3', $row->Name);
$name = preg_replace('/(?<!\$)((?:\$\$)*)\$[ow<>]/iu', '$1', $name);
$statement->bind_param('ssss', $row->Uid, $name, $row->Author, $row->Environment);
$statement->execute(); $statement->execute();
if ($statement->error) { if ($statement->error) {
trigger_error($statement->error); trigger_error($statement->error);

View File

@ -16,6 +16,7 @@ class Map {
*/ */
public $index = -1; public $index = -1;
public $name = 'undefined'; public $name = 'undefined';
public $rawName = '';
public $uid = ''; public $uid = '';
public $fileName = ''; public $fileName = '';
public $environment = ''; public $environment = '';
@ -49,6 +50,7 @@ class Map {
return; return;
} }
$this->name = FORMATTER::stripDirtyCodes($mpMap->name); $this->name = FORMATTER::stripDirtyCodes($mpMap->name);
$this->rawName = $mpMap->name;
$this->uid = $mpMap->uId; $this->uid = $mpMap->uId;
$this->fileName = $mpMap->fileName; $this->fileName = $mpMap->fileName;
$this->authorLogin = $mpMap->author; $this->authorLogin = $mpMap->author;

View File

@ -140,7 +140,7 @@ class MapManager implements CallbackListener {
trigger_error($mysqli->error); trigger_error($mysqli->error);
return false; 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(); $mapStatement->execute();
if ($mapStatement->error) { if ($mapStatement->error) {
trigger_error($mapStatement->error); trigger_error($mapStatement->error);

View File

@ -17,6 +17,7 @@ class Player {
public $pid = -1; public $pid = -1;
public $login = ''; public $login = '';
public $nickname = ''; public $nickname = '';
public $rawNickname = '';
public $path = ''; public $path = '';
public $authLevel = 0; public $authLevel = 0;
public $language = ''; public $language = '';
@ -70,6 +71,7 @@ class Player {
$this->pid = $mpPlayer->playerId; $this->pid = $mpPlayer->playerId;
$this->login = $mpPlayer->login; $this->login = $mpPlayer->login;
$this->nickname = Formatter::stripDirtyCodes($mpPlayer->nickName); $this->nickname = Formatter::stripDirtyCodes($mpPlayer->nickName);
$this->rawNickname = $mpPlayer->nickName;
$this->path = $mpPlayer->path; $this->path = $mpPlayer->path;
$this->language = $mpPlayer->language; $this->language = $mpPlayer->language;
$this->avatar = $mpPlayer->avatar['FileName']; $this->avatar = $mpPlayer->avatar['FileName'];

View File

@ -363,7 +363,8 @@ class PlayerManager implements CallbackListener {
$player = new Player(false); $player = new Player(false);
$player->index = $playerIndex; $player->index = $playerIndex;
$player->login = $row->login; $player->login = $row->login;
$player->nickname = $row->nickname; $player->rawNickname = $row->nickname;
$player->nickname = Formatter::stripDirtyCodes($player->rawNickname);
$player->path = $row->path; $player->path = $row->path;
$player->authLevel = $row->authLevel; $player->authLevel = $row->authLevel;
@ -397,7 +398,8 @@ class PlayerManager implements CallbackListener {
$player = new Player(false); $player = new Player(false);
$player->index = $row->index; $player->index = $row->index;
$player->login = $row->login; $player->login = $row->login;
$player->nickname = $row->nickname; $player->rawNickname = $row->nickname;
$player->nickname = Formatter::stripDirtyCodes($player->rawNickname);
$player->path = $row->path; $player->path = $row->path;
$player->authLevel = $row->authLevel; $player->authLevel = $row->authLevel;
@ -429,7 +431,7 @@ class PlayerManager implements CallbackListener {
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->rawNickname, $player->path);
$playerStatement->execute(); $playerStatement->execute();
if ($playerStatement->error) { if ($playerStatement->error) {
trigger_error($playerStatement->error); trigger_error($playerStatement->error);

View File

@ -181,7 +181,7 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
*/ */
public function handlePlayerConnect(Player $player) { public function handlePlayerConnect(Player $player) {
// Send Dedimania request // 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); $content = $this->encode_request(self::DEDIMANIA_PLAYERCONNECT, $data);
$this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) use (&$player) { $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 = array();
$mapInfo['UId'] = $map->uid; $mapInfo['UId'] = $map->uid;
$mapInfo['Name'] = $map->name; $mapInfo['Name'] = $map->rawName;
$mapInfo['Author'] = $map->authorLogin; $mapInfo['Author'] = $map->authorLogin;
$mapInfo['Environment'] = $map->environment; $mapInfo['Environment'] = $map->environment;
$mapInfo['NbCheckpoints'] = $map->nbCheckpoints; $mapInfo['NbCheckpoints'] = $map->nbCheckpoints;

View File

@ -30,10 +30,11 @@ class DedimaniaPlayer {
/** /**
* Construct a new Player by its login and maxRank * Construct a new Player by its login and maxRank
*
* @param $login * @param $login
* @param $maxRank * @param $maxRank
*/ */
public function constructNewPlayer($login, $maxRank){ public function constructNewPlayer($login, $maxRank) {
$this->login = $login; $this->login = $login;
$this->maxRank = $maxRank; $this->maxRank = $maxRank;
} }

View File

@ -41,6 +41,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
*/ */
const SETTING_MX_KARMA_ACTIVATED = 'Aktivate MX-Karma'; 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_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_URL = 'http://karma.mania-exchange.com/api2/';
const MX_KARMA_STARTSESSION = 'startSession'; const MX_KARMA_STARTSESSION = 'startSession';
const MX_KARMA_ACTIVATESESSION = 'activateSession'; const MX_KARMA_ACTIVATESESSION = 'activateSession';
@ -341,6 +342,20 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
if ($mysqli->error) { if ($mysqli->error) {
trigger_error($mysqli->error, E_USER_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); }, "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 * Save Mx Karma Votes at Mapend
*/ */
@ -619,14 +640,14 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$properties['titleid'] = $this->maniaControl->server->titleId; $properties['titleid'] = $this->maniaControl->server->titleId;
$properties['mapname'] = $map->name; $properties['mapname'] = $map->rawName;
$properties['mapuid'] = $map->uid; $properties['mapuid'] = $map->uid;
$properties['mapauthor'] = $map->authorLogin; $properties['mapauthor'] = $map->authorLogin;
$properties['votes'] = array(); $properties['votes'] = array();
foreach($this->mxKarma['votes'] as $login => $value) { foreach($this->mxKarma['votes'] as $login => $value) {
$player = $this->maniaControl->playerManager->getPlayer($login); $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); $content = json_encode($properties);