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