private ClientMessage TryParseAsOldCrypto(byte[] packet)
        {
            try
            {
                int i = 0;
                while (i < packet.Length)
                {
                    int lenght = Base64Encoding.DecodeInt32(new byte[] { (byte)packet[i++], (byte)packet[i++], (byte)packet[i++] });
                    if (lenght > 0)
                    {
                        uint id = Base64Encoding.DecodeUInt32(new byte[] { (byte)packet[i++], (byte)packet[i++] });
                        if (id > 0)
                        {
                            byte[] bytes = new byte[lenght - 2];
                            for (int j = 0; j < bytes.Length; j++)
                            {
                                bytes[j] = packet[i++];
                            }

                            OldCryptoClientMessage crypto = new OldCryptoClientMessage();
                            crypto.Init(id, bytes);
                            return(crypto);
                        }
                    }
                }
            }
            catch
            {
                return(null);
            }

            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// Handles a given amount of data in a given byte array, by attempting to parse messages from the received data and process them in the message handler.
        /// </summary>
        /// <param name="Data">The byte array with the data to process.</param>
        /// <param name="numBytesToProcess">The actual amount of bytes in the byte array to process.</param>
        public void HandleConnectionData(ref byte[] data)
        {
            // Gameclient protocol or policyrequest?
            if (data[0] != 64)
            {
                IonEnvironment.GetLog().WriteInformation("Client " + mID + " sent non-gameclient message: " + IonEnvironment.GetDefaultTextEncoding().GetString(data));

                string xmlPolicy =
                    "<?xml version=\"1.0\"?>\r\n" +
                    "<!DOCTYPE cross-domain-policy SYSTEM \"/xml/dtds/cross-domain-policy.dtd\">\r\n" +
                    "<cross-domain-policy>\r\n" +
                    "<allow-access-from domain=\"*\" to-ports=\"1-31111\" />\r\n" +
                    "</cross-domain-policy>\x0";

                IonEnvironment.GetLog().WriteInformation("Client " + mID + ": sending XML cross domain policy file: " + xmlPolicy);
                mConnection.SendData(xmlPolicy);

                mMessageHandler.GetResponse().Initialize(ResponseOpcodes.SecretKey); // "@A"
                mMessageHandler.GetResponse().Append("ION/Deltar");
                mMessageHandler.SendResponse();
            }
            else
            {
                int pos = 0;
                while (pos < data.Length)
                {
                    try
                    {
                        // Total length of message (without this): 3 Base64 bytes
                        int messageLength = Base64Encoding.DecodeInt32(new byte[] { data[pos++], data[pos++], data[pos++] });

                        // ID of message: 2 Base64 bytes
                        uint messageID = Base64Encoding.DecodeUInt32(new byte[] { data[pos++], data[pos++] });

                        // Data of message: (messageLength - 2) bytes
                        byte[] Content = new byte[messageLength - 2];
                        for (int i = 0; i < Content.Length; i++)
                        {
                            Content[i] = data[pos++];
                        }

                        // Create message object
                        ClientMessage message = new ClientMessage(messageID, Content);

                        // Handle message object
                        mMessageHandler.HandleRequest(message);
                    }
                    catch (IndexOutOfRangeException) // Bad formatting!
                    {
                        IonEnvironment.GetHabboHotel().GetClients().StopClient(mID);
                    }
                    catch (Exception ex)
                    {
                        IonEnvironment.GetLog().WriteUnhandledExceptionError("GameClient.HandleConnectionData", ex);
                    }
                }
            }
        }
Beispiel #3
0
        public void HandleConnectionData(ref byte[] data)
        {
            if (data[0] == 64)
            {
                int pos = 0;
                while (pos < data.Length)
                {
                    try
                    {
                        int  MessageLength = Base64Encoding.DecodeInt32(new byte[] { data[pos++], data[pos++], data[pos++] });
                        uint MessageId     = Base64Encoding.DecodeUInt32(new byte[] { data[pos++], data[pos++] });

                        byte[] Content = new byte[MessageLength - 2];
                        for (int j = 0; j < Content.Length; j++)
                        {
                            Content[j] = data[pos++];
                        }
                        if (this.MessageHandler == null)
                        {
                            this.InitHandler();
                        }
                        ClientMessage Message = new ClientMessage(MessageId, Content);
                        if (Message != null)
                        {
                            try
                            {
                                if (int.Parse(PhoenixEnvironment.GetConfig().data["debug"]) == 1)
                                {
                                    Logging.WriteLine(string.Concat(new object[] { "[", ClientId, "] --> [", Message.Id, "] ", Message.Header, Message.GetBody() }));
                                }
                            }
                            catch
                            {
                            }
                            MessageEvent MessageHandler;
                            if (PhoenixEnvironment.GetPacketManager().Get(Message.Id, out MessageHandler))
                            {
                                MessageHandler.parse(this, Message);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logging.LogException("Error: " + ex.ToString());
                        this.Disconnect();
                    }
                }
            }
            else
            {
                if (true)
                {
                    this.Connection.SendData(CrossdomainPolicy.GetXmlPolicy());
                    this.Connection.Dispose();
                }
            }
        }
Beispiel #4
0
        private void HandleConnectionData(ref byte[] data)
        {
            int pos = 0;
            while (pos < data.Length)
            {
                try
                {
                    if (data[0] == 60)
                    {
                        CoreManager.ServerCore.GetStandardOut().PrintDebug("[" + _id + "] --> Policy Request");
                        SendData(PolicyReplyData);
                        CoreManager.ServerCore.GetStandardOut().PrintDebug("[" + _id + "] <-- Policy Sent");
                        Close();
                        return;
                    }

                    // Total length of message (without this): 3 Base64 bytes                    
                    int messageLength = Base64Encoding.DecodeInt32(new[] {data[pos++], data[pos++], data[pos++]});

                    // ID of message: 2 Base64 bytes
                    uint messageID = Base64Encoding.DecodeUInt32(new[] {data[pos++], data[pos++]});

                    // Data of message: (messageLength - 2) bytes
                    byte[] content = new byte[messageLength - 2];
                    for (int i = 0; i < content.Length; i++)
                    {
                        content[i] = data[pos++];
                    }

                    // Create message object
                    IncomingMessage message = new IncomingMessage(messageID, content);

                    if (Habbo.IsLoggedIn())
                        CoreManager.ServerCore.GetStandardOut().PrintDebug("[" + Habbo.GetUsername() + "] --> " +
                                                                           message.GetHeader() +
                                                                           message.GetContentString());
                    else
                        CoreManager.ServerCore.GetStandardOut().PrintDebug("[" + _id + "] --> " +
                                                                           message.GetHeader() +
                                                                           message.GetContentString());


                    // Handle message object
                    bool unknown = true;

                    if (_packetHandlers.GetLength(0) > messageID)
                    {
                        if (_packetHandlers[messageID, 3] != null)
                        {
                            lock (_packetHandlers[messageID, 3])
                            {
                                _packetHandlers[messageID, 3].Invoke(Habbo, message); // Execute High Priority
                                unknown = false;
                            }
                        }

                        if (message.IsCancelled())
                            return;

                        if (_packetHandlers[messageID, 2] != null)
                        {
                            lock (_packetHandlers[messageID, 2])
                            {
                                _packetHandlers[messageID, 2].Invoke(Habbo, message); // Execute Low Priority
                                unknown = false;
                            }
                        }

                        if (message.IsCancelled())
                            return;

                        if (_packetHandlers[messageID, 1] != null)
                        {
                            lock (_packetHandlers[messageID, 1])
                            {
                                _packetHandlers[messageID, 1].Invoke(Habbo, message); // Execute Default Action
                                unknown = false;
                            }
                        }

                        if (_packetHandlers[messageID, 0] != null)
                        {
                            lock (_packetHandlers[messageID, 0])
                            {
                                _packetHandlers[messageID, 0].Invoke(Habbo, message); // Execute Watchers
                                unknown = false;
                            }
                        }
                    }

                    if (unknown)
                    {
                        CoreManager.ServerCore.GetStandardOut().PrintWarning("Packet " + messageID + " ('" +
                                                                             message.GetHeader() + "') unhandled!");
                    }
                }
                catch (IndexOutOfRangeException) // Bad formatting!
                {
                    // TODO: Move this to IHI
                    //IonEnvironment.GetHabboHotel().GetClients().StopClient(_id, 0);
                }
                catch (Exception ex)
                {
                    CoreManager.ServerCore.GetStandardOut().PrintException(ex);
                }
            }
        }
Beispiel #5
0
        private void ProcessData(byte[] Data)
        {
            if (Data.Length == 0)
            {
                return;
            }

            if (Data[0] == 64)
            {
                int Pos = 0;

                while (Pos < Data.Length)
                {
                    ClientMessage Message = null;

                    try
                    {
                        int  MessageLength = Base64Encoding.DecodeInt32(new byte[] { Data[Pos++], Data[Pos++], Data[Pos++] });
                        uint MessageId     = Base64Encoding.DecodeUInt32(new byte[] { Data[Pos++], Data[Pos++] });

                        byte[] Content = new byte[MessageLength - 2];

                        for (int i = 0; i < Content.Length; i++)
                        {
                            Content[i] = Data[Pos++];
                        }

                        Message = new ClientMessage(MessageId, Content);
                    }
                    catch (Exception)
                    {
                        SessionManager.StopSession(mId); // packet formatting exception
                        return;
                    }

                    if (Message != null)
                    {
                        Output.WriteLine("[RCV][" + mId + "]: " + Message.ToString(), OutputLevel.DebugInformation);

                        try
                        {
                            DataRouter.HandleData(this, Message);
                        }
                        catch (Exception e)
                        {
                            Output.WriteLine("Critical error in HandleData stack: " + e.Message + "\n\n" + e.StackTrace,
                                             OutputLevel.CriticalError);
                            SessionManager.StopSession(mId);
                            return;
                        }
                    }
                }
            }
            else if (Data[0] == 60)
            {
                Output.WriteLine("Sent crossdomain policy to client " + mId + ".", OutputLevel.DebugInformation);
                SendData(CrossdomainPolicy.GetBytes());
                SessionManager.StopSession(mId);
            }
            else
            {
                SessionManager.StopSession(mId);
            }
        }
        public void ParsePacket(ref byte[] bytes)
        {
            if (bytes[0] == 64)
            {
                int i = 0;

                while (i < bytes.Length)
                {
                    try
                    {
                        int num = Base64Encoding.DecodeInt32(new byte[]
                        {
                            bytes[i++],
                            bytes[i++],
                            bytes[i++]
                        });

                        uint uint_ = Base64Encoding.DecodeUInt32(new byte[]
                        {
                            bytes[i++],
                            bytes[i++]
                        });

                        byte[] array = new byte[num - 2];
                        for (int j = 0; j < array.Length; j++)
                        {
                            array[j] = bytes[i++];
                        }

                        if (this.ClientMessageHandler == null)
                        {
                            this.CreateClientMessageHandler();
                        }
                        ClientMessage @class = new ClientMessage(uint_, array);
                        if (@class != null)
                        {
                            try
                            {
                                if (int.Parse(GoldTree.GetConfig().data["debug"]) == 1)
                                {
                                    Logging.WriteLine(string.Concat(new object[]
                                    {
                                        "[",
                                        this.ID,
                                        "] --> [",
                                        @class.Id,
                                        "] ",
                                        @class.Header,
                                        @class.GetBody()
                                    }));
                                }
                            }
                            catch
                            {
                            }
                            Interface @interface;
                            if (GoldTree.GetPacketManager().Handle(@class.Id, out @interface))
                            {
                                try
                                {
                                    @interface.Handle(this, @class);
                                }
                                catch (Exception ex)
                                {
                                    Logging.LogException("Error: " + ex.ToString());
                                    this.method_12();
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex.GetType() == typeof(IndexOutOfRangeException))
                        {
                            return;
                        }
                        Logging.LogException("Error: " + ex.ToString());
                        this.method_12();
                    }
                }
            }
            else
            {
                if (true)                //Class13.Boolean_7)
                {
                    this.Connection.SendMessage(CrossdomainPolicy.GetXmlPolicy());
                    //this.Message1_0.SendData(GoldTree.GetDefaultEncoding().GetBytes(CrossdomainPolicy.GetXmlPolicy()));
                    this.Connection.Close();
                }
            }
        }
Beispiel #7
0
 public void method_13(ref byte[] byte_0)
 {
     if (byte_0[0] == 64)
     {
         int i = 0;
         while (i < byte_0.Length)
         {
             try
             {
                 int num = Base64Encoding.DecodeInt32(new byte[]
                 {
                     byte_0[i++],
                     byte_0[i++],
                     byte_0[i++]
                 });
                 uint uint_ = Base64Encoding.DecodeUInt32(new byte[]
                 {
                     byte_0[i++],
                     byte_0[i++]
                 });
                 byte[] array = new byte[num - 2];
                 for (int j = 0; j < array.Length; j++)
                 {
                     array[j] = byte_0[i++];
                 }
                 if (this.class17_0 == null)
                 {
                     this.method_4();
                 }
                 ClientMessage @class = new ClientMessage(uint_, array);
                 if (@class != null)
                 {
                     try
                     {
                         if (int.Parse(GoldTree.GetConfig().data["debug"]) == 1)
                         {
                             Logging.WriteLine(string.Concat(new object[]
                             {
                                 "[",
                                 this.UInt32_0,
                                 "] --> [",
                                 @class.Id,
                                 "] ",
                                 @class.Header,
                                 @class.GetBody()
                             }));
                         }
                     }
                     catch
                     {
                     }
                     Interface @interface;
                     if (GoldTree.smethod_10().Handle(@class.Id, out @interface))
                     {
                         @interface.Handle(this, @class);
                     }
                 }
             }
             catch (Exception ex)
             {
                 Logging.LogException("Error: " + ex.ToString());
                 this.method_12();
             }
         }
     }
     else
     {
         if (true)                //Class13.Boolean_7)
         {
             this.Message1_0.method_4(CrossdomainPolicy.GetXmlPolicy());
             this.Message1_0.Dispose();
         }
     }
 }
Beispiel #8
0
        private void HandleConnectionData(ref byte[] data)
        {
            int pos = 0;

            while (pos < data.Length)
            {
                try
                {
                    // Total length of message (without this): 3 Base64 bytes
                    int messageLength = Base64Encoding.DecodeInt32(new byte[] { data[pos++], data[pos++], data[pos++] });

                    // ID of message: 2 Base64 bytes
                    uint messageID = Base64Encoding.DecodeUInt32(new byte[] { data[pos++], data[pos++] });

                    // Data of message: (messageLength - 2) bytes
                    byte[] Content = new byte[messageLength - 2];
                    for (int i = 0; i < Content.Length; i++)
                    {
                        Content[i] = data[pos++];
                    }

                    // Create message object
                    IncomingMessage message = new IncomingMessage(messageID, Content);

                    if (this.mUser.IsLoggedIn())
                    {
                        Core.GetStandardOut().PrintDebug("[" + this.mUser.GetUsername() + "] -- > " + message.Header + message.GetContentString());
                    }
                    else
                    {
                        Core.GetStandardOut().PrintDebug("[No Name] -> " + message.Header + message.GetContentString());
                    }


                    // Handle message object
                    this.mPacketHandlers[messageID, 3].Invoke(message); // Execute High Priority

                    if (message.IsCancelled())
                    {
                        return;
                    }

                    this.mPacketHandlers[messageID, 2].Invoke(message); // Execute Low Priority

                    if (message.IsCancelled())
                    {
                        return;
                    }

                    this.mPacketHandlers[messageID, 1].Invoke(message); // Execute Default Action
                    this.mPacketHandlers[messageID, 0].Invoke(message); // Execute Watchers
                }
                catch (IndexOutOfRangeException)                        // Bad formatting!
                {
                    // TODO: Move this to IHI
                    //IonEnvironment.GetHabboHotel().GetClients().StopClient(mID, 0);
                }
                catch (Exception ex)
                {
                    Core.GetStandardOut().PrintError(ex.Message);
                }
            }
        }
        public override bool HandlePacket(GameClient session, ref byte[] packet)
        {
            try
            {
                for (int i = 0; i < packet.Length; i++)
                {
                    if (this.ReadByte(packet[i]))
                    {
                        if (this.RC4 != null)
                        {
                            this.Packet = this.RC4.Decipher(this.Packet);
                        }

                        OldCryptoClientMessage message = new OldCryptoClientMessage();
                        message.Init(Base64Encoding.DecodeUInt32(new byte[] { this.Packet[0], this.Packet[1] }), this.Packet);
                        message.Skip(2);
                        session.HandlePacket(message);

                        Array.Clear(this.Packet, 0, this.Packet.Length);
                        this.Packet      = null;
                        this.Lenght      = null;
                        this.LenghtBytes = null;
                        this.Pointer     = 0;

                        if (session.Disconnected)
                        {
                            return(false); //packet disconnected the user! :D
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.AppendLine("Exception: " + ex.ToString());
                stringBuilder.AppendLine("- - - DEBUG INFORMATION BELOW - - - ");
                stringBuilder.AppendLine("Lenght bytes:" + string.Join(",", this.LenghtBytes));
                stringBuilder.Append("Lenght bytes as UTF8: ");
                foreach (byte?byte_ in this.LenghtBytes)
                {
                    stringBuilder.Append(Encoding.UTF8.GetString(new byte[1] {
                        (byte)byte_
                    }));
                }
                stringBuilder.AppendLine();
                stringBuilder.AppendLine("Lenght: " + this.Lenght);
                if (this.Packet != null)
                {
                    stringBuilder.AppendLine("Bytes readed: " + string.Join(",", this.Packet));
                    stringBuilder.AppendLine("Bytes readed as UTF8: " + Encoding.UTF8.GetString(this.Packet));
                }
                stringBuilder.AppendLine("Pointer: " + this.Pointer);
                stringBuilder.AppendLine("Reading bytes: " + string.Join(",", packet));
                stringBuilder.AppendLine("Reading bytes as UTF8: " + Encoding.UTF8.GetString(packet));
                Logging.LogPacketException(stringBuilder.ToString());

                session.Stop("OldCryptoDataDecoderHandler failed");
                return(false);
            }
        }