How to use the minecraft-data.postNettyVersionsByProtocolVersion function in minecraft-data

To help you get started, we’ve selected a few minecraft-data examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PrismarineJS / node-minecraft-protocol / src / client / autoVersion.js View on Github external
// TODO: could also use ping pre-connect to save description, type, max players, etc.
    const motd = response.description
    debug('Server description:', motd) // TODO: save

    // Pass server-reported version to protocol handler
    // The version string is interpreted by https://github.com/PrismarineJS/node-minecraft-data
    const brandedMinecraftVersion = response.version.name // 1.8.9, 1.7.10
    const protocolVersion = response.version.protocol//    47,      5
    const versions = [brandedMinecraftVersion]
      .concat(brandedMinecraftVersion.match(/((\d+\.)+\d+)/g) || [])
      .map(function (version) {
        return minecraftData.versionsByMinecraftVersion.pc[version]
      })
      .filter(function (info) { return info })
      .sort(function (a, b) { return b.version - a.version })
      .concat(minecraftData.postNettyVersionsByProtocolVersion.pc[protocolVersion] || [])
    if (versions.length === 0) {
      client.emit('error', new Error(`unsupported/unknown protocol version: ${protocolVersion}, update minecraft-data`))
    }
    const minecraftVersion = versions[0].minecraftVersion

    debug(`Server version: ${minecraftVersion}, protocol: ${protocolVersion}`)

    options.version = minecraftVersion
    options.protocolVersion = protocolVersion

    // Reinitialize client object with new version TODO: move out of its constructor?
    client.version = minecraftVersion
    client.state = states.HANDSHAKING

    // Let other plugins such as Forge/FML (modinfo) respond to the ping response
    if (client.autoVersionHooks) {
github PrismarineJS / node-minecraft-protocol / src / client / autoVersion.js View on Github external
debug('ping response',response);
    // TODO: could also use ping pre-connect to save description, type, max players, etc.
    const motd = response.description;
    debug('Server description:',motd); // TODO: save

    // Pass server-reported version to protocol handler
    // The version string is interpereted by https://github.com/PrismarineJS/node-minecraft-data
    const minecraftVersion = response.version.name;        // 1.8.9, 1.7.10
    const protocolVersion = response.version.protocol;//    47,      5

    debug(`Server version: ${minecraftVersion}, protocol: ${protocolVersion}`);
    // Note that versionName is a descriptive version stirng like '1.8.9' on vailla, but other
    // servers add their own name (Spigot 1.8.8, Glowstone++ 1.8.9) so we cannot use it directly,
    // even though it is in a format accepted by minecraft-data. Instead, translate the protocol.
    // TODO: pre-Netty version support (uses overlapping version numbers, so would have to check versionName)
    const versionInfos = minecraft_data.postNettyVersionsByProtocolVersion[protocolVersion];
    if (!versionInfos && versionInfos.length < 1) throw new Error(`unsupported/unknown protocol version: ${protocolVersion}, update minecraft-data`);
    const versionInfo = versionInfos[0]; // use newest
    options.version = versionInfo.minecraftVersion;
    options.protocolVersion = protocolVersion;

    // Reinitialize client object with new version TODO: move out of its constructor?
    client.version = versionInfo.majorVersion;
    client.state = states.HANDSHAKING;

    if (response.modinfo && response.modinfo.type === 'FML') {
      // Use the list of Forge mods from the server ping, so client will match server
      const forgeMods = response.modinfo.modList;
      debug('Using forgeMods:',forgeMods);
      options.forgeMods = forgeMods;
      forgeHandshake(client, options);
    }