|
|
|
@@ -43,7 +43,6 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
const SETTING_WIDGET_POSY = 'Widget-Position: Y';
|
|
|
|
|
const SETTING_WIDGET_WIDTH = 'Widget-Size: Width';
|
|
|
|
|
const SETTING_WIDGET_HEIGHT = 'Widget-Size: Height';
|
|
|
|
|
|
|
|
|
|
const STAT_PLAYER_MAPVOTES = 'Voted Maps';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@@ -63,13 +62,15 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
* Private properties
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @var maniaControl $maniaControl
|
|
|
|
|
*/
|
|
|
|
|
private $maniaControl = null;
|
|
|
|
|
private $updateManialink = false;
|
|
|
|
|
/** @var ManiaLink $manialink */
|
|
|
|
|
/**
|
|
|
|
|
* @var ManiaLink $manialink
|
|
|
|
|
*/
|
|
|
|
|
private $manialink = null;
|
|
|
|
|
|
|
|
|
|
private $mxKarma = array();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@@ -89,6 +90,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::load()
|
|
|
|
|
*/
|
|
|
|
|
public function load(ManiaControl $maniaControl) {
|
|
|
|
@@ -130,6 +132,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::unload()
|
|
|
|
|
*/
|
|
|
|
|
public function unload() {
|
|
|
|
@@ -141,6 +144,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::getId()
|
|
|
|
|
*/
|
|
|
|
|
public static function getId() {
|
|
|
|
@@ -148,6 +152,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::getName()
|
|
|
|
|
*/
|
|
|
|
|
public static function getName() {
|
|
|
|
@@ -155,6 +160,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::getVersion()
|
|
|
|
|
*/
|
|
|
|
|
public static function getVersion() {
|
|
|
|
@@ -162,6 +168,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::getAuthor()
|
|
|
|
|
*/
|
|
|
|
|
public static function getAuthor() {
|
|
|
|
@@ -169,6 +176,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::getDescription()
|
|
|
|
|
*/
|
|
|
|
|
public static function getDescription() {
|
|
|
|
@@ -201,7 +209,8 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
if ($displayMxKarma && isset($this->mxKarma['session']) && isset($this->mxKarma['voteCount'])) {
|
|
|
|
|
$karma = $this->mxKarma['modeVoteAverage'] / 100;
|
|
|
|
|
$voteCount = $this->mxKarma['modeVoteCount'];
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$karma = $this->getMapKarma($map);
|
|
|
|
|
$votes = $this->getMapVotes($map);
|
|
|
|
|
$voteCount = $votes['count'];
|
|
|
|
@@ -212,9 +221,13 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
$this->buildManialink();
|
|
|
|
|
|
|
|
|
|
// Update karma gauge & label
|
|
|
|
|
/** @var Gauge $karmaGauge */
|
|
|
|
|
/**
|
|
|
|
|
* @var Gauge $karmaGauge
|
|
|
|
|
*/
|
|
|
|
|
$karmaGauge = $this->manialink->karmaGauge;
|
|
|
|
|
/** @var Label $karmaLabel */
|
|
|
|
|
/**
|
|
|
|
|
* @var Label $karmaLabel
|
|
|
|
|
*/
|
|
|
|
|
$karmaLabel = $this->manialink->karmaLabel;
|
|
|
|
|
if (is_numeric($karma) && $voteCount > 0) {
|
|
|
|
|
$karma = floatval($karma);
|
|
|
|
@@ -222,7 +235,8 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
$karmaColor = ColorUtil::floatToStatusColor($karma);
|
|
|
|
|
$karmaGauge->setColor($karmaColor . '7');
|
|
|
|
|
$karmaLabel->setText(' ' . round($karma * 100.) . '% (' . $voteCount . ')');
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$karmaGauge->setRatio(0.);
|
|
|
|
|
$karmaGauge->setColor('00fb');
|
|
|
|
|
$karmaLabel->setText('-');
|
|
|
|
@@ -350,7 +364,8 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
|
|
|
|
|
$modeSum = $this->mxKarma["modeVoteCount"] * $this->mxKarma["modeVoteAverage"] + $vote * 100;
|
|
|
|
|
$this->mxKarma["modeVoteCount"]++;
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$oldVote = $this->mxKarma["votes"][$player->login];
|
|
|
|
|
$sum = $this->mxKarma["voteCount"] * $this->mxKarma["voteAverage"] - $oldVote + $vote * 100;
|
|
|
|
|
$modeSum = $this->mxKarma["modeVoteCount"] * $this->mxKarma["modeVoteAverage"] - $oldVote + $vote * 100;
|
|
|
|
@@ -361,7 +376,6 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
$this->mxKarma["votes"][$player->login] = $vote * 100;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$voted = $this->getPlayerVote($player, $map);
|
|
|
|
|
if (!$voted) {
|
|
|
|
|
$this->maniaControl->statisticManager->incrementStat(self::STAT_PLAYER_MAPVOTES, $player, $this->maniaControl->server->index);
|
|
|
|
@@ -396,6 +410,8 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
*/
|
|
|
|
|
private function initTables() {
|
|
|
|
|
$mysqli = $this->maniaControl->database->mysqli;
|
|
|
|
|
|
|
|
|
|
// Create local table
|
|
|
|
|
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_KARMA . "` (
|
|
|
|
|
`index` int(11) NOT NULL AUTO_INCREMENT,
|
|
|
|
|
`mapIndex` int(11) NOT NULL,
|
|
|
|
@@ -410,10 +426,14 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
trigger_error($mysqli->error, E_USER_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Migrate settings
|
|
|
|
|
$this->maniaControl->database->migrationHelper->transferSettings('ManiaControl\Chat', $this);
|
|
|
|
|
|
|
|
|
|
if (!$this->maniaControl->settingManager->getSetting($this, self::SETTING_MX_KARMA_ACTIVATED)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create mx table
|
|
|
|
|
$query = "CREATE TABLE IF NOT EXISTS `" . self::MX_IMPORT_TABLE . "` (
|
|
|
|
|
`index` int(11) NOT NULL AUTO_INCREMENT,
|
|
|
|
|
`mapIndex` int(11) NOT NULL,
|
|
|
|
@@ -604,7 +624,6 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
$this->manialink = $manialink;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update Settings
|
|
|
|
|
*
|
|
|
|
@@ -625,7 +644,8 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
if ($settingName == 'Enable Karma Widget' && $value == true) {
|
|
|
|
|
$this->updateManialink = true;
|
|
|
|
|
$this->handle1Second(time());
|
|
|
|
|
} elseif ($settingName == 'Enable Karma Widget' && $value == false) {
|
|
|
|
|
}
|
|
|
|
|
elseif ($settingName == 'Enable Karma Widget' && $value == false) {
|
|
|
|
|
$this->updateManialink = false;
|
|
|
|
|
$ml = new ManiaLink(self::MLID_KARMA);
|
|
|
|
|
$mltext = $ml->render()->saveXML();
|
|
|
|
@@ -665,13 +685,15 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
if ($data->success) {
|
|
|
|
|
$self->mxKarma['session'] = $data->data;
|
|
|
|
|
$self->activateSession($mxKarmaCode);
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$self->maniaControl->log("Error while authenticating on Mania-Exchange Karma");
|
|
|
|
|
// TODO remove temp trigger
|
|
|
|
|
$self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message);
|
|
|
|
|
$self->mxKarma['connectionInProgress'] = false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$self->maniaControl->log($error);
|
|
|
|
|
// TODO remove temp trigger
|
|
|
|
|
$self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $error);
|
|
|
|
@@ -702,13 +724,15 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
|
|
|
|
|
// Fetch the Mx Karma Votes
|
|
|
|
|
$self->getMxKarmaVotes();
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$self->maniaControl->log("Error while authenticating on Mania-Exchange Karma " . $data->data->message);
|
|
|
|
|
// TODO remove temp trigger
|
|
|
|
|
$self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message . " url Query " . $query);
|
|
|
|
|
$self->mxKarma['connectionInProgress'] = false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// TODO remove temp trigger
|
|
|
|
|
$self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $error);
|
|
|
|
|
$self->maniaControl->log($error);
|
|
|
|
@@ -717,7 +741,6 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
}, "application/json", 1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetch the mxKarmaVotes for the current map
|
|
|
|
|
*/
|
|
|
|
@@ -741,7 +764,8 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
if ($gameMode == 'Script') {
|
|
|
|
|
$scriptName = $this->maniaControl->client->getScriptName();
|
|
|
|
|
$properties['gamemode'] = $scriptName["CurrentValue"];
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$properties['gamemode'] = $gameMode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -752,10 +776,13 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
$properties['getvotesonly'] = false;
|
|
|
|
|
$properties['playerlogins'] = array();
|
|
|
|
|
foreach ($this->maniaControl->playerManager->getPlayers() as $plyr) {
|
|
|
|
|
/** @var Player $player */
|
|
|
|
|
/**
|
|
|
|
|
* @var Player $player
|
|
|
|
|
*/
|
|
|
|
|
$properties['playerlogins'][] = $plyr->login;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$properties['getvotesonly'] = true;
|
|
|
|
|
$properties['playerlogins'] = array($player->login);
|
|
|
|
|
}
|
|
|
|
@@ -782,12 +809,14 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
$self->updateManialink = true;
|
|
|
|
|
$self->maniaControl->callbackManager->triggerCallback($self::CB_KARMA_MXUPDATED, $self->mxKarma);
|
|
|
|
|
$self->maniaControl->log("MX-Karma Votes successfully fetched");
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$self->maniaControl->log("Error while fetching votes: " . $data->data->message);
|
|
|
|
|
// TODO remove temp trigger
|
|
|
|
|
$self->maniaControl->errorHandler->triggerDebugNotice("Error while fetching votes: " . $data->data->message . " " . KarmaPlugin::MX_KARMA_URL . KarmaPlugin::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($self->mxKarma['session']->sessionKey));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$self->maniaControl->log($error);
|
|
|
|
|
}
|
|
|
|
|
}, $content, false, 'application/json');
|
|
|
|
@@ -899,13 +928,15 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
if ($gameMode == 'Script') {
|
|
|
|
|
$scriptName = $this->maniaControl->client->getScriptName();
|
|
|
|
|
$properties['gamemode'] = $scriptName["CurrentValue"];
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$properties['gamemode'] = $gameMode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($import) {
|
|
|
|
|
$properties['maptime'] = 0;
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$properties['maptime'] = time() - $this->mxKarma['startTime'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -924,12 +955,14 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
|
|
|
|
$data = json_decode($data);
|
|
|
|
|
if ($data->success) {
|
|
|
|
|
$self->maniaControl->log("Votes successfully permitted");
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$self->maniaControl->log("Error while updating votes: " . $data->data->message);
|
|
|
|
|
// TODO remove temp trigger
|
|
|
|
|
$self->maniaControl->errorHandler->triggerDebugNotice("Error while updating votes: " . $data->data->message . " " . KarmaPlugin::MX_KARMA_URL . $self::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($self->mxKarma['session']->sessionKey));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$self->maniaControl->log($error);
|
|
|
|
|
}
|
|
|
|
|
}, $content, false, 'application/json');
|
|
|
|
|