Exemplo n.º 1
0
        public void Connect()
        {
            try
            {
                PacketReader Reader = new PacketReader(PacketInformation.buffer);

                if (Reader.Byte() == 18)
                {
                    string ID       = Reader.Text();
                    string PW       = Reader.Text();
                    byte   ukn      = Reader.Byte(); // 0xff
                    UInt16 ServerID = Reader.UInt16();
                    int    lResult  = 99;

                    //Console.WriteLine("Id:{0} Pass:{1} ServerID:{2}",ID,PW,ServerID);

                    SRX_Serverinfo SSI = GSList[ServerID];
                    if (SSI != null)
                    {
                        UInt16 myKey   = 0;
                        string sReason = "";
                        lock (Program.IPCResultList)
                        {
                            myKey = Program.IPCNewId++;
                        }
                        byte[] rqp = Program.IPCServer.PacketRequestLogin(Program.IPCPort, ID, PW, myKey);
                        Servers.IPCenCode(ref rqp, SSI.code);
                        lock (Program.IPCResultList)
                        {
                            Program.IPCResultList.Add(myKey, new IPCItem());
                            Program.IPCResultList[myKey].resultCode = 0x8000;
                        }
                        Program.IPCServer.Send(SSI.ip, SSI.ipcport, rqp);
                        DateTime tOut = DateTime.Now.AddSeconds(30);
                        while ((tOut >= DateTime.Now) && (Program.IPCResultList[myKey].resultCode == 0x8000) && (client.clientSocket.Connected))
                        {
                            System.Threading.Thread.Sleep(10);
                        }
                        lResult = Program.IPCResultList[myKey].resultCode;
                        sReason = Program.IPCResultList[myKey].banReason;
                        lock (Program.IPCResultList)
                        {
                            Program.IPCResultList[myKey] = null;
                            Program.IPCResultList.Remove(myKey);
                        }
                        rqp = null;
                        //Console.WriteLine("Resultado de login: {0}",lResult);
                        switch (lResult)
                        {
                        case 0:
                            if (SSI.lan_wan)
                            {
                                client.Send(ConnectSucces(SSI.wan, SSI.port, 1));
                            }
                            else
                            {
                                client.Send(ConnectSucces(SSI.ip, SSI.port, 1));
                            }
                            return;

                        case 1:
                            if (WrongPassword < 3)
                            {
                                client.Send(WrongInformation());
                                WrongPassword++;
                                return;
                            }
                            else
                            {
                                client.Disconnect(PacketInformation.Client);
                                return;
                            }

                        case 2:
                            client.Send(ServerIsFull());
                            client.Disconnect(PacketInformation.Client);
                            return;

                        case 3:
                            client.Send(AllreadyConnected());
                            client.Disconnect(PacketInformation.Client);
                            return;

                        case 4:
                            client.Send(BannedUser(sReason));
                            client.Disconnect(PacketInformation.Client);
                            return;

                        default:
                            if (lResult == 0x8000)
                            {
                                Console.WriteLine("[IPC] Timeout");
                            }
                            else
                            {
                                Console.WriteLine("[IPC] Result unknown {0}", lResult);
                            }
                            return;
                        }
                    }
                    else
                    {
                        Console.WriteLine("F**k No fun.. SSI");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Connection Error: " + ex);
            }
        }
Exemplo n.º 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");
                    }
                }
            }
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            Program pro = new Program();

            Definitions.Bootlogo._Load();
            LoginServer.Systems.Ini ini = null;
            #region Default Settings
            int    LSPort  = 15779;
            int    IPCPort = 15790;
            string LSIP    = "127.0.0.1";
            string IPCIP   = "127.0.0.1";
            Systems.DownloadServer = "127.0.0.1";
            #endregion

            #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", "127.0.0.1").ToString();
                    IPCPort = Convert.ToInt32(ini.GetValue("IPC", "port", 15790));
                    IPCIP   = ini.GetValue("IPC", "ip", "127.0.0.1").ToString();
                    Systems.DownloadServer = ini.GetValue("Patch_Server", "ip", "127.0.0.1");
                    Systems.DownloadPort   = Convert.ToInt16(ini.GetValue("Patch_Server", "port", ""));
                    ini = null;
                    Console.WriteLine("{0}Has loaded your ip settings successfully", Product.Prefix);
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.BackgroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("{0}Settings.ini could not be found, using default setting", Product.Prefix);
                }
            }
            catch (Exception)
            {
                return;
            }
            #endregion

            #region get local ip

            if (args.Length > 0)
            {
                if (args[0] == "extip")
                {
                    HttpWebRequest HWR = (HttpWebRequest)WebRequest.Create("http://checkip.dyndns.org/");
                    HWR.Method = "GET";
                    WebResponse  MWR   = HWR.GetResponse();
                    StreamReader Hsr   = new StreamReader(MWR.GetResponseStream(), System.Text.Encoding.UTF8);
                    string       theip = Hsr.ReadToEnd();
                }
            }

            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(pro._OnClientConnect);
            net.OnError   += new Systems.Server.dError(pro._ServerError);

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

            try
            {
                net.Start(LSIP, LSPort);
            }
            catch (Exception ex)
            {
                Console.WriteLine("{1}Starting Server error: {0}", ex, Product.Prefix);
            }

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

            #region IPC Listener
            IPCServer            = new Servers.IPCServer();
            IPCServer.OnReceive += new Servers.IPCServer.dOnReceive(pro.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)
            {
                Console.WriteLine("Error start ICP: {0}", ex);
            }
            #endregion
            Console.WriteLine("{0}Ready for gameserver connection...", Global.Product.Prefix);
            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;
                        Console.WriteLine("{2}Server: ({1}) has timed out, status changed to check", SSI.Value.id, SSI.Value.name, Product.Prefix);
                    }
                }
            }
        }