protected virtual void OnMessageReceived(MessageEventArgs e) { Trace.Call(e); if (MessageReceived != null) { MessageReceived(this, e); } var hooks = new HookRunner("engine", "protocol-manager", "on-message-received"); hooks.Environments.Add(new ChatHookEnvironment(e.Chat)); var receiver = e.Receiver; if (String.IsNullOrEmpty(receiver)) { receiver = Me.ID; } hooks.Environments.Add(new MessageHookEnvironment(e.Message, e.Sender, receiver)); hooks.Environments.Add(new ProtocolManagerHookEnvironment(this)); var cmdChar = (string)Session.UserConfig["Interface/Entry/CommandCharacter"]; hooks.Commands.Add(new SessionHookCommand(Session, e.Chat, cmdChar)); hooks.Commands.Add(new ProtocolManagerHookCommand(this, e.Chat, cmdChar)); // show time hooks.Init(); hooks.Run(); }
protected virtual void OnDisconnected(EventArgs e) { Trace.Call(e); var msg = CreateMessageBuilder(); msg.AppendEventPrefix(); msg.AppendText(_("Disconnected from {0}"), NetworkID); Session.AddMessageToChat(Chat, msg.ToMessage()); _PresenceStatus = PresenceStatus.Offline; Session.UpdateNetworkStatus(); if (Disconnected != null) { Disconnected(this, e); } var hooks = new HookRunner("engine", "protocol-manager", "on-disconnected"); hooks.Environments.Add(new ChatHookEnvironment(Chat)); hooks.Environments.Add(new ProtocolManagerHookEnvironment(this)); var cmdChar = (string)Session.UserConfig["Interface/Entry/CommandCharacter"]; hooks.Commands.Add(new SessionHookCommand(Session, Chat, cmdChar)); hooks.Commands.Add(new ProtocolManagerHookCommand(this, Chat, cmdChar)); // show time hooks.Init(); hooks.Run(); }
protected virtual void OnPresenceStatusChanged(PresenceStatusChangedEventArgs e) { Trace.Call(e); if (PresenceStatusChanged != null) { PresenceStatusChanged(this, e); } var hooks = new HookRunner("engine", "protocol-manager", "on-presence-status-changed"); hooks.EnvironmentVariables.Add("PRESENCE_STATUS_CHANGED_OLD_STATUS", e.OldStatus.ToString()); hooks.EnvironmentVariables.Add("PRESENCE_STATUS_CHANGED_NEW_STATUS", e.NewStatus.ToString()); hooks.EnvironmentVariables.Add("PRESENCE_STATUS_CHANGED_NEW_MESSAGE", e.NewMessage); hooks.Environments.Add(new ProtocolManagerHookEnvironment(this)); var cmdChar = (string)Session.UserConfig["Interface/Entry/CommandCharacter"]; hooks.Commands.Add(new SessionHookCommand(Session, Chat, cmdChar)); hooks.Commands.Add(new ProtocolManagerHookCommand(this, Chat, cmdChar)); // show time hooks.Init(); hooks.Run(); }
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); }