Пример #1
0
        /// <summary>
        ///     Saves the specified room identifier.
        /// </summary>
        /// <param name="databaseQueryChunk"></param>
        /// <param name="id">Auto increment</param>
        internal void Save(DatabaseQueryChunk databaseQueryChunk, uint id)
        {
            if (IsSaved)
                return;

            databaseQueryChunk.AddQuery("INSERT INTO users_chatlogs (user_id, room_id, timestamp, message) VALUES (@user" + id + ", @room, @time" + id + ", @message" + id + ")");
            databaseQueryChunk.AddParameter("user" + id, UserId);
            databaseQueryChunk.AddParameter("time" + id, Yupi.DateTimeToUnix(TimeStamp));
            databaseQueryChunk.AddParameter("message" + id, Message);
        }
Пример #2
0
        /// <summary>
        ///     Saves the furniture.
        /// </summary>
        /// <param name="dbClient">The database client.</param>
        /// <param name="session">The session.</param>
        public void SaveFurniture(IQueryAdapter dbClient, GameClient session = null)
        {
            try
            {
                if (!_updatedItems.Any() && !_removedItems.Any() &&
                    _room.GetRoomUserManager().PetCount <= 0)
                    return;

                DatabaseQueryChunk queryChunk = new DatabaseQueryChunk();
                DatabaseQueryChunk queryChunk2 = new DatabaseQueryChunk();

                foreach (uint itemId in _removedItems)
                {
                    queryChunk.AddQuery("UPDATE items_rooms SET room_id='0', x='0', y='0', z='0', rot='0' WHERE id = " +
                                        itemId);
                }

                foreach (RoomItem roomItem in _updatedItems.Select(GetItem).Where(roomItem => roomItem != null))
                {
                    if (roomItem.GetBaseItem() != null && roomItem.GetBaseItem().IsGroupItem)
                    {
                        try
                        {
                            string[] gD = roomItem.GroupData.Split(';');
                            roomItem.ExtraData = roomItem.ExtraData + ";" + gD[1] + ";" +
                                                 gD[2] + ";" + gD[3];
                        }
                        catch
                        {
                            roomItem.ExtraData = string.Empty;
                        }
                    }

                    if (roomItem.RoomId == 0) continue;

                    if (roomItem.GetBaseItem().Name.Contains("wallpaper_single") ||
                        roomItem.GetBaseItem().Name.Contains("floor_single") ||
                        roomItem.GetBaseItem().Name.Contains("landscape_single"))
                    {
                        queryChunk.AddQuery("DELETE FROM items_rooms WHERE id = " + roomItem.Id + " LIMIT 1");
                        continue;
                    }

                    string query = "UPDATE items_rooms SET room_id = " + roomItem.RoomId;
                    if (!string.IsNullOrEmpty(roomItem.ExtraData))
                    {
                        query += ", extra_data = @extraData" + roomItem.Id;
                        queryChunk2.AddParameter("extraData" + roomItem.Id, roomItem.ExtraData);
                    }

                    if (roomItem.IsFloorItem)
                    {
                        query +=
                            $", x={roomItem.X}, y={roomItem.Y}, z='{roomItem.Z.ToString(CultureInfo.InvariantCulture).Replace(',', '.')}', rot={roomItem.Rot}";
                    }
                    else
                    {
                        query += ", wall_pos = @wallPos" + roomItem.Id;
                        queryChunk2.AddParameter("wallPos" + roomItem.Id, roomItem.WallCoord);
                    }

                    query += " WHERE id = " + roomItem.Id;
                    queryChunk2.AddQuery(query);
                }

                _room.GetRoomUserManager().AppendPetsUpdateString(dbClient);

                if (session != null) session.GetHabbo().GetInventoryComponent().RunDbUpdate();

                _updatedItems.Clear();
                _removedItems.Clear();
                queryChunk.Execute(dbClient);
                queryChunk2.Execute(dbClient);
                queryChunk.Dispose();
                queryChunk2.Dispose();
                queryChunk = null;
                queryChunk2 = null;
            }
            catch (Exception ex)
            {
                ServerLogManager.LogCriticalException("Error during saving furniture for room " + _room.RoomId + ". Stack: " + ex);
            }
        }
