commands help

antiny2010

Member
Nov 27, 2014
171
6
hey im using plus emu and need some help adding custom commands i add them but then get this error for one of them? also the commands show now in my commands list but dont actully work
 

SOUL

┼ ┼ ┼
Nov 10, 2015
224
45
hey im using plus emu and need some help adding custom commands i add them but then get this error for one of them? also the commands show now in my commands list but dont actully work

Post your code i'll take a look when I'm on my laptop
 

antiny2010

Member
Nov 27, 2014
171
6
Code:
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Data;
using Plus.HabboHotel.GameClients;
using Plus.HabboHotel.Rooms;
using Plus.Communication.Packets.Outgoing.Users;
using Plus.Communication.Packets.Outgoing.Rooms.Avatar;
using System.Threading;
using System.Threading.Tasks;
using Plus.Communication.Packets.Outgoing.Rooms.Chat;
using Plus.HabboHotel.Items;
using Plus.HabboHotel.Catalog;
using Plus.Communication.Packets.Outgoing.Inventory.Furni;
using Plus.Database.Interfaces;
using Plus.Communication.Packets.Outgoing.Notifications;
using Plus.Communication.Packets.Outgoing.Rooms.Engine;

namespace Plus.HabboHotel.Rooms.Chat.Commands.Moderator
{
    class ViewPrivateMessageCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get { return "command_view_pms"; }
        }

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

        public string Description
        {
            get { return "Lets you view recent PMs from and to a user."; }
        }

        public void Exec(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            if (Params.Length == 1)
            {
                Session.SendWhisper("Please enter the username of the user you wish to view private messages of.");
                return;
            }

            GameClient TargetClient = PlusEnvironment.GetGame().GetClientManager().GetClientByUsername(Params[1]);
            if (TargetClient == null)
            {
                Session.SendWhisper("An error occoured whilst finding that user, maybe they're not online.");
                return;
            }

            if (TargetClient.GetHabbo() == null)
            {
                Session.SendWhisper("An error occoured whilst finding that user, maybe they're not online.");
                return;
            }
            StringBuilder b = new StringBuilder();
            b.Append("Private messages - " + TargetClient.GetHabbo().Username + "\n\n");

            using (IQueryAdapter db = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                db.SetQuery("SELECT * FROM `chatlogs_console` WHERE `from_id` = @id OR `to_id` = @id ORDER BY id DESC LIMIT 100");
                db.AddParameter("id", TargetClient.GetHabbo().Id);
                db.RunQuery();
                DataTable t = db.GetTable();

                foreach (DataRow r in t.Rows)
                {
                    b.Append(UnixTimeStampToDateTime((double)PlusEnvironment.GetUnixTimestamp()) + "\n");
                    b.Append(getUsernameFromId(Convert.ToInt32(r["from_id"])) + " to " + getUsernameFromId(Convert.ToInt32(r["to_id"])) + ": " + Convert.ToString(r["message"]) + "\n\n");
                }
            }

            Session.SendMessage(new MOTDNotificationComposer(b.ToString()));
        }

        private DateTime UnixTimeStampToDateTime(double unixTimeStamp)
        {
            // Unix timestamp is seconds past epoch
            System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
            dtDateTime = dtDateTime.AddSeconds(unixTimeStamp).ToLocalTime();
            return dtDateTime;
        }

        private string getUsernameFromId(int userId)
        {
            if (PlusEnvironment.GetHabboById(userId) != null)
                return PlusEnvironment.GetHabboById(userId).Username;

            using (IQueryAdapter db = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                db.SetQuery("SELECT `username` FROM `users` WHERE `id` = @id");
                db.AddParameter("id", userId);
                db.RunQuery();
                return db.GetString();
            }
        }
    }
}
 
thats for view pms command
 

Users who are viewing this thread

Top