Who's Online Command

GuruGuru

Member
Dec 1, 2016
52
3
Hi I am currently using Sledmore's EMU and looking to find out WHO is online. I can currently gather the total number of people in :about but is there a way to see which users are online via a command?

Thanks!
 

Blasteh

big tits
Apr 3, 2013
1,156
521
Here's a simple one, not sure if that's what you're looking for.

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Plus.HabboHotel.GameClients;

namespace Plus.HabboHotel.Rooms.Chat.Commands.User.Fun
{
    class OnlineCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get { return "command_online"; }
        }

        public string Parameters
        {
            get { return "%test%";  }
        }

        public string Description
        {
            get { return "Online command"; }
        }

        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            int OnlineUsers = PlusEnvironment.GetGame().GetClientManager().Count;

            Session.SendWhisper("There are " + OnlineUsers + " online, Coolio!");
        }
    }
}
Then add the below to your command manager, be sure to create the permissions as well.
Code:
this.Register("online", new OnlineCommand());
 
May 1, 2015
470
154
I'm pretty sure he wants to be able to view the users online.
Here's the command:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Plus.Database.Interfaces;
using System.Data;

namespace Plus.HabboHotel.Rooms.Chat.Commands.User.Fun
{
    class WhosOnlineCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get { return "command_whosonline"; }
        }
        public string Parameters
        {
            get { return ""; }
        }
        public string Description
        {
            get { return "Displays the online users"; }
        }
        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            string Output = "Current Users Online";
            Output += "-----------------------\r";

            using (IQueryAdapter Adapter = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                Adapter.SetQuery("SELECT FROM users WHERE online = '1'");
                Adapter.RunQuery();

                DataTable Table = Adapter.getTable();
                if (Table != null)
                {
                    foreach (DataRow Row in Table.Rows)
                    {
                        Output += Row["username"].ToString() + "\r";
                    }
                }
                Session.SendNotification(Output);
            }
        }
    }
}
 

GuruGuru

Member
Dec 1, 2016
52
3
H
I'm pretty sure he wants to be able to view the users online.
Here's the command:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Plus.Database.Interfaces;
using System.Data;

namespace Plus.HabboHotel.Rooms.Chat.Commands.User.Fun
{
    class WhosOnlineCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get { return "command_whosonline"; }
        }
        public string Parameters
        {
            get { return ""; }
        }
        public string Description
        {
            get { return "Displays the online users"; }
        }
        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            string Output = "Current Users Online";
            Output += "-----------------------\r";

            using (IQueryAdapter Adapter = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                Adapter.SetQuery("SELECT FROM users WHERE online = '1'");
                Adapter.RunQuery();

                DataTable Table = Adapter.getTable();
                if (Table != null)
                {
                    foreach (DataRow Row in Table.Rows)
                    {
                        Output += Row["username"].ToString() + "\r";
                    }
                }
                Session.SendNotification(Output);
            }
        }
    }
}
This appears to be what I'm looking for.

So far I have placed this code in a file called WhosOnlineCommand.cs at this path: \HabboHotel\Rooms\Chat\Commands\User\Fun

I've then placed this in HabboHotel\Rooms\Chat\Commands:

Code:
this.Register("whosonline", new WhosOnlineCommand());

I've then added a SQL input in permissions_commands:

Command: command_whosonline
Group_ID: 4
Subscription_ID: 0

Thoughts on why this would not work when I run :whosonline ?

Thank you?
 

JayC

Well-Known Member
Aug 8, 2013
5,505
1,401
I messed up the query in the command, lol.
silly mistake. It should be the following:
Code:
Adapter.SetQuery("SELECT username FROM users WHERE online = '1'");
Glad you helped him out - however pulling from the database is not the best way to do this.

This code:
Code:
 public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
           String usersOnline = "Users Online Now [" + PlusEnvironment.GetGame().GetClientManager().GetClients.Count + "]\n================================\n";
            foreach (GameClient Client in PlusEnvironment.GetGame().GetClientManager().GetClients)
            {
               usersOnline += Client.GetHabbo().Username + ", ";
            }
Session.SendNotification(usersOnline);
            }

This is how I do mine. (This is not actually tested - but should work).

All of the online sessions are stored in the client manager. No reason to import all the database classes/functions and add extra pull when you can use a Collection already storing this information.
 

GuruGuru

Member
Dec 1, 2016
52
3
Glad you helped him out - however pulling from the database is not the best way to do this.

This code:
Code:
 public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
           String usersOnline = "Users Online Now [" + PlusEnvironment.GetGame().GetClientManager().GetClients.Count + "]\n================================\n";
            foreach (GameClient Client in PlusEnvironment.GetGame().GetClientManager().GetClients)
            {
               usersOnline += Client.GetHabbo().Username + ", ";
            }
Session.SendNotification(usersOnline);
            }

This is how I do mine. (This is not actually tested - but should work).

All of the online sessions are stored in the client manager. No reason to import all the database classes/functions and add extra pull when you can use a Collection already storing this information.
My :whosonline command won't take, it just prints the text, any idea?
 

Jerry

not rly active lol
Jul 8, 2013
1,957
522
Glad you helped him out - however pulling from the database is not the best way to do this.

This code:
Code:
 public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
           String usersOnline = "Users Online Now [" + PlusEnvironment.GetGame().GetClientManager().GetClients.Count + "]\n================================\n";
            foreach (GameClient Client in PlusEnvironment.GetGame().GetClientManager().GetClients)
            {
               usersOnline += Client.GetHabbo().Username + ", ";
            }
Session.SendNotification(usersOnline);
            }

This is how I do mine. (This is not actually tested - but should work).

All of the online sessions are stored in the client manager. No reason to import all the database classes/functions and add extra pull when you can use a Collection already storing this information.
I don't like the way you coded the command, honestly.

This is how I done it:

In my code, it shows a list of all online VISIBLE users to everyone and it shows all online VISIBLE and INVISIBLE users to staff members. For the visible/invisible part, it uses a user setting hide_online from the users table. However, my code is cleaner, just saying.
 

GuruGuru

Member
Dec 1, 2016
52
3
I don't like the way you coded the command, honestly.

This is how I done it:

In my code, it shows a list of all online VISIBLE users to everyone and it shows all online VISIBLE and INVISIBLE users to staff members. For the visible/invisible part, it uses a user setting hide_online from the users table. However, my code is cleaner, just saying.
Hi Jerry,
I'm having trouble implementing it. Can you help me on a more granular basis after I add the file name you've submitted with the same name as the class?
 
Hi Jerry,
I'm having trouble implementing it. Can you help me on a more granular basis after I add the file name you've submitted with the same name as the class?
Wondering if you could help me implement this?
 

Users who are viewing this thread

Top