Пример #1
0
        public async Task <HttpResponseMessage> GetCaptcha()
        {
            try
            {
                string captcha = CaptchaManager.GetCaptchaBase64(5, CaptchaFormat.Numeric, 120, 50);
                return(this.Request.CreateResponse(HttpStatusCode.OK, new
                {
                    resultCode = 0,
                    data = captcha
                }));
            }
            catch (Exception ex)
            {
                //await ExceptionManager.SaveExceptionAsync(ex);
                return(this.Request.CreateResponse(HttpStatusCode.OK, new
                {
                    resultCode = 4,
                    //message = ExceptionManager.GetExceptionMessage(ex),
                    //stackTrace = ConfigurationController.WithDebugInfo ? ExceptionManager.GetExceptionMessageWithDebugInfo(ex) : ""
                }));
            }
            HttpResponseMessage httpResponseMessage;

            return(httpResponseMessage);
        }
Пример #2
0
        protected virtual string Validate(LoginRequest request)
        {
            string str = "";

            if (string.IsNullOrWhiteSpace(request.UserName))
            {
                str += "نام کاربری اجباری می باشد";
            }
            if (string.IsNullOrWhiteSpace(request.Password))
            {
                if (!string.IsNullOrEmpty(str))
                {
                    str += "<br />";
                }
                str += "رمز عبور اجباری می باشد";
            }
            if ((string.IsNullOrWhiteSpace(request.Captcha)) || !CaptchaManager.VerifyCaptcha(request.Captcha))
            {
                if (!string.IsNullOrEmpty(str))
                {
                    str += "<br />";
                }
                str += "کد امنیتی صحیح نمی باشد";
            }
            if (!string.IsNullOrEmpty(str) || !request.UserName.IsInvalidWebInput() && !request.Password.IsInvalidWebInput() && request.Password.Length <= 30)
            {
                return(str);
            }
            str = "اطلاعات وارد شده معتبر نمی باشد";
            return(str);
        }
Пример #3
0
        public string GetCaptcha(string key, ISession httpSession)
        {
            var captchaManager = new CaptchaManager();
            var generate       = captchaManager.Generate(key);

            httpSession.SetString(key, generate);
            return(generate);
        }
Пример #4
0
        public ActionResult Index(string c1, string c2)
        {
            var isCaptcha1Valid = CaptchaManager.ValidateCurrentCaptcha("c1", c1);
            var isCaptcha2Valid = CaptchaManager.ValidateCurrentCaptcha("c2", c2);

            ViewBag.c1 = isCaptcha1Valid;
            ViewBag.c2 = isCaptcha2Valid;
            return(View());
        }
Пример #5
0
 public UserLoginService(
     UserManager userManager,
     AdminManager adminManager,
     CaptchaManager captchaManager)
 {
     _userManager    = userManager;
     _adminManager   = adminManager;
     _captchaManager = captchaManager;
 }
Пример #6
0
        public ActionResult Index(string c1)
        {
            if (string.IsNullOrEmpty(c1))
            {
                ViewBag.c1 = false;
                return(View());
            }
            var isCaptcha1Valid = CaptchaManager.ValidateCurrentCaptcha("c1", c1);

            ViewBag.c1 = isCaptcha1Valid;
            return(View());
        }
