示例#1
0
        internal static Habbo getHabboForId(uint UserId)
        {
            Habbo result;

            try
            {
                GameClient clientByUserID = CyberEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);
                if (clientByUserID != null)
                {
                    Habbo habbo = clientByUserID.GetHabbo();
                    if (habbo != null && habbo.Id > 0u)
                    {
                        if (CyberEnvironment.usersCached.Contains(UserId))
                        {
                            CyberEnvironment.usersCached.Remove(UserId);
                        }
                        result = habbo;
                        return(result);
                    }
                }
                else
                {
                    if (CyberEnvironment.usersCached.Contains(UserId))
                    {
                        result = (Habbo)CyberEnvironment.usersCached[UserId];
                        return(result);
                    }
                    UserData userData = UserDataFactory.GetUserData(checked ((int)UserId));
                    Habbo    user     = userData.user;
                    if (user != null)
                    {
                        user.InitInformation(userData);
                        CyberEnvironment.usersCached.Add(UserId, user);
                        result = user;
                        return(result);
                    }
                }
                result = null;
            }
            catch
            {
                result = null;
            }
            return(result);
        }
示例#2
0
 internal static bool IsValidAlphaNumeric(string inputStr)
 {
     inputStr = inputStr.ToLower();
     if (string.IsNullOrEmpty(inputStr))
     {
         return(false);
     }
     checked
     {
         for (int i = 0; i < inputStr.Length; i++)
         {
             if (!CyberEnvironment.isValid(inputStr[i]))
             {
                 return(false);
             }
         }
         return(true);
     }
 }
示例#3
0
        internal static void PerformShutDown(bool Restart)
        {
            DateTime now = DateTime.Now;

            CyberEnvironment.ShutdownInitiated = true;
            ServerMessage serverMessage = new ServerMessage(Outgoing.SuperNotificationMessageComposer);

            serverMessage.AppendString("disconnection");
            serverMessage.AppendInt32(2);
            serverMessage.AppendString("title");
            serverMessage.AppendString("HEY EVERYONE!");
            serverMessage.AppendString("message");
            if (Restart)
            {
                serverMessage.AppendString("<b>The hotel is shutting down for a break.</b>\nYou may come back later.\r\n<b>So long!</b>");
            }
            else
            {
                serverMessage.AppendString("<b>The hotel is shutting down for a break.</b><br />You may come back soon. Don't worry, everything's going to be saved..<br /><b>So long!</b>\r\n~ This session was powered by Cyber Emulator");
            }
            CyberEnvironment.GetGame().GetClientManager().QueueBroadcaseMessage(serverMessage);
            Thread.Sleep(6000);
            CyberEnvironment.Game.StopGameLoop();
            DateTime arg_93_0 = DateTime.Now;

            Logging.WriteLine("Shutting down...", ConsoleColor.Yellow);
            Console.Title = "Cyber Emulator | Shutting down...";
            DateTime arg_AF_0 = DateTime.Now;

            CyberEnvironment.GetGame().GetClientManager().CloseAll();
            DateTime arg_C4_0 = DateTime.Now;

            CyberEnvironment.Game.GetRoomManager().RemoveAllRooms();
            foreach (Guild Group in Game.GetGroupManager().Groups.Values)
            {
                Group.UpdateForum();
            }

            CyberEnvironment.GetConnectionManager().Destroy();
            DateTime arg_E3_0 = DateTime.Now;

            using (IQueryAdapter queryreactor = CyberEnvironment.manager.getQueryReactor())
            {
                queryreactor.runFastQuery("UPDATE users SET online = '0'");
                queryreactor.runFastQuery("UPDATE rooms SET users_now = 0");
                queryreactor.runFastQuery("TRUNCATE TABLE user_roomvisits");
            }
            DateTime arg_121_0 = DateTime.Now;

            CyberEnvironment.ConnectionManager.Destroy();
            DateTime arg_131_0 = DateTime.Now;

            CyberEnvironment.Game.Destroy();
            DateTime arg_141_0 = DateTime.Now;

            try
            {
                Console.WriteLine("Destroying database manager...");
                CyberEnvironment.manager.Destroy();
            }
            catch
            {
            }
            TimeSpan span = DateTime.Now - now;

            Console.WriteLine("Cyber Emulator took " + CyberEnvironment.TimeSpanToString(span) + " in shutdown process.");
            Console.WriteLine("Cyber Emulator has shut down succesfully.");
            CyberEnvironment.isLive = false;
            if (Restart)
            {
                Process.Start(AppDomain.CurrentDomain.BaseDirectory + "\\Cyber Emulator.exe");
            }
            Console.WriteLine("Closing...");
            Environment.Exit(0);
        }
示例#4
0
 internal static void PerformShutDown()
 {
     CyberEnvironment.PerformShutDown(false);
 }
