public void SaveFurniture(IQueryAdapter dbClient)
        {
            try
            {
                if (this.mUpdateItems.Count <= 0 && this.GetRoom.GetRoomUserManager().BotCount <= 0)
                {
                    return;
                }
                if (this.mUpdateItems.Count > 0)
                {
                    QueryChunk standardQueries = new QueryChunk();

                    foreach (Item roomItem in (IEnumerable)this.mUpdateItems.Values)
                    {
                        if (!string.IsNullOrEmpty(roomItem.ExtraData))
                        {
                            standardQueries.AddQuery(string.Concat(new object[4]
                            {
                                "UPDATE items SET extra_data = @data",
                                roomItem.Id,
                                " WHERE id = ",
                                roomItem.Id
                            }));
                            standardQueries.AddParameter("data" + roomItem.Id, roomItem.ExtraData);
                        }
                        if (roomItem.IsWallItem)
                        {
                            standardQueries.AddQuery("UPDATE items SET wall_pos = @wallpost" + roomItem.Id + " WHERE id = " + roomItem.Id);
                            standardQueries.AddParameter("wallpost" + roomItem.Id, roomItem.wallCoord);
                        }
                        else
                        {
                            standardQueries.AddQuery("UPDATE items SET x=" + roomItem.GetX + ", y=" + roomItem.GetY + ", z=" + roomItem.GetZ + ", rot=" + roomItem.Rotation + " WHERE id=" + roomItem.Id + "");
                        }
                    }

                    standardQueries.Execute(dbClient);
                    standardQueries.Dispose();

                    this.mUpdateItems.Clear();
                }
                this.GetRoom.GetRoomUserManager().AppendPetsUpdateString(dbClient);
                this.GetRoom.GetRoomUserManager().SavePositionBots(dbClient);
            }
            catch (Exception ex)
            {
                Logging.LogCriticalException(string.Concat(new object[4]
                {
                    "Error during saving furniture for room ",
                    this.GetRoom.Id,
                    ". Stack: ",
                    (ex).ToString()
                }));
            }
        }
Beispiel #2
0
        internal void RunDBUpdate()
        {
            //DateTime Start = DateTime.Now;
            try
            {
                if (mRemovedItems.Count > 0 || mAddedItems.Count > 0 || InventoryPets.Count > 0)
                {
                    QueryChunk queries = new QueryChunk();

                    if (mAddedItems.Count > 0) //This should be checked more carefully
                    {
                        foreach (UserItem Item in mAddedItems.Values)
                        {
                            queries.AddQuery("UPDATE items_users SET user_id = " + UserId + " WHERE item_id = " + Item.Id);
                            //parameters.Add("extra_data" + Item.Id, Item.ExtraData);
                            //QueryBuilder.Append("UPDATE user_items SET user_id = " + UserId + " , base_item =" + Item.BaseItem + ", extra_data = @extra_data" + Item.Id + " WHERE id = " + Item.Id + "; ");
                        }

                        mAddedItems.Clear();
                    }
                    if (mRemovedItems.Count > 0)
                    {
                        foreach (UInt32 ItemID in mRemovedItems.ToArray())
                        {
                            queries.AddQuery("DELETE FROM items_users WHERE item_id=" + ItemID + " AND user_id=" + UserId);
                        }

                        mRemovedItems.Clear();
                    }

                    foreach (Pet pet in InventoryPets.Values)
                    {
                        if (pet.DBState == DatabaseUpdateState.NeedsUpdate)
                        {
                            queries.AddParameter(pet.PetId + "name", pet.Name);
                            queries.AddParameter(pet.PetId + "race", pet.Race);
                            queries.AddParameter(pet.PetId + "color", pet.Color);
                            queries.AddQuery("UPDATE user_pets SET room_id = " + pet.RoomId + ", name = @" + pet.PetId + "name, race = @" + pet.PetId + "race, color = @" + pet.PetId + "color, type = " + pet.Type + ", expirience = " + pet.Expirience + ", " +
                                             "energy = " + pet.Energy + ", nutrition = " + pet.Nutrition + ", respect = " + pet.Respect + ", createstamp = '" + pet.CreationStamp + "', x = " + pet.X + ", Y = " + pet.Y + ", Z = " + pet.Z + " WHERE id = " + pet.PetId);
                        }
                        pet.DBState = DatabaseUpdateState.Updated;
                    }

                    using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
                    {
                        queries.Execute(dbClient);
                    }
                }
            }
            catch (Exception e)
            {
                Logging.LogCacheError("FATAL ERROR DURING USER INVENTORY DB UPDATE: " + e.ToString());
            }
        }
