Ejemplo n.º 1
0
        public override void Handle(Connection connection)
        {
            if (Program.DelayManager.AddAndCheck(connection, DelayManager.Database))
                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;

            List<HistoryLine> lines;
            if (Util.DateTimeFromTimestamp(AfterDate) < (DateTime.UtcNow - Util.MaximumHistoryRequest))
            {
                lines = new List<HistoryLine>();
            }
            else
            {
                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;

                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);
        }
Ejemplo n.º 2
0
 private void ClearScrollbackFor(Connection connection)
 {
     var chatHistory = new ChatHistory { ShortName = RoomInfo.ShortName, Requested = false, Lines = new List<HistoryLine>() };
     connection.Send(chatHistory);
 }
Ejemplo n.º 3
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;
                }
            }

            var lines = GetHistoryLines(connection);
            var chatHistory = new ChatHistory { ShortName = RoomInfo.ShortName, Requested = false, Lines = lines };
            connection.Send(chatHistory);
        }
Ejemplo n.º 4
0
        public override void Handle(Connection connection)
        {
            if (Program.DelayManager.AddAndCheck(connection, DelayManager.Database))
            {
                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;
            }

            List <HistoryLine> lines;

            if (Util.DateTimeFromTimestamp(AfterDate) < (DateTime.UtcNow - Util.MaximumHistoryRequest))
            {
                lines = new List <HistoryLine>();
            }
            else
            {
                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;

                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);
        }