Execute functions locally if the current user is explicitly set as a recipient
This commit is contained in:
@@ -1,3 +1,8 @@
|
|||||||
|
## In development
|
||||||
|
### Bugfixes
|
||||||
|
- `ExecuteAsUser` and `ExecuteForUsers` didn't execute locally if the id of the current user was passed in as recipient.
|
||||||
|
|
||||||
|
|
||||||
## 1.0.1
|
## 1.0.1
|
||||||
### New features
|
### New features
|
||||||
- Added support for game systems
|
- Added support for game systems
|
||||||
|
|||||||
@@ -96,6 +96,8 @@ class SocketlibSocket {
|
|||||||
|
|
||||||
async executeAsUser(handler, userId, ...args) {
|
async executeAsUser(handler, userId, ...args) {
|
||||||
const [name, func] = this._resolveFunction(handler);
|
const [name, func] = this._resolveFunction(handler);
|
||||||
|
if (userId === game.userId)
|
||||||
|
return func(...args);
|
||||||
const user = game.users.get(userId);
|
const user = game.users.get(userId);
|
||||||
if (!user)
|
if (!user)
|
||||||
throw new SocketlibInvalidUserError(`No user with id '${userId}' exists.`);
|
throw new SocketlibInvalidUserError(`No user with id '${userId}' exists.`);
|
||||||
@@ -118,7 +120,13 @@ class SocketlibSocket {
|
|||||||
if (!(recipients instanceof Array))
|
if (!(recipients instanceof Array))
|
||||||
throw new TypeError("Recipients parameter must be an array of user ids.");
|
throw new TypeError("Recipients parameter must be an array of user ids.");
|
||||||
const [name, func] = this._resolveFunction(handler);
|
const [name, func] = this._resolveFunction(handler);
|
||||||
|
const currentUserIndex = recipients.indexOf(game.userId);
|
||||||
|
if (currentUserIndex >= 0)
|
||||||
|
recipients.splice(currentUserIndex, 1);
|
||||||
this._sendCommand(name, args, recipients);
|
this._sendCommand(name, args, recipients);
|
||||||
|
if (currentUserIndex >= 0)
|
||||||
|
// TODO Make this function call run async, even if the function isn't delcared as async to prevent exceptions to propagate through executeForUsers
|
||||||
|
func(...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
_sendRequest(handlerName, args, recipient) {
|
_sendRequest(handlerName, args, recipient) {
|
||||||
|
|||||||
Reference in New Issue
Block a user