Пример #1
0
        public override void Handle(Connection connection)
        {
            if (Program.DelayManager.AddAndCheck(connection, 2.5))
                return;

            if (connection.Session == null)
            {
                connection.SendSysMessage("You need to be logged in to do that.");
                return;
            }

            if (!connection.Session.IsInRoom(Target))
            {
                connection.SendSysMessage("You are not in that room.");
                return;
            }

            var room = Program.RoomManager.Get(Target);
            if (room == null)
            {
                connection.SendSysMessage("Room does not exist.");
                return;
            }

            if (room.IsPrivate && room.IsBanned(connection.Session.Account.Name))
                return;

            var cmd = new SqlCommand("SELECT * FROM rohbot.chathistory WHERE chat=lower(:chat) AND date<:afterdate ORDER BY date DESC LIMIT 100;");
            cmd["chat"] = Target;
            cmd["afterdate"] = AfterDate;

            var lines = cmd.Execute().Select(r => (HistoryLine)HistoryLine.Read(r)).ToList();
            lines.Reverse();

            if (lines.Count == 0)
                lines.Add(new ChatLine(0, Target, "Steam", Program.Settings.PersonaName, "0", "", "No additional history is available.", false));

            var history = new ChatHistory
            {
                ShortName = room.RoomInfo.ShortName,
                Requested = true,
                Lines = lines
            };

            connection.Send(history);
        }
Пример #2
0
        public override void Handle(Session session)
        {
            if (Program.DelayManager.AddAndCheck(session, 2.5))
                return;

            var room = Program.RoomManager.Get(session.Room);
            if (room == null)
            {
                session.SendSysMessage("Room does not exist.");
                return;
            }

            if (room.IsPrivate)
            {
                if (session.Account == null || room.IsBanned(session.Account.Name))
                    return;
            }

            List<HistoryLine> lines;

            if (Util.DateTimeFromUnixTimestamp(AfterDate) > DateTime.UtcNow.AddDays(-7))
            {
                var cmd = new SqlCommand("SELECT * FROM rohbot.chathistory WHERE chat=lower(:chat) AND date<:afterdate ORDER BY date DESC LIMIT 100;");
                cmd["chat"] = session.Room;
                cmd["afterdate"] = AfterDate;
                lines = cmd.Execute().Select(r => (HistoryLine)HistoryLine.Read(r)).Reverse().ToList();
            }
            else
            {
                lines = new List<HistoryLine>();
            }

            var history = new ChatHistory
            {
                Name = room.RoomInfo.Name,
                ShortName = room.RoomInfo.ShortName,
                Requested = true,
                Lines = lines
            };

            session.Send(history);
        }
Пример #3
0
 private void ClearScrollbackFor(Session session)
 {
     var chatHistory = new ChatHistory { Name = RoomInfo.Name, ShortName = RoomInfo.ShortName, Requested = false, Lines = new List<HistoryLine>() };
     session.Send(chatHistory);
 }
Пример #4
0
        /// <summary>
        /// Called when somebody joins the room. Should call base.
        /// </summary>
        public virtual void SendHistory(Session session)
        {
            if (IsPrivate)
            {
                if (session.Account == null)
                {
                    ClearScrollbackFor(session);
                    session.SendSysMessage("You must login to view this room.");
                    return;
                }

                if (IsBanned(session.Account.Name))
                {
                    ClearScrollbackFor(session);
                    session.SendSysMessage("You are banned from this room. To view it you must be unbanned (or whitelisted).");
                    return;
                }
            }

            lock (_history)
            {
                var chatHistory = new ChatHistory { Name = RoomInfo.Name, ShortName = RoomInfo.ShortName, Requested = false, Lines = _history.ToList() };
                session.Send(chatHistory);
            }
        }
Пример #5
0
 private void ClearScrollbackFor(Connection connection)
 {
     var chatHistory = new ChatHistory { ShortName = RoomInfo.ShortName, Requested = false, Lines = new List<HistoryLine>() };
     connection.Send(chatHistory);
 }
Пример #6
0
        /// <summary>
        /// Called when somebody joins the room. Should call base.
        /// </summary>
        public virtual void SendHistory(Connection connection)
        {
            if (IsPrivate)
            {
                if (connection.Session == null)
                {
                    ClearScrollbackFor(connection);
                    connection.SendSysMessage("You must login to view this room.");
                    return;
                }

                if (IsBanned(connection.Session.Account.Name))
                {
                    ClearScrollbackFor(connection);
                    connection.SendSysMessage("You are banned from this room.");
                    return;
                }
            }

            lock (_history)
            {
                var chatHistory = new ChatHistory { ShortName = RoomInfo.ShortName, Requested = false, Lines = _history };
                connection.Send(chatHistory);
            }
        }