Commit 85a01308 authored by 神楽坂玲奈's avatar 神楽坂玲奈

class Room

parent 06e55585
{
"name": "ygopro-server",
"version": "2.0.0",
"description": "a server for ygopro",
"repository": {
"type": "git",
"url": "https://github.com/mycard/ygopro-server.git"
},
"keywords": [
"mycard",
"ygopro",
"server"
],
"author": "zh99998 <zh99998@gmail.com>",
"dependencies": {
"underscore": "*",
"freeport": "*",
"struct": "*",
"inotify": "*"
},
"license": "GPLv3",
"main": "ygopro-server.js",
"scripts": {
"start": "forever start mycard-server-match.js",
"build": "coffee -c mycard-server-match.coffee"
},
"engines": {
"node": "*"
}
}
\ No newline at end of file
This diff is collapsed.
#官方库
net = require 'net' net = require 'net'
http = require 'http' http = require 'http'
url = require 'url' url = require 'url'
path = require 'path'
fs = require 'fs'
spawn = require('child_process').spawn spawn = require('child_process').spawn
#三方库
freeport = require 'freeport' freeport = require 'freeport'
Struct = require('struct').Struct Struct = require('struct').Struct
_ = require 'underscore' _ = require 'underscore'
Inotify = require('inotify').Inotify
#常量/类型声明
structs_declaration = require './structs.json' #结构体声明 structs_declaration = require './structs.json' #结构体声明
typedefs = require './typedefs.json' #类型声明 typedefs = require './typedefs.json' #类型声明
proto_structs = require './proto_structs.json' #消息与结构体的对应,未完成,对着duelclient.cpp加 proto_structs = require './proto_structs.json' #消息与结构体的对应,未完成,对着duelclient.cpp加
constants = require './constants.json' #network.h里定义的常量 constants = require './constants.json' #network.h里定义的常量
#配置文件
settings = require './config.json' #本机IP端口设置 settings = require './config.json' #本机IP端口设置
class Room
@all = []
#name
#port
#players: [{client, server, name, pos}]
#process
#established
#alive
constructor: (name, port, client) ->
@name = name
@port = port
@alive = true
@players = []
@add_client(client)
Room.all.push this #这个故事告诉我们没事不要乱new Room
delete: (room)->
delete Room.all[_.indexOf(Room.all, room)]
add_client: (client)->
@players.push {client: client, name: client.player}
#需要性能优化,建立个索引
@find_by_name: (name)->
_.find @all, (room)->
room.name == name
@find_by_port: (port)->
_.find @all, (room)->
room.name == port
@find_by_client: (client)->
_.find @all, (room)->
_.some room.players, (player)->
player.client == client
#debug模式 端口号+1
debug = false
if process.argv[2] == '--debug' if process.argv[2] == '--debug'
settings.port++ settings.port++
settings.http_port++ settings.http_port++
debug = true
#结构体定义 #结构体定义
structs = {} structs = {}
...@@ -43,6 +88,8 @@ for name, declaration of structs_declaration ...@@ -43,6 +88,8 @@ for name, declaration of structs_declaration
result[type] field.name result[type] field.name
structs[name] = result structs[name] = result
#消息跟踪函数 需要重构, 另暂时只支持异步, 同步没做.
stoc_follows = {} stoc_follows = {}
ctos_follows = {} ctos_follows = {}
stoc_follow = (proto, synchronous, callback)-> stoc_follow = (proto, synchronous, callback)->
...@@ -62,6 +109,8 @@ ctos_follow = (proto, synchronous, callback)-> ...@@ -62,6 +109,8 @@ ctos_follow = (proto, synchronous, callback)->
throw "unknown proto" if !constants.CTOS[proto] throw "unknown proto" if !constants.CTOS[proto]
ctos_follows[proto] = {callback: callback, synchronous: synchronous} ctos_follows[proto] = {callback: callback, synchronous: synchronous}
#消息发送函数,至少要把俩合起来....
stoc_send = (socket, proto, info)-> stoc_send = (socket, proto, info)->
#console.log proto, proto_structs.STOC[proto], structs[proto_structs.STOC[proto]] #console.log proto, proto_structs.STOC[proto], structs[proto_structs.STOC[proto]]
...@@ -87,7 +136,7 @@ stoc_send = (socket, proto, info)-> ...@@ -87,7 +136,7 @@ stoc_send = (socket, proto, info)->
header.writeUInt8 proto, 2 header.writeUInt8 proto, 2
socket.write header socket.write header
socket.write buffer if buffer.length socket.write buffer if buffer.length
console.log 'stoc_sent:', buffer console.log 'stoc_sent:', buffer if debug
ctos_send = (socket, proto, info)-> ctos_send = (socket, proto, info)->
#console.log proto, proto_structs.CTOS[proto], structs[proto_structs.CTOS[proto]] #console.log proto, proto_structs.CTOS[proto], structs[proto_structs.CTOS[proto]]
...@@ -114,8 +163,9 @@ ctos_send = (socket, proto, info)-> ...@@ -114,8 +163,9 @@ ctos_send = (socket, proto, info)->
header.writeUInt8 proto, 2 header.writeUInt8 proto, 2
socket.write header socket.write header
socket.write buffer if buffer.length socket.write buffer if buffer.length
console.log 'ctos_sent:', buffer console.log 'ctos_sent:', buffer if debug
#服务器端消息监听函数
server_listener = (port, client, server)-> server_listener = (port, client, server)->
client.connected = true client.connected = true
console.log "connected #{port}" console.log "connected #{port}"
...@@ -128,7 +178,7 @@ server_listener = (port, client, server)-> ...@@ -128,7 +178,7 @@ server_listener = (port, client, server)->
server.write buffer server.write buffer
server.on "data", (data) -> server.on "data", (data) ->
console.log 'server: ', data console.log 'server: ', data if debug
stoc_buffer = Buffer.concat([stoc_buffer, data], stoc_buffer.length + data.length) stoc_buffer = Buffer.concat([stoc_buffer, data], stoc_buffer.length + data.length)
#buffer的错误使用方式,好孩子不要学 #buffer的错误使用方式,好孩子不要学
...@@ -145,7 +195,7 @@ server_listener = (port, client, server)-> ...@@ -145,7 +195,7 @@ server_listener = (port, client, server)->
break break
else else
if stoc_buffer.length >= 2 + stoc_message_length if stoc_buffer.length >= 2 + stoc_message_length
console.log constants.STOC[stoc_proto] console.log constants.STOC[stoc_proto] if debug
if stoc_follows[stoc_proto] if stoc_follows[stoc_proto]
b = stoc_buffer.slice(3, stoc_message_length - 1 + 3) b = stoc_buffer.slice(3, stoc_message_length - 1 + 3)
if struct = structs[proto_structs.STOC[constants.STOC[stoc_proto]]] if struct = structs[proto_structs.STOC[constants.STOC[stoc_proto]]]
...@@ -173,10 +223,6 @@ server_listener = (port, client, server)-> ...@@ -173,10 +223,6 @@ server_listener = (port, client, server)->
#main #main
rooms = {}
rooms_port_process = {}
#rooms_clients = {}
listener = net.createServer (client) -> listener = net.createServer (client) ->
client.connected = false client.connected = false
...@@ -191,7 +237,7 @@ listener = net.createServer (client) -> ...@@ -191,7 +237,7 @@ listener = net.createServer (client) ->
console.log "server error #{e}" console.log "server error #{e}"
client.on "data", (data) -> client.on "data", (data) ->
console.log 'client: ', data console.log 'client: ', data if debug
ctos_buffer = Buffer.concat([ctos_buffer, data], ctos_buffer.length + data.length) #buffer的错误使用方式,好孩子不要学 ctos_buffer = Buffer.concat([ctos_buffer, data], ctos_buffer.length + data.length) #buffer的错误使用方式,好孩子不要学
while true while true
...@@ -207,7 +253,7 @@ listener = net.createServer (client) -> ...@@ -207,7 +253,7 @@ listener = net.createServer (client) ->
break break
else else
if ctos_buffer.length >= 2 + ctos_message_length if ctos_buffer.length >= 2 + ctos_message_length
console.log constants.CTOS[ctos_proto] console.log constants.CTOS[ctos_proto] if debug
if ctos_follows[ctos_proto] if ctos_follows[ctos_proto]
b = ctos_buffer.slice(3, ctos_message_length-1+3) b = ctos_buffer.slice(3, ctos_message_length-1+3)
if struct = structs[proto_structs.CTOS[constants.CTOS[ctos_proto]]] if struct = structs[proto_structs.CTOS[constants.CTOS[ctos_proto]]]
...@@ -263,23 +309,20 @@ ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -263,23 +309,20 @@ ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
client.end() client.end()
else else
if client.player != '[INCORRECT]' #用户验证 if client.player != '[INCORRECT]' #用户验证
if rooms[room_name] room = Room.find_by_name(room_name)
if typeof rooms[room_name] == 'number' #already connected if room
#rooms_clients[room_name].push client room.add_client client
server.connect rooms[room_name], '127.0.0.1', -> if room.established
server_listener(rooms[room_name], client, server) server.connect room.port, '127.0.0.1', ->
else server_listener(room.port, client, server)
#rooms_clients[room_name].push client
rooms[room_name].push client
else else
freeport (err, port)-> freeport (err, port)->
if rooms[room_name] #如果等freeport的时间差又来了个..... room = Room.find_by_name(room_name)
if typeof rooms[room_name] == 'number' #already connected if room #如果等freeport的时间差又来了个.....
#rooms_clients[room_name].push client room.add_client client
server.connect rooms[room_name], '127.0.0.1', -> if room.established
server_listener(rooms[room_name], client, server) server.connect room.port, '127.0.0.1', ->
else server_listener(room.port, client, server)
rooms[room_name].push client
else else
if(err) if(err)
stoc_send client, 'ERROR_MSG',{ stoc_send client, 'ERROR_MSG',{
...@@ -288,7 +331,7 @@ ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -288,7 +331,7 @@ ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
} }
client.end() client.end()
else else
rooms[room_name] = [client] room = new Room(room_name, port, client)
if room_name[0...2] == 'M#' if room_name[0...2] == 'M#'
param = [0, 0, 1, 'F', 'F', 'F', 8000, 5, 1] param = [0, 0, 1, 'F', 'F', 'F', 8000, 5, 1]
else if room_name[0...2] == 'T#' else if room_name[0...2] == 'T#'
...@@ -300,20 +343,15 @@ ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -300,20 +343,15 @@ ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
param = [0, 0, 0, 'F', 'F', 'F', 8000, 5, 1] param = [0, 0, 0, 'F', 'F', 'F', 8000, 5, 1]
param.unshift port param.unshift port
room = spawn './ygopro', param, cwd: 'ygocore' process = spawn './ygopro', param, cwd: 'ygocore'
room.alive = true room.process = process
rooms_port_process[port] = room process.on 'exit', (code)->
room.on 'exit', (code)-> room.delete()
delete rooms[room_name] process.stdout.once 'data', (data)->
delete rooms_port_process[port] room.established = true
room.stdout.once 'data', (data)-> _.each room.players, (player)->
if(rooms[room_name])
rooms[room_name].forEach (c)->
server.connect port, '127.0.0.1', -> server.connect port, '127.0.0.1', ->
server_listener(port, c, server) server_listener(port, player.client, server)
rooms[room_name] = port
else
room.kill()
else else
stoc_send client, 'ERROR_MSG',{ stoc_send client, 'ERROR_MSG',{
msg: 1 msg: 1
...@@ -357,17 +395,13 @@ stoc_follow 'GAME_MSG', false, (buffer, info, client, server)-> ...@@ -357,17 +395,13 @@ stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
http.createServer (request, response)-> http.createServer (request, response)->
if url.parse(request.url).pathname == '/count.json' if url.parse(request.url).pathname == '/count.json'
response.writeHead(200); response.writeHead(200);
response.end(Object.keys(rooms).length.toString()) response.end(rooms.length.toString())
else else
response.writeHead(404); response.writeHead(404);
response.end(); response.end();
.listen settings.http_port .listen settings.http_port
#清理90s没活动的房间 #清理90s没活动的房间
path = require 'path'
fs = require 'fs'
Inotify = require('inotify').Inotify
inotify = new Inotify() inotify = new Inotify()
inotify.addWatch inotify.addWatch
path: 'ygocore/replay', path: 'ygocore/replay',
...@@ -376,7 +410,7 @@ inotify.addWatch ...@@ -376,7 +410,7 @@ inotify.addWatch
mask = event.mask mask = event.mask
if event.name if event.name
port = parseInt path.basename(event.name, '.yrp') port = parseInt path.basename(event.name, '.yrp')
room = rooms_port_process[port] room = Room.find_by_port port
if room if room
if mask & Inotify.IN_CREATE if mask & Inotify.IN_CREATE
else if mask & Inotify.IN_CLOSE_WRITE else if mask & Inotify.IN_CLOSE_WRITE
...@@ -387,12 +421,12 @@ inotify.addWatch ...@@ -387,12 +421,12 @@ inotify.addWatch
console.log '[warn] event without filename' console.log '[warn] event without filename'
setInterval ()-> setInterval ()->
for port, room of rooms_port_process for room in rooms
if room.alive if room.alive
room.alive = false room.alive = false
else else
console.log "killed #{port} #{room}" console.log "kill #{port} #{room}"
room.kill() room.process.kill()
, 900000 , 900000
......
// Generated by CoffeeScript 1.6.3 // Generated by CoffeeScript 1.6.3
(function() { (function() {
var Inotify, Struct, constants, ctos_follow, ctos_follows, ctos_send, declaration, field, freeport, fs, http, inotify, listener, name, net, path, proto_structs, result, rooms, rooms_port_process, server_listener, settings, spawn, stoc_follow, stoc_follows, stoc_send, structs, structs_declaration, taici, type, typedefs, url, _, _i, _len; var Inotify, Room, Struct, constants, ctos_follow, ctos_follows, ctos_send, debug, declaration, field, freeport, fs, http, inotify, listener, name, net, path, proto_structs, result, server_listener, settings, spawn, stoc_follow, stoc_follows, stoc_send, structs, structs_declaration, taici, type, typedefs, url, _, _i, _len;
net = require('net'); net = require('net');
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
url = require('url'); url = require('url');
path = require('path');
fs = require('fs');
spawn = require('child_process').spawn; spawn = require('child_process').spawn;
freeport = require('freeport'); freeport = require('freeport');
...@@ -16,6 +20,8 @@ ...@@ -16,6 +20,8 @@
_ = require('underscore'); _ = require('underscore');
Inotify = require('inotify').Inotify;
structs_declaration = require('./structs.json'); structs_declaration = require('./structs.json');
typedefs = require('./typedefs.json'); typedefs = require('./typedefs.json');
...@@ -26,9 +32,59 @@ ...@@ -26,9 +32,59 @@
settings = require('./config.json'); settings = require('./config.json');
Room = (function() {
Room.all = [];
function Room(name, port, client) {
this.name = name;
this.port = port;
this.alive = true;
this.players = [];
this.add_client(client);
Room.all.push(this);
}
Room.prototype["delete"] = function(room) {
return delete Room.all[_.indexOf(Room.all, room)];
};
Room.prototype.add_client = function(client) {
return this.players.push({
client: client,
name: client.player
});
};
Room.find_by_name = function(name) {
return _.find(this.all, function(room) {
return room.name === name;
});
};
Room.find_by_port = function(port) {
return _.find(this.all, function(room) {
return room.name === port;
});
};
Room.find_by_client = function(client) {
return _.find(this.all, function(room) {
return _.some(room.players, function(player) {
return player.client === client;
});
});
};
return Room;
})();
debug = false;
if (process.argv[2] === '--debug') { if (process.argv[2] === '--debug') {
settings.port++; settings.port++;
settings.http_port++; settings.http_port++;
debug = true;
} }
structs = {}; structs = {};
...@@ -143,7 +199,9 @@ ...@@ -143,7 +199,9 @@
if (buffer.length) { if (buffer.length) {
socket.write(buffer); socket.write(buffer);
} }
if (debug) {
return console.log('stoc_sent:', buffer); return console.log('stoc_sent:', buffer);
}
}; };
ctos_send = function(socket, proto, info) { ctos_send = function(socket, proto, info) {
...@@ -178,7 +236,9 @@ ...@@ -178,7 +236,9 @@
if (buffer.length) { if (buffer.length) {
socket.write(buffer); socket.write(buffer);
} }
if (debug) {
return console.log('ctos_sent:', buffer); return console.log('ctos_sent:', buffer);
}
}; };
server_listener = function(port, client, server) { server_listener = function(port, client, server) {
...@@ -195,7 +255,9 @@ ...@@ -195,7 +255,9 @@
} }
server.on("data", function(data) { server.on("data", function(data) {
var b, struct; var b, struct;
if (debug) {
console.log('server: ', data); console.log('server: ', data);
}
stoc_buffer = Buffer.concat([stoc_buffer, data], stoc_buffer.length + data.length); stoc_buffer = Buffer.concat([stoc_buffer, data], stoc_buffer.length + data.length);
while (true) { while (true) {
if (stoc_message_length === 0) { if (stoc_message_length === 0) {
...@@ -212,7 +274,9 @@ ...@@ -212,7 +274,9 @@
} }
} else { } else {
if (stoc_buffer.length >= 2 + stoc_message_length) { if (stoc_buffer.length >= 2 + stoc_message_length) {
if (debug) {
console.log(constants.STOC[stoc_proto]); console.log(constants.STOC[stoc_proto]);
}
if (stoc_follows[stoc_proto]) { if (stoc_follows[stoc_proto]) {
b = stoc_buffer.slice(3, stoc_message_length - 1 + 3); b = stoc_buffer.slice(3, stoc_message_length - 1 + 3);
if (struct = structs[proto_structs.STOC[constants.STOC[stoc_proto]]]) { if (struct = structs[proto_structs.STOC[constants.STOC[stoc_proto]]]) {
...@@ -244,10 +308,6 @@ ...@@ -244,10 +308,6 @@
}); });
}; };
rooms = {};
rooms_port_process = {};
listener = net.createServer(function(client) { listener = net.createServer(function(client) {
var ctos_buffer, ctos_message_length, ctos_proto, server; var ctos_buffer, ctos_message_length, ctos_proto, server;
client.connected = false; client.connected = false;
...@@ -261,7 +321,9 @@ ...@@ -261,7 +321,9 @@
}); });
client.on("data", function(data) { client.on("data", function(data) {
var b, struct; var b, struct;
if (debug) {
console.log('client: ', data); console.log('client: ', data);
}
ctos_buffer = Buffer.concat([ctos_buffer, data], ctos_buffer.length + data.length); ctos_buffer = Buffer.concat([ctos_buffer, data], ctos_buffer.length + data.length);
while (true) { while (true) {
if (ctos_message_length === 0) { if (ctos_message_length === 0) {
...@@ -278,7 +340,9 @@ ...@@ -278,7 +340,9 @@
} }
} else { } else {
if (ctos_buffer.length >= 2 + ctos_message_length) { if (ctos_buffer.length >= 2 + ctos_message_length) {
if (debug) {
console.log(constants.CTOS[ctos_proto]); console.log(constants.CTOS[ctos_proto]);
}
if (ctos_follows[ctos_proto]) { if (ctos_follows[ctos_proto]) {
b = ctos_buffer.slice(3, ctos_message_length - 1 + 3); b = ctos_buffer.slice(3, ctos_message_length - 1 + 3);
if (struct = structs[proto_structs.CTOS[constants.CTOS[ctos_proto]]]) { if (struct = structs[proto_structs.CTOS[constants.CTOS[ctos_proto]]]) {
...@@ -321,7 +385,7 @@ ...@@ -321,7 +385,7 @@
}); });
ctos_follow('JOIN_GAME', false, function(buffer, info, client, server) { ctos_follow('JOIN_GAME', false, function(buffer, info, client, server) {
var room_name; var room, room_name;
room_name = info.pass; room_name = info.pass;
if (info.version !== settings.version) { if (info.version !== settings.version) {
stoc_send(client, 'ERROR_MSG', { stoc_send(client, 'ERROR_MSG', {
...@@ -343,24 +407,24 @@ ...@@ -343,24 +407,24 @@
return client.end(); return client.end();
} else { } else {
if (client.player !== '[INCORRECT]') { if (client.player !== '[INCORRECT]') {
if (rooms[room_name]) { room = Room.find_by_name(room_name);
if (typeof rooms[room_name] === 'number') { if (room) {
return server.connect(rooms[room_name], '127.0.0.1', function() { room.add_client(client);
return server_listener(rooms[room_name], client, server); if (room.established) {
return server.connect(room.port, '127.0.0.1', function() {
return server_listener(room.port, client, server);
}); });
} else {
return rooms[room_name].push(client);
} }
} else { } else {
return freeport(function(err, port) { return freeport(function(err, port) {
var param, room; var param, process;
if (rooms[room_name]) { room = Room.find_by_name(room_name);
if (typeof rooms[room_name] === 'number') { if (room) {
return server.connect(rooms[room_name], '127.0.0.1', function() { room.add_client(client);
return server_listener(rooms[room_name], client, server); if (room.established) {
return server.connect(room.port, '127.0.0.1', function() {
return server_listener(room.port, client, server);
}); });
} else {
return rooms[room_name].push(client);
} }
} else { } else {
if (err) { if (err) {
...@@ -370,7 +434,7 @@ ...@@ -370,7 +434,7 @@
}); });
return client.end(); return client.end();
} else { } else {
rooms[room_name] = [client]; room = new Room(room_name, port, client);
if (room_name.slice(0, 2) === 'M#') { if (room_name.slice(0, 2) === 'M#') {
param = [0, 0, 1, 'F', 'F', 'F', 8000, 5, 1]; param = [0, 0, 1, 'F', 'F', 'F', 8000, 5, 1];
} else if (room_name.slice(0, 2) === 'T#') { } else if (room_name.slice(0, 2) === 'T#') {
...@@ -382,26 +446,20 @@ ...@@ -382,26 +446,20 @@
param = [0, 0, 0, 'F', 'F', 'F', 8000, 5, 1]; param = [0, 0, 0, 'F', 'F', 'F', 8000, 5, 1];
} }
param.unshift(port); param.unshift(port);
room = spawn('./ygopro', param, { process = spawn('./ygopro', param, {
cwd: 'ygocore' cwd: 'ygocore'
}); });
room.alive = true; room.process = process;
rooms_port_process[port] = room; process.on('exit', function(code) {
room.on('exit', function(code) { return room["delete"]();
delete rooms[room_name];
return delete rooms_port_process[port];
}); });
return room.stdout.once('data', function(data) { return process.stdout.once('data', function(data) {
if (rooms[room_name]) { room.established = true;
rooms[room_name].forEach(function(c) { return _.each(room.players, function(player) {
return server.connect(port, '127.0.0.1', function() { return server.connect(port, '127.0.0.1', function() {
return server_listener(port, c, server); return server_listener(port, player.client, server);
}); });
}); });
return rooms[room_name] = port;
} else {
return room.kill();
}
}); });
} }
} }
...@@ -453,19 +511,13 @@ ...@@ -453,19 +511,13 @@
http.createServer(function(request, response) { http.createServer(function(request, response) {
if (url.parse(request.url).pathname === '/count.json') { if (url.parse(request.url).pathname === '/count.json') {
response.writeHead(200); response.writeHead(200);
return response.end(Object.keys(rooms).length.toString()); return response.end(rooms.length.toString());
} else { } else {
response.writeHead(404); response.writeHead(404);
return response.end(); return response.end();
} }
}).listen(settings.http_port); }).listen(settings.http_port);
path = require('path');
fs = require('fs');
Inotify = require('inotify').Inotify;
inotify = new Inotify(); inotify = new Inotify();
inotify.addWatch({ inotify.addWatch({
...@@ -476,7 +528,7 @@ ...@@ -476,7 +528,7 @@
mask = event.mask; mask = event.mask;
if (event.name) { if (event.name) {
port = parseInt(path.basename(event.name, '.yrp')); port = parseInt(path.basename(event.name, '.yrp'));
room = rooms_port_process[port]; room = Room.find_by_port(port);
if (room) { if (room) {
if (mask & Inotify.IN_CREATE) { if (mask & Inotify.IN_CREATE) {
...@@ -493,15 +545,15 @@ ...@@ -493,15 +545,15 @@
}); });
setInterval(function() { setInterval(function() {
var port, room, _results; var room, _j, _len1, _results;
_results = []; _results = [];
for (port in rooms_port_process) { for (_j = 0, _len1 = rooms.length; _j < _len1; _j++) {
room = rooms_port_process[port]; room = rooms[_j];
if (room.alive) { if (room.alive) {
_results.push(room.alive = false); _results.push(room.alive = false);
} else { } else {
console.log("killed " + port + " " + room); console.log("kill " + port + " " + room);
_results.push(room.kill()); _results.push(room.process.kill());
} }
} }
return _results; return _results;
......
This diff is collapsed.
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