Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Auth token used to verify your account.
- var token = localStorage.getItem("token");
- // saving the battles you already tried to entered into.
- var enteredBattles = localStorage.getItem("enteredBattles");
- if (enteredBattles == null) {
- localStorage.setItem("enteredBattles", "");
- enteredBattles = "";
- }
- // variables to make a connection with the site
- var http = new XMLHttpRequest();
- var socket = null;
- // Function that initiate a connection with the site with their sockets
- function httpConnection() {
- var delay = localStorage.getItem("delay");
- if(delay != null && delay > Date.now())
- return;
- localStorage.setItem("delay", Date.now() + 1000);
- http.open("GET", "https://api.cups.gg/socket.io/?EIO=3&transport=polling&t=asd", true);
- http.send();
- http.onreadystatechange = function () {
- if (this.readyState === 4 && this.status === 200) {
- var x = this.responseText;
- var obj = JSON.parse(x.slice(x.indexOf('{'), x.lastIndexOf('}') + 1));
- createConnection(obj.sid);
- }
- };
- }
- // Function that connect to their sockets + verifying what user uses the socket.
- function createConnection(sid) {
- socket = new WebSocket("wss://api.cups.gg/socket.io/?EIO=3&transport=websocket&sid=" + sid);
- // socket connection established
- socket.onopen = (e) => {
- console.log("[Cups.GG] Connection established!");
- socket.send("2probe");
- // Pass the socket that you want access to the chat.
- fetch("https://api.cups.gg/socket.io/?EIO=3&transport=polling&t=NCWUlDK" + "&sid=" + sid, {
- "credentials": "include",
- "headers": {
- "accept": "*/*",
- "accept-language": "he-IL,he;q=0.9,en-US;q=0.8,en;q=0.7",
- "content-type": "text/plain;charset=UTF-8",
- "sec-fetch-mode": "cors",
- "sec-fetch-site": "same-site"
- },
- "referrer": "https://cups.gg/cups/",
- "referrerPolicy": "no-referrer-when-downgrade",
- "body": "8:40/chat,",
- "method": "POST",
- "mode": "cors"
- });
- // Pass the socket the auth key of the user you want to verify as
- fetch("https://api.cups.gg/socket.io/?EIO=3&transport=polling&t=NCWUlDK" + "&sid=" + sid, {
- "credentials": "include",
- "headers": {
- "accept": "*/*",
- "accept-language": "he-IL,he;q=0.9,en-US;q=0.8,en;q=0.7",
- "content-type": "text/plain;charset=UTF-8",
- "sec-fetch-mode": "cors",
- "sec-fetch-site": "same-site"
- },
- "referrer": "https://cups.gg/cups/",
- "referrerPolicy": "no-referrer-when-downgrade",
- "body": "202:42/chat,[\"auth\",\"" + token + "\"]",
- "method": "POST",
- "mode": "cors"
- });
- // pass the socket that you want access to all the games
- fetch("https://api.cups.gg/socket.io/?EIO=3&transport=polling&t=NCWUlDK" + "&sid=" + sid, {
- "credentials": "include",
- "headers": {
- "accept": "*/*",
- "accept-language": "he-IL,he;q=0.9,en-US;q=0.8,en;q=0.7",
- "content-type": "text/plain;charset=UTF-8",
- "sec-fetch-mode": "cors",
- "sec-fetch-site": "same-site"
- },
- "referrer": "https://cups.gg/cups/",
- "referrerPolicy": "no-referrer-when-downgrade",
- "body": "8:40/cups,11:40/shuffle,8:40/king,12:40/roulette,",
- "method": "POST",
- "mode": "cors"
- });
- }
- // A message sent to the socket
- socket.onmessage = (e) => {
- var message = e.data;
- if(message === "3probe") {
- // Sending all the required data to the socket in order to verify the user and make the connection stay alive.
- socket.send("5");
- socket.send("40/chat,");
- socket.send(`42/cups,["auth", "${token}"]`);
- socket.send(`42/shuffle,["auth", "${token}"]`);
- socket.send(`42/king,["auth", "${token}"]`);
- socket.send(`42/roulette,["auth", "${token}"]`);
- return;
- }
- // A new chat message has been detected! Checking if a battle was sent
- if(message.indexOf("new-chat-message") !== -1) {
- var obj = JSON.parse(message.slice(message.indexOf('{'),message.lastIndexOf('}') + 1));
- var content = obj.content;
- checkContent(content);
- }
- }
- // socket connection was closed ( reinitating the socket connection in 5 seconds. )
- socket.onclose = (e) => {
- console.log("[Cups.GG] Connection closed reconnecting in 5 seconds!");
- setTimeout(httpConnection, 5000);
- }
- }
- // check the contect of the message for a free battle.
- async function checkContent(content) {
- // verifying the text to match xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (represent a battle link)
- var match = content.match("[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}");
- if(match == null || enteredBattles.indexOf(match[0]) !== -1)
- return;
- // adding the battle to the battle you already tried to enter into.
- var gameId = match[0];
- enteredBattles += gameId + ";";
- localStorage.setItem("enteredBattles", enteredBattles);
- // Fetching game data and checking whether its free (if its sponsored atleast 80% )
- var data = await gameData(gameId);
- if(data.sponsored > 80) {
- var delayTime = Math.random() * 1500 + 1000;
- console.log("Game has been found delay has been set to " + delayTime + "ms.");
- console.log(data);
- setTimeout(() => {
- joinGame(data.id);
- }, delayTime);
- }
- }
- // Function that fetches the data of the battle that was found and checks whether its exist or not.
- function gameData(gameLink) {
- return fetch("https://api.cups.gg/api/cups/private/" + gameLink, {
- "headers": {
- "accept": "application/json, text/plain, */*",
- "accept-language": "he-IL,he;q=0.9,en-US;q=0.8,en;q=0.7,nl;q=0.6",
- "sec-fetch-dest": "empty",
- "sec-fetch-mode": "cors",
- "sec-fetch-site": "same-site",
- "x-auth-token": token
- },
- "referrer": "https://cups.gg/cups/private/" + gameLink,
- "referrerPolicy": "no-referrer-when-downgrade",
- "body": null,
- "method": "GET",
- "mode": "cors",
- "credentials": "omit"
- }).then(r => r.json()).then(json => {
- let data = {
- sponsored: (json.costMultiplier * 100),
- players: json.playerAmount,
- bet: json.betAmount,
- private: json.privateGame,
- id: json._id
- };
- return data;
- });
- }
- // Joining the battle! It will enter in any available cup.
- function joinGame(gameId) {
- if(socket == null || socket.readyState !== socket.OPEN)
- return;
- socket.send(`42/cups,["join-game","${gameId}","blue"]`);
- socket.send(`42/cups,["join-game","${gameId}","red"]`);
- socket.send(`42/cups,["join-game","${gameId}","green"]`);
- socket.send(`42/cups,["join-game","${gameId}","yellow"]`);
- }
- // Every 15 seconds sends a message to the socket in order to keep it alive.
- setInterval(function() {
- if(socket != null && socket.readyState === socket.OPEN)
- socket.send("2");
- }, 15 * 1000);
- // Refreshing the site every 60mintues (You can remove it if you wish)
- setInterval(function() {
- window.location = window.location;
- }, 60 * 60 * 1000);
- // Running the main function in 2 seconds delay from when the site opened.
- setTimeout(() => {
- httpConnection();
- }, 2000);
Add Comment
Please, Sign In to add comment