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
return if @deleted
#log.info 'room-delete', this.name, Room.all.length
@watcher_buffers = []
@players = []
@watcher.end() if @watcher
@deleted = true
index = _.indexOf(Room.all, this)
#Room.all[index] = null unless index == -1
Room.all.splice(index, 1) unless index == -1
@deleted = true
return
connect: (client)->
......@@ -144,13 +146,16 @@ class Room
ygopro.stoc_send_chat_to_room this, "#{client.name} #{'退出了观战'}#{if error then ": #{error}" else ''}"
index = _.indexOf(@watchers, client)
@watchers.splice(index, 1) unless index == -1
client.room = null
else
index = _.indexOf(@players, client)
@players.splice(index, 1) unless index == -1
if @players.length
ygopro.stoc_send_chat_to_room this, "#{client.name} #{'离开了游戏'}#{if error then ": #{error}" else ''}"
client.room = null
else
@process.kill()
client.room = null
this.delete()
return
......
......@@ -154,11 +154,15 @@
return;
}
this.watcher_buffers = [];
this.players = [];
if (this.watcher) {
this.watcher.end();
}
this.deleted = true;
index = _.indexOf(Room.all, this);
if (index !== -1) {
Room.all.splice(index, 1);
}
this.deleted = true;
};
Room.prototype.connect = function(client) {
......@@ -185,6 +189,7 @@
if (index !== -1) {
this.watchers.splice(index, 1);
}
client.room = null;
} else {
index = _.indexOf(this.players, client);
if (index !== -1) {
......@@ -192,8 +197,10 @@
}
if (this.players.length) {
ygopro.stoc_send_chat_to_room(this, client.name + " " + '离开了游戏' + (error ? ": " + error : ''));
client.room = null;
} else {
this.process.kill();
client.room = null;
this["delete"]();
}
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -110,6 +110,9 @@ for name, declaration of structs_declaration
#util
@stoc_send_chat = (client, msg, player = 8)->
if !client
console.log "err stoc_send_chat"
return
for line in _.lines(msg)
@stoc_send client, 'CHAT', {
player: player
......@@ -118,6 +121,9 @@ for name, declaration of structs_declaration
return
@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
@stoc_send_chat(client, msg, player) if client
for client in room.watchers
......
......@@ -171,6 +171,10 @@
if (player == null) {
player = 8;
}
if (!client) {
console.log("err stoc_send_chat");
return;
}
ref = _.lines(msg);
for (j = 0, len1 = ref.length; j < len1; j++) {
line = ref[j];
......@@ -186,6 +190,10 @@
if (player == null) {
player = 8;
}
if (!room) {
console.log("err stoc_send_chat_to_room");
return;
}
ref = room.players;
for (j = 0, len1 = ref.length; j < len1; 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