Example #1
0
        public IRCChannel(IRCConnection pConnection, string pChannelName)
        {
            connection = pConnection;
            channelName = pChannelName;

            // plug into connection's events
            connectionGotMessage = new IRCConnection.MessageEventHandler(ConnectionGotMessage);
            connection.GotMessage += connectionGotMessage;
            connectionSentMessage = new IRCConnection.MessageEventHandler(ConnectionSentMessage);
            connection.SentMessage += connectionSentMessage;
        }
Example #2
0
 private void ChannelGotMessage(object sender, IRCConnection.MessageEventArgs e)
 {
     if (e.Message.IsSenderLocal)
     {
         Log(e.Message.ToShortString(), Color.DarkGreen);
     }
     else
     {
         Log(e.Message.ToShortString(), Color.Black);
     }
 }
Example #3
0
        public IRCManager(IRCConnection pConnection, IRCServer pServer, IRCLogInDetails pLogIn)
        {
            connection = pConnection;
            server = pServer;
            logininfo = pLogIn;

            // plug into IRCConnection's events
            connectionMade = new EventHandler(ConnectionMade);
            connection.Connected += connectionMade;
            connectionClosed = new EventHandler(ConnectionClosed);
            connection.ConnectionClosed += connectionClosed;
            connectionGotMessage = new IRCConnection.MessageEventHandler(ConnectionGotMessage);
            connection.GotMessage += connectionGotMessage;
            connectionSentMessage = new IRCConnection.MessageEventHandler(ConnectionSentMessage);
        }
Example #4
0
        private void ConnectionSentMessage(object sender, IRCConnection.MessageEventArgs e)
        {
            IRCMessage msg = e.Message;

            // process depending on message type
            switch (msg.MessageTypeID.ToUpper())
            {
                case IRCConstants.MSG_JOIN:
                    {
                        if (msg.Parameters.Count <= 0)
                            return;

                        string channelName = msg.Parameters[0].ToString().ToLower();    // extract name of the channel
                        // if we already are in channel, we can ignore
                        if (channels.ContainsKey(channelName))
                            return;

                        // join channel and notify listeners
                        IRCChannel channel = JoinChannel(channelName);
                        if (JoinedChannel != null)
                            JoinedChannel(this, new ChannelEventArgs(channel));
                        break;
                    }

                case IRCConstants.MSG_PART:
                    {
                        if (msg.Parameters.Count <= 0)
                            return;

                        string channelName = msg.Parameters[0].ToString().ToLower();    // extract name of the channel
                        // if we are not in the concerned channel, we can ignore
                        if (!channels.ContainsKey(channelName))
                            return;

                        // retrieve channel and leave
                        IRCChannel channel = channels[channelName] as IRCChannel;
                        channel.Dispose();
                        channels.Remove(channelName);
                        // notify listeners, if neccessary
                        if (LeftChannel != null)
                            LeftChannel(this, new ChannelEventArgs(channel));
                        break;
                    }
            }
        }