Пример #7
0
        public RegisterationValidator()
        {
            this.RuleFor(dr => dr.Password).NotNull().WithMessage("رمز عبور اجباری می باشد.")
            .NotEmpty().WithMessage("رمز عبور اجباری می باشد.")
            .Must(password => password.Length > 5).WithMessage(" رمز عبور باید حداقل 6 کاراکتر  باشد")
            .Matches("^([0-9]+[a-zA-Z]+|[a-zA-Z]+[0-9]+)[0-9a-zA-Z]*$").WithMessage(" رمز عبور باید ترکیب کاراکتر و عدد  باشد");

            this.RuleFor(dr => dr.MobileNo).NotNull().WithMessage(" تلفن همراه اجباری می باشد.")
            .NotEmpty().WithMessage("تلفن همراه اجباری می باشد.")
            .Matches(RegExPatterns.Mobile).WithMessage(dr => $"معتبر نمی باشد تلفن همراه '{dr.MobileNo}'");;
            When(dr => dr.IsFinalStep, () =>
            {
                this.RuleFor(dr => dr.MobileCaptcha).NotNull().WithMessage("کد تایید اجباری می باشد.")
                .NotEmpty().WithMessage("کد تایید اجباری می باشد.");
            });

            UserInfo uInfo = null;

            this.RuleFor(entity => entity.MobileNo).MustAsync(async(entity, userName) =>
            {
                using (UnitOfWork uow = new UnitOfWork())
                {
                    //var userQuery = uow.RepositoryAsync<ZhivarUserInfo>()
                    //                   .Queryable()
                    //                   .Where(user => !user.IsDeleted);// &&
                    //                                   //user.ApplicationId == ConfigurationController.ApplicationID);


                    //uInfo = await userQuery.Where(user => //user.UserName == userName
                    //                     //&&
                    //                     user.IsActive == true
                    //                                     && user.IsDeleted == false)
                    //                                     .FirstOrDefaultAsync();
                    if (uInfo == null)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }).WithMessage("نام کاربری بااین تلفن همراه قبلاً در سیستم ثبت شده است.");

            When(dr => !dr.IsFinalStep, () =>
            {
                this.RuleFor(dr => dr.Captcha).NotNull().WithMessage("کد امنیتی اجباری می باشد.")
                .NotEmpty().WithMessage("کد امنیتی اجباری می باشد.")
                .Must(captcha => {
                    return(CaptchaManager.VerifyCaptcha(captcha));
                }).WithMessage(" کد امنیتی معتبر می باشد.");
            });
        }
Пример #8
0
        public ActionResult GetCaptcha()
        {
            var captcha = new Captcha(4);

            CaptchaManager.Write("login", captcha.Value);
            Response.Cookies.Add(new HttpCookie("QiBu_Captcha", captcha.Value));
            Image image = captcha.CreateImage(
                Color.FromArgb(
                    Convert.ToInt32(255),
                    Convert.ToInt32(255),
                    Convert.ToInt32(255)
                    ), 170, 15, 4, 5
                );
            var stream = new MemoryStream();

            image.Save(stream, ImageFormat.Png);
            stream.Close();
            return(File(stream.GetBuffer(), @"image/png"));
        }
Пример #9
0
        public async Task Start(IState initialState, ISession session, string subPath, bool excelConfigAllowed = false)
        {
            GlobalSettings globalSettings = null;

            var state             = initialState;
            var profilePath       = Path.Combine(Directory.GetCurrentDirectory(), subPath);
            var profileConfigPath = Path.Combine(profilePath, "config");

            globalSettings = GlobalSettings.Load(subPath);

            FileSystemWatcher configWatcher = new FileSystemWatcher();

            configWatcher.Path                = profileConfigPath;
            configWatcher.Filter              = "config.json";
            configWatcher.NotifyFilter        = NotifyFilters.LastWrite;
            configWatcher.EnableRaisingEvents = true;

            configWatcher.Changed += (sender, e) =>
            {
                if (e.ChangeType == WatcherChangeTypes.Changed)
                {
                    globalSettings                    = GlobalSettings.Load(subPath);
                    session.LogicSettings             = new LogicSettings(globalSettings);
                    configWatcher.EnableRaisingEvents = !configWatcher.EnableRaisingEvents;
                    configWatcher.EnableRaisingEvents = !configWatcher.EnableRaisingEvents;
                    Logger.Write(" ##### config.json ##### ", LogLevel.Info);
                }
            };

            //watch the excel config file
            if (excelConfigAllowed)
            {
                Task.Run(async() =>
                {
                    while (true)
                    {
                        try
                        {
                            FileInfo inf = new FileInfo($"{profileConfigPath}\\config.xlsm");
                            if (inf.LastWriteTime > DateTime.Now.AddSeconds(-5))
                            {
                                globalSettings        = ExcelConfigHelper.ReadExcel(globalSettings, inf.FullName);
                                session.LogicSettings = new LogicSettings(globalSettings);
                                Logger.Write(" ##### config.xlsm ##### ", LogLevel.Info);
                            }
                            await Task.Delay(5000);
                        }
                        catch (Exception)
                        {
                        }
                    }
                });
            }

            int apiCallFailured = 0;

            do
            {
                try
                {
                    state = await state.Execute(session, session.CancellationTokenSource.Token);

                    // Exit the bot if both catching and looting has reached its limits
                    if ((UseNearbyPokestopsTask._pokestopLimitReached || UseNearbyPokestopsTask._pokestopTimerReached) &&
                        session.Stats.CatchThresholdExceeds(session))
                    {
                        session.EventDispatcher.Send(new ErrorEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.ExitDueToLimitsReached)
                        });

                        session.CancellationTokenSource.Cancel();

                        // A bit rough here; works but can be improved
                        await Task.Delay(10000);

                        state = null;
                        session.CancellationTokenSource.Dispose();
                        Environment.Exit(0);
                    }
                }
                catch (APIBadRequestException ex)
                {
                    Logger.Write("Bad Request - If you see this message please conpy error log & screenshot send back to dev asap.", level: LogLevel.Error);

                    session.EventDispatcher.Send(new ErrorEvent()
                    {
                        Message = ex.Message
                    });
                    Logger.Write(ex.StackTrace, level: LogLevel.Error);

                    if (session.LogicSettings.AllowMultipleBot)
                    {
                        session.ReInitSessionWithNextBot();
                    }
                    state = new LoginState();
                }
                catch (AccountNotVerifiedException)
                {
                    if (session.LogicSettings.AllowMultipleBot)
                    {
                        session.ReInitSessionWithNextBot();
                        state = new LoginState();
                    }
                    else
                    {
                        Console.Read();
                        Environment.Exit(0);
                    }
                }
                catch (ActiveSwitchByPokemonException rsae)
                {
                    session.EventDispatcher.Send(new WarnEvent {
                        Message = "Encountered a good pokemon , switch another bot to catch him too."
                    });
                    session.ReInitSessionWithNextBot(rsae.Bot, session.Client.CurrentLatitude, session.Client.CurrentLongitude, session.Client.CurrentAltitude);
                    state = new LoginState(rsae.LastEncounterPokemonId);
                }
                catch (ActiveSwitchByRuleException se)
                {
                    session.EventDispatcher.Send(new WarnEvent {
                        Message = $"Switch bot account activated by : {se.MatchedRule.ToString()}  - {se.ReachedValue} "
                    });
                    if (se.MatchedRule == SwitchRules.EmptyMap)
                    {
                        session.BlockCurrentBot(90);
                        session.ReInitSessionWithNextBot();
                    }
                    else
                    if (se.MatchedRule == SwitchRules.PokestopSoftban)
                    {
                        session.BlockCurrentBot();
                        session.ReInitSessionWithNextBot();
                    }
                    else
                    if (se.MatchedRule == SwitchRules.CatchFlee)
                    {
                        session.BlockCurrentBot(60);
                        session.ReInitSessionWithNextBot();
                    }
                    else
                    {
                        if (se.MatchedRule == SwitchRules.CatchLimitReached || se.MatchedRule == SwitchRules.SpinPokestopReached)
                        {
                            PushNotificationClient.SendNotification(session, $"{se.MatchedRule} - {session.Settings.GoogleUsername}{session.Settings.PtcUsername}", "This bot has reach limit, it will be blocked for 60 mins for safety.", true);
                            session.EventDispatcher.Send(new WarnEvent()
                            {
                                Message = "You reach limited. bot will sleep for 60 min"
                            });

                            session.BlockCurrentBot(60);

                            if (!session.LogicSettings.AllowMultipleBot)
                            {
                                await Task.Delay(60 * 1000 * 60);
                            }
                            else
                            {
                                session.ReInitSessionWithNextBot();
                            }
                        }
                        else
                        {
                            if (session.LogicSettings.MultipleBotConfig.StartFromDefaultLocation)
                            {
                                session.ReInitSessionWithNextBot(null, globalSettings.LocationConfig.DefaultLatitude, globalSettings.LocationConfig.DefaultLongitude, session.Client.CurrentAltitude);
                            }
                            else
                            {
                                session.ReInitSessionWithNextBot(); //current location
                            }
                        }
                    }
                    //return to login state
                    state = new LoginState();
                }

                catch (InvalidResponseException)
                {
                    session.EventDispatcher.Send(new ErrorEvent {
                        Message = "Niantic Servers unstable, throttling API Calls."
                    });
                    await Task.Delay(1000);

                    if (session.LogicSettings.AllowMultipleBot)
                    {
                        apiCallFailured++;
                        if (apiCallFailured > 20)
                        {
                            apiCallFailured = 0;
                            session.BlockCurrentBot(30);
                            session.ReInitSessionWithNextBot();
                        }
                    }
                    state = new LoginState();
                }
                catch (OperationCanceledException)
                {
                    session.EventDispatcher.Send(new ErrorEvent {
                        Message = "Current Operation was canceled."
                    });
                    if (session.LogicSettings.AllowMultipleBot)
                    {
                        session.BlockCurrentBot(30);
                        session.ReInitSessionWithNextBot();
                    }
                    state = new LoginState();
                }
                catch (LoginFailedException)
                {
                    PushNotificationClient.SendNotification(session, $"Banned!!!! {session.Settings.PtcUsername}{session.Settings.GoogleUsername}", session.Translation.GetTranslation(TranslationString.AccountBanned), true);

                    if (session.LogicSettings.AllowMultipleBot)
                    {
                        session.BlockCurrentBot(24 * 60); //need remove acc
                        session.ReInitSessionWithNextBot();
                        state = new LoginState();
                    }
                    else
                    {
                        session.EventDispatcher.Send(new ErrorEvent {
                            Message = session.Translation.GetTranslation(TranslationString.ExitNowAfterEnterKey)
                        });
                        Console.ReadKey();
                        System.Environment.Exit(1);
                    }
                }
                catch (MinimumClientVersionException ex)
                {
                    // We need to terminate the client.
                    session.EventDispatcher.Send(new ErrorEvent
                    {
                        Message = session.Translation.GetTranslation(TranslationString.MinimumClientVersionException, ex.CurrentApiVersion.ToString(), ex.MinimumClientVersion.ToString())
                    });

                    session.EventDispatcher.Send(new ErrorEvent {
                        Message = session.Translation.GetTranslation(TranslationString.ExitNowAfterEnterKey)
                    });
                    Console.ReadKey();
                    System.Environment.Exit(1);
                }
                catch (TokenRefreshException ex)
                {
                    session.EventDispatcher.Send(new ErrorEvent()
                    {
                        Message = ex.Message
                    });

                    if (session.LogicSettings.AllowMultipleBot)
                    {
                        session.ReInitSessionWithNextBot();
                    }
                    state = new LoginState();
                }

                catch (PtcOfflineException)
                {
                    session.EventDispatcher.Send(new ErrorEvent {
                        Message = session.Translation.GetTranslation(TranslationString.PtcOffline)
                    });
                    session.EventDispatcher.Send(new NoticeEvent {
                        Message = session.Translation.GetTranslation(TranslationString.TryingAgainIn, 15)
                    });

                    await Task.Delay(15000);

                    state = _initialState;
                }
                catch (GoogleOfflineException)
                {
                    session.EventDispatcher.Send(new ErrorEvent {
                        Message = session.Translation.GetTranslation(TranslationString.GoogleOffline)
                    });
                    session.EventDispatcher.Send(new NoticeEvent {
                        Message = session.Translation.GetTranslation(TranslationString.TryingAgainIn, 15)
                    });

                    await Task.Delay(15000);

                    state = _initialState;
                }
                catch (AccessTokenExpiredException)
                {
                    session.EventDispatcher.Send(new NoticeEvent {
                        Message = "Access Token Expired. Logging in again..."
                    });
                    state = _initialState;
                }
                catch (CaptchaException captchaException)
                {
                    var resolved = await CaptchaManager.SolveCaptcha(session, captchaException.Url);

                    if (!resolved)
                    {
                        PushNotificationClient.SendNotification(session, $"Captcha required {session.Settings.PtcUsername}{session.Settings.GoogleUsername}", session.Translation.GetTranslation(TranslationString.CaptchaShown), true);
                        session.EventDispatcher.Send(new WarnEvent {
                            Message = session.Translation.GetTranslation(TranslationString.CaptchaShown)
                        });
                        if (session.LogicSettings.AllowMultipleBot)
                        {
                            session.BlockCurrentBot(15);
                            if (!session.ReInitSessionWithNextBot())
                            {
                                await PushNotificationClient.SendNotification(session, "All accounts are being blocked", "Non of yours account available to switch, bot will sleep for 30 mins", true);

                                await Task.Delay(30 * 60 * 1000);
                            }
                            state = new LoginState();
                        }
                        else
                        {
                            session.EventDispatcher.Send(new ErrorEvent {
                                Message = session.Translation.GetTranslation(TranslationString.ExitNowAfterEnterKey)
                            });
                            Console.ReadKey();
                            Environment.Exit(0);
                        }
                    }
                    else
                    {
                        //resolve captcha
                        state = new LoginState();
                    }
                }
                catch (HasherException ex)
                {
                    session.EventDispatcher.Send(new ErrorEvent {
                        Message = ex.Message
                    });
                    //  session.EventDispatcher.Send(new ErrorEvent { Message = session.Translation.GetTranslation(TranslationString.ExitNowAfterEnterKey) });
                    state = new IdleState();
                    //Console.ReadKey();
                    //System.Environment.Exit(1);
                }
                catch (Exception ex)
                {
                    session.EventDispatcher.Send(new ErrorEvent {
                        Message = "Pokemon Servers might be offline / unstable. Trying again..."
                    });
                    session.EventDispatcher.Send(new ErrorEvent {
                        Message = "Error: " + ex
                    });
                    if (state is LoginState)
                    {
                    }
                    else
                    {
                        state = _initialState;
                    }
                }
            } while (state != null);
            configWatcher.EnableRaisingEvents = false;
            configWatcher.Dispose();
        }
