Commit 064e1a97 authored by mercury233's avatar mercury233

synchronous stoc_follow, disable local replay for tournament mode

parent 3d0c1c40
......@@ -20,6 +20,7 @@
"GAME_MSG": "GameMsg_Hint_Card_only",
"SELECT_HAND": "",
"SELECT_TP": "",
"REPLAY": "",
"CHAT": "STOC_Chat"
}
}
......@@ -230,6 +230,7 @@ class Room
@established = false
@watcher_buffers = []
@recorder_buffers = []
@cloud_replay_id = Math.floor(Math.random()*100000000)
@watchers = []
@random_type = ''
@welcome = ''
......@@ -438,6 +439,7 @@ class Room
return if @deleted
#log.info 'room-delete', this.name, ROOM_all.length
if @player_datas.length and settings.modules.enable_cloud_replay
replay_id = @cloud_replay_id
if @has_ygopro_error
log_rep_id = true
player_names=@player_datas[0].name + (if @player_datas[2] then "+" + @player_datas[2].name else "") +
......@@ -453,7 +455,7 @@ class Room
replay_buffer=replay_buffer.toString('binary')
#log.info err, replay_buffer
date_time=moment().format('YYYY-MM-DD HH:mm:ss')
replay_id=Math.floor(Math.random()*100000000)
#replay_id=Math.floor(Math.random()*100000000)
redisdb.hmset("replay:"+replay_id,
"replay_id", replay_id,
"replay_buffer", replay_buffer,
......@@ -685,7 +687,8 @@ net.createServer (client) ->
stoc_buffer = Buffer.concat([stoc_buffer, data], stoc_buffer.length + data.length) #buffer的错误使用方式,好孩子不要学
#unless ygopro.stoc_follows[stoc_proto] and ygopro.stoc_follows[stoc_proto].synchronous
client.write data
#client.write data
datas = []
looplimit = 0
......@@ -703,15 +706,22 @@ net.createServer (client) ->
else
if stoc_buffer.length >= 2 + stoc_message_length
#console.log "STOC", ygopro.constants.STOC[stoc_proto]
cancel = false
stanzas = stoc_proto
if ygopro.stoc_follows[stoc_proto]
b = stoc_buffer.slice(3, stoc_message_length - 1 + 3)
if struct = ygopro.structs[ygopro.proto_structs.STOC[ygopro.constants.STOC[stoc_proto]]]
struct._setBuff(b)
ygopro.stoc_follows[stoc_proto].callback b, _.clone(struct.fields), client, server
if ygopro.stoc_follows[stoc_proto].synchronous
cancel = ygopro.stoc_follows[stoc_proto].callback b, _.clone(struct.fields), client, server
else
ygopro.stoc_follows[stoc_proto].callback b, _.clone(struct.fields), client, server
else
ygopro.stoc_follows[stoc_proto].callback b, null, client, server
if ygopro.stoc_follows[stoc_proto].synchronous
cancel = ygopro.stoc_follows[stoc_proto].callback b, null, client, server
else
ygopro.stoc_follows[stoc_proto].callback b, null, client, server
datas.push stoc_buffer.slice(0, 2 + stoc_message_length) unless cancel
stoc_buffer = stoc_buffer.slice(2 + stoc_message_length)
stoc_message_length = 0
stoc_proto = 0
......@@ -724,6 +734,8 @@ net.createServer (client) ->
log.info("error stoc", client.name)
server.end()
break
client.write buffer for buffer in datas
return
return
.listen settings.port, ->
......@@ -1417,6 +1429,15 @@ ygopro.stoc_follow 'CHANGE_SIDE', false, (buffer, info, client, server)->
room.last_active_time = moment()
return
ygopro.stoc_follow 'REPLAY', true, (buffer, info, client, server)->
room=ROOM_all[client.rid]
return settings.modules.tournament_mode.enabled unless room
if settings.modules.tournament_mode.enabled
ygopro.stoc_send_chat(client, "本场比赛云录像:R##{room.cloud_replay_id}", ygopro.constants.COLORS.BABYBLUE)
return true
else
return false
setInterval ()->
for room in ROOM_all when room and room.started and room.random_type and room.last_active_time and room.waiting_for_player
time_passed = Math.floor((moment() - room.last_active_time) / 1000)
......
......@@ -336,6 +336,7 @@
this.established = false;
this.watcher_buffers = [];
this.recorder_buffers = [];
this.cloud_replay_id = Math.floor(Math.random() * 100000000);
this.watchers = [];
this.random_type = '';
this.welcome = '';
......@@ -591,11 +592,12 @@
}
Room.prototype["delete"] = function() {
var index, log_rep_id, player_ips, player_names, recorder_buffer;
var index, log_rep_id, player_ips, player_names, recorder_buffer, replay_id;
if (this.deleted) {
return;
}
if (this.player_datas.length && settings.modules.enable_cloud_replay) {
replay_id = this.cloud_replay_id;
if (this.has_ygopro_error) {
log_rep_id = true;
}
......@@ -606,10 +608,9 @@
});
recorder_buffer = Buffer.concat(this.recorder_buffers);
zlib.deflate(recorder_buffer, function(err, replay_buffer) {
var date_time, recorded_ip, replay_id;
var date_time, recorded_ip;
replay_buffer = replay_buffer.toString('binary');
date_time = moment().format('YYYY-MM-DD HH:mm:ss');
replay_id = Math.floor(Math.random() * 100000000);
redisdb.hmset("replay:" + replay_id, "replay_id", replay_id, "replay_buffer", replay_buffer, "player_names", player_names, "date_time", date_time);
redisdb.expire("replay:" + replay_id, 60 * 60 * 24);
recorded_ip = [];
......@@ -882,12 +883,12 @@
}
});
server.on('data', function(data) {
var b, looplimit, stanzas, stoc_buffer, stoc_message_length, stoc_proto, struct;
var b, buffer, cancel, datas, k, len, looplimit, stanzas, stoc_buffer, stoc_message_length, stoc_proto, struct;
stoc_buffer = new Buffer(0);
stoc_message_length = 0;
stoc_proto = 0;
stoc_buffer = Buffer.concat([stoc_buffer, data], stoc_buffer.length + data.length);
client.write(data);
datas = [];
looplimit = 0;
while (true) {
if (stoc_message_length === 0) {
......@@ -904,16 +905,28 @@
}
} else {
if (stoc_buffer.length >= 2 + stoc_message_length) {
cancel = false;
stanzas = stoc_proto;
if (ygopro.stoc_follows[stoc_proto]) {
b = stoc_buffer.slice(3, stoc_message_length - 1 + 3);
if (struct = ygopro.structs[ygopro.proto_structs.STOC[ygopro.constants.STOC[stoc_proto]]]) {
struct._setBuff(b);
ygopro.stoc_follows[stoc_proto].callback(b, _.clone(struct.fields), client, server);
if (ygopro.stoc_follows[stoc_proto].synchronous) {
cancel = ygopro.stoc_follows[stoc_proto].callback(b, _.clone(struct.fields), client, server);
} else {
ygopro.stoc_follows[stoc_proto].callback(b, _.clone(struct.fields), client, server);
}
} else {
ygopro.stoc_follows[stoc_proto].callback(b, null, client, server);
if (ygopro.stoc_follows[stoc_proto].synchronous) {
cancel = ygopro.stoc_follows[stoc_proto].callback(b, null, client, server);
} else {
ygopro.stoc_follows[stoc_proto].callback(b, null, client, server);
}
}
}
if (!cancel) {
datas.push(stoc_buffer.slice(0, 2 + stoc_message_length));
}
stoc_buffer = stoc_buffer.slice(2 + stoc_message_length);
stoc_message_length = 0;
stoc_proto = 0;
......@@ -928,6 +941,10 @@
break;
}
}
for (k = 0, len = datas.length; k < len; k++) {
buffer = datas[k];
client.write(buffer);
}
});
}).listen(settings.port, function() {
log.info("server started", settings.port);
......@@ -1783,6 +1800,20 @@
room.last_active_time = moment();
});
ygopro.stoc_follow('REPLAY', true, function(buffer, info, client, server) {
var room;
room = ROOM_all[client.rid];
if (!room) {
return settings.modules.tournament_mode.enabled;
}
if (settings.modules.tournament_mode.enabled) {
ygopro.stoc_send_chat(client, "本场比赛云录像:R#" + room.cloud_replay_id, ygopro.constants.COLORS.BABYBLUE);
return true;
} else {
return false;
}
});
setInterval(function() {
var k, len, room, time_passed;
for (k = 0, len = ROOM_all.length; k < len; k++) {
......
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