Advertisement
Guest User

Untitled

a guest
Mar 31st, 2019
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Websocket from 'websocket'
  2. import axios from 'axios-https-proxy-fix'
  3. import querystring from 'querystring'
  4. import { machineIdSync} from 'node-machine-id'
  5.  
  6. import { client as WebSocketClient } from 'websocket'
  7.  
  8. console.log('Authorization 4game client Copyright (c)2019 by iceTeam')
  9.  
  10. console.log('Settings file: ', process.argv[2] + '.json')
  11. const settings = require('./' + process.argv[2] + '.json')
  12.  
  13. const axiosproxyConfig =  { host: settings.proxy.ip, port: settings.proxy.port, auth: {
  14.   username: settings.proxy.login,
  15.   password: settings.proxy.pass
  16. }}
  17.  
  18. var child = require('child_process').execFile
  19.  
  20. const WsClient = new WebSocketClient()
  21. const launcherFile = settings.main.launcherFile
  22. const email = settings.main.email
  23. const password = settings.main.password
  24. const useProxy = settings.main.useProxy
  25. const compName = settings.main.compName
  26. const hwID = settings.main.hwID
  27. const launchID = settings.main.launchID
  28.  
  29. let glob = {}
  30.  
  31. glob.SessToken = makeID()
  32.  
  33. const tokenRequest = async () => {
  34.     console.log('\x1b[33m%s\x1b[0m', `Sending -> password=${password}&username=${email}&secure=true&grant_type=password`)
  35.     const xReqID = makeID()
  36.     const dataToPost = {'password': password, 'username': email, 'grant_type': 'password', 'secure': 'true'}   
  37.     try {
  38.         const response  = await axios.post('https://launcherbff.ru.4game.com/connect/token',querystring.stringify(dataToPost), {
  39.             proxy: useProxy ? axiosproxyConfig : null,
  40.             headers: {
  41.                 'Origin': 'https://launcher.ru.4game.com',
  42.                 'Host': 'launcherbff.ru.4game.com',
  43.                 'Content-Type': 'application/x-www-form-urlencoded',
  44.                 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.24 Safari/537.36',
  45.                 'computer-name' : compName,
  46.                 'accept' : 'application/json, text/plain, */*',
  47.                 'hardware-id' : hwID,
  48.                 'launcher-id' : launchID,
  49.                 'x-request-id' : xReqID,
  50.                 'referer' : 'https://launcher.ru.4game.com/auth',
  51.                 'session-token' : glob.SessToken,
  52.                 'accept-encoding' : 'gzip, deflate',
  53.                 'accept-language' : 'ru-ru'
  54.             }
  55.         })
  56.         console.log('\x1b[32m', 'Response <- GOOD')
  57.         glob.access_token = response.data && response.data.access_token
  58.         glob.refresh_token = response.data && response.data.refresh_token  
  59.         return true
  60.     } catch(e) {
  61.         console.log('\x1b[31m', 'Response <- Error')
  62.         if(e.response.data && e.response.data.error){
  63.             const error = e.response.data.error
  64.             glob.sessionId = e.response.data && e.response.data.error && e.response.data.error.data.sessionId
  65.             return error.code === 'guard.emailcoderequired' ? await promptCode() : false
  66.         }
  67.     }
  68. }
  69.  
  70. const promptCode = async () => {
  71.     const readline = require('readline');
  72.     const rl = readline.createInterface({input: process.stdin,output: process.stdout});
  73.     rl.question('ENTER THE 5 NUM CODE:', async (emailCode)=>{
  74.         glob.email_code = emailCode
  75.         rl.close();
  76.         return await sendEmailCode()
  77.     });
  78. }
  79.            
  80. const sendEmailCode = async () => {
  81.     console.log('\x1b[33m%s\x1b[0m', `Sending -> sessionId=${glob.sessionId}&code=${glob.email_code}`)
  82.     const xReqID = makeID()
  83.     const dataToPost = {'sessionId': glob.sessionId, 'code': glob.email_code}
  84.     try {
  85.         const response  = await axios.post('https://launcherbff.ru.4game.com/api/guard/accesscodes/activate',dataToPost, {
  86.             proxy: useProxy ? axiosproxyConfig : null,
  87.             headers: {
  88.                 'Origin': 'https://launcher.ru.4game.com',
  89.                 'Content-Type': 'application/json;charset=UTF-8',
  90.                 'authorization' : `Bearer ${glob.access_token}`,
  91.                 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.24 Safari/537.36',
  92.                 'computer-name' : compName,
  93.                 'accept' : 'application/json, text/plain, */*',
  94.                 'hardware-id' : hwID,
  95.                 'launcher-id' : launchID,
  96.                 'x-request-id' : xReqID,
  97.                 'referer' : 'https://launcher.ru.4game.com/auth',
  98.                 'session-token' : glob.SessToken,
  99.                 'accept-encoding' : 'gzip, deflate',
  100.                 'accept-language' : 'ru-ru'
  101.             }
  102.         })
  103.         console.log('\x1b[32m', 'Response <- GOOD')
  104.         console.log('isActivated: ', response.data.data.userSession.isActivated)
  105.         console.log('session-token: ', response.data.data.userSession.token)
  106.         glob.SessToken = response.data && response.data.data.userSession.token
  107.         return await tokenRequest()
  108.     } catch(e) {
  109.         console.log('\x1b[31m', 'Response <- Error')
  110.         console.log(e)
  111.         const error = e.response.data.error
  112.         console.log(error)
  113.         return error.code === 'guard.mismatchaccesscode' ? await promptCode() : false
  114.     }
  115. }
  116.            
  117. const getRelevantTokens = async () => {
  118.     console.log('\x1b[33m%s\x1b[0m', `Sending -> grant_type=refresh_token&refresh_token=${glob.refresh_token}`)
  119.     const xReqID = makeID()
  120.     const dataToPost = {'grant_type': 'refresh_token', 'refresh_token': glob.refresh_token}
  121.     try {
  122.         const response  = await axios.post('https://launcherbff.ru.4game.com/connect/token',querystring.stringify(dataToPost), {
  123.             proxy: useProxy ? axiosproxyConfig : null,
  124.             headers: {
  125.                 'Origin': 'https://launcher.ru.4game.com',
  126.                 'Host': 'launcherbff.ru.4game.com',
  127.                 'authorization' : `Bearer ${glob.access_token}`,
  128.                 'Content-Type': 'application/x-www-form-urlencoded',
  129.                 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.24 Safari/537.36',
  130.                 'computer-name' : compName,
  131.                 'accept' : 'application/json, text/plain, */*',
  132.                 'hardware-id' : hwID,
  133.                 'launcher-id' : launchID,
  134.                 'x-request-id' : xReqID,
  135.                 'referer' : 'https://launcher.ru.4game.com/auth',
  136.                 'session-token' : glob.SessToken,
  137.                 'accept-encoding' : 'gzip, deflate',
  138.                 'accept-language' : 'ru-ru'
  139.             }
  140.         })
  141.         console.log('\x1b[32m', 'Response <- GOOD')
  142.         glob.access_token = response.data && response.data.access_token
  143.         glob.refresh_token = response.data && response.data.refresh_token
  144.         return true
  145.     } catch(e) {
  146.         console.log('\x1b[31m', 'Response <- Error')
  147.         console.log(e.response)
  148.         return false
  149.     }
  150. }
  151.  
  152. const WsConnect = async () => {
  153.     WsClient.on('connectFailed', function(error) {
  154.         console.log('Connect Error: ' + error.toString());
  155.     });
  156.  
  157.     WsClient.on('connect', function(connection) {
  158.         console.log('\x1b[33m%s\x1b[0m', 'WebSocket Client Connected');
  159.         connection.on('error', function(error) {
  160.             console.log("Connection Error: " + error.toString());
  161.         });
  162.         connection.on('close', function() {
  163.             console.log('echo-protocol Connection Closed');
  164.         });
  165.         connection.on('message', function(message) {
  166.             const data = JSON.parse(message.utf8Data)
  167.             parseWsRequests(data, connection)
  168.         });    
  169.         getAuthProfile(connection)
  170.       })
  171.     WsClient.connect(`wss://launcherbff.ru.4game.com/?token=${glob.access_token}&hardware-id=${hwID}&launcher-id=${launchID}&computer-name=${compName}`);
  172. }
  173.  
  174. const getAuthProfile = (connection) => {   //Шлём для получения UserID
  175.     console.log('\x1b[32m', ' Process -> getAuthProfile')
  176.     glob.getAuthProfileID = makeID()
  177.     connection.send(`{"jsonrpc":"2.0","method":"getAuthProfile","params":null,"id":"${glob.getAuthProfileID}"}`);
  178. }
  179. const getLogin = (connection) => {
  180.     console.log('\x1b[32m', ' Process -> getLogin')
  181.     glob.getLoginID = makeID()
  182.     connection.send(`{"jsonrpc":"2.0","method":"getGameAccount","params":{"masterId":${glob.userID},"toPartnerId":"ro-ru"},"id":"${glob.getLoginID}"}`);
  183. }
  184. const acceptLicense = (connection) => {
  185.     console.log('\x1b[32m', ' Process -> acceptLicense')
  186.     glob.acceptLicenseID = makeID()
  187.     connection.send(`{"jsonrpc":"2.0","method":"createGameAccount","params":{"masterId":${glob.userID},"toPartnerId":"ro-ru","fromPartnerId":"forgame-ru","acceptLicense":true},"id":"${glob.acceptLicenseID}"}`);
  188. }
  189. const createGameTokenCode = (connection) => {
  190.     console.log('\x1b[32m', ' Process -> createGameTokenCode')
  191.     glob.GameTokenCodeID = makeID()
  192.     connection.send(JSON.stringify({   
  193.                         "jsonrpc":"2.0",
  194.                         "method":"createGameTokenCode",
  195.                         "params":{
  196.                             "accessToken":glob.access_token,
  197.                             "fromPartnerId":"forgame-eu",
  198.                             "ignoreLicenseAcceptance":true,
  199.                             "login":glob.login,
  200.                             "masterId":glob.userID,
  201.                             "toPartnerId":"ro-ru"
  202.                         },
  203.                         "id":glob.GameTokenCodeID
  204.                     }))
  205. }
  206.  
  207. const parseWsRequests = async (data, connection) => {
  208.     switch (data.id) {
  209.         case `${glob.getAuthProfileID}`:
  210.             glob.userID = data.result.id
  211.             getLogin(connection)
  212.             break;
  213.         case `${glob.getLoginID}`:
  214.             if (data.error && data.error.code === "gameauth.gameaccountsnotfound") {
  215.                 acceptLicense(connection)
  216.                 return
  217.             }
  218.             glob.login = data.result[0].login
  219.             createGameTokenCode(connection)
  220.             break;
  221.         case `${glob.acceptLicenseID}`:
  222.             if (data.error && data.error.code) {
  223.                 return
  224.             }
  225.             getLogin(connection)
  226.             break;
  227.         case `${glob.GameTokenCodeID}`:
  228.             if (data.result) {
  229.                 launchFrost(data.result.login, data.result.password)
  230.             }
  231.             break;
  232.         default:
  233.             // statements_def
  234.             console.log('\x1b[31m', 'Error:')
  235.             console.log(data)
  236.             break;
  237.     }
  238. }
  239.  
  240. const doRequests = async () => {
  241.     await tokenRequest() && await getRelevantTokens() && WsConnect()
  242. }
  243.  
  244. const launchFrost = (login, pass) => {
  245.      // id:%LOGIN% pw:%PASS%
  246.     const params = [login, pass]
  247.     child(launcherFile, params, function(err, data) {
  248.          console.log(err)
  249.          console.log(data.toString());
  250.     });
  251. }
  252.  
  253. doRequests()
  254.  
  255. function makeID() {
  256.     var text = ""
  257.     var possible = "abcdef1234567890"
  258.  
  259.     for( var i=1; i <= 8; i++ ) {
  260.         text += possible.charAt(Math.floor(Math.random() * possible.length));
  261.     }
  262.     text += "-"
  263.     for( var i=1; i <= 4; i++ ) {
  264.         text += possible.charAt(Math.floor(Math.random() * possible.length));
  265.     }
  266.     text += "-"
  267.     for( var i=1; i <= 4; i++ ) {
  268.         text += possible.charAt(Math.floor(Math.random() * possible.length));
  269.     }
  270.     text += "-"
  271.     for( var i=1; i <= 4; i++ ) {
  272.         text += possible.charAt(Math.floor(Math.random() * possible.length));
  273.     }
  274.     text += "-"
  275.     for( var i=1; i <= 12; i++ ) {
  276.         text += possible.charAt(Math.floor(Math.random() * possible.length));
  277.     }
  278.    
  279.     return text
  280. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement