private static void Main(string[] args) { bool processedargs = false; // Please dont kill the commented out lines below for the moment -NV //Misc.Playfields.Instance.playfields[0].districts.Add(new ZoneEngine.Misc.DistrictInfo()); //Misc.Playfields.Instance.playfields[0].districts[0].districtName = "some district"; //Misc.Playfields.Instance.playfields[0].districts.Add(new ZoneEngine.Misc.DistrictInfo()); //Misc.Playfields.Instance.playfields[0].districts[1].districtName = "some other district"; //Misc.DistrictInfo.DumpXML(@"C:\list.xml", Misc.Playfields.Instance.playfields[0]); #region Console Text... Console.Title = "CellAO " + AssemblyInfoclass.Title + " Console. Version: " + AssemblyInfoclass.Description + " " + AssemblyInfoclass.AssemblyVersion + " " + AssemblyInfoclass.Trademark; ConsoleText ct = new ConsoleText(); ct.TextRead("main.txt"); Console.WriteLine("Loading " + AssemblyInfoclass.Title + "..."); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Using ISComm v1.0"); Console.WriteLine("[OK]"); Console.ResetColor(); #endregion #region Delete old SqlError.log, so it doesnt get too big if (File.Exists("sqlerror.log")) { File.Delete("sqlerror.log"); } #endregion #region ISComm Code Area... Console.WriteLine("[ISComm] Waiting for Link..."); ChatCom.StartLink(Config.Instance.CurrentConfig.CommPort); //System.Console.WriteLine("[ISComm] Linked Successfully! :D"); #endregion zoneServer = new Server { EnableTCP = true, EnableUDP = false }; #region Script Loading Code Area.. csc = new ScriptCompiler(); #endregion try { zoneServer.TcpIP = IPAddress.Parse(Config.Instance.CurrentConfig.ListenIP); } catch { ct.TextRead("ip_config_parse_error.txt"); Console.ReadKey(); return; } try { zoneServer.UdpIP = IPAddress.Parse(Config.Instance.CurrentConfig.ListenIP); } catch { ct.TextRead("ip_config_parse_error.txt"); Console.ReadKey(); return; } zoneServer.TcpPort = Convert.ToInt32(Config.Instance.CurrentConfig.ZonePort); #region NLog LoggingConfiguration config = new LoggingConfiguration(); ColoredConsoleTarget consoleTarget = new ColoredConsoleTarget(); consoleTarget.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}"; FileTarget fileTarget = new FileTarget(); config.AddTarget("file", fileTarget); fileTarget.FileName = "${basedir}/ZoneEngineLog.txt"; fileTarget.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}"; LoggingRule rule1 = new LoggingRule("*", LogLevel.Trace, consoleTarget); config.LoggingRules.Add(rule1); LoggingRule rule2 = new LoggingRule("*", LogLevel.Trace, fileTarget); config.LoggingRules.Add(rule2); LogManager.Configuration = config; #endregion #region NBug SettingsOverride.LoadCustomSettings("NBug.ZoneEngine.Config"); NBug.Settings.WriteLogToDisk = true; AppDomain.CurrentDomain.UnhandledException += Handler.UnhandledException; TaskScheduler.UnobservedTaskException += Handler.UnobservedTaskException; //TODO: ADD More Handlers. #endregion FunctionC.ReadFunctions(); Console.WriteLine("Registered " + FunctionC.NumberofRegisteredFunctions().ToString() + " Functions"); #region Console Commands... string consoleCommand; ct.TextRead("zone_consolecommands.txt"); // removed CheckDBs here, added commands check and updatedb (updatedb will change to a versioning while (true) { if (!processedargs) { if (args.Length == 1) { if (args[0].ToLower() == "/autostart") { ct.TextRead("autostart.txt"); csc.Compile(false); StartTheServer(); } } processedargs = true; } Console.Write("\nServer Command >>"); consoleCommand = Console.ReadLine(); switch (consoleCommand.ToLower()) { case "start": if (zoneServer.Running) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Zone Server is already running"); Console.ResetColor(); break; } //TODO: Add Sql Check. csc.Compile(false); StartTheServer(); break; case "startm": // Multiple dll compile if (zoneServer.Running) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Zone Server is already running"); Console.ResetColor(); break; } //TODO: Add Sql Check. csc.Compile(true); StartTheServer(); break; case "stop": if (!zoneServer.Running) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Zone Server is not running"); Console.ResetColor(); break; } zoneServer.Stop(); ThreadMgr.Stop(); break; case "check": case "updatedb": using (SqlWrapper sqltester = new SqlWrapper()) { sqltester.CheckDBs(); Console.ResetColor(); } break; case "exit": case "quit": if (zoneServer.Running) { zoneServer.Stop(); ThreadMgr.Stop(); } Process.GetCurrentProcess().Kill(); break; case "ls": //list all available scripts, dont remove it since it does what it should Console.WriteLine("Available scripts"); /* Old Lua way string[] files = Directory.GetFiles("Scripts");*/ string[] files = Directory.GetFiles("Scripts\\", "*.cs", SearchOption.AllDirectories); if (files.Length == 0) { Console.WriteLine("No scripts were found."); break; } Console.ForegroundColor = ConsoleColor.Green; foreach (string s in files) { Console.WriteLine(s); /* Old Lua way if (s.EndsWith(".lua")) { Console.WriteLine(s.Split('\\')[1].Split('.')[0]); }*/ } Console.ResetColor(); break; case "ping": // ChatCom.Server.Ping(); Console.WriteLine("Ping is disabled till we can fix it"); break; case "running": if (zoneServer.Running) { Console.WriteLine("Zone Server is Running"); break; } Console.WriteLine("Zone Server not Running"); break; case "online": if (zoneServer.Running) { Console.ForegroundColor = ConsoleColor.White; lock (zoneServer.Clients) { foreach (Client c in zoneServer.Clients) { Console.WriteLine("Character " + c.Character.Name + " online"); } } Console.ResetColor(); } break; default: ct.TextRead("zone_consolecmdsdefault.txt"); break; } } }
/// <summary> /// </summary> /// <param name="args"> /// </param> private static void Main(string[] args) { bool processedargs = false; LogUtil.SetupConsoleLogging(LogLevel.Debug); LogUtil.SetupFileLogging("${basedir}/ZoneEngineLog.txt", LogLevel.Trace); SettingsOverride.LoadCustomSettings("NBug.ZoneEngine.Config"); Settings.WriteLogToDisk = true; AppDomain.CurrentDomain.UnhandledException += Handler.UnhandledException; TaskScheduler.UnobservedTaskException += Handler.UnobservedTaskException; csc = new ScriptCompiler(); // TODO: ADD More Handlers. Console.Title = "CellAO " + AssemblyInfoclass.Title + " Console. Version: " + AssemblyInfoclass.Description + " " + AssemblyInfoclass.AssemblyVersion + " " + AssemblyInfoclass.Trademark; ConsoleText ct = new ConsoleText(); ct.TextRead("main.txt"); Console.Write("Loading "); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write(AssemblyInfoclass.Title + " "); Console.ForegroundColor = ConsoleColor.White; Console.Write(AssemblyInfoclass.Description); Console.ResetColor(); Console.WriteLine("..."); zoneServer = Container.GetInstance<ZoneServer>(); int Port = Convert.ToInt32(Config.Instance.CurrentConfig.ZonePort); try { if (Config.Instance.CurrentConfig.ListenIP == "0.0.0.0") { zoneServer.TcpEndPoint = new IPEndPoint(IPAddress.Any, Port); } else { zoneServer.TcpIP = IPAddress.Parse(Config.Instance.CurrentConfig.ListenIP); } } catch { ct.TextRead("ip_config_parse_error.txt"); Console.ReadKey(); return; } string consoleCommand; ct.TextRead("zone_consolecommands.txt"); // removed CheckDBs here, added commands check and updatedb (updatedb will change to a versioning while (true) { if (!processedargs) { if (args.Length == 1) { if (args[0].ToLower() == "/autostart") { ct.TextRead("autostart.txt"); csc.Compile(false); StartTheServer(); } } processedargs = true; } Console.Write("\nServer Command >>"); consoleCommand = Console.ReadLine(); switch (consoleCommand.ToLower()) { case "start": if (zoneServer.Running) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Zone Server is already running"); Console.ResetColor(); break; } // TODO: Add Sql Check. csc.Compile(false); StartTheServer(); break; case "startm": // Multiple dll compile if (zoneServer.Running) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Zone Server is already running"); Console.ResetColor(); break; } // TODO: Add Sql Check. csc.Compile(true); StartTheServer(); break; case "stop": if (!zoneServer.Running) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Zone Server is not running"); Console.ResetColor(); break; } zoneServer.Stop(); break; case "check": case "updatedb": using (SqlWrapper sqltester = new SqlWrapper()) { sqltester.CheckDBs(); Console.ResetColor(); } break; case "exit": case "quit": if (zoneServer.Running) { zoneServer.Stop(); } Process.GetCurrentProcess().Kill(); break; case "ls": // list all available scripts, dont remove it since it does what it should Console.WriteLine("Available scripts"); /* Old Lua way string[] files = Directory.GetFiles("Scripts");*/ try { string[] files = Directory.GetFiles("Scripts", "*.cs", SearchOption.AllDirectories); if (files.Length == 0) { Console.WriteLine("No scripts were found."); break; } Console.ForegroundColor = ConsoleColor.Green; foreach (string s in files) { Console.WriteLine(s); } } catch (Exception) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Scripts folder not found."); } Console.ResetColor(); break; case "ping": // ChatCom.Server.Ping(); Console.WriteLine("Ping is disabled till we can fix it"); break; case "running": if (zoneServer.Running) { Console.WriteLine("Zone Server is Running"); break; } Console.WriteLine("Zone Server not Running"); break; case "online": if (zoneServer.Running) { Console.ForegroundColor = ConsoleColor.White; lock (zoneServer.Clients) { foreach (Client c in zoneServer.Clients) { Console.WriteLine("Character " + c.Character.Name + " online"); } } Console.ResetColor(); } break; default: ct.TextRead("zone_consolecmdsdefault.txt"); break; } } }
public static void StartTheServer() { try { Console.ForegroundColor = ConsoleColor.Green; zoneServer.Monsters = new List<NonPlayerCharacterClass>(); zoneServer.Vendors = new List<VendingMachine>(); zoneServer.Doors = new List<Doors>(); using (SqlWrapper sqltester = new SqlWrapper()) { if (sqltester.SQLCheck() != SqlWrapper.DBCheckCodes.DBC_ok) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Database setup not correct"); Console.WriteLine("Error: #" + sqltester.lasterrorcode + " - " + sqltester.lasterrormessage); Console.WriteLine("Please press Enter to exit."); Console.ReadLine(); Process.GetCurrentProcess().Kill(); } sqltester.CheckDBs(); } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Loaded {0} items", ItemHandler.CacheAllItems()); Console.WriteLine("Loaded {0} nanos", NanoHandler.CacheAllNanos()); Console.WriteLine("Loaded {0} spawns", NonPlayerCharacterHandler.CacheAllFromDB()); Console.WriteLine("Loaded {0} vendors", VendorHandler.CacheAllFromDB()); Console.WriteLine("Loaded {0} teleports", DoorHandler.CacheAllFromDB()); Console.WriteLine("Loaded {0} statels", Statels.CacheAllStatels()); LootHandler.CacheAllFromDB(); Tradeskill.CacheItemNames(); csc.AddScriptMembers(); csc.CallMethod("Init", null); ThreadMgr.Start(); zoneServer.Start(); Console.ResetColor(); } catch (MySqlException e) { Console.WriteLine("MySql Error. Server Cannot Start"); Console.WriteLine("Exception: " + e.Message); string current = DateTime.Now.ToString("HH:mm:ss"); StreamWriter logfile = File.AppendText("ZoneEngineLog.txt"); logfile.WriteLine(current + " " + e.Source + " MySql Error. Server Cannot Start"); logfile.WriteLine(current + " " + e.Source + " Exception: " + e.Message); logfile.Close(); zoneServer.Stop(); ThreadMgr.Stop(); Process.GetCurrentProcess().Kill(); } }