Example #5
0
        private void ConnectionGotMessage(object sender, IRCConnection.MessageEventArgs e)
        {
            IRCMessage msg = e.Message;

            // process depending on message type
            switch (msg.MessageTypeID.ToUpper())
            {
                case IRCConstants.MSG_JOIN:
                    {
                        if (string.Compare(msg.SenderNode.Nickname, connection.LocalIRCNode.Nickname, true) == 0)
                        {   // check if WE sent the message
                            if (msg.Parameters.Count <= 0)
                                return;

                            string channelName = msg.Parameters[0].ToString().ToLower();    // extract name of the channel
                            /*
                            string channelName = msg.Body.ToLower();    // extract name of the channel
                             * */

                            // if we already are in the channel, we can ignore the message
                            if (channels.ContainsKey(channelName))
                                return;

                            // otherwise, we join the channel and add it to our channels
                            IRCChannel channel = JoinChannel(channelName);
                            if (JoinedChannel != null)
                                JoinedChannel(this, new ChannelEventArgs(channel));
                        }
                        break;
                    }

                case IRCConstants.MSG_PART:
                    {
                        if (string.Compare(msg.SenderNode.Nickname, connection.LocalIRCNode.Nickname, true) == 0)
                        {   // check if WE sent the message
                            string channelName = msg.Parameters[0].ToString().ToLower();    // extract name of the channel

                            // if it's not for this channel, we can ignore
                            if (!channels.ContainsKey(channelName))
                                return;

                            // otherwise, retrieve channel and leave it
                            IRCChannel channel = channels[channelName] as IRCChannel;
                            channel.Dispose();
                            channels.Remove(channelName);
                            if (LeftChannel != null)
                                LeftChannel(this, new ChannelEventArgs(channel));
                        }
                        break;
                    }

                case IRCConstants.MSG_KICK:
                    {
                        if (    (msg.Parameters.Count > 1) &&
                                (string.Compare(msg.Parameters[1].ToString(), connection.Nickname, true) == 0))
                        {
                            string channelName = msg.Parameters[0].ToString().ToLower();    // extract name of the channel

                            // otherwise, retrieve channel and leave it
                            IRCChannel channel = channels[channelName] as IRCChannel;
                            channel.Dispose();
                            channels.Remove(channelName);
                            if (KickedFromChannel != null)
                                KickedFromChannel(this, new ChannelEventArgs(channel));
                        }
                        break;
                    }

                case IRCConstants.MSG_PRIVMSG:
                    {
                        if (    (msg.Parameters.Count > 0) &&   // syntax
                                (string.Compare(msg.Parameters[0].ToString(), connection.Nickname, true) == 0) &&   // PM to user
                                (GotPrivateMessage != null) &&  // trigger neccessary
                                (!privatechats.ContainsKey(msg.SenderNode.Nickname.ToLower()))) // PM-Chat does not exist yet
                        {
                            GotPrivateMessage(this, new IRCConnection.MessageEventArgs(msg));
                        }
                        break;
                    }

                case IRCConstants.MSG_403:
                    {
                        if (msg.Parameters.Count <= 1)
                            return;

                        // if channel exists, retrieve and leave
                        IRCChannel channel = channels[msg.Parameters[1].ToString()] as IRCChannel;
                        if (channel != null)
                            channel.Dispose();
                        channels.Remove(msg.Parameters[1].ToString());
                        break;
                    }

                case IRCConstants.MSG_473:
                    {
                        if (msg.Parameters.Count <= 1)
                            return;

                        // if channel exists, retrieve and leave
                        IRCChannel channel = channels[msg.Parameters[1].ToString()] as IRCChannel;
                        if (channel != null)
                        {
                            channel.Dispose();
                            channels.Remove(channel.ChannelName.ToLower());
                        }
                        break;
                    }

                case IRCConstants.MSG_475:
                    {
                        if (msg.Parameters.Count <= 1)
                            return;

                        // if channel exists, retrieve and leave
                        IRCChannel channel = channels[msg.Parameters[1].ToString()] as IRCChannel;
                        if (channel != null)
                        {
                            channel.Dispose();
                            channels.Remove(channel.ChannelName.ToLower());
                        }
                        break;
                    }
            }
        }
Example #6
0
        private void ConnectionSentMessage(object sender, IRCConnection.MessageEventArgs e)
        {
            IRCMessage msg = e.Message;

            switch (msg.MessageTypeID.ToUpper())
            {
                case IRCConstants.MSG_PART:
                    if ((msg.Parameters.Count > 0) && (MatchesChannel(msg.Parameters[0].ToString())))
                    {
                        if (LocalUserLeftChannel != null)
                            LocalUserLeftChannel(this, new IRCConnection.MessageEventArgs(msg));
                    }
                    else if (string.Compare(msg.Body, ChannelName, true) == 0)
                    {
                        if (LocalUserLeftChannel != null)
                            LocalUserLeftChannel(this, new IRCConnection.MessageEventArgs(msg));
                    }
                    break;

                case IRCConstants.MSG_PRIVMSG:
                    if ((msg.Parameters.Count > 0) && (MatchesChannel(msg.Parameters[0].ToString())))
                    {
                        if (SentMessage != null)
                            SentMessage(this, e);
                    }
                    break;
            }
        }
