public void Parse(GameClient session, ClientPacket packet) { int userId = packet.PopInt(); if (session == null || session.Habbo == null || !session.Habbo.InRoom) { return; } Room room = session.Habbo.CurrentRoom; if (room == null) { return; } RoomUser roomUser = room.GetRoomUserManager().GetRoomUserByHabbo(session.Habbo.Id); if (roomUser == null) { return; } RoomUser targetUser = room.GetRoomUserManager().GetRoomUserByVirtualId(userId); if (targetUser == null) { return; } if (session.Habbo.TradingLockExpiry > 0) { if (session.Habbo.TradingLockExpiry > PlusEnvironment.GetUnixTimestamp()) { session.SendNotification("You're currently banned from trading."); return; } session.Habbo.TradingLockExpiry = 0; session.SendNotification("Your trading ban has now expired."); using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.RunQuery("UPDATE `user_info` SET `trading_locked` = '0' WHERE `id` = '" + session.Habbo.Id + "' LIMIT 1"); } } if (!session.Habbo.GetPermissions().HasRight("room_trade_override")) { if (room.TradeSettings == 0) { session.SendPacket(new TradingErrorComposer(6, targetUser.GetUsername())); return; } if (room.TradeSettings == 1 && room.OwnerId != session.Habbo.Id) { session.SendPacket(new TradingErrorComposer(6, targetUser.GetUsername())); return; } } if (roomUser.IsTrading && roomUser.TradePartner != targetUser.UserId) { session.SendPacket(new TradingErrorComposer(7, targetUser.GetUsername())); return; } if (targetUser.IsTrading && targetUser.TradePartner != roomUser.UserId) { session.SendPacket(new TradingErrorComposer(8, targetUser.GetUsername())); return; } if (!targetUser.GetClient().Habbo.AllowTradingRequests) { session.SendPacket(new TradingErrorComposer(4, targetUser.GetUsername())); return; } if (targetUser.GetClient().Habbo.TradingLockExpiry > 0) { session.SendPacket(new TradingErrorComposer(4, targetUser.GetUsername())); return; } if (!room.GetTrading().StartTrade(roomUser, targetUser, out Trade trade)) { session.SendNotification("An error occured trying to start this trade"); return; } if (targetUser.HasStatus("trd")) { targetUser.RemoveStatus("trd"); } if (roomUser.HasStatus("trd")) { roomUser.RemoveStatus("trd"); } targetUser.SetStatus("trd"); targetUser.UpdateNeeded = true; roomUser.SetStatus("trd"); roomUser.UpdateNeeded = true; trade.SendPacket(new TradingStartComposer(roomUser.UserId, targetUser.UserId)); }
public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet) { int UserId = Packet.PopInt(); if (Session == null || Session.GetHabbo() == null || !Session.GetHabbo().InRoom) { return; } Room Room = Session.GetHabbo().CurrentRoom; if (Room == null) { return; } RoomUser RoomUser = Room.GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id); if (RoomUser == null) { return; } RoomUser TargetUser = Room.GetRoomUserManager().GetRoomUserByVirtualId(UserId); if (TargetUser == null) { return; } if (Session.GetHabbo().TradingLockExpiry > 0) { if (Session.GetHabbo().TradingLockExpiry > PlusEnvironment.GetUnixTimestamp()) { Session.SendNotification("You're currently banned from trading."); return; } else { Session.GetHabbo().TradingLockExpiry = 0; Session.SendNotification("Your trading ban has now expired."); using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.RunQuery("UPDATE `user_info` SET `trading_locked` = '0' WHERE `id` = '" + Session.GetHabbo().Id + "' LIMIT 1"); } } } if (!Session.GetHabbo().GetPermissions().HasRight("room_trade_override")) { if (Room.TradeSettings == 0) { Session.SendPacket(new TradingErrorComposer(6, TargetUser.GetUsername())); return; } else if (Room.TradeSettings == 1 && Room.OwnerId != Session.GetHabbo().Id) { Session.SendPacket(new TradingErrorComposer(6, TargetUser.GetUsername())); return; } } if (RoomUser.IsTrading && RoomUser.TradePartner != TargetUser.UserId) { Session.SendPacket(new TradingErrorComposer(7, TargetUser.GetUsername())); return; } else if (TargetUser.IsTrading && TargetUser.TradePartner != RoomUser.UserId) { Session.SendPacket(new TradingErrorComposer(8, TargetUser.GetUsername())); return; } else if (!TargetUser.GetClient().GetHabbo().AllowTradingRequests) { Session.SendPacket(new TradingErrorComposer(4, TargetUser.GetUsername())); return; } else if (TargetUser.GetClient().GetHabbo().TradingLockExpiry > 0) { Session.SendPacket(new TradingErrorComposer(4, TargetUser.GetUsername())); return; } Trade Trade = null; if (!Room.GetTrading().StartTrade(RoomUser, TargetUser, out Trade)) { Session.SendNotification("An error occured trying to start this trade"); return; } if (TargetUser.HasStatus("trd")) { TargetUser.RemoveStatus("trd"); } if (RoomUser.HasStatus("trd")) { RoomUser.RemoveStatus("trd"); } TargetUser.SetStatus("trd"); TargetUser.UpdateNeeded = true; RoomUser.SetStatus("trd"); RoomUser.UpdateNeeded = true; Trade.SendPacket(new TradingStartComposer(RoomUser.UserId, TargetUser.UserId)); }