Skip to content
This repository was archived by the owner on Apr 15, 2026. It is now read-only.

Commit 791f87b

Browse files
author
Dankrushen
authored
Merge pull request #234 from ServerMod/dank-3.3.0
Finalize release 3.3.0
2 parents d86e9e6 + 5c33ab6 commit 791f87b

10 files changed

Lines changed: 320 additions & 75 deletions

File tree

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using System.Text;
4+
using MultiAdmin.Config;
5+
using MultiAdmin.Config.ConfigHandler;
6+
using MultiAdmin.Features.Attributes;
7+
using MultiAdmin.Utility;
8+
9+
namespace MultiAdmin.Features
10+
{
11+
[Feature]
12+
internal class ConfigGenerator : Feature, ICommand
13+
{
14+
15+
public ConfigGenerator(Server server) : base(server)
16+
{
17+
}
18+
19+
public string GetCommand()
20+
{
21+
return "CONFIGGEN";
22+
}
23+
24+
public string GetCommandDescription()
25+
{
26+
return "Generates a full default MultiAdmin config file";
27+
}
28+
29+
public string GetUsage()
30+
{
31+
return "[FILE LOCATION]";
32+
}
33+
34+
public void OnCall(string[] args)
35+
{
36+
if (args.IsEmpty())
37+
{
38+
Server.Write("You must specify the location of the file.");
39+
return;
40+
}
41+
42+
string path = Utils.GetFullPathSafe(string.Join(" ", args));
43+
44+
ConfigEntry[] registeredConfigs = MultiAdminConfig.GlobalConfig.GetRegisteredConfigs();
45+
46+
List<string> lines = new List<string>(registeredConfigs.Length);
47+
foreach (ConfigEntry configEntry in registeredConfigs)
48+
{
49+
switch (configEntry)
50+
{
51+
case ConfigEntry<string[]> config:
52+
{
53+
lines.Add($"{config.Key}: {(config.Default == null ? "" : string.Join(", ", config.Default))}");
54+
break;
55+
}
56+
57+
default:
58+
{
59+
lines.Add($"{configEntry.Key}: {configEntry.ObjectDefault ?? ""}");
60+
break;
61+
}
62+
}
63+
}
64+
65+
File.WriteAllLines(path, lines);
66+
Server.Write($"Default config written to \"{path}\"");
67+
}
68+
69+
public bool PassToGame()
70+
{
71+
return false;
72+
}
73+
74+
public override void OnConfigReload()
75+
{
76+
}
77+
78+
public override string GetFeatureDescription()
79+
{
80+
return "Generates a full default MultiAdmin config file";
81+
}
82+
83+
public override string GetFeatureName()
84+
{
85+
return "Config Generator";
86+
}
87+
88+
public override void Init()
89+
{
90+
}
91+
}
92+
}

MultiAdmin/Features/GithubGenerator.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ public void OnCall(string[] args)
4747

4848
foreach (Feature feature in Server.features)
4949
{
50-
if (feature.Equals(this)) continue;
51-
5250
lines.Add($"- {feature.GetFeatureName()}: {feature.GetFeatureDescription()}");
5351
}
5452

@@ -152,12 +150,12 @@ public override void OnConfigReload()
152150

153151
public override string GetFeatureDescription()
154152
{
155-
return "NOT INCLUDED IN FILE";
153+
return "Generates a GitHub README file outlining all the features/commands";
156154
}
157155

158156
public override string GetFeatureName()
159157
{
160-
return "GITHUB GEN";
158+
return "GitHub Generator";
161159
}
162160

163161
public override void Init()

MultiAdmin/Features/NewCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void OnCall(string[] args)
2828

2929
Server.Write($"Launching new server with Server ID: \"{serverId}\"...");
3030

31-
Program.StartServer(new Server(serverId));
31+
Program.StartServer(new Server(serverId, args: Program.Args));
3232
}
3333
}
3434

@@ -86,7 +86,7 @@ public void OnServerFull()
8686

8787
Server.Write($"Launching new server with Server ID: \"{onFullServerId}\" due to this server being full...");
8888

89-
onFullServerInstance = Program.StartServer(new Server(onFullServerId));
89+
onFullServerInstance = Program.StartServer(new Server(onFullServerId, args: Program.Args));
9090
}
9191
}
9292
}

MultiAdmin/ModFeatures.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
3+
namespace MultiAdmin
4+
{
5+
[Flags]
6+
public enum ModFeatures
7+
{
8+
None = 0,
9+
10+
// Replaces detecting game output with MultiAdmin events for game events
11+
CustomEvents = 1 << 0,
12+
13+
// Supporting all current features
14+
All = ~(~0 << 1)
15+
}
16+
}

