Exemplo n.º 1
0
        public void CheckChatConditional(object sender, Connection.ChatEventArgs e = null)
        {
            if (!CanRunCommandOnConnection(e.Connection))
            {
                return;
            }

            switch (ConditionType)
            {
            case TriggerType.CustomServerCommand:
                #region

                if (e.Message.StartsWith(CustomServerCommand))
                {
                    RunCommands(e);
                }

                #endregion
                break;

            default: break;
            }
        }
Exemplo n.º 2
0
        public void RunCommands(Connection.ChatEventArgs e = null)
        {
            foreach (string command in CommandStrings)
            {
                string formatted = command.Trim();
                formatted = ParseResult.ReplaceDynamicReferences(formatted, Connection);
                if (command.Trim().StartsWith("!") || command.Trim().StartsWith("%"))
                {
                    if (command.Trim().StartsWith("!!"))
                    {
                        formatted = formatted.TrimStart("@".ToCharArray()); // I don't remember why this is necessary
                    }
                    else
                    {
                        // Remove the command-enclosing '%' characters
                        formatted = command.RemoveFirst('%', 2);
                    }
                    while (formatted.StartsWith("!"))
                    {
                        // Remove '!' characters
                        formatted = formatted.Remove(0, 1);
                    }

                    if (RuntimeCommand.StringStartsWithCommandName(formatted))
                    {
                        RuntimeCommand.TryRunCommand($"!{formatted}", null, Connection);
                    }
                    else
                    {
                        Connection.RconCommandQueue.Enqueue(
                            RconCommand.ConsoleLogCommand(
                                formatted, formatted,
                                e?.SendingPlayer?.Name ?? "SERVER"
                                )
                            );
                    }
                }
                else
                {
                    if (formatted.StartsWith("!"))
                    {
                        if (RuntimeCommand.StringStartsWithCommandName(formatted.TrimStart(1)))
                        {
                            RuntimeCommand.TryRunCommand(formatted, null, Connection);
                        }
                        else
                        {
                            Connection.RconCommandQueue.Enqueue(
                                RconCommand.ConsoleLogCommand(
                                    formatted, formatted,
                                    e?.SendingPlayer?.Name ?? "SERVER"
                                    )
                                );
                        }
                    }
                    else
                    {
                        if (RuntimeCommand.StringStartsWithCommandName(formatted))
                        {
                            RuntimeCommand.TryRunCommand($"!{formatted}", null, Connection);
                        }
                        else
                        {
                            Connection.RconCommandQueue.Enqueue(
                                RconCommand.ConsoleLogCommand(
                                    formatted, formatted,
                                    e?.SendingPlayer?.Name ?? "SERVER"
                                    )
                                );
                        }
                    }
                }
            }
        }