reformat code in plugins

This commit is contained in:
kremsy 2014-08-13 11:14:29 +02:00
parent 22915bb934
commit 13924f7d8a
10 changed files with 850 additions and 1477 deletions

View File

@ -80,43 +80,25 @@ class ChatMessagePlugin implements CommandListener, Plugin {
$this->maniaControl = $maniaControl;
// Chat commands
$this->maniaControl->getCommandManager()
->registerCommandListener('me', $this, 'chat_me', false, 'Can be used to express your feelings/ideas.');
$this->maniaControl->getCommandManager()
->registerCommandListener('hi', $this, 'chat_hi', false, 'Writes an hello message to the chat.');
$this->maniaControl->getCommandManager()
->registerCommandListener(array('bb', 'bye'), $this, 'chat_bye', false, 'Writes a goodbye message to the chat.');
$this->maniaControl->getCommandManager()
->registerCommandListener('thx', $this, 'chat_thx', false, 'Writes a thanks message to the chat.');
$this->maniaControl->getCommandManager()
->registerCommandListener('gg', $this, 'chat_gg', false, 'Writes a good game message to the chat.');
$this->maniaControl->getCommandManager()
->registerCommandListener('gl', $this, 'chat_gl', false, 'Writes a good luck message to the chat.');
$this->maniaControl->getCommandManager()
->registerCommandListener('hf', $this, 'chat_hf', false, 'Writes an have fun message to the chat.');
$this->maniaControl->getCommandManager()
->registerCommandListener('glhf', $this, 'chat_glhf', false, 'Writes a good luck, have fun message to the chat.');
$this->maniaControl->getCommandManager()
->registerCommandListener('ns', $this, 'chat_ns', false, 'Writes a nice shot message to the chat.');
$this->maniaControl->getCommandManager()
->registerCommandListener('n1', $this, 'chat_n1', false, 'Writes a nice one message to the chat.');
$this->maniaControl->getCommandManager()
->registerCommandListener('lol', $this, 'chat_lol', false, 'Writes a lol message to the chat.');
$this->maniaControl->getCommandManager()
->registerCommandListener('lool', $this, 'chat_lool', false, 'Writes a lool message to the chat.');
$this->maniaControl->getCommandManager()
->registerCommandListener('brb', $this, 'chat_brb', false, 'Writes a be right back message to the chat.');
$this->maniaControl->getCommandManager()
->registerCommandListener('bgm', $this, 'chat_bgm', false, 'Writes a bad game for me message to the chat.');
$this->maniaControl->getCommandManager()
->registerCommandListener('afk', $this, 'chat_afk', false, 'Writes an away from keyboard message to the chat.');
$this->maniaControl->getCommandManager()
->registerCommandListener(array('bm', 'bootme'), $this, 'chat_bootme', false, 'Gets you away from this server quickly!');
$this->maniaControl->getCommandManager()
->registerCommandListener(array('rq', 'ragequit'), $this, 'chat_ragequit', false, 'Gets you away from this server in rage!');
$this->maniaControl->getCommandManager()->registerCommandListener('me', $this, 'chat_me', false, 'Can be used to express your feelings/ideas.');
$this->maniaControl->getCommandManager()->registerCommandListener('hi', $this, 'chat_hi', false, 'Writes an hello message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener(array('bb', 'bye'), $this, 'chat_bye', false, 'Writes a goodbye message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('thx', $this, 'chat_thx', false, 'Writes a thanks message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('gg', $this, 'chat_gg', false, 'Writes a good game message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('gl', $this, 'chat_gl', false, 'Writes a good luck message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('hf', $this, 'chat_hf', false, 'Writes an have fun message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('glhf', $this, 'chat_glhf', false, 'Writes a good luck, have fun message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('ns', $this, 'chat_ns', false, 'Writes a nice shot message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('n1', $this, 'chat_n1', false, 'Writes a nice one message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('lol', $this, 'chat_lol', false, 'Writes a lol message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('lool', $this, 'chat_lool', false, 'Writes a lool message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('brb', $this, 'chat_brb', false, 'Writes a be right back message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('bgm', $this, 'chat_bgm', false, 'Writes a bad game for me message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener('afk', $this, 'chat_afk', false, 'Writes an away from keyboard message to the chat.');
$this->maniaControl->getCommandManager()->registerCommandListener(array('bm', 'bootme'), $this, 'chat_bootme', false, 'Gets you away from this server quickly!');
$this->maniaControl->getCommandManager()->registerCommandListener(array('rq', 'ragequit'), $this, 'chat_ragequit', false, 'Gets you away from this server in rage!');
//TODO block command listener for muted people
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_AFK_FORCE_SPEC, true);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_AFK_FORCE_SPEC, true);
return true;
}
@ -137,8 +119,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
$message = substr($chat[1][2], 4);
$msg = '$<' . $player->nickname . '$>$s$i$fa0 ' . $message;
$this->maniaControl->getChat()
->sendChat($msg, null, false);
$this->maniaControl->getChat()->sendChat($msg, null, false);
}
/**
@ -155,8 +136,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
} else {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iHello All!';
}
$this->maniaControl->getChat()
->sendChat($msg, null, false);
$this->maniaControl->getChat()->sendChat($msg, null, false);
}
/**
@ -168,8 +148,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
*/
private function getTarget($login) {
$player = null;
foreach ($this->maniaControl->getPlayerManager()
->getPlayers() as $player) {
foreach ($this->maniaControl->getPlayerManager()->getPlayers() as $player) {
if ($login == $player || $login == $player->login || $login == $player->pid || $login == $player->nickname) {
return $player->nickname;
}
@ -198,8 +177,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iI have to go... Bye All!';
}
$this->maniaControl->getChat()
->sendChat($msg, null, false);
$this->maniaControl->getChat()->sendChat($msg, null, false);
}
/**
@ -217,8 +195,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iThanks All!';
}
$this->maniaControl->getChat()
->sendChat($msg, null, false);
$this->maniaControl->getChat()->sendChat($msg, null, false);
}
/**
@ -236,8 +213,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
$msg = '$ff0[' . $player->getEscapedNickname() . '] $ff0$iGood Game All!';
}
$this->maniaControl->getChat()
->sendChat($msg, null, false);
$this->maniaControl->getChat()->sendChat($msg, null, false);
}
/**
@ -255,8 +231,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iGood Luck All!';
}
$this->maniaControl->getChat()
->sendChat($msg, null, false);
$this->maniaControl->getChat()->sendChat($msg, null, false);
}
/**
@ -274,8 +249,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
$msg = '$ff0[' . $player->getEscapedNickname() . '] $ff0$iHave Fun All!';
}
$this->maniaControl->getChat()
->sendChat($msg, null, false);
$this->maniaControl->getChat()->sendChat($msg, null, false);
}
/**
@ -293,8 +267,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iGood Luck and Have Fun All!';
}
$this->maniaControl->getChat()
->sendChat($msg, null, false);
$this->maniaControl->getChat()->sendChat($msg, null, false);
}
/**
@ -312,8 +285,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iNice Shot!';
}
$this->maniaControl->getChat()
->sendChat($msg, null, false);
$this->maniaControl->getChat()->sendChat($msg, null, false);
}
/**
@ -331,8 +303,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iNice One!';
}
$this->maniaControl->getChat()
->sendChat($msg, null, false);
$this->maniaControl->getChat()->sendChat($msg, null, false);
}
/**
@ -343,8 +314,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
*/
public function chat_lol(array $chat, Player $player) {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iLoL!';
$this->maniaControl->getChat()
->sendChat($msg, null, false);
$this->maniaControl->getChat()->sendChat($msg, null, false);
}
/**
@ -355,8 +325,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
*/
public function chat_lool(array $chat, Player $player) {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iLooOOooL!';
$this->maniaControl->getChat()
->sendChat($msg, null, false);
$this->maniaControl->getChat()->sendChat($msg, null, false);
}
/**
@ -367,8 +336,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
*/
public function chat_brb(array $chat, Player $player) {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iBe Right Back!';
$this->maniaControl->getChat()
->sendChat($msg, null, false);
$this->maniaControl->getChat()->sendChat($msg, null, false);
}
/**
@ -379,8 +347,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
*/
public function chat_bgm(array $chat, Player $player) {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iBad Game for me :(';
$this->maniaControl->getChat()
->sendChat($msg, null, false);
$this->maniaControl->getChat()->sendChat($msg, null, false);
}
/**
@ -391,16 +358,13 @@ class ChatMessagePlugin implements CommandListener, Plugin {
*/
public function chat_bootme(array $chat, Player $player) {
$msg = '$i$ff0 $<' . $player->nickname . '$>$s$39f chooses to boot back to the real world!';
$this->maniaControl->getChat()
->sendChat($msg, null, true);
$this->maniaControl->getChat()->sendChat($msg, null, true);
$message = '$39F Thanks for Playing, see you around!$z';
try {
$this->maniaControl->getClient()
->kick($player->login, $message);
$this->maniaControl->getClient()->kick($player->login, $message);
} catch (UnknownPlayerException $exception) {
$this->maniaControl->getChat()
->sendException($exception, $player);
$this->maniaControl->getChat()->sendException($exception, $player);
}
}
@ -413,14 +377,11 @@ class ChatMessagePlugin implements CommandListener, Plugin {
public function chat_ragequit(array $chat, Player $player) {
try {
$message = '$39F Thanks for Playing, please come back soon!$z ';
$this->maniaControl->getClient()
->kick($player->login, $message);
$this->maniaControl->getClient()->kick($player->login, $message);
$msg = '$i$ff0 $<' . $player->nickname . '$>$s$f00 said: "@"#!" and ragequitted!';
$this->maniaControl->getChat()
->sendChat($msg, null, true);
$this->maniaControl->getChat()->sendChat($msg, null, true);
} catch (UnknownPlayerException $e) {
$this->maniaControl->getChat()
->sendError('Error occurred: ' . $e->getMessage(), $player);
$this->maniaControl->getChat()->sendError('Error occurred: ' . $e->getMessage(), $player);
}
}
@ -432,11 +393,9 @@ class ChatMessagePlugin implements CommandListener, Plugin {
*/
public function chat_afk(array $chat, Player $player) {
$msg = '$ff0[$<' . $player->nickname . '$>] $ff0$iAway From Keyboard!';
$this->maniaControl->getChat()
->sendChat($msg, null, false);
$this->maniaControl->getChat()->sendChat($msg, null, false);
if (!$this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_AFK_FORCE_SPEC)
if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_AFK_FORCE_SPEC)
) {
return;
}
@ -446,14 +405,11 @@ class ChatMessagePlugin implements CommandListener, Plugin {
try {
// Force into spec
$this->maniaControl->getClient()
->forceSpectator($player->login, 3);
$this->maniaControl->getClient()->forceSpectator($player->login, 3);
// Free player slot
$this->maniaControl->getClient()
->spectatorReleasePlayerSlot($player->login);
$this->maniaControl->getClient()->spectatorReleasePlayerSlot($player->login);
} catch (UnknownPlayerException $exception) {
$this->maniaControl->getChat()
->sendException($exception, $player);
$this->maniaControl->getChat()->sendException($exception, $player);
} catch (PlayerStateException $exception) {
}
}

View File

@ -133,76 +133,48 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$this->maniaControl = $maniaControl;
// Commands
$this->maniaControl->getCommandManager()
->registerCommandListener('vote', $this, 'chat_vote', false, 'Starts a new vote.');
$this->maniaControl->getCommandManager()->registerCommandListener('vote', $this, 'chat_vote', false, 'Starts a new vote.');
// Callbacks
$this->maniaControl->getManialinkManager()
->registerManialinkPageAnswerListener(self::ACTION_POSITIVE_VOTE, $this, 'handlePositiveVote');
$this->maniaControl->getManialinkManager()
->registerManialinkPageAnswerListener(self::ACTION_NEGATIVE_VOTE, $this, 'handleNegativeVote');
$this->maniaControl->getTimerManager()
->registerTimerListening($this, 'handle1Second', 1000);
$this->maniaControl->getCallbackManager()
->registerCallbackListener(Commands::CB_VOTE_CANCELLED, $this, 'handleVoteCancelled');
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_POSITIVE_VOTE, $this, 'handlePositiveVote');
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_NEGATIVE_VOTE, $this, 'handleNegativeVote');
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'handle1Second', 1000);
$this->maniaControl->getCallbackManager()->registerCallbackListener(Commands::CB_VOTE_CANCELLED, $this, 'handleVoteCancelled');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(self::CB_CUSTOM_VOTE_FINISHED, $this, 'handleVoteFinished');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(Server::CB_TEAM_MODE_CHANGED, $this, 'constructMenu');
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
$this->maniaControl->getCallbackManager()->registerCallbackListener(self::CB_CUSTOM_VOTE_FINISHED, $this, 'handleVoteFinished');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Server::CB_TEAM_MODE_CHANGED, $this, 'constructMenu');
// Settings
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_VOTE_ICON_POSX, 156.);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_VOTE_ICON_POSY, -38.6);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_VOTE_ICON_WIDTH, 6);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_VOTE_ICON_HEIGHT, 6);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_VOTE_ICON_POSX, 156.);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_VOTE_ICON_POSY, -38.6);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_VOTE_ICON_WIDTH, 6);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_VOTE_ICON_HEIGHT, 6);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_POSX, -80); //160 -15
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_POSY, 80); //-15
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_WIDTH, 50); //30
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_HEIGHT, 20); //25
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_POSX, -80); //160 -15
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_POSY, 80); //-15
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_WIDTH, 50); //30
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_HEIGHT, 20); //25
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_DEFAULT_RATIO, 0.75);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_DEFAULT_PLAYER_RATIO, 0.65);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_SPECTATOR_ALLOW_VOTE, false);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_SPECTATOR_ALLOW_START_VOTE, true);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_VOTE_TIME, 40);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_DEFAULT_RATIO, 0.75);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_DEFAULT_PLAYER_RATIO, 0.65);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SPECTATOR_ALLOW_VOTE, false);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SPECTATOR_ALLOW_START_VOTE, true);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_VOTE_TIME, 40);
//Define Votes
$this->defineVote("teambalance", "Vote for Team Balance");
$this->defineVote("skipmap", "Vote for Skip Map")
->setStopCallback(Callbacks::ENDMAP);
$this->defineVote("nextmap", "Vote for Skip Map")
->setStopCallback(Callbacks::ENDMAP);
$this->defineVote("skip", "Vote for Skip Map")
->setStopCallback(Callbacks::ENDMAP);
$this->defineVote("restartmap", "Vote for Restart Map")
->setStopCallback(Callbacks::ENDMAP);
$this->defineVote("restart", "Vote for Restart Map")
->setStopCallback(Callbacks::ENDMAP);
$this->defineVote("skipmap", "Vote for Skip Map")->setStopCallback(Callbacks::ENDMAP);
$this->defineVote("nextmap", "Vote for Skip Map")->setStopCallback(Callbacks::ENDMAP);
$this->defineVote("skip", "Vote for Skip Map")->setStopCallback(Callbacks::ENDMAP);
$this->defineVote("restartmap", "Vote for Restart Map")->setStopCallback(Callbacks::ENDMAP);
$this->defineVote("restart", "Vote for Restart Map")->setStopCallback(Callbacks::ENDMAP);
$this->defineVote("pausegame", "Vote for Pause Game");
$this->defineVote("replay", "Vote to replay current map");
foreach ($this->voteCommands as $name => $voteCommand) {
$this->maniaControl->getCommandManager()
->registerCommandListener($name, $this, 'handleChatVote', false, $voteCommand->name);
$this->maniaControl->getCommandManager()->registerCommandListener($name, $this, 'handleChatVote', false, $voteCommand->name);
}
/* Disable Standard Votes */
@ -212,8 +184,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_TEAM_BALANCE, -1.);
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_NEXT_MAP, -1.);
$this->maniaControl->getClient()
->setCallVoteRatios($ratioArray, false);
$this->maniaControl->getClient()->setCallVoteRatios($ratioArray, false);
$this->constructMenu();
return true;
@ -231,8 +202,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
*/
public function defineVote($voteIndex, $voteName, $idBased = false, $startText = '', $neededRatio = -1) {
if ($neededRatio < 0) {
$neededRatio = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_DEFAULT_RATIO);
$neededRatio = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DEFAULT_RATIO);
}
$voteCommand = new VoteCommand($voteIndex, $voteName, $idBased, $neededRatio);
$voteCommand->startText = $startText;
@ -255,8 +225,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
//Check if Pause exists in current GameMode
try {
$scriptInfos = $this->maniaControl->getClient()
->getModeScriptInfo();
$scriptInfos = $this->maniaControl->getClient()->getModeScriptInfo();
$pauseExists = false;
foreach ($scriptInfos->commandDescs as $param) {
@ -282,8 +251,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$itemQuad->setAction(self::ACTION_START_VOTE . 'skipmap');
$this->addVoteMenuItem($itemQuad, 15, 'Vote for a Map Skip');
if ($this->maniaControl->getServer()
->isTeamMode()
if ($this->maniaControl->getServer()->isTeamMode()
) {
//Menu TeamBalance
$itemQuad = new Quad_Icons128x32_1();
@ -316,30 +284,18 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
* @param bool $login
*/
private function showIcon($login = false) {
$posX = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_VOTE_ICON_POSX);
$posY = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_VOTE_ICON_POSY);
$width = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_VOTE_ICON_WIDTH);
$height = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_VOTE_ICON_HEIGHT);
$shootManiaOffset = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultIconOffsetSM();
$quadStyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultQuadSubstyle();
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_VOTE_ICON_POSX);
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_VOTE_ICON_POSY);
$width = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_VOTE_ICON_WIDTH);
$height = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_VOTE_ICON_HEIGHT);
$shootManiaOffset = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultIconOffsetSM();
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
$itemMarginFactorX = 1.3;
$itemMarginFactorY = 1.2;
//If game is shootmania lower the icons position by 20
if ($this->maniaControl->getMapManager()
->getCurrentMap()
->getGame() === 'sm'
if ($this->maniaControl->getMapManager()->getCurrentMap()->getGame() === 'sm'
) {
$posY -= $shootManiaOffset;
}
@ -418,8 +374,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
// Send manialink
$this->maniaControl->getManialinkManager()
->sendManialink($maniaLink, $login);
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $login);
}
/**
@ -427,8 +382,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
*/
public function unload() {
//Enable Standard Votes
$defaultRatio = $this->maniaControl->getClient()
->getCallVoteRatio();
$defaultRatio = $this->maniaControl->getClient()->getCallVoteRatio();
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_BAN, $defaultRatio);
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_KICK, $defaultRatio);
@ -436,12 +390,10 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_TEAM_BALANCE, $defaultRatio);
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_NEXT_MAP, $defaultRatio);
$this->maniaControl->getClient()
->setCallVoteRatios($ratioArray, false);
$this->maniaControl->getClient()->setCallVoteRatios($ratioArray, false);
$this->destroyVote();
$this->maniaControl->getManialinkManager()
->hideManialink(self::MLID_ICON);
$this->maniaControl->getManialinkManager()->hideManialink(self::MLID_ICON);
}
/**
@ -449,13 +401,11 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
*/
private function destroyVote() {
$emptyManialink = new ManiaLink(self::MLID_WIDGET);
$this->maniaControl->getManialinkManager()
->sendManialink($emptyManialink);
$this->maniaControl->getManialinkManager()->sendManialink($emptyManialink);
// Remove the Listener for the Stop Callback if a stop callback is defined
if ($this->currentVote && $this->currentVote->stopCallback) {
$this->maniaControl->getCallbackManager()
->unregisterCallbackListening($this->currentVote->stopCallback, $this);
$this->maniaControl->getCallbackManager()->unregisterCallbackListening($this->currentVote->stopCallback, $this);
}
$this->currentVote = null;
@ -494,55 +444,44 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
*/
public function startVote(Player $player, $voteIndex, $function = null) {
//Player is muted
if ($this->maniaControl->getPlayerManager()
->getPlayerActions()
->isPlayerMuted($player)
if ($this->maniaControl->getPlayerManager()->getPlayerActions()->isPlayerMuted($player)
) {
$this->maniaControl->getChat()
->sendError('Muted Players are not allowed to start a vote.', $player);
$this->maniaControl->getChat()->sendError('Muted Players are not allowed to start a vote.', $player);
return;
}
// Spectators are not allowed to start a vote
if ($player->isSpectator
&& !$this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_SPECTATOR_ALLOW_START_VOTE)
&& !$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SPECTATOR_ALLOW_START_VOTE)
) {
$this->maniaControl->getChat()
->sendError('Spectators are not allowed to start a vote.', $player);
$this->maniaControl->getChat()->sendError('Spectators are not allowed to start a vote.', $player);
return;
}
//Vote does not exist
if (!isset($this->voteCommands[$voteIndex])) {
$this->maniaControl->getChat()
->sendError('Undefined vote.', $player);
$this->maniaControl->getChat()->sendError('Undefined vote.', $player);
return;
}
//A vote is currently running
if (isset($this->currentVote)) {
$this->maniaControl->getChat()
->sendError('There is currently another vote running.', $player);
$this->maniaControl->getChat()->sendError('There is currently another vote running.', $player);
return;
}
$maxTime = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_VOTE_TIME);
$maxTime = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_VOTE_TIME);
/** @var VoteCommand $voteCommand */
$voteCommand = $this->voteCommands[$voteIndex];
$this->currentVote = new CurrentVote($voteCommand, $player, time() + $maxTime);
$this->currentVote->neededRatio = floatval($this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_DEFAULT_RATIO));
$this->currentVote->neededPlayerRatio = floatval($this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_DEFAULT_PLAYER_RATIO));
$this->currentVote->neededRatio = floatval($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DEFAULT_RATIO));
$this->currentVote->neededPlayerRatio = floatval($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DEFAULT_PLAYER_RATIO));
$this->currentVote->function = $function;
if ($voteCommand->getStopCallback()) {
$this->maniaControl->getCallbackManager()
->registerCallbackListener($voteCommand->getStopCallback(), $this, 'handleStopCallback');
$this->maniaControl->getCallbackManager()->registerCallbackListener($voteCommand->getStopCallback(), $this, 'handleStopCallback');
$this->currentVote->stopCallback = $voteCommand->getStopCallback();
}
@ -552,8 +491,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$message = '$fff' . $player->getEscapedNickname() . '$s$f8f started a $fff$<' . $this->currentVote->voteCommand->name . '$>$f8f!';
}
$this->maniaControl->getChat()
->sendSuccess($message);
$this->maniaControl->getChat()->sendSuccess($message);
}
/**
@ -586,54 +524,40 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
switch ($voteName) {
case 'teambalance':
$this->maniaControl->getClient()
->autoTeamBalance();
$this->maniaControl->getChat()
->sendInformation('$f8fVote to $fffbalance the Teams$f8f has been successful!');
$this->maniaControl->getClient()->autoTeamBalance();
$this->maniaControl->getChat()->sendInformation('$f8fVote to $fffbalance the Teams$f8f has been successful!');
break;
case 'skipmap':
case 'skip':
case 'nextmap':
try {
$this->maniaControl->getMapManager()
->getMapActions()
->skipMap();
$this->maniaControl->getMapManager()->getMapActions()->skipMap();
} catch (ChangeInProgressException $e) {
}
$this->maniaControl->getChat()
->sendInformation('$f8fVote to $fffskip the Map$f8f has been successful!');
$this->maniaControl->getChat()->sendInformation('$f8fVote to $fffskip the Map$f8f has been successful!');
break;
case 'restartmap':
try {
$this->maniaControl->getClient()
->restartMap();
$this->maniaControl->getClient()->restartMap();
} catch (ChangeInProgressException $e) {
}
$this->maniaControl->getChat()
->sendInformation('$f8fVote to $fffrestart the Map$f8f has been successful!');
$this->maniaControl->getChat()->sendInformation('$f8fVote to $fffrestart the Map$f8f has been successful!');
break;
case 'pausegame':
try {
$this->maniaControl->getClient()
->sendModeScriptCommands(array('Command_ForceWarmUp' => true));
$this->maniaControl->getChat()
->sendInformation('$f8fVote to $fffpause the current Game$f8f has been successful!');
$this->maniaControl->getClient()->sendModeScriptCommands(array('Command_ForceWarmUp' => true));
$this->maniaControl->getChat()->sendInformation('$f8fVote to $fffpause the current Game$f8f has been successful!');
} catch (GameModeException $ex) {
}
break;
case 'replay':
$this->maniaControl->getMapManager()
->getMapQueue()
->addFirstMapToMapQueue($this->currentVote->voter, $this->maniaControl->getMapManager()
->getCurrentMap());
$this->maniaControl->getChat()
->sendInformation('$f8fVote to $fffreplay the Map$f8f has been successful!');
$this->maniaControl->getMapManager()->getMapQueue()->addFirstMapToMapQueue($this->currentVote->voter, $this->maniaControl->getMapManager()->getCurrentMap());
$this->maniaControl->getChat()->sendInformation('$f8fVote to $fffreplay the Map$f8f has been successful!');
break;
}
} else {
//FIXME bugreport, no fail message on vote fail sometimes
$this->maniaControl->getChat()
->sendError('Vote Failed!');
$this->maniaControl->getChat()->sendError('Vote Failed!');
}
}
@ -652,8 +576,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$voteIndex = $actionArray[2];
if (isset($this->voteCommands[$voteIndex])) {
$login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager()
->getPlayer($login);
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
$this->startVote($player, $voteIndex);
}
}
@ -692,8 +615,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
public function handlePositiveVote(array $callback, Player $player) {
if (!isset($this->currentVote)
|| $player->isSpectator
&& !$this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_SPECTATOR_ALLOW_VOTE)
&& !$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SPECTATOR_ALLOW_VOTE)
) {
return;
}
@ -710,8 +632,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
public function handleNegativeVote(array $callback, Player $player) {
if (!isset($this->currentVote)
|| $player->isSpectator
&& !$this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_SPECTATOR_ALLOW_VOTE)
&& !$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SPECTATOR_ALLOW_VOTE)
) {
return;
}
@ -736,8 +657,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$timeUntilExpire = $this->currentVote->expireTime - time();
$this->showVoteWidget($timeUntilExpire, $votePercentage);
$playerCount = $this->maniaControl->getPlayerManager()
->getPlayerCount();
$playerCount = $this->maniaControl->getPlayerManager()->getPlayerCount();
$playersVoteRatio = 0;
if ($playerCount > 0 && $voteCount > 0) {
$playersVoteRatio = floatval($voteCount) / floatval($playerCount);
@ -746,8 +666,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
//Check if vote is over
if ($timeUntilExpire <= 0 || (($playersVoteRatio >= $this->currentVote->neededPlayerRatio) && (($votePercentage >= $this->currentVote->neededRatio) || ($votePercentage <= 1 - $this->currentVote->neededRatio)))) {
// Trigger callback
$this->maniaControl->getCallbackManager()
->triggerCallback(self::CB_CUSTOM_VOTE_FINISHED, $this->currentVote->voteCommand->index, $votePercentage);
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_CUSTOM_VOTE_FINISHED, $this->currentVote->voteCommand->index, $votePercentage);
//reset vote
$this->destroyVote();
@ -761,26 +680,15 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
* @param float $votePercentage
*/
private function showVoteWidget($timeUntilExpire, $votePercentage) {
$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);
$maxTime = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_VOTE_TIME);
$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);
$maxTime = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_VOTE_TIME);
$quadStyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultQuadSubstyle();
$labelStyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultLabelStyle();
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
$labelStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultLabelStyle();
$maniaLink = new ManiaLink(self::MLID_WIDGET);
@ -892,8 +800,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$script->addFeature($keyActionNegative);
// Send manialink
$this->maniaControl->getManialinkManager()
->sendManialink($maniaLink);
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink);
}
}