MultiAdmin/Program.cs

Lines changed: 54 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace MultiAdmin
1515
{
1616
public static class Program
1717
{
18-
public const string MaVersion = "3.3.0.1";
18+
public const string MaVersion = "3.3.0.3";
1919
public const string RecommendedMonoVersion = "5.18";
2020

2121
private static readonly List<Server> InstantiatedServers = new List<Server>();
@@ -28,6 +28,7 @@ public static class Program
2828
: null;
2929

3030
private static uint? portArg;
31+
public static readonly string[] Args = Environment.GetCommandLineArgs();
3132

3233
private static IExitSignal exitSignalListener;
3334

@@ -37,7 +38,7 @@ public static class Program
3738
#region Server Properties
3839

3940
public static Server[] Servers => ServerDirectories
40-
.Select(serverDir => new Server(Path.GetFileName(serverDir), serverDir, portArg)).ToArray();
41+
.Select(serverDir => new Server(Path.GetFileName(serverDir), serverDir, portArg, Args)).ToArray();
4142

4243
public static string[] ServerDirectories
4344
{
@@ -206,28 +207,32 @@ public static void Main()
206207
exitSignalListener.Exit += OnExit;
207208
}
208209

209-
Headless = GetFlagFromArgs("headless", "h");
210+
// Remove executable path
211+
if (Args.Length > 0)
212+
Args[0] = null;
213+
214+
Headless = GetFlagFromArgs(Args, "headless", "h");
210215

211216
if (!Headless)
212217
CheckMonoVersion();
213218

214-
string serverIdArg = GetParamFromArgs("server-id", "id");
215-
string configArg = GetParamFromArgs("config", "c");
216-
portArg = uint.TryParse(GetParamFromArgs("port", "p"), out uint port) ? (uint?)port : null;
219+
string serverIdArg = GetParamFromArgs(Args, "server-id", "id");
220+
string configArg = GetParamFromArgs(Args, "config", "c");
221+
portArg = uint.TryParse(GetParamFromArgs(Args, "port", "p"), out uint port) ? (uint?)port : null;
217222

218223
Server server = null;
219224

220225
if (!string.IsNullOrEmpty(serverIdArg) || !string.IsNullOrEmpty(configArg))
221226
{
222-
server = new Server(serverIdArg, configArg, portArg);
227+
server = new Server(serverIdArg, configArg, portArg, Args);
223228

224229
InstantiatedServers.Add(server);
225230
}
226231
else
227232
{
228233
if (Servers.IsEmpty())
229234
{
230-
server = new Server(port: portArg);
235+
server = new Server(port: portArg, args: Args);
231236

232237
InstantiatedServers.Add(server);
233238
}
@@ -240,7 +245,7 @@ public static void Main()
240245
Write("No servers are set to automatically start, please enter a Server ID to start:");
241246
InputHandler.InputPrefix?.Write();
242247

243-
server = new Server(Console.ReadLine(), port: portArg);
248+
server = new Server(Console.ReadLine(), port: portArg, args: Args);
244249

245250
InstantiatedServers.Add(server);
246251
}
@@ -284,15 +289,13 @@ public static void Main()
284289
}
285290
}
286291

