public RoomData CreateRoom(GameClient Session, string Name, string Description, string Model, int Category, int MaxVisitors, int TradeSettings) { if (!_roomModels.ContainsKey(Model)) { Session.SendNotification(LanguageLocale.Get(Session, "invalid_room_model")); return(null); } if (Name.Length < 3) { Session.SendNotification(LanguageLocale.Get(Session, "invalid_room_name_length")); return(null); } int RoomId = 0; using (IQueryAdapter dbClient = QuasarEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("INSERT INTO `rooms` (`roomtype`,`caption`,`description`,`owner`,`model_name`,`category`,`users_max`,`trade_settings`) VALUES ('private',@caption,@description,@UserId,@model,@category,@usersmax,@tradesettings)"); dbClient.AddParameter("caption", Name); dbClient.AddParameter("description", Description); dbClient.AddParameter("UserId", Session.GetHabbo().Id); dbClient.AddParameter("model", Model); dbClient.AddParameter("category", Category); dbClient.AddParameter("usersmax", MaxVisitors); dbClient.AddParameter("tradesettings", TradeSettings); RoomId = Convert.ToInt32(dbClient.InsertQuery()); } RoomData newRoomData = GenerateRoomData(RoomId); Session.GetHabbo().UsersRooms.Add(newRoomData); return(newRoomData); }
public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet) { if (Session == null || Session.GetHabbo() == null || !Session.GetHabbo().GetPermissions().HasRight("mod_kick")) { return; } int UserId = Packet.PopInt(); string Message = Packet.PopString(); GameClient Client = QuasarEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId); if (Client == null || Client.GetHabbo() == null || Client.GetHabbo().CurrentRoomId < 1 || Client.GetHabbo().Id == Session.GetHabbo().Id) { return; } if (Client.GetHabbo().Rank >= Session.GetHabbo().Rank) { Session.SendNotification(LanguageLocale.Get(Session, "no_kick_permission")); return; } Room Room = null; if (!QuasarEnvironment.GetGame().GetRoomManager().TryGetRoom(Session.GetHabbo().CurrentRoomId, out Room)) { return; } Room.GetRoomUserManager().RemoveUserFromRoom(Client, true, false); }
public bool SetWallItem(GameClient Session, Item Item) { if (!Item.IsWallItem || _wallItems.ContainsKey(Item.Id)) { return(false); } if (_floorItems.ContainsKey(Item.Id)) { Session.SendNotification(LanguageLocale.Get(Session, "room_item_placed")); return(true); } Item.Interactor.OnPlace(Session, Item); if (Item.GetBaseItem().InteractionType == InteractionType.MOODLIGHT) { if (_room.MoodlightData != null) { _room.MoodlightData = new MoodlightData(Item.Id); Item.ExtraData = _room.MoodlightData.GenerateExtraData(); } } using (IQueryAdapter dbClient = QuasarEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("UPDATE `items` SET `room_id` = '" + _room.RoomId + "', `x` = '" + Item.GetX + "', `y` = '" + Item.GetY + "', `z` = '" + Item.GetZ + "', `rot` = '" + Item.Rotation + "', `wall_pos` = @WallPos WHERE `id` = '" + Item.Id + "' LIMIT 1"); dbClient.AddParameter("WallPos", Item.wallCoord); dbClient.RunQuery(); } _wallItems.TryAdd(Item.Id, Item); _room.SendMessage(new ItemAddComposer(Item)); return(true); }
public void DeliverItems() { // List items List <Item> ItemsOne = GetTradeUser(oneId).OfferedItems; List <Item> ItemsTwo = GetTradeUser(twoId).OfferedItems; string User1 = ""; string User2 = ""; // Verify they are still in user inventory foreach (Item I in ItemsOne.ToList()) { if (I == null) { continue; } if (GetTradeUser(oneId).GetClient().GetHabbo().GetInventoryComponent().GetItem(I.Id) == null) { GetTradeUser(oneId).GetClient().SendNotification(LanguageLocale.Get(GetTradeUser(oneId).GetClient(), "trade_failed")); GetTradeUser(twoId).GetClient().SendNotification(LanguageLocale.Get(GetTradeUser(twoId).GetClient(), "trade_failed")); return; } User1 += I.Id + ";"; } foreach (Item I in ItemsTwo.ToList()) { if (I == null) { continue; } if (GetTradeUser(twoId).GetClient().GetHabbo().GetInventoryComponent().GetItem(I.Id) == null) { GetTradeUser(oneId).GetClient().SendNotification(LanguageLocale.Get(GetTradeUser(oneId).GetClient(), "trade_failed")); GetTradeUser(twoId).GetClient().SendNotification(LanguageLocale.Get(GetTradeUser(twoId).GetClient(), "trade_failed")); return; } User2 += I.Id + ";"; } // Deliver them using (IQueryAdapter dbClient = QuasarEnvironment.GetDatabaseManager().GetQueryReactor()) { foreach (Item I in ItemsOne.ToList()) { if (I == null) { continue; } GetTradeUser(oneId).GetClient().GetHabbo().GetInventoryComponent().RemoveItem(I.Id); dbClient.SetQuery("UPDATE `items` SET `user_id` = @user WHERE `id` = @id LIMIT 1"); dbClient.AddParameter("user", twoId); dbClient.AddParameter("id", I.Id); dbClient.RunQuery(); GetTradeUser(twoId).GetClient().GetHabbo().GetInventoryComponent().AddNewItem(I.Id, I.BaseItem, I.ExtraData, I.GroupId, false, false, I.LimitedNo, I.LimitedTot); } foreach (Item I in ItemsTwo.ToList()) { if (I == null) { continue; } GetTradeUser(twoId).GetClient().GetHabbo().GetInventoryComponent().RemoveItem(I.Id); dbClient.SetQuery("UPDATE `items` SET `user_id` = @user WHERE `id` = @id LIMIT 1"); dbClient.AddParameter("user", oneId); dbClient.AddParameter("id", I.Id); dbClient.RunQuery(); GetTradeUser(oneId).GetClient().GetHabbo().GetInventoryComponent().AddNewItem(I.Id, I.BaseItem, I.ExtraData, I.GroupId, false, false, I.LimitedNo, I.LimitedTot); } } using (IQueryAdapter dbClient = QuasarEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("INSERT INTO `logs_client_trade` VALUES(null, @1id, @2id, @1items, @2items, UNIX_TIMESTAMP())"); dbClient.AddParameter("1id", oneId); dbClient.AddParameter("2id", twoId); dbClient.AddParameter("1items", User1); dbClient.AddParameter("2items", User2); dbClient.RunQuery(); } // Update inventories GetTradeUser(oneId).GetClient().GetHabbo().GetInventoryComponent().UpdateItems(false); GetTradeUser(twoId).GetClient().GetHabbo().GetInventoryComponent().UpdateItems(false); }
public bool SetFloorItem(GameClient Session, Item Item, int newX, int newY, int newRot, bool newItem, bool OnRoller, bool sendMessage, bool updateRoomUserStatuses = false) { bool NeedsReAdd = false; if (newItem) { if (Item.IsWired) { if (Item.GetBaseItem().WiredType == WiredBoxType.EffectRegenerateMaps && _room.GetRoomItemHandler().GetFloor.Where(x => x.GetBaseItem().WiredType == WiredBoxType.EffectRegenerateMaps).Count() > 0) { return(false); } } } List <Item> ItemsOnTile = GetFurniObjects(newX, newY); if (Item.GetBaseItem().InteractionType == InteractionType.ROLLER && ItemsOnTile.Where(x => x.GetBaseItem().InteractionType == InteractionType.ROLLER && x.Id != Item.Id).Count() > 0) { return(false); } if (!newItem) { NeedsReAdd = _room.GetGameMap().RemoveFromMap(Item); } Dictionary <int, ThreeDCoord> AffectedTiles = Gamemap.GetAffectedTiles(Item.GetBaseItem().Length, Item.GetBaseItem().Width, newX, newY, newRot); if (!_room.GetGameMap().ValidTile(newX, newY) || _room.GetGameMap().SquareHasUsers(newX, newY) && !Item.GetBaseItem().IsSeat) { if (NeedsReAdd) { _room.GetGameMap().AddToMap(Item); } return(false); } foreach (ThreeDCoord Tile in AffectedTiles.Values) { if (!_room.GetGameMap().ValidTile(Tile.X, Tile.Y) || (_room.GetGameMap().SquareHasUsers(Tile.X, Tile.Y) && !Item.GetBaseItem().IsSeat)) { if (NeedsReAdd) { _room.GetGameMap().AddToMap(Item); } return(false); } } // Start calculating new Z coordinate Double newZ = _room.GetGameMap().Model.SqFloorHeight[newX, newY]; if (!OnRoller) { // Make sure this tile is open and there are no users here if (_room.GetGameMap().Model.SqState[newX, newY] != SquareState.OPEN && !Item.GetBaseItem().IsSeat) { return(false); } foreach (var Tile in AffectedTiles.Values) { if (_room.GetGameMap().Model.SqState[Tile.X, Tile.Y] != SquareState.OPEN && !Item.GetBaseItem().IsSeat) { if (NeedsReAdd) { //AddItem(Item); _room.GetGameMap().AddToMap(Item); } return(false); } } // And that we have no users if (!Item.GetBaseItem().IsSeat&& !Item.IsRoller) { foreach (var Tile in AffectedTiles.Values) { if (_room.GetGameMap().GetRoomUsers(new Point(Tile.X, Tile.Y)).Count > 0) { if (NeedsReAdd) { _room.GetGameMap().AddToMap(Item); } return(false); } } } } // Find affected objects var ItemsAffected = new List <Item>(); var ItemsComplete = new List <Item>(); foreach (var Tile in AffectedTiles.Values.ToList()) { var Temp = GetFurniObjects(Tile.X, Tile.Y); if (Temp != null) { ItemsAffected.AddRange(Temp); } } ItemsComplete.AddRange(ItemsOnTile); ItemsComplete.AddRange(ItemsAffected); RoomUser User = null; if (Session?.GetHabbo() == null || (User = this._room?.GetRoomUserManager()?.GetRoomUserByHabbo(Session.GetHabbo().Id)) == null) { //no logic needed... } if (Item.GetBaseItem().InteractionType == InteractionType.STACKTOOL) { newZ = Item.GetZ; } else if (User?.BuildHeight != null) { newZ = (double)User.BuildHeight; } else { // Are there any higher objects in the stack!? foreach (var item in from item in ItemsComplete.ToList() where item != null where item.Id != Item.Id select item) { if (item.GetBaseItem().InteractionType == InteractionType.STACKTOOL) { newZ = item.GetZ; break; } if (!item.GetBaseItem().Stackable) { if (NeedsReAdd) { _room.GetGameMap().AddToMap(Item); } return(false); } var itemZ = item.GetZ + item.GetBaseItem().Height; if (itemZ > newZ) { newZ = itemZ; } } } // Verify the rotation is correct if (newRot != 0 && newRot != 2 && newRot != 4 && newRot != 6 && newRot != 8 && !Item.GetBaseItem().ExtraRot) { newRot = 0; } Item.Rotation = newRot; int oldX = Item.GetX; int oldY = Item.GetY; Item.SetState(newX, newY, newZ, AffectedTiles); if (!OnRoller && Session != null) { Item.Interactor.OnPlace(Session, Item); } if (newItem) { if (_floorItems.ContainsKey(Item.Id)) { if (Session != null) { Session.SendNotification(LanguageLocale.Get(Session, "room_item_placed")); } _room.GetGameMap().RemoveFromMap(Item); return(true); } if (Item.IsFloorItem && !_floorItems.ContainsKey(Item.Id)) { _floorItems.TryAdd(Item.Id, Item); } else if (Item.IsWallItem && !_wallItems.ContainsKey(Item.Id)) { _wallItems.TryAdd(Item.Id, Item); } if (sendMessage) { _room.SendMessage(new ObjectAddComposer(Item, _room)); } } else { UpdateItem(Item); if (!OnRoller && sendMessage) { _room.SendMessage(new ObjectUpdateComposer(Item, _room.OwnerId)); } } _room.GetGameMap().AddToMap(Item); if (Item.GetBaseItem().IsSeat) { updateRoomUserStatuses = true; } if (updateRoomUserStatuses) { _room.GetRoomUserManager().UpdateUserStatusses(); } if (Item.GetBaseItem().InteractionType == InteractionType.TENT || Item.GetBaseItem().InteractionType == InteractionType.TENT_SMALL) { _room.RemoveTent(Item.Id, Item); _room.AddTent(Item.Id); } using (IQueryAdapter dbClient = QuasarEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.RunQuery("UPDATE `items` SET `room_id` = '" + _room.RoomId + "', `x` = '" + Item.GetX + "', `y` = '" + Item.GetY + "', `z` = '" + Item.GetZ + "', `rot` = '" + Item.Rotation + "' WHERE `id` = '" + Item.Id + "' LIMIT 1"); } return(true); }