using System; using System.Text; using Duck.Net.Game.Protocol.Encoding; namespace Duck.Net.Game.Protocol.Messages { /// /// Represents a server>client message for the Habbo FUSE protocol. /// public class serverMessage { #region Declares /// /// The content of this message as a mutatable string. /// private StringBuilder Content; #endregion #region Constructors /// /// Constructs a server>client message with a certain ID. /// /// The ID of this message. public serverMessage(int messageID) { this.Content = new StringBuilder(base64Encoding.Encode(messageID)); } #endregion #region Methods #region Normal appending methods /// /// Appends a string to the message's content. /// /// The string to append. public void Append(string s) { this.Content.Append(s); } /// /// Appends an integer as a string to the message's content. /// /// The integer to append. public void Append(int i) { this.Content.Append(i); } #endregion #region Special appending methods /// /// Appends a Unicode character to the message's content. /// /// The number of the character to append. public void appendChar(int x) { this.Content.Append(Convert.ToChar(x)); } /// /// Appends a wire encoded integer to the message's content. /// /// The integer to encode and append. public void appendWired(int i) { this.Content.Append(base64Encoding.Encode(i)); } /// /// Appends a wire encoded boolean to the message's content. /// /// The boolean to encode and append. public void appendWired(bool b) { if (b) this.Content.Append('I'); else this.Content.Append('H'); } /// /// Appends a plain parameter in the 'key=value' format. Char13 is appended aswell. /// /// The key of the parameter to append. /// The value of the parameter to append. public void appendPlainParameter(string Key, string Value) { this.Content.Append(Key); this.Content.Append('='); this.Content.Append(Value); this.appendChar(13); } /// /// Appends a flat value to the message's content. Char9 is appended aswell. /// /// The flat value to append. public void appendFlatValue(string Value) { this.Content.Append(Value); this.appendChar(9); } /// /// Appends a value to the message's content. Char2 is appended aswell. /// /// The value to append. public void appendValue(string Value) { this.Content.Append(Value); this.appendChar(2); } #endregion #region Overridden methods /// /// Appends char1 to the message content and returns themessage content as a string. /// public override string ToString() { this.appendChar(1); return Content.ToString(); } #endregion #endregion } }