use new dedicated api
This commit is contained in:
parent
13fe48e4ce
commit
3ae50c9af6
@ -15,7 +15,9 @@ use ManiaControl\Players\PlayerManager;
|
|||||||
use ManiaControl\Plugins\PluginManager;
|
use ManiaControl\Plugins\PluginManager;
|
||||||
use ManiaControl\Server\Server;
|
use ManiaControl\Server\Server;
|
||||||
use ManiaControl\Statistics\StatisticManager;
|
use ManiaControl\Statistics\StatisticManager;
|
||||||
|
use Maniaplanet\DedicatedServer\Connection;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/Maniaplanet/DedicatedServer/Connection.php';
|
||||||
require_once __DIR__ . '/Callbacks/CallbackListener.php';
|
require_once __DIR__ . '/Callbacks/CallbackListener.php';
|
||||||
require_once __DIR__ . '/Commands/CommandListener.php';
|
require_once __DIR__ . '/Commands/CommandListener.php';
|
||||||
require_once __DIR__ . '/Manialinks/ManialinkPageAnswerListener.php';
|
require_once __DIR__ . '/Manialinks/ManialinkPageAnswerListener.php';
|
||||||
@ -71,10 +73,7 @@ class ManiaControl implements CommandListener {
|
|||||||
public $chat = null;
|
public $chat = null;
|
||||||
public $config = null;
|
public $config = null;
|
||||||
public $configurator = null;
|
public $configurator = null;
|
||||||
/**
|
/** @var Connection $client */
|
||||||
*
|
|
||||||
* @var \IXR_ClientMulticall_Gbx
|
|
||||||
*/
|
|
||||||
public $client = null;
|
public $client = null;
|
||||||
public $commandManager = null;
|
public $commandManager = null;
|
||||||
public $database = null;
|
public $database = null;
|
||||||
@ -166,10 +165,12 @@ class ManiaControl implements CommandListener {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getClientErrorText($client = null) {
|
public function getClientErrorText($client = null) {
|
||||||
if(is_object($client)) {
|
/*if(is_object($client)) {
|
||||||
return $client->getErrorMessage() . ' (' . $client->getErrorCode() . ')';
|
return $client->getErrorMessage() . ' (' . $client->getErrorCode() . ')';
|
||||||
}
|
}
|
||||||
return $this->client->getErrorMessage() . ' (' . $this->client->getErrorCode() . ')';
|
return $this->client->getErrorMessage() . ' (' . $this->client->getErrorCode() . ')';*/
|
||||||
|
//TODO
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -234,10 +235,13 @@ class ManiaControl implements CommandListener {
|
|||||||
$this->chat->sendInformation('ManiaControl shutting down.');
|
$this->chat->sendInformation('ManiaControl shutting down.');
|
||||||
|
|
||||||
// Hide manialinks
|
// Hide manialinks
|
||||||
$this->client->query('SendHideManialinkPage');
|
$this->client->sendHideManialinkPage();
|
||||||
|
|
||||||
|
|
||||||
|
//TODO: $this->client->delete()
|
||||||
|
|
||||||
// Close connection
|
// Close connection
|
||||||
$this->client->Terminate();
|
//$this->client->Terminate();
|
||||||
|
|
||||||
$this->log('Quitting ManiaControl!');
|
$this->log('Quitting ManiaControl!');
|
||||||
exit();
|
exit();
|
||||||
@ -259,10 +263,10 @@ class ManiaControl implements CommandListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Hide widgets
|
// Hide widgets
|
||||||
$this->client->query('SendHideManialinkPage');
|
$this->client->sendHideManialinkPage();
|
||||||
|
|
||||||
// Close connection
|
// Close connection
|
||||||
$this->client->Terminate();
|
//$this->client->Terminate(); //TODO
|
||||||
|
|
||||||
$this->log('Restarting ManiaControl!');
|
$this->log('Restarting ManiaControl!');
|
||||||
|
|
||||||
@ -322,7 +326,7 @@ class ManiaControl implements CommandListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Close the client connection
|
//Close the client connection
|
||||||
$this->client->Terminate();
|
//$this->client->Terminate();
|
||||||
|
|
||||||
// Shutdown
|
// Shutdown
|
||||||
$this->quit();
|
$this->quit();
|
||||||
@ -333,8 +337,6 @@ class ManiaControl implements CommandListener {
|
|||||||
*/
|
*/
|
||||||
private function connect() {
|
private function connect() {
|
||||||
// Load remote client
|
// Load remote client
|
||||||
$this->client = new \IXR_ClientMulticall_Gbx();
|
|
||||||
|
|
||||||
$host = $this->config->server->xpath('host');
|
$host = $this->config->server->xpath('host');
|
||||||
if(!$host) {
|
if(!$host) {
|
||||||
trigger_error("Invalid server configuration (host).", E_USER_ERROR);
|
trigger_error("Invalid server configuration (host).", E_USER_ERROR);
|
||||||
@ -348,11 +350,6 @@ class ManiaControl implements CommandListener {
|
|||||||
|
|
||||||
$this->log("Connecting to server at {$host}:{$port}...");
|
$this->log("Connecting to server at {$host}:{$port}...");
|
||||||
|
|
||||||
// Connect
|
|
||||||
if(!$this->client->InitWithIp($host, $port, 20)) {
|
|
||||||
trigger_error("Couldn't connect to server! " . $this->getClientErrorText(), E_USER_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
$login = $this->config->server->xpath('login');
|
$login = $this->config->server->xpath('login');
|
||||||
if(!$login) {
|
if(!$login) {
|
||||||
trigger_error("Invalid server configuration (login).", E_USER_ERROR);
|
trigger_error("Invalid server configuration (login).", E_USER_ERROR);
|
||||||
@ -364,13 +361,14 @@ class ManiaControl implements CommandListener {
|
|||||||
}
|
}
|
||||||
$pass = (string)$pass[0];
|
$pass = (string)$pass[0];
|
||||||
|
|
||||||
// Authenticate
|
//TODO timeout as constant
|
||||||
if(!$this->client->query('Authenticate', $login, $pass)) {
|
$this->client = Connection::factory($host, $port, 20, $login, $pass);
|
||||||
|
if($this->client == null) {
|
||||||
trigger_error("Couldn't authenticate on server with user '{$login}'! " . $this->getClientErrorText(), E_USER_ERROR);
|
trigger_error("Couldn't authenticate on server with user '{$login}'! " . $this->getClientErrorText(), E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable callback system
|
// Enable callback system
|
||||||
if(!$this->client->query('EnableCallbacks', true)) {
|
if(!$this->client->enableCallbacks(true)) {
|
||||||
trigger_error("Couldn't enable callbacks! " . $this->getClientErrorText(), E_USER_ERROR);
|
trigger_error("Couldn't enable callbacks! " . $this->getClientErrorText(), E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -380,30 +378,32 @@ class ManiaControl implements CommandListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set api version
|
// Set api version
|
||||||
if(!$this->client->query('SetApiVersion', self::API_VERSION)) {
|
/* if(!$this->client->query('SetApiVersion', self::API_VERSION)) {
|
||||||
trigger_error("Couldn't set API version '" . self::API_VERSION . "'! This might cause problems. " . $this->getClientErrorText());
|
trigger_error("Couldn't set API version '" . self::API_VERSION . "'! This might cause problems. " . $this->getClientErrorText());
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// Connect finished
|
// Connect finished
|
||||||
$this->log("Server Connection successfully established!");
|
$this->log("Server Connection successfully established!");
|
||||||
|
|
||||||
// Hide old widgets
|
// Hide old widgets
|
||||||
$this->client->query('SendHideManialinkPage');
|
$this->client->sendHideManialinkPage();
|
||||||
|
//$this->client->query('SendHideManialinkPage');
|
||||||
|
|
||||||
// Enable script callbacks if needed
|
// Enable script callbacks if needed
|
||||||
if($this->server->getGameMode() != 0) {
|
if($this->server->getGameMode() != 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!$this->client->query('GetModeScriptSettings')) {
|
if(!$scriptSettings = $this->client->getModeScriptSettings()) {
|
||||||
trigger_error("Couldn't get mode script settings. " . $this->getClientErrorText());
|
trigger_error("Couldn't get mode script settings. " . $this->getClientErrorText());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$scriptSettings = $this->client->getResponse();
|
|
||||||
if(!array_key_exists('S_UseScriptCallbacks', $scriptSettings)) {
|
if(!array_key_exists('S_UseScriptCallbacks', $scriptSettings)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$scriptSettings['S_UseScriptCallbacks'] = true;
|
$scriptSettings['S_UseScriptCallbacks'] = true;
|
||||||
if(!$this->client->query('SetModeScriptSettings', $scriptSettings)) {
|
if(!$this->client->setModeScriptSettings($scriptSettings)) {
|
||||||
trigger_error("Couldn't set mode script settings to enable script callbacks. " . $this->getClientErrorText());
|
trigger_error("Couldn't set mode script settings to enable script callbacks. " . $this->getClientErrorText());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user