Example #1
0
 /// <summary>
 /// Add a handler to capture a specific IRC code. This can be called from components that issue a command and are expecting
 /// some result code to be sent in the future.
 /// </summary>
 /// <param name="capture">An object encapsulating the handler and its options.</param>
 /// <remarks>
 /// A handler can prevent other components from processing a message. For example,
 /// a component that retrieves the hostname of a user with the USERHOST command can handle the response to prevent a client
 /// from displaying the result.
 /// </remarks>
 public void AddHandler(IrcCodeHandler capture)
 {
     lock (_captures)
     {
         _captures.Add(capture);
     }
 }
Example #2
0
 /// <summary>
 /// Remove a handler.
 /// </summary>
 /// <param name="capture">The handler to remove. This must be the same object that was added previously.</param>
 /// <returns>Returns true if the handler was removed, false if it had not been added.</returns>
 public bool RemoveHandler(IrcCodeHandler capture)
 {
     lock (_captures)
     {
         return(_captures.Remove(capture));
     }
 }
Example #3
0
        public ChatControl(ChatPageType type, IrcSession session, IrcTarget target)
            : base(type, session, target, type == ChatPageType.Server ? "server" : 
			(type == ChatPageType.DccChat ? "dcc-chat" : string.Format("{0}.{1}", session.NetworkName, target.Name).ToLowerInvariant()))
        {
            _history = new LinkedList<string>();
            _nickList = new NicknameList();

            InitializeComponent();

            var state = App.Settings.Current.Windows.States[this.Id];
            if (this.Type == ChatPageType.DccChat)
            {
                this.Header = string.Format("[CHAT] {0}", this.Target.Name);
            }
            else if (this.Type == ChatPageType.Chat || this.Type == ChatPageType.Server)
            {
                this.Header = this.Target == null ? "Server" : this.Target.ToString();
                this.SubscribeEvents();

                if (!this.IsServer)
                {
                    _logFile = App.OpenLogFile(this.Id);
                    var logLines = new List<ChatLine>();
                    while (_logFile.Buffer.Count > 0)
                    {
                        var cl = _logFile.Buffer.Dequeue();
                        cl.Marker = _logFile.Buffer.Count == 0 ? ChatMarker.OldMarker : ChatMarker.None;
                        logLines.Add(cl);
                    }
                    boxOutput.AppendBulkLines(logLines);
                }

                if (this.IsChannel)
                {
                    colNickList.MinWidth = MinNickListWidth;
                    colNickList.Width = new GridLength(state.NickListWidth);

                    this.Write("Join", string.Format("Now talking on {0}", this.Target.Name));
                    this.Session.AddHandler(new IrcCodeHandler((e) =>
                        {
                            if (e.Message.Parameters.Count > 2 &&
                                this.Target.Equals(new IrcTarget(e.Message.Parameters[1])))
                            {
                                _channelModes = e.Message.Parameters[2].ToCharArray().Where((c) => c != '+').ToArray();
                                this.SetTitle();
                            }
                            e.Handled = true;
                            return true;
                        }, IrcCode.RPL_CHANNELMODEIS));
                    this.Session.Mode(this.Target);
                    splitter.IsEnabled = true;

                    var nameHandler = new IrcCodeHandler((e) =>
                        {
                            if (e.Message.Parameters.Count >= 3)
                            {
                                var to = new IrcTarget(e.Message.Parameters[e.Message.Parameters.Count - 2]);
                                if (this.Target.Equals(to))
                                {
                                    _nickList.AddRange(e.Message.Parameters[e.Message.Parameters.Count - 1].Split(' ').
                                        Where((n) => n.Length > 0));
                                }
                            }
                            e.Handled = true;
                            return false;
                        }, IrcCode.RPL_NAMEREPLY);
                    this.Session.AddHandler(nameHandler);
                    this.Session.AddHandler(new IrcCodeHandler((e) =>
                        {
                            this.Session.RemoveHandler(nameHandler);
                            e.Handled = true;
                            return true;
                        }, IrcCode.RPL_ENDOFNAMES));
                }
                else if (this.IsNickname)
                {
                    _prefix = this.Target.Name;
                }
            }
            else
            {
                throw new ArgumentException("Page type is not supported.");
            }

            boxOutput.ColumnWidth = state.ColumnWidth;

            this.Loaded += new RoutedEventHandler(ChatControl_Loaded);
            this.Unloaded += new RoutedEventHandler(ChatControl_Unloaded);
            this.PrepareContextMenus();
            boxOutput.ContextMenu = this.GetDefaultContextMenu();
        }