- 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

@ -76,16 +76,15 @@ class PlayerActions {
$chatMessage = false;
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
*
@ -110,11 +109,9 @@ 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
*
@ -167,7 +164,6 @@ class PlayerActions {
$this->maniaControl->log(Formatter::stripCodes($chatMessage));
}
/**
* Warn a Player
*
@ -262,7 +258,8 @@ class PlayerActions {
if ($target->isFakePlayer()) {
$success = $this->maniaControl->client->query('DisconnectFakePlayer', $target->login);
} else {
}
else {
$success = $this->maniaControl->client->query('Kick', $target->login, $message);
}
@ -313,13 +310,15 @@ class PlayerActions {
$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);
$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;
}
@ -373,8 +372,7 @@ 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;
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
*/
@ -25,13 +25,12 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
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,14 +50,13 @@ 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
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_BALANCE_TEAMS, $this, 'command_TeamBalance');
$itemQuad = new Quad_Icons128x32_1();
@ -278,7 +276,7 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
* @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
*/
@ -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
@ -55,6 +58,7 @@ class PlayerManager implements CallbackListener {
$this->playerCommands = new PlayerCommands($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);
@ -109,8 +113,8 @@ 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) {
$players = $this->maniaControl->client->getResponse();
foreach ($players as $playerItem) {
if ($playerItem['PlayerId'] <= 0) {
continue;
}
@ -139,12 +143,14 @@ class PlayerManager implements CallbackListener {
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!';
$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
@ -196,55 +202,50 @@ class PlayerManager implements CallbackListener {
}
/**
* 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
* @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 (!isset($this->players[$login])) return null;
$player = $this->players[$login];
unset($this->players[$login]);
if ($savePlayedTime) {
$this->updatePlayedTime($player);
}
@ -252,10 +253,9 @@ class PlayerManager implements CallbackListener {
}
/**
* 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) {
@ -325,7 +325,6 @@ class PlayerManager implements CallbackListener {
}
$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();