Skip to content

Commit ba6bb4b

Browse files
committed
Merge pull request #1 from gamenet/master
Get actual version
2 parents aed75c8 + dd54f41 commit ba6bb4b

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
}
1717
],
1818
"require": {
19-
"php": ">=5.4.0"
19+
"php": ">=5.4.0",
20+
"lstrojny/fxmlrpc": "~0.10",
21+
"egeloen/http-adapter": "~1.0"
2022
},
2123
"require-dev": {
2224
"phpunit/phpunit": ">=4.0.0"

lib/GameNet/Jabber/Mixins/UserTrait.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,8 @@ public function deleteUserFromGroup($user, $contact, $group)
439439
*/
440440
public function getConnectedUsers()
441441
{
442-
return $this->sendRequest('connected_users', []);
442+
$users = $this->sendRequest('connected_users', []);
443+
444+
return isset($users['connected_users']) ? $users['connected_users'] : [];
443445
}
444446
}

lib/GameNet/Jabber/RpcClient.php

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
*/
3232
namespace GameNet\Jabber;
3333

34+
use fXmlRpc\Client;
35+
use fXmlRpc\Serializer\NativeSerializer;
36+
use fXmlRpc\Transport\HttpAdapterTransport;
37+
use Ivory\HttpAdapter\CurlHttpAdapter;
38+
use Ivory\HttpAdapter\Configuration;
39+
3440
/**
3541
* Class RpcClient
3642
*
@@ -127,37 +133,29 @@ public function getTimeout()
127133

128134
protected function sendRequest($command, array $params)
129135
{
136+
$config = new Configuration();
137+
$config->setTimeout($this->getTimeout());
138+
$config->setUserAgent('GameNet');
139+
140+
$transport = new HttpAdapterTransport(new CurlHttpAdapter($config));
141+
$client = new Client($this->server, $transport, null, new NativeSerializer());
142+
130143
if ($this->username && $this->password) {
131144
$params = [
132145
['user' => $this->username, 'server' => $this->server, 'password' => $this->password], $params
133146
];
134147
}
135148

136-
$request = xmlrpc_encode_request($command, $params, ['encoding' => 'utf-8', 'escaping' => 'markup']);
137-
138-
$ch = curl_init();
139-
curl_setopt($ch, CURLOPT_URL, $this->server);
140-
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
141-
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
142-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
143-
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
144-
curl_setopt($ch, CURLOPT_HEADER, false);
145-
curl_setopt($ch, CURLOPT_POST, true);
146-
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
147-
curl_setopt($ch, CURLOPT_HTTPHEADER, ['User-Agent: GameNet', 'Content-Type: text/xml']);
148-
149-
$response = curl_exec($ch);
150-
curl_close($ch);
151-
152-
$xml = xmlrpc_decode($response);
153-
if (!$xml || xmlrpc_is_fault($xml)) {
154-
throw new \RuntimeException("Error execution command '$command'' with parameters " . var_export($params, true) . ". Response: $response");
149+
try {
150+
$result = $client->call($command, $params);
151+
} catch (\fXmlRpc\Exception\RuntimeException $e) {
152+
throw new \RuntimeException($e->getMessage(), $e->getCode(), $e);
155153
}
156154

157155
if ($this->debug) {
158-
var_dump($command, $params, $response);
156+
var_dump($command, $client->getPrependParams(), $client->getAppendParams(), $result);
159157
}
160158

161-
return $xml;
159+
return $result;
162160
}
163161
}

0 commit comments

Comments
 (0)