Пример #3
0
        /// <summary>
        ///     Appends the pets update string.
        /// </summary>
        /// <param name="dbClient">The database client.</param>
        internal void AppendPetsUpdateString(IQueryAdapter dbClient)
        {
            DatabaseQueryChunk queryChunk = new DatabaseQueryChunk("INSERT INTO bots_data (id,user_id,room_id,name,x,y,z) VALUES ");
            DatabaseQueryChunk queryChunk2 = new DatabaseQueryChunk("INSERT INTO pets_data (type,race,color,experience,energy,createstamp,nutrition,respect) VALUES ");

            DatabaseQueryChunk queryChunk3 = new DatabaseQueryChunk();

            List<uint> list = new List<uint>();

            foreach (Pet current in GetPets().Where(current => !list.Contains(current.PetId)))
            {
                list.Add(current.PetId);
                switch (current.DbState)
                {
                    case DatabaseUpdateState.NeedsInsert:
                        queryChunk.AddParameter($"{current.PetId}name", current.Name);
                        queryChunk2.AddParameter($"{current.PetId}race", current.Race);
                        queryChunk2.AddParameter($"{current.PetId}color", current.Color);
                        queryChunk.AddQuery(string.Concat("(", current.PetId, ",", current.OwnerId, ",", current.RoomId,
                            ",@", current.PetId, "name,", current.X, ",", current.Y, ",", current.Z, ")"));
                        queryChunk2.AddQuery(string.Concat("(", current.Type, ",@", current.PetId, "race,@",
                            current.PetId, "color,0,100,'", current.CreationStamp, "',0,0)"));
                        break;

                    case DatabaseUpdateState.NeedsUpdate:
                        queryChunk3.AddParameter($"{current.PetId}name", current.Name);
                        queryChunk3.AddParameter($"{current.PetId}race", current.Race);
                        queryChunk3.AddParameter($"{current.PetId}color", current.Color);
                        queryChunk3.AddQuery(string.Concat("UPDATE bots_data SET room_id = ", current.RoomId, ", name = @",
                            current.PetId, "name, x = ", current.X, ", Y = ", current.Y, ", Z = ", current.Z,
                            " WHERE id = ", current.PetId));
                        queryChunk3.AddQuery(string.Concat("UPDATE pets_data SET race = @", current.PetId,
                            "race, color = @", current.PetId, "color, type = ", current.Type, ", experience = ",
                            current.Experience, ", energy = ", current.Energy, ", nutrition = ", current.Nutrition,
                            ", respect = ", current.Respect, ", createstamp = '", current.CreationStamp, "' WHERE id = ",
                            current.PetId));
                        break;
                }
                current.DbState = DatabaseUpdateState.Updated;
            }
            queryChunk.Execute(dbClient);
            queryChunk3.Execute(dbClient);
            queryChunk.Dispose();
            queryChunk3.Dispose();
        }
