update mp api
This commit is contained in:
parent
9f2b4b143d
commit
34f5598f24
@ -104,14 +104,14 @@ class Client
|
||||
$this->socket = @fsockopen($hostname, $port, $errno, $errstr, $timeout);
|
||||
if (!$this->socket)
|
||||
{
|
||||
throw new Exception("transport error - could not open socket (error: $errno, $errstr)", -32300);
|
||||
throw new FatalException("transport error - could not open socket (error: $errno, $errstr)", FatalException::NOT_INITIALIZED);
|
||||
}
|
||||
// handshake
|
||||
$array_result = unpack('Vsize', fread($this->socket, 4));
|
||||
$size = $array_result['size'];
|
||||
if ($size > 64)
|
||||
{
|
||||
throw new Exception('transport error - wrong lowlevel protocol header', -32300);
|
||||
throw new FatalException('transport error - wrong lowlevel protocol header', FatalException::OTHER);
|
||||
}
|
||||
$handshake = fread($this->socket, $size);
|
||||
if ($handshake == 'GBXRemote 1')
|
||||
@ -124,7 +124,7 @@ class Client
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception('transport error - wrong lowlevel protocol version', -32300);
|
||||
throw new FatalException('transport error - wrong lowlevel protocol version', FatalException::OTHER);
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,7 +163,7 @@ class Client
|
||||
$r = fwrite($this->socket, $bytes);
|
||||
if ($r === false || $r == 0)
|
||||
{
|
||||
throw new Exception('Connection interupted');
|
||||
throw new FatalException('Connection interupted', FatalException::INTERRUPTED);
|
||||
}
|
||||
|
||||
$bytes_to_write -= $r;
|
||||
@ -191,7 +191,7 @@ class Client
|
||||
$contents = fread($this->socket, 4);
|
||||
if (strlen($contents) == 0)
|
||||
{
|
||||
throw new Exception('transport error - connection interrupted!', -32700);
|
||||
throw new FatalException('transport error - connection interrupted!', FatalException::INTERRUPTED);
|
||||
}
|
||||
$array_result = unpack('Vsize', $contents);
|
||||
$size = $array_result['size'];
|
||||
@ -202,7 +202,7 @@ class Client
|
||||
$contents = fread($this->socket, 8);
|
||||
if (strlen($contents) == 0)
|
||||
{
|
||||
throw new Exception('transport error - connection interrupted!', -32700);
|
||||
throw new FatalException('transport error - connection interrupted!', FatalException::INTERRUPTED);
|
||||
}
|
||||
$array_result = unpack('Vsize/Vhandle', $contents);
|
||||
$size = $array_result['size'];
|
||||
@ -217,12 +217,12 @@ class Client
|
||||
|
||||
if ($recvhandle == 0 || $size == 0)
|
||||
{
|
||||
throw new Exception('transport error - connection interrupted!', -32700);
|
||||
throw new FatalException('transport error - connection interrupted!', FatalException::INTERRUPTED);
|
||||
}
|
||||
|
||||
if ($size > SIZE_MAX)
|
||||
{
|
||||
throw new Exception("transport error - answer too big ($size)", -32700);
|
||||
throw new Exception("transport error - answer too big ($size)", Exception::ANWSER_TOO_BIG);
|
||||
}
|
||||
|
||||
self::$received += $size;
|
||||
@ -253,7 +253,7 @@ class Client
|
||||
if (!$this->message->parse())
|
||||
{
|
||||
// XML error
|
||||
throw new Exception('parse error. not well formed', -32700);
|
||||
throw new Exception('parse error. not well formed', Exception::OTHER);
|
||||
}
|
||||
// Is the message a fault?
|
||||
if ($this->message->messageType == 'fault')
|
||||
@ -272,15 +272,15 @@ class Client
|
||||
|
||||
if (!$this->socket || $this->protocol == 0)
|
||||
{
|
||||
throw new Exception('transport error - Client not initialized', -32300);
|
||||
throw new FatalException('transport error - Client not initialized', FatalException::NOT_INITIALIZED);
|
||||
}
|
||||
|
||||
$request = new Request($method, $args);
|
||||
|
||||
// Check if request is larger than 1024 Kbytes
|
||||
if ($request->getLength() > 1024*1024-8)
|
||||
if ($request->getLength() > 1024*1024-8)
|
||||
{
|
||||
throw new Exception('transport error - request too large!', -32700);
|
||||
throw new Exception('transport error - request too large!', Exception::REQUEST_TOO_BIG);
|
||||
}
|
||||
|
||||
$this->sendRequest($request);
|
||||
@ -295,14 +295,14 @@ class Client
|
||||
|
||||
if (!$this->socket || $this->protocol == 0)
|
||||
{
|
||||
throw new Exception('transport error - Client not initialized', -32300);
|
||||
throw new FatalException('transport error - Client not initialized', FatalException::NOT_INITIALIZED);
|
||||
}
|
||||
|
||||
$request = new Request($method, $args);
|
||||
|
||||
// Check if the request is greater than 1024 Kbytes to avoid errors
|
||||
// Check if the request is greater than 512 Kbytes to avoid errors
|
||||
// If the method is system.multicall, make two calls (possibly recursively)
|
||||
if ($request->getLength() > 1024*1024-8)
|
||||
if ($request->getLength() > 1024*1024-8)
|
||||
{
|
||||
if ($method == 'system.multicall' && isset($args[0]))
|
||||
{
|
||||
@ -310,7 +310,7 @@ class Client
|
||||
// If count is 1, query cannot be reduced
|
||||
if ($count < 2)
|
||||
{
|
||||
throw new Exception('transport error - request too large!', -32700);
|
||||
throw new Exception('transport error - request too large!', Exception::REQUEST_TOO_BIG);
|
||||
}
|
||||
$length = floor($count/2);
|
||||
|
||||
@ -324,7 +324,7 @@ class Client
|
||||
// If the method is not a multicall, just stop
|
||||
else
|
||||
{
|
||||
throw new Exception('transport error - request too large!', -32700);
|
||||
throw new Exception('transport error - request too large!', Exception::REQUEST_TOO_BIG);
|
||||
}
|
||||
}
|
||||
|
||||
@ -340,7 +340,7 @@ class Client
|
||||
function readCallbacks($timeout = 2000)
|
||||
{
|
||||
if (!$this->socket || $this->protocol == 0)
|
||||
throw new Exception('transport error - Client not initialized', -32300);
|
||||
throw new FatalException('transport error - Client not initialized', FatalException::NOT_INITIALIZED);
|
||||
if ($this->protocol == 1)
|
||||
return false;
|
||||
|
||||
@ -349,7 +349,7 @@ class Client
|
||||
$contents = '';
|
||||
$contents_length = 0;
|
||||
|
||||
@stream_set_timeout($this->socket, 0, 10000); // timeout 10 ms (to read available data)
|
||||
@stream_set_timeout($this->socket, 0, 100000); // timeout 10 ms (to read available data)
|
||||
// (assignment in arguments is forbidden since php 5.1.1)
|
||||
$read = array($this->socket);
|
||||
$write = NULL;
|
||||
@ -392,20 +392,19 @@ class Client
|
||||
$contents = fread($this->socket, 8);
|
||||
if (strlen($contents) == 0)
|
||||
{
|
||||
throw new Exception('transport error - connection interrupted!', -32700);
|
||||
throw new FatalException('transport error - connection interrupted!', FatalException::INTERRUPTED);
|
||||
}
|
||||
|
||||
$array_result = unpack('Vsize/Vhandle', $contents);
|
||||
$size = $array_result['size'];
|
||||
$recvhandle = $array_result['handle'];
|
||||
|
||||
if ($recvhandle == 0 || $size == 0)
|
||||
{
|
||||
throw new Exception('transport error - connection interrupted!', -32700);
|
||||
throw new FatalException('transport error - connection interrupted!', FatalException::INTERRUPTED);
|
||||
}
|
||||
if ($size > SIZE_MAX)
|
||||
{
|
||||
throw new Exception("transport error - answer too big ($size)", -32700);
|
||||
throw new Exception("transport error - answer too big ($size)", Exception::ANWSER_TOO_BIG);
|
||||
}
|
||||
|
||||
self::$received += $size;
|
||||
@ -470,4 +469,4 @@ class Client
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
@ -7,6 +7,11 @@
|
||||
|
||||
namespace Maniaplanet\DedicatedServer\Xmlrpc;
|
||||
|
||||
class Exception extends \Exception {}
|
||||
class Exception extends \Exception
|
||||
{
|
||||
const ANWSER_TOO_BIG = 1;
|
||||
const REQUEST_TOO_BIG = 2;
|
||||
const OTHER = 999;
|
||||
}
|
||||
|
||||
?>
|
@ -22,6 +22,7 @@ use ManiaControl\Statistics\StatisticManager;
|
||||
use ManiaControl\Update\UpdateManager;
|
||||
use Maniaplanet\DedicatedServer\Connection;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\FatalException;
|
||||
|
||||
require_once __DIR__ . '/Libs/Maniaplanet/DedicatedServer/Connection.php';
|
||||
require_once __DIR__ . '/Libs/GbxDataFetcher/gbxdatafetcher.inc.php';
|
||||
@ -276,7 +277,7 @@ class ManiaControl implements CommandListener {
|
||||
|
||||
// Register shutdown handler
|
||||
register_shutdown_function(array($this, 'handleShutdown'));
|
||||
|
||||
|
||||
// Connect to server
|
||||
$this->connect();
|
||||
|
||||
@ -307,13 +308,9 @@ class ManiaControl implements CommandListener {
|
||||
// Manager callbacks
|
||||
$this->callbackManager->manageCallbacks();
|
||||
|
||||
} catch(Exception $e) {
|
||||
if ($e->getMessage() == 'Connection interupted' || $e->getMessage() == 'transport error - connection interrupted!') {
|
||||
} catch(FatalException $e) {
|
||||
$this->quit($e->getMessage());
|
||||
return;
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
|
||||
// Manage FileReader
|
||||
$this->fileReader->appendData();
|
||||
@ -363,7 +360,6 @@ class ManiaControl implements CommandListener {
|
||||
try {
|
||||
$this->client = Connection::factory($host, $port, self::CONNECT_TIMEOUT, $login, $pass);
|
||||
} catch(Exception $e) {
|
||||
// TODO: is it even needed to try-catch here? we will crash anyways, YES to avoid a message report to mc website
|
||||
trigger_error("Couldn't authenticate on server with user '{$login}'! " . $e->getMessage(), E_USER_ERROR);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user