Пример #10
0
        public async Task Start(IState initialState, ISession session, string subPath, bool excelConfigAllowed = false)
        {
            var manager = TinyIoCContainer.Current.Resolve <MultiAccountManager>();

            GlobalSettings globalSettings = null;

            var state             = initialState;
            var profilePath       = Path.Combine(Directory.GetCurrentDirectory(), subPath);
            var profileConfigPath = Path.Combine(profilePath, "config");

            globalSettings = GlobalSettings.Load(subPath);

            FileSystemWatcher configWatcher = new FileSystemWatcher()
            {
                Path                = profileConfigPath,
                Filter              = "config.json",
                NotifyFilter        = NotifyFilters.LastWrite,
                EnableRaisingEvents = true
            };

            configWatcher.Changed += (sender, e) =>
            {
                if (e.ChangeType == WatcherChangeTypes.Changed)
                {
                    globalSettings        = GlobalSettings.Load(subPath);
                    session.LogicSettings = new LogicSettings(globalSettings);
                    // BUG: duplicate boolean negation will take no effect
                    configWatcher.EnableRaisingEvents = !configWatcher.EnableRaisingEvents;
                    configWatcher.EnableRaisingEvents = !configWatcher.EnableRaisingEvents;
                    Logger.Write(" ##### config.json ##### ", LogLevel.Info);
                }
            };

            //watch the excel config file
            if (excelConfigAllowed)
            {
                // TODO - await is legal here! USE it or use pragma to suppress compilerwarning and write a comment why it is not used
                // TODO: Attention - do not touch (add pragma) when you do not know what you are doing ;)
                // jjskuld - Ignore CS4014 warning for now.
                #pragma warning disable 4014
                Run(async() =>
                {
                    while (true)
                    {
                        try
                        {
                            FileInfo inf = new FileInfo($"{profileConfigPath}\\config.xlsm");
                            if (inf.LastWriteTime > DateTime.Now.AddSeconds(-5))
                            {
                                globalSettings        = ExcelConfigHelper.ReadExcel(globalSettings, inf.FullName);
                                session.LogicSettings = new LogicSettings(globalSettings);
                                Logger.Write(" ##### config.xlsm ##### ", LogLevel.Info);
                            }
                            await Delay(5000).ConfigureAwait(false);
                        }
                        catch (Exception)
                        {
                            // TODO Bad practice! Wanna log this?
                        }
                    }
                });
                #pragma warning restore 4014
            }

            int apiCallFailured = 0;
            do
            {
                try
                {
                    state = await state.Execute(session, session.CancellationTokenSource.Token).ConfigureAwait(false);

                    // Exit the bot if both catching and looting has reached its limits
                    if ((UseNearbyPokestopsTask._pokestopLimitReached ||
                         UseNearbyPokestopsTask._pokestopTimerReached) &&
                        session.Stats.CatchThresholdExceeds(session))
                    {
                        session.EventDispatcher.Send(new ErrorEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.ExitDueToLimitsReached)
                        });

                        session.CancellationTokenSource.Cancel();

                        // A bit rough here; works but can be improved
                        await Delay(10000).ConfigureAwait(false);

                        state = null;
                        session.CancellationTokenSource.Dispose();
                        Environment.Exit(0);
                    }
                }
                catch (APIBadRequestException)
                {
                    session.EventDispatcher.Send(new ErrorEvent()
                    {
                        Message = "Unexpected error happen, bot will re-login"
                    });

                    if (manager.AllowMultipleBot())
                    {
                        ReInitializeSession(session, globalSettings);
                    }
                    state = new LoginState();
                }
                catch (AccountNotVerifiedException)
                {
                    if (manager.AllowMultipleBot())
                    {
                        ReInitializeSession(session, globalSettings);
                        state = new LoginState();
                    }
                    else
                    {
                        Console.Read();
                        Environment.Exit(0);
                    }
                }
                catch (ActiveSwitchAccountManualException ex)
                {
                    session.EventDispatcher.Send(new WarnEvent {
                        Message = "Switch bot account requested by: User"
                    });
                    ReInitializeSession(session, globalSettings, ex.RequestedAccount);
                    state = new LoginState();
                }
                catch (ActiveSwitchByPokemonException rsae)
                {
                    if (rsae.Snipe && rsae.EncounterData != null)
                    {
                        session.EventDispatcher.Send(new WarnEvent {
                            Message = $"Detected a good pokemon with snipe {rsae.EncounterData.PokemonId.ToString()}   IV:{rsae.EncounterData.IV}  Move:{rsae.EncounterData.Move1}/ Move:{rsae.EncounterData.Move2}   LV: Move:{rsae.EncounterData.Level}"
                        });
                    }
                    else
                    {
                        session.EventDispatcher.Send(new WarnEvent {
                            Message = "Encountered a good pokemon, switch another bot to catch him too."
                        });
                        if (session.LogicSettings.NotificationConfig.EnablePushBulletNotification == true)
                        {
                            await PushNotificationClient.SendNotification(session, $"Switch bot account", $"Encountered a good pokemon, switch another bot to catch him too.", true).ConfigureAwait(false);
                        }
                    }
                    session.ReInitSessionWithNextBot(rsae.Bot, session.Client.CurrentLatitude, session.Client.CurrentLongitude, session.Client.CurrentAltitude);
                    state = new LoginState(rsae.LastEncounterPokemonId, rsae.EncounterData);
                }
                catch (ActiveSwitchByRuleException se)
                {
                    session.EventDispatcher.Send(new WarnEvent {
                        Message = $"Switch bot account activated by: {se.MatchedRule.ToString()} - {se.ReachedValue}"
                    });
                    if (session.LogicSettings.NotificationConfig.EnablePushBulletNotification == true)
                    {
                        await PushNotificationClient.SendNotification(session, $"Switch bot account", $"Activated by: {se.MatchedRule.ToString()} - {se.ReachedValue}", true).ConfigureAwait(false);
                    }

                    if (se.MatchedRule == SwitchRules.EmptyMap)
                    {
                        TinyIoCContainer.Current.Resolve <MultiAccountManager>().BlockCurrentBot(90);
                        ReInitializeSession(session, globalSettings);
                    }
                    else if (se.MatchedRule == SwitchRules.PokestopSoftban)
                    {
                        TinyIoCContainer.Current.Resolve <MultiAccountManager>().BlockCurrentBot();
                        ReInitializeSession(session, globalSettings);
                    }
                    else if (se.MatchedRule == SwitchRules.CatchFlee)
                    {
                        TinyIoCContainer.Current.Resolve <MultiAccountManager>().BlockCurrentBot(60);
                        ReInitializeSession(session, globalSettings);
                    }
                    else
                    {
                        if (se.MatchedRule == SwitchRules.CatchLimitReached ||
                            se.MatchedRule == SwitchRules.SpinPokestopReached)
                        {
                            // TODO - await is legal here! USE it or use pragma to suppress compilerwarning and write a comment why it is not used
                            // TODO: Attention - do not touch (add pragma) when you do not know what you are doing ;)
                            // jjskuld - Ignore CS4014 warning for now.

                            if (session.LogicSettings.NotificationConfig.EnablePushBulletNotification == true)
                            {
                                await PushNotificationClient.SendNotification(session, $"{se.MatchedRule} - {session.Settings.Username}", $"This bot has reach limit, it will be blocked for {session.LogicSettings.MultipleBotConfig.OnLimitPauseTimes} mins for safety.", true).ConfigureAwait(false);
                            }

                            session.EventDispatcher.Send(new WarnEvent()
                            {
                                Message = $"You reach limited. bot will sleep for {session.LogicSettings.MultipleBotConfig.OnLimitPauseTimes} min"
                            });

                            TinyIoCContainer.Current.Resolve <MultiAccountManager>().BlockCurrentBot(session.LogicSettings.MultipleBotConfig.OnLimitPauseTimes);

                            ReInitializeSession(session, globalSettings);
                        }
                        else
                        {
                            ReInitializeSession(session, globalSettings);
                        }
                    }
                    //return to login state
                    state = new LoginState();
                }

                catch (InvalidResponseException e)
                {
                    session.EventDispatcher.Send(new ErrorEvent {
                        Message = $"Niantic Servers unstable, throttling API Calls. {e.Message}"
                    });
                    await Delay(1000).ConfigureAwait(false);

                    if (manager.AllowMultipleBot())
                    {
                        apiCallFailured++;
                        if (apiCallFailured > 20)
                        {
                            apiCallFailured = 0;
                            TinyIoCContainer.Current.Resolve <MultiAccountManager>().BlockCurrentBot(30);

                            ReInitializeSession(session, globalSettings);
                        }
                    }
                    state = new LoginState();
                }
                catch (SessionInvalidatedException e)
                {
                    session.EventDispatcher.Send(new ErrorEvent {
                        Message = $"Hashing Servers errors, throttling calls. {e.Message}"
                    });
                    await Delay(1000).ConfigureAwait(false);

                    if (manager.AllowMultipleBot())
                    {
                        apiCallFailured++;
                        if (apiCallFailured > 3)
                        {
                            apiCallFailured = 0;
                            TinyIoCContainer.Current.Resolve <MultiAccountManager>().BlockCurrentBot(30);

                            ReInitializeSession(session, globalSettings);
                        }
                    }

                    // Resetting position
                    session.EventDispatcher.Send(new ErrorEvent {
                        Message = $"Resetting position before relogging in."
                    });
                    session.Client.Player.UpdatePlayerLocation(session.Client.Settings.DefaultLatitude, session.Client.Settings.DefaultLongitude, session.Client.Settings.DefaultAltitude, 0);
                    state = new LoginState();
                }
                catch (OperationCanceledException)
                {
                    session.EventDispatcher.Send(new ErrorEvent {
                        Message = "Current Operation was canceled."
                    });
                    if (manager.AllowMultipleBot())
                    {
                        TinyIoCContainer.Current.Resolve <MultiAccountManager>().BlockCurrentBot(30);
                        ReInitializeSession(session, globalSettings);
                    }
                    state = new LoginState();
                }
                catch (PtcLoginException ex)
                {
                    if (session.LogicSettings.NotificationConfig.EnablePushBulletNotification == true)
                    {
                        await PushNotificationClient.SendNotification(session, $"PTC Login failed!!!! {session.Settings.Username}", session.Translation.GetTranslation(TranslationString.PtcLoginFail), true).ConfigureAwait(false);
                    }

                    if (manager.AllowMultipleBot())
                    {
                        TinyIoCContainer.Current.Resolve <MultiAccountManager>().BlockCurrentBot(60); //need remove acc
                        ReInitializeSession(session, globalSettings);
                        state = new LoginState();
                    }
                    else
                    {
                        session.EventDispatcher.Send(new ErrorEvent {
                            RequireExit = true, Message = session.Translation.GetTranslation(TranslationString.ExitNowAfterEnterKey)
                        });
                        session.EventDispatcher.Send(new ErrorEvent {
                            RequireExit = true, Message = session.Translation.GetTranslation(TranslationString.PtcLoginFail) + $" ({ex.Message})"
                        });

                        Console.ReadKey();
                        Environment.Exit(1);
                    }
                }
                catch (LoginFailedException)
                {
                    // TODO - await is legal here! USE it or use pragma to suppress compilerwarning and write a comment why it is not used
                    // TODO: Attention - do not touch (add pragma) when you do not know what you are doing ;)
                    // jjskuld - Ignore CS4014 warning for now.
                    if (session.LogicSettings.NotificationConfig.EnablePushBulletNotification == true)
                    {
                        await PushNotificationClient.SendNotification(session, $"Banned!!!! {session.Settings.Username}", session.Translation.GetTranslation(TranslationString.AccountBanned), true).ConfigureAwait(false);
                    }

                    if (manager.AllowMultipleBot())
                    {
                        TinyIoCContainer.Current.Resolve <MultiAccountManager>().BlockCurrentBot(24 * 60); //need remove acc
                        ReInitializeSession(session, globalSettings);
                        state = new LoginState();
                    }
                    else
                    {
                        session.EventDispatcher.Send(new ErrorEvent {
                            RequireExit = true, Message = session.Translation.GetTranslation(TranslationString.ExitNowAfterEnterKey)
                        });
                        Console.ReadKey();
                        Environment.Exit(1);
                    }
                }
                catch (MinimumClientVersionException ex)
                {
                    // We need to terminate the client.
                    session.EventDispatcher.Send(new ErrorEvent
                    {
                        Message = session.Translation.GetTranslation(TranslationString.MinimumClientVersionException, ex.CurrentApiVersion.ToString(), ex.MinimumClientVersion.ToString())
                    });

                    session.EventDispatcher.Send(new ErrorEvent {
                        RequireExit = true, Message = session.Translation.GetTranslation(TranslationString.ExitNowAfterEnterKey)
                    });
                    Console.ReadKey();
                    Environment.Exit(1);
                }
                catch (TokenRefreshException ex)
                {
                    session.EventDispatcher.Send(new ErrorEvent()
                    {
                        Message = ex.Message
                    });

                    if (manager.AllowMultipleBot())
                    {
                        ReInitializeSession(session, globalSettings);
                    }
                    state = new LoginState();
                }

                catch (PtcOfflineException)
                {
                    session.EventDispatcher.Send(new ErrorEvent {
                        Message = session.Translation.GetTranslation(TranslationString.PtcOffline)
                    });
                    session.EventDispatcher.Send(new NoticeEvent {
                        Message = session.Translation.GetTranslation(TranslationString.TryingAgainIn, 15)
                    });

                    await Delay(1000).ConfigureAwait(false);

                    state = _initialState;
                }
                catch (GoogleOfflineException)
                {
                    session.EventDispatcher.Send(new ErrorEvent {
                        Message = session.Translation.GetTranslation(TranslationString.GoogleOffline)
                    });
                    session.EventDispatcher.Send(new NoticeEvent {
                        Message = session.Translation.GetTranslation(TranslationString.TryingAgainIn, 15)
                    });

                    await Delay(15000).ConfigureAwait(false);

                    state = _initialState;
                }
                catch (AccessTokenExpiredException)
                {
                    session.EventDispatcher.Send(new NoticeEvent {
                        Message = "Access Token Expired. Logging in again..."
                    });
                    state = _initialState;
                }
                catch (CaptchaException captchaException)
                {
                    var resolved = await CaptchaManager.SolveCaptcha(session, captchaException.Url).ConfigureAwait(false);

                    if (!resolved)
                    {
                        if (session.LogicSettings.NotificationConfig.EnablePushBulletNotification == true)
                        {
                            await PushNotificationClient.SendNotification(session, $"Captcha required {session.Settings.Username}", session.Translation.GetTranslation(TranslationString.CaptchaShown), true).ConfigureAwait(false);
                        }

                        session.EventDispatcher.Send(new WarnEvent {
                            Message = session.Translation.GetTranslation(TranslationString.CaptchaShown)
                        });
                        Logger.Debug("Captcha not resolved");
                        if (manager.AllowMultipleBot())
                        {
                            Logger.Debug("Change account");
                            TinyIoCContainer.Current.Resolve <MultiAccountManager>().BlockCurrentBot(15);
                            ReInitializeSession(session, globalSettings);
                            state = new LoginState();
                        }
                        else
                        {
                            session.EventDispatcher.Send(new ErrorEvent {
                                Message = session.Translation.GetTranslation(TranslationString.ExitNowAfterEnterKey)
                            });
                            Console.ReadKey();
                            Environment.Exit(0);
                        }
                    }
                    else
                    {
                        //resolve captcha
                        state = new LoginState();
                    }
                }
                catch (HasherException ex)
                {
                    session.EventDispatcher.Send(new ErrorEvent {
                        Message = ex.Message
                    });
                    //  session.EventDispatcher.Send(new ErrorEvent { Message = session.Translation.GetTranslation(TranslationString.ExitNowAfterEnterKey) });
                    state = new IdleState();
                    //Console.ReadKey();
                    //System.Environment.Exit(1);
                }
                catch (Exception ex)
                {
                    session.EventDispatcher.Send(new ErrorEvent {
                        Message = "Pokemon Servers might be offline / unstable. Trying again..."
                    });
                    session.EventDispatcher.Send(new ErrorEvent {
                        Message = "Error: " + ex
                    });
                    if (state is LoginState)
                    {
                    }
                    else
                    {
                        state = _initialState;
                    }
                }
            } while (state != null);
            configWatcher.EnableRaisingEvents = false;
            configWatcher.Dispose();
        }
