1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Gameap\Http\Controllers\API; |
4
|
|
|
|
5
|
|
|
use Gameap\Http\Controllers\AuthController; |
|
|
|
|
6
|
|
|
use Gameap\Http\Requests\API\Rcon\BanRequest; |
7
|
|
|
use Gameap\Http\Requests\API\Rcon\CommandRequest; |
8
|
|
|
use Gameap\Http\Requests\API\Rcon\KickRequest; |
9
|
|
|
use Gameap\Models\Server; |
10
|
|
|
use Gameap\Services\RconService; |
11
|
|
|
|
12
|
|
|
class ServersRconController extends AuthController |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Get supported features list |
16
|
|
|
* |
17
|
|
|
* @param RconService $rconService |
18
|
|
|
* @param Server $server |
19
|
|
|
* @return array |
20
|
|
|
* @throws \Knik\GRcon\Exceptions\ProtocolNotSupportedException |
21
|
|
|
*/ |
22
|
|
|
public function supportedFeatures(RconService $rconService, Server $server) |
23
|
|
|
{ |
24
|
|
|
return $rconService->supportedFeatures($server); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function fastRcon(Server $server) |
28
|
|
|
{ |
29
|
|
|
$this->authorize('server-rcon-console', $server); |
30
|
|
|
|
31
|
|
|
return $server->gameMod->fast_rcon; |
32
|
9 |
|
} |
33
|
|
|
|
34
|
9 |
|
/** |
35
|
|
|
* @param RconService $rconService |
36
|
|
|
* @param CommandRequest $request |
37
|
6 |
|
* @return array |
38
|
|
|
*/ |
39
|
6 |
|
public function sendCommand(CommandRequest $request, RconService $rconService, Server $server) |
40
|
|
|
{ |
41
|
|
|
$this->authorize('server-rcon-console', $server); |
42
|
|
|
|
43
|
|
|
return [ |
44
|
|
|
'output' => $server->processActive() |
45
|
|
|
? $rconService->sendCommand($server, $request->post('command')) |
|
|
|
|
46
|
|
|
: 'Server is offline', |
47
|
|
|
]; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
9 |
|
* Get Player list |
52
|
|
|
* |
53
|
9 |
|
* @param RconService $rconService |
54
|
|
|
* @param Server $server |
55
|
6 |
|
* @return array |
56
|
6 |
|
* @throws \Knik\GRcon\Exceptions\PlayersManageNotSupportedExceptions |
57
|
|
|
*/ |
58
|
|
|
public function getPlayers(RconService $rconService, Server $server) |
59
|
|
|
{ |
60
|
|
|
$this->authorize('server-rcon-players', $server); |
61
|
|
|
|
62
|
|
|
if (!$server->processActive()) { |
63
|
|
|
return []; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $rconService->getPlayers($server); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Kick Player |
71
|
9 |
|
* |
72
|
|
|
* @param KickRequest $request |
73
|
9 |
|
* @param RconService $rconService |
74
|
|
|
* @param Server $server |
75
|
6 |
|
* @return mixed |
76
|
6 |
|
* @throws \Knik\GRcon\Exceptions\ProtocolNotSupportedException |
77
|
|
|
*/ |
78
|
|
|
public function kick(KickRequest $request, RconService $rconService, Server $server) |
79
|
|
|
{ |
80
|
|
|
$this->authorize('server-rcon-players', $server); |
81
|
|
|
|
82
|
|
|
if (!$server->processActive()) { |
83
|
|
|
return 'Server is offline'; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return $rconService->kick($server, $request->post('player'), $request->post('reason')); |
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Ban Player |
91
|
|
|
* |
92
|
9 |
|
* @param BanRequest $request |
93
|
|
|
* @param RconService $rconService |
94
|
9 |
|
* @param Server $server |
95
|
|
|
* @return mixed |
96
|
6 |
|
* @throws \Knik\GRcon\Exceptions\PlayersManageNotSupportedExceptions |
97
|
6 |
|
* @throws \Knik\GRcon\Exceptions\ProtocolNotSupportedException |
98
|
|
|
*/ |
99
|
|
|
public function ban(BanRequest $request, RconService $rconService, Server $server) |
100
|
|
|
{ |
101
|
|
|
$this->authorize('server-rcon-players', $server); |
102
|
|
|
|
103
|
|
|
if (!$server->processActive()) { |
104
|
|
|
return 'Server is offline'; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return $rconService->ban( |
108
|
9 |
|
$server, |
109
|
|
|
$request->post('player'), |
110
|
9 |
|
$request->post('reason'), |
|
|
|
|
111
|
|
|
$request->post('time') |
|
|
|
|
112
|
6 |
|
); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function message(RconService $rconService, Server $server) |
116
|
6 |
|
{ |
117
|
|
|
$this->authorize('server-rcon-players', $server); |
118
|
|
|
|
119
|
|
|
if ($server->processActive()) { |
120
|
|
|
return 'Server is offline'; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
return 'Not implemented'; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: