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(); } }
/// <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(); } }
public static void Main(string[] args) { #if !DEBUG AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); #endif AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit); try { mThread = Thread.CurrentThread; mProcess = Process.GetCurrentProcess(); mAssembly = Assembly.GetEntryAssembly(); if (mThread != null) { mThread.Name = "Core Thread"; } Timer.TimerThread ttObj = new Timer.TimerThread(); mTimerThread = new Thread(new ThreadStart(ttObj.TimerMain)); mTimerThread.Name = "Timer Thread"; int width = Math.Min(100, Console.LargestWindowWidth - 2); Console.CursorVisible = false; Console.Clear(); Console.WindowLeft = Console.WindowTop = 0; if (Console.WindowWidth < width) { Console.WindowWidth = width; } LogoPrinter.PrefixColor = EConsoleColor.Blue; LogoPrinter.SufixColor = EConsoleColor.Blue; LogoPrinter.TextColor = EConsoleColor.Gray; LogoPrinter.PrintLogo(); Version ver = mAssembly.GetName().Version; CConsole.StatusLine("Shaiya.Extended Server - Version {0}.{1}, Build {2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision); mConsoleEventHandler = new ConsoleEventHandler(OnConsoleEvent); SetConsoleCtrlHandler(mConsoleEventHandler, true); mAppConf = new ApplicationSettings(); mAppConf.ReadAll(); Stopwatch watch = Stopwatch.StartNew(); CConsole.Info("Connecting to SQL Server {0}...", mAppConf.Network["DB Server"]); mDatabase = new MySqlWrapper(mAppConf.Network["DB Server"], int.Parse(mAppConf.Network["DB Port"]), mAppConf.Network["DB User"], mAppConf.Network["DB Password"], mAppConf.Network["DB Database"]); MysqlError conRes = mDatabase.Prepare(); if (conRes != MysqlError.None) { CConsole.WriteLine(EConsoleColor.Error, " failed!"); throw new Exception("Failed to open Database Connection! Type: " + conRes.ToString()); } watch.Stop(); CConsole.WriteLine(EConsoleColor.Status, " done! Needed {0:F2} sec", watch.Elapsed.TotalSeconds); watch = null; ScriptDatabase.Initialize(@"Scripts\ScriptList.xml"); ScriptCompiler.Compile(AppDomain.CurrentDomain.BaseDirectory + Path.Combine(Settings.Default.MainConfDir, Settings.Default.ScriptAssemblies), true, true); World.Load(); // testing CallMethod ScriptCompiler.CallMethod("Initialize"); SocketPool.Create(); mSocketConnector = new SocketConnector(mAppConf.Network["Server IP"], mAppConf.Network.GetInt("Server Port")); PacketHandlers.Initialize(); // start Timer Thread mTimerThread.Start(); NetState.Initialize(); // finished Loading Events.InvokeServerStarted(); DateTime now, last = DateTime.Now; const int sampleInterval = 100; const float ticksPerSecond = (float)(TimeSpan.TicksPerSecond * sampleInterval); int sample = 0; while (mSignal.WaitOne()) { Timer.Slice(); mSocketConnector.Slice(); NetState.FlushAll(); NetState.ProcessDisposedQueue(); if (Slice != null) { Slice(); } // just for Diagnostics if ((++sample % sampleInterval) == 0) { now = DateTime.Now; mCyclesPerSecond[mCycleIndex++ % mCyclesPerSecond.Length] = ticksPerSecond / (now.Ticks - last.Ticks); last = now; } } } catch (Exception e) { CurrentDomain_UnhandledException(null, new UnhandledExceptionEventArgs(e, true)); } }