コード例 #1
0
ファイル: SafeDice.cs プロジェクト: wmgjang/DiceBot
        public override void Login(string Username, string Password, string twofa)
        {
            try
            {
                HttpWebRequest loginrequest = (HttpWebRequest)HttpWebRequest.Create("https://safedice.com/auth/local");
                if (Prox != null)
                {
                    loginrequest.Proxy = Prox;
                }
                loginrequest.Method = "POST";
                string post = "username="******"&password="******"&code=" + twofa;
                loginrequest.ContentLength = post.Length;
                loginrequest.ContentType   = "application/x-www-form-urlencoded; charset=UTF-8";
                loginrequest.Headers.Add("authorization", "Bearer " + accesstoken);
                using (var writer = new StreamWriter(loginrequest.GetRequestStream()))
                {
                    writer.Write(post);
                }
                HttpWebResponse EmitResponse  = (HttpWebResponse)loginrequest.GetResponse();
                string          sEmitResponse = new StreamReader(EmitResponse.GetResponseStream()).ReadToEnd();
                SafeDiceLogin   tmp           = json.JsonDeserialize <SafeDiceLogin>(sEmitResponse);
                accesstoken = tmp.token;
                if (accesstoken == "")
                {
                    finishedlogin(false);
                }
                else
                {
                    loginrequest = (HttpWebRequest)HttpWebRequest.Create("https://safedice.com/api/accounts/me?token=" + accesstoken);
                    if (Prox != null)
                    {
                        loginrequest.Proxy = Prox;
                    }
                    loginrequest.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";

                    loginrequest.CookieContainer = new CookieContainer();
                    loginrequest.CookieContainer.Add(new Cookie("token", accesstoken, "/", "safedice.com"));
                    loginrequest.Headers.Add("authorization", "Bearer " + accesstoken);
                    EmitResponse  = (HttpWebResponse)loginrequest.GetResponse();
                    sEmitResponse = new StreamReader(EmitResponse.GetResponseStream()).ReadToEnd();
                    SafeDicegetUserInfo tmp1 = json.JsonDeserialize <SafeDicegetUserInfo>(sEmitResponse);

                    loginrequest = (HttpWebRequest)HttpWebRequest.Create("https://safedice.com/api/accounts/" + tmp1.id + "/sites/" + curen + "/me");
                    if (Prox != null)
                    {
                        loginrequest.Proxy = Prox;
                    }
                    loginrequest.CookieContainer = new CookieContainer();
                    loginrequest.CookieContainer.Add(new Cookie("token", accesstoken, "", "safedice.com"));
                    loginrequest.Headers.Add("authorization", "Bearer " + accesstoken);
                    EmitResponse  = (HttpWebResponse)loginrequest.GetResponse();
                    sEmitResponse = new StreamReader(EmitResponse.GetResponseStream()).ReadToEnd();
                    SafeDiceWalletInfo tmp2 = json.JsonDeserialize <SafeDiceWalletInfo>(sEmitResponse);
                    Parent.updateBalance(tmp2.balance / (curen != 2 ? 100000000m : 1000000000000m));
                    balance = tmp2.balance / (curen != 2 ? 100000000.0 : 1000000000000.0);

                    Parent.updateBets(tmp2.win + tmp2.lose);
                    Parent.updateLosses(tmp2.lose);
                    wins   = (int)tmp2.win;
                    losses = (int)tmp2.lose;
                    Parent.updateProfit((tmp2.amountWin - tmp2.amountLose) / (curen != 2 ? 100000000.0 : 1000000000000.0));
                    profit = (tmp2.amountWin - tmp2.amountLose) / (curen != 2 ? 100000000.0 : 1000000000000.0);
                    Parent.updateWagered(tmp2.wagered / (curen != 2 ? 100000000.0 : 1000000000000.0));
                    wagered = tmp2.wagered / (curen != 2 ? 100000000.0 : 1000000000000.0);
                    Parent.updateWins(tmp2.win);
                    Parent.updateStatus("Logged in");
                    serverhash = tmp1.serverSeedHash;
                    client     = tmp1.accountSeed;
                    nonce      = tmp1.nonce;
                    UID        = tmp1.id;
                    Parent.updateDeposit(GetDepositAddress());
                    finishedlogin(true);
                }
            }
            catch (WebException e)
            {
                if (e.Response != null)
                {
                    string sEmitResponse = new StreamReader(e.Response.GetResponseStream()).ReadToEnd();
                    Parent.updateStatus(sEmitResponse);
                    if (e.Message.Contains("401"))
                    {
                        //System.Windows.Forms.MessageBox.Show("Could not log in. Please ensure the username, passowrd and 2fa code are all correct.");
                    }
                }
                finishedlogin(false);
            }
        }
