Beispiel #1
0
        /// <summary>
        /// Reads a length prefixed string from the message content and encodes it with a given System.Text.Encoding.
        /// </summary>
        /// <param name="pEncoding">The System.Text.Encoding to encode the string with.</param>
        /// <returns>String</returns>
        public String PopFixedString(Encoding pEncoding)
        {
            if (pEncoding == null)
            {
                pEncoding = IonEnvironment.GetDefaultTextEncoding();
            }

            return(pEncoding.GetString(this.ReadFixedValue()));
        }
Beispiel #2
0
        /// <summary>
        /// Encodes a string with a given text encoding and appends it to the message content.
        /// </summary>
        /// <param name="s">The string to append.</param>
        /// <param name="pEncoding">A System.Text.Encoding to use for encoding the string.</param>
        public void Append(string s, Encoding pEncoding)
        {
            if (s != null && s.Length > 0)
            {
                if (pEncoding == null)
                {
                    pEncoding = IonEnvironment.GetDefaultTextEncoding();
                }

                Append(pEncoding.GetBytes(s));
            }
        }
Beispiel #3
0
 public void SendData(string sData)
 {
     SendData(IonEnvironment.GetDefaultTextEncoding().GetBytes(sData));
 }
Beispiel #4
0
 /// <summary>
 /// Returns the total content of this message as a string.
 /// </summary>
 /// <returns>String</returns>
 public string GetContentString()
 {
     return(IonEnvironment.GetDefaultTextEncoding().GetString(mContent.ToArray()));
 }
Beispiel #5
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 #6
0
        /// <summary>
        /// Reads a length prefixed string from the message content and encodes it with the Ion environment default text encoding.
        /// </summary>
        /// <returns>String</returns>
        public String PopFixedString()
        {
            Encoding pEncoding = IonEnvironment.GetDefaultTextEncoding();

            return(PopFixedString(pEncoding));
        }