Commit 8b1f8400 authored by mercury233's avatar mercury233

add recorder for cloud replay

and ygopro should send hand cards data to Marshtomp
parent b35e9dd0
......@@ -149,6 +149,7 @@ class Room
@started = false
@established = false
@watcher_buffers = []
@recorder_buffers = []
@watchers = []
@random_type = ''
@welcome = ''
......@@ -359,8 +360,8 @@ class Room
_.each @player_datas, (player)=>
player_ips.push(player.ip)
return
watcher_buffer=Buffer.concat(@watcher_buffers)
zlib.deflate watcher_buffer, (err, replay_buffer) =>
recorder_buffer=Buffer.concat(@recorder_buffers)
zlib.deflate recorder_buffer, (err, replay_buffer) =>
replay_buffer=replay_buffer.toString('binary')
#log.info err, replay_buffer
date_time=moment().format('YYYY-MM-DD HH:mm:ss')
......@@ -379,6 +380,7 @@ class Room
return
return
@watcher_buffers = []
@recorder_buffers = []
@players = []
@watcher.end() if @watcher
@deleted = true
......
......@@ -208,6 +208,7 @@
this.started = false;
this.established = false;
this.watcher_buffers = [];
this.recorder_buffers = [];
this.watchers = [];
this.random_type = '';
this.welcome = '';
......@@ -457,7 +458,7 @@
}
Room.prototype["delete"] = function() {
var index, player_ips, player_names, watcher_buffer;
var index, player_ips, player_names, recorder_buffer;
if (this.deleted) {
return;
}
......@@ -469,8 +470,8 @@
player_ips.push(player.ip);
};
})(this));
watcher_buffer = Buffer.concat(this.watcher_buffers);
zlib.deflate(watcher_buffer, (function(_this) {
recorder_buffer = Buffer.concat(this.recorder_buffers);
zlib.deflate(recorder_buffer, (function(_this) {
return function(err, replay_buffer) {
var date_time, recorded_ip, replay_id;
replay_buffer = replay_buffer.toString('binary');
......@@ -490,6 +491,7 @@
})(this));
}
this.watcher_buffers = [];
this.recorder_buffers = [];
this.players = [];
if (this.watcher) {
this.watcher.end();
......
......@@ -577,6 +577,27 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)->
if client.room.welcome
ygopro.stoc_send_chat client, client.room.welcome, 14
if settings.modules.enable_cloud_replay and !client.room.recorder
client.room.recorder = recorder = net.connect client.room.port, ->
ygopro.ctos_send recorder, 'PLAYER_INFO', {
name: "Marshtomp"
}
ygopro.ctos_send recorder, 'JOIN_GAME', {
version: settings.version,
gameid: 2577,
some_unknown_mysterious_fucking_thing: 0
pass: ""
}
ygopro.ctos_send recorder, 'HS_TOOBSERVER'
return
recorder.on 'data', (data)->
return unless client.room
client.room.recorder_buffers.push data
recorder.on 'error', (error)->
return
if settings.modules.enable_halfway_watch and !client.room.watcher
client.room.watcher = watcher = net.connect client.room.port, ->
ygopro.ctos_send watcher, 'PLAYER_INFO', {
......@@ -780,6 +801,7 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server)->
return
ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server)->
return unless client.room
cancel = _.startsWith(_.trim(info.msg), "/")
client.room.last_active_time = moment() unless cancel or not client.room.random_type
switch _.trim(info.msg)
......
......@@ -637,7 +637,7 @@
});
ygopro.stoc_follow('JOIN_GAME', false, function(buffer, info, client, server) {
var watcher;
var recorder, watcher;
if (!client.room) {
return;
}
......@@ -647,6 +647,27 @@
if (client.room.welcome) {
ygopro.stoc_send_chat(client, client.room.welcome, 14);
}
if (settings.modules.enable_cloud_replay && !client.room.recorder) {
client.room.recorder = recorder = net.connect(client.room.port, function() {
ygopro.ctos_send(recorder, 'PLAYER_INFO', {
name: "Marshtomp"
});
ygopro.ctos_send(recorder, 'JOIN_GAME', {
version: settings.version,
gameid: 2577,
some_unknown_mysterious_fucking_thing: 0,
pass: ""
});
ygopro.ctos_send(recorder, 'HS_TOOBSERVER');
});
recorder.on('data', function(data) {
if (!client.room) {
return;
}
return client.room.recorder_buffers.push(data);
});
recorder.on('error', function(error) {});
}
if (settings.modules.enable_halfway_watch && !client.room.watcher) {
client.room.watcher = watcher = net.connect(client.room.port, function() {
ygopro.ctos_send(watcher, 'PLAYER_INFO', {
......@@ -932,6 +953,9 @@
ygopro.ctos_follow('CHAT', true, function(buffer, info, client, server) {
var cancel;
if (!client.room) {
return;
}
cancel = _.startsWith(_.trim(info.msg), "/");
if (!(cancel || !client.room.random_type)) {
client.room.last_active_time = moment();
......
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