/// <summary> /// </summary> /// <param name="parts"> /// </param> private static void ShutDownServer(string[] parts) { if (zoneServer.IsRunning) { zoneServer.Stop(); } ISComClient.ShutDown(); exited = true; }
/// <summary> /// </summary> public static void StartTheServer() { try { Console.ForegroundColor = ConsoleColor.Green; // Log off all characters // TODO: make it playfield dependent Misc.CheckDatabase(); Misc.LogOffAll(); /* TODO: Readd the things, Algorithman * 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; /* TODO: Readd when necessary classes are done again */ Console.WriteLine("Loaded {0} items", ItemLoader.CacheAllItems()); Console.WriteLine("Loaded {0} nanos", NanoHandler.CacheAllNanos()); // Console.WriteLine("Creaated {0} playfields", zoneServer.CreatePlayfields()); /* * 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()); */ /* Same as above * LootHandler.CacheAllFromDB(); * Tradeskill.CacheItemNames(); */ csc.AddScriptMembers(); csc.CallMethod("Init", null); zoneServer.Start(true, false); 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(); Process.GetCurrentProcess().Kill(); } }
/// <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; } } }