Example #1
0
        public Maincs()
        {
            //Set default settings
            #region Default Settings
            int LSPort  = 15779;
            int IPCPort = 15779;
            string LSIP = "";
            string IPCIP = "0.0.0.0";
            Systems.DownloadServer = "";
            #endregion

            //Initialize main
            InitializeComponent();
            //Set ini
            LoginServer.Systems.Ini ini = null;
            //Load settings
            #region Load Settings
            try
            {
                if (File.Exists(Environment.CurrentDirectory + @"\Settings\Settings.ini"))
                {
                    ini = new LoginServer.Systems.Ini(Environment.CurrentDirectory + @"\Settings\Settings.ini");
                    LSPort = Convert.ToInt32(ini.GetValue("Server", "port", 15779));
                    LSIP = ini.GetValue("Server", "ip", "").ToString();
                    IPCPort = Convert.ToInt32(ini.GetValue("IPC", "port", 15779));
                    IPCIP = ini.GetValue("IPC", "ip", "").ToString();
                    Systems.DownloadServer = ini.GetValue("Patch_Server", "ip", "");
                    Systems.DownloadPort = Convert.ToInt16(ini.GetValue("Patch_Server", "port", ""));
                    ini = null;
                    Activity("[INFO] Loaded your ip settings successfully");
                }
                else
                {
                    Activity("Could not find your settings.ini using defaults.");
                }
            }
            catch (Exception)
            {
                return;
            }
            #endregion

            #region get local ip

            Network.multihomed = false;
            if (Network.LocalIP == "")
            {
                IPAddress[] lIpList = Dns.GetHostAddresses(Dns.GetHostName());
                foreach (IPAddress aIP in lIpList)
                {
                    if (aIP.AddressFamily.Equals(AddressFamily.InterNetwork))
                    {
                        if (!aIP.Equals(IPAddress.Loopback))
                        {
                            if (Network.LocalIP != "")
                            {
                                Network.multihomed = true;
                            }
                            else
                            {
                                Network.LocalIP = aIP.ToString();
                            }
                        }
                    }
                }
            }
            #endregion

            Systems.Server net = new Systems.Server();

            net.OnConnect += new Systems.Server.dConnect(_OnClientConnect);
            net.OnError += new Systems.Server.dError(_ServerError);

            Systems.Client.OnReceiveData += new Systems.Client.dReceive(_OnReceiveData);
            Systems.Client.OnDisconnect += new Systems.Client.dDisconnect(_OnClientDisconnect);
            //Content.Patches.LoadPatches(this);
            Systems.Load_NewsList(this, newsform);

            try
            {
                net.Start(LSIP, LSPort);
            }
            catch (Exception ex)
            {
                Activity("Starting Server error "+ ex +"");
            }

            #region Load GameServers
            Systems.LoadServers("GameServers.ini", 15780, this, servers);
            #endregion

            #region IPC Listener
            IPCServer = new Servers.IPCServer();
            IPCServer.OnReceive += new Servers.IPCServer.dOnReceive(OnIPC);
            try
            {
                IPCServer.Start(IPCIP, IPCPort);
                foreach (KeyValuePair<int, Systems.SRX_Serverinfo> GS in Systems.GSList)
                {
                    byte[] rqPacket = IPCServer.PacketRequestServerInfo(IPCPort);
                    Servers.IPCenCode(ref rqPacket, GS.Value.code);
                    IPCServer.Send(GS.Value.ip, GS.Value.ipcport, rqPacket);
                    rqPacket = null;
                }
            }
            catch (Exception ex)
            {
                Activity("IPC start error " + ex + "");
            }
            #endregion
            Activity("[NET] Listening for gameserver connection...");
            this.ShowDialog();
            while (true)
            {
                Thread.Sleep(100);
                foreach (KeyValuePair<int, Systems.SRX_Serverinfo> SSI in Systems.GSList)
                {
                    if (SSI.Value.status != 0 && SSI.Value.lastPing.AddMinutes(5) < DateTime.Now) // server unavailable
                    {
                        SSI.Value.status = 0;
                        Activity("[ERROR] Server "+ SSI.Value.name +" has timed out");
                    }
                }
            }
        }
