Commit 1396cf30 authored by 神楽坂玲奈's avatar 神楽坂玲奈

auto lflist

parent 54869740
......@@ -12,7 +12,6 @@
"enable_random_duel": false,
"mycard_auth": "https://ygobbs.com",
"post_start_watching": true,
"TCG_banlist_id": 8,
"enable_TCG_as_default": false,
"http": {
"port": 7922,
......
......@@ -9,21 +9,23 @@ roomlist = require './roomlist' if settings.modules.enable_websocket_roomlist
bunyan = require 'bunyan'
moment = require 'moment'
#redis = require 'redis'
moment.locale('zh-cn', { relativeTime : {
future : '%s内',
past : '%s前',
s : '%d秒',
m : '1分钟',
mm : '%d分钟',
h : '1小时',
hh : '%d小时',
d : '1天',
dd : '%d天',
M : '1个月',
MM : '%d个月',
y : '1年',
yy : '%d年'
}})
moment.locale('zh-cn', {
relativeTime: {
future: '%s内',
past: '%s前',
s: '%d秒',
m: '1分钟',
mm: '%d分钟',
h: '1小时',
hh: '%d小时',
d: '1天',
dd: '%d天',
M: '1个月',
MM: '%d个月',
y: '1年',
yy: '%d年'
}
})
log = bunyan.createLogger name: "mycard-room"
#redisdb = redis.createClient host: "127.0.0.1", port: settings.modules.redis_port
......@@ -58,16 +60,16 @@ class Room
@ban_player: (name, ip, reason)->
bannedplayer = _.find Room.players_banned, (bannedplayer)->
ip==bannedplayer.ip
ip == bannedplayer.ip
if bannedplayer
bannedplayer.count=bannedplayer.count+1
bantime=if bannedplayer.count > 3 then Math.pow(2,bannedplayer.count-3)*2 else 0
bannedplayer.time=if moment()<bannedplayer.time then moment(bannedplayer.time).add(bantime,'m') else moment().add(bantime,'m')
bannedplayer.count = bannedplayer.count + 1
bantime = if bannedplayer.count > 3 then Math.pow(2, bannedplayer.count - 3) * 2 else 0
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)->
bannedreason==reason
bannedplayer.need_tip=true;
bannedreason == reason
bannedplayer.need_tip = true;
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)
log.info("banned", name, ip, reason, bannedplayer.count)
return
......@@ -77,41 +79,41 @@ class Room
return @find_or_create_random(name.toUpperCase(), player_ip)
if room = @find_by_name(name)
return room
else if get_memory_usage()>=90
else if get_memory_usage() >= 90
return null
else
return new Room(name)
@find_or_create_random: (type, player_ip)->
bannedplayer = _.find Room.players_banned, (bannedplayer)->
return player_ip==bannedplayer.ip
return player_ip == bannedplayer.ip
if bannedplayer
if bannedplayer.count > 6 and moment()<bannedplayer.time
return {"error":"因为您近期在游戏中多次#{bannedplayer.reasons.join('、')},您已被禁止使用随机对战功能,将在#{moment(bannedplayer.time).fromNow(true)}后解封"}
if bannedplayer.count > 3 and moment()<bannedplayer.time and bannedplayer.need_tip
bannedplayer.need_tip=false
return {"error":"因为您近期在游戏中#{bannedplayer.reasons.join('、')},在#{moment(bannedplayer.time).fromNow(true)}内您随机对战时只能遇到其他违规玩家"}
if bannedplayer.count > 6 and moment() < bannedplayer.time
return {"error": "因为您近期在游戏中多次#{bannedplayer.reasons.join('、')},您已被禁止使用随机对战功能,将在#{moment(bannedplayer.time).fromNow(true)}后解封"}
if bannedplayer.count > 3 and moment() < bannedplayer.time and bannedplayer.need_tip
bannedplayer.need_tip = false
return {"error": "因为您近期在游戏中#{bannedplayer.reasons.join('、')},在#{moment(bannedplayer.time).fromNow(true)}内您随机对战时只能遇到其他违规玩家"}
else if bannedplayer.need_tip
bannedplayer.need_tip=false
return {"error":"系统检测到您近期在游戏中#{bannedplayer.reasons.join('、')},若您违规超过3次,将受到惩罚"}
bannedplayer.need_tip = false
return {"error": "系统检测到您近期在游戏中#{bannedplayer.reasons.join('、')},若您违规超过3次,将受到惩罚"}
else if bannedplayer.count > 2
bannedplayer.need_tip=true
bannedplayer.need_tip = true
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)->
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
result.welcome = '对手已经在等你了,开始决斗吧!'
#log.info 'found room', player_name
#log.info 'found room', player_name
else
type = if type then type else 'S'
name = type + ',RANDOM#' + Math.floor(Math.random()*100000)
name = type + ',RANDOM#' + Math.floor(Math.random() * 100000)
result = new Room(name)
result.random_type = type
result.max_player = max_player
result.welcome = '已建立随机对战房间,正在等待对手!'
result.deprecated=playerbanned
#log.info 'create room', player_name, name
result.deprecated = playerbanned
#log.info 'create room', player_name, name
return result
@find_by_name: (name)->
......@@ -125,12 +127,12 @@ class Room
room.port == port
@validate: (name)->
client_name_and_pass = name.split('$',2)
client_name_and_pass = name.split('$', 2)
client_name = client_name_and_pass[0]
client_pass = client_name_and_pass[1]
return true if !client_pass
!_.find Room.all, (room)->
room_name_and_pass = room.name.split('$',2)
room_name_and_pass = room.name.split('$', 2)
room_name = room_name_and_pass[0]
room_pass = room_name_and_pass[1]
client_name == room_name and client_pass != room_pass
......@@ -150,7 +152,7 @@ class Room
Room.all.push this
@hostinfo ||=
lflist: 0
lflist: (list)-> !list.tcg and list.date.isBefore()
rule: if settings.modules.enable_TCG_as_default then 2 else 0
mode: 0
enable_priority: false
......@@ -177,8 +179,8 @@ class Room
@hostinfo.start_hand = parseInt(param[7])
@hostinfo.draw_count = parseInt(param[8])
else if (((param = name.match /(.+)#/) != null) and ( (param[1].length<=2 and param[1].match(/(S|N|M|T)(0|1|2|T|A)/i)) or (param[1].match(/^(S|N|M|T)(0|1|2|O|T|A)(0|1|O|T)/i)) ) )
rule=param[1].toUpperCase()
else if (((param = name.match /(.+)#/) != null) and ( (param[1].length <= 2 and param[1].match(/(S|N|M|T)(0|1|2|T|A)/i)) or (param[1].match(/^(S|N|M|T)(0|1|2|O|T|A)(0|1|O|T)/i)) ) )
rule = param[1].toUpperCase()
#log.info "C", rule
switch rule.charAt(0)
......@@ -200,12 +202,12 @@ class Room
switch rule.charAt(2)
when "1","T"
@hostinfo.lflist = settings.modules.TCG_banlist_id
@hostinfo.lflist = _.findIndex settings.lflist, (list)-> list.tcg and list.date.isBefore()
else
@hostinfo.lflist = 0
@hostinfo.lflist = _.findIndex settings.lflist, (list)-> !list.tcg and list.date.isBefore()
if ((param = parseInt(rule.charAt(3).match(/\d/))) >= 0)
@hostinfo.time_limit=param*60
@hostinfo.time_limit = param * 60
switch rule.charAt(4)
when "T","1"
......@@ -226,16 +228,16 @@ class Room
@hostinfo.no_shuffle_deck = false
if ((param = parseInt(rule.charAt(7).match(/\d/))) > 0)
@hostinfo.start_lp=param*4000
@hostinfo.start_lp = param * 4000
if ((param = parseInt(rule.charAt(8).match(/\d/))) > 0)
@hostinfo.start_hand=param
@hostinfo.start_hand = param
if ((param = parseInt(rule.charAt(9).match(/\d/))) >= 0)
@hostinfo.draw_count=param
@hostinfo.draw_count = param
else if ((param = name.match /(.+)#/) != null)
rule=param[1].toUpperCase()
rule = param[1].toUpperCase()
#log.info "233", rule
if (rule.match /(^|,|,)(M|MATCH)(,|,|$)/)
......@@ -247,7 +249,7 @@ class Room
if (rule.match /(^|,|,)(TCGONLY|TO)(,|,|$)/)
@hostinfo.rule = 1
@hostinfo.lflist = settings.modules.TCG_banlist_id
@hostinfo.lflist = _.findIndex settings.lflist, (list)-> list.tcg and list.date.isBefore()
if (rule.match /(^|,|,)(OCGONLY|OO)(,|,|$)/)
@hostinfo.rule = 0
......@@ -264,7 +266,7 @@ class Room
if (param = rule.match /(^|,|,)(TIME|TM|TI)(\d+)(,|,|$)/)
time_limit = parseInt(param[3])
if (time_limit < 0) then time_limit = 180
if (time_limit >= 1 and time_limit <= 60) then time_limit = time_limit*60
if (time_limit >= 1 and time_limit <= 60) then time_limit = time_limit * 60
if (time_limit >= 999) then time_limit = 999
@hostinfo.time_limit = time_limit
......@@ -280,7 +282,7 @@ class Room
@hostinfo.draw_count = draw_count
if (param = rule.match /(^|,|,)(LFLIST|LF)(\d+)(,|,|$)/)
lflist = parseInt(param[3])-1
lflist = parseInt(param[3]) - 1
@hostinfo.lflist = lflist
if (rule.match /(^|,|,)(NOLFLIST|NF)(,|,|$)/)
......@@ -298,7 +300,9 @@ class Room
if (rule.match /(^|,|,)(IGPRIORITY|PR)(,|,|$)/)
@hostinfo.enable_priority = true
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]
try
@process = spawn './ygopro', param, {cwd: settings.ygopro_path}
......@@ -312,7 +316,7 @@ class Room
roomlist.create(this) if !@private and settings.modules.enable_websocket_roomlist
@port = parseInt data
_.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.established = true
player.pre_establish_buffers = []
......@@ -320,19 +324,21 @@ class Room
return
console.log @windbot
if @windbot
spawn 'mono', ['WindBot.exe'], {cwd: 'windbot', env: {
YGOPRO_VERSION: settings.version
YGOPRO_HOST: '127.0.0.1'
YGOPRO_PORT: @port
YGOPRO_NAME: @windbot.name
YGOPRO_DECK: @windbot.deck
YGOPRO_DIALOG: @windbot.dialog
}}
spawn 'mono', ['WindBot.exe'], {
cwd: 'windbot', env: {
YGOPRO_VERSION: settings.version
YGOPRO_HOST: '127.0.0.1'
YGOPRO_PORT: @port
YGOPRO_NAME: @windbot.name
YGOPRO_DECK: @windbot.deck
YGOPRO_DIALOG: @windbot.dialog
}
}
return
catch
@error = "建立房间失败,请重试"
delete: ->
#积分
#积分
return if @deleted
#log.info 'room-delete', this.name, Room.all.length
###
......@@ -366,30 +372,30 @@ class Room
return
get_playing_player: ->
playing_player=[]
playing_player = []
_.each @players, (player)=>
if player.pos < 4 then playing_player.push player
return
return playing_player
get_host: ->
host_player=null
host_player = null
_.each @players, (player)=>
if player.is_host then host_player=player
if player.is_host then host_player = player
return
return host_player
connect: (client)->
@players.push client
client.ip=client.remoteAddress
client.ip = client.remoteAddress
if @random_type
host_player=@get_host()
host_player = @get_host()
if host_player && (host_player != client)
#进来时已经有人在等待了,互相记录为匹配过
#进来时已经有人在等待了,互相记录为匹配过
Room.players_oppentlist[host_player.remoteAddress] = client.remoteAddress
Room.players_oppentlist[client.remoteAddress] = host_player.remoteAddress
else
#第一个玩家刚进来,还没就位
#第一个玩家刚进来,还没就位
Room.players_oppentlist[client.remoteAddress] = null
if @established
......@@ -406,17 +412,17 @@ class Room
ygopro.stoc_send_chat_to_room this, "#{client.name} #{'退出了观战'}#{if error then ": #{error}" else ''}"
index = _.indexOf(@watchers, client)
@watchers.splice(index, 1) unless index == -1
#client.room = null
#client.room = null
else
index = _.indexOf(@players, client)
@players.splice(index, 1) unless index == -1
#log.info(@started,@disconnector,client.room.random_type)
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, "强退")
if @players.length
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
#client.room = null
#client.room = null
else
@process.kill()
#client.room = null
......
......@@ -204,7 +204,9 @@
this.welcome = '';
Room.all.push(this);
this.hostinfo || (this.hostinfo = {
lflist: 0,
lflist: function(list) {
return !list.tcg && list.date.isBefore();
},
rule: settings.modules.enable_TCG_as_default ? 2 : 0,
mode: 0,
enable_priority: false,
......@@ -259,10 +261,14 @@
switch (rule.charAt(2)) {
case "1":
case "T":
this.hostinfo.lflist = settings.modules.TCG_banlist_id;
this.hostinfo.lflist = _.findIndex(settings.lflist, function(list) {
return list.tcg && list.date.isBefore();
});
break;
default:
this.hostinfo.lflist = 0;
this.hostinfo.lflist = _.findIndex(settings.lflist, function(list) {
return !list.tcg && list.date.isBefore();
});
}
if ((param = parseInt(rule.charAt(3).match(/\d/))) >= 0) {
this.hostinfo.time_limit = param * 60;
......@@ -311,7 +317,9 @@
}
if (rule.match(/(^|,|,)(TCGONLY|TO)(,|,|$)/)) {
this.hostinfo.rule = 1;
this.hostinfo.lflist = settings.modules.TCG_banlist_id;
this.hostinfo.lflist = _.findIndex(settings.lflist, function(list) {
return list.tcg && list.date.isBefore();
});
}
if (rule.match(/(^|,|,)(OCGONLY|OO)(,|,|$)/)) {
this.hostinfo.rule = 0;
......
Subproject commit 58be174a410a1595e36105dc3ba6951ae70815ee
Subproject commit 1da1c4fbbb8dedf2c8655d9055e417b85548e1cf
......@@ -28,8 +28,11 @@ moment = require 'moment'
settings = require './config.json'
settings.BANNED_user = []
settings.BANNED_IP = []
settings.modules.hang_timeout=90
settings.modules.hang_timeout = 90
settings.version = parseInt(fs.readFileSync('ygopro/gframe/game.cpp', 'utf8').match(/PRO_VERSION = ([x\d]+)/)[1], '16')
lflist = (for list in fs.readFileSync('ygopro/lflist.conf', 'utf8').match(/![\d\.]+(?: TCG)?/g)
matched = list.match(/!([\d\.]+)(?: (TCG))?/)
{date: moment(matched[1]), tcg: !!matched[2]})
#组件
ygopro = require './ygopro.js'
......@@ -74,7 +77,7 @@ net.createServer (client) ->
#释放处理
client.on 'close', (had_error) ->
#log.info "client closed", client.name, had_error
#log.info "client closed", client.name, had_error
tribute(client)
unless client.closed
client.closed = true
......@@ -83,7 +86,7 @@ net.createServer (client) ->
return
client.on 'error', (error)->
#log.info "client error", client.name, error
#log.info "client error", client.name, error
tribute(client)
unless client.closed
client.closed = error
......@@ -96,7 +99,7 @@ net.createServer (client) ->
return
server.on 'close', (had_error) ->
#log.info "server closed", client.name, had_error
#log.info "server closed", client.name, had_error
tribute(server)
client.room.disconnector = 'server'
server.closed = true unless server.closed
......@@ -106,7 +109,7 @@ net.createServer (client) ->
return
server.on 'error', (error)->
#log.info "server error", client.name, error
#log.info "server error", client.name, error
tribute(server)
client.room.disconnector = 'server'
server.closed = error
......@@ -161,10 +164,10 @@ net.createServer (client) ->
break
else
if ctos_buffer.length >= 2 + ctos_message_length
#console.log "CTOS", ygopro.constants.CTOS[ctos_proto]
#console.log "CTOS", ygopro.constants.CTOS[ctos_proto]
cancel = false
if ygopro.ctos_follows[ctos_proto]
b = ctos_buffer.slice(3, ctos_message_length-1+3)
b = ctos_buffer.slice(3, ctos_message_length - 1 + 3)
if struct = ygopro.structs[ygopro.proto_structs.CTOS[ygopro.constants.CTOS[ctos_proto]]]
struct._setBuff(b)
if ygopro.ctos_follows[ctos_proto].synchronous
......@@ -182,8 +185,8 @@ net.createServer (client) ->
looplimit++
#log.info(looplimit)
if looplimit>800
log.info("error ctos",client.name)
if looplimit > 800
log.info("error ctos", client.name)
server.end()
break
......@@ -220,7 +223,7 @@ net.createServer (client) ->
break
else
if stoc_buffer.length >= 2 + stoc_message_length
#console.log "STOC", ygopro.constants.STOC[stoc_proto]
#console.log "STOC", ygopro.constants.STOC[stoc_proto]
stanzas = stoc_proto
if ygopro.stoc_follows[stoc_proto]
b = stoc_buffer.slice(3, stoc_message_length - 1 + 3)
......@@ -238,8 +241,8 @@ net.createServer (client) ->
looplimit++
#log.info(looplimit)
if looplimit>800
log.info("error stoc",client.name)
if looplimit > 800
log.info("error stoc", client.name)
server.end()
break
return
......@@ -251,19 +254,19 @@ net.createServer (client) ->
#功能模块
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._setBuff(buffer)
struct.set("name",name)
struct.set("name", name)
buffer = struct.buffer
client.name = name
return false
ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
#log.info info
#log.info info
if settings.modules.stop
ygopro.stoc_send_chat(client,settings.modules.stop, 11)
ygopro.stoc_send client, 'ERROR_MSG',{
ygopro.stoc_send_chat(client, settings.modules.stop, 11)
ygopro.stoc_send client, 'ERROR_MSG', {
msg: 1
code: 2
}
......@@ -305,16 +308,16 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
###
else if info.version != settings.version
ygopro.stoc_send_chat(client,settings.modules.update, 11)
ygopro.stoc_send client, 'ERROR_MSG',{
ygopro.stoc_send_chat(client, settings.modules.update, 11)
ygopro.stoc_send client, 'ERROR_MSG', {
msg: 4
code: settings.version
}
client.end()
else if !info.pass.length and !settings.modules.enable_random_duel
ygopro.stoc_send_chat(client,"房间名为空,请填写主机密码", 11)
ygopro.stoc_send client, 'ERROR_MSG',{
ygopro.stoc_send_chat(client, "房间名为空,请填写主机密码", 11)
ygopro.stoc_send client, 'ERROR_MSG', {
msg: 1
code: 2
}
......@@ -327,8 +330,8 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
windbot = _.sample _.filter settings.modules.windbot, (w)->
w.name == name or w.deck == name
if !windbot
ygopro.stoc_send_chat(client,'主机密码不正确 (Invalid Windbot Name)', 11)
ygopro.stoc_send client, 'ERROR_MSG',{
ygopro.stoc_send_chat(client, '主机密码不正确 (Invalid Windbot Name)', 11)
ygopro.stoc_send client, 'ERROR_MSG', {
msg: 1
code: 2
}
......@@ -344,10 +347,10 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
client.room.connect(client)
else if info.pass.length and settings.modules.mycard_auth
ygopro.stoc_send_chat(client,'正在读取用户信息...', 11)
ygopro.stoc_send_chat(client, '正在读取用户信息...', 11)
if info.pass.length <= 8
ygopro.stoc_send_chat(client,'主机密码不正确 (Invalid Length)', 11)
ygopro.stoc_send client, 'ERROR_MSG',{
ygopro.stoc_send_chat(client, '主机密码不正确 (Invalid Length)', 11)
ygopro.stoc_send client, 'ERROR_MSG', {
msg: 1
code: 2
}
......@@ -357,8 +360,8 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
buffer = new Buffer(info.pass[0...8], 'base64')
if buffer.length != 6
ygopro.stoc_send_chat(client,'主机密码不正确 (Invalid Payload Length)', 11)
ygopro.stoc_send client, 'ERROR_MSG',{
ygopro.stoc_send_chat(client, '主机密码不正确 (Invalid Payload Length)', 11)
ygopro.stoc_send client, 'ERROR_MSG', {
msg: 1
code: 2
}
......@@ -373,9 +376,9 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
finish = (buffer)->
action = buffer.readUInt8(1) >> 4
if buffer != decrypted_buffer and action in [1,2,4]
ygopro.stoc_send_chat(client,'主机密码不正确 (Unauthorized)', 11)
ygopro.stoc_send client, 'ERROR_MSG',{
if buffer != decrypted_buffer and action in [1, 2, 4]
ygopro.stoc_send_chat(client, '主机密码不正确 (Unauthorized)', 11)
ygopro.stoc_send client, 'ERROR_MSG', {
msg: 1
code: 2
}
......@@ -388,10 +391,10 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
# 4 join match
switch action
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)
ygopro.stoc_send_chat(client,'主机密码不正确 (Already Existed)', 11)
ygopro.stoc_send client, 'ERROR_MSG',{
ygopro.stoc_send_chat(client, '主机密码不正确 (Already Existed)', 11)
ygopro.stoc_send client, 'ERROR_MSG', {
msg: 1
code: 2
}
......@@ -413,6 +416,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
start_hand: opt3 >> 4
draw_count: opt3 & 0xF
}
@hostinfo.lflist = _.findIndex settings.lflist, (list)-> ((rule == 1) == list.tcg) and list.date.isBefore()
room = new Room(name, options)
room.title = info.pass.slice(8).replace(String.fromCharCode(0xFEFF), ' ')
room.private = action == 2
......@@ -420,8 +424,8 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
name = info.pass.slice(8)
room = Room.find_by_name(name)
if(!room)
ygopro.stoc_send_chat(client,'主机密码不正确 (Not Found)', 11)
ygopro.stoc_send client, 'ERROR_MSG',{
ygopro.stoc_send_chat(client, '主机密码不正确 (Not Found)', 11)
ygopro.stoc_send client, 'ERROR_MSG', {
msg: 1
code: 2
}
......@@ -431,8 +435,8 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
room = Room.find_or_create_by_name('M#' + info.pass.slice(8))
room.private = true
else
ygopro.stoc_send_chat(client,'主机密码不正确 (Invalid Action)', 11)
ygopro.stoc_send client, 'ERROR_MSG',{
ygopro.stoc_send_chat(client, '主机密码不正确 (Invalid Action)', 11)
ygopro.stoc_send client, 'ERROR_MSG', {
msg: 1
code: 2
}
......@@ -444,7 +448,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
if id = users_cache[client.name]
secret = id % 65535 + 1;
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)
if check(decrypted_buffer)
return finish(decrypted_buffer)
......@@ -458,42 +462,42 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
api_username: client.name,
skip_track_visit: true
json: true
, (error, response, body)->
if body and body.user
secret = body.user.id % 65535 + 1;
decrypted_buffer = new Buffer(6)
for i in [0,2,4]
decrypted_buffer.writeUInt16LE(buffer.readUInt16LE(i) ^ secret, i)
if check(decrypted_buffer)
buffer = decrypted_buffer
# buffer != decrypted_buffer ==> auth failed
if !check(buffer)
ygopro.stoc_send_chat(client,'主机密码不正确 (Checksum Failed)', 11)
ygopro.stoc_send client, 'ERROR_MSG',{
msg: 1
code: 2
}
client.end()
return
users_cache[client.name] = body.user.id
finish(buffer)
, (error, response, body)->
if body and body.user
secret = body.user.id % 65535 + 1;
decrypted_buffer = new Buffer(6)
for i in [0, 2, 4]
decrypted_buffer.writeUInt16LE(buffer.readUInt16LE(i) ^ secret, i)
if check(decrypted_buffer)
buffer = decrypted_buffer
# buffer != decrypted_buffer ==> auth failed
if !check(buffer)
ygopro.stoc_send_chat(client, '主机密码不正确 (Checksum Failed)', 11)
ygopro.stoc_send client, 'ERROR_MSG', {
msg: 1
code: 2
}
client.end()
return
users_cache[client.name] = body.user.id
finish(buffer)
else if info.pass.length && !Room.validate(info.pass)
#ygopro.stoc_send client, 'ERROR_MSG',{
# msg: 1
# code: 1 #这返错有问题,直接双ygopro直连怎么都正常,在这里就经常弹不出提示
#}
ygopro.stoc_send_chat(client,"房间密码不正确", 11)
ygopro.stoc_send client, 'ERROR_MSG',{
#ygopro.stoc_send client, 'ERROR_MSG',{
# msg: 1
# code: 1 #这返错有问题,直接双ygopro直连怎么都正常,在这里就经常弹不出提示
#}
ygopro.stoc_send_chat(client, "房间密码不正确", 11)
ygopro.stoc_send client, 'ERROR_MSG', {
msg: 1
code: 2
}
client.end()
else if client.name == '[INCORRECT]' #模拟用户验证
ygopro.stoc_send client, 'ERROR_MSG',{
ygopro.stoc_send client, 'ERROR_MSG', {
msg: 1
code: 2
}
......@@ -502,8 +506,8 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
else if _.indexOf(settings.BANNED_user, client.name) > -1 #账号被封
settings.BANNED_IP.push(client.remoteAddress)
log.info("BANNED USER LOGIN", client.name, client.remoteAddress)
ygopro.stoc_send_chat(client,"您的账号已被封禁", 11)
ygopro.stoc_send client, 'ERROR_MSG',{
ygopro.stoc_send_chat(client, "您的账号已被封禁", 11)
ygopro.stoc_send client, 'ERROR_MSG', {
msg: 1
code: 2
}
......@@ -511,33 +515,33 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
else if _.indexOf(settings.BANNED_IP, client.remoteAddress) > -1 #IP被封
log.info("BANNED IP LOGIN", client.name, client.remoteAddress)
ygopro.stoc_send_chat(client,"您的账号已被封禁", 11)
ygopro.stoc_send client, 'ERROR_MSG',{
ygopro.stoc_send_chat(client, "您的账号已被封禁", 11)
ygopro.stoc_send client, 'ERROR_MSG', {
msg: 1
code: 2
}
client.end()
else
#log.info 'join_game',info.pass, client.name
#log.info 'join_game',info.pass, client.name
room = Room.find_or_create_by_name(info.pass, client.remoteAddress)
if !room
ygopro.stoc_send_chat(client,"服务器已经爆满,请稍候再试", 11)
ygopro.stoc_send client, 'ERROR_MSG',{
ygopro.stoc_send_chat(client, "服务器已经爆满,请稍候再试", 11)
ygopro.stoc_send client, 'ERROR_MSG', {
msg: 1
code: 2
}
client.end()
else if room.error
ygopro.stoc_send_chat(client, room.error, 11)
ygopro.stoc_send client, 'ERROR_MSG',{
ygopro.stoc_send client, 'ERROR_MSG', {
msg: 1
code: 2
}
client.end()
else if room.started
if settings.modules.post_start_watching
client.room=room
client.room = room
client.is_post_watcher = true
ygopro.stoc_send_chat_to_room client.room, "#{client.name} 加入了观战"
client.room.watchers.push client
......@@ -545,19 +549,19 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
for buffer in client.room.watcher_buffers
client.write buffer
else
ygopro.stoc_send_chat(client,"决斗已开始,不允许观战", 11)
ygopro.stoc_send client, 'ERROR_MSG',{
ygopro.stoc_send_chat(client, "决斗已开始,不允许观战", 11)
ygopro.stoc_send client, 'ERROR_MSG', {
msg: 1
code: 2
}
client.end()
else
client.room=room
client.room = room
client.room.connect(client)
return
ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)->
#欢迎信息
#欢迎信息
return unless client.room
if settings.modules.welcome
ygopro.stoc_send_chat client, settings.modules.welcome
......@@ -586,7 +590,7 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)->
return
watcher.on 'error', (error)->
#log.error "watcher error", error
#log.error "watcher error", error
return
return
......@@ -596,23 +600,23 @@ if settings.modules.dialogues
request
url: settings.modules.dialogues
json: true
, (error, response, body)->
if _.isString body
log.warn "dialogues bad json", body
else if error or !body
log.warn 'dialogues error', error, response
else
#log.info "dialogues loaded", _.size body
dialogues = body
return
, (error, response, body)->
if _.isString body
log.warn "dialogues bad json", body
else if error or !body
log.warn 'dialogues error', error, response
else
#log.info "dialogues loaded", _.size body
dialogues = body
return
ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
msg = buffer.readInt8(0)
if msg>=10 and msg<30 #SELECT开头的消息
client.room.waiting_for_player=client
client.room.last_active_time=moment()
#log.info("#{ygopro.constants.MSG[msg]}等待#{client.room.waiting_for_player.name}")
if msg >= 10 and msg < 30 #SELECT开头的消息
client.room.waiting_for_player = client
client.room.last_active_time = moment()
#log.info("#{ygopro.constants.MSG[msg]}等待#{client.room.waiting_for_player.name}")
#log.info 'MSG', ygopro.constants.MSG[msg]
if ygopro.constants.MSG[msg] == 'START'
......@@ -620,7 +624,7 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
client.is_first = !(playertype & 0xf);
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}")
###
if ygopro.constants.MSG[msg] == 'WIN' and _.startsWith(client.room.name, 'M#') and client.is_host
pos = buffer.readUInt8(1)
......@@ -672,7 +676,7 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
ygopro.ctos_follow 'HS_KICK', true, (buffer, info, client, server)->
return unless client.room
for player in client.room.players
if player and player.pos==info.pos and player != client
if player and player.pos == info.pos and player != client
ygopro.stoc_send_chat_to_room client.room, "#{player.name} 被请出了房间", 11
return false
......@@ -691,22 +695,22 @@ ygopro.stoc_follow 'HS_PLAYER_CHANGE', false, (buffer, info, client, server)->
if pos < client.room.max_player
client.room.ready_player_count_without_host = 0
for player in client.room.players
if player.pos==pos
if player.pos == pos
player.is_ready = is_ready
unless player.is_host
client.room.ready_player_count_without_host+=player.is_ready
client.room.ready_player_count_without_host += player.is_ready
if client.room.ready_player_count_without_host >= client.room.max_player - 1
#log.info "all ready"
setTimeout (()->wait_room_start(client.room,20);return), 1000
#log.info "all ready"
setTimeout (()-> wait_room_start(client.room, 20);return), 1000
return
wait_room_start = (room,time)->
wait_room_start = (room, time)->
unless !room or room.started or room.ready_player_count_without_host < room.max_player - 1
time-=1
time -= 1
if time
unless time % 5
ygopro.stoc_send_chat_to_room room, "#{if time <= 9 then ' ' else ''}#{time}秒后房主若不开始游戏将被请出房间", if time <= 9 then 11 else 8
setTimeout (()->wait_room_start(room,time);return), 1000
setTimeout (()-> wait_room_start(room, time);return), 1000
else
for player in room.players
if player and player.is_host
......@@ -734,10 +738,10 @@ if settings.modules.tips
request
url: settings.modules.tips
json: true
, (error, response, body)->
tips = body
#log.info "tips loaded", tips.length
return
, (error, response, body)->
tips = body
#log.info "tips loaded", tips.length
return
if settings.modules.mycard_auth and process.env.MYCARD_AUTH_DATABASE
pg = require('pg');
......@@ -759,7 +763,7 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server)->
client.room.dueling_players = []
for player in client.room.players when player.pos != 7
client.room.dueling_players[player.pos] = player
client.room.player_datas.push ip:player.remoteAddress, name:player.name
client.room.player_datas.push ip: player.remoteAddress, name: player.name
if client.room.windbot
client.room.dueling_players[1 - player.pos] = {}
if settings.modules.tips
......@@ -767,8 +771,8 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server)->
return
ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server)->
cancel = _.startsWith(_.trim(info.msg),"/")
client.room.last_active_time=moment() unless cancel or not client.room.random_type
cancel = _.startsWith(_.trim(info.msg), "/")
client.room.last_active_time = moment() unless cancel or not client.room.random_type
switch _.trim(info.msg)
when '/ping'
execFile 'ss', ['-it', "dst #{client.remoteAddress}:#{client.remotePort}"], (error, stdout, stderr)->
......@@ -779,21 +783,21 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server)->
if line.indexOf('rtt') != -1
ygopro.stoc_send_chat_to_room client.room, line
else
#log.warn 'ping', stdout
#log.warn 'ping', stdout
ygopro.stoc_send_chat_to_room client.room, stdout
return
when '/help'
ygopro.stoc_send_chat(client,"YGOSrv233 指令帮助")
ygopro.stoc_send_chat(client,"/help 显示这个帮助信息")
ygopro.stoc_send_chat(client,"/roomname 显示当前房间的名字")
ygopro.stoc_send_chat(client,"/tip 显示一条提示") if settings.modules.tips
ygopro.stoc_send_chat(client, "YGOSrv233 指令帮助")
ygopro.stoc_send_chat(client, "/help 显示这个帮助信息")
ygopro.stoc_send_chat(client, "/roomname 显示当前房间的名字")
ygopro.stoc_send_chat(client, "/tip 显示一条提示") if settings.modules.tips
when '/tip'
ygopro.stoc_send_random_tip(client) if settings.modules.tips
when '/roomname'
ygopro.stoc_send_chat(client,"您当前的房间名是 " + client.room.name) if client.room
ygopro.stoc_send_chat(client, "您当前的房间名是 " + client.room.name) if client.room
when '/test'
ygopro.stoc_send_hint_card_to_room(client.room, 2333365)
......@@ -801,58 +805,58 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server)->
return cancel
ygopro.ctos_follow 'UPDATE_DECK', false, (buffer, info, client, server)->
#log.info info
#log.info info
main = (info.deckbuf[i] for i in [0...info.mainc])
side = (info.deckbuf[i] for i in [info.mainc...info.mainc+info.sidec])
side = (info.deckbuf[i] for i in [info.mainc...info.mainc + info.sidec])
client.main = main
client.side = side
return
ygopro.ctos_follow 'RESPONSE', false, (buffer, info, client, server)->
return unless client.room and client.room.random_type
client.room.last_active_time=moment()
client.room.last_active_time = moment()
return
ygopro.ctos_follow 'HAND_RESULT', false, (buffer, info, client, server)->
return unless client.room and client.room.random_type
if client.is_host
client.room.waiting_for_player=client.room.waiting_for_player2
client.room.last_active_time=moment().subtract(settings.modules.hang_timeout-19, 's')
client.room.waiting_for_player = client.room.waiting_for_player2
client.room.last_active_time = moment().subtract(settings.modules.hang_timeout - 19, 's')
return
ygopro.ctos_follow 'TP_RESULT', false, (buffer, info, client, server)->
return unless client.room and client.room.random_type
client.room.last_active_time=moment()
client.room.last_active_time = moment()
return
ygopro.stoc_follow 'SELECT_HAND', false, (buffer, info, client, server)->
return unless client.room and client.room.random_type
if client.is_host
client.room.waiting_for_player=client
client.room.waiting_for_player = client
else
client.room.waiting_for_player2=client
client.room.last_active_time=moment().subtract(settings.modules.hang_timeout-19, 's')
client.room.waiting_for_player2 = client
client.room.last_active_time = moment().subtract(settings.modules.hang_timeout - 19, 's')
return
ygopro.stoc_follow 'SELECT_TP', false, (buffer, info, client, server)->
return unless client.room and client.room.random_type
client.room.waiting_for_player=client
client.room.last_active_time=moment()
client.room.waiting_for_player = client
client.room.last_active_time = moment()
return
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)
time_passed = Math.floor((moment() - room.last_active_time) / 1000)
#log.info time_passed
if time_passed >= settings.modules.hang_timeout
room.last_active_time=moment()
room.last_active_time = moment()
Room.ban_player(room.waiting_for_player.name, room.waiting_for_player.ip, "挂机")
ygopro.stoc_send_chat_to_room(room, "#{room.waiting_for_player.name} 被系统请出了房间", 11)
room.waiting_for_player.server.end()
else if time_passed >= (settings.modules.hang_timeout-20) and not (time_passed % 10)
ygopro.stoc_send_chat_to_room(room, "#{room.waiting_for_player.name} 已经很久没有操作了,若继续挂机,将于#{settings.modules.hang_timeout-time_passed}秒后被请出房间", 11)
else if time_passed >= (settings.modules.hang_timeout - 20) and not (time_passed % 10)
ygopro.stoc_send_chat_to_room(room, "#{room.waiting_for_player.name} 已经很久没有操作了,若继续挂机,将于#{settings.modules.hang_timeout - time_passed}秒后被请出房间", 11)
return
,1000
, 1000
#http
if settings.modules.http
......@@ -865,13 +869,13 @@ if settings.modules.http
if u.pathname == '/api/getrooms'
if u.query.pass and !pass_validated
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
response.writeHead(200);
roomsjson = JSON.stringify rooms: (for room in Room.all when room.established
pid: room.process.pid.toString(),
roomid: room.port.toString(),
roomname: if pass_validated then room.name else room.name.split('$',2)[0],
roomname: if pass_validated then room.name else room.name.split('$', 2)[0],
needpass: (room.name.indexOf('$') != -1).toString(),
users: (for player in room.players when player.pos?
id: (-1).toString(),
......@@ -880,36 +884,36 @@ if settings.modules.http
),
istart: if room.started then 'start' else 'wait'
)
response.end(u.query.callback+"( " + roomsjson + " );")
response.end(u.query.callback + "( " + roomsjson + " );")
else if u.pathname == '/api/message'
if !pass_validated
response.writeHead(200);
response.end(u.query.callback+"( '密码错误', 0 );");
response.end(u.query.callback + "( '密码错误', 0 );");
return
if u.query.shout
for room in Room.all
ygopro.stoc_send_chat_to_room(room, u.query.shout, 16)
response.writeHead(200)
response.end(u.query.callback+"( 'shout ok', '" + u.query.shout + "' );")
response.end(u.query.callback + "( 'shout ok', '" + u.query.shout + "' );")
else if u.query.stop
if u.query.stop == 'false'
u.query.stop=false
u.query.stop = false
settings.modules.stop = u.query.stop
response.writeHead(200)
response.end(u.query.callback+"( 'stop ok', '" + u.query.stop + "' );")
response.end(u.query.callback + "( 'stop ok', '" + u.query.stop + "' );")
else if u.query.welcome
settings.modules.welcome = u.query.welcome
response.writeHead(200)
response.end(u.query.callback+"( 'welcome ok', '" + u.query.welcome + "' );")
response.end(u.query.callback + "( 'welcome ok', '" + u.query.welcome + "' );")
else if u.query.ban
settings.BANNED_user.push(u.query.ban)
response.writeHead(200)
response.end(u.query.callback+"( 'ban ok', '" + u.query.ban + "' );")
response.end(u.query.callback + "( 'ban ok', '" + u.query.ban + "' );")
else
response.writeHead(404);
......
// Generated by CoffeeScript 1.10.0
(function() {
var Graveyard, Room, _, bunyan, crypto, debug, dialogues, execFile, fs, http, http_server, https, https_server, log, moment, net, options, os, path, pg, request, requestListener, roomlist, settings, tips, tribute, url, users_cache, wait_room_start, ygopro;
var Graveyard, Room, _, bunyan, crypto, debug, dialogues, execFile, fs, http, http_server, https, https_server, lflist, list, log, matched, moment, net, options, os, path, pg, request, requestListener, roomlist, settings, tips, tribute, url, users_cache, wait_room_start, ygopro;
net = require('net');
......@@ -40,6 +40,21 @@
settings.version = parseInt(fs.readFileSync('ygopro/gframe/game.cpp', 'utf8').match(/PRO_VERSION = ([x\d]+)/)[1], '16');
lflist = (function() {
var k, len, ref, results;
ref = fs.readFileSync('ygopro/lflist.conf', 'utf8').match(/![\d\.]+(?: TCG)?/g);
results = [];
for (k = 0, len = ref.length; k < len; k++) {
list = ref[k];
matched = list.match(/!([\d\.]+)(?: (TCG))?/);
results.push({
date: moment(matched[1]),
tcg: !!matched[2]
});
}
return results;
})();
ygopro = require('./ygopro.js');
Room = require('./room.js');
......@@ -442,6 +457,9 @@
start_hand: opt3 >> 4,
draw_count: opt3 & 0xF
};
this.hostinfo.lflist = _.findIndex(settings.lflist, function(list) {
return ((rule === 1) === list.tcg) && list.date.isBefore();
});
room = new Room(name, options);
room.title = info.pass.slice(8).replace(String.fromCharCode(0xFEFF), ' ');
room["private"] = action === 2;
......
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