reformat code in plugins
This commit is contained in:
@ -81,18 +81,13 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
*/
|
||||
public static function prepare(ManiaControl $maniaControl) {
|
||||
$thisClass = get_class();
|
||||
$maniaControl->getSettingManager()
|
||||
->initSetting($thisClass, self::SETTING_MX_KARMA_ACTIVATED, true);
|
||||
$maniaControl->getSettingManager()
|
||||
->initSetting($thisClass, self::SETTING_MX_KARMA_IMPORTING, true);
|
||||
$maniaControl->getSettingManager()
|
||||
->initSetting($thisClass, self::SETTING_WIDGET_DISPLAY_MX, true);
|
||||
$servers = $maniaControl->getServer()
|
||||
->getAllServers();
|
||||
$maniaControl->getSettingManager()->initSetting($thisClass, self::SETTING_MX_KARMA_ACTIVATED, true);
|
||||
$maniaControl->getSettingManager()->initSetting($thisClass, self::SETTING_MX_KARMA_IMPORTING, true);
|
||||
$maniaControl->getSettingManager()->initSetting($thisClass, self::SETTING_WIDGET_DISPLAY_MX, true);
|
||||
$servers = $maniaControl->getServer()->getAllServers();
|
||||
foreach ($servers as $server) {
|
||||
$settingName = self::buildKarmaSettingName($server->login);
|
||||
$maniaControl->getSettingManager()
|
||||
->initSetting($thisClass, $settingName, '');
|
||||
$maniaControl->getSettingManager()->initSetting($thisClass, $settingName, '');
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,47 +146,29 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
$this->initTables();
|
||||
|
||||
// Settings
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_AVAILABLE_VOTES, '-2,2');
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_WIDGET_ENABLE, true);
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_WIDGET_TITLE, 'Map-Karma');
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_WIDGET_POSX, 160 - 27.5);
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_WIDGET_POSY, 90 - 10 - 6);
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_WIDGET_WIDTH, 25.);
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_WIDGET_HEIGHT, 12.);
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_NEWKARMA, true);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_AVAILABLE_VOTES, '-2,2');
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_ENABLE, true);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_TITLE, 'Map-Karma');
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_POSX, 160 - 27.5);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_POSY, 90 - 10 - 6);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_WIDTH, 25.);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_HEIGHT, 12.);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NEWKARMA, true);
|
||||
|
||||
// Callbacks
|
||||
$this->maniaControl->getTimerManager()
|
||||
->registerTimerListening($this, 'handle1Second', 1000);
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleBeginMap');
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->registerCallbackListener(Callbacks::BEGINMAP, $this, 'importMxKarmaVotes');
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->registerCallbackListener(Callbacks::ENDMAP, $this, 'sendMxKarmaVotes');
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'handlePlayerChat');
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'updateSettings');
|
||||
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'handle1Second', 1000);
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleBeginMap');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::BEGINMAP, $this, 'importMxKarmaVotes');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ENDMAP, $this, 'sendMxKarmaVotes');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'handlePlayerChat');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'updateSettings');
|
||||
|
||||
// Define player stats
|
||||
$this->maniaControl->getStatisticManager()
|
||||
->defineStatMetaData(self::STAT_PLAYER_MAPVOTES);
|
||||
$this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_PLAYER_MAPVOTES);
|
||||
|
||||
// Register Stat in Simple StatsList
|
||||
$this->maniaControl->getStatisticManager()
|
||||
->getSimpleStatsList()
|
||||
->registerStat(self::STAT_PLAYER_MAPVOTES, 100, "VM");
|
||||
$this->maniaControl->getStatisticManager()->getSimpleStatsList()->registerStat(self::STAT_PLAYER_MAPVOTES, 100, "VM");
|
||||
|
||||
$this->updateManialink = true;
|
||||
|
||||
@ -202,14 +179,11 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
//Check if Karma Code got specified, and inform admin that it would be good to specify one
|
||||
$serverLogin = $this->maniaControl->getServer()->login;
|
||||
$karmaSettingName = self::buildKarmaSettingName($serverLogin);
|
||||
$mxKarmaCode = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, $karmaSettingName);
|
||||
$mxKarmaCode = $this->maniaControl->getSettingManager()->getSettingValue($this, $karmaSettingName);
|
||||
|
||||
if (!$mxKarmaCode) {
|
||||
$permission = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this->maniaControl->getAuthenticationManager(), PluginMenu::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS);
|
||||
$this->maniaControl->getChat()
|
||||
->sendErrorToAdmins("Please specify a Mania-Exchange Karma Key in the Karma-Plugin settings!", $permission);
|
||||
$permission = $this->maniaControl->getSettingManager()->getSettingValue($this->maniaControl->getAuthenticationManager(), PluginMenu::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS);
|
||||
$this->maniaControl->getChat()->sendErrorToAdmins("Please specify a Mania-Exchange Karma Key in the Karma-Plugin settings!", $permission);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -219,8 +193,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
* Create necessary database tables
|
||||
*/
|
||||
private function initTables() {
|
||||
$mysqli = $this->maniaControl->getDatabase()
|
||||
->getMysqli();
|
||||
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
||||
|
||||
// Create local table
|
||||
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_KARMA . "` (
|
||||
@ -256,16 +229,14 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
* Open a Mx Karma Session
|
||||
*/
|
||||
private function mxKarmaOpenSession() {
|
||||
if (!$this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED)
|
||||
if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$serverLogin = $this->maniaControl->getServer()->login;
|
||||
$karmaSettingName = self::buildKarmaSettingName($serverLogin);
|
||||
$mxKarmaCode = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, $karmaSettingName);
|
||||
$mxKarmaCode = $this->maniaControl->getSettingManager()->getSettingValue($this, $karmaSettingName);
|
||||
|
||||
if (!$mxKarmaCode) {
|
||||
return;
|
||||
@ -281,31 +252,27 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
|
||||
$this->mxKarma['connectionInProgress'] = true;
|
||||
|
||||
$this->maniaControl->getFileReader()
|
||||
->loadFile($query, function ($json, $error) use ($mxKarmaCode) {
|
||||
$this->mxKarma['connectionInProgress'] = false;
|
||||
if ($error) {
|
||||
$this->maniaControl->getErrorHandler()
|
||||
->triggerDebugNotice('mx karma error: ' . $error);
|
||||
return;
|
||||
}
|
||||
$data = json_decode($json);
|
||||
if (!$data) {
|
||||
$this->maniaControl->getErrorHandler()
|
||||
->triggerDebugNotice('auth error', $json, $data);
|
||||
return;
|
||||
}
|
||||
if ($data->success) {
|
||||
$this->mxKarma['session'] = $data->data;
|
||||
$this->activateSession($mxKarmaCode);
|
||||
} else {
|
||||
Logger::logError("Error while authenticating on Mania-Exchange Karma");
|
||||
// TODO remove temp trigger
|
||||
$this->maniaControl->getErrorHandler()
|
||||
->triggerDebugNotice('auth error', $data->data->message);
|
||||
$this->mxKarma['connectionInProgress'] = false;
|
||||
}
|
||||
}, AsynchronousFileReader::CONTENT_TYPE_JSON, 1000);
|
||||
$this->maniaControl->getFileReader()->loadFile($query, function ($json, $error) use ($mxKarmaCode) {
|
||||
$this->mxKarma['connectionInProgress'] = false;
|
||||
if ($error) {
|
||||
$this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error: ' . $error);
|
||||
return;
|
||||
}
|
||||
$data = json_decode($json);
|
||||
if (!$data) {
|
||||
$this->maniaControl->getErrorHandler()->triggerDebugNotice('auth error', $json, $data);
|
||||
return;
|
||||
}
|
||||
if ($data->success) {
|
||||
$this->mxKarma['session'] = $data->data;
|
||||
$this->activateSession($mxKarmaCode);
|
||||
} else {
|
||||
Logger::logError("Error while authenticating on Mania-Exchange Karma");
|
||||
// TODO remove temp trigger
|
||||
$this->maniaControl->getErrorHandler()->triggerDebugNotice('auth error', $data->data->message);
|
||||
$this->mxKarma['connectionInProgress'] = false;
|
||||
}
|
||||
}, AsynchronousFileReader::CONTENT_TYPE_JSON, 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -320,39 +287,33 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
$query .= '?sessionKey=' . urlencode($this->mxKarma['session']->sessionKey);
|
||||
$query .= '&activationHash=' . urlencode($hash);
|
||||
|
||||
$this->maniaControl->getFileReader()
|
||||
->loadFile($query, function ($json, $error) use ($query) {
|
||||
$this->mxKarma['connectionInProgress'] = false;
|
||||
if ($error) {
|
||||
$this->maniaControl->getErrorHandler()
|
||||
->triggerDebugNotice('mx karma error', $error);
|
||||
return;
|
||||
}
|
||||
$data = json_decode($json);
|
||||
if (!$data) {
|
||||
$this->maniaControl->getErrorHandler()
|
||||
->triggerDebugNotice('parse error', $json, $data);
|
||||
return;
|
||||
}
|
||||
if ($data->success && $data->data->activated) {
|
||||
Logger::log('Successfully authenticated on Mania-Exchange Karma');
|
||||
$this->maniaControl->getFileReader()->loadFile($query, function ($json, $error) use ($query) {
|
||||
$this->mxKarma['connectionInProgress'] = false;
|
||||
if ($error) {
|
||||
$this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error);
|
||||
return;
|
||||
}
|
||||
$data = json_decode($json);
|
||||
if (!$data) {
|
||||
$this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data);
|
||||
return;
|
||||
}
|
||||
if ($data->success && $data->data->activated) {
|
||||
Logger::log('Successfully authenticated on Mania-Exchange Karma');
|
||||
|
||||
// Fetch the Mx Karma Votes
|
||||
$this->getMxKarmaVotes();
|
||||
} else {
|
||||
if ($data->data->message === 'invalid hash') {
|
||||
$permission = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this->maniaControl->getAuthenticationManager(), PluginMenu::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS);
|
||||
$this->maniaControl->getChat()
|
||||
->sendErrorToAdmins("Invalid Mania-Exchange Karma code in Karma Plugin specified!", $permission);
|
||||
} else {
|
||||
$this->maniaControl->getErrorHandler()
|
||||
->triggerDebugNotice('auth error', $data->data->message, $query);
|
||||
}
|
||||
Logger::logError("Error while activating Mania-Exchange Karma Session: " . $data->data->message);
|
||||
unset($this->mxKarma['session']);
|
||||
}
|
||||
}, AsynchronousFileReader::CONTENT_TYPE_JSON, 1000);
|
||||
// Fetch the Mx Karma Votes
|
||||
$this->getMxKarmaVotes();
|
||||
} else {
|
||||
if ($data->data->message === 'invalid hash') {
|
||||
$permission = $this->maniaControl->getSettingManager()->getSettingValue($this->maniaControl->getAuthenticationManager(), PluginMenu::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS);
|
||||
$this->maniaControl->getChat()->sendErrorToAdmins("Invalid Mania-Exchange Karma code in Karma Plugin specified!", $permission);
|
||||
} else {
|
||||
$this->maniaControl->getErrorHandler()->triggerDebugNotice('auth error', $data->data->message, $query);
|
||||
}
|
||||
Logger::logError("Error while activating Mania-Exchange Karma Session: " . $data->data->message);
|
||||
unset($this->mxKarma['session']);
|
||||
}
|
||||
}, AsynchronousFileReader::CONTENT_TYPE_JSON, 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -370,8 +331,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
* Fetch the mxKarmaVotes for the current map
|
||||
*/
|
||||
public function getMxKarmaVotes(Player $player = null) {
|
||||
if (!$this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED)
|
||||
if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
@ -383,16 +343,13 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
return;
|
||||
}
|
||||
|
||||
$map = $this->maniaControl->getMapManager()
|
||||
->getCurrentMap();
|
||||
$map = $this->maniaControl->getMapManager()->getCurrentMap();
|
||||
|
||||
$properties = array();
|
||||
|
||||
$gameMode = $this->maniaControl->getServer()
|
||||
->getGameMode(true);
|
||||
$gameMode = $this->maniaControl->getServer()->getGameMode(true);
|
||||
if ($gameMode === 'Script') {
|
||||
$scriptName = $this->maniaControl->getClient()
|
||||
->getScriptName();
|
||||
$scriptName = $this->maniaControl->getClient()->getScriptName();
|
||||
$properties['gamemode'] = $scriptName['CurrentValue'];
|
||||
} else {
|
||||
$properties['gamemode'] = $gameMode;
|
||||
@ -404,8 +361,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
if (!$player) {
|
||||
$properties['getvotesonly'] = false;
|
||||
$properties['playerlogins'] = array();
|
||||
foreach ($this->maniaControl->getPlayerManager()
|
||||
->getPlayers() as $loopPlayer) {
|
||||
foreach ($this->maniaControl->getPlayerManager()->getPlayers() as $loopPlayer) {
|
||||
$properties['playerlogins'][] = $loopPlayer->login;
|
||||
}
|
||||
} else {
|
||||
@ -414,60 +370,54 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
}
|
||||
|
||||
$content = json_encode($properties);
|
||||
$this->maniaControl->getFileReader()
|
||||
->postData(self::MX_KARMA_URL . self::MX_KARMA_GET_MAP_RATING . '?sessionKey=' . urlencode($this->mxKarma['session']->sessionKey), function ($json,
|
||||
$error) use
|
||||
(
|
||||
&$player
|
||||
) {
|
||||
if ($error) {
|
||||
$this->maniaControl->getErrorHandler()
|
||||
->triggerDebugNotice('mx karma error', $error);
|
||||
return;
|
||||
}
|
||||
$data = json_decode($json);
|
||||
if (!$data) {
|
||||
$this->maniaControl->getErrorHandler()
|
||||
->triggerDebugNotice('parse error', $json, $data);
|
||||
return;
|
||||
}
|
||||
$this->maniaControl->getFileReader()->postData(self::MX_KARMA_URL . self::MX_KARMA_GET_MAP_RATING . '?sessionKey=' . urlencode($this->mxKarma['session']->sessionKey), function ($json,
|
||||
$error) use
|
||||
(
|
||||
&$player
|
||||
) {
|
||||
if ($error) {
|
||||
$this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error);
|
||||
return;
|
||||
}
|
||||
$data = json_decode($json);
|
||||
if (!$data) {
|
||||
$this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($data->success) {
|
||||
// Fetch averages if it's for the whole server
|
||||
if (!$player) {
|
||||
$this->mxKarma['voteCount'] = $data->data->votecount;
|
||||
$this->mxKarma['voteAverage'] = $data->data->voteaverage;
|
||||
$this->mxKarma['modeVoteCount'] = $data->data->modevotecount;
|
||||
$this->mxKarma['modeVoteAverage'] = $data->data->modevoteaverage;
|
||||
}
|
||||
if ($data->success) {
|
||||
// Fetch averages if it's for the whole server
|
||||
if (!$player) {
|
||||
$this->mxKarma['voteCount'] = $data->data->votecount;
|
||||
$this->mxKarma['voteAverage'] = $data->data->voteaverage;
|
||||
$this->mxKarma['modeVoteCount'] = $data->data->modevotecount;
|
||||
$this->mxKarma['modeVoteAverage'] = $data->data->modevoteaverage;
|
||||
}
|
||||
|
||||
foreach ($data->data->votes as $votes) {
|
||||
$this->mxKarma['votes'][$votes->login] = $votes->vote;
|
||||
}
|
||||
foreach ($data->data->votes as $votes) {
|
||||
$this->mxKarma['votes'][$votes->login] = $votes->vote;
|
||||
}
|
||||
|
||||
$this->updateManialink = true;
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->triggerCallback(self::CB_KARMA_MXUPDATED, $this->mxKarma);
|
||||
Logger::logInfo('MX-Karma Votes successfully fetched!');
|
||||
} else {
|
||||
// Problem occurred
|
||||
Logger::logError('Error while fetching votes: ' . $data->data->message);
|
||||
if ($data->data->message === 'invalid session') {
|
||||
unset($this->mxKarma['session']);
|
||||
} else {
|
||||
$this->maniaControl->getErrorHandler()
|
||||
->triggerDebugNotice('fetch error', $data->data->message, self::MX_KARMA_GET_MAP_RATING, $this->mxKarma['session']);
|
||||
}
|
||||
}
|
||||
}, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON);
|
||||
$this->updateManialink = true;
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_KARMA_MXUPDATED, $this->mxKarma);
|
||||
Logger::logInfo('MX-Karma Votes successfully fetched!');
|
||||
} else {
|
||||
// Problem occurred
|
||||
Logger::logError('Error while fetching votes: ' . $data->data->message);
|
||||
if ($data->data->message === 'invalid session') {
|
||||
unset($this->mxKarma['session']);
|
||||
} else {
|
||||
$this->maniaControl->getErrorHandler()->triggerDebugNotice('fetch error', $data->data->message, self::MX_KARMA_GET_MAP_RATING, $this->mxKarma['session']);
|
||||
}
|
||||
}
|
||||
}, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Plugins\Plugin::unload()
|
||||
*/
|
||||
public function unload() {
|
||||
$this->maniaControl->getManialinkManager()
|
||||
->hideManialink(self::MLID_KARMA);
|
||||
$this->maniaControl->getManialinkManager()->hideManialink(self::MLID_KARMA);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -478,8 +428,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
if (isset($this->mxKarma['map'])) {
|
||||
$votes = array();
|
||||
foreach ($this->mxKarma['votes'] as $login => $value) {
|
||||
$player = $this->maniaControl->getPlayerManager()
|
||||
->getPlayer($login);
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
||||
array_push($votes, array('login' => $login, 'nickname' => $player->rawNickname, 'vote' => $value));
|
||||
}
|
||||
$this->postKarmaVotes($this->mxKarma['map'], $votes);
|
||||
@ -509,8 +458,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
return;
|
||||
}
|
||||
|
||||
$gameMode = $this->maniaControl->getServer()
|
||||
->getGameMode(true);
|
||||
$gameMode = $this->maniaControl->getServer()->getGameMode(true);
|
||||
|
||||
if (empty($votes)) {
|
||||
return;
|
||||
@ -518,8 +466,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
|
||||
$properties = array();
|
||||
if ($gameMode === 'Script') {
|
||||
$scriptName = $this->maniaControl->getClient()
|
||||
->getScriptName();
|
||||
$scriptName = $this->maniaControl->getClient()->getScriptName();
|
||||
$properties['gamemode'] = $scriptName['CurrentValue'];
|
||||
} else {
|
||||
$properties['gamemode'] = $gameMode;
|
||||
@ -540,33 +487,29 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
|
||||
$content = json_encode($properties);
|
||||
|
||||
$this->maniaControl->getFileReader()
|
||||
->postData(self::MX_KARMA_URL . self::MX_KARMA_SAVE_VOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($json,
|
||||
$error) {
|
||||
if ($error) {
|
||||
$this->maniaControl->getErrorHandler()
|
||||
->triggerDebugNotice('mx karma error', $error);
|
||||
return;
|
||||
}
|
||||
$data = json_decode($json);
|
||||
if (!$data) {
|
||||
$this->maniaControl->getErrorHandler()
|
||||
->triggerDebugNotice('parse error', $json, $data);
|
||||
return;
|
||||
}
|
||||
if ($data->success) {
|
||||
Logger::logInfo('Votes successfully submitted!');
|
||||
} else {
|
||||
// Problem occurred
|
||||
Logger::logError("Error while updating votes: '{$data->data->message}'");
|
||||
if ($data->data->message === "invalid session") {
|
||||
unset($this->mxKarma['session']);
|
||||
} else {
|
||||
$this->maniaControl->getErrorHandler()
|
||||
->triggerDebugNotice('saving error', $data->data->message, self::MX_KARMA_SAVE_VOTES, $this->mxKarma['session']);
|
||||
}
|
||||
}
|
||||
}, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON);
|
||||
$this->maniaControl->getFileReader()->postData(self::MX_KARMA_URL . self::MX_KARMA_SAVE_VOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($json,
|
||||
$error) {
|
||||
if ($error) {
|
||||
$this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error);
|
||||
return;
|
||||
}
|
||||
$data = json_decode($json);
|
||||
if (!$data) {
|
||||
$this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data);
|
||||
return;
|
||||
}
|
||||
if ($data->success) {
|
||||
Logger::logInfo('Votes successfully submitted!');
|
||||
} else {
|
||||
// Problem occurred
|
||||
Logger::logError("Error while updating votes: '{$data->data->message}'");
|
||||
if ($data->data->message === "invalid session") {
|
||||
unset($this->mxKarma['session']);
|
||||
} else {
|
||||
$this->maniaControl->getErrorHandler()->triggerDebugNotice('saving error', $data->data->message, self::MX_KARMA_SAVE_VOTES, $this->mxKarma['session']);
|
||||
}
|
||||
}
|
||||
}, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -606,8 +549,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
*/
|
||||
public function handlePlayerChat(array $chatCallback) {
|
||||
$login = $chatCallback[1][1];
|
||||
$player = $this->maniaControl->getPlayerManager()
|
||||
->getPlayer($login);
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
||||
if (!$player) {
|
||||
return;
|
||||
}
|
||||
@ -626,12 +568,10 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
$vote = $countPositive - $countNegative;
|
||||
$success = $this->handleVote($player, $vote);
|
||||
if (!$success) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendError('Error occurred.', $player->login);
|
||||
$this->maniaControl->getChat()->sendError('Error occurred.', $player->login);
|
||||
return;
|
||||
}
|
||||
$this->maniaControl->getChat()
|
||||
->sendSuccess('Vote updated!', $player->login);
|
||||
$this->maniaControl->getChat()->sendSuccess('Vote updated!', $player->login);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -643,8 +583,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
*/
|
||||
private function handleVote(Player $player, $vote) {
|
||||
// Check vote
|
||||
$votesSetting = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_AVAILABLE_VOTES);
|
||||
$votesSetting = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_AVAILABLE_VOTES);
|
||||
$votes = explode(',', $votesSetting);
|
||||
$voteLow = intval($votes[0]);
|
||||
$voteHigh = $voteLow + 2;
|
||||
@ -661,12 +600,10 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
$vote /= $voteHigh;
|
||||
|
||||
// Save vote
|
||||
$map = $this->maniaControl->getMapManager()
|
||||
->getCurrentMap();
|
||||
$map = $this->maniaControl->getMapManager()->getCurrentMap();
|
||||
|
||||
// Update vote in MX karma array
|
||||
if ($this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED)
|
||||
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED)
|
||||
&& isset($this->mxKarma['session'])
|
||||
) {
|
||||
if (!isset($this->mxKarma['votes'][$player->login])) {
|
||||
@ -701,16 +638,14 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
|
||||
$voted = $this->getPlayerVote($player, $map);
|
||||
if (!$voted) {
|
||||
$this->maniaControl->getStatisticManager()
|
||||
->incrementStat(self::STAT_PLAYER_MAPVOTES, $player, $this->maniaControl->getServer()->index);
|
||||
$this->maniaControl->getStatisticManager()->incrementStat(self::STAT_PLAYER_MAPVOTES, $player, $this->maniaControl->getServer()->index);
|
||||
}
|
||||
|
||||
$success = $this->savePlayerVote($player, $map, $vote);
|
||||
if (!$success) {
|
||||
return false;
|
||||
}
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->triggerCallback(self::CB_KARMA_CHANGED);
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_KARMA_CHANGED);
|
||||
$this->updateManialink = true;
|
||||
return true;
|
||||
}
|
||||
@ -723,8 +658,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
* @return int
|
||||
*/
|
||||
public function getPlayerVote(Player $player, Map $map) {
|
||||
$mysqli = $this->maniaControl->getDatabase()
|
||||
->getMysqli();
|
||||
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
||||
$query = "SELECT * FROM `" . self::TABLE_KARMA . "`
|
||||
WHERE `playerIndex` = {$player->index}
|
||||
AND `mapIndex` = {$map->index}
|
||||
@ -753,8 +687,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
* @return bool
|
||||
*/
|
||||
private function savePlayerVote(Player $player, Map $map, $vote) {
|
||||
$mysqli = $this->maniaControl->getDatabase()
|
||||
->getMysqli();
|
||||
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
||||
$query = "INSERT INTO `" . self::TABLE_KARMA . "` (
|
||||
`mapIndex`,
|
||||
`playerIndex`,
|
||||
@ -781,8 +714,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
* @return array
|
||||
*/
|
||||
public function getMapPlayerVotes(Map $map) {
|
||||
$mysqli = $this->maniaControl->getDatabase()
|
||||
->getMysqli();
|
||||
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
||||
$query = "SELECT * FROM `" . self::TABLE_KARMA . "`
|
||||
WHERE `mapIndex` = {$map->index}
|
||||
AND `vote` >= 0;";
|
||||
@ -794,8 +726,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
|
||||
$votes = array();
|
||||
while ($vote = $result->fetch_object()) {
|
||||
$player = $this->maniaControl->getPlayerManager()
|
||||
->getPlayerByIndex($vote->playerIndex);
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayerByIndex($vote->playerIndex);
|
||||
$karma = $vote->vote;
|
||||
$voteArray = array('player' => $player, 'karma' => $karma);
|
||||
array_push($votes, $voteArray);
|
||||
@ -835,8 +766,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
$this->handle1Second(time());
|
||||
} else {
|
||||
$this->updateManialink = false;
|
||||
$this->maniaControl->getManialinkManager()
|
||||
->hideManialink(self::MLID_KARMA);
|
||||
$this->maniaControl->getManialinkManager()->hideManialink(self::MLID_KARMA);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -851,20 +781,17 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
return;
|
||||
}
|
||||
|
||||
$displayMxKarma = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_WIDGET_DISPLAY_MX);
|
||||
$displayMxKarma = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_DISPLAY_MX);
|
||||
|
||||
// Get players
|
||||
$players = $this->updateManialink;
|
||||
if ($players === true) {
|
||||
$players = $this->maniaControl->getPlayerManager()
|
||||
->getPlayers();
|
||||
$players = $this->maniaControl->getPlayerManager()->getPlayers();
|
||||
}
|
||||
$this->updateManialink = false;
|
||||
|
||||
// Get map karma
|
||||
$map = $this->maniaControl->getMapManager()
|
||||
->getCurrentMap();
|
||||
$map = $this->maniaControl->getMapManager()->getCurrentMap();
|
||||
|
||||
// Display the mx Karma if the setting is chosen and the MX session is available
|
||||
if ($displayMxKarma && isset($this->mxKarma['session']) && isset($this->mxKarma['voteCount'])) {
|
||||
@ -876,8 +803,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
$voteCount = $votes['count'];
|
||||
}
|
||||
|
||||
if ($this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_WIDGET_ENABLE)
|
||||
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_ENABLE)
|
||||
) {
|
||||
// Build karma manialink
|
||||
$this->buildManialink();
|
||||
@ -912,8 +838,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
// $votesFrame->removeChildren();
|
||||
|
||||
// Send manialink
|
||||
$this->maniaControl->getManialinkManager()
|
||||
->sendManialink($this->manialink, $login);
|
||||
$this->maniaControl->getManialinkManager()->sendManialink($this->manialink, $login);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -925,8 +850,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
* @return float | bool
|
||||
*/
|
||||
public function getMapKarma(Map $map) {
|
||||
$mysqli = $this->maniaControl->getDatabase()
|
||||
->getMysqli();
|
||||
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
||||
$query = "SELECT AVG(`vote`) AS `karma` FROM `" . self::TABLE_KARMA . "`
|
||||
WHERE `mapIndex` = {$map->index}
|
||||
AND `vote` >= 0;";
|
||||
@ -955,8 +879,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
* @return array
|
||||
*/
|
||||
public function getMapVotes(Map $map) {
|
||||
$mysqli = $this->maniaControl->getDatabase()
|
||||
->getMysqli();
|
||||
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
||||
$query = "SELECT `vote`, COUNT(`vote`) AS `count` FROM `" . self::TABLE_KARMA . "`
|
||||
WHERE `mapIndex` = {$map->index}
|
||||
AND `vote` >= 0
|
||||
@ -987,25 +910,14 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
return;
|
||||
}
|
||||
|
||||
$title = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_WIDGET_TITLE);
|
||||
$posX = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_WIDGET_POSX);
|
||||
$posY = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_WIDGET_POSY);
|
||||
$width = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_WIDGET_WIDTH);
|
||||
$height = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_WIDGET_HEIGHT);
|
||||
$labelStyle = $this->maniaControl->getManialinkManager()
|
||||
->getStyleManager()
|
||||
->getDefaultLabelStyle();
|
||||
$quadStyle = $this->maniaControl->getManialinkManager()
|
||||
->getStyleManager()
|
||||
->getDefaultQuadStyle();
|
||||
$quadSubstyle = $this->maniaControl->getManialinkManager()
|
||||
->getStyleManager()
|
||||
->getDefaultQuadSubstyle();
|
||||
$title = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_TITLE);
|
||||
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_POSX);
|
||||
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_POSY);
|
||||
$width = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_WIDTH);
|
||||
$height = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_HEIGHT);
|
||||
$labelStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultLabelStyle();
|
||||
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
|
||||
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
|
||||
|
||||
$manialink = new ManiaLink(self::MLID_KARMA);
|
||||
|
||||
@ -1056,14 +968,12 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
* @param Map $map
|
||||
*/
|
||||
public function importMxKarmaVotes(Map $map) {
|
||||
if (!$this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED)
|
||||
if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_MX_KARMA_IMPORTING)
|
||||
if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_IMPORTING)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
@ -1075,8 +985,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
return;
|
||||
}
|
||||
|
||||
$mysqli = $this->maniaControl->getDatabase()
|
||||
->getMysqli();
|
||||
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
||||
$query = "SELECT `mapImported` FROM `" . self::MX_IMPORT_TABLE . "`
|
||||
WHERE `mapIndex` = {$map->index};";
|
||||
$result = $mysqli->query($query);
|
||||
@ -1130,8 +1039,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
* Save Mx Karma Votes at MapEnd
|
||||
*/
|
||||
public function sendMxKarmaVotes(Map $map) {
|
||||
if (!$this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED)
|
||||
if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user