This repository was archived by the owner on Dec 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsearchUsernameInGameInstance.js
65 lines (61 loc) · 2.64 KB
/
searchUsernameInGameInstance.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
const fetch = require('node-fetch');
const username = process.argv[2];
const placeId = process.argv[3];
const maxInstancesToGoThrough = process.argv[4] || 1;
const robloSecurity = process.argv[5];
const debug = process.argv[6] || false;
const getJson = async (url, cookie=false) => {
let headers = {};
if(cookie) {
// .ROBLOSECURITY
headers['Cookie'] = `.ROBLOSECURITY=${robloSecurity};`
}
let req = await fetch(url, {headers});
let json = await req.json();
return json;
}
const endpointUser = "https://api.roblox.com/users/get-by-username?username=";
const endpointThumbnail = "https://thumbnails.roblox.com/v1/users/avatar-headshot?size=48x48&format=png&userIds=";
const endpointGameInstances = (eplaceId, index=0) => `https://www.roblox.com/games/getgameinstancesjson?placeId=${eplaceId}&startIndex=${index}&_=${Date.now()}`;
const d = (...args) => {
if(debug) console.log(...args);
}
(async () => {
let user = await getJson(endpointUser + username);
if(user.success === false) {
console.log(user.errorMessage)
} else {
// 295551769
let thumbnail = await getJson(endpointThumbnail + user.Id);
let userThumbnailURL = thumbnail.data[0].imageUrl;
d(`Fetched ${user.Username} avatar headshot: ${userThumbnailURL}`)
let i = 0;
const asyncForEach = async () => {
if(i <= maxInstancesToGoThrough-1) {
d('Searching into instance ', i, 'Start Index: ', i*10)
getJson(endpointGameInstances(placeId, i*10), true).then(gameInstances => {
if(gameInstances.Collection.length < 1) {
finished('Reached instances limit. (' + i + ')')
} else {
gameInstances.Collection.forEach(gameInstance => {
d('Found instance with ', gameInstance.PlayersCapacity)
gameInstance.CurrentPlayers.forEach(player => {
if(player.Thumbnail.Url == userThumbnailURL) {
console.log(`Found user on an instance with GUID ${gameInstance.Guid}, join script: ${gameInstance.JoinScript}`)
}
})
})
asyncForEach();
}
})
} else {
finished();
}
i++
}
const finished = (m='') => {
console.log('Done. ' + m)
}
asyncForEach();
}
})()