HandleMessage() public method

Do any channel level processing required for the message.
public HandleMessage ( Message message ) : void
message Yaircc.Net.IRC.Message The message to process.
return void
Beispiel #1
0
        /// <summary>
        /// Process a message that contains a text based command.
        /// </summary>
        /// <param name="message">The message to process.</param>
        private void ProcessMessage(Message message)
        {
            message = MessageFactory.AssimilateMessage(message);
            string target = message.Target.Equals(this.Connection.Nickname, StringComparison.OrdinalIgnoreCase) ? message.Source : message.Target;

            if (message.MustBeHandledByTarget)
            {
                IRCChannel channel = this.Channels.Find(i => i.Name.Equals(target, StringComparison.OrdinalIgnoreCase));
                if (channel == null)
                {
                    channel = this.CreateChannel(target, false);
                }

                channel.HandleMessage(message);
            }
            else if (message.IsMultiChannelMessage)
            {
                for (int i = 0; i < this.Channels.Count; i++)
                {
                    this.Channels[i].HandleMessage(message);
                }
            }
            else if (message.IsGlobalMessage)
            {
                this.Channels.ForEach(i => i.HandleMessage(message));
                this.ServerTab.AppendMessage(message.Command, message.Source, message.Content, message.Type);
            }
            else
            {
                // If the message can be handled by both the server tab
                // and a channel tab, then we need to check if the currently
                // focused tab is a channel and if so handle it in the channel.
                // Otherwise we can just print it in the server tab
                this.TabHost.InvokeAction(() =>
                    {
                        if (this.TabHost.SelectedTab is IRCTabPage)
                        {
                            IRCChannel channel = this.Channels.Find(i => i.TabPage.Equals(this.TabHost.SelectedTab));
                            if ((channel != null) && (!this.AwaitingModeMessage))
                            {
                                channel.HandleMessage(message);
                            }
                            else
                            {
                                this.ServerTab.AppendMessage(message.Command, message.Source, message.Content, message.Type);
                            }
                        }
                    });
            }

            // If we are still awaiting the MODE message (i.e. we are awaiting confirmation we have finished connecting)
            // then also re-join any channels that we have in the Channels collection (i.e. reconnect to any channels)
            if (this.AwaitingModeMessage && message is ModeMessage)
            {
                this.AwaitingModeMessage = false;
                this.Send(this.ServerTab, new ModeMessage(new string[] { this.Connection.Nickname, this.Connection.Mode }));

                // Send the user host message so we can determine the full user host string.
                this.Send(this.ServerTab, new UserHostMessage(new string[] { this.connection.Nickname }));
            }
        }