Ejemplo n.º 1
0
        public bool RequestBuddy(string UserQuery)
        {
            int  userID;
            bool hasFQDisabled;

            #region Bot Friendship
            if (RoleplayBotManager.GetDeployedBotByName(UserQuery) != null)
            {
                RoomUser BotUser = RoleplayBotManager.GetDeployedBotByName(UserQuery);

                if (BotUser.GetBotRoleplay() == null)
                {
                    return(false);
                }

                if (GetClient().GetRoleplay().BotFriendShips.ContainsKey(BotUser.GetBotRoleplay().Id))
                {
                    GetClient().SendWhisper("Você já é amigo deste NPC!", 1);
                    return(false);
                }

                if (!BotUser.GetBotRoleplay().AddableBot)
                {
                    GetClient().SendWhisper("Você não pode adicionar este bot!", 1);
                    return(false);
                }

                BotUser.Chat("OK " + GetClient().GetHabbo().Username + ", eu adicionei você à lista de contatos do meu telefone!", true);
                GetClient().GetRoleplay().AddBotAsFriend(BotUser.GetBotRoleplay().Id);

                return(true);
            }
            #endregion

            if (GetClient().GetRoleplay().PhoneType <= 0)
            {
                GetClient().SendWhisper("Você não tem um telefone para fazer isso! Compre um na Loja de Celulares [Quarto ID: 25]", 1);
                return(false);
            }

            GameClient client = PlusEnvironment.GetGame().GetClientManager().GetClientByUsername(UserQuery);
            if (client == null)
            {
                DataRow Row = null;
                using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
                {
                    dbClient.SetQuery("SELECT `id`,`block_newfriends` FROM `users` WHERE `username` = @query LIMIT 1");
                    dbClient.AddParameter("query", UserQuery.ToLower());
                    Row = dbClient.getRow();
                }

                if (Row == null)
                {
                    return(false);
                }

                userID        = Convert.ToInt32(Row["id"]);
                hasFQDisabled = PlusEnvironment.EnumToBool(Row["block_newfriends"].ToString());
            }
            else
            {
                userID        = client.GetHabbo().Id;
                hasFQDisabled = client.GetHabbo().AllowFriendRequests;
            }

            if (hasFQDisabled)
            {
                GetClient().SendMessage(new MessengerErrorComposer(39, 3));
                return(false);
            }

            int ToId = userID;
            if (RequestExists(ToId))
            {
                return(true);
            }

            int PhoneType = 0;
            if (client == null || client.GetHabbo() == null || client.GetRoleplay() == null)
            {
                using (var dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
                {
                    dbClient.SetQuery("SELECT `phone` FROM `rp_stats` WHERE `id` = @userid LIMIT 1");
                    dbClient.AddParameter("userid", userID);
                    PhoneType = dbClient.getInteger();
                }
            }
            else
            {
                PhoneType = client.GetRoleplay().PhoneType;
            }

            if (PhoneType <= 0)
            {
                GetClient().SendWhisper("Desculpe, " + UserQuery + " não tem um telefone!", 1);
                return(false);
            }

            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.RunQuery("REPLACE INTO `messenger_requests` (`from_id`,`to_id`) VALUES ('" + _userId + "','" + ToId + "')");
            }

            GameClient ToUser = PlusEnvironment.GetGame().GetClientManager().GetClientByUserID(ToId);
            if (ToUser == null || ToUser.GetHabbo() == null)
            {
                return(true);
            }

            MessengerRequest Request = new MessengerRequest(ToId, _userId, PlusEnvironment.GetGame().GetClientManager().GetNameById(_userId));

            ToUser.GetHabbo().GetMessenger().OnNewRequest(_userId);

            using (UserCache ThisUser = PlusEnvironment.GetGame().GetCacheManager().GenerateUser(_userId))
            {
                if (ThisUser != null)
                {
                    ToUser.SendMessage(new NewBuddyRequestComposer(ThisUser));
                }
            }

            _requests.Add(ToId, Request);
            return(true);
        }