Example #1
0
		internal void UnloadRoom(Room Room)
		{
			if (Room == null)
			{
				return;
			}

            if (MercuryEnvironment.GetGame().GetNavigator().PrivateCategories.Contains(Room.Category))
            {
                ((FlatCat)MercuryEnvironment.GetGame().GetNavigator().PrivateCategories[Room.Category]).removeUsers(Room.UserCount);
            }
            Room.UsersNow = 0;
            
			StringBuilder stringBuilder = new StringBuilder();
			checked
			{
				for (int i = 0; i < Room.TagCount; i++)
				{
					if (i > 0)
					{
						stringBuilder.Append(",");
					}
					stringBuilder.Append(Room.Tags[i]);
				}
				string text = "open";
				if (Room.State == 1)
				{
					text = "locked";
				}
				else
				{
					if (Room.State > 1)
					{
						text = "password";
					}
				}
				using (IQueryAdapter queryreactor = MercuryEnvironment.GetDatabaseManager().getQueryreactor())
				{
					queryreactor.setQuery(string.Concat(new object[]
					{
						"UPDATE rooms SET caption = @caption, description = @description, password = @password, category = ",
						Room.Category,
						", state = '",
						text,
						"', tags = @tags, users_now = '0', users_max = ",
						Room.UsersMax,
						", allow_pets = '",
						Room.AllowPets,
						"', allow_pets_eat = '",
						Room.AllowPetsEating,
						"', allow_walkthrough = '",
						Room.AllowWalkthrough,
						"', allow_hidewall = '",
						Room.Hidewall,
						"', floorthick = ",
						Room.FloorThickness,
						", wallthick = ",
						Room.WallThickness,
						", mute_settings='",
						Room.WhoCanMute,
						"', kick_settings='",
						Room.WhoCanKick,
						"',ban_settings='",
						Room.WhoCanBan,
						"', walls_height = '", Room.WallHeight, "', chat_type = @chat_t,chat_balloon = @chat_b,chat_speed = @chat_s,chat_max_distance = @chat_m,chat_flood_protection = @chat_f WHERE id = ",
						Room.RoomId
					}));
					queryreactor.addParameter("caption", Room.Name);
					queryreactor.addParameter("description", Room.Description);
					queryreactor.addParameter("password", Room.Password);
					queryreactor.addParameter("tags", stringBuilder.ToString());
					queryreactor.addParameter("chat_t", Room.ChatType);
					queryreactor.addParameter("chat_b", Room.ChatBalloon);
					queryreactor.addParameter("chat_s", Room.ChatSpeed);
					queryreactor.addParameter("chat_m", Room.ChatMaxDistance);
					queryreactor.addParameter("chat_f", Room.ChatFloodProtection);
					queryreactor.runQuery();
				}
				lock (this.roomsToRemoveQueue.SyncRoot)
				{
					this.roomsToRemoveQueue.Enqueue(Room.RoomId);
				}
                Logging.WriteLine("[RoomMgr] Room #[" + Room.RoomId + "] was unloaded.", ConsoleColor.DarkYellow);
				foreach (RoomUser current in Room.GetRoomUserManager().UserList.Values)
				{
					if (current.IsPet)
					{
						using (IQueryAdapter queryreactor2 = MercuryEnvironment.GetDatabaseManager().getQueryreactor())
						{
							queryreactor2.setQuery("UPDATE bots SET x=@x, y=@y, z=@z WHERE id=@id LIMIT 1;");
							queryreactor2.addParameter("x", current.X);
							queryreactor2.addParameter("y", current.Y);
							queryreactor2.addParameter("z", current.Z);
							queryreactor2.addParameter("id", current.PetData.PetId);
							queryreactor2.runQuery();
							goto IL_4AA;
						}
					}
					goto IL_38A;
					IL_4AA:
					Room.GetRoomUserManager().RemoveRoomUser(current);
					continue;
					IL_38A:
					if (current.IsBot)
					{
						using (IQueryAdapter queryreactor3 = MercuryEnvironment.GetDatabaseManager().getQueryreactor())
						{
							queryreactor3.setQuery("UPDATE bots SET x=@x, y=@y, z=@z, name=@name, motto=@motto, look=@look, rotation=@rotation, dance=@dance WHERE id=@id LIMIT 1;");
							queryreactor3.addParameter("name", current.BotData.Name);
							queryreactor3.addParameter("motto", current.BotData.Motto);
							queryreactor3.addParameter("look", current.BotData.Look);
							queryreactor3.addParameter("rotation", current.BotData.Rot);
							queryreactor3.addParameter("dance", current.BotData.DanceId);
							queryreactor3.addParameter("x", current.X);
							queryreactor3.addParameter("y", current.Y);
							queryreactor3.addParameter("z", current.Z);
							queryreactor3.addParameter("id", current.BotData.BotId);
							queryreactor3.runQuery();
						}
						goto IL_4AA;
					}
					goto IL_4AA;
				}
                lock (Room.RoomChat)
                {
                    foreach (Chatlog current2 in Room.RoomChat)
                    {
                        current2.Save(Room.RoomId);
                    }
                }
				Room.Destroy();
			}
		}
		internal void PlantMonsterplant(RoomItem Mopla, Room Room)
		{
			if (Room == null)
			{
				return;
			}
			if (Mopla == null)
			{
				return;
			}
			if (Mopla.GetBaseItem().InteractionType != InteractionType.moplaseed)
			{
				return;
			}
			int rarity = int.Parse(Mopla.ExtraData);
			int getX = Mopla.GetX;
			int getY = Mopla.GetY;
			Room.GetRoomItemHandler().RemoveFurniture(this.Session, Mopla.Id, false);
			Pet pet = Catalog.CreatePet(this.Session.GetHabbo().Id, "Monsterplant", 16, "0", "0", rarity);
			this.Response.Init(Outgoing.SendMonsterplantIdMessageComposer);
			this.Response.AppendUInt(pet.PetId);
			this.SendResponse();
			using (IQueryAdapter queryreactor = MercuryEnvironment.GetDatabaseManager().getQueryreactor())
			{
				queryreactor.runFastQuery(string.Concat(new object[]
				{
					"UPDATE bots SET room_id = '",
					Room.RoomId,
					"', x = '",
					getX,
					"', y = '",
					getY,
					"' WHERE id = '",
					pet.PetId,
					"'"
				}));
			}
			pet.PlacedInRoom = true;
			pet.RoomId = Room.RoomId;
			List<RandomSpeech> list = new List<RandomSpeech>();
			List<BotResponse> list2 = new List<BotResponse>();
			RoomBot bot = new RoomBot(pet.PetId, pet.OwnerId, pet.RoomId, AIType.Pet, "freeroam", pet.Name, "", pet.Look, getX, getY, 0.0, 4, 0, 0, 0, 0, ref list, ref list2, "", 0, false);
			Room.GetRoomUserManager().DeployBot(bot, pet);

			if (pet.DBState != DatabaseUpdateState.NeedsInsert)
			{
				pet.DBState = DatabaseUpdateState.NeedsUpdate;
			}

			using (IQueryAdapter queryreactor2 = MercuryEnvironment.GetDatabaseManager().getQueryreactor())
			{
                queryreactor2.runFastQuery("DELETE FROM items WHERE id = " + Mopla.Id);
				Room.GetRoomUserManager().SavePets(queryreactor2);
			}
		}