public static int?GetPacketInformation(PACKET_COMMAND command)
        {
            if (!Command.HasMethod(command))
            {
                throw new BufferException("CClient::OnPacket()", string.Format("{0} (0x{0:X4}) packet is unknown", (ushort)command), null);
            }

            return(Command.GetPacketInfo(command));
        }
예제 #2
0
        private void HandleClientComm(object Client)
        {
            CLIENT_STRUCT ClientObj = new CLIENT_STRUCT();
            TOKEN_STRUCT  TokenObj  = new TOKEN_STRUCT();

            TcpClient TcpClient = (TcpClient)Client;

            TcpClient.SendBufferSize    = MaxSendRec;
            TcpClient.ReceiveBufferSize = MaxSendRec;
            TcpClient.NoDelay           = true;

            IPEndPoint IP_EndPoint = TcpClient.Client.RemoteEndPoint as IPEndPoint;
            string     IP          = TcpClient.Client.RemoteEndPoint.ToString().Split(new char[] { ':' })[0];

            NetworkStream NetStream    = TcpClient.GetStream();
            serverStream  ServerStream = new serverStream(NetStream);

            try {
                // Console.WriteLine(IP + " Connected!");

                byte[] TmpDataHeader = new byte[0x8];
                if (!NetStream.CanRead || NetStream.Read(TmpDataHeader, 0, 0x8) != 0x8)
                {
                    TcpClient.Close();
                    return;
                }

                EndianIO       DataHeader = new EndianIO(TmpDataHeader, EndianStyle.BigEndian);
                PACKET_COMMAND CommandID  = (PACKET_COMMAND)DataHeader.Reader.ReadUInt32();

                int DataCount = DataHeader.Reader.ReadInt32();
                if (DataCount >= 0x8000)
                {
                    TcpClient.Close();
                    return;
                }

                byte[] Data = new byte[DataCount];
                if (!ServerStream.CanRead || ServerStream.Read(Data, 0, DataCount) != DataCount)
                {
                    TcpClient.Close();
                    return;
                }

                EndianIO EndianData = new EndianIO(Data, EndianStyle.BigEndian)
                {
                    Writer = new EndianWriter(ServerStream, EndianStyle.BigEndian)
                };

                ioData ioData;
                ioData.reader      = EndianData.Reader;
                ioData.writer      = new EndianIO(ServerStream, EndianStyle.BigEndian).Writer;
                ioData.client      = TcpClient;
                ioData.ipaddr      = IP_EndPoint;
                ioData.payloadSize = DataCount;

                if (ioData.payloadSize > 0)
                {
                    if (CommandID == PACKET_COMMAND.PACKET_COMMAND_ID_AUTH)
                    {
                        int Start = DateTime.Now.Second;
                        if (LEServer.DebugModePrints)
                        {
                            Console.WriteLine("@{1} - Command Id: {0}", CommandID, ioData.ipaddr.ToString());
                        }
                        Responces.Auth.ProcessAuthorization(ioData, ref ClientObj);
                        int End = (DateTime.Now.Second - Start);
                        if (LEServer.DebugModePrints)
                        {
                            Console.WriteLine("@{1} - Command Id: {0} Completed in: {2} seconds", CommandID, ioData.ipaddr.ToString(), End);
                        }
                    }
                    else if (CommandID == PACKET_COMMAND.PACKET_COMMAND_ID_TIME)
                    {
                        int Start = DateTime.Now.Second;
                        if (LEServer.DebugModePrints)
                        {
                            Console.WriteLine("@{1} - Command Id: {0}", CommandID, ioData.ipaddr.ToString());
                        }
                        Responces.TimeUpdate.ProcessTime(ioData, ref ClientObj);
                        int End = (DateTime.Now.Second - Start);
                        if (LEServer.DebugModePrints)
                        {
                            Console.WriteLine("@{1} - Command Id: {0} Completed in {2} seconds", CommandID, ioData.ipaddr.ToString(), End);
                        }
                    }
                    else if (CommandID == PACKET_COMMAND.PACKET_COMMAND_ID_STATUS)
                    {
                        if (LEServer.DebugModePrints)
                        {
                            Console.WriteLine("@{1} - Command Id: {0}", CommandID, ioData.ipaddr.ToString());
                        }
                        Responces.Status.ProcessStatus(ioData, ref ClientObj);
                        if (LEServer.DebugModePrints)
                        {
                            Console.WriteLine("@{1} - Command Id: {0} Passed!", CommandID, ioData.ipaddr.ToString());
                        }
                    }
                    else if (CommandID == PACKET_COMMAND.PACKET_COMMAND_ID_PRES)
                    {
                        if (LEServer.DebugModePrints)
                        {
                            Console.WriteLine("@{1} - Command Id: {0}", CommandID, ioData.ipaddr.ToString());
                        }
                        Responces.Presence.ProcessPresence(ioData, ref ClientObj);
                        if (LEServer.DebugModePrints)
                        {
                            Console.WriteLine("@{1} - Command Id: {0} Passed!", CommandID, ioData.ipaddr.ToString());
                        }
                    }
                    else if (CommandID == PACKET_COMMAND.PACKET_COMMAND_ID_SECURITY)
                    {
                        if (LEServer.DebugModePrints)
                        {
                            Console.WriteLine("@{1} - Command Id: {0}", CommandID, ioData.ipaddr.ToString());
                        }
                        Responces.Security.ProcessSecurity(ioData, ref ClientObj);
                        if (LEServer.DebugModePrints)
                        {
                            Console.WriteLine("@{1} - Command Id: {0} Passed!", CommandID, ioData.ipaddr.ToString());
                        }
                    }
                    else if (CommandID == PACKET_COMMAND.PACKET_COMMAND_ID_TOKEN_CHECK)
                    {
                        if (LEServer.DebugModePrints)
                        {
                            Console.WriteLine("@{1} - Command Id: {0}", CommandID, ioData.ipaddr.ToString());
                        }
                        Responces.Token.ProcessVerifyTkn(ioData, ref ClientObj, ref TokenObj);
                        if (LEServer.DebugModePrints)
                        {
                            Console.WriteLine("@{1} - Command Id: {0} Passed!", CommandID, ioData.ipaddr.ToString());
                        }
                    }
                    else if (CommandID == PACKET_COMMAND.PACKET_COMMAND_ID_TOKEN_REDEEM)
                    {
                        if (LEServer.DebugModePrints)
                        {
                            Console.WriteLine("@{1} - Command Id: {0}", CommandID, ioData.ipaddr.ToString());
                        }
                        Responces.Token.ProcessRedeemTkn(ioData, ref ClientObj, ref TokenObj);
                        if (LEServer.DebugModePrints)
                        {
                            Console.WriteLine("@{1} - Command Id: {0} Passed!", CommandID, ioData.ipaddr.ToString());
                        }
                    }
                    else if (CommandID == PACKET_COMMAND.PACKET_COMMAND_ID_XKE)
                    {
                        if (LEServer.DebugModePrints)
                        {
                            Console.WriteLine("@{1} - Command Id: {0}", CommandID, ioData.ipaddr.ToString());
                        }
                        Responces.XKE.ProcessXKE(ioData, ref ClientObj);
                        if (LEServer.DebugModePrints)
                        {
                            Console.WriteLine("@{1} - Command Id: {0} Passed!", CommandID, ioData.ipaddr.ToString());
                        }
                    }
                    else if (CommandID == PACKET_COMMAND.PACKET_COMMAND_ID_XSC)
                    {
                        if (LEServer.DebugModePrints)
                        {
                            Console.WriteLine("@{1} - Command Id: {0}", CommandID, ioData.ipaddr.ToString());
                        }
                        Responces.SuperVisor.ProcessXSC(ioData, ref ClientObj);
                        if (LEServer.DebugModePrints)
                        {
                            Console.WriteLine("@{1} - Command Id: {0} Passed!", CommandID, ioData.ipaddr.ToString());
                        }
                    }
                    else if (CommandID == PACKET_COMMAND.PACKET_COMMAND_ID_OFFSETS)
                    {
                        if (LEServer.DebugModePrints)
                        {
                            Console.WriteLine("@{1} - Command Id: {0}", CommandID, ioData.ipaddr.ToString());
                        }
                        Responces.Games.ProccessOffsets(ioData, ref ClientObj);
                        if (LEServer.DebugModePrints)
                        {
                            Console.WriteLine("@{1} - Command Id: {0} Passed!", CommandID, ioData.ipaddr.ToString());
                        }
                    }
                    else if (CommandID == PACKET_COMMAND.PACKET_COMMAND_ID_CPI)
                    {
                        if (LEServer.DebugModePrints)
                        {
                            Console.WriteLine("@{1} - Command Id: {0}", CommandID, ioData.ipaddr.ToString());
                        }
                        Responces.CPI.ProcessCPI(ioData, ref ClientObj);
                        if (LEServer.DebugModePrints)
                        {
                            Console.WriteLine("@{1} - Command Id: {0} Passed!", CommandID, ioData.ipaddr.ToString());
                        }
                    }
                    else if (CommandID == PACKET_COMMAND.PACKET_COMMAND_ID_SETTINGS)
                    {
                        if (LEServer.DebugModePrints)
                        {
                            Console.WriteLine("@{1} - Command Id: {0}", CommandID, ioData.ipaddr.ToString());
                        }
                        Responces.Settings.ProccessSettings(ioData, ref ClientObj);
                        if (LEServer.DebugModePrints)
                        {
                            Console.WriteLine("@{1} - Command Id: {0} Passed!", CommandID, ioData.ipaddr.ToString());
                        }
                    }
                    else
                    {
                        FireWallBanEvent(IP, "Requested Invalid Response");
                    }
                }
                else
                {
                    FireWallBanEvent(IP, "Invalid Payload Size");
                }

                DisconnectClient(ioData);
            }
            catch (Exception Ex) {
                List <Log.PrintQueue> HandleServCommErrorid = Log.GetQueue();
                Log.Add(HandleServCommErrorid, ConsoleColor.Red, "ERROR", null);
                Log.Add(HandleServCommErrorid, ConsoleColor.Red, "Exception Message:", Ex.Message);
                Log.Add(HandleServCommErrorid, ConsoleColor.Red, "StrackTrace:", Ex.StackTrace);
                Log.Print(HandleServCommErrorid);

                TcpClient.Close();
                return;
            }
            if (TcpClient.Connected)
            {
                TcpClient.Close();
            }
            return;
        }
 public CommandAttribute(PACKET_COMMAND command)
 {
     Initialize(command, null);
 }
 private void Initialize(PACKET_COMMAND command, int?size)
 {
     Command = command;
     Size    = size;
 }
 public CommandAttribute(PACKET_COMMAND command, int size)
 {
     Initialize(command, size);
 }
예제 #6
0
        public static int?GetPacketInfo(PACKET_COMMAND command)
        {
            var packetInfo = ProvidedMethods.FirstOrDefault(x => x.Value.Command == command);

            return(packetInfo.Value?.Size);
        }
예제 #7
0
 public static bool HasMethod(PACKET_COMMAND command)
 {
     return(ProvidedMethods.Count(x => x.Value.Command == command) > 0);
 }
예제 #8
0
 public static Type GetType(PACKET_COMMAND command)
 {
     return((from pair in ProvidedMethods let methodInfo = pair.Value where methodInfo.Command == command select pair.Key).FirstOrDefault());
 }