PlusEMU Chatlogs Overflow :/

Pinkman

Posting Freak
Jul 27, 2016
818
194
Hello people,
I am having issues regarding with Chatlogs, I have asked @Sledmore to help me however you know how busy he is. I have removed the trycatch to see if it works and it did 50/50. Before removing the trycatch it gave me an error . If anyone can help that would really be helpful.

@Sledmore @Scar @Damiens
 

JayC

Well-Known Member
Aug 8, 2013
5,505
1,401
Code:
try
            {
                Session.SendMessage(new ModeratorRoomChatlogComposer(Room));
            }
            catch { Session.SendNotification("Overflow :/"); }
This means that you were unable to send a new ModeratorRoomChatlogComposer

Try This:
Code:
using System;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections.Generic;
using Plus.Database.Interfaces;
using Plus.HabboHotel.Rooms;
using Plus.HabboHotel.Users;

using Plus.Utilities;
using Plus.HabboHotel.Cache;

namespace Plus.Communication.Packets.Outgoing.Moderation
{
    class ModeratorRoomChatlogComposer : ServerPacket
    {
        public ModeratorRoomChatlogComposer(Room Room)
            : base(ServerPacketHeader.ModeratorRoomChatlogMessageComposer)
        {
            base.WriteByte(1);
            base.WriteShort(2);//Count
           base.WriteString("roomName");
            base.WriteByte(2);
           base.WriteString(Room.Name);
           base.WriteString("roomId");
            base.WriteByte(1);
            base.WriteInteger(Room.Id);

            DataTable Table = null;
            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("SELECT * FROM `chatlogs` WHERE `room_id` = @rid ORDER BY `id` DESC LIMIT 250");
                dbClient.AddParameter("rid", Room.Id);
                Table = dbClient.getTable();
            }

            base.WriteShort(Table.Rows.Count);
            if (Table != null)
            {
                foreach (DataRow Row in Table.Rows)
                {
                    UserCache Habbo = PlusEnvironment.GetGame().GetCacheManager().GenerateUser(Convert.ToInt32(Row["user_id"]));

                    if (Habbo == null)
                    {
                        base.WriteString((((int)PlusEnvironment.GetUnixTimestamp() - Convert.ToInt32(Row["timestamp"])) * 1000).ToString());
                        base.WriteInteger(-1);
                       base.WriteString("Unknown User");
                       base.WriteString(string.IsNullOrWhiteSpace(Convert.ToString(Row["message"])) ? "*user sent a blank message*" : Convert.ToString(Row["message"]));
                        base.WriteBoolean(false);
                    }
                    else
                    {
                        base.WriteString((((int)PlusEnvironment.GetUnixTimestamp() - Convert.ToInt32(Row["timestamp"])) * 1000).ToString());
                        base.WriteInteger(Habbo.Id);
                       base.WriteString(Habbo.Username);
                       base.WriteString(string.IsNullOrWhiteSpace(Convert.ToString(Row["message"]) )? "*user sent a blank message*" : Convert.ToString(Row["message"]));
                        base.WriteBoolean(false);
                    }
                }
            }
        }
    }
}
 

Haid

Member
Dec 20, 2011
363
449
Try This:
If it was a structure issue the client would be disconnected.
Had this before, it's a mathematical error but didn't look into it, this will catch the exception and set a default timestamp value.

We've not updated revision so we're on whatever PlusEMU was first released on; if you are on a newer revision it's possible the structure has changed so do not use this.

ModeratorRoomChatlogComposer.cs
Code:
using System;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections.Generic;
using Plus.Database.Interfaces;
using Plus.HabboHotel.Rooms;
using Plus.HabboHotel.Users;
using Plus.Utilities;
using Plus.HabboHotel.Cache;

namespace Plus.Communication.Packets.Outgoing.Moderation
{
    class ModeratorRoomChatlogComposer : ServerPacket
    {
        public ModeratorRoomChatlogComposer(Room Room)
            : base(ServerPacketHeader.ModeratorRoomChatlogMessageComposer)
        {
            base.WriteByte(1);
            base.WriteShort(2); //Count
            base.WriteString("roomName");
            base.WriteByte(2);
            base.WriteString(Room.Name);
            base.WriteString("roomId");
            base.WriteByte(1);
            base.WriteInteger(Room.Id);

            DataTable table;
            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("SELECT * FROM `chatlogs` WHERE `room_id` = @rid ORDER BY `id` DESC LIMIT 250");
                dbClient.AddParameter("rid", Room.Id);
                table = dbClient.getTable();
            }

            if (table != null)
            {
                base.WriteShort(table.Rows.Count);

                foreach (DataRow row in table.Rows)
                {
                    int timestamp;

                    try
                    {
                        timestamp = ((int) PlusEnvironment.GetUnixTimestamp() - Convert.ToInt32(row["timestamp"])) *
                                    1000;
                    }
                    catch
                    {
                        timestamp = 0; // For whatever reason, the maths failed
                    }

                    UserCache habbo =
                        PlusEnvironment.GetGame().GetCacheManager().GenerateUser(Convert.ToInt32(row["user_id"]));

                    base.WriteInteger(timestamp);

                    if (habbo != null)
                    {
                        base.WriteInteger(habbo.Id);
                        base.WriteString(habbo.Username);
                    }
                    else
                    {
                        base.WriteInteger(-1);
                        base.WriteString("Unknown User");
                    }

                    base.WriteString(
                        string.IsNullOrWhiteSpace(Convert.ToString(row["message"]))
                            ? "*user sent a blank message*"
                            : Convert.ToString(row["message"]));

                    base.WriteBoolean(false);
                }
            }
        }
    }
}

