AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
CommandlineArgs.cs
1 using UnityEngine;
2 using System;
3 using Utility;
4 using Commons;
5 
6 
7 namespace AirControl {
8 
9  public class CommandlineArgs: MonoBehaviour {
10 
11  static string cmdInfo = "";
12 
13  // // link current airplane to the active airplane
14  // public GameObject currentAirplane;
15  // public GameObject ActiveAirplane;
16 
17  // /// <summary>
18  // /// It takes the command line arguments, parses them, and then calls the ParseIt function
19  // /// </summary>
20  // void Awake() {
21  // string[] arguments = Environment.GetCommandLineArgs();
22  // Arguments CommandLine = new Arguments(arguments);
23  // ParseIt(CommandLine);
24 
25  // if (true){
26  // ActiveAirplane = currentAirplane;
27  // }
28 
29  // }
30 
35  void OnGUI() {
36 
37  Rect r = new Rect(5, 5, 800, 500);
38  GUI.Label(r, cmdInfo);
39  }
40 
45  void ParseIt(Arguments CommandLine) {
46  /* Parsing the port number from the command line and sets the port number to the
47  global variable `CommonFunctions.ServerPort` */
48  DefineServerPort(CommandLine);
49  /* This function displays the host and port of the client */
50  DisplayHostPortClient(CommandLine);
51 
52  }
53 
59  void DefineServerPort(Arguments CommandLine){
60  //parse port from commandline
61  if (int.TryParse(CommandLine["serverPort"], out _)) {
62  // if port provided
63  CommonFunctions.ServerPort = int.Parse(CommandLine["serverPort"]);
64  Console.WriteLine("Server port is defined as : "+ CommonFunctions.ServerPort);
65  } else {
66  //If no port is provided, set default port
67  CommonFunctions.ServerPort = 8054;
68  Console.WriteLine("Server Port not defined. Selecting default: "+ CommonFunctions.ServerPort);
69  }
70  }
71 
76  void DisplayHostPortClient(Arguments CommandLine){
77  if (CommandLine["clientIP"] != "") {
78  // if port provided
79  CommonFunctions.clientIP = CommandLine["clientIP"];
80  Console.WriteLine("ClientIP is defined as : "+ CommonFunctions.clientIP);
81  } else {
82  //If no port is provided, set default port
83  Console.WriteLine("ClientIP not defined.");
84  }
85  if (CommandLine["clientPort"] != "") {
86  // if port provided
87  CommonFunctions.clientPort = CommandLine["clientPort"];
88  Console.WriteLine("ClientPort is defined as : "+ CommonFunctions.ServerPort);
89  } else {
90  //If no port is provided, set default port
91  Console.WriteLine("ClientPort not defined.");
92  }
93  }
94  }
95 
96 }
AirControl.CommandlineArgs
Definition: CommandlineArgs.cs:9
Utility
Simple Commandline Argument Parser https://www.codeproject.com/Articles/3111/C-NET-Command-Line-Argum...
Definition: Arguments.cs:12
Utility.Arguments
Definition: Arguments.cs:13
AirControl
Definition: AirplaneSelector.cs:8
Commons
Definition: AirplaneProperties.cs:14