From a025211dfdb2494dd4a5041c5fdc648c59994d7e Mon Sep 17 00:00:00 2001 From: kremsy Date: Sun, 21 Jun 2015 21:45:52 +0200 Subject: [PATCH] started with simple usage doc --- changelog.txt | 2 +- core/Sockets/SocketManager.php | 2 +- core/Sockets/usage.txt | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 core/Sockets/usage.txt diff --git a/changelog.txt b/changelog.txt index e10627ff..bc39a2ab 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,7 +2,7 @@ #Additions - added changelog -- added SocketManager which acts like a webserver you can connect to and interact with ManiaControl +- added SocketManager which acts like a communication interface you can connect to and interact with ManiaControl (also thanks to TGYoshi for some help) - added "//removerights login" command - added new EchoManager which handles Interactions between different Controllers - It is possible to send an Echo command via the Method sendEcho, as message Parameter strings, objects or arrays can get used diff --git a/core/Sockets/SocketManager.php b/core/Sockets/SocketManager.php index d295eb92..020621ab 100644 --- a/core/Sockets/SocketManager.php +++ b/core/Sockets/SocketManager.php @@ -196,7 +196,7 @@ class SocketManager implements CallbackListener { $buffer = ''; $connection->on('data', function ($data) use (&$buffer, &$connection) { $buffer .= $data; - $arr = explode("\n", $buffer, 2); // much haxy. + $arr = explode("\n", $buffer, 2); while (count($arr) == 2 && strlen($arr[1]) >= (int) $arr[0]) { // received full message $len = (int) $arr[0]; diff --git a/core/Sockets/usage.txt b/core/Sockets/usage.txt new file mode 100644 index 00000000..28a6ff89 --- /dev/null +++ b/core/Sockets/usage.txt @@ -0,0 +1,34 @@ +Ingame you can activate the Socket Manager and set Password and Port of it. + +Sample Web Implementation + "getServerChat", "data" => ""); + + // Encode and Encrypt the Data + $data = json_encode(array("method" => "getServerChat", "data" => "")); + $data = openssl_encrypt($data, 'aes-192-cbc', 'YOUR_PASSWORD', OPENSSL_RAW_DATA, 'kZ2Kt0CzKUjN2MJX'); + + // Write the Data on the Socket + fwrite($socket, strlen($data) . "\n" . $data); + + + // Read Answer Data + $len = (int)fgets($socket); + echo $len; + while (!feof($socket) && strlen($buff) < $len) { + $buff .= fgets($socket, $len - strlen($buff) + 1); + } + + // Decrypt and Decode the Response Data + $data = openssl_decrypt($buff, 'aes-192-cbc', 'YOUR_PASSWORD', OPENSSL_RAW_DATA, 'kZ2Kt0CzKUjN2MJX'); + echo json_decode($data); + + //Close the Socket + fclose($socket); +?> \ No newline at end of file