[PlusEMU] Jail System

SOUL

┼ ┼ ┼
Nov 10, 2015
224
45


cb768f.png


Yo,
Releasing this as thought it would be a nice share anyhow...


How does this work?
Upon the user executing command in the format :jail username time the TargetClient will be sent to jail to the given time. A timer is then activated & disposed upon disconnection / completion of the timer.
The user cannot talk , leave the room , use the navigator , follow their friends nor message their friends until their timer is completed


Why the fuck are you storing it in the DB?
This was done a while ago keep in mind caching also uses a bit of RAM & CPU Usage , although thats no excuse to store it in the database rather than in memory.
Not going to fix what ain't broken , in regards to your MySQL server this will put slight strain on it but not to any extent where it's going to damage or slow down your MySQL server so disregard any bullshit comments in regards to this.




Adding this to PlusEMU

Run both of these SQLS
Code:
ALTER TABLE `users` ADD `in_jail` int(11) NOT NULL
ALTER TABLE `users` ADD `jail_time` int(11) NOT NULL


Go to Habbo.cs and find private int _id; under this put

Code:
public Timer JailTimer;

At the top of Habbo.cs put

Code:
using System.Timers;

Find private int _friendCount; under this put

Code:
private int _jail_time;
private int _in_jail;

Next find

Code:
 public Habbo(int Id, string Username, int Rank, string Motto, string Look, string Gender, int Credits, int ActivityPoints, int HomeRoom,
            bool HasFriendRequestsDisabled, int LastOnline, bool AppearOffline, bool HideInRoom, double CreateDate, int Diamonds,
            string machineID, string clientVolume, bool ChatPreference, bool FocusPreference, bool PetsMuted, bool BotsMuted, bool AdvertisingReportBlocked, double LastNameChange,
            int GOTWPoints, bool IgnoreInvites, double TimeMuted, double TradingLock, bool AllowGifts, int FriendBarState, bool DisableForcedEffects, bool AllowMimic, int VIPRank)

At the end add
Code:
,int In_Jail, int Jail_Time

