1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Gameap\Http\Requests\API; |
4
|
|
|
|
5
|
|
|
use Gameap\Http\Requests\JsonRequest; |
6
|
|
|
use Illuminate\Validation\Rule; |
7
|
|
|
|
8
|
|
|
class SaveServerRequest extends JsonRequest |
9
|
|
|
{ |
10
|
|
|
public function rules(): array |
11
|
|
|
{ |
12
|
|
|
$portRules = ['nullable', 'numeric', 'digits_between:1,65535', |
13
|
|
|
Rule::unique('servers', 'server_port') |
14
|
|
|
->ignore($this->route('server')) |
15
|
|
|
->where(function ($query) { |
16
|
|
|
$q = $query |
17
|
|
|
->where('ds_id', $this->ds_id) |
18
|
|
|
->where('server_ip', $this->server_ip) |
19
|
|
|
->whereNull('deleted_at'); |
20
|
|
|
|
21
|
|
|
if ($this->id) { |
22
|
|
|
$q->where('id', '!=', $this->id); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
return $q; |
26
|
|
|
}), |
27
|
|
|
Rule::unique('servers', 'query_port') |
28
|
|
|
->ignore($this->route('server')) |
29
|
|
|
->where(function ($query) { |
30
|
|
|
$q = $query |
31
|
|
|
->where('ds_id', $this->ds_id) |
32
|
|
|
->where('server_ip', $this->server_ip) |
33
|
|
|
->whereNull('deleted_at'); |
34
|
|
|
|
35
|
|
|
if ($this->id) { |
36
|
|
|
$q->where('id', '!=', $this->id); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
return $q; |
40
|
|
|
}), |
41
|
|
|
Rule::unique('servers', 'rcon_port') |
42
|
|
|
->ignore($this->route('server')) |
43
|
|
|
->where(function ($query) { |
44
|
|
|
$q = $query |
45
|
|
|
->where('ds_id', $this->ds_id) |
46
|
|
|
->where('server_ip', $this->server_ip) |
47
|
|
|
->whereNull('deleted_at'); |
48
|
|
|
|
49
|
|
|
if ($this->id) { |
50
|
|
|
$q->where('id', '!=', $this->id); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $q; |
54
|
|
|
}), |
55
|
|
|
]; |
56
|
|
|
|
57
|
|
|
return [ |
58
|
|
|
'id' => '', |
59
|
|
|
'enabled' => '', |
60
|
|
|
'blocked' => '', |
61
|
|
|
'installed' => '', |
62
|
|
|
'name' => 'required|max:128', |
63
|
|
|
'game_id' => 'required', |
64
|
|
|
'ds_id' => 'required', |
65
|
|
|
'game_mod_id' => 'required|exists:game_mods,id', |
66
|
|
|
'server_ip' => 'required', |
67
|
|
|
|
68
|
|
|
'server_port' => array_merge(['required'], $portRules), |
69
|
|
|
'query_port' => array_merge(['nullable'], $portRules), |
70
|
|
|
'rcon_port' => array_merge(['nullable'], $portRules), |
71
|
|
|
|
72
|
|
|
'dir' => ['nullable', 'string', Rule::unique('servers', 'dir') |
73
|
|
|
->ignore($this->route('server')) |
74
|
|
|
->where(function ($query) { |
75
|
|
|
return $query->where('ds_id', $this->ds_id) |
76
|
|
|
->whereNull('deleted_at'); |
77
|
|
|
}), ], |
78
|
|
|
]; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|