Esempio n. 1
0
        public void RunOnce()
        {
            string line = socket.read_until("\r\n", false);

            if (OnSocketLineReceive != null)
            {
                OnSocketLineReceive(this, new OnSocketLineReceiveArgs(line));
            }

            IrcPacket packet = new IrcPacket();

            packet.Parse(line);

            if (OnIrcPacketReceived != null)
            {
                OnIrcPacketReceived(this, new OnIrcPacketReceivedArgs(packet));
            }

            if (packet.Command == "PRIVMSG")
            {
                if (packet.Arguments [0].StartsWith("#"))
                {
                    if (OnPublicMessage != null)
                    {
                        OnPublicMessage(this, new OnPublicMessageArgs(packet.Prefix.Split('!') [0], packet.Arguments [0], packet.Arguments [1]));
                    }
                }
                else
                {
                    if (OnPrivMsg != null)
                    {
                        OnPrivMsg(this, new OnPrivMsgArgs(packet.Prefix.Split('!') [0], packet.Arguments [1]));
                    }
                }
            }
            else if (packet.Command == "PING")
            {
                SendLine(String.Format("PONG :{0}", packet.Arguments [0]));

                if (OnPingReceived != null)
                {
                    OnPingReceived(this, EventArgs.Empty);
                }
            }
            else if (packet.Command == "433")
            {
                //Command 433 is "Nick in use".
                //This will add underscore to the nickname until we find a free one.
                SetNick(String.Format("{0}_", Nick));
            }
            else if (packet.Command == "001")
            {
                //Command 376 is "End of motd".

                if (OnWelcome != null)
                {
                    OnWelcome(this, EventArgs.Empty);
                }
            }
        }
Esempio n. 2
0
 public OnIrcPacketReceivedArgs(IrcPacket packet)
 {
     Packet = packet;
 }