Esempio n. 1
0
        public void OnIPC(System.Net.Sockets.Socket aSocket, System.Net.EndPoint ep, byte[] data)
        {
            try
            {
                if (data.Length >= 6)
                {
                    /*string str;
                     * System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
                     * str = enc.GetString(data);*/

                    string[] ip_s = ep.ToString().Split(':');

                    Systems.SRX_Serverinfo remoteGameServer = Systems.GetServerByEndPoint(ip_s[0], UInt16.Parse(ip_s[1]));
                    if (remoteGameServer != null)
                    {
                        // decode data
                        //Network.Servers.IPCdeCode(ref data, remoteGameServer.code);

                        Systems.PacketReader pack = new Systems.PacketReader(data);
                        short pcmd = pack.Int16();
                        if (data.Length >= 6)
                        {
                            switch (pcmd)
                            {
                            default:
                                LogDebug.Show("[IPC] unknown command recevied {0:x}", pcmd);
                                break;
                            }
                        }
                        else
                        {
                            LogDebug.Show("[IPC] data to short");
                        }
                    }
                    else
                    {
                        LogDebug.Show("[IPC] can't find the GameServer {0}:{1}", ((IPEndPoint)ep).Address.ToString(), ip_s[1]);
                    }
                }
                else
                {
                    LogDebug.Show("[IPC] packet to short from {0}", ep.ToString());
                }
            }
            catch (Exception ex)
            {
                LogDebug.Show("[IPC.OnIPC] {0}", ex);
            }
        }