View File

@ -80,11 +80,9 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
* @see \ManiaControl\Plugins\Plugin::prepare()
*/
public static function prepare(ManiaControl $maniaControl) {
$servers = $maniaControl->getServer()
->getAllServers();
$servers = $maniaControl->getServer()->getAllServers();
foreach ($servers as $server) {
$maniaControl->getSettingManager()
->initSetting(get_class(), self::SETTING_DEDIMANIA_CODE . $server->login . '$l', '');
$maniaControl->getSettingManager()->initSetting(get_class(), self::SETTING_DEDIMANIA_CODE . $server->login . '$l', '');
}
}
@ -134,61 +132,39 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
}
// Settings
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_ENABLE, true);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_TITLE, 'Dedimania');
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_POSX, -139);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_POSY, 7);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_WIDTH, 40);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_LINE_HEIGHT, 4);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_LINE_COUNT, 12);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_ENABLE, true);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_TITLE, 'Dedimania');
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_POSX, -139);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_POSY, 7);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_WIDTH, 40);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_LINE_HEIGHT, 4);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_LINE_COUNT, 12);
// Callbacks
$this->maniaControl->getCallbackManager()
->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleBeginMap');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleMapEnd');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(RecordCallback::CHECKPOINT, $this, 'handleCheckpointCallback');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(RecordCallback::LAPFINISH, $this, 'handleLapFinishCallback');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(RecordCallback::FINISH, $this, 'handleFinishCallback');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleBeginMap');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleMapEnd');
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
$this->maniaControl->getCallbackManager()->registerCallbackListener(RecordCallback::CHECKPOINT, $this, 'handleCheckpointCallback');
$this->maniaControl->getCallbackManager()->registerCallbackListener(RecordCallback::LAPFINISH, $this, 'handleLapFinishCallback');
$this->maniaControl->getCallbackManager()->registerCallbackListener(RecordCallback::FINISH, $this, 'handleFinishCallback');
$this->maniaControl->getTimerManager()
->registerTimerListening($this, 'updateEverySecond', 1000);
$this->maniaControl->getTimerManager()
->registerTimerListening($this, 'handleEveryMinute', 1000 * 60);
$this->maniaControl->getTimerManager()
->registerTimerListening($this, 'updatePlayerList', 1000 * 60 * 3);
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'updateEverySecond', 1000);
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'handleEveryMinute', 1000 * 60);
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'updatePlayerList', 1000 * 60 * 3);
$this->maniaControl->getCommandManager()
->registerCommandListener(array('dedirecs', 'dedirecords'), $this, 'showDediRecordsList', false, 'Shows a list of Dedimania records of the current map.');
$this->maniaControl->getCommandManager()->registerCommandListener(array('dedirecs', 'dedirecords'), $this, 'showDediRecordsList', false, 'Shows a list of Dedimania records of the current map.');
// Open session
$serverInfo = $this->maniaControl->getServer()
->getInfo();
$serverInfo = $this->maniaControl->getServer()->getInfo();
$packMask = $this->maniaControl->getServer()->titleId;
$serverVersion = $this->maniaControl->getClient()
->getVersion();
$serverVersion = $this->maniaControl->getClient()->getVersion();
if ($packMask !== 'Trackmania_2@nadeolabs') {
$packMask = substr($this->maniaControl->getServer()->titleId, 2);
}
$dedimaniaCode = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_DEDIMANIA_CODE . $serverInfo->login . '$l');
$dedimaniaCode = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DEDIMANIA_CODE . $serverInfo->login . '$l');
if (!$dedimaniaCode) {
throw new \Exception("No Dedimania Code Specified, check the settings!");
}
@ -219,43 +195,42 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
//$this->maniaControl->fileReader->postDataTest($this->request, self::DEDIMANIA_URL, function ($data, $error) {
$this->maniaControl->getFileReader()
->postData(self::DEDIMANIA_URL, function ($data, $error) {
Logger::log("Try to connect on Dedimania");
$this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) {
Logger::log("Try to connect on Dedimania");
if (!$data || $error) {
Logger::logError("Dedimania Error: '{$error}'");
}
if (!$data || $error) {
Logger::logError("Dedimania Error: '{$error}'");
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_OPEN_SESSION);
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_OPEN_SESSION);
return;
}
$responseData = $methodResponse[0];
$this->dedimaniaData->sessionId = $responseData['SessionId'];
if ($this->dedimaniaData->sessionId) {
Logger::log("Dedimania connection successfully established.");
$this->fetchDedimaniaRecords();
$this->init = true;
} else {
Logger::logError("Error while opening Dedimania Connection");
}
$responseData = $methodResponse[0];
$this->dedimaniaData->sessionId = $responseData['SessionId'];
if ($this->dedimaniaData->sessionId) {
Logger::log("Dedimania connection successfully established.");
$this->fetchDedimaniaRecords();
$this->init = true;
} else {
Logger::logError("Error while opening Dedimania Connection");
}
if (self::DEDIMANIA_DEBUG) {
var_dump("Dedi Debug: Connect Method Response");
var_dump($methodResponse);
if (self::DEDIMANIA_DEBUG) {
var_dump("Dedi Debug: Connect Method Response");
var_dump($methodResponse);
var_dump("Dedi Debug: DedimaniaData after Startup");
var_dump($this->dedimaniaData);
}
}, $content, true);
var_dump("Dedi Debug: DedimaniaData after Startup");
var_dump($this->dedimaniaData);
}
}, $content, true);
}
/**
@ -319,48 +294,45 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$content = $this->encode_request(self::DEDIMANIA_GET_RECORDS, $data);
//var_dump("get recs");
//$this->maniaControl->fileReader->postDataTest($this->request,self::DEDIMANIA_URL, function ($data, $error) {
$this->maniaControl->getFileReader()
->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) {
Logger::logError('Dedimania Error: ' . $error);
}
$this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) {
Logger::logError('Dedimania Error: ' . $error);
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_GET_RECORDS);
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_GET_RECORDS);
return;
}
$responseData = $methodResponse[0];
if (!isset($responseData['Players']) || !isset($responseData['Records'])) {
$this->maniaControl->getErrorHandler()
->triggerDebugNotice('Invalid Dedimania response!', $responseData);
return;
}
$responseData = $methodResponse[0];
if (!isset($responseData['Players']) || !isset($responseData['Records'])) {
$this->maniaControl->getErrorHandler()->triggerDebugNotice('Invalid Dedimania response!', $responseData);
return;
}
$this->dedimaniaData->serverMaxRank = $responseData['ServerMaxRank'];
$this->dedimaniaData->serverMaxRank = $responseData['ServerMaxRank'];
foreach ($responseData['Players'] as $player) {
$dediPlayer = new DedimaniaPlayer($player);
$this->dedimaniaData->addPlayer($dediPlayer);
}
foreach ($responseData['Records'] as $key => $record) {
$this->dedimaniaData->records[$key] = new RecordData($record);
}
foreach ($responseData['Players'] as $player) {
$dediPlayer = new DedimaniaPlayer($player);
$this->dedimaniaData->addPlayer($dediPlayer);
}
foreach ($responseData['Records'] as $key => $record) {
$this->dedimaniaData->records[$key] = new RecordData($record);
}
if (self::DEDIMANIA_DEBUG) {
var_dump("Dedimania Records Fetched");
}
if (self::DEDIMANIA_DEBUG) {
var_dump("Dedimania Records Fetched");
}
$this->updateManialink = true;
$this->maniaControl->getCallbackManager()
->triggerCallback(self::CB_DEDIMANIA_UPDATED, $this->dedimaniaData->records);
}, $content, true);
$this->updateManialink = true;
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_DEDIMANIA_UPDATED, $this->dedimaniaData->records);
}, $content, true);
return true;
}
@ -369,22 +341,18 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
* Build server info Structure for callbacks
*/
private function getServerInfo() {
$server = $this->maniaControl->getClient()
->getServerOptions();
$server = $this->maniaControl->getClient()->getServerOptions();
if (!$server) {
return null;
}
if ($this->maniaControl->getPlayerManager()
->getPlayerCount(false) <= 0
if ($this->maniaControl->getPlayerManager()->getPlayerCount(false) <= 0
) {
return null;
}
$playerCount = $this->maniaControl->getPlayerManager()
->getPlayerCount();
$spectatorCount = $this->maniaControl->getPlayerManager()
->getSpectatorCount();
$playerCount = $this->maniaControl->getPlayerManager()->getPlayerCount();
$spectatorCount = $this->maniaControl->getPlayerManager()->getSpectatorCount();
return array('SrvName' => $server->name, 'Comment' => $server->comment, 'Private' => (strlen($server->password) > 0), 'NumPlayers' => $playerCount, 'MaxPlayers' => $server->currentMaxPlayers, 'NumSpecs' => $spectatorCount, 'MaxSpecs' => $server->currentMaxSpectators);
}
@ -393,8 +361,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
* Build simple player list for callbacks
*/
private function getPlayerList() {
$players = $this->maniaControl->getPlayerManager()
->getPlayers();
$players = $this->maniaControl->getPlayerManager()->getPlayers();
if (empty($players)) {
return null;
@ -412,8 +379,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
* @return array
*/
private function getMapInfo() {
$map = $this->maniaControl->getMapManager()
->getCurrentMap();
$map = $this->maniaControl->getMapManager()->getCurrentMap();
if (!$map) {
return null;
}
@ -433,8 +399,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
* @return String
*/
private function getGameModeString() {
$gameMode = $this->maniaControl->getServer()
->getGameMode();
$gameMode = $this->maniaControl->getServer()->getGameMode();
if ($gameMode === null) {
Logger::logError("Couldn't retrieve game mode.");
return null;
@ -442,8 +407,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
switch ($gameMode) {
case 0:
{
$scriptNameResponse = $this->maniaControl->getClient()
->getScriptName();
$scriptNameResponse = $this->maniaControl->getClient()->getScriptName();
$scriptName = str_replace('.Script.txt', '', $scriptNameResponse['CurrentValue']);
switch ($scriptName) {
case 'Rounds':
@ -487,12 +451,10 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
var_dump("Dedimania Debug: Update Manialink");
}
if ($this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_WIDGET_ENABLE)
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_ENABLE)
) {
$manialink = $this->buildManialink();
$this->maniaControl->getManialinkManager()
->sendManialink($manialink);
$this->maniaControl->getManialinkManager()->sendManialink($manialink);
}
}
@ -504,27 +466,15 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
private function buildManialink() {
$records = $this->dedimaniaData->records;
$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);
$lines = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_WIDGET_LINE_COUNT);
$lineHeight = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_WIDGET_LINE_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);
$lines = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_LINE_COUNT);
$lineHeight = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_LINE_HEIGHT);
$labelStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultLabelStyle();
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
$manialink = new ManiaLink(self::MLID_DEDIMANIA);
@ -622,35 +572,34 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$content = $this->encode_request(self::DEDIMANIA_CHECK_SESSION, array($this->dedimaniaData->sessionId));
//var_dump("check session"); //TODO remove
//$this->maniaControl->fileReader->postDataTest($this->request, self::DEDIMANIA_URL, function ($data, $error) {
$this->maniaControl->getFileReader()
->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) {
Logger::logError("Dedimania Error: " . $error);
}
$this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) {
Logger::logError("Dedimania Error: " . $error);
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_CHECK_SESSION);
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_CHECK_SESSION);
return;
}
$responseData = $methodResponse[0];
if (is_bool($responseData)) {
if (!$responseData) {
$this->openDedimaniaSession();
}
}
$responseData = $methodResponse[0];
if (is_bool($responseData)) {
if (!$responseData) {
$this->openDedimaniaSession();
}
}
if (self::DEDIMANIA_DEBUG) {
var_dump("Dedi Debug: Session Check ResponseData ");
var_dump($responseData);
}
}, $content, true);
if (self::DEDIMANIA_DEBUG) {
var_dump("Dedi Debug: Session Check ResponseData ");
var_dump($responseData);
}
}, $content, true);
}
/**
@ -667,42 +616,38 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$data = array($this->dedimaniaData->sessionId, $player->login, $player->rawNickname, $player->path, $player->isSpectator);
$content = $this->encode_request(self::DEDIMANIA_PLAYERCONNECT, $data);
$this->maniaControl->getFileReader()
->postData(self::DEDIMANIA_URL, function ($data, $error) use (&$player) {
if ($error) {
Logger::logError("Dedimania Error: " . $error);
}
$this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) use (&$player) {
if ($error) {
Logger::logError("Dedimania Error: " . $error);
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERCONNECT);
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERCONNECT);
return;
}
$responseData = $methodResponse[0];
$dediPlayer = new DedimaniaPlayer($responseData);
$this->dedimaniaData->addPlayer($dediPlayer);
$responseData = $methodResponse[0];
$dediPlayer = new DedimaniaPlayer($responseData);
$this->dedimaniaData->addPlayer($dediPlayer);
// Fetch records if he is the first who joined the server
if ($this->maniaControl->getPlayerManager()
->getPlayerCount(false) === 1
) {
$this->fetchDedimaniaRecords(true);
}
// Fetch records if he is the first who joined the server
if ($this->maniaControl->getPlayerManager()->getPlayerCount(false) === 1
) {
$this->fetchDedimaniaRecords(true);
}
if ($this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_WIDGET_ENABLE)
) {
$manialink = $this->buildManialink();
$this->maniaControl->getManialinkManager()
->sendManialink($manialink, $player->login);
}
}, $content, true);
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_ENABLE)
) {
$manialink = $this->buildManialink();
$this->maniaControl->getManialinkManager()->sendManialink($manialink, $player->login);
}
}, $content, true);
}
/**
@ -720,22 +665,21 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$data = array($this->dedimaniaData->sessionId, $player->login, '');
$content = $this->encode_request(self::DEDIMANIA_PLAYERDISCONNECT, $data);
$this->maniaControl->getFileReader()
->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) {
Logger::logError("Dedimania Error: " . $error);
}
$this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) {
Logger::logError("Dedimania Error: " . $error);
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERDISCONNECT);
}
}, $content, true);
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERDISCONNECT);
}
}, $content, true);
}
/**
@ -791,40 +735,39 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
var_dump("Dedimania Debug: Submitting Times at End-Map", $content);
}
$this->maniaControl->getFileReader()
->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) {
Logger::logError("Dedimania Error: " . $error);
}
$this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) {
Logger::logError("Dedimania Error: " . $error);
}
if (self::DEDIMANIA_DEBUG) {
var_dump("Dedimania Debug: Submit Data Response");
var_dump($data);
}
if (self::DEDIMANIA_DEBUG) {
var_dump("Dedimania Debug: Submit Data Response");
var_dump($data);
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_SET_CHALLENGE_TIMES);
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_SET_CHALLENGE_TIMES);
return;
}
// Called method response
if (!$methodResponse[0]) {
Logger::logError("Records Plugin: Submitting dedimania records failed.");
}
// Called method response
if (!$methodResponse[0]) {
Logger::logError("Records Plugin: Submitting dedimania records failed.");
}
if (self::DEDIMANIA_DEBUG) {
var_dump("Dedimania Debug: endMap response");
var_dump($methodResponse);
var_dump("Dedimania Data");
var_dump($this->dedimaniaData);
}
}, $content, false);
if (self::DEDIMANIA_DEBUG) {
var_dump("Dedimania Debug: endMap response");
var_dump($methodResponse);
var_dump("Dedimania Data");
var_dump($this->dedimaniaData);
}
}, $content, false);
}
/**
@ -842,30 +785,28 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$data = array($this->dedimaniaData->sessionId, $serverInfo, $votesInfo, $playerList);
$content = $this->encode_request(self::DEDIMANIA_UPDATE_SERVER_PLAYERS, $data);
$this->maniaControl->getFileReader()
->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) {
Logger::logError("Dedimania Error: " . $error);
}
$this->maniaControl->getFileReader()->postData(self::DEDIMANIA_URL, function ($data, $error) {
if ($error) {
Logger::logError("Dedimania Error: " . $error);
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$data = $this->decode($data);
if (!is_array($data) || empty($data)) {
return;
}
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_UPDATE_SERVER_PLAYERS);
}
}, $content, true);
$methodResponse = $data[0];
if (xmlrpc_is_fault($methodResponse)) {
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_UPDATE_SERVER_PLAYERS);
}
}, $content, true);
}
/**
* Build Votes Info Array for Callbacks
*/
private function getVotesInfo() {
$map = $this->maniaControl->getMapManager()
->getCurrentMap();
$map = $this->maniaControl->getMapManager()->getCurrentMap();
if (!$map) {
return null;
}
@ -919,8 +860,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
return;
}
$map = $this->maniaControl->getMapManager()
->getCurrentMap();
$map = $this->maniaControl->getMapManager()->getCurrentMap();
if (!$map) {
return;
}
@ -940,8 +880,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
break;
}
$this->maniaControl->getCallbackManager()
->triggerCallback(self::CB_DEDIMANIA_CHANGED, $newRecord);
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_DEDIMANIA_CHANGED, $newRecord);
// Announce record
if ($oldRecord->nullRecord || $newRecord->rank < $oldRecord->rank) {
@ -955,8 +894,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
if (!$oldRecord->nullRecord) {
$message .= ' ($<$ff0' . $oldRecord->rank . '.$> $<$fff-' . Formatter::formatTime(($oldRecord->best - $callback->lapTime)) . '$>)';
}
$this->maniaControl->getChat()
->sendInformation($message . '!');
$this->maniaControl->getChat()->sendInformation($message . '!');
$this->updateManialink = true;
}
@ -1092,8 +1030,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
*/
private function updateDedimaniaRecordRanks() {
if ($this->dedimaniaData->getRecordCount() === 0) {
$this->maniaControl->getCallbackManager()
->triggerCallback(self::CB_DEDIMANIA_UPDATED, $this->dedimaniaData->records);
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_DEDIMANIA_UPDATED, $this->dedimaniaData->records);
return;
}
@ -1105,8 +1042,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$record->rank = $rank;
$rank++;
}
$this->maniaControl->getCallbackManager()
->triggerCallback(self::CB_DEDIMANIA_UPDATED, $this->dedimaniaData->records);
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_DEDIMANIA_UPDATED, $this->dedimaniaData->records);
}
/**
@ -1116,28 +1052,23 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
*/
private function setRecordReplays(RecordData &$record) {
// Set validation replay
$validationReplay = $this->maniaControl->getServer()
->getValidationReplay($record->login);
$validationReplay = $this->maniaControl->getServer()->getValidationReplay($record->login);
if ($validationReplay) {
$record->vReplay = $validationReplay;
}
// Set ghost replay
if ($record->rank <= 1) {
$dataDirectory = $this->maniaControl->getServer()
->getDirectory()
->getGameDataFolder();
$dataDirectory = $this->maniaControl->getServer()->getDirectory()->getGameDataFolder();
if (!isset($this->dedimaniaData->directoryAccessChecked)) {
$access = $this->maniaControl->getServer()
->checkAccess($dataDirectory);
$access = $this->maniaControl->getServer()->checkAccess($dataDirectory);
if (!$access) {
trigger_error("No access to the servers data directory. Can't retrieve ghost replays.");
}
$this->dedimaniaData->directoryAccessChecked = $access;
}
if ($this->dedimaniaData->directoryAccessChecked) {
$ghostReplay = $this->maniaControl->getServer()
->getGhostReplay($record->login);
$ghostReplay = $this->maniaControl->getServer()->getGhostReplay($record->login);
if ($ghostReplay) {
$record->top1GReplay = $ghostReplay;
}
@ -1154,8 +1085,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$actionId = $callback[1][2];
$login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager()
->getPlayer($login);
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
if ($actionId === self::ACTION_SHOW_DEDIRECORDSLIST) {
$this->showDediRecordsList(array(), $player);
@ -1169,18 +1099,13 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
* @param Player $player
*/
public function showDediRecordsList(array $chat, Player $player) {
$width = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getListWidgetsWidth();
$height = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getListWidgetsHeight();
$width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
$height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
// get PlayerList
$records = $this->dedimaniaData->records;
if (!$records) {
$this->maniaControl->getChat()
->sendInformation('There are no Dedimania records on this map!');
$this->maniaControl->getChat()->sendInformation('There are no Dedimania records on this map!');
return;
}
@ -1191,9 +1116,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$script->addFeature($paging);
// Main frame
$frame = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultListFrame($script, $paging);
$frame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultListFrame($script, $paging);
$maniaLink->add($frame);
// Start offsets
@ -1201,9 +1124,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$posY = $height / 2;
// Predefine Description Label
$descriptionLabel = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultDescriptionLabel();
$descriptionLabel = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultDescriptionLabel();
$frame->add($descriptionLabel);
// Headline
@ -1211,8 +1132,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$frame->add($headFrame);
$headFrame->setY($posY - 5);
$array = array('Rank' => $posX + 5, 'Nickname' => $posX + 18, 'Login' => $posX + 70, 'Time' => $posX + 101);
$this->maniaControl->getManialinkManager()
->labelLine($headFrame, $array);
$this->maniaControl->getManialinkManager()->labelLine($headFrame, $array);
$index = 0;
$posY = $height / 2 - 10;
@ -1241,8 +1161,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
$listRecord->nickName = $listRecord->login;
}
$array = array($listRecord->rank => $posX + 5, '$fff' . $listRecord->nickName => $posX + 18, $listRecord->login => $posX + 70, Formatter::formatTime($listRecord->best) => $posX + 101);
$this->maniaControl->getManialinkManager()
->labelLine($recordFrame, $array);
$this->maniaControl->getManialinkManager()->labelLine($recordFrame, $array);
$recordFrame->setY($posY);
@ -1251,8 +1170,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
}
// Render and display xml
$this->maniaControl->getManialinkManager()
->displayWidget($maniaLink, $player, 'DediRecordsList');
$this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'DediRecordsList');
}
/**

View File

@ -104,44 +104,28 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$this->maniaControl = $maniaControl;
// Register for commands
$this->maniaControl->getCommandManager()
->registerCommandListener('donate', $this, 'command_Donate', false, 'Donate some planets to the server.');
$this->maniaControl->getCommandManager()
->registerCommandListener('pay', $this, 'command_Pay', true, 'Pays planets from the server to a player.');
$this->maniaControl->getCommandManager()
->registerCommandListener(array('getplanets', 'planets'), $this, 'command_GetPlanets', true, 'Checks the planets-balance of the server.');
$this->maniaControl->getCommandManager()
->registerCommandListener('topdons', $this, 'command_TopDons', false, 'Provides an overview of who donated the most planets.');
$this->maniaControl->getCommandManager()->registerCommandListener('donate', $this, 'command_Donate', false, 'Donate some planets to the server.');
$this->maniaControl->getCommandManager()->registerCommandListener('pay', $this, 'command_Pay', true, 'Pays planets from the server to a player.');
$this->maniaControl->getCommandManager()->registerCommandListener(array('getplanets', 'planets'), $this, 'command_GetPlanets', true, 'Checks the planets-balance of the server.');
$this->maniaControl->getCommandManager()->registerCommandListener('topdons', $this, 'command_TopDons', false, 'Provides an overview of who donated the most planets.');
// Register for callbacks
$this->maniaControl->getCallbackManager()
->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
// Define player stats
$this->maniaControl->getStatisticManager()
->defineStatMetaData(self::STAT_PLAYER_DONATIONS);
$this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_PLAYER_DONATIONS);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_DONATE_WIDGET_ACTIVATED, true);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_DONATE_WIDGET_POSX, 156.);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_DONATE_WIDGET_POSY, -31.4);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_DONATE_WIDGET_WIDTH, 6);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_DONATE_WIDGET_HEIGHT, 6);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_DONATION_VALUES, "20,50,100,500,1000,2000");
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_MIN_AMOUNT_SHOWN, 100);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_DONATE_WIDGET_ACTIVATED, true);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_DONATE_WIDGET_POSX, 156.);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_DONATE_WIDGET_POSY, -31.4);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_DONATE_WIDGET_WIDTH, 6);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_DONATE_WIDGET_HEIGHT, 6);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_DONATION_VALUES, "20,50,100,500,1000,2000");
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MIN_AMOUNT_SHOWN, 100);
// Register Stat in Simple StatsList
$this->maniaControl->getStatisticManager()
->getSimpleStatsList()
->registerStat(self::STAT_PLAYER_DONATIONS, 90, "DP", 15);
$this->maniaControl->getStatisticManager()->getSimpleStatsList()->registerStat(self::STAT_PLAYER_DONATIONS, 90, "DP", 15);
$this->displayWidget();
return true;
@ -151,8 +135,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
* Display the widget
*/
public function displayWidget() {
if ($this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_DONATE_WIDGET_ACTIVATED)
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DONATE_WIDGET_ACTIVATED)
) {
$this->displayDonateWidget();
}
@ -164,32 +147,19 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
* @param string $login
*/
public function displayDonateWidget($login = null) {
$posX = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_DONATE_WIDGET_POSX);
$posY = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_DONATE_WIDGET_POSY);
$width = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_DONATE_WIDGET_WIDTH);
$height = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_DONATE_WIDGET_HEIGHT);
$values = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_DONATION_VALUES);
$shootManiaOffset = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultIconOffsetSM();
$quadStyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultQuadSubstyle();
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DONATE_WIDGET_POSX);
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DONATE_WIDGET_POSY);
$width = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DONATE_WIDGET_WIDTH);
$height = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DONATE_WIDGET_HEIGHT);
$values = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DONATION_VALUES);
$shootManiaOffset = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultIconOffsetSM();
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
$itemMarginFactorX = 1.3;
$itemMarginFactorY = 1.2;
//If game is shootmania lower the icons position by 20
if ($this->maniaControl->getMapManager()
->getCurrentMap()
->getGame() === 'sm'
if ($this->maniaControl->getMapManager()->getCurrentMap()->getGame() === 'sm'
) {
$posY -= $shootManiaOffset;
}
@ -268,16 +238,14 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
}
// Send manialink
$this->maniaControl->getManialinkManager()
->sendManialink($maniaLink, $login);
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $login);
}
/**
* @see \ManiaControl\Plugins\Plugin::unload()
*/
public function unload() {
$this->maniaControl->getManialinkManager()
->hideManialink(self::MLID_DONATE_WIDGET);
$this->maniaControl->getManialinkManager()->hideManialink(self::MLID_DONATE_WIDGET);
}
/**
@ -292,8 +260,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
return;
}
$login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager()
->getPlayer($login);
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
$actionArray = explode(".", $callback[1][2]);
$this->handleDonation($player, intval($actionArray[2]));
}
@ -310,57 +277,47 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
if ($amount > 1000000) {
// Prevent too huge donation amounts that would cause xmlrpc parsing errors
$message = "You can only donate 1.000.000 Planets at a time!";
$this->maniaControl->getChat()
->sendError($message, $player);
$this->maniaControl->getChat()->sendError($message, $player);
return;
}
if (!$receiverName) {
$serverName = $this->maniaControl->getClient()
->getServerName();
$serverName = $this->maniaControl->getClient()->getServerName();
$message = 'Donate ' . $amount . ' Planets to $<' . $serverName . '$>?';
} else {
$message = 'Donate ' . $amount . ' Planets to $<' . $receiverName . '$>?';
}
//Send and Handle the Bill
$this->maniaControl->getBillManager()
->sendBill(function ($data, $status) use (&$player, $amount, $receiver) {
switch ($status) {
case BillManager::DONATED_TO_SERVER:
if ($this->maniaControl->getSettingManager()
->getSettingValue($this, DonationPlugin::SETTING_ANNOUNCE_SERVER_DONATION, true)
&& $amount >= $this->maniaControl->getSettingManager()
->getSettingValue($this, DonationPlugin::SETTING_MIN_AMOUNT_SHOWN, true)
) {
$login = null;
$message = $player->getEscapedNickname() . ' donated ' . $amount . ' Planets! Thanks.';
} else {
$login = $player->login;
$message = 'Donation successful! Thanks.';
}
$this->maniaControl->getChat()
->sendSuccess($message, $login);
$this->maniaControl->getStatisticManager()
->insertStat(DonationPlugin::STAT_PLAYER_DONATIONS, $player, $this->maniaControl->getServer()->index, $amount);
break;
case BillManager::DONATED_TO_RECEIVER:
$message = "Successfully donated {$amount} to '{$receiver}'!";
$this->maniaControl->getChat()
->sendSuccess($message, $player);
break;
case BillManager::PLAYER_REFUSED_DONATION:
$message = 'Transaction cancelled.';
$this->maniaControl->getChat()
->sendError($message, $player);
break;
case BillManager::ERROR_WHILE_TRANSACTION:
$message = $data;
$this->maniaControl->getChat()
->sendError($message, $player);
break;
}
}, $player, $amount, $message);
$this->maniaControl->getBillManager()->sendBill(function ($data, $status) use (&$player, $amount, $receiver) {
switch ($status) {
case BillManager::DONATED_TO_SERVER:
if ($this->maniaControl->getSettingManager()->getSettingValue($this, DonationPlugin::SETTING_ANNOUNCE_SERVER_DONATION, true)
&& $amount >= $this->maniaControl->getSettingManager()->getSettingValue($this, DonationPlugin::SETTING_MIN_AMOUNT_SHOWN, true)
) {
$login = null;
$message = $player->getEscapedNickname() . ' donated ' . $amount . ' Planets! Thanks.';
} else {
$login = $player->login;
$message = 'Donation successful! Thanks.';
}
$this->maniaControl->getChat()->sendSuccess($message, $login);
$this->maniaControl->getStatisticManager()->insertStat(DonationPlugin::STAT_PLAYER_DONATIONS, $player, $this->maniaControl->getServer()->index, $amount);
break;
case BillManager::DONATED_TO_RECEIVER:
$message = "Successfully donated {$amount} to '{$receiver}'!";
$this->maniaControl->getChat()->sendSuccess($message, $player);
break;
case BillManager::PLAYER_REFUSED_DONATION:
$message = 'Transaction cancelled.';
$this->maniaControl->getChat()->sendError($message, $player);
break;
case BillManager::ERROR_WHILE_TRANSACTION:
$message = $data;
$this->maniaControl->getChat()->sendError($message, $player);
break;
}
}, $player, $amount, $message);
}
/**
@ -370,8 +327,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
*/
public function handlePlayerConnect(Player $player) {
// Display Map Widget
if ($this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_DONATE_WIDGET_ACTIVATED)
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DONATE_WIDGET_ACTIVATED)
) {
$this->displayDonateWidget($player->login);
}
@ -397,13 +353,11 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
}
if (count($params) >= 3) {
$receiver = $params[2];
$receiverPlayer = $this->maniaControl->getPlayerManager()
->getPlayer($receiver);
$receiverPlayer = $this->maniaControl->getPlayerManager()->getPlayer($receiver);
$receiverName = ($receiverPlayer ? $receiverPlayer->nickname : $receiver);
} else {
$receiver = '';
$receiverName = $this->maniaControl->getClient()
->getServerName();
$receiverName = $this->maniaControl->getClient()->getServerName();
}
$this->handleDonation($player, $amount, $receiver, $receiverName);
@ -416,8 +370,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
*/
private function sendDonateUsageExample(Player $player) {
$message = "Usage Example: '/donate 100'";
$this->maniaControl->getChat()
->sendChat($message, $player);
$this->maniaControl->getChat()->sendChat($message, $player);
}
/**
@ -427,11 +380,9 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
* @param Player $player
*/
public function command_Pay(array $chatCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager()
->checkRight($player, AuthenticationManager::AUTH_LEVEL_SUPERADMIN)
if (!$this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::AUTH_LEVEL_SUPERADMIN)
) {
$this->maniaControl->getAuthenticationManager()
->sendNotAllowed($player);
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return;
}
$text = $chatCallback[1][2];
@ -450,29 +401,24 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
} else {
$receiver = $player->login;
}
$message = 'Payout from $<' . $this->maniaControl->getClient()
->getServerName() . '$>.';
$message = 'Payout from $<' . $this->maniaControl->getClient()->getServerName() . '$>.';
$this->maniaControl->getBillManager()
->sendPlanets(function ($data, $status) use (&$player, $amount, $receiver) {
switch ($status) {
case BillManager::PAYED_FROM_SERVER:
$message = "Successfully payed out {$amount} to '{$receiver}'!";
$this->maniaControl->getChat()
->sendSuccess($message, $player);
break;
case BillManager::PLAYER_REFUSED_DONATION:
$message = 'Transaction cancelled.';
$this->maniaControl->getChat()
->sendError($message, $player);
break;
case BillManager::ERROR_WHILE_TRANSACTION:
$message = $data;
$this->maniaControl->getChat()
->sendError($message, $player);
break;
}
}, $receiver, $amount, $message);
$this->maniaControl->getBillManager()->sendPlanets(function ($data, $status) use (&$player, $amount, $receiver) {
switch ($status) {
case BillManager::PAYED_FROM_SERVER:
$message = "Successfully payed out {$amount} to '{$receiver}'!";
$this->maniaControl->getChat()->sendSuccess($message, $player);
break;
case BillManager::PLAYER_REFUSED_DONATION:
$message = 'Transaction cancelled.';
$this->maniaControl->getChat()->sendError($message, $player);
break;
case BillManager::ERROR_WHILE_TRANSACTION:
$message = $data;
$this->maniaControl->getChat()->sendError($message, $player);
break;
}
}, $receiver, $amount, $message);
}
/**
@ -482,8 +428,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
*/
private function sendPayUsageExample(Player $player) {
$message = "Usage Example: '//pay 100 login'";
$this->maniaControl->getChat()
->sendChat($message, $player);
$this->maniaControl->getChat()->sendChat($message, $player);
}
/**
@ -493,18 +438,14 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
* @param Player $player
*/
public function command_GetPlanets(array $chatCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager()
->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)
if (!$this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)
) {
$this->maniaControl->getAuthenticationManager()
->sendNotAllowed($player);
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return;
}
$planets = $this->maniaControl->getClient()
->getServerPlanets();
$planets = $this->maniaControl->getClient()->getServerPlanets();
$message = "This Server has {$planets} Planets!";
$this->maniaControl->getChat()
->sendInformation($message, $player);
$this->maniaControl->getChat()->sendInformation($message, $player);
}
/**
@ -523,15 +464,10 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
* @param Player $player
*/
private function showTopDonsList(Player $player) {
$stats = $this->maniaControl->getStatisticManager()
->getStatsRanking(self::STAT_PLAYER_DONATIONS);
$stats = $this->maniaControl->getStatisticManager()->getStatsRanking(self::STAT_PLAYER_DONATIONS);
$width = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getListWidgetsWidth();
$height = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getListWidgetsHeight();
$width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
$height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
// create manialink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
@ -540,9 +476,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$script->addFeature($paging);
// Main frame
$frame = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultListFrame($script, $paging);
$frame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultListFrame($script, $paging);
$maniaLink->add($frame);
// Start offsets
@ -550,9 +484,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$posY = $height / 2;
//Predefine description Label
$descriptionLabel = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultDescriptionLabel();
$descriptionLabel = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultDescriptionLabel();
$frame->add($descriptionLabel);
// Headline
@ -560,8 +492,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$frame->add($headFrame);
$headFrame->setY($posY - 5);
$array = array('$oId' => $posX + 5, '$oNickname' => $posX + 18, '$oDonated planets' => $posX + 70);
$this->maniaControl->getManialinkManager()
->labelLine($headFrame, $array);
$this->maniaControl->getManialinkManager()->labelLine($headFrame, $array);
$index = 1;
$posY = $posY - 10;
@ -587,11 +518,9 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$lineQuad->setZ(0.001);
}
$donatingPlayer = $this->maniaControl->getPlayerManager()
->getPlayerByIndex($playerIndex);
$donatingPlayer = $this->maniaControl->getPlayerManager()->getPlayerByIndex($playerIndex);
$array = array($index => $posX + 5, $donatingPlayer->nickname => $posX + 18, $donations => $posX + 70);
$this->maniaControl->getManialinkManager()
->labelLine($playerFrame, $array);
$this->maniaControl->getManialinkManager()->labelLine($playerFrame, $array);
$posY -= 4;
$index++;
@ -602,7 +531,6 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
}
// Render and display xml
$this->maniaControl->getManialinkManager()
->displayWidget($maniaLink, $player, 'TopDons');
$this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'TopDons');
}
}

