|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace eXpansion\Core\Services\Application; |
|
5
|
|
|
|
|
6
|
|
|
use eXpansion\Core\Services\Console; |
|
7
|
|
|
use Maniaplanet\DedicatedServer\Connection; |
|
8
|
|
|
use Symfony\Component\Console\Output\ConsoleOutputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
|
|
11
|
|
|
abstract class AbstractApplication implements RunInterface |
|
12
|
|
|
{ |
|
13
|
|
|
/** @var Connection */ |
|
14
|
|
|
protected $connection; |
|
15
|
|
|
|
|
16
|
|
|
/** @var Dispatcher */ |
|
17
|
|
|
protected $dispatcher; |
|
18
|
|
|
|
|
19
|
|
|
/** @var Console */ |
|
20
|
|
|
protected $console; |
|
21
|
|
|
|
|
22
|
|
|
/** @var bool */ |
|
23
|
|
|
protected $isRunning = true; |
|
24
|
|
|
|
|
25
|
|
|
/** Base eXpansion callbacks. */ |
|
26
|
|
|
const EVENT_RUN = "expansion.run"; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Application constructor. |
|
30
|
|
|
* |
|
31
|
|
|
* @param DispatcherInterface $dispatcher |
|
32
|
|
|
* @param Connection $connection |
|
33
|
|
|
* @param Console $output |
|
34
|
|
|
*/ |
|
35
|
10 |
|
public function __construct( |
|
36
|
|
|
DispatcherInterface $dispatcher, |
|
37
|
|
|
Connection $connection, |
|
38
|
|
|
Console $output |
|
39
|
|
|
) { |
|
40
|
10 |
|
$this->connection = $connection; |
|
41
|
10 |
|
$this->dispatcher = $dispatcher; |
|
|
|
|
|
|
42
|
10 |
|
$this->console = $output; |
|
43
|
10 |
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Initialize eXpansion. |
|
47
|
|
|
* |
|
48
|
|
|
* @param ConsoleOutputInterface $console |
|
49
|
|
|
* |
|
50
|
|
|
* @return $this |
|
51
|
|
|
*/ |
|
52
|
1 |
|
public function init(OutputInterface $console) |
|
53
|
|
|
{ |
|
54
|
1 |
|
$this->console->init($console); |
|
|
|
|
|
|
55
|
1 |
|
$this->dispatcher->init(); |
|
56
|
|
|
|
|
57
|
1 |
|
return $this; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Run eXpansion |
|
62
|
|
|
* |
|
63
|
|
|
*/ |
|
64
|
2 |
|
public function run() |
|
65
|
|
|
{ |
|
66
|
2 |
|
$this->connection->enableCallbacks(true); |
|
67
|
|
|
|
|
68
|
2 |
|
$startTime = microtime(true); |
|
69
|
2 |
|
$nextCycleStart = $startTime; |
|
70
|
2 |
|
$cycleTime = 1 / 60; |
|
71
|
|
|
|
|
72
|
2 |
|
$this->console->writeln("Running preflight checks..."); |
|
73
|
|
|
|
|
74
|
|
|
// need to send this for scripts to start callback handling |
|
75
|
2 |
|
$this->connection->triggerModeScriptEvent("XmlRpc.EnableCallbacks", ["True"]); |
|
76
|
|
|
|
|
77
|
2 |
|
$this->dispatcher->dispatch(self::EVENT_RUN, []); |
|
78
|
|
|
|
|
79
|
2 |
|
$this->console->writeln("And takeoff"); |
|
80
|
|
|
|
|
81
|
|
|
do { |
|
82
|
2 |
|
$this->executeRun(); |
|
83
|
|
|
|
|
84
|
2 |
|
$endCycleTime = microtime(true) + $cycleTime / 10; |
|
85
|
|
|
do { |
|
86
|
2 |
|
$nextCycleStart += $cycleTime; |
|
87
|
2 |
|
} while ($nextCycleStart < $endCycleTime); |
|
88
|
|
|
|
|
89
|
2 |
|
@time_sleep_until($nextCycleStart); |
|
|
|
|
|
|
90
|
|
|
|
|
91
|
2 |
|
} while ($this->isRunning); |
|
92
|
2 |
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Stop eXpansion. |
|
96
|
|
|
*/ |
|
97
|
2 |
|
public function stopApplication() |
|
98
|
|
|
{ |
|
99
|
2 |
|
$this->isRunning = false; |
|
100
|
2 |
|
} |
|
101
|
|
|
|
|
102
|
|
|
abstract protected function executeRun(); |
|
103
|
|
|
} |
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 given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.