Skip to content

Instantly share code, notes, and snippets.

@Cynosphere
Last active January 19, 2022 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cynosphere/7ac45bd91175071f04989479d974aa26 to your computer and use it in GitHub Desktop.
Save Cynosphere/7ac45bd91175071f04989479d974aa26 to your computer and use it in GitHub Desktop.
sourcequery nodejs
const dgram = require("dgram");
const client = dgram.createSocket("udp4");
const ip = process.argv[2];
const port = process.argv[3] || 27015;
if (!ip) {
console.log("giv ip");
process.exit(1);
}
const request = [
0xff, 0xff, 0xff, 0xff, 0x54, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x20, 0x45,
0x6e, 0x67, 0x69, 0x6e, 0x65, 0x20, 0x51, 0x75, 0x65, 0x72, 0x79, 0x00,
];
client.send(Buffer.from(request), 27030, "soulja-boy-told.me", function (err) {
if (err) {
client.close();
throw err;
}
});
client.on("message", function (message) {
const msg = new DataView(message.buffer);
if (msg.getUint8(4) == 0x41) {
/*console.log(
"got challenge",
msg.getUint8(5).toString(16),
msg.getUint8(6).toString(16),
msg.getUint8(7).toString(16),
msg.getUint8(8).toString(16)
);*/
client.send(
Buffer.from([
...request,
msg.getUint8(5),
msg.getUint8(6),
msg.getUint8(7),
msg.getUint8(8),
]),
port,
ip,
function (err) {
if (err) {
client.close();
throw err;
}
}
);
} else if (msg.getUint8(4) == 0x49) {
//console.log("got query response");
const protocolVer = msg.getUint8(5);
console.log("protocol version:", protocolVer);
let idx = 6;
const name = [];
while (msg.getUint8(idx) != 0) {
name.push(msg.getUint8(idx));
idx++;
}
console.log("name:", String.fromCharCode(...name));
idx++;
const map = [];
while (msg.getUint8(idx) != 0) {
map.push(msg.getUint8(idx));
idx++;
}
console.log("map:", String.fromCharCode(...map));
idx++;
const folder = [];
while (msg.getUint8(idx) != 0) {
folder.push(msg.getUint8(idx));
idx++;
}
console.log("folder:", String.fromCharCode(...folder));
idx++;
const game = [];
while (msg.getUint8(idx) != 0) {
game.push(msg.getUint8(idx));
idx++;
}
console.log("game:", String.fromCharCode(...game));
idx++;
console.log("steam id:", msg.getUint16(idx));
idx += 2;
console.log("players:", msg.getUint8(idx));
idx++;
console.log("max players:", msg.getUint8(idx));
idx++;
console.log("bots:", msg.getUint8(idx));
idx++;
console.log("type:", String.fromCharCode(msg.getUint8(idx)));
idx++;
console.log("os:", String.fromCharCode(msg.getUint8(idx)));
idx++;
console.log("visibility:", msg.getUint8(idx));
idx++;
console.log("vac:", msg.getUint8(idx));
idx++;
const version = [];
while (msg.getUint8(idx) != 0) {
version.push(msg.getUint8(idx));
idx++;
}
console.log("version:", String.fromCharCode(...version));
idx++;
const edf = msg.getUint8(idx);
console.log("edf is:", edf);
console.log("\n====== EDF Values ======");
if (edf & 0x80) {
console.log("port:", msg.getUint16(idx));
idx += 2;
}
if (edf & 0x10) {
console.log("steamid:", msg.getUint32(idx));
idx += 4;
}
if (edf & 0x40) {
console.log("sourcetv port:", msg.getUint16(idx));
idx += 2;
const stvname = [];
while (msg.getUint8(idx) != 0) {
stvname.push(msg.getUint8(idx));
idx++;
}
console.log("sourcetv name:", String.fromCharCode(...stvname));
idx++;
}
if (edf & 0x20) {
const tags = [];
while (msg.getUint8(idx) != 0) {
tags.push(msg.getUint8(idx));
idx++;
}
console.log("tags:", String.fromCharCode(...tags));
idx++;
}
if (edf & 0x01) {
console.log("extended app id:", msg.getBigUint64(idx));
idx += 8;
}
client.close();
} else {
client.close();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment