Skip to content

Commit

Permalink
server / sesison fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bra1n committed Dec 24, 2020
1 parent f843e3d commit 0090b33
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release Notes

## Version 2.0.4
- fix bug with live sessions that contain travelers from a different set
- fix server channel cleanup

---

## Version 2.0.3
- load roles that belong to different editions (like travelers) from gamestate
- close session when missing custom roles and open edition modal
Expand Down
23 changes: 15 additions & 8 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,6 @@ wss.on("connection", function connection(ws, req) {
// start ping pong
ws.ping(noop);
ws.on("pong", heartbeat);
// remove client from channels on close
ws.on("close", () => {
const index = channels[ws.channel].indexOf(ws);
if (index >= 0) {
channels[ws.channel].splice(index, 1);
}
if (!channels[ws.channel].length) delete channels[ws.channel];
});
// handle message
ws.on("message", function incoming(data) {
metrics.messages_incoming.inc();
Expand Down Expand Up @@ -180,6 +172,7 @@ wss.on("connection", function connection(ws, req) {

// start ping interval timer
const interval = setInterval(function ping() {
// ping each client
wss.clients.forEach(function each(ws) {
if (ws.isAlive === false) {
metrics.connection_terminated_timeout.inc();
Expand All @@ -189,6 +182,20 @@ const interval = setInterval(function ping() {
ws.pingStart = new Date().getTime();
ws.ping(noop);
});
// clean up empty channels
for (let channel in channels) {
if (
!channels[channel].length ||
!channels[channel].some(
ws =>
ws &&
(ws.readyState === WebSocket.OPEN ||
ws.readyState === WebSocket.CONNECTING)
)
) {
delete channels[channel];
}
}
}, PING_INTERVAL);

// handle server shutdown
Expand Down
3 changes: 1 addition & 2 deletions src/store/persistence.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ module.exports = store => {
JSON.parse(localStorage.bluffs).forEach((role, index) => {
store.commit("players/setBluff", {
index,
role:
store.state.roles.get(role) || {}
role: store.state.roles.get(role) || {}
});
});
}
Expand Down
16 changes: 10 additions & 6 deletions src/store/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,16 @@ class LiveSession {
});
// roles are special, because of travelers
if (roleId && player.role.id !== roleId) {
const role = this._store.state.roles.get(roleId);
this._store.commit("players/update", {
player,
property: "role",
value: role
});
const role =
this._store.state.roles.get(roleId) ||
this._store.getters.rolesJSONbyId.get(roleId);
if (role) {
this._store.commit("players/update", {
player,
property: "role",
value: role
});
}
} else if (!roleId && player.role.team === "traveler") {
this._store.commit("players/update", {
player,
Expand Down

0 comments on commit 0090b33

Please sign in to comment.