Esempio n. 1
0
        private void DoExecute(CommandModel cmd)
        {
            Trace.Call(cmd);

            DateTime start, stop;

            start = DateTime.UtcNow;

            bool handled;

            handled = f_Session.Command(cmd);
            if (!handled)
            {
                // we maybe have no network manager yet
                IProtocolManager pm = cmd.Chat.ProtocolManager;
                if (pm != null)
                {
                    handled = pm.Command(cmd);
                }
                else
                {
                    handled = false;
                }
            }
            if (!handled)
            {
                Unknown(cmd);
            }

            stop = DateTime.UtcNow;
            f_LastCommandTimeSpan = (stop - start);
        }
Esempio n. 2
0
        private void DoExecute(CommandModel cmd)
        {
            Trace.Call(cmd);

            var handled = false;

            if (cmd.IsCommand)
            {
                switch (cmd.Command)
                {
                case "exec":
                    CommandExec(cmd);
                    handled = true;
                    break;

                case "echo":
                    CommandEcho(cmd);
                    handled = true;
                    break;

                case "benchmark_message_builder":
                    CommandBenchmarkMessageBuilder(cmd);
                    handled = true;
                    break;

                case "exception":
                    throw new Exception("You asked for it.");
                }
            }
            if (handled)
            {
                // no need to send the command to the engine
                return;
            }

            DateTime start, stop;

            start = DateTime.UtcNow;

            handled = f_Session.Command(cmd);
            IProtocolManager pm = null;

            if (!handled)
            {
                if (cmd.Chat is SessionChatModel && cmd.FrontendManager != null)
                {
                    pm = cmd.FrontendManager.CurrentProtocolManager;
                }
                else
                {
                    pm = cmd.Chat.ProtocolManager;
                }

                // we maybe have no network manager yet
                if (pm != null)
                {
                    handled = pm.Command(cmd);
                }
                else
                {
                    handled = false;
                }
            }
            if (!handled)
            {
                var filteredCmd = IOSecurity.GetFilteredPath(cmd.Command);
                var hooks       = new HookRunner("frontend", "command-manager",
                                                 "command-" + filteredCmd);
                hooks.EnvironmentVariables.Add("FRONTEND_VERSION", FrontendVersion);
                hooks.Environments.Add(new CommandHookEnvironment(cmd));
                hooks.Environments.Add(new ChatHookEnvironment(cmd.Chat));
                if (pm != null)
                {
                    hooks.Environments.Add(new ProtocolManagerHookEnvironment(pm));
                }

                var cmdChar = (string)f_Session.UserConfig["Interface/Entry/CommandCharacter"];
                hooks.Commands.Add(new SessionHookCommand(f_Session, cmd.Chat, cmdChar));
                if (pm != null)
                {
                    hooks.Commands.Add(new ProtocolManagerHookCommand(pm, cmd.Chat, cmdChar));
                }

                // show time
                hooks.Init();
                if (hooks.HasHooks)
                {
                    hooks.Run();
                    handled = true;
                }
            }
            if (!handled)
            {
                Unknown(cmd);
            }

            stop = DateTime.UtcNow;
            f_LastCommandTimeSpan = (stop - start);
        }