/// <summary> /// Unloads the room. /// </summary> /// <param name="room">The room.</param> /// <param name="reason">The reason.</param> internal void UnloadRoom(Room room, string reason) { if (room?.RoomData == null || room.Disposed) return; room.Disposed = true; if (Yupi.GetGame().GetNavigator().PrivateCategories.Contains(room.RoomData.Category)) ((PublicCategory) Yupi.GetGame().GetNavigator().PrivateCategories[room.RoomData.Category]).UsersNow -= room.UserCount; room.RoomData.UsersNow = 0; string state = "open"; if (room.RoomData.State == 1) state = "locked"; else if (room.RoomData.State > 1) state = "password"; uint roomId = room.RoomId; using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor()) { queryReactor.SetQuery("UPDATE rooms_data SET " + "caption = @roomcaption," + "description = @description," + "password = @password," + "category = @category," + "state = @state," + "tags = @tags," + "users_now = @usersnow," + "users_max = @usersmax," + "allow_pets = @allowpets," + "allow_pets_eat = @allowpetseat," + "allow_walkthrough = @allowwalk," + "hidewall = @hidewall," + "floorthick = @floorthick," + "wallthick = @wallthick," + "mute_settings = @whocanmute," + "kick_settings = @kicksettings," + "ban_settings = @bansettings," + "walls_height = @wallheight," + "chat_type = @chat_t," + "chat_balloon = @chat_b," + "chat_speed = @chat_s," + "chat_max_distance = @chat_m," + "chat_flood_protection = @chat_f," + "trade_state = @tradestate " + "WHERE id = " + roomId); queryReactor.AddParameter("usersnow", room.RoomData.UsersNow); queryReactor.AddParameter("roomcaption", room.RoomData.Name); queryReactor.AddParameter("usersmax", room.RoomData.UsersMax); queryReactor.AddParameter("allowpets", Yupi.BoolToEnum(room.RoomData.AllowPets)); queryReactor.AddParameter("allowpetseat", Yupi.BoolToEnum(room.RoomData.AllowPetsEating)); queryReactor.AddParameter("allowwalk", Yupi.BoolToEnum(room.RoomData.AllowWalkThrough)); queryReactor.AddParameter("hidewall", Yupi.BoolToEnum(room.RoomData.HideWall)); queryReactor.AddParameter("floorthick", room.RoomData.FloorThickness); queryReactor.AddParameter("wallthick", room.RoomData.WallThickness); queryReactor.AddParameter("whocanmute", room.RoomData.WhoCanMute); queryReactor.AddParameter("kicksettings", room.RoomData.WhoCanKick); queryReactor.AddParameter("bansettings", room.RoomData.WhoCanBan); queryReactor.AddParameter("wallheight", room.RoomData.WallHeight); queryReactor.AddParameter("tradestate", room.RoomData.TradeState); queryReactor.AddParameter("category", room.RoomData.Category); queryReactor.AddParameter("state", state); queryReactor.AddParameter("description", room.RoomData.Description); queryReactor.AddParameter("password", room.RoomData.PassWord); queryReactor.AddParameter("tags", string.Join(",", room.RoomData.Tags)); queryReactor.AddParameter("chat_t", room.RoomData.ChatType); queryReactor.AddParameter("chat_b", room.RoomData.ChatBalloon); queryReactor.AddParameter("chat_s", room.RoomData.ChatSpeed); queryReactor.AddParameter("chat_m", room.RoomData.ChatMaxDistance); queryReactor.AddParameter("chat_f", room.RoomData.ChatFloodProtection); queryReactor.RunQuery(); } if (room.GetRoomUserManager() != null && room.GetRoomUserManager().UserList != null) { foreach (RoomUser current in room.GetRoomUserManager().UserList.Values.Where(current => current != null)) { if (current.IsPet) { if (current.PetData == null) continue; using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor()) { queryReactor.SetQuery("UPDATE pets_data SET x=@x, y=@y, z=@z WHERE id=@id LIMIT 1"); queryReactor.AddParameter("x", current.X); queryReactor.AddParameter("y", current.Y); queryReactor.AddParameter("z", current.Z); queryReactor.AddParameter("id", current.PetData.PetId); queryReactor.RunQuery(); } if (current.BotAi == null) continue; current.BotAi.Dispose(); } else if (current.IsBot) { if (current.BotData == null) continue; using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor()) { queryReactor.SetQuery( "UPDATE bots_data SET x=@x, y=@y, z=@z, name=@name, motto=@motto, look=@look, rotation=@rotation, dance=@dance WHERE id=@id LIMIT 1"); queryReactor.AddParameter("name", current.BotData.Name); queryReactor.AddParameter("motto", current.BotData.Motto); queryReactor.AddParameter("look", current.BotData.Look); queryReactor.AddParameter("rotation", current.BotData.Rot); queryReactor.AddParameter("dance", current.BotData.DanceId); queryReactor.AddParameter("x", current.X); queryReactor.AddParameter("y", current.Y); queryReactor.AddParameter("z", current.Z); queryReactor.AddParameter("id", current.BotData.BotId); queryReactor.RunQuery(); } current.BotAi?.Dispose(); } else { if (current.GetClient() != null) { room.GetRoomUserManager().RemoveUserFromRoom(current.GetClient(), true, false); current.GetClient().CurrentRoomUserId = -1; } } } } room.SaveRoomChatlog(); Room junkRoom; LoadedRooms.TryRemove(room.RoomId, out junkRoom); YupiWriterManager.WriteLine(string.Format("Room #{0} was unloaded, reason: " + reason, room.RoomId), "Yupi.Rooms", ConsoleColor.DarkGray); room.Destroy(); }
/// <summary> /// Unloads the room. /// </summary> /// <param name="room">The room.</param> /// <param name="reason">The reason.</param> internal void UnloadRoom(Room room, string reason) { if (room?.RoomData == null || room.Disposed) return; room.Disposed = true; if (Yupi.GetGame().GetNavigator().PrivateCategories.Contains(room.RoomData.Category)) ((PublicCategory) Yupi.GetGame().GetNavigator().PrivateCategories[room.RoomData.Category]).UsersNow -= room.UserCount; room.RoomData.UsersNow = 0; string state = "open"; if (room.RoomData.State == 1) state = "locked"; else if (room.RoomData.State > 1) state = "password"; uint roomId = room.RoomId; try { using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor()) { queryReactor.SetQuery( "UPDATE rooms_data SET caption = @caption, description = @description, password = @password, category = " + room.RoomData.Category + ", state = '" + state + "', tags = @tags, users_now = '0', users_max = " + room.RoomData.UsersMax + ", allow_pets = '" + Yupi.BoolToEnum(room.RoomData.AllowPets) + "', allow_pets_eat = '" + Yupi.BoolToEnum(room.RoomData.AllowPetsEating) + "', allow_walkthrough = '" + Yupi.BoolToEnum(room.RoomData.AllowWalkThrough) + "', hidewall = '" + Yupi.BoolToEnum(room.RoomData.HideWall) + "', floorthick = " + room.RoomData.FloorThickness + ", wallthick = " + room.RoomData.WallThickness + ", mute_settings='" + room.RoomData.WhoCanMute + "', kick_settings='" + room.RoomData.WhoCanKick + "',ban_settings='" + room.RoomData.WhoCanBan + "', walls_height = '" + room.RoomData.WallHeight + "', chat_type = @chat_t,chat_balloon = @chat_b,chat_speed = @chat_s,chat_max_distance = @chat_m,chat_flood_protection = @chat_f, trade_state = '" + room.RoomData.TradeState + "' WHERE id = " + roomId); queryReactor.AddParameter("caption", room.RoomData.Name); queryReactor.AddParameter("description", room.RoomData.Description); queryReactor.AddParameter("password", room.RoomData.PassWord); queryReactor.AddParameter("tags", string.Join(",", room.RoomData.Tags)); queryReactor.AddParameter("chat_t", room.RoomData.ChatType); queryReactor.AddParameter("chat_b", room.RoomData.ChatBalloon); queryReactor.AddParameter("chat_s", room.RoomData.ChatSpeed); queryReactor.AddParameter("chat_m", room.RoomData.ChatMaxDistance); queryReactor.AddParameter("chat_f", room.RoomData.ChatFloodProtection); queryReactor.RunQuery(); } } catch (Exception e) { ServerLogManager.LogException(e.ToString()); } if (room.GetRoomUserManager() != null && room.GetRoomUserManager().UserList != null) { using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor()) { foreach (RoomUser current in room.GetRoomUserManager().UserList.Values.Where(current => current != null)) { if (current.IsPet) { if (current.PetData == null) continue; queryReactor.SetQuery("UPDATE pets_data SET x=@x, y=@y, z=@z WHERE id=@id LIMIT 1"); queryReactor.AddParameter("x", current.X); queryReactor.AddParameter("y", current.Y); queryReactor.AddParameter("z", current.Z); queryReactor.AddParameter("id", current.PetData.PetId); queryReactor.RunQuery(); if (current.BotAi == null) continue; current.BotAi.Dispose(); } else if (current.IsBot) { if (current.BotData == null) continue; queryReactor.SetQuery("UPDATE bots_data SET x=@x, y=@y, z=@z, name=@name, motto=@motto, look=@look, rotation=@rotation, dance=@dance WHERE id=@id LIMIT 1"); queryReactor.AddParameter("name", current.BotData.Name); queryReactor.AddParameter("motto", current.BotData.Motto); queryReactor.AddParameter("look", current.BotData.Look); queryReactor.AddParameter("rotation", current.BotData.Rot); queryReactor.AddParameter("dance", current.BotData.DanceId); queryReactor.AddParameter("x", current.X); queryReactor.AddParameter("y", current.Y); queryReactor.AddParameter("z", current.Z); queryReactor.AddParameter("id", current.BotData.BotId); queryReactor.RunQuery(); current.BotAi?.Dispose(); } else { if (current.GetClient() != null) { room.GetRoomUserManager().RemoveUserFromRoom(current.GetClient(), true, false); current.GetClient().CurrentRoomUserId = -1; } } } } } room.SaveRoomChatlog(); Room junkRoom; LoadedRooms.TryRemove(room.RoomId, out junkRoom); Writer.WriteLine(string.Format("Room #{0} was unloaded, reason: " + reason, room.RoomId), "Yupi.Rooms", ConsoleColor.DarkGray); room.Destroy(); }
internal void PlantMonsterplant(RoomItem mopla, Room room) { int rarity = 0, internalRarity; if (room == null || mopla == null) return; if ((mopla.GetBaseItem().InteractionType != Interaction.Moplaseed) && (mopla.GetBaseItem().InteractionType != Interaction.RareMoplaSeed)) return; if (string.IsNullOrEmpty(mopla.ExtraData) || mopla.ExtraData == "0") rarity = 1; if (!string.IsNullOrEmpty(mopla.ExtraData) && mopla.ExtraData != "0") rarity = int.TryParse(mopla.ExtraData, out internalRarity) ? internalRarity : 1; int getX = mopla.X; int getY = mopla.Y; room.GetRoomItemHandler().RemoveFurniture(Session, mopla.Id, false); Pet pet = CatalogManager.CreatePet(Session.GetHabbo().Id, "Monsterplant", "pet_monster", "0", "0", rarity); Response.Init(LibraryParser.OutgoingRequest("SendMonsterplantIdMessageComposer")); Response.AppendInteger(pet.PetId); SendResponse(); using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor()) queryReactor.RunFastQuery(string.Concat("UPDATE pets_data SET room_id = '", room.RoomId, "', x = '", getX, "', y = '", getY, "' WHERE id = '", pet.PetId, "'")); pet.PlacedInRoom = true; pet.RoomId = room.RoomId; RoomBot bot = new RoomBot(pet.PetId, pet.OwnerId, pet.RoomId, AiType.Pet, "freeroam", pet.Name, "", pet.Look, getX, getY, 0.0, 4, null, null, "", 0, ""); room.GetRoomUserManager().DeployBot(bot, pet); if (pet.DbState != DatabaseUpdateState.NeedsInsert) pet.DbState = DatabaseUpdateState.NeedsUpdate; using (IQueryAdapter queryreactor2 = Yupi.GetDatabaseManager().GetQueryReactor()) { queryreactor2.RunFastQuery($"DELETE FROM items_rooms WHERE id = {mopla.Id}"); room.GetRoomUserManager().SavePets(queryreactor2); } }