Commit 9eb9affd authored by mercury233's avatar mercury233

format

parent 4614147a
_ = require 'underscore' _ = require 'underscore'
_.str = require 'underscore.string' _.str = require 'underscore.string'
_.mixin(_.str.exports()); _.mixin(_.str.exports())
spawn = require('child_process').spawn spawn = require('child_process').spawn
spawnSync = require('child_process').spawnSync spawnSync = require('child_process').spawnSync
settings = require './config.json' settings = require './config.json'
...@@ -70,7 +70,7 @@ class Room ...@@ -70,7 +70,7 @@ class Room
bannedplayer.time = if moment() < bannedplayer.time then moment(bannedplayer.time).add(bantime, 'm') else moment().add(bantime, 'm') bannedplayer.time = if moment() < bannedplayer.time then moment(bannedplayer.time).add(bantime, 'm') else moment().add(bantime, 'm')
bannedplayer.reasons.push(reason) if not _.find bannedplayer.reasons, (bannedreason)-> bannedplayer.reasons.push(reason) if not _.find bannedplayer.reasons, (bannedreason)->
bannedreason == reason bannedreason == reason
bannedplayer.need_tip = true; bannedplayer.need_tip = true
else else
bannedplayer = {"ip": ip, "time": moment(), "count": 1, "reasons": [reason], "need_tip": true} bannedplayer = {"ip": ip, "time": moment(), "count": 1, "reasons": [reason], "need_tip": true}
Room.players_banned.push(bannedplayer) Room.players_banned.push(bannedplayer)
...@@ -104,7 +104,11 @@ class Room ...@@ -104,7 +104,11 @@ class Room
max_player = if type == 'T' then 4 else 2 max_player = if type == 'T' then 4 else 2
playerbanned = (bannedplayer and bannedplayer.count > 3 and moment() < bannedplayer.time) playerbanned = (bannedplayer and bannedplayer.count > 3 and moment() < bannedplayer.time)
result = _.find @all, (room)-> result = _.find @all, (room)->
return room.random_type != '' and !room.started and ((type == '' and room.random_type != 'T') or room.random_type == type) and room.get_playing_player().length < max_player and (room.get_host() == null or room.get_host().remoteAddress != Room.players_oppentlist[player_ip]) and (playerbanned == room.deprecated) return room.random_type != '' and !room.started and
((type == '' and room.random_type != 'T') or room.random_type == type) and
room.get_playing_player().length < max_player and
(room.get_host() == null or room.get_host().remoteAddress != Room.players_oppentlist[player_ip]) and
(playerbanned == room.deprecated)
if result if result
result.welcome = '对手已经在等你了,开始决斗吧!' result.welcome = '对手已经在等你了,开始决斗吧!'
#log.info 'found room', player_name #log.info 'found room', player_name
...@@ -321,7 +325,7 @@ class Room ...@@ -321,7 +325,7 @@ class Room
roomlist.create(this) if !@private and settings.modules.enable_websocket_roomlist roomlist.create(this) if !@private and settings.modules.enable_websocket_roomlist
@port = parseInt data @port = parseInt data
_.each @players, (player)=> _.each @players, (player)=>
player.server.connect @port, '127.0.0.1', => player.server.connect @port, '127.0.0.1', ->
player.server.write buffer for buffer in player.pre_establish_buffers player.server.write buffer for buffer in player.pre_establish_buffers
player.established = true player.established = true
player.pre_establish_buffers = [] player.pre_establish_buffers = []
...@@ -339,10 +343,10 @@ class Room ...@@ -339,10 +343,10 @@ class Room
YGOPRO_DIALOG: @windbot.dialog YGOPRO_DIALOG: @windbot.dialog
} }
} }
@ai_process.stdout.on 'data', (data)=> @ai_process.stdout.on 'data', (data)->
#log.info "AI stdout: " + data #log.info "AI stdout: " + data
return return
@ai_process.stderr.on 'data', (data)=> @ai_process.stderr.on 'data', (data)->
log.info "AI stderr: " + data log.info "AI stderr: " + data
return return
return return
...@@ -355,26 +359,26 @@ class Room ...@@ -355,26 +359,26 @@ class Room
if @player_datas.length and settings.modules.enable_cloud_replay if @player_datas.length and settings.modules.enable_cloud_replay
player_names=@player_datas[0].name + (if @player_datas[2] then "+" + @player_datas[2].name else "") + player_names=@player_datas[0].name + (if @player_datas[2] then "+" + @player_datas[2].name else "") +
" VS " + " VS " +
(if @player_datas[1] then @player_datas[1].name else "AI") + (if @player_datas[1] then @player_datas[1].name else "AI") +
(if @player_datas[3] then "+" + @player_datas[3].name else "") (if @player_datas[3] then "+" + @player_datas[3].name else "")
player_ips=[] player_ips=[]
_.each @player_datas, (player)=> _.each @player_datas, (player)->
player_ips.push(player.ip) player_ips.push(player.ip)
return return
recorder_buffer=Buffer.concat(@recorder_buffers) recorder_buffer=Buffer.concat(@recorder_buffers)
zlib.deflate recorder_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')
replay_id=Math.floor(Math.random()*100000000) replay_id=Math.floor(Math.random()*100000000)
redisdb.hmset("replay:"+replay_id, redisdb.hmset("replay:"+replay_id,
"replay_id", replay_id, "replay_id", replay_id,
"replay_buffer", replay_buffer, "replay_buffer", replay_buffer,
"player_names", player_names, "player_names", player_names,
"date_time", date_time) "date_time", date_time)
redisdb.expire("replay:"+replay_id, 60*60*24) redisdb.expire("replay:"+replay_id, 60*60*24)
recorded_ip=[] recorded_ip=[]
_.each player_ips, (player_ip)=> _.each player_ips, (player_ip)->
return if _.contains(recorded_ip, player_ip) return if _.contains(recorded_ip, player_ip)
recorded_ip.push player_ip recorded_ip.push player_ip
redisdb.lpush(player_ip+":replays", replay_id) redisdb.lpush(player_ip+":replays", replay_id)
...@@ -393,14 +397,14 @@ class Room ...@@ -393,14 +397,14 @@ class Room
get_playing_player: -> get_playing_player: ->
playing_player = [] playing_player = []
_.each @players, (player)=> _.each @players, (player)->
if player.pos < 4 then playing_player.push player if player.pos < 4 then playing_player.push player
return return
return playing_player return playing_player
get_host: -> get_host: ->
host_player = null host_player = null
_.each @players, (player)=> _.each @players, (player)->
if player.is_host then host_player = player if player.is_host then host_player = player
return return
return host_player return host_player
...@@ -429,7 +433,7 @@ class Room ...@@ -429,7 +433,7 @@ class Room
disconnect: (client, error)-> disconnect: (client, error)->
if client.is_post_watcher if client.is_post_watcher
ygopro.stoc_send_chat_to_room this, "#{client.name} #{'退出了观战'}#{if error then ": #{error}" else ''}" ygopro.stoc_send_chat_to_room this, "#{client.name} 退出了观战" + if error then ": #{error}" else ''
index = _.indexOf(@watchers, client) index = _.indexOf(@watchers, client)
@watchers.splice(index, 1) unless index == -1 @watchers.splice(index, 1) unless index == -1
#client.room = null #client.room = null
...@@ -440,7 +444,7 @@ class Room ...@@ -440,7 +444,7 @@ class Room
if @started and @disconnector != 'server' and client.room.random_type if @started and @disconnector != 'server' and client.room.random_type
Room.ban_player(client.name, client.ip, "强退") Room.ban_player(client.name, client.ip, "强退")
if @players.length if @players.length
ygopro.stoc_send_chat_to_room this, "#{client.name} #{'离开了游戏'}#{if error then ": #{error}" else ''}" ygopro.stoc_send_chat_to_room this, "#{client.name} 离开了游戏" + if error then ": #{error}" else ''
roomlist.update(this) if !@private and !@started and settings.modules.enable_websocket_roomlist roomlist.update(this) if !@private and !@started and settings.modules.enable_websocket_roomlist
#client.room = null #client.room = null
else else
......
...@@ -465,30 +465,26 @@ ...@@ -465,30 +465,26 @@
if (this.player_datas.length && settings.modules.enable_cloud_replay) { if (this.player_datas.length && settings.modules.enable_cloud_replay) {
player_names = this.player_datas[0].name + (this.player_datas[2] ? "+" + this.player_datas[2].name : "") + " VS " + (this.player_datas[1] ? this.player_datas[1].name : "AI") + (this.player_datas[3] ? "+" + this.player_datas[3].name : ""); player_names = this.player_datas[0].name + (this.player_datas[2] ? "+" + this.player_datas[2].name : "") + " VS " + (this.player_datas[1] ? this.player_datas[1].name : "AI") + (this.player_datas[3] ? "+" + this.player_datas[3].name : "");
player_ips = []; player_ips = [];
_.each(this.player_datas, (function(_this) { _.each(this.player_datas, function(player) {
return function(player) { player_ips.push(player.ip);
player_ips.push(player.ip); });
};
})(this));
recorder_buffer = Buffer.concat(this.recorder_buffers); recorder_buffer = Buffer.concat(this.recorder_buffers);
zlib.deflate(recorder_buffer, (function(_this) { zlib.deflate(recorder_buffer, 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'); date_time = moment().format('YYYY-MM-DD HH:mm:ss');
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, "player_names", player_names, "date_time", date_time);
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);
redisdb.expire("replay:" + replay_id, 60 * 60 * 24); recorded_ip = [];
recorded_ip = []; _.each(player_ips, function(player_ip) {
_.each(player_ips, function(player_ip) { if (_.contains(recorded_ip, player_ip)) {
if (_.contains(recorded_ip, player_ip)) { return;
return; }
} recorded_ip.push(player_ip);
recorded_ip.push(player_ip); redisdb.lpush(player_ip + ":replays", replay_id);
redisdb.lpush(player_ip + ":replays", replay_id); });
}); });
};
})(this));
} }
this.watcher_buffers = []; this.watcher_buffers = [];
this.recorder_buffers = []; this.recorder_buffers = [];
...@@ -509,26 +505,22 @@ ...@@ -509,26 +505,22 @@
Room.prototype.get_playing_player = function() { Room.prototype.get_playing_player = function() {
var playing_player; var playing_player;
playing_player = []; playing_player = [];
_.each(this.players, (function(_this) { _.each(this.players, function(player) {
return function(player) { if (player.pos < 4) {
if (player.pos < 4) { playing_player.push(player);
playing_player.push(player); }
} });
};
})(this));
return playing_player; return playing_player;
}; };
Room.prototype.get_host = function() { Room.prototype.get_host = function() {
var host_player; var host_player;
host_player = null; host_player = null;
_.each(this.players, (function(_this) { _.each(this.players, function(player) {
return function(player) { if (player.is_host) {
if (player.is_host) { host_player = player;
host_player = player; }
} });
};
})(this));
return host_player; return host_player;
}; };
...@@ -565,7 +557,7 @@ ...@@ -565,7 +557,7 @@
Room.prototype.disconnect = function(client, error) { Room.prototype.disconnect = function(client, error) {
var index; var index;
if (client.is_post_watcher) { if (client.is_post_watcher) {
ygopro.stoc_send_chat_to_room(this, client.name + " " + '退出了观战' + (error ? ": " + error : '')); ygopro.stoc_send_chat_to_room(this, (client.name + " 退出了观战") + (error ? ": " + error : ''));
index = _.indexOf(this.watchers, client); index = _.indexOf(this.watchers, client);
if (index !== -1) { if (index !== -1) {
this.watchers.splice(index, 1); this.watchers.splice(index, 1);
...@@ -579,7 +571,7 @@ ...@@ -579,7 +571,7 @@
Room.ban_player(client.name, client.ip, "强退"); Room.ban_player(client.name, client.ip, "强退");
} }
if (this.players.length) { if (this.players.length) {
ygopro.stoc_send_chat_to_room(this, client.name + " " + '离开了游戏' + (error ? ": " + error : '')); ygopro.stoc_send_chat_to_room(this, (client.name + " 离开了游戏") + (error ? ": " + error : ''));
if (!this["private"] && !this.started && settings.modules.enable_websocket_roomlist) { if (!this["private"] && !this.started && settings.modules.enable_websocket_roomlist) {
roomlist.update(this); roomlist.update(this);
} }
......
...@@ -11,7 +11,7 @@ execFile = require('child_process').execFile ...@@ -11,7 +11,7 @@ execFile = require('child_process').execFile
#三方库 #三方库
_ = require 'underscore' _ = require 'underscore'
_.str = require 'underscore.string' _.str = require 'underscore.string'
_.mixin(_.str.exports()); _.mixin(_.str.exports())
request = require 'request' request = require 'request'
...@@ -135,7 +135,7 @@ net.createServer (client) -> ...@@ -135,7 +135,7 @@ net.createServer (client) ->
return return
redisdb.expire("replay:"+replay.replay_id, 60*60*48) redisdb.expire("replay:"+replay.replay_id, 60*60*48)
buffer=new Buffer(replay.replay_buffer,'binary') buffer=new Buffer(replay.replay_buffer,'binary')
zlib.unzip buffer, (err, replay_buffer) => zlib.unzip buffer, (err, replay_buffer) ->
if err if err
log.info err log.info err
ygopro.stoc_send_chat(client, "播放录像出错", ygopro.constants.COLORS.RED) ygopro.stoc_send_chat(client, "播放录像出错", ygopro.constants.COLORS.RED)
...@@ -268,7 +268,7 @@ net.createServer (client) -> ...@@ -268,7 +268,7 @@ net.createServer (client) ->
#功能模块 #功能模块
ygopro.ctos_follow 'PLAYER_INFO', true, (buffer, info, client, server)-> ygopro.ctos_follow 'PLAYER_INFO', true, (buffer, info, client, server)->
name = info.name.split("$")[0]; name = info.name.split("$")[0]
struct = ygopro.structs["CTOS_PlayerInfo"] struct = ygopro.structs["CTOS_PlayerInfo"]
struct._setBuff(buffer) struct._setBuff(buffer)
struct.set("name", name) struct.set("name", name)
...@@ -289,9 +289,9 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -289,9 +289,9 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
else if info.pass.toUpperCase()=="R" and settings.modules.enable_cloud_replay else if info.pass.toUpperCase()=="R" and settings.modules.enable_cloud_replay
ygopro.stoc_send_chat(client,"以下是您近期的云录像,密码处输入 R#录像编号 即可观看", ygopro.constants.COLORS.BABYBLUE) ygopro.stoc_send_chat(client,"以下是您近期的云录像,密码处输入 R#录像编号 即可观看", ygopro.constants.COLORS.BABYBLUE)
redisdb.lrange client.remoteAddress+":replays", 0, 2, (err, result)=> redisdb.lrange client.remoteAddress+":replays", 0, 2, (err, result)->
_.each result, (replay_id,id)=> _.each result, (replay_id,id)->
redisdb.hgetall "replay:"+replay_id, (err, replay)=> redisdb.hgetall "replay:"+replay_id, (err, replay)->
if err or !replay if err or !replay
log.info err log.info err
return return
...@@ -300,7 +300,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -300,7 +300,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
return return
return return
#强行等待异步执行完毕_(:з」∠)_ #强行等待异步执行完毕_(:з」∠)_
setTimeout (()=> setTimeout (()->
ygopro.stoc_send client, 'ERROR_MSG',{ ygopro.stoc_send client, 'ERROR_MSG',{
msg: 1 msg: 1
code: 2 code: 2
...@@ -310,7 +310,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -310,7 +310,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
else if info.pass[0...2].toUpperCase()=="R#" and settings.modules.enable_cloud_replay else if info.pass[0...2].toUpperCase()=="R#" and settings.modules.enable_cloud_replay
replay_id=info.pass.split("#")[1] replay_id=info.pass.split("#")[1]
if (replay_id>0 and replay_id<=9) if (replay_id>0 and replay_id<=9)
redisdb.lindex client.remoteAddress+":replays", replay_id-1, (err, replay_id)=> redisdb.lindex client.remoteAddress+":replays", replay_id-1, (err, replay_id)->
if err or !replay_id if err or !replay_id
log.info err log.info err
ygopro.stoc_send_chat(client, "没有找到录像", ygopro.constants.COLORS.RED) ygopro.stoc_send_chat(client, "没有找到录像", ygopro.constants.COLORS.RED)
...@@ -417,7 +417,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -417,7 +417,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
# 4 join match # 4 join match
switch action switch action
when 1,2 when 1,2
name = crypto.createHash('md5').update(info.pass + client.name).digest('base64')[0...10].replace('+', '-').replace('/', '_'); name = crypto.createHash('md5').update(info.pass + client.name).digest('base64')[0...10].replace('+', '-').replace('/', '_')
if Room.find_by_name(name) if Room.find_by_name(name)
ygopro.stoc_send_chat(client, '主机密码不正确 (Already Existed)', ygopro.constants.COLORS.RED) ygopro.stoc_send_chat(client, '主机密码不正确 (Already Existed)', ygopro.constants.COLORS.RED)
ygopro.stoc_send client, 'ERROR_MSG', { ygopro.stoc_send client, 'ERROR_MSG', {
...@@ -472,7 +472,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -472,7 +472,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
client.room.connect(client) client.room.connect(client)
if id = users_cache[client.name] if id = users_cache[client.name]
secret = id % 65535 + 1; secret = id % 65535 + 1
decrypted_buffer = new Buffer(6) decrypted_buffer = new Buffer(6)
for i in [0, 2, 4] for i in [0, 2, 4]
decrypted_buffer.writeUInt16LE(buffer.readUInt16LE(i) ^ secret, i) decrypted_buffer.writeUInt16LE(buffer.readUInt16LE(i) ^ secret, i)
...@@ -490,7 +490,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -490,7 +490,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
json: true json: true
, (error, response, body)-> , (error, response, body)->
if body and body.user if body and body.user
secret = body.user.id % 65535 + 1; secret = body.user.id % 65535 + 1
decrypted_buffer = new Buffer(6) decrypted_buffer = new Buffer(6)
for i in [0, 2, 4] for i in [0, 2, 4]
decrypted_buffer.writeUInt16LE(buffer.readUInt16LE(i) ^ secret, i) decrypted_buffer.writeUInt16LE(buffer.readUInt16LE(i) ^ secret, i)
...@@ -668,7 +668,7 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)-> ...@@ -668,7 +668,7 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
#log.info 'MSG', ygopro.constants.MSG[msg] #log.info 'MSG', ygopro.constants.MSG[msg]
if ygopro.constants.MSG[msg] == 'START' if ygopro.constants.MSG[msg] == 'START'
playertype = buffer.readUInt8(1) playertype = buffer.readUInt8(1)
client.is_first = !(playertype & 0xf); client.is_first = !(playertype & 0xf)
client.lp = client.room.hostinfo.start_lp client.lp = client.room.hostinfo.start_lp
#ygopro.stoc_send_chat_to_room(client.room, "LP跟踪调试信息: #{client.name} 初始LP #{client.lp}") #ygopro.stoc_send_chat_to_room(client.room, "LP跟踪调试信息: #{client.name} 初始LP #{client.lp}")
...@@ -728,8 +728,8 @@ ygopro.ctos_follow 'HS_KICK', true, (buffer, info, client, server)-> ...@@ -728,8 +728,8 @@ ygopro.ctos_follow 'HS_KICK', true, (buffer, info, client, server)->
return false return false
ygopro.stoc_follow 'TYPE_CHANGE', false, (buffer, info, client, server)-> ygopro.stoc_follow 'TYPE_CHANGE', false, (buffer, info, client, server)->
selftype = info.type & 0xf; selftype = info.type & 0xf
is_host = ((info.type >> 4) & 0xf) != 0; is_host = ((info.type >> 4) & 0xf) != 0
client.is_host = is_host client.is_host = is_host
client.pos = selftype client.pos = selftype
#console.log "TYPE_CHANGE to #{client.name}:", info, selftype, is_host #console.log "TYPE_CHANGE to #{client.name}:", info, selftype, is_host
...@@ -737,8 +737,8 @@ ygopro.stoc_follow 'TYPE_CHANGE', false, (buffer, info, client, server)-> ...@@ -737,8 +737,8 @@ ygopro.stoc_follow 'TYPE_CHANGE', false, (buffer, info, client, server)->
ygopro.stoc_follow 'HS_PLAYER_CHANGE', false, (buffer, info, client, server)-> ygopro.stoc_follow 'HS_PLAYER_CHANGE', false, (buffer, info, client, server)->
return unless client.room and client.room.max_player and client.is_host return unless client.room and client.room.max_player and client.is_host
pos = info.status >> 4; pos = info.status >> 4
is_ready = (info.status & 0xf) == 9; is_ready = (info.status & 0xf) == 9
if pos < client.room.max_player if pos < client.room.max_player
client.room.ready_player_count_without_host = 0 client.room.ready_player_count_without_host = 0
for player in client.room.players for player in client.room.players
...@@ -790,12 +790,12 @@ if settings.modules.tips ...@@ -790,12 +790,12 @@ if settings.modules.tips
return return
if settings.modules.mycard_auth and process.env.MYCARD_AUTH_DATABASE if settings.modules.mycard_auth and process.env.MYCARD_AUTH_DATABASE
pg = require('pg'); pg = require('pg')
pg.connect process.env.MYCARD_AUTH_DATABASE, (error, client, done)-> pg.connect process.env.MYCARD_AUTH_DATABASE, (error, client, done)->
throw error if error throw error if error
client.query 'SELECT username, id from users', (error, result)-> client.query 'SELECT username, id from users', (error, result)->
throw error if error throw error if error
done(); done()
for row in result.rows for row in result.rows
users_cache[row.username] = row.id users_cache[row.username] = row.id
console.log("users loaded", _.keys(users_cache).length) console.log("users loaded", _.keys(users_cache).length)
...@@ -928,10 +928,10 @@ if settings.modules.http ...@@ -928,10 +928,10 @@ if settings.modules.http
if u.pathname == '/api/getrooms' if u.pathname == '/api/getrooms'
if !pass_validated if !pass_validated
response.writeHead(200); response.writeHead(200)
response.end(u.query.callback + '( {"rooms":[{"roomid":"0","roomname":"密码错误","needpass":"true"}]} );') response.end(u.query.callback + '( {"rooms":[{"roomid":"0","roomname":"密码错误","needpass":"true"}]} );')
else else
response.writeHead(200); response.writeHead(200)
roomsjson = JSON.stringify rooms: (for room in Room.all when room.established roomsjson = JSON.stringify rooms: (for room in Room.all when room.established
pid: room.process.pid.toString(), pid: room.process.pid.toString(),
roomid: room.port.toString(), roomid: room.port.toString(),
...@@ -948,8 +948,8 @@ if settings.modules.http ...@@ -948,8 +948,8 @@ if settings.modules.http
else if u.pathname == '/api/message' else if u.pathname == '/api/message'
if !pass_validated if !pass_validated
response.writeHead(200); response.writeHead(200)
response.end(u.query.callback + "( '密码错误', 0 );"); response.end(u.query.callback + "( '密码错误', 0 );")
return return
if u.query.shout if u.query.shout
...@@ -976,12 +976,12 @@ if settings.modules.http ...@@ -976,12 +976,12 @@ if settings.modules.http
response.end(u.query.callback + "( 'ban ok', '" + u.query.ban + "' );") response.end(u.query.callback + "( 'ban ok', '" + u.query.ban + "' );")
else else
response.writeHead(404); response.writeHead(404)
response.end(); response.end()
else else
response.writeHead(404); response.writeHead(404)
response.end(); response.end()
return return
http_server = http.createServer(requestListener) http_server = http.createServer(requestListener)
......
...@@ -184,19 +184,17 @@ ...@@ -184,19 +184,17 @@
} }
redisdb.expire("replay:" + replay.replay_id, 60 * 60 * 48); redisdb.expire("replay:" + replay.replay_id, 60 * 60 * 48);
buffer = new Buffer(replay.replay_buffer, 'binary'); buffer = new Buffer(replay.replay_buffer, 'binary');
zlib.unzip(buffer, (function(_this) { zlib.unzip(buffer, function(err, replay_buffer) {
return function(err, replay_buffer) { if (err) {
if (err) { log.info(err);
log.info(err); ygopro.stoc_send_chat(client, "播放录像出错", ygopro.constants.COLORS.RED);
ygopro.stoc_send_chat(client, "播放录像出错", ygopro.constants.COLORS.RED);
client.end();
return;
}
ygopro.stoc_send_chat(client, "正在观看云录像:R#" + replay.replay_id + " " + replay.player_names + " " + replay.date_time, ygopro.constants.COLORS.BABYBLUE);
client.write(replay_buffer);
client.end(); client.end();
}; return;
})(this)); }
ygopro.stoc_send_chat(client, "正在观看云录像:R#" + replay.replay_id + " " + replay.player_names + " " + replay.date_time, ygopro.constants.COLORS.BABYBLUE);
client.write(replay_buffer);
client.end();
});
}; };
} }
ctos_buffer = new Buffer(0); ctos_buffer = new Buffer(0);
...@@ -344,46 +342,40 @@ ...@@ -344,46 +342,40 @@
client.end(); client.end();
} else if (info.pass.toUpperCase() === "R" && settings.modules.enable_cloud_replay) { } else if (info.pass.toUpperCase() === "R" && settings.modules.enable_cloud_replay) {
ygopro.stoc_send_chat(client, "以下是您近期的云录像,密码处输入 R#录像编号 即可观看", ygopro.constants.COLORS.BABYBLUE); ygopro.stoc_send_chat(client, "以下是您近期的云录像,密码处输入 R#录像编号 即可观看", ygopro.constants.COLORS.BABYBLUE);
redisdb.lrange(client.remoteAddress + ":replays", 0, 2, (function(_this) { redisdb.lrange(client.remoteAddress + ":replays", 0, 2, function(err, result) {
return function(err, result) { _.each(result, function(replay_id, id) {
_.each(result, function(replay_id, id) { redisdb.hgetall("replay:" + replay_id, function(err, replay) {
redisdb.hgetall("replay:" + replay_id, function(err, replay) { if (err || !replay) {
if (err || !replay) { log.info(err);
log.info(err); return;
return; }
} ygopro.stoc_send_chat(client, "<" + (id - 0 + 1) + "> R#" + replay_id + " " + replay.player_names + " " + replay.date_time, ygopro.constants.COLORS.BABYBLUE);
ygopro.stoc_send_chat(client, "<" + (id - 0 + 1) + "> R#" + replay_id + " " + replay.player_names + " " + replay.date_time, ygopro.constants.COLORS.BABYBLUE);
});
});
};
})(this));
setTimeout(((function(_this) {
return function() {
ygopro.stoc_send(client, 'ERROR_MSG', {
msg: 1,
code: 2
}); });
return client.end(); });
}; });
})(this)), 500); setTimeout((function() {
ygopro.stoc_send(client, 'ERROR_MSG', {
msg: 1,
code: 2
});
return client.end();
}), 500);
} else if (info.pass.slice(0, 2).toUpperCase() === "R#" && settings.modules.enable_cloud_replay) { } else if (info.pass.slice(0, 2).toUpperCase() === "R#" && settings.modules.enable_cloud_replay) {
replay_id = info.pass.split("#")[1]; replay_id = info.pass.split("#")[1];
if (replay_id > 0 && replay_id <= 9) { if (replay_id > 0 && replay_id <= 9) {
redisdb.lindex(client.remoteAddress + ":replays", replay_id - 1, (function(_this) { redisdb.lindex(client.remoteAddress + ":replays", replay_id - 1, function(err, replay_id) {
return function(err, replay_id) { if (err || !replay_id) {
if (err || !replay_id) { log.info(err);
log.info(err); ygopro.stoc_send_chat(client, "没有找到录像", ygopro.constants.COLORS.RED);
ygopro.stoc_send_chat(client, "没有找到录像", ygopro.constants.COLORS.RED); ygopro.stoc_send(client, 'ERROR_MSG', {
ygopro.stoc_send(client, 'ERROR_MSG', { msg: 1,
msg: 1, code: 2
code: 2 });
}); client.end();
client.end(); return;
return; }
} redisdb.hgetall("replay:" + replay_id, client.open_cloud_replay);
redisdb.hgetall("replay:" + replay_id, client.open_cloud_replay); });
};
})(this));
} else if (replay_id) { } else if (replay_id) {
redisdb.hgetall("replay:" + replay_id, client.open_cloud_replay); redisdb.hgetall("replay:" + replay_id, client.open_cloud_replay);
} else { } else {
......
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