Example #7
0
        private void ConnectionGotMessage(object sender, IRCConnection.MessageEventArgs e)
        {
            IRCMessage msg = e.Message;

            switch (msg.MessageTypeID.ToUpper())
            {
                case IRCConstants.MSG_JOIN:
                    {
                        if (msg.Body.ToLower() == "" || msg.IsSenderLocal)
                            return;

                        // if the msg-body aka name of channel in JOIN <channame>
                        // matches this channel's name, trigger user joined channel
                        // event
                        string channame = msg.Body;
                        if (MatchesChannel(channame))
                        {
                            UserJoined(msg.SenderNode, msg);
                        }
                        break;
                    }

                case IRCConstants.MSG_PART:
                    {
                        if (msg.Parameters.Count <= 0 || msg.IsSenderLocal)
                            return;

                        // check if part parameter <channelname> is this channel's name
                        if (MatchesChannel(msg.Parameters[0].ToString()) || (string.Compare(msg.Body, ChannelName, true) == 0))
                        {
                            UserLeft(msg.SenderNode, msg);
                        }
                        break;
                    }

                case IRCConstants.MSG_QUIT:
                    {
                        // check if channel matches or if user was in channel-user-list
                        if (IsUserInChannel(msg.SenderNode.Nickname) || (string.Compare(msg.Body, ChannelName, true) == 0))
                        {
                            UserQuit(msg.SenderNode, msg);
                        }
                        break;
                    }

                case IRCConstants.MSG_KICK:
                    {
                        if (    msg.Parameters.Count > 1 && // necessary for correct KICK-command
                                MatchesChannel(msg.Parameters[0].ToString()) && // msg for this channel
                                users.ContainsValue(msg.Parameters[1].ToString())) // user is in channel
                        {
                            IRCUser u = (IRCUser)users[msg.Parameters[1].ToString().ToLower()];
                            UserKicked(u, msg);
                            // notify listeners if necessary
                            if (GotMessage != null)
                                GotMessage(this, e);
                        }
                        break;
                    }

                case IRCConstants.MSG_332:
                    {
                        if (msg.Parameters.Count <= 1)
                            return;

                        // change topic if this channel is concerned
                        string chan = msg.Parameters[1].ToString();
                        if (MatchesChannel(chan))
                        {
                            Topic = msg.Body;
                            if (TopicChanged != null)
                                TopicChanged(this, new IRCConnection.MessageEventArgs(msg));
                        }
                        break;
                    }

                case IRCConstants.MSG_333:
                    {
                        if (msg.Parameters.Count <= 1)
                            return;

                        // trigger GotMessage, if 333 was for this channel
                        string chan = msg.Parameters[1].ToString();
                        if (MatchesChannel(chan))
                        {
                            if (GotMessage != null)
                                GotMessage(this, new IRCConnection.MessageEventArgs(msg));
                        }
                        break;
                    }

                case IRCConstants.MSG_353:
                    {
                        if (msg.Parameters.Count <= 1)
                            return;

                        // perform names-update for given users
                        string chan = msg.Parameters[2].ToString();
                        if (MatchesChannel(chan))
                            UpdateNames(msg.Body);
                        break;
                    }

                case IRCConstants.MSG_366:
                    {
                        if (msg.Parameters.Count <= 1)
                            return;

                        // perform names-update for given users
                        string chan = msg.Parameters[1].ToString();
                        if (MatchesChannel(chan))
                        {
                            if (NamesChanged != null)
                                NamesChanged(this, new IRCConnection.MessageEventArgs(msg));
                        }
                        break;
                    }

                case IRCConstants.MSG_NICK:
                    {
                        UserNickChange(msg.SenderNode.Nickname, msg.Body, msg);
                        break;
                    }

                case IRCConstants.MSG_TOPIC:
                    {
                        if (msg.Parameters.Count <= 1)
                            return;

                        // if concerns this channel, update Topic
                        string chan = msg.Parameters[0].ToString();
                        if (MatchesChannel(chan))
                        {
                            Topic = msg.Body;
                            // inform listeners if necessary
                            if (TopicChanged != null)
                                TopicChanged(this, new IRCConnection.MessageEventArgs(msg));
                        }
                        break;
                    }

                case IRCConstants.MSG_PRIVMSG:
                    {
                        if (msg.Parameters.Count <= 0)
                            return;

                        // if for this channel, trigger GotMessage for listeners
                        string chan = msg.Parameters[0].ToString();
                        if (MatchesChannel(chan))
                        {
                            if (GotMessage != null)
                                GotMessage(this, e);
                        }
                        break;
                    }

                case IRCConstants.MSG_MODE:
                    {
                        if (msg.Parameters.Count <= 1)
                            return;

                        string chan = msg.Parameters[0].ToString();

                        if (!MatchesChannel(chan))
                            return;

                        string mode = msg.Parameters[1].ToString();
                        bool positive = true;
                        char firstmode = mode[1];
                        switch (firstmode)
                        {
                            case 'o':
                                {
                                    string nick = msg.Parameters[2].ToString();
                                    UserOperator(nick, true, msg);
                                    break;
                                }

                            case 'v':
                                {
                                    string nick = msg.Parameters[2].ToString();
                                    UserVoice(nick, true, msg);
                                    break;
                                }

                            default:
                                {
                                    for (int i = 0; i < mode.Length; i++)
                                    {
                                        if (mode[i] == '+')
                                            positive = true;
                                        else if (mode[i] == '-')
                                            positive = false;
                                        else
                                        {
                                            if (positive && !channelModes.ContainsKey(mode[i]))
                                                channelModes.Add(mode[i], null);
                                            else
                                                channelModes.Remove(mode[i]);
                                        }
                                    }
                                    string key = "", limit = "";
                                    if (msg.Parameters.Count > 2)
                                    {
                                        foreach (DictionaryEntry d in channelModes)
                                        {
                                            char m = (char)d.Key;
                                            switch (m)
                                            {
                                                case 'k':
                                                    {
                                                        key = msg.Parameters.Count > 3 ? msg.Parameters[3].ToString() : msg.Parameters[2].ToString();

                                                        break;
                                                    }
                                                case 'l':
                                                    {
                                                        limit = msg.Parameters[2].ToString();
                                                        break;
                                                    }
                                            }
                                        }
                                        if (key != "")
                                            channelModes['k'] = key;
                                        if (limit != "")
                                            channelModes['l'] = limit;
                                    }
                                }
                                if(ModesChanged!=null)
                                    ModesChanged(this,new IRCConnection.MessageEventArgs(msg));
                                break;

                        }

                        break;
                    }
            }
        }
