Example #1
0
        /// <summary>
        /// Destroys all the resources in the ClientMessageHandler.
        /// </summary>
        public void Destroy()
        {
            mSession = null;
            mRequestHandlers = null;

            Request = null;
            Response = null;
        }
Example #2
0
        /// <summary>
        /// Invokes the matching request handler for a given ClientMessage.
        /// </summary>
        /// <param name="request">The ClientMessage object to process.</param>
        public void HandleRequest(ClientMessage request)
        {
            IonEnvironment.GetLog().WriteLine("[" + mSession.ID + "] --> " + request.Header + request.GetContentString());

            if (request.ID > HIGHEST_MESSAGEID)
                return; // Not in protocol
            if (mRequestHandlers[request.ID] == null)
                return; // Handler not registered

            // Handle request
            Request = request;
            mRequestHandlers[request.ID].Invoke();
            Request = null;
        }
Example #3
0
        /// <summary>
        /// Decodes a ClientMessage body to user properties and puts them in the constructed object.
        /// </summary>
        /// <param name="message">The ClientMessage to decode the body with user properties of.</param>
        public UserPropertiesDecoder(ClientMessage message)
        {
            if (message == null)
                throw new ArgumentNullException("message");

            mProperties = new Dictionary<int, string>();
            while (message.remainingContent > 0)
            {
                int propID = message.PopInt32();

                if (propID == 10) // Spam me yes/no property
                {
                    // Weird exception on protocol due to Base64 boolean
                    // Skip 7 bytes and ignore this property

                    message.Advance(7);
                    continue;
                }

                string propVal = message.PopFixedString();
                mProperties.Add(propID, propVal);
            }
        }
Example #4
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);
                    }
                }
            }
        }