Пример #1
0
        internal void Register()
        {
            var type = GetType();

            foreach (var member in type.GetMembers())
            {
                foreach (object attribute in member.GetCustomAttributes(true))
                {
                    if (attribute is OnCommandAttribute)
                    {
                        if (member is MethodInfo)
                        {
                            Commands.Add(new MethodCommandTrigger <T>(this, attribute as OnCommandAttribute, member as MethodInfo));
                        }
                        else if (member is PropertyInfo)
                        {
                            Commands.Add(new PropertyCommandTrigger <T>(this, attribute as OnCommandAttribute, member as PropertyInfo));
                        }
                    }
                    else if (attribute is OnUserJoinAttribute)
                    {
                        if (member is MethodInfo)
                        {
                            UserJoins.Add(new UserJoinTrigger <T>(this, member as MethodInfo));
                        }
                    }
                    else if (attribute is OnUserLeaveAttribute)
                    {
                        if (member is MethodInfo)
                        {
                            UserLeaves.Add(new UserLeaveTrigger <T>(this, member as MethodInfo));
                        }
                    }
                    else if (attribute is PreCommandAttribute)
                    {
                        if (member is MethodInfo)
                        {
                            PreCommands.Add(new MethodPreCommandTrigger <T>(this, attribute as PreCommandAttribute, member as MethodInfo));
                        }
                        else if (member is PropertyInfo)
                        {
                            PreCommands.Add(new PropertyPreCommandTrigger <T>(this, attribute as PreCommandAttribute, member as PropertyInfo));
                        }
                    }
                }
            }
        }
Пример #2
0
        private bool StatusUserLine(Match match)
        {
            string steamId    = match.Groups[1].Value;
            string playerName = match.Groups[2].Value.Replace(@"\""", "\"");

            IPAddress.TryParse(match.Groups[5].Value, out IPAddress address);
            int.TryParse(match.Groups[6].Value, out int port);

            var user     = Users.Where(u => u.Name == playerName).FirstOrDefault();
            var endpoint = new IPEndPoint(address, port);

            if (user != null)
            {
                if (!string.IsNullOrEmpty(user.Id))
                {
                    return(false);
                }

                user.RemoteEndpoint = endpoint;
                user.Id             = steamId;
            }
            else
            {
                var newUser = new SimpleUser()
                {
                    Name           = playerName,
                    JoinTime       = DateTime.Now,
                    RemoteEndpoint = endpoint,
                    Id             = steamId,
                };

                Users.Add(newUser);
                UserJoins.InvokeSafe(this, new UserEventArgs(newUser));
            }

            return(false);
        }
Пример #3
0
 internal void HandleUserJoined(object sender, IrcChannelUserEventArgs e)
 {
     destination = e.GetDestination();
     UserJoins.ForEach(join => join.Handle(e));
     destination = null;
 }