Skip to content

Commit

Permalink
when players disconnect from websocket, they leave the game on all th…
Browse files Browse the repository at this point in the history
…e other client's browsers
  • Loading branch information
Micah Lee, micahflee & Ted Young, tedsuo committed Aug 29, 2010
1 parent c65a090 commit bdd62a7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion client/js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ var Game = function() {
self.player_id = message.id;
} else if(message.event=='bullet'){
self.create_bullet({position:message.bullet.position,owner_id: message.id, direction: message.bullet.direction});
}else {
} else if(message.event == 'die') {
console.log('avatar '+message.id+' got a die event');
delete self.avatars[message.id];
} else {
message.game = self;
if(self.avatars[message.id]) {
self.avatars[message.id].position = message.position;
Expand Down
7 changes: 6 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ socket.on( 'clientConnect', function(client){
});

socket.on('clientMessage', function( msg, client){
sys.puts(sys.inspect(msg));
// sys.puts(sys.inspect(msg));
client.broadcast(msg);
});

socket.on('clientDisconnect', function(client){
sys.puts('client diconnected: '+client.sessionId);
client.broadcast(JSON.stringify({event:'die',id:client.sessionId}));
});

0 comments on commit bdd62a7

Please sign in to comment.