View File

@ -52,16 +52,11 @@ class DynamicPointLimitPlugin implements CallbackListener, CommandListener, Plug
* @see \ManiaControl\Plugins\Plugin::prepare()
*/
public static function prepare(ManiaControl $maniaControl) {
$maniaControl->getSettingManager()
->initSetting(get_class(), self::SETTING_POINT_LIMIT_MULTIPLIER, 10);
$maniaControl->getSettingManager()
->initSetting(get_class(), self::SETTING_POINT_LIMIT_OFFSET, 0);
$maniaControl->getSettingManager()
->initSetting(get_class(), self::SETTING_MIN_POINT_LIMIT, 30);
$maniaControl->getSettingManager()
->initSetting(get_class(), self::SETTING_MAX_POINT_LIMIT, 200);
$maniaControl->getSettingManager()
->initSetting(get_class(), self::SETTING_ACCEPT_OTHER_MODES, false);
$maniaControl->getSettingManager()->initSetting(get_class(), self::SETTING_POINT_LIMIT_MULTIPLIER, 10);
$maniaControl->getSettingManager()->initSetting(get_class(), self::SETTING_POINT_LIMIT_OFFSET, 0);
$maniaControl->getSettingManager()->initSetting(get_class(), self::SETTING_MIN_POINT_LIMIT, 30);
$maniaControl->getSettingManager()->initSetting(get_class(), self::SETTING_MAX_POINT_LIMIT, 200);
$maniaControl->getSettingManager()->initSetting(get_class(), self::SETTING_ACCEPT_OTHER_MODES, false);
}
/**
@ -105,29 +100,21 @@ class DynamicPointLimitPlugin implements CallbackListener, CommandListener, Plug
public function load(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
$allowOthers = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_ACCEPT_OTHER_MODES);
$allowOthers = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_ACCEPT_OTHER_MODES);
if (!$allowOthers && $this->maniaControl->getServer()->titleId !== 'SMStormRoyal@nadeolabs') {
$error = 'This plugin only supports Royal (check Settings)!';
throw new \Exception($error);
}
$this->maniaControl->getCallbackManager()
->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'updatePointLimit');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'updatePointLimit');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(PlayerManager::CB_PLAYERINFOCHANGED, $this, 'handlePlayerInfoChangedCallback');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'updatePointLimit');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'updatePointLimit');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERINFOCHANGED, $this, 'handlePlayerInfoChangedCallback');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(Callbacks::BEGINROUND, $this, 'updatePointLimit');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleBeginMap');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'handleSettingChangedCallback');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::BEGINROUND, $this, 'updatePointLimit');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleBeginMap');
$this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'handleSettingChangedCallback');
$this->maniaControl->getCommandManager()
->registerCommandListener('setpointlimit', $this, 'commandSetPointlimit', true, 'Setpointlimit XXX or auto');
$this->maniaControl->getCommandManager()->registerCommandListener('setpointlimit', $this, 'commandSetPointlimit', true, 'Setpointlimit XXX or auto');
$this->updatePointLimit();
}
@ -139,17 +126,12 @@ class DynamicPointLimitPlugin implements CallbackListener, CommandListener, Plug
if ($this->staticMode) {
return;
}
$numberOfPlayers = $this->maniaControl->getPlayerManager()
->getPlayerCount();
$numberOfPlayers = $this->maniaControl->getPlayerManager()->getPlayerCount();
$multiplier = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_POINT_LIMIT_MULTIPLIER);
$offset = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_POINT_LIMIT_OFFSET);
$minValue = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MIN_POINT_LIMIT);
$maxValue = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MAX_POINT_LIMIT);
$multiplier = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_POINT_LIMIT_MULTIPLIER);
$offset = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_POINT_LIMIT_OFFSET);
$minValue = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MIN_POINT_LIMIT);
$maxValue = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAX_POINT_LIMIT);
$pointLimit = $offset + $numberOfPlayers * $multiplier;
if ($pointLimit < $minValue) {
@ -162,18 +144,15 @@ class DynamicPointLimitPlugin implements CallbackListener, CommandListener, Plug
if ($this->lastPointLimit !== $pointLimit) {
try {
$this->maniaControl->getClient()
->setModeScriptSettings(array(self::SCRIPT_SETTING_MAP_POINTS_LIMIT => $pointLimit));
$this->maniaControl->getClient()->setModeScriptSettings(array(self::SCRIPT_SETTING_MAP_POINTS_LIMIT => $pointLimit));
$message = "Dynamic PointLimit changed to: {$pointLimit}!";
if ($this->lastPointLimit !== null) {
$message .= " (From {$this->lastPointLimit})";
}
$this->maniaControl->getChat()
->sendInformation($message);
$this->maniaControl->getChat()->sendInformation($message);
$this->lastPointLimit = $pointLimit;
} catch (GameModeException $exception) {
$this->maniaControl->getChat()
->sendExceptionToAdmins($exception);
$this->maniaControl->getChat()->sendExceptionToAdmins($exception);
}
}
}
@ -187,38 +166,31 @@ class DynamicPointLimitPlugin implements CallbackListener, CommandListener, Plug
public function commandSetPointlimit(array $chatCallback, Player $player) {
$commandParts = explode(' ', $chatCallback[1][2]);
if (count($commandParts) < 2) {
$this->maniaControl->getChat()
->sendUsageInfo('Example: //setpointlimit auto', $player);
$this->maniaControl->getChat()->sendUsageInfo('Example: //setpointlimit auto', $player);
return;
}
$value = strtolower($commandParts[1]);
if ($value === "auto") {
$this->staticMode = false;
$this->maniaControl->getChat()
->sendInformation('Enabled Dynamic PointLimit!');
$this->maniaControl->getChat()->sendInformation('Enabled Dynamic PointLimit!');
$this->updatePointLimit();
} else {
if (is_numeric($value)) {
$value = (int)$value;
if ($value <= 0) {
$this->maniaControl->getChat()
->sendError('PointLimit needs to be greater than Zero.', $player);
$this->maniaControl->getChat()->sendError('PointLimit needs to be greater than Zero.', $player);
return;
}
try {
$this->maniaControl->getClient()
->setModeScriptSettings(array(self::SCRIPT_SETTING_MAP_POINTS_LIMIT => $value));
$this->maniaControl->getClient()->setModeScriptSettings(array(self::SCRIPT_SETTING_MAP_POINTS_LIMIT => $value));
$this->staticMode = true;
$this->lastPointLimit = $value;
$this->maniaControl->getChat()
->sendInformation("PointLimit changed to: {$value} (Fixed)");
$this->maniaControl->getChat()->sendInformation("PointLimit changed to: {$value} (Fixed)");
} catch (GameModeException $exception) {
$this->maniaControl->getChat()
->sendException($exception, $player);
$this->maniaControl->getChat()->sendException($exception, $player);
}
} else {
$this->maniaControl->getChat()
->sendUsageInfo('Example: //setpointlimit 150', $player);
$this->maniaControl->getChat()->sendUsageInfo('Example: //setpointlimit 150', $player);
}
}
}
@ -248,11 +220,9 @@ class DynamicPointLimitPlugin implements CallbackListener, CommandListener, Plug
if ($this->staticMode && !is_null($this->lastPointLimit)) {
// Refresh static point limit in case it has been reset
try {
$this->maniaControl->getClient()
->setModeScriptSettings(array(self::SCRIPT_SETTING_MAP_POINTS_LIMIT => $this->lastPointLimit));
$this->maniaControl->getClient()->setModeScriptSettings(array(self::SCRIPT_SETTING_MAP_POINTS_LIMIT => $this->lastPointLimit));
$message = "PointLimit fixed at {$this->lastPointLimit}.";
$this->maniaControl->getChat()
->sendInformation($message);
$this->maniaControl->getChat()->sendInformation($message);
} catch (GameModeException $e) {
$this->lastPointLimit = null;
}

View File

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

View File

@ -113,53 +113,32 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$this->initTables();
// Settings
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_TITLE, 'Local Records');
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_POSX, -139.);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_POSY, 75);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_WIDTH, 40.);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_LINESCOUNT, 15);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_LINEHEIGHT, 4.);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WIDGET_ENABLE, true);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_NOTIFY_ONLY_DRIVER, false);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_NOTIFY_BEST_RECORDS, -1);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_ADJUST_OUTER_BORDER, false);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_TITLE, 'Local Records');
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_POSX, -139.);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_POSY, 75);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_WIDTH, 40.);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_LINESCOUNT, 15);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_LINEHEIGHT, 4.);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_ENABLE, true);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NOTIFY_ONLY_DRIVER, false);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NOTIFY_BEST_RECORDS, -1);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_ADJUST_OUTER_BORDER, false);
// Callbacks
$this->maniaControl->getTimerManager()
->registerTimerListening($this, 'handle1Second', 1000);
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'handle1Second', 1000);
$this->maniaControl->getCallbackManager()
->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleMapBegin');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'handleSettingChanged');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleMapBegin');
$this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'handleSettingChanged');
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(RecordCallback::CHECKPOINT, $this, 'handleCheckpointCallback');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(RecordCallback::LAPFINISH, $this, 'handleLapFinishCallback');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(RecordCallback::FINISH, $this, 'handleFinishCallback');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()->registerCallbackListener(RecordCallback::CHECKPOINT, $this, 'handleCheckpointCallback');
$this->maniaControl->getCallbackManager()->registerCallbackListener(RecordCallback::LAPFINISH, $this, 'handleLapFinishCallback');
$this->maniaControl->getCallbackManager()->registerCallbackListener(RecordCallback::FINISH, $this, 'handleFinishCallback');
$this->maniaControl->getCommandManager()
->registerCommandListener(array('recs', 'records'), $this, 'showRecordsList', false, 'Shows a list of Local Records on the current map.');
$this->maniaControl->getCommandManager()
->registerCommandListener('delrec', $this, 'deleteRecord', true, 'Removes a record from the database.');
$this->maniaControl->getCommandManager()->registerCommandListener(array('recs', 'records'), $this, 'showRecordsList', false, 'Shows a list of Local Records on the current map.');
$this->maniaControl->getCommandManager()->registerCommandListener('delrec', $this, 'deleteRecord', true, 'Removes a record from the database.');
$this->updateManialink = true;
@ -170,8 +149,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
* Initialize needed database tables
*/
private function initTables() {
$mysqli = $this->maniaControl->getDatabase()
->getMysqli();
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_RECORDS . "` (
`index` int(11) NOT NULL AUTO_INCREMENT,
`mapIndex` int(11) NOT NULL,
@ -198,8 +176,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
* @see \ManiaControl\Plugins\Plugin::unload()
*/
public function unload() {
$this->maniaControl->getManialinkManager()
->hideManialink(self::MLID_RECORDS);
$this->maniaControl->getManialinkManager()->hideManialink(self::MLID_RECORDS);
}
/**
@ -218,12 +195,10 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
}
$this->updateManialink = false;
if ($this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_WIDGET_ENABLE)
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_ENABLE)
) {
$manialink = $this->buildManialink();
$this->maniaControl->getManialinkManager()
->sendManialink($manialink);
$this->maniaControl->getManialinkManager()->sendManialink($manialink);
}
}
@ -233,33 +208,20 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
* @return string
*/
private function buildManialink() {
$map = $this->maniaControl->getMapManager()
->getCurrentMap();
$map = $this->maniaControl->getMapManager()->getCurrentMap();
if (!$map) {
return null;
}
$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);
$lines = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_WIDGET_LINESCOUNT);
$lineHeight = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_WIDGET_LINEHEIGHT);
$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);
$lines = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_LINESCOUNT);
$lineHeight = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_LINEHEIGHT);
$labelStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultLabelStyle();
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
$records = $this->getLocalRecords($map);
if (!is_array($records)) {
@ -275,8 +237,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$backgroundQuad = new Quad();
$frame->add($backgroundQuad);
$backgroundQuad->setVAlign($backgroundQuad::TOP);
$adjustOuterBorder = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_ADJUST_OUTER_BORDER);
$adjustOuterBorder = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_ADJUST_OUTER_BORDER);
$height = 7. + ($adjustOuterBorder ? count($records) : $lines) * $lineHeight;
$backgroundQuad->setSize($width * 1.05, $height);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
@ -347,8 +308,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
* @return array
*/
public function getLocalRecords(Map $map, $limit = -1) {
$mysqli = $this->maniaControl->getDatabase()
->getMysqli();
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$limit = ($limit > 0 ? 'LIMIT ' . $limit : '');
$query = "SELECT * FROM (
SELECT recs.*, @rank := @rank + 1 as `rank` FROM `" . self::TABLE_RECORDS . "` recs, (SELECT @rank := 0) ra
@ -386,8 +346,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
if ($setting->value) {
$this->updateManialink = true;
} else {
$this->maniaControl->getManialinkManager()
->hideManialink(self::MLID_RECORDS);
$this->maniaControl->getManialinkManager()->hideManialink(self::MLID_RECORDS);
}
break;
}
@ -432,8 +391,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
return;
}
$map = $this->maniaControl->getMapManager()
->getCurrentMap();
$map = $this->maniaControl->getMapManager()->getCurrentMap();
$checkpointsString = $this->getCheckpoints($callback->player->login);
$this->checkpoints[$callback->login] = array();
@ -449,15 +407,13 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
// Same time
// TODO: respect notify-settings
$message = '$<$fff' . $callback->player->nickname . '$> equalized his/her $<$ff0' . $oldRecord->rank . '.$> Local Record: $<$fff' . Formatter::formatTime($oldRecord->time) . '$>!';
$this->maniaControl->getChat()
->sendInformation('$3c0' . $message);
$this->maniaControl->getChat()->sendInformation('$3c0' . $message);
return;
}
}
// Save time
$mysqli = $this->maniaControl->getDatabase()
->getMysqli();
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$query = "INSERT INTO `" . self::TABLE_RECORDS . "` (
`mapIndex`,
`playerIndex`,
@ -482,10 +438,8 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$newRecord = $this->getLocalRecord($map, $callback->player);
$improvedRank = (!$oldRecord || $newRecord->rank < $oldRecord->rank);
$notifyOnlyDriver = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_NOTIFY_ONLY_DRIVER);
$notifyOnlyBestRecords = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_NOTIFY_BEST_RECORDS);
$notifyOnlyDriver = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NOTIFY_ONLY_DRIVER);
$notifyOnlyBestRecords = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NOTIFY_BEST_RECORDS);
$message = '$3c0';
if ($notifyOnlyDriver) {
@ -506,15 +460,12 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
}
if ($notifyOnlyDriver) {
$this->maniaControl->getChat()
->sendInformation($message, $callback->player);
$this->maniaControl->getChat()->sendInformation($message, $callback->player);
} else if (!$notifyOnlyBestRecords || $newRecord->rank <= $notifyOnlyBestRecords) {
$this->maniaControl->getChat()
->sendInformation($message);
$this->maniaControl->getChat()->sendInformation($message);
}
$this->maniaControl->getCallbackManager()
->triggerCallback(self::CB_LOCALRECORDS_CHANGED, $newRecord);
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_LOCALRECORDS_CHANGED, $newRecord);
}
/**
@ -546,8 +497,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
* @return mixed
*/
private function getLocalRecord(Map $map, Player $player) {
$mysqli = $this->maniaControl->getDatabase()
->getMysqli();
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$query = "SELECT records.* FROM (
SELECT recs.*, @rank := @rank + 1 as `rank` FROM `" . self::TABLE_RECORDS . "` recs, (SELECT @rank := 0) ra
WHERE recs.`mapIndex` = {$map->index}
@ -586,8 +536,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$actionId = $callback[1][2];
$login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager()
->getPlayer($login);
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
if ($actionId === self::ACTION_SHOW_RECORDSLIST) {
$this->showRecordsList(array(), $player);
@ -601,16 +550,11 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
* @param Player $player
*/
public function showRecordsList(array $chat, Player $player) {
$width = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getListWidgetsWidth();
$height = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getListWidgetsHeight();
$width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
$height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
// get PlayerList
$records = $this->getLocalRecords($this->maniaControl->getMapManager()
->getCurrentMap());
$records = $this->getLocalRecords($this->maniaControl->getMapManager()->getCurrentMap());
// create manialink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
@ -619,9 +563,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$script->addFeature($paging);
// Main frame
$frame = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultListFrame($script, $paging);
$frame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultListFrame($script, $paging);
$maniaLink->add($frame);
// Start offsets
@ -629,9 +571,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$posY = $height / 2;
// Predefine Description Label
$descriptionLabel = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultDescriptionLabel();
$descriptionLabel = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultDescriptionLabel();
$frame->add($descriptionLabel);
// Headline
@ -639,8 +579,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$frame->add($headFrame);
$headFrame->setY($posY - 5);
$array = array('Rank' => $posX + 5, 'Nickname' => $posX + 18, 'Login' => $posX + 70, 'Time' => $posX + 101);
$this->maniaControl->getManialinkManager()
->labelLine($headFrame, $array);
$this->maniaControl->getManialinkManager()->labelLine($headFrame, $array);
$index = 0;
$posY = $height / 2 - 10;
@ -669,8 +608,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$listRecord->nickname = $listRecord->login;
}
$array = array($listRecord->rank => $posX + 5, '$fff' . $listRecord->nickname => $posX + 18, $listRecord->login => $posX + 70, Formatter::formatTime($listRecord->time) => $posX + 101);
$this->maniaControl->getManialinkManager()
->labelLine($recordFrame, $array);
$this->maniaControl->getManialinkManager()->labelLine($recordFrame, $array);
$recordFrame->setY($posY);
@ -679,8 +617,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
}
// Render and display xml
$this->maniaControl->getManialinkManager()
->displayWidget($maniaLink, $player, 'PlayerList');
$this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'PlayerList');
}
/**
@ -690,33 +627,27 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
* @param Player $player
*/
public function deleteRecord(array $chat, Player $player) {
if (!$this->maniaControl->getAuthenticationManager()
->checkRight($player, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)
if (!$this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)
) {
$this->maniaControl->getAuthenticationManager()
->sendNotAllowed($player);
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return;
}
$commandParts = explode(' ', $chat[1][2]);
if (count($commandParts) < 2) {
$this->maniaControl->getChat()
->sendUsageInfo('Missing Record ID! (Example: //delrec 3)', $player);
$this->maniaControl->getChat()->sendUsageInfo('Missing Record ID! (Example: //delrec 3)', $player);
return;
}
$recordId = (int)$commandParts[1];
$currentMap = $this->maniaControl->getMapManager()
->getCurrentMap();
$currentMap = $this->maniaControl->getMapManager()->getCurrentMap();
$records = $this->getLocalRecords($currentMap);
if (count($records) < $recordId) {
$this->maniaControl->getChat()
->sendError('Cannot remove record $<$fff' . $recordId . '$>!', $player);
$this->maniaControl->getChat()->sendError('Cannot remove record $<$fff' . $recordId . '$>!', $player);
return;
}
$mysqli = $this->maniaControl->getDatabase()
->getMysqli();
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$query = "DELETE FROM `" . self::TABLE_RECORDS . "`
WHERE `mapIndex` = {$currentMap->index}
AND `playerIndex` = {$player->index};";
@ -726,9 +657,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
return;
}
$this->maniaControl->getCallbackManager()
->triggerCallback(self::CB_LOCALRECORDS_CHANGED, null);
$this->maniaControl->getChat()
->sendInformation('Record no. $<$fff' . $recordId . '$> has been removed!');
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_LOCALRECORDS_CHANGED, null);
$this->maniaControl->getChat()->sendInformation('Record no. $<$fff' . $recordId . '$> has been removed!');
}
}

