Пример #1
0
        internal void SaveFurnitureToMSSQL(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) 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(Item.ExtraData))
                            {
                                extradataInserts.AddQuery("DELETE FROM items_extradata WHERE item_id = " + Item.Id);
                                extradataInserts.AddQuery("INSERT INTO items_extradata (item_id,data) VALUES (" + Item.Id + ",@data_id" + Item.Id + ")");
                                extradataInserts.AddParameter("@data_id" + Item.Id, Item.ExtraData);
                            }

                            itemInserts.AddQuery("DELETE FROM items_rooms WHERE item_id = " + Item.Id);

                            if (Item.IsFloorItem)
                            {
                                double combinedCoords = TextHandling.Combine(Item.GetX, Item.GetY);
                                itemInserts.AddQuery("INSERT INTO items_rooms (item_id,room_id,x,y,n) VALUES (" + Item.Id + "," + Item.RoomId + "," + TextHandling.GetString(combinedCoords) + "," + TextHandling.GetString(Item.GetZ) + "," + Item.Rot + ")");
                            }
                            else
                            {
                                itemInserts.AddQuery("INSERT INTO items_rooms (item_id,room_id,x,y,n) VALUES (" + 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(Item.ExtraData))
                        {
                            standardQueries.AddQuery("UPDATE items_extradata SET data = @data" + Item.Id + " WHERE item_id = " + Item.Id);
                            standardQueries.AddParameter("data" + Item.Id, Item.ExtraData);
                        }

                        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());
            }
        }
Пример #2
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;
        }
Пример #3
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 = PiciEnvironment.GetDatabaseManager().getQueryreactor())
                    {
                        queries.Execute(dbClient);
                    }
                }
            }
            catch (Exception e)
            {
                Logging.LogCacheError("FATAL ERROR DURING USER INVENTORY DB UPDATE: " + e.ToString());
            }
        }