using System; using Holo.Managers; using Holo.Virtual.Users; using Ion.Storage; 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; private virtualUser User; /// /// Intializes a virtual buddy. /// /// The database ID of this buddy. internal virtualBuddy(int userID) { User = userManager.getUser(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 = (User != null); bool _inRoom = false; if (_Online) _inRoom = (User.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) { User = userManager.getUser(userID); string OUT = Encoding.encodeVL64(userID); string Username = ""; if (Online) Username = User._Username; else { using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient()) { Username = dbClient.getString("SELECT name FROM users WHERE id = '" + userID + "'"); } } OUT += Username + Convert.ToChar(2); bool _Online = (User != null); if (_Online) { OUT += "II"; if (inRoom) { OUT += "I"; } else { OUT += "H"; } } else { OUT += "IHH"; } if (_Online) // Figure { string userFigure = User._Figure; OUT += userFigure + Convert.ToChar(2); } else { OUT += Convert.ToChar(2); } if (_Online) // Motto { string userMotto = User._Mission; OUT += "H" + userMotto + Convert.ToChar(2); } else { OUT += "H" + Convert.ToChar(2); } if (_Online) // Last visited { OUT += Convert.ToChar(2); } else { using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient()) { string userLastVisit = dbClient.getString("SELECT lastvisit FROM users WHERE id = '" + userID + "'"); OUT += userLastVisit + Convert.ToChar(2); } } return OUT; } } }