Пример #1
0
 private void RemoveUserFromChannel(User user, Channel channel)
 {
     channel.RemoveUser(user.Name);
     user.RemoveChannel(channel.Name);
 }
Пример #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)
                );
        }
Пример #3
0
 private ChannelUser AddUserToChannel(User user, Channel channel)
 {
     user.AddChannel(channel);
     return channel.AddUser(user);
 }
Пример #4
0
        private void ChangeNickname(User user, String nickname)
        {
            if(_users.Contains(nickname))
            {
                _logger.Error("Changing nickname of " + user.Name + " into " + nickname +
                    ", but a user with that nickname already exists. Some observable subscriptions may be lost.");

                if(user.Equals(_me))
                    _me = _users[nickname] as User;
                user.Channels.Cast<Channel>().Do(c => c.ChangeName(user.Name, nickname));
                _users.Remove(user);
                return;
            }

            _users.ChangeItemKey(user, nickname);
            user.Channels.Cast<Channel>().Do(c => c.ChangeName(user.Name, nickname));
            user.Name.Value = nickname;
            user.Identity.Name.Value = nickname;
        }
Пример #5
0
        public IUser GetUser(String nickname)
        {
            if(_users.Contains(nickname))
                return _users[nickname];

            User user = new User(this, nickname, _context);
            _users.Add(user);
            return user;
        }