Merge pull request #134 from bra1n/133_fix_race_condition_bug_setting_pronouns

updated the send and update sockets methods for player pronouns to pa…
This commit is contained in:
Steffen 2021-03-19 19:55:41 +01:00 committed by GitHub
commit 6a8f5608a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 17 deletions

View File

@ -1,5 +1,9 @@
# Release Notes # 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 ### Version 2.9.1
- added [nomination log indicator](https://fontawesome.com/icons/book-dead). When a nomination log [v] is available, the number of currently visible entries is displayed. Clicking the indicator can reveal/hide the nomination log. - added [nomination log indicator](https://fontawesome.com/icons/book-dead). When a nomination log [v] is available, the number of currently visible entries is displayed. Clicking the indicator can reveal/hide the nomination log.
- fix gamestate JSON not showing (custom) roles and failing to load states with custom scripts properly - fix gamestate JSON not showing (custom) roles and failing to load states with custom scripts properly

View File

@ -102,6 +102,14 @@ const mutations = {
set(state, players = []) { set(state, players = []) {
state.players = 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 }) { update(state, { player, property, value }) {
const index = state.players.indexOf(player); const index = state.players.indexOf(player);
if (index >= 0) { if (index >= 0) {

View File

@ -489,36 +489,36 @@ class LiveSession {
* Publish a player pronouns update * Publish a player pronouns update
* @param player * @param player
* @param value * @param value
* @param isFromSockets
*/ */
sendPlayerPronouns({ player, value }) { sendPlayerPronouns({ player, value, isFromSockets }) {
//send pronoun only for the seated player or storyteller //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 (
isFromSockets ||
(this._isSpectator && this._store.state.session.playerId !== player.id)
)
return; return;
const index = this._store.state.players.players.indexOf(player); 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 index
* @param value * @param value
* @param fromSt
* @private * @private
*/ */
_updatePlayerPronouns([index, value, fromST]) { _updatePlayerPronouns([index, value]) {
const player = this._store.state.players.players[index]; 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", { this._store.commit("players/update", {
player, player,
property: "pronouns", property: "pronouns",
value value,
isFromSockets: true
}); });
} }
}
/** /**
* Handle a ping message by another player / storyteller * Handle a ping message by another player / storyteller