33namespace App \GameHandlers ;
44
55use App \Contracts \GameHandler ;
6+ use App \Contracts \HasQueryPort ;
67use App \Models \ModPreset ;
78use App \Models \Server ;
89use Illuminate \Database \Eloquent \Model ;
10+ use Illuminate \Validation \Rule ;
911
1012abstract class AbstractGameHandler implements GameHandler
1113{
@@ -65,11 +67,27 @@ final public function settingsRelationName(): ?string
6567 // Default Implementations (override as needed)
6668 // ---------------------------------------------------------------
6769
70+ /**
71+ * @return array<string, mixed>
72+ */
6873 public function serverValidationRules (?Server $ server = null ): array
6974 {
70- return [];
75+ $ rules = [];
76+
77+ if ($ this instanceof HasQueryPort) {
78+ $ rules ['query_port ' ] = [
79+ 'required ' , 'integer ' , 'min:1 ' , 'max:65535 ' ,
80+ Rule::unique ('servers ' , 'query_port ' )->when ($ server , fn ($ rule ) => $ rule ->ignore ($ server ->id )),
81+ Rule::unique ('servers ' , 'port ' )->when ($ server , fn ($ rule ) => $ rule ->ignore ($ server ->id )),
82+ ];
83+ }
84+
85+ return $ rules ;
7186 }
7287
88+ /**
89+ * @return array<string, mixed>
90+ */
7391 public function settingsValidationRules (): array
7492 {
7593 return [];
@@ -89,6 +107,9 @@ public function createRelatedSettings(Server $server): void
89107 $ this ->settingsModelClass ::query ()->create (['server_id ' => $ server ->id ]);
90108 }
91109
110+ /**
111+ * @param array<string, mixed> $validated
112+ */
92113 public function updateRelatedSettings (Server $ server , array $ validated ): void
93114 {
94115 if ($ this ->settingsRelationName === null || $ this ->settingsModelClass === null ) {
@@ -115,6 +136,9 @@ public function modSections(): array
115136 return [];
116137 }
117138
139+ /**
140+ * @param array<string, mixed> $validated
141+ */
118142 public function syncPresetMods (ModPreset $ preset , array $ validated ): void
119143 {
120144 // No-op for handlers without mod support.
0 commit comments