예제 #1
0
		public void SaveFurniture(IQueryAdapter dbClient, GameClient Session = null)
		{
			try
			{
				if (this.mAddedItems.Count > 0 || this.mRemovedItems.Count > 0 || this.mMovedItems.Count > 0 || this.room.GetRoomUserManager().PetCount > 0)
				{
					QueryChunk queryChunk = new QueryChunk();
					QueryChunk queryChunk2 = new QueryChunk();
					QueryChunk queryChunk3 = new QueryChunk();
					foreach (RoomItem roomItem in this.mRemovedItems.Values)
					{
						queryChunk.AddQuery("UPDATE items SET room_id='0', x='0', y='0', z='0', rot='0' WHERE id = " + roomItem.Id + " ");
					}
					if (this.mAddedItems.Count > 0)
					{
						foreach (RoomItem roomItem2 in this.mAddedItems.Values)
						{
							if (!string.IsNullOrEmpty(roomItem2.ExtraData))
							{
								queryChunk3.AddQuery(string.Concat(new object[]
								{
									"UPDATE items SET extra_data=@edata",
									roomItem2.Id,
									" WHERE id='",
									roomItem2.Id,
									"'"
								}));
								queryChunk3.AddParameter("edata" + roomItem2.Id, roomItem2.ExtraData);
							}
							if (roomItem2.IsFloorItem)
							{
								queryChunk2.AddQuery(string.Concat(new object[]
								{
									"UPDATE items SET room_id=",
									roomItem2.RoomId,
									", x=",
									roomItem2.GetX,
									", y=",
									roomItem2.GetY,
									", z=",
									roomItem2.GetZ,
									", rot=",
									roomItem2.Rot,
									" WHERE id='",
									roomItem2.Id,
									"'"
								}));
							}
							else
							{
								queryChunk2.AddQuery(string.Concat(new object[]
								{
									"UPDATE items SET room_id='",
									roomItem2.RoomId,
									"',wall_pos='",
									roomItem2.wallCoord,
									"' WHERE id='",
									roomItem2.Id,
									"'"
								}));
							}
						}
					}
					foreach (RoomItem roomItem3 in this.mMovedItems.Values)
					{
						if (!string.IsNullOrEmpty(roomItem3.ExtraData))
						{
							queryChunk.AddQuery(string.Concat(new object[]
							{
								"UPDATE items SET extra_data = @EData",
								roomItem3.Id,
								" WHERE id='",
								roomItem3.Id,
								"'"
							}));
							queryChunk.AddParameter("EData" + roomItem3.Id, roomItem3.ExtraData);
						}
						if (roomItem3.IsWallItem && (!roomItem3.GetBaseItem().Name.Contains("wallpaper_single") || !roomItem3.GetBaseItem().Name.Contains("floor_single") || !roomItem3.GetBaseItem().Name.Contains("landscape_single")))
						{
							queryChunk.AddQuery(string.Concat(new object[]
							{
								"UPDATE items SET wall_pos='",
								roomItem3.wallCoord,
								"' WHERE id=",
								roomItem3.Id
							}));
						}
						else
						{
							if (roomItem3.GetBaseItem().Name.Contains("wallpaper_single") || roomItem3.GetBaseItem().Name.Contains("floor_single") || roomItem3.GetBaseItem().Name.Contains("landscape_single"))
							{
								queryChunk.AddQuery("DELETE FROM items WHERE id=" + roomItem3.Id + " LIMIT 1");
							}
							else
							{
								queryChunk.AddQuery(string.Concat(new object[]
								{
									"UPDATE items SET x=",
									roomItem3.GetX,
									", y=",
									roomItem3.GetY,
									", z=",
									roomItem3.GetZ,
									", rot=",
									roomItem3.Rot,
									" WHERE id=",
									roomItem3.Id
								}));
							}
						}
					}
					this.room.GetRoomUserManager().AppendPetsUpdateString(dbClient);
					if (Session != null)
					{
						Session.GetHabbo().GetInventoryComponent().RunDBUpdate();
					}
					this.mAddedItems.Clear();
					this.mRemovedItems.Clear();
					this.mMovedItems.Clear();
					queryChunk.Execute(dbClient);
					queryChunk2.Execute(dbClient);
					queryChunk3.Execute(dbClient);
					queryChunk.Dispose();
					queryChunk2.Dispose();
					queryChunk3.Dispose();
					queryChunk = null;
					queryChunk2 = null;
					queryChunk3 = null;
				}
			}
			catch (Exception ex)
			{
				Logging.LogCriticalException(string.Concat(new object[]
				{
					"Error during saving furniture for room ",
					this.room.RoomId,
					". Stack: ",
					ex.ToString()
				}));
			}
		}
예제 #2
0
        internal void AppendPetsUpdateString(IQueryAdapter dbClient)
        {
            QueryChunk queryChunk = new QueryChunk("INSERT INTO bots (id,user_id,room_id,name,x,y,z) VALUES ");
            QueryChunk queryChunk2 = new QueryChunk("INSERT INTO bots_petdata (type,race,color,experience,energy,createstamp,nutrition,respect) VALUES ");
            QueryChunk queryChunk3 = new QueryChunk();
            List<uint> list = new List<uint>();
            foreach (Pet current in this.GetPets())
            {
                if (!list.Contains(current.PetId))
                {
                    list.Add(current.PetId);
                    if (current.DBState == 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(new object[]
						{
							"(",
							current.PetId,
							",",
							current.OwnerId,
							",",
							current.RoomId,
							",@",
							current.PetId,
							"name,", current.X, ",", current.Y, ",", current.Z, ")"
						}));
                        queryChunk2.AddQuery(string.Concat(new object[]
						{
							"(",
							current.Type,
							",@",
							current.PetId,
							"race,@",
							current.PetId,
							"color,0,100,'",
							current.CreationStamp,
							"',0,0)"
						}));
                    }
                    else
                    {
                        if (current.DBState == 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(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
							}));
                            queryChunk3.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,
								"' WHERE id = ",
								current.PetId
							}));
                        }
                    }
                    current.DBState = DatabaseUpdateState.Updated;
                }
            }
            queryChunk.Execute(dbClient);
            queryChunk3.Execute(dbClient);
            queryChunk.Dispose();
            queryChunk3.Dispose();
            queryChunk = null;
            queryChunk3 = null;
        }
예제 #3
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 = MercuryEnvironment.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 = ",
								MercuryEnvironment.DateTimeToUnix(current.LastHealth),
								", untilgrown_stamp = ",
								MercuryEnvironment.DateTimeToUnix(current.UntilGrown),
								" WHERE id = ",
								current.PetId
							}));
						}
						current.DBState = DatabaseUpdateState.Updated;
					}
					using (IQueryAdapter queryreactor2 = MercuryEnvironment.GetDatabaseManager().getQueryreactor())
					{
						queryChunk.Execute(queryreactor2);
					}
				}
			}
			catch (Exception ex)
			{
				Logging.LogCacheError("FATAL ERROR DURING USER INVENTORY DB UPDATE: " + ex.ToString());
			}
		}