示例#5
0
        internal static void Initialize()
        {
            Console.Clear();
            CyberEnvironment.ServerStarted = DateTime.Now;
            Console.SetWindowSize(120, 40);
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine();
            Console.WriteLine(@"                              ____ _   _ ___  ____ ____    ____ _  _ _  _ _    ____ ___ ____ ____ ");
            Console.WriteLine(@"                              |     \_/  |__] |___ |__/    |___ |\/| |  | |    |__|  |  |  | |__/ ");
            Console.WriteLine(@"                              |___   |   |__] |___ |  \    |___ |  | |__| |___ |  |  |  |__| |  \ ");
            Console.WriteLine();
            Console.WriteLine("                                                Cyber Emulator - Version: " + PrettyBuild);
            Console.WriteLine("                                         based on Plus, developed by Kessiler Rodrigues.");
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("                                                 " + PrettyRelease);
            Console.Title = "Cyber Emulator | Loading data [...]";
            CyberEnvironment.DefaultEncoding = Encoding.Default;
            Console.WriteLine("");

            CyberEnvironment.cultureInfo = CultureInfo.CreateSpecificCulture("en-GB");
            TextHandling.replaceDecimal();
            try
            {
                CyberEnvironment.Configuration = new ConfigurationData(Path.Combine(Application.StartupPath, "config.ini"), false);


                MySqlConnectionStringBuilder mySqlConnectionStringBuilder = new MySqlConnectionStringBuilder();
                mySqlConnectionStringBuilder.Server                = (CyberEnvironment.GetConfig().data["db.hostname"]);
                mySqlConnectionStringBuilder.Port                  = (uint.Parse(CyberEnvironment.GetConfig().data["db.port"]));
                mySqlConnectionStringBuilder.UserID                = (CyberEnvironment.GetConfig().data["db.username"]);
                mySqlConnectionStringBuilder.Password              = (CyberEnvironment.GetConfig().data["db.password"]);
                mySqlConnectionStringBuilder.Database              = (CyberEnvironment.GetConfig().data["db.name"]);
                mySqlConnectionStringBuilder.MinimumPoolSize       = (uint.Parse(CyberEnvironment.GetConfig().data["db.pool.minsize"]));
                mySqlConnectionStringBuilder.MaximumPoolSize       = (uint.Parse(CyberEnvironment.GetConfig().data["db.pool.maxsize"]));
                mySqlConnectionStringBuilder.Pooling               = (true);
                mySqlConnectionStringBuilder.AllowZeroDateTime     = (true);
                mySqlConnectionStringBuilder.ConvertZeroDateTime   = (true);
                mySqlConnectionStringBuilder.DefaultCommandTimeout = (300u);
                mySqlConnectionStringBuilder.ConnectionTimeout     = (10u);
                CyberEnvironment.manager = new DatabaseManager(mySqlConnectionStringBuilder.ToString());

                using (IQueryAdapter queryreactor = CyberEnvironment.GetDatabaseManager().getQueryReactor())
                {
                    ConfigData = new ConfigData(queryreactor);
                    PetLocale.Init(queryreactor);
                    OfflineMessages = new Dictionary <uint, List <OfflineMessage> >();
                    OfflineMessage.InitOfflineMessages(queryreactor);
                    GiftWrappers = new GiftWrappers(queryreactor);
                }

                FriendRequestLimit = (uint)int.Parse(CyberEnvironment.GetConfig().data["client.maxrequests"]);
                if (ExtraSettings.RunExtraSettings())
                {
                    Logging.WriteLine("Loaded an extra settings file.");
                }

                Game = new Game(int.Parse(GetConfig().data["game.tcp.conlimit"]));
                Game.start();

                ConnectionManager = new ConnectionHandling(int.Parse(GetConfig().data["game.tcp.port"]), int.Parse(GetConfig().data["game.tcp.conlimit"]), int.Parse(GetConfig().data["game.tcp.conperip"]), GetConfig().data["game.tcp.enablenagles"].ToLower() == "true");

                HabboCrypto.Initialize(new RsaKeyHolder());
                CyberEnvironment.ConnectionManager.init();
                CyberEnvironment.ConnectionManager.Start();
                StaticClientMessageHandler.Initialize();

                string[] allowedIps = GetConfig().data["mus.tcp.allowedaddr"].Split(';');
                MusSystem = new MusSocket(GetConfig().data["mus.tcp.bindip"], int.Parse(GetConfig().data["mus.tcp.port"]), allowedIps, 0);


                if (Configuration.data.ContainsKey("StaffAlert.MinRank"))
                {
                    StaffAlertMinRank = uint.Parse(CyberEnvironment.GetConfig().data["StaffAlert.MinRank"]);
                }
                if (Configuration.data.ContainsKey("SeparatedTasksInMainLoops.enabled") && Configuration.data["SeparatedTasksInMainLoops.enabled"] == "true")
                {
                    SeparatedTasksInMainLoops = true;
                }
                if (Configuration.data.ContainsKey("SeparatedTasksInGameClientManager.enabled") && Configuration.data["SeparatedTasksInGameClientManager.enabled"] == "true")
                {
                    SeparatedTasksInGameClientManager = true;
                }
                Logging.WriteLine("Game was succesfully loaded.");
                isLive = true;
            }
            catch (KeyNotFoundException ex)
            {
                Logging.WriteLine("Something is missing in your configuration", ConsoleColor.Red);
                Logging.WriteLine(ex.ToString(), ConsoleColor.Yellow);
                Logging.WriteLine("Please type a key to shut down ...", ConsoleColor.Gray);
                Console.ReadKey(true);
                CyberEnvironment.Destroy();
            }
            catch (InvalidOperationException ex1)
            {
                Logging.WriteLine("Something wrong happened: " + ex1.Message, ConsoleColor.Red);
                Logging.WriteLine(ex1.ToString(), ConsoleColor.Yellow);
                Logging.WriteLine("Please type a key to shut down...", ConsoleColor.Gray);
                Console.ReadKey(true);
                CyberEnvironment.Destroy();
            }
            catch (Exception ex2)
            {
                Logging.WriteLine("An exception got caught: " + ex2.Message, ConsoleColor.Red);
                Logging.WriteLine("Type a key to know more about the error", ConsoleColor.Gray);
                Console.ReadKey();
                Logging.WriteLine(ex2.ToString(), ConsoleColor.Yellow);
                Logging.WriteLine("Please type a ket to shut down...", ConsoleColor.Gray);
                Console.ReadKey();
                Environment.Exit(1);
            }
        }