Example #1
0
 public override void Login(string Username, string Password, string twofa)
 {
     ClientHandlr = new HttpClientHandler {
         UseCookies = true, AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip, Proxy = this.Prox, UseProxy = Prox != null
     };;
     Client = new HttpClient(ClientHandlr)
     {
         BaseAddress = new Uri("https://session.satoshidice.com/userapi/")
     };
     Client.DefaultRequestHeaders.AcceptEncoding.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("gzip"));
     Client.DefaultRequestHeaders.AcceptEncoding.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("deflate"));
     try
     {
         List <KeyValuePair <string, string> > pairs = new List <KeyValuePair <string, string> >();
         pairs.Add(new KeyValuePair <string, string>("email", Username));
         pairs.Add(new KeyValuePair <string, string>("password", Password));
         FormUrlEncodedContent Content = new FormUrlEncodedContent(pairs);
         string       sEmitResponse    = Client.PostAsync("login.php", Content).Result.Content.ReadAsStringAsync().Result;
         SatDiceLogin tmplog           = json.JsonDeserialize <SatDiceLogin>(sEmitResponse);
         if (tmplog.message.ToLower() == "login successful.")
         {
             accesstoken   = tmplog.ctoken;
             sEmitResponse = Client.GetStringAsync("useraddress/?ctoken=" + accesstoken).Result;
             SatDepAddress tmpDep = json.JsonDeserialize <SatDepAddress>(sEmitResponse);
             sEmitResponse = Client.GetStringAsync("userbalance/?ctoken=" + accesstoken).Result;
             SatBalance tmpbal = json.JsonDeserialize <SatBalance>(sEmitResponse);
             sEmitResponse = Client.GetStringAsync("startround/?ctoken=" + accesstoken).Result;
             SatGameRound tmpgame = json.JsonDeserialize <SatGameRound>(sEmitResponse);
             curHash = tmpgame.hash;
             GameID  = tmpgame.id;
             if (GameID > 0 && curHash != "")
             {
                 Parent.updateBalance((decimal)tmpbal.balanceInSatoshis / 100000000m);
                 Parent.updateDeposit(tmpDep.depositaddress);
                 IsSatDice = true;
                 new System.Threading.Thread(new System.Threading.ThreadStart(GetBalanceThread)).Start();
                 finishedlogin(true);
                 return;
             }
         }
         else
         {
             finishedlogin(false);
             return;
         }
     }
     catch { }
     finishedlogin(true);
 }
Example #2
0
 void GetBalanceThread()
 {
     while (IsSatDice)
     {
         try
         {
             if (((DateTime.Now - LastBalance).TotalSeconds > 15 || ForceUpdateStats) && accesstoken != "")
             {
                 LastBalance = DateTime.Now;
                 string     sEmitResponse = Client.GetStringAsync("userbalance/?ctoken=" + accesstoken).Result;
                 SatBalance tmpbal        = json.JsonDeserialize <SatBalance>(sEmitResponse);
                 balance = tmpbal.balanceInSatoshis / 100000000.0m;
                 Parent.updateBalance(balance);
                 LastBalance = DateTime.Now;
             }
         }
         catch
         {
         }
         System.Threading.Thread.Sleep(500);
     }
 }