Commit bba69ea7 authored by mercury233's avatar mercury233

memory leak test4, synchronous ctos_follow, hide password, add http stop server

parent 5df13214
...@@ -122,10 +122,12 @@ class Room ...@@ -122,10 +122,12 @@ class Room
return if @deleted return if @deleted
#log.info 'room-delete', this.name, Room.all.length #log.info 'room-delete', this.name, Room.all.length
@watcher_buffers = [] @watcher_buffers = []
@players = []
@watcher.end() if @watcher
@deleted = true
index = _.indexOf(Room.all, this) index = _.indexOf(Room.all, this)
#Room.all[index] = null unless index == -1 #Room.all[index] = null unless index == -1
Room.all.splice(index, 1) unless index == -1 Room.all.splice(index, 1) unless index == -1
@deleted = true
return return
connect: (client)-> connect: (client)->
...@@ -144,13 +146,16 @@ class Room ...@@ -144,13 +146,16 @@ class Room
ygopro.stoc_send_chat_to_room this, "#{client.name} #{'退出了观战'}#{if error then ": #{error}" else ''}" ygopro.stoc_send_chat_to_room this, "#{client.name} #{'退出了观战'}#{if error then ": #{error}" else ''}"
index = _.indexOf(@watchers, client) index = _.indexOf(@watchers, client)
@watchers.splice(index, 1) unless index == -1 @watchers.splice(index, 1) unless index == -1
client.room = null
else else
index = _.indexOf(@players, client) index = _.indexOf(@players, client)
@players.splice(index, 1) unless index == -1 @players.splice(index, 1) unless index == -1
if @players.length if @players.length
ygopro.stoc_send_chat_to_room this, "#{client.name} #{'离开了游戏'}#{if error then ": #{error}" else ''}" ygopro.stoc_send_chat_to_room this, "#{client.name} #{'离开了游戏'}#{if error then ": #{error}" else ''}"
client.room = null
else else
@process.kill() @process.kill()
client.room = null
this.delete() this.delete()
return return
......
...@@ -154,11 +154,15 @@ ...@@ -154,11 +154,15 @@
return; return;
} }
this.watcher_buffers = []; this.watcher_buffers = [];
this.players = [];
if (this.watcher) {
this.watcher.end();
}
this.deleted = true;
index = _.indexOf(Room.all, this); index = _.indexOf(Room.all, this);
if (index !== -1) { if (index !== -1) {
Room.all.splice(index, 1); Room.all.splice(index, 1);
} }
this.deleted = true;
}; };
Room.prototype.connect = function(client) { Room.prototype.connect = function(client) {
...@@ -185,6 +189,7 @@ ...@@ -185,6 +189,7 @@
if (index !== -1) { if (index !== -1) {
this.watchers.splice(index, 1); this.watchers.splice(index, 1);
} }
client.room = null;
} else { } else {
index = _.indexOf(this.players, client); index = _.indexOf(this.players, client);
if (index !== -1) { if (index !== -1) {
...@@ -192,8 +197,10 @@ ...@@ -192,8 +197,10 @@
} }
if (this.players.length) { if (this.players.length) {
ygopro.stoc_send_chat_to_room(this, client.name + " " + '离开了游戏' + (error ? ": " + error : '')); ygopro.stoc_send_chat_to_room(this, client.name + " " + '离开了游戏' + (error ? ": " + error : ''));
client.room = null;
} else { } else {
this.process.kill(); this.process.kill();
client.room = null;
this["delete"](); this["delete"]();
} }
} }
......
This diff is collapsed.
This diff is collapsed.
...@@ -110,6 +110,9 @@ for name, declaration of structs_declaration ...@@ -110,6 +110,9 @@ for name, declaration of structs_declaration
#util #util
@stoc_send_chat = (client, msg, player = 8)-> @stoc_send_chat = (client, msg, player = 8)->
if !client
console.log "err stoc_send_chat"
return
for line in _.lines(msg) for line in _.lines(msg)
@stoc_send client, 'CHAT', { @stoc_send client, 'CHAT', {
player: player player: player
...@@ -118,6 +121,9 @@ for name, declaration of structs_declaration ...@@ -118,6 +121,9 @@ for name, declaration of structs_declaration
return return
@stoc_send_chat_to_room = (room, msg, player = 8)-> @stoc_send_chat_to_room = (room, msg, player = 8)->
if !room
console.log "err stoc_send_chat_to_room"
return
for client in room.players for client in room.players
@stoc_send_chat(client, msg, player) if client @stoc_send_chat(client, msg, player) if client
for client in room.watchers for client in room.watchers
......
...@@ -171,6 +171,10 @@ ...@@ -171,6 +171,10 @@
if (player == null) { if (player == null) {
player = 8; player = 8;
} }
if (!client) {
console.log("err stoc_send_chat");
return;
}
ref = _.lines(msg); ref = _.lines(msg);
for (j = 0, len1 = ref.length; j < len1; j++) { for (j = 0, len1 = ref.length; j < len1; j++) {
line = ref[j]; line = ref[j];
...@@ -186,6 +190,10 @@ ...@@ -186,6 +190,10 @@
if (player == null) { if (player == null) {
player = 8; player = 8;
} }
if (!room) {
console.log("err stoc_send_chat_to_room");
return;
}
ref = room.players; ref = room.players;
for (j = 0, len1 = ref.length; j < len1; j++) { for (j = 0, len1 = ref.length; j < len1; j++) {
client = ref[j]; client = ref[j];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment