using System; using System.Threading.Tasks; namespace MistoxHolePunch { enum Mode { Server, Client } class Program { static serverExample? server; static clientExample? client; static Mode mode; async Task StartServer(string name, int port) { server = new serverExample(); await server.StartServer(name, port); // On a game this sleep loop isnt needed if (server.serverObject == null) return; while (server.serverObject.Alive) { // becuase this is a console app if we dont keep the main thread alive the app will close await Task.Delay(5000); } } async Task StartClient(string username, string host, int port, string password) { client = new clientExample(); await client.StartClient(username, host, port, password); // On a game this sleep loop isnt needed if (client.clientObject == null) return; while (client.clientObject.Alive) { // becuase this is a console app if we dont keep the main thread alive the app will close await Task.Delay(5000); } } async Task Main(string[] args) { string Job = args.Length > 0 ? args[0].ToLower() : ""; string host = ""; string name = ""; string pass = ""; int port = 0; for( int i = 0; i < args.Length; i++ ) { string cur = args[i].ToLower(); if( cur == "/h" || cur == "-h" ) { host = args [i + 1]; } else if( cur == "/p" || cur == "-p" ) { port = Convert.ToInt32( args [i + 1] ); } else if( cur == "/n" || cur == "-n" ) { name = args [i + 1]; } else if( cur == "/u" || cur == "-u" ) { pass = args [i + 1]; } } if (Job == "/?" || Job == "--help") { Console.WriteLine(HelpDocumentation.HelpText); } else if (Job == "/s" || Job == "-s") { await StartServer(name, port); } else if (Job == "/c" || Job == "-c") { await StartClient(name, host, port, pass); } else { await StartServer("example.com", 4500); } } } }