1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of GameQ. |
4
|
|
|
* |
5
|
|
|
* GameQ is free software; you can redistribute it and/or modify |
6
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
7
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
8
|
|
|
* (at your option) any later version. |
9
|
|
|
* |
10
|
|
|
* GameQ is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
* GNU Lesser General Public License for more details. |
14
|
|
|
* |
15
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
16
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace GameQ\Protocols; |
20
|
|
|
|
21
|
|
|
use GameQ\Exception\Protocol as Exception; |
22
|
|
|
use GameQ\Result; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* ARK: Survival Ascended Protocol Class |
26
|
|
|
* |
27
|
|
|
* Extends the EOS protocol and adds ARK-specific server response processing. |
28
|
|
|
* |
29
|
|
|
* @package GameQ\Protocols |
30
|
|
|
* @author H.Rouatbi |
31
|
|
|
*/ |
32
|
|
|
class Arksa extends Eos |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* The protocol being used |
36
|
|
|
* |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $protocol = 'arksa'; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Longer string name of this protocol class |
43
|
|
|
* |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
protected $name_long = 'ARK: Survival Ascended'; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* String name of this protocol class |
50
|
|
|
* |
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
protected $name = 'arksa'; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Grant type used for authentication |
57
|
|
|
* |
58
|
|
|
* @var string |
59
|
|
|
*/ |
60
|
|
|
protected $grant_type = 'client_credentials'; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Deployment ID for the game or application |
64
|
|
|
* |
65
|
|
|
* @var string |
66
|
|
|
*/ |
67
|
|
|
protected $deployment_id = 'ad9a8feffb3b4b2ca315546f038c3ae2'; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* User ID for authentication |
71
|
|
|
* |
72
|
|
|
* @var string |
73
|
|
|
*/ |
74
|
|
|
protected $user_id = 'xyza7891muomRmynIIHaJB9COBKkwj6n'; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* User secret key for authentication |
78
|
|
|
* |
79
|
|
|
* @var string |
80
|
|
|
*/ |
81
|
|
|
protected $user_secret = 'PP5UGxysEieNfSrEicaD1N2Bb3TdXuD7xHYcsdUHZ7s'; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Process the response from the EOS API and filter ARK-specific server data |
85
|
|
|
* |
86
|
|
|
* @return array |
87
|
|
|
* @throws Exception |
88
|
|
|
*/ |
89
|
|
|
public function processResponse() |
90
|
|
|
{ |
91
|
|
|
$server_data = parent::processResponse(); |
92
|
|
|
|
93
|
|
|
if (!$server_data) { |
94
|
|
|
throw new Exception('No server data received from EOS API.'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
// Filter by port to match server sessions |
98
|
|
|
$filtered = array_filter($server_data, function ($session) { |
99
|
|
|
return $session['attributes']['ADDRESSBOUND_s'] === "{$this->serverIp}:{$this->serverPortQuery}" || |
100
|
|
|
$session['attributes']['ADDRESSBOUND_s'] === "0.0.0.0:{$this->serverPortQuery}"; |
101
|
|
|
}); |
102
|
|
|
|
103
|
|
|
if (!$filtered) { |
104
|
|
|
throw new Exception('No matching sessions found for the specified port.'); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
$session = reset($filtered); |
108
|
|
|
|
109
|
|
|
$result = new Result(); |
110
|
|
|
|
111
|
|
|
// Add server items to the result object |
112
|
|
|
$result->add('hostname', isset($session['attributes']['CUSTOMSERVERNAME_s']) ? $session['attributes']['CUSTOMSERVERNAME_s'] : 'Unknown'); |
113
|
|
|
$result->add('mapname', isset($session['attributes']['MAPNAME_s']) ? $session['attributes']['MAPNAME_s'] : 'Unknown'); |
114
|
|
|
$result->add('password', isset($session['attributes']['SERVERPASSWORD_b']) ? $session['attributes']['SERVERPASSWORD_b'] : false); |
|
|
|
|
115
|
|
|
$result->add('numplayers', isset($session['totalPlayers']) ? $session['totalPlayers'] : 0); |
116
|
|
|
$result->add('maxplayers', isset($session['settings']['maxPublicPlayers']) ? $session['settings']['maxPublicPlayers'] : 0); |
117
|
|
|
$result->add('anticheat', isset($session['attributes']['SERVERUSESBATTLEYE_b']) ? $session['attributes']['SERVERUSESBATTLEYE_b'] : false); |
118
|
|
|
$result->add('allowJoinInProgress', isset($session['settings']['allowJoinInProgress']) ? $session['settings']['allowJoinInProgress'] : false); |
119
|
|
|
$result->add('day', isset($session['attributes']['DAYTIME_s']) ? $session['attributes']['DAYTIME_s'] : ''); |
120
|
|
|
$result->add('version', "v" . (isset($session['attributes']['BUILDID_s']) ? $session['attributes']['BUILDID_s'] : '0') . "." . (isset($session['attributes']['MINORBUILDID_s']) ? $session['attributes']['MINORBUILDID_s'] : '0')); |
121
|
|
|
$result->add('pve', isset($session['attributes']['SESSIONISPVE_l']) ? boolval($session['attributes']['SESSIONISPVE_l']) : false); |
122
|
|
|
$result->add('officialserver', isset($session['attributes']['OFFICIALSERVER_s']) ? boolval($session['attributes']['OFFICIALSERVER_s']) : false); |
123
|
|
|
|
124
|
|
|
// Return the final result |
125
|
|
|
return $result->fetch(); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|