Пример #1
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);
            }
        }
Пример #2
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();
        }