コード例 #1
0
        public override void Login(string Username, string Password, string twofa)
        {
            try
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
                                                       | SecurityProtocolType.Tls11
                                                       | SecurityProtocolType.Tls12
                                                       | SecurityProtocolType.Ssl3;
                cookies      = new CookieContainer();
                ClientHandlr = new HttpClientHandler
                {
                    UseCookies             = true,
                    CookieContainer        = cookies,
                    AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip,
                    Proxy    = (IWebProxy)this.Prox,
                    UseProxy = this.Prox != null
                };
                WebClient = new HttpClient(ClientHandlr)
                {
                    BaseAddress = new Uri("https://www.bitdice.me/")
                };
                WebClient.DefaultRequestHeaders.AcceptEncoding.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("gzip"));
                WebClient.DefaultRequestHeaders.AcceptEncoding.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("deflate"));
                WebClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0");

                string s1 = "";
                try
                {
                    /*HttpResponseMessage resp = WebClient.GetAsync("").Result;
                     * if (resp.IsSuccessStatusCode)
                     * {
                     *  s1 = resp.Content.ReadAsStringAsync().Result;
                     * }
                     * else
                     * {
                     *  if (resp.StatusCode == HttpStatusCode.ServiceUnavailable)
                     *  {
                     *      s1 = resp.Content.ReadAsStringAsync().Result;
                     *      //cflevel = 0;
                     *      System.Threading.Tasks.Task.Factory.StartNew(() =>
                     *      {
                     *          System.Windows.Forms.MessageBox.Show("bitdice.me has their cloudflare protection on HIGH\n\nThis will cause a slight delay in logging in. Please allow up to a minute.");
                     *      });
                     *      if (!Cloudflare.doCFThing(s1, WebClient, ClientHandlr, 0, "www.bitdice.me"))
                     *      {
                     *          finishedlogin(false);
                     *          return;
                     *      }*/
                    /*if (!Cloudflare.doCFThing(s1, WebClient, ClientHandlr, 0, "www.bitdice.me"))
                     * {
                     *  finishedlogin(false);
                     *  return;
                     * }*/

                    /*}
                     * }*/
                    string a = json.JsonSerializer <bitdicedatainfo>(new bitdicedatainfo());

                    //encode
                    //a = System.Web.HttpUtility.HtmlEncode(a);
                    //a = a.Replace("+", "%20");
                    //unescape
                    a = System.Web.HttpUtility.UrlDecode(a);

                    //base 64 encode

                    /*a = EncodeTo64(a);
                     *  user[username]:etaeasdf
                     * user[two_fa]:
                     * user[password]:asdfasdfasdf*/
                    List <KeyValuePair <string, string> > pairs = new List <KeyValuePair <string, string> >();
                    if (Username.Contains("@") && Username.Contains("."))
                    {
                        pairs.Add(new KeyValuePair <string, string>("user[email]", Username));
                    }
                    else
                    {
                        pairs.Add(new KeyValuePair <string, string>("user[username]", Username));
                    }
                    pairs.Add(new KeyValuePair <string, string>("data[info]", a));
                    pairs.Add(new KeyValuePair <string, string>("user[password]", Password /*==""?"undefined":twofa*/));
                    pairs.Add(new KeyValuePair <string, string>("user[two_fa]", twofa /*==""?"undefined":twofa*/));


                    FormUrlEncodedContent Content = new FormUrlEncodedContent(pairs);
                    string       sEmitResponse    = WebClient.PostAsync("api/sign_in", Content).Result.Content.ReadAsStringAsync().Result;
                    bitdicelogin login            = json.JsonDeserialize <bitdicelogin>(sEmitResponse);
                    if (login.status)
                    {
                        stream = login.token;
                    }
                    else
                    {
                        finishedlogin(false);
                        return;
                    }
                    sEmitResponse = WebClient.GetAsync("dashboard").Result.Content.ReadAsStringAsync().Result;
                }
                catch
                {
                    finishedlogin(false);
                    return;
                }
                Cookie c = new Cookie();

                username = Username;

                //

                List <KeyValuePair <string, string> > headers  = new List <KeyValuePair <string, string> >();
                List <KeyValuePair <string, string> > cookies2 = new List <KeyValuePair <string, string> >();
                string cookie = "";
                foreach (Cookie x in ClientHandlr.CookieContainer.GetCookies(new Uri("https://www.bitdice.me")))
                {
                    if (x.Name.ToLower() == "token")
                    {
                        cookies2.Add(new KeyValuePair <string, string>(x.Name, x.Value.Replace("%3D", "=")));
                    }
                    else
                    {
                        cookies2.Add(new KeyValuePair <string, string>(x.Name, x.Value));
                    }
                }
                for (int i = 0; i < cookies2.Count; i++)
                {
                    if (i != 0)
                    {
                        cookie += "; ";
                    }
                    cookie += cookies2[i].Key + "=" + cookies2[i].Value;
                }
                //cookies2.Add(new KeyValuePair<string, string>("Authorized", "1"));


                headers.Add(new KeyValuePair <string, string>("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0"));

                Client = new WebSocket("wss://www.bitdice.me/socket" /*/?token=" + stream*/, "actioncable-v1-json", cookies2, headers, "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0",
                                       "https://www.bitdice.me", WebSocketVersion.Rfc6455, null, System.Security.Authentication.SslProtocols.Tls | System.Security.Authentication.SslProtocols.Tls11 | System.Security.Authentication.SslProtocols.Tls12);


                Client.Opened          += Client_Opened;
                Client.Error           += Client_Error;
                Client.Closed          += Client_Closed;
                Client.MessageReceived += Client_MessageReceived;


                Client.Open();
                while (Client.State == WebSocketState.Connecting)
                {
                    Thread.Sleep(100);
                }
                //CurrencyChanged();
                loggedin   = true;
                lastUpdate = DateTime.Now;
                new Thread(new ThreadStart(GetBalanceThread)).Start();
                finishedlogin(Client.State == WebSocketState.Open);
                loggedin = true;
                //System.Windows.Forms.MessageBox.Show("Due to current limitations of the API, I can't show you your stats until you place a valid bet. Sorry.\n\nAlso, you will need to reselect your currency. If you already selected the currency you want to play in, please select another first, and then switch back.", "Stats Errors", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
            }
            catch (WebException e)
            {
                if (e.Response != null)
                {
                    string s = new StreamReader(e.Response.GetResponseStream()).ReadToEnd();
                    finishedlogin(false);
                    return;
                }
            }
            catch
            {
                finishedlogin(false);
                return;
            }
        }
