1
|
|
|
<?php namespace FreedomCore\TrinityCore\Console\Commands; |
2
|
|
|
|
3
|
|
|
use FreedomCore\TrinityCore\Console\Abstracts\BaseCommand; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class Server |
7
|
|
|
* @package FreedomCore\TrinityCore\Console\Commands |
8
|
|
|
* @codeCoverageIgnore |
9
|
|
|
*/ |
10
|
|
|
class Server extends BaseCommand |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @inheritdoc |
15
|
|
|
* @var array |
16
|
|
|
*/ |
17
|
|
|
protected $doNotPrefix = [ |
18
|
|
|
'saveAll', |
19
|
|
|
'notify', |
20
|
|
|
'announce' |
21
|
|
|
]; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Trigger corpses expire check in world |
25
|
|
|
* @return array|string |
26
|
|
|
*/ |
27
|
|
|
public function corpses() |
28
|
|
|
{ |
29
|
|
|
return $this->executeCommand(__FUNCTION__, get_defined_vars()); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Terminate server NOW |
34
|
|
|
* Exit code 0 |
35
|
|
|
* @return array|string |
36
|
|
|
*/ |
37
|
|
|
public function exit() |
38
|
|
|
{ |
39
|
|
|
return $this->executeCommand(__FUNCTION__, get_defined_vars()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Display server version and the number of connected players |
44
|
|
|
* @return array|string |
45
|
|
|
*/ |
46
|
|
|
public function info() |
47
|
|
|
{ |
48
|
|
|
return $this->executeCommand(__FUNCTION__, get_defined_vars()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Show message of the day |
53
|
|
|
* @return array|string |
54
|
|
|
*/ |
55
|
|
|
public function motd() |
56
|
|
|
{ |
57
|
|
|
return $this->executeCommand(__FUNCTION__, get_defined_vars()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Without the argument passed, it will display current limit for players. |
62
|
|
|
* With argument greater that 0, it will set the new limit for max players. |
63
|
|
|
* `reset` parameter may be used to set the value from config. |
64
|
|
|
* @param string $parameter |
65
|
|
|
* @return array|string |
66
|
|
|
*/ |
67
|
|
|
public function plimit($parameter = '') |
68
|
|
|
{ |
69
|
|
|
return $this->executeCommand(__FUNCTION__, get_defined_vars()); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Set Diff Time For Sever |
74
|
|
|
* @param int $diffTime |
75
|
|
|
* @return array|string |
76
|
|
|
*/ |
77
|
|
|
public function setDiffTime(int $diffTime) |
78
|
|
|
{ |
79
|
|
|
return $this->executeCommand(__FUNCTION__, get_defined_vars()); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Set Log Level For Server |
84
|
|
|
* @param string $facility |
85
|
|
|
* @param string $name |
86
|
|
|
* @param int $logLevel |
87
|
|
|
* @return array|string |
88
|
|
|
*/ |
89
|
|
|
public function setLogLevel(string $facility, string $name, int $logLevel) |
90
|
|
|
{ |
91
|
|
|
$facilities = ['a', 'l']; |
92
|
|
|
$levels = range(0, 6); |
93
|
|
|
if (!in_array($facility, $facilities)) { |
94
|
|
|
throw new \RuntimeException('Invalid type of facility, possible values are: a (appender), l (logger)'); |
95
|
|
|
} |
96
|
|
|
if (in_array($logLevel, $levels)) { |
97
|
|
|
throw new \RuntimeException('Log level is out of range, possible values are between 0 (disabled) and 6'); |
98
|
|
|
} |
99
|
|
|
return $this->executeCommand(__FUNCTION__, [ |
100
|
|
|
'facility' => $facility, |
101
|
|
|
'name' => $name, |
102
|
|
|
'logLevel' => $logLevel |
103
|
|
|
]); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Set new message of the day |
108
|
|
|
* @param string $motd |
109
|
|
|
* @return array|string |
110
|
|
|
*/ |
111
|
|
|
public function setMotd(string $motd) |
112
|
|
|
{ |
113
|
|
|
return $this->executeCommand(__FUNCTION__, get_defined_vars()); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Sets whether the world accepts new client connections |
118
|
|
|
* @param bool $isClosed |
119
|
|
|
* @return array|string |
120
|
|
|
*/ |
121
|
|
|
public function setClosed(bool $isClosed) |
122
|
|
|
{ |
123
|
|
|
$closed = ($isClosed) ? 'on' : 'off'; |
124
|
|
|
return $this->executeCommand(__FUNCTION__, ['isClosed' => $closed]); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Shutdown server |
129
|
|
|
* @param int $timer Timer for the sever shutdown |
130
|
|
|
* @param bool $force Should the shutdown be forced |
131
|
|
|
* @param int $code Exit code |
132
|
|
|
* @return array|string |
133
|
|
|
*/ |
134
|
|
|
public function shutdown(int $timer, bool $force = false, int $code = 0) |
135
|
|
|
{ |
136
|
|
|
$force = ($force) ? 'force' : ''; |
137
|
|
|
return $this->executeCommand(__FUNCTION__, [ |
138
|
|
|
'force' => $force, |
139
|
|
|
'timer' => $timer, |
140
|
|
|
'code' => $code |
141
|
|
|
]); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Cancel the restart/shutdown timer if any |
146
|
|
|
*/ |
147
|
|
|
public function shutdownCancel() |
148
|
|
|
{ |
149
|
|
|
return $this->executeCommand(__FUNCTION__, get_defined_vars()); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Save all players. |
154
|
|
|
* @return array|string |
155
|
|
|
*/ |
156
|
|
|
public function saveAll() |
157
|
|
|
{ |
158
|
|
|
return $this->executeCommand(__FUNCTION__, get_defined_vars()); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Display a message to all online players |
163
|
|
|
* @param string $message |
164
|
|
|
* @return array|string |
165
|
|
|
*/ |
166
|
|
|
public function notify(string $message) |
167
|
|
|
{ |
168
|
|
|
return $this->executeCommand(__FUNCTION__, get_defined_vars()); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Send announcement |
173
|
|
|
* @param string $message |
174
|
|
|
* @return array|string |
175
|
|
|
*/ |
176
|
|
|
public function announce(string $message) |
177
|
|
|
{ |
178
|
|
|
return $this->executeCommand(__FUNCTION__, get_defined_vars()); |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|