|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Framework\GameManiaplanet\DataProviders; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Framework\Core\DataProviders\AbstractDataProvider; |
|
6
|
|
|
use eXpansion\Framework\Core\Plugins\StatusAwarePluginInterface; |
|
7
|
|
|
use eXpansion\Framework\Core\Services\DedicatedConnection\Factory; |
|
8
|
|
|
use eXpansion\Framework\Core\Storage\MapStorage; |
|
9
|
|
|
use Maniaplanet\DedicatedServer\Connection; |
|
10
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\IndexOutOfBoundException; |
|
11
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\NextMapException; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class MapDataProvider provides information to plugins about what is going on with the maps on the server. |
|
15
|
|
|
* |
|
16
|
|
|
* @package eXpansion\Framework\Core\DataProviders |
|
17
|
|
|
*/ |
|
18
|
|
|
class MapListDataProvider extends AbstractDataProvider implements StatusAwarePluginInterface |
|
19
|
|
|
{ |
|
20
|
|
|
/** Size of batch to get maps from the storage. */ |
|
21
|
|
|
const BATCH_SIZE = 500; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var MapStorage |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $mapStorage; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var Factory |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $connection; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* MapListDataProvider constructor. |
|
35
|
|
|
* |
|
36
|
|
|
* @param MapStorage $mapStorage |
|
37
|
|
|
* @param Factory $factory |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct(MapStorage $mapStorage, Factory $factory) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->mapStorage = $mapStorage; |
|
42
|
|
|
$this->connection = $factory->getConnection(); |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @inheritdoc |
|
47
|
|
|
*/ |
|
48
|
|
|
public function setStatus($status) |
|
49
|
|
|
{ |
|
50
|
|
|
if ($status) { |
|
51
|
|
|
$this->updateMapList(); |
|
52
|
|
|
$currentMap = $this->connection->getCurrentMapInfo(); |
|
|
|
|
|
|
53
|
|
|
if ($currentMap) { |
|
54
|
|
|
$this->mapStorage->setCurrentMap($currentMap); |
|
55
|
|
|
try { |
|
56
|
|
|
$this->mapStorage->setNextMap($this->connection->getNextMapInfo()); |
|
|
|
|
|
|
57
|
|
|
} catch (NextMapException $ex) { |
|
58
|
|
|
$this->mapStorage->setNextMap($currentMap); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Update the list of maps in the storage. |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function updateMapList() |
|
69
|
|
|
{ |
|
70
|
|
|
$start = 0; |
|
71
|
|
|
|
|
72
|
|
|
do { |
|
73
|
|
|
try { |
|
74
|
|
|
$maps = $this->connection->getMapList(self::BATCH_SIZE, $start); |
|
|
|
|
|
|
75
|
|
|
} catch (IndexOutOfBoundException $e) { |
|
76
|
|
|
// This is normal error when we we are trying to find all maps and we are out of bounds. |
|
77
|
|
|
return; |
|
78
|
|
|
} catch (NextMapException $ex) { |
|
79
|
|
|
// this is if no maps defined |
|
80
|
|
|
return; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
if (!empty($maps)) { |
|
84
|
|
|
foreach ($maps as $map) { |
|
85
|
|
|
$this->mapStorage->addMap($map); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
$start += self::BATCH_SIZE; |
|
90
|
|
|
|
|
91
|
|
|
} while (count($maps) == self::BATCH_SIZE); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Called when map list is modified. |
|
96
|
|
|
* |
|
97
|
|
|
* @param $curMapIndex |
|
98
|
|
|
* @param $nextMapIndex |
|
99
|
|
|
* @param $isListModified |
|
100
|
|
|
* |
|
101
|
|
|
*/ |
|
102
|
|
|
public function onMapListModified($curMapIndex, $nextMapIndex, $isListModified) |
|
103
|
|
|
{ |
|
104
|
|
|
if ($isListModified) { |
|
105
|
|
|
$oldMaps = $this->mapStorage->getMaps(); |
|
106
|
|
|
|
|
107
|
|
|
$this->mapStorage->resetMapData(); |
|
108
|
|
|
$this->updateMapList(); |
|
109
|
|
|
|
|
110
|
|
|
// We will dispatch even only when list is modified. If not we dispatch specific events. |
|
111
|
|
|
$this->dispatch(__FUNCTION__, [$oldMaps, $curMapIndex, $nextMapIndex, $isListModified]); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
try { |
|
115
|
|
|
$currentMap = $this->connection->getCurrentMapInfo(); // sync better |
|
|
|
|
|
|
116
|
|
|
} catch (\Exception $e) { |
|
117
|
|
|
echo $e->getMessage(). "\n"; |
|
118
|
|
|
|
|
119
|
|
|
$currentMap = null; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
// current map can be false if map by index is not found.. |
|
123
|
|
|
if ($currentMap) { |
|
124
|
|
|
if ($this->mapStorage->getCurrentMap()->uId != $currentMap->uId) { |
|
125
|
|
|
$previousMap = $this->mapStorage->getCurrentMap(); |
|
126
|
|
|
$this->mapStorage->setCurrentMap($currentMap); |
|
127
|
|
|
|
|
128
|
|
|
$this->dispatch('onExpansionMapChange', [$currentMap, $previousMap]); |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
try { |
|
133
|
|
|
$nextMap = $this->connection->getNextMapInfo(); // sync better |
|
|
|
|
|
|
134
|
|
|
} catch (\Exception $e) { |
|
135
|
|
|
echo $e->getMessage(). "\n"; |
|
136
|
|
|
$nextMap = null; |
|
137
|
|
|
} |
|
138
|
|
|
// next map can be false if map by index is not found.. |
|
139
|
|
|
if ($nextMap) { |
|
140
|
|
|
if ($this->mapStorage->getNextMap()->uId != $nextMap->uId) { |
|
141
|
|
|
$previousNextMap = $this->mapStorage->getNextMap(); |
|
142
|
|
|
$this->mapStorage->setNextMap($nextMap); |
|
143
|
|
|
|
|
144
|
|
|
$this->dispatch('onExpansionNextMapChange', [$nextMap, $previousNextMap]); |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.