Esempio n. 1
0
        public static String FilterBefore(IUser client, String text)
        {
            String ip = client.ExternalIP.ToString();

            foreach (Item item in list)
            {
                string trigger = Regex.Escape(item.Trigger);
                trigger = trigger.Replace("\\?", ".").Replace("\\*", ".*");
                Regex regex = new Regex(trigger, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);

                if (regex.IsMatch(text))
                {
                    switch (item.Type)
                    {
                    case FilterType.Muzzle:
                        if (client.Link.IsLinked && client.Level == ILevel.Regular)
                        {
                            return(String.Empty);
                        }
                        else if (client.Level == ILevel.Regular)
                        {
                            Server.Print(Template.Text(Category.Filter, 9).Replace("+n", client.Name), true);
                            LogSend.Log(LOGFILE, $"{client.Name} muzzled for typing {item.Trigger}");

                            client.Muzzled = true;
                            Muzzles.AddMuzzle(client);     // Adding this fixes bug where they can rejoin to remove muzzle
                            return(String.Empty);
                        }
                        break;

                    case FilterType.Kill:
                        if (client.Link.IsLinked && client.Level == ILevel.Regular)
                        {
                            return(String.Empty);
                        }
                        else if (client.Level == ILevel.Regular)
                        {
                            Server.Print(Template.Text(Category.Filter, 10).Replace("+n", client.Name), true);
                            LogSend.Log(LOGFILE, $"{client.Name} killed for typing {item.Trigger}");
                            client.Disconnect();
                            return(String.Empty);
                        }
                        break;

                    case FilterType.Ban:
                        if (client.Link.IsLinked && client.Level == ILevel.Regular)
                        {
                            return(String.Empty);
                        }
                        else if (client.Level == ILevel.Regular)
                        {
                            Server.Print(Template.Text(Category.Filter, 11).Replace("+n", client.Name), true);
                            LogSend.Log(LOGFILE, $"{client.Name} banned for typing {item.Trigger}");
                            client.Ban();
                            return(String.Empty);
                        }
                        break;

                    case FilterType.Censor:
                        if (client.Link.IsLinked && client.Level == ILevel.Regular)
                        {
                            return(String.Empty);
                        }
                        else if (client.Level == ILevel.Regular)
                        {
                            client.Print(Template.Text(Category.Filter, 12).Replace("+n", client.Name));
                            LogSend.Log(LOGFILE, $"{client.Name} censored for typing {item.Trigger}");
                            return(String.Empty);
                        }
                        break;

                    case FilterType.Move:
                        if (client.Link.IsLinked && client.Level == ILevel.Regular)
                        {
                            return(String.Empty);
                        }
                        else if (client.Level == ILevel.Regular)
                        {
                            ushort u;

                            if (ushort.TryParse(item.Args, out u))
                            {
                                Server.Print(Template.Text(Category.Filter, 13).Replace("+n", client.Name), true);
                                LogSend.Log(LOGFILE, $"{client.Name} moved for typing {item.Trigger}");
                                client.Vroom = u;
                            }

                            return(String.Empty);
                        }
                        break;

                    case FilterType.Redirect:
                        if (client.Link.IsLinked && client.Level == ILevel.Regular)
                        {
                            return(String.Empty);
                        }
                        else if (client.Level == ILevel.Regular)
                        {
                            Server.Print(Template.Text(Category.Filter, 14).Replace("+n", client.Name), true);
                            LogSend.Log(LOGFILE, $"{client.Name} redirected for typing {item.Trigger}");
                            client.Redirect(item.Args);
                            client.Disconnect();
                            return(String.Empty);
                        }
                        break;

                    case FilterType.Announce:
                        if (Settings.AdminAnnounce)
                        {
                            if (client.Level == ILevel.Regular)
                            {
                                break;
                            }
                        }

                        if (client.Level > ILevel.Regular)
                        {
                            if (text.StartsWith("#addline") || text.StartsWith("#remline") ||
                                text.StartsWith("#addwordfilter"))
                            {
                                break;
                            }
                        }

                        String[] lines = item.Args.Split(new String[] { "\r\n" }, StringSplitOptions.None);
                        String   reply = String.Empty;

                        if (text.StartsWith(item.Trigger) && text.Length > item.Trigger.Length)
                        {
                            reply = text.Substring(item.Trigger.Length + 1);
                        }

                        foreach (String str in lines)
                        {
                            Server.Print(str.Replace("+n", client.Name).Replace("+ip", ip).Replace("+r", reply),
                                         true);
                        }
                        break;

                    case FilterType.Replace:
                        if (client.Level == ILevel.Regular)
                        {
                            text = Regex.Replace(text, Regex.Escape(item.Trigger), item.Args,
                                                 RegexOptions.IgnoreCase);
                        }
                        break;

                    case FilterType.Scribble:
                        if (!client.WebClient && !client.Link.IsLinked && !text.StartsWith("#addwordfilter"))
                        {
                            uint time = Server.Time;

                            if (client.Level > ILevel.Regular || (time >= (client.LastScribble + 30)))
                            {
                                client.LastScribble = time;
                                String html = "<img src=\"" + item.Args +
                                              "\" style=\"max-width: 320px; max-height: 320px;\" alt=\"\" />";

                                Server.Users.Ares(x =>
                                {
                                    if (x.Vroom == client.Vroom && !x.Quarantined &&
                                        x.SupportsHTML && !x.IgnoreList.Contains(client.Name))
                                    {
                                        x.SendHTML(html);
                                    }
                                });
                            }
                        }
                        break;
                    }
                }
            }

            return(text);
        }
