-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlauncher.js
66 lines (59 loc) · 2.28 KB
/
launcher.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const net = require('net'),
querystring = require('querystring'),
crypto = require('crypto'),
request = require('./request'),
accounts = require('./accounts'),
server = new net.Server().listen(26117);
server.on('connection', function (socket) {
let uuid;
socket.on('data', function (data) {
try {
const str = data.toString().slice(0, -1);
if (str.startsWith("connect retro main -1")) {
const split = str.split(" ");
uuid = split[split.length - 1];
socket.write("connected\x00");
socket.write("connect " + uuid + "\x00");
} else if (str.startsWith("auth_getGameToken")) {
for (let a in accounts) {
if (accounts[a].key === uuid) {
// noinspection JSIgnoredPromiseFromCall
getGameToken(accounts[a], socket, 101);
break;
}
}
}
} catch (e) {
console.log(e);
}
});
socket.on('end', function () {
});
});
function generateHashFromCertif(hm1, hm2, certif) {
const i = crypto.createDecipheriv("aes-256-ecb", hm2, ""),
r = Buffer.concat([i.update(certif['encodedCertificate'], "base64"), i.final()]);
return crypto.createHash("sha256").update(hm1 + r.toString()).digest("hex")
}
async function getGameToken(account, socket, game) {
const queryPath = {game, certificate_id: "", certificate_hash: ""};
socket['accountLogin'] = account['login'];
if (account['certificate']) {
queryPath['certificate_id'] = account['certificate']['id'];
queryPath['certificate_hash'] = generateHashFromCertif(account['hm1'], account['hm2'], account['certificate']);
}
const APIKEY = account['key'];
await request(
{
path: "/json/Ankama/v5/Api/RefreshApiKey",
method: 'POST',
headers: {APIKEY}
}, "refresh_token=" + account['refresh_token'] + "&long_life_token=true"
);
const json = await request({
path: "/json/Ankama/v5/Account/CreateToken?" + querystring.stringify(queryPath),
method: 'GET',
headers: {APIKEY}
});
socket.write("auth_getGameToken " + json[1]['token'] + "\x00");
}