Beispiel #1
0
        private void InitializeServer()
        {
            try
            {
                Server.Init(Program.IMGFilename);


                this.Invoke((MethodInvoker) delegate
                {
                    this.Text += " (" + Program.IMGFilename + ")";
                    txtLog.AddLine("Loaded as " + Program.IMGFilename);
                    if (Server.Tespia)
                    {
                        Text    += " -TESPIA MODE-";
                        Icon     = Resources.Tespia;
                        ShowIcon = true;
                    }
                });


                Pinger.Init(Program.MainForm.LogAppend, Program.MainForm.LogAppend);

                MasterThread.RepeatingAction.Start(
                    "Form Updater",
                    (date) =>
                {
                    try
                    {
                        this.BeginInvoke((MethodInvoker) delegate
                        {
                            txtPingEntries.Text = Pinger.CurrentLoggingConnections.ToString();
                            txtLoad.Text        = load.ToString();
                        });
                    }
                    catch { }
                },
                    0,
                    1500
                    );
            }
            catch (Exception ex)
            {
                Program.LogFile.WriteLine("Got exception @ frmMain::InitializeServer : {0}", ex.ToString());
                MessageBox.Show($"[LOGIN SERVER] Got exception @ frmMain::InitializeServer : {ex.ToString()}");
                Environment.Exit(5);
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                MessageBox.Show("Invalid argument length.");
                return;
            }

            log4net.GlobalContext.Properties["ImgName"] = args[0];
            XmlConfigurator.ConfigureAndWatch(new FileInfo(Path.Combine(Environment.CurrentDirectory, "..", "DataSvr", "logging-config-shop.xml")));

            IMGFilename = args[0];
            LogFile     = new Common.Logfile(IMGFilename);


            UnhandledExceptionHandler.Set(args, IMGFilename, LogFile);
            MasterThread.Load(IMGFilename);
            Pinger.Init();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(MainForm = new frmMain());
        }
Beispiel #3
0
        private void InitializeServer()
        {
            try
            {
                Server.Init(Program.IMGFilename);
                DataProvider.Load();

                for (var reconnects = 0; reconnects < 8; reconnects++)
                {
                    for (var timeouts = 0; timeouts < 10; timeouts++)
                    {
                        if (Server.Instance.ID != 0xFF)
                        {
                            break;
                        }
                        System.Threading.Thread.Sleep(100);
                    }
                    if (Server.Instance.ID != 0xFF)
                    {
                        break;
                    }

                    Server.Instance.ConnectToCenter();
                    System.Threading.Thread.Sleep(500);
                }


                if (Server.Instance.ID == 0xFF)
                {
                    Environment.Exit(1);
                }

                this.Invoke((MethodInvoker) delegate
                {
                    this.txtLoad.Text = "0";
                    this.Text        += " Channel " + (Server.Instance.ID + 1) + " (" + Program.IMGFilename + ")";
                });

                MasterThread.RepeatingAction.Start("Map Checker", Server.Instance.CheckMaps, 0, 1000);

                LogAppend("Server successfully booted!");

                MasterThread.RepeatingAction.Start(
                    "MasterThread Stats for form",
                    x =>
                {
                    try
                    {
                        this.Invoke((MethodInvoker) delegate
                        {
                            var mt = MasterThread.Instance;
                            lblMasterThreadStats.Text =
                                $"MT Queue: {mt.CurrentCallbackQueueLength}; " +
                                $"RA count: {mt.RegisteredRepeatingActions}; " +
                                $"Ping conns: {Pinger.CurrentLoggingConnections}";
                        });
                    }
                    catch { }
                },
                    0,
                    2000
                    );


                if (Server.Instance.InMigration)
                {
                    // Tell the other server to start migrating...
                    var pw = new Packet(ISClientMessages.ServerMigrationUpdate);
                    pw.WriteByte((byte)ServerMigrationStatus.StartMigration);
                    Server.Instance.CenterConnection.SendPacket(pw);
                }

                Pinger.Init(x => Program.MainForm.LogAppend(x), x => Program.MainForm.LogAppend(x));
            }
            catch (Exception ex)
            {
                Program.LogFile.WriteLine("Got exception @ frmMain::InitServer : {0}", ex.ToString());
                MessageBox.Show(string.Format("[{0}][GAME SERVER] Got exception @ frmMain::InitServer:\r\n {1}", DateTime.Now.ToString(), ex.ToString()));
                Environment.Exit(5);
            }
        }
