From c7d325c2165baf5831d042d703fb15654d51631f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Mon, 6 Jan 2014 16:14:49 +0100 Subject: [PATCH] - updates for new server properties - refactored various imports --- .../core/Configurators/ScriptSettings.php | 4 +- .../core/Configurators/ServerSettings.php | 4 +- application/core/ManiaControl.php | 5 - application/core/Maps/MapManager.php | 8 +- application/core/Players/PlayerActions.php | 196 +++++++++--------- application/core/Players/PlayerCommands.php | 112 +++++----- application/core/Players/PlayerManager.php | 171 ++++++++------- application/core/Server/ServerCommands.php | 2 +- .../core/Statistics/StatisticCollector.php | 6 +- .../core/Statistics/StatisticManager.php | 2 +- application/plugins/Donations.php | 3 +- application/plugins/Karma.php | 3 +- application/plugins/WidgetPlugin.php | 3 +- 13 files changed, 251 insertions(+), 268 deletions(-) diff --git a/application/core/Configurators/ScriptSettings.php b/application/core/Configurators/ScriptSettings.php index 34ee7b39..2b1c367e 100644 --- a/application/core/Configurators/ScriptSettings.php +++ b/application/core/Configurators/ScriptSettings.php @@ -395,8 +395,6 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener { return false; } - $serverIndex = $this->maniaControl->server->getIndex(); - // Notifications $settingsCount = count($newSettings); $settingIndex = 0; @@ -411,7 +409,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener { } // Add To Database - $statement->bind_param('iss', $serverIndex, $setting, $value); + $statement->bind_param('iss', $this->maniaControl->server->index, $setting, $value); $statement->execute(); if($statement->error) { trigger_error($statement->error); diff --git a/application/core/Configurators/ServerSettings.php b/application/core/Configurators/ServerSettings.php index 3e3c4caa..5355d1ae 100644 --- a/application/core/Configurators/ServerSettings.php +++ b/application/core/Configurators/ServerSettings.php @@ -351,8 +351,6 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener { return false; } - $serverIndex = $this->maniaControl->server->getIndex(); - // Notifications $settingsCount = count($newSettings); $settingIndex = 0; @@ -360,7 +358,7 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener { // $chatMessage = '$ff0' . $title . ' $<' . $player->nickname . '$> set ScriptSetting' . ($settingsCount > 1 ? 's' : '') . ' '; foreach($newSettings as $setting => $value) { - $statement->bind_param('iss', $serverIndex, $setting, $value); + $statement->bind_param('iss', $this->maniaControl->server->index, $setting, $value); $statement->execute(); if($statement->error) { trigger_error($statement->error); diff --git a/application/core/ManiaControl.php b/application/core/ManiaControl.php index e45c0bcb..47167ba4 100644 --- a/application/core/ManiaControl.php +++ b/application/core/ManiaControl.php @@ -34,14 +34,9 @@ require_once __DIR__ . '/ManiaExchange/mxinfofetcher.inc.php'; require_once __DIR__ . '/ManiaExchange/mxinfosearcher.inc.php'; require_once __DIR__ . '/Manialinks/ManialinkManager.php'; require_once __DIR__ . '/Statistics/StatisticManager.php'; -require_once __DIR__ . '/Maps/Map.php'; require_once __DIR__ . '/Maps/MapManager.php'; -require_once __DIR__ . '/Maps/MapList.php'; -require_once __DIR__ . '/Maps/MapQueue.php'; require_once __DIR__ . '/Players/PlayerManager.php'; -require_once __DIR__ . '/Players/PlayerActions.php'; require_once __DIR__ . '/Plugins/PluginManager.php'; -require_once __DIR__ . '/Players/PlayerList.php'; require_once __DIR__ . '/Server/Server.php'; require_once __DIR__ . '/Settings/SettingManager.php'; require_once __DIR__ . '/UpdateManager.php'; diff --git a/application/core/Maps/MapManager.php b/application/core/Maps/MapManager.php index 8e0a042b..51ce7c7e 100644 --- a/application/core/Maps/MapManager.php +++ b/application/core/Maps/MapManager.php @@ -2,9 +2,6 @@ namespace ManiaControl\Maps; -require_once __DIR__ . '/Map.php'; -require_once __DIR__ . '/MapCommands.php'; - use ManiaControl\FileUtil; use ManiaControl\Formatter; use ManiaControl\ManiaControl; @@ -12,6 +9,11 @@ use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackManager; use MXInfoFetcher; +require_once __DIR__ . '/Map.php'; +require_once __DIR__ . '/MapCommands.php'; +require_once __DIR__ . '/MapList.php'; +require_once __DIR__ . '/MapQueue.php'; + /** * Manager for Maps * diff --git a/application/core/Players/PlayerActions.php b/application/core/Players/PlayerActions.php index 5301f164..c4430b2c 100644 --- a/application/core/Players/PlayerActions.php +++ b/application/core/Players/PlayerActions.php @@ -22,13 +22,13 @@ class PlayerActions { /** * Constants */ - const BLUE_TEAM = 0; - const RED_TEAM = 1; - const SPECTATOR_USER_SELECTABLE = 0; - const SPECTATOR_SPECTATOR = 1; - const SPECTATOR_PLAYER = 2; + const BLUE_TEAM = 0; + const RED_TEAM = 1; + const SPECTATOR_USER_SELECTABLE = 0; + const SPECTATOR_SPECTATOR = 1; + const SPECTATOR_PLAYER = 2; const SPECTATOR_BUT_KEEP_SELECTABLE = 3; - + /** * Private Properties */ @@ -48,96 +48,93 @@ class PlayerActions { * * @param string $adminLogin * @param string $targetLogin - * @param int $teamId + * @param int $teamId */ public function forcePlayerToTeam($adminLogin, $targetLogin, $teamId) { // TODO: get used by playercommands - $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); + $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin); - if(!$admin || !$target) { + if (!$admin || !$target) { return; } $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); - - if($target->isSpectator) { + + if ($target->isSpectator) { $success = $this->maniaControl->client->query('ForceSpectator', $target->login, self::SPECTATOR_PLAYER); - if(!$success) { + if (!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); return; } } - + $success = $this->maniaControl->client->query('ForcePlayerTeam', $target->login, $teamId); - if(!$success) { + if (!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); return; } - + $chatMessage = false; - if($teamId == self::BLUE_TEAM) { + if ($teamId == self::BLUE_TEAM) { $chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Blue-Team!'; - } else if($teamId == self::RED_TEAM) { + } + else if ($teamId == self::RED_TEAM) { $chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Red-Team!'; } - if(!$chatMessage) - return; + if (!$chatMessage) return; $this->maniaControl->chat->sendInformation($chatMessage); $this->maniaControl->log(Formatter::stripCodes($chatMessage)); } - /** * Force a Player to Spectator * * @param string $adminLogin * @param string $targetLogin - * @param int $spectatorState + * @param int $spectatorState */ public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE, $releaseSlot = true) { // TODO: get used by playercommands - $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); + $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin); - $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); - + $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); + $success = $this->maniaControl->client->query('ForceSpectator', $targetLogin, $spectatorState); - if(!$success) { + if (!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); return; } - + $chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> to Spectator!'; $this->maniaControl->chat->sendInformation($chatMessage); $this->maniaControl->log(Formatter::stripCodes($chatMessage)); - + // free player slot - if($releaseSlot) - $this->maniaControl->client->query('SpectatorReleasePlayerSlot', $target->login); + if ($releaseSlot) $this->maniaControl->client->query('SpectatorReleasePlayerSlot', $target->login); } - /** * UnMutes a Player * * @param string $adminLogin * @param string $targetLogin - * @param int $spectatorState + * @param int $spectatorState */ public function unMutePlayer($adminLogin, $targetLogin) { // TODO: playercommand - $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); + $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin); - $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); - + $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); + $success = $this->maniaControl->client->query('UnIgnore', $targetLogin); - + var_dump($success); var_dump($this->maniaControl->client->getResponse()); - - if(!$success) { + + if (!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); return; } - + $chatMessage = $title . ' $<' . $admin->nickname . '$> un-muted $<' . $target->nickname . '$>!'; $this->maniaControl->chat->sendInformation($chatMessage); $this->maniaControl->log(Formatter::stripCodes($chatMessage)); @@ -148,26 +145,25 @@ class PlayerActions { * * @param string $adminLogin * @param string $targetLogin - * @param int $spectatorState + * @param int $spectatorState */ public function mutePlayer($adminLogin, $targetLogin) { // TODO: playercommand - $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); + $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin); - $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); - + $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); + $success = $this->maniaControl->client->query('Ignore', $targetLogin); - if(!$success) { + if (!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); return; } - + $chatMessage = $title . ' $<' . $admin->nickname . '$> muted $<' . $target->nickname . '$>!'; $this->maniaControl->chat->sendInformation($chatMessage); $this->maniaControl->log(Formatter::stripCodes($chatMessage)); } - /** * Warn a Player * @@ -176,35 +172,35 @@ class PlayerActions { */ public function warnPlayer($adminLogin, $targetLogin) { // TODO: chatcommand - $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); + $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin); - $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); - + $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); + // display warning message $message = '$s$f00This is an administrative warning.{br}{br}$gWhatever you wrote or you have done is against {br} our server\'s policy. {br}Not respecting other players, or{br}using offensive language might result in a{br}$f00kick, or ban $ff0the next time. {br}{br}$gThe server administrators.'; $message = preg_split('/{br}/', $message); - - $width = 80; - $height = 50; - $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle(); + + $width = 80; + $height = 50; + $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle(); - + $maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID); - + // mainframe $frame = new Frame(); $maniaLink->add($frame); $frame->setSize($width, $height); $frame->setPosition(0, 10); - + // Background Quad $backgroundQuad = new Quad(); $frame->add($backgroundQuad); $backgroundQuad->setSize($width, $height); $backgroundQuad->setStyles($quadStyle, $quadSubstyle); - + // Add Close Quad (X) $closeQuad = new Quad_Icons64x64_1(); $frame->add($closeQuad); @@ -212,7 +208,7 @@ class PlayerActions { $closeQuad->setSize(6, 6); $closeQuad->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_QuitRace); $closeQuad->setAction(ManialinkManager::ACTION_CLOSEWIDGET); - + // Headline Label $label = new Label_Text(); $frame->add($label); @@ -223,9 +219,9 @@ class PlayerActions { $label->setTextSize(4); $label->setText('Administrative Warning'); $label->setTextColor('F00'); - + $y = $height / 2 - 15; - foreach($message as &$line) { + foreach ($message as &$line) { // Warn Labels $label = new Label_Text(); $frame->add($label); @@ -239,10 +235,10 @@ class PlayerActions { $label->setTextColor('FF0'); $y -= 4; } - + // Display manialink $this->maniaControl->manialinkManager->displayWidget($maniaLink, $target); - + $chatMessage = $title . ' $<' . $admin->nickname . '$> warned $<' . $target->nickname . '$>!'; $this->maniaControl->chat->sendInformation($chatMessage); $this->maniaControl->log(Formatter::stripCodes($chatMessage)); @@ -256,21 +252,22 @@ class PlayerActions { * @param string $message */ public function kickPlayer($adminLogin, $targetLogin, $message = '') { - $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); + $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin); - $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); - - if($target->isFakePlayer()) { + $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); + + if ($target->isFakePlayer()) { $success = $this->maniaControl->client->query('DisconnectFakePlayer', $target->login); - } else { + } + else { $success = $this->maniaControl->client->query('Kick', $target->login, $message); } - - if(!$success) { + + if (!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); return; } - + $chatMessage = $title . ' $<' . $admin->nickname . '$> kicked $<' . $target->nickname . '$>!'; $this->maniaControl->chat->sendInformation($chatMessage); $this->maniaControl->log(Formatter::stripCodes($chatMessage)); @@ -284,17 +281,17 @@ class PlayerActions { * @param string $message */ public function banPlayer($adminLogin, $targetLogin, $message = '') { - $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); + $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin); - $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); - + $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); + $success = $this->maniaControl->client->query('Ban', $target->login, $message); - - if(!$success) { + + if (!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); return; } - + $chatMessage = $title . ' $<' . $admin->nickname . '$> banned $<' . $target->nickname . '$>!'; $this->maniaControl->chat->sendInformation($chatMessage); $this->maniaControl->log(Formatter::stripCodes($chatMessage)); @@ -305,32 +302,34 @@ class PlayerActions { * * @param string $adminLogin * @param string $targetLogin - * @param int $authLevel + * @param int $authLevel */ public function grandAuthLevel($adminLogin, $targetLogin, $authLevel) { - $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); + $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin); - $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); - - if($this->maniaControl->authenticationManager->checkRight($target, $authLevel)) { - $this->maniaControl->chat->sendError('This Player is already ' . $this->maniaControl->authenticationManager->getAuthLevelName($target->authLevel), $admin->login); + $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); + + if ($this->maniaControl->authenticationManager->checkRight($target, $authLevel)) { + $this->maniaControl->chat->sendError( + 'This Player is already ' . $this->maniaControl->authenticationManager->getAuthLevelName($target->authLevel), $admin->login); return; } - + $authLevelName = $this->maniaControl->authenticationManager->getAuthLevelName($authLevel); - - if($this->maniaControl->authenticationManager->checkRight($admin, $authLevel) <= $this->maniaControl->authenticationManager->checkRight($target, $authLevel)) { + + if ($this->maniaControl->authenticationManager->checkRight($admin, $authLevel) <= + $this->maniaControl->authenticationManager->checkRight($target, $authLevel)) { $this->maniaControl->chat->sendError('You don\'t have the permission to add a ' . $authLevelName . '!', $admin->login); return; } - + $success = $this->maniaControl->authenticationManager->grantAuthLevel($target, $authLevel); - - if(!$success) { + + if (!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); return; } - + $chatMessage = $title . ' $<' . $admin->nickname . '$> added $<' . $target->nickname . '$> as $< ' . $authLevelName . '$>!'; $this->maniaControl->chat->sendInformation($chatMessage); $this->maniaControl->log(Formatter::stripCodes($chatMessage)); @@ -343,22 +342,22 @@ class PlayerActions { * @param string $targetLogin */ public function revokeAuthLevel($adminLogin, $targetLogin) { - $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); + $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin); - $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); - - if($this->maniaControl->authenticationManager->checkRight($target, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)) { + $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); + + if ($this->maniaControl->authenticationManager->checkRight($target, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)) { $this->maniaControl->chat->sendError('MasterAdmins can\'t be removed ', $admin->login); return; } - + $success = $this->maniaControl->authenticationManager->grantAuthLevel($target, AuthenticationManager::AUTH_LEVEL_PLAYER); - - if(!$success) { + + if (!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); return; } - + $chatMessage = $title . ' $<' . $admin->nickname . '$> revokes the Rights of $<' . $target->nickname . '$>!'; $this->maniaControl->chat->sendInformation($chatMessage); $this->maniaControl->log(Formatter::stripCodes($chatMessage)); @@ -372,9 +371,8 @@ class PlayerActions { */ public function isPlayerMuted($login) { $this->maniaControl->client->query('GetIgnoreList', 100, 0); - foreach($this->maniaControl->client->getResponse() as $ignoredPlayers) { - if($ignoredPlayers["Login"] == $login) - return true; + foreach ($this->maniaControl->client->getResponse() as $ignoredPlayers) { + if ($ignoredPlayers["Login"] == $login) return true; } return false; } diff --git a/application/core/Players/PlayerCommands.php b/application/core/Players/PlayerCommands.php index 523db3fa..39be1bf3 100644 --- a/application/core/Players/PlayerCommands.php +++ b/application/core/Players/PlayerCommands.php @@ -12,7 +12,7 @@ use ManiaControl\ManiaControl; use ManiaControl\Manialinks\ManialinkPageAnswerListener; /** - * Class offering various admin commands related to players + * Class offering various Admin Commands related to Players * * @author steeffeen & kremsy */ @@ -20,24 +20,23 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener { /** * Constants */ - const ACTION_BALANCE_TEAMS = 'PlayerCommands.BalanceTeams'; + const ACTION_BALANCE_TEAMS = 'PlayerCommands.BalanceTeams'; const ACTION_OPEN_PLAYERLIST = 'PlayerCommands.OpenPlayerList'; - const ACTION_CANCEL_VOTE = 'PlayerCommands.CancelVote'; - + const ACTION_CANCEL_VOTE = 'PlayerCommands.CancelVote'; + /** - * Private properties + * Private Properties */ private $maniaControl = null; - public $playerList = null; /** - * Create a new server commands instance + * Create a new Player Commands Instance * * @param ManiaControl $maniaControl */ public function __construct(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; - + // Register for admin commands $this->maniaControl->commandManager->registerCommandListener('balance', $this, 'command_TeamBalance', true); $this->maniaControl->commandManager->registerCommandListener('teambalance', $this, 'command_TeamBalance', true); @@ -51,29 +50,28 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener { $this->maniaControl->commandManager->registerCommandListener('removebot', $this, 'command_RemoveFakePlayers', true); $this->maniaControl->commandManager->registerCommandListener('addbots', $this, 'command_AddFakePlayers', true); $this->maniaControl->commandManager->registerCommandListener('removebots', $this, 'command_RemoveFakePlayers', true); - $this->maniaControl->commandManager->registerCommandListener('cancel', $this, 'command_CancelVote', true); //TODO remove in other class? - + // TODO: Move into another class + $this->maniaControl->commandManager->registerCommandListener('cancel', $this, 'command_CancelVote', true); + // Register for player chat commands $this->maniaControl->commandManager->registerCommandListener('player', $this, 'command_playerList'); $this->maniaControl->commandManager->registerCommandListener('players', $this, 'command_playerList'); - - $this->playerList = new PlayerList($this->maniaControl); - - //Action Balance Teams + + // Action Balance Teams $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_BALANCE_TEAMS, $this, 'command_TeamBalance'); $itemQuad = new Quad_Icons128x32_1(); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_RT_Team); $itemQuad->setAction(self::ACTION_BALANCE_TEAMS); $this->maniaControl->actionsMenu->addMenuItem($itemQuad, false, 9, 'Balance Teams'); - - //Action cancel Vote + + // Action cancel Vote $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CANCEL_VOTE, $this, 'command_cancelVote'); $itemQuad = new Quad_Icons64x64_1(); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_ArrowRed); $itemQuad->setAction(self::ACTION_CANCEL_VOTE); $this->maniaControl->actionsMenu->addMenuItem($itemQuad, false, 6, 'Cancel Vote'); - - //Action Open Playerlist + + // Action Open Playerlist $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_PLAYERLIST, $this, 'command_playerList'); $itemQuad = new Quad_UIConstruction_Buttons(); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_Author); @@ -84,16 +82,16 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener { /** * Handle //cancelvote command * - * @param array $chatCallback + * @param array $chatCallback * @param Player $player */ public function command_CancelVote(array $chatCallback, Player $player) { - if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { + if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { $this->maniaControl->authenticationManager->sendNotAllowed($player); return; } $success = $this->maniaControl->client->query('CancelVote'); - if(!$success) { + if (!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); return; } @@ -103,16 +101,16 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener { /** * Handle //teambalance command * - * @param array $chatCallback + * @param array $chatCallback * @param Player $player */ public function command_TeamBalance(array $chatCallback, Player $player) { - if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { + if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { $this->maniaControl->authenticationManager->sendNotAllowed($player); return; } $success = $this->maniaControl->client->query('AutoTeamBalance'); - if(!$success) { + if (!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); return; } @@ -122,65 +120,65 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener { /** * Handle //kick command * - * @param array $chat + * @param array $chat * @param Player $player */ public function command_Kick(array $chat, Player $player) { - if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { + if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { $this->maniaControl->authenticationManager->sendNotAllowed($player); return; } $params = explode(' ', $chat[1][2], 3); - if(!isset($params[1])) { + if (!isset($params[1])) { $this->maniaControl->chat->sendUsageInfo('Usage example: //kick login', $player->login); return; } $target = $params[1]; $target = $this->maniaControl->playerManager->getPlayer($target); - if(!$target) { + if (!$target) { $this->maniaControl->chat->sendError("Invalid player login.", $player->login); return; } $message = ''; - if(isset($params[2])) { + if (isset($params[2])) { $message = $params[2]; } - + $this->maniaControl->playerManager->playerActions->kickPlayer($player->login, $target, $message); } /** * Handle //forcespec command * - * @param array $chat + * @param array $chat * @param Player $player */ public function command_ForceSpectator(array $chat, Player $player) { - if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { + if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { $this->maniaControl->authenticationManager->sendNotAllowed($player); return; } $params = explode(' ', $chat[1][2]); - if(!isset($params[1])) { + if (!isset($params[1])) { $this->maniaControl->chat->sendUsageInfo('Usage example: //forcespec login', $player->login); return; } $target = $params[1]; $target = $this->maniaControl->playerManager->getPlayer($target); - if(!$target) { + if (!$target) { $this->maniaControl->chat->sendError("Invalid player login.", $player->login); return; } $type = 3; - if(isset($params[2]) && is_numeric($params[2])) { + if (isset($params[2]) && is_numeric($params[2])) { $type = intval($params[2]); } $success = $this->maniaControl->client->query('ForceSpectator', $target->login, $type); - if(!$success) { + if (!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); return; } - if($type != 1) { + if ($type != 1) { $this->maniaControl->client->query('ForceSpectator', $target->login, 0); } $this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> forced $<' . $target->nickname . '$> to spectator!'); @@ -189,35 +187,35 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener { /** * Handle //forceplay command * - * @param array $chat + * @param array $chat * @param Player $player */ public function command_ForcePlayer(array $chat, Player $player) { - if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { + if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { $this->maniaControl->authenticationManager->sendNotAllowed($player); return; } $params = explode(' ', $chat[1][2]); - if(!isset($params[1])) { + if (!isset($params[1])) { $this->maniaControl->chat->sendUsageInfo('Usage example: //forceplay login', $player->login); return; } $target = $params[1]; $target = $this->maniaControl->playerManager->getPlayer($target); - if(!$target) { + if (!$target) { $this->maniaControl->chat->sendError("Invalid player login.", $player->login); return; } $type = 2; - if(isset($params[2]) && is_numeric($params[2])) { + if (isset($params[2]) && is_numeric($params[2])) { $type = intval($params[2]); } $success = $this->maniaControl->client->query('ForceSpectator', $target->login, 2); - if(!$success) { + if (!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); return; } - if($type != 1) { + if ($type != 1) { $this->maniaControl->client->query('ForceSpectator', $target->login, 0); } $this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> forced $<' . $target->nickname . '$> to player!'); @@ -226,26 +224,26 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener { /** * Handle //addfakeplayers command * - * @param array $chatCallback + * @param array $chatCallback * @param Player $player */ public function command_AddFakePlayers(array $chatCallback, Player $player) { - if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) { + if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) { $this->maniaControl->authenticationManager->sendNotAllowed($player); return; } - $amount = 1; + $amount = 1; $messageParts = explode(' ', $chatCallback[1][2]); - if(isset($messageParts[1]) && is_numeric($messageParts[1])) { + if (isset($messageParts[1]) && is_numeric($messageParts[1])) { $amount = intval($messageParts[1]); } $success = true; - for($i = 0; $i < $amount; $i++) { - if(!$this->maniaControl->client->query('ConnectFakePlayer')) { + for ($i = 0; $i < $amount; $i++) { + if (!$this->maniaControl->client->query('ConnectFakePlayer')) { $success = false; } } - if(!$success) { + if (!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); return; } @@ -255,16 +253,16 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener { /** * Handle //removefakeplayers command * - * @param array $chatCallback + * @param array $chatCallback * @param Player $player */ public function command_RemoveFakePlayers(array $chatCallback, Player $player) { - if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) { + if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) { $this->maniaControl->authenticationManager->sendNotAllowed($player); return; } $success = $this->maniaControl->client->query('DisconnectFakePlayer', '*'); - if(!$success) { + if (!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); return; } @@ -274,11 +272,11 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener { /** * Handle Player list command * - * @param array $chatCallback + * @param array $chatCallback * @param Player $player */ public function command_playerList(array $chatCallback, Player $player) { - $this->playerList->addPlayerToShownList($player, PlayerList::SHOWN_MAIN_WINDOW); - $this->playerList->showPlayerList($player); + $this->maniaControl->playerManager->playerList->addPlayerToShownList($player, PlayerList::SHOWN_MAIN_WINDOW); + $this->maniaControl->playerManager->playerList->showPlayerList($player); } } diff --git a/application/core/Players/PlayerManager.php b/application/core/Players/PlayerManager.php index 6666c49a..10f98faa 100644 --- a/application/core/Players/PlayerManager.php +++ b/application/core/Players/PlayerManager.php @@ -2,18 +2,20 @@ namespace ManiaControl\Players; -require_once __DIR__ . '/Player.php'; -require_once __DIR__ . '/PlayerCommands.php'; -require_once __DIR__ . '/PlayerDetailed.php'; - use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Formatter; use ManiaControl\ManiaControl; use ManiaControl\Statistics\StatisticManager; +require_once __DIR__ . '/Player.php'; +require_once __DIR__ . '/PlayerActions.php'; +require_once __DIR__ . '/PlayerCommands.php'; +require_once __DIR__ . '/PlayerDetailed.php'; +require_once __DIR__ . '/PlayerList.php'; + /** - * Class managing players + * Class managing Players * * @author kremsy & steeffeen */ @@ -21,23 +23,24 @@ class PlayerManager implements CallbackListener { /** * Constants */ - const CB_PLAYERJOINED = 'PlayerManagerCallback.PlayerJoined'; - const CB_PLAYERDISCONNECTED = 'PlayerManagerCallback.PlayerDisconnected'; - const CB_ONINIT = 'PlayerManagerCallback.OnInit'; - const CB_PLAYERINFOCHANGED = 'PlayerManagerCallback.PlayerInfoChanged'; - const TABLE_PLAYERS = 'mc_players'; + const CB_PLAYERJOINED = 'PlayerManagerCallback.PlayerJoined'; + const CB_PLAYERDISCONNECTED = 'PlayerManagerCallback.PlayerDisconnected'; + const CB_ONINIT = 'PlayerManagerCallback.OnInit'; + const CB_PLAYERINFOCHANGED = 'PlayerManagerCallback.PlayerInfoChanged'; + const TABLE_PLAYERS = 'mc_players'; const SETTING_JOIN_LEAVE_MESSAGES = 'Enable Join & Leave Messages'; - const STAT_JOIN_COUNT = 'Joins'; - const STAT_SERVERTIME = 'Servertime'; - + const STAT_JOIN_COUNT = 'Joins'; + const STAT_SERVERTIME = 'Servertime'; + /** * Public Properties */ public $playerActions = null; public $playerCommands = null; public $playerDetailed = null; - public $playerList = array(); - + public $playerList = null; + public $players = array(); + /** * Private Properties */ @@ -51,20 +54,21 @@ class PlayerManager implements CallbackListener { public function __construct(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; $this->initTables(); - + $this->playerCommands = new PlayerCommands($maniaControl); - $this->playerActions = new PlayerActions($maniaControl); - $this->playerDetailed = new PlayerDetailed($maniaControl); - + $this->playerActions = new PlayerActions($maniaControl); + $this->playerDetailed = new PlayerDetailed($maniaControl); + $this->playerList = new PlayerList($this->maniaControl); + // Init settings $this->maniaControl->settingManager->initSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES, true); - + // Register for callbacks $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'onInit'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCONNECT, $this, 'playerConnect'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this, 'playerDisconnect'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERINFOCHANGED, $this, 'playerInfoChanged'); - + // Define player stats $this->maniaControl->statisticManager->defineStatMetaData(self::STAT_JOIN_COUNT); $this->maniaControl->statisticManager->defineStatMetaData(self::STAT_SERVERTIME, StatisticManager::STAT_TYPE_TIME); @@ -76,8 +80,8 @@ class PlayerManager implements CallbackListener { * @return bool */ private function initTables() { - $mysqli = $this->maniaControl->database->mysqli; - $playerTableQuery = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_PLAYERS . "` ( + $mysqli = $this->maniaControl->database->mysqli; + $playerTableQuery = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_PLAYERS . "` ( `index` int(11) NOT NULL AUTO_INCREMENT, `login` varchar(100) COLLATE utf8_unicode_ci NOT NULL, `nickname` varchar(150) COLLATE utf8_unicode_ci NOT NULL, @@ -88,12 +92,12 @@ class PlayerManager implements CallbackListener { UNIQUE KEY `login` (`login`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Player Data' AUTO_INCREMENT=1;"; $playerTableStatement = $mysqli->prepare($playerTableQuery); - if($mysqli->error) { + if ($mysqli->error) { trigger_error($mysqli->error, E_USER_ERROR); return false; } $playerTableStatement->execute(); - if($playerTableStatement->error) { + if ($playerTableStatement->error) { trigger_error($playerTableStatement->error, E_USER_ERROR); return false; } @@ -109,17 +113,17 @@ class PlayerManager implements CallbackListener { public function onInit(array $callback) { // Add all players $this->maniaControl->client->query('GetPlayerList', 300, 0, 2); - $playerList = $this->maniaControl->client->getResponse(); - foreach($playerList as $playerItem) { - if($playerItem['PlayerId'] <= 0) { + $players = $this->maniaControl->client->getResponse(); + foreach ($players as $playerItem) { + if ($playerItem['PlayerId'] <= 0) { continue; } $this->maniaControl->client->query('GetDetailedPlayerInfo', $playerItem['Login']); $playerInfo = $this->maniaControl->client->getResponse(); - $player = new Player($playerInfo); + $player = new Player($playerInfo); $this->addPlayer($player); } - + // Trigger own callback $this->maniaControl->callbackManager->triggerCallback(self::CB_ONINIT, array(self::CB_ONINIT)); } @@ -133,20 +137,22 @@ class PlayerManager implements CallbackListener { $login = $callback[1][0]; $this->maniaControl->client->query('GetDetailedPlayerInfo', $login); $playerInfo = $this->maniaControl->client->getResponse(); - $player = new Player($playerInfo); - + $player = new Player($playerInfo); + $this->addPlayer($player); - - if($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer()) { - $string = array(0 => '$0f0Player', 1 => '$0f0Moderator', 2 => '$0f0Admin', 3 => '$0f0MasterAdmin', 4 => '$0f0MasterAdmin'); - $chatMessage = '$s$0f0' . $string[$player->authLevel] . ' $fff' . $player->nickname . '$z$s$0f0 Nation:$fff ' . $player->getCountry() . ' $z$s$0f0joined!'; + + if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer()) { + $string = array(0 => '$0f0Player', 1 => '$0f0Moderator', 2 => '$0f0Admin', 3 => '$0f0MasterAdmin', 4 => '$0f0MasterAdmin'); + $chatMessage = '$s$0f0' . $string[$player->authLevel] . ' $fff' . $player->nickname . '$z$s$0f0 Nation:$fff ' . $player->getCountry() . + ' $z$s$0f0joined!'; $this->maniaControl->chat->sendChat($chatMessage); $this->maniaControl->chat->sendInformation('This server uses ManiaControl v' . ManiaControl::VERSION . '!', $player->login); } - - $logMessage = "Player joined: {$player->login} / " . Formatter::stripCodes($player->nickname) . " Nation: " . $player->getCountry() . " IP: {$player->ipAddress}"; + + $logMessage = "Player joined: {$player->login} / " . Formatter::stripCodes($player->nickname) . " Nation: " . $player->getCountry() . + " IP: {$player->ipAddress}"; $this->maniaControl->log($logMessage); - + // Trigger own PlayerJoined callback $this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERJOINED, array(self::CB_PLAYERJOINED, $player)); } @@ -157,21 +163,21 @@ class PlayerManager implements CallbackListener { * @param array $callback */ public function playerDisconnect(array $callback) { - $login = $callback[1][0]; + $login = $callback[1][0]; $player = $this->removePlayer($login); - + // Trigger own callback $this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERDISCONNECTED, array(self::CB_PLAYERDISCONNECTED, $player)); - - if($player == null || $player->isFakePlayer()) { + + if ($player == null || $player->isFakePlayer()) { return; } - - $played = Formatter::formatTimeH(time() - $player->joinTime); + + $played = Formatter::formatTimeH(time() - $player->joinTime); $logMessage = "Player left: {$player->login} / {$player->nickname} Playtime: {$played}"; $this->maniaControl->log(Formatter::stripCodes($logMessage)); - - if($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES)) { + + if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES)) { $this->maniaControl->chat->sendChat('$<' . $player->nickname . '$> $s$0f0has left the game'); } } @@ -183,86 +189,80 @@ class PlayerManager implements CallbackListener { */ public function playerInfoChanged(array $callback) { $player = $this->getPlayer($callback[1][0]['Login']); - if($player == null) { + if ($player == null) { return; } - - $player->teamId = $callback[1][0]["TeamId"]; + + $player->teamId = $callback[1][0]["TeamId"]; $player->isSpectator = $callback[1][0]["SpectatorStatus"]; - $player->ladderRank = $callback[1][0]["LadderRanking"]; - + $player->ladderRank = $callback[1][0]["LadderRanking"]; + // Trigger own callback $this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERINFOCHANGED, array(self::CB_PLAYERINFOCHANGED)); } /** - * Get the complete PlayerList + * Get all Players * * @return array */ public function getPlayers() { - return $this->playerList; + return $this->players; } /** - * Get a Player from the PlayerList + * Get a Player by Login * * @param string $login * @return Player */ public function getPlayer($login) { - if(!isset($this->playerList[$login])) { + if (!isset($this->players[$login])) { return null; } - return $this->playerList[$login]; + return $this->players[$login]; } /** - * Add a player to the PlayerList + * Add a player * * @param Player $player * @return bool */ private function addPlayer(Player $player) { - if(!$player) { - return false; - } $this->savePlayer($player); - $this->playerList[$player->login] = $player; + $this->players[$player->login] = $player; return true; } /** - * Remove a Player from the PlayerList + * Remove a Player * * @param string $login - * @param bool $savePlayedTime + * @param bool $savePlayedTime * @return Player $player */ private function removePlayer($login, $savePlayedTime = true) { - if(!isset($this->playerList[$login])) { - return null; - } - $player = $this->playerList[$login]; - unset($this->playerList[$login]); - if($savePlayedTime) { + if (!isset($this->players[$login])) return null; + $player = $this->players[$login]; + unset($this->players[$login]); + if ($savePlayedTime) { $this->updatePlayedTime($player); } return $player; } /** - * Save player in database and fill up object properties + * Save player in Database and fill up Object Properties * * @param Player $player - * @internal param int $joinCount * @return bool */ private function savePlayer(Player &$player) { $mysqli = $this->maniaControl->database->mysqli; - + // Save player - $playerQuery = "INSERT INTO `" . self::TABLE_PLAYERS . "` ( + $playerQuery = "INSERT INTO `" . self::TABLE_PLAYERS . "` ( `login`, `nickname`, `path` @@ -273,30 +273,30 @@ class PlayerManager implements CallbackListener { `nickname` = VALUES(`nickname`), `path` = VALUES(`path`);"; $playerStatement = $mysqli->prepare($playerQuery); - if($mysqli->error) { + if ($mysqli->error) { trigger_error($mysqli->error); return false; } $playerStatement->bind_param('sss', $player->login, $player->nickname, $player->path); $playerStatement->execute(); - if($playerStatement->error) { + if ($playerStatement->error) { trigger_error($playerStatement->error); $playerStatement->close(); return false; } $player->index = $playerStatement->insert_id; $playerStatement->close(); - + // Get Player Auth Level from DB - $playerQuery = "SELECT `authLevel` FROM `" . self::TABLE_PLAYERS . "` WHERE `index` = ?;"; + $playerQuery = "SELECT `authLevel` FROM `" . self::TABLE_PLAYERS . "` WHERE `index` = ?;"; $playerStatement = $mysqli->prepare($playerQuery); - if($mysqli->error) { + if ($mysqli->error) { trigger_error($mysqli->error); return false; } $playerStatement->bind_param('i', $player->index); $playerStatement->execute(); - if($playerStatement->error) { + if ($playerStatement->error) { trigger_error($playerStatement->error); $playerStatement->close(); return false; @@ -306,10 +306,10 @@ class PlayerManager implements CallbackListener { $playerStatement->fetch(); $playerStatement->free_result(); $playerStatement->close(); - + // Increment the Player Join Count $this->maniaControl->statisticManager->incrementStat(self::STAT_JOIN_COUNT, $player, $this->maniaControl->server->index); - + return true; } @@ -320,12 +320,11 @@ class PlayerManager implements CallbackListener { * @return bool */ private function updatePlayedTime(Player $player) { - if(!$player) { + if (!$player) { return false; } $playedTime = time() - $player->joinTime; - - $serverIndex = $this->maniaControl->server->getIndex(); - return $this->maniaControl->statisticManager->insertStat(self::STAT_SERVERTIME, $player, $serverIndex, $playedTime); + + return $this->maniaControl->statisticManager->insertStat(self::STAT_SERVERTIME, $player, $this->maniaControl->server->index, $playedTime); } } diff --git a/application/core/Server/ServerCommands.php b/application/core/Server/ServerCommands.php index 67c14756..41421525 100644 --- a/application/core/Server/ServerCommands.php +++ b/application/core/Server/ServerCommands.php @@ -58,7 +58,7 @@ class ServerCommands implements CallbackListener, CommandListener { public function each5Seconds(array $callback) { // Empty shutdown if ($this->serverShutdownEmpty) { - $players = $this->maniaControl->server->getPlayers(); + $players = $this->maniaControl->playerManager->getPlayers(); if (count($players) <= 0) { $this->shutdownServer('empty'); } diff --git a/application/core/Statistics/StatisticCollector.php b/application/core/Statistics/StatisticCollector.php index 89491f32..a7cc8aaa 100644 --- a/application/core/Statistics/StatisticCollector.php +++ b/application/core/Statistics/StatisticCollector.php @@ -90,9 +90,8 @@ class StatisticCollector implements CallbackListener { //Write Shoot Data into database if($this->onShootArray[$login] > $this->maniaControl->settingManager->getSetting($this, self::SETTING_ON_SHOOT_PRESTORE)) { - $serverIndex = $this->maniaControl->server->getIndex(); $player = $this->maniaControl->playerManager->getPlayer($login); - $this->maniaControl->statisticManager->insertStat(self::STAT_ON_SHOOT, $player, $serverIndex, $this->onShootArray[$login]); + $this->maniaControl->statisticManager->insertStat(self::STAT_ON_SHOOT, $player, $this->maniaControl->server->index, $this->onShootArray[$login]); $this->onShootArray[$login] = 0; } } @@ -114,8 +113,7 @@ class StatisticCollector implements CallbackListener { //Insert Data into Database, and destroy player if(isset($this->onShootArray[$player->login])) { if($this->onShootArray[$player->login] > 0) { - $serverIndex = $this->maniaControl->server->getIndex(); - $this->maniaControl->statisticManager->insertStat(self::STAT_ON_SHOOT, $player, $serverIndex, $this->onShootArray[$player->login]); + $this->maniaControl->statisticManager->insertStat(self::STAT_ON_SHOOT, $player, $this->maniaControl->server->index, $this->onShootArray[$player->login]); } unset($this->onShootArray[$player->login]); } diff --git a/application/core/Statistics/StatisticManager.php b/application/core/Statistics/StatisticManager.php index 492c7633..a82a9909 100644 --- a/application/core/Statistics/StatisticManager.php +++ b/application/core/Statistics/StatisticManager.php @@ -154,7 +154,7 @@ class StatisticManager { if (!$statId) return false; if ($serverIndex == -1) { - $serverIndex = $this->maniaControl->server->getIndex(); + $serverIndex = $this->maniaControl->server->index; } $mysqli = $this->maniaControl->database->mysqli; diff --git a/application/plugins/Donations.php b/application/plugins/Donations.php index 9fc79a2f..0087b247 100644 --- a/application/plugins/Donations.php +++ b/application/plugins/Donations.php @@ -423,8 +423,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin { $message = 'Donation successful! Thanks.'; } $this->maniaControl->chat->sendSuccess($message, $login); - $serverIndex = $this->maniaControl->server->getIndex(); - $this->maniaControl->statisticManager->insertStat(self::STAT_PLAYER_DONATIONS, $player, $serverIndex, $amount); + $this->maniaControl->statisticManager->insertStat(self::STAT_PLAYER_DONATIONS, $player, $this->maniaControl->server->index, $amount); } } else { diff --git a/application/plugins/Karma.php b/application/plugins/Karma.php index 946fc550..9de039e0 100644 --- a/application/plugins/Karma.php +++ b/application/plugins/Karma.php @@ -272,8 +272,7 @@ class KarmaPlugin implements CallbackListener, Plugin { $voted = $this->getPlayerVote($player, $map); var_dump($voted); if(!$voted){ - $serverIndex = $this->maniaControl->server->getIndex(); - $this->maniaControl->statisticManager->incrementStat(self::STAT_PLAYER_MAPVOTES, $player, $serverIndex); + $this->maniaControl->statisticManager->incrementStat(self::STAT_PLAYER_MAPVOTES, $player, $this->maniaControl->server->index); } $success = $this->savePlayerVote($player, $map, $vote); diff --git a/application/plugins/WidgetPlugin.php b/application/plugins/WidgetPlugin.php index ce00ac0e..05cffe3b 100644 --- a/application/plugins/WidgetPlugin.php +++ b/application/plugins/WidgetPlugin.php @@ -358,8 +358,7 @@ class WidgetPlugin implements CallbackListener, Plugin { $quad->setPosition($width / 2 - 4, -1.5, -0.5); $quad->setSize(4, 4); $quad->setHAlign(Control::CENTER); - $serverLogin = $this->maniaControl->server->getLogin(); - $quad->setManialink('mcontrol?favorite&' . $serverLogin); + $quad->setManialink('mcontrol?favorite&' . $this->maniaControl->server->login); // Send manialink $manialinkText = $maniaLink->render()->saveXML();