Beispiel #3
0
        private void PerformExecute()
        {
            var openNew = !(null != qc && qc.TransactionAlreadyBegun);

            if (openNew)
            {
                qc = new QueryChunk();
                qc.Open();
            }

            qc.AddCommand(QueryInput.Text);
            qc.Execute();
            if (openNew)
            {
                qc.Close();
            }
        }
Beispiel #4
0
        internal void AppendPetsUpdateString(IQueryAdapter dbClient)
        {
            QueryChunk inserts = new QueryChunk("INSERT INTO user_pets (id,user_id,room_id,name,type,race,color,expirience,energy,createstamp,nutrition,respect,z,y,z) VALUES ");
            QueryChunk updates = new QueryChunk();

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

            foreach (Pet pet in GetPets())
            {
                if (petsSaved.Contains(pet.PetId))
                {
                    continue;
                }

                petsSaved.Add(pet.PetId);
                if (pet.DBState == DatabaseUpdateState.NeedsInsert)
                {
                    inserts.AddParameter(pet.PetId + "name", pet.Name);
                    inserts.AddParameter(pet.PetId + "race", pet.Race);
                    inserts.AddParameter(pet.PetId + "color", pet.Color);
                    inserts.AddQuery("(" + pet.PetId + "," + pet.OwnerId + "," + pet.RoomId + ",@" + pet.PetId + "name," + pet.Type + ",@" + pet.PetId + "race,@" + pet.PetId + "color,0,100,'" + pet.CreationStamp + "',0,0,0,0,0)");
                }
                else if (pet.DBState == DatabaseUpdateState.NeedsUpdate)
                {
                    updates.AddParameter(pet.PetId + "name", pet.Name);
                    updates.AddParameter(pet.PetId + "race", pet.Race);
                    updates.AddParameter(pet.PetId + "color", pet.Color);
                    updates.AddQuery("UPDATE user_pets SET room_id = " + pet.RoomId + ", name = @" + pet.PetId + "name, race = @" + pet.PetId + "race, color = @" + pet.PetId + "color, type = " + pet.Type + ", expirience = " + pet.Expirience + ", " +
                                     "energy = " + pet.Energy + ", nutrition = " + pet.Nutrition + ", respect = " + pet.Respect + ", createstamp = '" + pet.CreationStamp + "', x = " + pet.X + ", Y = " + pet.Y + ", Z = " + pet.Z + " WHERE id = " + pet.PetId);
                }

                pet.DBState = DatabaseUpdateState.Updated;
            }

            inserts.Execute(dbClient);
            updates.Execute(dbClient);

            inserts.Dispose();
            updates.Dispose();

            inserts = null;
            updates = null;
        }
