Skip to content

Commit

Permalink
🐛 Fix info queries failing because of challenge response
Browse files Browse the repository at this point in the history
  • Loading branch information
GiyoMoon committed Dec 30, 2021
1 parent 4eb4134 commit e3e27b9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
18 changes: 13 additions & 5 deletions src/gameServer/gameServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ class GameServerQuery {
throw new Error(err);
}

// If the server replied with a challenge, grab challenge number and send request again
if (resultBuffer.compare(Buffer.from([0xFF, 0xFF, 0xFF, 0xFF, 0x41]), 0, 5, 0, 5) === 0) {
resultBuffer = resultBuffer.slice(5);
const challenge = resultBuffer;
try {
resultBuffer = await this._promiseSocket.send(this._buildInfoPacket(challenge), this._host, this._port);
} catch (err: any) {
throw new Error(err);
}
}

const parsedInfoBuffer = this._parseInfoBuffer(resultBuffer);
return parsedInfoBuffer as InfoResponse;
}
Expand Down Expand Up @@ -120,18 +131,15 @@ class GameServerQuery {
let packet = Buffer.concat([
Buffer.from([0xFF, 0xFF, 0xFF, 0xFF]),
Buffer.from([0x54]),
Buffer.from('Source Engine Query', 'ascii')
Buffer.from('Source Engine Query', 'ascii'),
Buffer.from([0x00])
]);
if (challenge) {
packet = Buffer.concat([
packet,
challenge
]);
}
packet = Buffer.concat([
packet,
Buffer.from([0x00])
]);
return packet;
}

Expand Down
10 changes: 7 additions & 3 deletions src/masterServer/masterServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ class MasterServerQuery {
// @ts-ignore
let val = this._filters[key];
str += '\\' + key + '\\';
str += (key === 'nor' || key === 'nand')
? Object.keys(val).length + this._slashifyObject(val)
: val;
if (key === 'nor' || key === 'nand') {
str += Object.keys(val).length + this._slashifyObject(val);
} else if (Array.isArray(val)) {
str += val.join(',');
} else {
str += val;
}
}
str += '\x00';
return str;
Expand Down

0 comments on commit e3e27b9

Please sign in to comment.