using System;
using System.Collections.Generic;
using Ion.Net.Messages;
namespace Ion.HabboHotel.Client.Utilities
{
///
/// Decodes a ClientMessage whose body consists out of structured user properties.
///
public class UserPropertiesDecoder
{
#region Fields
private readonly Dictionary mProperties;
#endregion
#region Properties
///
/// Gets a user property with a given ID. If there is no property with that ID decoded, null is returned.
///
/// The ID of the property to get.
public string this[int propID]
{
get
{
if (mProperties.ContainsKey(propID))
return mProperties[propID];
return null;
}
}
#endregion
#region Constructor
///
/// Decodes a ClientMessage body to user properties and puts them in the constructed object.
///
/// The ClientMessage to decode the body with user properties of.
public UserPropertiesDecoder(ClientMessage message)
{
if (message == null)
throw new ArgumentNullException("message");
mProperties = new Dictionary();
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);
}
}
#endregion
}
}