コード例 #2
0
ファイル: SafeDice.cs プロジェクト: vosa88/DiceBot
        public override bool Register(string username, string password)
        {
            //System.Windows.Forms.MessageBox.Show("Registration is temporarily disabled for Safe Dice. Please use the site https://safedice.com to register and then log in using the bot.");
            //return false;
            try
            {
                HttpWebRequest loginrequest = (HttpWebRequest)HttpWebRequest.Create("https://safedice.com/api/accounts");
                if (Prox != null)
                {
                    loginrequest.Proxy = Prox;
                }
                loginrequest.Method = "POST";
                string post = "username="******"&referralId=" + 1050;
                loginrequest.ContentLength = post.Length;
                loginrequest.ContentType   = "application/x-www-form-urlencoded; charset=UTF-8";
                loginrequest.Headers.Add("authorization", "Bearer " + accesstoken);
                using (var writer = new StreamWriter(loginrequest.GetRequestStream()))
                {
                    writer.Write(post);
                }
                HttpWebResponse EmitResponse  = (HttpWebResponse)loginrequest.GetResponse();
                string          sEmitResponse = new StreamReader(EmitResponse.GetResponseStream()).ReadToEnd();
                SafeDiceLogin   tmp           = json.JsonDeserialize <SafeDiceLogin>(sEmitResponse);
                accesstoken = tmp.token;
                if (accesstoken == "")
                {
                    finishedlogin(false);
                }
                else
                {
                    loginrequest = (HttpWebRequest)HttpWebRequest.Create("https://safedice.com/api/accounts/me?token=" + accesstoken);
                    if (Prox != null)
                    {
                        loginrequest.Proxy = Prox;
                    }
                    loginrequest.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";

                    loginrequest.CookieContainer = new CookieContainer();
                    loginrequest.CookieContainer.Add(new Cookie("token", accesstoken, "/", "safedice.com"));
                    loginrequest.Headers.Add("authorization", "Bearer " + accesstoken);
                    EmitResponse  = (HttpWebResponse)loginrequest.GetResponse();
                    sEmitResponse = new StreamReader(EmitResponse.GetResponseStream()).ReadToEnd();
                    SafeDicegetUserInfo tmp1 = json.JsonDeserialize <SafeDicegetUserInfo>(sEmitResponse);

                    loginrequest = (HttpWebRequest)HttpWebRequest.Create("https://safedice.com/api/accounts/" + tmp1.id + "/sites/" + curen + "/me");
                    if (Prox != null)
                    {
                        loginrequest.Proxy = Prox;
                    }
                    loginrequest.CookieContainer = new CookieContainer();
                    loginrequest.CookieContainer.Add(new Cookie("token", accesstoken, "", "safedice.com"));
                    loginrequest.Headers.Add("authorization", "Bearer " + accesstoken);
                    EmitResponse  = (HttpWebResponse)loginrequest.GetResponse();
                    sEmitResponse = new StreamReader(EmitResponse.GetResponseStream()).ReadToEnd();
                    SafeDiceWalletInfo tmp2 = json.JsonDeserialize <SafeDiceWalletInfo>(sEmitResponse);



                    loginrequest = (HttpWebRequest)HttpWebRequest.Create("https://safedice.com/api/accounts/userpass");
                    if (Prox != null)
                    {
                        loginrequest.Proxy = Prox;
                    }
                    loginrequest.ContentType     = "application/json;charset=utf-8";
                    loginrequest.Method          = "PUT";
                    loginrequest.CookieContainer = new CookieContainer();
                    loginrequest.CookieContainer.Add(new Cookie("token", accesstoken, "/", "safedice.com"));
                    loginrequest.Headers.Add("Authorization", "Bearer " + accesstoken);
                    post = json.JsonSerializer <SDSetPw>(new SDSetPw {
                        username = username, password = password
                    });
                    loginrequest.ContentLength = post.Length;
                    using (var writer = new StreamWriter(loginrequest.GetRequestStream()))
                    {
                        writer.Write(post);
                    }
                    EmitResponse  = (HttpWebResponse)loginrequest.GetResponse();
                    sEmitResponse = new StreamReader(EmitResponse.GetResponseStream()).ReadToEnd();

                    ClientHandlr = new HttpClientHandler()
                    {
                        UseCookies             = true,
                        AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip,
                        Proxy    = (IWebProxy)this.Prox,
                        UseProxy = this.Prox != null
                    };

                    ClientHandlr.CookieContainer = new CookieContainer();
                    ClientHandlr.CookieContainer.Add(new Cookie("token", accesstoken, "/", "safedice.com"));
                    Client = new HttpClient(ClientHandlr)
                    {
                        BaseAddress = new Uri("https://safedice.com/api/")
                    };
                    Client.DefaultRequestHeaders.AcceptEncoding.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("gzip"));
                    Client.DefaultRequestHeaders.AcceptEncoding.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("deflate"));
                    Client.DefaultRequestHeaders.Add("authorization", "Bearer " + accesstoken);
                    Parent.updateBalance(tmp2.balance / (curen != 2 ? 100000000m : 1000000000000m));
                    balance = tmp2.balance / (curen != 2 ? 100000000.0m : 1000000000000.0m);

                    Parent.updateBets(tmp2.win + tmp2.lose);
                    Parent.updateLosses(tmp2.lose);
                    wins   = (int)tmp2.win;
                    losses = (int)tmp2.lose;
                    Parent.updateProfit((tmp2.amountWin - tmp2.amountLose) / (curen != 2 ? 100000000.0m : 1000000000000.0m));
                    profit = (tmp2.amountWin - tmp2.amountLose) / (curen != 2 ? 100000000.0m : 1000000000000.0m);
                    Parent.updateWagered(tmp2.wagered / (curen != 2 ? 100000000.0m : 1000000000000.0m));
                    wagered = tmp2.wagered / (curen != 2 ? 100000000.0m : 1000000000000.0m);
                    Parent.updateWins(tmp2.win);
                    Parent.updateStatus("Logged in");
                    serverhash = tmp1.serverSeedHash;
                    client     = tmp1.accountSeed;
                    nonce      = tmp1.nonce;
                    UID        = tmp1.id;
                    Parent.updateDeposit(GetDepositAddress());
                    ispd = true;
                    Thread t = new Thread(GetBalanceThread);
                    t.Start();
                    finishedlogin(true);
                }
            }
            catch (WebException e)
            {
                if (e.Response != null)
                {
                    string sEmitResponse = new StreamReader(e.Response.GetResponseStream()).ReadToEnd();
                    //Parent.updateStatus(sEmitResponse);
                    if (e.Message.Contains("401"))
                    {
                        //System.Windows.Forms.MessageBox.Show("Could not log in. Please ensure the username, passowrd and 2fa code are all correct.");
                    }
                }
                finishedlogin(false);
            }
            return(false);
        }
