|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Core\Services; |
|
4
|
|
|
|
|
5
|
|
|
use Maniaplanet\DedicatedServer\Connection; |
|
6
|
|
|
use Symfony\Component\Console\Output\ConsoleOutputInterface; |
|
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* eXpansion Application main routine. |
|
11
|
|
|
* |
|
12
|
|
|
* @package eXpansion\Core\Services |
|
13
|
|
|
*/ |
|
14
|
|
|
class Application |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var Connection */ |
|
17
|
|
|
protected $connection; |
|
18
|
|
|
|
|
19
|
|
|
/** @var PluginManager */ |
|
20
|
|
|
protected $pluginManager; |
|
21
|
|
|
|
|
22
|
|
|
/** @var DataProviderManager */ |
|
23
|
|
|
protected $dataProviderManager; |
|
24
|
|
|
|
|
25
|
|
|
/** @var Console */ |
|
26
|
|
|
protected $console; |
|
27
|
|
|
|
|
28
|
|
|
protected $isRunning = false; |
|
29
|
|
|
|
|
30
|
|
|
/** Base eXpansion callbacks. */ |
|
31
|
|
|
const EVENT_RUN = "expansion.run"; |
|
32
|
|
|
const EVENT_PRE_LOOP = "expansion.pre_loop"; |
|
33
|
|
|
const EVENT_POST_LOOP = "expansion.post_loop"; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Application constructor. |
|
37
|
|
|
* @param PluginManager $pluginManager |
|
38
|
|
|
* @param DataProviderManager $dataProviderManager |
|
39
|
|
|
* @param Connection $connection |
|
40
|
|
|
* @param ConsoleOutputInterface $output |
|
41
|
|
|
*/ |
|
42
|
2 |
|
public function __construct( |
|
43
|
|
|
PluginManager $pluginManager, |
|
44
|
|
|
DataProviderManager $dataProviderManager, |
|
45
|
|
|
Connection $connection, |
|
46
|
|
|
Console $output |
|
47
|
|
|
) |
|
48
|
|
|
{ |
|
49
|
2 |
|
$this->pluginManager = $pluginManager; |
|
50
|
2 |
|
$this->connection = $connection; |
|
51
|
2 |
|
$this->dataProviderManager = $dataProviderManager; |
|
52
|
2 |
|
$this->console = $output; |
|
53
|
2 |
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Initialize eXpansion. |
|
57
|
|
|
* |
|
58
|
|
|
* @param OutputInterface $output |
|
|
|
|
|
|
59
|
|
|
* @return $this |
|
60
|
|
|
*/ |
|
61
|
1 |
|
public function init(ConsoleOutputInterface $console) |
|
62
|
|
|
{ |
|
63
|
1 |
|
$this->console->init($console); |
|
64
|
|
|
|
|
65
|
1 |
|
$this->console->writeln('$fff 8b d8$fff $0d0 ad888888b, '); |
|
66
|
1 |
|
$this->console->writeln('$fff Y8, ,8P $fff $0d0 d8" "88 '); |
|
67
|
1 |
|
$this->console->writeln('$fff `8b d8\' $fff $0d0 a8 '); |
|
68
|
1 |
|
$this->console->writeln('$fff ,adPPYba, Y88P $fff 8b,dPPYba, $0d0 ,d8P" '); |
|
69
|
1 |
|
$this->console->writeln('$fffa8P_____88 d88b $fff 88P\' "8a $0d0 a8P" '); |
|
70
|
1 |
|
$this->console->writeln('$fff8PP""""""" ,8P Y8, $fff 88 d8 $0d0 a8P\' '); |
|
71
|
1 |
|
$this->console->writeln('$fff"8b, ,aa d8\' `8b$fff 88b, ,a8" $0d0 d8" '); |
|
72
|
1 |
|
$this->console->writeln('$fff `"Ybbd8"\' 8P Y8$fff 88`YbbdP"\' $0d0 88888888888'); |
|
73
|
1 |
|
$this->console->writeln('$fff $fff 88 $0d0 '); |
|
74
|
1 |
|
$this->console->writeln('$777 eXpansion v.2.0.0.0 $fff 88 $0d0 '); |
|
75
|
|
|
|
|
76
|
1 |
|
$this->pluginManager->init(); |
|
77
|
1 |
|
$this->dataProviderManager->init(); |
|
78
|
|
|
|
|
79
|
1 |
|
return $this; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Run eXpansion |
|
84
|
|
|
* |
|
85
|
|
|
*/ |
|
86
|
1 |
|
public function run() |
|
87
|
|
|
{ |
|
88
|
1 |
|
$this->connection->enableCallbacks(true); |
|
89
|
|
|
|
|
90
|
1 |
|
$startTime = microtime(true); |
|
91
|
1 |
|
$nextCycleStart = $startTime; |
|
92
|
1 |
|
$cycleTime = 1 / 60; |
|
93
|
|
|
|
|
94
|
1 |
|
$this->console->writeln("Running preflight checks..."); |
|
95
|
|
|
|
|
96
|
1 |
|
$this->dataProviderManager->dispatch(self::EVENT_RUN, []); |
|
97
|
|
|
|
|
98
|
1 |
|
$this->console->writeln("And takeoff"); |
|
99
|
|
|
|
|
100
|
|
|
do { |
|
101
|
1 |
|
$this->dataProviderManager->dispatch(self::EVENT_PRE_LOOP, []); |
|
102
|
|
|
|
|
103
|
1 |
|
$calls = $this->connection->executeCallbacks(); |
|
104
|
1 |
|
if (!empty($calls)) { |
|
105
|
1 |
|
foreach ($calls as $call) { |
|
106
|
1 |
|
$method = preg_replace('/^[[:alpha:]]+\./', '', $call[0]); // remove trailing "Whatever." |
|
107
|
1 |
|
$params = (array) $call[1]; |
|
108
|
|
|
|
|
109
|
1 |
|
$this->dataProviderManager->dispatch($method, $params); |
|
110
|
1 |
|
} |
|
111
|
1 |
|
} |
|
112
|
1 |
|
$this->connection->executeMulticall(); |
|
113
|
1 |
|
$this->dataProviderManager->dispatch(self::EVENT_POST_LOOP, []); |
|
114
|
|
|
|
|
115
|
|
|
|
|
116
|
1 |
|
$endCycleTime = microtime(true) + $cycleTime / 10; |
|
117
|
|
|
do { |
|
118
|
1 |
|
$nextCycleStart += $cycleTime; |
|
119
|
1 |
|
} while ($nextCycleStart < $endCycleTime); |
|
120
|
|
|
|
|
121
|
1 |
|
@time_sleep_until($nextCycleStart); |
|
|
|
|
|
|
122
|
1 |
|
} while($this->isRunning); |
|
123
|
1 |
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Stop eXpansion. |
|
127
|
|
|
*/ |
|
128
|
1 |
|
public function stopApplication() |
|
129
|
|
|
{ |
|
130
|
1 |
|
$this->isRunning = false; |
|
131
|
1 |
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.