From 6ad1df5a35287f80e540033352c733ede484c38a Mon Sep 17 00:00:00 2001 From: Dave Date: Tue, 16 Mar 2021 15:14:51 +0000 Subject: [PATCH 1/4] updated the send and update sockets methods for player pronouns to pass through a flag when the pronoun is updated from the sockets to stop the update being broadcast again and causing infinite loops of sockets messages being sent. This also simplifys from the previous loop prevention functionality. --- src/store/socket.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/store/socket.js b/src/store/socket.js index a69ab24..3f9adbb 100644 --- a/src/store/socket.js +++ b/src/store/socket.js @@ -489,35 +489,35 @@ class LiveSession { * Publish a player pronouns update * @param player * @param value + * @param fromSockets */ - sendPlayerPronouns({ player, value }) { + sendPlayerPronouns({ player, value, fromSockets }) { //send pronoun only for the seated player or storyteller - if (this._isSpectator && this._store.state.session.playerId !== player.id) + //Do not re-send pronoun data for an update that was recieved from the sockets layer + if ( + fromSockets || + (this._isSpectator && this._store.state.session.playerId !== player.id) + ) return; const index = this._store.state.players.players.indexOf(player); - this._send("pronouns", [index, value, !this._isSpectator]); + this._send("pronouns", [index, value]); } /** - * Update a pronouns based on incoming data. Player only. + * Update a pronouns based on incoming data. * @param index * @param value - * @param fromSt * @private */ - _updatePlayerPronouns([index, value, fromST]) { + _updatePlayerPronouns([index, value]) { const player = this._store.state.players.players[index]; - if ( - player && - (fromST || this._store.state.session.playerId !== player.id) && - player.pronouns !== value - ) { - this._store.commit("players/update", { - player, - property: "pronouns", - value - }); - } + + this._store.commit("players/update", { + player, + property: "pronouns", + value, + fromSockets: true + }); } /** From 8b4f09a2c45e473359be75c9950b39cfcca07a9f Mon Sep 17 00:00:00 2001 From: Dave Date: Tue, 16 Mar 2021 19:46:52 +0000 Subject: [PATCH 2/4] correcting fromSockets property to be isFromSockets --- src/store/socket.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/store/socket.js b/src/store/socket.js index 3f9adbb..326bb8d 100644 --- a/src/store/socket.js +++ b/src/store/socket.js @@ -489,13 +489,13 @@ class LiveSession { * Publish a player pronouns update * @param player * @param value - * @param fromSockets + * @param isFromSockets */ - sendPlayerPronouns({ player, value, fromSockets }) { + sendPlayerPronouns({ player, value, isFromSockets }) { //send pronoun only for the seated player or storyteller //Do not re-send pronoun data for an update that was recieved from the sockets layer if ( - fromSockets || + isFromSockets || (this._isSpectator && this._store.state.session.playerId !== player.id) ) return; @@ -516,7 +516,7 @@ class LiveSession { player, property: "pronouns", value, - fromSockets: true + isFromSockets: true }); } From dedf0be0b9b54fe25d755323e967714194a09a20 Mon Sep 17 00:00:00 2001 From: Dave Date: Tue, 16 Mar 2021 19:47:42 +0000 Subject: [PATCH 3/4] adding documentation comment to explain new isFromSockets property --- src/store/modules/players.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/store/modules/players.js b/src/store/modules/players.js index 30d4d2b..9a7ab0f 100644 --- a/src/store/modules/players.js +++ b/src/store/modules/players.js @@ -102,6 +102,14 @@ const mutations = { set(state, players = []) { state.players = players; }, + /** + The update mutation also has a property for isFromSockets + this property can be addded to payload object for any mutations + then can be used to prevent infinite loops when a property is + able to be set from multiple different session on websockets. + An example of this is in the sendPlayerPronouns and _updatePlayerPronouns + in socket.js. + */ update(state, { player, property, value }) { const index = state.players.indexOf(player); if (index >= 0) { From d0b2d88344312d1f3b3d571f3cefd01dd421d7e3 Mon Sep 17 00:00:00 2001 From: Dave Date: Tue, 16 Mar 2021 20:41:20 +0000 Subject: [PATCH 4/4] updating changelog.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5b7638..58ece6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes +### Version 2.9.2 +- fix issue where a player and storyteller updating the same players pronouns at around the same time causes an infinite loop disconnecting the session. + +--- ### Version 2.9.1 - fix gamestate JSON not showing (custom) roles and failing to load states with custom scripts properly - fix gamestate not stripping out special characters from role.id on load