@@ -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