Sellroom / Buyroom.

May 1, 2015
470
154
Hello,
There was a sellroom command recently released in an emulator, the code was written very poorly and had a few exploits.
I've touched it up, removed a bunch of unnecessary code and cleaned it up.
It requires a lot of steps, but it's worth it.
Add
Code:
public int ForSaleAmount;
public bool RoomForSale;
to room.cs as well as the following method:
Code:
public void AssignNewOwner(Room ForSale, RoomUser Buyer, RoomUser Seller)
        {
            using (IQueryAdapter Adapter = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                Adapter.SetQuery("UPDATE rooms SET owner = @new WHERE id = @id");
                Adapter.AddParameter("new", Buyer.HabboId);
                Adapter.AddParameter("id", ForSale.RoomData.Id);
                Adapter.RunQuery();

                Adapter.SetQuery("UPDATE items SET user_id = @new WHERE id = @id");
                Adapter.AddParameter("new", Buyer.HabboId);
                Adapter.AddParameter("id", ForSale.RoomData.Id);
                Adapter.RunQuery();

                Adapter.SetQuery("DELETE FROM room_rights WHERE room_id = @id");
                Adapter.AddParameter("id", ForSale.RoomData.Id);

                if (ForSale.Group != null)
                {
                    Adapter.SetQuery("SELECT id FROM groups WHERE room_id = @id");
                    Adapter.AddParameter("id", ForSale.RoomData.Id);
                    int GroupID = Adapter.getInteger();
                    if (GroupID > 0)
                    {
                        ForSale.Group.ClearRequests();
                        foreach (int UserID in ForSale.Group.GetAllMembers)
                        {
                            ForSale.Group.DeleteMember(UserID);
                            GameClient UserClient = PlusEnvironment.GetGame().GetClientManager().GetClientByUserID(UserID);
                            if (UserClient == null)
                                continue;

                            if (UserClient.GetHabbo().GetStats().FavouriteGroupId == GroupID)
                            {
                                UserClient.GetHabbo().GetStats().FavouriteGroupId = 0;
                            }
                        }
                        Adapter.RunQuery("DELETE FROM `groups` WHERE `id` = @id = '" + ForSale.Group.Id + "'");
                        Adapter.RunQuery("DELETE FROM `group_memberships` WHERE group_id = '" + ForSale.Group.Id + "'");
                        Adapter.RunQuery("DELETE FROM `group_requests` WHERE group_id = '" + ForSale.Group.Id + "'");
                        Adapter.RunQuery("UPDATE `rooms` SET `group_id` = '0' WHERE `group_id` = '" + ForSale.Group.Id + "'");
                        Adapter.RunQuery("UPDATE `user_stats` SET `group_id` = '0' WHERE group_id = '" + ForSale.Group.Id + "'");
                        Adapter.RunQuery("DELETE FROM `items_groups` WHERE `group_id` = '" + ForSale.Group.Id + "'");
                    }
                    PlusEnvironment.GetGame().GetGroupManager().DeleteGroup(ForSale.Group.Id);
                    ForSale.RoomData.Group = null;
                    ForSale.Group = null;
                }
            }
            ForSale.RoomData.OwnerId = Buyer.HabboId;
            ForSale.RoomData.OwnerName = Buyer.GetClient().GetHabbo().Username;

            foreach (Item Item in ForSale.GetRoomItemHandler().GetWallAndFloor)
            {
                Item.UserID = Buyer.HabboId;
                Item.Username = Buyer.GetClient().GetHabbo().Username;
            }
            Buyer.GetClient().GetHabbo().Credits -= ForSale.ForSaleAmount;
            Buyer.GetClient().SendMessage(new CreditBalanceComposer(Buyer.GetClient().GetHabbo().Credits));
            Seller.GetClient().GetHabbo().Credits += ForSale.ForSaleAmount;
            Seller.GetClient().SendMessage(new CreditBalanceComposer(Seller.GetClient().GetHabbo().Credits));

            ForSale.RoomForSale = false;
            ForSale.ForSaleAmount = 0;

            Buyer.GetClient().GetHabbo().UsersRooms.Add(ForSale);
            Buyer.GetClient().GetHabbo().UsersRooms.Remove(ForSale);

            Room Room = null;
            List<RoomUser> UsersReturn = ForSale.GetRoomUserManager().GetRoomUsers().ToList();
            PlusEnvironment.GetGame().GetNavigator().Init();
            PlusEnvironment.GetGame().GetRoomManager().UnloadRoom(Room, true);
            foreach (RoomUser User in UsersReturn)
            {
                if (User == null || User.GetClient() == null)
                    continue;
                User.GetClient().SendMessage(new RoomForwardComposer(ForSale.RoomId));
                User.GetClient().SendNotification("This room has just been purchased by " + Buyer.GetClient().GetHabbo().Username + " for " + ForSale.ForSaleAmount + "!");
            }
        }
now for the commands,
SellRoomCommand
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Plus.Database.Interfaces;

