- updates for new server properties

- refactored various imports
This commit is contained in:
Steffen Schröder 2014-01-06 16:14:49 +01:00
parent c3a2cd6122
commit c7d325c216
13 changed files with 251 additions and 268 deletions

View File

@ -395,8 +395,6 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
return false; return false;
} }
$serverIndex = $this->maniaControl->server->getIndex();
// Notifications // Notifications
$settingsCount = count($newSettings); $settingsCount = count($newSettings);
$settingIndex = 0; $settingIndex = 0;
@ -411,7 +409,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
} }
// Add To Database // Add To Database
$statement->bind_param('iss', $serverIndex, $setting, $value); $statement->bind_param('iss', $this->maniaControl->server->index, $setting, $value);
$statement->execute(); $statement->execute();
if($statement->error) { if($statement->error) {
trigger_error($statement->error); trigger_error($statement->error);

View File

@ -351,8 +351,6 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
return false; return false;
} }
$serverIndex = $this->maniaControl->server->getIndex();
// Notifications // Notifications
$settingsCount = count($newSettings); $settingsCount = count($newSettings);
$settingIndex = 0; $settingIndex = 0;
@ -360,7 +358,7 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
// $chatMessage = '$ff0' . $title . ' $<' . $player->nickname . '$> set ScriptSetting' . ($settingsCount > 1 ? 's' : '') . ' '; // $chatMessage = '$ff0' . $title . ' $<' . $player->nickname . '$> set ScriptSetting' . ($settingsCount > 1 ? 's' : '') . ' ';
foreach($newSettings as $setting => $value) { foreach($newSettings as $setting => $value) {
$statement->bind_param('iss', $serverIndex, $setting, $value); $statement->bind_param('iss', $this->maniaControl->server->index, $setting, $value);
$statement->execute(); $statement->execute();
if($statement->error) { if($statement->error) {
trigger_error($statement->error); trigger_error($statement->error);

View File

@ -34,14 +34,9 @@ require_once __DIR__ . '/ManiaExchange/mxinfofetcher.inc.php';
require_once __DIR__ . '/ManiaExchange/mxinfosearcher.inc.php'; require_once __DIR__ . '/ManiaExchange/mxinfosearcher.inc.php';
require_once __DIR__ . '/Manialinks/ManialinkManager.php'; require_once __DIR__ . '/Manialinks/ManialinkManager.php';
require_once __DIR__ . '/Statistics/StatisticManager.php'; require_once __DIR__ . '/Statistics/StatisticManager.php';
require_once __DIR__ . '/Maps/Map.php';
require_once __DIR__ . '/Maps/MapManager.php'; require_once __DIR__ . '/Maps/MapManager.php';
require_once __DIR__ . '/Maps/MapList.php';
require_once __DIR__ . '/Maps/MapQueue.php';
require_once __DIR__ . '/Players/PlayerManager.php'; require_once __DIR__ . '/Players/PlayerManager.php';
require_once __DIR__ . '/Players/PlayerActions.php';
require_once __DIR__ . '/Plugins/PluginManager.php'; require_once __DIR__ . '/Plugins/PluginManager.php';
require_once __DIR__ . '/Players/PlayerList.php';
require_once __DIR__ . '/Server/Server.php'; require_once __DIR__ . '/Server/Server.php';
require_once __DIR__ . '/Settings/SettingManager.php'; require_once __DIR__ . '/Settings/SettingManager.php';
require_once __DIR__ . '/UpdateManager.php'; require_once __DIR__ . '/UpdateManager.php';

View File

@ -2,9 +2,6 @@
namespace ManiaControl\Maps; namespace ManiaControl\Maps;
require_once __DIR__ . '/Map.php';
require_once __DIR__ . '/MapCommands.php';
use ManiaControl\FileUtil; use ManiaControl\FileUtil;
use ManiaControl\Formatter; use ManiaControl\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
@ -12,6 +9,11 @@ use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use MXInfoFetcher; use MXInfoFetcher;
require_once __DIR__ . '/Map.php';
require_once __DIR__ . '/MapCommands.php';
require_once __DIR__ . '/MapList.php';
require_once __DIR__ . '/MapQueue.php';
/** /**
* Manager for Maps * Manager for Maps
* *

View File

@ -22,11 +22,11 @@ class PlayerActions {
/** /**
* Constants * Constants
*/ */
const BLUE_TEAM = 0; const BLUE_TEAM = 0;
const RED_TEAM = 1; const RED_TEAM = 1;
const SPECTATOR_USER_SELECTABLE = 0; const SPECTATOR_USER_SELECTABLE = 0;
const SPECTATOR_SPECTATOR = 1; const SPECTATOR_SPECTATOR = 1;
const SPECTATOR_PLAYER = 2; const SPECTATOR_PLAYER = 2;
const SPECTATOR_BUT_KEEP_SELECTABLE = 3; const SPECTATOR_BUT_KEEP_SELECTABLE = 3;
/** /**
@ -48,59 +48,58 @@ class PlayerActions {
* *
* @param string $adminLogin * @param string $adminLogin
* @param string $targetLogin * @param string $targetLogin
* @param int $teamId * @param int $teamId
*/ */
public function forcePlayerToTeam($adminLogin, $targetLogin, $teamId) { public function forcePlayerToTeam($adminLogin, $targetLogin, $teamId) {
// TODO: get used by playercommands // TODO: get used by playercommands
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
if(!$admin || !$target) { if (!$admin || !$target) {
return; return;
} }
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
if($target->isSpectator) { if ($target->isSpectator) {
$success = $this->maniaControl->client->query('ForceSpectator', $target->login, self::SPECTATOR_PLAYER); $success = $this->maniaControl->client->query('ForceSpectator', $target->login, self::SPECTATOR_PLAYER);
if(!$success) { if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
} }
$success = $this->maniaControl->client->query('ForcePlayerTeam', $target->login, $teamId); $success = $this->maniaControl->client->query('ForcePlayerTeam', $target->login, $teamId);
if(!$success) { if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
$chatMessage = false; $chatMessage = false;
if($teamId == self::BLUE_TEAM) { if ($teamId == self::BLUE_TEAM) {
$chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Blue-Team!'; $chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Blue-Team!';
} else if($teamId == self::RED_TEAM) { }
else if ($teamId == self::RED_TEAM) {
$chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Red-Team!'; $chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Red-Team!';
} }
if(!$chatMessage) if (!$chatMessage) return;
return;
$this->maniaControl->chat->sendInformation($chatMessage); $this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log(Formatter::stripCodes($chatMessage)); $this->maniaControl->log(Formatter::stripCodes($chatMessage));
} }
/** /**
* Force a Player to Spectator * Force a Player to Spectator
* *
* @param string $adminLogin * @param string $adminLogin
* @param string $targetLogin * @param string $targetLogin
* @param int $spectatorState * @param int $spectatorState
*/ */
public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE, $releaseSlot = true) { public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE, $releaseSlot = true) {
// TODO: get used by playercommands // TODO: get used by playercommands
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
$success = $this->maniaControl->client->query('ForceSpectator', $targetLogin, $spectatorState); $success = $this->maniaControl->client->query('ForceSpectator', $targetLogin, $spectatorState);
if(!$success) { if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
@ -110,30 +109,28 @@ class PlayerActions {
$this->maniaControl->log(Formatter::stripCodes($chatMessage)); $this->maniaControl->log(Formatter::stripCodes($chatMessage));
// free player slot // free player slot
if($releaseSlot) if ($releaseSlot) $this->maniaControl->client->query('SpectatorReleasePlayerSlot', $target->login);
$this->maniaControl->client->query('SpectatorReleasePlayerSlot', $target->login);
} }
/** /**
* UnMutes a Player * UnMutes a Player
* *
* @param string $adminLogin * @param string $adminLogin
* @param string $targetLogin * @param string $targetLogin
* @param int $spectatorState * @param int $spectatorState
*/ */
public function unMutePlayer($adminLogin, $targetLogin) { public function unMutePlayer($adminLogin, $targetLogin) {
// TODO: playercommand // TODO: playercommand
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
$success = $this->maniaControl->client->query('UnIgnore', $targetLogin); $success = $this->maniaControl->client->query('UnIgnore', $targetLogin);
var_dump($success); var_dump($success);
var_dump($this->maniaControl->client->getResponse()); var_dump($this->maniaControl->client->getResponse());
if(!$success) { if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
@ -148,16 +145,16 @@ class PlayerActions {
* *
* @param string $adminLogin * @param string $adminLogin
* @param string $targetLogin * @param string $targetLogin
* @param int $spectatorState * @param int $spectatorState
*/ */
public function mutePlayer($adminLogin, $targetLogin) { public function mutePlayer($adminLogin, $targetLogin) {
// TODO: playercommand // TODO: playercommand
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
$success = $this->maniaControl->client->query('Ignore', $targetLogin); $success = $this->maniaControl->client->query('Ignore', $targetLogin);
if(!$success) { if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
@ -167,7 +164,6 @@ class PlayerActions {
$this->maniaControl->log(Formatter::stripCodes($chatMessage)); $this->maniaControl->log(Formatter::stripCodes($chatMessage));
} }
/** /**
* Warn a Player * Warn a Player
* *
@ -176,9 +172,9 @@ class PlayerActions {
*/ */
public function warnPlayer($adminLogin, $targetLogin) { public function warnPlayer($adminLogin, $targetLogin) {
// TODO: chatcommand // TODO: chatcommand
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
// display warning message // display warning message
$message = '$s$f00This is an administrative warning.{br}{br}$gWhatever you wrote or you have done is against {br} our server\'s policy. $message = '$s$f00This is an administrative warning.{br}{br}$gWhatever you wrote or you have done is against {br} our server\'s policy.
@ -186,9 +182,9 @@ class PlayerActions {
{br}{br}$gThe server administrators.'; {br}{br}$gThe server administrators.';
$message = preg_split('/{br}/', $message); $message = preg_split('/{br}/', $message);
$width = 80; $width = 80;
$height = 50; $height = 50;
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle(); $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle();
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle();
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID); $maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
@ -225,7 +221,7 @@ class PlayerActions {
$label->setTextColor('F00'); $label->setTextColor('F00');
$y = $height / 2 - 15; $y = $height / 2 - 15;
foreach($message as &$line) { foreach ($message as &$line) {
// Warn Labels // Warn Labels
$label = new Label_Text(); $label = new Label_Text();
$frame->add($label); $frame->add($label);
@ -256,17 +252,18 @@ class PlayerActions {
* @param string $message * @param string $message
*/ */
public function kickPlayer($adminLogin, $targetLogin, $message = '') { public function kickPlayer($adminLogin, $targetLogin, $message = '') {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
if($target->isFakePlayer()) { if ($target->isFakePlayer()) {
$success = $this->maniaControl->client->query('DisconnectFakePlayer', $target->login); $success = $this->maniaControl->client->query('DisconnectFakePlayer', $target->login);
} else { }
else {
$success = $this->maniaControl->client->query('Kick', $target->login, $message); $success = $this->maniaControl->client->query('Kick', $target->login, $message);
} }
if(!$success) { if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
@ -284,13 +281,13 @@ class PlayerActions {
* @param string $message * @param string $message
*/ */
public function banPlayer($adminLogin, $targetLogin, $message = '') { public function banPlayer($adminLogin, $targetLogin, $message = '') {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
$success = $this->maniaControl->client->query('Ban', $target->login, $message); $success = $this->maniaControl->client->query('Ban', $target->login, $message);
if(!$success) { if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
@ -305,28 +302,30 @@ class PlayerActions {
* *
* @param string $adminLogin * @param string $adminLogin
* @param string $targetLogin * @param string $targetLogin
* @param int $authLevel * @param int $authLevel
*/ */
public function grandAuthLevel($adminLogin, $targetLogin, $authLevel) { public function grandAuthLevel($adminLogin, $targetLogin, $authLevel) {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
if($this->maniaControl->authenticationManager->checkRight($target, $authLevel)) { if ($this->maniaControl->authenticationManager->checkRight($target, $authLevel)) {
$this->maniaControl->chat->sendError('This Player is already ' . $this->maniaControl->authenticationManager->getAuthLevelName($target->authLevel), $admin->login); $this->maniaControl->chat->sendError(
'This Player is already ' . $this->maniaControl->authenticationManager->getAuthLevelName($target->authLevel), $admin->login);
return; return;
} }
$authLevelName = $this->maniaControl->authenticationManager->getAuthLevelName($authLevel); $authLevelName = $this->maniaControl->authenticationManager->getAuthLevelName($authLevel);
if($this->maniaControl->authenticationManager->checkRight($admin, $authLevel) <= $this->maniaControl->authenticationManager->checkRight($target, $authLevel)) { if ($this->maniaControl->authenticationManager->checkRight($admin, $authLevel) <=
$this->maniaControl->authenticationManager->checkRight($target, $authLevel)) {
$this->maniaControl->chat->sendError('You don\'t have the permission to add a ' . $authLevelName . '!', $admin->login); $this->maniaControl->chat->sendError('You don\'t have the permission to add a ' . $authLevelName . '!', $admin->login);
return; return;
} }
$success = $this->maniaControl->authenticationManager->grantAuthLevel($target, $authLevel); $success = $this->maniaControl->authenticationManager->grantAuthLevel($target, $authLevel);
if(!$success) { if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
@ -343,18 +342,18 @@ class PlayerActions {
* @param string $targetLogin * @param string $targetLogin
*/ */
public function revokeAuthLevel($adminLogin, $targetLogin) { public function revokeAuthLevel($adminLogin, $targetLogin) {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
if($this->maniaControl->authenticationManager->checkRight($target, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)) { if ($this->maniaControl->authenticationManager->checkRight($target, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)) {
$this->maniaControl->chat->sendError('MasterAdmins can\'t be removed ', $admin->login); $this->maniaControl->chat->sendError('MasterAdmins can\'t be removed ', $admin->login);
return; return;
} }
$success = $this->maniaControl->authenticationManager->grantAuthLevel($target, AuthenticationManager::AUTH_LEVEL_PLAYER); $success = $this->maniaControl->authenticationManager->grantAuthLevel($target, AuthenticationManager::AUTH_LEVEL_PLAYER);
if(!$success) { if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
@ -372,9 +371,8 @@ class PlayerActions {
*/ */
public function isPlayerMuted($login) { public function isPlayerMuted($login) {
$this->maniaControl->client->query('GetIgnoreList', 100, 0); $this->maniaControl->client->query('GetIgnoreList', 100, 0);
foreach($this->maniaControl->client->getResponse() as $ignoredPlayers) { foreach ($this->maniaControl->client->getResponse() as $ignoredPlayers) {
if($ignoredPlayers["Login"] == $login) if ($ignoredPlayers["Login"] == $login) return true;
return true;
} }
return false; return false;
} }

View File

@ -12,7 +12,7 @@ use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Manialinks\ManialinkPageAnswerListener;
/** /**
* Class offering various admin commands related to players * Class offering various Admin Commands related to Players
* *
* @author steeffeen & kremsy * @author steeffeen & kremsy
*/ */
@ -20,18 +20,17 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
/** /**
* Constants * Constants
*/ */
const ACTION_BALANCE_TEAMS = 'PlayerCommands.BalanceTeams'; const ACTION_BALANCE_TEAMS = 'PlayerCommands.BalanceTeams';
const ACTION_OPEN_PLAYERLIST = 'PlayerCommands.OpenPlayerList'; const ACTION_OPEN_PLAYERLIST = 'PlayerCommands.OpenPlayerList';
const ACTION_CANCEL_VOTE = 'PlayerCommands.CancelVote'; const ACTION_CANCEL_VOTE = 'PlayerCommands.CancelVote';
/** /**
* Private properties * Private Properties
*/ */
private $maniaControl = null; private $maniaControl = null;
public $playerList = null;
/** /**
* Create a new server commands instance * Create a new Player Commands Instance
* *
* @param ManiaControl $maniaControl * @param ManiaControl $maniaControl
*/ */
@ -51,29 +50,28 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
$this->maniaControl->commandManager->registerCommandListener('removebot', $this, 'command_RemoveFakePlayers', true); $this->maniaControl->commandManager->registerCommandListener('removebot', $this, 'command_RemoveFakePlayers', true);
$this->maniaControl->commandManager->registerCommandListener('addbots', $this, 'command_AddFakePlayers', true); $this->maniaControl->commandManager->registerCommandListener('addbots', $this, 'command_AddFakePlayers', true);
$this->maniaControl->commandManager->registerCommandListener('removebots', $this, 'command_RemoveFakePlayers', true); $this->maniaControl->commandManager->registerCommandListener('removebots', $this, 'command_RemoveFakePlayers', true);
$this->maniaControl->commandManager->registerCommandListener('cancel', $this, 'command_CancelVote', true); //TODO remove in other class? // TODO: Move into another class
$this->maniaControl->commandManager->registerCommandListener('cancel', $this, 'command_CancelVote', true);
// Register for player chat commands // Register for player chat commands
$this->maniaControl->commandManager->registerCommandListener('player', $this, 'command_playerList'); $this->maniaControl->commandManager->registerCommandListener('player', $this, 'command_playerList');
$this->maniaControl->commandManager->registerCommandListener('players', $this, 'command_playerList'); $this->maniaControl->commandManager->registerCommandListener('players', $this, 'command_playerList');
$this->playerList = new PlayerList($this->maniaControl); // Action Balance Teams
//Action Balance Teams
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_BALANCE_TEAMS, $this, 'command_TeamBalance'); $this->maniaControl->manialinkManager->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->actionsMenu->addMenuItem($itemQuad, false, 9, 'Balance Teams'); $this->maniaControl->actionsMenu->addMenuItem($itemQuad, false, 9, 'Balance Teams');
//Action cancel Vote // Action cancel Vote
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CANCEL_VOTE, $this, 'command_cancelVote'); $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CANCEL_VOTE, $this, 'command_cancelVote');
$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->actionsMenu->addMenuItem($itemQuad, false, 6, 'Cancel Vote'); $this->maniaControl->actionsMenu->addMenuItem($itemQuad, false, 6, 'Cancel Vote');
//Action Open Playerlist // Action Open Playerlist
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_PLAYERLIST, $this, 'command_playerList'); $this->maniaControl->manialinkManager->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);
@ -84,16 +82,16 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
/** /**
* Handle //cancelvote command * Handle //cancelvote command
* *
* @param array $chatCallback * @param array $chatCallback
* @param Player $player * @param Player $player
*/ */
public function command_CancelVote(array $chatCallback, Player $player) { public function command_CancelVote(array $chatCallback, Player $player) {
if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
$success = $this->maniaControl->client->query('CancelVote'); $success = $this->maniaControl->client->query('CancelVote');
if(!$success) { if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
return; return;
} }
@ -103,16 +101,16 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
/** /**
* Handle //teambalance command * Handle //teambalance command
* *
* @param array $chatCallback * @param array $chatCallback
* @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->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
$success = $this->maniaControl->client->query('AutoTeamBalance'); $success = $this->maniaControl->client->query('AutoTeamBalance');
if(!$success) { if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
return; return;
} }
@ -122,27 +120,27 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
/** /**
* Handle //kick command * Handle //kick command
* *
* @param array $chat * @param array $chat
* @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->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chat[1][2], 3); $params = explode(' ', $chat[1][2], 3);
if(!isset($params[1])) { if (!isset($params[1])) {
$this->maniaControl->chat->sendUsageInfo('Usage example: //kick login', $player->login); $this->maniaControl->chat->sendUsageInfo('Usage example: //kick login', $player->login);
return; return;
} }
$target = $params[1]; $target = $params[1];
$target = $this->maniaControl->playerManager->getPlayer($target); $target = $this->maniaControl->playerManager->getPlayer($target);
if(!$target) { if (!$target) {
$this->maniaControl->chat->sendError("Invalid player login.", $player->login); $this->maniaControl->chat->sendError("Invalid player login.", $player->login);
return; return;
} }
$message = ''; $message = '';
if(isset($params[2])) { if (isset($params[2])) {
$message = $params[2]; $message = $params[2];
} }
@ -152,35 +150,35 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
/** /**
* Handle //forcespec command * Handle //forcespec command
* *
* @param array $chat * @param array $chat
* @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->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chat[1][2]); $params = explode(' ', $chat[1][2]);
if(!isset($params[1])) { if (!isset($params[1])) {
$this->maniaControl->chat->sendUsageInfo('Usage example: //forcespec login', $player->login); $this->maniaControl->chat->sendUsageInfo('Usage example: //forcespec login', $player->login);
return; return;
} }
$target = $params[1]; $target = $params[1];
$target = $this->maniaControl->playerManager->getPlayer($target); $target = $this->maniaControl->playerManager->getPlayer($target);
if(!$target) { if (!$target) {
$this->maniaControl->chat->sendError("Invalid player login.", $player->login); $this->maniaControl->chat->sendError("Invalid player login.", $player->login);
return; return;
} }
$type = 3; $type = 3;
if(isset($params[2]) && is_numeric($params[2])) { if (isset($params[2]) && is_numeric($params[2])) {
$type = intval($params[2]); $type = intval($params[2]);
} }
$success = $this->maniaControl->client->query('ForceSpectator', $target->login, $type); $success = $this->maniaControl->client->query('ForceSpectator', $target->login, $type);
if(!$success) { if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
return; return;
} }
if($type != 1) { if ($type != 1) {
$this->maniaControl->client->query('ForceSpectator', $target->login, 0); $this->maniaControl->client->query('ForceSpectator', $target->login, 0);
} }
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> forced $<' . $target->nickname . '$> to spectator!'); $this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> forced $<' . $target->nickname . '$> to spectator!');
@ -189,35 +187,35 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
/** /**
* Handle //forceplay command * Handle //forceplay command
* *
* @param array $chat * @param array $chat
* @param Player $player * @param Player $player
*/ */
public function command_ForcePlayer(array $chat, Player $player) { public function command_ForcePlayer(array $chat, Player $player) {
if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chat[1][2]); $params = explode(' ', $chat[1][2]);
if(!isset($params[1])) { if (!isset($params[1])) {
$this->maniaControl->chat->sendUsageInfo('Usage example: //forceplay login', $player->login); $this->maniaControl->chat->sendUsageInfo('Usage example: //forceplay login', $player->login);
return; return;
} }
$target = $params[1]; $target = $params[1];
$target = $this->maniaControl->playerManager->getPlayer($target); $target = $this->maniaControl->playerManager->getPlayer($target);
if(!$target) { if (!$target) {
$this->maniaControl->chat->sendError("Invalid player login.", $player->login); $this->maniaControl->chat->sendError("Invalid player login.", $player->login);
return; return;
} }
$type = 2; $type = 2;
if(isset($params[2]) && is_numeric($params[2])) { if (isset($params[2]) && is_numeric($params[2])) {
$type = intval($params[2]); $type = intval($params[2]);
} }
$success = $this->maniaControl->client->query('ForceSpectator', $target->login, 2); $success = $this->maniaControl->client->query('ForceSpectator', $target->login, 2);
if(!$success) { if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
return; return;
} }
if($type != 1) { if ($type != 1) {
$this->maniaControl->client->query('ForceSpectator', $target->login, 0); $this->maniaControl->client->query('ForceSpectator', $target->login, 0);
} }
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> forced $<' . $target->nickname . '$> to player!'); $this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> forced $<' . $target->nickname . '$> to player!');
@ -226,26 +224,26 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
/** /**
* Handle //addfakeplayers command * Handle //addfakeplayers command
* *
* @param array $chatCallback * @param array $chatCallback
* @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->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) { if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
$amount = 1; $amount = 1;
$messageParts = explode(' ', $chatCallback[1][2]); $messageParts = explode(' ', $chatCallback[1][2]);
if(isset($messageParts[1]) && is_numeric($messageParts[1])) { if (isset($messageParts[1]) && is_numeric($messageParts[1])) {
$amount = intval($messageParts[1]); $amount = intval($messageParts[1]);
} }
$success = true; $success = true;
for($i = 0; $i < $amount; $i++) { for ($i = 0; $i < $amount; $i++) {
if(!$this->maniaControl->client->query('ConnectFakePlayer')) { if (!$this->maniaControl->client->query('ConnectFakePlayer')) {
$success = false; $success = false;
} }
} }
if(!$success) { if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
return; return;
} }
@ -255,16 +253,16 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
/** /**
* Handle //removefakeplayers command * Handle //removefakeplayers command
* *
* @param array $chatCallback * @param array $chatCallback
* @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->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) { if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
$success = $this->maniaControl->client->query('DisconnectFakePlayer', '*'); $success = $this->maniaControl->client->query('DisconnectFakePlayer', '*');
if(!$success) { if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
return; return;
} }
@ -274,11 +272,11 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
/** /**
* Handle Player list command * Handle Player list command
* *
* @param array $chatCallback * @param array $chatCallback
* @param Player $player * @param Player $player
*/ */
public function command_playerList(array $chatCallback, Player $player) { public function command_playerList(array $chatCallback, Player $player) {
$this->playerList->addPlayerToShownList($player, PlayerList::SHOWN_MAIN_WINDOW); $this->maniaControl->playerManager->playerList->addPlayerToShownList($player, PlayerList::SHOWN_MAIN_WINDOW);
$this->playerList->showPlayerList($player); $this->maniaControl->playerManager->playerList->showPlayerList($player);
} }
} }

View File

@ -2,18 +2,20 @@
namespace ManiaControl\Players; namespace ManiaControl\Players;
require_once __DIR__ . '/Player.php';
require_once __DIR__ . '/PlayerCommands.php';
require_once __DIR__ . '/PlayerDetailed.php';
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Formatter; use ManiaControl\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Statistics\StatisticManager; use ManiaControl\Statistics\StatisticManager;
require_once __DIR__ . '/Player.php';
require_once __DIR__ . '/PlayerActions.php';
require_once __DIR__ . '/PlayerCommands.php';
require_once __DIR__ . '/PlayerDetailed.php';
require_once __DIR__ . '/PlayerList.php';
/** /**
* Class managing players * Class managing Players
* *
* @author kremsy & steeffeen * @author kremsy & steeffeen
*/ */
@ -21,14 +23,14 @@ class PlayerManager implements CallbackListener {
/** /**
* Constants * Constants
*/ */
const CB_PLAYERJOINED = 'PlayerManagerCallback.PlayerJoined'; const CB_PLAYERJOINED = 'PlayerManagerCallback.PlayerJoined';
const CB_PLAYERDISCONNECTED = 'PlayerManagerCallback.PlayerDisconnected'; const CB_PLAYERDISCONNECTED = 'PlayerManagerCallback.PlayerDisconnected';
const CB_ONINIT = 'PlayerManagerCallback.OnInit'; const CB_ONINIT = 'PlayerManagerCallback.OnInit';
const CB_PLAYERINFOCHANGED = 'PlayerManagerCallback.PlayerInfoChanged'; const CB_PLAYERINFOCHANGED = 'PlayerManagerCallback.PlayerInfoChanged';
const TABLE_PLAYERS = 'mc_players'; const TABLE_PLAYERS = 'mc_players';
const SETTING_JOIN_LEAVE_MESSAGES = 'Enable Join & Leave Messages'; const SETTING_JOIN_LEAVE_MESSAGES = 'Enable Join & Leave Messages';
const STAT_JOIN_COUNT = 'Joins'; const STAT_JOIN_COUNT = 'Joins';
const STAT_SERVERTIME = 'Servertime'; const STAT_SERVERTIME = 'Servertime';
/** /**
* Public Properties * Public Properties
@ -36,7 +38,8 @@ class PlayerManager implements CallbackListener {
public $playerActions = null; public $playerActions = null;
public $playerCommands = null; public $playerCommands = null;
public $playerDetailed = null; public $playerDetailed = null;
public $playerList = array(); public $playerList = null;
public $players = array();
/** /**
* Private Properties * Private Properties
@ -53,8 +56,9 @@ class PlayerManager implements CallbackListener {
$this->initTables(); $this->initTables();
$this->playerCommands = new PlayerCommands($maniaControl); $this->playerCommands = new PlayerCommands($maniaControl);
$this->playerActions = new PlayerActions($maniaControl); $this->playerActions = new PlayerActions($maniaControl);
$this->playerDetailed = new PlayerDetailed($maniaControl); $this->playerDetailed = new PlayerDetailed($maniaControl);
$this->playerList = new PlayerList($this->maniaControl);
// Init settings // Init settings
$this->maniaControl->settingManager->initSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES, true); $this->maniaControl->settingManager->initSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES, true);
@ -76,8 +80,8 @@ class PlayerManager implements CallbackListener {
* @return bool * @return bool
*/ */
private function initTables() { private function initTables() {
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;
$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) COLLATE utf8_unicode_ci NOT NULL, `login` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`nickname` varchar(150) COLLATE utf8_unicode_ci NOT NULL, `nickname` varchar(150) COLLATE utf8_unicode_ci NOT NULL,
@ -88,12 +92,12 @@ class PlayerManager implements CallbackListener {
UNIQUE KEY `login` (`login`) UNIQUE KEY `login` (`login`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Player Data' AUTO_INCREMENT=1;"; ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Player Data' AUTO_INCREMENT=1;";
$playerTableStatement = $mysqli->prepare($playerTableQuery); $playerTableStatement = $mysqli->prepare($playerTableQuery);
if($mysqli->error) { if ($mysqli->error) {
trigger_error($mysqli->error, E_USER_ERROR); trigger_error($mysqli->error, E_USER_ERROR);
return false; return false;
} }
$playerTableStatement->execute(); $playerTableStatement->execute();
if($playerTableStatement->error) { if ($playerTableStatement->error) {
trigger_error($playerTableStatement->error, E_USER_ERROR); trigger_error($playerTableStatement->error, E_USER_ERROR);
return false; return false;
} }
@ -109,14 +113,14 @@ class PlayerManager implements CallbackListener {
public function onInit(array $callback) { public function onInit(array $callback) {
// Add all players // Add all players
$this->maniaControl->client->query('GetPlayerList', 300, 0, 2); $this->maniaControl->client->query('GetPlayerList', 300, 0, 2);
$playerList = $this->maniaControl->client->getResponse(); $players = $this->maniaControl->client->getResponse();
foreach($playerList as $playerItem) { foreach ($players as $playerItem) {
if($playerItem['PlayerId'] <= 0) { if ($playerItem['PlayerId'] <= 0) {
continue; continue;
} }
$this->maniaControl->client->query('GetDetailedPlayerInfo', $playerItem['Login']); $this->maniaControl->client->query('GetDetailedPlayerInfo', $playerItem['Login']);
$playerInfo = $this->maniaControl->client->getResponse(); $playerInfo = $this->maniaControl->client->getResponse();
$player = new Player($playerInfo); $player = new Player($playerInfo);
$this->addPlayer($player); $this->addPlayer($player);
} }
@ -133,18 +137,20 @@ class PlayerManager implements CallbackListener {
$login = $callback[1][0]; $login = $callback[1][0];
$this->maniaControl->client->query('GetDetailedPlayerInfo', $login); $this->maniaControl->client->query('GetDetailedPlayerInfo', $login);
$playerInfo = $this->maniaControl->client->getResponse(); $playerInfo = $this->maniaControl->client->getResponse();
$player = new Player($playerInfo); $player = new Player($playerInfo);
$this->addPlayer($player); $this->addPlayer($player);
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer()) { if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer()) {
$string = array(0 => '$0f0Player', 1 => '$0f0Moderator', 2 => '$0f0Admin', 3 => '$0f0MasterAdmin', 4 => '$0f0MasterAdmin'); $string = array(0 => '$0f0Player', 1 => '$0f0Moderator', 2 => '$0f0Admin', 3 => '$0f0MasterAdmin', 4 => '$0f0MasterAdmin');
$chatMessage = '$s$0f0' . $string[$player->authLevel] . ' $fff' . $player->nickname . '$z$s$0f0 Nation:$fff ' . $player->getCountry() . ' $z$s$0f0joined!'; $chatMessage = '$s$0f0' . $string[$player->authLevel] . ' $fff' . $player->nickname . '$z$s$0f0 Nation:$fff ' . $player->getCountry() .
' $z$s$0f0joined!';
$this->maniaControl->chat->sendChat($chatMessage); $this->maniaControl->chat->sendChat($chatMessage);
$this->maniaControl->chat->sendInformation('This server uses ManiaControl v' . ManiaControl::VERSION . '!', $player->login); $this->maniaControl->chat->sendInformation('This server uses ManiaControl v' . ManiaControl::VERSION . '!', $player->login);
} }
$logMessage = "Player joined: {$player->login} / " . Formatter::stripCodes($player->nickname) . " Nation: " . $player->getCountry() . " IP: {$player->ipAddress}"; $logMessage = "Player joined: {$player->login} / " . Formatter::stripCodes($player->nickname) . " Nation: " . $player->getCountry() .
" IP: {$player->ipAddress}";
$this->maniaControl->log($logMessage); $this->maniaControl->log($logMessage);
// Trigger own PlayerJoined callback // Trigger own PlayerJoined callback
@ -157,21 +163,21 @@ class PlayerManager implements CallbackListener {
* @param array $callback * @param array $callback
*/ */
public function playerDisconnect(array $callback) { public function playerDisconnect(array $callback) {
$login = $callback[1][0]; $login = $callback[1][0];
$player = $this->removePlayer($login); $player = $this->removePlayer($login);
// Trigger own callback // Trigger own callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERDISCONNECTED, array(self::CB_PLAYERDISCONNECTED, $player)); $this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERDISCONNECTED, array(self::CB_PLAYERDISCONNECTED, $player));
if($player == null || $player->isFakePlayer()) { if ($player == null || $player->isFakePlayer()) {
return; return;
} }
$played = Formatter::formatTimeH(time() - $player->joinTime); $played = Formatter::formatTimeH(time() - $player->joinTime);
$logMessage = "Player left: {$player->login} / {$player->nickname} Playtime: {$played}"; $logMessage = "Player left: {$player->login} / {$player->nickname} Playtime: {$played}";
$this->maniaControl->log(Formatter::stripCodes($logMessage)); $this->maniaControl->log(Formatter::stripCodes($logMessage));
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES)) { if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES)) {
$this->maniaControl->chat->sendChat('$<' . $player->nickname . '$> $s$0f0has left the game'); $this->maniaControl->chat->sendChat('$<' . $player->nickname . '$> $s$0f0has left the game');
} }
} }
@ -183,86 +189,80 @@ class PlayerManager implements CallbackListener {
*/ */
public function playerInfoChanged(array $callback) { public function playerInfoChanged(array $callback) {
$player = $this->getPlayer($callback[1][0]['Login']); $player = $this->getPlayer($callback[1][0]['Login']);
if($player == null) { if ($player == null) {
return; return;
} }
$player->teamId = $callback[1][0]["TeamId"]; $player->teamId = $callback[1][0]["TeamId"];
$player->isSpectator = $callback[1][0]["SpectatorStatus"]; $player->isSpectator = $callback[1][0]["SpectatorStatus"];
$player->ladderRank = $callback[1][0]["LadderRanking"]; $player->ladderRank = $callback[1][0]["LadderRanking"];
// Trigger own callback // Trigger own callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERINFOCHANGED, array(self::CB_PLAYERINFOCHANGED)); $this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERINFOCHANGED, array(self::CB_PLAYERINFOCHANGED));
} }
/** /**
* Get the complete PlayerList * Get all Players
* *
* @return array * @return array
*/ */
public function getPlayers() { public function getPlayers() {
return $this->playerList; return $this->players;
} }
/** /**
* Get a Player from the PlayerList * Get a Player by Login
* *
* @param string $login * @param string $login
* @return Player * @return Player
*/ */
public function getPlayer($login) { public function getPlayer($login) {
if(!isset($this->playerList[$login])) { if (!isset($this->players[$login])) {
return null; return null;
} }
return $this->playerList[$login]; return $this->players[$login];
} }
/** /**
* Add a player to the PlayerList * Add a player
* *
* @param Player $player * @param Player $player
* @return bool * @return bool
*/ */
private function addPlayer(Player $player) { private function addPlayer(Player $player) {
if(!$player) {
return false;
}
$this->savePlayer($player); $this->savePlayer($player);
$this->playerList[$player->login] = $player; $this->players[$player->login] = $player;
return true; return true;
} }
/** /**
* Remove a Player from the PlayerList * Remove a Player
* *
* @param string $login * @param string $login
* @param bool $savePlayedTime * @param bool $savePlayedTime
* @return Player $player * @return Player $player
*/ */
private function removePlayer($login, $savePlayedTime = true) { private function removePlayer($login, $savePlayedTime = true) {
if(!isset($this->playerList[$login])) { if (!isset($this->players[$login])) return null;
return null; $player = $this->players[$login];
} unset($this->players[$login]);
$player = $this->playerList[$login]; if ($savePlayedTime) {
unset($this->playerList[$login]);
if($savePlayedTime) {
$this->updatePlayedTime($player); $this->updatePlayedTime($player);
} }
return $player; return $player;
} }
/** /**
* Save player in database and fill up object properties * Save player in Database and fill up Object Properties
* *
* @param Player $player * @param Player $player
* @internal param int $joinCount
* @return bool * @return bool
*/ */
private function savePlayer(Player &$player) { private function savePlayer(Player &$player) {
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;
// Save player // Save player
$playerQuery = "INSERT INTO `" . self::TABLE_PLAYERS . "` ( $playerQuery = "INSERT INTO `" . self::TABLE_PLAYERS . "` (
`login`, `login`,
`nickname`, `nickname`,
`path` `path`
@ -273,13 +273,13 @@ class PlayerManager implements CallbackListener {
`nickname` = VALUES(`nickname`), `nickname` = VALUES(`nickname`),
`path` = VALUES(`path`);"; `path` = VALUES(`path`);";
$playerStatement = $mysqli->prepare($playerQuery); $playerStatement = $mysqli->prepare($playerQuery);
if($mysqli->error) { if ($mysqli->error) {
trigger_error($mysqli->error); trigger_error($mysqli->error);
return false; return false;
} }
$playerStatement->bind_param('sss', $player->login, $player->nickname, $player->path); $playerStatement->bind_param('sss', $player->login, $player->nickname, $player->path);
$playerStatement->execute(); $playerStatement->execute();
if($playerStatement->error) { if ($playerStatement->error) {
trigger_error($playerStatement->error); trigger_error($playerStatement->error);
$playerStatement->close(); $playerStatement->close();
return false; return false;
@ -288,15 +288,15 @@ class PlayerManager implements CallbackListener {
$playerStatement->close(); $playerStatement->close();
// Get Player Auth Level from DB // Get Player Auth Level from DB
$playerQuery = "SELECT `authLevel` FROM `" . self::TABLE_PLAYERS . "` WHERE `index` = ?;"; $playerQuery = "SELECT `authLevel` FROM `" . self::TABLE_PLAYERS . "` WHERE `index` = ?;";
$playerStatement = $mysqli->prepare($playerQuery); $playerStatement = $mysqli->prepare($playerQuery);
if($mysqli->error) { if ($mysqli->error) {
trigger_error($mysqli->error); trigger_error($mysqli->error);
return false; return false;
} }
$playerStatement->bind_param('i', $player->index); $playerStatement->bind_param('i', $player->index);
$playerStatement->execute(); $playerStatement->execute();
if($playerStatement->error) { if ($playerStatement->error) {
trigger_error($playerStatement->error); trigger_error($playerStatement->error);
$playerStatement->close(); $playerStatement->close();
return false; return false;
@ -320,12 +320,11 @@ class PlayerManager implements CallbackListener {
* @return bool * @return bool
*/ */
private function updatePlayedTime(Player $player) { private function updatePlayedTime(Player $player) {
if(!$player) { if (!$player) {
return false; return false;
} }
$playedTime = time() - $player->joinTime; $playedTime = time() - $player->joinTime;
$serverIndex = $this->maniaControl->server->getIndex(); return $this->maniaControl->statisticManager->insertStat(self::STAT_SERVERTIME, $player, $this->maniaControl->server->index, $playedTime);
return $this->maniaControl->statisticManager->insertStat(self::STAT_SERVERTIME, $player, $serverIndex, $playedTime);
} }
} }

View File

@ -58,7 +58,7 @@ class ServerCommands implements CallbackListener, CommandListener {
public function each5Seconds(array $callback) { public function each5Seconds(array $callback) {
// Empty shutdown // Empty shutdown
if ($this->serverShutdownEmpty) { if ($this->serverShutdownEmpty) {
$players = $this->maniaControl->server->getPlayers(); $players = $this->maniaControl->playerManager->getPlayers();
if (count($players) <= 0) { if (count($players) <= 0) {
$this->shutdownServer('empty'); $this->shutdownServer('empty');
} }

View File

@ -90,9 +90,8 @@ class StatisticCollector implements CallbackListener {
//Write Shoot Data into database //Write Shoot Data into database
if($this->onShootArray[$login] > $this->maniaControl->settingManager->getSetting($this, self::SETTING_ON_SHOOT_PRESTORE)) { if($this->onShootArray[$login] > $this->maniaControl->settingManager->getSetting($this, self::SETTING_ON_SHOOT_PRESTORE)) {
$serverIndex = $this->maniaControl->server->getIndex();
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
$this->maniaControl->statisticManager->insertStat(self::STAT_ON_SHOOT, $player, $serverIndex, $this->onShootArray[$login]); $this->maniaControl->statisticManager->insertStat(self::STAT_ON_SHOOT, $player, $this->maniaControl->server->index, $this->onShootArray[$login]);
$this->onShootArray[$login] = 0; $this->onShootArray[$login] = 0;
} }
} }
@ -114,8 +113,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) {
$serverIndex = $this->maniaControl->server->getIndex(); $this->maniaControl->statisticManager->insertStat(self::STAT_ON_SHOOT, $player, $this->maniaControl->server->index, $this->onShootArray[$player->login]);
$this->maniaControl->statisticManager->insertStat(self::STAT_ON_SHOOT, $player, $serverIndex, $this->onShootArray[$player->login]);
} }
unset($this->onShootArray[$player->login]); unset($this->onShootArray[$player->login]);
} }

View File

@ -154,7 +154,7 @@ class StatisticManager {
if (!$statId) return false; if (!$statId) return false;
if ($serverIndex == -1) { if ($serverIndex == -1) {
$serverIndex = $this->maniaControl->server->getIndex(); $serverIndex = $this->maniaControl->server->index;
} }
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;

View File

@ -423,8 +423,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$message = 'Donation successful! Thanks.'; $message = 'Donation successful! Thanks.';
} }
$this->maniaControl->chat->sendSuccess($message, $login); $this->maniaControl->chat->sendSuccess($message, $login);
$serverIndex = $this->maniaControl->server->getIndex(); $this->maniaControl->statisticManager->insertStat(self::STAT_PLAYER_DONATIONS, $player, $this->maniaControl->server->index, $amount);
$this->maniaControl->statisticManager->insertStat(self::STAT_PLAYER_DONATIONS, $player, $serverIndex, $amount);
} }
} }
else { else {

View File

@ -272,8 +272,7 @@ class KarmaPlugin implements CallbackListener, Plugin {
$voted = $this->getPlayerVote($player, $map); $voted = $this->getPlayerVote($player, $map);
var_dump($voted); var_dump($voted);
if(!$voted){ if(!$voted){
$serverIndex = $this->maniaControl->server->getIndex(); $this->maniaControl->statisticManager->incrementStat(self::STAT_PLAYER_MAPVOTES, $player, $this->maniaControl->server->index);
$this->maniaControl->statisticManager->incrementStat(self::STAT_PLAYER_MAPVOTES, $player, $serverIndex);
} }
$success = $this->savePlayerVote($player, $map, $vote); $success = $this->savePlayerVote($player, $map, $vote);

View File

@ -358,8 +358,7 @@ class WidgetPlugin implements CallbackListener, Plugin {
$quad->setPosition($width / 2 - 4, -1.5, -0.5); $quad->setPosition($width / 2 - 4, -1.5, -0.5);
$quad->setSize(4, 4); $quad->setSize(4, 4);
$quad->setHAlign(Control::CENTER); $quad->setHAlign(Control::CENTER);
$serverLogin = $this->maniaControl->server->getLogin(); $quad->setManialink('mcontrol?favorite&' . $this->maniaControl->server->login);
$quad->setManialink('mcontrol?favorite&' . $serverLogin);
// Send manialink // Send manialink
$manialinkText = $maniaLink->render()->saveXML(); $manialinkText = $maniaLink->render()->saveXML();