mirror of https://github.com/bra1n/townsquare.git
server / sesison fixes
This commit is contained in:
parent
f843e3d439
commit
0090b33e94
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
|
|
@ -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) || {}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue