Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Restored left-game flag

  • Loading branch information...
commit cab1fdf2f19403c5b9016d26ded68b2f7de05b82 1 parent ffdbb04
@tracend tracend authored
Showing with 22 additions and 4 deletions.
  1. +14 −3 lib/game.js
  2. +8 −1 public/assets/js/logic/game.js
View
17 lib/game.js
@@ -387,10 +387,19 @@ function createDummies(){
}
function deletePlayer( id ){
+ var player = players[id];
var socket = io.sockets.sockets[id];
- socket.leave('arena');
- socket.leave('lobby');
- delete players[id];
+ if( typeof( socket ) != "undefined" ){
+ socket.leave('arena');
+ socket.leave('lobby');
+ }
+ if( typeof( player ) != "undefined" ){
+ // delete player from list locally
+ delete players[id];
+ // broadcast to all the users
+ io.sockets.emit("left-game", player.name);
+ }
+
}
// A basic time tracking function set to 0.5sec updates
@@ -446,6 +455,8 @@ function time(){
}
+// Helpers
+
function objLength( obj ){
var length=0;
for( el in obj ) length++;
View
9 public/assets/js/logic/game.js
@@ -46,7 +46,14 @@ return {
lobby.hide();
});
-
+ socket.on('left-game', function( name) {
+ console.log("Left: " + name);
+ // remove user from lobby
+ lobby.remove( name );
+ // remove user from arena
+ invaders.remove( name );
+ });
+
},
render : function( root ) {
Please sign in to comment.
Something went wrong with that request. Please try again.