コード例 #1
0
ファイル: WvsGame.cs プロジェクト: Bia10/DestinyFork
        private static void Main(string[] args)
        {
            if (args.Length > 0 && args[0].ToLower() == "setup")
            {
                InitiateGameServerSetup();
            }

            if (args.Length > 0 && args[0].ToLower() != "setup")
            {
                Log.Warn("Arguments found yet none were recognized! Arguments: " + args);

                HaltOnFatalError();
            }

            if (!File.Exists(Application.ExecutablePath + "WvsGame.ini"))
            {
                Log.Warn("Could not find file WvsGame.ini at path: {0}", Application.ExecutablePath);

                if (Log.YesNo("Would you like to initiate setup process for Destiny game server? ", true))
                {
                    InitiateGameServerSetup();
                }
                else
                {
                    Log.Warn("\n Argument setup was not found!" +
                             "\n Neither was found WvsGame.ini!" +
                             "\n And finally you chose not to setup game server!" +
                             "\n What shall i do then? Make a prophecy about your intent?");

                    HaltOnFatalError();
                }
            }

start:
            Clients = new GameClients();

            Log.Entitle("WvsGame v.{0}.{1}", Application.MapleVersion, Application.PatchVersion);

            try
            {
                // Read game-server settings from ini
                Settings.Initialize(Application.ExecutablePath + "WvsGame.ini");
                // Test connection to database
                Database.Test();
                // Parse thru MaplestoryDB
                Database.Analyze(true);
                // Create key shortcuts
                Shortcuts.Apply();
                // Set auto-reset
                AutoRestartTime = Settings.GetInt("Server/AutoRestartTime");
                Log.Inform("Automatic restart time set to {0} seconds.", AutoRestartTime);
                // Initiate data handler
                DataProvider.Initialize();
                // Success game-server is alive!
                IsAlive = true;
            }
            catch (Exception ex)
            {
                Log.SkipLine();
                Tracer.TraceErrorMessage(ex, "Exception occurred during game-server initialization!");
            }

            if (IsAlive)
            {
                CenterConnectionDone.Reset();

                new Thread(new ThreadStart(GameToCenterServer.Main)).Start();

                CenterConnectionDone.WaitOne();
#if DEBUG
                string linkPath = Path.Combine(Application.ExecutablePath, "LaunchClient.lnk");

                if (File.Exists(linkPath) && WorldID == 0 && ChannelID == 0) //Only for the first WvsGame instance, and only if shortcut exists
                {
                    System.Diagnostics.Process proc = new System.Diagnostics.Process {
                        StartInfo = { FileName = linkPath }
                    };
                    proc.Start();
                }
#endif
            }
            else
            {
                HaltOnFatalError();
            }

            while (IsAlive)
            {
                AcceptDone.Reset();

                try
                {
                    Listener.BeginAcceptSocket(new AsyncCallback(OnAcceptSocket), null);
                }

                catch (Exception ex)
                {
                    Log.SkipLine();
                    Tracer.TraceErrorMessage(ex, "Ex occured in game server!");
                    throw;
                }

                AcceptDone.WaitOne();
            }

            CloseGameServer();

            if (AutoRestartTime > 0) // TODO: fugly rework
            {
                Log.Inform("Attempting auto-restart in {0} seconds.", AutoRestartTime);
                Thread.Sleep(AutoRestartTime * 1000);
                goto start;
            }

            Console.Read();
        }