ModeratorUserChatlogComposer.cs
Code:
using System;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections.Generic;
using Plus.HabboHotel.Users;
using Plus.Database.Interfaces;
using Plus.HabboHotel.Rooms;
using Plus.HabboHotel.Cache;

namespace Plus.Communication.Packets.Outgoing.Moderation
{
    class ModeratorUserChatlogComposer : ServerPacket
    {
        public ModeratorUserChatlogComposer(int UserId)
            : base(ServerPacketHeader.ModeratorUserChatlogMessageComposer)
        {
            base.WriteInteger(UserId);
            base.WriteString(PlusEnvironment.GetGame().GetClientManager().GetNameById(UserId));

            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery(
                    "SELECT room_id,entry_timestamp,exit_timestamp FROM user_roomvisits WHERE `user_id` = " + UserId +
                    " ORDER BY entry_timestamp DESC LIMIT 5");
                DataTable visits = dbClient.getTable();

                if (visits != null)
                {
                    base.WriteInteger(visits.Rows.Count);

                    foreach (DataRow visit in visits.Rows)
                    {
                        string roomName = "Unknown";

                        Room room =
                            PlusEnvironment.GetGame().GetRoomManager().LoadRoom(Convert.ToInt32(visit["room_id"]));

                        if (room != null)
                            roomName = room.Name;

                        base.WriteByte(1);
                        base.WriteShort(2); //Count
                        base.WriteString("roomName");
                        base.WriteByte(2);
                        base.WriteString(roomName); // room name
                        base.WriteString("roomId");
                        base.WriteByte(1);
                        base.WriteInteger(Convert.ToInt32(visit["room_id"]));

                        DataTable chatlogs = null;
                        if ((Double) visit["exit_timestamp"] <= 0)
                        {
                            visit["exit_timestamp"] = PlusEnvironment.GetUnixTimestamp();
                        }

                        dbClient.SetQuery("SELECT user_id,timestamp,message FROM `chatlogs` WHERE room_id = " +
                                          Convert.ToInt32(visit["room_id"]) + " AND timestamp > " +
                                          (Double) visit["entry_timestamp"] + " AND timestamp < " +
                                          (Double) visit["exit_timestamp"] + " ORDER BY timestamp DESC LIMIT 150");
                        chatlogs = dbClient.getTable();

                        if (chatlogs != null)
                        {
                            base.WriteShort(chatlogs.Rows.Count);

                            foreach (DataRow log in chatlogs.Rows)
                            {
                                UserCache habbo =
                                    PlusEnvironment.GetGame()
                                        .GetCacheManager()
                                        .GenerateUser(Convert.ToInt32(log["user_id"]));

                                if (habbo == null)
                                    continue;

                                int timestamp;

                                try
                                {
                                    timestamp = ((int) PlusEnvironment.GetUnixTimestamp() -
                                                 Convert.ToInt32(log["timestamp"])) * 1000;
                                }
                                catch
                                {
                                    timestamp = 0;
                                }

                                base.WriteInteger(timestamp);
                                base.WriteInteger(habbo.Id);
                                base.WriteString(habbo.Username);
                                base.WriteString(string.IsNullOrWhiteSpace(Convert.ToString(log["message"]))
                                    ? "*user sent a blank message*"
                                    : Convert.ToString(log["message"]));
                                base.WriteBoolean(false);
                            }
                        }
                        else
                            base.WriteInteger(0);
                    }
                }
                else
                    base.WriteInteger(0);
            }
        }
    }
}
 
Last edited:

Core

Member
Nov 10, 2016
356
138
Haidyn, I will try this when I'm laptop but if it don't work can I send u a pm and you help me with it please?

Message me your TV details when you're home. The error doesn't catch properly so we will remove it and see what error it gives us specifically.
My guess is that it's an issue with date format in query, but will have to see.
 

Sledmore

Chaturbate Livestreamer
Staff member
FindRetros Moderator
Jul 24, 2010
5,199
3,934
I think this might have fixed itself in the newer version. However, a big suggestion (something I never did, while I was on this emulator I never really got the time to sort little bits like this) is to move the logic around and use the ChatlogEntry stuff, e.g;

This is purely an example, don't just copy & paste and overwrite, however it will work to copy & paste this into the right area.

GetModeratorRoomChatlogEvent.cs

PHP:
            PlusEnvironment.GetGame().GetChatManager().GetLogs().FlushAndSave();

            DataTable Table = null;
            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("SELECT * FROM `chatlogs` WHERE `room_id` = @rid ORDER BY `id` DESC LIMIT 250");
                dbClient.AddParameter("rid", Room.Id);
                Table = dbClient.GetTable();
            }

            List<ChatlogEntry> Chats = new List<ChatlogEntry>();

            if (Table != null)
            {
                foreach (DataRow Row in Table.Rows)
                {
                    Chats.Add(new ChatlogEntry(Convert.ToInt32(Row["user_id"]), RoomId, Convert.ToString(Row["message"]), Convert.ToDouble(Row["timestamp"]), PlusEnvironment.GetHabboById(Convert.ToInt32(Row["user_id"]))));
                }
            }

            Session.SendPacket(new ModeratorRoomChatlogComposer(Room, Chats));

ModeratorRoomChatlogComposer.cs

PHP:
            base.WriteShort(Chats.Count);
            foreach (ChatlogEntry Entry in Chats)
            {
                string Username = "Unknown";
                if (Entry.PlayerNullable() != null)
                    Username = Entry.PlayerNullable().Username;

                base.WriteString(UnixTimestamp.FromUnixTimestamp(Entry.Timestamp).ToShortTimeString());
                base.WriteInteger(Entry.PlayerId);
                base.WriteString(Username);
                base.WriteString(Entry.Message);
                base.WriteBoolean(false);
            }
 

Users who are viewing this thread

Top