Пример #1
0
 private void ParserOnNewPacket(ClientPacket Message)
 {
     try
     {
         ProjectHub.GetGame().GetPacketManager().TryExecutePacket(this, Message);
     }
     catch (Exception Error)
     {
         Logging.LogError(Error.ToString());
     }
 }
Пример #2
0
        public UserCache GenerateUser(int Id)
        {
            UserCache User = null;

            if (UsersCached.ContainsKey(Id))
            {
                if (TryGetUser(Id, out User))
                {
                    return(User);
                }
            }

            GameClient Client = ProjectHub.GetGame().GetClientManager().GetClientByUserID(Id);

            if (Client != null)
            {
                if (Client.GetHabbo() != null)
                {
                    User = new UserCache(Id, Client.GetHabbo().Username, Client.GetHabbo().Motto, Client.GetHabbo().Look);
                    UsersCached.TryAdd(Id, User);

                    return(User);
                }
            }

            using (IQueryAdapter DbClient = ProjectHub.GetDatabaseManager().GetQueryReactor())
            {
                DbClient.SetQuery("SELECT `username`, `motto`, `look` FROM " + ProjectHub.DbPrefix + "users WHERE id = @id LIMIT 1");
                DbClient.AddParameter("id", Id);

                DataRow DataRow = DbClient.getRow();

                if (DataRow != null)
                {
                    User = new UserCache(Id, DataRow["username"].ToString(), DataRow["motto"].ToString(), DataRow["look"].ToString());
                    UsersCached.TryAdd(Id, User);
                }

                DataRow = null;
            }

            return(User);
        }
Пример #3
0
        public static Bot CreateBot(ItemData Data, int OwnerId)
        {
            DataRow    BotData = null;
            CatalogBot CataBot = null;

            if (!ProjectHub.GetGame().GetCatalog().TryGetBot(Data.Id, out CataBot))
            {
                return(null);
            }

            using (IQueryAdapter DbClient = ProjectHub.GetDatabaseManager().GetQueryReactor())
            {
                DbClient.SetQuery("INSERT INTO " + ProjectHub.DbPrefix + "bots (`user_id`,`name`,`motto`,`look`,`gender`,`ai_type`) VALUES ('" + OwnerId + "', '" + CataBot.Name + "', '" + CataBot.Motto + "', '" + CataBot.Figure + "', '" + CataBot.Gender + "', '" + CataBot.AIType + "')");
                int Id = Convert.ToInt32(DbClient.InsertQuery());

                DbClient.SetQuery("SELECT `id`,`user_id`,`name`,`motto`,`look`,`gender` FROM `" + ProjectHub.DbPrefix + "bots` WHERE `user_id` = '" + OwnerId + "' AND `id` = '" + Id + "' LIMIT 1");
                BotData = DbClient.getRow();
            }

            return(new Bot(Convert.ToInt32(BotData["id"]), Convert.ToInt32(BotData["user_id"]), Convert.ToString(BotData["name"]), Convert.ToString(BotData["motto"]), Convert.ToString(BotData["look"]), Convert.ToString(BotData["gender"])));
        }
