Esempio n. 1
0
        public void Authenticate()
        {
            Licensing.User user = new Licensing.User();
            user.hWID      = Program.fingerprint;
            user.timeStamp = DateTime.Now;

            try
            {
                var res    = CheckLicense(user).GetAwaiter().GetResult();
                var aTimer = new System.Timers.Timer(6 * 1000); //one hour in milliseconds
                aTimer.Enabled = true;

                if (res.status)
                {
                    this.Invoke((MethodInvoker) delegate
                    {
                        label2.Text = res.expirationDate.ToString();
                        Bot.Log("License valid until: " + res.expirationDate);
                        DownloadFiles();
                    });
                    aTimer.Elapsed += new ElapsedEventHandler((sender, e) => OnTimedEvent(sender, e, res.expirationDate));
                    aTimer.Start();
                }
                else
                {
                    try
                    {
                        this.Invoke((MethodInvoker) delegate
                        {
                            buttonStart.Invoke((MethodInvoker)(() =>
                            {
                                buttonStart.Enabled = false;
                            }));
                            Bot.Log(
                                "You don't have a valid license to use the bot! " +
                                "Please contact on the Discord server for more information.");
                        });
                    }
                    catch
                    {
                        Application.Exit();
                    }
                }
            }
            catch (Exception ex)
            {
                buttonStart.Invoke((MethodInvoker)(() =>
                {
                    buttonStart.Enabled = false;
                }));
                ShowErrorAndClose(ex.Message);
            }
        }
Esempio n. 2
0
        private async Task <RoleValidation> CheckLicense(Licensing.User user)
        {
            try
            {
                using (var httpClient = new HttpClient())
                {
#if DEBUG
                    //httpClient.BaseAddress = new Uri("https://akchan.me/");
                    httpClient.BaseAddress = new Uri("http://localhost:5000/");
#else
                    httpClient.BaseAddress = new Uri("https://akchan.me/");
#endif
                    httpClient.DefaultRequestHeaders.Accept.Clear();
                    httpClient.DefaultRequestHeaders.Accept.Add(
                        new MediaTypeWithQualityHeaderValue("application/json"));


                    //var crypto = new ClsCrypto("lol");
                    //DateTime result;
                    //DateTime.TryParse(crypto.Encrypt(user.timeStamp.ToString()), out result);
                    //user.timeStamp = result;

                    using (var response = httpClient.PostAsJsonAsync("api/checkLicense", user).Result)
                    {
                        if (response.IsSuccessStatusCode)
                        {
                            RoleValidation roleValidation = response.Content.ReadAsAsync <RoleValidation>().Result;
                            return(roleValidation);
                        }
                        else
                        {
                            Bot.Log("Can't connect to the license server.");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ShowErrorAndClose(ex.Message);
            }
            return(new RoleValidation());
        }