diff --git a/HISTORY.md b/HISTORY.md index 2657248..dd5ab1d 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,9 @@ # History +## 1.1.4 (UNRELEASED) + +* Added a errorHandler option to createServer. + ## 1.1.3 * requires node 6 diff --git a/doc/README.md b/doc/README.md index bb0aefe..b650d44 100644 --- a/doc/README.md +++ b/doc/README.md @@ -19,6 +19,8 @@ automatically logged in and validated against mojang's auth. * keepAlive : send keep alive packets : default to true * version : 1.8 or 1.9 : default to 1.8 * customPackets (optional) : an object index by version/state/direction/name, see client_custom_packet for an example + * errorHandler : A way to override the default error handler for client errors. A function that takes a Client and an error. + The default kicks the client. ## mc.Server(version,[customPackets]) diff --git a/src/createServer.js b/src/createServer.js index 70f7f35..930de40 100644 --- a/src/createServer.js +++ b/src/createServer.js @@ -19,6 +19,9 @@ function createServer(options) { options['server-port'] != null ? options['server-port'] : 25565; + const clientErrorHandler = options.errorHandler || function(client, err) { + client.end(); + }; const host = options.host || '0.0.0.0'; const kickTimeout = options.kickTimeout || 30 * 1000; const checkTimeoutInterval = options.checkTimeoutInterval || 4 * 1000; @@ -47,6 +50,9 @@ function createServer(options) { client.once('login_start', onLogin); client.once('ping_start', onPing); client.once('legacy_server_list_ping', onLegacyPing); + client.on('error', function(err) { + clientErrorHandler(client, err); + }); client.on('end', onEnd); let keepAlive = false;