From 1646bbbe3bfea2b022f17598753a60704ce549e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Mon, 26 Apr 2021 17:29:57 +0200 Subject: [PATCH] Don't send a package id for commands as it's not needed --- CHANGELOG.md | 1 + src/socketlib.js | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f63b9f..af133eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## In development ### New features - The `this` value of functions now contains the id of the user that triggered the function execution. +- Some network packets are now more efficient. ### Bugfixes - When an invalid user id is specified socketlib will now throw the correct error message. diff --git a/src/socketlib.js b/src/socketlib.js index 4598f05..d095df4 100644 --- a/src/socketlib.js +++ b/src/socketlib.js @@ -168,7 +168,6 @@ class SocketlibSocket { _sendCommand(handlerName, args, recipient) { const message = {handlerName, args, recipient}; - message.id = randomID(); message.type = MESSAGE_TYPES.COMMAND; game.socket.emit(this.socketName, message); } @@ -241,7 +240,7 @@ class SocketlibSocket { [name, func] = this._resolveFunction(handlerName); } catch (e) { - if (e instanceof errors.SocketlibUnregisteredHandlerError) { + if (e instanceof errors.SocketlibUnregisteredHandlerError && type === MESSAGE_TYPES.REQUEST) { this._sendError(id, MESSAGE_TYPES.UNREGISTERED); } throw e; @@ -258,7 +257,6 @@ class SocketlibSocket { } catch (e) { console.error(`An exception occured while executing handler '${name}'.`); - this._sendError(id, MESSAGE_TYPES.EXCEPTION); throw e; } this._sendResult(id, result);