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
+16-14Lines changed: 16 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,25 +2,23 @@
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
-
First you create a new GameSpyQuery instance, first argument is the IP address to query, second argument is the port to query
5
+
To query a server, you call the `GameSpyQuery::query()` function, first argument is the IP, second argument is the port
6
6
```php
7
-
$query = new GameSpyQuery("someserver.org", 19132);
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
10
10
```php
11
-
$query->query();
11
+
$query = GameSpyQuery::query("someserver.org", 19132, 5); // it will wait for 5 seconds, if there was no response it would close the connection
12
12
```
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:
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:
20
18
```php
21
19
$query->get("hostname"); // Server MOTD
22
-
$query->get("gametype"); // Game type, not sure what that means
23
-
$query->get("game_id"); // I think that's the game edition
20
+
$query->get("gametype"); // Game type, e.g SMP or CMP
21
+
$query->get("game_id"); // Game edition
24
22
$query->get("version"); // Version of minecraft the server is running on
25
23
$query->get("server_engine"); // Server software being used
26
24
$query->get("plugins"); // Plugins list with their version
@@ -30,6 +28,10 @@ $query->get("maxplayers"); // Max number of players
30
28
$query->get("whitelist"); // On if whitelist is turned on, otherwise off
31
29
$query->get("hostip"); // Host ip
32
30
$query->get("hostport"); // Host port
33
-
$query->get("players"); // List of online players names
31
+
$query->get("players"); // List of online players on the server
34
32
```
35
33
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($this->socket, $command, $length)){
118
+
if ($length !== fwrite($socket, $command, $length)){
115
119
thrownewGameSpyQueryException("Failed to write to socket");
116
120
}
117
121
118
-
$response = fread($this->socket, 4096);
122
+
$response = fread($socket, 4096);
119
123
120
124
if($response === false){
121
125
thrownewGameSpyQueryException("Failed to read from socket");
@@ -125,7 +129,7 @@ private function retrieveStatus(int $sessionId, int $challengeToken){
125
129
}
126
130
127
131
/**
128
-
* Gets data by it's key
132
+
* Gets data by its key
129
133
* @param string $key The key of the data you want to get
130
134
* @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
131
135
*/
@@ -156,15 +160,15 @@ public function get(string $key){
156
160
return$data[$pos + 1];
157
161
}
158
162
returnfalse;
159
-
163
+
160
164
}
161
165
}
162
166
163
167
/**
164
-
* @return string The raw status response from the server, or false if the status data is null
168
+
* @return string The raw status response from the server
0 commit comments