Ejemplo n.º 1
0
        /// <summary>
        /// Overrides Update from BaseClient to trigger advertising in intervals.
        /// </summary>
        public override void Update()
        {
            base.Update();

            // Try send an available WhoXQuery.
            if (WhoXQueryQueue.TryDequeue(out string command))
            {
                SendWhoXQuery(command);
            }

            if (IRCSendQueue.TryDequeue(out IrcMessage ircMessage))
            {
                IrcClient.SendMessage(ircMessage.Message, ircMessage.Name);
            }

            // execute the chatcommands - this is all which work in the 3d client also
            // like tell, say, broadcast - but also "dm", "getplayer" etc.
            while (ChatCommandQueue.TryDequeue(out command))
            {
                ExecChatCommand(command);
            }

            // these are admin textcommands without a prefix, just plain was written in adminconsole
            while (AdminCommandQueue.TryDequeue(out command))
            {
                SendReqAdminMessage(command);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Overrides Update from BaseClient to trigger advertising in intervals.
        /// </summary>
        public override void Update()
        {
            base.Update();

            string command;

            // execute the chatcommands - this is all which work in the 3d client also
            // like tell, say, broadcast - but also "dm", "getplayer" etc.
            while (ChatCommandQueue.TryDequeue(out command))
            {
                ExecChatCommand(command);
            }

            // these are admin textcommands without a prefix, just plain was written in adminconsole
            while (AdminCommandQueue.TryDequeue(out command))
            {
                SendReqAdminMessage(command);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Invoked when a channel message was received
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void OnMessageReceived(object sender, IrcMessageEventArgs e)
        {
            // ignore messages without @prefix start or which are only @prefix + @ + space length
            if (e.Text == null || e.Text.IndexOf("@" + Config.ChatPrefix) != 0 || e.Text.Length <= Config.ChatPrefix.Length + 1 + 1)
            {
                return;
            }

            // try get channeluser by name
            IrcChannelUser usr = GetChannelUser(e.Source.Name);

            if (usr == null)
            {
                return;
            }

            // only allow operators
            if (!usr.Modes.Contains('o'))
            {
                // respond user he can't use this feature
                IrcClient.LocalUser.SendMessage(
                    IrcChannel,
                    e.Source.Name + " you can't use this feature. Only operators allowed.");

                return;
            }

            // now remove the @103 start
            string s = e.Text.Substring(Config.ChatPrefix.Length + 1 + 1);

            // used delimiter
            const char delimiter = ' ';

            // split up into words
            string[] words = s.Split(delimiter);

            if (words.Length > 0)
            {
                switch (words[0])
                {
                case ChatCommandBroadcast.KEY1:
                case ChatCommandBroadcast.KEY2:

                    // keep first word
                    s = String.Join(delimiter.ToString(), words, 0, 1);

                    // insert banner + name
                    s += delimiter + Config.Banner;
                    s += e.Source.Name + ": ~n";

                    // add rest
                    s += String.Join(delimiter.ToString(), words, 1, words.Length - 1);
                    break;

                case ChatCommandTell.KEY1:
                case ChatCommandTell.KEY2:

                    // keep first two word
                    s = String.Join(delimiter.ToString(), words, 0, 2);

                    // insert banner + name
                    s += delimiter + Config.Banner;
                    s += e.Source.Name + ": ~n";

                    // add rest
                    s += String.Join(delimiter.ToString(), words, 2, words.Length - 2);
                    break;
                }
            }

            // enqueue it for execution
            ChatCommandQueue.Enqueue(s);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Invoked when a channel message was received
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void OnMessageReceived(object sender, IrcMessageEventArgs e)
        {
            // Ignore message whose length is just @prefix + @ + space length.
            if (e.Text == null || e.Text.Length <= Config.ChatPrefix.Length + 1 + 1)
            {
                return;
            }

            // try get channeluser by name
            IrcChannelUser usr = GetChannelUser(e.Source.Name);

            if (usr == null)
            {
                return;
            }

            string s                 = String.Empty;
            string banner            = String.Empty;
            string ignoreSystemRegex = String.Empty;
            bool   relayMsg          = false;

            // Relay messages from allowed chatbots
            foreach (var relayBot in Config.RelayBots)
            {
                if (relayBot.Name.Contains(e.Source.Name))
                {
                    // Sanity check for our own name
                    if (e.Source.Name.Equals(Config.NickName))
                    {
                        return;
                    }

                    // Convert the IRC colors back to server styles/colors.
                    s = IRCChatStyle.CreateChatMessageFromIRCMessage(e.Text);

                    // Ignore any messages containing...
                    if (!String.IsNullOrEmpty(relayBot.IgnoreAllRegex) && (Regex.Match(s, relayBot.IgnoreAllRegex)).Success)
                    {
                        return;
                    }

                    // Banner is the second string in the tuple.
                    banner            = relayBot.Banner;
                    ignoreSystemRegex = relayBot.IgnoreSystemRegex;

                    relayMsg = true;
                    break;
                }
            }

            if (!relayMsg)
            {
                // Ignore messages without @prefix start.
                if (!relayMsg && e.Text.IndexOf("@" + Config.ChatPrefix) != 0)
                {
                    return;
                }

                // only allowed users and admins can use the bot
                if (!(Config.AllowedUsers.Contains(e.Source.Name) ||
                      Config.Admins.Contains(e.Source.Name)))
                {
                    // respond user he can't use this feature
                    IrcClient.LocalUser.SendMessage(
                        IrcChannel,
                        e.Source.Name + " you can't use this feature.");

                    return;
                }

                if (!IsUserRegistered(e.Source.Name))
                {
                    // Must have registered nickname.
                    IrcClient.LocalUser.SendMessage(IrcChannel,
                                                    e.Source.Name + " you must register your nickname to use this feature.");

                    return;
                }

                // now remove the @103 start
                s = e.Text.Substring(Config.ChatPrefix.Length + 1 + 1);
            }

            // used delimiter
            const char delimiter = ' ';

            // split up into words
            string[] words = s.Split(delimiter);

            if (words.Length > 0)
            {
                if (Util.IsDisallowedDMCommand(words[0]))
                {
                    IrcClient.LocalUser.SendMessage(
                        IrcChannel,
                        e.Source.Name + " you can't use this feature. This incident has been logged.");
                    foreach (string admin in Config.Admins)
                    {
                        // try get channeluser by name
                        usr = GetChannelUser(admin);

                        // online? send!
                        if (usr != null)
                        {
                            IrcClient.LocalUser.SendMessage(admin, String.Format("IRC User {0} has attempted to use a DM command", e.Source.Name));
                        }
                    }
                    return;
                }
                else if (words.Length > 3 && relayMsg)
                {
                    // First word is the server's header (e.g. 103:) so don't use it.
                    if (words[1].Contains("[###]"))
                    {
                        // Ignore system messages containing....
                        if (!String.IsNullOrEmpty(ignoreSystemRegex) && (Regex.Match(s, ignoreSystemRegex)).Success)
                        {
                            return;
                        }

                        // Adjust the color codes to display [###] correctly, drop the
                        // existing [###] and add a fixed one here. Doesn't seem to be
                        // possible to fix the one in the message itself.
                        s  = "dm gqemote " + banner + " ~U[###]~n ~U";
                        s += String.Join(delimiter.ToString(), words, 2, words.Length - 2);
                    }
                    else if ((Regex.Match(s, @"(broadcasts,|teilt allen)")).Success)
                    {
                        // Add server header, echo message.
                        s  = "dm gqemote " + banner + " ~n~w";
                        s += String.Join(delimiter.ToString(), words, 1, words.Length - 1);
                    }
                    else if (words[1].Contains("You") && words[2].Contains("broadcast,"))
                    {
                        // Echo messages that the other bot broadcasts to its server.
                        s  = "dm gqemote " + banner + " ~n~wHelp broadcasts,";
                        s += String.Join(delimiter.ToString(), words, 3, words.Length - 3);
                    }
                    else if (words.Length > 5 && words[1].Contains("Du") && words[3].Contains("allen"))
                    {
                        // German bot broadcasting to its server, echo the German translation.
                        s  = "dm gqemote " + banner + " ~n~wHelp teilt allen mit,";
                        s += String.Join(delimiter.ToString(), words, 5, words.Length - 5);
                    }
                }
                else
                {
                    switch (words[0])
                    {
                    case ChatCommandBroadcast.KEY1:
                    case ChatCommandBroadcast.KEY2:

                        // keep first word
                        s = String.Join(delimiter.ToString(), words, 0, 1);

                        // insert banner + name
                        s += delimiter + Config.Banner;
                        s += e.Source.Name + ": ~n";

                        // add rest
                        s += String.Join(delimiter.ToString(), words, 1, words.Length - 1);
                        break;

                    case ChatCommandTell.KEY1:
                    case ChatCommandTell.KEY2:

                        // keep first two word
                        s = String.Join(delimiter.ToString(), words, 0, 2);

                        // insert banner + name
                        s += delimiter + Config.Banner;
                        s += e.Source.Name + ": ~n";

                        // add rest
                        s += String.Join(delimiter.ToString(), words, 2, words.Length - 2);
                        break;
                    }
                }
            }

            // enqueue it for execution
            ChatCommandQueue.Enqueue(s);
        }