Under the { add

Code:
this._jail_time = Jail_Time;
this._in_jail = In_Jail;

Find
Code:
public int Id

        {
            get { return this._id; }
            set { this._id = value; }
        }
Under this add
Code:
 public int Jail_Time

        {
            get { return this._jail_time; }
            set { this._jail_time = value; }
        }

        public int In_Jail
        {
            get { return this._in_jail; }
            set { this._in_jail = value; }
        }

Then find
Code:
  public string GetQueryString
        {
            get
            {
                this._habboSaved = true;
                return "UPDATE `users` SET `online` = '0', `last_online` = '" + PlusEnvironment.GetUnixTimestamp() + "', `activity_points` = '" + this.Duckets + "', `credits` = '" + this.Credits + "',  `in_jail` = '" + this.In_Jail + "', `jail_time` = '" + this.Jail_Time + "', `vip_points` = '" + this.Diamonds + "', `home_room` = '" + this.HomeRoom + "', `gotw_points` = '" + this.GOTWPoints + "', `time_muted` = '" + this.TimeMuted + "',`friend_bar_state` = '" + FriendBarStateUtility.GetInt(this._friendbarState) + "' WHERE id = '" + Id + "' LIMIT 1;UPDATE `user_stats` SET `roomvisits` = '" + this._habboStats.RoomVisits + "', `onlineTime` = '" + (PlusEnvironment.GetUnixTimestamp() - SessionStart + this._habboStats.OnlineTime) + "', `respect` = '" + this._habboStats.Respect + "', `respectGiven` = '" + this._habboStats.RespectGiven + "', `giftsGiven` = '" + this._habboStats.GiftsGiven + "', `giftsReceived` = '" + this._habboStats.GiftsReceived + "', `dailyRespectPoints` = '" + this._habboStats.DailyRespectPoints + "', `dailyPetRespectPoints` = '" + this._habboStats.DailyPetRespectPoints + "', `AchievementScore` = '" + this._habboStats.AchievementPoints + "', `quest_id` = '" + this._habboStats.QuestID + "', `quest_progress` = '" + this._habboStats.QuestProgress + "', `groupid` = '" + this._habboStats.FavouriteGroupId + "',`forum_posts` = '" + this._habboStats.ForumPosts + "' WHERE `id` = '" + this.Id + "' LIMIT 1;";
            }
        }
And replace it with
Code:
  public string GetQueryString
        {
            get
            {
                this._habboSaved = true;
                return "UPDATE `users` SET `online` = '0', `last_online` = '" + PlusEnvironment.GetUnixTimestamp() + "', `activity_points` = '" + this.Duckets + "', `credits` = '" + this.Credits + "',  `in_jail` = '" + this.In_Jail + "', `jail_time` = '" + this.Jail_Time + "', `vip_points` = '" + this.Diamonds + "', `home_room` = '" + this.HomeRoom + "', `gotw_points` = '" + this.GOTWPoints + "', `time_muted` = '" + this.TimeMuted + "',`friend_bar_state` = '" + FriendBarStateUtility.GetInt(this._friendbarState) + "' WHERE id = '" + Id + "' LIMIT 1;UPDATE `user_stats` SET `roomvisits` = '" + this._habboStats.RoomVisits + "', `onlineTime` = '" + (PlusEnvironment.GetUnixTimestamp() - SessionStart + this._habboStats.OnlineTime) + "', `respect` = '" + this._habboStats.Respect + "', `respectGiven` = '" + this._habboStats.RespectGiven + "', `giftsGiven` = '" + this._habboStats.GiftsGiven + "', `giftsReceived` = '" + this._habboStats.GiftsReceived + "', `dailyRespectPoints` = '" + this._habboStats.DailyRespectPoints + "', `dailyPetRespectPoints` = '" + this._habboStats.DailyPetRespectPoints + "', `AchievementScore` = '" + this._habboStats.AchievementPoints + "', `quest_id` = '" + this._habboStats.QuestID + "', `quest_progress` = '" + this._habboStats.QuestProgress + "', `groupid` = '" + this._habboStats.FavouriteGroupId + "',`forum_posts` = '" + this._habboStats.ForumPosts + "' WHERE `id` = '" + this.Id + "' LIMIT 1;";
            }
        }

Find
Code:
 public void InitInformation(UserData data)

        {
            BadgeComponent = new BadgeComponent(this   , data);
            Relationships = data.Relations;
        }
Under this insert
Code:
internal void StartJailTimer(GameClient Session, int Time)
        {
            Timer JailTimer = new Timer((Time * 60) * 1000);
            JailTimer.Start();
            Session.GetHabbo().In_Jail = 1;
            JailTimer.Elapsed += (o, e) =>
            {
                Session.GetHabbo().PrepareRoom(0, "");
                Session.SendMessage(new RoomNotificationComposer("Notification",
                "  You've been released from jail! \n\n" +
                "  Next time behave yourself!!", "small", ""));

                using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
                {
                    Session.GetHabbo().In_Jail = 0;
                    dbClient.SetQuery("UPDATE `users` SET `jail_time` = @jail_time, `in_jail` = @in_jail, `home_room` = @home_room WHERE id = @id");
                    dbClient.AddParameter("jail_time", 0);
                    dbClient.AddParameter("in_jail", 0);
                    dbClient.AddParameter("home_room", 0);
                    dbClient.AddParameter("id", Session.GetHabbo().Id);
                    dbClient.RunQuery();
                }
                JailTimer.Dispose();
            }
             ;

Okay we're done with this class , now go to Authenticator.cs
Change Convert.ToInt32(Row["rank_vip"])); to Convert.ToInt32(Row["rank_vip"]), and add the following code next to it
Code:
 Convert.ToInt32(Row["in_jail"]), Convert.ToInt32(Row["jail_time"]));

Go to UserDataFactory.cs & Find