Пример #11
0
 public CaptchaService(CaptchaManager captchaManager)
 {
     _captchaManager = captchaManager;
 }
        private static void Text(ib0tClient client, String args, ulong time)
        {
            String text = args;

            if (text.StartsWith("#login") || text.StartsWith("#register"))
            {
                Command(client, text.Substring(1));
                return;
            }

            if (text.StartsWith("#") && client.SocketConnected)
            {
                Command(client, text.Substring(1));
            }

            if (client.SocketConnected)
            {
                if (!client.Captcha)
                {
                    if (String.IsNullOrEmpty(client.CaptchaWord) || (client.CaptchaWord.Length > 0 && client.CaptchaWord.ToUpper() != Helpers.StripColors(text).Trim().ToUpper()))
                    {
                        if (client.CaptchaWord.Length > 0 && client.CaptchaWord.ToUpper() != Helpers.StripColors(text).Trim().ToUpper())
                        {
                            Events.CaptchaReply(client, text);

                            if (!client.SocketConnected)
                            {
                                return;
                            }
                        }

                        CaptchaItem cap = Captcha.Create();
                        client.CaptchaWord = cap.Word;
                        Events.CaptchaSending(client);
                        client.QueuePacket(WebOutbound.NoSuchTo(client, String.Empty));

                        foreach (String str in cap.Lines)
                        {
                            client.QueuePacket(WebOutbound.NoSuchTo(client, str));
                        }

                        client.QueuePacket(WebOutbound.NoSuchTo(client, String.Empty));
                        return;
                    }
                    else
                    {
                        client.Captcha = true;
                        Events.CaptchaReply(client, text);
                        CaptchaManager.AddCaptcha(client);

                        if (client.Quarantined)
                        {
                            client.Unquarantine();
                        }

                        return;
                    }
                }
                else
                {
                    Events.TextReceived(client, text);
                }
            }
            else
            {
                return;
            }

            if (client.SocketConnected)
            {
                text = Events.TextSending(client, text);

                if (!String.IsNullOrEmpty(text) && client.SocketConnected && !client.Muzzled)
                {
                    if (client.Idled)
                    {
                        uint seconds_away = (uint)((Time.Now - client.IdleStart) / 1000);
                        IdleManager.Remove(client);
                        Events.Unidled(client, seconds_away);
                    }

                    if (client.SocketConnected)
                    {
                        byte[] js_style = null;

                        UserPool.AUsers.ForEachWhere(x =>
                        {
                            if (x.SupportsHTML)
                            {
                                if (String.IsNullOrEmpty(client.CustomName) || x.BlockCustomNames)
                                {
                                    if (x.SupportsHTML)
                                    {
                                        if (js_style != null)
                                        {
                                            x.SendPacket(js_style);
                                        }
                                    }

                                    x.SendPacket(TCPOutbound.Public(x, client.Name, text));
                                }
                                else
                                {
                                    if (x.SupportsHTML)
                                    {
                                        if (js_style != null)
                                        {
                                            x.SendPacket(js_style);
                                        }
                                    }

                                    x.SendPacket(TCPOutbound.NoSuch(x, client.CustomName + text));
                                }
                            }
                            else
                            {
                                if (String.IsNullOrEmpty(client.CustomName) || x.BlockCustomNames)
                                {
                                    x.SendPacket(TCPOutbound.Public(x, client.Name, text));
                                }
                                else
                                {
                                    x.SendPacket(TCPOutbound.NoSuch(x, client.CustomName + text));
                                }
                            }
                        }, x => x.LoggedIn && x.Vroom == client.Vroom && !x.IgnoreList.Contains(client.Name) && !x.Quarantined);

                        UserPool.WUsers.ForEachWhere(x => x.QueuePacket(String.IsNullOrEmpty(client.CustomName) ?
                                                                        ib0t.WebOutbound.PublicTo(x, client.Name, text) : ib0t.WebOutbound.NoSuchTo(x, client.CustomName + text)),
                                                     x => x.LoggedIn && x.Vroom == client.Vroom && !x.IgnoreList.Contains(client.Name) && !x.Quarantined);

                        if (ServerCore.Linker.Busy && ServerCore.Linker.LoginPhase == LinkLeaf.LinkLogin.Ready)
                        {
                            ServerCore.Linker.SendPacket(LinkLeaf.LeafOutbound.LeafPublicText(ServerCore.Linker, client.Name, text));
                        }

                        Events.TextSent(client, text);
                    }
                }
            }
        }
        private static void Login(ib0tClient client, String args, ulong time)
        {
            String[] arg_items = GetArgItems(args);

            client.Extended = int.Parse(arg_items[0]) >= 2000;

            byte[] g = new byte[16];

            for (int i = 0; i < g.Length; i++)
            {
                g[i] = byte.Parse(arg_items[1].Substring((i * 2), 2), NumberStyles.HexNumber);
            }

            using (MD5 md5 = MD5.Create())
                client.Guid = new Guid(md5.ComputeHash(g));

            client.OrgName = arg_items[2].Trim();
            Helpers.FormatUsername(client);
            client.Name         = client.OrgName;
            client.FastPing     = false;
            client.FileCount    = 0;
            client.DataPort     = 0;
            client.NodeIP       = IPAddress.Parse("0.0.0.0");
            client.NodePort     = 0;
            client.Version      = arg_items[4] + " [" + arg_items[3] + "]";
            client._pmsg        = arg_items[4];
            client.CustomClient = true;
            client.LocalIP      = client.ExternalIP;
            client.Browsable    = false;
            client.Age          = 0;
            client.Sex          = 0;
            client.Country      = 0;
            client.Region       = String.Empty;
            IPAddress p_check = new IPAddress(client.ExternalIP.GetAddressBytes());

            ObSalt.GetSalt(client);
            client.Captcha = !Settings.Get <bool>("captcha");

            if (!client.Captcha)
            {
                client.Captcha = CaptchaManager.HasCaptcha(client);
            }

            if ((UserPool.AUsers.FindAll(x => x.ExternalIP.Equals(client.ExternalIP)).Count +
                 UserPool.WUsers.FindAll(x => x.ExternalIP.Equals(client.ExternalIP)).Count) > 3)
            {
                Events.Rejected(client, RejectedMsg.TooManyClients);
                throw new Exception("too many clients from this ip");
            }

            if (UserHistory.IsJoinFlooding(client, time))
            {
                Events.Rejected(client, RejectedMsg.TooSoon);
                throw new Exception("joined too quickly");
            }

            IClient hijack = UserPool.AUsers.Find(x => (x.Name == client.Name ||
                                                        x.OrgName == client.OrgName) && x.ID != client.ID && x.LoggedIn);

            if (hijack == null)
            {
                hijack = UserPool.WUsers.Find(x => (x.Name == client.Name ||
                                                    x.OrgName == client.OrgName) && x.ID != client.ID && x.LoggedIn);
            }

            if (hijack != null)
            {
                if (hijack.ExternalIP.Equals(client.ExternalIP))
                {
                    if (!hijack.WebClient)
                    {
                        ((AresClient)hijack).Disconnect(true);
                    }
                    else
                    {
                        ((ib0t.ib0tClient)hijack).Disconnect();
                    }

                    client.Name = client.OrgName;
                }
                else
                {
                    Events.Rejected(client, RejectedMsg.NameInUse);
                    throw new Exception("name in use");
                }
            }

            UserHistory.AddUser(client, time);

            if (BanSystem.IsBanned(client))
            {
                if (!Helpers.IsLocalHost(client))
                {
                    if (hijack != null && hijack is AresClient)
                    {
                        ((AresClient)hijack).SendDepart();
                    }

                    Events.Rejected(client, RejectedMsg.Banned);
                    throw new Exception("banned user");
                }
            }

            if (Proxies.Check(p_check, client.DNS))
            {
                if (!Helpers.IsLocalHost(client))
                {
                    if (Events.ProxyDetected(client))
                    {
                        if (hijack != null && hijack is AresClient)
                        {
                            ((AresClient)hijack).SendDepart();
                        }

                        Events.Rejected(client, RejectedMsg.Proxy);
                        throw new Exception("proxy detected");
                    }
                }
            }

            client.Quarantined = !client.Captcha && Settings.Get <int>("captcha_mode") == 1;

            if (!Events.Joining(client))
            {
                if (!Helpers.IsLocalHost(client))
                {
                    if (hijack != null && hijack is AresClient)
                    {
                        ((AresClient)hijack).SendDepart();
                    }

                    Events.Rejected(client, RejectedMsg.UserDefined);
                    throw new Exception("user defined rejection");
                }
            }

            if (Helpers.IsLocalHost(client))
            {
                client.Captcha     = true;
                client.Quarantined = false;
                client.Registered  = true;
                client.Owner       = true;
            }

            if (!client.Quarantined)
            {
                if (hijack == null || !(hijack is AresClient))
                {
                    LinkLeaf.LinkUser other = null;

                    if (ServerCore.Linker.Busy)
                    {
                        foreach (LinkLeaf.Leaf leaf in ServerCore.Linker.Leaves)
                        {
                            other = leaf.Users.Find(x => x.Vroom == client.Vroom && x.Name == client.Name && x.Link.Visible);

                            if (other != null)
                            {
                                other.LinkCredentials.Visible = false;
                                break;
                            }
                        }
                    }

                    UserPool.AUsers.ForEachWhere(x => x.SendPacket(other == null ? TCPOutbound.Join(x, client) : TCPOutbound.UpdateUserStatus(x, client)),
                                                 x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined);

                    UserPool.WUsers.ForEachWhere(x => x.QueuePacket(other == null ? ib0t.WebOutbound.JoinTo(x, client.Name, client.Level) : ib0t.WebOutbound.UpdateTo(x, client.Name, client.Level)),
                                                 x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined);
                }

                client.LoggedIn = true;
                client.QueuePacket(WebOutbound.AckTo(client, client.Name));
                client.QueuePacket(WebOutbound.TopicFirstTo(client, Settings.Get <String>("topic")));
                client.QueuePacket(WebOutbound.UserlistItemTo(client, Settings.Get <String>("bot"), ILevel.Host));

                UserPool.AUsers.ForEachWhere(x => client.QueuePacket(WebOutbound.UserlistItemTo(client, x.Name, x.Level)),
                                             x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined);

                UserPool.WUsers.ForEachWhere(x => client.QueuePacket(WebOutbound.UserlistItemTo(client, x.Name, x.Level)),
                                             x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined);

                if (ServerCore.Linker.Busy)
                {
                    foreach (LinkLeaf.Leaf leaf in ServerCore.Linker.Leaves)
                    {
                        leaf.Users.ForEachWhere(x => client.QueuePacket(WebOutbound.UserlistItemTo(client, x.Name, x.Level)),
                                                x => x.Vroom == client.Vroom && x.Link.Visible);
                    }
                }

                client.QueuePacket(WebOutbound.UserlistEndTo(client));
                client.QueuePacket(WebOutbound.UrlTo(client, Settings.Get <String>("link", "url"), Settings.Get <String>("text", "url")));

                UserPool.AUsers.ForEachWhere(x => x.SendPacket(TCPOutbound.Avatar(x, client)),
                                             x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined);

                UserPool.WUsers.ForEachWhere(x => x.QueuePacket(WebOutbound.AvatarTo(x, client.Name, client.Avatar)),
                                             x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined && x.Extended);

                UserPool.AUsers.ForEachWhere(x => x.SendPacket(TCPOutbound.PersonalMessage(x, client)),
                                             x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined);

                UserPool.WUsers.ForEachWhere(x => x.QueuePacket(WebOutbound.PersMsgTo(x, client.Name, client.PersonalMessage)),
                                             x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined && x.Extended);

                if (client.Extended)
                {
                    client.QueuePacket(WebOutbound.PerMsgBotTo(client));

                    if (Avatars.GotServerAvatar)
                    {
                        client.QueuePacket(Avatars.Server(client));
                    }

                    UserPool.AUsers.ForEachWhere(x => client.QueuePacket(WebOutbound.AvatarTo(client, x.Name, x.Avatar)),
                                                 x => x.LoggedIn && x.Vroom == client.Vroom && x.Avatar.Length > 0 && !x.Quarantined);

                    UserPool.WUsers.ForEachWhere(x => client.QueuePacket(WebOutbound.AvatarTo(client, x.Name, x.Avatar)),
                                                 x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined);

                    if (ServerCore.Linker.Busy)
                    {
                        foreach (LinkLeaf.Leaf leaf in ServerCore.Linker.Leaves)
                        {
                            leaf.Users.ForEachWhere(x => client.QueuePacket(WebOutbound.AvatarTo(client, x.Name, x.Avatar)),
                                                    x => x.Vroom == client.Vroom && x.Link.Visible && x.Avatar.Length > 0);
                        }
                    }

                    UserPool.AUsers.ForEachWhere(x => client.QueuePacket(WebOutbound.PersMsgTo(client, x.Name, x.PersonalMessage)),
                                                 x => x.LoggedIn && x.Vroom == client.Vroom && x.PersonalMessage.Length > 0 && !x.Quarantined);

                    UserPool.WUsers.ForEachWhere(x => client.QueuePacket(WebOutbound.PersMsgTo(client, x.Name, x.PersonalMessage)),
                                                 x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined);

                    UserPool.AUsers.ForEachWhere(x =>
                    {
                        AresFont f = (AresFont)x.Font;
                        client.QueuePacket(WebOutbound.FontTo(client, x.Name, f.oldN, f.oldT));
                    }, x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined && x.Font.Enabled);

                    if (ServerCore.Linker.Busy)
                    {
                        foreach (LinkLeaf.Leaf leaf in ServerCore.Linker.Leaves)
                        {
                            leaf.Users.ForEachWhere(x => client.QueuePacket(WebOutbound.PersMsgTo(client, x.Name, x.PersonalMessage)),
                                                    x => x.Vroom == client.Vroom && x.Link.Visible && x.PersonalMessage.Length > 0);
                        }
                    }
                }

                FloodControl.Remove(client);

                if (client.SocketConnected)
                {
                    IdleManager.Set(client);
                }

                if (ServerCore.Linker.Busy && ServerCore.Linker.LoginPhase == LinkLeaf.LinkLogin.Ready)
                {
                    ServerCore.Linker.SendPacket(LinkLeaf.LeafOutbound.LeafJoin(ServerCore.Linker, client));
                }

                Events.Joined(client);

                if (client.Owner)
                {
                    client.Level = ILevel.Host;
                }
            }
            else
            {
                if (hijack != null && hijack is AresClient)
                {
                    ((AresClient)hijack).SendDepart();
                }

                client.LoggedIn = true;
                client.QueuePacket(WebOutbound.AckTo(client, client.Name));
                client.QueuePacket(WebOutbound.TopicFirstTo(client, Settings.Get <String>("topic")));
                client.QueuePacket(WebOutbound.UserlistEndTo(client));
                client.QueuePacket(WebOutbound.PerMsgBotTo(client));
                client.QueuePacket(Avatars.Server(client));

                CaptchaItem cap = Captcha.Create();
                client.CaptchaWord = cap.Word;
                Events.CaptchaSending(client);
                client.QueuePacket(WebOutbound.NoSuchTo(client, String.Empty));

                foreach (String str in cap.Lines)
                {
                    client.QueuePacket(WebOutbound.NoSuchTo(client, str));
                }

                client.QueuePacket(WebOutbound.NoSuchTo(client, String.Empty));
            }
        }