|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of GameQ. |
|
5
|
|
|
* |
|
6
|
|
|
* GameQ is free software; you can redistribute it and/or modify |
|
7
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
|
8
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
9
|
|
|
* (at your option) any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* GameQ is distributed in the hope that it will be useful, |
|
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14
|
|
|
* GNU Lesser General Public License for more details. |
|
15
|
|
|
* |
|
16
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
17
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace GameQ\Protocols; |
|
21
|
|
|
|
|
22
|
|
|
use GameQ\Exception\Protocol as Exception; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* GTA Five M Protocol Class |
|
26
|
|
|
* |
|
27
|
|
|
* Server base can be found at https://fivem.net/ |
|
28
|
|
|
* |
|
29
|
|
|
* Based on code found at https://github.com/LiquidObsidian/fivereborn-query |
|
30
|
|
|
* |
|
31
|
|
|
* @author Austin Bischoff <[email protected]> |
|
32
|
|
|
* |
|
33
|
|
|
* Adding FiveM Player List by |
|
34
|
|
|
* @author Jesse Lukas <[email protected]> |
|
35
|
|
|
*/ |
|
36
|
|
|
|
|
37
|
|
|
class CFXPlayers extends Http |
|
38
|
|
|
{ |
|
39
|
|
|
/** |
|
40
|
|
|
* Holds the real ip so we can overwrite it back |
|
41
|
|
|
* |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $realIp = null; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Holds the real port so we can overwrite it back |
|
48
|
|
|
* |
|
49
|
|
|
* @var int |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $realPortQuery = null; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Packets to send |
|
55
|
|
|
* |
|
56
|
|
|
* @var array |
|
57
|
|
|
*/ |
|
58
|
|
|
protected $packets = [ |
|
59
|
|
|
self::PACKET_STATUS => "GET /players.json HTTP/1.0\r\nAccept: */*\r\n\r\n", // Player List |
|
60
|
|
|
]; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* The protocol being used |
|
64
|
|
|
* |
|
65
|
|
|
* @var string |
|
66
|
|
|
*/ |
|
67
|
|
|
protected $protocol = 'cfxplayers'; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* String name of this protocol class |
|
71
|
|
|
* |
|
72
|
|
|
* @var string |
|
73
|
|
|
*/ |
|
74
|
|
|
protected $name = 'cfxplayers'; |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Longer string name of this protocol class |
|
78
|
|
|
* |
|
79
|
|
|
* @var string |
|
80
|
|
|
*/ |
|
81
|
|
|
protected $name_long = "cfxplayers"; |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Process the response |
|
85
|
|
|
* |
|
86
|
|
|
* @return array |
|
87
|
|
|
* @throws Exception |
|
88
|
|
|
*/ |
|
89
|
30 |
|
public function processResponse() |
|
90
|
|
|
{ |
|
91
|
|
|
// Make sure we have any players |
|
92
|
30 |
|
if (empty($this->packets_response)) { |
|
93
|
30 |
|
return []; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
// Implode and rip out the JSON |
|
97
|
|
|
preg_match('/\{(.*)\}/ms', implode('', $this->packets_response), $matches); |
|
98
|
|
|
|
|
99
|
|
|
// Return should be JSON, let's validate |
|
100
|
|
|
if (!isset($matches[0]) || ($json = json_decode($matches[0], true)) === null) { |
|
101
|
|
|
throw new Exception(__METHOD__ . " JSON response from Stationeers protocol is invalid."); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
// Return json as it should already be well formed |
|
105
|
|
|
return [ |
|
106
|
|
|
'players' => $json, |
|
107
|
|
|
]; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|