tedztar / mcstatusbot

discrod bot for server status
MIT License
99 stars 93 forks source link

Disallowed Underscores #230

Open nnotwen opened 4 hours ago

nnotwen commented 4 hours ago

Why was underscores on ip address disabled? Is this a technical limitation? I see that it was explicitly set to not allow underscores in this line:

/functions/validateHost.js#L21

function validateAddress(ip) {
    const decoded = unidecode(ip);
    return (
        isIP(decoded) ||
        isFQDN(decoded, {
            allow_underscores: false,
            allow_numeric_tld: true
        })
    );
}

Is the fix not as simple as

- allow_underscores: false,
+ allow_underscores: true,
nnotwen commented 3 hours ago

I dug deeper and maybe this is a limitation of the mcstatus API? I tried plugging in an address with an underscore and it returned an error. If so, is it not possible to use this API instead (for bedrock servers with underscores). It may not give the same info but it does give server information such as Player Count and Server Status (Online/Offline). I haven't tested it's reliability yet but it does accept address with underscore.

api.mcsrvstat.us sample JSON body response (offline server) ```json { "ip": "185.107.XXX.XXX", "port": 99999, "debug": { "ping": false, "query": false, "srv": false, "querymismatch": false, "ipinsrv": false, "cnameinsrv": false, "animatedmotd": false, "cachehit": false, "cachetime": 1729746969, "cacheexpire": 1729747029, "apiversion": 3, "dns": { "a": [ { "name": "xxx_xxx.aternos.me", "type": "A", "class": "IN", "ttl": 5, "rdlength": 0, "rdata": "", "address": "185.107.XXX.XXX" }, { "name": "xxx_xxx.aternos.me", "type": "A", "class": "IN", "ttl": 5, "rdlength": 0, "rdata": "", "address": "185.107.XXX.XXX" }, { "name": "xxx_xxx.aternos.me", "type": "RRSIG", "class": "IN", "ttl": 5, "rdlength": 0, "rdata": "", "typecovered": "A", "algorithm": 13, "labels": 3, "origttl": 5, "sigexp": "20241107000000", "sigincep": "20241017000000", "keytag": 56863, "signname": "aternos.me", "signature": "" } ] }, "error": { "query": "Failed to read from socket." } }, "hostname": "xxx_xxx.aternos.me", "online": false } ```
api.mcsrvstat.us sample JSON body response (online server) ```json { "ip": "89.116.234.165", "port": 19132, "debug": { "ping": false, "query": true, "srv": false, "querymismatch": false, "ipinsrv": false, "cnameinsrv": false, "animatedmotd": false, "cachehit": false, "cachetime": 1729747895, "cacheexpire": 1729747955, "apiversion": 3 }, "motd": { "raw": [ "§r§fplay.§r§c§lLIFESTEAL§r§f§lMC§r§f.net | §r§cdiscord.gg/lsmc§r" ], "clean": [ "play.LIFESTEALMC.net | discord.gg/lsmc" ], "html": [ "play.LIFESTEALMC.net | discord.gg/lsmc" ] }, "players": { "online": 7, "max": 1000 }, "version": "1.21.30", "online": true, "protocol": { "version": 729, "name": "1.21.30" }, "software": "Geyser", "gamemode": "Survival", "serverid": "8436967703580594055" } ```