Beispiel #1
0
        //
        // Event handlers
        //

        // Handler object events

        private void HandleNamesComplete(object sender, NamesCompleteEventArgs ev)
        {
            Debug.Print("Channel.HandleNamesComplete: channel={0} nicks={1}", _name, string.Join(",", ev.NickNames));
            Users     = new Collection <User>( );
            UserFlags = new Dictionary <User, string>( );

            var flagList = string.IsNullOrEmpty(_server.Information.ChannelModes.StatusSigils) ? "@+" : _server.Information.ChannelModes.StatusSigils;

            foreach (var item in ev.NickNames)
            {
                var flags = string.Empty;
                for (var i = 0; i < item.Length; i++)
                {
                    if (flagList.IndexOf(item[i]) > -1)
                    {
                        flags += item[i];
                    }
                    else
                    {
                        var channelMember = new NickUserHost(item.Substring(i));
                        var user          = _server.LookUpOrRegisterUser(channelMember);
                        _users.Add(user);
                        _userFlags.Add(user, flags);
                        break;
                    }
                }
            }
        }
        public virtual WhoResponse ParseResponse(Message message)
        {
            var channel = Server.LookUpChannel(message.Args[0]);

            var realName = message.Args[6];
            var index    = realName.IndexOf(' ');
            int hopCount = -1;

            if (-1 != index)
            {
                if (Int32.TryParse(realName.Substring(0, index), NumberStyles.Integer, CultureInfo.InvariantCulture, out hopCount))
                {
                    realName = realName.Substring(index + 1);
                }
            }

            var response = new WhoResponse {
                ChannelName = message.Args[0],
                UserName    = message.Args[1],
                HostName    = message.Args[2],
                ServerName  = message.Args[3],
                NickName    = message.Args[4],
                Flags       = message.Args[5],
                HopCount    = hopCount,
                RealName    = realName,
            };

            var user = Server.LookUpOrRegisterUser(new NickUserHost(response.NickName, response.UserName, response.HostName));

            if (null != channel)
            {
                try {
                    user.Channels.AddIfMissing(response.ChannelName, channel);
                    channel.Users.Add(user);
                }
                catch (Exception e) {
                    Debug.Print("WhoResponseParser.ParseResponse: caught exception:\n{0}", e);
                    Debugger.Break( );
                }
            }

            return(response);
        }
Beispiel #3
0
 protected virtual void HandleQuit(object sender, MessageEventArgs ev)
 {
     Debug.Print("User.HandleQuit: origin='{0}' target='{1}' args='{2}'", ev.Message.Origin, ev.Message.Target, string.Join("','", ev.Message.Args));
     OnQuit(_server.LookUpOrRegisterUser(ev.Message.Origin), string.Join(" ", ev.Message.Args));
 }