Ejemplo n.º 1
0
        private void IrcTopicChanged(string[] ircCommand)
        {
            string ircChannel = ircCommand[2];
            string ircUser    = ircCommand[0].Split('!')[0];

            if (!ChannelsIn.Contains(ircChannel))
            {
                ChannelsIn.Add(ircChannel);
            }

            string ircTopic = "";

            for (int intI = 4; intI < ircCommand.Length; intI++)
            {
                ircTopic += ircCommand[intI] + " ";
            }
            if (TopicChanged != null)
            {
                try
                {
                    TopicChanged(ircUser, ircChannel, ircTopic.Remove(0, 1).Trim());
                }
                catch (ArgumentException)
                {
                    //TODO: figure out why this error happens.
                }
            }
        }
Ejemplo n.º 2
0
        public void LeaveChannel(string channel)
        {
            var channels = channel.Split(',');

            foreach (var chan in channels)
            {
                if (ChannelsIn.Contains(chan))
                {
                    ChannelsIn.Remove(chan);
                }

                SendCommand(String.Format("PART {0}", chan));
            }
        }
Ejemplo n.º 3
0
        private void IrcPart(string[] ircCommand)
        {
            string ircChannel = ircCommand[2];
            string ircUser    = ircCommand[0].Split('!')[0];

            if (ircUser == Nick && ChannelsIn.Contains(ircChannel))
            {
                ChannelsIn.Remove(ircChannel);
            }

            if (Part != null)
            {
                Part(ircChannel, ircUser);
            }
        }
Ejemplo n.º 4
0
        private void IrcTopic(string[] ircCommand)
        {
            string ircChannel = ircCommand[3];

            if (!ChannelsIn.Contains(ircChannel))
            {
                ChannelsIn.Add(ircChannel);
            }

            string ircTopic = "";

            for (int intI = 4; intI < ircCommand.Length; intI++)
            {
                ircTopic += ircCommand[intI] + " ";
            }
            if (TopicSet != null)
            {
                TopicSet(ircChannel, ircTopic.Remove(0, 1).Trim());
            }
        }
Ejemplo n.º 5
0
        private void IrcKick(string[] ircCommand)
        {
            string userKicker  = ircCommand[0].Split('!')[0];
            string userKicked  = ircCommand[3];
            string ircChannel  = ircCommand[2];
            string kickMessage = "";

            if (userKicked == Nick && ChannelsIn.Contains(ircChannel))
            {
                ChannelsIn.Remove(ircChannel);
            }

            for (int intI = 4; intI < ircCommand.Length; intI++)
            {
                kickMessage += ircCommand[intI] + " ";
            }
            if (Kick != null)
            {
                Kick(ircChannel, userKicker, userKicked, kickMessage.Remove(0, 1).Trim());
            }
        }
Ejemplo n.º 6
0
        private void Listen()
        {
            while (!disconnecting)
            {
                string ircCommand;
                try
                {
                    while (!disconnecting && (ircCommand = Reader.ReadLine()) != null)
                    {
                        if (CommandReceived != null)
                        {
                            CommandReceived(ircCommand);
                        }

                        string[] commandParts = ircCommand.Split(' ');
                        if (commandParts[0].Substring(0, 1) == ":")
                        {
                            commandParts[0] = commandParts[0].Remove(0, 1);
                        }

                        if ((!commandParts[0].Contains("!")) && (commandParts[0].EndsWith(Server.Substring(Server.IndexOf('.'))) || commandParts[0].EndsWith("testserver.local")))
                        {
                            // Server message
                            switch (commandParts[1])
                            {
                            case "001":
                                RegisterUser();
                                break;

                            case "332":
                                IrcTopic(commandParts);
                                break;

                            case "333":
                                IrcTopicOwner(commandParts);
                                break;

                            case "353":
                                IrcNamesList(commandParts);
                                break;

                            case "366":     /*this.IrcEndNamesList(commandParts);*/
                                break;

                            case "372":     /*this.IrcMOTD(commandParts);*/
                                break;

                            case "376":     /*this.IrcEndMOTD(commandParts);*/
                                break;

                            default:
                                IrcServerMessage(commandParts);
                                break;
                            }
                        }
                        else if (commandParts[0] == "PING")
                        {
                            // Server PING, send PONG back
                            IrcPing(commandParts);
                        }
                        else
                        {
                            // Normal message
                            string commandAction = commandParts[1];
                            switch (commandAction)
                            {
                            case "JOIN":
                                IrcJoin(commandParts);
                                break;

                            case "PART":
                                IrcPart(commandParts);
                                break;

                            case "MODE":
                                IrcMode(commandParts);
                                break;

                            case "NICK":
                                IrcNickChange(commandParts);
                                break;

                            case "KICK":
                                IrcKick(commandParts);
                                break;

                            case "QUIT":
                                IrcQuit(commandParts);
                                break;

                            case "TOPIC":
                                IrcTopicChanged(commandParts);
                                break;
                            }
                        }
                    }
                }
                catch (ObjectDisposedException)
                {
                    //This means we got disconnected, carry on.
                }
                catch (IOException)
                {
                    //Do nothing, this is probably because the stream closed.
                }
                catch (ArgumentOutOfRangeException)
                {
                    //Do nothing, this is probably because a staff member joined.
                }
                catch (ArgumentException)
                {
                    //Do nothing, this is probably safe to ignore.
                }
                catch (Exception ex)
                {
                    LogError(ex);

                    throw;
                }

                disconnecting = true;
                Writer.Close();
                Reader.Close();
                Connection.Close();
                ChannelsIn.Clear();

                if (Disconnected != null)
                {
                    Disconnected();
                }

                Thread.Sleep(100);
            }

            Writer        = null;
            Connected     = false;
            disconnecting = false;
        }
Ejemplo n.º 7
0
 public Channel GetChannel(int channelId)
 {
     return(ChannelsIn.SingleOrDefault(c => c.Id == channelId));
 }