Add errorHandler option

This commit is contained in:
roblabla 2017-01-28 23:50:33 +01:00
parent a4db7a10a7
commit 4b99245a80
3 changed files with 12 additions and 0 deletions

View File

@ -1,5 +1,9 @@
# History
## 1.1.2 (UNRELEASED)
* Added a errorHandler option to createServer.
## 1.1.1
* update to yggdrasil 0.2.0

View File

@ -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])

View File

@ -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;