Beispiel #5
0
        internal void SaveFurniture(IQueryAdapter dbClient)
        {
            try
            {
                if (mAddedItems.Count > 0 || mRemovedItems.Count > 0 || mMovedItems.Count > 0 || room.GetRoomUserManager().PetCount > 0)
                {
                    QueryChunk standardQueries  = new QueryChunk();
                    QueryChunk itemInserts      = new QueryChunk("REPLACE INTO items_rooms (item_id,room_id,x,y,n) VALUES ");
                    QueryChunk extradataInserts = new QueryChunk("REPLACE INTO items_extradata (item_id,data_type,data) VALUES ");

                    foreach (RoomItem Item in mRemovedItems.Values)
                    {
                        standardQueries.AddQuery("DELETE FROM items_rooms WHERE item_id = " + Item.Id + " AND room_id = " + room.RoomId); //Do join + function
                    }

                    if (mAddedItems.Count > 0)
                    {
                        foreach (RoomItem Item in mAddedItems.Values)
                        {
                            //if (!string.IsNullOrEmpty((string)Item.data.GetData()))
                            {
                                extradataInserts.AddQuery("(" + Item.Id + ",@data_type_id" + Item.Id + ",@data_id" + Item.Id + ")");
                                extradataInserts.AddParameter("@data_type_id" + Item.Id, Item.data.GetTypeID());
                                extradataInserts.AddParameter("@data_id" + Item.Id, Item.data.ToString());
                            }

                            if (Item.IsFloorItem)
                            {
                                double combinedCoords = TextHandling.Combine(Item.GetX, Item.GetY);
                                itemInserts.AddQuery("(" + Item.Id + "," + Item.RoomId + "," + TextHandling.GetString(combinedCoords) + "," + TextHandling.GetString(Item.GetZ) + "," + Item.Rot + ")");
                            }
                            else
                            {
                                itemInserts.AddQuery("(" + Item.Id + "," + Item.RoomId + "," + TextHandling.GetString(Item.wallCoord.GetXValue()) + "," + TextHandling.GetString(Item.wallCoord.GetYValue()) + "," + Item.wallCoord.n() + ")");
                            }
                        }
                    }


                    foreach (RoomItem Item in mMovedItems.Values)
                    {
                        //if (!string.IsNullOrEmpty((string)Item.data.GetData()))
                        {
                            extradataInserts.AddQuery("(" + Item.Id + ",@data_type_id" + Item.Id + ",@data_id" + Item.Id + ")");
                            extradataInserts.AddParameter("@data_type_id" + Item.Id, Item.data.GetTypeID());
                            extradataInserts.AddParameter("@data_id" + Item.Id, Item.data.ToString());

                            //standardQueries.AddQuery("UPDATE items_extradata SET data = @data" + Item.Id + " WHERE item_id = " + Item.Id);
                            //standardQueries.AddParameter("data" + Item.Id, ((StringData)Item.data).Data);
                        }

                        if (Item.IsWallItem)
                        {
                            standardQueries.AddQuery("UPDATE items_rooms SET x=" + TextHandling.GetString(Item.wallCoord.GetXValue()) + ", y=" + TextHandling.GetString(Item.wallCoord.GetYValue()) + ", n=" + Item.wallCoord.n() + " WHERE item_id = " + Item.Id);
                        }
                        else
                        {
                            double combinedCoords = TextHandling.Combine(Item.GetX, Item.GetY);

                            standardQueries.AddQuery("UPDATE items_rooms SET x=" + TextHandling.GetString(combinedCoords) + ", y=" + TextHandling.GetString(Item.GetZ) + ", n=" + Item.Rot + " WHERE item_id = " + Item.Id);
                        }
                    }

                    //room.GetRoomUserManager().AppendPetsUpdateString(dbClient);

                    mAddedItems.Clear();
                    mRemovedItems.Clear();
                    mMovedItems.Clear();

                    standardQueries.Execute(dbClient);
                    itemInserts.Execute(dbClient);
                    extradataInserts.Execute(dbClient);

                    standardQueries.Dispose();
                    itemInserts.Dispose();
                    extradataInserts.Dispose();

                    standardQueries  = null;
                    itemInserts      = null;
                    extradataInserts = null;
                }
            }
            catch (Exception e)
            {
                Logging.LogCriticalException("Error during saving furniture for room " + room.RoomId + ". Stack: " + e.ToString());
            }
        }