namespace Plus.HabboHotel.Rooms.Chat.Commands.User.Fun
{
    class SellRoom : IChatCommand
    {
        public string PermissionRequired
        {
            get { return "command_sellroom"; }
        }
        public string Parameters
        {
            get { return "%price%"; }
        }
        public string Description
        {
            get { return "Sell your room"; }
        }
        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            RoomUser User = Room.GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id);

            if (Params.Length == 1)
            {
                Session.SendWhisper("Please enter a price for your room!");
                return;
            }

            string roomCost = Params[1];
            int Cost;
            Cost = int.Parse(roomCost.Substring(0, roomCost.Length - 1));

            if (Cost == 0)
            {
                Room.RoomForSale = false;
                Room.ForSaleAmount = 0;
                return;
            }

            if (Room.RoomData.OwnerId != User.HabboId)
            {
                Session.SendWhisper("You can not sell this room because you are not the owner.");
                return;
            }

            if (Cost < 1 || Cost > 100000)
            {
                Session.SendWhisper("Invalid cost. (1-100000)");
                return;
            }
            else
            {
                Room.RoomForSale = true;
                Room.ForSaleAmount = Cost;
                Session.SendWhisper("This room has now been put for up for sale, the room has been notified.");

                foreach (RoomUser user in Room.GetRoomUserManager().GetRoomUsers())
                {
                    if (user == null || user.GetClient() == null)
                        continue;

                    user.GetClient().SendNotification("This room is now for sale for " + Cost + " credits! type :buyroom to purchase it.");
                }
            }
        }
    }
}
BuyRoomCommand
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Plus.HabboHotel.Rooms.Chat.Commands.User.Fun
{
    class BuyRoomCommand
    {
        public string PermissionRequired
        {
            get { return "command_buyroom"; }
        }
        public string Parameters
        {
            get { return ""; }
        }
        public string Description
        {
            get { return "Purchase a room that is for sale."; }
        }
        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            RoomUser User = Room.GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id);
            RoomUser Owner = Room.GetRoomUserManager().GetRoomUserByHabbo(Room.RoomData.OwnerId);

            if (User == null)
                return;

            if (!Room.RoomForSale)
            {
                Session.SendWhisper("This room is not for sale!");
                return;
            }

            if (Room.OwnerId == User.HabboId)
            {
                Session.SendWhisper("You can not purchase your own room.");
                return;
            }

            if (User.GetClient().GetHabbo().Credits >= Room.ForSaleAmount)
            {
                Room.AssignNewOwner(Room, User, Owner);
            }
            else
            {
                User.GetClient().SendWhisper("You do not have enough credits!");
                return;
            }
        }
    }
}
Now, this may not be the best way to do this but it properly transfers the items and swaps the owners so it gets the job done.
This has not been tested, if you come across any issues i'd be more than happy to help.
 
Last edited:

Sledmore

Chaturbate Livestreamer
Staff member
FindRetros Moderator
Jul 24, 2010
5,199
3,934
Looks good nice share, but just a question is this needed?

PHP:
PlusEnvironment.GetGame().GetNavigator().Init();

Also, I don't think you need to change the item owners in that loop if you're updating them in the database and then unloading? (I think).

Good share nonetheless.
 
May 1, 2015
470
154
I had an issue with it updating on the navigator - That's why i added that navigator bit.
I think you're right about the item bit, not too sure why i added that.
Thanks, means a lot.
 

JynX

Posting Freak
Feb 6, 2016
710
438
Where to put this:
public int ForSaleAmount;
public bool RoomForSale;
?
Room.cs
You're giving the room those values, it wouldn't make sense defining it somewhere like Habbo.cs because you'd be allowing the habbo to have a value for "ForSaleAmount". :p
 

Nustix

New Member
Aug 12, 2016
7
1
I think Room.cs:
Add
public int ForSaleAmount;
public bool RoomForSale;
to room.cs as well as the following method:

Room.cs
You're giving the room those values, it wouldn't make sense defining it somewhere like Habbo.cs because you'd be allowing the habbo to have a value for "ForSaleAmount". :p

Thx, but now i've got errors on the debug:
476f8d45269b47e8b5c3a7cdaf8b8395.png
 

MasterJiq

Member
Jul 8, 2016
385
23
When I sell it for 50 credits, then I tried on my other accounts :buyroom and I receive message "Username buy your room for 0 credits"
 

NO4H

New Member
Dec 21, 2016
27
13
Already included in a number of Plus edits out there, however useful for those who want to add it manually.
Thanks for the share
 

slaapkop

New Member
May 21, 2015
8
0
hi, where i need to put the scripts in? i know in room.cs but where? and the script for room.cs gives some line errors but i don't know how i can fix it correctly so can some one help my?
 

C0MB4T122

New Member
Aug 15, 2016
25
0
There's a foult...
If you sell it for 322 credits and you buy it, it says you've bought it for 0 credits. But from your credits amount it will take 322 credits...
Do you have to add something in the database?
 

Users who are viewing this thread

Top