Пример #1
0
        public void Run(object state)
        {
            try
            {
                if (_disabled)
                {
                    return;
                }

                if (_timerRunning)
                {
                    _timerLagging = true;
                    return;
                }

                _resetEvent.Reset();

                // BEGIN CODE
                var cacheList = Program.GameContext.GetCacheManager().GetUserCache().ToList();
                if (cacheList.Count > 0)
                {
                    foreach (var cache in cacheList)
                    {
                        try
                        {
                            if (cache == null)
                            {
                                continue;
                            }

                            if (cache.IsExpired())
                            {
                                Program.GameContext.GetCacheManager().TryRemoveUser(cache.Id, out _);
                            }
                        }
                        catch (Exception e)
                        {
                            Logger.Error(e);
                        }
                    }
                }

                var cachedUsers = HabboFactory.GetUsersCached().ToList();
                if (cachedUsers.Count > 0)
                {
                    foreach (var data in cachedUsers)
                    {
                        try
                        {
                            if (data == null)
                            {
                                continue;
                            }

                            Habbo temp = null;

                            if (data.CacheExpired())
                            {
                                HabboFactory.RemoveFromCache(data.Id, out temp);
                            }

                            if (temp != null)
                            {
                                temp.Dispose();
                            }
                        }
                        catch (Exception e)
                        {
                            Logger.Error(e);
                        }
                    }
                }
                // END CODE

                // Reset the values
                _timerRunning = false;
                _timerLagging = false;

                _resetEvent.Set();
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
        }