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

@ -45,10 +45,10 @@ class Chat {
* @return string * @return string
*/ */
private function getPrefix($prefix) { private function getPrefix($prefix) {
if (is_string($prefix)) { if(is_string($prefix)) {
return $prefix; return $prefix;
} }
if ($prefix === true) { if($prefix === true) {
return $this->maniaControl->settingManager->getSetting($this, self::SETTING_PREFIX); return $this->maniaControl->settingManager->getSetting($this, self::SETTING_PREFIX);
} }
return ''; return '';
@ -63,15 +63,15 @@ class Chat {
* @return bool * @return bool
*/ */
public function sendChat($message, $login = null, $prefix = true) { public function sendChat($message, $login = null, $prefix = true) {
if (!$this->maniaControl->client) { if(!$this->maniaControl->client) {
return false; return false;
} }
$client = $this->maniaControl->client; $client = $this->maniaControl->client;
$chatMessage = '$z$<' . $this->getPrefix($prefix) . $message . '$>$z'; $chatMessage = '$z$<' . $this->getPrefix($prefix) . $message . '$>$z';
if ($login === null) { if($login === null) {
return $client->query('ChatSendServerMessage', $chatMessage); return $client->chatSendServerMessage($chatMessage);
} }
return $client->query('ChatSendServerMessageToLogin', $chatMessage, $login); return $client->chatSendServerMessage($chatMessage, $login);
} }
/** /**

View File

@ -127,18 +127,18 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
* @param bool $hideOnClick * @param bool $hideOnClick
* @return bool * @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; $manialinkText = (string)$manialinkText;
if(!$logins) { if(!$logins) {//TODO check if null works?
return $this->maniaControl->client->query('SendDisplayManialinkPage', $manialinkText, $timeout, $hideOnClick); return $this->maniaControl->client->sendDisplayManialinkPage(null, $manialinkText, $timeout, $hideOnClick);
} }
if(is_string($logins)) { 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)) { if(is_array($logins)) {
$success = true; $success = true;
foreach($logins as $login) { 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) { if(!$subSuccess) {
$success = false; $success = false;
} }
@ -157,7 +157,7 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
* @return bool * @return bool
*/ */
public function enableAltMenu(Player $player) { 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 * @return bool
*/ */
public function disableAltMenu(Player $player) { 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 * Create a new Map Object from Rpc Data
* *
* @param array $rpc_infos * @param \Maniaplanet\DedicatedServer\Structures\Map $mpMap
* @internal param \ManiaControl\ManiaControl $maniaControl * @internal param \ManiaControl\ManiaControl $maniaControl
*/ */
public function __construct($rpc_infos = null) { public function __construct($mpMap = null) {
$this->startTime = time(); $this->startTime = time();
if(!$rpc_infos) { if(!$mpMap) {
return; return;
} }
$this->name = FORMATTER::stripDirtyCodes($rpc_infos['Name']); $this->name = FORMATTER::stripDirtyCodes($mpMap->name);
$this->uid = $rpc_infos['UId']; $this->uid = $mpMap->uId;
$this->fileName = $rpc_infos['FileName']; $this->fileName = $mpMap->fileName;
$this->authorLogin = $rpc_infos['Author']; $this->authorLogin = $mpMap->author;
$this->environment = $rpc_infos['Environnement']; $this->environment = $mpMap->environnement;
$this->goldTime = $rpc_infos['GoldTime']; $this->goldTime = $mpMap->goldTime;
$this->copperPrice = $rpc_infos['CopperPrice']; $this->copperPrice = $mpMap->copperPrice;
$this->mapType = $rpc_infos['MapType']; $this->mapType = $mpMap->mapType;
$this->mapStyle = $rpc_infos['MapStyle']; $this->mapStyle = $mpMap->mapStyle;
if(isset($rpc_infos['NbCheckpoints'])) { if(isset($mpMap->nbCheckpoints)) {
$this->nbCheckpoints = $rpc_infos['NbCheckpoints']; $this->nbCheckpoints = $mpMap->nbCheckpoints;
} }
$this->authorNick = $this->authorLogin; $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 * Updates the full Map list, needed on Init, addMap and on ShuffleMaps
*/ */
private function updateFullMapList() { 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()); trigger_error("Couldn't fetch mapList. " . $this->maniaControl->getClientErrorText());
return null; return null;
} }
$tempList = array(); $tempList = array();
$maps = $this->maniaControl->client->getResponse();
foreach($maps as $rpcMap) { 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 // Map already exists, only update index
$tempList[$rpcMap["UId"]] = $this->maps[$rpcMap["UId"]]; $tempList[$rpcMap->uId] = $this->maps[$rpcMap->uId];
} else { // Insert Map Object } else { // Insert Map Object
$map = $this->initializeMap($rpcMap); $map = $this->initializeMap($rpcMap);
$tempList[$map->uid] = $map; $tempList[$map->uid] = $map;
@ -351,13 +350,12 @@ class MapManager implements CallbackListener {
* @return bool * @return bool
*/ */
private function fetchCurrentMap() { 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()); trigger_error("Couldn't fetch map info. " . $this->maniaControl->getClientErrorText());
return false; return false;
} }
$rpcMap = $this->maniaControl->client->getResponse(); if(array_key_exists($rpcMap->uId, $this->maps)) {
if(array_key_exists($rpcMap["UId"], $this->maps)) { $this->currentMap = $this->maps[$rpcMap->uId];
$this->currentMap = $this->maps[$rpcMap["UId"]];
return true; return true;
} }
$map = $this->initializeMap($rpcMap); $map = $this->initializeMap($rpcMap);
@ -469,13 +467,12 @@ class MapManager implements CallbackListener {
*/ */
public function addMapFromMx($mapId, $login, $update = false) { public function addMapFromMx($mapId, $login, $update = false) {
// Check if ManiaControl can even write to the maps dir // 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()); trigger_error("Couldn't get map directory. " . $this->maniaControl->getClientErrorText());
$this->maniaControl->chat->sendError("ManiaControl couldn't retrieve the maps directory.", $login); $this->maniaControl->chat->sendError("ManiaControl couldn't retrieve the maps directory.", $login);
return; return;
} }
$mapDir = $this->maniaControl->client->getResponse();
if(!is_dir($mapDir)) { if(!is_dir($mapDir)) {
trigger_error("ManiaControl doesn't have have access to the maps directory in '{$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); $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 // Check for valid map
$mapFileName = $downloadDirectory . '/' . $fileName; $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()); trigger_error("Couldn't check if map is valid ('{$mapFileName}'). " . $this->maniaControl->getClientErrorText());
$this->maniaControl->chat->sendError('Error checking map!', $login); $this->maniaControl->chat->sendError('Error checking map!', $login);
return; return;
} }
$response = $this->maniaControl->client->getResponse();
if(!$response) { if(!$response) {
// Invalid map type // Invalid map type
$this->maniaControl->chat->sendError("Invalid map type.", $login); $this->maniaControl->chat->sendError("Invalid map type.", $login);
@ -546,7 +543,7 @@ class MapManager implements CallbackListener {
} }
// Add map to map list // 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); $this->maniaControl->chat->sendError("Couldn't add map to match settings!", $login);
return; return;
} }

View File

@ -112,14 +112,12 @@ 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); $players = $this->maniaControl->client->getPlayerList(300, 0, 2);
$players = $this->maniaControl->client->getResponse();
foreach($players as $playerItem) { foreach($players as $playerItem) {
if($playerItem['PlayerId'] <= 0) { if($playerItem->playerId <= 0) {
continue; continue;
} }
$this->maniaControl->client->query('GetDetailedPlayerInfo', $playerItem['Login']); $playerInfo = $this->maniaControl->client->getDetailedPlayerInfo($playerItem['Login']);
$playerInfo = $this->maniaControl->client->getResponse();
$player = new Player($playerInfo); $player = new Player($playerInfo);
$this->addPlayer($player); $this->addPlayer($player);
} }
@ -135,8 +133,7 @@ class PlayerManager implements CallbackListener {
*/ */
public function playerConnect(array $callback) { public function playerConnect(array $callback) {
$login = $callback[1][0]; $login = $callback[1][0];
$this->maniaControl->client->query('GetDetailedPlayerInfo', $login); $playerInfo = $this->maniaControl->client->getDetailedPlayerInfo($login);
$playerInfo = $this->maniaControl->client->getResponse();
$player = new Player($playerInfo); $player = new Player($playerInfo);
$this->addPlayer($player); $this->addPlayer($player);
@ -220,11 +217,10 @@ class PlayerManager implements CallbackListener {
if($player->index == $index) { if($player->index == $index) {
return $player; return $player;
} else { }
}
return null; return null;
} }
}
}
/** /**
* Get a Player by Login * Get a Player by Login

View File

@ -6,6 +6,7 @@ use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Structures\SystemInfos;
require_once __DIR__ . '/ServerCommands.php'; require_once __DIR__ . '/ServerCommands.php';
@ -59,11 +60,11 @@ class Server implements CallbackListener {
private function updateProperties() { private function updateProperties() {
// System info // System info
$systemInfo = $this->getSystemInfo(); $systemInfo = $this->getSystemInfo();
$this->ip = $systemInfo['PublishedIp']; $this->ip = $systemInfo->publishedIp;
$this->port = $systemInfo['Port']; $this->port = $systemInfo->port;
$this->p2pPort = $systemInfo['P2PPort']; $this->p2pPort = $systemInfo->p2PPort;
$this->login = $systemInfo['ServerLogin']; $this->login = $systemInfo->serverLogin;
$this->titleId = $systemInfo['TitleId']; $this->titleId = $systemInfo->titleId;
// Database index // Database index
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;
@ -231,7 +232,7 @@ class Server implements CallbackListener {
/** /**
* Fetch Server System Info * Fetch Server System Info
* *
* @return array * @return SystemInfos
*/ */
public function getSystemInfo() { public function getSystemInfo() {
if(!$systemInfo = $this->maniaControl->client->getSystemInfo()) { if(!$systemInfo = $this->maniaControl->client->getSystemInfo()) {
@ -309,7 +310,7 @@ class Server implements CallbackListener {
} }
// Build file name // Build file name
$map = $this->getMap(); //TODO does that work?= $map = $this->getMap(); //TODO does that workm, where is the method?=
$gameMode = $this->getGameMode(); $gameMode = $this->getGameMode();
$time = time(); $time = time();
$fileName = "GhostReplays/Ghost.{$player->login}.{$gameMode}.{$time}.{$map['UId']}.Replay.Gbx"; $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) { public function handleOnInit(array $callback) {
//Check if Pause exists in current gamemode //Check if Pause exists in current gamemode
$this->maniaControl->client->query('GetModeScriptInfo'); $scriptInfos = $this->maniaControl->client->getModeScriptInfo();
$scriptInfos = $this->maniaControl->client->getResponse();
$pauseExists = false; $pauseExists = false;
foreach($scriptInfos["CommandDescs"] as $param) { /*foreach($scriptInfos['commandDescs'] as $param) {
if($param['Name'] == "Command_ForceWarmUp") { if($param['Name'] == "Command_ForceWarmUp") {
$pauseExists = true; $pauseExists = true;
break; break;
} }
} }*/ //TODO temp
$pauseExists = true;
// Set Pause // Set Pause
if($pauseExists) { if($pauseExists) {
$itemQuad = new Quad_Icons128x32_1(); $itemQuad = new Quad_Icons128x32_1();
@ -101,7 +102,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
$success = $this->maniaControl->client->query('CancelVote'); $success = $this->maniaControl->client->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;
@ -118,8 +119,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
* @param array $callback * @param array $callback
*/ */
public function setPause(array $callback) { public function setPause(array $callback) {
$this->maniaControl->client->query('SendModeScriptCommands', array('Command_ForceWarmUp' => True)); $success = $this->maniaControl->client->sendModeScriptCommands(array('Command_ForceWarmUp' => True));
$success = $this->maniaControl->client->getResponse();
if(!$success) { if(!$success) {
$this->maniaControl->chat->sendError("Error while setting the pause"); $this->maniaControl->chat->sendError("Error while setting the pause");
} }
@ -220,7 +220,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
return; return;
} }
$serverName = $params[1]; $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); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
return; return;
} }
@ -245,7 +245,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
$password = $messageParts[1]; $password = $messageParts[1];
$successMessage = "Password changed to: '{$password}'!"; $successMessage = "Password changed to: '{$password}'!";
} }
$success = $this->maniaControl->client->query('SetServerPassword', $password); $success = $this->maniaControl->client->setServerPassword($password);
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;
@ -271,7 +271,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
$password = $messageParts[1]; $password = $messageParts[1];
$successMessage = "Spectator password changed to: '{$password}'!"; $successMessage = "Spectator password changed to: '{$password}'!";
} }
$success = $this->maniaControl->client->query('SetServerPasswordForSpectator', $password); $success = $this->maniaControl->client->setServerPasswordForSpectator($password);
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;
@ -304,7 +304,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
if($amount < 0) { if($amount < 0) {
$amount = 0; $amount = 0;
} }
$success = $this->maniaControl->client->query('SetMaxPlayers', $amount); $success = $this->maniaControl->client->setMaxPlayers($amount);
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;
@ -337,7 +337,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
if($amount < 0) { if($amount < 0) {
$amount = 0; $amount = 0;
} }
$success = $this->maniaControl->client->query('SetMaxSpectators', $amount); $success = $this->maniaControl->client->setMaxSpectators($amount);
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;
@ -352,7 +352,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
* @return bool * @return bool
*/ */
private function shutdownServer($login = '#') { 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()); trigger_error("Server shutdown command from '{login}' failed. " . $this->maniaControl->getClientErrorText());
return false; return false;
} }