From 787f8d3423a8950b60603c36b6d13f8ea7ffbc04 Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Sat, 7 Nov 2015 22:06:49 +0100 Subject: [PATCH] fix gamemode3 in proxy : fix #146 * correctly generate the same uuidv3 than the vanilla server does in offline mode : fix #282 * remove "one player online mode" in the proxy : it doesn't make sense to identify all players as the user/passwd given in the cli. Now both servers in offline mode. --- examples/proxy/proxy.js | 10 ++-------- package.json | 5 +++-- src/createServer.js | 20 +++++++++++++++++++- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/examples/proxy/proxy.js b/examples/proxy/proxy.js index d5baf4e..38d9a4c 100644 --- a/examples/proxy/proxy.js +++ b/examples/proxy/proxy.js @@ -2,7 +2,7 @@ var mc = require('../../'); var states = mc.states; function printHelpAndExit(exitCode) { - console.log("usage: node proxy.js [...] [] []"); + console.log("usage: node proxy.js [...] []"); console.log("options:"); console.log(" --dump name"); console.log(" print to stdout messages with the specified name."); @@ -35,8 +35,6 @@ process.argv.forEach(function(val, index, array) { var args = process.argv.slice(2); var host; var port = 25565; -var user; -var passwd; var version; var printAllNames = false; @@ -62,8 +60,6 @@ var printNameBlacklist = {}; } if(!(i + 2 <= args.length && args.length <= i + 4)) printHelpAndExit(1); host = args[i++]; - user = args[i++]; - passwd = args[i++]; version = args[i++]; })(); @@ -98,9 +94,7 @@ srv.on('login', function(client) { var targetClient = mc.createClient({ host: host, port: port, - username: user, - password: passwd, - 'online-mode': passwd != null ? true : false, + username: client.username, keepAlive:false, version:version }); diff --git a/package.json b/package.json index f7ae3ae..9cc1583 100644 --- a/package.json +++ b/package.json @@ -46,12 +46,13 @@ "minecraft-data": "^0.13.0", "node-uuid": "~1.4.1", "prismarine-nbt": "0.0.1", + "protodef": "0.2.0", "readable-stream": "^1.1.0", "superagent": "~0.10.0", "ursa-purejs": "0.0.3", "uuid": "^2.0.1", - "yggdrasil": "0.1.0", - "protodef":"0.2.0" + "uuid-1345": "^0.99.6", + "yggdrasil": "0.1.0" }, "optionalDependencies": { "ursa": "~0.9.1" diff --git a/src/createServer.js b/src/createServer.js index 814a1d4..543300a 100644 --- a/src/createServer.js +++ b/src/createServer.js @@ -4,6 +4,7 @@ var yggserver = require('yggdrasil').server({}); var states = require("./states"); var bufferEqual = require('buffer-equal'); var Server = require('./server'); +var UUID = require('uuid-1345'); module.exports=createServer; @@ -194,10 +195,27 @@ function createServer(options) { } } + + // https://github.com/openjdk-mirror/jdk7u-jdk/blob/f4d80957e89a19a29bb9f9807d2a28351ed7f7df/src/share/classes/java/util/UUID.java#L163 + function javaUUID(s) + { + var hash = crypto.createHash("md5"); + hash.update(s, 'utf8'); + var buffer = hash.digest(); + buffer[6] = (buffer[6] & 0x0f) | 0x30; + buffer[8] = (buffer[8] & 0x3f) | 0x80; + return buffer; + } + + function nameToMcOfflineUUID(name) + { + return (new UUID(javaUUID("OfflinePlayer:"+name))).toString(); + } + function loginClient() { var isException = !!server.onlineModeExceptions[client.username.toLowerCase()]; if(onlineMode == false || isException) { - client.uuid = "0-0-0-0-0"; + client.uuid = nameToMcOfflineUUID(client.username); } client.write('compress', { threshold: 256 }); // Default threshold is 256 client.compressionThreshold = 256;