Exemplo n.º 1
0
        /// <summary>
        ///     Generates the habbo.
        /// </summary>
        /// <param name="dRow">The d row.</param>
        /// <param name="mRow">The m row.</param>
        /// <param name="group">The group.</param>
        /// <returns>Habbo.</returns>
        internal static Habbo GenerateHabbo(DataRow dRow, DataRow mRow, HashSet <GroupMember> group)
        {
            try
            {
                Dictionary <int, UserSearchLog> navilogs = new Dictionary <int, UserSearchLog>();

                #region User Basic Data

                // Positive Integers (Unsigned)
                uint id             = (uint)dRow["id"];
                uint ras            = (uint)dRow["rank"];
                uint homeRoom       = (uint)dRow["home_room"];
                uint credits        = (uint)dRow["credits"];
                uint activityPoints = (uint)dRow["activity_points"];
                uint diamonds       = (uint)dRow["diamonds"];

                // Strings
                string userName    = dRow["username"].ToString();
                string realName    = dRow["real_name"].ToString();
                string motto       = dRow["motto"].ToString();
                string look        = dRow["look"].ToString();
                string gender      = dRow["gender"].ToString();
                string citizenship = dRow["talent_status"].ToString();

                // Integers
                int lastOnline        = (int)dRow["last_online"];
                int createDate        = (int)dRow["account_created"];
                int lastChange        = (int)dRow["last_name_change"];
                int regTimestamp      = (int)dRow["account_created"];
                int tradeLockExpire   = (int)dRow["trade_lock_expire"];
                int buildersExpire    = (int)dRow["builders_expire"];
                int buildersItemsMax  = (int)dRow["builders_items_max"];
                int buildersItemsUsed = (int)dRow["builders_items_used"];
                int releaseVersion    = (int)dRow["release_version"];
                int dutyLevel         = (int)dRow["duty_level"];

                // Booleans (Enumerators/ String Enumerators)
                bool hasFriendRequestsDisabled = Yupi.EnumToBool(dRow["block_newfriends"].ToString());
                bool appearOffline             = Yupi.EnumToBool(dRow["hide_online"].ToString());
                bool hideInRoom  = Yupi.EnumToBool(dRow["hide_inroom"].ToString());
                bool muted       = Yupi.EnumToBool(dRow["is_muted"].ToString());
                bool vip         = Yupi.EnumToBool(dRow["vip"].ToString());
                bool online      = Yupi.EnumToBool(dRow["online"].ToString());
                bool tradeLocked = Yupi.EnumToBool(dRow["trade_lock"].ToString());
                bool nuxPassed   = Yupi.EnumToBool(dRow["nux_passed"].ToString());
                bool onDuty      = Yupi.EnumToBool(dRow["on_duty"].ToString());

                // Double Integers
                double lastActivityPointsUpdate = (double)dRow["activity_points_lastupdate"];

                #endregion

                #region User Status and Additional Data

                // Integers
                int respect               = (int)mRow["respect"];
                int dailyRespectPoints    = (int)mRow["daily_respect_points"];
                int dailyPetRespectPoints = (int)mRow["daily_pet_respect_points"];
                int currentQuestId        = 0; //(uint)mRow["quest_id"];
                int currentQuestProgress  = (int)mRow["quest_progress"];
                int favId = (int)mRow["favourite_group"];
                int dailyCompetitionVotes = (int)mRow["daily_competition_votes"];

                // Positive Integers (Unsigned)
                uint achievementPoints = (uint)mRow["achievement_score"];

                #endregion

                #region Navigator Logs

                // Navigator Search Logs Query String
                string navilogstring = dRow["navigator_logs"].ToString();

                // Navigator Logs Builder
                if (navilogstring.Length > 0)
                {
                    foreach (
                        UserSearchLog naviLogs in
                        navilogstring.Split(';')
                        .Where(value => navilogstring.Contains(','))
                        .Select(
                            value =>
                            new UserSearchLog(int.Parse(value.Split(',')[0]), value.Split(',')[1],
                                              value.Split(',')[2]))
                        .Where(naviLogs => !navilogs.ContainsKey(naviLogs.Id)))
                    {
                        navilogs.Add(naviLogs.Id, naviLogs);
                    }
                }

                #endregion

                #region Return Generated Data

                // Return new Generated Habbo Model
                return(new Habbo(id, userName, realName, ras, motto, look, gender, credits, activityPoints,
                                 lastActivityPointsUpdate, muted, homeRoom, respect, dailyRespectPoints, dailyPetRespectPoints,
                                 hasFriendRequestsDisabled, currentQuestId, currentQuestProgress, achievementPoints, regTimestamp,
                                 lastOnline, appearOffline, hideInRoom, vip, createDate, online, citizenship, diamonds, group, favId,
                                 lastChange, tradeLocked, tradeLockExpire, nuxPassed, buildersExpire, buildersItemsMax,
                                 buildersItemsUsed, releaseVersion, onDuty, navilogs, dailyCompetitionVotes, dutyLevel));

                #endregion
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Requests the buddy.
        /// </summary>
        /// <param name="userQuery">The user query.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        internal bool RequestBuddy(string userQuery)
        {
            GameClient clientByUsername = Yupi.GetGame().GetClientManager().GetClientByUserName(userQuery);

            uint userId;
            bool blockForNewFriends;

            if (clientByUsername == null)
            {
                DataRow dataRow;

                using (IQueryAdapter commitableQueryReactor = Yupi.GetDatabaseManager().GetQueryReactor())
                {
                    commitableQueryReactor.SetQuery("SELECT id, block_newfriends FROM users WHERE username = @query");

                    commitableQueryReactor.AddParameter("query", userQuery.ToLower());
                    dataRow = commitableQueryReactor.GetRow();
                }

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

                userId = Convert.ToUInt32(dataRow["id"]);

                blockForNewFriends = Yupi.EnumToBool(dataRow["block_newfriends"].ToString());
            }
            else
            {
                Habbo currentUser = clientByUsername.GetHabbo();

                userId = currentUser.Id;

                blockForNewFriends = currentUser.HasFriendRequestsDisabled;
            }

            GameClient client = GetClient();

            if (blockForNewFriends && client.GetHabbo().Rank < 4)
            {
                client.GetMessageHandler()
                .GetResponse()
                .Init(LibraryParser.OutgoingRequest("NotAcceptingRequestsMessageComposer"));

                client.GetMessageHandler().GetResponse().AppendInteger(39);
                client.GetMessageHandler().GetResponse().AppendInteger(3);
                client.GetMessageHandler().SendResponse();

                return(false);
            }

            if (RequestExists(userId))
            {
                client.SendNotif("Você já enviou um pedido de amizade anteriormente.");
                //@todo: Mudar Texto para sistema de langs

                return(true);
            }

            using (IQueryAdapter queryreactor2 = Yupi.GetDatabaseManager().GetQueryReactor())
                queryreactor2.RunFastQuery(string.Concat("REPLACE INTO messenger_requests (from_id,to_id) VALUES (",
                                                         _userId, ",", userId, ")"));

            Habbo fromUser = client.GetHabbo();

            if (clientByUsername?.GetHabbo() != null && fromUser != null)
            {
                MessengerRequest messengerRequest = new MessengerRequest(userId, _userId, fromUser.UserName, fromUser.Look);

                clientByUsername.GetHabbo().GetMessenger().OnNewRequest(_userId, messengerRequest);

                ServerMessage serverMessage =
                    new ServerMessage(LibraryParser.OutgoingRequest("ConsoleSendFriendRequestMessageComposer"));

                messengerRequest.Serialize(serverMessage);
                clientByUsername.SendMessage(serverMessage);
            }

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Fills the specified row.
        /// </summary>
        /// <param name="row">The row.</param>
        internal void Fill(DataRow row)
        {
            try
            {
                Id          = (uint)row["id"];
                Name        = (string)row["caption"];
                PassWord    = (string)row["password"];
                Description = (string)row["description"];
                Type        = (string)row["roomtype"];
                Owner       = string.Empty;
                OwnerId     = (uint)row["owner"];
                RoomChat    = new ConcurrentStack <Chatlog>();
                WordFilter  = new List <string>();

                using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor())
                {
                    queryReactor.SetQuery("SELECT username FROM users WHERE id = @userId");
                    queryReactor.AddParameter("userId", OwnerId);

                    Owner = queryReactor.GetString();

                    queryReactor.SetQuery($"SELECT user_id, message, timestamp FROM users_chatlogs WHERE room_id = '{Id}' ORDER BY timestamp ASC LIMIT 150");

                    DataTable table = queryReactor.GetTable();

                    if (table != null)
                    {
                        foreach (DataRow dataRow in table.Rows)
                        {
                            RoomChat.Push(new Chatlog((uint)dataRow[0], (string)dataRow[1], Yupi.UnixToDateTime(int.Parse(dataRow[2].ToString())), false));
                        }
                    }

                    queryReactor.SetQuery($"SELECT word FROM rooms_wordfilter WHERE room_id = '{Id}'");

                    DataTable tableFilter = queryReactor.GetTable();

                    if (tableFilter != null)
                    {
                        foreach (DataRow dataRow in tableFilter.Rows)
                        {
                            WordFilter.Add(dataRow["word"].ToString());
                        }
                    }
                }

                string roomState = row["state"].ToString().ToLower();

                switch (roomState)
                {
                case "locked":
                    State = 1;
                    break;

                case "password":
                    State = 2;
                    break;

                default:
                    State = 0;
                    break;
                }

                ModelName = (string)row["model_name"];
                WallPaper = (string)row["wallpaper"];
                Floor     = (string)row["floor"];
                LandScape = (string)row["landscape"];
                CcTs      = (string)row["public_ccts"];

                int.TryParse(row["trade_state"].ToString(), out TradeState);
                int.TryParse(row["category"].ToString(), out Category);
                int.TryParse(row["walls_height"].ToString(), out WallHeight);
                int.TryParse(row["score"].ToString(), out Score);
                int.TryParse(row["floorthick"].ToString(), out FloorThickness);
                int.TryParse(row["wallthick"].ToString(), out WallThickness);
                int.TryParse(row["chat_type"].ToString(), out ChatType);
                int.TryParse(row["game_id"].ToString(), out GameId);
                int.TryParse(row["mute_settings"].ToString(), out WhoCanMute);
                int.TryParse(row["kick_settings"].ToString(), out WhoCanKick);
                int.TryParse(row["ban_settings"].ToString(), out WhoCanBan);

                uint.TryParse(row["users_now"].ToString(), out UsersNow);
                uint.TryParse(row["users_max"].ToString(), out UsersMax);
                uint.TryParse(row["group_id"].ToString(), out GroupId);
                uint.TryParse(row["chat_balloon"].ToString(), out ChatBalloon);
                uint.TryParse(row["chat_speed"].ToString(), out ChatSpeed);
                uint.TryParse(row["chat_max_distance"].ToString(), out ChatMaxDistance);
                uint.TryParse(row["chat_flood_protection"].ToString(), out ChatFloodProtection);

                AllowPets        = Yupi.EnumToBool(row["allow_pets"].ToString());
                AllowPetsEating  = Yupi.EnumToBool(row["allow_pets_eat"].ToString());
                AllowWalkThrough = Yupi.EnumToBool(row["allow_walkthrough"].ToString());
                HideWall         = Yupi.EnumToBool(row["hidewall"].ToString());

                AllowRightsOverride = false;

                Group             = Yupi.GetGame().GetGroupManager().GetGroup(GroupId);
                Event             = Yupi.GetGame().GetRoomEvents().GetEvent(Id);
                _model            = Yupi.GetGame().GetRoomManager().GetModel(ModelName, Id);
                CompetitionStatus = 0;

                Tags = new List <string>();

                if (row.IsNull("tags") || string.IsNullOrEmpty(row["tags"].ToString()))
                {
                    return;
                }

                foreach (string item in row["tags"].ToString().Split(','))
                {
                    Tags.Add(item);
                }
            }
            catch (Exception ex)
            {
                YupiLogManager.LogException(ex, "Registered Room Serialization Exception.", "Yupi.Rooms");
            }
        }