Example #2
0
        //Run
        #region run
        public Maincs()
        {
            //Set default settings
            #region Default Settings
            int    LSPort  = 15779;
            int    IPCPort = 15779;
            string LSIP    = "";
            string IPCIP   = "0.0.0.0";
            Systems.DownloadServer = "";
            #endregion

            //Initialize main
            InitializeComponent();
            //Set ini
            LoginServer.Systems.Ini ini = null;
            //Load settings
            #region Load Settings
            try
            {
                if (File.Exists(Environment.CurrentDirectory + @"\Settings\Settings.ini"))
                {
                    ini     = new LoginServer.Systems.Ini(Environment.CurrentDirectory + @"\Settings\Settings.ini");
                    LSPort  = Convert.ToInt32(ini.GetValue("Server", "port", 15779));
                    LSIP    = ini.GetValue("Server", "ip", "").ToString();
                    IPCPort = Convert.ToInt32(ini.GetValue("IPC", "port", 15779));
                    IPCIP   = ini.GetValue("IPC", "ip", "").ToString();
                    Systems.DownloadServer = ini.GetValue("Patch_Server", "ip", "");
                    Systems.DownloadPort   = Convert.ToInt16(ini.GetValue("Patch_Server", "port", ""));
                    ini = null;
                    Activity("[INFO] Loaded your ip settings successfully");
                }
                else
                {
                    Activity("Could not find your settings.ini using defaults.");
                }
            }
            catch (Exception)
            {
                return;
            }
            #endregion

            #region get local ip

            Network.multihomed = false;
            if (Network.LocalIP == "")
            {
                IPAddress[] lIpList = Dns.GetHostAddresses(Dns.GetHostName());
                foreach (IPAddress aIP in lIpList)
                {
                    if (aIP.AddressFamily.Equals(AddressFamily.InterNetwork))
                    {
                        if (!aIP.Equals(IPAddress.Loopback))
                        {
                            if (Network.LocalIP != "")
                            {
                                Network.multihomed = true;
                            }
                            else
                            {
                                Network.LocalIP = aIP.ToString();
                            }
                        }
                    }
                }
            }
            #endregion

            Systems.Server net = new Systems.Server();

            net.OnConnect += new Systems.Server.dConnect(_OnClientConnect);
            net.OnError   += new Systems.Server.dError(_ServerError);

            Systems.Client.OnReceiveData += new Systems.Client.dReceive(_OnReceiveData);
            Systems.Client.OnDisconnect  += new Systems.Client.dDisconnect(_OnClientDisconnect);
            //Content.Patches.LoadPatches(this);
            Systems.Load_NewsList(this, newsform);

            try
            {
                net.Start(LSIP, LSPort);
            }
            catch (Exception ex)
            {
                Activity("Starting Server error " + ex + "");
            }

            #region Load GameServers
            Systems.LoadServers("GameServers.ini", 15780, this, servers);
            #endregion

            #region IPC Listener
            IPCServer            = new Servers.IPCServer();
            IPCServer.OnReceive += new Servers.IPCServer.dOnReceive(OnIPC);
            try
            {
                IPCServer.Start(IPCIP, IPCPort);
                foreach (KeyValuePair <int, Systems.SRX_Serverinfo> GS in Systems.GSList)
                {
                    byte[] rqPacket = IPCServer.PacketRequestServerInfo(IPCPort);
                    Servers.IPCenCode(ref rqPacket, GS.Value.code);
                    IPCServer.Send(GS.Value.ip, GS.Value.ipcport, rqPacket);
                    rqPacket = null;
                }
            }
            catch (Exception ex)
            {
                Activity("IPC start error " + ex + "");
            }
            #endregion
            Activity("[NET] Listening for gameserver connection...");
            this.ShowDialog();
            while (true)
            {
                Thread.Sleep(100);
                foreach (KeyValuePair <int, Systems.SRX_Serverinfo> SSI in Systems.GSList)
                {
                    if (SSI.Value.status != 0 && SSI.Value.lastPing.AddMinutes(5) < DateTime.Now) // server unavailable
                    {
                        SSI.Value.status = 0;
                        Activity("[ERROR] Server " + SSI.Value.name + " has timed out");
                    }
                }
            }
        }