Code:
dbClient.SetQuery("SELECT `id`,`username`,`rank`,`motto`,`look`,`gender`,`last_online`,`credits`,`activity_points`,`home_room`,`block_newfriends`,`hide_online`,`hide_inroom`,`vip`,`account_created`,`vip_points`,`machine_id`,`volume`,`chat_preference`,`focus_preference`, `pets_muted`,`bots_muted`,`advertising_report_blocked`,`last_change`,`gotw_points`,`ignore_invites`,`time_muted`,`allow_gifts`,`friend_bar_state`,`disable_forced_effects`,`allow_mimic`,`rank_vip` FROM `users` WHERE `auth_ticket` = @sso LIMIT 1");

                dbClient.AddParameter("sso", SessionTicket);
And replace with
Code:
dbClient.SetQuery("SELECT `id`,`username`,`rank`,`jail_time`,`in_jail`,`motto`,`look`,`gender`,`last_online`,`credits`,`activity_points`,`home_room`,`block_newfriends`,`hide_online`,`hide_inroom`,`vip`,`account_created`,`vip_points`,`machine_id`,`volume`,`chat_preference`,`focus_preference`, `pets_muted`,`bots_muted`,`advertising_report_blocked`,`last_change`,`gotw_points`,`ignore_invites`,`time_muted`,`allow_gifts`,`friend_bar_state`,`disable_forced_effects`,`allow_mimic`,`rank_vip` FROM `users` WHERE `auth_ticket` = @sso LIMIT 1");

                dbClient.AddParameter("sso", SessionTicket);

Find
Code:
  using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("SELECT `id`,`username`,`rank`,`motto`,`look`,`gender`,`last_online`,`credits`,`activity_points`,`home_room`,`block_newfriends`,`hide_online`,`hide_inroom`,`vip`,`account_created`,`vip_points`,`machine_id`,`volume`,`chat_preference`, `focus_preference`, `pets_muted`,`bots_muted`,`advertising_report_blocked`,`last_change`,`gotw_points`,`ignore_invites`,`time_muted`,`allow_gifts`,`friend_bar_state`,`disable_forced_effects`,`allow_mimic`,`rank_vip` FROM `users` WHERE `id` = @id LIMIT 1");
                dbClient.AddParameter("id", UserId);
