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() })); } }
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; }
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()); } }