View File

@ -100,32 +100,22 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$this->initTables();
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_MIN_HITS_RATIO_RANKING, 100);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_MIN_HITS_POINTS_RANKING, 15);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MIN_HITS_RATIO_RANKING, 100);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MIN_HITS_POINTS_RANKING, 15);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_MIN_REQUIRED_RECORDS, 3);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_MAX_STORED_RECORDS, 50);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MIN_REQUIRED_RECORDS, 3);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAX_STORED_RECORDS, 50);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_RANKING_TYPE, $this->getRankingsTypeArray());
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_RANKING_TYPE, $this->getRankingsTypeArray());
// Callbacks
$this->maniaControl->getCallbackManager()
->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleEndMap');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleEndMap');
// Commands
$this->maniaControl->getCommandManager()
->registerCommandListener('rank', $this, 'command_showRank', false, 'Shows your current ServerRank.');
$this->maniaControl->getCommandManager()
->registerCommandListener('nextrank', $this, 'command_nextRank', false, 'Shows the person in front of you in the ServerRanking.');
$this->maniaControl->getCommandManager()
->registerCommandListener(array('topranks', 'top100'), $this, 'command_topRanks', false, 'Shows an overview of the best-ranked 100 players.');
$this->maniaControl->getCommandManager()->registerCommandListener('rank', $this, 'command_showRank', false, 'Shows your current ServerRank.');
$this->maniaControl->getCommandManager()->registerCommandListener('nextrank', $this, 'command_nextRank', false, 'Shows the person in front of you in the ServerRanking.');
$this->maniaControl->getCommandManager()->registerCommandListener(array('topranks', 'top100'), $this, 'command_topRanks', false, 'Shows an overview of the best-ranked 100 players.');
// TODO: only update records count
$this->resetRanks();
@ -138,12 +128,9 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
* @return array[]
*/
private function getRankingsTypeArray() {
$script = $this->maniaControl->getClient()
->getScriptName();
$script = $this->maniaControl->getClient()->getScriptName();
if ($this->maniaControl->getMapManager()
->getCurrentMap()
->getGame() === 'tm'
if ($this->maniaControl->getMapManager()->getCurrentMap()->getGame() === 'tm'
) {
//TODO also add obstacle here as default
return array(self::RANKING_TYPE_RECORDS, self::RANKING_TYPE_POINTS, self::RANKING_TYPE_RATIOS);
@ -158,8 +145,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
* Create necessary database tables
*/
private function initTables() {
$mysqli = $this->maniaControl->getDatabase()
->getMysqli();
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_RANK . "` (
`PlayerIndex` int(11) NOT NULL,
`Rank` int(11) NOT NULL,
@ -177,8 +163,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
* Resets and rebuilds the Ranking
*/
private function resetRanks() {
$mysqli = $this->maniaControl->getDatabase()
->getMysqli();
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
// Erase old Average Data
$query = "TRUNCATE TABLE `" . self::TABLE_RANK . "`;";
@ -187,20 +172,15 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
trigger_error($mysqli->error);
}
$type = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_RANKING_TYPE);
$type = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_RANKING_TYPE);
switch ($type) {
case self::RANKING_TYPE_RATIOS:
$minHits = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MIN_HITS_RATIO_RANKING);
$minHits = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MIN_HITS_RATIO_RANKING);
$hits = $this->maniaControl->getStatisticManager()
->getStatsRanking(StatisticCollector::STAT_ON_HIT, -1, $minHits);
$killDeathRatios = $this->maniaControl->getStatisticManager()
->getStatsRanking(StatisticManager::SPECIAL_STAT_KD_RATIO);
$accuracies = $this->maniaControl->getStatisticManager()
->getStatsRanking(StatisticManager::SPECIAL_STAT_LASER_ACC);
$hits = $this->maniaControl->getStatisticManager()->getStatsRanking(StatisticCollector::STAT_ON_HIT, -1, $minHits);
$killDeathRatios = $this->maniaControl->getStatisticManager()->getStatsRanking(StatisticManager::SPECIAL_STAT_KD_RATIO);
$accuracies = $this->maniaControl->getStatisticManager()->getStatsRanking(StatisticManager::SPECIAL_STAT_LASER_ACC);
$ranks = array();
foreach ($hits as $login => $hitCount) {
@ -214,24 +194,19 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
break;
case self::RANKING_TYPE_POINTS:
$minHits = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MIN_HITS_POINTS_RANKING);
$ranks = $this->maniaControl->getStatisticManager()
->getStatsRanking(StatisticCollector::STAT_ON_HIT, -1, $minHits);
$minHits = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MIN_HITS_POINTS_RANKING);
$ranks = $this->maniaControl->getStatisticManager()->getStatsRanking(StatisticCollector::STAT_ON_HIT, -1, $minHits);
break;
case self::RANKING_TYPE_RECORDS:
// TODO: verify workable status
/** @var LocalRecordsPlugin $localRecordsPlugin */
$localRecordsPlugin = $this->maniaControl->getPluginManager()
->getPlugin(__NAMESPACE__ . '\LocalRecordsPlugin');
$localRecordsPlugin = $this->maniaControl->getPluginManager()->getPlugin(__NAMESPACE__ . '\LocalRecordsPlugin');
if (!$localRecordsPlugin) {
return;
}
$requiredRecords = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MIN_REQUIRED_RECORDS);
$maxRecords = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MAX_STORED_RECORDS);
$requiredRecords = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MIN_REQUIRED_RECORDS);
$maxRecords = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAX_STORED_RECORDS);
$query = "SELECT `playerIndex`, COUNT(*) AS `Cnt`
FROM `" . LocalRecordsPlugin::TABLE_RECORDS . "`
@ -245,8 +220,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
}
$result->free_result();
$maps = $this->maniaControl->getMapManager()
->getMaps();
$maps = $this->maniaControl->getMapManager()->getMaps();
foreach ($maps as $map) {
$records = $localRecordsPlugin->getLocalRecords($map, $maxRecords);
@ -321,17 +295,14 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
public function showRank(Player $player) {
$rankObj = $this->getRank($player);
$type = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_RANKING_TYPE);
$type = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_RANKING_TYPE);
$message = '';
if ($rankObj) {
switch ($type) {
case self::RANKING_TYPE_RATIOS:
$killDeathRatio = $this->maniaControl->getStatisticManager()
->getStatisticData(StatisticManager::SPECIAL_STAT_KD_RATIO, $player->index);
$accuracy = $this->maniaControl->getStatisticManager()
->getStatisticData(StatisticManager::SPECIAL_STAT_LASER_ACC, $player->index);
$killDeathRatio = $this->maniaControl->getStatisticManager()->getStatisticData(StatisticManager::SPECIAL_STAT_KD_RATIO, $player->index);
$accuracy = $this->maniaControl->getStatisticManager()->getStatisticData(StatisticManager::SPECIAL_STAT_LASER_ACC, $player->index);
$message = '$0f3Your Server rank is $<$ff3' . $rankObj->rank . '$> / $<$fff' . $this->recordCount . '$> (K/D: $<$fff' . round($killDeathRatio, 2) . '$> Acc: $<$fff' . round($accuracy * 100) . '%$>)';
break;
case self::RANKING_TYPE_POINTS:
@ -343,23 +314,19 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
} else {
switch ($type) {
case self::RANKING_TYPE_RATIOS:
$minHits = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MIN_HITS_RATIO_RANKING);
$minHits = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MIN_HITS_RATIO_RANKING);
$message = '$0f3 You must make $<$fff' . $minHits . '$> Hits on this server before receiving a rank...';
break;
case self::RANKING_TYPE_POINTS:
$minPoints = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MIN_HITS_POINTS_RANKING);
$minPoints = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MIN_HITS_POINTS_RANKING);
$message = '$0f3 You must make $<$fff' . $minPoints . '$> Hits on this server before receiving a rank...';
break;
case self::RANKING_TYPE_RECORDS:
$minRecords = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MIN_REQUIRED_RECORDS);
$minRecords = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MIN_REQUIRED_RECORDS);
$message = '$0f3 You need $<$fff' . $minRecords . '$> Records on this server before receiving a rank...';
}
}
$this->maniaControl->getChat()
->sendChat($message, $player);
$this->maniaControl->getChat()->sendChat($message, $player);
}
/**
@ -370,8 +337,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
*/
private function getRank(Player $player) {
//TODO setting global from db or local
$mysqli = $this->maniaControl->getDatabase()
->getMysqli();
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$query = "SELECT * FROM `" . self::TABLE_RANK . "`
WHERE `PlayerIndex` = {$player->index};";
@ -404,14 +370,12 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
if ($rankObject->rank > 1) {
$nextRank = $this->getNextRank($player);
$nextPlayer = $this->maniaControl->getPlayerManager()
->getPlayerByIndex($nextRank->playerIndex);
$nextPlayer = $this->maniaControl->getPlayerManager()->getPlayerByIndex($nextRank->playerIndex);
$message = '$0f3The next better ranked player is $fff' . $nextPlayer->nickname;
} else {
$message = '$0f3No better ranked player :-)';
}
$this->maniaControl->getChat()
->sendChat($message, $player);
$this->maniaControl->getChat()->sendChat($message, $player);
return true;
}
@ -429,8 +393,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
}
$nextRank = $rankObject->rank - 1;
$mysqli = $this->maniaControl->getDatabase()
->getMysqli();
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$query = "SELECT * FROM `" . self::TABLE_RANK . "`
WHERE `Rank` = {$nextRank};";
$result = $mysqli->query($query);
@ -454,8 +417,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
public function handleEndMap() {
$this->resetRanks();
foreach ($this->maniaControl->getPlayerManager()
->getPlayers() as $player) {
foreach ($this->maniaControl->getPlayerManager()->getPlayers() as $player) {
if ($player->isFakePlayer()) {
continue;
}
@ -464,8 +426,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
}
// Trigger callback
$this->maniaControl->getCallbackManager()
->triggerCallback(self::CB_RANK_BUILT);
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_RANK_BUILT);
}
/**
@ -487,8 +448,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
public function command_nextRank(array $chatCallback, Player $player) {
if (!$this->showNextRank($player)) {
$message = '$0f3You need to have a ServerRank first!';
$this->maniaControl->getChat()
->sendChat($message, $player);
$this->maniaControl->getChat()->sendChat($message, $player);
}
}
@ -510,20 +470,15 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
private function showTopRanksList(Player $player) {
$query = "SELECT * FROM `" . self::TABLE_RANK . "`
ORDER BY `Rank` ASC LIMIT 0, 100;";
$mysqli = $this->maniaControl->getDatabase()
->getMysqli();
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$result = $mysqli->query($query);
if ($mysqli->error) {
trigger_error($mysqli->error);
return;
}
$width = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getListWidgetsWidth();
$height = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getListWidgetsHeight();
$width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
$height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
// create manialink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
@ -532,9 +487,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$script->addFeature($paging);
// Main frame
$frame = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultListFrame($script, $paging);
$frame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultListFrame($script, $paging);
$maniaLink->add($frame);
// Start offsets
@ -542,9 +495,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$posY = $height / 2;
//Predefine description Label
$descriptionLabel = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultDescriptionLabel();
$descriptionLabel = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultDescriptionLabel();
$frame->add($descriptionLabel);
// Headline
@ -552,8 +503,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$frame->add($headFrame);
$headFrame->setY($posY - 5);
$array = array('$oRank' => $posX + 5, '$oNickname' => $posX + 18, '$oAverage' => $posX + 70);
$this->maniaControl->getManialinkManager()
->labelLine($headFrame, $array);
$this->maniaControl->getManialinkManager()->labelLine($headFrame, $array);
$index = 1;
$posY -= 10;
@ -579,19 +529,16 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$lineQuad->setZ(0.001);
}
$playerObject = $this->maniaControl->getPlayerManager()
->getPlayerByIndex($rankedPlayer->PlayerIndex);
$playerObject = $this->maniaControl->getPlayerManager()->getPlayerByIndex($rankedPlayer->PlayerIndex);
$array = array($rankedPlayer->Rank => $posX + 5, $playerObject->nickname => $posX + 18, (string)round($rankedPlayer->Avg, 2) => $posX + 70);
$this->maniaControl->getManialinkManager()
->labelLine($playerFrame, $array);
$this->maniaControl->getManialinkManager()->labelLine($playerFrame, $array);
$posY -= 4;
$index++;
}
// Render and display xml
$this->maniaControl->getManialinkManager()
->displayWidget($maniaLink, $player, 'TopRanks');
$this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'TopRanks');
}
}

View File

@ -123,68 +123,40 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
$this->maniaControl = $maniaControl;
// Set CustomUI Setting
$this->maniaControl->getManialinkManager()
->getCustomUIManager()
->setChallengeInfoVisible(false);
$this->maniaControl->getManialinkManager()->getCustomUIManager()->setChallengeInfoVisible(false);
// Callbacks
$this->maniaControl->getCallbackManager()
->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleOnBeginMap');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleOnEndMap');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'updateWidgets');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(PlayerManager::CB_PLAYERINFOCHANGED, $this, 'updateWidgets');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'updateSettings');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleOnBeginMap');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleOnEndMap');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'updateWidgets');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERINFOCHANGED, $this, 'updateWidgets');
$this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'updateSettings');
// Settings
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED, true);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_MAP_WIDGET_POSX, 160 - 20);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_MAP_WIDGET_POSY, 90 - 4.5);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_MAP_WIDGET_WIDTH, 40);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_MAP_WIDGET_HEIGHT, 9.);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED, true);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAP_WIDGET_POSX, 160 - 20);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAP_WIDGET_POSY, 90 - 4.5);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAP_WIDGET_WIDTH, 40);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAP_WIDGET_HEIGHT, 9.);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED, true);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_SERVERINFO_WIDGET_POSX, -160 + 17.5);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_SERVERINFO_WIDGET_POSY, 90 - 4.5);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_SERVERINFO_WIDGET_WIDTH, 35);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_SERVERINFO_WIDGET_HEIGHT, 9.);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED, true);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SERVERINFO_WIDGET_POSX, -160 + 17.5);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SERVERINFO_WIDGET_POSY, 90 - 4.5);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SERVERINFO_WIDGET_WIDTH, 35);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SERVERINFO_WIDGET_HEIGHT, 9.);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_NEXTMAP_WIDGET_ACTIVATED, true);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_NEXTMAP_WIDGET_POSX, 160 - 20);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_NEXTMAP_WIDGET_POSY, 90 - 25.5);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_NEXTMAP_WIDGET_WIDTH, 40);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_NEXTMAP_WIDGET_HEIGHT, 12.);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NEXTMAP_WIDGET_ACTIVATED, true);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NEXTMAP_WIDGET_POSX, 160 - 20);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NEXTMAP_WIDGET_POSY, 90 - 25.5);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NEXTMAP_WIDGET_WIDTH, 40);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NEXTMAP_WIDGET_HEIGHT, 12.);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED, true);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_CLOCK_WIDGET_POSX, 160 - 5);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_CLOCK_WIDGET_POSY, 90 - 11);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_CLOCK_WIDGET_WIDTH, 10);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_CLOCK_WIDGET_HEIGHT, 5.5);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_CLOCK_WIDGET_ACTIVATED, true);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_CLOCK_WIDGET_POSX, 160 - 5);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_CLOCK_WIDGET_POSY, 90 - 11);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_CLOCK_WIDGET_WIDTH, 10);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_CLOCK_WIDGET_HEIGHT, 5.5);
$this->displayWidgets();
@ -196,20 +168,16 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
*/
private function displayWidgets() {
// Display Map Widget
if ($this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MAP_WIDGET_ACTIVATED)
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAP_WIDGET_ACTIVATED)
) {
$this->maniaControl->getClient()
->triggerModeScriptEvent("Siege_SetProgressionLayerPosition", array("160.", "-67.", "0."));
$this->maniaControl->getClient()->triggerModeScriptEvent("Siege_SetProgressionLayerPosition", array("160.", "-67.", "0."));
$this->displayMapWidget();
}
if ($this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)
) {
$this->displayClockWidget();
}
if ($this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)
) {
$this->displayServerInfoWidget();
}
@ -221,20 +189,12 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
* @param string $login
*/
public function displayMapWidget($login = null) {
$posX = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MAP_WIDGET_POSX);
$posY = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MAP_WIDGET_POSY);
$width = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MAP_WIDGET_WIDTH);
$height = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MAP_WIDGET_HEIGHT);
$quadStyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultQuadSubstyle();
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAP_WIDGET_POSX);
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAP_WIDGET_POSY);
$width = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAP_WIDGET_WIDTH);
$height = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAP_WIDGET_HEIGHT);
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
$maniaLink = new ManiaLink(self::MLID_MAP_WIDGET);
$script = new Script();
@ -253,8 +213,7 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$backgroundQuad->addMapInfoFeature();
$map = $this->maniaControl->getMapManager()
->getCurrentMap();
$map = $this->maniaControl->getMapManager()->getCurrentMap();
$label = new Label_Text();
$frame->add($label);
@ -276,20 +235,15 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
if (isset($map->mx->pageurl)) {
$quad = new Quad();
$frame->add($quad);
$quad->setImageFocus($this->maniaControl->getManialinkManager()
->getIconManager()
->getIcon(IconManager::MX_ICON_MOVER));
$quad->setImage($this->maniaControl->getManialinkManager()
->getIconManager()
->getIcon(IconManager::MX_ICON));
$quad->setImageFocus($this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON_MOVER));
$quad->setImage($this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON));
$quad->setPosition(-$width / 2 + 4, -1.5, -0.5);
$quad->setSize(4, 4);
$quad->setUrl($map->mx->pageurl);
}
// Send manialink
$this->maniaControl->getManialinkManager()
->sendManialink($maniaLink, $login);
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $login);
}
/**
@ -298,20 +252,12 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
* @param bool $login
*/
public function displayClockWidget($login = false) {
$posX = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_CLOCK_WIDGET_POSX);
$posY = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_CLOCK_WIDGET_POSY);
$width = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_CLOCK_WIDGET_WIDTH);
$height = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_CLOCK_WIDGET_HEIGHT);
$quadStyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultQuadSubstyle();
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_CLOCK_WIDGET_POSX);
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_CLOCK_WIDGET_POSY);
$width = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_CLOCK_WIDGET_WIDTH);
$height = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_CLOCK_WIDGET_HEIGHT);
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
$maniaLink = new ManiaLink(self::MLID_CLOCK_WIDGET);
@ -336,8 +282,7 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
$label->addClockFeature(false);
// Send manialink
$this->maniaControl->getManialinkManager()
->sendManialink($maniaLink, $login);
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $login);
}
/**
@ -346,20 +291,12 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
* @param string $login
*/
public function displayServerInfoWidget($login = null) {
$posX = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_POSX);
$posY = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_POSY);
$width = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_WIDTH);
$height = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_HEIGHT);
$quadStyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultQuadSubstyle();
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_POSX);
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_POSY);
$width = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_WIDTH);
$height = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_HEIGHT);
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
$maniaLink = new ManiaLink(self::MLID_SERVERINFO_WIDGET);
@ -375,18 +312,13 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
$backgroundQuad->setSize($width, $height);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$serverName = $this->maniaControl->getClient()
->getServerName();
$serverName = $this->maniaControl->getClient()->getServerName();
$playerCount = $this->maniaControl->getPlayerManager()
->getPlayerCount(true);
$maxPlayers = $this->maniaControl->getClient()
->getMaxPlayers();
$playerCount = $this->maniaControl->getPlayerManager()->getPlayerCount(true);
$maxPlayers = $this->maniaControl->getClient()->getMaxPlayers();
$spectatorCount = $this->maniaControl->getPlayerManager()
->getSpectatorCount();
$maxSpectators = $this->maniaControl->getClient()
->getMaxSpectators();
$spectatorCount = $this->maniaControl->getPlayerManager()->getSpectatorCount();
$maxSpectators = $this->maniaControl->getClient()->getMaxSpectators();
$label = new Label_Text();
$frame->add($label);
@ -438,8 +370,7 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
$quad->setManialink('maniacontrol?favorite=' . urlencode($this->maniaControl->getServer()->login));
// Send manialink
$this->maniaControl->getManialinkManager()
->sendManialink($maniaLink, $login);
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $login);
}
/**
@ -447,8 +378,7 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
*/
public function unload() {
//Restore Siege Progression Layer
$this->maniaControl->getClient()
->triggerModeScriptEvent('Siege_SetProgressionLayerPosition', array("160.", "90.", "0."));
$this->maniaControl->getClient()->triggerModeScriptEvent('Siege_SetProgressionLayerPosition', array("160.", "90.", "0."));
$this->closeWidget(self::MLID_CLOCK_WIDGET);
$this->closeWidget(self::MLID_SERVERINFO_WIDGET);
@ -462,16 +392,14 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
* @param string $widgetId
*/
public function closeWidget($widgetId) {
$this->maniaControl->getManialinkManager()
->hideManialink($widgetId);
$this->maniaControl->getManialinkManager()->hideManialink($widgetId);
}
/**
* Handle Begin Map Callback
*/
public function handleOnBeginMap() {
if ($this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MAP_WIDGET_ACTIVATED)
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAP_WIDGET_ACTIVATED)
) {
$this->displayMapWidget();
}
@ -482,8 +410,7 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
* Handle End Map Callback
*/
public function handleOnEndMap() {
if ($this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_NEXTMAP_WIDGET_ACTIVATED)
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NEXTMAP_WIDGET_ACTIVATED)
) {
$this->displayNextMapWidget();
}
@ -495,23 +422,13 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
* @param string $login
*/
public function displayNextMapWidget($login = null) {
$posX = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_NEXTMAP_WIDGET_POSX);
$posY = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_NEXTMAP_WIDGET_POSY);
$width = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_NEXTMAP_WIDGET_WIDTH);
$height = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_NEXTMAP_WIDGET_HEIGHT);
$quadStyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultQuadSubstyle();
$labelStyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultLabelStyle();
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NEXTMAP_WIDGET_POSX);
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NEXTMAP_WIDGET_POSY);
$width = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NEXTMAP_WIDGET_WIDTH);
$height = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NEXTMAP_WIDGET_HEIGHT);
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
$labelStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultLabelStyle();
$maniaLink = new ManiaLink(self::MLID_NEXTMAP_WIDGET);
@ -528,9 +445,7 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
// Check if the Next Map is a queued Map
$queuedMap = $this->maniaControl->getMapManager()
->getMapQueue()
->getNextMap();
$queuedMap = $this->maniaControl->getMapManager()->getMapQueue()->getNextMap();
/**
* @var Player $requester
@ -538,8 +453,7 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
$requester = null;
// if the nextmap is not a queued map, get it from map info
if (!$queuedMap) {
$map = $this->maniaControl->getClient()
->getNextMapInfo();
$map = $this->maniaControl->getClient()->getNextMapInfo();
$name = Formatter::stripDirtyCodes($map->name);
$author = $map->author;
} else {
@ -585,8 +499,7 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
}
// Send manialink
$this->maniaControl->getManialinkManager()
->sendManialink($maniaLink, $login);
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $login);
}
/**
@ -596,18 +509,15 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
*/
public function handlePlayerConnect(Player $player) {
// Display Map Widget
if ($this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MAP_WIDGET_ACTIVATED)
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAP_WIDGET_ACTIVATED)
) {
$this->displayMapWidget($player->login);
}
if ($this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_CLOCK_WIDGET_ACTIVATED)
) {
$this->displayClockWidget($player->login);
}
if ($this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)
) {
$this->displayServerInfoWidget();
}
@ -628,8 +538,7 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
* Update Widget on certain callbacks
*/
public function updateWidgets() {
if ($this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SERVERINFO_WIDGET_ACTIVATED)
) {
$this->displayServerInfoWidget();
}

View File

@ -358,8 +358,9 @@ class QueuePlugin implements CallbackListener, ManialinkPageAnswerListener, Time
/** @var Player $playerObj */
foreach ($this->maniaControl->playerManager->getPlayers() as $playerObj) {
if($playerObj->isSpectator)
if ($playerObj->isSpectator) {
continue;
}
if (!isset($teams[$playerObj->teamId])) {
$teams[$playerObj->teamId] = 1;