Replace with
Code:
  using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())

            {
                dbClient.SetQuery("SELECT `id`,`username`,`rank`,`motto`,`jail_time`,`in_jail`,`look`,`gender`,`last_online`,`credits`,`activity_points`,`home_room`,`block_newfriends`,`hide_online`,`hide_inroom`,`vip`,`account_created`,`vip_points`,`machine_id`,`volume`,`chat_preference`, `focus_preference`, `pets_muted`,`bots_muted`,`advertising_report_blocked`,`last_change`,`gotw_points`,`ignore_invites`,`time_muted`,`allow_gifts`,`friend_bar_state`,`disable_forced_effects`,`allow_mimic`,`rank_vip` FROM `users` WHERE `id` = @id LIMIT 1");
                dbClient.AddParameter("id", UserId);

Go to HabboHotel > Rooms > Chat > Commands > Administrator
Right click then click "Add new class" and call it JailUserCommand
Delete everything in the current class and replace it with
Code:
using Plus.Communication.Packets.Outgoing.Rooms.Notifications;
using Plus.Database.Interfaces;
using Plus.HabboHotel.GameClients;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Plus.HabboHotel.Rooms.Chat.Commands.Administrator
{
    class JailUserCommand : IChatCommand
    {
        public string PermissionRequired => "command_jail";
        public string Parameters => "%username% %time%";
        public string Description => "Put a user in jail!.";


        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            int Time = 0;
            int Time_Now;

            Time_Now = Time;


            if (Params.Length == 1)
            {
                Session.SendWhisper("Please enter the username of the user you wish to jail");
                return;
            }

            GameClient TargetClient = PlusEnvironment.GetGame().GetClientManager().GetClientByUsername(Params[1]);
            if (TargetClient == null)
            {
                Session.SendWhisper($"An error occoured whilst trying to find {Params[1]}!");
                return;
            }

            RoomUser TargetUser = Room.GetRoomUserManager().GetRoomUserByHabbo(TargetClient.GetHabbo().Id);
            if (TargetUser == null)
            {
                Session.SendWhisper($"An error occoured whilst trying to find {Params[1]}, maybe they're not online or in this room.");
                return;
            }

            if (TargetClient.GetHabbo().Rank > Session.GetHabbo().Rank)
            {
                Session.SendWhisper("Oops , it appears you can't jail this user!");
                return;
            }

            if (Session.GetHabbo().In_Jail == 1)
            {
                Session.SendWhisper($"Oops , it appears {Params[1]} is already jailed!");
                return;
            }

            if (Session == TargetClient)
            {
                Session.SendWhisper("You can't put yourself in jail!");
                return;
            }


            if (Int32.TryParse(Params[2], out Time))
            {
 


                Session.SendWhisper($"You have successfully jailed {Params[1]} for {Time} minutes!");

                TargetClient.GetHabbo().PrepareRoom(// put room id of jail here // , "");
                TargetClient.GetHabbo().StartJailTimer(TargetClient, Time);

                TargetClient.SendMessage(new RoomNotificationComposer("Notification",
                "  You've been jailed by " + $"{Params[1]}\n\n" +
                "  You've been jailed for " + $"{Time} " + "Minute(s)", "small", ""));

                using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
                {
                    dbClient.SetQuery("UPDATE `users` SET `jail_time` = @jail_time, `in_jail` = @in_jail, `home_room` = @home_room WHERE id = @id");
                    dbClient.AddParameter("jail_time", Params[2]);
                    dbClient.AddParameter("in_jail", 1);
                    dbClient.AddParameter("home_room", // your room id here //);
                    dbClient.AddParameter("id", TargetClient.GetHabbo().Id);
                    dbClient.RunQuery();
                }
            }

        }

    }
}

Navigate to the following classes , "ShoutEvent" "WhisperEvent" "ChatEvent"
In each class insert the following code somewhere
Code:
if (Session.GetHabbo().In_Jail == 1)
            {
                Session.SendWhisper("You can't talk whilst you're in jail!");
                return;
            }

Go to SendMsgEvent
And insert the following code
Code:
if (Session.GetHabbo().In_Jail == 1)
            {
                Session.SendMessage(new RoomNotificationComposer("Notification",
                      "  Oops , it appears you're jailed! \n\n" +
                      "  You can't message your friends whilst jailed!", "small", ""));
                return;
            }

Go to FollowFriendEvent
And insert the following code
Code:
 if (Session.GetHabbo().In_Jail == 1)
            {
                Session.SendMessage(new RoomNotificationComposer("Notification",
               " Oops, it appears you're jailed ! \n\n" +
               "  You can't visit your friend whilst you're in jail!", "small", ""));
                return;
            }

Go to GameClient.cs and find the following
Code:
   if (!string.IsNullOrWhiteSpace(PlusEnvironment.GetDBConfig().DBData["welcome_message"]))
                        SendMessage(new MOTDNotificationComposer(PlusEnvironment.GetDBConfig().DBData["welcome_message"]));
Under this put
Code:
 if (Session.GetHabbo().Jail_Time != 0)
                    {
                        Session.GetHabbo().StartJailTimer(Session, Session.GetHabbo().Jail_Time);
                    }

                    if (Session.GetHabbo().Jail_Time == 0 && Session.GetHabbo().Jail_Time == 0)
                    {
                        using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
                        {
                            dbClient.SetQuery("UPDATE `users` SET `jail_time` = '0', `in_jail` = '0' WHERE id = @id");
                            dbClient.AddParameter("jail_time", 0);
                            dbClient.AddParameter("in_jail", 0);
                            dbClient.AddParameter("id", Session.GetHabbo().Id);
                            dbClient.RunQuery();
                        }
                    }

In GameClient find
Code:
public bool TryAuthenticate(string AuthTicket)
And replace with the following code
Code:
 public bool TryAuthenticate(string AuthTicket,GameClient Session)

Now go to SSOTicketEvent
And replace the last line with the following code
Code:
 Session.TryAuthenticate(Packet.PopString(), Session);

Nearly done just a few more classes!
Go to the following classes UpdateNavigatorSettingsEvent , GetNavigatorFlatsEvent , NewNavigatorSearchEvent , InitializeNewNavigatorEvent & CanCreateRoomEvent
And insert the following code somewhere in each class
Code:
 if (Session.GetHabbo().In_Jail == 1)
                return;

Go to CommandManager
Add the following code
Code:
this.Register("jail", new JailUserCommand());

Add the following in permission_commands
Code:
command_jail

Finally go to & download the image and save it as "small"
Then go to Swf/c_images/Notifications
And drag it in there

Re-build your solution and you're done!



Screenshots:

84d2948996f94abda1b776610a4a05c4.png



a65c2ea777064ff2b7e3a36f31d4a287.png


bdc81c97a3cc42ebb1ae32e4aa0e3445.png


38e57f300cdb4866aad72bdf279a7997.png



51243bf89bcc4da2ba79ac2f12812016.png

 
Looks easier than it is , if struggling to set up message me , failing that i'll just toss a download link for current revisions with this system on it
 
Last edited:

Velaski

winner
Aug 4, 2015
562
165
After 1 minute has gone, the jail time should be decremented and logged in the database. So if one reloads, it still has their renaming time.
 

SOUL

┼ ┼ ┼
Nov 10, 2015
224
45
namespace
Code:
using System.Timers;
would be added ?
Yea done this thread while half asleep will update it later
 
After 1 minute has gone, the jail time should be decremented and logged in the database. So if one reloads, it still has their renaming time.

Why 'should it be' this isn't for a RP and in this case users are being jailed for being annoying so didn't think it mattered , will look in to it later though
 

MasterJiq

Member
Jul 8, 2016
385
23
But the user can enter the next room, as I've seen that errors. So I've added this code:
Code:
            if (Room.Id != 100028)
            {
                if (this.GetClient().GetHabbo().In_Jail == 1)
                {
                    this.GetClient().SendMessage(new RoomNotificationComposer("Notification",
                          "  Oops , it appears you're jailed! \n\n" +
                          "  You can't message your friends whilst jailed!", "jail", ""));
                    return;
                }
            }
Above the code if (!EnterRoom(Room)) on Habbo.cs
 
But it seems not working, it just say 1 users in the room but all I get is the black room. (cant enter any room)
 

SOUL

┼ ┼ ┼
Nov 10, 2015
224
45
But the user can enter the next room, as I've seen that errors. So I've added this code:
Code:
            if (Room.Id != 100028)
            {
                if (this.GetClient().GetHabbo().In_Jail == 1)
                {
                    this.GetClient().SendMessage(new RoomNotificationComposer("Notification",
                          "  Oops , it appears you're jailed! \n\n" +
                          "  You can't message your friends whilst jailed!", "jail", ""));
                    return;
                }
            }
Above the code if (!EnterRoom(Room)) on Habbo.cs
 
But it seems not working, it just say 1 users in the room but all I get is the black room. (cant enter any room)

Seems like you put that in SendMsgEvent and how can users enter other rooms?
 
Seems like you put that in SendMsgEvent and how can users enter other rooms?

Make sure you put the Room ID in the prepareroom method and the addparameter

If you're on new revision change sendmessage to sendpacket
 

SOUL

┼ ┼ ┼
Nov 10, 2015
224
45
No, I am on the old revision. SO how do I make a jailed users can't enter another room

When they're jailed the navigator is disabled for them as well as following their friends unless you didn't add it
 

Marko97

M97 Project based Plus EMU
Aug 7, 2013
99
45
If the client stuck 76% follow this guide:

Open SSOTicketEvent.cs
Search:
Code:
Session.TryAuthenticate(Packet.PopString(), Session);
Replace:
Code:
Session.TryAuthenticate(SSO, Session);
 

Marko97

M97 Project based Plus EMU
Aug 7, 2013
99
45
dfjgi.png


When I click the Hotel view button or/and search friends buttons, the user can exit from the prison and go in another room.
@SOUL
 

Users who are viewing this thread

Top