예제 #1
0
        static void Main(string[] args)
        {
            ServerList serverList = new ServerList();

            var servers = serverList.Refresh();
            servers.Wait();
            foreach (Server server in servers.Result)
            {
                Console.WriteLine(server.Name);
            }

            var pings = serverList.Ping(servers.Result.Select(s => s.Address));
            pings.Wait();
            foreach (PingResult result in pings.Result)
            {
                if (result == null)
                    continue;
                Console.WriteLine("{0}: {1}", result.Reply.Status, result.Address);
            }

            IClient ircClient = new Client();
            IClientConnection connection = ircClient.CreateClientConnection("irc.freenode.net", 6666, null);
            connection.Connect().Wait();
            connection.Login("Harvester", "Harvester", "Harvester").Wait();
            connection.Join("#tz");

            Console.ReadKey();
        }
예제 #2
0
        public IRCClientConnection(String address, ushort port, SynchronizationContext context, Client client)
            : base(address, port)
        {
            _context = context;
            _client = client;
            _networks = new SynchronizedKeyedCollection<String, INetwork>(_context);
            _channels = new SynchronizedKeyedCollection<String, IChannel>(_context);
            _users = new SynchronizedKeyedCollection<String, IUser>(_context);

            _me = GetUser(_initialNickname) as User;

            _messageSender = new MessageSender(this);
            _messageReceiver = new MessageReceiver(this);

            _disposables.Add(RawMessages
                .Select(r => _messageReceiver.Receive(r))
                .Subscribe(_internalReceivedMessages)
                );
            _disposables.Add(_internalReceivedMessages.Subscribe(_receivedMessages));
            _disposables.Add(_receivedMessages.Subscribe(_messages));
            _disposables.Add(_sentMessages.Subscribe(_messages));
            _disposables.Add(_sentMessages
                .Where(m => m.Type == SendType.Privmsg || m.Type == SendType.Notice)
                .Subscribe(m => HandleMessage(m))
            );

            _disposables.Add(_internalReceivedMessages
                .Where(m => m.Type == ReceiveType.Ping)
                .Subscribe(HandlePing)
                );
            _disposables.Add(_internalReceivedMessages
                .Where(m => m.Type == ReceiveType.Join)
                .Subscribe(HandleJoin)
                );
            _disposables.Add(_internalReceivedMessages
                .Where(m => m.Type == ReceiveType.Part)
                .Subscribe(HandlePart)
                );
            _disposables.Add(_internalReceivedMessages
                .Where(m => m.Type == ReceiveType.Kick)
                .Subscribe(HandleKick)
                );
            _disposables.Add(_internalReceivedMessages
                .Where(m => m.Type == ReceiveType.Quit)
                .Subscribe(HandleQuit)
                );
            _disposables.Add(_internalReceivedMessages
                .Where(m => m.Type == ReceiveType.NickChange)
                .Subscribe(HandleNickChange)
                );
            _disposables.Add(_internalReceivedMessages
                .Where(m => m.Type == ReceiveType.TopicChange)
                .Subscribe(HandleTopicChange)
                );
            _disposables.Add(_internalReceivedMessages
                .Where(m => m.Type == ReceiveType.ChannelModeChange)
                .Subscribe(HandleChannelModeChange)
                );
            _disposables.Add(_internalReceivedMessages
                .Where(m => m.Type == ReceiveType.UserModeChange)
                .Subscribe(HandleUserModeChange)
                );

            _disposables.Add(_internalReceivedMessages
                .Where(m => m.ReplyType == ReplyType.Welcome)
                .Subscribe(HandleWelcome)
                );
            _disposables.Add(_internalReceivedMessages
                .Where(m => m.ReplyType == ReplyType.ChannelModeIs)
                .Subscribe(HandleChannelModeIsReply)
                );
            _disposables.Add(_internalReceivedMessages
                .Where(m => m.ReplyType == ReplyType.CreatedAt)
                .Subscribe(HandleCreatedAtReply)
                );
            _disposables.Add(_internalReceivedMessages
                .Where(m => m.ReplyType == ReplyType.Topic)
                .Subscribe(HandleTopicReply)
                );
            _disposables.Add(_internalReceivedMessages
                .Where(m => m.ReplyType == ReplyType.TopicSetBy)
                .Subscribe(HandleTopicSetByReply)
                );
            _disposables.Add(_internalReceivedMessages
                .Where(m => m.ReplyType == ReplyType.NamesReply)
                .Subscribe(HandleNamesReply)
                );
            _disposables.Add(_internalReceivedMessages
                .Where(m => m.ReplyType == ReplyType.WhoReply)
                .Subscribe(HandleWhoReply)
                );
            _disposables.Add(_internalReceivedMessages
                .Where(m => m.ReplyType == ReplyType.Away)
                .Subscribe(HandleAwayReply)
                );
            _disposables.Add(_internalReceivedMessages
                .Where(m => m.ReplyType == ReplyType.UnAway)
                .Subscribe(HandleUnAwayReply)
                );
        }