Reduced chance of protocol collisions between gamespy3 and minecraftbedrock (2.0.27)

This commit is contained in:
Michael Morrison 2021-02-12 11:36:51 -06:00
parent 883700d7dd
commit 052736edd7
6 changed files with 41 additions and 21 deletions

View file

@ -9,7 +9,7 @@ class MinecraftBedrock extends Core {
async run(state) {
const bufs = [
Buffer.from([0x01]), // Message ID, ID_UNCONNECTED_PING
Buffer.from('0000000000000000', 'hex'), // Nonce / timestamp
Buffer.from('1122334455667788', 'hex'), // Nonce / timestamp
Buffer.from('00ffff00fefefefefdfdfdfd12345678', 'hex'), // Magic
Buffer.from('0000000000000000', 'hex') // Cliend GUID
];
@ -19,17 +19,26 @@ class MinecraftBedrock extends Core {
const messageId = reader.uint(1);
if (messageId !== 0x1c) {
throw new Error('Invalid message id');
this.logger.debug('Skipping packet, invalid message id');
return;
}
const nonce = reader.part(8).toString('hex'); // should match the nonce we sent
this.logger.debug('Nonce: ' + nonce);
if (nonce !== '1122334455667788') {
this.logger.debug('Skipping packet, invalid nonce');
return;
}
// These 8 bytes are identical to the serverId string we receive in decimal below
reader.skip(8);
const magic = reader.part(16).toString('hex');
this.logger.debug('Magic value: ' + magic);
if (magic !== '00ffff00fefefefefdfdfdfd12345678') {
this.logger.debug('Skipping packet, invalid magic');
return;
}
const statusLen = reader.uint(2);
if (reader.remaining() !== statusLen) {
@ -40,23 +49,22 @@ class MinecraftBedrock extends Core {
this.logger.debug('Raw status str: ' + statusStr);
const split = statusStr.split(';');
if (split.length < 12) {
if (split.length < 6) {
throw new Error('Missing enough chunks in status str');
}
let i = 0;
state.raw.edition = split[i++];
state.name = split[i++];
state.raw.protocolVersion = split[i++];
state.raw.mcVersion = split[i++];
state.players = parseInt(split[i++]);
state.maxplayers = parseInt(split[i++]);
state.raw.serverId = split[i++];
state.map = split[i++];
state.raw.gameMode = split[i++];
state.raw.nintendoOnly = !!parseInt(split[i++]);
state.raw.ipv4Port = split[i++];
state.raw.ipv6Port = split[i++];
state.raw.edition = split.shift();
state.name = split.shift();
state.raw.protocolVersion = split.shift();
state.raw.mcVersion = split.shift();
state.players = parseInt(split.shift());
state.maxplayers = parseInt(split.shift());
if (split.length) state.raw.serverId = split.shift();
if (split.length) state.map = split.shift();
if (split.length) state.raw.gameMode = split.shift();
if (split.length) state.raw.nintendoOnly = !!parseInt(split.shift());
if (split.length) state.raw.ipv4Port = split.shift();
if (split.length) state.raw.ipv6Port = split.shift();
return true;
});