Пример #4
0
        public static void InvokeCommand(string Data)
        {
            try
            {
                string[] Params = Data.Split(' ');

                switch (Params[0].ToLower())
                {
                case "close":
                case "stop":
                case "shutdown":
                {
                    new Logger("console", Params[0], "NULL");
                    ProjectHub.Shutdown();
                    break;
                }

                case "commands":
                {
                    Logging.WriteLine("Current console command list:", ConsoleColor.DarkMagenta);
                    Logging.WriteLine("- commands - Lists all console commands!", ConsoleColor.DarkMagenta);
                    Logging.WriteLine("- close, stop, shutdown - Shuts down server securely!", ConsoleColor.DarkMagenta);
                    Logging.WriteLine("- update_settings, reload_settings - Reloads server settings from database!", ConsoleColor.DarkMagenta);
                    Logging.WriteLine("- update_texts, reload_texts - Reloads server texts from database!", ConsoleColor.DarkMagenta);
                    Logging.WriteLine("- update_wordfilter, reload_wordfilter - Reloads wordfilter from database!", ConsoleColor.DarkMagenta);
                    Logging.WriteLine("- uptime - Shows current uptime of server!", ConsoleColor.DarkMagenta);
                    new Logger("console", Params[0], "NULL");
                    break;
                }

                case "update_settings":
                case "reload_settings":
                {
                    Logging.Write("Updating server settings", ConsoleColor.DarkMagenta);
                    ProjectHub.SettingsData = new SettingsData();
                    new Logger("console", Params[0], "NULL");
                    Logging.WriteSimpleLine(" - Completed!", ConsoleColor.DarkMagenta);
                    break;
                }

                case "update_texts":
                case "reload_texts":
                {
                    Logging.Write("Updating server texts", ConsoleColor.DarkMagenta);
                    ProjectHub.TextsData = new TextsData();
                    new Logger("console", Params[0], "NULL");
                    Logging.WriteSimpleLine(" - Completed!", ConsoleColor.DarkMagenta);
                    break;
                }

                case "update_wordfilter":
                case "reload_wordfilter":
                {
                    Logging.Write("Updating wordfilter", ConsoleColor.DarkMagenta);
                    ProjectHub.GetGame().GetWordFilterManager();
                    new Logger("console", Params[0], "NULL");
                    Logging.WriteSimpleLine(" - Completed!", ConsoleColor.DarkMagenta);
                    break;
                }

                case "uptime":
                {
                    TimeSpan Uptime = DateTime.Now - ProjectHub.ServerStarted;
                    Logging.WriteLine("Uptime: Days: " + Uptime.Days + ", Hours: " + Uptime.Days + ", Minutes: " + Uptime.Minutes + ", Seconds: " + Uptime.Seconds);
                    new Logger("console", Params[0], "NULL");
                    break;
                }

                default:
                {
                    if (string.IsNullOrEmpty(Data))
                    {
                        Logging.WriteLine("Empty command data! Type commands for list of commands!");
                    }
                    else
                    {
                        Logging.WriteLine(Params[0].ToLower() + " is an unknown or unsupported command! Type commands for list of commands!");
                    }

                    break;
                }
                }
            }
            catch
            {
            }
        }
Пример #5
0
        public void Run(object State)
        {
            try
            {
                if (Disabled)
                {
                    return;
                }

                if (TimerRunning)
                {
                    TimerLagging = true;
                    return;
                }

                ResetEvent.Reset();
                List <UserCache> CacheList = ProjectHub.GetGame().GetCacheManager().GetUserCache().ToList();

                if (CacheList.Count > 0)
                {
                    foreach (UserCache Cache in CacheList)
                    {
                        try
                        {
                            if (Cache == null)
                            {
                                continue;
                            }

                            UserCache Temp = null;

                            if (Cache.IsExpired())
                            {
                                ProjectHub.GetGame().GetCacheManager().TryRemoveUser(Cache.Id, out Temp);
                            }

                            Temp = null;
                        }
                        catch (Exception Error)
                        {
                            Logging.LogError(Error.ToString());
                        }
                    }
                }

                CacheList = null;
                List <Habbo> CachedUsers = ProjectHub.GetUsersCached().ToList();

                if (CachedUsers.Count > 0)
                {
                    foreach (Habbo Data in CachedUsers)
                    {
                        try
                        {
                            if (Data == null)
                            {
                                continue;
                            }

                            Habbo Temp = null;

                            if (Data.CacheExpired())
                            {
                                ProjectHub.RemoveFromCache(Data.Id, out Temp);
                            }

                            if (Temp != null)
                            {
                                Temp.Dispose();
                            }

                            Temp = null;
                        }
                        catch (Exception Error)
                        {
                            Logging.LogError(Error.ToString());
                        }
                    }
                }

                CachedUsers  = null;
                TimerRunning = false;
                TimerLagging = false;
                ResetEvent.Set();
            }
            catch (Exception Error)
            {
                Logging.LogError(Error.ToString());
            }
        }