private static void Main(string[] args) { Log.SetLogFile(".\\Logs\\MessageLog.log"); start: MessageServer.Clients = new List <Client>(); Log.Entitle("Message Server v.{0}.{1}", 10, 10); try { Settings.Initialize(); MessageServer.AutoRestartTime = 15; // TODO: Get actual restart-time. Log.Inform("Automatic restart time set to {0} seconds.", MessageServer.AutoRestartTime); Database.Test(); Database.Analyze(false); // NOTE: The shop server uses mcdb for information like items, etcetera. MessageServer.RemoteEndPoint = new IPEndPoint(Settings.GetIPAddress("ExternalIP", "Message"), Settings.GetInt("Port", "Message")); //MapleData.Initialize(); MessageServer.Listener = new TcpListener(IPAddress.Any, MessageServer.RemoteEndPoint.Port); MessageServer.Listener.Start(); Log.Inform("Initialized clients listener on {0}.", MessageServer.Listener.LocalEndpoint); MessageServer.IsAlive = true; } catch (Exception e) { #if DEBUG Log.Error(e.ToString()); #else Log.Error(e); #endif } if (MessageServer.IsAlive) { Log.Success("Server started on thread {0}.", Thread.CurrentThread.ManagedThreadId); new Thread(new ThreadStart(InteroperabilityClient.Main)).Start(); } else { Log.Inform("Could not start server because of errors."); } while (MessageServer.IsAlive) { MessageServer.AcceptDone.Reset(); MessageServer.Listener.BeginAcceptSocket(new AsyncCallback(MessageServer.OnAcceptSocket), null); MessageServer.AcceptDone.WaitOne(); } Client[] remainingClients = MessageServer.Clients.ToArray(); foreach (Client client in remainingClients) { client.Dispose(); } MessageServer.Dispose(); Log.Warn("Server stopped."); if (MessageServer.AutoRestartTime > 0) { Log.Inform("Attempting auto-restart in {0} seconds.", MessageServer.AutoRestartTime); Thread.Sleep(MessageServer.AutoRestartTime * 1000); goto start; } else { Console.Read(); } }
private static void Main(string[] args) { int port = 0; Log.SetLogFile(".\\Logs\\GameLog.log"); start: GameServer.Clients = new List <Client>(); Log.Entitle("Game Server v.{0}.{1}", 10, 10); try { if (port == 0) { try { port = int.Parse(args[0]); } catch { //port = Log.Input("Port[15101]: ", 15101); port = 15101; Log.Inform("Default Game Server Port: {0}", port); } } Settings.Initialize(); GameServer.AutoRestartTime = 15; // TODO: Get actual restart-time. Log.Inform("Automatic restart time set to {0} seconds.", GameServer.AutoRestartTime); Database.Test(); Database.Analyze(false); GameServer.RemoteEndPoint = new IPEndPoint(IPAddress.Parse(ServerConstants.LISTENER_SERVER_IP), port); // TODO: Get actual host. Log.Load("Items Initialize"); ItemFactory.Initialize(); Log.Success("\r\n"); Log.Load("Maps Initialize"); MapFactory.Initialize(); Log.Success("\r\n"); MobFactory.InitializeMonsterDrop(); CashShopFactory.InitializeHatCommodity(); CashShopFactory.InitializeMantleCommodity(); CashShopFactory.InitializeBoyDressCommodity(); CashShopFactory.InitializeGirlDressCommodity(); CashShopFactory.InitializeBoyHairCommodity(); CashShopFactory.InitializeGirlHairCommodity(); CashShopFactory.InitializeFace1Commodity(); CashShopFactory.InitializeFace2Commodity(); CashShopFactory.InitializeBoyEyesCommodity(); CashShopFactory.InitializeGirlEyesCommodity(); CashShopFactory.InitializePetCommodity(); CashShopFactory.InitializeAmuletCommodity(); CashShopFactory.InitializeTalismanCommodity(); CashShopFactory.InitializeProduceCommodity(); UdpRemoteEndPoint = new IPEndPoint(IPAddress.Parse(ServerConstants.SERVER_IP), ServerConstants.UDP_PORT); UdpListener = new UdpClient(UdpRemoteEndPoint); Log.Inform("Initialized clients UDP listener on {0}. Port {1}", UdpRemoteEndPoint.Address, UdpRemoteEndPoint.Port); GameServer.Listener = new TcpListener(IPAddress.Any, GameServer.RemoteEndPoint.Port); GameServer.Listener.Start(); Log.Inform("Initialized clients listener on {0}.", GameServer.Listener.LocalEndpoint); GameServer.IsAlive = true; } catch (Exception e) { Log.Error(e); } if (GameServer.IsAlive) { Log.Success("Server started on thread {0}.", Thread.CurrentThread.ManagedThreadId); AppDomain.CurrentDomain.UnhandledException += (s, e) => { Log.Error("Unhandled exception from Server: \n{0}", e.ExceptionObject.ToString()); }; new Thread(new ThreadStart(InteroperabilityClient.Main)).Start(); } else { Log.Inform("Could not start server because of errors."); } while (GameServer.IsAlive) { GameServer.AcceptDone.Reset(); GameServer.Listener.BeginAcceptSocket(new AsyncCallback(GameServer.OnAcceptSocket), null); GameServer.AcceptDone.WaitOne(); } Client[] remainingClients = GameServer.Clients.ToArray(); foreach (Client client in remainingClients) { client.Dispose(); } GameServer.Dispose(); Log.Warn("Server stopped."); if (GameServer.AutoRestartTime > 0) { Log.Inform("Attempting auto-restart in {0} seconds.", GameServer.AutoRestartTime); Thread.Sleep(GameServer.AutoRestartTime * 1000); goto start; } else { Console.Read(); } }
public static void ServerLoop() { AcceptDone = new ManualResetEvent(false); Worlds = new Worlds(); Clients = new List <Client>(); Log.SetLogFile(".\\Logs\\LoginLog.log"); Log.Entitle("Login Server (CLIENT VERSION {0})", ServerConstants.CLIENT_VERSION); try { Settings.Initialize(); Database.Test(); Database.Analyze(false); SecurityCode = Settings.GetString("SecurityCode", "Interconnection"); Log.Inform("Cross-servers code '{0}' assigned.", Log.MaskString(LoginServer.SecurityCode)); RequireStaffIP = Settings.GetBool("RequireStaffIP", "Login"); IsMaintenance = Settings.GetBool("isMaintenance", "Login"); PatchVer = Settings.GetInt("PatchVersion", "Login"); PatchDownloadUrl = Settings.GetString("PatchDownloadUrl", "Login"); Log.Inform("Staff will {0} be required to connect through a staff IP.", LoginServer.RequireStaffIP ? " " : " not "); Log.Debug("IsMaintenance: {0}", IsMaintenance); TcpListener Listener = new TcpListener(IPAddress.Any, Settings.GetInt("Port", "Login")); Listener.Start(); Log.Inform("Initialized clients listener on {0}.", Listener.LocalEndpoint); LoginServer.Pinger.Interval = Settings.GetInt("PingInterval"); LoginServer.Pinger.Start(); Log.Inform("Clients pinger set to {0} ms.", LoginServer.Pinger.Interval); foreach (string world in Settings.GetBlocksFromBlock("Worlds", 1)) { Worlds.Add(new World() { ID = Settings.GetByte("ID", world), HostIP = Settings.GetIPAddress("Host", world), Flag = Settings.GetEnum <ServerUtilities.ServerFlag>("Flag", world), Channel = Settings.GetByte("Channel", world), EventMessage = Settings.GetString("EventMessage", world), DisableCreation = Settings.GetBool("DisableCreation", world), ScrollingHeader = Settings.GetString("ScrollingHeader", world), Rates = new ServerUtilities.Rates() { Experience = Settings.GetInt("ExperienceRate", world), QuestExperience = Settings.GetInt("QuestExperienceRate", world), PartyQuestExperience = Settings.GetInt("PartyQuestExperience", world), Meso = Settings.GetInt("MesoDropRate", world), Loot = Settings.GetInt("LootDropRate", world) } }); } IsAlive = true; Log.Success("Server started on thread {0}.", Thread.CurrentThread.ManagedThreadId); AppDomain.CurrentDomain.UnhandledException += (s, e) => { Log.Error("Unhandled exception from Server: \n{0}", e.ExceptionObject.ToString()); }; new Thread(new ThreadStart(InteroperabilityServer.ServerLoop)).Start(); while (IsAlive) { AcceptDone.Reset(); Listener.BeginAcceptSocket((iar) => { new Client(Listener.EndAcceptSocket(iar)); AcceptDone.Set(); }, null); AcceptDone.WaitOne(); } InteroperabilityServer.Stop(); Client[] remainingClients = Clients.ToArray(); foreach (Client client in remainingClients) { client.Dispose(); } Listener.Stop(); Log.Warn("Login stopped."); } catch (Exception e) { Log.Error(e); Log.Inform("Could not start server because of errors."); } finally { Console.Read(); } }