Beispiel #4
0
        public override void InitializeServer()
        {
            Server.Init(Program.IMGFilename);
            DataProvider.Load();

            for (var reconnects = 0; reconnects < 8; reconnects++)
            {
                for (var timeouts = 0; timeouts < 10; timeouts++)
                {
                    if (Server.Instance.ID != 0xFF)
                    {
                        break;
                    }
                    System.Threading.Thread.Sleep(100);
                }
                if (Server.Instance.ID != 0xFF)
                {
                    break;
                }

                Server.Instance.ConnectToCenter();
                System.Threading.Thread.Sleep(500);
            }

            if (Server.Instance.ID == 0xFF)
            {
                Environment.Exit(1);
            }

            Server.Instance.LoadFieldSet();
            MasterThread.RepeatingAction.Start("Map Checker", Server.Instance.CheckMaps, 0, 1000);
            MasterThread.RepeatingAction.Start("FieldSet Checker", FieldSet.Update, 0, 1000);


            MasterThread.RepeatingAction.Start(
                "Console title updater",
                x =>
            {
                var mt        = MasterThread.Instance;
                Console.Title = $"Game CH.{(Server.Instance.ID + 1)} ({Program.IMGFilename}) {load} Stats {mt.CurrentCallbackQueueLength}/{mt.RegisteredRepeatingActions}/{Pinger.CurrentLoggingConnections}";
                if (Server.Tespia)
                {
                    Console.Title += " -TESPIA MODE-";
                }
            },
                0,
                2000
                );

            MasterThread.RepeatingAction.Start("Log killed mobs",
                                               curTime =>
            {
                DataProvider.Maps.Values.ForEach(x => x.FlushMobKillCount());
            },
                                               0,
                                               60 * 1000
                                               );


            LogAppend("Server successfully booted!");

            if (Server.Instance.InMigration)
            {
                // Tell the other server to start migrating...
                var pw = new Packet(ISClientMessages.ServerMigrationUpdate);
                pw.WriteByte((byte)ServerMigrationStatus.StartMigration);
                Server.Instance.CenterConnection.SendPacket(pw);
            }

            if (Server.Tespia && !IsMono)
            {
                var curProcess = GetConsoleWindow();
                SendMessage(curProcess, WM_SETICON, ICON_BIG, Resources.Tespia.Handle);
                SendMessage(curProcess, WM_SETICON, ICON_SMALL, Resources.Tespia.Handle);
                curProcess = Process.GetCurrentProcess().Handle;
                SendMessage(curProcess, WM_SETICON, ICON_BIG, Resources.Tespia.Handle);
                SendMessage(curProcess, WM_SETICON, ICON_SMALL, Resources.Tespia.Handle);
            }
            Pinger.Init(x => Program.MainForm.LogAppend(x), x => Program.MainForm.LogAppend(x));
        }
Beispiel #5
0
        private void InitializeServer()
        {
            try
            {
                CenterServer.Init(Program.IMGFilename);

                Invoke((MethodInvoker) delegate
                {
                    Text += " (" + Program.IMGFilename + ")";
                    if (CenterServer.Tespia)
                    {
                        Text += " -TESPIA MODE-";
#if DEBUG
                        Text += " -DEBUG-";
#endif
                        Icon     = Resources.Tespia;
                        ShowIcon = true;
                    }
                });

                MasterThread.RepeatingAction.Start(
                    "Server List Updator",
                    date =>
                {
                    try
                    {
                        BeginInvoke((MethodInvoker) delegate
                        {
                            UpdateServerList();
                            txtPingEntries.Text = Pinger.CurrentLoggingConnections.ToString();
                        });
                    }
                    catch { }
                },
                    0,
                    1000
                    );

                // Update the online player count every minute
                MasterThread.RepeatingAction.Start(
                    "OnlinePlayerCounter",
                    date =>
                {
                    int totalCount = 0;
                    foreach (var kvp in CenterServer.Instance.LocalServers)
                    {
                        var ls = kvp.Value;
                        if (ls.Connected == false)
                        {
                            continue;
                        }
                        if (ls.Type != LocalServerType.Login &&
                            ls.Type != LocalServerType.Game &&
                            ls.Type != LocalServerType.Shop)
                        {
                            continue;
                        }
                        totalCount += ls.Connections;
                        _onlinePlayerLog.Info(new OnlinePlayerCount
                        {
                            count      = ls.Connections,
                            serverName = ls.Name
                        });
                    }

                    _onlinePlayerLog.Info(new OnlinePlayerCount
                    {
                        count      = totalCount,
                        serverName = "TotalCount-" + CenterServer.Instance.World.ID
                    });
                },
                    60000,
                    60000
                    );

                Pinger.Init(Program.MainForm.LogAppend, Program.MainForm.LogAppend);
            }
            catch (Exception ex)
            {
                Program.LogFile.WriteLine("Got exception @ frmMain::InitServer : {0}", ex.ToString());
                MessageBox.Show($"[{DateTime.Now}][CENTER SERVER] Got exception @ frmMain::InitServer : {ex}");
                Environment.Exit(5);
            }
        }