287-
public static string GetParamFromArgs(string[] keys = null, string[] aliases = null)
292+
public static string GetParamFromArgs(string[] args, string[] keys = null, string[] aliases = null)
288293
{
289294
bool hasKeys = !keys.IsNullOrEmpty();
290295
bool hasAliases = !aliases.IsNullOrEmpty();
291296

292297
if (!hasKeys && !hasAliases) return null;
293298

294-
string[] args = Environment.GetCommandLineArgs();
295-
296299
for (int i = 0; i < args.Length - 1; i++)
297300
{
298301
string lowArg = args[i]?.ToLower();
@@ -301,44 +304,61 @@ public static string GetParamFromArgs(string[] keys = null, string[] aliases = n
301304

302305
if (hasKeys)
303306
{
304-
if (keys.Any(key => !string.IsNullOrEmpty(key) && lowArg == $"--{key.ToLower()}"))
307+
if (keys.Any(key => lowArg == $"--{key?.ToLower()}"))
305308
{
306-
return args[i + 1];
309+
string value = args[i + 1];
310+
311+
args[i] = null;
312+
args[i + 1] = null;
313+
314+
return value;
307315
}
308316
}
309317

310318
if (hasAliases)
311319
{
312-
if (aliases.Any(alias => !string.IsNullOrEmpty(alias) && lowArg == $"-{alias.ToLower()}"))
320+
if (aliases.Any(alias => lowArg == $"-{alias?.ToLower()}"))
313321
{
314-
return args[i + 1];
322+
string value = args[i + 1];
323+
324+
args[i] = null;
325+
args[i + 1] = null;
326+
327+
return value;
315328
}
316329
}
317330
}
318331

319332
return null;
320333
}
321334

322-
public static bool ArgsContainsParam(string[] keys = null, string[] aliases = null)
335+
public static bool ArgsContainsParam(string[] args, string[] keys = null, string[] aliases = null)
323336
{
324-
foreach (string arg in Environment.GetCommandLineArgs())
337+
bool hasKeys = !keys.IsNullOrEmpty();
338+
bool hasAliases = !aliases.IsNullOrEmpty();
339+
340+
if (!hasKeys && !hasAliases) return false;
341+
342+
for (int i = 0; i < args.Length; i++)
325343
{
326-
string lowArg = arg?.ToLower();
344+
string lowArg = args[i]?.ToLower();
327345

328346
if (string.IsNullOrEmpty(lowArg)) continue;
329347

330-
if (!keys.IsNullOrEmpty())
348+
if (hasKeys)
331349
{
332-
if (keys.Any(key => !string.IsNullOrEmpty(key) && lowArg == $"--{key.ToLower()}"))
350+
if (keys.Any(key => lowArg == $"--{key?.ToLower()}"))
333351
{
352+
args[i] = null;
334353
return true;
335354
}
336355
}
337356

338-
if (!aliases.IsNullOrEmpty())
357+
if (hasAliases)
339358
{
340-
if (aliases.Any(alias => !string.IsNullOrEmpty(alias) && lowArg == $"-{alias.ToLower()}"))
359+
if (aliases.Any(alias => lowArg == $"-{alias?.ToLower()}"))
341360
{
361+
args[i] = null;
342362
return true;
343363
}
344364
}
@@ -347,28 +367,28 @@ public static bool ArgsContainsParam(string[] keys = null, string[] aliases = nu
347367
return false;
348368
}
349369

350-
public static bool GetFlagFromArgs(string[] keys = null, string[] aliases = null)
370+
public static bool GetFlagFromArgs(string[] args, string[] keys = null, string[] aliases = null)
351371
{
352372
if (keys.IsNullOrEmpty() && aliases.IsNullOrEmpty()) return false;
353373

354-
return bool.TryParse(GetParamFromArgs(keys, aliases), out bool result)
374+
return bool.TryParse(GetParamFromArgs(args, keys, aliases), out bool result)
355375
? result
356-
: ArgsContainsParam(keys, aliases);
376+
: ArgsContainsParam(args, keys, aliases);
357377
}
358378

359-
public static string GetParamFromArgs(string key = null, string alias = null)
379+
public static string GetParamFromArgs(string[] args, string key = null, string alias = null)
360380
{
361-
return GetParamFromArgs(new string[] {key}, new string[] {alias});
381+
return GetParamFromArgs(args, new string[] {key}, new string[] {alias});
362382
}
363383

364-
public static bool ArgsContainsParam(string key = null, string alias = null)
384+
public static bool ArgsContainsParam(string[] args, string key = null, string alias = null)
365385
{
366-
return ArgsContainsParam(new string[] {key}, new string[] {alias});
386+
return ArgsContainsParam(args, new string[] {key}, new string[] {alias});
367387
}
368388

369-
public static bool GetFlagFromArgs(string key = null, string alias = null)
389+
public static bool GetFlagFromArgs(string[] args, string key = null, string alias = null)
370390
{
371-
return GetFlagFromArgs(new string[] {key}, new string[] {alias});
391+
return GetFlagFromArgs(args, new string[] {key}, new string[] {alias});
372392
}
373393

374394
public static Process StartServer(Server server)
@@ -380,7 +400,7 @@ public static Process StartServer(Server server)
380400
Write("Error while starting new server: Could not find the executable location!", ConsoleColor.Red);
381401
}
382402

383-
List<string> args = new List<string>();
403+
List<string> args = new List<string>(server.args);
384404

385405
if (!string.IsNullOrEmpty(server.serverId))
386406
args.Add($"-id \"{server.serverId}\"");
@@ -391,11 +411,7 @@ public static Process StartServer(Server server)
391411
if (Headless)
392412
args.Add("-h");
393413

394-
args.RemoveAll(string.IsNullOrEmpty);
395-
396-
string stringArgs = string.Join(" ", args);
397-
398-
ProcessStartInfo startInfo = new ProcessStartInfo(assemblyLocation, stringArgs);
414+
ProcessStartInfo startInfo = new ProcessStartInfo(assemblyLocation, args.JoinArgs());
399415

400416
Write($"Launching \"{startInfo.FileName}\" with arguments \"{startInfo.Arguments}\"...");
401417

0 commit comments

Comments
 (0)