Hirsw0w

[Cups.GG] Free Battle Script! 2.5s

Jul 10th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.76 KB | None | 0 0
  1. // Auth token used to verify your account.
  2. var token = localStorage.getItem("token");
  3.  
  4. // saving the battles you already tried to entered into.
  5. var enteredBattles = localStorage.getItem("enteredBattles");
  6. if (enteredBattles == null) {
  7. localStorage.setItem("enteredBattles", "");
  8. enteredBattles = "";
  9. }
  10.  
  11. // variables to make a connection with the site
  12. var http = new XMLHttpRequest();
  13. var socket = null;
  14.  
  15. // Function that initiate a connection with the site with their sockets
  16. function httpConnection() {
  17.  
  18. var delay = localStorage.getItem("delay");
  19. if(delay != null && delay > Date.now())
  20. return;
  21.  
  22. localStorage.setItem("delay", Date.now() + 1000);
  23. http.open("GET", "https://api.cups.gg/socket.io/?EIO=3&transport=polling&t=asd", true);
  24. http.send();
  25.  
  26. http.onreadystatechange = function () {
  27. if (this.readyState === 4 && this.status === 200) {
  28. var x = this.responseText;
  29. var obj = JSON.parse(x.slice(x.indexOf('{'), x.lastIndexOf('}') + 1));
  30.  
  31. createConnection(obj.sid);
  32. }
  33. };
  34. }
  35.  
  36. // Function that connect to their sockets + verifying what user uses the socket.
  37. function createConnection(sid) {
  38. socket = new WebSocket("wss://api.cups.gg/socket.io/?EIO=3&transport=websocket&sid=" + sid);
  39.  
  40. // socket connection established
  41. socket.onopen = (e) => {
  42. console.log("[Cups.GG] Connection established!");
  43. socket.send("2probe");
  44.  
  45. // Pass the socket that you want access to the chat.
  46. fetch("https://api.cups.gg/socket.io/?EIO=3&transport=polling&t=NCWUlDK" + "&sid=" + sid, {
  47. "credentials": "include",
  48. "headers": {
  49. "accept": "*/*",
  50. "accept-language": "he-IL,he;q=0.9,en-US;q=0.8,en;q=0.7",
  51. "content-type": "text/plain;charset=UTF-8",
  52. "sec-fetch-mode": "cors",
  53. "sec-fetch-site": "same-site"
  54. },
  55. "referrer": "https://cups.gg/cups/",
  56. "referrerPolicy": "no-referrer-when-downgrade",
  57. "body": "8:40/chat,",
  58. "method": "POST",
  59. "mode": "cors"
  60. });
  61.  
  62. // Pass the socket the auth key of the user you want to verify as
  63. fetch("https://api.cups.gg/socket.io/?EIO=3&transport=polling&t=NCWUlDK" + "&sid=" + sid, {
  64. "credentials": "include",
  65. "headers": {
  66. "accept": "*/*",
  67. "accept-language": "he-IL,he;q=0.9,en-US;q=0.8,en;q=0.7",
  68. "content-type": "text/plain;charset=UTF-8",
  69. "sec-fetch-mode": "cors",
  70. "sec-fetch-site": "same-site"
  71. },
  72. "referrer": "https://cups.gg/cups/",
  73. "referrerPolicy": "no-referrer-when-downgrade",
  74. "body": "202:42/chat,[\"auth\",\"" + token + "\"]",
  75. "method": "POST",
  76. "mode": "cors"
  77. });
  78.  
  79. // pass the socket that you want access to all the games
  80. fetch("https://api.cups.gg/socket.io/?EIO=3&transport=polling&t=NCWUlDK" + "&sid=" + sid, {
  81. "credentials": "include",
  82. "headers": {
  83. "accept": "*/*",
  84. "accept-language": "he-IL,he;q=0.9,en-US;q=0.8,en;q=0.7",
  85. "content-type": "text/plain;charset=UTF-8",
  86. "sec-fetch-mode": "cors",
  87. "sec-fetch-site": "same-site"
  88. },
  89. "referrer": "https://cups.gg/cups/",
  90. "referrerPolicy": "no-referrer-when-downgrade",
  91. "body": "8:40/cups,11:40/shuffle,8:40/king,12:40/roulette,",
  92. "method": "POST",
  93. "mode": "cors"
  94. });
  95. }
  96.  
  97. // A message sent to the socket
  98. socket.onmessage = (e) => {
  99. var message = e.data;
  100.  
  101. if(message === "3probe") {
  102. // Sending all the required data to the socket in order to verify the user and make the connection stay alive.
  103. socket.send("5");
  104. socket.send("40/chat,");
  105. socket.send(`42/cups,["auth", "${token}"]`);
  106. socket.send(`42/shuffle,["auth", "${token}"]`);
  107. socket.send(`42/king,["auth", "${token}"]`);
  108. socket.send(`42/roulette,["auth", "${token}"]`);
  109. return;
  110. }
  111.  
  112. // A new chat message has been detected! Checking if a battle was sent
  113. if(message.indexOf("new-chat-message") !== -1) {
  114. var obj = JSON.parse(message.slice(message.indexOf('{'),message.lastIndexOf('}') + 1));
  115. var content = obj.content;
  116. checkContent(content);
  117. }
  118. }
  119.  
  120. // socket connection was closed ( reinitating the socket connection in 5 seconds. )
  121. socket.onclose = (e) => {
  122. console.log("[Cups.GG] Connection closed reconnecting in 5 seconds!");
  123. setTimeout(httpConnection, 5000);
  124. }
  125. }
  126.  
  127. // check the contect of the message for a free battle.
  128. async function checkContent(content) {
  129. // verifying the text to match xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (represent a battle link)
  130. var match = content.match("[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}");
  131. if(match == null || enteredBattles.indexOf(match[0]) !== -1)
  132. return;
  133.  
  134. // adding the battle to the battle you already tried to enter into.
  135. var gameId = match[0];
  136. enteredBattles += gameId + ";";
  137. localStorage.setItem("enteredBattles", enteredBattles);
  138.  
  139. // Fetching game data and checking whether its free (if its sponsored atleast 80% )
  140. var data = await gameData(gameId);
  141. if(data.sponsored > 80) {
  142. var delayTime = Math.random() * 1500 + 1000;
  143. console.log("Game has been found delay has been set to " + delayTime + "ms.");
  144. console.log(data);
  145. setTimeout(() => {
  146. joinGame(data.id);
  147. }, delayTime);
  148. }
  149. }
  150.  
  151.  
  152. // Function that fetches the data of the battle that was found and checks whether its exist or not.
  153. function gameData(gameLink) {
  154. return fetch("https://api.cups.gg/api/cups/private/" + gameLink, {
  155. "headers": {
  156. "accept": "application/json, text/plain, */*",
  157. "accept-language": "he-IL,he;q=0.9,en-US;q=0.8,en;q=0.7,nl;q=0.6",
  158. "sec-fetch-dest": "empty",
  159. "sec-fetch-mode": "cors",
  160. "sec-fetch-site": "same-site",
  161. "x-auth-token": token
  162. },
  163. "referrer": "https://cups.gg/cups/private/" + gameLink,
  164. "referrerPolicy": "no-referrer-when-downgrade",
  165. "body": null,
  166. "method": "GET",
  167. "mode": "cors",
  168. "credentials": "omit"
  169. }).then(r => r.json()).then(json => {
  170. let data = {
  171. sponsored: (json.costMultiplier * 100),
  172. players: json.playerAmount,
  173. bet: json.betAmount,
  174. private: json.privateGame,
  175. id: json._id
  176. };
  177.  
  178. return data;
  179. });
  180. }
  181.  
  182. // Joining the battle! It will enter in any available cup.
  183. function joinGame(gameId) {
  184. if(socket == null || socket.readyState !== socket.OPEN)
  185. return;
  186.  
  187. socket.send(`42/cups,["join-game","${gameId}","blue"]`);
  188. socket.send(`42/cups,["join-game","${gameId}","red"]`);
  189. socket.send(`42/cups,["join-game","${gameId}","green"]`);
  190. socket.send(`42/cups,["join-game","${gameId}","yellow"]`);
  191. }
  192.  
  193.  
  194. // Every 15 seconds sends a message to the socket in order to keep it alive.
  195. setInterval(function() {
  196. if(socket != null && socket.readyState === socket.OPEN)
  197. socket.send("2");
  198. }, 15 * 1000);
  199.  
  200. // Refreshing the site every 60mintues (You can remove it if you wish)
  201. setInterval(function() {
  202. window.location = window.location;
  203. }, 60 * 60 * 1000);
  204.  
  205. // Running the main function in 2 seconds delay from when the site opened.
  206. setTimeout(() => {
  207. httpConnection();
  208. }, 2000);
Add Comment
Please, Sign In to add comment