1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | namespace GameQ\Protocols; |
20: | |
21: | use GameQ\Exception\Protocol as Exception; |
22: | use GameQ\Result; |
23: | |
24: | |
25: | |
26: | |
27: | |
28: | |
29: | class Eco extends Http |
30: | { |
31: | |
32: | |
33: | |
34: | |
35: | |
36: | protected $packets = [ |
37: | self::PACKET_STATUS => "GET /frontpage HTTP/1.0\r\nAccept: */*\r\n\r\n", |
38: | ]; |
39: | |
40: | |
41: | |
42: | |
43: | |
44: | |
45: | protected $transport = self::TRANSPORT_TCP; |
46: | |
47: | |
48: | |
49: | |
50: | |
51: | |
52: | protected $protocol = 'eco'; |
53: | |
54: | |
55: | |
56: | |
57: | |
58: | |
59: | protected $name = 'eco'; |
60: | |
61: | |
62: | |
63: | |
64: | |
65: | |
66: | protected $name_long = "ECO Global Survival"; |
67: | |
68: | |
69: | |
70: | |
71: | |
72: | |
73: | protected $port_diff = 1; |
74: | |
75: | |
76: | |
77: | |
78: | |
79: | |
80: | protected $normalize = [ |
81: | |
82: | 'general' => [ |
83: | |
84: | 'dedicated' => 'dedicated', |
85: | 'hostname' => 'description', |
86: | 'maxplayers' => 'totalplayers', |
87: | 'numplayers' => 'onlineplayers', |
88: | 'password' => 'haspassword', |
89: | ], |
90: | ]; |
91: | |
92: | |
93: | |
94: | |
95: | |
96: | |
97: | |
98: | public function processResponse() |
99: | { |
100: | if (empty($this->packets_response)) { |
101: | return []; |
102: | } |
103: | |
104: | |
105: | preg_match('/\{(.*)\}/ms', implode('', $this->packets_response), $matches); |
106: | |
107: | |
108: | if (!isset($matches[0]) || ($json = json_decode($matches[0])) === null) { |
109: | throw new Exception("JSON response from Eco server is invalid."); |
110: | } |
111: | |
112: | $result = new Result(); |
113: | |
114: | |
115: | $result->add('dedicated', 1); |
116: | |
117: | foreach ($json->Info as $info => $setting) { |
118: | $result->add(strtolower($info), $setting); |
119: | } |
120: | |
121: | return $result->fetch(); |
122: | } |
123: | } |
124: | |