Beispiel #1
0
 public async Task CheckOnJoin(ClientJoinedEventArgs client)
 {
     try
     {
         var restrictedwords = _config.BannedWords;
         var regexMatch      = string.Join <string>("|", restrictedwords);
         var regex           = new Regex($"({regexMatch})", RegexOptions.IgnoreCase);
         var clientinfo      = new ClientInfoCommand(client.ClientId).ExecuteAsync(Interface.XfQueryBot.QueryClient)
                               .Result;
         if (!regex.IsMatch(client.Nickname) || !client.ClientType.Equals(0))
         {
             return;
         }
         if (_config.PokeOrKick.Equals("Kick", StringComparison.OrdinalIgnoreCase))
         {
             await new ClientKickCommand(client.ClientId, KickReason.Server,
                                         _config.Reason[CheckClientLang(clientinfo)].Replace("[NICKNAME]", client.Nickname))
             .ExecuteAsync(Interface.XfQueryBot.QueryClient);
         }
         else
         {
             await new ClientPokeCommand(client.ClientId,
                                         _config.Reason[CheckClientLang(clientinfo)].Replace("[NICKNAME]", client.Nickname))
             .ExecuteAsync(Interface.XfQueryBot.QueryClient);
         }
     }
     catch (Exception ex)
     {
         _log.Error($"({_extension.Name}) : {ex}");
     }
 }
Beispiel #2
0
        private void FetchClientInfo()
        {
            if (!_valid)
            {
                return;
            }

            try
            {
                lock (RankingBot.TS3Lock)
                {
                    RankingBot.Logger.Debug(_file + " Fetching client info (ClientID: '" + _clid + "')");
                    ClientInfoCommandResponse clinfo = new ClientInfoCommand(_clid).Execute(RankingBot.TS3);
                    if (clinfo.IsErroneous)
                    {
                        RankingBot.Logger.Error(_file + " Received erroneous client info data (ClientID: '" + _clid + "')");
                        RankingBot.Logger.Debug(_file + " Erroneous data: " + clinfo.ResponseText);
                        Invalidate();
                        return;
                    }
                    RankingBot.Logger.Debug(_file + " Fetched client info (ClientID: '" + _clid + "')");
                    _clinfo = clinfo;
                    _errors = 0;
                }
            }
            catch (Exception e)
            {
                if (_errors != 2)
                {
                    _errors++;
                    RankingBot.Logger.Warn(_file + " Caught exception trying to get client info, will try " + (3 - _errors) + " more time(s) (ClientID: '" + _clid + "')");
                    FetchClientInfo();
                }
                else
                {
                    RankingBot.Logger.Error(_file + " Repeated exceptions (" + e.Message + ") trying to get client info. Invalidating client (ClientID: '" + _clid + "')");
                    Invalidate();
                    return;
                }
            }
        }
Beispiel #3
0
        public async Task RegisterOnChannel(ClientMovedEventArgs e)
        {
            try
            {
                var clientInfo = new ClientInfoCommand(e.ClientId).ExecuteAsync(Interface.XfQueryBot.QueryClient)
                                 .Result;
                if (_config.RegisterChannels.ContainsKey((int)e.TargetChannelId))
                {
                    var channelId = Convert.ToInt16(e.TargetChannelId);
                    if (clientInfo.TotalConnections < _config.RegisterChannels[channelId].ConnectionsNeeded ||
                        clientInfo.ConnectedTime.TotalSeconds < _config.RegisterChannels[channelId].SecondsNeeded ||
                        clientInfo.ServerGroups.Any(x =>
                                                    _config.RegisterChannels[channelId].RestrictedRanks.Any(y => y == x)))
                    {
                        await new ClientPokeCommand(e.ClientId, _config.KickMessage[CheckClientLang(clientInfo)])
                        .ExecuteAsync(Interface.XfQueryBot.QueryClient);

                        await new ClientKickCommand(e.ClientId, KickReason.Channel,
                                                    _config.KickMessage[CheckClientLang(clientInfo)])
                        .ExecuteAsync(Interface.XfQueryBot.QueryClient);
                    }
                    else
                    {
                        await new ServerGroupAddClientCommand(
                            (uint)_config.RegisterChannels[(int)e.TargetChannelId].RankId, clientInfo.DatabaseId)
                        .ExecuteAsync(Interface.XfQueryBot.QueryClient);

                        await new ClientPokeCommand(e.ClientId, _config.SucessMessage[CheckClientLang(clientInfo)])
                        .ExecuteAsync(Interface.XfQueryBot.QueryClient);

                        await new ClientKickCommand(e.ClientId, KickReason.Channel,
                                                    _config.SucessMessage[CheckClientLang(clientInfo)])
                        .ExecuteAsync(Interface.XfQueryBot.QueryClient);
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Error($"({_addon.Name}) : {ex}");
            }
        }