コード例 #2
0
ファイル: bitdice.cs プロジェクト: Avanatiker/DiceBot
        public override void Login(string Username, string Password, string twofa)
        {
            try
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
                                                       | SecurityProtocolType.Tls11
                                                       | SecurityProtocolType.Tls12
                                                       | SecurityProtocolType.Ssl3;
                cookies      = new CookieContainer();
                ClientHandlr = new HttpClientHandler
                {
                    UseCookies             = true,
                    CookieContainer        = cookies,
                    AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip,
                    Proxy    = (IWebProxy)this.Prox,
                    UseProxy = this.Prox != null
                };
                WebClient = new HttpClient(ClientHandlr)
                {
                    BaseAddress = new Uri("https://www.bitdice.me/")
                };
                WebClient.DefaultRequestHeaders.AcceptEncoding.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("gzip"));
                WebClient.DefaultRequestHeaders.AcceptEncoding.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("deflate"));
                WebClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0");

                string s1 = "";
                try
                {
                    /*HttpResponseMessage resp = WebClient.GetAsync("").Result;
                     * if (resp.IsSuccessStatusCode)
                     * {
                     *  s1 = resp.Content.ReadAsStringAsync().Result;
                     * }
                     * else
                     * {
                     *  if (resp.StatusCode == HttpStatusCode.ServiceUnavailable)
                     *  {
                     *      s1 = resp.Content.ReadAsStringAsync().Result;
                     *      //cflevel = 0;
                     *      System.Threading.Tasks.Task.Factory.StartNew(() =>
                     *      {
                     *          System.Windows.Forms.MessageBox.Show("bitdice.me has their cloudflare protection on HIGH\n\nThis will cause a slight delay in logging in. Please allow up to a minute.");
                     *      });
                     *      if (!Cloudflare.doCFThing(s1, WebClient, ClientHandlr, 0, "www.bitdice.me"))
                     *      {
                     *          finishedlogin(false);
                     *          return;
                     *      }*/
                    /*if (!Cloudflare.doCFThing(s1, WebClient, ClientHandlr, 0, "www.bitdice.me"))
                     * {
                     *  finishedlogin(false);
                     *  return;
                     * }*/

                    /*}
                     * }*/
                    //data%5Binfo%5D=eyJsYW5nIjoiZW4tVVMsIGVuIiwicGxhdGZvcm0iOiJXaW4zMiIsImNwdSI6OCwic2l6ZSI6IjE1ODN4NDI1MCAoMTYwMHg5MDApIiwid2VicnRjIjoiMTY5LjI1NC44MC44MCwgMTkyLjE2OC4xLjMiLCJ0aW1lem9uZSI6IkFmcmljYS9Kb2hhbm5lc2J1cmciLCJ0aW1lIjoiU3VuIERlYyAxMSAyMDE2IDExOjQzOjM1IEdNVCswMjAwIChTb3V0aCBBZnJpY2EgU3RhbmRhcmQgVGltZSkifQ%3D%3D&user%5Bemail%5D=seuntjie%40seuntjie.com&user%5Bpassword%5D=qFkIn1q8FZvljdbmytXq&user%5Btwo_fa%5D=
                    string a = json.JsonSerializer <bitdicedatainfo>(new bitdicedatainfo());

                    //encode
                    //a = System.Web.HttpUtility.HtmlEncode(a);
                    //a = a.Replace("+", "%20");
                    //unescape
                    a = System.Web.HttpUtility.UrlDecode(a);

                    //base 64 encode
                    a = EncodeTo64(a);

                    List <KeyValuePair <string, string> > pairs = new List <KeyValuePair <string, string> >();
                    pairs.Add(new KeyValuePair <string, string>("data[info]", a));
                    pairs.Add(new KeyValuePair <string, string>("user[email]", Username));
                    pairs.Add(new KeyValuePair <string, string>("user[password]", Password /*==""?"undefined":twofa*/));
                    pairs.Add(new KeyValuePair <string, string>("user[two_fa]", twofa /*==""?"undefined":twofa*/));
                    FormUrlEncodedContent Content = new FormUrlEncodedContent(pairs);
                    string       sEmitResponse    = WebClient.PostAsync("api/sign_in", Content).Result.Content.ReadAsStringAsync().Result;
                    bitdicelogin login            = json.JsonDeserialize <bitdicelogin>(sEmitResponse);
                    if (login.status)
                    {
                        stream = login.token;
                    }
                    else
                    {
                        finishedlogin(false);
                        return;
                    }
                }
                catch
                {
                    finishedlogin(false);
                    return;
                }
                Cookie c = new Cookie();

                username = Username;

                //

                List <KeyValuePair <string, string> > headers  = new List <KeyValuePair <string, string> >();
                List <KeyValuePair <string, string> > cookies2 = new List <KeyValuePair <string, string> >();
                foreach (Cookie x in ClientHandlr.CookieContainer.GetCookies(new Uri("https://www.bitdice.me")))
                {
                    cookies2.Add(new KeyValuePair <string, string>(x.Name, x.Value));
                }

                headers.Add(new KeyValuePair <string, string>("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0"));

                Client = new WebSocket("wss://www.bitdice.me/socket/?token=" + stream, "actioncable-v1-json", cookies2, headers, "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0",
                                       "https://www.bitdice.me", WebSocketVersion.Rfc6455, null, System.Security.Authentication.SslProtocols.Tls | System.Security.Authentication.SslProtocols.Tls11 | System.Security.Authentication.SslProtocols.Tls12);


                Client.Opened          += Client_Opened;
                Client.Error           += Client_Error;
                Client.Closed          += Client_Closed;
                Client.MessageReceived += Client_MessageReceived;


                Client.Open();
                while (Client.State == WebSocketState.Connecting)
                {
                    Thread.Sleep(100);
                }
                //CurrencyChanged();
                finishedlogin(Client.State == WebSocketState.Open);
                loggedin = true;
                //System.Windows.Forms.MessageBox.Show("Due to current limitations of the API, I can't show you your stats until you place a valid bet. Sorry.\n\nAlso, you will need to reselect your currency. If you already selected the currency you want to play in, please select another first, and then switch back.", "Stats Errors", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
            }
            catch (WebException e)
            {
                if (e.Response != null)
                {
                    string s = new StreamReader(e.Response.GetResponseStream()).ReadToEnd();
                    finishedlogin(false);
                    return;
                }
            }
            catch
            {
                finishedlogin(false);
                return;
            }
        }