Exemplo n.º 1
0
        private ChannelUser AddKnownUser(IUser user)
        {
            ChannelUser channelUser = new ChannelUser(Connection, this, user);

            _knownUsers.Add(channelUser);
            return(channelUser);
        }
        private void HandleChannelModeChange(IReceiveMessage message)
        {
            Channel channel = message.Receiver as Channel;

            String[] split = message.Contents.Split(new[] { ' ' }, 2);
            if (split.Length == 1)
            {
                channel.Modes.ParseAndApply(split[0]);
            }
            else
            {
                ModeChange[] changes   = Mode.Parse(split[0]);
                String[]     nicknames = split[1].Split(' ');

                if (changes.Length != nicknames.Length)
                {
                    _logger.Error("Length of changes does not match length of nicknames.");
                    return;
                }

                for (int i = 0; i < changes.Length; ++i)
                {
                    ChannelUser channelUser = channel.GetUser(nicknames[i]) as ChannelUser;
                    channelUser.Modes.Apply(changes[i]);
                }
            }
        }
        private void HandleNamesReply(IReceiveMessage message)
        {
            String[] split = message.Contents.Split(new[] { ' ' }, 4);

            if (split.Length != 4)
            {
                _logger.Error("Names reply with less than 4 parameters.");
                return;
            }

            Channel channel = GetChannel(split[2]) as Channel;

            String[] nicks = split[3].Substring(1).Split(' ');

            foreach (String nick in nicks)
            {
                char mode = ChannelUserMode.SymbolToMode(nick[0]);
                if (mode != char.MinValue)
                {
                    User        user        = GetUser(nick.Substring(1)) as User;
                    ChannelUser channelUser = AddUserToChannel(user, channel);
                    channelUser.Modes.AddMode(mode);
                }
                else
                {
                    User        user        = GetUser(nick) as User;
                    ChannelUser channelUser = AddUserToChannel(user, channel);
                }
            }
        }
        private void HandlePart(IReceiveMessage message)
        {
            ChannelUser channelUser = message.Sender as ChannelUser;
            Channel     channel     = message.Receiver as Channel;

            RemoveUserFromChannel(channelUser.User as User, channel);
        }
        private void HandleJoin(IReceiveMessage message)
        {
            ChannelUser channelUser = message.Sender as ChannelUser;
            Channel     channel     = message.Receiver as Channel;

            AddUserToChannel(channelUser.User as User, channel);

            if (_me.Equals(channelUser.User))
            {
                this.SendAndForget(
                    _messageSender.Mode(channel)
                    , _messageSender.Who(channel.Name)
                    );
            }
            else
            {
                this.SendAndForget(_messageSender.Who(channelUser.Name));
            }
        }
Exemplo n.º 6
0
        internal ChannelUser AddUser(IUser user)
        {
            if (ContainsUser(user.Name))
            {
                return(_users[user.Name] as ChannelUser);
            }

            ChannelUser channelUser;

            if (ContainsKnownUser(user.Name))
            {
                channelUser = _knownUsers[user.Name] as ChannelUser;
            }
            else
            {
                channelUser = new ChannelUser(Connection, this, user);
                _knownUsers.Add(channelUser);
            }

            _users.Add(channelUser);
            return(channelUser);
        }
        private void HandleWhoReply(IReceiveMessage message)
        {
            String[] split = message.Contents.Split(new[] { ' ' }, 9);

            if (split.Length != 9)
            {
                _logger.Error("Who reply with less than 9 parameters.");
                return;
            }

            Channel     channel     = GetChannel(split[1]) as Channel;
            User        user        = GetUser(split[5]) as User;
            ChannelUser channelUser = channel.GetUser(user.Name) as ChannelUser;

            user.Identity.Ident.Value = split[2];
            user.Identity.Host.Value  = split[3];
            user.Network.Value        = GetNetwork(split[4]);

            bool away         = false;
            bool serverOp     = false;
            bool channelVoice = false;
            bool channelOp    = false;

            foreach (char c in split[6])
            {
                switch (c)
                {
                case 'H': away = false; break;

                case 'G': away = true; break;

                case '*': serverOp = true; break;

                case '@': channelOp = true; break;

                case '+': channelVoice = true; break;
                }
            }

            user.Away.Value = away;

            // TODO: proper server operator mode.
            if (serverOp)
            {
                user.Modes.AddMode('o');
            }
            else
            {
                user.Modes.RemoveMode('o');
            }

            if (channelVoice)
            {
                channelUser.Modes.AddMode('v');
            }
            else
            {
                channelUser.Modes.RemoveMode('v');
            }

            if (channelOp)
            {
                channelUser.Modes.AddMode('o');
            }
            else
            {
                channelUser.Modes.RemoveMode('o');
            }

            // TODO: hop count.

            user.RealName.Value = split[8];
        }
        private void HandleKick(IReceiveMessage message)
        {
            ChannelUser channelUser = message.Receiver as ChannelUser;

            RemoveUserFromChannel(channelUser);
        }
 private void RemoveUserFromChannel(ChannelUser channelUser)
 {
     RemoveUserFromChannel(channelUser.User as User, channelUser.Channel as Channel);
 }
Exemplo n.º 10
0
 private void RemoveUserFromChannel(ChannelUser channelUser)
 {
     RemoveUserFromChannel(channelUser.User as User, channelUser.Channel as Channel);
 }
Exemplo n.º 11
0
 private ChannelUser AddKnownUser(IUser user)
 {
     ChannelUser channelUser = new ChannelUser(Connection, this, user);
     _knownUsers.Add(channelUser);
     return channelUser;
 }
Exemplo n.º 12
0
        internal ChannelUser AddUser(IUser user)
        {
            if(ContainsUser(user.Name))
                return _users[user.Name] as ChannelUser;

            ChannelUser channelUser;
            if(ContainsKnownUser(user.Name))
                channelUser = _knownUsers[user.Name] as ChannelUser;
            else
            {
                channelUser = new ChannelUser(Connection, this, user);
                _knownUsers.Add(channelUser);
            }

            _users.Add(channelUser);
            return channelUser;
        }