/// <summary> /// Set if the user is logged in. /// This also updates the LastAccess time if required. /// </summary> /// <param name = "value">The user's new logged in status.</param> public Habbo SetLoggedIn(bool value) { if (!_isLoggedIn && value) { HabboEventArgs habboEventArgs = new HabboEventArgs(); if (OnPreHabboLogin != null) { OnPreHabboLogin(this, habboEventArgs); } CoreManager.ServerCore.GetHabboDistributor().InvokeOnPreHabboLogin(this, habboEventArgs); if (habboEventArgs.Cancelled) { GetConnection().Disconnect(); return(this); } _lastAccess = DateTime.Now; using (ISession db = CoreManager.ServerCore.GetDatabaseSession()) { Database.Habbo habbo = db.Get <Database.Habbo>(_id); habbo.last_access = _lastAccess; db.Update(habbo); } } _isLoggedIn = value; return(this); }
/// <summary> /// Return a Habbo from the cache if possible. /// If the Habbo is not cached then put it in the cache and return it. /// FYI: If the Habbo is not cached then this the Habbo will be created from the data provided. /// </summary> /// <param name = "habbo">The database result of the Habbo to return.</param> public Habbo GetHabbo(Database.Habbo habbo) { lock (this) { // Is this Habbo already cached? if (_habboCache.ContainsKey(habbo.habbo_id)) { // Yes, get the cached Habbo. Habbo cached = _habboCache[habbo.habbo_id].Target as Habbo; // Has the cached Habbo been collected and removed from memory? if (cached != null) { // No, return the cached copy. return(cached); } // Yes, we may as well do a full clean up here. We'll have to loop over it all anyway. CleanUp(true); } // Load the Habbo into memory from the database. Habbo theHabbo = new Habbo(habbo); // Yes, cache it. CacheHabbo(theHabbo); // Return the newly cached Habbo. return(theHabbo); } }
public Habbo(Database.Habbo habboData) { _id = habboData.habbo_id; DisplayName = _username = habboData.username; _motto = habboData.motto; Figure = CoreManager.ServerCore.GetHabboFigureFactory().Parse(habboData.figure, habboData.gender); }
/// <summary> /// Deduct credits from the user's balance. /// </summary> /// <param name = "amount">The amount of credits.</param> public Habbo TakeCredits(int amount) { using (ISession db = CoreManager.ServerCore.GetDatabaseSession()) { Database.Habbo habboData = db.CreateCriteria <Habbo>() .SetProjection(Projections.Property("credits")) .Add(new EqPropertyExpression("habbo_id", _id.ToString())) .UniqueResult <Database.Habbo>(); _creditBalance = habboData.credits -= amount; db.Update(habboData); } return(this); }
/// <summary> /// Construct a User object for the user with the given ID. /// DO NOT USE THIS FOR GETTING A USER - USE THE USER DISTRIBUTOR /// </summary> /// <param name = "username">The username of user you wish to a User object for.</param> internal Habbo(string username) { _username = DisplayName = username; Database.Habbo habbo = new Database.Habbo { username = username }; using (ISession db = CoreManager.ServerCore.GetDatabaseSession()) { habbo = db.CreateCriteria <Database.Habbo>() .Add(Example.Create(habbo)) .UniqueResult <Database.Habbo>(); } _id = habbo.habbo_id; _motto = habbo.motto; Figure = CoreManager.ServerCore.GetHabboFigureFactory().Parse(habbo.figure, habbo.gender); }
/// <summary> /// Construct a User object for the user with the given ID. /// DO NOT USE THIS FOR GETTING A USER - USE THE USER DISTRIBUTOR /// </summary> /// <param name = "username">The username of user you wish to a User object for.</param> internal Habbo(string username) { _username = DisplayName = username; Database.Habbo habbo = new Database.Habbo { username = username }; using (ISession db = CoreManager.ServerCore.GetDatabaseSession()) { habbo = db.CreateCriteria<Database.Habbo>() .Add(Example.Create(habbo)) .UniqueResult<Database.Habbo>(); } _id = habbo.habbo_id; _motto = habbo.motto; Figure = CoreManager.ServerCore.GetHabboFigureFactory().Parse(habbo.figure, habbo.gender); }