static void Main(string[] args) { reader = new ConsoleReader(); reader.Title = "Gateway server, type help for commands"; reader.Initialize += new EventHandler(reader_Initialize); reader.Register(new ConsoleCommandHandler(Version)); reader.Register(new ConsoleCommandHandler(CrcValidationCheck)); reader.Register(new ConsoleCommandHandler(CheckHost)); reader.Register(new ConsoleCommandHandler(Shutdown)); reader.Clear(null); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); //SagaConfigurationManager.read(); string file = System.Reflection.Assembly.GetExecutingAssembly().Location; string fname = Path.GetFileNameWithoutExtension(file); //TRACELOG Trace.AutoFlush = true; Trace.IndentSize = 4; if (System.Diagnostics.Trace.Listeners.Count <= 1 && (System.Diagnostics.Trace.Listeners["Default"] == null || System.Diagnostics.Trace.Listeners["Default"].GetType() == typeof(System.Diagnostics.DefaultTraceListener))) { DelimitedListTraceListener del = new System.Diagnostics.DelimitedListTraceListener((fname + ".log.csv"), "text"); del.Delimiter = ","; System.Diagnostics.Trace.Listeners.Add(del); } Trace.WriteLine("#############################################################################"); Trace.WriteLine(string.Format("Saga Gateway Server starting on: {0}", DateTime.Now)); Trace.WriteLine(string.Format("OS Information: {0}", Environment.OSVersion)); Trace.WriteLine(string.Format("Number of Processors: {0}", Environment.ProcessorCount)); Trace.WriteLine(string.Format("CLR Version: {0}", Environment.Version)); Trace.WriteLine(string.Format("Working set: {0}", Environment.WorkingSet)); Trace.WriteLine(string.Format("OS Bit Version: {0} Bit", IntPtr.Size * 8)); Trace.WriteLine("#############################################################################"); System.Configuration.Configuration b = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); if (CheckConfigExists() == false) { Console.WriteLine("First time run-configuration"); char key; ConfigureGatewayNetwork: Console.WriteLine("Do you wan to configure the gateway-network settings? Y/N"); key = Console.ReadKey(true).KeyChar; if (key == 'y') { Console.WriteLine("What ip should the gateway server listen to?"); while (!IPAddress.TryParse(Console.ReadLine(), out gatewayip)) { Console.WriteLine("Incorrect value please use an ipv4 adress, recommended 0.0.0.0"); } Console.WriteLine("What port should the gateway server listen to?"); while (!int.TryParse(Console.ReadLine(), out gatewayport)) { Console.WriteLine("Incorrect value please use an number between 1024–49151, recommended 64000"); } } else if (key != 'n') { goto ConfigureGatewayNetwork; } ConfigureAuthenticationNetwork: Console.WriteLine("Do you wan to configure the authentication-network settings? Y/N"); key = Console.ReadKey(true).KeyChar; if (key == 'y') { Console.WriteLine("What is the ip of the authentication server"); while (!IPAddress.TryParse(Console.ReadLine(), out authenticationip)) { Console.WriteLine("Incorrect value please use an ipv4 adress, recommended 0.0.0.0"); } Console.WriteLine("On what port is the authentication server listening"); while (!int.TryParse(Console.ReadLine(), out authenticationport)) { Console.WriteLine("Incorrect value please use an number between 1024–49151, recommended 64000"); } } else if (key != 'n') { goto ConfigureAuthenticationNetwork; } ConfigureGUID: Console.WriteLine("Do you wan to configure the gateway-guid settings? Y/N"); key = Console.ReadKey(true).KeyChar; if (key == 'y') { Console.WriteLine("What is the crc key"); byte[] ncrckey; while (!Conversions.TryParse(Console.ReadLine(), out ncrckey) || crckey.Length != 20) { Console.WriteLine("Crc key key must be 20 hex digit string, recommended: A928CDC9DBE8751B3BC99EB65AE07E0C849CE739"); } Console.WriteLine("What is the guid key"); byte[] nguidkey; while (!Conversions.TryParse(Console.ReadLine(), out nguidkey) || guidkey.Length != 20) { Console.WriteLine("Guid key key must be 20 hex digit string, recommended: ED90AA25AE906FB36308C8523A4737A7E7B1FC6F"); } crckey = Conversions.ByteToHexString(ncrckey); guidkey = Conversions.ByteToHexString(nguidkey); } else if (key != 'n') { goto ConfigureGUID; } NetworkSettings networkSettings = new NetworkSettings(); NetworkFileCollection collection = networkSettings.Connections; collection["public"] = new NetworkElement("public", gatewayip.ToString(), gatewayport); collection["internal"] = new NetworkElement("internal", authenticationip.ToString(), authenticationport); networkSettings.Crckey = crckey; networkSettings.Guidkey = guidkey; b.Sections.Remove("Saga.NetworkSettings"); b.Sections.Add("Saga.NetworkSettings", networkSettings); b.Save(); ConfigurationManager.RefreshSection("Saga.NetworkSettings"); Console.WriteLine("Everything configured"); LoginClient client; for (int i = 0; i < 3; i++) { if (NetworkManager.TryGetLoginClient(out client)) { Console.WriteLine("Test connection created"); client.Close(); break; } else { Thread.Sleep(3000); Console.WriteLine("Test connection failed retrying in 3 secconds"); } } } else { Console.WriteLine("Configuration file exists"); } reader.Start(); }