You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+14-16Lines changed: 14 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,23 +2,25 @@
2
2
A query virion for Pocketmine-MP\
3
3
This virion uses GS4 to query servers which provides more info. Servers that don't have GS4 supported/enabled can't be queried using this virion, so you need to use another virion such as [libpmquery](https://github.com/jasonwynn10/libpmquery)
4
4
## Usage
5
-
To query a server, you call the `GameSpyQuery::query()` function, first argument is the IP, second argument is the port
5
+
First you create a new GameSpyQuery instance, first argument is the IP address to query, second argument is the port to query
$query = new GameSpyQuery("someserver.org", 19132);
8
8
```
9
-
There's an additional (optional) third argument which is the timeout, it's simply how long it will wait for a response before it closes the connection. The timeout is in seconds
9
+
Then we query the server
10
10
```php
11
-
$query = GameSpyQuery::query("someserver.org", 19132, 5); // it will wait for 5 seconds, if there was no response it would close the connection
11
+
$query->query();
12
12
```
13
-
After the query is done, it will return a `GameSpyQuery` instance
14
-
15
-
The `query()` function will throw a GameSpyQueryException if the destination IP and port can't be queried, so you need to surround it with a try-catch block
16
-
17
-
After that, use the `get()` function to get info about the server. List of all the data you can get:
13
+
You can also set a timeout in seconds (optional)
14
+
```php
15
+
$query->query(5);
16
+
```
17
+
The `query()` function will throw a GameSpyQueryException if the destination IP and port can't be queried, so you need to surround it with a try-catch block\
18
+
If everything worked correctly, you can use the `get()` function to get some info about the server\
19
+
List of the data you can get:
18
20
```php
19
21
$query->get("hostname"); // Server MOTD
20
-
$query->get("gametype"); // Game type, e.g SMP or CMP
21
-
$query->get("game_id"); // Game edition
22
+
$query->get("gametype"); // Game type, not sure what that means
23
+
$query->get("game_id"); // I think that's the game edition
22
24
$query->get("version"); // Version of minecraft the server is running on
23
25
$query->get("server_engine"); // Server software being used
24
26
$query->get("plugins"); // Plugins list with their version
@@ -28,10 +30,6 @@ $query->get("maxplayers"); // Max number of players
28
30
$query->get("whitelist"); // On if whitelist is turned on, otherwise off
29
31
$query->get("hostip"); // Host ip
30
32
$query->get("hostport"); // Host port
31
-
$query->get("players"); // List of online players on the server
33
+
$query->get("players"); // List of online players names
32
34
```
33
35
In case you want to get the raw response, you can use `getStatusRaw()`
34
-
35
-
## Notes
36
-
- Do NOT query a server on the main thread, use an AsyncTask instead
37
-
- The info returned by the server can be easily faked, e.g someone doesn't want people to see his highly classified core plugin name, so he removes that info from the query so no one can see it!
if ($length !== fwrite($socket, $command, $length)){
114
+
if ($length !== fwrite($this->socket, $command, $length)){
119
115
thrownewGameSpyQueryException("Failed to write to socket");
120
116
}
121
117
122
-
$response = fread($socket, 4096);
118
+
$response = fread($this->socket, 4096);
123
119
124
120
if($response === false){
125
121
thrownewGameSpyQueryException("Failed to read from socket");
@@ -129,7 +125,7 @@ private static function retrieveStatus($socket, int $sessionId, int $challengeTo
129
125
}
130
126
131
127
/**
132
-
* Gets data by its key
128
+
* Gets data by it's key
133
129
* @param string $key The key of the data you want to get
134
130
* @return string|string[]|bool The return can be either a string or an array, depending on what data you want to get. Returns false if the key can't be found
135
131
*/
@@ -160,15 +156,15 @@ public function get(string $key){
160
156
return$data[$pos + 1];
161
157
}
162
158
returnfalse;
163
-
159
+
164
160
}
165
161
}
166
162
167
163
/**
168
-
* @return string The raw status response from the server
164
+
* @return string The raw status response from the server, or false if the status data is null
0 commit comments