begin new structure

This commit is contained in:
kremsy 2014-01-16 18:08:32 +01:00 committed by Steffen Schröder
parent 5a2d849137
commit af16f2ac8d
7 changed files with 88 additions and 94 deletions

View File

@ -11,12 +11,12 @@ class Chat {
/**
* Constants
*/
const SETTING_PREFIX = 'Messages Prefix';
const SETTING_PREFIX = 'Messages Prefix';
const SETTING_FORMAT_INFORMATION = 'Information Format';
const SETTING_FORMAT_SUCCESS = 'Success Format';
const SETTING_FORMAT_ERROR = 'Error Format';
const SETTING_FORMAT_USAGEINFO = 'UsageInfo Format';
const SETTING_FORMAT_SUCCESS = 'Success Format';
const SETTING_FORMAT_ERROR = 'Error Format';
const SETTING_FORMAT_USAGEINFO = 'UsageInfo Format';
/**
* Private properties
*/
@ -25,11 +25,11 @@ class Chat {
/**
* Construct chat utility
*
* @param ManiaControl $maniaControl
* @param ManiaControl $maniaControl
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
// Init settings
$this->maniaControl->settingManager->initSetting($this, self::SETTING_PREFIX, '» ');
$this->maniaControl->settingManager->initSetting($this, self::SETTING_FORMAT_INFORMATION, '$fff');
@ -41,14 +41,14 @@ class Chat {
/**
* Get prefix
*
* @param string|bool $prefix
* @param string|bool $prefix
* @return string
*/
private function getPrefix($prefix) {
if (is_string($prefix)) {
if(is_string($prefix)) {
return $prefix;
}
if ($prefix === true) {
if($prefix === true) {
return $this->maniaControl->settingManager->getSetting($this, self::SETTING_PREFIX);
}
return '';
@ -57,29 +57,29 @@ class Chat {
/**
* Send a chat message to the given login
*
* @param string $message
* @param string $login
* @param string|bool $prefix
* @param string $message
* @param string $login
* @param string|bool $prefix
* @return bool
*/
public function sendChat($message, $login = null, $prefix = true) {
if (!$this->maniaControl->client) {
if(!$this->maniaControl->client) {
return false;
}
$client = $this->maniaControl->client;
$client = $this->maniaControl->client;
$chatMessage = '$z$<' . $this->getPrefix($prefix) . $message . '$>$z';
if ($login === null) {
return $client->query('ChatSendServerMessage', $chatMessage);
if($login === null) {
return $client->chatSendServerMessage($chatMessage);
}
return $client->query('ChatSendServerMessageToLogin', $chatMessage, $login);
return $client->chatSendServerMessage($chatMessage, $login);
}
/**
* Send an information message to the given login
*
* @param string $message
* @param string $login
* @param string|bool $prefix
* @param string $message
* @param string $login
* @param string|bool $prefix
* @return bool
*/
public function sendInformation($message, $login = null, $prefix = true) {
@ -90,9 +90,9 @@ class Chat {
/**
* Send a success message to the given login
*
* @param string $message
* @param string $login
* @param string|bool $prefix
* @param string $message
* @param string $login
* @param string|bool $prefix
* @return bool
*/
public function sendSuccess($message, $login = null, $prefix = true) {
@ -103,9 +103,9 @@ class Chat {
/**
* Send an error message to the given login
*
* @param string $message
* @param string $login
* @param string|bool $prefix
* @param string $message
* @param string $login
* @param string|bool $prefix
* @return bool
*/
public function sendError($message, $login = null, $prefix = true) {
@ -116,9 +116,9 @@ class Chat {
/**
* Send an usage info message to the given login
*
* @param string $message
* @param string $login
* @param string|bool $prefix
* @param string $message
* @param string $login
* @param string|bool $prefix
* @return bool
*/
public function sendUsageInfo($message, $login = null, $prefix = false) {

View File

@ -127,18 +127,18 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
* @param bool $hideOnClick
* @return bool
*/
public function sendManialink($manialinkText, $logins = null, $timeout = 0, $hideOnClick = false) {
public function sendManialink($manialinkText, $logins = null, $timeout = 0, $hideOnClick = false) { //TODO imrpvoe
$manialinkText = (string)$manialinkText;
if(!$logins) {
return $this->maniaControl->client->query('SendDisplayManialinkPage', $manialinkText, $timeout, $hideOnClick);
if(!$logins) {//TODO check if null works?
return $this->maniaControl->client->sendDisplayManialinkPage(null, $manialinkText, $timeout, $hideOnClick);
}
if(is_string($logins)) {
return $this->maniaControl->client->query('SendDisplayManialinkPageToLogin', $logins, $manialinkText, $timeout, $hideOnClick);
return $this->maniaControl->client->sendDisplayManialinkPage(null, $logins, $manialinkText, $timeout, $hideOnClick);
}
if(is_array($logins)) {
$success = true;
foreach($logins as $login) {
$subSuccess = $this->maniaControl->client->query('SendDisplayManialinkPageToLogin', $login, $manialinkText, $timeout, $hideOnClick);
$subSuccess = $this->maniaControl->client->sendDisplayManialinkPage(null, $login, $manialinkText, $timeout, $hideOnClick);
if(!$subSuccess) {
$success = false;
}
@ -157,7 +157,7 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
* @return bool
*/
public function enableAltMenu(Player $player) {
return $this->maniaControl->client->query('TriggerModeScriptEvent', 'LibXmlRpc_EnableAltMenu', $player->login);
return $this->maniaControl->client->triggerModeScriptEvent('LibXmlRpc_EnableAltMenu', $player->login);
}
/**
@ -167,7 +167,7 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
* @return bool
*/
public function disableAltMenu(Player $player) {
return $this->maniaControl->client->query('TriggerModeScriptEvent', 'LibXmlRpc_DisableAltMenu', $player->login);
return $this->maniaControl->client->triggerModeScriptEvent('LibXmlRpc_DisableAltMenu', $player->login);
}
/**

View File

@ -37,27 +37,27 @@ class Map {
/**
* Create a new Map Object from Rpc Data
*
* @param array $rpc_infos
* @param \Maniaplanet\DedicatedServer\Structures\Map $mpMap
* @internal param \ManiaControl\ManiaControl $maniaControl
*/
public function __construct($rpc_infos = null) {
public function __construct($mpMap = null) {
$this->startTime = time();
if(!$rpc_infos) {
if(!$mpMap) {
return;
}
$this->name = FORMATTER::stripDirtyCodes($rpc_infos['Name']);
$this->uid = $rpc_infos['UId'];
$this->fileName = $rpc_infos['FileName'];
$this->authorLogin = $rpc_infos['Author'];
$this->environment = $rpc_infos['Environnement'];
$this->goldTime = $rpc_infos['GoldTime'];
$this->copperPrice = $rpc_infos['CopperPrice'];
$this->mapType = $rpc_infos['MapType'];
$this->mapStyle = $rpc_infos['MapStyle'];
$this->name = FORMATTER::stripDirtyCodes($mpMap->name);
$this->uid = $mpMap->uId;
$this->fileName = $mpMap->fileName;
$this->authorLogin = $mpMap->author;
$this->environment = $mpMap->environnement;
$this->goldTime = $mpMap->goldTime;
$this->copperPrice = $mpMap->copperPrice;
$this->mapType = $mpMap->mapType;
$this->mapStyle = $mpMap->mapStyle;
if(isset($rpc_infos['NbCheckpoints'])) {
$this->nbCheckpoints = $rpc_infos['NbCheckpoints'];
if(isset($mpMap->nbCheckpoints)) {
$this->nbCheckpoints = $mpMap->nbCheckpoints;
}
$this->authorNick = $this->authorLogin;

View File

@ -320,18 +320,17 @@ class MapManager implements CallbackListener {
* Updates the full Map list, needed on Init, addMap and on ShuffleMaps
*/
private function updateFullMapList() {
if(!$this->maniaControl->client->query('GetMapList', 100, 0)) {
if(!$maps = $this->maniaControl->client->getMapList(100, 0)) {
trigger_error("Couldn't fetch mapList. " . $this->maniaControl->getClientErrorText());
return null;
}
$tempList = array();
$maps = $this->maniaControl->client->getResponse();
foreach($maps as $rpcMap) {
if(array_key_exists($rpcMap["UId"], $this->maps)) {
if(array_key_exists($rpcMap->uId, $this->maps)) {
// Map already exists, only update index
$tempList[$rpcMap["UId"]] = $this->maps[$rpcMap["UId"]];
$tempList[$rpcMap->uId] = $this->maps[$rpcMap->uId];
} else { // Insert Map Object
$map = $this->initializeMap($rpcMap);
$tempList[$map->uid] = $map;
@ -351,13 +350,12 @@ class MapManager implements CallbackListener {
* @return bool
*/
private function fetchCurrentMap() {
if(!$this->maniaControl->client->query('GetCurrentMapInfo')) {
if(!$rpcMap = $this->maniaControl->client->getCurrentMapInfo()) {
trigger_error("Couldn't fetch map info. " . $this->maniaControl->getClientErrorText());
return false;
}
$rpcMap = $this->maniaControl->client->getResponse();
if(array_key_exists($rpcMap["UId"], $this->maps)) {
$this->currentMap = $this->maps[$rpcMap["UId"]];
if(array_key_exists($rpcMap->uId, $this->maps)) {
$this->currentMap = $this->maps[$rpcMap->uId];
return true;
}
$map = $this->initializeMap($rpcMap);
@ -469,13 +467,12 @@ class MapManager implements CallbackListener {
*/
public function addMapFromMx($mapId, $login, $update = false) {
// Check if ManiaControl can even write to the maps dir
if(!$this->maniaControl->client->query('GetMapsDirectory')) {
if(!$mapDir = $this->maniaControl->client->getMapsDirectory()) {
trigger_error("Couldn't get map directory. " . $this->maniaControl->getClientErrorText());
$this->maniaControl->chat->sendError("ManiaControl couldn't retrieve the maps directory.", $login);
return;
}
$mapDir = $this->maniaControl->client->getResponse();
if(!is_dir($mapDir)) {
trigger_error("ManiaControl doesn't have have access to the maps directory in '{$mapDir}'.");
$this->maniaControl->chat->sendError("ManiaControl doesn't have access to the maps directory.", $login);
@ -533,12 +530,12 @@ class MapManager implements CallbackListener {
// Check for valid map
$mapFileName = $downloadDirectory . '/' . $fileName;
if(!$this->maniaControl->client->query('CheckMapForCurrentServerParams', $mapFileName)) {
if(!$response = $this->maniaControl->client->checkMapForCurrentServerParams($mapFileName)) {
trigger_error("Couldn't check if map is valid ('{$mapFileName}'). " . $this->maniaControl->getClientErrorText());
$this->maniaControl->chat->sendError('Error checking map!', $login);
return;
}
$response = $this->maniaControl->client->getResponse();
if(!$response) {
// Invalid map type
$this->maniaControl->chat->sendError("Invalid map type.", $login);
@ -546,7 +543,7 @@ class MapManager implements CallbackListener {
}
// Add map to map list
if(!$this->maniaControl->client->query('InsertMap', $mapFileName)) {
if(!$this->maniaControl->client->insertMap($mapFileName)) {
$this->maniaControl->chat->sendError("Couldn't add map to match settings!", $login);
return;
}

View File

@ -112,14 +112,12 @@ class PlayerManager implements CallbackListener {
*/
public function onInit(array $callback) {
// Add all players
$this->maniaControl->client->query('GetPlayerList', 300, 0, 2);
$players = $this->maniaControl->client->getResponse();
$players = $this->maniaControl->client->getPlayerList(300, 0, 2);
foreach($players as $playerItem) {
if($playerItem['PlayerId'] <= 0) {
if($playerItem->playerId <= 0) {
continue;
}
$this->maniaControl->client->query('GetDetailedPlayerInfo', $playerItem['Login']);
$playerInfo = $this->maniaControl->client->getResponse();
$playerInfo = $this->maniaControl->client->getDetailedPlayerInfo($playerItem['Login']);
$player = new Player($playerInfo);
$this->addPlayer($player);
}
@ -134,9 +132,8 @@ class PlayerManager implements CallbackListener {
* @param array $callback
*/
public function playerConnect(array $callback) {
$login = $callback[1][0];
$this->maniaControl->client->query('GetDetailedPlayerInfo', $login);
$playerInfo = $this->maniaControl->client->getResponse();
$login = $callback[1][0];
$playerInfo = $this->maniaControl->client->getDetailedPlayerInfo($login);
$player = new Player($playerInfo);
$this->addPlayer($player);
@ -220,10 +217,9 @@ class PlayerManager implements CallbackListener {
if($player->index == $index) {
return $player;
} else {
return null;
}
}
return null;
}
/**

View File

@ -6,6 +6,7 @@ use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Structures\SystemInfos;
require_once __DIR__ . '/ServerCommands.php';
@ -59,11 +60,11 @@ class Server implements CallbackListener {
private function updateProperties() {
// System info
$systemInfo = $this->getSystemInfo();
$this->ip = $systemInfo['PublishedIp'];
$this->port = $systemInfo['Port'];
$this->p2pPort = $systemInfo['P2PPort'];
$this->login = $systemInfo['ServerLogin'];
$this->titleId = $systemInfo['TitleId'];
$this->ip = $systemInfo->publishedIp;
$this->port = $systemInfo->port;
$this->p2pPort = $systemInfo->p2PPort;
$this->login = $systemInfo->serverLogin;
$this->titleId = $systemInfo->titleId;
// Database index
$mysqli = $this->maniaControl->database->mysqli;
@ -231,7 +232,7 @@ class Server implements CallbackListener {
/**
* Fetch Server System Info
*
* @return array
* @return SystemInfos
*/
public function getSystemInfo() {
if(!$systemInfo = $this->maniaControl->client->getSystemInfo()) {
@ -309,7 +310,7 @@ class Server implements CallbackListener {
}
// Build file name
$map = $this->getMap(); //TODO does that work?=
$map = $this->getMap(); //TODO does that workm, where is the method?=
$gameMode = $this->getGameMode();
$time = time();
$fileName = "GhostReplays/Ghost.{$player->login}.{$gameMode}.{$time}.{$map['UId']}.Replay.Gbx";

View File

@ -64,16 +64,17 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
*/
public function handleOnInit(array $callback) {
//Check if Pause exists in current gamemode
$this->maniaControl->client->query('GetModeScriptInfo');
$scriptInfos = $this->maniaControl->client->getResponse();
$scriptInfos = $this->maniaControl->client->getModeScriptInfo();
$pauseExists = false;
foreach($scriptInfos["CommandDescs"] as $param) {
/*foreach($scriptInfos['commandDescs'] as $param) {
if($param['Name'] == "Command_ForceWarmUp") {
$pauseExists = true;
break;
}
}
}*/ //TODO temp
$pauseExists = true;
// Set Pause
if($pauseExists) {
$itemQuad = new Quad_Icons128x32_1();
@ -101,7 +102,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
}
$success = $this->maniaControl->client->query('CancelVote');
$success = $this->maniaControl->client->cancelVote();
if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
return;
@ -118,8 +119,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
* @param array $callback
*/
public function setPause(array $callback) {
$this->maniaControl->client->query('SendModeScriptCommands', array('Command_ForceWarmUp' => True));
$success = $this->maniaControl->client->getResponse();
$success = $this->maniaControl->client->sendModeScriptCommands(array('Command_ForceWarmUp' => True));
if(!$success) {
$this->maniaControl->chat->sendError("Error while setting the pause");
}
@ -220,7 +220,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
return;
}
$serverName = $params[1];
if(!$this->maniaControl->client->query('SetServerName', $serverName)) {
if(!$this->maniaControl->client->setServerName($serverName)) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
return;
}
@ -245,7 +245,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
$password = $messageParts[1];
$successMessage = "Password changed to: '{$password}'!";
}
$success = $this->maniaControl->client->query('SetServerPassword', $password);
$success = $this->maniaControl->client->setServerPassword($password);
if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
return;
@ -271,7 +271,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
$password = $messageParts[1];
$successMessage = "Spectator password changed to: '{$password}'!";
}
$success = $this->maniaControl->client->query('SetServerPasswordForSpectator', $password);
$success = $this->maniaControl->client->setServerPasswordForSpectator($password);
if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
return;
@ -304,7 +304,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
if($amount < 0) {
$amount = 0;
}
$success = $this->maniaControl->client->query('SetMaxPlayers', $amount);
$success = $this->maniaControl->client->setMaxPlayers($amount);
if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
return;
@ -337,7 +337,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
if($amount < 0) {
$amount = 0;
}
$success = $this->maniaControl->client->query('SetMaxSpectators', $amount);
$success = $this->maniaControl->client->setMaxSpectators($amount);
if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
return;
@ -352,7 +352,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
* @return bool
*/
private function shutdownServer($login = '#') {
if(!$this->maniaControl->client->query('StopServer')) {
if(!$this->maniaControl->client->stopServer()) {
trigger_error("Server shutdown command from '{login}' failed. " . $this->maniaControl->getClientErrorText());
return false;
}