—
First, when a player connects, server must give him his unique number, or a client must notify server what is his number, and store that number on server somehow (you can make your own list of numbers, or use a socket.id number or you can use constructs sprite ID, or etc. but clients and server must know what that number is).
So, when connects, client can do something like:
On connect
Socket send message ("PLAYER, MYID") // in this case client notifys server what his number is
Depending on what kind of arhitecture you want, you must code this part yourself, you can do something like this maybe (code is a mess, just for a general idea)
myNumber = 0;
var Me = [];
io.sockets.on("connection", function (socket) {
socket.on("message", function (data) {
var new_data = data.split(',');
if (new_data[0] == 'PLAYER') {
var myNumber = count++;
Me[0]='player'
Me[1]=new_data[1];
}
socket.on('disconnect', function (data) {
socket.broadcast.emit("message",'D,'+ Me[1]);
//remove player from the list here somehow; Me[1]=null
}
So, when a player disconnects, you can notify all connected games that a specific player is (D)ead, and what is his ID, so that client can:
On Message "D"
Pick instance(ID)
Destroy
sorry for the messy post, i'm in a hurry but that's how i'd do it. There is probably much more smarter way for this.