1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace eXpansion\Bundle\LocalMapRatings\Plugin; |
4
|
|
|
|
5
|
|
|
use eXpansion\Bundle\LocalMapRatings\Services\MapRatingsService; |
6
|
|
|
use eXpansion\Framework\Core\DataProviders\Listener\ListenerInterfaceExpApplication; |
7
|
|
|
use eXpansion\Framework\Core\Model\UserGroups\Group; |
8
|
|
|
use eXpansion\Framework\Core\Storage\Data\Player; |
9
|
|
|
use eXpansion\Framework\Core\Storage\MapStorage; |
10
|
|
|
use eXpansion\Framework\Core\Storage\PlayerStorage; |
11
|
|
|
use eXpansion\Framework\GameManiaplanet\DataProviders\Listener\ListenerInterfaceMpLegacyChat; |
12
|
|
|
use eXpansion\Framework\GameManiaplanet\DataProviders\Listener\ListenerInterfaceMpScriptMap; |
13
|
|
|
use eXpansion\Framework\GameManiaplanet\DataProviders\Listener\ListenerInterfaceMpScriptMatch; |
14
|
|
|
use Maniaplanet\DedicatedServer\Structures\Map; |
15
|
|
|
use Propel\Runtime\Exception\PropelException; |
16
|
|
|
use Psr\Log\LoggerInterface; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
class MapRatings implements ListenerInterfaceExpApplication, ListenerInterfaceMpScriptMatch, |
20
|
|
|
ListenerInterfaceMpScriptMap, ListenerInterfaceMpLegacyChat |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var MapStorage |
24
|
|
|
*/ |
25
|
|
|
private $mapStorage; |
26
|
|
|
/** |
27
|
|
|
* @var PlayerStorage |
28
|
|
|
*/ |
29
|
|
|
private $playerStorage; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var Group |
33
|
|
|
*/ |
34
|
|
|
private $players; |
35
|
|
|
/** |
36
|
|
|
* @var MapRatingsService |
37
|
|
|
*/ |
38
|
|
|
private $mapRatingsService; |
39
|
|
|
/** |
40
|
|
|
* @var LoggerInterface |
41
|
|
|
*/ |
42
|
|
|
private $logger; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* MapRatingService constructor. |
46
|
|
|
* @param MapStorage $mapStorage |
47
|
|
|
* @param PlayerStorage $playerStorage |
48
|
|
|
* @param MapRatingsService $mapRatingsService |
49
|
|
|
* @param Group $players |
50
|
|
|
* @param LoggerInterface $logger |
51
|
|
|
*/ |
52
|
|
|
public function __construct( |
53
|
|
|
MapStorage $mapStorage, |
54
|
|
|
PlayerStorage $playerStorage, |
55
|
|
|
MapRatingsService $mapRatingsService, |
56
|
|
|
Group $players, |
57
|
|
|
LoggerInterface $logger |
58
|
|
|
) |
59
|
|
|
{ |
60
|
|
|
$this->mapStorage = $mapStorage; |
61
|
|
|
$this->playerStorage = $playerStorage; |
62
|
|
|
$this->players = $players; |
63
|
|
|
$this->mapRatingsService = $mapRatingsService; |
64
|
|
|
$this->logger = $logger; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Called when a player chats. |
69
|
|
|
* |
70
|
|
|
* @param Player $player |
71
|
|
|
* @param $text |
72
|
|
|
* |
73
|
|
|
* @return void |
74
|
|
|
*/ |
75
|
|
|
public function onPlayerChat(Player $player, $text) |
76
|
|
|
{ |
77
|
|
|
if ($player->getPlayerId() == 0) { |
78
|
|
|
return; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
if ($player->getPlayerId() != 0 && substr($text, 0, 1) != "/") { |
82
|
|
|
if ($text === "++") { |
83
|
|
|
$this->mapRatingsService->changeRating($player->getLogin(), 1); |
84
|
|
|
|
85
|
|
|
return; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if ($text === "--") { |
89
|
|
|
$this->mapRatingsService->changeRating($player->getLogin(), -1); |
90
|
|
|
|
91
|
|
|
return; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* helper function to load mapratings for current map |
98
|
|
|
* @param Map $map |
99
|
|
|
*/ |
100
|
|
|
private function loadRatings(Map $map) |
101
|
|
|
{ |
102
|
|
|
try { |
103
|
|
|
$this->mapRatingsService->load($map); |
104
|
|
|
} catch (PropelException $e) { |
105
|
|
|
$this->logger->error("error loading map ratings", ["exception" => $e]); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
private function saveRatings() |
110
|
|
|
{ |
111
|
|
|
try { |
112
|
|
|
$this->mapRatingsService->save(); |
113
|
|
|
} catch (PropelException $e) { |
114
|
|
|
$this->logger->error("error saving map ratings", ["exception" => $e]); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* called at eXpansion init |
120
|
|
|
* |
121
|
|
|
* @return void |
122
|
|
|
*/ |
123
|
|
|
public function onApplicationInit() |
124
|
|
|
{ |
125
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* called when init is done and callbacks are enabled |
130
|
|
|
* |
131
|
|
|
* @return void |
132
|
|
|
*/ |
133
|
|
|
public function onApplicationReady() |
134
|
|
|
{ |
135
|
|
|
$this->loadRatings($this->mapStorage->getCurrentMap()); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* called when requesting application stop |
140
|
|
|
* |
141
|
|
|
* @return void |
142
|
|
|
*/ |
143
|
|
|
public function onApplicationStop() |
144
|
|
|
{ |
145
|
|
|
|
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Callback sent when the "StartMatch" section start. |
150
|
|
|
* |
151
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
152
|
|
|
* @param int $time Server time when the callback was sent |
153
|
|
|
* |
154
|
|
|
* @return void |
155
|
|
|
*/ |
156
|
|
|
public function onStartMatchStart($count, $time) |
157
|
|
|
{ |
158
|
|
|
|
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Callback sent when the "StartMatch" section end. |
163
|
|
|
* |
164
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
165
|
|
|
* @param int $time Server time when the callback was sent |
166
|
|
|
* |
167
|
|
|
* @return void |
168
|
|
|
*/ |
169
|
|
|
public function onStartMatchEnd($count, $time) |
170
|
|
|
{ |
171
|
|
|
|
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Callback sent when the "EndMatch" section start. |
176
|
|
|
* |
177
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
178
|
|
|
* @param int $time Server time when the callback was sent |
179
|
|
|
* |
180
|
|
|
* @return void |
181
|
|
|
*/ |
182
|
|
|
public function onEndMatchStart($count, $time) |
183
|
|
|
{ |
184
|
|
|
|
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Callback sent when the "EndMatch" section end. |
189
|
|
|
* |
190
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
191
|
|
|
* @param int $time Server time when the callback was sent |
192
|
|
|
* |
193
|
|
|
* @return void |
194
|
|
|
*/ |
195
|
|
|
public function onEndMatchEnd($count, $time) |
196
|
|
|
{ |
197
|
|
|
$this->saveRatings(); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Callback sent when the "StartTurn" section start. |
202
|
|
|
* |
203
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
204
|
|
|
* @param int $time Server time when the callback was sent |
205
|
|
|
* |
206
|
|
|
* @return void |
207
|
|
|
*/ |
208
|
|
|
public function onStartTurnStart($count, $time) |
209
|
|
|
{ |
210
|
|
|
|
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Callback sent when the "StartTurn" section end. |
215
|
|
|
* |
216
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
217
|
|
|
* @param int $time Server time when the callback was sent |
218
|
|
|
* |
219
|
|
|
* @return void |
220
|
|
|
*/ |
221
|
|
|
public function onStartTurnEnd($count, $time) |
222
|
|
|
{ |
223
|
|
|
|
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Callback sent when the "EndMatch" section start. |
228
|
|
|
* |
229
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
230
|
|
|
* @param int $time Server time when the callback was sent |
231
|
|
|
* |
232
|
|
|
* @return void |
233
|
|
|
*/ |
234
|
|
|
public function onEndTurnStart($count, $time) |
235
|
|
|
{ |
236
|
|
|
|
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Callback sent when the "EndMatch" section end. |
241
|
|
|
* |
242
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
243
|
|
|
* @param int $time Server time when the callback was sent |
244
|
|
|
* |
245
|
|
|
* @return void |
246
|
|
|
*/ |
247
|
|
|
public function onEndTurnEnd($count, $time) |
248
|
|
|
{ |
249
|
|
|
|
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Callback sent when the "StartRound" section start. |
254
|
|
|
* |
255
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
256
|
|
|
* @param int $time Server time when the callback was sent |
257
|
|
|
* |
258
|
|
|
* @return void |
259
|
|
|
*/ |
260
|
|
|
public function onStartRoundStart($count, $time) |
261
|
|
|
{ |
262
|
|
|
|
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* Callback sent when the "StartRound" section end. |
267
|
|
|
* |
268
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
269
|
|
|
* @param int $time Server time when the callback was sent |
270
|
|
|
* |
271
|
|
|
* @return void |
272
|
|
|
*/ |
273
|
|
|
public function onStartRoundEnd($count, $time) |
274
|
|
|
{ |
275
|
|
|
|
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* Callback sent when the "EndMatch" section start. |
280
|
|
|
* |
281
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
282
|
|
|
* @param int $time Server time when the callback was sent |
283
|
|
|
* |
284
|
|
|
* @return void |
285
|
|
|
*/ |
286
|
|
|
public function onEndRoundStart($count, $time) |
287
|
|
|
{ |
288
|
|
|
|
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* Callback sent when the "EndMatch" section end. |
293
|
|
|
* |
294
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
295
|
|
|
* @param int $time Server time when the callback was sent |
296
|
|
|
* |
297
|
|
|
* @return void |
298
|
|
|
*/ |
299
|
|
|
public function onEndRoundEnd($count, $time) |
300
|
|
|
{ |
301
|
|
|
|
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* Callback sent when the "StartMap" section start. |
307
|
|
|
* |
308
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
309
|
|
|
* @param int $time Server time when the callback was sent |
310
|
|
|
* @param boolean $restarted true if the map was restarted, false otherwise |
311
|
|
|
* @param Map $map Map started with. |
312
|
|
|
* |
313
|
|
|
* @return void |
314
|
|
|
*/ |
315
|
|
|
public function onStartMapStart($count, $time, $restarted, Map $map) |
316
|
|
|
{ |
317
|
|
|
if ($restarted) { |
318
|
|
|
$this->saveRatings(); |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
$this->loadRatings($map); |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* Callback sent when the "StartMap" section end. |
326
|
|
|
* |
327
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
328
|
|
|
* @param int $time Server time when the callback was sent |
329
|
|
|
* @param boolean $restarted true if the map was restarted, false otherwise |
330
|
|
|
* @param Map $map Map started with. |
331
|
|
|
* |
332
|
|
|
* @return void |
333
|
|
|
*/ |
334
|
|
|
public function onStartMapEnd($count, $time, $restarted, Map $map) |
335
|
|
|
{ |
336
|
|
|
|
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
/** |
340
|
|
|
* Callback sent when the "EndMap" section start. |
341
|
|
|
* |
342
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
343
|
|
|
* @param int $time Server time when the callback was sent |
344
|
|
|
* @param boolean $restarted true if the map was restarted, false otherwise |
345
|
|
|
* @param Map $map Map started with. |
346
|
|
|
* |
347
|
|
|
* @return void |
348
|
|
|
*/ |
349
|
|
|
public function onEndMapStart($count, $time, $restarted, Map $map) |
350
|
|
|
{ |
351
|
|
|
$this->saveRatings(); |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* Callback sent when the "EndMap" section end. |
356
|
|
|
* |
357
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
358
|
|
|
* @param int $time Server time when the callback was sent |
359
|
|
|
* @param boolean $restarted true if the map was restarted, false otherwise |
360
|
|
|
* @param Map $map Map started with. |
361
|
|
|
* |
362
|
|
|
* @return void |
363
|
|
|
*/ |
364
|
|
|
public function onEndMapEnd($count, $time, $restarted, Map $map) |
365
|
|
|
{ |
366
|
|
|
|
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
} |
370
|
|
|
|