mirror of
				https://github.com/bra1n/townsquare.git
				synced 2025-10-21 16:55:12 +00:00 
			
		
		
		
	server / sesison fixes
This commit is contained in:
		
							parent
							
								
									f843e3d439
								
							
						
					
					
						commit
						0090b33e94
					
				
					 4 changed files with 32 additions and 16 deletions
				
			
		| 
						 | 
					@ -1,5 +1,11 @@
 | 
				
			||||||
# Release Notes
 | 
					# 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
 | 
					## Version 2.0.3
 | 
				
			||||||
- load roles that belong to different editions (like travelers) from gamestate
 | 
					- load roles that belong to different editions (like travelers) from gamestate
 | 
				
			||||||
- close session when missing custom roles and open edition modal
 | 
					- close session when missing custom roles and open edition modal
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -113,14 +113,6 @@ wss.on("connection", function connection(ws, req) {
 | 
				
			||||||
  // start ping pong
 | 
					  // start ping pong
 | 
				
			||||||
  ws.ping(noop);
 | 
					  ws.ping(noop);
 | 
				
			||||||
  ws.on("pong", heartbeat);
 | 
					  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
 | 
					  // handle message
 | 
				
			||||||
  ws.on("message", function incoming(data) {
 | 
					  ws.on("message", function incoming(data) {
 | 
				
			||||||
    metrics.messages_incoming.inc();
 | 
					    metrics.messages_incoming.inc();
 | 
				
			||||||
| 
						 | 
					@ -180,6 +172,7 @@ wss.on("connection", function connection(ws, req) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// start ping interval timer
 | 
					// start ping interval timer
 | 
				
			||||||
const interval = setInterval(function ping() {
 | 
					const interval = setInterval(function ping() {
 | 
				
			||||||
 | 
					  // ping each client
 | 
				
			||||||
  wss.clients.forEach(function each(ws) {
 | 
					  wss.clients.forEach(function each(ws) {
 | 
				
			||||||
    if (ws.isAlive === false) {
 | 
					    if (ws.isAlive === false) {
 | 
				
			||||||
      metrics.connection_terminated_timeout.inc();
 | 
					      metrics.connection_terminated_timeout.inc();
 | 
				
			||||||
| 
						 | 
					@ -189,6 +182,20 @@ const interval = setInterval(function ping() {
 | 
				
			||||||
    ws.pingStart = new Date().getTime();
 | 
					    ws.pingStart = new Date().getTime();
 | 
				
			||||||
    ws.ping(noop);
 | 
					    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);
 | 
					}, PING_INTERVAL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handle server shutdown
 | 
					// handle server shutdown
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,8 +21,7 @@ module.exports = store => {
 | 
				
			||||||
    JSON.parse(localStorage.bluffs).forEach((role, index) => {
 | 
					    JSON.parse(localStorage.bluffs).forEach((role, index) => {
 | 
				
			||||||
      store.commit("players/setBluff", {
 | 
					      store.commit("players/setBluff", {
 | 
				
			||||||
        index,
 | 
					        index,
 | 
				
			||||||
        role:
 | 
					        role: store.state.roles.get(role) || {}
 | 
				
			||||||
          store.state.roles.get(role) || {}
 | 
					 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -287,12 +287,16 @@ class LiveSession {
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
      // roles are special, because of travelers
 | 
					      // roles are special, because of travelers
 | 
				
			||||||
      if (roleId && player.role.id !== roleId) {
 | 
					      if (roleId && player.role.id !== roleId) {
 | 
				
			||||||
        const role = this._store.state.roles.get(roleId);
 | 
					        const role =
 | 
				
			||||||
        this._store.commit("players/update", {
 | 
					          this._store.state.roles.get(roleId) ||
 | 
				
			||||||
          player,
 | 
					          this._store.getters.rolesJSONbyId.get(roleId);
 | 
				
			||||||
          property: "role",
 | 
					        if (role) {
 | 
				
			||||||
          value: role
 | 
					          this._store.commit("players/update", {
 | 
				
			||||||
        });
 | 
					            player,
 | 
				
			||||||
 | 
					            property: "role",
 | 
				
			||||||
 | 
					            value: role
 | 
				
			||||||
 | 
					          });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
      } else if (!roleId && player.role.team === "traveler") {
 | 
					      } else if (!roleId && player.role.team === "traveler") {
 | 
				
			||||||
        this._store.commit("players/update", {
 | 
					        this._store.commit("players/update", {
 | 
				
			||||||
          player,
 | 
					          player,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue