improvements
This commit is contained in:
parent
176b9eef6d
commit
7b6ff4dcb8
@ -308,11 +308,7 @@ class PlayerManager implements CallbackListener {
|
|||||||
$playerStatement->close();
|
$playerStatement->close();
|
||||||
|
|
||||||
// Increment the Player Join Count
|
// Increment the Player Join Count
|
||||||
$success = $this->maniaControl->statisticManager->incrementStat(self::STAT_JOIN_COUNT, $player, $this->maniaControl->server->getLogin());
|
$this->maniaControl->statisticManager->incrementStat(self::STAT_JOIN_COUNT, $player, $this->maniaControl->server->getLogin());
|
||||||
|
|
||||||
if(!$success) {
|
|
||||||
trigger_error("Error while setting the JoinCount");
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -183,6 +183,7 @@ class StatisticManager {
|
|||||||
trigger_error($mysqli->error);
|
trigger_error($mysqli->error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$statement->bind_param('iiii', $serverId, $player->index, $statId, $value);
|
$statement->bind_param('iiii', $serverId, $player->index, $statId, $value);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
if($statement->error) {
|
if($statement->error) {
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
use ManiaControl\ColorUtil;
|
use FML\Controls\Frame;
|
||||||
use ManiaControl\ManiaControl;
|
use FML\Controls\Gauge;
|
||||||
|
use FML\Controls\Label;
|
||||||
|
use FML\Controls\Quad;
|
||||||
|
use FML\ManiaLink;
|
||||||
use ManiaControl\Callbacks\CallbackListener;
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
use ManiaControl\Callbacks\CallbackManager;
|
use ManiaControl\Callbacks\CallbackManager;
|
||||||
|
use ManiaControl\ColorUtil;
|
||||||
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Maps\Map;
|
use ManiaControl\Maps\Map;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
use ManiaControl\Plugins\Plugin;
|
use ManiaControl\Plugins\Plugin;
|
||||||
use FML\ManiaLink;
|
|
||||||
use FML\Controls\Frame;
|
|
||||||
use FML\Controls\Label;
|
|
||||||
use FML\Controls\Quad;
|
|
||||||
use FML\Controls\Gauge;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ManiaControl Karma Plugin
|
* ManiaControl Karma Plugin
|
||||||
@ -21,17 +21,19 @@ class KarmaPlugin implements CallbackListener, Plugin {
|
|||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const ID = 5;
|
const ID = 5;
|
||||||
const VERSION = 0.1;
|
const VERSION = 0.1;
|
||||||
const MLID_KARMA = 'KarmaPlugin.MLID';
|
const MLID_KARMA = 'KarmaPlugin.MLID';
|
||||||
const TABLE_KARMA = 'mc_karma';
|
const TABLE_KARMA = 'mc_karma';
|
||||||
const SETTING_AVAILABLE_VOTES = 'Available Votes (X-Y: Comma separated)';
|
const SETTING_AVAILABLE_VOTES = 'Available Votes (X-Y: Comma separated)';
|
||||||
const SETTING_WIDGET_TITLE = 'Widget-Title';
|
const SETTING_WIDGET_TITLE = 'Widget-Title';
|
||||||
const SETTING_WIDGET_POSX = 'Widget-Position: X';
|
const SETTING_WIDGET_POSX = 'Widget-Position: X';
|
||||||
const SETTING_WIDGET_POSY = 'Widget-Position: Y';
|
const SETTING_WIDGET_POSY = 'Widget-Position: Y';
|
||||||
const SETTING_WIDGET_WIDTH = 'Widget-Size: Width';
|
const SETTING_WIDGET_WIDTH = 'Widget-Size: Width';
|
||||||
const SETTING_WIDGET_HEIGHT = 'Widget-Size: Height';
|
const SETTING_WIDGET_HEIGHT = 'Widget-Size: Height';
|
||||||
|
|
||||||
|
const STAT_PLAYER_MAPVOTES = 'Voted Maps';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private properties
|
* Private properties
|
||||||
*/
|
*/
|
||||||
@ -49,10 +51,10 @@ class KarmaPlugin implements CallbackListener, Plugin {
|
|||||||
*/
|
*/
|
||||||
public function load(ManiaControl $maniaControl) {
|
public function load(ManiaControl $maniaControl) {
|
||||||
$this->maniaControl = $maniaControl;
|
$this->maniaControl = $maniaControl;
|
||||||
|
|
||||||
// Init database
|
// Init database
|
||||||
$this->initTables();
|
$this->initTables();
|
||||||
|
|
||||||
// Init settings
|
// Init settings
|
||||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_AVAILABLE_VOTES, '-2,2');
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_AVAILABLE_VOTES, '-2,2');
|
||||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_TITLE, 'Map-Karma');
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_TITLE, 'Map-Karma');
|
||||||
@ -60,15 +62,17 @@ class KarmaPlugin implements CallbackListener, Plugin {
|
|||||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_POSY, 90 - 10 - 6);
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_POSY, 90 - 10 - 6);
|
||||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_WIDTH, 25.);
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_WIDTH, 25.);
|
||||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_HEIGHT, 12.);
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_HEIGHT, 12.);
|
||||||
|
|
||||||
// Register for callbacks
|
// Register for callbacks
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit');
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit');
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_BEGINMAP, $this, 'handleBeginMap');
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_BEGINMAP, $this, 'handleBeginMap');
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_1_SECOND, $this, 'handle1Second');
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_1_SECOND, $this, 'handle1Second');
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCONNECT, $this,
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCONNECT, $this, 'handlePlayerConnect');
|
||||||
'handlePlayerConnect');
|
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'handlePlayerChat');
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'handlePlayerChat');
|
||||||
|
|
||||||
|
// Define player stats
|
||||||
|
$this->maniaControl->statisticManager->defineStatMetaData(self::STAT_PLAYER_MAPVOTES);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,49 +131,50 @@ class KarmaPlugin implements CallbackListener, Plugin {
|
|||||||
* @param array $callback
|
* @param array $callback
|
||||||
*/
|
*/
|
||||||
public function handle1Second(array $callback) {
|
public function handle1Second(array $callback) {
|
||||||
if (!$this->updateManialink) return;
|
if(!$this->updateManialink) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Get players
|
// Get players
|
||||||
$players = $this->updateManialink;
|
$players = $this->updateManialink;
|
||||||
if ($players === true) {
|
if($players === true) {
|
||||||
$players = $this->maniaControl->playerManager->getPlayers();
|
$players = $this->maniaControl->playerManager->getPlayers();
|
||||||
}
|
}
|
||||||
$this->updateManialink = false;
|
$this->updateManialink = false;
|
||||||
|
|
||||||
// Get map karma
|
// Get map karma
|
||||||
$map = $this->maniaControl->mapManager->getCurrentMap();
|
$map = $this->maniaControl->mapManager->getCurrentMap();
|
||||||
$karma = $this->getMapKarma($map);
|
$karma = $this->getMapKarma($map);
|
||||||
$votes = $this->getMapVotes($map);
|
$votes = $this->getMapVotes($map);
|
||||||
|
|
||||||
// Build karma manialink
|
// Build karma manialink
|
||||||
$this->buildManialink();
|
$this->buildManialink();
|
||||||
|
|
||||||
// Update karma gauge & label
|
// Update karma gauge & label
|
||||||
$karmaGauge = $this->manialink->karmaGauge;
|
$karmaGauge = $this->manialink->karmaGauge;
|
||||||
$karmaLabel = $this->manialink->karmaLabel;
|
$karmaLabel = $this->manialink->karmaLabel;
|
||||||
if (is_numeric($karma)) {
|
if(is_numeric($karma)) {
|
||||||
$karma = floatval($karma);
|
$karma = floatval($karma);
|
||||||
$karmaGauge->setRatio($karma + 0.15 - $karma * 0.15);
|
$karmaGauge->setRatio($karma + 0.15 - $karma * 0.15);
|
||||||
$karmaColor = ColorUtil::floatToStatusColor($karma);
|
$karmaColor = ColorUtil::floatToStatusColor($karma);
|
||||||
$karmaGauge->setColor($karmaColor . '9');
|
$karmaGauge->setColor($karmaColor . '9');
|
||||||
$karmaLabel->setText(' ' . round($karma * 100.) . '% (' . $votes['count'] . ')');
|
$karmaLabel->setText(' ' . round($karma * 100.) . '% (' . $votes['count'] . ')');
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$karma = 0.;
|
$karma = 0.;
|
||||||
$karmaGauge->setRatio(0.);
|
$karmaGauge->setRatio(0.);
|
||||||
$karmaGauge->setColor('00fb');
|
$karmaGauge->setColor('00fb');
|
||||||
$karmaLabel->setText('-');
|
$karmaLabel->setText('-');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop players
|
// Loop players
|
||||||
foreach ($players as $login => $player) {
|
foreach($players as $login => $player) {
|
||||||
// Get player vote
|
// Get player vote
|
||||||
$vote = $this->getPlayerVote($player, $map);
|
$vote = $this->getPlayerVote($player, $map);
|
||||||
|
|
||||||
// Adjust manialink for player's vote
|
// Adjust manialink for player's vote
|
||||||
$votesFrame = $this->manialink->votesFrame;
|
$votesFrame = $this->manialink->votesFrame;
|
||||||
$votesFrame->removeChildren();
|
$votesFrame->removeChildren();
|
||||||
|
|
||||||
// Send manialink
|
// Send manialink
|
||||||
$manialinkText = $this->manialink->render()->saveXML();
|
$manialinkText = $this->manialink->render()->saveXML();
|
||||||
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);
|
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);
|
||||||
@ -200,9 +205,9 @@ class KarmaPlugin implements CallbackListener, Plugin {
|
|||||||
* @param array $callback
|
* @param array $callback
|
||||||
*/
|
*/
|
||||||
public function handlePlayerConnect(array $callback) {
|
public function handlePlayerConnect(array $callback) {
|
||||||
$login = $callback[1][0];
|
$login = $callback[1][0];
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
if (!$player) {
|
if(!$player) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->queryManialinkUpdateFor($player);
|
$this->queryManialinkUpdateFor($player);
|
||||||
@ -214,22 +219,22 @@ class KarmaPlugin implements CallbackListener, Plugin {
|
|||||||
* @param array $chatCallback
|
* @param array $chatCallback
|
||||||
*/
|
*/
|
||||||
public function handlePlayerChat(array $chatCallback) {
|
public function handlePlayerChat(array $chatCallback) {
|
||||||
$login = $chatCallback[1][1];
|
$login = $chatCallback[1][1];
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
if (!$player) {
|
if(!$player) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$message = $chatCallback[1][2];
|
$message = $chatCallback[1][2];
|
||||||
if ($chatCallback[1][3]) {
|
if($chatCallback[1][3]) {
|
||||||
$message = substr($message, 1);
|
$message = substr($message, 1);
|
||||||
}
|
}
|
||||||
if (preg_match('/[^+-]/', $message)) {
|
if(preg_match('/[^+-]/', $message)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$vote = substr_count($message, '+');
|
$vote = substr_count($message, '+');
|
||||||
$vote -= substr_count($message, '-');
|
$vote -= substr_count($message, '-');
|
||||||
$success = $this->handleVote($player, $vote);
|
$success = $this->handleVote($player, $vote);
|
||||||
if (!$success) {
|
if(!$success) {
|
||||||
$this->maniaControl->chat->sendError('Error occurred.', $player->login);
|
$this->maniaControl->chat->sendError('Error occurred.', $player->login);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -240,31 +245,37 @@ class KarmaPlugin implements CallbackListener, Plugin {
|
|||||||
* Handle a vote done by a player
|
* Handle a vote done by a player
|
||||||
*
|
*
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
* @param int $vote
|
* @param int $vote
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function handleVote(Player $player, $vote) {
|
private function handleVote(Player $player, $vote) {
|
||||||
// Check vote
|
// Check vote
|
||||||
$votesSetting = $this->maniaControl->settingManager->getSetting($this, self::SETTING_AVAILABLE_VOTES);
|
$votesSetting = $this->maniaControl->settingManager->getSetting($this, self::SETTING_AVAILABLE_VOTES);
|
||||||
$votes = explode(',', $votesSetting);
|
$votes = explode(',', $votesSetting);
|
||||||
$voteLow = intval($votes[0]);
|
$voteLow = intval($votes[0]);
|
||||||
$voteHigh = $voteLow + 2;
|
$voteHigh = $voteLow + 2;
|
||||||
if (isset($votes[1])) {
|
if(isset($votes[1])) {
|
||||||
$voteHigh = intval($votes[1]);
|
$voteHigh = intval($votes[1]);
|
||||||
}
|
}
|
||||||
if ($vote < $voteLow || $vote > $voteHigh) {
|
if($vote < $voteLow || $vote > $voteHigh) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate actual voting
|
// Calculate actual voting
|
||||||
$vote -= $voteLow;
|
$vote -= $voteLow;
|
||||||
$voteHigh -= $voteLow;
|
$voteHigh -= $voteLow;
|
||||||
$vote /= $voteHigh;
|
$vote /= $voteHigh;
|
||||||
|
|
||||||
// Save vote
|
// Save vote
|
||||||
$map = $this->maniaControl->mapManager->getCurrentMap();
|
$map = $this->maniaControl->mapManager->getCurrentMap();
|
||||||
|
|
||||||
|
$voted = $this->getPlayerVote($player, $map);
|
||||||
|
if(!$voted){
|
||||||
|
$this->maniaControl->statisticManager->incrementStat(self::STAT_PLAYER_MAPVOTES, $player, $this->maniaControl->server->getLogin());
|
||||||
|
}
|
||||||
|
|
||||||
$success = $this->savePlayerVote($player, $map, $vote);
|
$success = $this->savePlayerVote($player, $map, $vote);
|
||||||
if (!$success) {
|
if(!$success) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->updateManialink = true;
|
$this->updateManialink = true;
|
||||||
@ -277,10 +288,10 @@ class KarmaPlugin implements CallbackListener, Plugin {
|
|||||||
* @param Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
private function queryManialinkUpdateFor(Player $player) {
|
private function queryManialinkUpdateFor(Player $player) {
|
||||||
if ($this->updateManialink === true) {
|
if($this->updateManialink === true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!is_array($this->updateManialink)) {
|
if(!is_array($this->updateManialink)) {
|
||||||
$this->updateManialink = array();
|
$this->updateManialink = array();
|
||||||
}
|
}
|
||||||
$this->updateManialink[$player->login] = $player;
|
$this->updateManialink[$player->login] = $player;
|
||||||
@ -291,7 +302,7 @@ class KarmaPlugin implements CallbackListener, Plugin {
|
|||||||
*/
|
*/
|
||||||
private function initTables() {
|
private function initTables() {
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_KARMA . "` (
|
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_KARMA . "` (
|
||||||
`index` int(11) NOT NULL AUTO_INCREMENT,
|
`index` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`mapIndex` int(11) NOT NULL,
|
`mapIndex` int(11) NOT NULL,
|
||||||
`playerIndex` int(11) NOT NULL,
|
`playerIndex` int(11) NOT NULL,
|
||||||
@ -301,7 +312,7 @@ class KarmaPlugin implements CallbackListener, Plugin {
|
|||||||
UNIQUE KEY `player_map_vote` (`mapIndex`, `playerIndex`)
|
UNIQUE KEY `player_map_vote` (`mapIndex`, `playerIndex`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Save players map votes' AUTO_INCREMENT=1;";
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Save players map votes' AUTO_INCREMENT=1;";
|
||||||
$mysqli->query($query);
|
$mysqli->query($query);
|
||||||
if ($mysqli->error) {
|
if($mysqli->error) {
|
||||||
trigger_error($mysqli->error, E_USER_ERROR);
|
trigger_error($mysqli->error, E_USER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -310,13 +321,13 @@ class KarmaPlugin implements CallbackListener, Plugin {
|
|||||||
* Save the vote of the player for the map
|
* Save the vote of the player for the map
|
||||||
*
|
*
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
* @param Map $map
|
* @param Map $map
|
||||||
* @param float $vote
|
* @param float $vote
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function savePlayerVote(Player $player, Map $map, $vote) {
|
private function savePlayerVote(Player $player, Map $map, $vote) {
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$query = "INSERT INTO `" . self::TABLE_KARMA . "` (
|
$query = "INSERT INTO `" . self::TABLE_KARMA . "` (
|
||||||
`mapIndex`,
|
`mapIndex`,
|
||||||
`playerIndex`,
|
`playerIndex`,
|
||||||
`vote`
|
`vote`
|
||||||
@ -327,7 +338,7 @@ class KarmaPlugin implements CallbackListener, Plugin {
|
|||||||
) ON DUPLICATE KEY UPDATE
|
) ON DUPLICATE KEY UPDATE
|
||||||
`vote` = VALUES(`vote`);";
|
`vote` = VALUES(`vote`);";
|
||||||
$result = $mysqli->query($query);
|
$result = $mysqli->query($query);
|
||||||
if ($mysqli->error) {
|
if($mysqli->error) {
|
||||||
trigger_error($mysqli->error);
|
trigger_error($mysqli->error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -338,21 +349,21 @@ class KarmaPlugin implements CallbackListener, Plugin {
|
|||||||
* Get the current vote of the player for the map
|
* Get the current vote of the player for the map
|
||||||
*
|
*
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
* @param Map $map
|
* @param Map $map
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
private function getPlayerVote(Player $player, Map $map) {
|
private function getPlayerVote(Player $player, Map $map) {
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$query = "SELECT * FROM `" . self::TABLE_KARMA . "`
|
$query = "SELECT * FROM `" . self::TABLE_KARMA . "`
|
||||||
WHERE `playerIndex` = {$player->index}
|
WHERE `playerIndex` = {$player->index}
|
||||||
AND `mapIndex` = {$map->index}
|
AND `mapIndex` = {$map->index}
|
||||||
AND `vote` >= 0;";
|
AND `vote` >= 0;";
|
||||||
$result = $mysqli->query($query);
|
$result = $mysqli->query($query);
|
||||||
if ($mysqli->error) {
|
if($mysqli->error) {
|
||||||
trigger_error($mysqli->error);
|
trigger_error($mysqli->error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($result->num_rows <= 0) {
|
if($result->num_rows <= 0) {
|
||||||
$result->free();
|
$result->free();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -370,22 +381,22 @@ class KarmaPlugin implements CallbackListener, Plugin {
|
|||||||
*/
|
*/
|
||||||
public function getMapKarma(Map $map) {
|
public function getMapKarma(Map $map) {
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$query = "SELECT AVG(`vote`) AS `karma` FROM `" . self::TABLE_KARMA . "`
|
$query = "SELECT AVG(`vote`) AS `karma` FROM `" . self::TABLE_KARMA . "`
|
||||||
WHERE `mapIndex` = {$map->index}
|
WHERE `mapIndex` = {$map->index}
|
||||||
AND `vote` >= 0;";
|
AND `vote` >= 0;";
|
||||||
$result = $mysqli->query($query);
|
$result = $mysqli->query($query);
|
||||||
if ($mysqli->error) {
|
if($mysqli->error) {
|
||||||
trigger_error($mysqli->error);
|
trigger_error($mysqli->error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($result->num_rows <= 0) {
|
if($result->num_rows <= 0) {
|
||||||
$result->free();
|
$result->free();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$item = $result->fetch_object();
|
$item = $result->fetch_object();
|
||||||
$result->free();
|
$result->free();
|
||||||
$karma = $item->karma;
|
$karma = $item->karma;
|
||||||
if ($karma === null) {
|
if($karma === null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return floatval($karma);
|
return floatval($karma);
|
||||||
@ -399,18 +410,18 @@ class KarmaPlugin implements CallbackListener, Plugin {
|
|||||||
*/
|
*/
|
||||||
public function getMapVotes(Map $map) {
|
public function getMapVotes(Map $map) {
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$query = "SELECT `vote`, COUNT(`vote`) AS `count` FROM `" . self::TABLE_KARMA . "`
|
$query = "SELECT `vote`, COUNT(`vote`) AS `count` FROM `" . self::TABLE_KARMA . "`
|
||||||
WHERE `mapIndex` = {$map->index}
|
WHERE `mapIndex` = {$map->index}
|
||||||
AND `vote` >= 0
|
AND `vote` >= 0
|
||||||
GROUP BY `vote`;";
|
GROUP BY `vote`;";
|
||||||
$result = $mysqli->query($query);
|
$result = $mysqli->query($query);
|
||||||
if ($mysqli->error) {
|
if($mysqli->error) {
|
||||||
trigger_error($mysqli->error);
|
trigger_error($mysqli->error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$votes = array();
|
$votes = array();
|
||||||
$count = 0;
|
$count = 0;
|
||||||
while ($vote = $result->fetch_object()) {
|
while($vote = $result->fetch_object()) {
|
||||||
$votes[$vote->vote] = $vote;
|
$votes[$vote->vote] = $vote;
|
||||||
$count += $vote->count;
|
$count += $vote->count;
|
||||||
}
|
}
|
||||||
@ -425,29 +436,31 @@ class KarmaPlugin implements CallbackListener, Plugin {
|
|||||||
* @param bool $forceBuild
|
* @param bool $forceBuild
|
||||||
*/
|
*/
|
||||||
private function buildManialink($forceBuild = false) {
|
private function buildManialink($forceBuild = false) {
|
||||||
if (is_object($this->manialink) && !$forceBuild) return;
|
if(is_object($this->manialink) && !$forceBuild) {
|
||||||
|
return;
|
||||||
$title = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_TITLE);
|
}
|
||||||
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSX);
|
|
||||||
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSY);
|
$title = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_TITLE);
|
||||||
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_WIDTH);
|
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSX);
|
||||||
$height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_HEIGHT);
|
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSY);
|
||||||
$labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle();
|
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_WIDTH);
|
||||||
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
|
$height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_HEIGHT);
|
||||||
|
$labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle();
|
||||||
|
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
|
||||||
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
||||||
|
|
||||||
$manialink = new ManiaLink(self::MLID_KARMA);
|
$manialink = new ManiaLink(self::MLID_KARMA);
|
||||||
|
|
||||||
$frame = new Frame();
|
$frame = new Frame();
|
||||||
$manialink->add($frame);
|
$manialink->add($frame);
|
||||||
$frame->setPosition($pos_x, $pos_y);
|
$frame->setPosition($pos_x, $pos_y);
|
||||||
|
|
||||||
$backgroundQuad = new Quad();
|
$backgroundQuad = new Quad();
|
||||||
$frame->add($backgroundQuad);
|
$frame->add($backgroundQuad);
|
||||||
$backgroundQuad->setY($height * 0.15);
|
$backgroundQuad->setY($height * 0.15);
|
||||||
$backgroundQuad->setSize($width, $height);
|
$backgroundQuad->setSize($width, $height);
|
||||||
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||||
|
|
||||||
$titleLabel = new Label();
|
$titleLabel = new Label();
|
||||||
$frame->add($titleLabel);
|
$frame->add($titleLabel);
|
||||||
$titleLabel->setY($height * 0.36);
|
$titleLabel->setY($height * 0.36);
|
||||||
@ -457,13 +470,13 @@ class KarmaPlugin implements CallbackListener, Plugin {
|
|||||||
$titleLabel->setTextSize(1);
|
$titleLabel->setTextSize(1);
|
||||||
$titleLabel->setScale(0.90);
|
$titleLabel->setScale(0.90);
|
||||||
$titleLabel->setText($title);
|
$titleLabel->setText($title);
|
||||||
|
|
||||||
$karmaGauge = new Gauge();
|
$karmaGauge = new Gauge();
|
||||||
$frame->add($karmaGauge);
|
$frame->add($karmaGauge);
|
||||||
$karmaGauge->setSize($width * 0.95, $height * 0.92);
|
$karmaGauge->setSize($width * 0.95, $height * 0.92);
|
||||||
$karmaGauge->setDrawBg(false);
|
$karmaGauge->setDrawBg(false);
|
||||||
$manialink->karmaGauge = $karmaGauge;
|
$manialink->karmaGauge = $karmaGauge;
|
||||||
|
|
||||||
$karmaLabel = new Label();
|
$karmaLabel = new Label();
|
||||||
$frame->add($karmaLabel);
|
$frame->add($karmaLabel);
|
||||||
$karmaLabel->setPosition(0, -0.4, 1);
|
$karmaLabel->setPosition(0, -0.4, 1);
|
||||||
@ -471,11 +484,11 @@ class KarmaPlugin implements CallbackListener, Plugin {
|
|||||||
$karmaLabel->setStyle($labelStyle);
|
$karmaLabel->setStyle($labelStyle);
|
||||||
$karmaLabel->setTextSize(1);
|
$karmaLabel->setTextSize(1);
|
||||||
$manialink->karmaLabel = $karmaLabel;
|
$manialink->karmaLabel = $karmaLabel;
|
||||||
|
|
||||||
$votesFrame = new Frame();
|
$votesFrame = new Frame();
|
||||||
$frame->add($votesFrame);
|
$frame->add($votesFrame);
|
||||||
$manialink->votesFrame = $votesFrame;
|
$manialink->votesFrame = $votesFrame;
|
||||||
|
|
||||||
$this->manialink = $manialink;
|
$this->manialink = $manialink;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user