Hirsw0w

[Cups.GG] Free Battle Script!

Jul 9th, 2020
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.60 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. console.log("Game found!");
  142. console.log(data);
  143. if(data.sponsored > 80)
  144. joinGame(data.id);
  145. }
  146.  
  147.  
  148. // Function that fetches the data of the battle that was found and checks whether its exist or not.
  149. function gameData(gameLink) {
  150. return fetch("https://api.cups.gg/api/cups/private/" + gameLink, {
  151. "headers": {
  152. "accept": "application/json, text/plain, */*",
  153. "accept-language": "he-IL,he;q=0.9,en-US;q=0.8,en;q=0.7,nl;q=0.6",
  154. "sec-fetch-dest": "empty",
  155. "sec-fetch-mode": "cors",
  156. "sec-fetch-site": "same-site",
  157. "x-auth-token": token
  158. },
  159. "referrer": "https://cups.gg/cups/private/" + gameLink,
  160. "referrerPolicy": "no-referrer-when-downgrade",
  161. "body": null,
  162. "method": "GET",
  163. "mode": "cors",
  164. "credentials": "omit"
  165. }).then(r => r.json()).then(json => {
  166. let data = {
  167. sponsored: (json.costMultiplier * 100),
  168. players: json.playerAmount,
  169. bet: json.betAmount,
  170. private: json.privateGame,
  171. id: json._id
  172. };
  173.  
  174. return data;
  175. });
  176. }
  177.  
  178. // Joining the battle! It will enter in any available cup.
  179. function joinGame(gameId) {
  180. if(socket == null || socket.readyState !== socket.OPEN)
  181. return;
  182.  
  183. socket.send(`42/cups,["join-game","${gameId}","blue"]`);
  184. socket.send(`42/cups,["join-game","${gameId}","red"]`);
  185. socket.send(`42/cups,["join-game","${gameId}","green"]`);
  186. socket.send(`42/cups,["join-game","${gameId}","yellow"]`);
  187. }
  188.  
  189.  
  190. // Every 15 seconds sends a message to the socket in order to keep it alive.
  191. setInterval(function() {
  192. if(socket != null && socket.readyState === socket.OPEN)
  193. socket.send("2");
  194. }, 15 * 1000);
  195.  
  196. // Refreshing the site every 60mintues (You can remove it if you wish)
  197. setInterval(function() {
  198. window.location = window.location;
  199. }, 60 * 60 * 1000);
  200.  
  201. // Running the main function in 2 seconds delay from when the site opened.
  202. setTimeout(() => {
  203. httpConnection();
  204. }, 2000);
Add Comment
Please, Sign In to add comment