Advertisement
Guest User

Primedice Better Bot r1

a guest
Apr 9th, 2015
806
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 25.44 KB | None | 0 0
  1. package PrimeBot;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.DataOutputStream;
  5. import java.io.InputStreamReader;
  6. import java.net.URL;
  7. import java.text.SimpleDateFormat;
  8. import java.util.Date;
  9. import java.util.Random;
  10.  
  11. import javax.net.ssl.HttpsURLConnection;
  12.  
  13. //import javax.swing.text.GapContent;
  14. import java.awt.*;
  15.  
  16. import org.json.JSONObject;
  17.  
  18. public class PrimeBot {
  19.  
  20.     private final String USER_AGENT = "Mozilla/5.0";
  21.     private static String accessToken;
  22.     private static String txid;
  23.  
  24.     private static double newBal;
  25.     private static double maxBets;
  26.  
  27.     public static String username;
  28.     public static String password;
  29.    
  30.     public static final String LESS = "<";
  31.     public static final String BIG = ">";
  32.    
  33.     public static String direction = LESS; 
  34.  
  35.     private static UserStats meStats = new UserStats();
  36.  
  37.     public static int delay = 300;
  38.     public static double nextBetAmount;
  39.     public static double target = 20;
  40.     public static double baseBet = 40;
  41.     public static double increaseOnLossMultiplier = 1.25;
  42.    
  43.    
  44.     public static int betType;
  45.     public static int luckyBets;
  46.     public static int zigZag = 5;
  47.     public static int changeSeed = 5;
  48.     public static int warnAlert = 5;
  49.     public static int stopLoss = 5;
  50.     public static int resetLoss = 5;
  51.     public static double chance;
  52.     public static double withdrawTarget;
  53.     public static double withdrawAmount;
  54.     public static String swithdrawAmount;
  55.    
  56.     public static String withdrawAddress;
  57.    
  58.     public static int successHTTP = 0;
  59.  
  60.     public static double sessionProfitTarget = 100000;
  61.  
  62.     public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  63.  
  64.     public static void main(String[] args) throws Exception
  65.     {
  66.         PrimeBot primeBot = new PrimeBot();
  67.         System.out.println("\nPrimedice Better Bot 1.0 ");
  68.         System.out.println("by blayzer");
  69.         System.out.println("\nOriginal code from daCoops (https://bitcointalk.org/index.php?topic=833129)");
  70.         System.out.println("\nPlease consider donating: 1BtDA32VwButWhsE4343AqfJt3EnnvjPZL");
  71.        
  72.        
  73.         System.out.println();
  74.  
  75.         if(args.length == 0)
  76.         {
  77.             System.out.println("No parameters supplied.");
  78.             System.out.println("java -jar PBBot.jar [Username] [Password] [Base Bet] [Base Betmode] [LuckBets] [Target] [Increase On Loss Multiplier] [ZigZag] [Randomize Seed] [Warning Alert] [Reset on Loss] [Stop on Loss] [Profit Target] [Withdraw on Balance] [Withdraw Amount] [Withdraw Address]");
  79.             System.out.println("e.g.");
  80.             System.out.println("java -jar PBBot.jar Bob Bob123 16 1 0 49.5 2.0 9 9 10 4 99 0.001 0.0024378  0.0011 1BtDA32VwButWhsE4343AqfJt3EnnvjPZL");
  81.             System.out.println("java -jar PBBot.jar Bob Bob123 0.0000152590218966964 51.5 2.1 10000 5 10 12 0 2");
  82.             System.out.println("java -jar PrimeBot.jar Bob Bob123 0.00000001 51.5 2.1 10000 5 10 12 1 0");
  83.             System.out.println("\t[Base Bet]:\n\t\tYour Base Bet. entering a value of 0.00000001, represents PrimeDice lowest bet - 0.00000001 BTC if used with the proper betmode.");
  84.             System.out.println("\t[Base Betmode]:\n\t\t1 specifies base bet will be treated as x number of max bets. 2 indicates it's a multiplier for the bankroll balance. 0 will set it as a direct base bet in 0.00000000 format. ");
  85.             System.out.println("\t[LuckBets]:\n\t\tSet to 0 or 1. When enabled, base bet is reduced by 1/2 when luck is > 100% as loss is expected due to the law of large numbers. This gives player an extra bet in the event of a bad streak.");
  86.             System.out.println("\t[Target]:\n\t\tThe Win Chance. e.g. 51.5 represents a win chance of 51.5%");
  87.             System.out.println("\t[Increase On Loss Multiplier]:\n\t\tThe Factor increase to increase your bet on loss. CAUTION! This is a multiplier and NOT a Percentage. e.g. 2.1 Will Multiply Previous Bet * 2.1 on loss for next wager");
  88.  
  89.  
  90.             System.out.println("\t[ZigZag]:\n\t\tSwitch hi/lo after this many losses.");
  91.             System.out.println("\t[Randomize Seed]:\n\t\tRandomize client seed after this many losses.");
  92.            
  93.             System.out.println("\t[Warning Alert]:\n\t\tPlay alert sound after this many losses (Windows Beep)");
  94.             System.out.println("\t[Reset on Loss]:\n\t\treset back to base bet after this many losses");
  95.             System.out.println("\t[Stop on Loss]:\n\t\tstop betting after this many losses");
  96.            
  97.             System.out.println("\t[Profit Target]:\n\t\tTarget Profit for the session.");
  98.             System.out.println("\t[Withdraw on Balance]:\n\t\tAutomatically withdraw when balance reaches this amount.");
  99.             System.out.println("\t[Withdraw Amount]:\n\t\tWithdraw this amount.");
  100.             System.out.println("\t[Withdraw Address]:\n\t\tBitcoin address to receive withdrawal.");
  101.  
  102.            
  103.            
  104.            
  105.             System.out.println();
  106.             System.out.println("Reminder of how this works..");
  107.             System.out.println("You set the Base Bet Amount, Profit Target, and Win Chance, and then the bot will bet as fast as it can until profit target has been reached.");
  108.             System.out.println("On a loss, it will increase the base bet by a factor of the Multiplier entered. On win, it resets back to base.");
  109.             System.exit(0);
  110.         }
  111.         else
  112.         {
  113.             try {
  114.                 username = args[0];
  115.                 password = args[1];
  116.                 baseBet = Double.parseDouble(args[2]);
  117.                 betType = Integer.parseInt(args[3]);
  118.                 luckyBets = Integer.parseInt(args[4]);
  119.                 target = Double.parseDouble(args[5]);
  120.                 increaseOnLossMultiplier = Double.parseDouble(args[6]);
  121.                 zigZag = Integer.parseInt(args[7]);
  122.                 changeSeed = Integer.parseInt(args[8]);
  123.                 warnAlert = Integer.parseInt(args[9]);
  124.                 resetLoss = Integer.parseInt(args[10]);
  125.                 stopLoss = Integer.parseInt(args[11]);
  126.                 sessionProfitTarget = Double.parseDouble(args[12]);
  127.                 withdrawTarget = Double.parseDouble(args[13]);
  128.                 withdrawAmount = Double.parseDouble(args[14]);
  129.                 withdrawAddress = args[15];
  130.                
  131.                
  132.                
  133.             }
  134.             catch(Exception e)
  135.             {
  136.                 System.out.println("Problem reading arguments. Please try again.");
  137.                 System.exit(0);
  138.             }
  139.         }
  140.  
  141.         java.security.Security.setProperty("networkaddress.cache.ttl" , "0");
  142.         Thread.sleep(5000);  
  143.         System.out.println("Initializing startup sequence... ");
  144.         System.out.println("\nSystem Settings:");
  145.         System.out.println("Base Bet: " + baseBet);
  146.         System.out.println("Bet Mode: " + betType);
  147.         System.out.println("Adjust on luck " + luckyBets);
  148.         System.out.println("Chance: " + target);
  149.         System.out.println("Zig Zag every " + zigZag + " losses");
  150.         System.out.println("Randomize Client Seed after " + changeSeed + " losses");
  151.         System.out.println("Warning alert after: " + warnAlert + " losses");
  152.         System.out.println("Reset base bet after: " + resetLoss + " losses");
  153.         System.out.println("Stop betting after: " + stopLoss + " losses");
  154.         System.out.println("Profit Target: " + sessionProfitTarget);
  155.         System.out.println("Withdraw on Target: " + withdrawTarget);
  156.         System.out.println("Amount to Withdraw: " + withdrawAmount);
  157.         System.out.println("Withdraw Address: " + withdrawAddress);
  158.        
  159.        
  160.        
  161.         System.out.println();
  162.  
  163.  
  164.         primeBot.doLogin();
  165.         try {
  166.             Thread.sleep(2000);                 //1000 milliseconds is one second.
  167.         } catch(InterruptedException ex) {
  168.             Thread.currentThread().interrupt();
  169.         }
  170.  
  171.         primeBot.doStats();
  172.        
  173.         try {
  174.             Thread.sleep(1000);                 //1000 milliseconds is one second.
  175.         } catch(InterruptedException ex) {
  176.             Thread.currentThread().interrupt();
  177.         }
  178.        
  179.         System.out.println("\nUsername:  " + meStats.getUsername());
  180.         System.out.println("Balance:  " + String.format("%.8f", (meStats.getBalance()/100000000)));
  181.         System.out.println("Deposit Address:  " + meStats.getAddress());
  182.        
  183.        
  184.        
  185.        
  186.         chance = (target/100);
  187.         maxBets = Math.pow(2,baseBet);
  188.         sessionProfitTarget = (sessionProfitTarget * 100000000);
  189.         withdrawAmount = (withdrawAmount * 100000000);
  190.        
  191.         if (betType == 1)
  192.         {
  193.             nextBetAmount = Math.round(meStats.getBalance() / maxBets);
  194.                        
  195.         }
  196.         else if (betType == 2)
  197.         {
  198.             nextBetAmount = Math.round(meStats.getBalance() * baseBet);
  199.         }
  200.         else
  201.         {
  202.             nextBetAmount = (baseBet * 100000000);
  203.         }
  204.        
  205.        
  206.        
  207.        
  208.        
  209.        
  210.        
  211.         JSONObject currentBet = new JSONObject();
  212.         int lostCount = 0;
  213.         int seedLostcount = 0;
  214.         int lostResetcount = 0;
  215.         int zzCount = 0;
  216.         int lostCnt = 0;
  217.         int winCnt = 0;
  218.         double winCount = 0;
  219.         int highestLoss = 0;
  220.         double luck;
  221.        
  222.        
  223.         System.out.println("\nInitializing betting routine...");
  224.         System.out.println();
  225.         while (meStats.getProfitSession() < sessionProfitTarget)
  226.         {
  227.             // Main betting loop
  228.             try
  229.             {
  230.                 currentBet = primeBot.doBet();
  231.             }
  232.             catch(Exception e )
  233.             {
  234.                 System.out.println(e.getMessage());
  235.                 try {
  236.                     Thread.sleep(2000);                 //1000 milliseconds is one second.
  237.                 } catch(InterruptedException ex) {
  238.                     Thread.currentThread().interrupt();
  239.                 }
  240.             }
  241.            
  242.             if (currentBet != null)
  243.    
  244.             {
  245.                 successHTTP = successHTTP + 1;
  246.                 meStats.updateProfitSession(currentBet.getDouble("profit"));
  247.                 newBal = (meStats.getProfitSession() + meStats.getBalance());
  248.                
  249.                 //added to count maxbets
  250.                
  251.                 double nxtBet = nextBetAmount;
  252.                 int numBets = 0;
  253.                
  254.                 while (nxtBet < meStats.getBalance())
  255.                 {
  256.                     nxtBet = Math.round(nxtBet * increaseOnLossMultiplier);
  257.                     numBets = numBets +1;
  258.                 }          
  259.                
  260.                 if (!currentBet.getBoolean("win"))
  261.                 {
  262.                                                        
  263.                     lostCnt = lostCnt + 1; //total losses counter
  264.                     seedLostcount = seedLostcount + 1;
  265.                     lostCount = lostCount + 1; //longest streak counter
  266.                     zzCount = zzCount + 1; //zigzag counter
  267.                     lostResetcount = lostResetcount + 1;
  268.                    
  269.                     if (lostResetcount >= resetLoss)
  270.                     {  
  271.                         if (betType == 1)
  272.                         {
  273.                             nextBetAmount = Math.round(meStats.getBalance() / maxBets);
  274.                         }
  275.                         else if (betType == 2)
  276.                         {
  277.                             nextBetAmount = Math.round(meStats.getBalance() * baseBet);
  278.                         }
  279.                         else
  280.                         {
  281.                             nextBetAmount = (baseBet * 100000000);
  282.                         }
  283.                        
  284.                         lostResetcount = 0;
  285.                     }
  286.                     else
  287.                     {
  288.                         nextBetAmount = Math.round(nextBetAmount * increaseOnLossMultiplier);
  289.                     }
  290.                    
  291.                     if (zzCount >= zigZag)
  292.                     {
  293.                         if (direction.equals(LESS))
  294.                         {
  295.                             direction = BIG;
  296.                             target = (100 - target);
  297.                             zzCount = 0;
  298.                         }
  299.                         else
  300.                         {
  301.                             direction = LESS;
  302.                             target = (100 - target);
  303.                             zzCount = 0;
  304.                         }
  305.                     }
  306.                    
  307.                                        
  308.                 }
  309.                 else
  310.                 {
  311.                    
  312.                     if (betType == 1)
  313.                     {
  314.                         nextBetAmount = Math.round(newBal / maxBets);
  315.                                    
  316.                     }
  317.                     else if (betType == 2)
  318.                     {
  319.                         nextBetAmount = Math.round(newBal * baseBet);
  320.                     }
  321.                     else
  322.                     {
  323.                         nextBetAmount = (baseBet * 100000000);
  324.                     }
  325.                    
  326.                    
  327.                     if (luckyBets == 1)
  328.                     {
  329.                         if ((((winCount/(winCnt+lostCnt))/chance)*100) > 100)
  330.                             {
  331.                                 nextBetAmount = nextBetAmount / increaseOnLossMultiplier;
  332.                             }
  333.                     }
  334.                    
  335.  
  336.                    
  337.                    
  338.                     //longest losing streak counter
  339.                     if (highestLoss < lostCount)
  340.                     {
  341.                     highestLoss = lostCount;   
  342.                     }
  343.                    
  344.                     lostResetcount = 0;
  345.                     seedLostcount = 0;
  346.                     lostCount = 0;
  347.                     zzCount = 0;
  348.                     winCnt = winCnt + 1; //total wins counter
  349.                     winCount = winCnt;
  350.                    
  351.                 }
  352.                
  353.                 luck = (((winCount/(winCnt+lostCnt))/chance)*100);
  354.  
  355.                
  356.                 System.out.println("\nDATE       TIME         DEL BET ID       NONCE  ROLL  TARGET  STRK      LAST BET    SES PROFIT       BALANCE   WINS LOSSES  ROLLS   LUCK MAX");
  357.                 System.out.print(sdf.format(new Date()) + " ");
  358.                 System.out.format("%d %10.0f %7d %5.2f %s %5.2f %2d %2d %13.8f %13.8f %13.8f %6d %6d %6d %6.2f  %2d", delay,currentBet.getDouble("id"),currentBet.getInt("nonce"),currentBet.getDouble("roll"),direction,target,lostCount,highestLoss,(currentBet.getDouble("profit")/100000000), (meStats.getProfitSession()/100000000),(newBal/100000000),winCnt,lostCnt,(winCnt+lostCnt),luck,numBets);
  359.                 System.out.println();
  360.                
  361.                 if (seedLostcount >= changeSeed)
  362.                 {
  363.                     //Thread.sleep(5000);      
  364.                     primeBot.doSeedchange();
  365.                     try {
  366.                     Thread.sleep(1000);                 //1000 milliseconds is one second.
  367.                     } catch(InterruptedException ex) {
  368.                     Thread.currentThread().interrupt();
  369.                     }
  370.                     seedLostcount = 0;
  371.                 }
  372.                
  373.                 if ((newBal/100000000) > withdrawTarget)
  374.                 {
  375.                    
  376.                     System.out.println("\nWithdrawal target attained.");
  377.                    
  378.                     primeBot.doWithdraw();
  379.                     try {
  380.                         Thread.sleep(1000);                 //1000 milliseconds is one second.
  381.                     } catch(InterruptedException ex) {
  382.                         Thread.currentThread().interrupt();
  383.                     }
  384.            
  385.                     primeBot.doStats();
  386.                    
  387.                     try {
  388.                         Thread.sleep(1000);                 //1000 milliseconds is one second.
  389.                     } catch(InterruptedException ex) {
  390.                         Thread.currentThread().interrupt();
  391.                     }
  392.                    
  393.                     System.out.println("Balance:  " + String.format("%.8f", (meStats.getBalance()/100000000)));
  394.                 }
  395.                
  396.                 //warning alert
  397.                 if (lostCount >= warnAlert)
  398.                 {
  399.                     Toolkit.getDefaultToolkit().beep();
  400.                 }
  401.                 //stop loss
  402.                 if (lostCount >= stopLoss)
  403.                 {
  404.                     System.out.println();
  405.                     Toolkit.getDefaultToolkit().beep();
  406.                     System.out.println("Stop loss reached. Halting");
  407.                     System.exit(0);
  408.                 }
  409.                
  410.                 if (successHTTP == 20)
  411.                 {
  412.                    
  413.                     delay = delay -1;
  414.                     successHTTP = 0;
  415.                 }
  416.                
  417.                 try {
  418.                     Thread.sleep(delay);                 //1000 milliseconds is one second.
  419.                 } catch(InterruptedException ex) {
  420.                     Thread.currentThread().interrupt();
  421.                 }
  422.  
  423.             }
  424.             else
  425.             {
  426.                 successHTTP = 0;
  427.                 //System.out.println("Slowing down....");
  428.                 try {
  429.                     Thread.sleep(10);                 //1000 milliseconds is one second.
  430.                 } catch(InterruptedException ex) {
  431.                     Thread.currentThread().interrupt();
  432.                 }
  433.                 delay = delay + 1;
  434.             }
  435.         }
  436.        
  437.         System.out.println();
  438.         System.out.println("Session profit target attained. Stopped.");
  439.  
  440.     }
  441.  
  442.     // Login
  443.     private void doLogin() throws Exception
  444.     {
  445.  
  446.         String url = "https://api.primedice.com/api/login";
  447.         URL obj = new URL(url);
  448.         HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
  449.  
  450.        
  451.        
  452.         //add reuqest header
  453.         con.setRequestMethod("POST");
  454.         con.setRequestProperty("User-Agent", USER_AGENT);
  455.         con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
  456.  
  457.         String urlParameters = "username=" + username + "&password=" + password;
  458.  
  459.         //System.out.println("\nSending 'POST' request to URL : " + url);
  460.         //System.out.println("Post parameters : " + urlParameters);
  461.        
  462.         System.out.println("Logging in...");
  463.         System.out.println("Username:   " + username);
  464.         System.out.println("Password:   " + password);
  465.                
  466.         // Send post request
  467.         con.setDoOutput(true);
  468.         DataOutputStream wr = new DataOutputStream(con.getOutputStream());
  469.         wr.writeBytes(urlParameters);
  470.         wr.flush();
  471.         wr.close();
  472.        
  473.  
  474.  
  475.         int responseCode = con.getResponseCode();
  476.        
  477.         System.out.println("Response Code : " + responseCode);
  478.        
  479.  
  480.         BufferedReader in = new BufferedReader(
  481.                 new InputStreamReader(con.getInputStream()));
  482.         String inputLine;
  483.         StringBuffer response = new StringBuffer();
  484.  
  485.         while ((inputLine = in.readLine()) != null) {
  486.             response.append(inputLine);
  487.         }
  488.         in.close();
  489.  
  490.  
  491.         //print result
  492.         //System.out.println(response.toString());
  493.  
  494.         JSONObject loginJsonResp = new JSONObject(response.toString());
  495.         accessToken = loginJsonResp.getString("access_token");
  496.        
  497.        
  498.         //System.out.println("\nAccess Token: "+ accessToken);
  499.  
  500.     }
  501.  
  502.    
  503.     private JSONObject doBet() throws Exception
  504.     {
  505.         String url = "https://api.primedice.com/api/bet?access_token=" + accessToken;
  506.         URL obj = new URL(url);
  507.         HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
  508.  
  509.         //add reuqest header
  510.         con.setRequestMethod("POST");
  511.         con.setRequestProperty("User-Agent", USER_AGENT);
  512.         con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
  513.         con.setRequestProperty("origin","https://primedice.com");
  514.         con.setRequestProperty("referer","https://primedice.com/play");
  515.         con.setRequestProperty("cache-control","no-cache");
  516.         con.setRequestProperty("pragma","no-cache");
  517.  
  518.         String urlParameters = "amount="+nextBetAmount + "&condition=" + direction + "&target=" + target;
  519.  
  520.         // Send post request
  521.         con.setDoOutput(true);
  522.         DataOutputStream wr = new DataOutputStream(con.getOutputStream());
  523.         wr.writeBytes(urlParameters);
  524.         wr.flush();
  525.         wr.close();
  526.  
  527.         int responseCode = con.getResponseCode();
  528.         // System.out.println("Betting HTTP Response Code : " + responseCode);
  529.  
  530.         if (responseCode == 200)
  531.         {
  532.             BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
  533.             String inputLine;
  534.             StringBuffer response = new StringBuffer();
  535.  
  536.             while ((inputLine = in.readLine()) != null) {
  537.                 response.append(inputLine);
  538.             }
  539.             in.close();
  540.            
  541.             // test print out
  542.             //System.out.println(response.toString());
  543.            
  544.            
  545.  
  546.             JSONObject betResult = new JSONObject(response.toString());
  547.  
  548.             return betResult.getJSONObject("bet");
  549.            
  550.         }
  551.         else
  552.         {
  553.             return null;
  554.         }
  555.  
  556.     }
  557.    
  558.    
  559.    
  560.     private JSONObject doWithdraw() throws Exception
  561.     {
  562.         String url = "https://api.primedice.com/api/withdraw?access_token=" + accessToken;
  563.         URL obj = new URL(url);
  564.         HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
  565.  
  566.         //add reuqest header
  567.         con.setRequestMethod("POST");
  568.         con.setRequestProperty("User-Agent", USER_AGENT);
  569.         con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
  570.         con.setRequestProperty("origin","https://primedice.com");
  571.         con.setRequestProperty("referer","https://primedice.com/play");
  572.         con.setRequestProperty("cache-control","no-cache");
  573.         con.setRequestProperty("pragma","no-cache");
  574.  
  575.         String urlParameters = "amount=" + withdrawAmount + "&address=" + withdrawAddress;
  576.        
  577.         System.out.println("\nInitiating withdrawal...");
  578.        
  579.         // Send post request
  580.         con.setDoOutput(true);
  581.         DataOutputStream wr = new DataOutputStream(con.getOutputStream());
  582.         wr.writeBytes(urlParameters);
  583.         wr.flush();
  584.         wr.close();
  585.  
  586.         int responseCode = con.getResponseCode();
  587.        
  588.         System.out.println("Withdraw HTTP Response Code : " + responseCode);
  589.  
  590.         if (responseCode == 200)
  591.         {
  592.             BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
  593.             String inputLine;
  594.             StringBuffer response = new StringBuffer();
  595.  
  596.             while ((inputLine = in.readLine()) != null) {
  597.                 response.append(inputLine);
  598.             }
  599.             in.close();
  600.  
  601.            
  602.  
  603.             JSONObject withdrawResp = new JSONObject(response.toString());
  604.             txid = withdrawResp.getString("txid");
  605.            
  606.            
  607.             //System.out.println("\nAccess Token: "+ accessToken);
  608.            
  609.            
  610.            
  611.             System.out.println("\nSuccessful withdrawal of " + (withdrawAmount / 100000000) +" to BTC address: " + withdrawAddress);
  612.             System.out.println("TXID: " + txid);
  613.            
  614.             System.out.println("\nUpdating user balance...");
  615.             //System.out.println(response.toString());
  616.             return withdrawResp;
  617.            
  618.            
  619.            
  620.         }
  621.         else
  622.         {
  623.             return null;
  624.         }
  625.  
  626.     }
  627.  
  628.    
  629.    
  630.     private JSONObject doSeedchange() throws Exception
  631.     {
  632.         String url = "https://api.primedice.com/api/seed?access_token=" + accessToken;
  633.         URL obj = new URL(url);
  634.         HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
  635.  
  636.         //add reuqest header
  637.         con.setRequestMethod("POST");
  638.         con.setRequestProperty("User-Agent", USER_AGENT);
  639.         con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
  640.         con.setRequestProperty("origin","https://primedice.com");
  641.         con.setRequestProperty("referer","https://primedice.com/play");
  642.         con.setRequestProperty("cache-control","no-cache");
  643.         con.setRequestProperty("pragma","no-cache");
  644.  
  645.         char[] chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toCharArray();
  646.         StringBuilder sb = new StringBuilder();
  647.         Random random = new Random();
  648.         for (int i = 0; i < 30; i++) {
  649.             char c = chars[random.nextInt(chars.length)];
  650.             sb.append(c);
  651.         }
  652.         String randomSeed = sb.toString();
  653.        
  654.        
  655.        
  656.        
  657.        
  658.        
  659.         String urlParameters = "seed=" + randomSeed;
  660.        
  661.         System.out.println("\n\nRandomizing Seed: "+ randomSeed);
  662.        
  663.         // Send post request
  664.         con.setDoOutput(true);
  665.         DataOutputStream wr = new DataOutputStream(con.getOutputStream());
  666.         wr.writeBytes(urlParameters);
  667.         wr.flush();
  668.         wr.close();
  669.  
  670.         int responseCode = con.getResponseCode();
  671.        
  672.         System.out.println("Seedchange HTTP Response Code : " + responseCode);
  673.  
  674.         if (responseCode == 200)
  675.         {
  676.             BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
  677.             String inputLine;
  678.             StringBuffer response = new StringBuffer();
  679.  
  680.             while ((inputLine = in.readLine()) != null) {
  681.                 response.append(inputLine);
  682.             }
  683.             in.close();
  684.  
  685.            
  686.  
  687.             JSONObject seedChangerespResp = new JSONObject(response.toString());
  688.  
  689.             return seedChangerespResp;
  690.            
  691.            
  692.            
  693.         }
  694.         else
  695.         {
  696.             return null;
  697.         }
  698.  
  699.     }
  700.  
  701.    
  702.    
  703.    
  704.    
  705.    
  706.    
  707.    
  708.    
  709.     private void doStats() throws Exception
  710.     {
  711.         String url = "https://api.primedice.com/api/users/1?access_token=" + accessToken;
  712.         URL obj = new URL(url);
  713.         HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
  714.  
  715.         //add reuqest header
  716.         con.setRequestMethod("GET");
  717.         con.setRequestProperty("User-Agent", USER_AGENT);
  718.         con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
  719.         con.setRequestProperty("origin","https://primedice.com");
  720.         con.setRequestProperty("referer","https://primedice.com/play");
  721.         con.setRequestProperty("cache-control","no-cache");
  722.         con.setRequestProperty("pragma","no-cache");
  723.  
  724.         System.out.println("\nRetrieving user info...");
  725.        
  726.        
  727.         int responseCode = con.getResponseCode();
  728.         System.out.println("Response Code : " + responseCode);
  729.  
  730.         BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
  731.         String inputLine;
  732.         StringBuffer response = new StringBuffer();
  733.  
  734.         while ((inputLine = in.readLine()) != null) {
  735.             response.append(inputLine);
  736.         }
  737.         in.close();
  738.        
  739.  
  740.         //System.out.println(response.toString());
  741.  
  742.         // Parse them to the UserStas Obj - only want the "users" JSON obj
  743.         JSONObject userStats = new JSONObject(response.toString()).getJSONObject("user");
  744.         meStats.parseStats(userStats);
  745.  
  746.  
  747.     }
  748.  
  749.     public static class UserStats {
  750.  
  751.         private String username;
  752.         private String address;
  753.         private double balance;
  754.         private double wagered;
  755.         private double profit;
  756.         private int bets;
  757.         private int wins;
  758.         private int losses;
  759.         private double wageredSession;
  760.         private double profitSession;
  761.         private int betsSession;
  762.         private int winsSession;
  763.         private int lossesSession;
  764.  
  765.         public UserStats()
  766.         {
  767.             super();
  768.             this.username = "x";
  769.             this.balance = 0;
  770.             this.wagered = 0;
  771.             this.profit = 0;
  772.             this.bets = 0;
  773.             this.wins = 0;
  774.             this.losses = 0;
  775.             this.wageredSession = 0;
  776.             this.profitSession = 0;
  777.             this.betsSession = 0;
  778.             this.winsSession = 0;
  779.             this.lossesSession = 0;
  780.         }
  781.  
  782.         public void parseStats(JSONObject userStats)
  783.         {
  784.             this.username = userStats.getString("username");
  785.             this.address = userStats.getString("address");
  786.             this.balance = userStats.getDouble("balance");
  787.             this.wagered = userStats.getDouble("wagered");
  788.             this.profit =userStats.getDouble("profit");
  789.             this.bets = userStats.getInt("bets");
  790.             this.wins = userStats.getInt("wins");
  791.             this.losses = userStats.getInt("losses");
  792.         }
  793.  
  794.        
  795.         public void resetSessionStats()
  796.         {
  797.             this.wageredSession = 0;
  798.             this.profitSession = 0;
  799.             this.betsSession = 0;
  800.             this.winsSession = 0;
  801.             this.lossesSession = 0;
  802.         }
  803.  
  804.         public String getUsername() {
  805.             return username;
  806.         }
  807.        
  808.         public String getAddress() {
  809.             return address;
  810.         }
  811.        
  812.         public double getBalance() {
  813.             return balance;
  814.         }
  815.         public void setBalance(double balance) {
  816.             this.balance = balance;
  817.         }
  818.         public double getWagered() {
  819.             return wagered;
  820.         }
  821.         public void setWagered(double wagered) {
  822.             this.wagered = wagered;
  823.         }
  824.         public double getProfit() {
  825.             return profit;
  826.         }
  827.         public void setProfit(double profit) {
  828.             this.profit = profit;
  829.         }
  830.         public int getBets() {
  831.             return bets;
  832.         }
  833.         public void setBets(int bets) {
  834.             this.bets = bets;
  835.         }
  836.         public int getWins() {
  837.             return wins;
  838.         }
  839.         public void setWins(int wins) {
  840.             this.wins = wins;
  841.         }
  842.         public int getLosses() {
  843.             return losses;
  844.         }
  845.         public void setLosses(int losses) {
  846.             this.losses = losses;
  847.         }
  848.         public double getWageredSession() {
  849.             return wageredSession;
  850.         }
  851.         public void setWageredSession(double wageredSession) {
  852.             this.wageredSession = wageredSession;
  853.         }
  854.         public double getProfitSession() {
  855.             return profitSession;
  856.         }
  857.         public void setProfitSession(double profitSession) {
  858.             this.profitSession = profitSession;
  859.         }
  860.         public int getBetsSession() {
  861.             return betsSession;
  862.         }
  863.         public void setBetsSession(int betsSession) {
  864.             this.betsSession = betsSession;
  865.         }
  866.         public int getWinsSession() {
  867.             return winsSession;
  868.         }
  869.         public void setWinsSession(int winsSession) {
  870.             this.winsSession = winsSession;
  871.         }
  872.         public int getLossesSession() {
  873.             return lossesSession;
  874.         }
  875.         public void setLossesSession(int lossesSession) {
  876.             this.lossesSession = lossesSession;
  877.         }
  878.  
  879.         @Override
  880.         public String toString() {
  881.             return "UserStats [balance=" + balance + ", wagered=" + wagered
  882.                     + ", profit=" + profit + ", bets=" + bets + ", wins=" + wins
  883.                     + ", losses=" + losses + ", wageredSession=" + wageredSession
  884.                     + ", profitSession=" + profitSession + ", betsSession="
  885.                     + betsSession + ", winsSession=" + winsSession
  886.                     + ", lossesSession=" + lossesSession + "]";
  887.         }
  888.  
  889.         public void updateProfitSession(double betProfit)
  890.         {
  891.             this.profitSession = this.profitSession + betProfit;
  892.         }
  893.  
  894.  
  895.     }
  896.  
  897. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement