示例#1
0
文件: PD.cs 项目: Alexmarch1/DiceBot
        void placebetthread()
        {
            try
            {
                if ((DateTime.Now - Lastbet).TotalMilliseconds < 500)
                {
                    Thread.Sleep((int)(500.0 - (DateTime.Now - Lastbet).TotalMilliseconds));
                }
                double tmpchance = High ? 99.99 - chance : chance;
                List <KeyValuePair <string, string> > pairs = new List <KeyValuePair <string, string> >();
                pairs.Add(new KeyValuePair <string, string>("amount", (amount * 100000000).ToString(System.Globalization.NumberFormatInfo.InvariantInfo)));
                pairs.Add(new KeyValuePair <string, string>("target", tmpchance.ToString("0.00", System.Globalization.NumberFormatInfo.InvariantInfo)));
                pairs.Add(new KeyValuePair <string, string>("condition", High ? ">" : "<"));


                FormUrlEncodedContent Content = new FormUrlEncodedContent(pairs);
                string sEmitResponse          = Client.PostAsync("bet?access_token=" + accesstoken, Content).Result.Content.ReadAsStringAsync().Result;
                Lastbet = DateTime.Now;
                try
                {
                    pdbetresult tmp = json.JsonDeserialize <pdbetresult>(sEmitResponse);

                    tmp.bet.client     = tmp.user.client;
                    tmp.bet.serverhash = tmp.user.server;
                    lastupdate         = DateTime.Now;
                    balance            = tmp.user.balance / 100000000.0; //i assume
                    bets    = tmp.user.bets;
                    wins    = tmp.user.wins;
                    losses  = tmp.user.losses;
                    wagered = (double)(tmp.user.wagered / 100000000m);
                    profit  = (double)(tmp.user.profit / 100000000m);
                    FinishedBet(tmp.bet.toBet());
                    retrycount = 0;
                }
                catch
                {
                    Parent.updateStatus(sEmitResponse);
                }
            }
            catch (AggregateException e)
            {
                if (retrycount++ < 3)
                {
                    Thread.Sleep(500);
                    placebetthread();
                    return;
                }
                if (e.InnerException.Message.Contains("429") || e.InnerException.Message.Contains("502"))
                {
                    Thread.Sleep(500);
                    placebetthread();
                }
            }
            catch (Exception e2)
            {
            }
        }
示例#2
0
文件: PD.cs 项目: wmgjang/DiceBot
        void placebetthread()
        {
            try
            {
                HttpWebRequest betrequest = (HttpWebRequest)HttpWebRequest.Create("https://api.primedice.com/api/bet?access_token=" + accesstoken);
                if (Prox != null)
                {
                    betrequest.Proxy = Prox;
                }
                betrequest.Method = "POST";
                double tmpchance = High ? 99.99 - chance : chance;
                string post      = string.Format("amount={0}&target={1}&condition={2}", (amount * 100000000).ToString(""), tmpchance.ToString("0.00"), High ? ">" : "<");
                betrequest.ContentLength = post.Length;
                betrequest.ContentType   = "application/x-www-form-urlencoded; charset=UTF-8";

                using (var writer = new StreamWriter(betrequest.GetRequestStream()))
                {
                    writer.Write(post);
                }
                HttpWebResponse EmitResponse  = (HttpWebResponse)betrequest.GetResponse();
                string          sEmitResponse = new StreamReader(EmitResponse.GetResponseStream()).ReadToEnd();

                pdbetresult tmp = json.JsonDeserialize <pdbetresult>(sEmitResponse);

                tmp.bet.client     = tmp.user.client;
                tmp.bet.serverhash = tmp.user.server;
                lastupdate         = DateTime.Now;
                balance            = tmp.user.balance / 100000000.0; //i assume
                bets    = tmp.user.bets;
                wins    = tmp.user.wins;
                losses  = tmp.user.losses;
                wagered = (double)(tmp.user.wagered / 100000000m);
                profit  = (double)(tmp.user.profit / 100000000m);
                FinishedBet(tmp.bet.toBet());
            }
            catch (WebException e)
            {
                if (e.Response != null)
                {
                    string sEmitResponse = new StreamReader(e.Response.GetResponseStream()).ReadToEnd();
                    Parent.updateStatus(sEmitResponse);
                }
                if (e.Message.Contains("429") || e.Message.Contains("502"))
                {
                    Thread.Sleep(200);
                    placebetthread();
                }
            }
        }