refactor codestyle (chaining)

This commit is contained in:
kremsy 2014-08-13 11:05:52 +02:00
parent 699c5951d9
commit 22915bb934
56 changed files with 1572 additions and 3132 deletions

View File

@ -51,20 +51,14 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Settings // Settings
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_POSX, 156.);
->initSetting($this, self::SETTING_MENU_POSX, 156.); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_POSY, -17.);
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_ITEMSIZE, 6.);
->initSetting($this, self::SETTING_MENU_POSY, -17.);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_MENU_ITEMSIZE, 6.);
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit'); $this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined');
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(AuthenticationManager::CB_AUTH_LEVEL_CHANGED, $this, 'handlePlayerJoined');
->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(AuthenticationManager::CB_AUTH_LEVEL_CHANGED, $this, 'handlePlayerJoined');
} }
/** /**
@ -106,12 +100,10 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
if (!$this->initCompleted) { if (!$this->initCompleted) {
return; return;
} }
$players = $this->maniaControl->getPlayerManager() $players = $this->maniaControl->getPlayerManager()->getPlayers();
->getPlayers();
foreach ($players as $player) { foreach ($players as $player) {
$manialink = $this->buildMenuIconsManialink($player); $manialink = $this->buildMenuIconsManialink($player);
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->sendManialink($manialink, $player->login);
->sendManialink($manialink, $player->login);
} }
} }
@ -122,28 +114,17 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
* @return ManiaLink * @return ManiaLink
*/ */
private function buildMenuIconsManialink(Player $player) { private function buildMenuIconsManialink(Player $player) {
$posX = $this->maniaControl->getSettingManager() $posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_POSX);
->getSettingValue($this, self::SETTING_MENU_POSX); $posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_POSY);
$posY = $this->maniaControl->getSettingManager() $itemSize = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_ITEMSIZE);
->getSettingValue($this, self::SETTING_MENU_POSY); $shootManiaOffset = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultIconOffsetSM();
$itemSize = $this->maniaControl->getSettingManager() $quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
->getSettingValue($this, self::SETTING_MENU_ITEMSIZE); $quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
$shootManiaOffset = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultIconOffsetSM();
$quadStyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultQuadSubstyle();
$itemMarginFactorX = 1.3; $itemMarginFactorX = 1.3;
$itemMarginFactorY = 1.2; $itemMarginFactorY = 1.2;
// If game is shootmania lower the icons position by 20 // If game is shootmania lower the icons position by 20
if ($this->maniaControl->getMapManager() if ($this->maniaControl->getMapManager()->getCurrentMap()->getGame() === 'sm'
->getCurrentMap()
->getGame() === 'sm'
) { ) {
$posY -= $shootManiaOffset; $posY -= $shootManiaOffset;
} }
@ -153,8 +134,7 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
/* /*
* Admin Menu * Admin Menu
*/ */
if ($this->maniaControl->getAuthenticationManager() if ($this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)
->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)
) { ) {
// Admin Menu Icon Frame // Admin Menu Icon Frame
$iconFrame = new Frame(); $iconFrame = new Frame();
@ -333,7 +313,6 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
*/ */
public function handlePlayerJoined(Player $player) { public function handlePlayerJoined(Player $player) {
$maniaLink = $this->buildMenuIconsManialink($player); $maniaLink = $this->buildMenuIconsManialink($player);
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $player);
->sendManialink($maniaLink, $player);
} }
} }

View File

@ -46,23 +46,17 @@ class AdminLists implements ManialinkPageAnswerListener, CallbackListener {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer'); $this->maniaControl->getCallbackManager()->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget'); $this->maniaControl->getCallbackManager()->registerCallbackListener(AuthenticationManager::CB_AUTH_LEVEL_CHANGED, $this, 'updateWidget');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(AuthenticationManager::CB_AUTH_LEVEL_CHANGED, $this, 'updateWidget');
// Menu Entry AdminList // Menu Entry AdminList
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_OPEN_ADMIN_LIST, $this, 'openAdminList');
->registerManialinkPageAnswerListener(self::ACTION_OPEN_ADMIN_LIST, $this, 'openAdminList');
$itemQuad = new Quad_UIConstruction_Buttons(); $itemQuad = new Quad_UIConstruction_Buttons();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Author); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_Author);
$itemQuad->setAction(self::ACTION_OPEN_ADMIN_LIST); $itemQuad->setAction(self::ACTION_OPEN_ADMIN_LIST);
$this->maniaControl->getActionsMenu() $this->maniaControl->getActionsMenu()->addMenuItem($itemQuad, false, 50, 'Open AdminList');
->addMenuItem($itemQuad, false, 50, 'Open AdminList');
} }
/** /**
@ -83,16 +77,11 @@ class AdminLists implements ManialinkPageAnswerListener, CallbackListener {
public function showAdminLists(Player $player) { public function showAdminLists(Player $player) {
$this->adminListShown[$player->login] = true; $this->adminListShown[$player->login] = true;
$width = $this->maniaControl->getManialinkManager() $width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
->getStyleManager() $height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
->getListWidgetsWidth();
$height = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getListWidgetsHeight();
// get Admins // get Admins
$admins = $this->maniaControl->getAuthenticationManager() $admins = $this->maniaControl->getAuthenticationManager()->getAdmins();
->getAdmins();
//Create ManiaLink //Create ManiaLink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID); $maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
@ -101,9 +90,7 @@ class AdminLists implements ManialinkPageAnswerListener, CallbackListener {
$script->addFeature($paging); $script->addFeature($paging);
// Main frame // Main frame
$frame = $this->maniaControl->getManialinkManager() $frame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultListFrame($script, $paging);
->getStyleManager()
->getDefaultListFrame($script, $paging);
$maniaLink->add($frame); $maniaLink->add($frame);
// Start offsets // Start offsets
@ -111,9 +98,7 @@ class AdminLists implements ManialinkPageAnswerListener, CallbackListener {
$posY = $height / 2; $posY = $height / 2;
//Predefine description Label //Predefine description Label
$descriptionLabel = $this->maniaControl->getManialinkManager() $descriptionLabel = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultDescriptionLabel();
->getStyleManager()
->getDefaultDescriptionLabel();
$frame->add($descriptionLabel); $frame->add($descriptionLabel);
// Headline // Headline
@ -121,8 +106,7 @@ class AdminLists implements ManialinkPageAnswerListener, CallbackListener {
$frame->add($headFrame); $frame->add($headFrame);
$headFrame->setY($posY - 5); $headFrame->setY($posY - 5);
$array = array('Id' => $posX + 5, 'Nickname' => $posX + 18, 'Login' => $posX + 70, 'Actions' => $posX + 120); $array = array('Id' => $posX + 5, 'Nickname' => $posX + 18, 'Login' => $posX + 70, 'Actions' => $posX + 120);
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->labelLine($headFrame, $array);
->labelLine($headFrame, $array);
$index = 1; $index = 1;
$posY -= 10; $posY -= 10;
@ -150,8 +134,7 @@ class AdminLists implements ManialinkPageAnswerListener, CallbackListener {
} }
$array = array($index => $posX + 5, $admin->nickname => $posX + 18, $admin->login => $posX + 70); $array = array($index => $posX + 5, $admin->nickname => $posX + 18, $admin->login => $posX + 70);
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->labelLine($playerFrame, $array);
->labelLine($playerFrame, $array);
// Level Quad // Level Quad
@ -167,16 +150,13 @@ class AdminLists implements ManialinkPageAnswerListener, CallbackListener {
$rightLabel->setX($posX + 13.9); $rightLabel->setX($posX + 13.9);
$rightLabel->setTextSize(0.8); $rightLabel->setTextSize(0.8);
$rightLabel->setZ(10); $rightLabel->setZ(10);
$rightLabel->setText($this->maniaControl->getAuthenticationManager() $rightLabel->setText($this->maniaControl->getAuthenticationManager()->getAuthLevelAbbreviation($admin));
->getAuthLevelAbbreviation($admin)); $description = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin) . " " . $admin->nickname;
$description = $this->maniaControl->getAuthenticationManager()
->getAuthLevelName($admin) . " " . $admin->nickname;
$rightLabel->addTooltipLabelFeature($descriptionLabel, $description); $rightLabel->addTooltipLabelFeature($descriptionLabel, $description);
//Revoke Button //Revoke Button
if ($admin->authLevel > 0 if ($admin->authLevel > 0
&& $this->maniaControl->getAuthenticationManager() && $this->maniaControl->getAuthenticationManager()->checkRight($player, $admin->authLevel + 1)
->checkRight($player, $admin->authLevel + 1)
) { ) {
//Settings //Settings
$style = Label_Text::STYLE_TextCardSmall; $style = Label_Text::STYLE_TextCardSmall;
@ -209,8 +189,7 @@ class AdminLists implements ManialinkPageAnswerListener, CallbackListener {
} }
// Render and display xml // Render and display xml
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'AdminList');
->displayWidget($maniaLink, $player, 'AdminList');
} }
/** /**
@ -231,9 +210,7 @@ class AdminLists implements ManialinkPageAnswerListener, CallbackListener {
switch ($action) { switch ($action) {
case self::ACTION_REVOKE_RIGHTS: case self::ACTION_REVOKE_RIGHTS:
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerActions()->revokeAuthLevel($adminLogin, $targetLogin);
->getPlayerActions()
->revokeAuthLevel($adminLogin, $targetLogin);
break; break;
} }
} }
@ -246,8 +223,7 @@ class AdminLists implements ManialinkPageAnswerListener, CallbackListener {
public function updateWidget(Player $player) { public function updateWidget(Player $player) {
foreach ($this->adminListShown as $login => $shown) { foreach ($this->adminListShown as $login => $shown) {
if ($shown) { if ($shown) {
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($login);
->getPlayer($login);
if ($player) { if ($player) {
$this->showAdminLists($player); $this->showAdminLists($player);
} else { } else {

View File

@ -29,12 +29,9 @@ class AuthCommands implements CommandListener {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Commands // Commands
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener('addsuperadmin', $this, 'command_AddSuperAdmin', true, 'Add Player to the AdminList as SuperAdmin.');
->registerCommandListener('addsuperadmin', $this, 'command_AddSuperAdmin', true, 'Add Player to the AdminList as SuperAdmin.'); $this->maniaControl->getCommandManager()->registerCommandListener('addadmin', $this, 'command_AddAdmin', true, 'Add Player to the AdminList as Admin.');
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener('addmod', $this, 'command_AddModerator', true, 'Add Player to the AdminList as Moderator.');
->registerCommandListener('addadmin', $this, 'command_AddAdmin', true, 'Add Player to the AdminList as Admin.');
$this->maniaControl->getCommandManager()
->registerCommandListener('addmod', $this, 'command_AddModerator', true, 'Add Player to the AdminList as Moderator.');
} }
/** /**
@ -45,8 +42,7 @@ class AuthCommands implements CommandListener {
*/ */
public function command_AddSuperAdmin(array $chatCallback, Player $player) { public function command_AddSuperAdmin(array $chatCallback, Player $player) {
if (!AuthenticationManager::checkRight($player, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)) { if (!AuthenticationManager::checkRight($player, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$text = $chatCallback[1][2]; $text = $chatCallback[1][2];
@ -55,23 +51,18 @@ class AuthCommands implements CommandListener {
$this->sendAddSuperAdminUsageInfo($player); $this->sendAddSuperAdminUsageInfo($player);
return; return;
} }
$target = $this->maniaControl->getPlayerManager() $target = $this->maniaControl->getPlayerManager()->getPlayer($commandParts[1]);
->getPlayer($commandParts[1]);
if (!$target) { if (!$target) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError("Player '{$commandParts[1]}' not found!", $player);
->sendError("Player '{$commandParts[1]}' not found!", $player);
return; return;
} }
$success = $this->maniaControl->getAuthenticationManager() $success = $this->maniaControl->getAuthenticationManager()->grantAuthLevel($target, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
->grantAuthLevel($target, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
if (!$success) { if (!$success) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('Error occurred.', $player);
->sendError('Error occurred.', $player);
return; return;
} }
$message = $player->getEscapedNickname() . ' added ' . $target->getEscapedNickname() . ' as SuperAdmin!'; $message = $player->getEscapedNickname() . ' added ' . $target->getEscapedNickname() . ' as SuperAdmin!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess($message);
->sendSuccess($message);
} }
/** /**
@ -82,8 +73,7 @@ class AuthCommands implements CommandListener {
*/ */
private function sendAddSuperAdminUsageInfo(Player $player) { private function sendAddSuperAdminUsageInfo(Player $player) {
$message = "Usage Example: '//addsuperadmin login'"; $message = "Usage Example: '//addsuperadmin login'";
return $this->maniaControl->getChat() return $this->maniaControl->getChat()->sendUsageInfo($message, $player);
->sendUsageInfo($message, $player);
} }
/** /**
@ -94,8 +84,7 @@ class AuthCommands implements CommandListener {
*/ */
public function command_AddAdmin(array $chatCallback, Player $player) { public function command_AddAdmin(array $chatCallback, Player $player) {
if (!AuthenticationManager::checkRight($player, AuthenticationManager::AUTH_LEVEL_SUPERADMIN)) { if (!AuthenticationManager::checkRight($player, AuthenticationManager::AUTH_LEVEL_SUPERADMIN)) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$text = $chatCallback[1][2]; $text = $chatCallback[1][2];
@ -104,23 +93,18 @@ class AuthCommands implements CommandListener {
$this->sendAddAdminUsageInfo($player); $this->sendAddAdminUsageInfo($player);
return; return;
} }
$target = $this->maniaControl->getPlayerManager() $target = $this->maniaControl->getPlayerManager()->getPlayer($commandParts[1]);
->getPlayer($commandParts[1]);
if (!$target) { if (!$target) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError("Player '{$commandParts[1]}' not found!", $player);
->sendError("Player '{$commandParts[1]}' not found!", $player);
return; return;
} }
$success = $this->maniaControl->getAuthenticationManager() $success = $this->maniaControl->getAuthenticationManager()->grantAuthLevel($target, AuthenticationManager::AUTH_LEVEL_ADMIN);
->grantAuthLevel($target, AuthenticationManager::AUTH_LEVEL_ADMIN);
if (!$success) { if (!$success) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('Error occurred.', $player);
->sendError('Error occurred.', $player);
return; return;
} }
$message = $player->getEscapedNickname() . ' added ' . $target->getEscapedNickname() . ' as Admin!'; $message = $player->getEscapedNickname() . ' added ' . $target->getEscapedNickname() . ' as Admin!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess($message);
->sendSuccess($message);
} }
/** /**
@ -131,8 +115,7 @@ class AuthCommands implements CommandListener {
*/ */
private function sendAddAdminUsageInfo(Player $player) { private function sendAddAdminUsageInfo(Player $player) {
$message = "Usage Example: '//addadmin login'"; $message = "Usage Example: '//addadmin login'";
return $this->maniaControl->getChat() return $this->maniaControl->getChat()->sendUsageInfo($message, $player);
->sendUsageInfo($message, $player);
} }
/** /**
@ -143,8 +126,7 @@ class AuthCommands implements CommandListener {
*/ */
public function command_AddModerator(array $chatCallback, Player $player) { public function command_AddModerator(array $chatCallback, Player $player) {
if (!AuthenticationManager::checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) { if (!AuthenticationManager::checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$text = $chatCallback[1][2]; $text = $chatCallback[1][2];
@ -153,23 +135,18 @@ class AuthCommands implements CommandListener {
$this->sendAddModeratorUsageInfo($player); $this->sendAddModeratorUsageInfo($player);
return; return;
} }
$target = $this->maniaControl->getPlayerManager() $target = $this->maniaControl->getPlayerManager()->getPlayer($commandParts[1]);
->getPlayer($commandParts[1]);
if (!$target) { if (!$target) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError("Player '{$commandParts[1]}' not found!", $player);
->sendError("Player '{$commandParts[1]}' not found!", $player);
return; return;
} }
$success = $this->maniaControl->getAuthenticationManager() $success = $this->maniaControl->getAuthenticationManager()->grantAuthLevel($target, AuthenticationManager::AUTH_LEVEL_MODERATOR);
->grantAuthLevel($target, AuthenticationManager::AUTH_LEVEL_MODERATOR);
if (!$success) { if (!$success) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('Error occurred.', $player);
->sendError('Error occurred.', $player);
return; return;
} }
$message = $player->getEscapedNickname() . ' added ' . $target->getEscapedNickname() . ' as Moderator!'; $message = $player->getEscapedNickname() . ' added ' . $target->getEscapedNickname() . ' as Moderator!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess($message);
->sendSuccess($message);
} }
/** /**
@ -180,7 +157,6 @@ class AuthCommands implements CommandListener {
*/ */
private function sendAddModeratorUsageInfo(Player $player) { private function sendAddModeratorUsageInfo(Player $player) {
$message = "Usage Example: '//addmod login'"; $message = "Usage Example: '//addmod login'";
return $this->maniaControl->getChat() return $this->maniaControl->getChat()->sendUsageInfo($message, $player);
->sendUsageInfo($message, $player);
} }
} }

View File

@ -51,8 +51,7 @@ class AuthenticationManager implements CallbackListener {
$this->authCommands = new AuthCommands($maniaControl); $this->authCommands = new AuthCommands($maniaControl);
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONINIT, $this, 'handleOnInit');
->registerCallbackListener(Callbacks::ONINIT, $this, 'handleOnInit');
} }
/** /**
@ -147,16 +146,14 @@ class AuthenticationManager implements CallbackListener {
* @return bool * @return bool
*/ */
private function updateMasterAdmins() { private function updateMasterAdmins() {
$masterAdminsElements = $this->maniaControl->getConfig() $masterAdminsElements = $this->maniaControl->getConfig()->xpath('masteradmins');
->xpath('masteradmins');
if (!$masterAdminsElements) { if (!$masterAdminsElements) {
Logger::logError('Missing MasterAdmins configuration!'); Logger::logError('Missing MasterAdmins configuration!');
return false; return false;
} }
$masterAdminsElement = $masterAdminsElements[0]; $masterAdminsElement = $masterAdminsElements[0];
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
// Remove all MasterAdmins // Remove all MasterAdmins
$adminQuery = "UPDATE `" . PlayerManager::TABLE_PLAYERS . "` $adminQuery = "UPDATE `" . PlayerManager::TABLE_PLAYERS . "`
@ -212,8 +209,7 @@ class AuthenticationManager implements CallbackListener {
* @return Player[] * @return Player[]
*/ */
public function getConnectedAdmins($authLevel = self::AUTH_LEVEL_MODERATOR) { public function getConnectedAdmins($authLevel = self::AUTH_LEVEL_MODERATOR) {
$players = $this->maniaControl->getPlayerManager() $players = $this->maniaControl->getPlayerManager()->getPlayers();
->getPlayers();
$admins = array(); $admins = array();
foreach ($players as $player) { foreach ($players as $player) {
if (self::checkRight($player, $authLevel)) { if (self::checkRight($player, $authLevel)) {
@ -244,8 +240,7 @@ class AuthenticationManager implements CallbackListener {
* @return Player[] * @return Player[]
*/ */
public function getAdmins($authLevel = self::AUTH_LEVEL_MODERATOR) { public function getAdmins($authLevel = self::AUTH_LEVEL_MODERATOR) {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$query = "SELECT `login` FROM `" . PlayerManager::TABLE_PLAYERS . "` $query = "SELECT `login` FROM `" . PlayerManager::TABLE_PLAYERS . "`
WHERE `authLevel` > " . $authLevel . " WHERE `authLevel` > " . $authLevel . "
ORDER BY `authLevel` DESC;"; ORDER BY `authLevel` DESC;";
@ -256,8 +251,7 @@ class AuthenticationManager implements CallbackListener {
} }
$admins = array(); $admins = array();
while ($row = $result->fetch_object()) { while ($row = $result->fetch_object()) {
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($row->login, false);
->getPlayer($row->login, false);
if ($player) { if ($player) {
array_push($admins, $player); array_push($admins, $player);
} }
@ -282,8 +276,7 @@ class AuthenticationManager implements CallbackListener {
return false; return false;
} }
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$authQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` ( $authQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` (
`login`, `login`,
`authLevel` `authLevel`
@ -306,8 +299,7 @@ class AuthenticationManager implements CallbackListener {
$authStatement->close(); $authStatement->close();
$player->authLevel = $authLevel; $player->authLevel = $authLevel;
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_AUTH_LEVEL_CHANGED, $player);
->triggerCallback(self::CB_AUTH_LEVEL_CHANGED, $player);
return true; return true;
} }
@ -322,8 +314,7 @@ class AuthenticationManager implements CallbackListener {
if (!$player) { if (!$player) {
return false; return false;
} }
return $this->maniaControl->getChat() return $this->maniaControl->getChat()->sendError('You do not have the required Rights to perform this Action!', $player);
->sendError('You do not have the required Rights to perform this Action!', $player);
} }
/** /**
@ -334,8 +325,7 @@ class AuthenticationManager implements CallbackListener {
* @return bool * @return bool
*/ */
public function checkPermission(Player $player, $rightName) { public function checkPermission(Player $player, $rightName) {
$right = $this->maniaControl->getSettingManager() $right = $this->maniaControl->getSettingManager()->getSettingValue($this, $rightName);
->getSettingValue($this, $rightName);
return $this->checkRight($player, $this->getAuthLevel($right)); return $this->checkRight($player, $this->getAuthLevel($right));
} }
@ -346,8 +336,7 @@ class AuthenticationManager implements CallbackListener {
* @param int $authLevelNeeded * @param int $authLevelNeeded
*/ */
public function definePermissionLevel($rightName, $authLevelNeeded) { public function definePermissionLevel($rightName, $authLevelNeeded) {
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, $rightName, $this->getPermissionLevelNameArray($authLevelNeeded));
->initSetting($this, $rightName, $this->getPermissionLevelNameArray($authLevelNeeded));
} }
/** /**

View File

@ -41,8 +41,7 @@ class BillManager implements CallbackListener {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_BILLUPDATED, $this, 'handleBillUpdated');
->registerCallbackListener(CallbackManager::CB_MP_BILLUPDATED, $this, 'handleBillUpdated');
} }
/** /**
@ -56,8 +55,7 @@ class BillManager implements CallbackListener {
* @return bool * @return bool
*/ */
public function sendBill(callable $function, Player $player, $amount, $message, $receiver = '') { public function sendBill(callable $function, Player $player, $amount, $message, $receiver = '') {
$bill = $this->maniaControl->getClient() $bill = $this->maniaControl->getClient()->sendBill($player->login, $amount, $message, $receiver);
->sendBill($player->login, $amount, $message, $receiver);
$this->openBills[$bill] = new BillData($function, $player, $amount); $this->openBills[$bill] = new BillData($function, $player, $amount);
return true; return true;
} }
@ -72,8 +70,7 @@ class BillManager implements CallbackListener {
* @return bool * @return bool
*/ */
public function sendPlanets(callable $function, $receiverLogin, $amount, $message) { public function sendPlanets(callable $function, $receiverLogin, $amount, $message) {
$bill = $this->maniaControl->getClient() $bill = $this->maniaControl->getClient()->pay($receiverLogin, $amount, $message);
->pay($receiverLogin, $amount, $message);
$this->openBills[$bill] = new BillData($function, $receiverLogin, $amount, true); $this->openBills[$bill] = new BillData($function, $receiverLogin, $amount, true);
return true; return true;
} }

View File

@ -210,8 +210,7 @@ class CallbackManager {
*/ */
public function manageCallbacks() { public function manageCallbacks() {
// Manage Timings // Manage Timings
$this->maniaControl->getTimerManager() $this->maniaControl->getTimerManager()->manageTimings();
->manageTimings();
// Server Callbacks // Server Callbacks
if (!$this->maniaControl->getClient()) { if (!$this->maniaControl->getClient()) {
@ -219,8 +218,7 @@ class CallbackManager {
} }
// Handle callbacks // Handle callbacks
$callbacks = $this->maniaControl->getClient() $callbacks = $this->maniaControl->getClient()->executeCallbacks();
->executeCallbacks();
foreach ($callbacks as $callback) { foreach ($callbacks as $callback) {
$this->handleCallback($callback); $this->handleCallback($callback);
} }
@ -238,16 +236,14 @@ class CallbackManager {
$this->triggerCallback($callbackName, $callback); $this->triggerCallback($callbackName, $callback);
break; break;
case self::CB_MP_BEGINMAP: case self::CB_MP_BEGINMAP:
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->handleBeginMap($callback);
->handleBeginMap($callback);
$this->triggerCallback($callbackName, $callback); $this->triggerCallback($callbackName, $callback);
break; break;
case self::CB_MP_ENDMATCH: case self::CB_MP_ENDMATCH:
$this->triggerCallback($callbackName, $callback); $this->triggerCallback($callbackName, $callback);
break; break;
case self::CB_MP_ENDMAP: case self::CB_MP_ENDMAP:
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->handleEndMap($callback);
->handleEndMap($callback);
$this->triggerCallback($callbackName, $callback); $this->triggerCallback($callbackName, $callback);
break; break;
case self::CB_MP_MODESCRIPTCALLBACK: case self::CB_MP_MODESCRIPTCALLBACK:

View File

@ -39,101 +39,79 @@ class LibXmlRpcCallbacks implements CallbackListener {
public function handleScriptCallback($name, $data) { public function handleScriptCallback($name, $data) {
switch ($name) { switch ($name) {
case 'LibXmlRpc_BeginMatch': case 'LibXmlRpc_BeginMatch':
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::BEGINMATCH, $data[0]);
->triggerCallback(Callbacks::BEGINMATCH, $data[0]);
break; break;
case 'LibXmlRpc_LoadingMap': case 'LibXmlRpc_LoadingMap':
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::LOADINGMAP, $data[0]);
->triggerCallback(Callbacks::LOADINGMAP, $data[0]);
break; break;
case 'BeginMap': case 'BeginMap':
case 'LibXmlRpc_BeginMap': case 'LibXmlRpc_BeginMap':
if (!isset($data[2])) { if (!isset($data[2])) {
$data[2] = 'False'; $data[2] = 'False';
} }
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->handleScriptBeginMap($data[1], $data[2]);
->handleScriptBeginMap($data[1], $data[2]);
break; break;
case 'LibXmlRpc_BeginSubmatch': case 'LibXmlRpc_BeginSubmatch':
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::BEGINSUBMATCH, $data[0]);
->triggerCallback(Callbacks::BEGINSUBMATCH, $data[0]);
break; break;
case 'LibXmlRpc_BeginTurn': case 'LibXmlRpc_BeginTurn':
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::BEGINTURN, $data[0]);
->triggerCallback(Callbacks::BEGINTURN, $data[0]);
break; break;
case 'LibXmlRpc_BeginPlaying': case 'LibXmlRpc_BeginPlaying':
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::BEGINPLAYING);
->triggerCallback(Callbacks::BEGINPLAYING);
break; break;
case 'LibXmlRpc_EndPlaying': case 'LibXmlRpc_EndPlaying':
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ENDPLAYING);
->triggerCallback(Callbacks::ENDPLAYING);
break; break;
case 'LibXmlRpc_EndTurn': case 'LibXmlRpc_EndTurn':
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ENDTURN, $data[0]);
->triggerCallback(Callbacks::ENDTURN, $data[0]);
break; break;
case 'LibXmlRpc_EndRound': case 'LibXmlRpc_EndRound':
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ENDROUND, $data[0]);
->triggerCallback(Callbacks::ENDROUND, $data[0]);
break; break;
case 'LibXmlRpc_EndSubmatch': case 'LibXmlRpc_EndSubmatch':
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ENDSUBMATCH, $data[0]);
->triggerCallback(Callbacks::ENDSUBMATCH, $data[0]);
break; break;
case 'EndMap': case 'EndMap':
case 'LibXmlRpc_EndMap': case 'LibXmlRpc_EndMap':
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->handleScriptEndMap();
->handleScriptEndMap();
break; break;
case 'LibXmlRpc_BeginPodium': case 'LibXmlRpc_BeginPodium':
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::BEGINPODIUM);
->triggerCallback(Callbacks::BEGINPODIUM);
break; break;
case 'LibXmlRpc_EndPodium': case 'LibXmlRpc_EndPodium':
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ENDPODIUM);
->triggerCallback(Callbacks::ENDPODIUM);
break; break;
case 'LibXmlRpc_UnloadingMap': case 'LibXmlRpc_UnloadingMap':
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::UNLOADINGMAP, $data[0]);
->triggerCallback(Callbacks::UNLOADINGMAP, $data[0]);
break; break;
case 'LibXmlRpc_EndMatch': case 'LibXmlRpc_EndMatch':
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ENDMATCH, $data[0]);
->triggerCallback(Callbacks::ENDMATCH, $data[0]);
break; break;
case 'LibXmlRpc_BeginWarmUp': case 'LibXmlRpc_BeginWarmUp':
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::BEGINWARMUP);
->triggerCallback(Callbacks::BEGINWARMUP);
break; break;
case 'LibXmlRpc_EndWarmUp': case 'LibXmlRpc_EndWarmUp':
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ENDWARMUP);
->triggerCallback(Callbacks::ENDWARMUP);
break; break;
case 'LibXmlRpc_PlayerRanking': case 'LibXmlRpc_PlayerRanking':
//TODO really useful? what does it have what RankingsManager not have? //TODO really useful? what does it have what RankingsManager not have?
$this->triggerPlayerRanking($data[0]); $this->triggerPlayerRanking($data[0]);
break; break;
case 'LibXmlRpc_OnStartLine': case 'LibXmlRpc_OnStartLine':
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONSTARTLINE, $data[0]);
->triggerCallback(Callbacks::ONSTARTLINE, $data[0]);
break; break;
case 'LibXmlRpc_OnWayPoint': case 'LibXmlRpc_OnWayPoint':
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONWAYPOINT, $data);
->triggerCallback(Callbacks::ONWAYPOINT, $data);
break; break;
case 'LibXmlRpc_OnGiveUp': case 'LibXmlRpc_OnGiveUp':
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONGIVEUP, $data[0]);
->triggerCallback(Callbacks::ONGIVEUP, $data[0]);
break; break;
case 'LibXmlRpc_OnRespawn': case 'LibXmlRpc_OnRespawn':
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONRESPAWN, $data[0]);
->triggerCallback(Callbacks::ONRESPAWN, $data[0]);
break; break;
case 'LibXmlRpc_OnStunt': case 'LibXmlRpc_OnStunt':
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONSTUNT, $data);
->triggerCallback(Callbacks::ONSTUNT, $data);
break; break;
} }
} }
@ -144,9 +122,7 @@ class LibXmlRpcCallbacks implements CallbackListener {
* @param array $data * @param array $data
*/ */
private function triggerPlayerRanking(array $data) { private function triggerPlayerRanking(array $data) {
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($data[1]);
->getPlayer($data[1]); $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::PLAYERRANKING, $player, $data[0], $data[6], $data[5]);
$this->maniaControl->getCallbackManager()
->triggerCallback(Callbacks::PLAYERRANKING, $player, $data[0], $data[6], $data[5]);
} }
} }

View File

@ -49,20 +49,16 @@ class ShootManiaCallbacks implements CallbackListener {
public function handleScriptCallbacks($name, $data) { public function handleScriptCallbacks($name, $data) {
switch ($name) { switch ($name) {
case 'LibXmlRpc_Rankings': case 'LibXmlRpc_Rankings':
$this->maniaControl->getServer() $this->maniaControl->getServer()->getRankingManager()->updateRankings($data[0]);
->getRankingManager()
->updateRankings($data[0]);
break; break;
case 'LibXmlRpc_Scores': case 'LibXmlRpc_Scores':
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SCORES, $data[0]);
->triggerCallback(Callbacks::SCORES, $data[0]);
break; break;
case 'LibAFK_IsAFK': case 'LibAFK_IsAFK':
$this->triggerAfkStatus($data[0]); $this->triggerAfkStatus($data[0]);
break; break;
case 'WarmUp_Status': case 'WarmUp_Status':
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::WARMUPSTATUS, $data[0]);
->triggerCallback(Callbacks::WARMUPSTATUS, $data[0]);
break; break;
case self::CB_TIMEATTACK_ONCHECKPOINT: case self::CB_TIMEATTACK_ONCHECKPOINT:
$this->handleTimeAttackOnCheckpoint($name, $data); $this->handleTimeAttackOnCheckpoint($name, $data);
@ -79,10 +75,8 @@ class ShootManiaCallbacks implements CallbackListener {
* @param string $login * @param string $login
*/ */
private function triggerAfkStatus($login) { private function triggerAfkStatus($login) {
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($login);
->getPlayer($login); $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::AFKSTATUS, $player);
$this->maniaControl->getCallbackManager()
->triggerCallback(Callbacks::AFKSTATUS, $player);
} }
/** /**
@ -93,8 +87,7 @@ class ShootManiaCallbacks implements CallbackListener {
*/ */
public function handleTimeAttackOnCheckpoint($name, array $data) { public function handleTimeAttackOnCheckpoint($name, array $data) {
$login = $data[0]; $login = $data[0];
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($login);
->getPlayer($login);
if (!$player) { if (!$player) {
return; return;
} }
@ -106,8 +99,7 @@ class ShootManiaCallbacks implements CallbackListener {
$checkpointCallback->setPlayer($player); $checkpointCallback->setPlayer($player);
$checkpointCallback->time = (int)$data[1]; $checkpointCallback->time = (int)$data[1];
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback($checkpointCallback);
->triggerCallback($checkpointCallback);
} }
/** /**
@ -118,8 +110,7 @@ class ShootManiaCallbacks implements CallbackListener {
*/ */
public function handleTimeAttackOnFinish($name, array $data) { public function handleTimeAttackOnFinish($name, array $data) {
$login = $data[0]; $login = $data[0];
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($login);
->getPlayer($login);
if (!$player) { if (!$player) {
return; return;
} }
@ -131,7 +122,6 @@ class ShootManiaCallbacks implements CallbackListener {
$finishCallback->setPlayer($player); $finishCallback->setPlayer($player);
$finishCallback->time = (int)$data[1]; $finishCallback->time = (int)$data[1];
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback($finishCallback);
->triggerCallback($finishCallback);
} }
} }

View File

@ -42,8 +42,7 @@ class TrackManiaCallbacks implements CallbackListener {
*/ */
public function handleOnWayPointCallback(array $callback) { public function handleOnWayPointCallback(array $callback) {
$login = $callback[0]; $login = $callback[0];
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($login);
->getPlayer($login);
if (!$player) { if (!$player) {
return; return;
} }
@ -62,8 +61,7 @@ class TrackManiaCallbacks implements CallbackListener {
$wayPointCallback->isEndLap = Formatter::parseBoolean($callback[7]); $wayPointCallback->isEndLap = Formatter::parseBoolean($callback[7]);
if ($wayPointCallback->checkpoint > 0) { if ($wayPointCallback->checkpoint > 0) {
$currentMap = $this->maniaControl->getMapManager() $currentMap = $this->maniaControl->getMapManager()->getCurrentMap();
->getCurrentMap();
$wayPointCallback->lap += $wayPointCallback->checkpoint / $currentMap->nbCheckpoints; $wayPointCallback->lap += $wayPointCallback->checkpoint / $currentMap->nbCheckpoints;
} }
@ -75,8 +73,7 @@ class TrackManiaCallbacks implements CallbackListener {
$wayPointCallback->name = $wayPointCallback::CHECKPOINT; $wayPointCallback->name = $wayPointCallback::CHECKPOINT;
} }
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback($wayPointCallback);
->triggerCallback($wayPointCallback);
} }
/** /**
@ -87,8 +84,7 @@ class TrackManiaCallbacks implements CallbackListener {
public function handlePlayerCheckpointCallback(array $callback) { public function handlePlayerCheckpointCallback(array $callback) {
$data = $callback[1]; $data = $callback[1];
$login = $data[1]; $login = $data[1];
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($login);
->getPlayer($login);
if (!$player) { if (!$player) {
return; return;
} }
@ -104,8 +100,7 @@ class TrackManiaCallbacks implements CallbackListener {
$checkpointCallback->lapCheckpoint = $checkpointCallback->checkpoint; $checkpointCallback->lapCheckpoint = $checkpointCallback->checkpoint;
if ($checkpointCallback->lap > 0) { if ($checkpointCallback->lap > 0) {
$currentMap = $this->maniaControl->getMapManager() $currentMap = $this->maniaControl->getMapManager()->getCurrentMap();
->getCurrentMap();
$checkpointCallback->lapCheckpoint -= $checkpointCallback->lap * $currentMap->nbCheckpoints; $checkpointCallback->lapCheckpoint -= $checkpointCallback->lap * $currentMap->nbCheckpoints;
} }
@ -115,8 +110,7 @@ class TrackManiaCallbacks implements CallbackListener {
$checkpointCallback->name = $checkpointCallback::CHECKPOINT; $checkpointCallback->name = $checkpointCallback::CHECKPOINT;
} }
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback($checkpointCallback);
->triggerCallback($checkpointCallback);
} }
/** /**
@ -127,8 +121,7 @@ class TrackManiaCallbacks implements CallbackListener {
public function handlePlayerFinishCallback(array $callback) { public function handlePlayerFinishCallback(array $callback) {
$data = $callback[1]; $data = $callback[1];
$login = $data[1]; $login = $data[1];
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($login);
->getPlayer($login);
if (!$player) { if (!$player) {
return; return;
} }
@ -141,7 +134,6 @@ class TrackManiaCallbacks implements CallbackListener {
$finishCallback->setPlayer($player); $finishCallback->setPlayer($player);
$finishCallback->time = (int)$data[2]; $finishCallback->time = (int)$data[2];
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback($finishCallback);
->triggerCallback($finishCallback);
} }
} }

View File

@ -39,8 +39,7 @@ class CommandManager implements CallbackListener {
$this->helpManager = new HelpManager($this->maniaControl); $this->helpManager = new HelpManager($this->maniaControl);
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'handleChatCallback');
->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'handleChatCallback');
} }
/** /**
@ -164,8 +163,7 @@ class CommandManager implements CallbackListener {
// Check for valid player // Check for valid player
$login = $callback[1][1]; $login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($login);
->getPlayer($login);
if (!$player) { if (!$player) {
return; return;
} }

View File

@ -38,22 +38,17 @@ class HelpManager implements CommandListener, CallbackListener {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONINIT, $this, 'handleOnInit');
->registerCallbackListener(Callbacks::ONINIT, $this, 'handleOnInit');
} }
/** /**
* Handle ManiaControl OnInit Callback * Handle ManiaControl OnInit Callback
*/ */
public function handleOnInit() { public function handleOnInit() {
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener('help', $this, 'command_playerHelp', false, 'Shows all commands in chat.');
->registerCommandListener('help', $this, 'command_playerHelp', false, 'Shows all commands in chat.'); $this->maniaControl->getCommandManager()->registerCommandListener('helpall', $this, 'command_playerHelpAll', false, 'Shows all commands in ManiaLink with description.');
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener('help', $this, 'command_adminHelp', true, 'Shows all admin commands in chat.');
->registerCommandListener('helpall', $this, 'command_playerHelpAll', false, 'Shows all commands in ManiaLink with description.'); $this->maniaControl->getCommandManager()->registerCommandListener('helpall', $this, 'command_adminHelpAll', true, 'Shows all admin commands in ManiaLink with description.');
$this->maniaControl->getCommandManager()
->registerCommandListener('help', $this, 'command_adminHelp', true, 'Shows all admin commands in chat.');
$this->maniaControl->getCommandManager()
->registerCommandListener('helpall', $this, 'command_adminHelpAll', true, 'Shows all admin commands in ManiaLink with description.');
} }
/** /**
@ -84,8 +79,7 @@ class HelpManager implements CommandListener, CallbackListener {
$message .= $command['Name'] . ','; $message .= $command['Name'] . ',';
} }
$message = substr($message, 0, -1); $message = substr($message, 0, -1);
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendChat($message, $player);
->sendChat($message, $player);
} }
/** /**
@ -116,8 +110,7 @@ class HelpManager implements CommandListener, CallbackListener {
$message .= $command['Name'] . ','; $message .= $command['Name'] . ',';
} }
$message = substr($message, 0, -1); $message = substr($message, 0, -1);
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendChat($message, $player);
->sendChat($message, $player);
} }
/** /**
@ -168,12 +161,8 @@ class HelpManager implements CommandListener, CallbackListener {
* @param mixed $player * @param mixed $player
*/ */
private function showHelpAllList(array $commands, $player) { private function showHelpAllList(array $commands, $player) {
$width = $this->maniaControl->getManialinkManager() $width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
->getStyleManager() $height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
->getListWidgetsWidth();
$height = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getListWidgetsHeight();
// create manialink // create manialink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID); $maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
@ -182,9 +171,7 @@ class HelpManager implements CommandListener, CallbackListener {
$script->addFeature($paging); $script->addFeature($paging);
// Main frame // Main frame
$frame = $this->maniaControl->getManialinkManager() $frame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultListFrame($script, $paging);
->getStyleManager()
->getDefaultListFrame($script, $paging);
$maniaLink->add($frame); $maniaLink->add($frame);
// Start offsets // Start offsets
@ -192,9 +179,7 @@ class HelpManager implements CommandListener, CallbackListener {
$posY = $height / 2; $posY = $height / 2;
//Predefine description Label //Predefine description Label
$descriptionLabel = $this->maniaControl->getManialinkManager() $descriptionLabel = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultDescriptionLabel();
->getStyleManager()
->getDefaultDescriptionLabel();
$frame->add($descriptionLabel); $frame->add($descriptionLabel);
// Headline // Headline
@ -202,8 +187,7 @@ class HelpManager implements CommandListener, CallbackListener {
$frame->add($headFrame); $frame->add($headFrame);
$headFrame->setY($posY - 5); $headFrame->setY($posY - 5);
$array = array('Command' => $posX + 5, 'Description' => $posX + 50); $array = array('Command' => $posX + 5, 'Description' => $posX + 50);
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->labelLine($headFrame, $array);
->labelLine($headFrame, $array);
$index = 1; $index = 1;
$posY -= 10; $posY -= 10;
@ -230,8 +214,7 @@ class HelpManager implements CommandListener, CallbackListener {
} }
$array = array($command['Name'] => $posX + 5, $command['Description'] => $posX + 50); $array = array($command['Name'] => $posX + 5, $command['Description'] => $posX + 50);
$labels = $this->maniaControl->getManialinkManager() $labels = $this->maniaControl->getManialinkManager()->labelLine($playerFrame, $array);
->labelLine($playerFrame, $array);
$label = $labels[0]; $label = $labels[0];
$label->setWidth(40); $label->setWidth(40);
@ -241,8 +224,7 @@ class HelpManager implements CommandListener, CallbackListener {
} }
// Render and display xml // Render and display xml
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'HelpAllList');
->displayWidget($maniaLink, $player, 'HelpAllList');
} }
/** /**

View File

@ -70,36 +70,24 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
$this->addActionsMenuItem(); $this->addActionsMenuItem();
// Settings // Settings
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_POSX, 0.);
->initSetting($this, self::SETTING_MENU_POSX, 0.); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_POSY, 3.);
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_WIDTH, 170.);
->initSetting($this, self::SETTING_MENU_POSY, 3.); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_HEIGHT, 81.);
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_STYLE, Quad_BgRaceScore2::STYLE);
->initSetting($this, self::SETTING_MENU_WIDTH, 170.); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_SUBSTYLE, Quad_BgRaceScore2::SUBSTYLE_HandleSelectable);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_MENU_HEIGHT, 81.);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_MENU_STYLE, Quad_BgRaceScore2::STYLE);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_MENU_SUBSTYLE, Quad_BgRaceScore2::SUBSTYLE_HandleSelectable);
// Permissions // Permissions
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_OPEN_CONFIGURATOR, AuthenticationManager::AUTH_LEVEL_ADMIN);
->definePermissionLevel(self::SETTING_PERMISSION_OPEN_CONFIGURATOR, AuthenticationManager::AUTH_LEVEL_ADMIN);
// Page answers // Page answers
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_TOGGLEMENU, $this, 'handleToggleMenuAction');
->registerManialinkPageAnswerListener(self::ACTION_TOGGLEMENU, $this, 'handleToggleMenuAction'); $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_SAVECONFIG, $this, 'handleSaveConfigAction');
$this->maniaControl->getManialinkManager()
->registerManialinkPageAnswerListener(self::ACTION_SAVECONFIG, $this, 'handleSaveConfigAction');
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer'); $this->maniaControl->getCallbackManager()->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
// Create server options menu // Create server options menu
$this->serverOptionsMenu = new ServerOptionsMenu($maniaControl); $this->serverOptionsMenu = new ServerOptionsMenu($maniaControl);
@ -118,8 +106,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
$this->addMenu($this->maniaControlSettings); $this->addMenu($this->maniaControlSettings);
// Chat commands // Chat commands
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener('config', $this, 'handleConfigCommand', true, 'Loads Config panel.');
->registerCommandListener('config', $this, 'handleConfigCommand', true, 'Loads Config panel.');
} }
/** /**
@ -127,10 +114,8 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
*/ */
private function addActionsMenuItem() { private function addActionsMenuItem() {
$itemQuad = new Quad_UIConstruction_Buttons(); $itemQuad = new Quad_UIConstruction_Buttons();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Tools) $itemQuad->setSubStyle($itemQuad::SUBSTYLE_Tools)->setAction(self::ACTION_TOGGLEMENU);
->setAction(self::ACTION_TOGGLEMENU); $this->maniaControl->getActionsMenu()->addAdminMenuItem($itemQuad, 100, 'Settings');
$this->maniaControl->getActionsMenu()
->addAdminMenuItem($itemQuad, 100, 'Settings');
} }
/** /**
@ -149,11 +134,9 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
* @param Player $player * @param Player $player
*/ */
public function handleConfigCommand(array $callback, Player $player) { public function handleConfigCommand(array $callback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_OPEN_CONFIGURATOR)
->checkPermission($player, self::SETTING_PERMISSION_OPEN_CONFIGURATOR)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
@ -171,8 +154,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
$menuId = $this->getMenuId($menuId->getTitle()); $menuId = $this->getMenuId($menuId->getTitle());
} }
$manialink = $this->buildManialink($menuId, $player); $manialink = $this->buildManialink($menuId, $player);
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->displayWidget($manialink, $player, self::MENU_NAME);
->displayWidget($manialink, $player, self::MENU_NAME);
$player->setCache($this, self::CACHE_MENU_SHOWN, true); $player->setCache($this, self::CACHE_MENU_SHOWN, true);
} }
@ -201,18 +183,12 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
* @return \FML\ManiaLink * @return \FML\ManiaLink
*/ */
private function buildManialink($menuIdShown = 0, Player $player = null) { private function buildManialink($menuIdShown = 0, Player $player = null) {
$menuPosX = $this->maniaControl->getSettingManager() $menuPosX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_POSX);
->getSettingValue($this, self::SETTING_MENU_POSX); $menuPosY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_POSY);
$menuPosY = $this->maniaControl->getSettingManager() $menuWidth = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_WIDTH);
->getSettingValue($this, self::SETTING_MENU_POSY); $menuHeight = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_HEIGHT);
$menuWidth = $this->maniaControl->getSettingManager() $quadStyle = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_STYLE);
->getSettingValue($this, self::SETTING_MENU_WIDTH); $quadSubstyle = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_SUBSTYLE);
$menuHeight = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MENU_HEIGHT);
$quadStyle = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MENU_STYLE);
$quadSubstyle = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MENU_SUBSTYLE);
$menuListWidth = $menuWidth * 0.3; $menuListWidth = $menuWidth * 0.3;
$menuItemHeight = 10.; $menuItemHeight = 10.;
@ -227,9 +203,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
$backgroundQuad = new Quad(); $backgroundQuad = new Quad();
$frame->add($backgroundQuad); $frame->add($backgroundQuad);
$backgroundQuad->setZ(-10) $backgroundQuad->setZ(-10)->setSize($menuWidth, $menuHeight)->setStyles($quadStyle, $quadSubstyle);
->setSize($menuWidth, $menuHeight)
->setStyles($quadStyle, $quadSubstyle);
$menuItemsFrame = new Frame(); $menuItemsFrame = new Frame();
$frame->add($menuItemsFrame); $frame->add($menuItemsFrame);
@ -238,8 +212,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
$itemsBackgroundQuad = new Quad(); $itemsBackgroundQuad = new Quad();
$menuItemsFrame->add($itemsBackgroundQuad); $menuItemsFrame->add($itemsBackgroundQuad);
$backgroundQuad->setZ(-9); $backgroundQuad->setZ(-9);
$itemsBackgroundQuad->setSize($menuListWidth, $menuHeight) $itemsBackgroundQuad->setSize($menuListWidth, $menuHeight)->setStyles($quadStyle, $quadSubstyle);
->setStyles($quadStyle, $quadSubstyle);
$menusFrame = new Frame(); $menusFrame = new Frame();
$frame->add($menusFrame); $frame->add($menusFrame);
@ -254,11 +227,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
// Add title // Add title
$menuItemLabel = new Label_Text(); $menuItemLabel = new Label_Text();
$menuItemsFrame->add($menuItemLabel); $menuItemsFrame->add($menuItemLabel);
$menuItemLabel->setY($menuItemY) $menuItemLabel->setY($menuItemY)->setSize($menuListWidth * 0.9, $menuItemHeight * 0.9)->setStyle($menuItemLabel::STYLE_TextCardRaceRank)->setText($menu->getTitle())->setAction(self::ACTION_SELECTMENU . $menuId);
->setSize($menuListWidth * 0.9, $menuItemHeight * 0.9)
->setStyle($menuItemLabel::STYLE_TextCardRaceRank)
->setText($menu->getTitle())
->setAction(self::ACTION_SELECTMENU . $menuId);
// Show the menu // Show the menu
if ($menuId === $menuIdShown) { if ($menuId === $menuIdShown) {
@ -266,8 +235,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
if ($menuControl) { if ($menuControl) {
$menusFrame->add($menuControl); $menusFrame->add($menuControl);
} else { } else {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('Error loading Menu!', $player);
->sendError('Error loading Menu!', $player);
} }
} }
@ -278,32 +246,17 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
// Add Close Quad (X) // Add Close Quad (X)
$closeQuad = new Quad_Icons64x64_1(); $closeQuad = new Quad_Icons64x64_1();
$frame->add($closeQuad); $frame->add($closeQuad);
$closeQuad->setPosition($menuWidth * 0.483, $menuHeight * 0.467, 3) $closeQuad->setPosition($menuWidth * 0.483, $menuHeight * 0.467, 3)->setSize(6, 6)->setSubStyle($closeQuad::SUBSTYLE_QuitRace)->setAction(ManialinkManager::ACTION_CLOSEWIDGET);
->setSize(6, 6)
->setSubStyle($closeQuad::SUBSTYLE_QuitRace)
->setAction(ManialinkManager::ACTION_CLOSEWIDGET);
// Add close button // Add close button
$closeButton = new Label_Text(); $closeButton = new Label_Text();
$frame->add($closeButton); $frame->add($closeButton);
$closeButton->setPosition($menuWidth * -0.5 + $menuListWidth * 0.29, $menuHeight * -0.43) $closeButton->setPosition($menuWidth * -0.5 + $menuListWidth * 0.29, $menuHeight * -0.43)->setSize($menuListWidth * 0.3, $menuListWidth * 0.1)->setStyle($closeButton::STYLE_TextButtonNavBack)->setTextPrefix('$999')->setTranslate(true)->setText('Close')->setAction(self::ACTION_TOGGLEMENU);
->setSize($menuListWidth * 0.3, $menuListWidth * 0.1)
->setStyle($closeButton::STYLE_TextButtonNavBack)
->setTextPrefix('$999')
->setTranslate(true)
->setText('Close')
->setAction(self::ACTION_TOGGLEMENU);
// Add save button // Add save button
$saveButton = new Label_Text(); $saveButton = new Label_Text();
$frame->add($saveButton); $frame->add($saveButton);
$saveButton->setPosition($menuWidth * -0.5 + $menuListWidth * 0.71, $menuHeight * -0.43) $saveButton->setPosition($menuWidth * -0.5 + $menuListWidth * 0.71, $menuHeight * -0.43)->setSize($menuListWidth * 0.3, $menuListWidth * 0.1)->setStyle($saveButton::STYLE_TextButtonNavBack)->setTextPrefix('$0f5')->setTranslate(true)->setText('Save')->setAction(self::ACTION_SAVECONFIG);
->setSize($menuListWidth * 0.3, $menuListWidth * 0.1)
->setStyle($saveButton::STYLE_TextButtonNavBack)
->setTextPrefix('$0f5')
->setTranslate(true)
->setText('Save')
->setAction(self::ACTION_SAVECONFIG);
return $manialink; return $manialink;
} }
@ -338,8 +291,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
*/ */
public function hideMenu(Player $player) { public function hideMenu(Player $player) {
$this->closeWidget($player); $this->closeWidget($player);
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->closeWidget($player);
->closeWidget($player);
} }
/** /**
@ -388,8 +340,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
} }
$login = $callback[1][1]; $login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($login);
->getPlayer($login);
if ($player) { if ($player) {
$actionArray = explode('.', $callback[1][2]); $actionArray = explode('.', $callback[1][2]);

View File

@ -52,12 +52,10 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
// Permissions // Permissions
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_MC_SETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN);
->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_MC_SETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN);
} }
/** /**
@ -89,8 +87,7 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
* @return \FML\Controls\Frame * @return \FML\Controls\Frame
*/ */
private function getMenuSettingsForClass($settingClass, $width, $height, Script $script, Player $player) { private function getMenuSettingsForClass($settingClass, $width, $height, Script $script, Player $player) {
$settings = $this->maniaControl->getSettingManager() $settings = $this->maniaControl->getSettingManager()->getSettingsByClass($settingClass);
->getSettingsByClass($settingClass);
$paging = new Paging(); $paging = new Paging();
$script->addFeature($paging); $script->addFeature($paging);
@ -217,8 +214,7 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
* @return \FML\Controls\Frame * @return \FML\Controls\Frame
*/ */
private function getMenuSettingClasses($width, $height, Script $script, Player $player) { private function getMenuSettingClasses($width, $height, Script $script, Player $player) {
$settingClasses = $this->maniaControl->getSettingManager() $settingClasses = $this->maniaControl->getSettingManager()->getSettingClasses(true);
->getSettingClasses(true);
$paging = new Paging(); $paging = new Paging();
$script->addFeature($paging); $script->addFeature($paging);
@ -301,26 +297,20 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
if ($actionId === self::ACTION_SETTINGCLASS_BACK) { if ($actionId === self::ACTION_SETTINGCLASS_BACK) {
// Back to classes list // Back to classes list
$login = $callback[1][1]; $login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($login);
->getPlayer($login);
$player->destroyCache($this, self::CACHE_CLASS_OPENED); $player->destroyCache($this, self::CACHE_CLASS_OPENED);
$menuId = $this->maniaControl->getConfigurator() $menuId = $this->maniaControl->getConfigurator()->getMenuId($this);
->getMenuId($this); $this->maniaControl->getConfigurator()->showMenu($player, $menuId);
$this->maniaControl->getConfigurator()
->showMenu($player, $menuId);
} else if (strpos($actionId, self::ACTION_PREFIX_SETTINGCLASS) === 0) { } else if (strpos($actionId, self::ACTION_PREFIX_SETTINGCLASS) === 0) {
// Setting class selected // Setting class selected
$settingClass = substr($actionId, strlen(self::ACTION_PREFIX_SETTINGCLASS)); $settingClass = substr($actionId, strlen(self::ACTION_PREFIX_SETTINGCLASS));
$login = $callback[1][1]; $login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($login);
->getPlayer($login);
$player->setCache($this, self::CACHE_CLASS_OPENED, $settingClass); $player->setCache($this, self::CACHE_CLASS_OPENED, $settingClass);
$menuId = $this->maniaControl->getConfigurator() $menuId = $this->maniaControl->getConfigurator()->getMenuId($this);
->getMenuId($this); $this->maniaControl->getConfigurator()->showMenu($player, $menuId);
$this->maniaControl->getConfigurator()
->showMenu($player, $menuId);
} }
} }
@ -328,11 +318,9 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData() * @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
*/ */
public function saveConfigData(array $configData, Player $player) { public function saveConfigData(array $configData, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_CHANGE_MC_SETTINGS)
->checkPermission($player, self::SETTING_PERMISSION_CHANGE_MC_SETTINGS)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING) !== 0) { if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING) !== 0) {
@ -343,8 +331,7 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
foreach ($configData[3] as $settingData) { foreach ($configData[3] as $settingData) {
$settingIndex = (int)substr($settingData['Name'], $prefixLength); $settingIndex = (int)substr($settingData['Name'], $prefixLength);
$settingObject = $this->maniaControl->getSettingManager() $settingObject = $this->maniaControl->getSettingManager()->getSettingObjectByIndex($settingIndex);
->getSettingObjectByIndex($settingIndex);
if (!$settingObject) { if (!$settingObject) {
continue; continue;
} }
@ -354,15 +341,12 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
} }
$settingObject->value = $settingData['Value']; $settingObject->value = $settingData['Value'];
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->saveSetting($settingObject);
->saveSetting($settingObject);
} }
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess('Settings saved!', $player);
->sendSuccess('Settings saved!', $player);
// Reopen the Menu // Reopen the Menu
$this->maniaControl->getConfigurator() $this->maniaControl->getConfigurator()->showMenu($player, $this);
->showMenu($player, $this);
} }
} }

View File

@ -53,18 +53,14 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
$this->initTables(); $this->initTables();
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONINIT, $this, 'onInit');
->registerCallbackListener(Callbacks::ONINIT, $this, 'onInit'); $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::BEGINMAP, $this, 'onBeginMap');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(Callbacks::BEGINMAP, $this, 'onBeginMap');
// Settings // Settings
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN, false);
->initSetting($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN, false);
// Permissions // Permissions
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_SCRIPT_SETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN);
->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_SCRIPT_SETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN);
} }
/** /**
@ -73,8 +69,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
* @return boolean * @return boolean
*/ */
private function initTables() { private function initTables() {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_SCRIPT_SETTINGS . "` ( $query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_SCRIPT_SETTINGS . "` (
`index` int(11) NOT NULL AUTO_INCREMENT, `index` int(11) NOT NULL AUTO_INCREMENT,
`serverIndex` int(11) NOT NULL, `serverIndex` int(11) NOT NULL,
@ -119,14 +114,12 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
*/ */
public function loadSettingsFromDatabase() { public function loadSettingsFromDatabase() {
try { try {
$scriptSettings = $this->maniaControl->getClient() $scriptSettings = $this->maniaControl->getClient()->getModeScriptSettings();
->getModeScriptSettings();
} catch (GameModeException $e) { } catch (GameModeException $e) {
return false; return false;
} }
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$serverIndex = $this->maniaControl->getServer()->index; $serverIndex = $this->maniaControl->getServer()->index;
$query = "SELECT * FROM `" . self::TABLE_SCRIPT_SETTINGS . "` $query = "SELECT * FROM `" . self::TABLE_SCRIPT_SETTINGS . "`
WHERE serverIndex = {$serverIndex};"; WHERE serverIndex = {$serverIndex};";
@ -149,16 +142,14 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
return true; return true;
} }
return $this->maniaControl->getClient() return $this->maniaControl->getClient()->setModeScriptSettings($loadedSettings);
->setModeScriptSettings($loadedSettings);
} }
/** /**
* Handle Begin Map Callback * Handle Begin Map Callback
*/ */
public function onBeginMap() { public function onBeginMap() {
if ($this->maniaControl->getSettingManager() if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN)
->getSettingValue($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN)
) { ) {
$this->loadSettingsFromDatabase(); $this->loadSettingsFromDatabase();
} }
@ -173,8 +164,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
$frame = new Frame(); $frame = new Frame();
try { try {
$scriptInfo = $this->maniaControl->getClient() $scriptInfo = $this->maniaControl->getClient()->getModeScriptInfo();
->getModeScriptInfo();
} catch (GameModeException $e) { } catch (GameModeException $e) {
$label = new Label(); $label = new Label();
$frame->add($label); $frame->add($label);
@ -185,8 +175,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
$scriptParams = $scriptInfo->paramDescs; $scriptParams = $scriptInfo->paramDescs;
try { try {
$scriptSettings = $this->maniaControl->getClient() $scriptSettings = $this->maniaControl->getClient()->getModeScriptSettings();
->getModeScriptSettings();
} catch (GameModeException $e) { } catch (GameModeException $e) {
} }
@ -293,11 +282,9 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData() * @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
*/ */
public function saveConfigData(array $configData, Player $player) { public function saveConfigData(array $configData, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_CHANGE_SCRIPT_SETTINGS)
->checkPermission($player, self::SETTING_PERMISSION_CHANGE_SCRIPT_SETTINGS)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING) !== 0) { if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING) !== 0) {
@ -305,8 +292,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
} }
try { try {
$scriptSettings = $this->maniaControl->getClient() $scriptSettings = $this->maniaControl->getClient()->getModeScriptSettings();
->getModeScriptSettings();
} catch (GameModeException $e) { } catch (GameModeException $e) {
return; return;
} }
@ -332,16 +318,13 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
$success = $this->applyNewScriptSettings($newSettings, $player); $success = $this->applyNewScriptSettings($newSettings, $player);
if ($success) { if ($success) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess('Script Settings saved!', $player);
->sendSuccess('Script Settings saved!', $player);
} else { } else {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('Script Settings Saving failed!', $player);
->sendError('Script Settings Saving failed!', $player);
} }
// Reopen the Menu // Reopen the Menu
$this->maniaControl->getConfigurator() $this->maniaControl->getConfigurator()->showMenu($player, $this);
->showMenu($player, $this);
} }
/** /**
@ -356,12 +339,10 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
return true; return true;
} }
$this->maniaControl->getClient() $this->maniaControl->getClient()->setModeScriptSettings($newSettings);
->setModeScriptSettings($newSettings);
// Save Settings into Database // Save Settings into Database
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$query = "INSERT INTO `" . self::TABLE_SCRIPT_SETTINGS . "` ( $query = "INSERT INTO `" . self::TABLE_SCRIPT_SETTINGS . "` (
`serverIndex`, `serverIndex`,
`settingName`, `settingName`,
@ -382,8 +363,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
// Notifications // Notifications
$settingsCount = count($newSettings); $settingsCount = count($newSettings);
$settingIndex = 0; $settingIndex = 0;
$title = $this->maniaControl->getAuthenticationManager() $title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($player);
->getAuthLevelName($player);
$chatMessage = '$ff0' . $title . ' ' . $player->getEscapedNickname() . ' set ScriptSetting' . ($settingsCount > 1 ? 's' : '') . ' '; $chatMessage = '$ff0' . $title . ' ' . $player->getEscapedNickname() . ' set ScriptSetting' . ($settingsCount > 1 ? 's' : '') . ' ';
foreach ($newSettings as $setting => $value) { foreach ($newSettings as $setting => $value) {
$chatMessage .= '$<' . '$fff' . preg_replace('/^S_/', '', $setting) . '$z$s$ff0 '; $chatMessage .= '$<' . '$fff' . preg_replace('/^S_/', '', $setting) . '$z$s$ff0 ';
@ -402,19 +382,16 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
} }
// Trigger own callback // Trigger own callback
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_SCRIPTSETTING_CHANGED, $setting, $value);
->triggerCallback(self::CB_SCRIPTSETTING_CHANGED, $setting, $value);
$settingIndex++; $settingIndex++;
} }
$statement->close(); $statement->close();
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_SCRIPTSETTINGS_CHANGED);
->triggerCallback(self::CB_SCRIPTSETTINGS_CHANGED);
$chatMessage .= '!'; $chatMessage .= '!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation($chatMessage);
->sendInformation($chatMessage);
Logger::logInfo($chatMessage, true); Logger::logInfo($chatMessage, true);
return true; return true;
} }

View File

@ -49,15 +49,13 @@ class Database implements TimerListener {
$message = "Couldn't connect to Database: '{$connectError}'"; $message = "Couldn't connect to Database: '{$connectError}'";
$this->maniaControl->quit($message, true); $this->maniaControl->quit($message, true);
} }
$this->getMysqli() $this->getMysqli()->set_charset("utf8");
->set_charset("utf8");
$this->initDatabase(); $this->initDatabase();
$this->optimizeTables(); $this->optimizeTables();
// Register Method which checks the Database Connection every 5 seconds // Register Method which checks the Database Connection every 5 seconds
$this->maniaControl->getTimerManager() $this->maniaControl->getTimerManager()->registerTimerListening($this, 'checkConnection', 5000);
->registerTimerListening($this, 'checkConnection', 5000);
// Children // Children
$this->migrationHelper = new MigrationHelper($maniaControl); $this->migrationHelper = new MigrationHelper($maniaControl);
@ -67,8 +65,7 @@ class Database implements TimerListener {
* Load the Database Config * Load the Database Config
*/ */
private function loadConfig() { private function loadConfig() {
$databaseElements = $this->maniaControl->getConfig() $databaseElements = $this->maniaControl->getConfig()->xpath('database');
->xpath('database');
if (!$databaseElements) { if (!$databaseElements) {
$this->maniaControl->quit('No Database configured!', true); $this->maniaControl->quit('No Database configured!', true);
} }
@ -127,26 +124,22 @@ class Database implements TimerListener {
*/ */
private function initDatabase() { private function initDatabase() {
// Try to connect // Try to connect
$result = $this->getMysqli() $result = $this->getMysqli()->select_db($this->config->name);
->select_db($this->config->name);
if ($result) { if ($result) {
return true; return true;
} }
Logger::logInfo("Database '{$this->config->name}' doesn't exist! Trying to create it..."); Logger::logInfo("Database '{$this->config->name}' doesn't exist! Trying to create it...");
// Create database // Create database
$databaseQuery = "CREATE DATABASE " . $this->getMysqli() $databaseQuery = "CREATE DATABASE " . $this->getMysqli()->escape_string($this->config->name) . ";";
->escape_string($this->config->name) . ";"; $this->getMysqli()->query($databaseQuery);
$this->getMysqli()
->query($databaseQuery);
if ($this->getMysqli()->error) { if ($this->getMysqli()->error) {
$this->maniaControl->quit($this->getMysqli()->error, true); $this->maniaControl->quit($this->getMysqli()->error, true);
return false; return false;
} }
// Connect to new database // Connect to new database
$this->getMysqli() $this->getMysqli()->select_db($this->config->name);
->select_db($this->config->name);
if ($error = $this->getMysqli()->error) { if ($error = $this->getMysqli()->error) {
$message = "Couldn't select database '{$this->config->name}'. {$error}"; $message = "Couldn't select database '{$this->config->name}'. {$error}";
$this->maniaControl->quit($message, true); $this->maniaControl->quit($message, true);
@ -163,8 +156,7 @@ class Database implements TimerListener {
*/ */
private function optimizeTables() { private function optimizeTables() {
$showQuery = 'SHOW TABLES;'; $showQuery = 'SHOW TABLES;';
$result = $this->getMysqli() $result = $this->getMysqli()->query($showQuery);
->query($showQuery);
if ($error = $this->getMysqli()->error) { if ($error = $this->getMysqli()->error) {
Logger::logError($error); Logger::logError($error);
return false; return false;
@ -186,8 +178,7 @@ class Database implements TimerListener {
} }
$result->free(); $result->free();
$optimizeQuery .= ';'; $optimizeQuery .= ';';
$this->getMysqli() $this->getMysqli()->query($optimizeQuery);
->query($optimizeQuery);
if ($error = $this->getMysqli()->error) { if ($error = $this->getMysqli()->error) {
Logger::logError($error); Logger::logError($error);
return false; return false;
@ -227,8 +218,7 @@ class Database implements TimerListener {
*/ */
public function checkConnection() { public function checkConnection() {
if (!$this->getMysqli() if (!$this->getMysqli()
|| !$this->getMysqli() || !$this->getMysqli()->ping()
->ping()
) { ) {
$this->maniaControl->quit('The MySQL Server has gone away!', true); $this->maniaControl->quit('The MySQL Server has gone away!', true);
} }
@ -239,8 +229,7 @@ class Database implements TimerListener {
*/ */
public function __destruct() { public function __destruct() {
if ($this->getMysqli() && !$this->getMysqli()->connect_error) { if ($this->getMysqli() && !$this->getMysqli()->connect_error) {
$this->getMysqli() $this->getMysqli()->close();
->close();
} }
} }
} }

View File

@ -40,8 +40,7 @@ class MigrationHelper {
$sourceClass = ClassUtil::getClass($sourceClass); $sourceClass = ClassUtil::getClass($sourceClass);
$targetClass = ClassUtil::getClass($targetClass); $targetClass = ClassUtil::getClass($targetClass);
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$query = "INSERT IGNORE INTO `" . SettingManager::TABLE_SETTINGS . "` $query = "INSERT IGNORE INTO `" . SettingManager::TABLE_SETTINGS . "`
(`class`, `setting`, `type`, `value`, `default`) (`class`, `setting`, `type`, `value`, `default`)

View File

@ -47,8 +47,7 @@ class ErrorHandler {
* Initialize error handler features * Initialize error handler features
*/ */
public function init() { public function init() {
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_RESTART_ON_EXCEPTION, true);
->initSetting($this, self::SETTING_RESTART_ON_EXCEPTION, true);
} }
/** /**
@ -126,8 +125,7 @@ class ErrorHandler {
if ($pluginId > 0) { if ($pluginId > 0) {
$report['PluginId'] = $pluginId; $report['PluginId'] = $pluginId;
if ($isFatalError) { if ($isFatalError) {
$this->maniaControl->getPluginManager() $this->maniaControl->getPluginManager()->deactivatePlugin($sourceClass);
->deactivatePlugin($sourceClass);
} }
} }
} }
@ -142,10 +140,8 @@ class ErrorHandler {
} }
if ($this->maniaControl->getSettingManager() && $this->maniaControl->getUpdateManager()) { if ($this->maniaControl->getSettingManager() && $this->maniaControl->getUpdateManager()) {
$report['UpdateChannel'] = $this->maniaControl->getSettingManager() $report['UpdateChannel'] = $this->maniaControl->getSettingManager()->getSettingValue($this->maniaControl->getUpdateManager(), UpdateManager::SETTING_UPDATECHECK_CHANNEL);
->getSettingValue($this->maniaControl->getUpdateManager(), UpdateManager::SETTING_UPDATECHECK_CHANNEL); $report['ManiaControlVersion'] = ManiaControl::VERSION . ' ' . $this->maniaControl->getUpdateManager()->getNightlyBuildDate();
$report['ManiaControlVersion'] = ManiaControl::VERSION . ' ' . $this->maniaControl->getUpdateManager()
->getNightlyBuildDate();
} else { } else {
$report['ManiaControlVersion'] = ManiaControl::VERSION; $report['ManiaControlVersion'] = ManiaControl::VERSION;
} }
@ -399,20 +395,17 @@ class ErrorHandler {
if ($this->maniaControl->getCallbackManager()) { if ($this->maniaControl->getCallbackManager()) {
// OnShutdown callback // OnShutdown callback
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONSHUTDOWN);
->triggerCallback(Callbacks::ONSHUTDOWN);
} }
if ($this->maniaControl->getChat()) { if ($this->maniaControl->getChat()) {
// Announce quit // Announce quit
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation('ManiaControl shutting down.');
->sendInformation('ManiaControl shutting down.');
} }
if ($this->maniaControl->getClient()) { if ($this->maniaControl->getClient()) {
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->sendHideManialinkPage();
->sendHideManialinkPage();
} catch (TransportException $e) { } catch (TransportException $e) {
$this->handleException($e, false); $this->handleException($e, false);
} }
@ -460,10 +453,8 @@ class ErrorHandler {
} }
if ($this->maniaControl->getSettingManager() && $this->maniaControl->getUpdateManager()) { if ($this->maniaControl->getSettingManager() && $this->maniaControl->getUpdateManager()) {
$report['UpdateChannel'] = $this->maniaControl->getSettingManager() $report['UpdateChannel'] = $this->maniaControl->getSettingManager()->getSettingValue($this->maniaControl->getUpdateManager(), UpdateManager::SETTING_UPDATECHECK_CHANNEL);
->getSettingValue($this->maniaControl->getUpdateManager(), UpdateManager::SETTING_UPDATECHECK_CHANNEL); $report['ManiaControlVersion'] = ManiaControl::VERSION . ' #' . $this->maniaControl->getUpdateManager()->getNightlyBuildDate();
$report['ManiaControlVersion'] = ManiaControl::VERSION . ' #' . $this->maniaControl->getUpdateManager()
->getNightlyBuildDate();
} else { } else {
$report['ManiaControlVersion'] = ManiaControl::VERSION; $report['ManiaControlVersion'] = ManiaControl::VERSION;
} }
@ -499,8 +490,7 @@ class ErrorHandler {
if (!$this->maniaControl || !$this->maniaControl->getSettingManager() || DEV_MODE) { if (!$this->maniaControl || !$this->maniaControl->getSettingManager() || DEV_MODE) {
return false; return false;
} }
$setting = $this->maniaControl->getSettingManager() $setting = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_RESTART_ON_EXCEPTION, true);
->getSettingValue($this, self::SETTING_RESTART_ON_EXCEPTION, true);
return $setting; return $setting;
} }
} }

View File

@ -38,9 +38,7 @@ class AsynchronousFileReader {
public static function newRequestTest($url) { public static function newRequestTest($url) {
$request = new Request($url); $request = new Request($url);
$request->getOptions() $request->getOptions()->set(CURLOPT_TIMEOUT, 60)->set(CURLOPT_HEADER, false) // don't display response header
->set(CURLOPT_TIMEOUT, 60)
->set(CURLOPT_HEADER, false) // don't display response header
->set(CURLOPT_CRLF, true) // linux line feed ->set(CURLOPT_CRLF, true) // linux line feed
->set(CURLOPT_ENCODING, '') // accept encoding ->set(CURLOPT_ENCODING, '') // accept encoding
->set(CURLOPT_USERAGENT, 'ManiaControl v' . ManiaControl::VERSION) // user-agent ->set(CURLOPT_USERAGENT, 'ManiaControl v' . ManiaControl::VERSION) // user-agent
@ -78,16 +76,14 @@ class AsynchronousFileReader {
} }
$request = $this->newRequest($url); $request = $this->newRequest($url);
$request->getOptions() $request->getOptions()->set(CURLOPT_AUTOREFERER, true) // accept link reference
->set(CURLOPT_AUTOREFERER, true) // accept link reference
->set(CURLOPT_HTTPHEADER, $headers); // headers ->set(CURLOPT_HTTPHEADER, $headers); // headers
$request->addListener('complete', function (Event $event) use (&$function) { $request->addListener('complete', function (Event $event) use (&$function) {
$error = null; $error = null;
$content = null; $content = null;
if ($event->response->hasError()) { if ($event->response->hasError()) {
$error = $event->response->getError() $error = $event->response->getError()->getMessage();
->getMessage();
} else { } else {
$content = $event->response->getContent(); $content = $event->response->getContent();
} }
@ -105,9 +101,7 @@ class AsynchronousFileReader {
*/ */
protected function newRequest($url) { protected function newRequest($url) {
$request = new Request($url); $request = new Request($url);
$request->getOptions() $request->getOptions()->set(CURLOPT_TIMEOUT, 60)->set(CURLOPT_HEADER, false) // don't display response header
->set(CURLOPT_TIMEOUT, 60)
->set(CURLOPT_HEADER, false) // don't display response header
->set(CURLOPT_CRLF, true) // linux line feed ->set(CURLOPT_CRLF, true) // linux line feed
->set(CURLOPT_ENCODING, '') // accept encoding ->set(CURLOPT_ENCODING, '') // accept encoding
->set(CURLOPT_USERAGENT, 'ManiaControl v' . ManiaControl::VERSION) // user-agent ->set(CURLOPT_USERAGENT, 'ManiaControl v' . ManiaControl::VERSION) // user-agent
@ -140,8 +134,7 @@ class AsynchronousFileReader {
array_push($headers, 'Content-Encoding: gzip'); array_push($headers, 'Content-Encoding: gzip');
} }
$request->getOptions() $request->getOptions()->set(CURLOPT_POST, true) // post method
->set(CURLOPT_POST, true) // post method
->set(CURLOPT_POSTFIELDS, $content) // post content field ->set(CURLOPT_POSTFIELDS, $content) // post content field
->set(CURLOPT_HTTPHEADER, $headers) // headers ->set(CURLOPT_HTTPHEADER, $headers) // headers
; ;
@ -149,8 +142,7 @@ class AsynchronousFileReader {
$error = null; $error = null;
$content = null; $content = null;
if ($event->response->hasError()) { if ($event->response->hasError()) {
$error = $event->response->getError() $error = $event->response->getError()->getMessage();
->getMessage();
} else { } else {
$content = $event->response->getContent(); $content = $event->response->getContent();
} }
@ -186,8 +178,7 @@ class AsynchronousFileReader {
} }
$request = $this->newRequest($url); $request = $this->newRequest($url);
$request->getOptions() $request->getOptions()->set(CURLOPT_POST, true) // post method
->set(CURLOPT_POST, true) // post method
->set(CURLOPT_POSTFIELDS, $content) // post content field ->set(CURLOPT_POSTFIELDS, $content) // post content field
->set(CURLOPT_HTTPHEADER, $headers) // headers ->set(CURLOPT_HTTPHEADER, $headers) // headers
; ;
@ -195,8 +186,7 @@ class AsynchronousFileReader {
$error = null; $error = null;
$content = null; $content = null;
if ($event->response->hasError()) { if ($event->response->hasError()) {
$error = $event->response->getError() $error = $event->response->getError()->getMessage();
->getMessage();
} else { } else {
$content = $event->response->getContent(); $content = $event->response->getContent();
} }

View File

@ -155,26 +155,19 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
$this->pluginManager = new PluginManager($this); $this->pluginManager = new PluginManager($this);
$this->updateManager = new UpdateManager($this); $this->updateManager = new UpdateManager($this);
$this->getErrorHandler() $this->getErrorHandler()->init();
->init();
// Permissions // Permissions
$this->getAuthenticationManager() $this->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_SHUTDOWN, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
->definePermissionLevel(self::SETTING_PERMISSION_SHUTDOWN, AuthenticationManager::AUTH_LEVEL_SUPERADMIN); $this->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_RESTART, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
$this->getAuthenticationManager()
->definePermissionLevel(self::SETTING_PERMISSION_RESTART, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
// Commands // Commands
$this->getCommandManager() $this->getCommandManager()->registerCommandListener('version', $this, 'commandVersion', false, 'Shows ManiaControl version.');
->registerCommandListener('version', $this, 'commandVersion', false, 'Shows ManiaControl version.'); $this->getCommandManager()->registerCommandListener('restart', $this, 'commandRestart', true, 'Restarts ManiaControl.');
$this->getCommandManager() $this->getCommandManager()->registerCommandListener('shutdown', $this, 'commandShutdown', true, 'Shuts ManiaControl down.');
->registerCommandListener('restart', $this, 'commandRestart', true, 'Restarts ManiaControl.');
$this->getCommandManager()
->registerCommandListener('shutdown', $this, 'commandShutdown', true, 'Shuts ManiaControl down.');
// Check connection every 30 seconds // Check connection every 30 seconds
$this->getTimerManager() $this->getTimerManager()->registerTimerListening($this, 'checkConnection', 1000 * 30);
->registerTimerListening($this, 'checkConnection', 1000 * 30);
} }
/** /**
@ -410,11 +403,9 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
* Check connection * Check connection
*/ */
public function checkConnection() { public function checkConnection() {
if ($this->getClient() if ($this->getClient()->getIdleTime() > 180
->getIdleTime() > 180
) { ) {
$this->getClient() $this->getClient()->getServerName();
->getServerName();
} }
} }
@ -426,8 +417,7 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
*/ */
public function commandVersion(array $chatCallback, Player $player) { public function commandVersion(array $chatCallback, Player $player) {
$message = 'This server is using ManiaControl v' . ManiaControl::VERSION . '!'; $message = 'This server is using ManiaControl v' . ManiaControl::VERSION . '!';
$this->getChat() $this->getChat()->sendInformation($message, $player);
->sendInformation($message, $player);
} }
/** /**
@ -437,11 +427,9 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
* @param Player $player * @param Player $player
*/ */
public function commandRestart(array $chatCallback, Player $player) { public function commandRestart(array $chatCallback, Player $player) {
if (!$this->getAuthenticationManager() if (!$this->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_RESTART)
->checkPermission($player, self::SETTING_PERMISSION_RESTART)
) { ) {
$this->getAuthenticationManager() $this->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$this->restart("ManiaControl Restart requested by '{$player->login}'!"); $this->restart("ManiaControl Restart requested by '{$player->login}'!");
@ -454,21 +442,18 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
*/ */
public function restart($message = null) { public function restart($message = null) {
// Shutdown callback // Shutdown callback
$this->getCallbackManager() $this->getCallbackManager()->triggerCallback(Callbacks::ONSHUTDOWN);
->triggerCallback(Callbacks::ONSHUTDOWN);
// Announce restart // Announce restart
if ($message) { if ($message) {
Logger::log($message); Logger::log($message);
} }
$this->getChat() $this->getChat()->sendInformation('Restarting ManiaControl...');
->sendInformation('Restarting ManiaControl...');
Logger::log('Restarting ManiaControl!'); Logger::log('Restarting ManiaControl!');
// Hide widgets // Hide widgets
if ($this->getClient()) { if ($this->getClient()) {
$this->getClient() $this->getClient()->sendHideManialinkPage();
->sendHideManialinkPage();
} }
// Start new instance // Start new instance
@ -485,11 +470,9 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
* @param Player $player * @param Player $player
*/ */
public function commandShutdown(array $chat, Player $player) { public function commandShutdown(array $chat, Player $player) {
if (!$this->getAuthenticationManager() if (!$this->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_SHUTDOWN)
->checkPermission($player, self::SETTING_PERMISSION_SHUTDOWN)
) { ) {
$this->getAuthenticationManager() $this->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$this->requestQuit("ManiaControl Shutdown requested by '{$player->login}'!"); $this->requestQuit("ManiaControl Shutdown requested by '{$player->login}'!");
@ -518,37 +501,28 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
} }
// Check if the version of the server is high enough // Check if the version of the server is high enough
$version = $this->getClient() $version = $this->getClient()->getVersion();
->getVersion();
if ($version->build < self::MIN_DEDIVERSION) { if ($version->build < self::MIN_DEDIVERSION) {
$this->quit("The Server has Version '{$version->build}', while at least '" . self::MIN_DEDIVERSION . "' is required!", true); $this->quit("The Server has Version '{$version->build}', while at least '" . self::MIN_DEDIVERSION . "' is required!", true);
} }
// Listen for shutdown // Listen for shutdown
$this->getCallbackManager() $this->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_SERVERSTOP, $this, 'handleServerStopCallback');
->registerCallbackListener(CallbackManager::CB_MP_SERVERSTOP, $this, 'handleServerStopCallback');
// OnInit callback // OnInit callback
$this->getCallbackManager() $this->getCallbackManager()->triggerCallback(Callbacks::ONINIT);
->triggerCallback(Callbacks::ONINIT);
// Load plugins // Load plugins
$this->getPluginManager() $this->getPluginManager()->loadPlugins();
->loadPlugins(); $this->getUpdateManager()->getPluginUpdateManager()->checkPluginsUpdate();
$this->getUpdateManager()
->getPluginUpdateManager()
->checkPluginsUpdate();
// AfterInit callback // AfterInit callback
$this->getCallbackManager() $this->getCallbackManager()->triggerCallback(Callbacks::AFTERINIT);
->triggerCallback(Callbacks::AFTERINIT);
// Loading finished // Loading finished
Logger::log('Loading completed!'); Logger::log('Loading completed!');
Logger::log('Link: ' . $this->getServer() Logger::log('Link: ' . $this->getServer()->getJoinLink());
->getJoinLink()); $this->getChat()->sendInformation('ManiaControl v' . self::VERSION . ' successfully started!');
$this->getChat()
->sendInformation('ManiaControl v' . self::VERSION . ' successfully started!');
// Main loop // Main loop
while (!$this->requestQuitMessage) { while (!$this->requestQuitMessage) {
@ -564,8 +538,7 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
*/ */
private function connect() { private function connect() {
// Load remote client // Load remote client
$serverConfig = $this->getServer() $serverConfig = $this->getServer()->loadConfig();
->loadConfig();
Logger::log("Connecting to Server at {$serverConfig->host}:{$serverConfig->port}..."); Logger::log("Connecting to Server at {$serverConfig->host}:{$serverConfig->port}...");
@ -580,12 +553,10 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
} }
// Enable callback system // Enable callback system
$this->getClient() $this->getClient()->enableCallbacks(true);
->enableCallbacks(true);
// Wait for server to be ready // Wait for server to be ready
if (!$this->getServer() if (!$this->getServer()->waitForStatus(4)
->waitForStatus(4)
) { ) {
$this->quit("Server couldn't get ready!"); $this->quit("Server couldn't get ready!");
} }
@ -594,13 +565,10 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
Logger::log('Server Connection successfully established!'); Logger::log('Server Connection successfully established!');
// Hide old widgets // Hide old widgets
$this->getClient() $this->getClient()->sendHideManialinkPage();
->sendHideManialinkPage();
// Enable script callbacks // Enable script callbacks
$this->getServer() $this->getServer()->getScriptManager()->enableScriptCallbacks();
->getScriptManager()
->enableScriptCallbacks();
} }
/** /**
@ -613,16 +581,14 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
set_time_limit(self::SCRIPT_TIMEOUT); set_time_limit(self::SCRIPT_TIMEOUT);
try { try {
$this->getCallbackManager() $this->getCallbackManager()->manageCallbacks();
->manageCallbacks();
} catch (TransportException $e) { } catch (TransportException $e) {
Logger::logError('Connection interrupted!'); Logger::logError('Connection interrupted!');
$this->quit($e->getMessage(), true); $this->quit($e->getMessage(), true);
} }
// Manage FileReader // Manage FileReader
$this->getFileReader() $this->getFileReader()->appendData();
->appendData();
// Yield for next tick // Yield for next tick
$loopEnd = microtime(true); $loopEnd = microtime(true);

View File

@ -58,17 +58,12 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget'); $this->maniaControl->getCallbackManager()->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_SEARCH_MAPNAME, $this, 'showList');
->registerManialinkPageAnswerListener(self::ACTION_SEARCH_MAPNAME, $this, 'showList'); $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_SEARCH_AUTHOR, $this, 'showList');
$this->maniaControl->getManialinkManager()
->registerManialinkPageAnswerListener(self::ACTION_SEARCH_AUTHOR, $this, 'showList');
} }
/** /**
@ -85,8 +80,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
$action = $actionArray[0] . '.' . $actionArray[1]; $action = $actionArray[0] . '.' . $actionArray[1];
$login = $callback[1][1]; $login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($login);
->getPlayer($login);
$mapId = (int)$actionArray[2]; $mapId = (int)$actionArray[2];
switch ($action) { switch ($action) {
@ -95,8 +89,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
$this->showList($callback, $player); $this->showList($callback, $player);
break; break;
case self::ACTION_ADD_MAP: case self::ACTION_ADD_MAP:
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->addMapFromMx($mapId, $player->login);
->addMapFromMx($mapId, $player->login);
break; break;
} }
} }
@ -138,12 +131,9 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
} }
// search for matching maps // search for matching maps
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->getMXManager()->fetchMapsAsync(function (array $maps) use (&$player) {
->getMXManager()
->fetchMapsAsync(function (array $maps) use (&$player) {
if (!$maps) { if (!$maps) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('No maps found, or MX is down!', $player->login);
->sendError('No maps found, or MX is down!', $player->login);
return; return;
} }
$this->showManiaExchangeList($maps, $player); $this->showManiaExchangeList($maps, $player);
@ -159,12 +149,8 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
*/ */
private function showManiaExchangeList(array $maps, Player $player) { private function showManiaExchangeList(array $maps, Player $player) {
// Start offsets // Start offsets
$width = $this->maniaControl->getManialinkManager() $width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
->getStyleManager() $height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
->getListWidgetsWidth();
$height = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getListWidgetsHeight();
$posX = -$width / 2; $posX = -$width / 2;
$posY = $height / 2; $posY = $height / 2;
@ -175,15 +161,11 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
$script->addFeature($paging); $script->addFeature($paging);
// Main frame // Main frame
$frame = $this->maniaControl->getManialinkManager() $frame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultListFrame($script, $paging);
->getStyleManager()
->getDefaultListFrame($script, $paging);
$maniaLink->add($frame); $maniaLink->add($frame);
//Predefine description Label //Predefine description Label
$descriptionLabel = $this->maniaControl->getManialinkManager() $descriptionLabel = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultDescriptionLabel();
->getStyleManager()
->getDefaultDescriptionLabel();
$frame->add($descriptionLabel); $frame->add($descriptionLabel);
// Headline // Headline
@ -191,8 +173,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
$frame->add($headFrame); $frame->add($headFrame);
$headFrame->setY($posY - 12); $headFrame->setY($posY - 12);
$array = array('$oId' => $posX + 3.5, '$oName' => $posX + 12.5, '$oAuthor' => $posX + 59, '$oKarma' => $posX + 85, '$oType' => $posX + 103, '$oMood' => $posX + 118, '$oLast Update' => $posX + 130); $array = array('$oId' => $posX + 3.5, '$oName' => $posX + 12.5, '$oAuthor' => $posX + 59, '$oKarma' => $posX + 85, '$oType' => $posX + 103, '$oMood' => $posX + 118, '$oLast Update' => $posX + 130);
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->labelLine($headFrame, $array);
->labelLine($headFrame, $array);
$index = 0; $index = 0;
$posY = $height / 2 - 16; $posY = $height / 2 - 16;
@ -221,8 +202,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
$time = Formatter::time_elapsed_string(strtotime($map->updated)); $time = Formatter::time_elapsed_string(strtotime($map->updated));
$array = array('$s' . $map->id => $posX + 3.5, '$s' . $map->name => $posX + 12.5, '$s' . $map->author => $posX + 59, '$s' . str_replace('Arena', '', $map->maptype) => $posX + 103, '$s' . $map->mood => $posX + 118, '$s' . $time => $posX + 130); $array = array('$s' . $map->id => $posX + 3.5, '$s' . $map->name => $posX + 12.5, '$s' . $map->author => $posX + 59, '$s' . str_replace('Arena', '', $map->maptype) => $posX + 103, '$s' . $map->mood => $posX + 118, '$s' . $time => $posX + 130);
$labels = $this->maniaControl->getManialinkManager() $labels = $this->maniaControl->getManialinkManager()->labelLine($mapFrame, $array);
->labelLine($mapFrame, $array);
$authorLabel = $labels[2]; $authorLabel = $labels[2];
$authorLabel->setAction(self::ACTION_GET_MAPS_FROM_AUTHOR . '.' . $map->author); $authorLabel->setAction(self::ACTION_GET_MAPS_FROM_AUTHOR . '.' . $map->author);
@ -231,20 +211,15 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
$mxQuad = new Quad(); $mxQuad = new Quad();
$mapFrame->add($mxQuad); $mapFrame->add($mxQuad);
$mxQuad->setSize(3, 3); $mxQuad->setSize(3, 3);
$mxQuad->setImage($this->maniaControl->getManialinkManager() $mxQuad->setImage($this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON));
->getIconManager() $mxQuad->setImageFocus($this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON_MOVER));
->getIcon(IconManager::MX_ICON));
$mxQuad->setImageFocus($this->maniaControl->getManialinkManager()
->getIconManager()
->getIcon(IconManager::MX_ICON_MOVER));
$mxQuad->setX($posX + 56); $mxQuad->setX($posX + 56);
$mxQuad->setUrl($map->pageurl); $mxQuad->setUrl($map->pageurl);
$mxQuad->setZ(0.01); $mxQuad->setZ(0.01);
$description = 'View $<' . $map->name . '$> on Mania-Exchange'; $description = 'View $<' . $map->name . '$> on Mania-Exchange';
$mxQuad->addTooltipLabelFeature($descriptionLabel, $description); $mxQuad->addTooltipLabelFeature($descriptionLabel, $description);
if ($this->maniaControl->getAuthenticationManager() if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)
->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)
) { ) {
$addQuad = new Quad_Icons64x64_1(); $addQuad = new Quad_Icons64x64_1();
$mapFrame->add($addQuad); $mapFrame->add($addQuad);
@ -352,8 +327,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
$quad->setAction(self::ACTION_SEARCH_AUTHOR); $quad->setAction(self::ACTION_SEARCH_AUTHOR);
// render and display xml // render and display xml
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'ManiaExchangeList');
->displayWidget($maniaLink, $player, 'ManiaExchangeList');
} }
/** /**

View File

@ -81,12 +81,10 @@ class ManiaExchangeManager {
$maps = array($maps); $maps = array($maps);
} else { } else {
// Fetch Information for whole MapList // Fetch Information for whole MapList
$maps = $this->maniaControl->getMapManager() $maps = $this->maniaControl->getMapManager()->getMaps();
->getMaps();
} }
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$mapIdString = ''; $mapIdString = '';
// Fetch mx ids // Fetch mx ids
@ -102,8 +100,7 @@ class ManiaExchangeManager {
foreach ($maps as $map) { foreach ($maps as $map) {
if (!$map) { if (!$map) {
// TODO: remove after resolving of error report about "non-object" // TODO: remove after resolving of error report about "non-object"
$this->maniaControl->getErrorHandler() $this->maniaControl->getErrorHandler()->triggerDebugNotice('Non-Object-Map', $map, $maps);
->triggerDebugNotice('Non-Object-Map', $map, $maps);
continue; continue;
} }
/** @var Map $map */ /** @var Map $map */
@ -156,15 +153,12 @@ class ManiaExchangeManager {
*/ */
public function fetchMaplistByMixedUidIdString($string) { public function fetchMaplistByMixedUidIdString($string) {
// Get Title Prefix // Get Title Prefix
$titlePrefix = $this->maniaControl->getMapManager() $titlePrefix = $this->maniaControl->getMapManager()->getCurrentMap()->getGame();
->getCurrentMap()
->getGame();
// compile search URL // compile search URL
$url = "http://api.mania-exchange.com/{$titlePrefix}/maps/?ids={$string}"; $url = "http://api.mania-exchange.com/{$titlePrefix}/maps/?ids={$string}";
$this->maniaControl->getFileReader() $this->maniaControl->getFileReader()->loadFile($url, function ($mapInfo, $error) use ($titlePrefix, $url) {
->loadFile($url, function ($mapInfo, $error) use ($titlePrefix, $url) {
if ($error) { if ($error) {
trigger_error("Error: '{$error}' for Url '{$url}'"); trigger_error("Error: '{$error}' for Url '{$url}'");
return; return;
@ -199,8 +193,7 @@ class ManiaExchangeManager {
* @param array $mxMapInfos * @param array $mxMapInfos
*/ */
public function updateMapObjectsWithManiaExchangeIds(array $mxMapInfos) { public function updateMapObjectsWithManiaExchangeIds(array $mxMapInfos) {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
// Save map data // Save map data
$saveMapQuery = "UPDATE `" . MapManager::TABLE_MAPS . "` $saveMapQuery = "UPDATE `" . MapManager::TABLE_MAPS . "`
SET `mxid` = ? SET `mxid` = ?
@ -226,8 +219,7 @@ class ManiaExchangeManager {
} else { } else {
$uid = $mxMapInfo->uid; $uid = $mxMapInfo->uid;
} }
$map = $this->maniaControl->getMapManager() $map = $this->maniaControl->getMapManager()->getMapByUid($uid);
->getMapByUid($uid);
if ($map) { if ($map) {
// TODO: how does it come that $map can be empty here? we got an error report for that // TODO: how does it come that $map can be empty here? we got an error report for that
/** @var Map $map */ /** @var Map $map */
@ -254,15 +246,12 @@ class ManiaExchangeManager {
*/ */
public function fetchMapInfo($mapId, callable $function) { public function fetchMapInfo($mapId, callable $function) {
// Get Title Prefix // Get Title Prefix
$titlePrefix = $this->maniaControl->getMapManager() $titlePrefix = $this->maniaControl->getMapManager()->getCurrentMap()->getGame();
->getCurrentMap()
->getGame();
// compile search URL // compile search URL
$url = 'http://api.mania-exchange.com/' . $titlePrefix . '/maps/?ids=' . $mapId; $url = 'http://api.mania-exchange.com/' . $titlePrefix . '/maps/?ids=' . $mapId;
$this->maniaControl->getFileReader() $this->maniaControl->getFileReader()->loadFile($url, function ($mapInfo, $error) use (&$function, $titlePrefix, $url) {
->loadFile($url, function ($mapInfo, $error) use (&$function, $titlePrefix, $url) {
$mxMapInfo = null; $mxMapInfo = null;
if ($error) { if ($error) {
trigger_error($error); trigger_error($error);
@ -304,9 +293,7 @@ class ManiaExchangeManager {
// Get Title Id // Get Title Id
$titleId = $this->maniaControl->getServer()->titleId; $titleId = $this->maniaControl->getServer()->titleId;
$titlePrefix = $this->maniaControl->getMapManager() $titlePrefix = $this->maniaControl->getMapManager()->getCurrentMap()->getGame();
->getCurrentMap()
->getGame();
// compile search URL // compile search URL
$url = 'http://' . $titlePrefix . '.mania-exchange.com/tracksearch2/search?api=on'; $url = 'http://' . $titlePrefix . '.mania-exchange.com/tracksearch2/search?api=on';
@ -332,15 +319,13 @@ class ManiaExchangeManager {
// Get MapTypes // Get MapTypes
try { try {
$scriptInfos = $this->maniaControl->getClient() $scriptInfos = $this->maniaControl->getClient()->getModeScriptInfo();
->getModeScriptInfo();
$mapTypes = $scriptInfos->compatibleMapTypes; $mapTypes = $scriptInfos->compatibleMapTypes;
$url .= '&mtype=' . $mapTypes; $url .= '&mtype=' . $mapTypes;
} catch (GameModeException $e) { } catch (GameModeException $e) {
} }
$this->maniaControl->getFileReader() $this->maniaControl->getFileReader()->loadFile($url, function ($mapInfo, $error) use (&$function, $titlePrefix) {
->loadFile($url, function ($mapInfo, $error) use (&$function, $titlePrefix) {
if ($error) { if ($error) {
trigger_error($error); trigger_error($error);
return; return;

View File

@ -41,10 +41,8 @@ class CustomUIManager implements CallbackListener, TimerListener {
$this->prepareManialink(); $this->prepareManialink();
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined');
->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined'); $this->maniaControl->getTimerManager()->registerTimerListening($this, 'handle1Second', 1000);
$this->maniaControl->getTimerManager()
->registerTimerListening($this, 'handle1Second', 1000);
} }
/** /**
@ -72,12 +70,10 @@ class CustomUIManager implements CallbackListener, TimerListener {
*/ */
public function updateManialink(Player $player = null) { public function updateManialink(Player $player = null) {
if ($player) { if ($player) {
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->sendManialink($this->customUI, $player);
->sendManialink($this->customUI, $player);
return; return;
} }
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->sendManialink($this->customUI);
->sendManialink($this->customUI);
} }
/** /**
@ -90,8 +86,7 @@ class CustomUIManager implements CallbackListener, TimerListener {
//TODO: validate necessity //TODO: validate necessity
//send it again after 500ms //send it again after 500ms
$this->maniaControl->getTimerManager() $this->maniaControl->getTimerManager()->registerOneTimeListening($this, function () use (&$player) {
->registerOneTimeListening($this, function () use (&$player) {
$this->updateManialink($player); $this->updateManialink($player);
}, 500); }, 500);
} }

View File

@ -51,10 +51,8 @@ class IconManager implements CallbackListener {
$this->addDefaultIcons(); $this->addDefaultIcons();
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit'); $this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
} }
/** /**
@ -116,8 +114,7 @@ class IconManager implements CallbackListener {
} }
// Send manialink // Send manialink
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $player);
->sendManialink($maniaLink, $player);
} }
/** /**

View File

@ -66,8 +66,7 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
// Callbacks // Callbacks
$this->registerManialinkPageAnswerListener(self::ACTION_CLOSEWIDGET, $this, 'closeWidgetCallback'); $this->registerManialinkPageAnswerListener(self::ACTION_CLOSEWIDGET, $this, 'closeWidgetCallback');
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
} }
/** /**
@ -176,8 +175,7 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
public function handleManialinkPageAnswer(array $callback) { public function handleManialinkPageAnswer(array $callback) {
$actionId = $callback[1][2]; $actionId = $callback[1][2];
$login = $callback[1][1]; $login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($login);
->getPlayer($login);
if (array_key_exists($actionId, $this->pageAnswerListeners) && is_array($this->pageAnswerListeners[$actionId])) { if (array_key_exists($actionId, $this->pageAnswerListeners) && is_array($this->pageAnswerListeners[$actionId])) {
// Inform page answer listeners // Inform page answer listeners
@ -212,10 +210,8 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
// TODO make check by manialinkId, getter is needed to avoid uses on non main widgets // TODO make check by manialinkId, getter is needed to avoid uses on non main widgets
$this->disableAltMenu($player); $this->disableAltMenu($player);
// Trigger callback // Trigger callback
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($player);
->getPlayer($player); $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MAIN_WINDOW_OPENED, $player, $widgetName);
$this->maniaControl->getCallbackManager()
->triggerCallback(self::CB_MAIN_WINDOW_OPENED, $player, $widgetName);
} }
} }
@ -237,17 +233,14 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
try { try {
if (!$logins) { if (!$logins) {
return $this->maniaControl->getClient() return $this->maniaControl->getClient()->sendDisplayManialinkPage(null, $manialinkText, $timeout, $hideOnClick);
->sendDisplayManialinkPage(null, $manialinkText, $timeout, $hideOnClick);
} }
if (is_string($logins)) { if (is_string($logins)) {
$success = $this->maniaControl->getClient() $success = $this->maniaControl->getClient()->sendDisplayManialinkPage($logins, $manialinkText, $timeout, $hideOnClick);
->sendDisplayManialinkPage($logins, $manialinkText, $timeout, $hideOnClick);
return $success; return $success;
} }
if ($logins instanceof Player) { if ($logins instanceof Player) {
$success = $this->maniaControl->getClient() $success = $this->maniaControl->getClient()->sendDisplayManialinkPage($logins->login, $manialinkText, $timeout, $hideOnClick);
->sendDisplayManialinkPage($logins->login, $manialinkText, $timeout, $hideOnClick);
return $success; return $success;
} }
if (is_array($logins)) { if (is_array($logins)) {
@ -276,8 +269,7 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
public function disableAltMenu($player) { public function disableAltMenu($player) {
$login = Player::parseLogin($player); $login = Player::parseLogin($player);
try { try {
$success = $this->maniaControl->getClient() $success = $this->maniaControl->getClient()->triggerModeScriptEvent('LibXmlRpc_DisableAltMenu', $login);
->triggerModeScriptEvent('LibXmlRpc_DisableAltMenu', $login);
} catch (GameModeException $e) { } catch (GameModeException $e) {
return false; return false;
} }
@ -306,10 +298,8 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
$this->enableAltMenu($player); $this->enableAltMenu($player);
// Trigger callback // Trigger callback
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($player);
->getPlayer($player); $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MAIN_WINDOW_CLOSED, $player);
$this->maniaControl->getCallbackManager()
->triggerCallback(self::CB_MAIN_WINDOW_CLOSED, $player);
} else { } else {
$this->hideManialink($widgetId, $player); $this->hideManialink($widgetId, $player);
} }
@ -341,8 +331,7 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
public function enableAltMenu($player) { public function enableAltMenu($player) {
$login = Player::parseLogin($player); $login = Player::parseLogin($player);
try { try {
$success = $this->maniaControl->getClient() $success = $this->maniaControl->getClient()->triggerModeScriptEvent('LibXmlRpc_EnableAltMenu', $login);
->triggerModeScriptEvent('LibXmlRpc_EnableAltMenu', $login);
} catch (GameModeException $e) { } catch (GameModeException $e) {
return false; return false;
} }

View File

@ -50,24 +50,16 @@ class StyleManager {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Settings // Settings
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_LABEL_DEFAULT_STYLE, Label_Text::STYLE_TextTitle1);
->initSetting($this, self::SETTING_LABEL_DEFAULT_STYLE, Label_Text::STYLE_TextTitle1); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_QUAD_DEFAULT_STYLE, Quad_Bgs1InRace::STYLE);
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_QUAD_DEFAULT_SUBSTYLE, Quad_Bgs1InRace::SUBSTYLE_BgTitleShadow);
->initSetting($this, self::SETTING_QUAD_DEFAULT_STYLE, Quad_Bgs1InRace::STYLE);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_QUAD_DEFAULT_SUBSTYLE, Quad_Bgs1InRace::SUBSTYLE_BgTitleShadow);
// Main Widget // Main Widget
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAIN_WIDGET_DEFAULT_STYLE, Quad_BgRaceScore2::STYLE);
->initSetting($this, self::SETTING_MAIN_WIDGET_DEFAULT_STYLE, Quad_BgRaceScore2::STYLE); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAIN_WIDGET_DEFAULT_SUBSTYLE, Quad_BgRaceScore2::SUBSTYLE_HandleSelectable);
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_LIST_WIDGETS_WIDTH, 150.);
->initSetting($this, self::SETTING_MAIN_WIDGET_DEFAULT_SUBSTYLE, Quad_BgRaceScore2::SUBSTYLE_HandleSelectable); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_LIST_WIDGETS_HEIGHT, 80.);
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_ICON_DEFAULT_OFFSET_SM, 20.);
->initSetting($this, self::SETTING_LIST_WIDGETS_WIDTH, 150.);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_LIST_WIDGETS_HEIGHT, 80.);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_ICON_DEFAULT_OFFSET_SM, 20.);
} }
/** /**
@ -76,8 +68,7 @@ class StyleManager {
* @return float * @return float
*/ */
public function getDefaultIconOffsetSM() { public function getDefaultIconOffsetSM() {
return $this->maniaControl->getSettingManager() return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_ICON_DEFAULT_OFFSET_SM);
->getSettingValue($this, self::SETTING_ICON_DEFAULT_OFFSET_SM);
} }
/** /**
@ -86,8 +77,7 @@ class StyleManager {
* @return string * @return string
*/ */
public function getDefaultLabelStyle() { public function getDefaultLabelStyle() {
return $this->maniaControl->getSettingManager() return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_LABEL_DEFAULT_STYLE);
->getSettingValue($this, self::SETTING_LABEL_DEFAULT_STYLE);
} }
/** /**
@ -96,8 +86,7 @@ class StyleManager {
* @return string * @return string
*/ */
public function getDefaultQuadStyle() { public function getDefaultQuadStyle() {
return $this->maniaControl->getSettingManager() return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_QUAD_DEFAULT_STYLE);
->getSettingValue($this, self::SETTING_QUAD_DEFAULT_STYLE);
} }
/** /**
@ -106,8 +95,7 @@ class StyleManager {
* @return string * @return string
*/ */
public function getDefaultQuadSubstyle() { public function getDefaultQuadSubstyle() {
return $this->maniaControl->getSettingManager() return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_QUAD_DEFAULT_SUBSTYLE);
->getSettingValue($this, self::SETTING_QUAD_DEFAULT_SUBSTYLE);
} }
/** /**
@ -121,11 +109,7 @@ class StyleManager {
// Predefine Description Label // Predefine Description Label
$descriptionLabel = new Label(); $descriptionLabel = new Label();
$descriptionLabel->setAlign($descriptionLabel::LEFT, $descriptionLabel::TOP) $descriptionLabel->setAlign($descriptionLabel::LEFT, $descriptionLabel::TOP)->setPosition($width * -0.5 + 10, $height * -0.5 + 5)->setSize($width * 0.7, 4)->setTextSize(2)->setVisible(false);
->setPosition($width * -0.5 + 10, $height * -0.5 + 5)
->setSize($width * 0.7, 4)
->setTextSize(2)
->setVisible(false);
return $descriptionLabel; return $descriptionLabel;
} }
@ -136,8 +120,7 @@ class StyleManager {
* @return float * @return float
*/ */
public function getListWidgetsWidth() { public function getListWidgetsWidth() {
return $this->maniaControl->getSettingManager() return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_LIST_WIDGETS_WIDTH);
->getSettingValue($this, self::SETTING_LIST_WIDGETS_WIDTH);
} }
/** /**
@ -146,8 +129,7 @@ class StyleManager {
* @return float * @return float
*/ */
public function getListWidgetsHeight() { public function getListWidgetsHeight() {
return $this->maniaControl->getSettingManager() return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_LIST_WIDGETS_HEIGHT);
->getSettingValue($this, self::SETTING_LIST_WIDGETS_HEIGHT);
} }
/** /**
@ -177,49 +159,34 @@ class StyleManager {
// mainframe // mainframe
$frame = new Frame(); $frame = new Frame();
$frame->setSize($width, $height) $frame->setSize($width, $height)->setZ(35); //TODO place before scoreboards
->setZ(35); //TODO place before scoreboards
// Background Quad // Background Quad
$backgroundQuad = new Quad(); $backgroundQuad = new Quad();
$frame->add($backgroundQuad); $frame->add($backgroundQuad);
$backgroundQuad->setZ(-2) $backgroundQuad->setZ(-2)->setSize($width, $height)->setStyles($quadStyle, $quadSubstyle);
->setSize($width, $height)
->setStyles($quadStyle, $quadSubstyle);
// Add Close Quad (X) // Add Close Quad (X)
$closeQuad = new Quad_Icons64x64_1(); $closeQuad = new Quad_Icons64x64_1();
$frame->add($closeQuad); $frame->add($closeQuad);
$closeQuad->setPosition($width * 0.483, $height * 0.467, 3) $closeQuad->setPosition($width * 0.483, $height * 0.467, 3)->setSize(6, 6)->setSubStyle($closeQuad::SUBSTYLE_QuitRace)->setAction(ManialinkManager::ACTION_CLOSEWIDGET);
->setSize(6, 6)
->setSubStyle($closeQuad::SUBSTYLE_QuitRace)
->setAction(ManialinkManager::ACTION_CLOSEWIDGET);
if ($script) { if ($script) {
$pagerSize = 6.; $pagerSize = 6.;
$pagerPrev = new Quad_Icons64x64_1(); $pagerPrev = new Quad_Icons64x64_1();
$frame->add($pagerPrev); $frame->add($pagerPrev);
$pagerPrev->setPosition($width * 0.42, $height * -0.44, 2) $pagerPrev->setPosition($width * 0.42, $height * -0.44, 2)->setSize($pagerSize, $pagerSize)->setSubStyle($pagerPrev::SUBSTYLE_ArrowPrev);
->setSize($pagerSize, $pagerSize)
->setSubStyle($pagerPrev::SUBSTYLE_ArrowPrev);
$pagerNext = new Quad_Icons64x64_1(); $pagerNext = new Quad_Icons64x64_1();
$frame->add($pagerNext); $frame->add($pagerNext);
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2) $pagerNext->setPosition($width * 0.45, $height * -0.44, 2)->setSize($pagerSize, $pagerSize)->setSubStyle($pagerNext::SUBSTYLE_ArrowNext);
->setSize($pagerSize, $pagerSize)
->setSubStyle($pagerNext::SUBSTYLE_ArrowNext);
$pageCountLabel = new Label_Text(); $pageCountLabel = new Label_Text();
$frame->add($pageCountLabel); $frame->add($pageCountLabel);
$pageCountLabel->setHAlign($pageCountLabel::RIGHT) $pageCountLabel->setHAlign($pageCountLabel::RIGHT)->setPosition($width * 0.40, $height * -0.44, 1)->setStyle($pageCountLabel::STYLE_TextTitle1)->setTextSize(1.3);
->setPosition($width * 0.40, $height * -0.44, 1)
->setStyle($pageCountLabel::STYLE_TextTitle1)
->setTextSize(1.3);
if ($paging) { if ($paging) {
$paging->addButton($pagerNext) $paging->addButton($pagerNext)->addButton($pagerPrev)->setLabel($pageCountLabel);
->addButton($pagerPrev)
->setLabel($pageCountLabel);
} }
} }
@ -232,8 +199,7 @@ class StyleManager {
* @return string * @return string
*/ */
public function getDefaultMainWindowStyle() { public function getDefaultMainWindowStyle() {
return $this->maniaControl->getSettingManager() return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAIN_WIDGET_DEFAULT_STYLE);
->getSettingValue($this, self::SETTING_MAIN_WIDGET_DEFAULT_STYLE);
} }
/** /**
@ -242,7 +208,6 @@ class StyleManager {
* @return string * @return string
*/ */
public function getDefaultMainWindowSubStyle() { public function getDefaultMainWindowSubStyle() {
return $this->maniaControl->getSettingManager() return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAIN_WIDGET_DEFAULT_SUBSTYLE);
->getSettingValue($this, self::SETTING_MAIN_WIDGET_DEFAULT_SUBSTYLE);
} }
} }

View File

@ -56,20 +56,13 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// ManiaLink Actions // ManiaLink Actions
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_SHOW, $this, 'handleActionShow');
->registerManialinkPageAnswerListener(self::ACTION_SHOW, $this, 'handleActionShow'); $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_NAVIGATE_UP, $this, 'handleNavigateUp');
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_NAVIGATE_ROOT, $this, 'handleNavigateRoot');
->registerManialinkPageAnswerListener(self::ACTION_NAVIGATE_UP, $this, 'handleNavigateUp'); $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerRegexListener($this->buildActionRegex(self::ACTION_OPEN_FOLDER), $this, 'handleOpenFolder');
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerRegexListener($this->buildActionRegex(self::ACTION_INSPECT_FILE), $this, 'handleInspectFile');
->registerManialinkPageAnswerListener(self::ACTION_NAVIGATE_ROOT, $this, 'handleNavigateRoot'); $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerRegexListener($this->buildActionRegex(self::ACTION_ADD_FILE), $this, 'handleAddFile');
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerRegexListener($this->buildActionRegex(self::ACTION_ERASE_FILE), $this, 'handleEraseFile');
->registerManialinkPageAnswerRegexListener($this->buildActionRegex(self::ACTION_OPEN_FOLDER), $this, 'handleOpenFolder');
$this->maniaControl->getManialinkManager()
->registerManialinkPageAnswerRegexListener($this->buildActionRegex(self::ACTION_INSPECT_FILE), $this, 'handleInspectFile');
$this->maniaControl->getManialinkManager()
->registerManialinkPageAnswerRegexListener($this->buildActionRegex(self::ACTION_ADD_FILE), $this, 'handleAddFile');
$this->maniaControl->getManialinkManager()
->registerManialinkPageAnswerRegexListener($this->buildActionRegex(self::ACTION_ERASE_FILE), $this, 'handleEraseFile');
} }
/** /**
@ -102,9 +95,7 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
$oldFolderPath = $player->getCache($this, self::CACHE_FOLDER_PATH); $oldFolderPath = $player->getCache($this, self::CACHE_FOLDER_PATH);
$isInMapsFolder = false; $isInMapsFolder = false;
if (!$oldFolderPath) { if (!$oldFolderPath) {
$oldFolderPath = $this->maniaControl->getServer() $oldFolderPath = $this->maniaControl->getServer()->getDirectory()->getMapsFolder();
->getDirectory()
->getMapsFolder();
$isInMapsFolder = true; $isInMapsFolder = true;
} }
$folderPath = $oldFolderPath; $folderPath = $oldFolderPath;
@ -115,16 +106,12 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
$folderName = basename($newFolderPath); $folderName = basename($newFolderPath);
switch ($folderName) { switch ($folderName) {
case 'Maps': case 'Maps':
$mapsDir = dirname($this->maniaControl->getServer() $mapsDir = dirname($this->maniaControl->getServer()->getDirectory()->getMapsFolder());
->getDirectory()
->getMapsFolder());
$folderDir = dirname($folderPath); $folderDir = dirname($folderPath);
$isInMapsFolder = ($mapsDir === $folderDir); $isInMapsFolder = ($mapsDir === $folderDir);
break; break;
case 'UserData': case 'UserData':
$dataDir = dirname($this->maniaControl->getServer() $dataDir = dirname($this->maniaControl->getServer()->getDirectory()->getGameDataFolder());
->getDirectory()
->getGameDataFolder());
$folderDir = dirname($folderPath); $folderDir = dirname($folderPath);
if ($dataDir === $folderDir) { if ($dataDir === $folderDir) {
// Prevent navigation out of maps directory // Prevent navigation out of maps directory
@ -140,32 +127,22 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
$script = $maniaLink->getScript(); $script = $maniaLink->getScript();
$paging = new Paging(); $paging = new Paging();
$script->addFeature($paging); $script->addFeature($paging);
$frame = $this->maniaControl->getManialinkManager() $frame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultListFrame($script, $paging);
->getStyleManager()
->getDefaultListFrame($script, $paging);
$maniaLink->add($frame); $maniaLink->add($frame);
$width = $this->maniaControl->getManialinkManager() $width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
->getStyleManager() $height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
->getListWidgetsWidth();
$height = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getListWidgetsHeight();
$index = 0; $index = 0;
$posY = $height / 2 - 10; $posY = $height / 2 - 10;
$pageFrame = null; $pageFrame = null;
$navigateRootQuad = new Quad_Icons64x64_1(); $navigateRootQuad = new Quad_Icons64x64_1();
$frame->add($navigateRootQuad); $frame->add($navigateRootQuad);
$navigateRootQuad->setPosition($width * -0.47, $height * 0.45) $navigateRootQuad->setPosition($width * -0.47, $height * 0.45)->setSize(4, 4)->setSubStyle($navigateRootQuad::SUBSTYLE_ToolRoot);
->setSize(4, 4)
->setSubStyle($navigateRootQuad::SUBSTYLE_ToolRoot);
$navigateUpQuad = new Quad_Icons64x64_1(); $navigateUpQuad = new Quad_Icons64x64_1();
$frame->add($navigateUpQuad); $frame->add($navigateUpQuad);
$navigateUpQuad->setPosition($width * -0.44, $height * 0.45) $navigateUpQuad->setPosition($width * -0.44, $height * 0.45)->setSize(4, 4)->setSubStyle($navigateUpQuad::SUBSTYLE_ToolUp);
->setSize(4, 4)
->setSubStyle($navigateUpQuad::SUBSTYLE_ToolUp);
if (!$isInMapsFolder) { if (!$isInMapsFolder) {
$navigateRootQuad->setAction(self::ACTION_NAVIGATE_ROOT); $navigateRootQuad->setAction(self::ACTION_NAVIGATE_ROOT);
@ -174,23 +151,13 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
$directoryLabel = new Label_Text(); $directoryLabel = new Label_Text();
$frame->add($directoryLabel); $frame->add($directoryLabel);
$dataFolder = $this->maniaControl->getServer() $dataFolder = $this->maniaControl->getServer()->getDirectory()->getGameDataFolder();
->getDirectory()
->getGameDataFolder();
$directoryText = substr($folderPath, strlen($dataFolder)); $directoryText = substr($folderPath, strlen($dataFolder));
$directoryLabel->setPosition($width * -0.41, $height * 0.45) $directoryLabel->setPosition($width * -0.41, $height * 0.45)->setSize($width * 0.85, 4)->setHAlign($directoryLabel::LEFT)->setText($directoryText)->setTextSize(2);
->setSize($width * 0.85, 4)
->setHAlign($directoryLabel::LEFT)
->setText($directoryText)
->setTextSize(2);
$tooltipLabel = new Label(); $tooltipLabel = new Label();
$frame->add($tooltipLabel); $frame->add($tooltipLabel);
$tooltipLabel->setPosition($width * -0.48, $height * -0.44) $tooltipLabel->setPosition($width * -0.48, $height * -0.44)->setSize($width * 0.8, 5)->setHAlign($tooltipLabel::LEFT)->setTextSize(1)->setText('tooltip');
->setSize($width * 0.8, 5)
->setHAlign($tooltipLabel::LEFT)
->setTextSize(1)
->setText('tooltip');
$mapFiles = $this->scanMapFiles($folderPath); $mapFiles = $this->scanMapFiles($folderPath);
@ -198,15 +165,10 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
if (empty($mapFiles)) { if (empty($mapFiles)) {
$emptyLabel = new Label(); $emptyLabel = new Label();
$frame->add($emptyLabel); $frame->add($emptyLabel);
$emptyLabel->setY(20) $emptyLabel->setY(20)->setTextColor('aaa')->setText('No files found.')->setTranslate(true);
->setTextColor('aaa')
->setText('No files found.')
->setTranslate(true);
} else { } else {
$canAddMaps = $this->maniaControl->getAuthenticationManager() $canAddMaps = $this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP);
->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP); $canEraseMaps = $this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_ERASE_MAP);
$canEraseMaps = $this->maniaControl->getAuthenticationManager()
->checkPermission($player, MapManager::SETTING_PERMISSION_ERASE_MAP);
foreach ($mapFiles as $filePath => $fileName) { foreach ($mapFiles as $filePath => $fileName) {
$shortFilePath = substr($filePath, strlen($folderPath)); $shortFilePath = substr($filePath, strlen($folderPath));
@ -228,50 +190,33 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
// Striped background line // Striped background line
$lineQuad = new Quad_BgsPlayerCard(); $lineQuad = new Quad_BgsPlayerCard();
$mapFrame->add($lineQuad); $mapFrame->add($lineQuad);
$lineQuad->setZ(-1) $lineQuad->setZ(-1)->setSize($width, 4)->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
->setSize($width, 4)
->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
} }
// File name Label // File name Label
$nameLabel = new Label_Text(); $nameLabel = new Label_Text();
$mapFrame->add($nameLabel); $mapFrame->add($nameLabel);
$nameLabel->setX($width * -0.48) $nameLabel->setX($width * -0.48)->setSize($width * 0.79, 4)->setHAlign($nameLabel::LEFT)->setStyle($nameLabel::STYLE_TextCardRaceRank)->setTextSize(1)->setText($fileName);
->setSize($width * 0.79, 4)
->setHAlign($nameLabel::LEFT)
->setStyle($nameLabel::STYLE_TextCardRaceRank)
->setTextSize(1)
->setText($fileName);
if (is_dir($filePath)) { if (is_dir($filePath)) {
// Folder // Folder
$nameLabel->setAction(self::ACTION_OPEN_FOLDER . substr($shortFilePath, 0, -1)) $nameLabel->setAction(self::ACTION_OPEN_FOLDER . substr($shortFilePath, 0, -1))->addTooltipLabelFeature($tooltipLabel, 'Open folder ' . $fileName);
->addTooltipLabelFeature($tooltipLabel, 'Open folder ' . $fileName);
} else { } else {
// File // File
$nameLabel->setAction(self::ACTION_INSPECT_FILE . $fileName) $nameLabel->setAction(self::ACTION_INSPECT_FILE . $fileName)->addTooltipLabelFeature($tooltipLabel, 'Inspect file ' . $fileName);
->addTooltipLabelFeature($tooltipLabel, 'Inspect file ' . $fileName);
if ($canAddMaps) { if ($canAddMaps) {
// 'Add' button // 'Add' button
$addButton = new Quad_UIConstructionBullet_Buttons(); $addButton = new Quad_UIConstructionBullet_Buttons();
$mapFrame->add($addButton); $mapFrame->add($addButton);
$addButton->setX($width * 0.42) $addButton->setX($width * 0.42)->setSize(4, 4)->setSubStyle($addButton::SUBSTYLE_NewBullet)->setAction(self::ACTION_ADD_FILE . $fileName)->addTooltipLabelFeature($tooltipLabel, 'Add map ' . $fileName);
->setSize(4, 4)
->setSubStyle($addButton::SUBSTYLE_NewBullet)
->setAction(self::ACTION_ADD_FILE . $fileName)
->addTooltipLabelFeature($tooltipLabel, 'Add map ' . $fileName);
} }
if ($canEraseMaps) { if ($canEraseMaps) {
// 'Erase' button // 'Erase' button
$eraseButton = new Quad_UIConstruction_Buttons(); $eraseButton = new Quad_UIConstruction_Buttons();
$mapFrame->add($eraseButton); $mapFrame->add($eraseButton);
$eraseButton->setX($width * 0.46) $eraseButton->setX($width * 0.46)->setSize(4, 4)->setSubStyle($eraseButton::SUBSTYLE_Erase)->setAction(self::ACTION_ERASE_FILE . $fileName)->addTooltipLabelFeature($tooltipLabel, 'Erase file ' . $fileName);
->setSize(4, 4)
->setSubStyle($eraseButton::SUBSTYLE_Erase)
->setAction(self::ACTION_ERASE_FILE . $fileName)
->addTooltipLabelFeature($tooltipLabel, 'Erase file ' . $fileName);
} }
} }
@ -282,14 +227,10 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
} else { } else {
$errorLabel = new Label(); $errorLabel = new Label();
$frame->add($errorLabel); $frame->add($errorLabel);
$errorLabel->setY(20) $errorLabel->setY(20)->setTextColor('f30')->setText('No access to the directory.')->setTranslate(true);
->setTextColor('f30')
->setText('No access to the directory.')
->setTranslate(true);
} }
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, self::WIDGET_NAME);
->displayWidget($maniaLink, $player, self::WIDGET_NAME);
} }
/** /**
@ -394,52 +335,40 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
$folderPath = $player->getCache($this, self::CACHE_FOLDER_PATH); $folderPath = $player->getCache($this, self::CACHE_FOLDER_PATH);
$filePath = $folderPath . $fileName; $filePath = $folderPath . $fileName;
$mapsFolder = $this->maniaControl->getServer() $mapsFolder = $this->maniaControl->getServer()->getDirectory()->getMapsFolder();
->getDirectory()
->getMapsFolder();
$relativeFilePath = substr($filePath, strlen($mapsFolder)); $relativeFilePath = substr($filePath, strlen($mapsFolder));
// Check for valid map // Check for valid map
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->checkMapForCurrentServerParams($relativeFilePath);
->checkMapForCurrentServerParams($relativeFilePath);
} catch (InvalidMapException $exception) { } catch (InvalidMapException $exception) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendException($exception, $player);
->sendException($exception, $player);
return; return;
} catch (FileException $exception) { } catch (FileException $exception) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendException($exception, $player);
->sendException($exception, $player);
return; return;
} }
// Add map to map list // Add map to map list
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->insertMap($relativeFilePath);
->insertMap($relativeFilePath);
} catch (AlreadyInListException $exception) { } catch (AlreadyInListException $exception) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendException($exception, $player);
->sendException($exception, $player);
return; return;
} }
$map = $this->maniaControl->getMapManager() $map = $this->maniaControl->getMapManager()->fetchMapByFileName($relativeFilePath);
->fetchMapByFileName($relativeFilePath);
if (!$map) { if (!$map) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('Error occurred.', $player);
->sendError('Error occurred.', $player);
return; return;
} }
// Message // Message
$message = $player->getEscapedNickname() . ' added ' . $map->getEscapedName() . '!'; $message = $player->getEscapedNickname() . ' added ' . $map->getEscapedName() . '!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess($message);
->sendSuccess($message);
Logger::logInfo($message, true); Logger::logInfo($message, true);
// Queue requested Map // Queue requested Map
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->getMapQueue()->addMapToMapQueue($player, $map);
->getMapQueue()
->addMapToMapQueue($player, $map);
} }
/** /**
@ -454,12 +383,10 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
$folderPath = $player->getCache($this, self::CACHE_FOLDER_PATH); $folderPath = $player->getCache($this, self::CACHE_FOLDER_PATH);
$filePath = $folderPath . $fileName; $filePath = $folderPath . $fileName;
if (@unlink($filePath)) { if (@unlink($filePath)) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess("Erased {$fileName}!");
->sendSuccess("Erased {$fileName}!");
$this->showManiaLink($player); $this->showManiaLink($player);
} else { } else {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError("Couldn't erase {$fileName}!");
->sendError("Couldn't erase {$fileName}!");
} }
} }
} }

View File

@ -33,19 +33,14 @@ class MapActions {
*/ */
public function skipMap() { public function skipMap() {
// Force an EndMap on the MapQueue to set the next Map // Force an EndMap on the MapQueue to set the next Map
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->getMapQueue()->endMap(null);
->getMapQueue()
->endMap(null);
// Ignore EndMap on MapQueue // Ignore EndMap on MapQueue
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->getMapQueue()->dontQueueNextMapChange();
->getMapQueue()
->dontQueueNextMapChange();
// Switch The Map // Switch The Map
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->nextMap();
->nextMap();
} catch (ChangeInProgressException $e) { } catch (ChangeInProgressException $e) {
} }
} }

View File

@ -50,44 +50,27 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
$this->initActionsMenuButtons(); $this->initActionsMenuButtons();
// Admin commands // Admin commands
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener(array('nextmap', 'next', 'skip'), $this, 'command_NextMap', true, 'Skips to the next map.');
->registerCommandListener(array('nextmap', 'next', 'skip'), $this, 'command_NextMap', true, 'Skips to the next map.'); $this->maniaControl->getCommandManager()->registerCommandListener(array('restartmap', 'resmap', 'res'), $this, 'command_RestartMap', true, 'Restarts the current map.');
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener(array('replaymap', 'replay'), $this, 'command_ReplayMap', true, 'Replays the current map (after the end of the map).');
->registerCommandListener(array('restartmap', 'resmap', 'res'), $this, 'command_RestartMap', true, 'Restarts the current map.'); $this->maniaControl->getCommandManager()->registerCommandListener(array('addmap', 'add'), $this, 'command_AddMap', true, 'Adds map from ManiaExchange.');
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener(array('removemap', 'removethis'), $this, 'command_RemoveMap', true, 'Removes the current map.');
->registerCommandListener(array('replaymap', 'replay'), $this, 'command_ReplayMap', true, 'Replays the current map (after the end of the map).'); $this->maniaControl->getCommandManager()->registerCommandListener(array('erasemap', 'erasethis'), $this, 'command_EraseMap', true, 'Erases the current map.');
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener(array('shufflemaps', 'shuffle'), $this, 'command_ShuffleMaps', true, 'Shuffles the maplist.');
->registerCommandListener(array('addmap', 'add'), $this, 'command_AddMap', true, 'Adds map from ManiaExchange.'); $this->maniaControl->getCommandManager()->registerCommandListener(array('writemaplist', 'wml'), $this, 'command_WriteMapList', true, 'Writes the current maplist to a file.');
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener(array('readmaplist', 'rml'), $this, 'command_ReadMapList', true, 'Loads a maplist into the server.');
->registerCommandListener(array('removemap', 'removethis'), $this, 'command_RemoveMap', true, 'Removes the current map.');
$this->maniaControl->getCommandManager()
->registerCommandListener(array('erasemap', 'erasethis'), $this, 'command_EraseMap', true, 'Erases the current map.');
$this->maniaControl->getCommandManager()
->registerCommandListener(array('shufflemaps', 'shuffle'), $this, 'command_ShuffleMaps', true, 'Shuffles the maplist.');
$this->maniaControl->getCommandManager()
->registerCommandListener(array('writemaplist', 'wml'), $this, 'command_WriteMapList', true, 'Writes the current maplist to a file.');
$this->maniaControl->getCommandManager()
->registerCommandListener(array('readmaplist', 'rml'), $this, 'command_ReadMapList', true, 'Loads a maplist into the server.');
// Player commands // Player commands
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener('nextmap', $this, 'command_showNextMap', false, 'Shows which map is next.');
->registerCommandListener('nextmap', $this, 'command_showNextMap', false, 'Shows which map is next.'); $this->maniaControl->getCommandManager()->registerCommandListener(array('maps', 'list'), $this, 'command_List', false, 'Shows the current maplist (or variations).');
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener(array('xmaps', 'xlist'), $this, 'command_xList', false, 'Shows maps from ManiaExchange.');
->registerCommandListener(array('maps', 'list'), $this, 'command_List', false, 'Shows the current maplist (or variations).');
$this->maniaControl->getCommandManager()
->registerCommandListener(array('xmaps', 'xlist'), $this, 'command_xList', false, 'Shows maps from ManiaExchange.');
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer'); $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_OPEN_XLIST, $this, 'command_xList');
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_OPEN_MAPLIST, $this, 'command_List');
->registerManialinkPageAnswerListener(self::ACTION_OPEN_XLIST, $this, 'command_xList'); $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_RESTART_MAP, $this, 'command_RestartMap');
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_SKIP_MAP, $this, 'command_NextMap');
->registerManialinkPageAnswerListener(self::ACTION_OPEN_MAPLIST, $this, 'command_List');
$this->maniaControl->getManialinkManager()
->registerManialinkPageAnswerListener(self::ACTION_RESTART_MAP, $this, 'command_RestartMap');
$this->maniaControl->getManialinkManager()
->registerManialinkPageAnswerListener(self::ACTION_SKIP_MAP, $this, 'command_NextMap');
} }
/** /**
@ -96,36 +79,28 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
private function initActionsMenuButtons() { private function initActionsMenuButtons() {
// Menu Open xList // Menu Open xList
$itemQuad = new Quad(); $itemQuad = new Quad();
$itemQuad->setImage($this->maniaControl->getManialinkManager() $itemQuad->setImage($this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON));
->getIconManager() $itemQuad->setImageFocus($this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON_MOVER));
->getIcon(IconManager::MX_ICON));
$itemQuad->setImageFocus($this->maniaControl->getManialinkManager()
->getIconManager()
->getIcon(IconManager::MX_ICON_MOVER));
$itemQuad->setAction(self::ACTION_OPEN_XLIST); $itemQuad->setAction(self::ACTION_OPEN_XLIST);
$this->maniaControl->getActionsMenu() $this->maniaControl->getActionsMenu()->addPlayerMenuItem($itemQuad, 5, 'Open MX List');
->addPlayerMenuItem($itemQuad, 5, 'Open MX List');
// Menu Open List // Menu Open List
$itemQuad = new Quad_Icons64x64_1(); $itemQuad = new Quad_Icons64x64_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ToolRoot); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_ToolRoot);
$itemQuad->setAction(self::ACTION_OPEN_MAPLIST); $itemQuad->setAction(self::ACTION_OPEN_MAPLIST);
$this->maniaControl->getActionsMenu() $this->maniaControl->getActionsMenu()->addPlayerMenuItem($itemQuad, 10, 'Open MapList');
->addPlayerMenuItem($itemQuad, 10, 'Open MapList');
// Menu RestartMap // Menu RestartMap
$itemQuad = new Quad_UIConstruction_Buttons(); $itemQuad = new Quad_UIConstruction_Buttons();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Reload); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_Reload);
$itemQuad->setAction(self::ACTION_RESTART_MAP); $itemQuad->setAction(self::ACTION_RESTART_MAP);
$this->maniaControl->getActionsMenu() $this->maniaControl->getActionsMenu()->addAdminMenuItem($itemQuad, 10, 'Restart Map');
->addAdminMenuItem($itemQuad, 10, 'Restart Map');
// Menu NextMap // Menu NextMap
$itemQuad = new Quad_Icons64x64_1(); $itemQuad = new Quad_Icons64x64_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ArrowFastNext); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_ArrowFastNext);
$itemQuad->setAction(self::ACTION_SKIP_MAP); $itemQuad->setAction(self::ACTION_SKIP_MAP);
$this->maniaControl->getActionsMenu() $this->maniaControl->getActionsMenu()->addAdminMenuItem($itemQuad, 20, 'Skip Map');
->addAdminMenuItem($itemQuad, 20, 'Skip Map');
} }
/** /**
@ -135,24 +110,18 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
* @param Player $player * @param Player $player
*/ */
public function command_ShowNextMap(array $chatCallback, Player $player) { public function command_ShowNextMap(array $chatCallback, Player $player) {
$nextQueued = $this->maniaControl->getMapManager() $nextQueued = $this->maniaControl->getMapManager()->getMapQueue()->getNextQueuedMap();
->getMapQueue()
->getNextQueuedMap();
if ($nextQueued) { if ($nextQueued) {
/** @var Player $requester */ /** @var Player $requester */
$requester = $nextQueued[0]; $requester = $nextQueued[0];
/** @var Map $map */ /** @var Map $map */
$map = $nextQueued[1]; $map = $nextQueued[1];
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation("Next Map is $<{$map->name}$> from $<{$map->authorNick}$> requested by $<{$requester->nickname}$>.", $player);
->sendInformation("Next Map is $<{$map->name}$> from $<{$map->authorNick}$> requested by $<{$requester->nickname}$>.", $player);
} else { } else {
$mapIndex = $this->maniaControl->getClient() $mapIndex = $this->maniaControl->getClient()->getNextMapIndex();
->getNextMapIndex(); $maps = $this->maniaControl->getMapManager()->getMaps();
$maps = $this->maniaControl->getMapManager()
->getMaps();
$map = $maps[$mapIndex]; $map = $maps[$mapIndex];
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation("Next Map is $<{$map->name}$> from $<{$map->authorNick}$>.", $player);
->sendInformation("Next Map is $<{$map->name}$> from $<{$map->authorNick}$>.", $player);
} }
} }
@ -163,25 +132,20 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
* @param Player $player * @param Player $player
*/ */
public function command_RemoveMap(array $chatCallback, Player $player) { public function command_RemoveMap(array $chatCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_REMOVE_MAP)
->checkPermission($player, MapManager::SETTING_PERMISSION_REMOVE_MAP)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
// Get map // Get map
$map = $this->maniaControl->getMapManager() $map = $this->maniaControl->getMapManager()->getCurrentMap();
->getCurrentMap();
if (!$map) { if (!$map) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError("Couldn't remove map.", $player);
->sendError("Couldn't remove map.", $player);
return; return;
} }
// Remove map // Remove map
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->removeMap($player, $map->uid);
->removeMap($player, $map->uid);
} }
/** /**
@ -191,25 +155,20 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
* @param Player $player * @param Player $player
*/ */
public function command_EraseMap(array $chatCallback, Player $player) { public function command_EraseMap(array $chatCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_ERASE_MAP)
->checkPermission($player, MapManager::SETTING_PERMISSION_ERASE_MAP)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
// Get map // Get map
$map = $this->maniaControl->getMapManager() $map = $this->maniaControl->getMapManager()->getCurrentMap();
->getCurrentMap();
if (!$map) { if (!$map) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError("Couldn't erase map.", $player);
->sendError("Couldn't erase map.", $player);
return; return;
} }
// Erase map // Erase map
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->removeMap($player, $map->uid, true);
->removeMap($player, $map->uid, true);
} }
/** /**
@ -219,17 +178,14 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
* @param \ManiaControl\Players\Player $player * @param \ManiaControl\Players\Player $player
*/ */
public function command_ShuffleMaps(array $chatCallback, Player $player) { public function command_ShuffleMaps(array $chatCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_SHUFFLE_MAPS)
->checkPermission($player, MapManager::SETTING_PERMISSION_SHUFFLE_MAPS)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
// Shuffles the maps // Shuffles the maps
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->shuffleMapList($player);
->shuffleMapList($player);
} }
/** /**
@ -239,23 +195,19 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
* @param \ManiaControl\Players\Player $player * @param \ManiaControl\Players\Player $player
*/ */
public function command_AddMap(array $chatCallback, Player $player) { public function command_AddMap(array $chatCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)
->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chatCallback[1][2], 2); $params = explode(' ', $chatCallback[1][2], 2);
if (count($params) < 2) { if (count($params) < 2) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendUsageInfo('Usage example: //addmap 1234', $player);
->sendUsageInfo('Usage example: //addmap 1234', $player);
return; return;
} }
// add Map from Mania Exchange // add Map from Mania Exchange
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->addMapFromMx($params[1], $player->login);
->addMapFromMx($params[1], $player->login);
} }
/** /**
@ -265,21 +217,16 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
* @param \ManiaControl\Players\Player $player * @param \ManiaControl\Players\Player $player
*/ */
public function command_NextMap(array $chat, Player $player) { public function command_NextMap(array $chat, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_SKIP_MAP)
->checkPermission($player, MapManager::SETTING_PERMISSION_SKIP_MAP)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->getMapActions()->skipMap();
->getMapActions()
->skipMap();
$message = $player->getEscapedNickname() . ' skipped the current Map!'; $message = $player->getEscapedNickname() . ' skipped the current Map!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess($message);
->sendSuccess($message);
Logger::logInfo($message, true); Logger::logInfo($message, true);
} }
@ -290,21 +237,17 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
* @param \ManiaControl\Players\Player $player * @param \ManiaControl\Players\Player $player
*/ */
public function command_RestartMap(array $chat, Player $player) { public function command_RestartMap(array $chat, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_RESTART_MAP)
->checkPermission($player, MapManager::SETTING_PERMISSION_RESTART_MAP)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$message = $player->getEscapedNickname() . ' restarted the current Map!'; $message = $player->getEscapedNickname() . ' restarted the current Map!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess($message);
->sendSuccess($message);
Logger::logInfo($message, true); Logger::logInfo($message, true);
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->restartMap();
->restartMap();
} catch (ChangeInProgressException $e) { } catch (ChangeInProgressException $e) {
} }
} }
@ -317,22 +260,16 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
* @param \ManiaControl\Players\Player $player * @param \ManiaControl\Players\Player $player
*/ */
public function command_ReplayMap(array $chat, Player $player) { public function command_ReplayMap(array $chat, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_RESTART_MAP)
->checkPermission($player, MapManager::SETTING_PERMISSION_RESTART_MAP)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$message = $player->getEscapedNickname() . ' replays the current Map!'; $message = $player->getEscapedNickname() . ' replays the current Map!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess($message);
->sendSuccess($message);
Logger::logInfo($message, true); Logger::logInfo($message, true);
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->getMapQueue()->addFirstMapToMapQueue($player, $this->maniaControl->getMapManager()->getCurrentMap());
->getMapQueue()
->addFirstMapToMapQueue($player, $this->maniaControl->getMapManager()
->getCurrentMap());
} }
/** /**
@ -342,11 +279,9 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
* @param \ManiaControl\Players\Player $player * @param \ManiaControl\Players\Player $player
*/ */
public function command_WriteMapList(array $chat, Player $player) { public function command_WriteMapList(array $chat, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::AUTH_LEVEL_SUPERADMIN)
->checkRight($player, AuthenticationManager::AUTH_LEVEL_SUPERADMIN)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
@ -363,16 +298,13 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
$maplist = 'MatchSettings' . DIRECTORY_SEPARATOR . $maplist; $maplist = 'MatchSettings' . DIRECTORY_SEPARATOR . $maplist;
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->saveMatchSettings($maplist);
->saveMatchSettings($maplist);
$message = 'Maplist $<$fff' . $maplist . '$> written.'; $message = 'Maplist $<$fff' . $maplist . '$> written.';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess($message, $player);
->sendSuccess($message, $player);
Logger::logInfo($message, true); Logger::logInfo($message, true);
} catch (FaultException $e) { } catch (FaultException $e) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('Cannot write maplist $<$fff' . $maplist . '$>!', $player);
->sendError('Cannot write maplist $<$fff' . $maplist . '$>!', $player);
} }
} }
@ -383,11 +315,9 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
* @param \ManiaControl\Players\Player $player * @param \ManiaControl\Players\Player $player
*/ */
public function command_ReadMapList(array $chat, Player $player) { public function command_ReadMapList(array $chat, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::AUTH_LEVEL_SUPERADMIN)
->checkRight($player, AuthenticationManager::AUTH_LEVEL_SUPERADMIN)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
@ -404,18 +334,14 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
$maplist = 'MatchSettings' . DIRECTORY_SEPARATOR . $maplist; $maplist = 'MatchSettings' . DIRECTORY_SEPARATOR . $maplist;
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->loadMatchSettings($maplist);
->loadMatchSettings($maplist);
$message = 'Maplist $<$fff' . $maplist . '$> loaded.'; $message = 'Maplist $<$fff' . $maplist . '$> loaded.';
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->restructureMapList();
->restructureMapList(); $this->maniaControl->getChat()->sendSuccess($message, $player);
$this->maniaControl->getChat()
->sendSuccess($message, $player);
Logger::logInfo($message, true); Logger::logInfo($message, true);
} catch (FaultException $e) { } catch (FaultException $e) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('Cannot load maplist $<$fff' . $maplist . '$>!', $player);
->sendError('Cannot load maplist $<$fff' . $maplist . '$>!', $player);
} }
} }
@ -428,14 +354,11 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
$actionId = $callback[1][2]; $actionId = $callback[1][2];
$login = $callback[1][1]; $login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($login);
->getPlayer($login);
if (strstr($actionId, self::ACTION_SHOW_AUTHOR)) { if (strstr($actionId, self::ACTION_SHOW_AUTHOR)) {
$login = str_replace(self::ACTION_SHOW_AUTHOR, '', $actionId); $login = str_replace(self::ACTION_SHOW_AUTHOR, '', $actionId);
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->getMapList()->playerCloseWidget($player);
->getMapList()
->playerCloseWidget($player);
$this->showMapListAuthor($login, $player); $this->showMapListAuthor($login, $player);
} }
} }
@ -447,8 +370,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
* @param Player $player * @param Player $player
*/ */
private function showMapListAuthor($author, Player $player) { private function showMapListAuthor($author, Player $player) {
$maps = $this->maniaControl->getMapManager() $maps = $this->maniaControl->getMapManager()->getMaps();
->getMaps();
$mapList = array(); $mapList = array();
/** @var Map $map */ /** @var Map $map */
foreach ($maps as $map) { foreach ($maps as $map) {
@ -458,14 +380,11 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
} }
if (empty($mapList)) { if (empty($mapList)) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('There are no maps to show!', $player->login);
->sendError('There are no maps to show!', $player->login);
return; return;
} }
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->getMapList()->showMapList($player, $mapList);
->getMapList()
->showMapList($player, $mapList);
} }
/** /**
@ -476,9 +395,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
*/ */
public function command_List(array $chatCallback, Player $player) { public function command_List(array $chatCallback, Player $player) {
$chatCommands = explode(' ', $chatCallback[1][2]); $chatCommands = explode(' ', $chatCallback[1][2]);
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->getMapList()->playerCloseWidget($player);
->getMapList()
->playerCloseWidget($player);
if (isset($chatCommands[1])) { if (isset($chatCommands[1])) {
$listParam = strtolower($chatCommands[1]); $listParam = strtolower($chatCommands[1]);
@ -499,20 +416,15 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
if (isset($chatCommands[2])) { if (isset($chatCommands[2])) {
$this->showMaplistAuthor($chatCommands[2], $player); $this->showMaplistAuthor($chatCommands[2], $player);
} else { } else {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('Missing Author Login!', $player);
->sendError('Missing Author Login!', $player);
} }
break; break;
default: default:
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->getMapList()->showMapList($player);
->getMapList()
->showMapList($player);
break; break;
} }
} else { } else {
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->getMapList()->showMapList($player);
->getMapList()
->showMapList($player);
} }
} }
@ -524,16 +436,13 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
*/ */
private function showMapListKarma($best, Player $player) { private function showMapListKarma($best, Player $player) {
/** @var \MCTeam\KarmaPlugin $karmaPlugin */ /** @var \MCTeam\KarmaPlugin $karmaPlugin */
$karmaPlugin = $this->maniaControl->getPluginManager() $karmaPlugin = $this->maniaControl->getPluginManager()->getPlugin(MapList::DEFAULT_KARMA_PLUGIN);
->getPlugin(MapList::DEFAULT_KARMA_PLUGIN);
if ($karmaPlugin) { if ($karmaPlugin) {
$maps = $this->maniaControl->getMapManager() $maps = $this->maniaControl->getMapManager()->getMaps();
->getMaps();
$mapList = array(); $mapList = array();
foreach ($maps as $map) { foreach ($maps as $map) {
if ($map instanceof Map) { if ($map instanceof Map) {
if ($this->maniaControl->getSettingManager() if ($this->maniaControl->getSettingManager()->getSettingValue($karmaPlugin, $karmaPlugin::SETTING_NEWKARMA) === true
->getSettingValue($karmaPlugin, $karmaPlugin::SETTING_NEWKARMA) === true
) { ) {
$karma = $karmaPlugin->getMapKarma($map); $karma = $karmaPlugin->getMapKarma($map);
$map->karma = round($karma * 100.); $map->karma = round($karma * 100.);
@ -565,12 +474,9 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
$mapList = array_reverse($mapList); $mapList = array_reverse($mapList);
} }
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->getMapList()->showMapList($player, $mapList);
->getMapList()
->showMapList($player, $mapList);
} else { } else {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('KarmaPlugin is not enabled!', $player->login);
->sendError('KarmaPlugin is not enabled!', $player->login);
} }
} }
@ -581,8 +487,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
* @param Player $player * @param Player $player
*/ */
private function showMapListDate($newest, Player $player) { private function showMapListDate($newest, Player $player) {
$maps = $this->maniaControl->getMapManager() $maps = $this->maniaControl->getMapManager()->getMaps();
->getMaps();
usort($maps, function (Map $mapA, Map $mapB) { usort($maps, function (Map $mapA, Map $mapB) {
return ($mapA->index - $mapB->index); return ($mapA->index - $mapB->index);
@ -591,9 +496,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
$maps = array_reverse($maps); $maps = array_reverse($maps);
} }
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->getMapList()->showMapList($player, $maps);
->getMapList()
->showMapList($player, $maps);
} }
/** /**
@ -603,8 +506,6 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
* @param Player $player * @param Player $player
*/ */
public function command_xList(array $chatCallback, Player $player) { public function command_xList(array $chatCallback, Player $player) {
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->getMXList()->showList($chatCallback, $player);
->getMXList()
->showList($chatCallback, $player);
} }
} }

View File

@ -73,25 +73,16 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget'); $this->maniaControl->getCallbackManager()->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened'); $this->maniaControl->getCallbackManager()->registerCallbackListener(MapQueue::CB_MAPQUEUE_CHANGED, $this, 'updateWidget');
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(MapManager::CB_MAPS_UPDATED, $this, 'updateWidget');
->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer'); $this->maniaControl->getCallbackManager()->registerCallbackListener(MapManager::CB_KARMA_UPDATED, $this, 'updateWidget');
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::BEGINMAP, $this, 'updateWidget');
->registerCallbackListener(MapQueue::CB_MAPQUEUE_CHANGED, $this, 'updateWidget');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(MapManager::CB_MAPS_UPDATED, $this, 'updateWidget');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(MapManager::CB_KARMA_UPDATED, $this, 'updateWidget');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(Callbacks::BEGINMAP, $this, 'updateWidget');
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_CHECK_UPDATE, $this, 'checkUpdates');
->registerManialinkPageAnswerListener(self::ACTION_CHECK_UPDATE, $this, 'checkUpdates'); $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_CLEAR_MAPQUEUE, $this, 'clearMapQueue');
$this->maniaControl->getManialinkManager()
->registerManialinkPageAnswerListener(self::ACTION_CLEAR_MAPQUEUE, $this, 'clearMapQueue');
} }
/** /**
@ -102,9 +93,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
*/ */
public function clearMapQueue(array $chatCallback, Player $player) { public function clearMapQueue(array $chatCallback, Player $player) {
// Clears the Map Queue // Clears the Map Queue
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->getMapQueue()->clearMapQueue($player);
->getMapQueue()
->clearMapQueue($player);
} }
/** /**
@ -115,9 +104,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
*/ */
public function checkUpdates(array $chatCallback, Player $player) { public function checkUpdates(array $chatCallback, Player $player) {
// Update Mx Infos // Update Mx Infos
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->getMXManager()->fetchManiaExchangeMapInformation();
->getMXManager()
->fetchManiaExchangeMapInformation();
// Reshow the Maplist // Reshow the Maplist
$this->showMapList($player); $this->showMapList($player);
@ -131,33 +118,25 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
* @param int $pageIndex * @param int $pageIndex
*/ */
public function showMapList(Player $player, $mapList = null, $pageIndex = -1) { public function showMapList(Player $player, $mapList = null, $pageIndex = -1) {
$width = $this->maniaControl->getManialinkManager() $width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
->getStyleManager() $height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
->getListWidgetsWidth();
$height = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getListWidgetsHeight();
if ($pageIndex < 0) { if ($pageIndex < 0) {
$pageIndex = (int)$player->getCache($this, self::CACHE_CURRENT_PAGE); $pageIndex = (int)$player->getCache($this, self::CACHE_CURRENT_PAGE);
} }
$player->setCache($this, self::CACHE_CURRENT_PAGE, $pageIndex); $player->setCache($this, self::CACHE_CURRENT_PAGE, $pageIndex);
$queueBuffer = $this->maniaControl->getMapManager() $queueBuffer = $this->maniaControl->getMapManager()->getMapQueue()->getQueueBuffer();
->getMapQueue()
->getQueueBuffer();
$chunkIndex = $this->getChunkIndexFromPageNumber($pageIndex); $chunkIndex = $this->getChunkIndexFromPageNumber($pageIndex);
$mapsBeginIndex = $this->getChunkMapsBeginIndex($chunkIndex); $mapsBeginIndex = $this->getChunkMapsBeginIndex($chunkIndex);
// Get Maps // Get Maps
if (!is_array($mapList)) { if (!is_array($mapList)) {
$mapList = $this->maniaControl->getMapManager() $mapList = $this->maniaControl->getMapManager()->getMaps();
->getMaps();
} }
$mapList = array_slice($mapList, $mapsBeginIndex, self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE); $mapList = array_slice($mapList, $mapsBeginIndex, self::MAX_PAGES_PER_CHUNK * self::MAX_MAPS_PER_PAGE);
$totalMapsCount = $this->maniaControl->getMapManager() $totalMapsCount = $this->maniaControl->getMapManager()->getMapsCount();
->getMapsCount();
$pagesCount = ceil($totalMapsCount / self::MAX_MAPS_PER_PAGE); $pagesCount = ceil($totalMapsCount / self::MAX_MAPS_PER_PAGE);
// Create ManiaLink // Create ManiaLink
@ -170,14 +149,11 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$paging->setChunkActions(self::ACTION_PAGING_CHUNKS); $paging->setChunkActions(self::ACTION_PAGING_CHUNKS);
// Main frame // Main frame
$frame = $this->maniaControl->getManialinkManager() $frame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultListFrame($script, $paging);
->getStyleManager()
->getDefaultListFrame($script, $paging);
$maniaLink->add($frame); $maniaLink->add($frame);
// Admin Buttons // Admin Buttons
if ($this->maniaControl->getAuthenticationManager() if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, MapQueue::SETTING_PERMISSION_CLEAR_MAPQUEUE)
->checkPermission($player, MapQueue::SETTING_PERMISSION_CLEAR_MAPQUEUE)
) { ) {
// Clear Map-Queue // Clear Map-Queue
$label = new Label_Button(); $label = new Label_Button();
@ -196,8 +172,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$quad->setAction(self::ACTION_CLEAR_MAPQUEUE); $quad->setAction(self::ACTION_CLEAR_MAPQUEUE);
} }
if ($this->maniaControl->getAuthenticationManager() if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_CHECK_UPDATE)
->checkPermission($player, MapManager::SETTING_PERMISSION_CHECK_UPDATE)
) { ) {
// Check Update // Check Update
$label = new Label_Button(); $label = new Label_Button();
@ -218,19 +193,14 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$mxQuad = new Quad(); $mxQuad = new Quad();
$frame->add($mxQuad); $frame->add($mxQuad);
$mxQuad->setSize(3, 3); $mxQuad->setSize(3, 3);
$mxQuad->setImage($this->maniaControl->getManialinkManager() $mxQuad->setImage($this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON_GREEN));
->getIconManager() $mxQuad->setImageFocus($this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON_GREEN_MOVER));
->getIcon(IconManager::MX_ICON_GREEN));
$mxQuad->setImageFocus($this->maniaControl->getManialinkManager()
->getIconManager()
->getIcon(IconManager::MX_ICON_GREEN_MOVER));
$mxQuad->setPosition($width / 2 - 67, -$height / 2 + 9); $mxQuad->setPosition($width / 2 - 67, -$height / 2 + 9);
$mxQuad->setZ(0.01); $mxQuad->setZ(0.01);
$mxQuad->setAction(self::ACTION_CHECK_UPDATE); $mxQuad->setAction(self::ACTION_CHECK_UPDATE);
} }
if ($this->maniaControl->getAuthenticationManager() if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)
->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)
) { ) {
// Directory browser // Directory browser
$browserButton = new Label_Button(); $browserButton = new Label_Button();
@ -253,21 +223,15 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$headFrame->setY($height / 2 - 5); $headFrame->setY($height / 2 - 5);
$posX = -$width / 2; $posX = -$width / 2;
$array = array('Id' => $posX + 5, 'Mx Id' => $posX + 10, 'Map Name' => $posX + 20, 'Author' => $posX + 68, 'Karma' => $posX + 115, 'Actions' => $width / 2 - 16); $array = array('Id' => $posX + 5, 'Mx Id' => $posX + 10, 'Map Name' => $posX + 20, 'Author' => $posX + 68, 'Karma' => $posX + 115, 'Actions' => $width / 2 - 16);
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->labelLine($headFrame, $array);
->labelLine($headFrame, $array);
// Predefine description Label // Predefine description Label
$descriptionLabel = $this->maniaControl->getManialinkManager() $descriptionLabel = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultDescriptionLabel();
->getStyleManager()
->getDefaultDescriptionLabel();
$frame->add($descriptionLabel); $frame->add($descriptionLabel);
$queuedMaps = $this->maniaControl->getMapManager() $queuedMaps = $this->maniaControl->getMapManager()->getMapQueue()->getQueuedMapsRanking();
->getMapQueue()
->getQueuedMapsRanking();
/** @var KarmaPlugin $karmaPlugin */ /** @var KarmaPlugin $karmaPlugin */
$karmaPlugin = $this->maniaControl->getPluginManager() $karmaPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::DEFAULT_KARMA_PLUGIN);
->getPlugin(self::DEFAULT_KARMA_PLUGIN);
$pageNumber = 1 + $chunkIndex * self::MAX_PAGES_PER_CHUNK; $pageNumber = 1 + $chunkIndex * self::MAX_PAGES_PER_CHUNK;
$paging->setStartPageNumber($pageIndex + 1); $paging->setStartPageNumber($pageIndex + 1);
@ -277,20 +241,11 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$posY = $height / 2 - 10; $posY = $height / 2 - 10;
$pageFrame = null; $pageFrame = null;
$currentMap = $this->maniaControl->getMapManager() $currentMap = $this->maniaControl->getMapManager()->getCurrentMap();
->getCurrentMap(); $mxIcon = $this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON);
$mxIcon = $this->maniaControl->getManialinkManager() $mxIconHover = $this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON_MOVER);
->getIconManager() $mxIconGreen = $this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON_GREEN);
->getIcon(IconManager::MX_ICON); $mxIconGreenHover = $this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON_GREEN_MOVER);
$mxIconHover = $this->maniaControl->getManialinkManager()
->getIconManager()
->getIcon(IconManager::MX_ICON_MOVER);
$mxIconGreen = $this->maniaControl->getManialinkManager()
->getIconManager()
->getIcon(IconManager::MX_ICON_GREEN);
$mxIconGreenHover = $this->maniaControl->getManialinkManager()
->getIconManager()
->getIcon(IconManager::MX_ICON_GREEN_MOVER);
foreach ($mapList as $map) { foreach ($mapList as $map) {
/** @var Map $map */ /** @var Map $map */
@ -353,8 +308,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$mxQuad->addTooltipLabelFeature($descriptionLabel, $description); $mxQuad->addTooltipLabelFeature($descriptionLabel, $description);
// Update Button // Update Button
if ($this->maniaControl->getAuthenticationManager() if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)
->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)
) { ) {
$mxQuad->setAction(self::ACTION_UPDATE_MAP . '.' . $map->uid); $mxQuad->setAction(self::ACTION_UPDATE_MAP . '.' . $map->uid);
} }
@ -363,8 +317,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
// Display Maps // Display Maps
$array = array($mapListId => $posX + 5, $mxId => $posX + 10, Formatter::stripDirtyCodes($map->name) => $posX + 20, $map->authorNick => $posX + 68); $array = array($mapListId => $posX + 5, $mxId => $posX + 10, Formatter::stripDirtyCodes($map->name) => $posX + 20, $map->authorNick => $posX + 68);
$labels = $this->maniaControl->getManialinkManager() $labels = $this->maniaControl->getManialinkManager()->labelLine($mapFrame, $array);
->labelLine($mapFrame, $array);
if (isset($labels[3])) { if (isset($labels[3])) {
/** @var Label $label */ /** @var Label $label */
$label = $labels[3]; $label = $labels[3];
@ -386,9 +339,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$label->setTextColor('fff'); $label->setTextColor('fff');
// Checks if the Player who opened the Widget has queued the map // Checks if the Player who opened the Widget has queued the map
$queuer = $this->maniaControl->getMapManager() $queuer = $this->maniaControl->getMapManager()->getMapQueue()->getQueuer($map->uid);
->getMapQueue()
->getQueuer($map->uid);
if ($queuer->login == $player->login) { if ($queuer->login == $player->login) {
$description = 'Remove ' . $map->getEscapedName() . ' from the Map Queue'; $description = 'Remove ' . $map->getEscapedName() . ' from the Map Queue';
$label->addTooltipLabelFeature($descriptionLabel, $description); $label->addTooltipLabelFeature($descriptionLabel, $description);
@ -407,8 +358,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$queueLabel->setText('+'); $queueLabel->setText('+');
if (in_array($map->uid, $queueBuffer)) { if (in_array($map->uid, $queueBuffer)) {
if ($this->maniaControl->getAuthenticationManager() if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, MapQueue::SETTING_PERMISSION_CLEAR_MAPQUEUE)
->checkPermission($player, MapQueue::SETTING_PERMISSION_CLEAR_MAPQUEUE)
) { ) {
$queueLabel->setAction(self::ACTION_QUEUED_MAP . '.' . $map->uid); $queueLabel->setAction(self::ACTION_QUEUED_MAP . '.' . $map->uid);
} }
@ -423,8 +373,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
} }
} }
if ($this->maniaControl->getAuthenticationManager() if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_REMOVE_MAP)
->checkPermission($player, MapManager::SETTING_PERMISSION_REMOVE_MAP)
) { ) {
// remove map button // remove map button
$removeButton = new Label_Button(); $removeButton = new Label_Button();
@ -442,8 +391,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$removeButton->addTooltipLabelFeature($descriptionLabel, $description); $removeButton->addTooltipLabelFeature($descriptionLabel, $description);
} }
if ($this->maniaControl->getAuthenticationManager() if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)
->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)
) { ) {
// Switch to button // Switch to button
$switchLabel = new Label_Button(); $switchLabel = new Label_Button();
@ -461,11 +409,9 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$description = 'Switch Directly to Map: ' . $map->getEscapedName(); $description = 'Switch Directly to Map: ' . $map->getEscapedName();
$switchLabel->addTooltipLabelFeature($descriptionLabel, $description); $switchLabel->addTooltipLabelFeature($descriptionLabel, $description);
} }
if ($this->maniaControl->getPluginManager() if ($this->maniaControl->getPluginManager()->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)
->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)
) { ) {
if ($this->maniaControl->getAuthenticationManager() if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)
->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)
) { ) {
// Switch Map Voting for Admins // Switch Map Voting for Admins
$switchQuad = new Quad_UIConstruction_Buttons(); $switchQuad = new Quad_UIConstruction_Buttons();
@ -498,8 +444,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$karma = $karmaPlugin->getMapKarma($map); $karma = $karmaPlugin->getMapKarma($map);
$votes = $karmaPlugin->getMapVotes($map); $votes = $karmaPlugin->getMapVotes($map);
if (is_numeric($karma)) { if (is_numeric($karma)) {
if ($this->maniaControl->getSettingManager() if ($this->maniaControl->getSettingManager()->getSettingValue($karmaPlugin, $karmaPlugin::SETTING_NEWKARMA)
->getSettingValue($karmaPlugin, $karmaPlugin::SETTING_NEWKARMA)
) { ) {
$karmaText = ' ' . round($karma * 100.) . '% (' . $votes['count'] . ')'; $karmaText = ' ' . round($karma * 100.) . '% (' . $votes['count'] . ')';
} else { } else {
@ -547,8 +492,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$index++; $index++;
} }
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, self::WIDGET_NAME);
->displayWidget($maniaLink, $player, self::WIDGET_NAME);
} }
/** /**
@ -558,8 +502,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
* @return int * @return int
*/ */
private function getChunkIndexFromPageNumber($pageIndex) { private function getChunkIndexFromPageNumber($pageIndex) {
$mapsCount = $this->maniaControl->getMapManager() $mapsCount = $this->maniaControl->getMapManager()->getMapsCount();
->getMapsCount();
$pagesCount = ceil($mapsCount / self::MAX_MAPS_PER_PAGE); $pagesCount = ceil($mapsCount / self::MAX_MAPS_PER_PAGE);
if ($pageIndex > $pagesCount - 1) { if ($pageIndex > $pagesCount - 1) {
$pageIndex = $pagesCount - 1; $pageIndex = $pagesCount - 1;
@ -590,15 +533,9 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
// TODO: get rid of the confirm frame to decrease xml size & network usage // TODO: get rid of the confirm frame to decrease xml size & network usage
// SUGGESTION: just send them as own manialink again on clicking? // SUGGESTION: just send them as own manialink again on clicking?
$width = $this->maniaControl->getManialinkManager() $width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
->getStyleManager() $quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowStyle();
->getListWidgetsWidth(); $quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowSubStyle();
$quadStyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultMainWindowStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultMainWindowSubStyle();
$confirmFrame = new Frame(); $confirmFrame = new Frame();
$maniaLink->add($confirmFrame); $maniaLink->add($confirmFrame);
@ -678,77 +615,60 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$action = $actionArray[0] . '.' . $actionArray[1]; $action = $actionArray[0] . '.' . $actionArray[1];
$login = $callback[1][1]; $login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($login);
->getPlayer($login);
$mapUid = $actionArray[2]; $mapUid = $actionArray[2];
switch ($action) { switch ($action) {
case self::ACTION_UPDATE_MAP: case self::ACTION_UPDATE_MAP:
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->updateMap($player, $mapUid);
->updateMap($player, $mapUid);
$this->showMapList($player); $this->showMapList($player);
break; break;
case self::ACTION_REMOVE_MAP: case self::ACTION_REMOVE_MAP:
try { try {
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->removeMap($player, $mapUid);
->removeMap($player, $mapUid);
} catch (FileException $e) { } catch (FileException $e) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendException($e, $player);
->sendException($e, $player);
} }
break; break;
case self::ACTION_SWITCH_MAP: case self::ACTION_SWITCH_MAP:
// Don't queue on Map-Change // Don't queue on Map-Change
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->getMapQueue()->dontQueueNextMapChange();
->getMapQueue()
->dontQueueNextMapChange();
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->jumpToMapIdent($mapUid);
->jumpToMapIdent($mapUid);
} catch (NextMapException $exception) { } catch (NextMapException $exception) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('Error on Jumping to Map Ident: ' . $exception->getMessage(), $player);
->sendError('Error on Jumping to Map Ident: ' . $exception->getMessage(), $player);
break; break;
} catch (NotInListException $exception) { } catch (NotInListException $exception) {
// TODO: "Map not found." -> how is that possible? // TODO: "Map not found." -> how is that possible?
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('Error on Jumping to Map Ident: ' . $exception->getMessage(), $player);
->sendError('Error on Jumping to Map Ident: ' . $exception->getMessage(), $player);
break; break;
} }
$map = $this->maniaControl->getMapManager() $map = $this->maniaControl->getMapManager()->getMapByUid($mapUid);
->getMapByUid($mapUid);
$message = $player->getEscapedNickname() . ' skipped to Map $z' . $map->getEscapedName() . '!'; $message = $player->getEscapedNickname() . ' skipped to Map $z' . $map->getEscapedName() . '!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess($message);
->sendSuccess($message);
Logger::logInfo($message, true); Logger::logInfo($message, true);
$this->playerCloseWidget($player); $this->playerCloseWidget($player);
break; break;
case self::ACTION_START_SWITCH_VOTE: case self::ACTION_START_SWITCH_VOTE:
/** @var CustomVotesPlugin $votesPlugin */ /** @var CustomVotesPlugin $votesPlugin */
$votesPlugin = $this->maniaControl->getPluginManager() $votesPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN);
->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN); $map = $this->maniaControl->getMapManager()->getMapByUid($mapUid);
$map = $this->maniaControl->getMapManager()
->getMapByUid($mapUid);
$message = $player->getEscapedNickname() . '$s started a vote to switch to ' . $map->getEscapedName() . '!'; $message = $player->getEscapedNickname() . '$s started a vote to switch to ' . $map->getEscapedName() . '!';
$votesPlugin->defineVote('switchmap', 'Goto ' . $map->name, true, $message) $votesPlugin->defineVote('switchmap', 'Goto ' . $map->name, true, $message)->setStopCallback(Callbacks::ENDMAP);
->setStopCallback(Callbacks::ENDMAP);
$votesPlugin->startVote($player, 'switchmap', function ($result) use (&$votesPlugin, &$map) { $votesPlugin->startVote($player, 'switchmap', function ($result) use (&$votesPlugin, &$map) {
$votesPlugin->undefineVote('switchmap'); $votesPlugin->undefineVote('switchmap');
//Don't queue on Map-Change //Don't queue on Map-Change
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->getMapQueue()->dontQueueNextMapChange();
->getMapQueue()
->dontQueueNextMapChange();
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->JumpToMapIdent($map->uid);
->JumpToMapIdent($map->uid);
} catch (NextMapException $exception) { } catch (NextMapException $exception) {
return; return;
} catch (NotInListException $exception) { } catch (NotInListException $exception) {
@ -758,20 +678,15 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
return; return;
} }
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation('$sVote Successful -> Map switched!');
->sendInformation('$sVote Successful -> Map switched!');
}); });
break; break;
case self::ACTION_QUEUED_MAP: case self::ACTION_QUEUED_MAP:
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->getMapQueue()->addMapToMapQueue($callback[1][1], $mapUid);
->getMapQueue()
->addMapToMapQueue($callback[1][1], $mapUid);
$this->showMapList($player); $this->showMapList($player);
break; break;
case self::ACTION_UNQUEUE_MAP: case self::ACTION_UNQUEUE_MAP:
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->getMapQueue()->removeFromMapQueue($player, $mapUid);
->getMapQueue()
->removeFromMapQueue($player, $mapUid);
$this->showMapList($player); $this->showMapList($player);
break; break;
default: default:
@ -791,16 +706,14 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
*/ */
public function playerCloseWidget(Player $player) { public function playerCloseWidget(Player $player) {
$player->destroyCache($this, self::CACHE_CURRENT_PAGE); $player->destroyCache($this, self::CACHE_CURRENT_PAGE);
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->closeWidget($player);
->closeWidget($player);
} }
/** /**
* Reopen the widget on Map Begin, MapListChanged, etc. * Reopen the widget on Map Begin, MapListChanged, etc.
*/ */
public function updateWidget() { public function updateWidget() {
$players = $this->maniaControl->getPlayerManager() $players = $this->maniaControl->getPlayerManager()->getPlayers();
->getPlayers();
foreach ($players as $player) { foreach ($players as $player) {
$currentPage = $player->getCache($this, self::CACHE_CURRENT_PAGE); $currentPage = $player->getCache($this, self::CACHE_CURRENT_PAGE);
if ($currentPage !== null) { if ($currentPage !== null) {

View File

@ -104,36 +104,23 @@ class MapManager implements CallbackListener {
$this->mapActions = new MapActions($maniaControl); $this->mapActions = new MapActions($maniaControl);
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONINIT, $this, 'handleOnInit');
->registerCallbackListener(Callbacks::ONINIT, $this, 'handleOnInit'); $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_MAPLISTMODIFIED, $this, 'mapsModified');
->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(CallbackManager::CB_MP_MAPLISTMODIFIED, $this, 'mapsModified');
// Permissions // Permissions
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_ADD_MAP, AuthenticationManager::AUTH_LEVEL_ADMIN);
->definePermissionLevel(self::SETTING_PERMISSION_ADD_MAP, AuthenticationManager::AUTH_LEVEL_ADMIN); $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_REMOVE_MAP, AuthenticationManager::AUTH_LEVEL_ADMIN);
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_ERASE_MAP, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
->definePermissionLevel(self::SETTING_PERMISSION_REMOVE_MAP, AuthenticationManager::AUTH_LEVEL_ADMIN); $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_SHUFFLE_MAPS, AuthenticationManager::AUTH_LEVEL_ADMIN);
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_CHECK_UPDATE, AuthenticationManager::AUTH_LEVEL_MODERATOR);
->definePermissionLevel(self::SETTING_PERMISSION_ERASE_MAP, AuthenticationManager::AUTH_LEVEL_SUPERADMIN); $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_SKIP_MAP, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_RESTART_MAP, AuthenticationManager::AUTH_LEVEL_MODERATOR);
->definePermissionLevel(self::SETTING_PERMISSION_SHUFFLE_MAPS, AuthenticationManager::AUTH_LEVEL_ADMIN);
$this->maniaControl->getAuthenticationManager()
->definePermissionLevel(self::SETTING_PERMISSION_CHECK_UPDATE, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->getAuthenticationManager()
->definePermissionLevel(self::SETTING_PERMISSION_SKIP_MAP, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->getAuthenticationManager()
->definePermissionLevel(self::SETTING_PERMISSION_RESTART_MAP, AuthenticationManager::AUTH_LEVEL_MODERATOR);
// Settings // Settings
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_AUTOSAVE_MAPLIST, true);
->initSetting($this, self::SETTING_AUTOSAVE_MAPLIST, true); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAPLIST_FILE, "MatchSettings/tracklist.txt");
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WRITE_OWN_MAPLIST_FILE, false);
->initSetting($this, self::SETTING_MAPLIST_FILE, "MatchSettings/tracklist.txt");
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_WRITE_OWN_MAPLIST_FILE, false);
} }
/** /**
@ -142,8 +129,7 @@ class MapManager implements CallbackListener {
* @return bool * @return bool
*/ */
private function initTables() { private function initTables() {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_MAPS . "` ( $query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_MAPS . "` (
`index` int(11) NOT NULL AUTO_INCREMENT, `index` int(11) NOT NULL AUTO_INCREMENT,
`mxid` int(11), `mxid` int(11),
@ -238,8 +224,7 @@ class MapManager implements CallbackListener {
$this->updateMapTimestamp($uid); $this->updateMapTimestamp($uid);
if (!isset($uid) || !isset($this->maps[$uid])) { if (!isset($uid) || !isset($this->maps[$uid])) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError("Error updating Map: Unknown UID '{$uid}'!", $admin);
->sendError("Error updating Map: Unknown UID '{$uid}'!", $admin);
return; return;
} }
@ -258,8 +243,7 @@ class MapManager implements CallbackListener {
* @return bool * @return bool
*/ */
private function updateMapTimestamp($uid) { private function updateMapTimestamp($uid) {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$mapQuery = "UPDATE `" . self::TABLE_MAPS . "` SET $mapQuery = "UPDATE `" . self::TABLE_MAPS . "` SET
mxid = 0, mxid = 0,
changed = NOW() changed = NOW()
@ -290,8 +274,7 @@ class MapManager implements CallbackListener {
*/ */
public function removeMap(Player $admin, $uid, $eraseFile = false, $message = true) { public function removeMap(Player $admin, $uid, $eraseFile = false, $message = true) {
if (!isset($this->maps[$uid])) { if (!isset($this->maps[$uid])) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('Map does not exist!', $admin);
->sendError('Map does not exist!', $admin);
return; return;
} }
@ -299,18 +282,15 @@ class MapManager implements CallbackListener {
$map = $this->maps[$uid]; $map = $this->maps[$uid];
// Unset the Map everywhere // Unset the Map everywhere
$this->getMapQueue() $this->getMapQueue()->removeFromMapQueue($admin, $map->uid);
->removeFromMapQueue($admin, $map->uid);
if ($map->mx) { if ($map->mx) {
$this->getMXManager() $this->getMXManager()->unsetMap($map->mx->id);
->unsetMap($map->mx->id);
} }
// Remove map // Remove map
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->removeMap($map->fileName);
->removeMap($map->fileName);
} catch (NotInListException $e) { } catch (NotInListException $e) {
} }
@ -318,20 +298,16 @@ class MapManager implements CallbackListener {
if ($eraseFile) { if ($eraseFile) {
// Check if ManiaControl can even write to the maps dir // Check if ManiaControl can even write to the maps dir
$mapDir = $this->maniaControl->getClient() $mapDir = $this->maniaControl->getClient()->getMapsDirectory();
->getMapsDirectory(); if ($this->maniaControl->getServer()->checkAccess($mapDir)
if ($this->maniaControl->getServer()
->checkAccess($mapDir)
) { ) {
// Delete map file // Delete map file
if (!@unlink($mapDir . $map->fileName)) { if (!@unlink($mapDir . $map->fileName)) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError("Couldn't erase the map file.", $admin);
->sendError("Couldn't erase the map file.", $admin);
$eraseFile = false; $eraseFile = false;
} }
} else { } else {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError("Couldn't erase the map file (no access).", $admin);
->sendError("Couldn't erase the map file (no access).", $admin);
$eraseFile = false; $eraseFile = false;
} }
} }
@ -340,8 +316,7 @@ class MapManager implements CallbackListener {
if ($message) { if ($message) {
$action = ($eraseFile ? 'erased' : 'removed'); $action = ($eraseFile ? 'erased' : 'removed');
$message = $admin->getEscapedNickname() . ' ' . $action . ' ' . $map->getEscapedName() . '!'; $message = $admin->getEscapedNickname() . ' ' . $action . ' ' . $map->getEscapedName() . '!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess($message);
->sendSuccess($message);
Logger::logInfo($message, true); Logger::logInfo($message, true);
} }
} }
@ -356,27 +331,22 @@ class MapManager implements CallbackListener {
public function addMapFromMx($mapId, $login, $update = false) { public function addMapFromMx($mapId, $login, $update = false) {
if (is_numeric($mapId)) { if (is_numeric($mapId)) {
// Check if map exists // Check if map exists
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->getMXManager()->fetchMapInfo($mapId, function (MXMapInfo $mapInfo = null) use (
->getMXManager()
->fetchMapInfo($mapId, function (MXMapInfo $mapInfo = null) use (
&$login, &$update &$login, &$update
) { ) {
if (!$mapInfo || !isset($mapInfo->uploaded)) { if (!$mapInfo || !isset($mapInfo->uploaded)) {
// Invalid id // Invalid id
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('Invalid MX-Id!', $login);
->sendError('Invalid MX-Id!', $login);
return; return;
} }
// Download the file // Download the file
$this->maniaControl->getFileReader() $this->maniaControl->getFileReader()->loadFile($mapInfo->downloadurl, function ($file, $error) use (
->loadFile($mapInfo->downloadurl, function ($file, $error) use (
&$login, &$mapInfo, &$update &$login, &$mapInfo, &$update
) { ) {
if (!$file || $error) { if (!$file || $error) {
// Download error // Download error
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError("Download failed: '{$error}'!", $login);
->sendError("Download failed: '{$error}'!", $login);
return; return;
} }
$this->processMapFile($file, $mapInfo, $login, $update); $this->processMapFile($file, $mapInfo, $login, $update);
@ -397,8 +367,7 @@ class MapManager implements CallbackListener {
private function processMapFile($file, MXMapInfo $mapInfo, $login, $update) { private function processMapFile($file, MXMapInfo $mapInfo, $login, $update) {
// Check if map is already on the server // Check if map is already on the server
if ($this->getMapByUid($mapInfo->uid)) { if ($this->getMapByUid($mapInfo->uid)) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('Map is already on the server!', $login);
->sendError('Map is already on the server!', $login);
return; return;
} }
@ -406,41 +375,33 @@ class MapManager implements CallbackListener {
$fileName = $mapInfo->id . '_' . $mapInfo->name . '.Map.Gbx'; $fileName = $mapInfo->id . '_' . $mapInfo->name . '.Map.Gbx';
$fileName = FileUtil::getClearedFileName($fileName); $fileName = FileUtil::getClearedFileName($fileName);
$downloadFolderName = $this->maniaControl->getSettingManager() $downloadFolderName = $this->maniaControl->getSettingManager()->getSettingValue($this, 'MapDownloadDirectory', 'MX');
->getSettingValue($this, 'MapDownloadDirectory', 'MX');
$relativeMapFileName = $downloadFolderName . DIRECTORY_SEPARATOR . $fileName; $relativeMapFileName = $downloadFolderName . DIRECTORY_SEPARATOR . $fileName;
$mapDir = $this->maniaControl->getServer() $mapDir = $this->maniaControl->getServer()->getDirectory()->getMapsFolder();
->getDirectory()
->getMapsFolder();
$downloadDirectory = $mapDir . $downloadFolderName . DIRECTORY_SEPARATOR; $downloadDirectory = $mapDir . $downloadFolderName . DIRECTORY_SEPARATOR;
$fullMapFileName = $downloadDirectory . $fileName; $fullMapFileName = $downloadDirectory . $fileName;
// Check if it can get written locally // Check if it can get written locally
if ($this->maniaControl->getServer() if ($this->maniaControl->getServer()->checkAccess($mapDir)
->checkAccess($mapDir)
) { ) {
// Create download directory if necessary // Create download directory if necessary
if (!is_dir($downloadDirectory) && !mkdir($downloadDirectory) || !is_writable($downloadDirectory)) { if (!is_dir($downloadDirectory) && !mkdir($downloadDirectory) || !is_writable($downloadDirectory)) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError("ManiaControl doesn't have to rights to save maps in '{$downloadDirectory}'.", $login);
->sendError("ManiaControl doesn't have to rights to save maps in '{$downloadDirectory}'.", $login);
return; return;
} }
if (!file_put_contents($fullMapFileName, $file)) { if (!file_put_contents($fullMapFileName, $file)) {
// Save error // Save error
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('Saving map failed!', $login);
->sendError('Saving map failed!', $login);
return; return;
} }
} else { } else {
// Write map via write file method // Write map via write file method
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->writeFile($relativeMapFileName, $file);
->writeFile($relativeMapFileName, $file);
} catch (InvalidArgumentException $e) { } catch (InvalidArgumentException $e) {
if ($e->getMessage() === 'data are too big') { if ($e->getMessage() === 'data are too big') {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError("Map is too big for a remote save.", $login);
->sendError("Map is too big for a remote save.", $login);
return; return;
} }
throw $e; throw $e;
@ -449,63 +410,49 @@ class MapManager implements CallbackListener {
// Check for valid map // Check for valid map
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->checkMapForCurrentServerParams($relativeMapFileName);
->checkMapForCurrentServerParams($relativeMapFileName);
} catch (InvalidMapException $exception) { } catch (InvalidMapException $exception) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendException($exception, $login);
->sendException($exception, $login);
return; return;
} catch (FileException $exception) { } catch (FileException $exception) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendException($exception, $login);
->sendException($exception, $login);
return; return;
} }
// Add map to map list // Add map to map list
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->insertMap($relativeMapFileName);
->insertMap($relativeMapFileName);
} catch (AlreadyInListException $exception) { } catch (AlreadyInListException $exception) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendException($exception, $login);
->sendException($exception, $login);
return; return;
} }
$this->updateFullMapList(); $this->updateFullMapList();
// Update Mx MapInfo // Update Mx MapInfo
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->getMXManager()->updateMapObjectsWithManiaExchangeIds(array($mapInfo));
->getMXManager()
->updateMapObjectsWithManiaExchangeIds(array($mapInfo));
// Update last updated time // Update last updated time
$map = $this->getMapByUid($mapInfo->uid); $map = $this->getMapByUid($mapInfo->uid);
if (!$map) { if (!$map) {
// TODO: improve this - error reports about not existing maps // TODO: improve this - error reports about not existing maps
$this->maniaControl->getErrorHandler() $this->maniaControl->getErrorHandler()->triggerDebugNotice('Map not in List after Insert!');
->triggerDebugNotice('Map not in List after Insert!'); $this->maniaControl->getChat()->sendError('Server Error!', $login);
$this->maniaControl->getChat()
->sendError('Server Error!', $login);
return; return;
} }
$map->lastUpdate = time(); $map->lastUpdate = time();
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($login);
->getPlayer($login);
if (!$update) { if (!$update) {
// Message // Message
$message = $player->getEscapedNickname() . ' added $<' . $mapInfo->name . '$>!'; $message = $player->getEscapedNickname() . ' added $<' . $mapInfo->name . '$>!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess($message);
->sendSuccess($message);
Logger::logInfo($message, true); Logger::logInfo($message, true);
// Queue requested Map // Queue requested Map
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->getMapQueue()->addMapToMapQueue($login, $mapInfo->uid);
->getMapQueue()
->addMapToMapQueue($login, $mapInfo->uid);
} else { } else {
$message = $player->getEscapedNickname() . ' updated $<' . $mapInfo->name . '$>!'; $message = $player->getEscapedNickname() . ' updated $<' . $mapInfo->name . '$>!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess($message);
->sendSuccess($message);
Logger::logInfo($message, true); Logger::logInfo($message, true);
} }
} }
@ -532,8 +479,7 @@ class MapManager implements CallbackListener {
try { try {
$offset = 0; $offset = 0;
while ($this->maniaControl->getClient()) { while ($this->maniaControl->getClient()) {
$maps = $this->maniaControl->getClient() $maps = $this->maniaControl->getClient()->getMapList(150, $offset);
->getMapList(150, $offset);
foreach ($maps as $rpcMap) { foreach ($maps as $rpcMap) {
if (array_key_exists($rpcMap->uId, $this->maps)) { if (array_key_exists($rpcMap->uId, $this->maps)) {
@ -555,26 +501,21 @@ class MapManager implements CallbackListener {
$this->maps = $tempList; $this->maps = $tempList;
// Trigger own callback // Trigger own callback
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MAPS_UPDATED);
->triggerCallback(self::CB_MAPS_UPDATED);
// Write MapList // Write MapList
if ($this->maniaControl->getSettingManager() if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_AUTOSAVE_MAPLIST)
->getSettingValue($this, self::SETTING_AUTOSAVE_MAPLIST)
) { ) {
if ($this->maniaControl->getSettingManager() if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WRITE_OWN_MAPLIST_FILE)
->getSettingValue($this, self::SETTING_WRITE_OWN_MAPLIST_FILE)
) { ) {
$serverLogin = $this->maniaControl->getServer()->login; $serverLogin = $this->maniaControl->getServer()->login;
$matchSettingsFileName = "MatchSettings/{$serverLogin}.txt"; $matchSettingsFileName = "MatchSettings/{$serverLogin}.txt";
} else { } else {
$matchSettingsFileName = $this->maniaControl->getSettingManager() $matchSettingsFileName = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAPLIST_FILE);
->getSettingValue($this, self::SETTING_MAPLIST_FILE);
} }
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->saveMatchSettings($matchSettingsFileName);
->saveMatchSettings($matchSettingsFileName);
} catch (FileException $e) { } catch (FileException $e) {
Logger::logError("Unable to write the playlist file, please checkout your MX-Folders File permissions!"); Logger::logError("Unable to write the playlist file, please checkout your MX-Folders File permissions!");
} }
@ -601,8 +542,7 @@ class MapManager implements CallbackListener {
*/ */
private function saveMap(Map &$map) { private function saveMap(Map &$map) {
//TODO saveMaps for whole maplist at once (usage of prepared statements) //TODO saveMaps for whole maplist at once (usage of prepared statements)
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$mapQuery = "INSERT INTO `" . self::TABLE_MAPS . "` ( $mapQuery = "INSERT INTO `" . self::TABLE_MAPS . "` (
`uid`, `uid`,
`name`, `name`,
@ -653,12 +593,10 @@ class MapManager implements CallbackListener {
} }
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->chooseNextMapList($mapArray);
->chooseNextMapList($mapArray);
} catch (Exception $e) { } catch (Exception $e) {
//TODO temp added 19.04.2014 //TODO temp added 19.04.2014
$this->maniaControl->getErrorHandler() $this->maniaControl->getErrorHandler()->triggerDebugNotice("Exception line 331 MapManager" . $e->getMessage());
->triggerDebugNotice("Exception line 331 MapManager" . $e->getMessage());
trigger_error("Couldn't shuffle mapList. " . $e->getMessage()); trigger_error("Couldn't shuffle mapList. " . $e->getMessage());
return false; return false;
} }
@ -667,8 +605,7 @@ class MapManager implements CallbackListener {
if ($admin) { if ($admin) {
$message = $admin->getEscapedNickname() . ' shuffled the Maplist!'; $message = $admin->getEscapedNickname() . ' shuffled the Maplist!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess($message);
->sendSuccess($message);
Logger::logInfo($message, true); Logger::logInfo($message, true);
} }
@ -684,8 +621,7 @@ class MapManager implements CallbackListener {
*/ */
private function fetchCurrentMap() { private function fetchCurrentMap() {
try { try {
$rpcMap = $this->maniaControl->getClient() $rpcMap = $this->maniaControl->getClient()->getCurrentMapInfo();
->getCurrentMapInfo();
} catch (UnavailableFeatureException $exception) { } catch (UnavailableFeatureException $exception) {
return null; return null;
} }
@ -730,8 +666,7 @@ class MapManager implements CallbackListener {
array_shift($mapArray); array_shift($mapArray);
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->chooseNextMapList($mapArray);
->chooseNextMapList($mapArray);
} catch (Exception $e) { } catch (Exception $e) {
trigger_error("Error restructuring the Maplist. " . $e->getMessage()); trigger_error("Error restructuring the Maplist. " . $e->getMessage());
return false; return false;
@ -795,8 +730,7 @@ class MapManager implements CallbackListener {
*/ */
public function handleAfterInit() { public function handleAfterInit() {
// Fetch MX infos // Fetch MX infos
$this->getMXManager() $this->getMXManager()->fetchManiaExchangeMapInformation();
->fetchManiaExchangeMapInformation();
} }
/** /**
@ -831,8 +765,7 @@ class MapManager implements CallbackListener {
// Map already exists, only update index // Map already exists, only update index
$this->currentMap = $this->maps[$uid]; $this->currentMap = $this->maps[$uid];
if (!$this->currentMap->nbCheckpoints || !$this->currentMap->nbLaps) { if (!$this->currentMap->nbCheckpoints || !$this->currentMap->nbLaps) {
$rpcMap = $this->maniaControl->getClient() $rpcMap = $this->maniaControl->getClient()->getCurrentMapInfo();
->getCurrentMapInfo();
$this->currentMap->nbLaps = $rpcMap->nbLaps; $this->currentMap->nbLaps = $rpcMap->nbLaps;
$this->currentMap->nbCheckpoints = $rpcMap->nbCheckpoints; $this->currentMap->nbCheckpoints = $rpcMap->nbCheckpoints;
} }
@ -842,12 +775,10 @@ class MapManager implements CallbackListener {
$this->restructureMapList(); $this->restructureMapList();
// Update the mx of the map (for update checks, etc.) // Update the mx of the map (for update checks, etc.)
$this->getMXManager() $this->getMXManager()->fetchManiaExchangeMapInformation($this->currentMap);
->fetchManiaExchangeMapInformation($this->currentMap);
// Trigger own BeginMap callback // Trigger own BeginMap callback
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::BEGINMAP, $this->currentMap);
->triggerCallback(Callbacks::BEGINMAP, $this->currentMap);
} }
/** /**
@ -861,8 +792,7 @@ class MapManager implements CallbackListener {
$this->mapBegan = false; $this->mapBegan = false;
// Trigger own EndMap callback // Trigger own EndMap callback
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ENDMAP, $this->currentMap);
->triggerCallback(Callbacks::ENDMAP, $this->currentMap);
} }
/** /**
@ -872,8 +802,7 @@ class MapManager implements CallbackListener {
* @return Map * @return Map
*/ */
public function fetchMapByFileName($relativeFileName) { public function fetchMapByFileName($relativeFileName) {
$mapInfo = $this->maniaControl->getClient() $mapInfo = $this->maniaControl->getClient()->getMapInfo($relativeFileName);
->getMapInfo($relativeFileName);
if (!$mapInfo) { if (!$mapInfo) {
return null; return null;
} }

View File

@ -56,38 +56,25 @@ class MapQueue implements CallbackListener, CommandListener {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ENDMAP, $this, 'endMap');
->registerCallbackListener(Callbacks::ENDMAP, $this, 'endMap'); $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::BEGINMAP, $this, 'beginMap');
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
->registerCallbackListener(Callbacks::BEGINMAP, $this, 'beginMap');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
// Settings // Settings
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SKIP_MAP_ON_LEAVE, true);
->initSetting($this, self::SETTING_SKIP_MAP_ON_LEAVE, true); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SKIP_MAPQUEUE_ADMIN, false);
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAPLIMIT_PLAYER, 1);
->initSetting($this, self::SETTING_SKIP_MAPQUEUE_ADMIN, false); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAPLIMIT_ADMIN, -1);
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_BUFFERSIZE, 10);
->initSetting($this, self::SETTING_MAPLIMIT_PLAYER, 1);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_MAPLIMIT_ADMIN, -1);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_BUFFERSIZE, 10);
// Permissions // Permissions
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_CLEAR_MAPQUEUE, AuthenticationManager::AUTH_LEVEL_MODERATOR);
->definePermissionLevel(self::SETTING_PERMISSION_CLEAR_MAPQUEUE, AuthenticationManager::AUTH_LEVEL_MODERATOR); $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_QUEUE_BUFFER, AuthenticationManager::AUTH_LEVEL_ADMIN);
$this->maniaControl->getAuthenticationManager()
->definePermissionLevel(self::SETTING_PERMISSION_QUEUE_BUFFER, AuthenticationManager::AUTH_LEVEL_ADMIN);
// Admin Commands // Admin Commands
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener(self::ADMIN_COMMAND_CLEAR_JUKEBOX, $this, 'command_ClearMapQueue', true, 'Clears the Map-Queue.');
->registerCommandListener(self::ADMIN_COMMAND_CLEAR_JUKEBOX, $this, 'command_ClearMapQueue', true, 'Clears the Map-Queue.'); $this->maniaControl->getCommandManager()->registerCommandListener(self::ADMIN_COMMAND_CLEAR_MAPQUEUE, $this, 'command_ClearMapQueue', true, 'Clears the Map-Queue.');
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener(array('jb', 'jukebox', 'mapqueue'), $this, 'command_MapQueue', false, 'Shows current maps in Map-Queue.');
->registerCommandListener(self::ADMIN_COMMAND_CLEAR_MAPQUEUE, $this, 'command_ClearMapQueue', true, 'Clears the Map-Queue.');
$this->maniaControl->getCommandManager()
->registerCommandListener(array('jb', 'jukebox', 'mapqueue'), $this, 'command_MapQueue', false, 'Shows current maps in Map-Queue.');
} }
/** /**
@ -101,8 +88,7 @@ class MapQueue implements CallbackListener, CommandListener {
* Add current map to buffer on startup * Add current map to buffer on startup
*/ */
public function handleAfterInit() { public function handleAfterInit() {
$currentMap = $this->maniaControl->getMapManager() $currentMap = $this->maniaControl->getMapManager()->getCurrentMap();
->getCurrentMap();
$this->buffer[] = $currentMap->uid; $this->buffer[] = $currentMap->uid;
} }
@ -122,34 +108,28 @@ class MapQueue implements CallbackListener, CommandListener {
* @param Player $admin * @param Player $admin
*/ */
public function clearMapQueue(Player $admin) { public function clearMapQueue(Player $admin) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)
->checkPermission($admin, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
->sendNotAllowed($admin);
return; return;
} }
if (empty($this->queuedMaps)) { if (empty($this->queuedMaps)) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('$fa0There are no maps in the jukebox!', $admin->login);
->sendError('$fa0There are no maps in the jukebox!', $admin->login);
return; return;
} }
$title = $this->maniaControl->getAuthenticationManager() $title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
->getAuthLevelName($admin->authLevel);
//Destroy map - queue list //Destroy map - queue list
$this->queuedMaps = array(); $this->queuedMaps = array();
$message = '$fa0' . $title . ' $<$fff' . $admin->nickname . '$> cleared the Map-Queue!'; $message = '$fa0' . $title . ' $<$fff' . $admin->nickname . '$> cleared the Map-Queue!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation($message);
->sendInformation($message);
Logger::logInfo($message, true); Logger::logInfo($message, true);
// Trigger callback // Trigger callback
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('clear'));
->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('clear'));
} }
/** /**
@ -189,8 +169,7 @@ class MapQueue implements CallbackListener, CommandListener {
*/ */
public function showMapQueue(Player $player) { public function showMapQueue(Player $player) {
if (empty($this->queuedMaps)) { if (empty($this->queuedMaps)) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('$fa0There are no maps in the jukebox!', $player->login);
->sendError('$fa0There are no maps in the jukebox!', $player->login);
return; return;
} }
@ -201,8 +180,7 @@ class MapQueue implements CallbackListener, CommandListener {
$index++; $index++;
} }
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation($message, $player);
->sendInformation($message, $player);
} }
/** /**
@ -212,8 +190,7 @@ class MapQueue implements CallbackListener, CommandListener {
*/ */
public function showMapQueueManialink(Player $player) { public function showMapQueueManialink(Player $player) {
if (empty($this->queuedMaps)) { if (empty($this->queuedMaps)) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('There are no Maps in the Jukebox!', $player);
->sendError('There are no Maps in the Jukebox!', $player);
return; return;
} }
@ -222,9 +199,7 @@ class MapQueue implements CallbackListener, CommandListener {
array_push($maps, $queuedMap[1]); array_push($maps, $queuedMap[1]);
} }
$this->maniaControl->getMapManager() $this->maniaControl->getMapManager()->getMapList()->showMapList($player, $maps);
->getMapList()
->showMapList($player, $maps);
} }
/** /**
@ -259,15 +234,13 @@ class MapQueue implements CallbackListener, CommandListener {
* @param string $uid * @param string $uid
*/ */
public function addMapToMapQueue($login, $uid) { public function addMapToMapQueue($login, $uid) {
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($login);
->getPlayer($login);
if (!$player) { if (!$player) {
return; return;
} }
//Check if player is allowed to add (another) map //Check if player is allowed to add (another) map
$isModerator = $this->maniaControl->getAuthenticationManager() $isModerator = $this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR);
->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$mapsForPlayer = 0; $mapsForPlayer = 0;
foreach ($this->queuedMaps as $queuedMap) { foreach ($this->queuedMaps as $queuedMap) {
@ -277,19 +250,15 @@ class MapQueue implements CallbackListener, CommandListener {
} }
if ($isModerator) { if ($isModerator) {
$maxAdmin = $this->maniaControl->getSettingManager() $maxAdmin = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAPLIMIT_ADMIN);
->getSettingValue($this, self::SETTING_MAPLIMIT_ADMIN);
if ($maxAdmin >= 0 && $mapsForPlayer >= $maxAdmin) { if ($maxAdmin >= 0 && $mapsForPlayer >= $maxAdmin) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('You already have $<$fff' . $maxAdmin . '$> map(s) in the Map-Queue!', $login);
->sendError('You already have $<$fff' . $maxAdmin . '$> map(s) in the Map-Queue!', $login);
return; return;
} }
} else { } else {
$maxPlayer = $this->maniaControl->getSettingManager() $maxPlayer = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAPLIMIT_PLAYER);
->getSettingValue($this, self::SETTING_MAPLIMIT_PLAYER);
if ($maxPlayer >= 0 && $mapsForPlayer >= $maxPlayer) { if ($maxPlayer >= 0 && $mapsForPlayer >= $maxPlayer) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('You already have $<$fff' . $maxPlayer . '$> map(s) in the Map-Queue!', $login);
->sendError('You already have $<$fff' . $maxPlayer . '$> map(s) in the Map-Queue!', $login);
return; return;
} }
} }
@ -301,36 +270,30 @@ class MapQueue implements CallbackListener, CommandListener {
$uid = $map->uid; $uid = $map->uid;
} }
if (array_key_exists($uid, $this->queuedMaps)) { if (array_key_exists($uid, $this->queuedMaps)) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('That map is already in the Map-Queue!', $login);
->sendError('That map is already in the Map-Queue!', $login);
return; return;
} }
//TODO recently maps not able to add to queue-amps setting, and management //TODO recently maps not able to add to queue-amps setting, and management
// Check if map is in the buffer // Check if map is in the buffer
if (in_array($uid, $this->buffer)) { if (in_array($uid, $this->buffer)) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('That map has recently been played!', $login);
->sendError('That map has recently been played!', $login); if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)
if (!$this->maniaControl->getAuthenticationManager()
->checkPermission($player, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)
) { ) {
return; return;
} }
} }
if (!$map) { if (!$map) {
$map = $this->maniaControl->getMapManager() $map = $this->maniaControl->getMapManager()->getMapByUid($uid);
->getMapByUid($uid);
} }
$this->queuedMaps[$uid] = array($player, $map); $this->queuedMaps[$uid] = array($player, $map);
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation('$fa0$<$fff' . $map->name . '$> has been added to the Map-Queue by $<$fff' . $player->nickname . '$>.');
->sendInformation('$fa0$<$fff' . $map->name . '$> has been added to the Map-Queue by $<$fff' . $player->nickname . '$>.');
// Trigger callback // Trigger callback
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('add', $this->queuedMaps[$uid]));
->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('add', $this->queuedMaps[$uid]));
} }
/** /**
@ -347,12 +310,10 @@ class MapQueue implements CallbackListener, CommandListener {
$map = $this->queuedMaps[$uid][1]; $map = $this->queuedMaps[$uid][1];
unset($this->queuedMaps[$uid]); unset($this->queuedMaps[$uid]);
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation('$fa0$<$fff' . $map->name . '$> is removed from the Map-Queue by $<$fff' . $player->nickname . '$>.');
->sendInformation('$fa0$<$fff' . $map->name . '$> is removed from the Map-Queue by $<$fff' . $player->nickname . '$>.');
// Trigger callback // Trigger callback
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('remove', $map));
->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('remove', $map));
} }
/** /**
@ -368,8 +329,7 @@ class MapQueue implements CallbackListener, CommandListener {
} }
$this->nextMap = null; $this->nextMap = null;
if ($this->maniaControl->getSettingManager() if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SKIP_MAP_ON_LEAVE)
->getSettingValue($this, self::SETTING_SKIP_MAP_ON_LEAVE)
) { ) {
// Skip Map if requester has left // Skip Map if requester has left
foreach ($this->queuedMaps as $queuedMap) { foreach ($this->queuedMaps as $queuedMap) {
@ -381,14 +341,12 @@ class MapQueue implements CallbackListener, CommandListener {
} }
// Player found, so play this map // Player found, so play this map
if ($this->maniaControl->getPlayerManager() if ($this->maniaControl->getPlayerManager()->getPlayer($player->login)
->getPlayer($player->login)
) { ) {
break; break;
} }
if (!$this->maniaControl->getSettingManager() if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SKIP_MAPQUEUE_ADMIN)
->getSettingValue($this, self::SETTING_SKIP_MAPQUEUE_ADMIN)
) { ) {
//Check if the queuer is a admin //Check if the queuer is a admin
if ($player->authLevel > 0) { if ($player->authLevel > 0) {
@ -397,14 +355,12 @@ class MapQueue implements CallbackListener, CommandListener {
} }
// Trigger callback // Trigger callback
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('skip', $queuedMap[0]));
->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('skip', $queuedMap[0]));
// Player not found, so remove the map from the mapqueue // Player not found, so remove the map from the mapqueue
array_shift($this->queuedMaps); array_shift($this->queuedMaps);
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation('$fa0$<$fff' . $queuedMap[0]->name . '$> is skipped because $<' . $player->nickname . '$> left the game!');
->sendInformation('$fa0$<$fff' . $queuedMap[0]->name . '$> is skipped because $<' . $player->nickname . '$> left the game!');
} }
} }
@ -416,12 +372,10 @@ class MapQueue implements CallbackListener, CommandListener {
} }
$map = $this->nextMap[1]; $map = $this->nextMap[1];
/** @var Map $map */ /** @var Map $map */
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation('$fa0Next map will be $<$fff' . $map->name . '$> as requested by $<' . $this->nextMap[0]->nickname . '$>.');
->sendInformation('$fa0Next map will be $<$fff' . $map->name . '$> as requested by $<' . $this->nextMap[0]->nickname . '$>.');
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->setNextMapIdent($map->uid);
->setNextMapIdent($map->uid);
} catch (NextMapException $e) { } catch (NextMapException $e) {
} catch (NotInListException $e) { } catch (NotInListException $e) {
} }
@ -437,8 +391,7 @@ class MapQueue implements CallbackListener, CommandListener {
return; return;
} }
if (count($this->buffer) >= $this->maniaControl->getSettingManager() if (count($this->buffer) >= $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_BUFFERSIZE)
->getSettingValue($this, self::SETTING_BUFFERSIZE)
) { ) {
array_shift($this->buffer); array_shift($this->buffer);
} }

View File

@ -313,9 +313,7 @@ class Player {
* @return mixed * @return mixed
*/ */
public function getPlayerData($object, $dataName, $serverIndex = -1) { public function getPlayerData($object, $dataName, $serverIndex = -1) {
return $this->maniaControl->getPlayerManager() return $this->maniaControl->getPlayerManager()->getPlayerDataManager()->getPlayerData($object, $dataName, $this, $serverIndex);
->getPlayerDataManager()
->getPlayerData($object, $dataName, $this, $serverIndex);
} }
/** /**
@ -328,9 +326,7 @@ class Player {
* @return bool * @return bool
*/ */
public function setPlayerData($object, $dataName, $value, $serverIndex = -1) { public function setPlayerData($object, $dataName, $value, $serverIndex = -1) {
return $this->maniaControl->getPlayerManager() return $this->maniaControl->getPlayerManager()->getPlayerDataManager()->setPlayerData($object, $dataName, $this, $value, $serverIndex);
->getPlayerDataManager()
->setPlayerData($object, $dataName, $this, $value, $serverIndex);
} }
/** /**

View File

@ -63,20 +63,13 @@ class PlayerActions {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Permissions // Permissions
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_BAN_PLAYER, AuthenticationManager::AUTH_LEVEL_ADMIN);
->definePermissionLevel(self::SETTING_PERMISSION_BAN_PLAYER, AuthenticationManager::AUTH_LEVEL_ADMIN); $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_KICK_PLAYER, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_WARN_PLAYER, AuthenticationManager::AUTH_LEVEL_MODERATOR);
->definePermissionLevel(self::SETTING_PERMISSION_KICK_PLAYER, AuthenticationManager::AUTH_LEVEL_MODERATOR); $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_MUTE_PLAYER, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_FORCE_PLAYER_PLAY, AuthenticationManager::AUTH_LEVEL_MODERATOR);
->definePermissionLevel(self::SETTING_PERMISSION_WARN_PLAYER, AuthenticationManager::AUTH_LEVEL_MODERATOR); $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_FORCE_PLAYER_TEAM, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_FORCE_PLAYER_SPEC, AuthenticationManager::AUTH_LEVEL_MODERATOR);
->definePermissionLevel(self::SETTING_PERMISSION_MUTE_PLAYER, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->getAuthenticationManager()
->definePermissionLevel(self::SETTING_PERMISSION_FORCE_PLAYER_PLAY, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->getAuthenticationManager()
->definePermissionLevel(self::SETTING_PERMISSION_FORCE_PLAYER_TEAM, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->getAuthenticationManager()
->definePermissionLevel(self::SETTING_PERMISSION_FORCE_PLAYER_SPEC, AuthenticationManager::AUTH_LEVEL_MODERATOR);
} }
/** /**
@ -87,17 +80,13 @@ class PlayerActions {
* @param int $teamId * @param int $teamId
*/ */
public function forcePlayerToTeam($adminLogin, $targetLogin, $teamId) { public function forcePlayerToTeam($adminLogin, $targetLogin, $teamId) {
$admin = $this->maniaControl->getPlayerManager() $admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
->getPlayer($adminLogin); if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_TEAM)
if (!$this->maniaControl->getAuthenticationManager()
->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_TEAM)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
->sendNotAllowed($admin);
return; return;
} }
$target = $this->maniaControl->getPlayerManager() $target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
->getPlayer($targetLogin);
if (!$target || !$admin) { if (!$target || !$admin) {
return; return;
} }
@ -108,14 +97,12 @@ class PlayerActions {
return; return;
} }
} catch (FaultException $exception) { } catch (FaultException $exception) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendException($exception, $admin);
->sendException($exception, $admin);
} }
} }
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->forcePlayerTeam($target->login, $teamId);
->forcePlayerTeam($target->login, $teamId);
} catch (ServerOptionsException $exception) { } catch (ServerOptionsException $exception) {
$this->forcePlayerToPlay($adminLogin, $targetLogin); $this->forcePlayerToPlay($adminLogin, $targetLogin);
return; return;
@ -125,8 +112,7 @@ class PlayerActions {
} }
$chatMessage = false; $chatMessage = false;
$title = $this->maniaControl->getAuthenticationManager() $title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
->getAuthLevelName($admin->authLevel);
if ($teamId === self::TEAM_BLUE) { if ($teamId === self::TEAM_BLUE) {
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' forced ' . $target->getEscapedNickname() . ' into the Blue-Team!'; $chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' forced ' . $target->getEscapedNickname() . ' into the Blue-Team!';
} else if ($teamId === self::TEAM_RED) { } else if ($teamId === self::TEAM_RED) {
@ -135,8 +121,7 @@ class PlayerActions {
if (!$chatMessage) { if (!$chatMessage) {
return; return;
} }
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation($chatMessage);
->sendInformation($chatMessage);
Logger::logInfo($chatMessage, true); Logger::logInfo($chatMessage, true);
} }
@ -150,37 +135,29 @@ class PlayerActions {
* @return bool * @return bool
*/ */
public function forcePlayerToPlay($adminLogin, $targetLogin, $userIsAbleToSelect = true, $displayAnnouncement = true) { public function forcePlayerToPlay($adminLogin, $targetLogin, $userIsAbleToSelect = true, $displayAnnouncement = true) {
$admin = $this->maniaControl->getPlayerManager() $admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
->getPlayer($adminLogin); if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_PLAY)
if (!$this->maniaControl->getAuthenticationManager()
->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_PLAY)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
->sendNotAllowed($admin);
return false; return false;
} }
$target = $this->maniaControl->getPlayerManager() $target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
->getPlayer($targetLogin);
if (!$target) { if (!$target) {
return false; return false;
} }
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->forceSpectator($target->login, self::SPECTATOR_PLAYER);
->forceSpectator($target->login, self::SPECTATOR_PLAYER);
} catch (ServerOptionsException $exception) { } catch (ServerOptionsException $exception) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendException($exception, $admin);
->sendException($exception, $admin);
return false; return false;
} }
if ($userIsAbleToSelect) { if ($userIsAbleToSelect) {
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->forceSpectator($target->login, self::SPECTATOR_USER_SELECTABLE);
->forceSpectator($target->login, self::SPECTATOR_USER_SELECTABLE);
} catch (ServerOptionsException $exception) { } catch (ServerOptionsException $exception) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendException($exception, $admin);
->sendException($exception, $admin);
return false; return false;
} }
} }
@ -188,8 +165,7 @@ class PlayerActions {
// Announce force // Announce force
if ($displayAnnouncement) { if ($displayAnnouncement) {
$chatMessage = $admin->getEscapedNickname() . ' forced ' . $target->getEscapedNickname() . ' to Play!'; $chatMessage = $admin->getEscapedNickname() . ' forced ' . $target->getEscapedNickname() . ' to Play!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation($chatMessage);
->sendInformation($chatMessage);
} }
return true; return true;
@ -205,43 +181,34 @@ class PlayerActions {
*/ */
public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE, public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE,
$releaseSlot = true) { $releaseSlot = true) {
$admin = $this->maniaControl->getPlayerManager() $admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
->getPlayer($adminLogin); if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_SPEC)
if (!$this->maniaControl->getAuthenticationManager()
->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_SPEC)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
->sendNotAllowed($admin);
return; return;
} }
$target = $this->maniaControl->getPlayerManager() $target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
->getPlayer($targetLogin);
if (!$admin || !$target || $target->isSpectator) { if (!$admin || !$target || $target->isSpectator) {
return; return;
} }
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->forceSpectator($target->login, $spectatorState);
->forceSpectator($target->login, $spectatorState);
} catch (ServerOptionsException $exception) { } catch (ServerOptionsException $exception) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendException($exception, $admin->login);
->sendException($exception, $admin->login);
return; return;
} }
$title = $this->maniaControl->getAuthenticationManager() $title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
->getAuthLevelName($admin->authLevel);
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' forced ' . $target->getEscapedNickname() . ' to Spectator!'; $chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' forced ' . $target->getEscapedNickname() . ' to Spectator!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation($chatMessage);
->sendInformation($chatMessage);
Logger::logInfo($chatMessage, true); Logger::logInfo($chatMessage, true);
if ($releaseSlot) { if ($releaseSlot) {
// Free player slot // Free player slot
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->spectatorReleasePlayerSlot($target->login);
->spectatorReleasePlayerSlot($target->login);
} catch (PlayerStateException $e) { } catch (PlayerStateException $e) {
} catch (UnknownPlayerException $e) { } catch (UnknownPlayerException $e) {
} }
@ -255,37 +222,29 @@ class PlayerActions {
* @param string $targetLogin * @param string $targetLogin
*/ */
public function unMutePlayer($adminLogin, $targetLogin) { public function unMutePlayer($adminLogin, $targetLogin) {
$admin = $this->maniaControl->getPlayerManager() $admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
->getPlayer($adminLogin); if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_MUTE_PLAYER)
if (!$this->maniaControl->getAuthenticationManager()
->checkPermission($admin, self::SETTING_PERMISSION_MUTE_PLAYER)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
->sendNotAllowed($admin);
return; return;
} }
$target = $this->maniaControl->getPlayerManager() $target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
->getPlayer($targetLogin);
if (!$target) { if (!$target) {
return; return;
} }
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->unIgnore($targetLogin);
->unIgnore($targetLogin);
} catch (NotInListException $e) { } catch (NotInListException $e) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('Player is not ignored!');
->sendError('Player is not ignored!');
return; return;
} }
$title = $this->maniaControl->getAuthenticationManager() $title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
->getAuthLevelName($admin->authLevel);
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' un-muted ' . $target->getEscapedNickname() . '!'; $chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' un-muted ' . $target->getEscapedNickname() . '!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation($chatMessage);
->sendInformation($chatMessage);
Logger::logInfo($chatMessage, true); Logger::logInfo($chatMessage, true);
} }
@ -296,37 +255,29 @@ class PlayerActions {
* @param string $targetLogin * @param string $targetLogin
*/ */
public function mutePlayer($adminLogin, $targetLogin) { public function mutePlayer($adminLogin, $targetLogin) {
$admin = $this->maniaControl->getPlayerManager() $admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
->getPlayer($adminLogin); if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_MUTE_PLAYER)
if (!$this->maniaControl->getAuthenticationManager()
->checkPermission($admin, self::SETTING_PERMISSION_MUTE_PLAYER)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
->sendNotAllowed($admin);
return; return;
} }
$target = $this->maniaControl->getPlayerManager() $target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
->getPlayer($targetLogin);
if (!$target) { if (!$target) {
return; return;
} }
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->ignore($targetLogin);
->ignore($targetLogin);
} catch (AlreadyInListException $e) { } catch (AlreadyInListException $e) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError("Player already ignored!");
->sendError("Player already ignored!");
return; return;
} }
$title = $this->maniaControl->getAuthenticationManager() $title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
->getAuthLevelName($admin->authLevel);
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' muted ' . $target->getEscapedNickname() . '!'; $chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' muted ' . $target->getEscapedNickname() . '!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation($chatMessage);
->sendInformation($chatMessage);
Logger::logInfo($chatMessage, true); Logger::logInfo($chatMessage, true);
} }
@ -337,18 +288,14 @@ class PlayerActions {
* @param string $targetLogin * @param string $targetLogin
*/ */
public function warnPlayer($adminLogin, $targetLogin) { public function warnPlayer($adminLogin, $targetLogin) {
$admin = $this->maniaControl->getPlayerManager() $admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
->getPlayer($adminLogin); if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_WARN_PLAYER)
if (!$this->maniaControl->getAuthenticationManager()
->checkPermission($admin, self::SETTING_PERMISSION_WARN_PLAYER)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
->sendNotAllowed($admin);
return; return;
} }
$target = $this->maniaControl->getPlayerManager() $target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
->getPlayer($targetLogin);
if (!$target) { if (!$target) {
return; return;
@ -363,12 +310,8 @@ class PlayerActions {
// Build Manialink // Build Manialink
$width = 80; $width = 80;
$height = 50; $height = 50;
$quadStyle = $this->maniaControl->getManialinkManager() $quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowStyle();
->getStyleManager() $quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowSubStyle();
->getDefaultMainWindowStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultMainWindowSubStyle();
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID); $maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$frame = new Frame(); $frame = new Frame();
@ -412,15 +355,12 @@ class PlayerActions {
} }
// Display manialink // Display manialink
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $target);
->displayWidget($maniaLink, $target);
// Announce warning // Announce warning
$title = $this->maniaControl->getAuthenticationManager() $title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
->getAuthLevelName($admin->authLevel);
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' warned ' . $target->getEscapedNickname() . '!'; $chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' warned ' . $target->getEscapedNickname() . '!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation($chatMessage);
->sendInformation($chatMessage);
Logger::log($chatMessage, true); Logger::log($chatMessage, true);
} }
@ -432,41 +372,32 @@ class PlayerActions {
* @param string $message * @param string $message
*/ */
public function kickPlayer($adminLogin, $targetLogin, $message = '') { public function kickPlayer($adminLogin, $targetLogin, $message = '') {
$admin = $this->maniaControl->getPlayerManager() $admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
->getPlayer($adminLogin); if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_KICK_PLAYER)
if (!$this->maniaControl->getAuthenticationManager()
->checkPermission($admin, self::SETTING_PERMISSION_KICK_PLAYER)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
->sendNotAllowed($admin);
return; return;
} }
$target = $this->maniaControl->getPlayerManager() $target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
->getPlayer($targetLogin);
if (!$target) { if (!$target) {
return; return;
} }
try { try {
if ($target->isFakePlayer()) { if ($target->isFakePlayer()) {
$this->maniaControl->getClient() $this->maniaControl->getClient()->disconnectFakePlayer($target->login);
->disconnectFakePlayer($target->login);
} else { } else {
$this->maniaControl->getClient() $this->maniaControl->getClient()->kick($target->login, $message);
->kick($target->login, $message);
} }
} catch (UnknownPlayerException $e) { } catch (UnknownPlayerException $e) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendException($e, $admin);
->sendException($e, $admin);
return; return;
} }
// Announce kick // Announce kick
$title = $this->maniaControl->getAuthenticationManager() $title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
->getAuthLevelName($admin->authLevel);
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' kicked ' . $target->getEscapedNickname() . '!'; $chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' kicked ' . $target->getEscapedNickname() . '!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation($chatMessage);
->sendInformation($chatMessage);
Logger::logInfo($chatMessage, true); Logger::logInfo($chatMessage, true);
} }
@ -478,36 +409,28 @@ class PlayerActions {
* @param string $message * @param string $message
*/ */
public function banPlayer($adminLogin, $targetLogin, $message = '') { public function banPlayer($adminLogin, $targetLogin, $message = '') {
$admin = $this->maniaControl->getPlayerManager() $admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
->getPlayer($adminLogin); if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_BAN_PLAYER)
if (!$this->maniaControl->getAuthenticationManager()
->checkPermission($admin, self::SETTING_PERMISSION_BAN_PLAYER)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
->sendNotAllowed($admin);
return; return;
} }
$target = $this->maniaControl->getPlayerManager() $target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
->getPlayer($targetLogin);
if (!$target) { if (!$target) {
return; return;
} }
if ($target->isFakePlayer()) { if ($target->isFakePlayer()) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('It is not possible to Ban a bot', $admin);
->sendError('It is not possible to Ban a bot', $admin);
return; return;
} }
$this->maniaControl->getClient() $this->maniaControl->getClient()->ban($target->login, $message);
->ban($target->login, $message);
// Announce ban // Announce ban
$title = $this->maniaControl->getAuthenticationManager() $title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
->getAuthLevelName($admin->authLevel);
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' banned ' . $target->getEscapedNickname() . '!'; $chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' banned ' . $target->getEscapedNickname() . '!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation($chatMessage);
->sendInformation($chatMessage);
Logger::logInfo($chatMessage, true); Logger::logInfo($chatMessage, true);
} }
@ -519,46 +442,35 @@ class PlayerActions {
* @param int $authLevel * @param int $authLevel
*/ */
public function grandAuthLevel($adminLogin, $targetLogin, $authLevel) { public function grandAuthLevel($adminLogin, $targetLogin, $authLevel) {
$admin = $this->maniaControl->getPlayerManager() $admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
->getPlayer($adminLogin); $target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
$target = $this->maniaControl->getPlayerManager()
->getPlayer($targetLogin);
if (!$admin || !$target) { if (!$admin || !$target) {
return; return;
} }
$authLevelName = $this->maniaControl->getAuthenticationManager() $authLevelName = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($authLevel);
->getAuthLevelName($authLevel); if (!$this->maniaControl->getAuthenticationManager()->checkRight($admin, $authLevel + 1)
if (!$this->maniaControl->getAuthenticationManager()
->checkRight($admin, $authLevel + 1)
) { ) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError("You don't have the permission to add a {$authLevelName}!", $admin);
->sendError("You don't have the permission to add a {$authLevelName}!", $admin);
return; return;
} }
if ($this->maniaControl->getAuthenticationManager() if ($this->maniaControl->getAuthenticationManager()->checkRight($target, $authLevel)
->checkRight($target, $authLevel)
) { ) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError("This Player is already {$authLevelName}!", $admin);
->sendError("This Player is already {$authLevelName}!", $admin);
return; return;
} }
$success = $this->maniaControl->getAuthenticationManager() $success = $this->maniaControl->getAuthenticationManager()->grantAuthLevel($target, $authLevel);
->grantAuthLevel($target, $authLevel);
if (!$success) { if (!$success) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('Error occurred.', $admin);
->sendError('Error occurred.', $admin);
return; return;
} }
// Announce granting // Announce granting
$title = $this->maniaControl->getAuthenticationManager() $title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
->getAuthLevelName($admin->authLevel);
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' added ' . $target->getEscapedNickname() . ' as $< ' . $authLevelName . '$>!'; $chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' added ' . $target->getEscapedNickname() . ' as $< ' . $authLevelName . '$>!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation($chatMessage);
->sendInformation($chatMessage);
Logger::logInfo($chatMessage, true); Logger::logInfo($chatMessage, true);
} }
@ -569,46 +481,35 @@ class PlayerActions {
* @param string $targetLogin * @param string $targetLogin
*/ */
public function revokeAuthLevel($adminLogin, $targetLogin) { public function revokeAuthLevel($adminLogin, $targetLogin) {
$admin = $this->maniaControl->getPlayerManager() $admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
->getPlayer($adminLogin); $target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
$target = $this->maniaControl->getPlayerManager()
->getPlayer($targetLogin);
if (!$admin || !$target) { if (!$admin || !$target) {
return; return;
} }
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkRight($admin, $target->authLevel + 1)
->checkRight($admin, $target->authLevel + 1)
) { ) {
$title = $this->maniaControl->getAuthenticationManager() $title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($target->authLevel);
->getAuthLevelName($target->authLevel); $this->maniaControl->getChat()->sendError("You can't revoke the Rights of a {$title}!", $admin);
$this->maniaControl->getChat()
->sendError("You can't revoke the Rights of a {$title}!", $admin);
return; return;
} }
if ($this->maniaControl->getAuthenticationManager() if ($this->maniaControl->getAuthenticationManager()->checkRight($target, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)
->checkRight($target, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)
) { ) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError("MasterAdmins can't be removed!", $admin);
->sendError("MasterAdmins can't be removed!", $admin);
return; return;
} }
$success = $this->maniaControl->getAuthenticationManager() $success = $this->maniaControl->getAuthenticationManager()->grantAuthLevel($target, AuthenticationManager::AUTH_LEVEL_PLAYER);
->grantAuthLevel($target, AuthenticationManager::AUTH_LEVEL_PLAYER);
if (!$success) { if (!$success) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('Error occurred.', $admin);
->sendError('Error occurred.', $admin);
return; return;
} }
// Announce revoke // Announce revoke
$title = $this->maniaControl->getAuthenticationManager() $title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
->getAuthLevelName($admin->authLevel);
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' revoked the Rights of ' . $target->getEscapedNickname() . '!'; $chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' revoked the Rights of ' . $target->getEscapedNickname() . '!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation($chatMessage);
->sendInformation($chatMessage);
Logger::logInfo($chatMessage, true); Logger::logInfo($chatMessage, true);
} }
@ -619,8 +520,7 @@ class PlayerActions {
* @return bool * @return bool
*/ */
public function isPlayerMuted($login) { public function isPlayerMuted($login) {
$ignoreList = $this->maniaControl->getClient() $ignoreList = $this->maniaControl->getClient()->getIgnoreList(100, 0);
->getIgnoreList(100, 0);
foreach ($ignoreList as $ignoredPlayers) { foreach ($ignoreList as $ignoredPlayers) {
if ($ignoredPlayers->login === $login) { if ($ignoredPlayers->login === $login) {
return true; return true;

View File

@ -44,51 +44,34 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Admin commands // Admin commands
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener(array('balance', 'teambalance', 'autoteambalance'), $this, 'command_TeamBalance', true, 'Balances the teams.');
->registerCommandListener(array('balance', 'teambalance', 'autoteambalance'), $this, 'command_TeamBalance', true, 'Balances the teams.'); $this->maniaControl->getCommandManager()->registerCommandListener('kick', $this, 'command_Kick', true, 'Kicks player from the server.');
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener('ban', $this, 'command_Ban', true, 'Bans player from the server.');
->registerCommandListener('kick', $this, 'command_Kick', true, 'Kicks player from the server.'); $this->maniaControl->getCommandManager()->registerCommandListener(array('forcespec', 'forcespectator'), $this, 'command_ForceSpectator', true, 'Forces player into spectator.');
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener('forceplay', $this, 'command_ForcePlay', true, 'Forces player into Play mode.');
->registerCommandListener('ban', $this, 'command_Ban', true, 'Bans player from the server.'); $this->maniaControl->getCommandManager()->registerCommandListener('forceblue', $this, 'command_ForceBlue', true, 'Forces player into blue team.');
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener('forcered', $this, 'command_ForceRed', true, 'Forces player into red team.');
->registerCommandListener(array('forcespec', 'forcespectator'), $this, 'command_ForceSpectator', true, 'Forces player into spectator.'); $this->maniaControl->getCommandManager()->registerCommandListener(array('addbots', 'addbot'), $this, 'command_AddFakePlayers', true, 'Adds bots to the game.');
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener(array('removebot', 'removebots'), $this, 'command_RemoveFakePlayers', true, 'Removes bots from the game.');
->registerCommandListener('forceplay', $this, 'command_ForcePlay', true, 'Forces player into Play mode.'); $this->maniaControl->getCommandManager()->registerCommandListener('mute', $this, 'command_MutePlayer', true, 'Mutes a player (prevents player from chatting).');
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener('unmute', $this, 'command_UnmutePlayer', true, 'Unmute a player (enables player to chat again).');
->registerCommandListener('forceblue', $this, 'command_ForceBlue', true, 'Forces player into blue team.');
$this->maniaControl->getCommandManager()
->registerCommandListener('forcered', $this, 'command_ForceRed', true, 'Forces player into red team.');
$this->maniaControl->getCommandManager()
->registerCommandListener(array('addbots', 'addbot'), $this, 'command_AddFakePlayers', true, 'Adds bots to the game.');
$this->maniaControl->getCommandManager()
->registerCommandListener(array('removebot', 'removebots'), $this, 'command_RemoveFakePlayers', true, 'Removes bots from the game.');
$this->maniaControl->getCommandManager()
->registerCommandListener('mute', $this, 'command_MutePlayer', true, 'Mutes a player (prevents player from chatting).');
$this->maniaControl->getCommandManager()
->registerCommandListener('unmute', $this, 'command_UnmutePlayer', true, 'Unmute a player (enables player to chat again).');
// Player commands // Player commands
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener(array('player', 'players'), $this, 'command_playerList', false, 'Shows players currently on the server.');
->registerCommandListener(array('player', 'players'), $this, 'command_playerList', false, 'Shows players currently on the server.');
// Permissions // Permissions
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_ADD_BOT, AuthenticationManager::AUTH_LEVEL_MODERATOR);
->definePermissionLevel(self::SETTING_PERMISSION_ADD_BOT, AuthenticationManager::AUTH_LEVEL_MODERATOR); $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_TEAM_BALANCE, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->getAuthenticationManager()
->definePermissionLevel(self::SETTING_PERMISSION_TEAM_BALANCE, AuthenticationManager::AUTH_LEVEL_MODERATOR);
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(Server::CB_TEAM_MODE_CHANGED, $this, 'teamStatusChanged');
->registerCallbackListener(Server::CB_TEAM_MODE_CHANGED, $this, 'teamStatusChanged');
// Action Open PlayerList // Action Open PlayerList
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_OPEN_PLAYERLIST, $this, 'command_playerList');
->registerManialinkPageAnswerListener(self::ACTION_OPEN_PLAYERLIST, $this, 'command_playerList');
$itemQuad = new Quad_UIConstruction_Buttons(); $itemQuad = new Quad_UIConstruction_Buttons();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Author); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_Author);
$itemQuad->setAction(self::ACTION_OPEN_PLAYERLIST); $itemQuad->setAction(self::ACTION_OPEN_PLAYERLIST);
$this->maniaControl->getActionsMenu() $this->maniaControl->getActionsMenu()->addMenuItem($itemQuad, true, 15, 'Open PlayerList');
->addMenuItem($itemQuad, true, 15, 'Open PlayerList');
} }
/** /**
@ -100,13 +83,11 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
//Add Balance Team Icon if it's a teamMode //Add Balance Team Icon if it's a teamMode
if ($teamMode) { if ($teamMode) {
// Action Balance Teams // Action Balance Teams
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_BALANCE_TEAMS, $this, 'command_TeamBalance');
->registerManialinkPageAnswerListener(self::ACTION_BALANCE_TEAMS, $this, 'command_TeamBalance');
$itemQuad = new Quad_Icons128x32_1(); $itemQuad = new Quad_Icons128x32_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_RT_Team); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_RT_Team);
$itemQuad->setAction(self::ACTION_BALANCE_TEAMS); $itemQuad->setAction(self::ACTION_BALANCE_TEAMS);
$this->maniaControl->getActionsMenu() $this->maniaControl->getActionsMenu()->addMenuItem($itemQuad, false, 40, 'Balance Teams');
->addMenuItem($itemQuad, false, 40, 'Balance Teams');
} }
} }
@ -117,25 +98,20 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
* @param Player $player * @param Player $player
*/ */
public function command_TeamBalance(array $chatCallback, Player $player) { public function command_TeamBalance(array $chatCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_TEAM_BALANCE)
->checkPermission($player, self::SETTING_PERMISSION_TEAM_BALANCE)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->autoTeamBalance();
->autoTeamBalance();
} catch (GameModeException $exception) { } catch (GameModeException $exception) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendException($exception, $player);
->sendException($exception, $player);
return; return;
} }
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation($player->getEscapedNickname() . ' balanced Teams!');
->sendInformation($player->getEscapedNickname() . ' balanced Teams!');
} }
/** /**
@ -145,17 +121,14 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
* @param Player $player * @param Player $player
*/ */
public function command_Kick(array $chat, Player $player) { public function command_Kick(array $chat, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_KICK_PLAYER)
->checkPermission($player, PlayerActions::SETTING_PERMISSION_KICK_PLAYER)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chat[1][2], 3); $params = explode(' ', $chat[1][2], 3);
if (count($params) <= 1) { if (count($params) <= 1) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendUsageInfo("No Login given! Example: '//kick login'", $player->login);
->sendUsageInfo("No Login given! Example: '//kick login'", $player->login);
return; return;
} }
$targetLogin = $params[1]; $targetLogin = $params[1];
@ -163,9 +136,7 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
if (isset($params[2])) { if (isset($params[2])) {
$message = $params[2]; $message = $params[2];
} }
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerActions()->kickPlayer($player->login, $targetLogin, $message);
->getPlayerActions()
->kickPlayer($player->login, $targetLogin, $message);
} }
/** /**
@ -175,17 +146,14 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
* @param Player $player * @param Player $player
*/ */
public function command_Ban(array $chat, Player $player) { public function command_Ban(array $chat, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_BAN_PLAYER)
->checkPermission($player, PlayerActions::SETTING_PERMISSION_BAN_PLAYER)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chat[1][2], 3); $params = explode(' ', $chat[1][2], 3);
if (count($params) <= 1) { if (count($params) <= 1) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendUsageInfo("No Login given! Example: '//ban login'", $player->login);
->sendUsageInfo("No Login given! Example: '//ban login'", $player->login);
return; return;
} }
$targetLogin = $params[1]; $targetLogin = $params[1];
@ -193,9 +161,7 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
if (isset($params[2])) { if (isset($params[2])) {
$message = $params[2]; $message = $params[2];
} }
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerActions()->banPlayer($player->login, $targetLogin, $message);
->getPlayerActions()
->banPlayer($player->login, $targetLogin, $message);
} }
/** /**
@ -207,14 +173,11 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
public function command_Warn(array $chatCallback, Player $player) { public function command_Warn(array $chatCallback, Player $player) {
$params = explode(' ', $chatCallback[1][2], 3); $params = explode(' ', $chatCallback[1][2], 3);
if (count($params) <= 1) { if (count($params) <= 1) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendUsageInfo("No Login given! Example: '//warn login'", $player->login);
->sendUsageInfo("No Login given! Example: '//warn login'", $player->login);
return; return;
} }
$targetLogin = $params[1]; $targetLogin = $params[1];
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerActions()->warnPlayer($player->login, $targetLogin);
->getPlayerActions()
->warnPlayer($player->login, $targetLogin);
} }
/** /**
@ -224,30 +187,23 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
* @param Player $player * @param Player $player
*/ */
public function command_ForceSpectator(array $chat, Player $player) { public function command_ForceSpectator(array $chat, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_SPEC)
->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_SPEC)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chat[1][2]); $params = explode(' ', $chat[1][2]);
if (count($params) <= 1) { if (count($params) <= 1) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendUsageInfo("No Login given! Example: '//forcespec login'", $player->login);
->sendUsageInfo("No Login given! Example: '//forcespec login'", $player->login);
return; return;
} }
$targetLogin = $params[1]; $targetLogin = $params[1];
if (isset($params[2]) && is_numeric($params[2])) { if (isset($params[2]) && is_numeric($params[2])) {
$type = (int)$params[2]; $type = (int)$params[2];
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToSpectator($player->login, $targetLogin, $type);
->getPlayerActions()
->forcePlayerToSpectator($player->login, $targetLogin, $type);
} else { } else {
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToSpectator($player->login, $targetLogin);
->getPlayerActions()
->forcePlayerToSpectator($player->login, $targetLogin);
} }
} }
@ -258,17 +214,14 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
* @param Player $player * @param Player $player
*/ */
public function command_ForcePlay(array $chat, Player $player) { public function command_ForcePlay(array $chat, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_PLAY)
->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_PLAY)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chat[1][2]); $params = explode(' ', $chat[1][2]);
if (!isset($params[1])) { if (!isset($params[1])) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendUsageInfo("No Login given! Example: '//forceplay login'", $player->login);
->sendUsageInfo("No Login given! Example: '//forceplay login'", $player->login);
return; return;
} }
$targetLogin = $params[1]; $targetLogin = $params[1];
@ -279,9 +232,7 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
} }
$selectable = ($type === 2); $selectable = ($type === 2);
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToPlay($player->login, $targetLogin, $selectable);
->getPlayerActions()
->forcePlayerToPlay($player->login, $targetLogin, $selectable);
} }
/** /**
@ -291,24 +242,19 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
* @param Player $player * @param Player $player
*/ */
public function command_ForceBlue(array $chat, Player $player) { public function command_ForceBlue(array $chat, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_TEAM)
->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_TEAM)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chat[1][2]); $params = explode(' ', $chat[1][2]);
if (!isset($params[1])) { if (!isset($params[1])) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendUsageInfo("No Login given! Example: '//forceblue login'", $player->login);
->sendUsageInfo("No Login given! Example: '//forceblue login'", $player->login);
return; return;
} }
$targetLogin = $params[1]; $targetLogin = $params[1];
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToTeam($player->login, $targetLogin, PlayerActions::TEAM_BLUE);
->getPlayerActions()
->forcePlayerToTeam($player->login, $targetLogin, PlayerActions::TEAM_BLUE);
} }
/** /**
@ -318,24 +264,19 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
* @param Player $player * @param Player $player
*/ */
public function command_ForceRed(array $chat, Player $player) { public function command_ForceRed(array $chat, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_TEAM)
->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_TEAM)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chat[1][2]); $params = explode(' ', $chat[1][2]);
if (!isset($params[1])) { if (!isset($params[1])) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendUsageInfo("No Login given! Example: '//forcered login'", $player->login);
->sendUsageInfo("No Login given! Example: '//forcered login'", $player->login);
return; return;
} }
$targetLogin = $params[1]; $targetLogin = $params[1];
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToTeam($player->login, $targetLogin, PlayerActions::TEAM_RED);
->getPlayerActions()
->forcePlayerToTeam($player->login, $targetLogin, PlayerActions::TEAM_RED);
} }
/** /**
@ -345,11 +286,9 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
* @param Player $player * @param Player $player
*/ */
public function command_AddFakePlayers(array $chatCallback, Player $player) { public function command_AddFakePlayers(array $chatCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_ADD_BOT)
->checkPermission($player, self::SETTING_PERMISSION_ADD_BOT)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$amount = 1; $amount = 1;
@ -360,14 +299,11 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
try { try {
for ($i = 0; $i < $amount; $i++) { for ($i = 0; $i < $amount; $i++) {
$this->maniaControl->getClient() $this->maniaControl->getClient()->connectFakePlayer();
->connectFakePlayer();
} }
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess('Fake players connected!', $player);
->sendSuccess('Fake players connected!', $player);
} catch (UnavailableFeatureException $e) { } catch (UnavailableFeatureException $e) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess('Error while connecting a Fake-Player.', $player);
->sendSuccess('Error while connecting a Fake-Player.', $player);
} }
} }
@ -378,17 +314,13 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
* @param Player $player * @param Player $player
*/ */
public function command_RemoveFakePlayers(array $chatCallback, Player $player) { public function command_RemoveFakePlayers(array $chatCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_ADD_BOT)
->checkPermission($player, self::SETTING_PERMISSION_ADD_BOT)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$this->maniaControl->getClient() $this->maniaControl->getClient()->disconnectFakePlayer('*');
->disconnectFakePlayer('*'); $this->maniaControl->getChat()->sendSuccess('Fake players disconnected!', $player);
$this->maniaControl->getChat()
->sendSuccess('Fake players disconnected!', $player);
} }
/** /**
@ -400,14 +332,11 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
public function command_MutePlayer(array $chatCallback, Player $admin) { public function command_MutePlayer(array $chatCallback, Player $admin) {
$commandParts = explode(' ', $chatCallback[1][2]); $commandParts = explode(' ', $chatCallback[1][2]);
if (count($commandParts) <= 1) { if (count($commandParts) <= 1) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendUsageInfo("No login specified! Example: '//mute login'", $admin);
->sendUsageInfo("No login specified! Example: '//mute login'", $admin);
return; return;
} }
$targetLogin = $commandParts[1]; $targetLogin = $commandParts[1];
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerActions()->mutePlayer($admin->login, $targetLogin);
->getPlayerActions()
->mutePlayer($admin->login, $targetLogin);
} }
/** /**
@ -419,14 +348,11 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
public function command_UnmutePlayer(array $chatCallback, Player $admin) { public function command_UnmutePlayer(array $chatCallback, Player $admin) {
$commandParts = explode(' ', $chatCallback[1][2]); $commandParts = explode(' ', $chatCallback[1][2]);
if (count($commandParts) <= 1) { if (count($commandParts) <= 1) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendUsageInfo("No login specified! Example: '//unmute login'", $admin);
->sendUsageInfo("No login specified! Example: '//unmute login'", $admin);
return; return;
} }
$targetLogin = $commandParts[1]; $targetLogin = $commandParts[1];
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerActions()->unMutePlayer($admin->login, $targetLogin);
->getPlayerActions()
->unMutePlayer($admin->login, $targetLogin);
} }
/** /**
@ -436,11 +362,7 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
* @param Player $player * @param Player $player
*/ */
public function command_playerList(array $chatCallback, Player $player) { public function command_playerList(array $chatCallback, Player $player) {
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerList()->addPlayerToShownList($player, PlayerList::SHOWN_MAIN_WINDOW);
->getPlayerList() $this->maniaControl->getPlayerManager()->getPlayerList()->showPlayerList($player);
->addPlayerToShownList($player, PlayerList::SHOWN_MAIN_WINDOW);
$this->maniaControl->getPlayerManager()
->getPlayerList()
->showPlayerList($player);
} }
} }

View File

@ -50,8 +50,7 @@ class PlayerDataManager {
* @return bool * @return bool
*/ */
private function initTables() { private function initTables() {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$defaultType = "'" . self::TYPE_STRING . "'"; $defaultType = "'" . self::TYPE_STRING . "'";
$typeSet = $defaultType . ",'" . self::TYPE_INT . "','" . self::TYPE_REAL . "','" . self::TYPE_BOOL . "','" . self::TYPE_ARRAY . "'"; $typeSet = $defaultType . ",'" . self::TYPE_INT . "','" . self::TYPE_REAL . "','" . self::TYPE_BOOL . "','" . self::TYPE_ARRAY . "'";
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_PLAYERDATAMETADATA . "` ( $query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_PLAYERDATAMETADATA . "` (
@ -104,8 +103,7 @@ class PlayerDataManager {
* Store Meta Data from the Database in the Ram * Store Meta Data from the Database in the Ram
*/ */
private function storeMetaData() { private function storeMetaData() {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$query = "SELECT * FROM `" . self::TABLE_PLAYERDATAMETADATA . "`;"; $query = "SELECT * FROM `" . self::TABLE_PLAYERDATAMETADATA . "`;";
$result = $mysqli->query($query); $result = $mysqli->query($query);
@ -139,8 +137,7 @@ class PlayerDataManager {
* @return bool * @return bool
*/ */
public function defineMetaData($object, $dataName, $default, $dataDescription = '') { public function defineMetaData($object, $dataName, $default, $dataDescription = '') {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$className = ClassUtil::getClass($object); $className = ClassUtil::getClass($object);
$query = "INSERT INTO `" . self::TABLE_PLAYERDATAMETADATA . "` ( $query = "INSERT INTO `" . self::TABLE_PLAYERDATAMETADATA . "` (
@ -218,8 +215,7 @@ class PlayerDataManager {
return $this->storedData[$player->index][$meta->dataId]; return $this->storedData[$player->index][$meta->dataId];
} }
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$dataQuery = "SELECT `value` FROM `" . self::TABLE_PLAYERDATA . "` $dataQuery = "SELECT `value` FROM `" . self::TABLE_PLAYERDATA . "`
WHERE `dataId` = ? WHERE `dataId` = ?
AND `playerId` = ? AND `playerId` = ?
@ -275,8 +271,7 @@ class PlayerDataManager {
return false; return false;
} }
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$query = "INSERT INTO `" . self::TABLE_PLAYERDATA . "` ( $query = "INSERT INTO `" . self::TABLE_PLAYERDATA . "` (
`serverIndex`, `serverIndex`,
`playerId`, `playerId`,

View File

@ -42,18 +42,10 @@ class PlayerDetailed {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Settings // Settings
$this->width = $this->maniaControl->getManialinkManager() $this->width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
->getStyleManager() $this->height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
->getListWidgetsWidth(); $this->quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowStyle();
$this->height = $this->maniaControl->getManialinkManager() $this->quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowSubStyle();
->getStyleManager()
->getListWidgetsHeight();
$this->quadStyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultMainWindowStyle();
$this->quadSubstyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultMainWindowSubStyle();
} }
/** /**
@ -64,17 +56,14 @@ class PlayerDetailed {
*/ */
public function showPlayerDetailed(Player $player, $targetLogin) { public function showPlayerDetailed(Player $player, $targetLogin) {
/** @var Player $target */ /** @var Player $target */
$target = $this->maniaControl->getPlayerManager() $target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
->getPlayer($targetLogin);
// Create ManiaLink // Create ManiaLink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID); $maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$script = $maniaLink->getScript(); $script = $maniaLink->getScript();
// Main frame // Main frame
$frame = $this->maniaControl->getManialinkManager() $frame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultListFrame($script);
->getStyleManager()
->getDefaultListFrame($script);
$maniaLink->add($frame); $maniaLink->add($frame);
// Create script and features // Create script and features
@ -179,8 +168,7 @@ class PlayerDetailed {
$label = clone $mainLabel; $label = clone $mainLabel;
$frame->add($label); $frame->add($label);
$label->setY($posY); $label->setY($posY);
$label->setText($this->maniaControl->getAuthenticationManager() $label->setText($this->maniaControl->getAuthenticationManager()->getAuthLevelName($target->authLevel));
->getAuthLevelName($target->authLevel));
//LadderRank //LadderRank
$posY -= 5; $posY -= 5;
@ -224,8 +212,7 @@ class PlayerDetailed {
$quad->setAction(PlayerCommands::ACTION_OPEN_PLAYERLIST); $quad->setAction(PlayerCommands::ACTION_OPEN_PLAYERLIST);
// render and display xml // render and display xml
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'PlayerDetailed');
->displayWidget($maniaLink, $player, 'PlayerDetailed');
} }
/** /**
@ -237,8 +224,7 @@ class PlayerDetailed {
public function statisticsFrame(Player $player) { public function statisticsFrame(Player $player) {
$frame = new Frame(); $frame = new Frame();
$playerStats = $this->maniaControl->getStatisticManager() $playerStats = $this->maniaControl->getStatisticManager()->getAllPlayerStats($player);
->getAllPlayerStats($player);
$posY = $this->height / 2 - 15; $posY = $this->height / 2 - 15;
$posX = -$this->width / 2 + 52; $posX = -$this->width / 2 + 52;
$index = 1; $index = 1;

View File

@ -74,24 +74,16 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Callbacks // Callbacks
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_CLOSE_PLAYER_ADV, $this, 'closePlayerAdvancedWidget');
->registerManialinkPageAnswerListener(self::ACTION_CLOSE_PLAYER_ADV, $this, 'closePlayerAdvancedWidget'); $this->maniaControl->getCallbackManager()->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget'); $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
// Update Widget Events // Update Widget Events
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERINFOCHANGED, $this, 'updateWidget');
->registerCallbackListener(PlayerManager::CB_PLAYERINFOCHANGED, $this, 'updateWidget'); $this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'updateWidget');
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'updateWidget');
->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'updateWidget'); $this->maniaControl->getCallbackManager()->registerCallbackListener(AuthenticationManager::CB_AUTH_LEVEL_CHANGED, $this, 'updateWidget');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'updateWidget');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(AuthenticationManager::CB_AUTH_LEVEL_CHANGED, $this, 'updateWidget');
} }
/** /**
@ -143,16 +135,11 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
* @param Player $player * @param Player $player
*/ */
public function showPlayerList(Player $player) { public function showPlayerList(Player $player) {
$width = $this->maniaControl->getManialinkManager() $width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
->getStyleManager() $height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
->getListWidgetsWidth();
$height = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getListWidgetsHeight();
// get PlayerList // get PlayerList
$players = $this->maniaControl->getPlayerManager() $players = $this->maniaControl->getPlayerManager()->getPlayers();
->getPlayers();
//create manialink //create manialink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID); $maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
@ -161,9 +148,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$script->addFeature($paging); $script->addFeature($paging);
// Main frame // Main frame
$frame = $this->maniaControl->getManialinkManager() $frame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultListFrame($script, $paging);
->getStyleManager()
->getDefaultListFrame($script, $paging);
$maniaLink->add($frame); $maniaLink->add($frame);
// Start offsets // Start offsets
@ -171,9 +156,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$posY = $height / 2; $posY = $height / 2;
// Predefine Description Label // Predefine Description Label
$descriptionLabel = $this->maniaControl->getManialinkManager() $descriptionLabel = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultDescriptionLabel();
->getStyleManager()
->getDefaultDescriptionLabel();
$frame->add($descriptionLabel); $frame->add($descriptionLabel);
// Headline // Headline
@ -181,13 +164,11 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$frame->add($headFrame); $frame->add($headFrame);
$headFrame->setY($posY - 5); $headFrame->setY($posY - 5);
$labelLineArray = array('Id' => $posX + 5, 'Nickname' => $posX + 18, 'Login' => $posX + 70, 'Location' => $posX + 101); $labelLineArray = array('Id' => $posX + 5, 'Nickname' => $posX + 18, 'Login' => $posX + 70, 'Location' => $posX + 101);
if ($this->maniaControl->getAuthenticationManager() if ($this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)
->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)
) { ) {
$labelLineArray['Actions'] = $posX + 135; $labelLineArray['Actions'] = $posX + 135;
} }
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->labelLine($headFrame, $labelLineArray);
->labelLine($headFrame, $labelLineArray);
$index = 1; $index = 1;
$posY = $height / 2 - 10; $posY = $height / 2 - 10;
@ -215,8 +196,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
} }
$array = array($index => $posX + 5, $listPlayer->nickname => $posX + 18, $listPlayer->login => $posX + 70, $path => $posX + 101); $array = array($index => $posX + 5, $listPlayer->nickname => $posX + 18, $listPlayer->login => $posX + 70, $path => $posX + 101);
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->labelLine($playerFrame, $array);
->labelLine($playerFrame, $array);
$playerFrame->setY($posY); $playerFrame->setY($posY);
@ -282,13 +262,11 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$playerFrame->add($rightLabel); $playerFrame->add($rightLabel);
$rightLabel->setX($posX + 13.9); $rightLabel->setX($posX + 13.9);
$rightLabel->setZ(3.1); $rightLabel->setZ(3.1);
$rightLabel->setText($this->maniaControl->getAuthenticationManager() $rightLabel->setText($this->maniaControl->getAuthenticationManager()->getAuthLevelAbbreviation($listPlayer->authLevel));
->getAuthLevelAbbreviation($listPlayer->authLevel));
$rightLabel->setTextSize(0.8); $rightLabel->setTextSize(0.8);
$rightLabel->setTextColor('fff'); $rightLabel->setTextColor('fff');
$description = $this->maniaControl->getAuthenticationManager() $description = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($listPlayer) . ' ' . $listPlayer->nickname;
->getAuthLevelName($listPlayer) . ' ' . $listPlayer->nickname;
$rightLabel->addTooltipLabelFeature($descriptionLabel, $description); $rightLabel->addTooltipLabelFeature($descriptionLabel, $description);
// Player Statistics // Player Statistics
@ -326,8 +304,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$description = 'View Player Profile of $<' . $listPlayer->nickname . '$>'; $description = 'View Player Profile of $<' . $listPlayer->nickname . '$>';
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description); $playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
if ($this->maniaControl->getAuthenticationManager() if ($this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)
->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)
) { ) {
// Further Player actions Quad // Further Player actions Quad
$playerQuad = new Quad_Icons64x64_1(); $playerQuad = new Quad_Icons64x64_1();
@ -343,11 +320,9 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description); $playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
} }
if ($this->maniaControl->getServer() if ($this->maniaControl->getServer()->isTeamMode()
->isTeamMode()
) { ) {
if ($this->maniaControl->getAuthenticationManager() if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_TEAM)
->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_TEAM)
) { ) {
// Force to Red-Team Quad // Force to Red-Team Quad
$redQuad = new Quad_Emblems(); $redQuad = new Quad_Emblems();
@ -375,8 +350,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$description = 'Force $<' . $listPlayer->nickname . '$> to Blue Team!'; $description = 'Force $<' . $listPlayer->nickname . '$> to Blue Team!';
$blueQuad->addTooltipLabelFeature($descriptionLabel, $description); $blueQuad->addTooltipLabelFeature($descriptionLabel, $description);
} else if ($this->maniaControl->getPluginManager() } else if ($this->maniaControl->getPluginManager()->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)
->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)
) { ) {
// Kick Player Vote // Kick Player Vote
$kickQuad = new Quad_UIConstruction_Buttons(); $kickQuad = new Quad_UIConstruction_Buttons();
@ -391,8 +365,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$kickQuad->addTooltipLabelFeature($descriptionLabel, $description); $kickQuad->addTooltipLabelFeature($descriptionLabel, $description);
} }
} else { } else {
if ($this->maniaControl->getAuthenticationManager() if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_PLAY)
->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_PLAY)
) { ) {
// Force to Play // Force to Play
$playQuad = new Quad_Emblems(); $playQuad = new Quad_Emblems();
@ -408,8 +381,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
} }
} }
if ($this->maniaControl->getAuthenticationManager() if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_SPEC)
->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_SPEC)
) { ) {
// Force to Spectator Quad // Force to Spectator Quad
$spectatorQuad = new Quad_BgRaceScore2(); $spectatorQuad = new Quad_BgRaceScore2();
@ -423,8 +395,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
// Force to Spectator Description Label // Force to Spectator Description Label
$description = 'Force $<' . $listPlayer->nickname . '$> to Spectator!'; $description = 'Force $<' . $listPlayer->nickname . '$> to Spectator!';
$spectatorQuad->addTooltipLabelFeature($descriptionLabel, $description); $spectatorQuad->addTooltipLabelFeature($descriptionLabel, $description);
} else if ($this->maniaControl->getPluginManager() } else if ($this->maniaControl->getPluginManager()->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)
->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)
) { ) {
// Force to Spectator Quad // Force to Spectator Quad
$spectatorQuad = new Quad_BgRaceScore2(); $spectatorQuad = new Quad_BgRaceScore2();
@ -452,8 +423,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
} }
// Render and display xml // Render and display xml
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'PlayerList');
->displayWidget($maniaLink, $player, 'PlayerList');
} }
/** /**
@ -464,20 +434,11 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
* @return Frame * @return Frame
*/ */
public function showAdvancedPlayerWidget(Player $admin, $login) { public function showAdvancedPlayerWidget(Player $admin, $login) {
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($login);
->getPlayer($login); $width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
$width = $this->maniaControl->getManialinkManager() $height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
->getStyleManager() $quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowStyle();
->getListWidgetsWidth(); $quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowSubStyle();
$height = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getListWidgetsHeight();
$quadStyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultMainWindowStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultMainWindowSubStyle();
//Settings //Settings
$posX = $width / 2 + 2.5; $posX = $width / 2 + 2.5;
@ -554,9 +515,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$label->setTextSize($textSize); $label->setTextSize($textSize);
$label->setTextColor($textColor); $label->setTextColor($textColor);
if (!$this->maniaControl->getPlayerManager() if (!$this->maniaControl->getPlayerManager()->getPlayerActions()->isPlayerMuted($login)
->getPlayerActions()
->isPlayerMuted($login)
) { ) {
$label->setText('Mute'); $label->setText('Mute');
$quad->setAction(self::ACTION_MUTE_PLAYER . '.' . $login); $quad->setAction(self::ACTION_MUTE_PLAYER . '.' . $login);
@ -645,8 +604,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$label->setTextColor($textColor); $label->setTextColor($textColor);
if ($player->authLevel > 0 if ($player->authLevel > 0
&& $this->maniaControl->getAuthenticationManager() && $this->maniaControl->getAuthenticationManager()->checkRight($admin, $player->authLevel + 1)
->checkRight($admin, $player->authLevel + 1)
) { ) {
$posY -= 5; $posY -= 5;
// Revoke Rights // Revoke Rights
@ -684,119 +642,79 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
switch ($action) { switch ($action) {
case self::ACTION_SPECTATE_PLAYER: case self::ACTION_SPECTATE_PLAYER:
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->forceSpectator($adminLogin, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
->forceSpectator($adminLogin, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE); $this->maniaControl->getClient()->forceSpectatorTarget($adminLogin, $targetLogin, 1);
$this->maniaControl->getClient()
->forceSpectatorTarget($adminLogin, $targetLogin, 1);
} catch (PlayerStateException $e) { } catch (PlayerStateException $e) {
} }
break; break;
case self::ACTION_OPEN_PLAYER_DETAILED: case self::ACTION_OPEN_PLAYER_DETAILED:
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
->getPlayer($adminLogin); $this->maniaControl->getPlayerManager()->getPlayerDetailed()->showPlayerDetailed($player, $targetLogin);
$this->maniaControl->getPlayerManager()
->getPlayerDetailed()
->showPlayerDetailed($player, $targetLogin);
unset($this->playersListShown[$player->login]); unset($this->playersListShown[$player->login]);
break; break;
case self::ACTION_FORCE_BLUE: case self::ACTION_FORCE_BLUE:
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToTeam($adminLogin, $targetLogin, PlayerActions::TEAM_BLUE);
->getPlayerActions()
->forcePlayerToTeam($adminLogin, $targetLogin, PlayerActions::TEAM_BLUE);
break; break;
case self::ACTION_FORCE_RED: case self::ACTION_FORCE_RED:
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToTeam($adminLogin, $targetLogin, PlayerActions::TEAM_RED);
->getPlayerActions()
->forcePlayerToTeam($adminLogin, $targetLogin, PlayerActions::TEAM_RED);
break; break;
case self::ACTION_FORCE_SPEC: case self::ACTION_FORCE_SPEC:
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToSpectator($adminLogin, $targetLogin, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
->getPlayerActions()
->forcePlayerToSpectator($adminLogin, $targetLogin, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
break; break;
case self::ACTION_FORCE_PLAY: case self::ACTION_FORCE_PLAY:
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToPlay($adminLogin, $targetLogin);
->getPlayerActions()
->forcePlayerToPlay($adminLogin, $targetLogin);
break; break;
case self::ACTION_MUTE_PLAYER: case self::ACTION_MUTE_PLAYER:
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerActions()->mutePlayer($adminLogin, $targetLogin);
->getPlayerActions() $this->showPlayerList($this->maniaControl->getPlayerManager()->getPlayer($adminLogin));
->mutePlayer($adminLogin, $targetLogin);
$this->showPlayerList($this->maniaControl->getPlayerManager()
->getPlayer($adminLogin));
break; break;
case self::ACTION_UNMUTE_PLAYER: case self::ACTION_UNMUTE_PLAYER:
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerActions()->unMutePlayer($adminLogin, $targetLogin);
->getPlayerActions() $this->showPlayerList($this->maniaControl->getPlayerManager()->getPlayer($adminLogin));
->unMutePlayer($adminLogin, $targetLogin);
$this->showPlayerList($this->maniaControl->getPlayerManager()
->getPlayer($adminLogin));
break; break;
case self::ACTION_WARN_PLAYER: case self::ACTION_WARN_PLAYER:
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerActions()->warnPlayer($adminLogin, $targetLogin);
->getPlayerActions()
->warnPlayer($adminLogin, $targetLogin);
break; break;
case self::ACTION_KICK_PLAYER: case self::ACTION_KICK_PLAYER:
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerActions()->kickPlayer($adminLogin, $targetLogin);
->getPlayerActions()
->kickPlayer($adminLogin, $targetLogin);
break; break;
case self::ACTION_BAN_PLAYER: case self::ACTION_BAN_PLAYER:
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerActions()->banPlayer($adminLogin, $targetLogin);
->getPlayerActions()
->banPlayer($adminLogin, $targetLogin);
break; break;
case self::ACTION_PLAYER_ADV: case self::ACTION_PLAYER_ADV:
$admin = $this->maniaControl->getPlayerManager() $admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
->getPlayer($adminLogin);
$this->advancedPlayerWidget($admin, $targetLogin); $this->advancedPlayerWidget($admin, $targetLogin);
break; break;
case self::ACTION_ADD_AS_MASTER: case self::ACTION_ADD_AS_MASTER:
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerActions()->grandAuthLevel($adminLogin, $targetLogin, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
->getPlayerActions()
->grandAuthLevel($adminLogin, $targetLogin, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
break; break;
case self::ACTION_ADD_AS_ADMIN: case self::ACTION_ADD_AS_ADMIN:
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerActions()->grandAuthLevel($adminLogin, $targetLogin, AuthenticationManager::AUTH_LEVEL_ADMIN);
->getPlayerActions()
->grandAuthLevel($adminLogin, $targetLogin, AuthenticationManager::AUTH_LEVEL_ADMIN);
break; break;
case self::ACTION_ADD_AS_MOD: case self::ACTION_ADD_AS_MOD:
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerActions()->grandAuthLevel($adminLogin, $targetLogin, AuthenticationManager::AUTH_LEVEL_MODERATOR);
->getPlayerActions()
->grandAuthLevel($adminLogin, $targetLogin, AuthenticationManager::AUTH_LEVEL_MODERATOR);
break; break;
case self::ACTION_REVOKE_RIGHTS: case self::ACTION_REVOKE_RIGHTS:
$this->maniaControl->getPlayerManager() $this->maniaControl->getPlayerManager()->getPlayerActions()->revokeAuthLevel($adminLogin, $targetLogin);
->getPlayerActions()
->revokeAuthLevel($adminLogin, $targetLogin);
break; break;
case self::ACTION_FORCE_SPEC_VOTE: case self::ACTION_FORCE_SPEC_VOTE:
/** @var $votesPlugin CustomVotesPlugin */ /** @var $votesPlugin CustomVotesPlugin */
$votesPlugin = $this->maniaControl->getPluginManager() $votesPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN);
->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN);
$admin = $this->maniaControl->getPlayerManager() $admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
->getPlayer($adminLogin); $target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
$target = $this->maniaControl->getPlayerManager()
->getPlayer($targetLogin);
$startMessage = $admin->getEscapedNickname() . '$s started a vote to force $<' . $target->nickname . '$> into spectator!'; $startMessage = $admin->getEscapedNickname() . '$s started a vote to force $<' . $target->nickname . '$> into spectator!';
$votesPlugin->defineVote('forcespec', 'Force ' . $target->getEscapedNickname() . ' Spec', true, $startMessage); $votesPlugin->defineVote('forcespec', 'Force ' . $target->getEscapedNickname() . ' Spec', true, $startMessage);
$votesPlugin->startVote($admin, 'forcespec', function ($result) use (&$votesPlugin, &$target) { $votesPlugin->startVote($admin, 'forcespec', function ($result) use (&$votesPlugin, &$target) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation('$sVote successful -> Player ' . $target->getEscapedNickname() . ' forced to Spectator!');
->sendInformation('$sVote successful -> Player ' . $target->getEscapedNickname() . ' forced to Spectator!');
$votesPlugin->undefineVote('forcespec'); $votesPlugin->undefineVote('forcespec');
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE); $this->maniaControl->getClient()->spectatorReleasePlayerSlot($target->login);
$this->maniaControl->getClient()
->spectatorReleasePlayerSlot($target->login);
} catch (PlayerStateException $e) { } catch (PlayerStateException $e) {
} catch (UnknownPlayerException $e) { } catch (UnknownPlayerException $e) {
} }
@ -804,13 +722,10 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
break; break;
case self::ACTION_KICK_PLAYER_VOTE: case self::ACTION_KICK_PLAYER_VOTE:
/** @var $votesPlugin CustomVotesPlugin */ /** @var $votesPlugin CustomVotesPlugin */
$votesPlugin = $this->maniaControl->getPluginManager() $votesPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN);
->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN);
$admin = $this->maniaControl->getPlayerManager() $admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
->getPlayer($adminLogin); $target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
$target = $this->maniaControl->getPlayerManager()
->getPlayer($targetLogin);
$startMessage = $admin->getEscapedNickname() . '$s started a vote to kick $<' . $target->nickname . '$>!'; $startMessage = $admin->getEscapedNickname() . '$s started a vote to kick $<' . $target->nickname . '$>!';
@ -818,14 +733,12 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$votesPlugin->defineVote('kick', 'Kick ' . $target->getEscapedNickname(), true, $startMessage); $votesPlugin->defineVote('kick', 'Kick ' . $target->getEscapedNickname(), true, $startMessage);
$votesPlugin->startVote($admin, 'kick', function ($result) use (&$votesPlugin, &$target) { $votesPlugin->startVote($admin, 'kick', function ($result) use (&$votesPlugin, &$target) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation('$sVote successful -> ' . $target->getEscapedNickname() . ' got Kicked!');
->sendInformation('$sVote successful -> ' . $target->getEscapedNickname() . ' got Kicked!');
$votesPlugin->undefineVote('kick'); $votesPlugin->undefineVote('kick');
$message = '$39F You got kicked due to a Public Vote!$z '; $message = '$39F You got kicked due to a Public Vote!$z ';
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->kick($target->login, $message);
->kick($target->login, $message);
} catch (UnknownPlayerException $e) { } catch (UnknownPlayerException $e) {
} }
}); });
@ -859,8 +772,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
} }
// Check if shown player still exists // Check if shown player still exists
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($login);
->getPlayer($login);
if (!$player) { if (!$player) {
unset($this->playersListShown[$login]); unset($this->playersListShown[$login]);
continue; continue;

View File

@ -80,24 +80,17 @@ class PlayerManager implements CallbackListener, TimerListener {
$this->adminLists = new AdminLists($maniaControl); $this->adminLists = new AdminLists($maniaControl);
// Settings // Settings
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES, true);
->initSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES, true);
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONINIT, $this, 'onInit');
->registerCallbackListener(Callbacks::ONINIT, $this, 'onInit'); $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERCONNECT, $this, 'playerConnect');
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this, 'playerDisconnect');
->registerCallbackListener(CallbackManager::CB_MP_PLAYERCONNECT, $this, 'playerConnect'); $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERINFOCHANGED, $this, 'playerInfoChanged');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this, 'playerDisconnect');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(CallbackManager::CB_MP_PLAYERINFOCHANGED, $this, 'playerInfoChanged');
// Player stats // Player stats
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_JOIN_COUNT);
->defineStatMetaData(self::STAT_JOIN_COUNT); $this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_SERVERTIME, StatisticManager::STAT_TYPE_TIME);
$this->maniaControl->getStatisticManager()
->defineStatMetaData(self::STAT_SERVERTIME, StatisticManager::STAT_TYPE_TIME);
} }
/** /**
@ -106,8 +99,7 @@ class PlayerManager implements CallbackListener, TimerListener {
* @return bool * @return bool
*/ */
private function initTables() { private function initTables() {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$playerTableQuery = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_PLAYERS . "` ( $playerTableQuery = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_PLAYERS . "` (
`index` int(11) NOT NULL AUTO_INCREMENT, `index` int(11) NOT NULL AUTO_INCREMENT,
`login` varchar(100) NOT NULL, `login` varchar(100) NOT NULL,
@ -192,23 +184,20 @@ class PlayerManager implements CallbackListener, TimerListener {
*/ */
public function onInit() { public function onInit() {
// Add all players // Add all players
$players = $this->maniaControl->getClient() $players = $this->maniaControl->getClient()->getPlayerList(300, 0, 2);
->getPlayerList(300, 0, 2);
foreach ($players as $playerItem) { foreach ($players as $playerItem) {
if ($playerItem->playerId <= 0) { if ($playerItem->playerId <= 0) {
continue; continue;
} }
try { try {
$detailedPlayerInfo = $this->maniaControl->getClient() $detailedPlayerInfo = $this->maniaControl->getClient()->getDetailedPlayerInfo($playerItem->login);
->getDetailedPlayerInfo($playerItem->login);
} catch (UnknownPlayerException $exception) { } catch (UnknownPlayerException $exception) {
continue; continue;
} }
// Check if the Player is in a Team, to notify if its a TeamMode or not // Check if the Player is in a Team, to notify if its a TeamMode or not
if ($playerItem->teamId >= 0) { if ($playerItem->teamId >= 0) {
$this->maniaControl->getServer() $this->maniaControl->getServer()->setTeamMode(true);
->setTeamMode(true);
} }
$player = new Player($this->maniaControl, true); $player = new Player($this->maniaControl, true);
@ -238,8 +227,7 @@ class PlayerManager implements CallbackListener, TimerListener {
* @return bool * @return bool
*/ */
private function savePlayer(Player &$player) { private function savePlayer(Player &$player) {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
// Save player // Save player
$playerQuery = "INSERT INTO `" . self::TABLE_PLAYERS . "` ( $playerQuery = "INSERT INTO `" . self::TABLE_PLAYERS . "` (
@ -298,8 +286,7 @@ class PlayerManager implements CallbackListener, TimerListener {
public function playerConnect(array $callback) { public function playerConnect(array $callback) {
$login = $callback[1][0]; $login = $callback[1][0];
try { try {
$playerInfo = $this->maniaControl->getClient() $playerInfo = $this->maniaControl->getClient()->getDetailedPlayerInfo($login);
->getDetailedPlayerInfo($login);
$player = new Player($this->maniaControl, true); $player = new Player($this->maniaControl, true);
$player->setDetailedInfo($playerInfo); $player->setDetailedInfo($playerInfo);
@ -321,11 +308,9 @@ class PlayerManager implements CallbackListener, TimerListener {
} }
// Trigger own callbacks // Trigger own callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_PLAYERDISCONNECT, $player);
->triggerCallback(self::CB_PLAYERDISCONNECT, $player);
if ($this->getPlayerCount(false) <= 0) { if ($this->getPlayerCount(false) <= 0) {
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_SERVER_EMPTY);
->triggerCallback(self::CB_SERVER_EMPTY);
} }
if ($player->isFakePlayer()) { if ($player->isFakePlayer()) {
@ -336,16 +321,13 @@ class PlayerManager implements CallbackListener, TimerListener {
$logMessage = "Player left: {$player->login} / {$player->nickname} Playtime: {$played}"; $logMessage = "Player left: {$player->login} / {$player->nickname} Playtime: {$played}";
Logger::logInfo($logMessage, true); Logger::logInfo($logMessage, true);
if ($this->maniaControl->getSettingManager() if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_JOIN_LEAVE_MESSAGES)
->getSettingValue($this, self::SETTING_JOIN_LEAVE_MESSAGES)
) { ) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendChat('$0f0$<$fff' . $player->nickname . '$> has left the game');
->sendChat('$0f0$<$fff' . $player->nickname . '$> has left the game');
} }
//Destroys stored PlayerData, after all Disconnect Callbacks got Handled //Destroys stored PlayerData, after all Disconnect Callbacks got Handled
$this->getPlayerDataManager() $this->getPlayerDataManager()->destroyPlayerData($player);
->destroyPlayerData($player);
} }
/** /**
@ -379,8 +361,7 @@ class PlayerManager implements CallbackListener, TimerListener {
} }
$playedTime = time() - $player->joinTime; $playedTime = time() - $player->joinTime;
return $this->maniaControl->getStatisticManager() return $this->maniaControl->getStatisticManager()->insertStat(self::STAT_SERVERTIME, $player, $this->maniaControl->getServer()->index, $playedTime);
->insertStat(self::STAT_SERVERTIME, $player, $this->maniaControl->getServer()->index, $playedTime);
} }
/** /**
@ -418,8 +399,7 @@ class PlayerManager implements CallbackListener, TimerListener {
//Check if the Player is in a Team, to notify if its a TeamMode or not //Check if the Player is in a Team, to notify if its a TeamMode or not
if ($player->teamId >= 0) { if ($player->teamId >= 0) {
$this->maniaControl->getServer() $this->maniaControl->getServer()->setTeamMode(true);
->setTeamMode(true);
} }
$prevJoinState = $player->hasJoinedGame; $prevJoinState = $player->hasJoinedGame;
@ -430,33 +410,27 @@ class PlayerManager implements CallbackListener, TimerListener {
//Check if Player finished joining the game //Check if Player finished joining the game
if ($player->hasJoinedGame && !$prevJoinState) { if ($player->hasJoinedGame && !$prevJoinState) {
if ($this->maniaControl->getSettingManager() if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_JOIN_LEAVE_MESSAGES)
->getSettingValue($this, self::SETTING_JOIN_LEAVE_MESSAGES)
&& !$player->isFakePlayer() && !$player->isFakePlayer()
) { ) {
$string = array(0 => '$0f0Player', 1 => '$0f0Moderator', 2 => '$0f0Admin', 3 => '$0f0SuperAdmin', 4 => '$0f0MasterAdmin'); $string = array(0 => '$0f0Player', 1 => '$0f0Moderator', 2 => '$0f0Admin', 3 => '$0f0SuperAdmin', 4 => '$0f0MasterAdmin');
$chatMessage = '$0f0' . $string[$player->authLevel] . ' $<$fff' . $player->nickname . '$> Nation: $<$fff' . $player->getCountry() . '$> joined!'; $chatMessage = '$0f0' . $string[$player->authLevel] . ' $<$fff' . $player->nickname . '$> Nation: $<$fff' . $player->getCountry() . '$> joined!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendChat($chatMessage);
->sendChat($chatMessage); $this->maniaControl->getChat()->sendInformation('This server uses ManiaControl v' . ManiaControl::VERSION . '!', $player->login);
$this->maniaControl->getChat()
->sendInformation('This server uses ManiaControl v' . ManiaControl::VERSION . '!', $player->login);
} }
$logMessage = "Player joined: {$player->login} / {$player->nickname} Nation: " . $player->getCountry() . " IP: {$player->ipAddress}"; $logMessage = "Player joined: {$player->login} / {$player->nickname} Nation: " . $player->getCountry() . " IP: {$player->ipAddress}";
Logger::logInfo($logMessage, true); Logger::logInfo($logMessage, true);
// Increment the Player Join Count // Increment the Player Join Count
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->incrementStat(self::STAT_JOIN_COUNT, $player, $this->maniaControl->getServer()->index);
->incrementStat(self::STAT_JOIN_COUNT, $player, $this->maniaControl->getServer()->index);
// Trigger own PlayerJoined callback // Trigger own PlayerJoined callback
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_PLAYERCONNECT, $player);
->triggerCallback(self::CB_PLAYERCONNECT, $player);
} }
// Trigger own callback // Trigger own callback
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_PLAYERINFOCHANGED, $player);
->triggerCallback(self::CB_PLAYERINFOCHANGED, $player);
} }
/** /**
@ -486,8 +460,7 @@ class PlayerManager implements CallbackListener, TimerListener {
* @return Player * @return Player
*/ */
private function getPlayerFromDatabaseByLogin($playerLogin) { private function getPlayerFromDatabaseByLogin($playerLogin) {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$query = "SELECT * FROM `" . self::TABLE_PLAYERS . "` $query = "SELECT * FROM `" . self::TABLE_PLAYERS . "`
WHERE `login` LIKE '" . $mysqli->escape_string($playerLogin) . "';"; WHERE `login` LIKE '" . $mysqli->escape_string($playerLogin) . "';";
@ -572,8 +545,7 @@ class PlayerManager implements CallbackListener, TimerListener {
return null; return null;
} }
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$query = "SELECT * FROM `" . self::TABLE_PLAYERS . "` $query = "SELECT * FROM `" . self::TABLE_PLAYERS . "`
WHERE `index` = {$playerIndex};"; WHERE `index` = {$playerIndex};";
$result = $mysqli->query($query); $result = $mysqli->query($query);

View File

@ -46,12 +46,10 @@ class InstallMenu implements ConfiguratorMenu, ManialinkPageAnswerListener {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Permissions // Permissions
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_INSTALL_PLUGINS, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
->definePermissionLevel(self::SETTING_PERMISSION_INSTALL_PLUGINS, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
// Callbacks // Callbacks
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_REFRESH_LIST, $this, 'handleRefreshListAction');
->registerManialinkPageAnswerListener(self::ACTION_REFRESH_LIST, $this, 'handleRefreshListAction');
} }
/** /**
@ -94,9 +92,7 @@ class InstallMenu implements ConfiguratorMenu, ManialinkPageAnswerListener {
// Pagers // Pagers
$pagerPrev = new Quad_Icons64x64_1(); $pagerPrev = new Quad_Icons64x64_1();
$frame->add($pagerPrev); $frame->add($pagerPrev);
$pagerPrev->setPosition($width * 0.39, $height * -0.44, 2) $pagerPrev->setPosition($width * 0.39, $height * -0.44, 2)->setSize($pagerSize, $pagerSize)->setSubStyle($pagerPrev::SUBSTYLE_ArrowPrev);
->setSize($pagerSize, $pagerSize)
->setSubStyle($pagerPrev::SUBSTYLE_ArrowPrev);
$pagerNext = clone $pagerPrev; $pagerNext = clone $pagerPrev;
$frame->add($pagerNext); $frame->add($pagerNext);
@ -104,31 +100,18 @@ class InstallMenu implements ConfiguratorMenu, ManialinkPageAnswerListener {
$pageCountLabel = new Label_Text(); $pageCountLabel = new Label_Text();
$frame->add($pageCountLabel); $frame->add($pageCountLabel);
$pageCountLabel->setHAlign($pageCountLabel::RIGHT) $pageCountLabel->setHAlign($pageCountLabel::RIGHT)->setPosition($width * 0.35, $height * -0.44, 1)->setStyle($pageCountLabel::STYLE_TextTitle1)->setTextSize(2);
->setPosition($width * 0.35, $height * -0.44, 1)
->setStyle($pageCountLabel::STYLE_TextTitle1)
->setTextSize(2);
$paging->addButton($pagerNext) $paging->addButton($pagerNext)->addButton($pagerPrev)->setLabel($pageCountLabel);
->addButton($pagerPrev)
->setLabel($pageCountLabel);
// Info tooltip // Info tooltip
$infoTooltipLabel = new Label(); $infoTooltipLabel = new Label();
$frame->add($infoTooltipLabel); $frame->add($infoTooltipLabel);
$infoTooltipLabel->setAlign($infoTooltipLabel::LEFT, $infoTooltipLabel::TOP) $infoTooltipLabel->setAlign($infoTooltipLabel::LEFT, $infoTooltipLabel::TOP)->setPosition($width * -0.45, $height * -0.22)->setSize($width * 0.7, $entryHeight)->setTextSize(1)->setTranslate(true)->setVisible(false)->setAutoNewLine(true)->setMaxLines(5);
->setPosition($width * -0.45, $height * -0.22)
->setSize($width * 0.7, $entryHeight)
->setTextSize(1)
->setTranslate(true)
->setVisible(false)
->setAutoNewLine(true)
->setMaxLines(5);
// List plugins // List plugins
foreach ($pluginList as $plugin) { foreach ($pluginList as $plugin) {
if ($this->maniaControl->getPluginManager() if ($this->maniaControl->getPluginManager()->isPluginIdInstalled($plugin->id)
->isPluginIdInstalled($plugin->id)
) { ) {
// Already installed -> Skip // Already installed -> Skip
continue; continue;
@ -148,12 +131,7 @@ class InstallMenu implements ConfiguratorMenu, ManialinkPageAnswerListener {
$nameLabel = new Label_Text(); $nameLabel = new Label_Text();
$pluginFrame->add($nameLabel); $pluginFrame->add($nameLabel);
$nameLabel->setHAlign($nameLabel::LEFT) $nameLabel->setHAlign($nameLabel::LEFT)->setX($width * -0.46)->setSize($width * 0.62, $entryHeight)->setStyle($nameLabel::STYLE_TextCardSmall)->setTextSize(2)->setText($plugin->name);
->setX($width * -0.46)
->setSize($width * 0.62, $entryHeight)
->setStyle($nameLabel::STYLE_TextCardSmall)
->setTextSize(2)
->setText($plugin->name);
$description = "Author: {$plugin->author}\nVersion: {$plugin->currentVersion->version}\nDesc: {$plugin->description}"; $description = "Author: {$plugin->author}\nVersion: {$plugin->currentVersion->version}\nDesc: {$plugin->description}";
$nameLabel->addTooltipLabelFeature($infoTooltipLabel, $description); $nameLabel->addTooltipLabelFeature($infoTooltipLabel, $description);
@ -162,11 +140,7 @@ class InstallMenu implements ConfiguratorMenu, ManialinkPageAnswerListener {
// Incompatibility label // Incompatibility label
$infoLabel = new Label_Text(); $infoLabel = new Label_Text();
$pluginFrame->add($infoLabel); $pluginFrame->add($infoLabel);
$infoLabel->setHAlign($infoLabel::RIGHT) $infoLabel->setHAlign($infoLabel::RIGHT)->setX($width * 0.47)->setSize($width * 0.33, $entryHeight)->setTextSize(1)->setTextColor('f30');
->setX($width * 0.47)
->setSize($width * 0.33, $entryHeight)
->setTextSize(1)
->setTextColor('f30');
if ($plugin->currentVersion->min_mc_version > ManiaControl::VERSION) { if ($plugin->currentVersion->min_mc_version > ManiaControl::VERSION) {
$infoLabel->setText("Needs at least MC-Version '{$plugin->currentVersion->min_mc_version}'"); $infoLabel->setText("Needs at least MC-Version '{$plugin->currentVersion->min_mc_version}'");
} else { } else {
@ -176,21 +150,14 @@ class InstallMenu implements ConfiguratorMenu, ManialinkPageAnswerListener {
// Install button // Install button
$installButton = new Label_Button(); $installButton = new Label_Button();
$pluginFrame->add($installButton); $pluginFrame->add($installButton);
$installButton->setHAlign($installButton::RIGHT) $installButton->setHAlign($installButton::RIGHT)->setX($width * 0.47)->setStyle($installButton::STYLE_CardButtonSmall)->setText('Install')->setTranslate(true)->setAction(self::ACTION_PREFIX_INSTALL_PLUGIN . $plugin->id);
->setX($width * 0.47)
->setStyle($installButton::STYLE_CardButtonSmall)
->setText('Install')
->setTranslate(true)
->setAction(self::ACTION_PREFIX_INSTALL_PLUGIN . $plugin->id);
} }
if ($plugin->currentVersion->verified > 0) { if ($plugin->currentVersion->verified > 0) {
// Suggested quad // Suggested quad
$suggestedQuad = new Quad_Icons64x64_1(); $suggestedQuad = new Quad_Icons64x64_1();
$pluginFrame->add($suggestedQuad); $pluginFrame->add($suggestedQuad);
$suggestedQuad->setPosition($width * 0.45, $entryHeight * 0.12, 2) $suggestedQuad->setPosition($width * 0.45, $entryHeight * 0.12, 2)->setSize(4, 4)->setSubStyle($suggestedQuad::SUBSTYLE_StateSuggested);
->setSize(4, 4)
->setSubStyle($suggestedQuad::SUBSTYLE_StateSuggested);
} }
$posY -= $entryHeight; $posY -= $entryHeight;
@ -211,19 +178,11 @@ class InstallMenu implements ConfiguratorMenu, ManialinkPageAnswerListener {
$infoLabel = new Label_Text(); $infoLabel = new Label_Text();
$frame->add($infoLabel); $frame->add($infoLabel);
$infoLabel->setVAlign($infoLabel::BOTTOM) $infoLabel->setVAlign($infoLabel::BOTTOM)->setY(2)->setSize(100, 25)->setTextColor('f30')->setTranslate(true)->setText('An error occurred. Please try again later.');
->setY(2)
->setSize(100, 25)
->setTextColor('f30')
->setTranslate(true)
->setText('An error occurred. Please try again later.');
$refreshQuad = new Quad_Icons64x64_1(); $refreshQuad = new Quad_Icons64x64_1();
$frame->add($refreshQuad); $frame->add($refreshQuad);
$refreshQuad->setY(-4) $refreshQuad->setY(-4)->setSize(8, 8)->setSubStyle($refreshQuad::SUBSTYLE_Refresh)->setAction(self::ACTION_REFRESH_LIST);
->setSize(8, 8)
->setSubStyle($refreshQuad::SUBSTYLE_Refresh)
->setAction(self::ACTION_REFRESH_LIST);
return $frame; return $frame;
} }
@ -238,10 +197,7 @@ class InstallMenu implements ConfiguratorMenu, ManialinkPageAnswerListener {
$infoLabel = new Label_Text(); $infoLabel = new Label_Text();
$frame->add($infoLabel); $frame->add($infoLabel);
$infoLabel->setSize(100, 50) $infoLabel->setSize(100, 50)->setTextColor('0f3')->setTranslate(true)->setText('No other plugins available.');
->setTextColor('0f3')
->setTranslate(true)
->setText('No other plugins available.');
return $frame; return $frame;
} }
@ -277,7 +233,6 @@ class InstallMenu implements ConfiguratorMenu, ManialinkPageAnswerListener {
* @param Player $player * @param Player $player
*/ */
public function handleRefreshListAction(array $actionCallback, Player $player) { public function handleRefreshListAction(array $actionCallback, Player $player) {
$this->maniaControl->getConfigurator() $this->maniaControl->getConfigurator()->showMenu($player, $this);
->showMenu($player, $this);
} }
} }

View File

@ -50,12 +50,10 @@ class PluginManager {
$this->initTables(); $this->initTables();
$this->pluginMenu = new PluginMenu($maniaControl); $this->pluginMenu = new PluginMenu($maniaControl);
$this->maniaControl->getConfigurator() $this->maniaControl->getConfigurator()->addMenu($this->pluginMenu);
->addMenu($this->pluginMenu);
$this->pluginInstallMenu = new InstallMenu($maniaControl); $this->pluginInstallMenu = new InstallMenu($maniaControl);
$this->maniaControl->getConfigurator() $this->maniaControl->getConfigurator()->addMenu($this->pluginInstallMenu);
->addMenu($this->pluginInstallMenu);
} }
/** /**
@ -64,8 +62,7 @@ class PluginManager {
* @return bool * @return bool
*/ */
private function initTables() { private function initTables() {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$pluginsTableQuery = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_PLUGINS . "` ( $pluginsTableQuery = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_PLUGINS . "` (
`index` int(11) NOT NULL AUTO_INCREMENT, `index` int(11) NOT NULL AUTO_INCREMENT,
`className` varchar(100) NOT NULL, `className` varchar(100) NOT NULL,
@ -145,28 +142,22 @@ class PluginManager {
$plugin->unload(); $plugin->unload();
if ($plugin instanceof CallbackListener) { if ($plugin instanceof CallbackListener) {
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->unregisterCallbackListener($plugin);
->unregisterCallbackListener($plugin); $this->maniaControl->getCallbackManager()->unregisterScriptCallbackListener($plugin);
$this->maniaControl->getCallbackManager()
->unregisterScriptCallbackListener($plugin);
} }
if ($plugin instanceof CommandListener) { if ($plugin instanceof CommandListener) {
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->unregisterCommandListener($plugin);
->unregisterCommandListener($plugin);
} }
if ($plugin instanceof ManialinkPageAnswerListener) { if ($plugin instanceof ManialinkPageAnswerListener) {
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->unregisterManialinkPageAnswerListener($plugin);
->unregisterManialinkPageAnswerListener($plugin);
} }
if ($plugin instanceof TimerListener) { if ($plugin instanceof TimerListener) {
$this->maniaControl->getTimerManager() $this->maniaControl->getTimerManager()->unregisterTimerListenings($plugin);
->unregisterTimerListenings($plugin);
} }
$this->savePluginStatus($pluginClass, false); $this->savePluginStatus($pluginClass, false);
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_PLUGIN_UNLOADED, $pluginClass, $plugin);
->triggerCallback(self::CB_PLUGIN_UNLOADED, $pluginClass, $plugin);
return true; return true;
} }
@ -204,8 +195,7 @@ class PluginManager {
* @return bool * @return bool
*/ */
private function savePluginStatus($className, $active) { private function savePluginStatus($className, $active) {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$pluginStatusQuery = "INSERT INTO `" . self::TABLE_PLUGINS . "` ( $pluginStatusQuery = "INSERT INTO `" . self::TABLE_PLUGINS . "` (
`className`, `className`,
`active` `active`
@ -349,8 +339,7 @@ class PluginManager {
* @return bool * @return bool
*/ */
public function getSavedPluginStatus($className) { public function getSavedPluginStatus($className) {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$pluginStatusQuery = "SELECT `active` FROM `" . self::TABLE_PLUGINS . "` $pluginStatusQuery = "SELECT `active` FROM `" . self::TABLE_PLUGINS . "`
WHERE `className` = ?;"; WHERE `className` = ?;";
$pluginStatement = $mysqli->prepare($pluginStatusQuery); $pluginStatement = $mysqli->prepare($pluginStatusQuery);
@ -401,8 +390,7 @@ class PluginManager {
$plugin->load($this->maniaControl); $plugin->load($this->maniaControl);
} catch (\Exception $e) { } catch (\Exception $e) {
$message = "Error during Plugin Activation of '{$pluginClass}': '{$e->getMessage()}'"; $message = "Error during Plugin Activation of '{$pluginClass}': '{$e->getMessage()}'";
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError($message, $adminLogin);
->sendError($message, $adminLogin);
Logger::logError($message); Logger::logError($message);
$this->savePluginStatus($pluginClass, false); $this->savePluginStatus($pluginClass, false);
return false; return false;
@ -411,8 +399,7 @@ class PluginManager {
$this->activePlugins[$pluginClass] = $plugin; $this->activePlugins[$pluginClass] = $plugin;
$this->savePluginStatus($pluginClass, true); $this->savePluginStatus($pluginClass, true);
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_PLUGIN_LOADED, $pluginClass, $plugin);
->triggerCallback(self::CB_PLUGIN_LOADED, $pluginClass, $plugin);
return true; return true;
} }
@ -487,8 +474,7 @@ class PluginManager {
*/ */
public function fetchPluginList(callable $function) { public function fetchPluginList(callable $function) {
$url = ManiaControl::URL_WEBSERVICE . 'plugins'; $url = ManiaControl::URL_WEBSERVICE . 'plugins';
$this->maniaControl->getFileReader() $this->maniaControl->getFileReader()->loadFile($url, function ($dataJson, $error) use (&$function) {
->loadFile($url, function ($dataJson, $error) use (&$function) {
$data = json_decode($dataJson); $data = json_decode($dataJson);
call_user_func($function, $data, $error); call_user_func($function, $data, $error);
}); });

View File

@ -61,14 +61,11 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer'); $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_BACK_TO_PLUGINS, $this, 'backToPlugins');
$this->maniaControl->getManialinkManager()
->registerManialinkPageAnswerListener(self::ACTION_BACK_TO_PLUGINS, $this, 'backToPlugins');
// Permissions // Permissions
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
} }
/** /**
@ -86,8 +83,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
*/ */
public function backToPlugins($callback, Player $player) { public function backToPlugins($callback, Player $player) {
$player->destroyCache($this, self::CACHE_SETTING_CLASS); $player->destroyCache($this, self::CACHE_SETTING_CLASS);
$this->maniaControl->getConfigurator() $this->maniaControl->getConfigurator()->showMenu($player, $this);
->showMenu($player, $this);
} }
/** /**
@ -98,8 +94,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$script->addFeature($paging); $script->addFeature($paging);
$frame = new Frame(); $frame = new Frame();
$pluginClasses = $this->maniaControl->getPluginManager() $pluginClasses = $this->maniaControl->getPluginManager()->getPluginClasses();
->getPluginClasses();
// Config // Config
$pagerSize = 9.; $pagerSize = 9.;
@ -140,9 +135,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
// Display normal Plugin List // Display normal Plugin List
// Plugin pages // Plugin pages
$posY = 0.; $posY = 0.;
$pluginUpdates = $this->maniaControl->getUpdateManager() $pluginUpdates = $this->maniaControl->getUpdateManager()->getPluginUpdateManager()->getPluginsUpdates();
->getPluginUpdateManager()
->getPluginsUpdates();
usort($pluginClasses, function ($pluginClassA, $pluginClassB) { usort($pluginClasses, function ($pluginClassA, $pluginClassB) {
/** @var Plugin $pluginClassA */ /** @var Plugin $pluginClassA */
@ -160,8 +153,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$posY = $height * 0.41; $posY = $height * 0.41;
} }
$active = $this->maniaControl->getPluginManager() $active = $this->maniaControl->getPluginManager()->isPluginActive($pluginClass);
->isPluginActive($pluginClass);
$pluginFrame = new Frame(); $pluginFrame = new Frame();
$pageFrame->add($pluginFrame); $pageFrame->add($pluginFrame);
@ -263,8 +255,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
*/ */
private function getPluginSettingsMenu(Frame $frame, $width, $height, Paging $paging, Player $player, $settingClass) { private function getPluginSettingsMenu(Frame $frame, $width, $height, Paging $paging, Player $player, $settingClass) {
// TODO: centralize menu code to use by mc settings and plugin settings // TODO: centralize menu code to use by mc settings and plugin settings
$settings = $this->maniaControl->getSettingManager() $settings = $this->maniaControl->getSettingManager()->getSettingsByClass($settingClass);
->getSettingsByClass($settingClass);
$pageSettingsMaxCount = 11; $pageSettingsMaxCount = 11;
$posY = 0; $posY = 0;
@ -357,8 +348,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
*/ */
public function handleManialinkPageAnswer(array $callback) { public function handleManialinkPageAnswer(array $callback) {
$login = $callback[1][1]; $login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($login);
->getPlayer($login);
if (!$player) { if (!$player) {
return; return;
} }
@ -374,28 +364,22 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
if ($enable) { if ($enable) {
$pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_ENABLEPLUGIN)); $pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_ENABLEPLUGIN));
/** @var Plugin $pluginClass */ /** @var Plugin $pluginClass */
$activated = $this->maniaControl->getPluginManager() $activated = $this->maniaControl->getPluginManager()->activatePlugin($pluginClass, $player->login);
->activatePlugin($pluginClass, $player->login);
if ($activated) { if ($activated) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess($pluginClass::getName() . ' activated!', $player);
->sendSuccess($pluginClass::getName() . ' activated!', $player);
Logger::logInfo("{$player->login} activated '{$pluginClass}'!", true); Logger::logInfo("{$player->login} activated '{$pluginClass}'!", true);
} else { } else {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('Error activating ' . $pluginClass::getName() . '!', $player);
->sendError('Error activating ' . $pluginClass::getName() . '!', $player);
} }
} else if ($disable) { } else if ($disable) {
$pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_DISABLEPLUGIN)); $pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_DISABLEPLUGIN));
/** @var Plugin $pluginClass */ /** @var Plugin $pluginClass */
$deactivated = $this->maniaControl->getPluginManager() $deactivated = $this->maniaControl->getPluginManager()->deactivatePlugin($pluginClass);
->deactivatePlugin($pluginClass);
if ($deactivated) { if ($deactivated) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess($pluginClass::getName() . ' deactivated!', $player);
->sendSuccess($pluginClass::getName() . ' deactivated!', $player);
Logger::logInfo("{$player->login} deactivated '{$pluginClass}'!", true); Logger::logInfo("{$player->login} deactivated '{$pluginClass}'!", true);
} else { } else {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('Error deactivating ' . $pluginClass::getName() . '!', $player);
->sendError('Error deactivating ' . $pluginClass::getName() . '!', $player);
} }
} else if ($settings) { } else if ($settings) {
// Open Settings Menu // Open Settings Menu
@ -404,19 +388,16 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
} }
// Reopen the Menu // Reopen the Menu
$this->maniaControl->getConfigurator() $this->maniaControl->getConfigurator()->showMenu($player, $this);
->showMenu($player, $this);
} }
/** /**
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData() * @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
*/ */
public function saveConfigData(array $configData, Player $player) { public function saveConfigData(array $configData, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS)
->checkPermission($player, self::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING) !== 0) { if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING) !== 0) {
@ -427,8 +408,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
foreach ($configData[3] as $settingData) { foreach ($configData[3] as $settingData) {
$settingIndex = (int)substr($settingData['Name'], $prefixLength); $settingIndex = (int)substr($settingData['Name'], $prefixLength);
$settingObject = $this->maniaControl->getSettingManager() $settingObject = $this->maniaControl->getSettingManager()->getSettingObjectByIndex($settingIndex);
->getSettingObjectByIndex($settingIndex);
if (!$settingObject) { if (!$settingObject) {
continue; continue;
} }
@ -438,15 +418,12 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
} }
$settingObject->value = $settingData['Value']; $settingObject->value = $settingData['Value'];
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->saveSetting($settingObject);
->saveSetting($settingObject);
} }
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess('Plugin Settings saved!', $player);
->sendSuccess('Plugin Settings saved!', $player);
// Reopen the Menu // Reopen the Menu
$this->maniaControl->getConfigurator() $this->maniaControl->getConfigurator()->showMenu($player, $this);
->showMenu($player, $this);
} }
} }

View File

@ -58,40 +58,25 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Callbacks // Callbacks
$this->maniaControl->getTimerManager() $this->maniaControl->getTimerManager()->registerTimerListening($this, 'each5Seconds', 5000);
->registerTimerListening($this, 'each5Seconds', 5000); $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONINIT, $this, 'handleOnInit');
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::WARMUPSTATUS, $this, 'handleWarmUpStatus');
->registerCallbackListener(Callbacks::ONINIT, $this, 'handleOnInit');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(Callbacks::WARMUPSTATUS, $this, 'handleWarmUpStatus');
// Chat commands // Chat commands
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener('setservername', $this, 'commandSetServerName', true, 'Sets the ServerName.');
->registerCommandListener('setservername', $this, 'commandSetServerName', true, 'Sets the ServerName.'); $this->maniaControl->getCommandManager()->registerCommandListener('setpwd', $this, 'commandSetPwd', true, 'Sets play password.');
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener('setspecpwd', $this, 'commandSetSpecPwd', true, 'Sets spectator password.');
->registerCommandListener('setpwd', $this, 'commandSetPwd', true, 'Sets play password.'); $this->maniaControl->getCommandManager()->registerCommandListener('setmaxplayers', $this, 'commandSetMaxPlayers', true, 'Sets the maximum number of players.');
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener('setmaxspectators', $this, 'commandSetMaxSpectators', true, 'Sets the maximum number of spectators.');
->registerCommandListener('setspecpwd', $this, 'commandSetSpecPwd', true, 'Sets spectator password.'); $this->maniaControl->getCommandManager()->registerCommandListener('shutdownserver', $this, 'commandShutdownServer', true, 'Shuts down the ManiaPlanet server.');
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener('systeminfo', $this, 'commandSystemInfo', true, 'Shows system information.');
->registerCommandListener('setmaxplayers', $this, 'commandSetMaxPlayers', true, 'Sets the maximum number of players.'); $this->maniaControl->getCommandManager()->registerCommandListener('cancel', $this, 'commandCancelVote', true, 'Cancels the current vote.');
$this->maniaControl->getCommandManager()
->registerCommandListener('setmaxspectators', $this, 'commandSetMaxSpectators', true, 'Sets the maximum number of spectators.');
$this->maniaControl->getCommandManager()
->registerCommandListener('shutdownserver', $this, 'commandShutdownServer', true, 'Shuts down the ManiaPlanet server.');
$this->maniaControl->getCommandManager()
->registerCommandListener('systeminfo', $this, 'commandSystemInfo', true, 'Shows system information.');
$this->maniaControl->getCommandManager()
->registerCommandListener('cancel', $this, 'commandCancelVote', true, 'Cancels the current vote.');
// Page actions // Page actions
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_SET_PAUSE, $this, 'setPause');
->registerManialinkPageAnswerListener(self::ACTION_SET_PAUSE, $this, 'setPause'); $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_EXTEND_WARMUP, $this, 'commandExtendWarmup');
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_END_WARMUP, $this, 'commandEndWarmup');
->registerManialinkPageAnswerListener(self::ACTION_EXTEND_WARMUP, $this, 'commandExtendWarmup'); $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_CANCEL_VOTE, $this, 'commandCancelVote');
$this->maniaControl->getManialinkManager()
->registerManialinkPageAnswerListener(self::ACTION_END_WARMUP, $this, 'commandEndWarmup');
$this->maniaControl->getManialinkManager()
->registerManialinkPageAnswerListener(self::ACTION_CANCEL_VOTE, $this, 'commandCancelVote');
} }
/** /**
@ -99,18 +84,12 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
*/ */
public function handleOnInit() { public function handleOnInit() {
// Permissions // Permissions
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_SHUTDOWN_SERVER, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
->definePermissionLevel(self::SETTING_PERMISSION_SHUTDOWN_SERVER, AuthenticationManager::AUTH_LEVEL_SUPERADMIN); $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_SHOW_SYSTEMINFO, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_SERVERSETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN);
->definePermissionLevel(self::SETTING_PERMISSION_SHOW_SYSTEMINFO, AuthenticationManager::AUTH_LEVEL_SUPERADMIN); $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_SET_PAUSE, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_CANCEL_VOTE, AuthenticationManager::AUTH_LEVEL_MODERATOR);
->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_SERVERSETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN); $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_HANDLE_WARMUP, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->getAuthenticationManager()
->definePermissionLevel(self::SETTING_PERMISSION_SET_PAUSE, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->getAuthenticationManager()
->definePermissionLevel(self::SETTING_PERMISSION_CANCEL_VOTE, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->getAuthenticationManager()
->definePermissionLevel(self::SETTING_PERMISSION_HANDLE_WARMUP, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->updateCancelVoteMenuItem(); $this->updateCancelVoteMenuItem();
$this->updateWarmUpMenuItems(); $this->updateWarmUpMenuItems();
@ -123,8 +102,7 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
$itemQuad = new Quad_Icons64x64_1(); $itemQuad = new Quad_Icons64x64_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ArrowRed); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_ArrowRed);
$itemQuad->setAction(self::ACTION_CANCEL_VOTE); $itemQuad->setAction(self::ACTION_CANCEL_VOTE);
$this->maniaControl->getActionsMenu() $this->maniaControl->getActionsMenu()->addMenuItem($itemQuad, false, 30, 'Cancel Vote');
->addMenuItem($itemQuad, false, 30, 'Cancel Vote');
} }
/** /**
@ -133,16 +111,14 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
private function updateWarmUpMenuItems() { private function updateWarmUpMenuItems() {
$pauseExists = false; $pauseExists = false;
try { try {
$scriptInfos = $this->maniaControl->getClient() $scriptInfos = $this->maniaControl->getClient()->getModeScriptInfo();
->getModeScriptInfo();
foreach ($scriptInfos->commandDescs as $param) { foreach ($scriptInfos->commandDescs as $param) {
if ($param->name === self::COMMAND_FORCE_WARMUP) { if ($param->name === self::COMMAND_FORCE_WARMUP) {
$pauseExists = true; $pauseExists = true;
break; break;
} }
} }
$this->maniaControl->getClient() $this->maniaControl->getClient()->triggerModeScriptEvent("WarmUp_GetStatus");
->triggerModeScriptEvent("WarmUp_GetStatus");
} catch (GameModeException $e) { } catch (GameModeException $e) {
} }
@ -151,8 +127,7 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
$itemQuad = new Quad_Icons128x32_1(); $itemQuad = new Quad_Icons128x32_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ManiaLinkSwitch); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_ManiaLinkSwitch);
$itemQuad->setAction(self::ACTION_SET_PAUSE); $itemQuad->setAction(self::ACTION_SET_PAUSE);
$this->maniaControl->getActionsMenu() $this->maniaControl->getActionsMenu()->addAdminMenuItem($itemQuad, 13, 'Pause the current game');
->addAdminMenuItem($itemQuad, 13, 'Pause the current game');
} }
} }
@ -168,20 +143,16 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
$itemQuad = new Quad_BgRaceScore2(); $itemQuad = new Quad_BgRaceScore2();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_SendScore); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_SendScore);
$itemQuad->setAction(self::ACTION_EXTEND_WARMUP); $itemQuad->setAction(self::ACTION_EXTEND_WARMUP);
$this->maniaControl->getActionsMenu() $this->maniaControl->getActionsMenu()->addMenuItem($itemQuad, false, 14, 'Extend Warmup');
->addMenuItem($itemQuad, false, 14, 'Extend Warmup');
// Stop WarmUp menu item // Stop WarmUp menu item
$itemQuad = new Quad_Icons64x64_1(); $itemQuad = new Quad_Icons64x64_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ArrowGreen); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_ArrowGreen);
$itemQuad->setAction(self::ACTION_END_WARMUP); $itemQuad->setAction(self::ACTION_END_WARMUP);
$this->maniaControl->getActionsMenu() $this->maniaControl->getActionsMenu()->addMenuItem($itemQuad, false, 15, 'End Warmup');
->addMenuItem($itemQuad, false, 15, 'End Warmup');
} else { } else {
$this->maniaControl->getActionsMenu() $this->maniaControl->getActionsMenu()->removeMenuItem(14, false);
->removeMenuItem(14, false); $this->maniaControl->getActionsMenu()->removeMenuItem(15, false);
$this->maniaControl->getActionsMenu()
->removeMenuItem(15, false);
} }
} }
@ -192,26 +163,20 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
* @param Player $player * @param Player $player
*/ */
public function commandCancelVote(array $chatCallback, Player $player) { public function commandCancelVote(array $chatCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_CANCEL_VOTE)
->checkPermission($player, self::SETTING_PERMISSION_CANCEL_VOTE)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
if ($this->maniaControl->getClient() if ($this->maniaControl->getClient()->cancelVote()
->cancelVote()
) { ) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation($player->getEscapedNickname() . ' cancelled the Vote!');
->sendInformation($player->getEscapedNickname() . ' cancelled the Vote!');
} else { } else {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation("There's no vote running currently!", $player);
->sendInformation("There's no vote running currently!", $player);
} }
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_VOTE_CANCELLED, $player);
->triggerCallback(self::CB_VOTE_CANCELLED, $player);
} }
@ -222,19 +187,15 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
* @param Player $player * @param Player $player
*/ */
public function commandExtendWarmup(array $callback, Player $player) { public function commandExtendWarmup(array $callback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_HANDLE_WARMUP)
->checkPermission($player, self::SETTING_PERMISSION_HANDLE_WARMUP)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->triggerModeScriptEvent('WarmUp_Extend', '10');
->triggerModeScriptEvent('WarmUp_Extend', '10'); $this->maniaControl->getChat()->sendInformation($player->getEscapedNickname() . ' extended the WarmUp by 10 seconds!');
$this->maniaControl->getChat()
->sendInformation($player->getEscapedNickname() . ' extended the WarmUp by 10 seconds!');
} catch (GameModeException $e) { } catch (GameModeException $e) {
} }
} }
@ -246,19 +207,15 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
* @param Player $player * @param Player $player
*/ */
public function commandEndWarmup(array $callback, Player $player) { public function commandEndWarmup(array $callback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_HANDLE_WARMUP)
->checkPermission($player, self::SETTING_PERMISSION_HANDLE_WARMUP)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->triggerModeScriptEvent('WarmUp_Stop', '');
->triggerModeScriptEvent('WarmUp_Stop', ''); $this->maniaControl->getChat()->sendInformation($player->getEscapedNickname() . ' stopped the WarmUp!');
$this->maniaControl->getChat()
->sendInformation($player->getEscapedNickname() . ' stopped the WarmUp!');
} catch (GameModeException $e) { } catch (GameModeException $e) {
} }
} }
@ -270,18 +227,14 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
* @param Player $player * @param Player $player
*/ */
public function setPause(array $callback, Player $player) { public function setPause(array $callback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_SET_PAUSE)
->checkPermission($player, self::SETTING_PERMISSION_SET_PAUSE)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->sendModeScriptCommands(array('Command_ForceWarmUp' => true));
->sendModeScriptCommands(array('Command_ForceWarmUp' => true)); $this->maniaControl->getChat()->sendInformation($player->getEscapedNickname() . ' paused the Game!');
$this->maniaControl->getChat()
->sendInformation($player->getEscapedNickname() . ' paused the Game!');
} catch (GameModeException $e) { } catch (GameModeException $e) {
} }
} }
@ -293,8 +246,7 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
// TODO: move empty & delayed shutdown code into server class // TODO: move empty & delayed shutdown code into server class
// Empty shutdown // Empty shutdown
if ($this->serverShutdownEmpty) { if ($this->serverShutdownEmpty) {
if ($this->maniaControl->getPlayerManager() if ($this->maniaControl->getPlayerManager()->getPlayerCount(false) <= 0
->getPlayerCount(false) <= 0
) { ) {
$this->shutdownServer('empty'); $this->shutdownServer('empty');
} }
@ -315,8 +267,7 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
*/ */
private function shutdownServer($login = '-') { private function shutdownServer($login = '-') {
Logger::logInfo("Server shutdown requested by '{$login}'!"); Logger::logInfo("Server shutdown requested by '{$login}'!");
$this->maniaControl->getClient() $this->maniaControl->getClient()->stopServer();
->stopServer();
} }
/** /**
@ -326,18 +277,14 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
* @param Player $player * @param Player $player
*/ */
public function commandSystemInfo(array $chat, Player $player) { public function commandSystemInfo(array $chat, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_SHOW_SYSTEMINFO)
->checkPermission($player, self::SETTING_PERMISSION_SHOW_SYSTEMINFO)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$systemInfo = $this->maniaControl->getClient() $systemInfo = $this->maniaControl->getClient()->getSystemInfo();
->getSystemInfo();
$message = 'SystemInfo: ip=' . $systemInfo->publishedIp . ', port=' . $systemInfo->port . ', p2pPort=' . $systemInfo->p2PPort . ', title=' . $systemInfo->titleId . ', login=' . $systemInfo->serverLogin . '.'; $message = 'SystemInfo: ip=' . $systemInfo->publishedIp . ', port=' . $systemInfo->port . ', p2pPort=' . $systemInfo->p2PPort . ', title=' . $systemInfo->titleId . ', login=' . $systemInfo->serverLogin . '.';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation($message, $player->login);
->sendInformation($message, $player->login);
} }
/** /**
@ -347,11 +294,9 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
* @param Player $player * @param Player $player
*/ */
public function commandShutdownServer(array $chat, Player $player) { public function commandShutdownServer(array $chat, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_SHUTDOWN_SERVER)
->checkPermission($player, self::SETTING_PERMISSION_SHUTDOWN_SERVER)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
// Check for delayed shutdown // Check for delayed shutdown
@ -361,26 +306,22 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
if (strtolower($param) === 'empty') { if (strtolower($param) === 'empty') {
$this->serverShutdownEmpty = !$this->serverShutdownEmpty; $this->serverShutdownEmpty = !$this->serverShutdownEmpty;
if ($this->serverShutdownEmpty) { if ($this->serverShutdownEmpty) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation("The server will shutdown as soon as it's empty!", $player);
->sendInformation("The server will shutdown as soon as it's empty!", $player);
return; return;
} }
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation("Empty-shutdown cancelled!", $player);
->sendInformation("Empty-shutdown cancelled!", $player);
return; return;
} }
$delay = (int)$param; $delay = (int)$param;
if ($delay <= 0) { if ($delay <= 0) {
// Cancel shutdown // Cancel shutdown
$this->serverShutdownTime = -1; $this->serverShutdownTime = -1;
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation("Delayed shutdown cancelled!", $player);
->sendInformation("Delayed shutdown cancelled!", $player);
return; return;
} }
// Trigger delayed shutdown // Trigger delayed shutdown
$this->serverShutdownTime = time() + $delay * 60.; $this->serverShutdownTime = time() + $delay * 60.;
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation("The server will shut down in {$delay} minutes!", $player);
->sendInformation("The server will shut down in {$delay} minutes!", $player);
return; return;
} }
$this->shutdownServer($player->login); $this->shutdownServer($player->login);
@ -393,24 +334,19 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
* @param Player $player * @param Player $player
*/ */
public function commandSetServerName(array $chat, Player $player) { public function commandSetServerName(array $chat, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_CHANGE_SERVERSETTINGS)
->checkPermission($player, self::SETTING_PERMISSION_CHANGE_SERVERSETTINGS)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chat[1][2], 2); $params = explode(' ', $chat[1][2], 2);
if (count($params) < 2) { if (count($params) < 2) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendUsageInfo('Usage example: //setservername ManiaPlanet Server', $player);
->sendUsageInfo('Usage example: //setservername ManiaPlanet Server', $player);
return; return;
} }
$serverName = $params[1]; $serverName = $params[1];
$this->maniaControl->getClient() $this->maniaControl->getClient()->setServerName($serverName);
->setServerName($serverName); $this->maniaControl->getChat()->sendSuccess("Server name changed to: '{$serverName}'!", $player);
$this->maniaControl->getChat()
->sendSuccess("Server name changed to: '{$serverName}'!", $player);
} }
/** /**
@ -420,11 +356,9 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
* @param Player $player * @param Player $player
*/ */
public function commandSetPwd(array $chatCallback, Player $player) { public function commandSetPwd(array $chatCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_CHANGE_SERVERSETTINGS)
->checkPermission($player, self::SETTING_PERMISSION_CHANGE_SERVERSETTINGS)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$messageParts = explode(' ', $chatCallback[1][2], 2); $messageParts = explode(' ', $chatCallback[1][2], 2);
@ -434,10 +368,8 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
$password = $messageParts[1]; $password = $messageParts[1];
$successMessage = "Password changed to: '{$password}'!"; $successMessage = "Password changed to: '{$password}'!";
} }
$this->maniaControl->getClient() $this->maniaControl->getClient()->setServerPassword($password);
->setServerPassword($password); $this->maniaControl->getChat()->sendSuccess($successMessage, $player);
$this->maniaControl->getChat()
->sendSuccess($successMessage, $player);
} }
/** /**
@ -447,11 +379,9 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
* @param Player $player * @param Player $player
*/ */
public function commandSetSpecPwd(array $chatCallback, Player $player) { public function commandSetSpecPwd(array $chatCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_CHANGE_SERVERSETTINGS)
->checkPermission($player, self::SETTING_PERMISSION_CHANGE_SERVERSETTINGS)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$messageParts = explode(' ', $chatCallback[1][2], 2); $messageParts = explode(' ', $chatCallback[1][2], 2);
@ -461,10 +391,8 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
$password = $messageParts[1]; $password = $messageParts[1];
$successMessage = "Spectator password changed to: '{$password}'!"; $successMessage = "Spectator password changed to: '{$password}'!";
} }
$this->maniaControl->getClient() $this->maniaControl->getClient()->setServerPasswordForSpectator($password);
->setServerPasswordForSpectator($password); $this->maniaControl->getChat()->sendSuccess($successMessage, $player);
$this->maniaControl->getChat()
->sendSuccess($successMessage, $player);
} }
/** /**
@ -474,23 +402,19 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
* @param Player $player * @param Player $player
*/ */
public function commandSetMaxPlayers(array $chatCallback, Player $player) { public function commandSetMaxPlayers(array $chatCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_CHANGE_SERVERSETTINGS)
->checkPermission($player, self::SETTING_PERMISSION_CHANGE_SERVERSETTINGS)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$messageParts = explode(' ', $chatCallback[1][2], 2); $messageParts = explode(' ', $chatCallback[1][2], 2);
if (!isset($messageParts[1])) { if (!isset($messageParts[1])) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendUsageInfo('Usage example: //setmaxplayers 16', $player);
->sendUsageInfo('Usage example: //setmaxplayers 16', $player);
return; return;
} }
$amount = $messageParts[1]; $amount = $messageParts[1];
if (!is_numeric($amount)) { if (!is_numeric($amount)) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendUsageInfo('Usage example: //setmaxplayers 16', $player);
->sendUsageInfo('Usage example: //setmaxplayers 16', $player);
return; return;
} }
$amount = (int)$amount; $amount = (int)$amount;
@ -498,10 +422,8 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
$amount = 0; $amount = 0;
} }
$this->maniaControl->getClient() $this->maniaControl->getClient()->setMaxPlayers($amount);
->setMaxPlayers($amount); $this->maniaControl->getChat()->sendSuccess("Changed max players to: {$amount}", $player);
$this->maniaControl->getChat()
->sendSuccess("Changed max players to: {$amount}", $player);
} }
/** /**
@ -511,23 +433,19 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
* @param Player $player * @param Player $player
*/ */
public function commandSetMaxSpectators(array $chatCallback, Player $player) { public function commandSetMaxSpectators(array $chatCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_CHANGE_SERVERSETTINGS)
->checkPermission($player, self::SETTING_PERMISSION_CHANGE_SERVERSETTINGS)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$messageParts = explode(' ', $chatCallback[1][2], 2); $messageParts = explode(' ', $chatCallback[1][2], 2);
if (!isset($messageParts[1])) { if (!isset($messageParts[1])) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendUsageInfo('Usage example: //setmaxspectators 16', $player);
->sendUsageInfo('Usage example: //setmaxspectators 16', $player);
return; return;
} }
$amount = $messageParts[1]; $amount = $messageParts[1];
if (!is_numeric($amount)) { if (!is_numeric($amount)) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendUsageInfo('Usage example: //setmaxspectators 16', $player);
->sendUsageInfo('Usage example: //setmaxspectators 16', $player);
return; return;
} }
$amount = (int)$amount; $amount = (int)$amount;
@ -535,9 +453,7 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
$amount = 0; $amount = 0;
} }
$this->maniaControl->getClient() $this->maniaControl->getClient()->setMaxSpectators($amount);
->setMaxSpectators($amount); $this->maniaControl->getChat()->sendSuccess("Changed max spectators to: {$amount}", $player);
$this->maniaControl->getChat()
->sendSuccess("Changed max spectators to: {$amount}", $player);
} }
} }

View File

@ -30,8 +30,7 @@ class Directory implements CallbackListener {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_SERVERSTOP, $this, 'handleServerStopCallback');
->registerCallbackListener(CallbackManager::CB_MP_SERVERSTOP, $this, 'handleServerStopCallback');
} }
/** /**
@ -40,8 +39,7 @@ class Directory implements CallbackListener {
* @return string * @return string
*/ */
public function getMapsFolder() { public function getMapsFolder() {
return $this->maniaControl->getClient() return $this->maniaControl->getClient()->getMapsDirectory();
->getMapsDirectory();
} }
/** /**
@ -50,8 +48,7 @@ class Directory implements CallbackListener {
* @return string * @return string
*/ */
public function getSkinsFolder() { public function getSkinsFolder() {
return $this->maniaControl->getClient() return $this->maniaControl->getClient()->getSkinsDirectory();
->getSkinsDirectory();
} }
/** /**
@ -86,8 +83,7 @@ class Directory implements CallbackListener {
* @return string * @return string
*/ */
public function getGameDataFolder() { public function getGameDataFolder() {
return $this->maniaControl->getClient() return $this->maniaControl->getClient()->gameDataDirectory();
->gameDataDirectory();
} }
/** /**

View File

@ -30,12 +30,9 @@ class RankingManager implements CallbackListener {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_MODESCRIPTCALLBACK, $this, 'handleCallbacks');
->registerCallbackListener(CallbackManager::CB_MP_MODESCRIPTCALLBACK, $this, 'handleCallbacks'); $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_MODESCRIPTCALLBACKARRAY, $this, 'handleCallbacks');
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONINIT, $this, 'onInit');
->registerCallbackListener(CallbackManager::CB_MP_MODESCRIPTCALLBACKARRAY, $this, 'handleCallbacks');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(Callbacks::ONINIT, $this, 'onInit');
//TODO won message at end of the map (disable as setting) (and public announce only all %50 (setting) players) //TODO won message at end of the map (disable as setting) (and public announce only all %50 (setting) players)
} }
@ -44,8 +41,7 @@ class RankingManager implements CallbackListener {
*/ */
public function onInit() { public function onInit() {
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->triggerModeScriptEvent('LibXmlRpc_GetRankings', '');
->triggerModeScriptEvent('LibXmlRpc_GetRankings', '');
} catch (GameModeException $e) { } catch (GameModeException $e) {
} }
} }
@ -94,8 +90,7 @@ class RankingManager implements CallbackListener {
array_multisort($this->rankings, SORT_DESC, SORT_NUMERIC); array_multisort($this->rankings, SORT_DESC, SORT_NUMERIC);
//TODO if Local Records activated-> sort asc //TODO if Local Records activated-> sort asc
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::RANKINGSUPDATED, $this->getRankings());
->triggerCallback(Callbacks::RANKINGSUPDATED, $this->getRankings());
} }
/** /**

View File

@ -39,8 +39,7 @@ class ScriptManager {
if (!$this->isScriptMode()) { if (!$this->isScriptMode()) {
return false; return false;
} }
$scriptSettings = $this->maniaControl->getClient() $scriptSettings = $this->maniaControl->getClient()->getModeScriptSettings();
->getModeScriptSettings();
if (!array_key_exists('S_UseScriptCallbacks', $scriptSettings)) { if (!array_key_exists('S_UseScriptCallbacks', $scriptSettings)) {
return false; return false;
@ -49,8 +48,7 @@ class ScriptManager {
$scriptSettings['S_UseScriptCallbacks'] = (bool)$enable; $scriptSettings['S_UseScriptCallbacks'] = (bool)$enable;
$actionName = ($enable ? 'en' : 'dis'); $actionName = ($enable ? 'en' : 'dis');
$this->maniaControl->getClient() $this->maniaControl->getClient()->setModeScriptSettings($scriptSettings);
->setModeScriptSettings($scriptSettings);
Logger::logInfo("Script Callbacks successfully {$actionName}abled!"); Logger::logInfo("Script Callbacks successfully {$actionName}abled!");
return true; return true;
} }
@ -62,8 +60,7 @@ class ScriptManager {
*/ */
public function isScriptMode() { public function isScriptMode() {
if (is_null($this->isScriptMode)) { if (is_null($this->isScriptMode)) {
$gameMode = $this->maniaControl->getClient() $gameMode = $this->maniaControl->getClient()->getGameMode();
->getGameMode();
$this->isScriptMode = ($gameMode === 0); $this->isScriptMode = ($gameMode === 0);
} }
return $this->isScriptMode; return $this->isScriptMode;

View File

@ -74,8 +74,7 @@ class Server implements CallbackListener {
$this->scriptManager = new ScriptManager($maniaControl); $this->scriptManager = new ScriptManager($maniaControl);
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONINIT, $this, 'onInit');
->registerCallbackListener(Callbacks::ONINIT, $this, 'onInit');
} }
/** /**
@ -84,8 +83,7 @@ class Server implements CallbackListener {
* @return bool * @return bool
*/ */
private function initTables() { private function initTables() {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_SERVERS . "` ( $query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_SERVERS . "` (
`index` int(11) NOT NULL AUTO_INCREMENT, `index` int(11) NOT NULL AUTO_INCREMENT,
`login` varchar(100) NOT NULL, `login` varchar(100) NOT NULL,
@ -172,15 +170,13 @@ class Server implements CallbackListener {
// Server xml element with given id // Server xml element with given id
$serverElement = null; $serverElement = null;
if ($serverId) { if ($serverId) {
$serverElements = $this->maniaControl->getConfig() $serverElements = $this->maniaControl->getConfig()->xpath("server[@id='{$serverId}']");
->xpath("server[@id='{$serverId}']");
if (!$serverElements) { if (!$serverElements) {
$this->maniaControl->quit("No Server configured with the ID '{$serverId}'!", true); $this->maniaControl->quit("No Server configured with the ID '{$serverId}'!", true);
} }
$serverElement = $serverElements[0]; $serverElement = $serverElements[0];
} else { } else {
$serverElements = $this->maniaControl->getConfig() $serverElements = $this->maniaControl->getConfig()->xpath('server');
->xpath('server');
if (!$serverElements) { if (!$serverElements) {
$this->maniaControl->quit('Invalid server configuration (No Server configured).', true); $this->maniaControl->quit('Invalid server configuration (No Server configured).', true);
} }
@ -212,8 +208,7 @@ class Server implements CallbackListener {
* @return \stdClass[] * @return \stdClass[]
*/ */
public function getAllServers() { public function getAllServers() {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$query = "SELECT * FROM `" . self::TABLE_SERVERS . "`;"; $query = "SELECT * FROM `" . self::TABLE_SERVERS . "`;";
$result = $mysqli->query($query); $result = $mysqli->query($query);
if (!$result) { if (!$result) {
@ -242,8 +237,7 @@ class Server implements CallbackListener {
*/ */
private function updateProperties() { private function updateProperties() {
// System info // System info
$systemInfo = $this->maniaControl->getClient() $systemInfo = $this->maniaControl->getClient()->getSystemInfo();
->getSystemInfo();
$this->ip = $systemInfo->publishedIp; $this->ip = $systemInfo->publishedIp;
$this->port = $systemInfo->port; $this->port = $systemInfo->port;
$this->p2pPort = $systemInfo->p2PPort; $this->p2pPort = $systemInfo->p2PPort;
@ -251,8 +245,7 @@ class Server implements CallbackListener {
$this->titleId = $systemInfo->titleId; $this->titleId = $systemInfo->titleId;
// Database index // Database index
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$query = "INSERT INTO `" . self::TABLE_SERVERS . "` ( $query = "INSERT INTO `" . self::TABLE_SERVERS . "` (
`login` `login`
) VALUES ( ) VALUES (
@ -281,8 +274,7 @@ class Server implements CallbackListener {
* @return \Maniaplanet\DedicatedServer\Structures\PlayerDetailedInfo * @return \Maniaplanet\DedicatedServer\Structures\PlayerDetailedInfo
*/ */
public function getInfo() { public function getInfo() {
return $this->maniaControl->getClient() return $this->maniaControl->getClient()->getDetailedPlayerInfo($this->login);
->getDetailedPlayerInfo($this->login);
} }
/** /**
@ -294,12 +286,10 @@ class Server implements CallbackListener {
public function getValidationReplay($login) { public function getValidationReplay($login) {
$login = Player::parseLogin($login); $login = Player::parseLogin($login);
try { try {
$replay = $this->maniaControl->getClient() $replay = $this->maniaControl->getClient()->getValidationReplay($login);
->getValidationReplay($login);
} catch (Exception $e) { } catch (Exception $e) {
// TODO temp added 19.04.2014 // TODO temp added 19.04.2014
$this->maniaControl->getErrorHandler() $this->maniaControl->getErrorHandler()->triggerDebugNotice("Exception line 330 Server.php" . $e->getMessage());
->triggerDebugNotice("Exception line 330 Server.php" . $e->getMessage());
trigger_error("Couldn't get validation replay of '{$login}'. " . $e->getMessage()); trigger_error("Couldn't get validation replay of '{$login}'. " . $e->getMessage());
return null; return null;
} }
@ -313,28 +303,24 @@ class Server implements CallbackListener {
* @return string * @return string
*/ */
public function getGhostReplay($login) { public function getGhostReplay($login) {
$dataDir = $this->getDirectory() $dataDir = $this->getDirectory()->getGameDataFolder();
->getGameDataFolder();
if (!$this->checkAccess($dataDir)) { if (!$this->checkAccess($dataDir)) {
return null; return null;
} }
// Build file name // Build file name
$login = Player::parseLogin($login); $login = Player::parseLogin($login);
$map = $this->maniaControl->getMapManager() $map = $this->maniaControl->getMapManager()->getCurrentMap();
->getCurrentMap();
$gameMode = $this->getGameMode(); $gameMode = $this->getGameMode();
$time = time(); $time = time();
$fileName = "GhostReplays/Ghost.{$login}.{$gameMode}.{$time}.{$map->uid}.Replay.Gbx"; $fileName = "GhostReplays/Ghost.{$login}.{$gameMode}.{$time}.{$map->uid}.Replay.Gbx";
// Save ghost replay // Save ghost replay
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->saveBestGhostsReplay($login, $fileName);
->saveBestGhostsReplay($login, $fileName);
} catch (Exception $e) { } catch (Exception $e) {
// TODO temp added 19.04.2014 // TODO temp added 19.04.2014
$this->maniaControl->getErrorHandler() $this->maniaControl->getErrorHandler()->triggerDebugNotice("Exception line 360 Server.php" . $e->getMessage());
->triggerDebugNotice("Exception line 360 Server.php" . $e->getMessage());
trigger_error("Couldn't save ghost replay. " . $e->getMessage()); trigger_error("Couldn't save ghost replay. " . $e->getMessage());
return null; return null;
@ -373,8 +359,7 @@ class Server implements CallbackListener {
if (is_int($parseValue)) { if (is_int($parseValue)) {
$gameMode = $parseValue; $gameMode = $parseValue;
} else { } else {
$gameMode = $this->maniaControl->getClient() $gameMode = $this->maniaControl->getClient()->getGameMode();
->getGameMode();
} }
if ($stringValue) { if ($stringValue) {
switch ($gameMode) { switch ($gameMode) {
@ -406,8 +391,7 @@ class Server implements CallbackListener {
* @return bool * @return bool
*/ */
public function waitForStatus($statusCode = 4) { public function waitForStatus($statusCode = 4) {
$response = $this->maniaControl->getClient() $response = $this->maniaControl->getClient()->getStatus();
->getStatus();
// Check if server has the given status // Check if server has the given status
if ($response->code === 4) { if ($response->code === 4) {
return true; return true;
@ -420,8 +404,7 @@ class Server implements CallbackListener {
Logger::log("Current Status: {$lastStatus}"); Logger::log("Current Status: {$lastStatus}");
while ($response->code !== 4) { while ($response->code !== 4) {
sleep(1); sleep(1);
$response = $this->maniaControl->getClient() $response = $this->maniaControl->getClient()->getStatus();
->getStatus();
if ($lastStatus !== $response->name) { if ($lastStatus !== $response->name) {
Logger::log("New Status: {$response->name}"); Logger::log("New Status: {$response->name}");
$lastStatus = $response->name; $lastStatus = $response->name;
@ -446,8 +429,7 @@ class Server implements CallbackListener {
// Trigger callback // Trigger callback
if ($oldStatus !== $this->teamMode | $oldStatus === null) { if ($oldStatus !== $this->teamMode | $oldStatus === null) {
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_TEAM_MODE_CHANGED, $teamMode);
->triggerCallback(self::CB_TEAM_MODE_CHANGED, $teamMode);
} }
} }
@ -475,7 +457,6 @@ class Server implements CallbackListener {
* @return bool * @return bool
*/ */
public function isEmpty() { public function isEmpty() {
return ($this->maniaControl->getPlayerManager() return ($this->maniaControl->getPlayerManager()->getPlayerCount(false) === 0);
->getPlayerCount(false) === 0);
} }
} }

View File

@ -59,14 +59,11 @@ class ServerOptionsMenu implements CallbackListener, ConfiguratorMenu, TimerList
$this->initTables(); $this->initTables();
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONINIT, $this, 'onInit');
->registerCallbackListener(Callbacks::ONINIT, $this, 'onInit'); $this->maniaControl->getTimerManager()->registerTimerListening($this, 'saveCurrentServerOptions', 6 * 3600 * 1000);
$this->maniaControl->getTimerManager()
->registerTimerListening($this, 'saveCurrentServerOptions', 6 * 3600 * 1000);
// Permissions // Permissions
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_SERVER_OPTIONS, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_SERVER_OPTIONS, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
} }
/** /**
@ -75,8 +72,7 @@ class ServerOptionsMenu implements CallbackListener, ConfiguratorMenu, TimerList
* @return bool * @return bool
*/ */
private function initTables() { private function initTables() {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_SERVER_OPTIONS . "` ( $query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_SERVER_OPTIONS . "` (
`index` int(11) NOT NULL AUTO_INCREMENT, `index` int(11) NOT NULL AUTO_INCREMENT,
`serverIndex` int(11) NOT NULL, `serverIndex` int(11) NOT NULL,
@ -113,8 +109,7 @@ class ServerOptionsMenu implements CallbackListener, ConfiguratorMenu, TimerList
* @return bool * @return bool
*/ */
public function saveCurrentServerOptions() { public function saveCurrentServerOptions() {
$serverOptions = $this->maniaControl->getClient() $serverOptions = $this->maniaControl->getClient()->getServerOptions();
->getServerOptions();
return $this->saveServerOptions($serverOptions); return $this->saveServerOptions($serverOptions);
} }
@ -126,8 +121,7 @@ class ServerOptionsMenu implements CallbackListener, ConfiguratorMenu, TimerList
* @return bool * @return bool
*/ */
private function saveServerOptions(ServerOptions $serverOptions, $triggerCallbacks = false) { private function saveServerOptions(ServerOptions $serverOptions, $triggerCallbacks = false) {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$query = "INSERT INTO `" . self::TABLE_SERVER_OPTIONS . "` ( $query = "INSERT INTO `" . self::TABLE_SERVER_OPTIONS . "` (
`serverIndex`, `serverIndex`,
`optionName`, `optionName`,
@ -160,8 +154,7 @@ class ServerOptionsMenu implements CallbackListener, ConfiguratorMenu, TimerList
} }
if ($triggerCallbacks) { if ($triggerCallbacks) {
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_SERVER_OPTION_CHANGED, array(self::CB_SERVER_OPTION_CHANGED, $optionName, $optionValue));
->triggerCallback(self::CB_SERVER_OPTION_CHANGED, array(self::CB_SERVER_OPTION_CHANGED, $optionName, $optionValue));
} }
} }
@ -182,8 +175,7 @@ class ServerOptionsMenu implements CallbackListener, ConfiguratorMenu, TimerList
* @return bool * @return bool
*/ */
public function loadOptionsFromDatabase() { public function loadOptionsFromDatabase() {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$serverIndex = $this->maniaControl->getServer()->index; $serverIndex = $this->maniaControl->getServer()->index;
$query = "SELECT * FROM `" . self::TABLE_SERVER_OPTIONS . "` $query = "SELECT * FROM `" . self::TABLE_SERVER_OPTIONS . "`
WHERE `serverIndex` = {$serverIndex};"; WHERE `serverIndex` = {$serverIndex};";
@ -193,8 +185,7 @@ class ServerOptionsMenu implements CallbackListener, ConfiguratorMenu, TimerList
return false; return false;
} }
$oldServerOptions = $this->maniaControl->getClient() $oldServerOptions = $this->maniaControl->getClient()->getServerOptions();
->getServerOptions();
$newServerOptions = new ServerOptions(); $newServerOptions = new ServerOptions();
while ($row = $result->fetch_object()) { while ($row = $result->fetch_object()) {
@ -211,11 +202,9 @@ class ServerOptionsMenu implements CallbackListener, ConfiguratorMenu, TimerList
$loaded = false; $loaded = false;
try { try {
$loaded = $this->maniaControl->getClient() $loaded = $this->maniaControl->getClient()->setServerOptions($newServerOptions);
->setServerOptions($newServerOptions);
} catch (ServerOptionsException $exception) { } catch (ServerOptionsException $exception) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendExceptionToAdmins($exception);
->sendExceptionToAdmins($exception);
} }
if ($loaded) { if ($loaded) {
@ -252,8 +241,7 @@ class ServerOptionsMenu implements CallbackListener, ConfiguratorMenu, TimerList
$script->addFeature($paging); $script->addFeature($paging);
$frame = new Frame(); $frame = new Frame();
$serverOptions = $this->maniaControl->getClient() $serverOptions = $this->maniaControl->getClient()->getServerOptions();
->getServerOptions();
$serverOptionsArray = $serverOptions->toArray(); $serverOptionsArray = $serverOptions->toArray();
// Config // Config
@ -264,26 +252,17 @@ class ServerOptionsMenu implements CallbackListener, ConfiguratorMenu, TimerList
// Pagers // Pagers
$pagerPrev = new Quad_Icons64x64_1(); $pagerPrev = new Quad_Icons64x64_1();
$frame->add($pagerPrev); $frame->add($pagerPrev);
$pagerPrev->setPosition($width * 0.39, $height * -0.44, 2) $pagerPrev->setPosition($width * 0.39, $height * -0.44, 2)->setSize($pagerSize, $pagerSize)->setSubStyle($pagerPrev::SUBSTYLE_ArrowPrev);
->setSize($pagerSize, $pagerSize)
->setSubStyle($pagerPrev::SUBSTYLE_ArrowPrev);
$pagerNext = new Quad_Icons64x64_1(); $pagerNext = new Quad_Icons64x64_1();
$frame->add($pagerNext); $frame->add($pagerNext);
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2) $pagerNext->setPosition($width * 0.45, $height * -0.44, 2)->setSize($pagerSize, $pagerSize)->setSubStyle($pagerNext::SUBSTYLE_ArrowNext);
->setSize($pagerSize, $pagerSize)
->setSubStyle($pagerNext::SUBSTYLE_ArrowNext);
$pageCountLabel = new Label_Text(); $pageCountLabel = new Label_Text();
$frame->add($pageCountLabel); $frame->add($pageCountLabel);
$pageCountLabel->setHAlign($pageCountLabel::RIGHT) $pageCountLabel->setHAlign($pageCountLabel::RIGHT)->setPosition($width * 0.35, $height * -0.44, 1)->setStyle($pageCountLabel::STYLE_TextTitle1)->setTextSize(2);
->setPosition($width * 0.35, $height * -0.44, 1)
->setStyle($pageCountLabel::STYLE_TextTitle1)
->setTextSize(2);
$paging->addButton($pagerNext) $paging->addButton($pagerNext)->addButton($pagerPrev)->setLabel($pageCountLabel);
->addButton($pagerPrev)
->setLabel($pageCountLabel);
// Pages // Pages
$posY = 0.; $posY = 0.;
@ -310,35 +289,22 @@ class ServerOptionsMenu implements CallbackListener, ConfiguratorMenu, TimerList
$nameLabel = new Label_Text(); $nameLabel = new Label_Text();
$optionsFrame->add($nameLabel); $optionsFrame->add($nameLabel);
$nameLabel->setHAlign($nameLabel::LEFT) $nameLabel->setHAlign($nameLabel::LEFT)->setX($width * -0.46)->setSize($width * 0.4, $optionHeight)->setStyle($nameLabel::STYLE_TextCardSmall)->setTextSize($labelTextSize)->setText($name)->setTextColor('fff');
->setX($width * -0.46)
->setSize($width * 0.4, $optionHeight)
->setStyle($nameLabel::STYLE_TextCardSmall)
->setTextSize($labelTextSize)
->setText($name)
->setTextColor('fff');
if (is_bool($value)) { if (is_bool($value)) {
// Boolean checkbox // Boolean checkbox
$quad = new Quad(); $quad = new Quad();
$quad->setPosition($width * 0.23, 0, -0.01) $quad->setPosition($width * 0.23, 0, -0.01)->setSize(4, 4);
->setSize(4, 4);
$checkBox = new CheckBox(self::ACTION_PREFIX_OPTION . $name, $value, $quad); $checkBox = new CheckBox(self::ACTION_PREFIX_OPTION . $name, $value, $quad);
$optionsFrame->add($checkBox); $optionsFrame->add($checkBox);
} else { } else {
// Other // Other
$entry = new Entry(); $entry = new Entry();
$optionsFrame->add($entry); $optionsFrame->add($entry);
$entry->setStyle(Label_Text::STYLE_TextValueSmall) $entry->setStyle(Label_Text::STYLE_TextValueSmall)->setX($width * 0.23)->setTextSize(1)->setSize($width * 0.48, $optionHeight * 0.9)->setName(self::ACTION_PREFIX_OPTION . $name)->setDefault($value);
->setX($width * 0.23)
->setTextSize(1)
->setSize($width * 0.48, $optionHeight * 0.9)
->setName(self::ACTION_PREFIX_OPTION . $name)
->setDefault($value);
if ($name === 'Comment') { if ($name === 'Comment') {
$entry->setSize($width * 0.48, $optionHeight * 3. + $optionHeight * 0.9) $entry->setSize($width * 0.48, $optionHeight * 3. + $optionHeight * 0.9)->setAutoNewLine(true);
->setAutoNewLine(true);
$optionsFrame->setY($posY - $optionHeight * 1.5); $optionsFrame->setY($posY - $optionHeight * 1.5);
$posY -= $optionHeight * 3.; $posY -= $optionHeight * 3.;
$index += 3; $index += 3;
@ -356,11 +322,9 @@ class ServerOptionsMenu implements CallbackListener, ConfiguratorMenu, TimerList
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData() * @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
*/ */
public function saveConfigData(array $configData, Player $player) { public function saveConfigData(array $configData, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_CHANGE_SERVER_OPTIONS)
->checkPermission($player, self::SETTING_PERMISSION_CHANGE_SERVER_OPTIONS)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_OPTION) !== 0) { if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_OPTION) !== 0) {
@ -369,8 +333,7 @@ class ServerOptionsMenu implements CallbackListener, ConfiguratorMenu, TimerList
$prefixLength = strlen(self::ACTION_PREFIX_OPTION); $prefixLength = strlen(self::ACTION_PREFIX_OPTION);
$oldServerOptions = $this->maniaControl->getClient() $oldServerOptions = $this->maniaControl->getClient()->getServerOptions();
->getServerOptions();
$newServerOptions = new ServerOptions(); $newServerOptions = new ServerOptions();
foreach ($configData[3] as $option) { foreach ($configData[3] as $option) {
@ -383,16 +346,13 @@ class ServerOptionsMenu implements CallbackListener, ConfiguratorMenu, TimerList
$success = $this->applyNewServerOptions($newServerOptions, $player); $success = $this->applyNewServerOptions($newServerOptions, $player);
if ($success) { if ($success) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess('Server Options saved!', $player);
->sendSuccess('Server Options saved!', $player);
} else { } else {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('Server Options saving failed!', $player);
->sendError('Server Options saving failed!', $player);
} }
// Reopen the Menu // Reopen the Menu
$this->maniaControl->getConfigurator() $this->maniaControl->getConfigurator()->showMenu($player, $this);
->showMenu($player, $this);
} }
/** /**
@ -404,18 +364,15 @@ class ServerOptionsMenu implements CallbackListener, ConfiguratorMenu, TimerList
*/ */
private function applyNewServerOptions(ServerOptions $newServerOptions, Player $player) { private function applyNewServerOptions(ServerOptions $newServerOptions, Player $player) {
try { try {
$this->maniaControl->getClient() $this->maniaControl->getClient()->setServerOptions($newServerOptions);
->setServerOptions($newServerOptions);
} catch (ServerOptionsException $exception) { } catch (ServerOptionsException $exception) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendException($exception, $player);
->sendException($exception, $player);
return false; return false;
} }
$this->saveServerOptions($newServerOptions, true); $this->saveServerOptions($newServerOptions, true);
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_SERVER_OPTIONS_CHANGED, array(self::CB_SERVER_OPTIONS_CHANGED));
->triggerCallback(self::CB_SERVER_OPTIONS_CHANGED, array(self::CB_SERVER_OPTIONS_CHANGED));
return true; return true;
} }

View File

@ -36,11 +36,9 @@ class UsageReporter implements TimerListener {
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_REPORT_USAGE, true);
->initSetting($this, self::SETTING_REPORT_USAGE, true);
$this->maniaControl->getTimerManager() $this->maniaControl->getTimerManager()->registerTimerListening($this, 'reportUsage', 1000 * 60 * self::UPDATE_MINUTE_COUNT);
->registerTimerListening($this, 'reportUsage', 1000 * 60 * self::UPDATE_MINUTE_COUNT);
} }
/** /**
@ -48,8 +46,7 @@ class UsageReporter implements TimerListener {
*/ */
public function reportUsage() { public function reportUsage() {
if (DEV_MODE if (DEV_MODE
|| !$this->maniaControl->getSettingManager() || !$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_REPORT_USAGE)
->getSettingValue($this, self::SETTING_REPORT_USAGE)
) { ) {
return; return;
} }
@ -60,37 +57,30 @@ class UsageReporter implements TimerListener {
$properties['PHPVersion'] = phpversion(); $properties['PHPVersion'] = phpversion();
$properties['ServerLogin'] = $this->maniaControl->getServer()->login; $properties['ServerLogin'] = $this->maniaControl->getServer()->login;
$properties['TitleId'] = $this->maniaControl->getServer()->titleId; $properties['TitleId'] = $this->maniaControl->getServer()->titleId;
$properties['ServerName'] = Formatter::stripDirtyCodes($this->maniaControl->getClient() $properties['ServerName'] = Formatter::stripDirtyCodes($this->maniaControl->getClient()->getServerName());
->getServerName()); $properties['UpdateChannel'] = $this->maniaControl->getUpdateManager()->getCurrentUpdateChannelSetting();
$properties['UpdateChannel'] = $this->maniaControl->getUpdateManager()
->getCurrentUpdateChannelSetting();
$properties['PlayerCount'] = $this->maniaControl->getPlayerManager() $properties['PlayerCount'] = $this->maniaControl->getPlayerManager()->getPlayerCount();
->getPlayerCount();
$properties['MemoryUsage'] = memory_get_usage(); $properties['MemoryUsage'] = memory_get_usage();
$properties['MemoryPeakUsage'] = memory_get_peak_usage(); $properties['MemoryPeakUsage'] = memory_get_peak_usage();
$maxPlayers = $this->maniaControl->getClient() $maxPlayers = $this->maniaControl->getClient()->getMaxPlayers();
->getMaxPlayers();
$properties['MaxPlayers'] = $maxPlayers['CurrentValue']; $properties['MaxPlayers'] = $maxPlayers['CurrentValue'];
try { try {
$scriptName = $this->maniaControl->getClient() $scriptName = $this->maniaControl->getClient()->getScriptName();
->getScriptName();
$properties['ScriptName'] = $scriptName['CurrentValue']; $properties['ScriptName'] = $scriptName['CurrentValue'];
} catch (GameModeException $e) { } catch (GameModeException $e) {
$properties['ScriptName'] = ''; $properties['ScriptName'] = '';
} }
$properties['ActivePlugins'] = $this->maniaControl->getPluginManager() $properties['ActivePlugins'] = $this->maniaControl->getPluginManager()->getActivePluginsIds();
->getActivePluginsIds();
$json = json_encode($properties); $json = json_encode($properties);
$info = base64_encode($json); $info = base64_encode($json);
$url = ManiaControl::URL_WEBSERVICE . '/usagereport?info=' . urlencode($info); $url = ManiaControl::URL_WEBSERVICE . '/usagereport?info=' . urlencode($info);
$this->maniaControl->getFileReader() $this->maniaControl->getFileReader()->loadFile($url, function ($response, $error) {
->loadFile($url, function ($response, $error) {
$response = json_decode($response); $response = json_decode($response);
if ($error || !$response) { if ($error || !$response) {
Logger::logError('Error while Sending data: ' . print_r($error, true)); Logger::logError('Error while Sending data: ' . print_r($error, true));

View File

@ -43,8 +43,7 @@ class VoteRatiosMenu implements CallbackListener, ConfiguratorMenu, TimerListene
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Permissions // Permissions
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_VOTE_RATIOS, AuthenticationManager::AUTH_LEVEL_ADMIN);
->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_VOTE_RATIOS, AuthenticationManager::AUTH_LEVEL_ADMIN);
} }
/** /**
@ -64,8 +63,7 @@ class VoteRatiosMenu implements CallbackListener, ConfiguratorMenu, TimerListene
$index = 0; $index = 0;
$voteRatioCommands = $this->getVoteCommands(); $voteRatioCommands = $this->getVoteCommands();
$voteRatios = $this->maniaControl->getClient() $voteRatios = $this->maniaControl->getClient()->getCallVoteRatios();
->getCallVoteRatios();
foreach ($voteRatioCommands as $voteRatioCommand => $voteRatioDescription) { foreach ($voteRatioCommands as $voteRatioCommand => $voteRatioDescription) {
$voteRatioFrame = new Frame(); $voteRatioFrame = new Frame();
$frame->add($voteRatioFrame); $frame->add($voteRatioFrame);
@ -73,20 +71,11 @@ class VoteRatiosMenu implements CallbackListener, ConfiguratorMenu, TimerListene
$nameLabel = new Label_Text(); $nameLabel = new Label_Text();
$voteRatioFrame->add($nameLabel); $voteRatioFrame->add($nameLabel);
$nameLabel->setHAlign($nameLabel::LEFT) $nameLabel->setHAlign($nameLabel::LEFT)->setX($width * -0.46)->setSize($width * 0.7, $lineHeight)->setTextSize(2)->setTranslate(true)->setText($voteRatioDescription);
->setX($width * -0.46)
->setSize($width * 0.7, $lineHeight)
->setTextSize(2)
->setTranslate(true)
->setText($voteRatioDescription);
$entry = new Entry(); $entry = new Entry();
$voteRatioFrame->add($entry); $voteRatioFrame->add($entry);
$entry->setX($width * 0.35) $entry->setX($width * 0.35)->setSize($width * 0.14, $lineHeight * 0.9)->setStyle(Label_Text::STYLE_TextValueSmall)->setTextSize($index === 0 ? 2 : 1)->setName(self::ACTION_PREFIX_VOTE_RATIO . $voteRatioCommand);
->setSize($width * 0.14, $lineHeight * 0.9)
->setStyle(Label_Text::STYLE_TextValueSmall)
->setTextSize($index === 0 ? 2 : 1)
->setName(self::ACTION_PREFIX_VOTE_RATIO . $voteRatioCommand);
$voteRatio = $this->getVoteRatioForCommand($voteRatios, $voteRatioCommand); $voteRatio = $this->getVoteRatioForCommand($voteRatios, $voteRatioCommand);
if ($voteRatio) { if ($voteRatio) {
@ -132,11 +121,9 @@ class VoteRatiosMenu implements CallbackListener, ConfiguratorMenu, TimerListene
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData() * @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
*/ */
public function saveConfigData(array $configData, Player $player) { public function saveConfigData(array $configData, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_CHANGE_VOTE_RATIOS)
->checkPermission($player, self::SETTING_PERMISSION_CHANGE_VOTE_RATIOS)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_VOTE_RATIO) !== 0) { if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_VOTE_RATIO) !== 0) {
@ -167,19 +154,15 @@ class VoteRatiosMenu implements CallbackListener, ConfiguratorMenu, TimerListene
array_push($newVoteRatios, $voteRatio); array_push($newVoteRatios, $voteRatio);
} }
$success = $this->maniaControl->getClient() $success = $this->maniaControl->getClient()->setCallVoteRatios($newVoteRatios);
->setCallVoteRatios($newVoteRatios);
if ($success) { if ($success) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess('Vote Ratios saved!', $player);
->sendSuccess('Vote Ratios saved!', $player);
} else { } else {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('Vote Ratios saving failed!', $player);
->sendError('Vote Ratios saving failed!', $player);
} }
// Reopen the Menu // Reopen the Menu
$this->maniaControl->getConfigurator() $this->maniaControl->getConfigurator()->showMenu($player, $this);
->showMenu($player, $this);
} }
/** /**
@ -189,7 +172,6 @@ class VoteRatiosMenu implements CallbackListener, ConfiguratorMenu, TimerListene
* @param string $commandName * @param string $commandName
*/ */
private function sendInvalidValueError(Player $player, $commandName) { private function sendInvalidValueError(Player $player, $commandName) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError("Invalid Value given for '{$commandName}'!", $player);
->sendError("Invalid Value given for '{$commandName}'!", $player);
} }
} }

View File

@ -40,8 +40,7 @@ class SettingManager implements CallbackListener {
$this->initTables(); $this->initTables();
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
} }
/** /**
@ -50,8 +49,7 @@ class SettingManager implements CallbackListener {
* @return bool * @return bool
*/ */
private function initTables() { private function initTables() {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$settingTableQuery = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_SETTINGS . "` ( $settingTableQuery = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_SETTINGS . "` (
`index` INT(11) NOT NULL AUTO_INCREMENT, `index` INT(11) NOT NULL AUTO_INCREMENT,
`class` VARCHAR(100) NOT NULL, `class` VARCHAR(100) NOT NULL,
@ -84,8 +82,7 @@ class SettingManager implements CallbackListener {
* @return bool * @return bool
*/ */
private function deleteUnusedSettings() { private function deleteUnusedSettings() {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$settingQuery = "DELETE FROM `" . self::TABLE_SETTINGS . "` $settingQuery = "DELETE FROM `" . self::TABLE_SETTINGS . "`
WHERE `changed` < NOW() - INTERVAL 1 HOUR;"; WHERE `changed` < NOW() - INTERVAL 1 HOUR;";
$result = $mysqli->query($settingQuery); $result = $mysqli->query($settingQuery);
@ -137,8 +134,7 @@ class SettingManager implements CallbackListener {
* @return Setting * @return Setting
*/ */
public function getSettingObjectByIndex($settingIndex) { public function getSettingObjectByIndex($settingIndex) {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$settingQuery = "SELECT * FROM `" . self::TABLE_SETTINGS . "` $settingQuery = "SELECT * FROM `" . self::TABLE_SETTINGS . "`
WHERE `index` = {$settingIndex};"; WHERE `index` = {$settingIndex};";
$result = $mysqli->query($settingQuery); $result = $mysqli->query($settingQuery);
@ -217,8 +213,7 @@ class SettingManager implements CallbackListener {
} }
// Fetch setting // Fetch setting
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$settingQuery = "SELECT * FROM `" . self::TABLE_SETTINGS . "` $settingQuery = "SELECT * FROM `" . self::TABLE_SETTINGS . "`
WHERE `class` = '" . $mysqli->escape_string($settingClass) . "' WHERE `class` = '" . $mysqli->escape_string($settingClass) . "'
AND `setting` = '" . $mysqli->escape_string($settingName) . "';"; AND `setting` = '" . $mysqli->escape_string($settingName) . "';";
@ -285,8 +280,7 @@ class SettingManager implements CallbackListener {
* @return bool * @return bool
*/ */
public function saveSetting(Setting $setting, $init = false) { public function saveSetting(Setting $setting, $init = false) {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
if ($init) { if ($init) {
// Init - Keep old value if the default didn't change // Init - Keep old value if the default didn't change
$valueUpdateString = '`value` = IF(`default` = VALUES(`default`), `value`, VALUES(`default`))'; $valueUpdateString = '`value` = IF(`default` = VALUES(`default`), `value`, VALUES(`default`))';
@ -329,8 +323,7 @@ class SettingManager implements CallbackListener {
// Trigger Settings Changed Callback // Trigger Settings Changed Callback
if (!$init) { if (!$init) {
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_SETTING_CHANGED, $setting);
->triggerCallback(self::CB_SETTING_CHANGED, $setting);
} }
return true; return true;
} }
@ -373,8 +366,7 @@ class SettingManager implements CallbackListener {
} else { } else {
$className = ClassUtil::getClass($object); $className = ClassUtil::getClass($object);
} }
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$settingQuery = "UPDATE `" . self::TABLE_SETTINGS . "` $settingQuery = "UPDATE `" . self::TABLE_SETTINGS . "`
SET `value` = `default` SET `value` = `default`
WHERE `class` = '" . $mysqli->escape_string($className) . "' WHERE `class` = '" . $mysqli->escape_string($className) . "'
@ -405,8 +397,7 @@ class SettingManager implements CallbackListener {
$className = ClassUtil::getClass($object); $className = ClassUtil::getClass($object);
} }
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$settingQuery = "DELETE FROM `" . self::TABLE_SETTINGS . "` $settingQuery = "DELETE FROM `" . self::TABLE_SETTINGS . "`
WHERE `class` = '" . $mysqli->escape_string($className) . "' WHERE `class` = '" . $mysqli->escape_string($className) . "'
AND `setting` = '" . $mysqli->escape_string($settingName) . "';"; AND `setting` = '" . $mysqli->escape_string($settingName) . "';";
@ -431,8 +422,7 @@ class SettingManager implements CallbackListener {
*/ */
public function getSettingsByClass($object) { public function getSettingsByClass($object) {
$className = ClassUtil::getClass($object); $className = ClassUtil::getClass($object);
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$query = "SELECT * FROM `" . self::TABLE_SETTINGS . "` $query = "SELECT * FROM `" . self::TABLE_SETTINGS . "`
WHERE `class` = '" . $mysqli->escape_string($className) . "' WHERE `class` = '" . $mysqli->escape_string($className) . "'
ORDER BY `setting` ASC;"; ORDER BY `setting` ASC;";
@ -455,8 +445,7 @@ class SettingManager implements CallbackListener {
* @return Setting[] * @return Setting[]
*/ */
public function getSettings() { public function getSettings() {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$query = "SELECT * FROM `" . self::TABLE_SETTINGS . "` $query = "SELECT * FROM `" . self::TABLE_SETTINGS . "`
ORDER BY `class` ASC, `setting` ASC;"; ORDER BY `class` ASC, `setting` ASC;";
$result = $mysqli->query($query); $result = $mysqli->query($query);
@ -479,8 +468,7 @@ class SettingManager implements CallbackListener {
* @return string[] * @return string[]
*/ */
public function getSettingClasses($hidePluginClasses = false) { public function getSettingClasses($hidePluginClasses = false) {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$query = "SELECT DISTINCT `class` FROM `" . self::TABLE_SETTINGS . "` $query = "SELECT DISTINCT `class` FROM `" . self::TABLE_SETTINGS . "`
ORDER BY `class` ASC;"; ORDER BY `class` ASC;";
$result = $mysqli->query($query); $result = $mysqli->query($query);

View File

@ -52,28 +52,23 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer'); $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONINIT, $this, 'handleOnInit');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(Callbacks::ONINIT, $this, 'handleOnInit');
} }
/** /**
* Add the menu entry * Add the menu entry
*/ */
public function handleOnInit() { public function handleOnInit() {
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener('stats', $this, 'command_ShowStatsList', false, 'Shows statistics.');
->registerCommandListener('stats', $this, 'command_ShowStatsList', false, 'Shows statistics.');
// Action Open StatsList // Action Open StatsList
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_OPEN_STATSLIST, $this, 'command_ShowStatsList');
->registerManialinkPageAnswerListener(self::ACTION_OPEN_STATSLIST, $this, 'command_ShowStatsList');
$itemQuad = new Quad_UIConstruction_Buttons(); $itemQuad = new Quad_UIConstruction_Buttons();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Stats); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_Stats);
$itemQuad->setAction(self::ACTION_OPEN_STATSLIST); $itemQuad->setAction(self::ACTION_OPEN_STATSLIST);
$this->maniaControl->getActionsMenu() $this->maniaControl->getActionsMenu()->addMenuItem($itemQuad, true, 14, 'Open Statistics');
->addMenuItem($itemQuad, true, 14, 'Open Statistics');
//TODO settings if a stat get shown //TODO settings if a stat get shown
$this->registerStat(PlayerManager::STAT_SERVERTIME, 10, "ST", 20, StatisticManager::STAT_TYPE_TIME); $this->registerStat(PlayerManager::STAT_SERVERTIME, 10, "ST", 20, StatisticManager::STAT_TYPE_TIME);
@ -124,15 +119,9 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
* @param string $order * @param string $order
*/ */
public function showStatsList(Player $player, $order = PlayerManager::STAT_SERVERTIME) { public function showStatsList(Player $player, $order = PlayerManager::STAT_SERVERTIME) {
$height = $this->maniaControl->getManialinkManager() $height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
->getStyleManager() $quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowStyle();
->getListWidgetsHeight(); $quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowSubStyle();
$quadStyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultMainWindowStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultMainWindowSubStyle();
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID); $maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
@ -185,8 +174,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
$posX = $xStart + 55; $posX = $xStart + 55;
$statRankings = array(); $statRankings = array();
foreach ($this->statArray as $key => $stat) { foreach ($this->statArray as $key => $stat) {
$ranking = $this->maniaControl->getStatisticManager() $ranking = $this->maniaControl->getStatisticManager()->getStatsRanking($stat["Name"]);
->getStatsRanking($stat["Name"]);
if (!empty($ranking)) { if (!empty($ranking)) {
$statRankings[$stat["Name"]] = $ranking; $statRankings[$stat["Name"]] = $ranking;
$array[$stat['HeadShortCut']] = $posX; $array[$stat['HeadShortCut']] = $posX;
@ -196,8 +184,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
} }
} }
$labels = $this->maniaControl->getManialinkManager() $labels = $this->maniaControl->getManialinkManager()->labelLine($headFrame, $array);
->labelLine($headFrame, $array);
// Description Label // Description Label
$index = 2; $index = 2;
@ -225,8 +212,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
} }
foreach ($statRankings[$order] as $playerId => $value) { foreach ($statRankings[$order] as $playerId => $value) {
$listPlayer = $this->maniaControl->getPlayerManager() $listPlayer = $this->maniaControl->getPlayerManager()->getPlayerByIndex($playerId);
->getPlayerByIndex($playerId);
if (!$listPlayer) { if (!$listPlayer) {
continue; continue;
} }
@ -263,8 +249,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
} }
$array = array($index => $xStart + 5, $listPlayer->nickname => $xStart + 14); $array = array($index => $xStart + 5, $listPlayer->nickname => $xStart + 14);
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->labelLine($playerFrame, $array);
->labelLine($playerFrame, $array);
$posX = $xStart + 55; $posX = $xStart + 55;
foreach ($displayArray as $key => $array) { foreach ($displayArray as $key => $array) {
@ -294,8 +279,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
$posY -= 4; $posY -= 4;
} }
$this->maniaControl->getManialinkManager() $this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'SimpleStatsList');
->displayWidget($maniaLink, $player, 'SimpleStatsList');
} }
/** /**
@ -315,8 +299,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
switch ($action) { switch ($action) {
case self::ACTION_SORT_STATS: case self::ACTION_SORT_STATS:
$playerLogin = $callback[1][1]; $playerLogin = $callback[1][1];
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($playerLogin);
->getPlayer($playerLogin);
$this->showStatsList($player, $actionArray[2]); $this->showStatsList($player, $actionArray[2]);
break; break;
} }

View File

@ -68,22 +68,15 @@ class StatisticCollector implements CallbackListener {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_MODESCRIPTCALLBACK, $this, 'handleCallbacks');
->registerCallbackListener(CallbackManager::CB_MP_MODESCRIPTCALLBACK, $this, 'handleCallbacks'); $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_MODESCRIPTCALLBACKARRAY, $this, 'handleCallbacks');
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONINIT, $this, 'onInit');
->registerCallbackListener(CallbackManager::CB_MP_MODESCRIPTCALLBACKARRAY, $this, 'handleCallbacks'); $this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'onPlayerDisconnect');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(Callbacks::ONINIT, $this, 'onInit');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'onPlayerDisconnect');
// Settings // Settings
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_COLLECT_STATS_ENABLED, true);
->initSetting($this, self::SETTING_COLLECT_STATS_ENABLED, true); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_COLLECT_STATS_MINPLAYERS, 4);
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_ON_SHOOT_PRESTORE, 10);
->initSetting($this, self::SETTING_COLLECT_STATS_MINPLAYERS, 4);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_ON_SHOOT_PRESTORE, 10);
} }
/** /**
@ -91,42 +84,24 @@ class StatisticCollector implements CallbackListener {
*/ */
public function onInit() { public function onInit() {
// Define Stats MetaData // Define Stats MetaData
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_PLAYTIME, StatisticManager::STAT_TYPE_TIME);
->defineStatMetaData(self::STAT_PLAYTIME, StatisticManager::STAT_TYPE_TIME); $this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_MAP_WINS);
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_ON_SHOOT);
->defineStatMetaData(self::STAT_MAP_WINS); $this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_ON_NEARMISS);
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_ON_CAPTURE);
->defineStatMetaData(self::STAT_ON_SHOOT); $this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_ON_HIT);
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_ON_GOT_HIT);
->defineStatMetaData(self::STAT_ON_NEARMISS); $this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_ON_DEATH);
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_ON_PLAYER_REQUEST_RESPAWN);
->defineStatMetaData(self::STAT_ON_CAPTURE); $this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_ON_KILL);
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_LASER_HIT);
->defineStatMetaData(self::STAT_ON_HIT); $this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_LASER_SHOT);
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_NUCLEUS_HIT);
->defineStatMetaData(self::STAT_ON_GOT_HIT); $this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_NUCLEUS_SHOT);
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_ROCKET_HIT);
->defineStatMetaData(self::STAT_ON_DEATH); $this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_ROCKET_SHOT);
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_ARROW_HIT);
->defineStatMetaData(self::STAT_ON_PLAYER_REQUEST_RESPAWN); $this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_ARROW_SHOT);
$this->maniaControl->getStatisticManager()
->defineStatMetaData(self::STAT_ON_KILL);
$this->maniaControl->getStatisticManager()
->defineStatMetaData(self::STAT_LASER_HIT);
$this->maniaControl->getStatisticManager()
->defineStatMetaData(self::STAT_LASER_SHOT);
$this->maniaControl->getStatisticManager()
->defineStatMetaData(self::STAT_NUCLEUS_HIT);
$this->maniaControl->getStatisticManager()
->defineStatMetaData(self::STAT_NUCLEUS_SHOT);
$this->maniaControl->getStatisticManager()
->defineStatMetaData(self::STAT_ROCKET_HIT);
$this->maniaControl->getStatisticManager()
->defineStatMetaData(self::STAT_ROCKET_SHOT);
$this->maniaControl->getStatisticManager()
->defineStatMetaData(self::STAT_ARROW_HIT);
$this->maniaControl->getStatisticManager()
->defineStatMetaData(self::STAT_ARROW_SHOT);
} }
/** /**
@ -136,22 +111,16 @@ class StatisticCollector implements CallbackListener {
*/ */
public function onEndMap(array $callback) { public function onEndMap(array $callback) {
//Check for Minimum PlayerCount //Check for Minimum PlayerCount
if ($this->maniaControl->getPlayerManager() if ($this->maniaControl->getPlayerManager()->getPlayerCount() < $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLLECT_STATS_MINPLAYERS)
->getPlayerCount() < $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_COLLECT_STATS_MINPLAYERS)
) { ) {
return; return;
} }
$leaders = $this->maniaControl->getServer() $leaders = $this->maniaControl->getServer()->getRankingManager()->getLeaders();
->getRankingManager()
->getLeaders();
foreach ($leaders as $leaderLogin) { foreach ($leaders as $leaderLogin) {
$leader = $this->maniaControl->getPlayerManager() $leader = $this->maniaControl->getPlayerManager()->getPlayer($leaderLogin);
->getPlayer($leaderLogin); $this->maniaControl->getStatisticManager()->incrementStat(self::STAT_MAP_WINS, $leader);
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_MAP_WINS, $leader);
} }
} }
@ -162,8 +131,7 @@ class StatisticCollector implements CallbackListener {
*/ */
public function onPlayerDisconnect(Player $player) { public function onPlayerDisconnect(Player $player) {
// Check if Stat Collecting is enabled // Check if Stat Collecting is enabled
if (!$this->maniaControl->getSettingManager() if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLLECT_STATS_ENABLED)
->getSettingValue($this, self::SETTING_COLLECT_STATS_ENABLED)
) { ) {
return; return;
} }
@ -171,8 +139,7 @@ class StatisticCollector implements CallbackListener {
// Insert Data into Database, and destroy player // Insert Data into Database, and destroy player
if (isset($this->onShootArray[$player->login])) { if (isset($this->onShootArray[$player->login])) {
if ($this->onShootArray[$player->login] > 0) { if ($this->onShootArray[$player->login] > 0) {
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->insertStat(self::STAT_ON_SHOOT, $player, $this->maniaControl->getServer()->index, $this->onShootArray[$player->login]);
->insertStat(self::STAT_ON_SHOOT, $player, $this->maniaControl->getServer()->index, $this->onShootArray[$player->login]);
} }
unset($this->onShootArray[$player->login]); unset($this->onShootArray[$player->login]);
} }
@ -186,16 +153,13 @@ class StatisticCollector implements CallbackListener {
public function handleCallbacks(array $callback) { public function handleCallbacks(array $callback) {
//TODO survivals //TODO survivals
// Check if Stat Collecting is enabled // Check if Stat Collecting is enabled
if (!$this->maniaControl->getSettingManager() if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLLECT_STATS_ENABLED)
->getSettingValue($this, self::SETTING_COLLECT_STATS_ENABLED)
) { ) {
return; return;
} }
// Check for Minimum PlayerCount // Check for Minimum PlayerCount
if ($this->maniaControl->getPlayerManager() if ($this->maniaControl->getPlayerManager()->getPlayerCount() < $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLLECT_STATS_MINPLAYERS)
->getPlayerCount() < $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_COLLECT_STATS_MINPLAYERS)
) { ) {
return; return;
} }
@ -207,62 +171,47 @@ class StatisticCollector implements CallbackListener {
$this->handleOnShoot($callback[1][1][0], $callback[1][1][1]); $this->handleOnShoot($callback[1][1][0], $callback[1][1][1]);
break; break;
case 'LibXmlRpc_OnHit': case 'LibXmlRpc_OnHit':
$shooter = $this->maniaControl->getPlayerManager() $shooter = $this->maniaControl->getPlayerManager()->getPlayer($callback[1][1][0]);
->getPlayer($callback[1][1][0]); $victim = $this->maniaControl->getPlayerManager()->getPlayer($callback[1][1][1]);
$victim = $this->maniaControl->getPlayerManager()
->getPlayer($callback[1][1][1]);
$weapon = $callback[1][1][3]; $weapon = $callback[1][1][3];
if ($shooter) { if ($shooter) {
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->incrementStat($this->getWeaponStat(intval($weapon), false), $shooter);
->incrementStat($this->getWeaponStat(intval($weapon), false), $shooter); $this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_HIT, $shooter);
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_ON_HIT, $shooter);
} }
if ($victim) { if ($victim) {
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_GOT_HIT, $victim);
->incrementStat(self::STAT_ON_GOT_HIT, $victim);
} }
break; break;
case 'LibXmlRpc_OnNearMiss': case 'LibXmlRpc_OnNearMiss':
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($callback[1][1][0]);
->getPlayer($callback[1][1][0]); $this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_NEARMISS, $player);
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_ON_NEARMISS, $player);
break; break;
case 'LibXmlRpc_OnCapture': case 'LibXmlRpc_OnCapture':
$logins = $callback[1][1][0]; $logins = $callback[1][1][0];
$logins = explode(';', $logins); $logins = explode(';', $logins);
foreach ($logins as $login) { foreach ($logins as $login) {
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($login);
->getPlayer($login);
if (!$player) { if (!$player) {
continue; continue;
} }
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_CAPTURE, $player);
->incrementStat(self::STAT_ON_CAPTURE, $player);
} }
break; break;
case 'LibXmlRpc_OnArmorEmpty': case 'LibXmlRpc_OnArmorEmpty':
$victim = $this->maniaControl->getPlayerManager() $victim = $this->maniaControl->getPlayerManager()->getPlayer($callback[1][1][1]);
->getPlayer($callback[1][1][1]);
if (isset($callback[1][1][0])) { if (isset($callback[1][1][0])) {
$shooter = $this->maniaControl->getPlayerManager() $shooter = $this->maniaControl->getPlayerManager()->getPlayer($callback[1][1][0]);
->getPlayer($callback[1][1][0]);
if ($shooter) { if ($shooter) {
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_KILL, $shooter);
->incrementStat(self::STAT_ON_KILL, $shooter);
} }
} }
if ($victim) { if ($victim) {
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_DEATH, $victim);
->incrementStat(self::STAT_ON_DEATH, $victim);
} }
break; break;
case 'LibXmlRpc_OnPlayerRequestRespawn': case 'LibXmlRpc_OnPlayerRequestRespawn':
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($callback[1][1][0]);
->getPlayer($callback[1][1][0]); $this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_PLAYER_REQUEST_RESPAWN, $player);
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_ON_PLAYER_REQUEST_RESPAWN, $player);
break; break;
case 'OnShoot': case 'OnShoot':
$paramsObject = json_decode($callback[1][1]); $paramsObject = json_decode($callback[1][1]);
@ -273,19 +222,15 @@ class StatisticCollector implements CallbackListener {
case 'OnNearMiss': case 'OnNearMiss':
$paramsObject = json_decode($callback[1][1]); $paramsObject = json_decode($callback[1][1]);
if ($paramsObject && isset($paramsObject->Event)) { if ($paramsObject && isset($paramsObject->Event)) {
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($paramsObject->Event->Shooter->Login);
->getPlayer($paramsObject->Event->Shooter->Login); $this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_NEARMISS, $player);
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_ON_NEARMISS, $player);
} }
break; break;
case 'OnCapture': case 'OnCapture':
$paramsObject = json_decode($callback[1][1]); $paramsObject = json_decode($callback[1][1]);
if ($paramsObject && isset($paramsObject->Event)) { if ($paramsObject && isset($paramsObject->Event)) {
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($paramsObject->Event->Player->Login);
->getPlayer($paramsObject->Event->Player->Login); $this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_CAPTURE, $player);
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_ON_CAPTURE, $player);
} }
break; break;
case 'OnHit': case 'OnHit':
@ -293,21 +238,16 @@ class StatisticCollector implements CallbackListener {
if ($paramsObject && isset($paramsObject->Event)) { if ($paramsObject && isset($paramsObject->Event)) {
$weapon = (int)$paramsObject->Event->WeaponNum; $weapon = (int)$paramsObject->Event->WeaponNum;
if (isset($paramsObject->Event->Shooter)) { if (isset($paramsObject->Event->Shooter)) {
$shooter = $this->maniaControl->getPlayerManager() $shooter = $this->maniaControl->getPlayerManager()->getPlayer($paramsObject->Event->Shooter->Login);
->getPlayer($paramsObject->Event->Shooter->Login);
if ($shooter) { if ($shooter) {
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->incrementStat($this->getWeaponStat($weapon, false), $shooter);
->incrementStat($this->getWeaponStat($weapon, false), $shooter); $this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_HIT, $shooter);
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_ON_HIT, $shooter);
} }
} }
if (isset($paramsObject->Event->Victim)) { if (isset($paramsObject->Event->Victim)) {
$victim = $this->maniaControl->getPlayerManager() $victim = $this->maniaControl->getPlayerManager()->getPlayer($paramsObject->Event->Victim->Login);
->getPlayer($paramsObject->Event->Victim->Login);
if ($victim) { if ($victim) {
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_GOT_HIT, $victim);
->incrementStat(self::STAT_ON_GOT_HIT, $victim);
} }
} }
} }
@ -315,29 +255,22 @@ class StatisticCollector implements CallbackListener {
case 'OnArmorEmpty': case 'OnArmorEmpty':
$paramsObject = json_decode($callback[1][1]); $paramsObject = json_decode($callback[1][1]);
if ($paramsObject && isset($paramsObject->Event)) { if ($paramsObject && isset($paramsObject->Event)) {
$victim = $this->maniaControl->getPlayerManager() $victim = $this->maniaControl->getPlayerManager()->getPlayer($paramsObject->Event->Victim->Login);
->getPlayer($paramsObject->Event->Victim->Login); $this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_DEATH, $victim);
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_ON_DEATH, $victim);
if (isset($paramsObject->Event->Shooter->Login)) { if (isset($paramsObject->Event->Shooter->Login)) {
$shooter = $this->maniaControl->getPlayerManager() $shooter = $this->maniaControl->getPlayerManager()->getPlayer($paramsObject->Event->Shooter->Login);
->getPlayer($paramsObject->Event->Shooter->Login);
if ($shooter) { if ($shooter) {
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_KILL, $shooter);
->incrementStat(self::STAT_ON_KILL, $shooter);
} }
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_KILL, $shooter);
->incrementStat(self::STAT_ON_KILL, $shooter);
} }
} }
break; break;
case 'OnRequestRespawn': case 'OnRequestRespawn':
$paramsObject = json_decode($callback[1][1]); $paramsObject = json_decode($callback[1][1]);
if ($paramsObject && isset($paramsObject->Event)) { if ($paramsObject && isset($paramsObject->Event)) {
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($paramsObject->Event->Player->Login);
->getPlayer($paramsObject->Event->Player->Login); $this->maniaControl->getStatisticManager()->incrementStat(self::STAT_ON_PLAYER_REQUEST_RESPAWN, $player);
$this->maniaControl->getStatisticManager()
->incrementStat(self::STAT_ON_PLAYER_REQUEST_RESPAWN, $player);
} }
break; break;
case 'EndTurn': //TODO make it for other modes working case 'EndTurn': //TODO make it for other modes working
@ -345,10 +278,8 @@ class StatisticCollector implements CallbackListener {
if ($paramsObject && is_array($paramsObject->ScoresTable)) { if ($paramsObject && is_array($paramsObject->ScoresTable)) {
$durationTime = (int)(($paramsObject->EndTime - $paramsObject->StartTime) / 1000); $durationTime = (int)(($paramsObject->EndTime - $paramsObject->StartTime) / 1000);
foreach ($paramsObject->ScoresTable as $score) { foreach ($paramsObject->ScoresTable as $score) {
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($score->Login);
->getPlayer($score->Login); $this->maniaControl->getStatisticManager()->insertStat(self::STAT_PLAYTIME, $player, -1, $durationTime);
$this->maniaControl->getStatisticManager()
->insertStat(self::STAT_PLAYTIME, $player, -1, $durationTime);
} }
} }
break; break;
@ -371,11 +302,9 @@ class StatisticCollector implements CallbackListener {
$this->onShootArray[$login][$weaponNumber]++; $this->onShootArray[$login][$weaponNumber]++;
//Write Shoot Data into database //Write Shoot Data into database
if (array_sum($this->onShootArray[$login]) > $this->maniaControl->getSettingManager() if (array_sum($this->onShootArray[$login]) > $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_ON_SHOOT_PRESTORE)
->getSettingValue($this, self::SETTING_ON_SHOOT_PRESTORE)
) { ) {
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($login);
->getPlayer($login);
$rocketShots = $this->onShootArray[$login][self::WEAPON_ROCKET]; $rocketShots = $this->onShootArray[$login][self::WEAPON_ROCKET];
$laserShots = $this->onShootArray[$login][self::WEAPON_LASER]; $laserShots = $this->onShootArray[$login][self::WEAPON_LASER];
@ -383,28 +312,23 @@ class StatisticCollector implements CallbackListener {
$nucleusShots = $this->onShootArray[$login][self::WEAPON_NUCLEUS]; $nucleusShots = $this->onShootArray[$login][self::WEAPON_NUCLEUS];
if ($rocketShots > 0) { if ($rocketShots > 0) {
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->insertStat(self::STAT_ROCKET_SHOT, $player, $this->maniaControl->getServer()->index, $rocketShots);
->insertStat(self::STAT_ROCKET_SHOT, $player, $this->maniaControl->getServer()->index, $rocketShots);
$this->onShootArray[$login][self::WEAPON_ROCKET] = 0; $this->onShootArray[$login][self::WEAPON_ROCKET] = 0;
} }
if ($laserShots > 0) { if ($laserShots > 0) {
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->insertStat(self::STAT_LASER_SHOT, $player, $this->maniaControl->getServer()->index, $laserShots);
->insertStat(self::STAT_LASER_SHOT, $player, $this->maniaControl->getServer()->index, $laserShots);
$this->onShootArray[$login][self::WEAPON_LASER] = 0; $this->onShootArray[$login][self::WEAPON_LASER] = 0;
} }
if ($arrowShots > 0) { if ($arrowShots > 0) {
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->insertStat(self::STAT_ARROW_SHOT, $player, $this->maniaControl->getServer()->index, $arrowShots);
->insertStat(self::STAT_ARROW_SHOT, $player, $this->maniaControl->getServer()->index, $arrowShots);
$this->onShootArray[$login][self::WEAPON_ARROW] = 0; $this->onShootArray[$login][self::WEAPON_ARROW] = 0;
} }
if ($nucleusShots > 0) { if ($nucleusShots > 0) {
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->insertStat(self::STAT_NUCLEUS_SHOT, $player, $this->maniaControl->getServer()->index, $nucleusShots);
->insertStat(self::STAT_NUCLEUS_SHOT, $player, $this->maniaControl->getServer()->index, $nucleusShots);
$this->onShootArray[$login][self::WEAPON_NUCLEUS] = 0; $this->onShootArray[$login][self::WEAPON_NUCLEUS] = 0;
} }
$this->maniaControl->getStatisticManager() $this->maniaControl->getStatisticManager()->insertStat(self::STAT_ON_SHOOT, $player, $this->maniaControl->getServer()->index, $rocketShots + $laserShots + $arrowShots + $nucleusShots);
->insertStat(self::STAT_ON_SHOOT, $player, $this->maniaControl->getServer()->index, $rocketShots + $laserShots + $arrowShots + $nucleusShots);
} }
} }

View File

@ -69,8 +69,7 @@ class StatisticManager {
* @return bool * @return bool
*/ */
private function initTables() { private function initTables() {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_STATMETADATA . "` ( $query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_STATMETADATA . "` (
`index` int(11) NOT NULL AUTO_INCREMENT, `index` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL, `name` varchar(100) NOT NULL,
@ -118,8 +117,7 @@ class StatisticManager {
* Store Stats Meta Data from the Database * Store Stats Meta Data from the Database
*/ */
private function storeStatMetaData() { private function storeStatMetaData() {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$query = "SELECT * FROM `" . self::TABLE_STATMETADATA . "`;"; $query = "SELECT * FROM `" . self::TABLE_STATMETADATA . "`;";
$result = $mysqli->query($query); $result = $mysqli->query($query);
@ -204,8 +202,7 @@ class StatisticManager {
return $this->getStatsRankingOfSpecialStat($statName, $serverIndex); return $this->getStatsRankingOfSpecialStat($statName, $serverIndex);
} }
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$statId = $this->getStatId($statName); $statId = $this->getStatId($statName);
$query = "SELECT `playerId`, `serverIndex`, `value` FROM `" . self::TABLE_STATISTICS . "` $query = "SELECT `playerId`, `serverIndex`, `value` FROM `" . self::TABLE_STATISTICS . "`
@ -494,8 +491,7 @@ class StatisticManager {
return intval($hits) / intval($shots); return intval($hits) / intval($shots);
} }
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$statId = $this->getStatId($statName); $statId = $this->getStatId($statName);
if (!$statId) { if (!$statId) {
@ -567,8 +563,7 @@ class StatisticManager {
$serverIndex = $this->maniaControl->getServer()->index; $serverIndex = $this->maniaControl->getServer()->index;
} }
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$query = "INSERT INTO `" . self::TABLE_STATISTICS . "` ( $query = "INSERT INTO `" . self::TABLE_STATISTICS . "` (
`serverIndex`, `serverIndex`,
`playerId`, `playerId`,
@ -603,8 +598,7 @@ class StatisticManager {
* @return bool * @return bool
*/ */
public function defineStatMetaData($statName, $type = self::STAT_TYPE_INT, $statDescription = '') { public function defineStatMetaData($statName, $type = self::STAT_TYPE_INT, $statDescription = '') {
$mysqli = $this->maniaControl->getDatabase() $mysqli = $this->maniaControl->getDatabase()->getMysqli();
->getMysqli();
$query = "INSERT INTO `" . self::TABLE_STATMETADATA . "` ( $query = "INSERT INTO `" . self::TABLE_STATMETADATA . "` (
`name`, `name`,
`type`, `type`,

View File

@ -40,14 +40,11 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
// Chat commands // Chat commands
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener('checkpluginsupdate', $this, 'handle_CheckPluginsUpdate', true, 'Check for Plugin Updates.');
->registerCommandListener('checkpluginsupdate', $this, 'handle_CheckPluginsUpdate', true, 'Check for Plugin Updates.'); $this->maniaControl->getCommandManager()->registerCommandListener('pluginsupdate', $this, 'handle_PluginsUpdate', true, 'Perform the Plugin Updates.');
$this->maniaControl->getCommandManager()
->registerCommandListener('pluginsupdate', $this, 'handle_PluginsUpdate', true, 'Perform the Plugin Updates.');
} }
/** /**
@ -57,11 +54,9 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
* @param Player $player * @param Player $player
*/ */
public function handle_CheckPluginsUpdate(array $chatCallback, Player $player) { public function handle_CheckPluginsUpdate(array $chatCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, UpdateManager::SETTING_PERMISSION_UPDATECHECK)
->checkPermission($player, UpdateManager::SETTING_PERMISSION_UPDATECHECK)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
@ -76,26 +71,22 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
public function checkPluginsUpdate(Player $player = null) { public function checkPluginsUpdate(Player $player = null) {
$message = 'Checking Plugins for newer Versions...'; $message = 'Checking Plugins for newer Versions...';
if ($player) { if ($player) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation($message, $player);
->sendInformation($message, $player);
} }
Logger::log($message); Logger::log($message);
$this->maniaControl->getPluginManager() $this->maniaControl->getPluginManager()->fetchPluginList(function ($data, $error) use (&$player) {
->fetchPluginList(function ($data, $error) use (&$player) {
if (!$data || $error) { if (!$data || $error) {
$message = 'Error while checking Plugins for newer Versions!'; $message = 'Error while checking Plugins for newer Versions!';
if ($player) { if ($player) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError($message, $player);
->sendError($message, $player);
} }
Logger::logError($message); Logger::logError($message);
return; return;
} }
$pluginsData = $this->parsePluginsData($data); $pluginsData = $this->parsePluginsData($data);
$pluginClasses = $this->maniaControl->getPluginManager() $pluginClasses = $this->maniaControl->getPluginManager()->getPluginClasses();
->getPluginClasses();
$pluginUpdates = array(); $pluginUpdates = array();
foreach ($pluginClasses as $pluginClass) { foreach ($pluginClasses as $pluginClass) {
@ -111,8 +102,7 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
$pluginUpdates[$pluginId] = $pluginData; $pluginUpdates[$pluginId] = $pluginData;
$message = "There is an Update of '{$pluginData->pluginName}' available! ('{$pluginClass}' - Version {$pluginData->version})"; $message = "There is an Update of '{$pluginData->pluginName}' available! ('{$pluginClass}' - Version {$pluginData->version})";
if ($player) { if ($player) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess($message, $player);
->sendSuccess($message, $player);
} }
Logger::log($message); Logger::log($message);
} }
@ -121,16 +111,14 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
if (empty($pluginUpdates)) { if (empty($pluginUpdates)) {
$message = 'Plugins Update Check completed: All Plugins are up-to-date!'; $message = 'Plugins Update Check completed: All Plugins are up-to-date!';
if ($player) { if ($player) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess($message, $player);
->sendSuccess($message, $player);
} }
Logger::log($message); Logger::log($message);
} else { } else {
$updatesCount = count($pluginUpdates); $updatesCount = count($pluginUpdates);
$message = "Plugins Update Check completed: There are {$updatesCount} Updates available!"; $message = "Plugins Update Check completed: There are {$updatesCount} Updates available!";
if ($player) { if ($player) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess($message, $player);
->sendSuccess($message, $player);
} }
Logger::log($message); Logger::log($message);
} }
@ -162,11 +150,9 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
* @param Player $player * @param Player $player
*/ */
public function handle_PluginsUpdate(array $chatCallback, Player $player) { public function handle_PluginsUpdate(array $chatCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, UpdateManager::SETTING_PERMISSION_UPDATE)
->checkPermission($player, UpdateManager::SETTING_PERMISSION_UPDATE)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
@ -183,8 +169,7 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
if (empty($pluginsUpdates)) { if (empty($pluginsUpdates)) {
$message = 'There are no Plugin Updates available!'; $message = 'There are no Plugin Updates available!';
if ($player) { if ($player) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation($message, $player);
->sendInformation($message, $player);
} }
Logger::log($message); Logger::log($message);
return; return;
@ -192,18 +177,15 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
$message = "Starting Plugins Updating..."; $message = "Starting Plugins Updating...";
if ($player) { if ($player) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation($message, $player);
->sendInformation($message, $player);
} }
Logger::log($message); Logger::log($message);
$performBackup = $this->maniaControl->getSettingManager() $performBackup = $this->maniaControl->getSettingManager()->getSettingValue($this->maniaControl->getUpdateManager(), UpdateManager::SETTING_PERFORM_BACKUPS);
->getSettingValue($this->maniaControl->getUpdateManager(), UpdateManager::SETTING_PERFORM_BACKUPS);
if ($performBackup && !BackupUtil::performPluginsBackup()) { if ($performBackup && !BackupUtil::performPluginsBackup()) {
$message = 'Creating Backup before Plugins Update failed!'; $message = 'Creating Backup before Plugins Update failed!';
if ($player) { if ($player) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError($message, $player);
->sendError($message, $player);
} }
Logger::logError($message); Logger::logError($message);
} }
@ -230,8 +212,7 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
$pluginsUpdates = $this->parsePluginsData($pluginData); $pluginsUpdates = $this->parsePluginsData($pluginData);
$updates = array(); $updates = array();
$pluginClasses = $this->maniaControl->getPluginManager() $pluginClasses = $this->maniaControl->getPluginManager()->getPluginClasses();
->getPluginClasses();
foreach ($pluginClasses as $pluginClass) { foreach ($pluginClasses as $pluginClass) {
/** @var Plugin $pluginClass */ /** @var Plugin $pluginClass */
$pluginId = $pluginClass::getId(); $pluginId = $pluginClass::getId();
@ -259,15 +240,13 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
* @param bool $update * @param bool $update
*/ */
private function installPlugin(PluginUpdateData $pluginUpdateData, Player $player = null, $update = false) { private function installPlugin(PluginUpdateData $pluginUpdateData, Player $player = null, $update = false) {
$this->maniaControl->getFileReader() $this->maniaControl->getFileReader()->loadFile($pluginUpdateData->url, function ($updateFileContent, $error) use (
->loadFile($pluginUpdateData->url, function ($updateFileContent, $error) use (
&$pluginUpdateData, &$player, &$update &$pluginUpdateData, &$player, &$update
) { ) {
if (!$updateFileContent || $error) { if (!$updateFileContent || $error) {
$message = "Error loading Update Data for '{$pluginUpdateData->pluginName}': {$error}!"; $message = "Error loading Update Data for '{$pluginUpdateData->pluginName}': {$error}!";
if ($player) { if ($player) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation($message, $player);
->sendInformation($message, $player);
} }
Logger::logError($message); Logger::logError($message);
return; return;
@ -279,8 +258,7 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
$message = "Now {$actionVerb} '{$pluginUpdateData->pluginName}'..."; $message = "Now {$actionVerb} '{$pluginUpdateData->pluginName}'...";
if ($player) { if ($player) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation($message, $player);
->sendInformation($message, $player);
} }
Logger::log($message); Logger::log($message);
@ -291,8 +269,7 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
if (!$bytes || $bytes <= 0) { if (!$bytes || $bytes <= 0) {
$message = "Plugin {$actionNoun} failed: Couldn't save {$actionNoun} Zip!"; $message = "Plugin {$actionNoun} failed: Couldn't save {$actionNoun} Zip!";
if ($player) { if ($player) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError($message, $player);
->sendError($message, $player);
} }
Logger::logError($message); Logger::logError($message);
return; return;
@ -303,8 +280,7 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
if ($result !== true) { if ($result !== true) {
$message = "Plugin {$actionNoun} failed: Couldn't open {$actionNoun} Zip! ({$result})"; $message = "Plugin {$actionNoun} failed: Couldn't open {$actionNoun} Zip! ({$result})";
if ($player) { if ($player) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError($message, $player);
->sendError($message, $player);
} }
Logger::logError($message); Logger::logError($message);
return; return;
@ -321,31 +297,26 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
} }
$message = "Successfully {$actionVerbDone} '{$pluginUpdateData->pluginName}'!{$messageExtra}"; $message = "Successfully {$actionVerbDone} '{$pluginUpdateData->pluginName}'!{$messageExtra}";
if ($player) { if ($player) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess($message, $player);
->sendSuccess($message, $player);
} }
Logger::log($message); Logger::log($message);
if (!$update) { if (!$update) {
$newPluginClasses = $this->maniaControl->getPluginManager() $newPluginClasses = $this->maniaControl->getPluginManager()->loadPlugins();
->loadPlugins();
if (empty($newPluginClasses)) { if (empty($newPluginClasses)) {
$message = "Loading fresh installed Plugin '{$pluginUpdateData->pluginName}' failed!"; $message = "Loading fresh installed Plugin '{$pluginUpdateData->pluginName}' failed!";
if ($player) { if ($player) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError($message, $player);
->sendError($message, $player);
} }
Logger::log($message); Logger::log($message);
} else { } else {
$message = "Successfully loaded fresh installed Plugin '{$pluginUpdateData->pluginName}'!"; $message = "Successfully loaded fresh installed Plugin '{$pluginUpdateData->pluginName}'!";
if ($player) { if ($player) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess($message, $player);
->sendSuccess($message, $player);
} }
Logger::log($message); Logger::log($message);
$this->maniaControl->getConfigurator() $this->maniaControl->getConfigurator()->showMenu($player, InstallMenu::getTitle());
->showMenu($player, InstallMenu::getTitle());
} }
} }
}); });
@ -365,8 +336,7 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
} }
$login = $callback[1][1]; $login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager() $player = $this->maniaControl->getPlayerManager()->getPlayer($login);
->getPlayer($login);
if ($update) { if ($update) {
$pluginClass = substr($actionId, strlen(PluginMenu::ACTION_PREFIX_UPDATEPLUGIN)); $pluginClass = substr($actionId, strlen(PluginMenu::ACTION_PREFIX_UPDATEPLUGIN));
@ -378,28 +348,24 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
$this->installPlugin($pluginUpdateData, $player, true); $this->installPlugin($pluginUpdateData, $player, true);
} else { } else {
$message = 'Error loading Plugin Update Data!'; $message = 'Error loading Plugin Update Data!';
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError($message, $player);
->sendError($message, $player);
} }
} }
} else { } else {
$pluginId = substr($actionId, strlen(InstallMenu::ACTION_PREFIX_INSTALL_PLUGIN)); $pluginId = substr($actionId, strlen(InstallMenu::ACTION_PREFIX_INSTALL_PLUGIN));
$url = ManiaControl::URL_WEBSERVICE . 'plugins/' . $pluginId; $url = ManiaControl::URL_WEBSERVICE . 'plugins/' . $pluginId;
$this->maniaControl->getFileReader() $this->maniaControl->getFileReader()->loadFile($url, function ($data, $error) use (&$player) {
->loadFile($url, function ($data, $error) use (&$player) {
if ($error || !$data) { if ($error || !$data) {
$message = "Error loading Plugin Install Data! {$error}"; $message = "Error loading Plugin Install Data! {$error}";
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError($message, $player);
->sendError($message, $player);
return; return;
} }
$data = json_decode($data); $data = json_decode($data);
if (!$data) { if (!$data) {
$message = "Error loading Plugin Install Data! {$error}"; $message = "Error loading Plugin Install Data! {$error}";
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError($message, $player);
->sendError($message, $player);
return; return;
} }

View File

@ -60,38 +60,25 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Settings // Settings
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_ENABLE_UPDATECHECK, true);
->initSetting($this, self::SETTING_ENABLE_UPDATECHECK, true); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_AUTO_UPDATE, true);
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_UPDATECHECK_INTERVAL, 1);
->initSetting($this, self::SETTING_AUTO_UPDATE, true); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_UPDATECHECK_CHANNEL, $this->getUpdateChannels());
$this->maniaControl->getSettingManager() $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PERFORM_BACKUPS, true);
->initSetting($this, self::SETTING_UPDATECHECK_INTERVAL, 1);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_UPDATECHECK_CHANNEL, $this->getUpdateChannels());
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_PERFORM_BACKUPS, true);
// Callbacks // Callbacks
$updateInterval = $this->maniaControl->getSettingManager() $updateInterval = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_UPDATECHECK_INTERVAL);
->getSettingValue($this, self::SETTING_UPDATECHECK_INTERVAL); $this->maniaControl->getTimerManager()->registerTimerListening($this, 'hourlyUpdateCheck', 1000 * 60 * 60 * $updateInterval);
$this->maniaControl->getTimerManager() $this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined');
->registerTimerListening($this, 'hourlyUpdateCheck', 1000 * 60 * 60 * $updateInterval); $this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
// Permissions // Permissions
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_UPDATE, AuthenticationManager::AUTH_LEVEL_ADMIN);
->definePermissionLevel(self::SETTING_PERMISSION_UPDATE, AuthenticationManager::AUTH_LEVEL_ADMIN); $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_UPDATECHECK, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->getAuthenticationManager()
->definePermissionLevel(self::SETTING_PERMISSION_UPDATECHECK, AuthenticationManager::AUTH_LEVEL_MODERATOR);
// Chat commands // Chat commands
$this->maniaControl->getCommandManager() $this->maniaControl->getCommandManager()->registerCommandListener('checkupdate', $this, 'handle_CheckUpdate', true, 'Checks if there is a core update.');
->registerCommandListener('checkupdate', $this, 'handle_CheckUpdate', true, 'Checks if there is a core update.'); $this->maniaControl->getCommandManager()->registerCommandListener('coreupdate', $this, 'handle_CoreUpdate', true, 'Performs the core update.');
$this->maniaControl->getCommandManager()
->registerCommandListener('coreupdate', $this, 'handle_CoreUpdate', true, 'Performs the core update.');
// Children // Children
$this->pluginUpdateManager = new PluginUpdateManager($maniaControl); $this->pluginUpdateManager = new PluginUpdateManager($maniaControl);
@ -120,8 +107,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
* Perform Hourly Update Check * Perform Hourly Update Check
*/ */
public function hourlyUpdateCheck() { public function hourlyUpdateCheck() {
$updateCheckEnabled = $this->maniaControl->getSettingManager() $updateCheckEnabled = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_ENABLE_UPDATECHECK);
->getSettingValue($this, self::SETTING_ENABLE_UPDATECHECK);
if (!$updateCheckEnabled) { if (!$updateCheckEnabled) {
$this->setCoreUpdateData(); $this->setCoreUpdateData();
} else { } else {
@ -154,8 +140,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$updateChannel = $this->getCurrentUpdateChannelSetting(); $updateChannel = $this->getCurrentUpdateChannelSetting();
$url = ManiaControl::URL_WEBSERVICE . 'versions?current=1&channel=' . $updateChannel; $url = ManiaControl::URL_WEBSERVICE . 'versions?current=1&channel=' . $updateChannel;
$this->maniaControl->getFileReader() $this->maniaControl->getFileReader()->loadFile($url, function ($dataJson, $error) use (&$function) {
->loadFile($url, function ($dataJson, $error) use (&$function) {
if ($error) { if ($error) {
Logger::logError('Error on UpdateCheck: ' . $error); Logger::logError('Error on UpdateCheck: ' . $error);
return; return;
@ -176,8 +161,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
* @return string * @return string
*/ */
public function getCurrentUpdateChannelSetting() { public function getCurrentUpdateChannelSetting() {
$updateChannel = $this->maniaControl->getSettingManager() $updateChannel = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_UPDATECHECK_CHANNEL);
->getSettingValue($this, self::SETTING_UPDATECHECK_CHANNEL);
$updateChannel = strtolower($updateChannel); $updateChannel = strtolower($updateChannel);
if (!in_array($updateChannel, $this->getUpdateChannels())) { if (!in_array($updateChannel, $this->getUpdateChannels())) {
$updateChannel = self::CHANNEL_RELEASE; $updateChannel = self::CHANNEL_RELEASE;
@ -275,8 +259,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
return false; return false;
} }
$version = $this->maniaControl->getClient() $version = $this->maniaControl->getClient()->getVersion();
->getVersion();
if ($updateData->minDedicatedBuild > $version->build) { if ($updateData->minDedicatedBuild > $version->build) {
// Server not compatible // Server not compatible
return false; return false;
@ -289,8 +272,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
* Check if an automatic Update should be performed * Check if an automatic Update should be performed
*/ */
public function checkAutoUpdate() { public function checkAutoUpdate() {
$autoUpdate = $this->maniaControl->getSettingManager() $autoUpdate = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_AUTO_UPDATE);
->getSettingValue($this, self::SETTING_AUTO_UPDATE);
if (!$autoUpdate) { if (!$autoUpdate) {
// Auto update turned off // Auto update turned off
return; return;
@ -299,8 +281,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
// No update available // No update available
return; return;
} }
if ($this->maniaControl->getPlayerManager() if ($this->maniaControl->getPlayerManager()->getPlayerCount(false) > 0
->getPlayerCount(false) > 0
) { ) {
// Server not empty // Server not empty
return; return;
@ -319,8 +300,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
if (!$this->coreUpdateData) { if (!$this->coreUpdateData) {
$message = 'Update failed: No update Data available!'; $message = 'Update failed: No update Data available!';
if ($player) { if ($player) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError($message, $player);
->sendError($message, $player);
} }
Logger::logError($message); Logger::logError($message);
return false; return false;
@ -332,34 +312,29 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
if (!FileUtil::checkWritePermissions($directories)) { if (!FileUtil::checkWritePermissions($directories)) {
$message = 'Update not possible: Incorrect File System Permissions!'; $message = 'Update not possible: Incorrect File System Permissions!';
if ($player) { if ($player) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError($message, $player);
->sendError($message, $player);
} }
Logger::logError($message); Logger::logError($message);
return false; return false;
} }
$performBackup = $this->maniaControl->getSettingManager() $performBackup = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PERFORM_BACKUPS);
->getSettingValue($this, self::SETTING_PERFORM_BACKUPS);
if ($performBackup && !BackupUtil::performFullBackup()) { if ($performBackup && !BackupUtil::performFullBackup()) {
$message = 'Creating Backup before Update failed!'; $message = 'Creating Backup before Update failed!';
if ($player) { if ($player) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError($message, $player);
->sendError($message, $player);
} }
Logger::logError($message); Logger::logError($message);
} }
$updateData = $this->coreUpdateData; $updateData = $this->coreUpdateData;
$this->maniaControl->getFileReader() $this->maniaControl->getFileReader()->loadFile($updateData->url, function ($updateFileContent, $error) use (
->loadFile($updateData->url, function ($updateFileContent, $error) use (
$updateData, &$player $updateData, &$player
) { ) {
if (!$updateFileContent || $error) { if (!$updateFileContent || $error) {
$message = "Update failed: Couldn't load Update zip! {$error}"; $message = "Update failed: Couldn't load Update zip! {$error}";
if ($player) { if ($player) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError($message, $player);
->sendError($message, $player);
} }
Logger::logError($message); Logger::logError($message);
return; return;
@ -369,8 +344,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
if (!$tempDir) { if (!$tempDir) {
$message = "Update failed: Can't save Update zip!"; $message = "Update failed: Can't save Update zip!";
if ($player) { if ($player) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError($message, $player);
->sendError($message, $player);
} }
Logger::logError($message); Logger::logError($message);
return; return;
@ -381,8 +355,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
if (!$bytes || $bytes <= 0) { if (!$bytes || $bytes <= 0) {
$message = "Update failed: Couldn't save Update zip!"; $message = "Update failed: Couldn't save Update zip!";
if ($player) { if ($player) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError($message, $player);
->sendError($message, $player);
} }
Logger::logError($message); Logger::logError($message);
return; return;
@ -393,8 +366,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
if ($result !== true) { if ($result !== true) {
$message = "Update failed: Couldn't open Update Zip. ({$result})"; $message = "Update failed: Couldn't open Update Zip. ({$result})";
if ($player) { if ($player) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError($message, $player);
->sendError($message, $player);
} }
Logger::logError($message); Logger::logError($message);
unlink($updateFileName); unlink($updateFileName);
@ -411,8 +383,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$message = 'Update finished!'; $message = 'Update finished!';
if ($player) { if ($player) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess($message, $player);
->sendSuccess($message, $player);
} }
Logger::log($message); Logger::log($message);
@ -445,18 +416,15 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
return; return;
} }
// Announce available update // Announce available update
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_UPDATE)
->checkPermission($player, self::SETTING_PERMISSION_UPDATE)
) { ) {
return; return;
} }
if ($this->isNightlyUpdateChannel()) { if ($this->isNightlyUpdateChannel()) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess('New Nightly Build (' . $this->coreUpdateData->releaseDate . ') available!', $player->login);
->sendSuccess('New Nightly Build (' . $this->coreUpdateData->releaseDate . ') available!', $player->login);
} else { } else {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation('New ManiaControl Version ' . $this->coreUpdateData->version . ' available!', $player->login);
->sendInformation('New ManiaControl Version ' . $this->coreUpdateData->version . ' available!', $player->login);
} }
} }
@ -476,24 +444,20 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
* @param Player $player * @param Player $player
*/ */
public function handle_CheckUpdate(array $chatCallback, Player $player) { public function handle_CheckUpdate(array $chatCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_UPDATECHECK)
->checkPermission($player, self::SETTING_PERMISSION_UPDATECHECK)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$player) { $this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$player) {
if (!$this->checkUpdateData($updateData)) { if (!$this->checkUpdateData($updateData)) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation('No Update available!', $player->login);
->sendInformation('No Update available!', $player->login);
return; return;
} }
if (!$this->checkUpdateDataBuildVersion($updateData)) { if (!$this->checkUpdateDataBuildVersion($updateData)) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError("Please update Your Server to '{$updateData->minDedicatedBuild}' in order to receive further Updates!", $player->login);
->sendError("Please update Your Server to '{$updateData->minDedicatedBuild}' in order to receive further Updates!", $player->login);
return; return;
} }
@ -502,20 +466,16 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$buildDate = $this->getNightlyBuildDate(); $buildDate = $this->getNightlyBuildDate();
if ($buildDate) { if ($buildDate) {
if ($updateData->isNewerThan($buildDate)) { if ($updateData->isNewerThan($buildDate)) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendInformation("No new Build available! (Current Build: '{$buildDate}')", $player->login);
->sendInformation("No new Build available! (Current Build: '{$buildDate}')", $player->login);
return; return;
} else { } else {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess("New Nightly Build ({$updateData->releaseDate}) available! (Current Build: '{$buildDate}')", $player->login);
->sendSuccess("New Nightly Build ({$updateData->releaseDate}) available! (Current Build: '{$buildDate}')", $player->login);
} }
} else { } else {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess("New Nightly Build ('{$updateData->releaseDate}') available!", $player->login);
->sendSuccess("New Nightly Build ('{$updateData->releaseDate}') available!", $player->login);
} }
} else { } else {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendSuccess('Update for Version ' . $updateData->version . ' available!', $player->login);
->sendSuccess('Update for Version ' . $updateData->version . ' available!', $player->login);
} }
$this->coreUpdateData = $updateData; $this->coreUpdateData = $updateData;
@ -529,23 +489,19 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
* @param Player $player * @param Player $player
*/ */
public function handle_CoreUpdate(array $chatCallback, Player $player) { public function handle_CoreUpdate(array $chatCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager() if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_UPDATE)
->checkPermission($player, self::SETTING_PERMISSION_UPDATE)
) { ) {
$this->maniaControl->getAuthenticationManager() $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
->sendNotAllowed($player);
return; return;
} }
$this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$player) { $this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$player) {
if (!$updateData) { if (!$updateData) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError('Update is currently not possible!', $player);
->sendError('Update is currently not possible!', $player);
return; return;
} }
if (!$this->checkUpdateDataBuildVersion($updateData)) { if (!$this->checkUpdateDataBuildVersion($updateData)) {
$this->maniaControl->getChat() $this->maniaControl->getChat()->sendError("The Next ManiaControl Update requires a newer Dedicated Server Version!", $player);
->sendError("The Next ManiaControl Update requires a newer Dedicated Server Version!", $player);
return; return;
} }

View File

@ -27,8 +27,7 @@ abstract class WebReader {
$response = $request->send(); $response = $request->send();
if (!is_null($function)) { if (!is_null($function)) {
$content = $response->getContent(); $content = $response->getContent();
$error = $response->getError() $error = $response->getError()->getMessage();
->getMessage();
call_user_func($function, $content, $error); call_user_func($function, $content, $error);
} }
return $response; return $response;
@ -42,9 +41,7 @@ abstract class WebReader {
*/ */
protected static function newRequest($url) { protected static function newRequest($url) {
$request = new Request($url); $request = new Request($url);
$request->getOptions() $request->getOptions()->set(CURLOPT_TIMEOUT, 10)->set(CURLOPT_HEADER, false) // don't display response header
->set(CURLOPT_TIMEOUT, 10)
->set(CURLOPT_HEADER, false) // don't display response header
->set(CURLOPT_CRLF, true) // linux line feed ->set(CURLOPT_CRLF, true) // linux line feed
->set(CURLOPT_ENCODING, '') // accept encoding ->set(CURLOPT_ENCODING, '') // accept encoding
->set(CURLOPT_USERAGENT, 'ManiaControl v' . ManiaControl::VERSION) // user-agent ->set(CURLOPT_USERAGENT, 'ManiaControl v' . ManiaControl::VERSION) // user-agent
@ -63,17 +60,14 @@ abstract class WebReader {
*/ */
public static function postUrl($url, $content = null, callable $function = null) { public static function postUrl($url, $content = null, callable $function = null) {
$request = static::newRequest($url); $request = static::newRequest($url);
$request->getOptions() $request->getOptions()->set(CURLOPT_POST, true); // post method
->set(CURLOPT_POST, true); // post method
if ($content) { if ($content) {
$request->getOptions() $request->getOptions()->set(CURLOPT_POSTFIELDS, $content); // post content field
->set(CURLOPT_POSTFIELDS, $content); // post content field
} }
$response = $request->send(); $response = $request->send();
if (!is_null($function)) { if (!is_null($function)) {
$content = $response->getContent(); $content = $response->getContent();
$error = $response->getError() $error = $response->getError()->getMessage();
->getMessage();
call_user_func($function, $content, $error); call_user_func($function, $content, $error);
} }
return $response; return $response;