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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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