1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Gameap\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Gameap\Http\Requests\ServerVarsRequest; |
6
|
|
|
use Gameap\Models\Server; |
7
|
|
|
use Gameap\Models\ServerSetting; |
8
|
|
|
use Gameap\Repositories\ServerRepository; |
9
|
|
|
use Gameap\Services\RconService; |
10
|
|
|
use Illuminate\Support\Facades\Auth; |
11
|
|
|
use Knik\GRcon\Exceptions\GRconException; |
12
|
|
|
|
13
|
|
|
class ServersController extends AuthController |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* The ServerRepository instance. |
17
|
|
|
* |
18
|
|
|
* @var \Gameap\Repositories\ServerRepository |
19
|
|
|
*/ |
20
|
|
|
protected $repository; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Create a new ServersController instance. |
24
|
|
|
* |
25
|
|
|
* @param ServerRepository $repository |
26
|
|
|
*/ |
27
|
6 |
|
public function __construct(ServerRepository $repository) |
28
|
|
|
{ |
29
|
6 |
|
parent::__construct(); |
30
|
|
|
|
31
|
6 |
|
$this->repository = $repository; |
32
|
6 |
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Display a listing of the resource. |
36
|
|
|
* |
37
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
38
|
|
|
*/ |
39
|
|
|
public function index() |
40
|
|
|
{ |
41
|
|
|
return view('servers.list',[ |
42
|
|
|
'servers' => $this->repository->getServersForAuth() |
43
|
|
|
]); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Display the specified resource. |
48
|
|
|
* |
49
|
|
|
* @param RconService $rconService |
50
|
|
|
* @param \Gameap\Models\Server $server |
51
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
52
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException |
53
|
|
|
*/ |
54
|
6 |
|
public function show(RconService $rconService, Server $server) |
55
|
|
|
{ |
56
|
6 |
|
$this->authorize('server-control', $server); |
57
|
|
|
|
58
|
3 |
|
$autostartSetting = $server->settings->where('name', 'autostart')->first() |
59
|
3 |
|
?? new ServerSetting([ |
60
|
3 |
|
'server_id' => $server->id, |
61
|
3 |
|
'name' => 'autostart', |
62
|
|
|
'value' => false, |
63
|
|
|
]); |
64
|
|
|
|
65
|
3 |
|
$autostart = $autostartSetting->value; |
66
|
|
|
|
67
|
3 |
|
$rconSupportedFeatures = $rconService->supportedFeatures($server); |
68
|
3 |
|
$rconSupported = $rconSupportedFeatures['rcon']; |
69
|
|
|
|
70
|
3 |
|
return ($server->installed === $server::INSTALLED && $server->enabled && !$server->blocked) ? |
71
|
|
|
view('servers.view', compact('server', 'autostart', 'rconSupportedFeatures', 'rconSupported')) |
72
|
3 |
|
: view('servers.not_active', compact('server')); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param ServerVarsRequest $request |
77
|
|
|
* @param Server $server |
78
|
|
|
* @return \Illuminate\Http\RedirectResponse |
79
|
|
|
* |
80
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException |
81
|
|
|
*/ |
82
|
|
|
public function updateSettings(ServerVarsRequest $request, Server $server) |
83
|
|
|
{ |
84
|
|
|
$this->authorize('server-control', $server); |
85
|
|
|
$this->authorize('server-settings', $server); |
86
|
|
|
|
87
|
|
|
$this->repository->updateAutostart($server, ($request->get('autostart') == true)); |
88
|
|
|
$this->repository->updateVars($server, $request); |
89
|
|
|
|
90
|
|
|
return redirect()->to(route('servers.control', ['server' => $server->id]) . '#settings') |
91
|
|
|
->with('success', __('servers.update_success_msg')); |
92
|
|
|
} |
93
|
|
|
} |