Commit 309b626e authored by mercury233's avatar mercury233

catch stdout undefined

parent ad1f15a5
...@@ -242,23 +242,26 @@ class Room ...@@ -242,23 +242,26 @@ class Room
param = [0, @hostinfo.lflist, @hostinfo.rule, @hostinfo.mode, (if @hostinfo.enable_priority then 'T' else 'F'), (if @hostinfo.no_check_deck then 'T' else 'F'), (if @hostinfo.no_shuffle_deck then 'T' else 'F'), @hostinfo.start_lp, @hostinfo.start_hand, @hostinfo.draw_count, @hostinfo.time_limit] param = [0, @hostinfo.lflist, @hostinfo.rule, @hostinfo.mode, (if @hostinfo.enable_priority then 'T' else 'F'), (if @hostinfo.no_check_deck then 'T' else 'F'), (if @hostinfo.no_shuffle_deck then 'T' else 'F'), @hostinfo.start_lp, @hostinfo.start_hand, @hostinfo.draw_count, @hostinfo.time_limit]
@process = spawn './ygopro', param, cwd: 'ygocore' try
@process.on 'exit', (code)=> @process = spawn './ygopro', param, cwd: 'ygocore'
@disconnector = 'server' unless @disconnector @process.on 'exit', (code)=>
this.delete() @disconnector = 'server' unless @disconnector
return this.delete()
@process.stdout.setEncoding('utf8') return
@process.stdout.once 'data', (data)=> @process.stdout.setEncoding('utf8')
@established = true @process.stdout.once 'data', (data)=>
@port = parseInt data @established = true
_.each @players, (player)=> @port = parseInt data
player.server.connect @port, '127.0.0.1',=> _.each @players, (player)=>
player.server.write buffer for buffer in player.pre_establish_buffers player.server.connect @port, '127.0.0.1',=>
player.established = true player.server.write buffer for buffer in player.pre_establish_buffers
player.pre_establish_buffers = null player.established = true
player.pre_establish_buffers = null
return
return return
return return
return catch
@error = "建立房间失败,请重试"
delete: -> delete: ->
#积分 #积分
return if @deleted return if @deleted
......
...@@ -291,36 +291,40 @@ ...@@ -291,36 +291,40 @@
} }
} }
param = [0, this.hostinfo.lflist, this.hostinfo.rule, this.hostinfo.mode, (this.hostinfo.enable_priority ? 'T' : 'F'), (this.hostinfo.no_check_deck ? 'T' : 'F'), (this.hostinfo.no_shuffle_deck ? 'T' : 'F'), this.hostinfo.start_lp, this.hostinfo.start_hand, this.hostinfo.draw_count, this.hostinfo.time_limit]; param = [0, this.hostinfo.lflist, this.hostinfo.rule, this.hostinfo.mode, (this.hostinfo.enable_priority ? 'T' : 'F'), (this.hostinfo.no_check_deck ? 'T' : 'F'), (this.hostinfo.no_shuffle_deck ? 'T' : 'F'), this.hostinfo.start_lp, this.hostinfo.start_hand, this.hostinfo.draw_count, this.hostinfo.time_limit];
this.process = spawn('./ygopro', param, { try {
cwd: 'ygocore' this.process = spawn('./ygopro', param, {
}); cwd: 'ygocore'
this.process.on('exit', (function(_this) { });
return function(code) { this.process.on('exit', (function(_this) {
if (!_this.disconnector) { return function(code) {
_this.disconnector = 'server'; if (!_this.disconnector) {
} _this.disconnector = 'server';
_this["delete"](); }
}; _this["delete"]();
})(this)); };
this.process.stdout.setEncoding('utf8'); })(this));
this.process.stdout.once('data', (function(_this) { this.process.stdout.setEncoding('utf8');
return function(data) { this.process.stdout.once('data', (function(_this) {
_this.established = true; return function(data) {
_this.port = parseInt(data); _this.established = true;
_.each(_this.players, function(player) { _this.port = parseInt(data);
player.server.connect(_this.port, '127.0.0.1', function() { _.each(_this.players, function(player) {
var buffer, i, len, ref; player.server.connect(_this.port, '127.0.0.1', function() {
ref = player.pre_establish_buffers; var buffer, i, len, ref;
for (i = 0, len = ref.length; i < len; i++) { ref = player.pre_establish_buffers;
buffer = ref[i]; for (i = 0, len = ref.length; i < len; i++) {
player.server.write(buffer); buffer = ref[i];
} player.server.write(buffer);
player.established = true; }
player.pre_establish_buffers = null; player.established = true;
player.pre_establish_buffers = null;
});
}); });
}); };
}; })(this));
})(this)); } catch (_error) {
this.error = "建立房间失败,请重试";
}
} }
Room.prototype["delete"] = function() { Room.prototype["delete"] = function() {
......
...@@ -284,6 +284,13 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -284,6 +284,13 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
code: 2 code: 2
} }
client.end() client.end()
else if client.room.error
ygopro.stoc_send_chat(client,client.room.error)
ygopro.stoc_send client, 'ERROR_MSG',{
msg: 1
code: 2
}
client.end()
else if client.room.started else if client.room.started
if settings.modules.post_start_watching if settings.modules.post_start_watching
client.is_post_watcher = true client.is_post_watcher = true
......
...@@ -292,6 +292,13 @@ ...@@ -292,6 +292,13 @@
code: 2 code: 2
}); });
client.end(); client.end();
} else if (client.room.error) {
ygopro.stoc_send_chat(client, client.room.error);
ygopro.stoc_send(client, 'ERROR_MSG', {
msg: 1,
code: 2
});
client.end();
} else if (client.room.started) { } else if (client.room.started) {
if (settings.modules.post_start_watching) { if (settings.modules.post_start_watching) {
client.is_post_watcher = true; client.is_post_watcher = true;
......
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