|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Bundle\Acme\Plugins; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Framework\Core\DataProviders\Listener\ListenerInterfaceMpLegacyMap; |
|
6
|
|
|
use eXpansion\Framework\Core\DataProviders\Listener\ListenerInterfaceMpLegacyMaplist; |
|
7
|
|
|
use eXpansion\Framework\Core\DataProviders\Listener\ListenerInterfaceExpTimer; |
|
8
|
|
|
use eXpansion\Framework\Core\Helpers\Time; |
|
9
|
|
|
use eXpansion\Framework\Core\Model\UserGroups\Group; |
|
10
|
|
|
use eXpansion\Framework\Core\Plugins\Gui\ManialinkFactory; |
|
11
|
|
|
use eXpansion\Framework\Core\Plugins\StatusAwarePluginInterface; |
|
12
|
|
|
use eXpansion\Framework\Core\Services\Console; |
|
13
|
|
|
use Maniaplanet\DedicatedServer\Connection; |
|
14
|
|
|
use Maniaplanet\DedicatedServer\Structures\Map; |
|
15
|
|
|
|
|
16
|
|
|
class Test implements ListenerInterfaceMpLegacyMap, ListenerInterfaceExpTimer, StatusAwarePluginInterface |
|
17
|
|
|
{ |
|
18
|
|
|
|
|
19
|
|
|
public $memoryMsg; |
|
20
|
|
|
/** @var Connection */ |
|
21
|
|
|
protected $connection; |
|
22
|
|
|
|
|
23
|
|
|
/** @var Console */ |
|
24
|
|
|
protected $console; |
|
25
|
|
|
|
|
26
|
|
|
/** @var Time */ |
|
27
|
|
|
protected $time; |
|
28
|
|
|
|
|
29
|
|
|
/** @var float|int */ |
|
30
|
|
|
private $previousMemoryValue = 0; |
|
31
|
|
|
private $startMemValue = 0; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var ManialinkFactory |
|
35
|
|
|
*/ |
|
36
|
|
|
private $mlFactory; |
|
37
|
|
|
/** |
|
38
|
|
|
* @var Group |
|
39
|
|
|
*/ |
|
40
|
|
|
private $players; |
|
41
|
|
|
|
|
42
|
|
|
function __construct( |
|
|
|
|
|
|
43
|
|
|
Connection $connection, |
|
44
|
|
|
Console $console, |
|
45
|
|
|
Time $time, |
|
46
|
|
|
ManialinkFactory $mlFactory, |
|
47
|
|
|
Group $players |
|
48
|
|
|
) { |
|
49
|
|
|
$this->connection = $connection; |
|
50
|
|
|
$this->console = $console; |
|
51
|
|
|
$this->time = $time; |
|
52
|
|
|
$this->mlFactory = $mlFactory; |
|
53
|
|
|
$this->players = $players; |
|
54
|
|
|
$this->startMemValue = memory_get_usage(true); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function onBeginMap(Map $map) |
|
58
|
|
|
{ |
|
59
|
|
|
$this->console->writeln('$0f0Begin Map: $fff'.$map->name); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function onEndMap(Map $map) |
|
63
|
|
|
{ |
|
64
|
|
|
$this->console->writeln('$0f0End Map: $fff'.$map->name); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function onPreLoop() |
|
68
|
|
|
{ |
|
69
|
|
|
// do nothing |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function onPostLoop() |
|
73
|
|
|
{ |
|
74
|
|
|
// do nothing |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function onEverySecond() |
|
78
|
|
|
{ |
|
79
|
|
|
$mem = memory_get_usage(false); |
|
80
|
|
|
|
|
81
|
|
|
if ($this->previousMemoryValue != $mem) { |
|
82
|
|
|
$diff = ($mem - $this->previousMemoryValue); |
|
83
|
|
|
$msg = 'Memory: $0d0'.round($mem / 1024)."kb "; |
|
84
|
|
|
|
|
85
|
|
|
if ($this->previousMemoryValue < $mem) { |
|
86
|
|
|
$msg .= ' $f00+'.round($diff / 1024)."kb"; |
|
87
|
|
|
} else { |
|
88
|
|
|
$msg .= ' $0f0'.round($diff / 1024)."kb"; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
$diff = ($mem - $this->startMemValue); |
|
92
|
|
|
if ($this->startMemValue < $diff) { |
|
93
|
|
|
$msg .= ' $f00('.round($diff / 1024)."kb)"; |
|
94
|
|
|
} else { |
|
95
|
|
|
$msg .= ' $0f0('.round($diff / 1024)."kb)"; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
$this->memoryMsg = $msg; |
|
99
|
|
|
$this->mlFactory->setMemory($msg); |
|
|
|
|
|
|
100
|
|
|
$this->mlFactory->update($this->players); |
|
101
|
|
|
// $this->console->writeln($msg); |
|
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
$this->previousMemoryValue = $mem; |
|
104
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @param Map[] $oldMaps |
|
109
|
|
|
* @param string $currentMapUid |
|
110
|
|
|
* @param string $nextMapUid |
|
111
|
|
|
* @param bool $isListModified |
|
112
|
|
|
* @return mixed |
|
113
|
|
|
*/ |
|
114
|
|
|
public function onMapListModified($oldMaps, $currentMapUid, $nextMapUid, $isListModified) |
|
|
|
|
|
|
115
|
|
|
{ |
|
116
|
|
|
// TODO: Implement onMapListModified() method. |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function onExpansionMapChange($currentMap, $previousMap) |
|
|
|
|
|
|
120
|
|
|
{ |
|
121
|
|
|
// TODO: Implement onExpansionMapChange() method. |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function onExpansionNextMapChange($nextMap, $previousNextMap) |
|
|
|
|
|
|
125
|
|
|
{ |
|
126
|
|
|
// TODO: Implement onExpansionNextMapChange() method. |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Set the status of the plugin |
|
131
|
|
|
* |
|
132
|
|
|
* @param boolean $status |
|
133
|
|
|
* |
|
134
|
|
|
* @return null |
|
135
|
|
|
*/ |
|
136
|
|
|
public function setStatus($status) |
|
137
|
|
|
{ |
|
138
|
|
|
if ($status) { |
|
139
|
|
|
$this->mlFactory->create($this->players); |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* @return mixed |
|
145
|
|
|
*/ |
|
146
|
|
|
public function getMemoryMsg() |
|
147
|
|
|
{ |
|
148
|
|
|
return $this->memoryMsg; |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.