Esempio n. 2
0
        public static void FilterPM(IUser client, IPrivateMsg msg)
        {
            String ip = client.ExternalIP.ToString();

            foreach (Item item in list)
            {
                string trigger = Regex.Escape(item.Trigger);
                trigger = trigger.Replace("\\?", ".").Replace("\\*", ".*");
                Regex regex = new Regex(trigger, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);

                if (regex.IsMatch(item.Trigger))
                {
                    switch (item.Type)
                    {
                    case FilterType.Ban:
                        if (client.Level == ILevel.Regular)
                        {
                            if (!client.Link.IsLinked)
                            {
                                Server.Print(
                                    Template.Text(Category.Filter, 16).Replace("+n", client.Name).Replace("+ip", ip),
                                    true);
                                LogSend.Log(LOGFILE, $"{client.Name} banned for typing {item.Trigger} in PM");
                                client.Ban();
                            }

                            msg.Cancel = true;
                            return;
                        }
                        break;

                    case FilterType.Kill:
                        if (client.Level == ILevel.Regular)
                        {
                            if (!client.Link.IsLinked)
                            {
                                Server.Print(
                                    Template.Text(Category.Filter, 15).Replace("+n", client.Name).Replace("+ip", ip),
                                    true);
                                LogSend.Log(LOGFILE, $"{client.Name} killed for typing {item.Trigger} in PM");
                                client.Disconnect();
                            }

                            msg.Cancel = true;
                            return;
                        }
                        break;

                    case FilterType.Redirect:
                        if (client.Level == ILevel.Regular)
                        {
                            if (!client.Link.IsLinked)
                            {
                                Server.Print(
                                    Template.Text(Category.Filter, 17).Replace("+n", client.Name).Replace("+ip", ip),
                                    true);
                                LogSend.Log(LOGFILE, $"{client.Name} redirected for typing {item.Trigger} in PM");
                                client.Redirect(item.Args);
                            }

                            msg.Cancel = true;
                            return;
                        }
                        break;
                    }
                }
            }
        }
Esempio n. 3
0
        public static bool IsPreFiltered(IUser client)
        {
            String ip = client.ExternalIP.ToString();
            ushort u;

            foreach (Item item in list)
            {
                string trigger = Regex.Escape(item.Trigger);
                trigger = trigger.Replace("\\?", ".").Replace("\\*", ".*");
                Regex regex = new Regex(trigger, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);

                switch (item.Type)
                {
                case FilterType.Censor:
                    if (regex.IsMatch(client.Name))
                    {
                        client.Name = Regex.Replace(client.Name, Regex.Escape(item.Trigger), String.Empty, RegexOptions.IgnoreCase);
                    }
                    break;

                case FilterType.PortBan:
                    if (ushort.TryParse(item.Trigger, out u))
                    {
                        if (client.DataPort == u)
                        {
                            LogSend.Log(LOGFILE, $"{client.Name} banned by PortBan. Filter: {item.Trigger}");
                            return(true);
                        }
                    }
                    break;

                case FilterType.IPBan:
                    if (ip.StartsWith(item.Trigger))
                    {
                        LogSend.Log(LOGFILE, $"{client.Name} banned by IPBAN. Filter: {item.Trigger}");
                        return(true);
                    }
                    break;

                case FilterType.NameBan:
                    if (regex.IsMatch(client.Name))
                    {
                        LogSend.Log(LOGFILE, $"{client.Name} banned by NameBan. Filter: {item.Trigger}");
                        return(true);
                    }
                    break;

                case FilterType.DNSBan:
                    if (regex.IsMatch(client.DNS))
                    {
                        LogSend.Log(LOGFILE, $"{client.Name} banned by DNSBan. Filter: {item.Trigger}");
                        return(true);
                    }
                    break;

                case FilterType.Move:
                    if (regex.IsMatch(client.Name) || ip.StartsWith(item.Trigger))
                    {
                        if (ushort.TryParse(item.Args, out u))
                        {
                            client.Vroom = u;
                        }
                    }
                    break;

                case FilterType.Redirect:
                    if (regex.IsMatch(client.Name) || ip.StartsWith(item.Trigger))
                    {
                        LogSend.Log(LOGFILE, $"{client.Name} redirected by filter. Filter: {item.Trigger}");
                        client.Redirect(item.Args);
                        return(true);
                    }
                    break;

                case FilterType.ChangeName:
                    if (regex.IsMatch(client.Name) || ip.StartsWith(item.Trigger))
                    {
                        client.Name = item.Args;
                    }
                    break;

                case FilterType.VersionBan:
                    if (regex.IsMatch(client.Version))
                    {
                        LogSend.Log(LOGFILE, $"{client.Name} banned by VersionBan. Filter: {item.Trigger}");
                        return(true);
                    }
                    break;
                }
            }

            return(false);
        }