예제 #1
0
        internal static ServerMessage SerializeUserChatlog(UInt32 UserId)
        {
            GameClient client = FirewindEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);

            if (client == null || client.GetHabbo() == null)
            {
                ServerMessage Message = new ServerMessage(Outgoing.UserChatlog);
                Message.AppendUInt(UserId);
                Message.AppendString("User not online");
                Message.AppendInt32(0);

                return(Message);
            }
            else
            {
                ChatMessageManager manager = client.GetHabbo().GetChatMessageManager();
                Dictionary <int, List <ChatMessage> > messages = manager.GetSortedMessages();

                ServerMessage Message = new ServerMessage(Outgoing.UserChatlog);
                Message.AppendUInt(UserId);
                Message.AppendString(client.GetHabbo().Username);
                Message.AppendInt32(messages.Count);
                foreach (KeyValuePair <int, List <ChatMessage> > valuePair in messages)
                {
                    List <ChatMessage> sortedMessages = valuePair.Value;
                    ChatMessage        firstMessage   = sortedMessages.First();

                    Message.AppendBoolean(false); // is public
                    Message.AppendUInt(firstMessage.roomID);
                    Message.AppendString(firstMessage.roomName);

                    Message.AppendInt32(sortedMessages.Count);

                    foreach (ChatMessage message in sortedMessages)
                    {
                        message.Serialize(ref Message);
                    }
                }

                return(Message);
            }

            //using (IQueryAdapter dbClient = FirewindEnvironment.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();


            //    ServerMessage Message = new ServerMessage(536);
            //    Message.AppendUInt(UserId);
            //    Message.AppendString(FirewindEnvironment.GetGame().GetClientManager().GetNameById(UserId));

            //    if (Visits != null)
            //    {
            //        Message.AppendInt32(Visits.Rows.Count);

            //        foreach (DataRow Visit in Visits.Rows)
            //        {
            //            DataTable Chatlogs = null;

            //            if ((Double)Visit["exit_timestamp"] <= 0.0)
            //            {
            //                Visit["exit_timestamp"] = FirewindEnvironment.GetUnixTimestamp();
            //            }

            //            //using (DatabaseClient dbClient = FirewindEnvironment.GetDatabase().GetClient())
            //            //{
            //            //Chatlogs = dbClient.getTable("SELECT user_id,user_name,hour,minute,message FROM chatlogs WHERE room_id = " + (uint)Visit["room_id"] + " AND timestamp > " + (Double)Visit["entry_timestamp"] + " AND timestamp < " + (Double)Visit["exit_timestamp"] + " ORDER BY timestamp DESC");
            //            //}

            //            RoomData RoomData = FirewindEnvironment.GetGame().GetRoomManager().GenerateNullableRoomData((UInt32)Visit["room_id"]);

            //            Message.AppendBoolean(RoomData.IsPublicRoom);
            //            Message.AppendUInt(RoomData.Id);
            //            Message.AppendString(RoomData.Name);

            //            if (Chatlogs != null)
            //            {
            //                Message.AppendInt32(Chatlogs.Rows.Count);

            //                foreach (DataRow Log in Chatlogs.Rows)
            //                {
            //                    Message.AppendInt32((int)Log["hour"]);
            //                    Message.AppendInt32((int)Log["minute"]);
            //                    Message.AppendUInt((UInt32)Log["user_id"]);
            //                    Message.AppendString((string)Log["user_name"]);
            //                    Message.AppendString((string)Log["message"]);
            //                }
            //            }
            //            else
            //            {
            //                Message.AppendInt32(0);
            //            }
            //        }
            //    }
            //    else
            //    {
            //        Message.AppendInt32(0);
            //    }

            //    return Message;
            // }
        }