コード例 #3
0
        public override void Login(string Username, string Password, string twofa)
        {
            LastBalance = DateTime.Now;
            try
            {
                ClientHandlr = new HttpClientHandler()
                {
                    UseCookies             = true,
                    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
                    Proxy    = (IWebProxy)this.Prox,
                    UseProxy = this.Prox != null
                };

                ClientHandlr.CookieContainer = new CookieContainer();
                //ClientHandlr.CookieContainer.Add(new Cookie("token", accesstoken, "/", "safedice.com"));
                Client = new HttpClient(ClientHandlr)
                {
                    BaseAddress = new Uri("https://safedice.com/")
                };
                Client.DefaultRequestHeaders.AcceptEncoding.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("gzip"));
                Client.DefaultRequestHeaders.AcceptEncoding.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("deflate"));
                Client.DefaultRequestHeaders.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36");

                string s1 = "";
                HttpResponseMessage resp = Client.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("safedice.com 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, Client, ClientHandlr, 0, "www.safedice.com"))
                        {
                            finishedlogin(false);
                            return;
                        }
                    }
                    else
                    {
                    }
                }

                /*if (!Cloudflare.doCFThing(s1, WebClient, ClientHandlr, 0, "www.bitdice.me"))
                 * {
                 *  finishedlogin(false);
                 *  return;
                 * }*/

                /*}
                 * }*/

                /*HttpWebRequest loginrequest = (HttpWebRequest)HttpWebRequest.Create("https://safedice.com/auth/local");
                 * if (Prox != null)
                 *  loginrequest.Proxy = Prox;
                 * loginrequest.Method = "POST";
                 * string post = "username="******"&password="******"&code=" + twofa;
                 * loginrequest.ContentLength = post.Length;
                 * loginrequest.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
                 * loginrequest.Headers.Add("authorization", "Bearer " + accesstoken);
                 * using (var writer = new StreamWriter(loginrequest.GetRequestStream()))
                 * {
                 *
                 *  writer.Write(post);
                 * }
                 * HttpWebResponse EmitResponse = (HttpWebResponse)loginrequest.GetResponse();
                 * string sEmitResponse = new StreamReader(EmitResponse.GetResponseStream()).ReadToEnd();*/

                //List < KeyValuePair<string, string>> pairs = new List<KeyValuePair<string, string>>();
                //         pairs.Add(new KeyValuePair<string, string>("username", Username));
                //         pairs.Add(new KeyValuePair<string, string>("captcha", ""));

                //         pairs.Add(new KeyValuePair<string, string>("password", Password/*==""?"undefined":twofa*/));
                //         pairs.Add(new KeyValuePair<string, string>("code", twofa/*==""?"undefined":twofa*/));
                Thread.Sleep(1000);
                string loginjson = json.JsonSerializer <SafeDiceLoginPost>(new SafeDiceLoginPost()
                {
                    username = Username,
                    password = Password,
                    code     = twofa,
                    captcha  = "094t3y8e47byegr"
                });//string.Format("{{username:\"{0}\",password:\"{1}\",code:\"{2}\",captcha:\"{3}\"}}",Username,Password,twofa,"");

                HttpContent cont = new StringContent(loginjson);
                cont.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
                HttpResponseMessage resp2 = Client.PostAsync("https://safedice.com/auth/local", cont).Result;

                if (resp2.IsSuccessStatusCode)
                {
                }
                string        sEmitResponse = resp2.Content.ReadAsStringAsync().Result;
                SafeDiceLogin tmp           = json.JsonDeserialize <SafeDiceLogin>(sEmitResponse);
                accesstoken = tmp.token;
                if (accesstoken == "")
                {
                    finishedlogin(false);
                }
                else
                {
                    Client.DefaultRequestHeaders.Add("authorization", "Bearer " + accesstoken);

                    /*loginrequest = (HttpWebRequest)HttpWebRequest.Create("https://safedice.com/api/accounts/me?token=" + accesstoken);
                     * if (Prox != null)
                     *  loginrequest.Proxy = Prox;
                     * loginrequest.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
                     *
                     * loginrequest.CookieContainer = new CookieContainer();
                     * loginrequest.CookieContainer.Add(new Cookie("token", accesstoken, "/", "safedice.com"));
                     * loginrequest.Headers.Add("authorization", "Bearer " + accesstoken);
                     * EmitResponse = (HttpWebResponse)loginrequest.GetResponse();
                     * sEmitResponse = new StreamReader(EmitResponse.GetResponseStream()).ReadToEnd();*/
                    try
                    {
                        sEmitResponse = Client.GetStringAsync("api/accounts/me?token=" + accesstoken).Result;
                    }
                    catch
                    {
                        finishedlogin(false);
                        return;
                    }
                    SafeDicegetUserInfo tmp1 = json.JsonDeserialize <SafeDicegetUserInfo>(sEmitResponse);

                    /*loginrequest = (HttpWebRequest)HttpWebRequest.Create("https://safedice.com/api/accounts/" + tmp1.id + "/sites/" + curen + "/me");
                     * if (Prox != null)
                     *  loginrequest.Proxy = Prox;
                     * loginrequest.CookieContainer = new CookieContainer();
                     * loginrequest.CookieContainer.Add(new Cookie("token", accesstoken, "", "safedice.com"));
                     * loginrequest.Headers.Add("authorization", "Bearer " + accesstoken);
                     * EmitResponse = (HttpWebResponse)loginrequest.GetResponse();
                     * sEmitResponse = new StreamReader(EmitResponse.GetResponseStream()).ReadToEnd();*/
                    sEmitResponse = Client.GetStringAsync("api/accounts/" + tmp1.id + "/sites/" + curen + "/me").Result;
                    SafeDiceWalletInfo tmp2 = json.JsonDeserialize <SafeDiceWalletInfo>(sEmitResponse);


                    Parent.updateBalance(tmp2.balance / (curen != 2 ? 100000000m : 1000000000000m));
                    balance = tmp2.balance / (curen != 2 ? 100000000.0m : 1000000000000.0m);

                    Parent.updateBets(tmp2.win + tmp2.lose);
                    Parent.updateLosses(tmp2.lose);
                    wins   = (int)tmp2.win;
                    losses = (int)tmp2.lose;
                    Parent.updateProfit((tmp2.amountWin - tmp2.amountLose) / (curen != 2 ? 100000000.0m : 1000000000000.0m));
                    profit = (tmp2.amountWin - tmp2.amountLose) / (curen != 2 ? 100000000.0m : 1000000000000.0m);
                    Parent.updateWagered(tmp2.wagered / (curen != 2 ? 100000000.0m : 1000000000000.0m));
                    wagered = tmp2.wagered / (curen != 2 ? 100000000.0m : 1000000000000.0m);
                    Parent.updateWins(tmp2.win);
                    Parent.updateStatus("Logged in");
                    serverhash = tmp1.serverSeedHash;
                    client     = tmp1.accountSeed;
                    nonce      = tmp1.nonce;
                    UID        = tmp1.id;
                    Parent.updateDeposit(GetDepositAddress());
                    ispd = true;
                    Thread t = new Thread(GetBalanceThread);
                    t.Start();
                    finishedlogin(true);
                }
            }
            catch (WebException e)
            {
                if (e.Response != null)
                {
                    Parent.DumpLog(e.ToString(), -1);
                    string sEmitResponse = new StreamReader(e.Response.GetResponseStream()).ReadToEnd();
                    Parent.updateStatus(sEmitResponse);
                    if (e.Message.Contains("401"))
                    {
                        //System.Windows.Forms.MessageBox.Show("Could not log in. Please ensure the username, passowrd and 2fa code are all correct.");
                    }
                }
                finishedlogin(false);
            }
            catch (Exception e)
            {
                Parent.DumpLog(e.ToString(), -1);
                finishedlogin(false);
            }
        }