Example #8
0
        private void ChannelNamesChanged(object sender, IRCConnection.MessageEventArgs e)
        {
            if (InvokeRequired)
            {
                Invoke(new Action(delegate { ChannelNamesChanged(sender, e); }));
                return;
            }

            Log(e.Message.ToString(), Color.DarkRed);

            // update user-list
            fChannelUsers.Items.Clear();
            foreach (DictionaryEntry d in channel.Users)
            {
                fChannelUsers.Items.Add(d.Value);
            }
        }
Example #9
0
 private void ChannelModesChanged(object sender, IRCConnection.MessageEventArgs e)
 {
     Log(e.Message.ToString(), Color.DarkRed);
 }
Example #10
0
 private void ChannelLocalUserLeft(object sender, IRCConnection.MessageEventArgs e)
 {
     isJoined = false;   // we left
     this.Close();       // cleanup
 }
Example #11
0
        private void SetChannel(IRCChannel pChannel)
        {
            this.channel = pChannel;
            this.connection = channel.Connection;

            // setup user list
            fChannelUsers.Items.Clear();
            foreach (DictionaryEntry d in channel.Users)
            {
                fChannelUsers.Items.Add(d.Value);
            }

            // set window title
            this.Text = channel.ChannelName + " - " + channel.Topic;

            // setup event-handlers
            channelUserStatusChanged = new IRCChannel.UserStatusChangeEventHandler(ChannelUserStatusChanged);
            channelGotMessage = new IRCConnection.MessageEventHandler(ChannelGotMessage);
            channelSentMessage = new IRCConnection.MessageEventHandler(ChannelSentMessage);
            channelTopicChanged = new IRCConnection.MessageEventHandler(ChannelTopicChanged);
            channelModesChanged = new IRCConnection.MessageEventHandler(ChannelModesChanged);
            channelNamesChanged = new IRCConnection.MessageEventHandler(ChannelNamesChanged);
            channelLocalUserLeft = new IRCConnection.MessageEventHandler(ChannelLocalUserLeft);

            // plug-in to channel via event-handlers
            channel.UserStatusChanged += channelUserStatusChanged;
            channel.GotMessage += channelGotMessage;
            channel.SentMessage += channelGotMessage;
            channel.TopicChanged += channelTopicChanged;
            channel.ModesChanged += channelModesChanged;
            channel.NamesChanged += channelNamesChanged;
            channel.LocalUserLeftChannel += channelLocalUserLeft;
        }
Example #12
0
        private void ChannelTopicChanged(object sender, IRCConnection.MessageEventArgs e)
        {
            if (InvokeRequired)
            {
                Invoke(new Action(delegate { ChannelTopicChanged(sender, e); }));
                return;
            }

            Log(e.Message.ToString(), Color.DarkRed);

            // set window title
            this.Text = channel.ChannelName + " - " + channel.Topic;
        }
Example #13
0
 private void ChannelSentMessage(object sender, IRCConnection.MessageEventArgs e)
 {
     Log(e.Message.ToShortString(), Color.Green);
 }
Example #14
0
        private void ConnectionSentMessage(object sender, IRCConnection.MessageEventArgs e)
        {
            IRCMessage msg = e.Message;

            // TODO: fix
            Log(msg.ToString(), Color.DarkGreen);
        }
Example #15
0
        private void ConnectionGotMessage(object sender, IRCConnection.MessageEventArgs e)
        {
            IRCMessage msg = e.Message;

            Log(msg.ToString(), Color.Blue);
        }
Example #16
0
 private void ManagerGotPrivateMessage(object sender, IRCConnection.MessageEventArgs e)
 {
     // todo: fill..
 }