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
while($row = $result->fetch_object()) {
//Strip links and dirty codes
$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->bind_param('ssss', $row->Uid, $row->Name, $row->Author, $row->Environment);
$statement->execute();
if ($statement->error) {
trigger_error($statement->error);

View File

@ -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;

View File

@ -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);

View File

@ -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'];

View File

@ -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);

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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');
}
/**