Reduced chance of protocol collisions between gamespy3 and minecraftbedrock (2.0.27)
This commit is contained in:
parent
883700d7dd
commit
052736edd7
|
@ -1,3 +1,6 @@
|
||||||
|
### 2.0.27
|
||||||
|
* Reduced chance of protocol collisions between gamespy3 and minecraftbedrock
|
||||||
|
|
||||||
### 2.0.26
|
### 2.0.26
|
||||||
* Added support for the native minecraft bedrock protocol, since some
|
* Added support for the native minecraft bedrock protocol, since some
|
||||||
bedrock servers apparently do not respond to the gamespy3 protocol.
|
bedrock servers apparently do not respond to the gamespy3 protocol.
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
],
|
],
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"author": "GameDig Contributors",
|
"author": "GameDig Contributors",
|
||||||
"version": "2.0.26",
|
"version": "2.0.27",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/gamedig/node-gamedig.git"
|
"url": "https://github.com/gamedig/node-gamedig.git"
|
||||||
|
|
|
@ -35,7 +35,9 @@ class Core extends EventEmitter {
|
||||||
}
|
}
|
||||||
this.logger.prefix = 'Q#' + (uid++);
|
this.logger.prefix = 'Q#' + (uid++);
|
||||||
|
|
||||||
this.logger.debug("Query is running with options:", this.options);
|
this.logger.debug("Starting");
|
||||||
|
this.logger.debug("Protocol: " + this.constructor.name);
|
||||||
|
this.logger.debug("Options:", this.options);
|
||||||
|
|
||||||
let abortCall = null;
|
let abortCall = null;
|
||||||
this.abortedPromise = new Promise((resolve,reject) => {
|
this.abortedPromise = new Promise((resolve,reject) => {
|
||||||
|
|
|
@ -148,9 +148,15 @@ class Gamespy3 extends Core {
|
||||||
return await this.udpSend(b,(buffer) => {
|
return await this.udpSend(b,(buffer) => {
|
||||||
const reader = this.reader(buffer);
|
const reader = this.reader(buffer);
|
||||||
const iType = reader.uint(1);
|
const iType = reader.uint(1);
|
||||||
if(iType !== type) return;
|
if(iType !== type) {
|
||||||
|
this.logger.debug('Skipping packet, type mismatch');
|
||||||
|
return;
|
||||||
|
}
|
||||||
const iSessionId = reader.uint(4);
|
const iSessionId = reader.uint(4);
|
||||||
if(iSessionId !== this.sessionId) return;
|
if(iSessionId !== this.sessionId) {
|
||||||
|
this.logger.debug('Skipping packet, session id mismatch');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(!assemble) {
|
if(!assemble) {
|
||||||
return reader.rest();
|
return reader.rest();
|
||||||
|
|
|
@ -81,7 +81,8 @@ class Minecraft extends Core {
|
||||||
if (gamespyState) {
|
if (gamespyState) {
|
||||||
if (gamespyState.name) state.name = gamespyState.name;
|
if (gamespyState.name) state.name = gamespyState.name;
|
||||||
if (gamespyState.maxplayers) state.maxplayers = gamespyState.maxplayers;
|
if (gamespyState.maxplayers) state.maxplayers = gamespyState.maxplayers;
|
||||||
if (gamespyState.players) state.players = gamespyState.players;
|
if (gamespyState.players.length) state.players = gamespyState.players;
|
||||||
|
else if (gamespyState.raw.numplayers) state.players = parseInt(gamespyState.raw.numplayers);
|
||||||
}
|
}
|
||||||
// remove dupe spaces from name
|
// remove dupe spaces from name
|
||||||
state.name = state.name.replace(/\s+/g, ' ');
|
state.name = state.name.replace(/\s+/g, ' ');
|
||||||
|
|
|
@ -9,7 +9,7 @@ class MinecraftBedrock extends Core {
|
||||||
async run(state) {
|
async run(state) {
|
||||||
const bufs = [
|
const bufs = [
|
||||||
Buffer.from([0x01]), // Message ID, ID_UNCONNECTED_PING
|
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('00ffff00fefefefefdfdfdfd12345678', 'hex'), // Magic
|
||||||
Buffer.from('0000000000000000', 'hex') // Cliend GUID
|
Buffer.from('0000000000000000', 'hex') // Cliend GUID
|
||||||
];
|
];
|
||||||
|
@ -19,17 +19,26 @@ class MinecraftBedrock extends Core {
|
||||||
|
|
||||||
const messageId = reader.uint(1);
|
const messageId = reader.uint(1);
|
||||||
if (messageId !== 0x1c) {
|
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
|
const nonce = reader.part(8).toString('hex'); // should match the nonce we sent
|
||||||
this.logger.debug('Nonce: ' + nonce);
|
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
|
// These 8 bytes are identical to the serverId string we receive in decimal below
|
||||||
reader.skip(8);
|
reader.skip(8);
|
||||||
|
|
||||||
const magic = reader.part(16).toString('hex');
|
const magic = reader.part(16).toString('hex');
|
||||||
this.logger.debug('Magic value: ' + magic);
|
this.logger.debug('Magic value: ' + magic);
|
||||||
|
if (magic !== '00ffff00fefefefefdfdfdfd12345678') {
|
||||||
|
this.logger.debug('Skipping packet, invalid magic');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const statusLen = reader.uint(2);
|
const statusLen = reader.uint(2);
|
||||||
if (reader.remaining() !== statusLen) {
|
if (reader.remaining() !== statusLen) {
|
||||||
|
@ -40,23 +49,22 @@ class MinecraftBedrock extends Core {
|
||||||
this.logger.debug('Raw status str: ' + statusStr);
|
this.logger.debug('Raw status str: ' + statusStr);
|
||||||
|
|
||||||
const split = statusStr.split(';');
|
const split = statusStr.split(';');
|
||||||
if (split.length < 12) {
|
if (split.length < 6) {
|
||||||
throw new Error('Missing enough chunks in status str');
|
throw new Error('Missing enough chunks in status str');
|
||||||
}
|
}
|
||||||
|
|
||||||
let i = 0;
|
state.raw.edition = split.shift();
|
||||||
state.raw.edition = split[i++];
|
state.name = split.shift();
|
||||||
state.name = split[i++];
|
state.raw.protocolVersion = split.shift();
|
||||||
state.raw.protocolVersion = split[i++];
|
state.raw.mcVersion = split.shift();
|
||||||
state.raw.mcVersion = split[i++];
|
state.players = parseInt(split.shift());
|
||||||
state.players = parseInt(split[i++]);
|
state.maxplayers = parseInt(split.shift());
|
||||||
state.maxplayers = parseInt(split[i++]);
|
if (split.length) state.raw.serverId = split.shift();
|
||||||
state.raw.serverId = split[i++];
|
if (split.length) state.map = split.shift();
|
||||||
state.map = split[i++];
|
if (split.length) state.raw.gameMode = split.shift();
|
||||||
state.raw.gameMode = split[i++];
|
if (split.length) state.raw.nintendoOnly = !!parseInt(split.shift());
|
||||||
state.raw.nintendoOnly = !!parseInt(split[i++]);
|
if (split.length) state.raw.ipv4Port = split.shift();
|
||||||
state.raw.ipv4Port = split[i++];
|
if (split.length) state.raw.ipv6Port = split.shift();
|
||||||
state.raw.ipv6Port = split[i++];
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue