PassTheMayo / minecraft-server-util

A Node.js library for Minecraft servers that can retrieve status, query, RCON, and send Votifier votes.
https://passthemayo.gitbook.io/minecraft-server-util/
MIT License
141 stars 24 forks source link

bug: Some bedrock servers come back as offline / hit the default timeout of 5 seconds even when they are online. #67

Closed mve closed 2 years ago

mve commented 2 years ago

Using statusBedrock to get the status for some bedrock servers i noticed many of them were offline. When checking with a different api i found that they were online.

Some example servers that are currently online but hit the default timeout of 5 seconds when using statusBedrock. Increasing the timeout to 10 seconds didn't make a difference.

Error: Timed out while retrieving server status
          at Timeout._a [as _onTimeout] (/Users/mve/code/mc-pinger-serverless/node_modules/minecraft-server-util/dist/statusBedrock.js:42:20)
          at listOnTimeout (node:internal/timers:568:17)
          at processTimers (node:internal/timers:510:7),
      request: [Object]

"host": "bedrock.punchedmc.com", "port": 19132,

"host": "OwnagePE.com", "port": 19132,

"host": "play.hyperlandsmc.net", "port": 19132,

"host": "play.venitymc.com", "port": 19132,

Describe the bug: It is just a regular request to a bedrock server using statusBedrock. It will run for 5 seconds (or whatever the timeout is set to).

Expected behavior: The servers should return the result for an online server.

Additional context Node version 17.3.0 minecraft-server-util version 5.2.7

fabianwennink commented 2 years ago

After playing around with the code a bit, I solved the issue by changing the following part in the statusBedrock.ts file:

// Unconnected ping packet
// https://wiki.vg/Raknet_Protocol#Unconnected_Ping
{
    socket.writeByte(0x01);
    socket.writeInt64BE(BigInt(Date.now()));
    socket.writeBytes(Uint8Array.from([0x00, 0xff, 0xff, 0x00, 0xfe, 0xfe, 0xfe, 0xfe, 0xfd, 0xfd, 0xfd, 0xfd, 0x12, 0x34, 0x56, 0x78]));
    socket.writeBytes(randomBytes(4));
    await socket.flush(false);
}

to

// Unconnected ping packet
// https://wiki.vg/Raknet_Protocol#Unconnected_Ping
{
    socket.writeByte(0x01);
    socket.writeInt64BE(BigInt(Date.now()));
    socket.writeBytes(Uint8Array.from([0x00, 0xff, 0xff, 0x00, 0xfe, 0xfe, 0xfe, 0xfe, 0xfd, 0xfd, 0xfd, 0xfd, 0x12, 0x34, 0x56, 0x78]));
    socket.writeInt64BE(BigInt(2));
    await socket.flush(false);
}

See https://github.com/xPaw/PHP-Minecraft-Query/blob/master/src/MinecraftQuery.php#L208

PassTheMayo commented 2 years ago

This issue seems to be fixed in #69 thanks to @fabianwennink. I will go ahead and release 5.2.8 here in a few minutes which will solve this.