Exemplo n.º 1
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);
            }
        }
        public static void _OnIPC(Socket aSocket, EndPoint ep, byte[] data)
        {
            try
            {
                if (data.Length >= 6)
                {
                    ushort pServer = (ushort)(data[0] + (data[1] << 8));
                    Helpers.Settings.SrevoServerInfo remoteLoginServer = Helpers.GetInformation.GetServerByEndPoint(((IPEndPoint)ep).Address.ToString(), pServer);
                    if (remoteLoginServer != null)
                    {
                        // decode data
                        Servers.IPCdeCode(ref data, remoteLoginServer.code);

                        byte pCmd = data[3];
                        int  dLen = (data[4] + (data[5] << 8));
                        byte crc  = Servers.BCRC(data, data.Length - 1);
                        if (data[data.Length - 1] != crc) // wrong CRC
                        {
                            Log.Exception("[IPC] Wrong Checksum from Server " + remoteLoginServer.id + ". Please Check !");
                            return;
                        }
                        if (data.Length >= (dLen + 6))
                        {
                            if (pCmd == (byte)IPCCommand.IPC_REQUEST_SERVERINFO)
                            {
                                remoteLoginServer.lastPing = DateTime.Now;
                                byte[] rspBuf = Helpers.Manager.IPC.PacketResponseServerInfo(Servers.IPCPort, 1, 100, Helpers.Manager.GetOnlineClientCount, Helpers.Settings.ClientVersion);
                                Servers.IPCenCode(ref rspBuf, remoteLoginServer.code);
                                Helpers.Manager.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 = ASCIIEncoding.ASCII.GetString(tmpbuf);
                                    cLen   = data[bp++];
                                    tmpbuf = new byte[cLen];
                                    Buffer.BlockCopy(data, bp, tmpbuf, 0, cLen);
                                    bp += cLen;
                                    ushort          rCode     = (ushort)(data[bp] + (data[bp + 1] << 8));
                                    string          tmpPW     = ASCIIEncoding.ASCII.GetString(tmpbuf);
                                    WorldMgr.player tmpPlayer = null;
                                    ushort          lResult   = PlayerMgr.LoginUser(tmpID, ref tmpPW, ref tmpPlayer, false);
                                    tmpPlayer = null;
                                    tmpbuf    = Helpers.Manager.IPC.PacketResponseLogin(Servers.IPCPort, lResult, rCode, lResult == 4 ? tmpPW : "");
                                    Servers.IPCenCode(ref tmpbuf, remoteLoginServer.code);
                                    Helpers.Manager.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
                {
                    Log.Exception("[IPC] packet to short from " + ep.ToString());
                }
            }
            catch (Exception ex)
            {
                Log.Exception("[IPC.OnIPC] ", ex);
            }
        }