Beispiel #6
0
 /// <summary>
 /// Runs the database update.
 /// </summary>
 internal void RunDbUpdate()
 {
     try
     {
         if (_mRemovedItems.Count <= 0 && _mAddedItems.Count <= 0 && _inventoryPets.Count <= 0)
         {
             return;
         }
         var queryChunk = new QueryChunk();
         if (_mAddedItems.Count > 0)
         {
             foreach (UserItem userItem in _mAddedItems.Values)
             {
                 queryChunk.AddQuery(string.Format("UPDATE items_rooms SET user_id='{0}', room_id='0' WHERE id='{1}'", UserId, userItem.Id));
             }
             _mAddedItems.Clear();
         }
         if (_mRemovedItems.Count > 0)
         {
             try
             {
                 foreach (UserItem userItem2 in _mRemovedItems.Values)
                 {
                     using (var queryReactor = Plus.GetDatabaseManager().GetQueryReactor())
                         GetClient()
                         .GetHabbo()
                         .CurrentRoom.GetRoomItemHandler()
                         .SaveFurniture(queryReactor);
                     if (SongDisks.Contains(userItem2.Id))
                     {
                         SongDisks.Remove(userItem2.Id);
                     }
                 }
             }
             catch (Exception)
             {
             }
             _mRemovedItems.Clear();
         }
         foreach (Pet current in _inventoryPets.Values)
         {
             if (current.DbState == DatabaseUpdateState.NeedsUpdate)
             {
                 queryChunk.AddParameter(string.Format("{0}name", current.PetId), current.Name);
                 queryChunk.AddParameter(string.Format("{0}race", current.PetId), current.Race);
                 queryChunk.AddParameter(string.Format("{0}color", current.PetId), current.Color);
                 queryChunk.AddQuery(string.Concat(new object[]
                 {
                     "UPDATE bots 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(new object[]
                 {
                     "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 = ",
                     Plus.DateTimeToUnix(current.LastHealth),
                     ", untilgrown_stamp = ",
                     Plus.DateTimeToUnix(current.UntilGrown),
                     " WHERE id = ",
                     current.PetId
                 }));
             }
             current.DbState = DatabaseUpdateState.Updated;
         }
         using (var queryreactor2 = Plus.GetDatabaseManager().GetQueryReactor())
             queryChunk.Execute(queryreactor2);
     }
     catch (Exception ex)
     {
         Logging.LogCacheError(string.Format("FATAL ERROR DURING USER INVENTORY DB UPDATE: {0}", ex));
     }
 }
Beispiel #7
0
 internal void RunDBUpdate()
 {
     try
     {
         if (this.mRemovedItems.Count > 0 || this.mAddedItems.Count > 0 || this.InventoryPets.Count > 0)
         {
             QueryChunk queryChunk = new QueryChunk();
             if (this.mAddedItems.Count > 0)
             {
                 foreach (UserItem userItem in this.mAddedItems.Values)
                 {
                     queryChunk.AddQuery(string.Concat(new object[]
                     {
                         "UPDATE items SET user_id = ",
                         this.UserId,
                         ", room_id='0' WHERE id = ",
                         userItem.Id
                     }));
                 }
                 this.mAddedItems.Clear();
             }
             if (this.mRemovedItems.Count > 0)
             {
                 try
                 {
                     foreach (UserItem userItem2 in this.mRemovedItems.Values)
                     {
                         using (IQueryAdapter queryreactor = CyberEnvironment.GetDatabaseManager().getQueryReactor())
                         {
                             this.GetClient().GetHabbo().CurrentRoom.GetRoomItemHandler().SaveFurniture(queryreactor, null);
                         }
                         if (this.discs.Contains(userItem2.Id))
                         {
                             this.discs.Remove(userItem2.Id);
                         }
                     }
                 }
                 catch (Exception)
                 {
                 }
                 this.mRemovedItems.Clear();
             }
             foreach (Pet current in this.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(new object[]
                     {
                         "UPDATE bots 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(new object[]
                     {
                         "UPDATE bots_petdata 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 = ",
                         CyberEnvironment.DateTimeToUnix(current.LastHealth),
                         ", untilgrown_stamp = ",
                         CyberEnvironment.DateTimeToUnix(current.UntilGrown),
                         " WHERE id = ",
                         current.PetId
                     }));
                 }
                 current.DBState = DatabaseUpdateState.Updated;
             }
             using (IQueryAdapter queryreactor2 = CyberEnvironment.GetDatabaseManager().getQueryReactor())
             {
                 queryChunk.Execute(queryreactor2);
             }
         }
     }
     catch (Exception ex)
     {
         Logging.LogCacheError("FATAL ERROR DURING USER INVENTORY DB UPDATE: " + ex.ToString());
     }
 }