1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace eXpansion\Framework\Core\Storage; |
4
|
|
|
|
5
|
|
|
use eXpansion\Framework\Core\Helpers\CompatibleFetcher; |
6
|
|
|
use eXpansion\Framework\Core\Helpers\Countries; |
7
|
|
|
use Maniaplanet\DedicatedServer\Structures\GameInfos; |
8
|
|
|
use Maniaplanet\DedicatedServer\Structures\PlayerDetailedInfo; |
9
|
|
|
use Maniaplanet\DedicatedServer\Structures\ServerOptions; |
10
|
|
|
use Maniaplanet\DedicatedServer\Structures\SystemInfos; |
11
|
|
|
use Maniaplanet\DedicatedServer\Structures\Version; |
12
|
|
|
use oliverde8\AssociativeArraySimplified\AssociativeArray; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class GameDataStorage |
16
|
|
|
* |
17
|
|
|
* @author de Cramer Oliver<[email protected]> |
18
|
|
|
* @copyright 2017 eXpansion |
19
|
|
|
* @package eXpansion\Framework\Core\Storage |
20
|
|
|
*/ |
21
|
|
|
class GameDataStorage |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Constant used for unknown game modes. |
25
|
|
|
*/ |
26
|
|
|
const GAME_MODE_CODE_UNKNOWN = 'unknown'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Constants for the operating system. |
30
|
|
|
*/ |
31
|
|
|
const OS_LINUX = 'Linux'; |
32
|
|
|
const OS_WINDOWS = 'Windows'; |
33
|
|
|
const OS_MAC = 'Mac'; |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
/** @var Countries */ |
37
|
|
|
protected $countriesHelper; |
38
|
|
|
|
39
|
|
|
/** @var SystemInfos */ |
40
|
|
|
protected $systemInfo; |
41
|
|
|
|
42
|
|
|
/** @var ServerOptions */ |
43
|
|
|
protected $serverOptions; |
44
|
|
|
|
45
|
|
|
/** @var array */ |
46
|
|
|
protected $scriptOptions; |
47
|
|
|
|
48
|
|
|
/** @var GameInfos */ |
49
|
|
|
protected $gameInfos; |
50
|
|
|
|
51
|
|
|
/** @var Version */ |
52
|
|
|
protected $version; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var AssociativeArray |
56
|
|
|
*/ |
57
|
|
|
protected $gameModeCodes; |
58
|
|
|
|
59
|
|
|
/** @var string */ |
60
|
|
|
protected $mapFolder; |
61
|
|
|
|
62
|
|
|
/** @var string */ |
63
|
|
|
protected $serverCleanPhpVersion; |
64
|
|
|
|
65
|
|
|
/** @var string */ |
66
|
|
|
protected $serverMajorPhpVersion; |
67
|
|
|
/** |
68
|
|
|
* @var CompatibleFetcher |
69
|
|
|
*/ |
70
|
|
|
private $compatibleFetcher; |
71
|
|
|
|
72
|
|
|
/** @var PlayerDetailedInfo */ |
73
|
|
|
private $serverPlayer; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* GameDataStorage constructor. |
77
|
|
|
* |
78
|
|
|
* @param CompatibleFetcher $compatibleFetcher |
79
|
|
|
* @param Countries $countries |
80
|
|
|
* @param array $gameModeCodes |
81
|
|
|
*/ |
82
|
44 |
|
public function __construct(CompatibleFetcher $compatibleFetcher, Countries $countries, array $gameModeCodes) |
|
|
|
|
83
|
|
|
{ |
84
|
44 |
|
$this->gameModeCodes = new AssociativeArray($gameModeCodes); |
85
|
|
|
|
86
|
44 |
|
$version = explode('-', phpversion()); |
87
|
44 |
|
$this->serverCleanPhpVersion = $version[0]; |
88
|
44 |
|
$this->serverMajorPhpVersion = implode( |
89
|
44 |
|
'.', |
90
|
44 |
|
array_slice(explode('.', $this->serverCleanPhpVersion), 0, 2) |
91
|
|
|
); |
92
|
|
|
|
93
|
44 |
|
$this->compatibleFetcher = $compatibleFetcher; |
94
|
44 |
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return GameInfos |
99
|
|
|
*/ |
100
|
|
|
public function getGameInfos() |
101
|
|
|
{ |
102
|
|
|
return $this->gameInfos; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param GameInfos $gameInfos |
107
|
|
|
*/ |
108
|
|
|
public function setGameInfos($gameInfos) |
109
|
|
|
{ |
110
|
|
|
$gameInfos->scriptName = strtolower($gameInfos->scriptName); |
111
|
|
|
$this->gameInfos = $gameInfos; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return Version |
116
|
|
|
*/ |
117
|
|
|
public function getVersion() |
118
|
|
|
{ |
119
|
|
|
return $this->version; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param Version $version |
124
|
|
|
*/ |
125
|
|
|
public function setVersion($version) |
126
|
|
|
{ |
127
|
|
|
$this->version = $version; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Get code of the game mode. |
133
|
|
|
* |
134
|
|
|
* @return mixed |
135
|
|
|
*/ |
136
|
|
|
public function getGameModeCode() |
137
|
|
|
{ |
138
|
|
|
return $this->gameModeCodes->get($this->getGameInfos()->gameMode, self::GAME_MODE_CODE_UNKNOWN); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* |
143
|
|
|
* Get the title name, this returns a simplified title name such as TM |
144
|
|
|
* @return string |
145
|
|
|
*/ |
146
|
|
|
public function getTitleGame() |
147
|
|
|
{ |
148
|
|
|
return $this->compatibleFetcher->getTitleGame($this->getTitle()); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Get titlepack name such as TMStadium@nadeo |
153
|
|
|
* @return mixed |
154
|
|
|
*/ |
155
|
|
|
public function getTitle() |
156
|
|
|
{ |
157
|
|
|
return $this->getVersion()->titleId; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @return ServerOptions |
162
|
|
|
*/ |
163
|
|
|
public function getServerOptions() |
164
|
|
|
{ |
165
|
|
|
return $this->serverOptions; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @param ServerOptions $serverOptions |
170
|
|
|
*/ |
171
|
|
|
public function setServerOptions($serverOptions) |
172
|
|
|
{ |
173
|
|
|
$this->serverOptions = $serverOptions; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @return array |
178
|
|
|
*/ |
179
|
|
|
public function getScriptOptions(): array |
180
|
|
|
{ |
181
|
|
|
return $this->scriptOptions; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @param array $scriptOptions |
186
|
|
|
*/ |
187
|
|
|
public function setScriptOptions(array $scriptOptions) |
188
|
|
|
{ |
189
|
|
|
$this->scriptOptions = $scriptOptions; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @param Systeminfos $systemInfo |
194
|
|
|
*/ |
195
|
|
|
public function setSystemInfo(Systeminfos $systemInfo) |
196
|
|
|
{ |
197
|
|
|
$this->systemInfo = $systemInfo; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @return PlayerDetailedInfo |
202
|
|
|
*/ |
203
|
|
|
public function getServerPlayer(): PlayerDetailedInfo |
204
|
|
|
{ |
205
|
|
|
return $this->serverPlayer; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @param PlayerDetailedInfo $serverPlayer |
210
|
|
|
*/ |
211
|
|
|
public function setServerPlayer(PlayerDetailedInfo $serverPlayer) |
212
|
|
|
{ |
213
|
|
|
$this->serverPlayer = $serverPlayer; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @return SystemInfos |
218
|
|
|
*/ |
219
|
|
|
public function getSystemInfo() |
220
|
|
|
{ |
221
|
|
|
return $this->systemInfo; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @return string |
226
|
|
|
*/ |
227
|
|
|
public function getMapFolder(): string |
228
|
|
|
{ |
229
|
|
|
return $this->mapFolder; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @param string $mapFolder |
234
|
|
|
*/ |
235
|
|
|
public function setMapFolder(string $mapFolder) |
236
|
|
|
{ |
237
|
|
|
$this->mapFolder = $mapFolder; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Get the country the server is on. |
242
|
|
|
* |
243
|
|
|
* @return string |
244
|
|
|
*/ |
245
|
|
|
public function getServerPath() |
246
|
|
|
{ |
247
|
|
|
return $this->getServerPlayer()->path; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Get Operating system. |
252
|
|
|
* |
253
|
|
|
* @return string |
254
|
|
|
*/ |
255
|
|
|
public function getServerOs() |
256
|
|
|
{ |
257
|
|
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
258
|
|
|
return self::OS_WINDOWS; |
259
|
|
|
} else { |
260
|
|
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'MAC') { |
261
|
|
|
return self::OS_MAC; |
262
|
|
|
} else { |
263
|
|
|
return self::OS_LINUX; |
264
|
|
|
} |
265
|
|
|
} |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* Get clean php version without build information. |
270
|
|
|
*/ |
271
|
|
|
public function getServerCleanPhpVersion() |
272
|
|
|
{ |
273
|
|
|
return $this->serverCleanPhpVersion; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* Get the major php version numbers. 7.0 for exemple. |
278
|
|
|
*/ |
279
|
|
|
public function getServerMajorPhpVersion() |
280
|
|
|
{ |
281
|
|
|
return $this->serverMajorPhpVersion; |
282
|
|
|
} |
283
|
|
|
} |
284
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.