Esempio n. 2
0
        public void _OnIPC(Socket aSocket, EndPoint ep, byte[] data)
        {
            try
            {
                if (data.Length >= 6)
                {
                    UInt16 pServer = (UInt16)(data[0] + (data[1] << 8));
                    Systems.SRX_Serverinfo remoteLoginServer = Systems.GetServerByEndPoint(((IPEndPoint)ep).Address.ToString(), pServer);
                    if (remoteLoginServer != null)
                    {
                        // decode data
                        Servers.IPCdeCode(ref data, remoteLoginServer.code);

                        byte pCmd = data[3];
                        int  dLen = (int)(data[4] + (data[5] << 8));
                        byte crc  = Servers.BCRC(data, data.Length - 1);
                        if (data[data.Length - 1] != crc) // wrong CRC
                        {
                            Console.WriteLine("[IPC] Wrong Checksum from Server {0}. Please Check !", remoteLoginServer.id);
                            return;
                        }
                        if (data.Length >= (dLen + 6))
                        {
                            if (pCmd == (byte)IPCCommand.IPC_REQUEST_SERVERINFO)
                            {
                                remoteLoginServer.lastPing = DateTime.Now;
                                byte[] rspBuf = Systems.IPC.PacketResponseServerInfo((UInt16)Servers.IPCPort, 1, 100, (UInt16)Systems.clients.Count, (UInt16)DarkEmu_GameServer.Global.Versions.clientVersion);
                                Servers.IPCenCode(ref rspBuf, remoteLoginServer.code);
                                Systems.IPC.Send(remoteLoginServer.ip, remoteLoginServer.ipcport, rspBuf);
                            }
                            else if (pCmd == (byte)IPCCommand.IPC_REQUEST_LOGIN)
                            {
                                remoteLoginServer.lastPing = DateTime.Now;
                                if (dLen > 4)
                                {
                                    int    bp     = 6;
                                    byte   cLen   = data[bp++];
                                    byte[] tmpbuf = new byte[cLen];
                                    Buffer.BlockCopy(data, bp, tmpbuf, 0, cLen);
                                    bp += cLen;
                                    string tmpID = System.Text.ASCIIEncoding.ASCII.GetString(tmpbuf);
                                    cLen   = data[bp++];
                                    tmpbuf = new byte[cLen];
                                    Buffer.BlockCopy(data, bp, tmpbuf, 0, cLen);
                                    bp += cLen;
                                    UInt16 rCode     = (UInt16)(data[bp] + (data[bp + 1] << 8));
                                    string tmpPW     = System.Text.ASCIIEncoding.ASCII.GetString(tmpbuf);
                                    player tmpPlayer = null;
                                    int    lResult   = Systems.LoginUser(tmpID, ref tmpPW, ref tmpPlayer, false);
                                    tmpPlayer = null;
                                    tmpbuf    = Systems.IPC.PacketResponseLogin(Servers.IPCPort, (UInt16)lResult, rCode, lResult == 4 ? tmpPW : "");
                                    Servers.IPCenCode(ref tmpbuf, remoteLoginServer.code);
                                    Systems.IPC.Send(remoteLoginServer.ip, remoteLoginServer.ipcport, tmpbuf);
                                }
                                else
                                {
                                    Console.WriteLine("[IPC] content to short");
                                }
                            }
                            else
                            {
                                Console.WriteLine("[IPC] unknown command recevied");
                            }
                        }
                        else
                        {
                            Console.WriteLine("[IPC] data to short");
                        }
                    }
                    else
                    {
                        Console.WriteLine("[IPC] can't find the LoginServer {0}:{1}", ((IPEndPoint)ep).Address.ToString(), pServer);
                    }
                }
                else
                {
                    Console.WriteLine("[IPC] packet to short from {0}", ep.ToString());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("[IPC.OnIPC] {0}", ex);
            }
        }
Esempio n. 3
0
 public static int LoadServers(string serverFile, UInt16 defaultPort)
 {
     try
     {
         if (File.Exists(Environment.CurrentDirectory + @"\Settings\" + serverFile))
         {
             Systems.Ini ini   = new Systems.Ini(Environment.CurrentDirectory + @"\Settings\" + serverFile);
             string[]    sList = null;
             sList = ini.GetEntryNames("SERVERS");
             if (sList != null && sList.Length > 0)
             {
                 foreach (string sectname in sList)
                 {
                     string sName = ini.GetValue("SERVERS", sectname, "");
                     Systems.SRX_Serverinfo SServerInfo = new Systems.SRX_Serverinfo();
                     SServerInfo.id      = Convert.ToUInt16(ini.GetValue(sName, "id", 0));
                     SServerInfo.ip      = ini.GetValue(sName, "ip", "192.168.1.5");
                     SServerInfo.wan     = ini.GetValue(sName, "wan", "192.168.1.5");
                     SServerInfo.name    = ini.GetValue(sName, "name", sName);
                     SServerInfo.port    = Convert.ToUInt16(ini.GetValue(sName, "port", defaultPort));
                     SServerInfo.ipcport = Convert.ToUInt16(ini.GetValue(sName, "ipcport", "6001"));
                     SServerInfo.code    = ini.GetValue(sName, "code", "");
                     SServerInfo.lan_wan = ini.GetValue(sName, "lan_wan", "0") == "1" ? true : false;
                     SServerInfo.Version = Convert.ToInt32(ini.GetValue(sName, "version", 0));
                     if (SServerInfo.ip == "" || SServerInfo.port == 0 || SServerInfo.id == 0 || SServerInfo.ipcport == 0 || GSList.ContainsKey(SServerInfo.id))
                     {
                         LogDebug.Show("IPC: Error on Server " + sName + " in " + serverFile + ": field missing or id already in use!");
                         SServerInfo = null;
                     }
                     else
                     {
                         GSList.Add(SServerInfo.id, SServerInfo);
                     }
                 }
             }
             if (GSList.Count() > 0)
             {
                 string servers = "Server";
                 if (GSList.Count > 1)
                 {
                     servers = "Servers";
                 }
                 LogConsole.Show("Loaded " + GSList.Count() + " " + servers + " from server settings");
             }
             else
             {
                 Systems.SRX_Serverinfo GServer = new Systems.SRX_Serverinfo();
                 GServer.id = 1;
                 GServer.ip = "192.168.1.5";
                 if (Global.Network.multihomed)
                 {
                     //Multihomed
                 }
                 else
                 {
                     GServer.extip = Global.Network.LocalIP;
                 }
                 GServer.name    = "[SERVER] Default";
                 GServer.port    = defaultPort;
                 GServer.ipcport = 6001;
                 GServer.code    = "xdxdxdxdxdxd";
                 GSList.Add(GServer.id, GServer);
             }
             sList = null;
             ini   = null;
             return(GSList.Count());
         }
         else
         {
             Systems.SRX_Serverinfo GServer = new Systems.SRX_Serverinfo();
             GServer.id = 1;
             GServer.ip = "192.168.1.5";
             if (Global.Network.multihomed)
             {
                 //Multihomed
             }
             else
             {
                 //No servers
                 GServer.extip = Global.Network.LocalIP;
             }
             GServer.name    = "[SERVER " + Global.Versions.appVersion + "]";
             GServer.port    = defaultPort;
             GServer.ipcport = 6001;
             GServer.code    = "";
             GSList.Add(GServer.id, GServer);
             return(-1);
         }
     }
     catch (Exception ex)
     {
         LogConsole.Show("Error loading GameServer settings " + ex + "");
         return(-2);
     }
 }