コード例 #2
0
ファイル: WvsGame.cs プロジェクト: slashXXxu/Destiny
        private static void Main(string[] args)
        {
            if (args.Length == 1 && args[0].ToLower() == "setup" || !File.Exists(Application.ExecutablePath + "WvsGame.ini"))
            {
                WvsGameSetup.Run();
            }

start:
            WvsGame.Clients = new GameClients();

            Log.Entitle("WvsGame v.{0}.{1}", Application.MapleVersion, Application.PatchVersion);

            try
            {
                Settings.Initialize(Application.ExecutablePath + "WvsGame.ini");

                Database.Test();
                Database.Analyze(true);

                Shortcuts.Apply();

                WvsGame.AutoRestartTime = Settings.GetInt("Server/AutoRestartTime");
                Log.Inform("Automatic restart time set to {0} seconds.", WvsGame.AutoRestartTime);

                DataProvider.Initialize();

                WvsGame.IsAlive = true;
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }

            if (WvsGame.IsAlive)
            {
                WvsGame.CenterConnectionDone.Reset();

                new Thread(new ThreadStart(CenterServer.Main)).Start();

                WvsGame.CenterConnectionDone.WaitOne();

#if DEBUG
                string linkPath = Path.Combine(Application.ExecutablePath, "LaunchClient.lnk");
                if (File.Exists(linkPath) && WvsGame.WorldID == 0 && WvsGame.ChannelID == 0) //Only for the first WvsGame instance, and only if shortcut exists
                {
                    System.Diagnostics.Process proc = new System.Diagnostics.Process();
                    proc.StartInfo.FileName = linkPath;
                    proc.Start();
                }
#endif
            }
            else
            {
                Log.Inform("Could not start server because of errors.");
            }

            while (WvsGame.IsAlive)
            {
                WvsGame.AcceptDone.Reset();

                WvsGame.Listener.BeginAcceptSocket(new AsyncCallback(WvsGame.OnAcceptSocket), null);

                WvsGame.AcceptDone.WaitOne();
            }

            foreach (GameClient client in WvsGame.Clients)
            {
                client.Stop();
            }

            WvsGame.Dispose();

            Log.Warn("Server stopped.");

            if (WvsGame.AutoRestartTime > 0)
            {
                Log.Inform("Attempting auto-restart in {0} seconds.", WvsGame.AutoRestartTime);

                Thread.Sleep(WvsGame.AutoRestartTime * 1000);

                goto start;
            }
            else
            {
                Console.Read();
            }
        }
コード例 #3
0
        public static void Main(string[] args)
        {
            if (args.Length == 1 && args[0].ToLower() == "setup" || !File.Exists(Application.ExecutablePath + "Configuration.ini"))
            {
                ChannelServerSetup.Run();
            }

            int port = 0;

start:
            ChannelServer.Clients = new List <ChannelClientHandler>();

            Log.Entitle("Channel Server v.{0}.{1}", Application.MapleVersion, Application.PatchVersion);

            try
            {
                if (port == 0)
                {
                    try
                    {
                        port = int.Parse(args[0]);
                    }
                    catch
                    {
                        port = Log.Input("Port: ", 7575);
                    }
                }

                Settings.Initialize();
                Shortcuts.Apply();

                ChannelServer.AutoRestartTime = Settings.GetInt("Server/AutoRestartTime");
                Log.Inform("Automatic restart time set to {0} seconds.", ChannelServer.AutoRestartTime);

                Database.Test();
                Database.Analyze(true);

                ChannelServer.LoggedIn = new List <int>(Settings.GetInt("Server/MaxUsers"));
                Log.Inform("Maximum of {0} simultaneous online users.", ChannelServer.LoggedIn.Capacity);

                ChannelServer.RemoteEndPoint = new IPEndPoint(Settings.GetIPAddress("Server/ExternalIP"), port);

                ChannelData.Initialize();

                ChannelServer.Listener = new TcpListener(IPAddress.Any, ChannelServer.RemoteEndPoint.Port);
                ChannelServer.Listener.Start();
                Log.Inform("Initialized clients listener on {0}.", ChannelServer.Listener.LocalEndpoint);

                ChannelServer.IsAlive = true;
            }
            catch (Exception e)
            {
                Log.Error(e);
            }

            if (ChannelServer.IsAlive)
            {
                Log.Success("Channel server started.");

                new Thread(new ThreadStart(InteroperabilityClient.Main)).Start();
            }
            else
            {
                Log.Inform("Could not start server because of errors.");
            }

            while (ChannelServer.IsAlive)
            {
                ChannelServer.AcceptDone.Reset();

                ChannelServer.Listener.BeginAcceptSocket(new AsyncCallback(ChannelServer.OnAcceptSocket), null);

                ChannelServer.AcceptDone.WaitOne();
            }

            ChannelClientHandler[] remainingClients = ChannelServer.Clients.ToArray();

            foreach (ChannelClientHandler client in remainingClients)
            {
                client.Stop();
            }

            ChannelServer.Dispose();

            Log.Warn("Server stopped.");

            if (ChannelServer.AutoRestartTime > 0)
            {
                Log.Inform("Attempting auto-restart in {0} seconds.", ChannelServer.AutoRestartTime);
                Thread.Sleep(ChannelServer.AutoRestartTime * 1000);
                goto start;
            }
            else
            {
                Console.Read();
            }
        }