Пример #4
0
        /// <summary>
        ///     Runs the database update.
        /// </summary>
        internal void RunDbUpdate()
        {
            try
            {
                if (_mRemovedItems.Count <= 0 && _mAddedItems.Count <= 0 && _inventoryPets.Count <= 0)
                    return;

                DatabaseQueryChunk queryChunk = new DatabaseQueryChunk();

                if (_mAddedItems.Count > 0)
                {
                    foreach (UserItem userItem in _mAddedItems.Values)
                        queryChunk.AddQuery($"UPDATE items_rooms SET user_id='{UserId}', room_id='0' WHERE id='{userItem.Id}'");

                    _mAddedItems.Clear();
                }

                if (_mRemovedItems.Count > 0)
                {
                    try
                    {
                        foreach (UserItem userItem2 in _mRemovedItems.Values)
                        {
                            using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor())
                                GetClient().GetHabbo().CurrentRoom.GetRoomItemHandler().SaveFurniture(queryReactor);

                            if (SongDisks.Contains(userItem2.Id))
                                SongDisks.Remove(userItem2.Id);
                        }
                    }
                    catch
                    {
                        // ignored
                    }

                    _mRemovedItems.Clear();
                }

                foreach (Pet current in _inventoryPets.Values)
                {
                    if (current.DbState == DatabaseUpdateState.NeedsUpdate)
                    {
                        queryChunk.AddParameter($"{current.PetId}name", current.Name);
                        queryChunk.AddParameter($"{current.PetId}race", current.Race);
                        queryChunk.AddParameter($"{current.PetId}color", current.Color);

                        queryChunk.AddQuery(string.Concat("UPDATE bots_data SET room_id = ", current.RoomId, ", name = @", current.PetId, "name, x = ", current.X, ", Y = ", current.Y, ", Z = ", current.Z, " WHERE id = ", current.PetId));

                        queryChunk.AddQuery(string.Concat("UPDATE pets_data SET race = @", current.PetId, "race, color = @", current.PetId, "color, type = ", current.Type, ", experience = ", current.Experience, ", energy = ", current.Energy, ", nutrition = ", current.Nutrition, ", respect = ", current.Respect, ", createstamp = '", current.CreationStamp, "', lasthealth_stamp = ", Yupi.DateTimeToUnix(current.LastHealth), ", untilgrown_stamp = ", Yupi.DateTimeToUnix(current.UntilGrown), " WHERE id = ", current.PetId));
                    }

                    current.DbState = DatabaseUpdateState.Updated;
                }

                using (IQueryAdapter queryreactor2 = Yupi.GetDatabaseManager().GetQueryReactor())
                    queryChunk.Execute(queryreactor2);
            }
            catch (Exception ex)
            {
                ServerLogManager.LogCacheError($"FATAL ERROR DURING USER INVENTORY DB UPDATE: {ex}");
            }
        }
Пример #5
0
        /// <summary>
        ///     Runs the database update.
        /// </summary>
        internal void RunDbUpdate()
        {
            try
            {
                if (_mRemovedItems.Count <= 0 && _mAddedItems.Count <= 0 && _inventoryPets.Count <= 0)
                    return;

                DatabaseQueryChunk queryChunk = new DatabaseQueryChunk();

                if (_mAddedItems.Count > 0)
                {
                    foreach (UserItem userItem in _mAddedItems.Values)
                        queryChunk.AddQuery($"UPDATE items_rooms SET user_id='{UserId}', room_id='0' WHERE id='{userItem.Id}'");

                    _mAddedItems.Clear();
                }

                if (_mRemovedItems.Count > 0)
                {
                    try
                    {
                        foreach (UserItem userItem2 in _mRemovedItems.Values)
                        {
                            using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor())
                                GetClient().GetHabbo().CurrentRoom.GetRoomItemHandler().SaveFurniture(queryReactor);

                            if (SongDisks.Contains(userItem2.Id))
                                SongDisks.Remove(userItem2.Id);
                        }
                    }
                    catch
                    {
                        // ignored
                    }

                    _mRemovedItems.Clear();
                }

                foreach (Pet current in _inventoryPets.Values)
                {
                    if (current.DbState == DatabaseUpdateState.NeedsUpdate)
                    {
                        using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor())
                        {
                            queryReactor.SetQuery("UPDATE pets_data SET " +
                                                  $"room_id = {current.RoomId}, name = @petName, x = {current.X}, y = {current.Y}, " +
                                                  $"z = {current.Z}, race_id = @petRace, pet_type = @petType', experience = {current.Experience}, " +
                                                  $"energy = {current.Energy}, nutrition = {current.Nutrition}, respect = {current.Respect}, " +
                                                  $"createstamp = '{current.CreationStamp}', lasthealth_stamp = '{Yupi.DateTimeToUnix(current.LastHealth)}', untilgrown_stamp = '{Yupi.DateTimeToUnix(current.UntilGrown)}', " +
                                                  $"color = @petColor WHERE id = {current.PetId}");

                            queryReactor.AddParameter("petName", current.Name);
                            queryReactor.AddParameter("petRace", current.Race);
                            queryReactor.AddParameter("petType", current.Type);
                            queryReactor.AddParameter("petColor", current.Color);

                            queryReactor.RunQuery();
                        }
                    }

                    current.DbState = DatabaseUpdateState.Updated;
                }
            }
            catch (Exception ex)
            {
                ServerLogManager.LogCacheError($"FATAL ERROR DURING USER INVENTORY DB UPDATE: {ex}");
            }
        }