using System; using Holo.Managers; using Holo.Virtual.Users; using Ion.Storage; using System.Text; namespace Holo.Virtual.Users.Messenger { /// /// Represents a virtual buddy used in the virtualMessenger object. /// class virtualBuddy { /// /// The database ID of this user. /// internal int userID; /// /// Indicates if this user was online at the moment of the latest ToString request. /// internal bool Online; /// /// Indicates if this user was in a room at the moment of the latest ToString request. /// private bool inRoom; /// /// Intializes a virtual buddy. /// /// The database ID of this buddy. internal virtualBuddy(int userID) { this.userID = userID; bool b = Updated; // Update } /// /// Updates the booleans for online and inroom, and returns if there has been changes (so: updates) since the last call to this bool. /// internal bool Updated { get { bool _Online = userManager.containsUser(userID); bool _inRoom = false; if (_Online) _inRoom = (userManager.getUser(userID).roomUser != null); if (_inRoom != inRoom || _Online != Online) { Online = _Online; inRoom = _inRoom; return true; } else return false; } } /// /// Important to check the 'Updated' bool first. Returns the status string for a virtual buddy based on the statistics of the last call of 'Updated'. /// /// Specifies if to include the username in the string. Only required at first sending of packet in session of client. internal string ToString(bool includeUsername) { StringBuilder OUT = new StringBuilder(Encoding.encodeVL64(userID)); if (includeUsername) { string Username = ""; if (Online) Username = userManager.getUser(userID)._Username; else { using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient()) { Username = dbClient.getString("SELECT name FROM users WHERE id = '" + userID + "'"); } } #region buildlist friends OUT.Append(Username + Convert.ToChar(2)); #endregion } if (Online) { OUT.Append("II"); if (inRoom) OUT.Append("I"); else OUT.Append("H"); OUT.Append(userManager.getUser(userID)._Figure); } else OUT.Append("IHH"); return OUT.ToString() + Convert.ToChar(2) + "H"; } } }