Commit c5b16dea authored by mercury233's avatar mercury233

format

parent f2c81cd4
...@@ -65,7 +65,7 @@ class Room ...@@ -65,7 +65,7 @@ class Room
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)
log.info("banned", name, ip, reason, bannedplayer.count) log.info("banned", name, ip, reason, bannedplayer.count)
...@@ -78,9 +78,9 @@ class Room ...@@ -78,9 +78,9 @@ class Room
return room return room
else if get_memory_usage()>=90 else if get_memory_usage()>=90
return null return null
else else
return new Room(name) return new Room(name)
@find_or_create_random: (type, player_ip)-> @find_or_create_random: (type, player_ip)->
bannedplayer = _.find Room.players_banned, (bannedplayer)-> bannedplayer = _.find Room.players_banned, (bannedplayer)->
return player_ip==bannedplayer.ip return player_ip==bannedplayer.ip
...@@ -165,7 +165,7 @@ class Room ...@@ -165,7 +165,7 @@ class Room
else if name[0...2] == 'T#' else if name[0...2] == 'T#'
@hostinfo.mode = 2 @hostinfo.mode = 2
@hostinfo.start_lp = 16000 @hostinfo.start_lp = 16000
else if (param = name.match /^(\d)(\d)(T|F)(T|F)(T|F)(\d+),(\d+),(\d+)/i) else if (param = name.match /^(\d)(\d)(T|F)(T|F)(T|F)(\d+),(\d+),(\d+)/i)
@hostinfo.rule = parseInt(param[1]) @hostinfo.rule = parseInt(param[1])
@hostinfo.mode = parseInt(param[2]) @hostinfo.mode = parseInt(param[2])
...@@ -175,11 +175,11 @@ class Room ...@@ -175,11 +175,11 @@ class Room
@hostinfo.start_lp = parseInt(param[6]) @hostinfo.start_lp = parseInt(param[6])
@hostinfo.start_hand = parseInt(param[7]) @hostinfo.start_hand = parseInt(param[7])
@hostinfo.draw_count = parseInt(param[8]) @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)) ) ) 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() rule=param[1].toUpperCase()
#log.info "C", rule #log.info "C", rule
switch rule.charAt(0) switch rule.charAt(0)
when "M","1" when "M","1"
@hostinfo.mode = 1 @hostinfo.mode = 1
...@@ -188,7 +188,7 @@ class Room ...@@ -188,7 +188,7 @@ class Room
@hostinfo.start_lp = 16000 @hostinfo.start_lp = 16000
else else
@hostinfo.mode = 0 @hostinfo.mode = 0
switch rule.charAt(1) switch rule.charAt(1)
when "0","O" when "0","O"
@hostinfo.rule = 0 @hostinfo.rule = 0
...@@ -196,104 +196,104 @@ class Room ...@@ -196,104 +196,104 @@ class Room
@hostinfo.rule = 1 @hostinfo.rule = 1
else else
@hostinfo.rule = 2 @hostinfo.rule = 2
switch rule.charAt(2) switch rule.charAt(2)
when "1","T" when "1","T"
@hostinfo.lflist = settings.modules.TCG_banlist_id @hostinfo.lflist = settings.modules.TCG_banlist_id
else else
@hostinfo.lflist = 0 @hostinfo.lflist = 0
if ((param = parseInt(rule.charAt(3).match(/\d/))) >= 0) if ((param = parseInt(rule.charAt(3).match(/\d/))) >= 0)
@hostinfo.time_limit=param*60 @hostinfo.time_limit=param*60
switch rule.charAt(4) switch rule.charAt(4)
when "T","1" when "T","1"
@hostinfo.enable_priority = true @hostinfo.enable_priority = true
else else
@hostinfo.enable_priority = false @hostinfo.enable_priority = false
switch rule.charAt(5) switch rule.charAt(5)
when "T","1" when "T","1"
@hostinfo.no_check_deck = true @hostinfo.no_check_deck = true
else else
@hostinfo.no_check_deck = false @hostinfo.no_check_deck = false
switch rule.charAt(6) switch rule.charAt(6)
when "T","1" when "T","1"
@hostinfo.no_shuffle_deck = true @hostinfo.no_shuffle_deck = true
else else
@hostinfo.no_shuffle_deck = false @hostinfo.no_shuffle_deck = false
if ((param = parseInt(rule.charAt(7).match(/\d/))) > 0) 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) 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) if ((param = parseInt(rule.charAt(9).match(/\d/))) >= 0)
@hostinfo.draw_count=param @hostinfo.draw_count=param
else if ((param = name.match /(.+)#/) != null) else if ((param = name.match /(.+)#/) != null)
rule=param[1].toUpperCase() rule=param[1].toUpperCase()
#log.info "233", rule #log.info "233", rule
if (rule.match /(^|,|,)(M|MATCH)(,|,|$)/) if (rule.match /(^|,|,)(M|MATCH)(,|,|$)/)
@hostinfo.mode = 1 @hostinfo.mode = 1
if (rule.match /(^|,|,)(T|TAG)(,|,|$)/) if (rule.match /(^|,|,)(T|TAG)(,|,|$)/)
@hostinfo.mode = 2 @hostinfo.mode = 2
@hostinfo.start_lp = 16000 @hostinfo.start_lp = 16000
if (rule.match /(^|,|,)(TCGONLY|TO)(,|,|$)/) if (rule.match /(^|,|,)(TCGONLY|TO)(,|,|$)/)
@hostinfo.rule = 1 @hostinfo.rule = 1
@hostinfo.lflist = settings.modules.TCG_banlist_id @hostinfo.lflist = settings.modules.TCG_banlist_id
if (rule.match /(^|,|,)(OCGONLY|OO)(,|,|$)/) if (rule.match /(^|,|,)(OCGONLY|OO)(,|,|$)/)
@hostinfo.rule = 0 @hostinfo.rule = 0
if (rule.match /(^|,|,)(OT|TCG)(,|,|$)/) if (rule.match /(^|,|,)(OT|TCG)(,|,|$)/)
@hostinfo.rule = 2 @hostinfo.rule = 2
if (param = rule.match /(^|,|,)LP(\d+)(,|,|$)/) if (param = rule.match /(^|,|,)LP(\d+)(,|,|$)/)
start_lp = parseInt(param[2]) start_lp = parseInt(param[2])
if (start_lp <= 0) then start_lp = 1 if (start_lp <= 0) then start_lp = 1
if (start_lp >= 99999) then start_lp = 99999 if (start_lp >= 99999) then start_lp = 99999
@hostinfo.start_lp = start_lp @hostinfo.start_lp = start_lp
if (param = rule.match /(^|,|,)(TIME|TM|TI)(\d+)(,|,|$)/) if (param = rule.match /(^|,|,)(TIME|TM|TI)(\d+)(,|,|$)/)
time_limit = parseInt(param[3]) time_limit = parseInt(param[3])
if (time_limit < 0) then time_limit = 180 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 if (time_limit >= 999) then time_limit = 999
@hostinfo.time_limit = time_limit @hostinfo.time_limit = time_limit
if (param = rule.match /(^|,|,)(START|ST)(\d+)(,|,|$)/) if (param = rule.match /(^|,|,)(START|ST)(\d+)(,|,|$)/)
start_hand = parseInt(param[3]) start_hand = parseInt(param[3])
if (start_hand <= 0) then start_hand = 1 if (start_hand <= 0) then start_hand = 1
if (start_hand >= 40) then start_hand = 40 if (start_hand >= 40) then start_hand = 40
@hostinfo.start_hand = start_hand @hostinfo.start_hand = start_hand
if (param = rule.match /(^|,|,)(DRAW|DR)(\d+)(,|,|$)/) if (param = rule.match /(^|,|,)(DRAW|DR)(\d+)(,|,|$)/)
draw_count = parseInt(param[3]) draw_count = parseInt(param[3])
if (draw_count >= 35) then draw_count = 35 if (draw_count >= 35) then draw_count = 35
@hostinfo.draw_count = draw_count @hostinfo.draw_count = draw_count
if (param = rule.match /(^|,|,)(LFLIST|LF)(\d+)(,|,|$)/) if (param = rule.match /(^|,|,)(LFLIST|LF)(\d+)(,|,|$)/)
lflist = parseInt(param[3])-1 lflist = parseInt(param[3])-1
@hostinfo.lflist = lflist @hostinfo.lflist = lflist
if (rule.match /(^|,|,)(NOLFLIST|NF)(,|,|$)/) if (rule.match /(^|,|,)(NOLFLIST|NF)(,|,|$)/)
@hostinfo.lflist = -1 @hostinfo.lflist = -1
if (rule.match /(^|,|,)(NOUNIQUE|NU)(,|,|$)/) if (rule.match /(^|,|,)(NOUNIQUE|NU)(,|,|$)/)
@hostinfo.rule = 3 @hostinfo.rule = 3
if (rule.match /(^|,|,)(NOCHECK|NC)(,|,|$)/) if (rule.match /(^|,|,)(NOCHECK|NC)(,|,|$)/)
@hostinfo.no_check_deck = true @hostinfo.no_check_deck = true
if (rule.match /(^|,|,)(NOSHUFFLE|NS)(,|,|$)/) if (rule.match /(^|,|,)(NOSHUFFLE|NS)(,|,|$)/)
@hostinfo.no_shuffle_deck = true @hostinfo.no_shuffle_deck = true
if (rule.match /(^|,|,)(IGPRIORITY|PR)(,|,|$)/) if (rule.match /(^|,|,)(IGPRIORITY|PR)(,|,|$)/)
@hostinfo.enable_priority = true @hostinfo.enable_priority = true
...@@ -351,7 +351,7 @@ class Room ...@@ -351,7 +351,7 @@ class Room
#Room.all[index] = null unless index == -1 #Room.all[index] = null unless index == -1
Room.all.splice(index, 1) unless index == -1 Room.all.splice(index, 1) unless index == -1
return return
get_playing_player: -> get_playing_player: ->
playing_player=[] playing_player=[]
_.each @players, (player)=> _.each @players, (player)=>
......
...@@ -45,7 +45,7 @@ else ...@@ -45,7 +45,7 @@ else
log = bunyan.createLogger name: "mycard" log = bunyan.createLogger name: "mycard"
#定时清理关闭的连接 #定时清理关闭的连接
Graveyard = [] Graveyard = []
tribute = (socket) -> tribute = (socket) ->
setTimeout ((socket)-> Graveyard.push(socket);return)(socket), 3000 setTimeout ((socket)-> Graveyard.push(socket);return)(socket), 3000
...@@ -65,7 +65,7 @@ setInterval ()-> ...@@ -65,7 +65,7 @@ setInterval ()->
net.createServer (client) -> net.createServer (client) ->
server = new net.Socket() server = new net.Socket()
client.server = server client.server = server
client.setTimeout(300000) #5分钟 client.setTimeout(300000) #5分钟
#释放处理 #释放处理
...@@ -139,9 +139,9 @@ net.createServer (client) -> ...@@ -139,9 +139,9 @@ net.createServer (client) ->
client.room.watcher.write data client.room.watcher.write data
else else
ctos_buffer = Buffer.concat([ctos_buffer, data], ctos_buffer.length + data.length) #buffer的错误使用方式,好孩子不要学 ctos_buffer = Buffer.concat([ctos_buffer, data], ctos_buffer.length + data.length) #buffer的错误使用方式,好孩子不要学
datas = [] datas = []
looplimit = 0 looplimit = 0
while true while true
...@@ -175,7 +175,7 @@ net.createServer (client) -> ...@@ -175,7 +175,7 @@ net.createServer (client) ->
ctos_proto = 0 ctos_proto = 0
else else
break break
looplimit++ looplimit++
#log.info(looplimit) #log.info(looplimit)
if looplimit>800 if looplimit>800
...@@ -200,7 +200,7 @@ net.createServer (client) -> ...@@ -200,7 +200,7 @@ net.createServer (client) ->
#unless ygopro.stoc_follows[stoc_proto] and ygopro.stoc_follows[stoc_proto].synchronous #unless ygopro.stoc_follows[stoc_proto] and ygopro.stoc_follows[stoc_proto].synchronous
client.write data client.write data
looplimit = 0 looplimit = 0
while true while true
...@@ -231,7 +231,7 @@ net.createServer (client) -> ...@@ -231,7 +231,7 @@ net.createServer (client) ->
stoc_proto = 0 stoc_proto = 0
else else
break break
looplimit++ looplimit++
#log.info(looplimit) #log.info(looplimit)
if looplimit>800 if looplimit>800
...@@ -264,7 +264,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -264,7 +264,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
code: 2 code: 2
} }
client.end() client.end()
### ###
else if info.pass.toUpperCase()=="R" else if info.pass.toUpperCase()=="R"
ygopro.stoc_send_chat(client,"以下是您近期的云录像,密码处输入 R#录像编号 即可观看", 14) ygopro.stoc_send_chat(client,"以下是您近期的云录像,密码处输入 R#录像编号 即可观看", 14)
...@@ -353,7 +353,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -353,7 +353,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
code: 2 code: 2
} }
client.end() client.end()
else 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) room = Room.find_or_create_by_name(info.pass, client.remoteAddress)
...@@ -413,7 +413,7 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -413,7 +413,7 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)->
} }
ygopro.ctos_send watcher, 'HS_TOOBSERVER' ygopro.ctos_send watcher, 'HS_TOOBSERVER'
return return
watcher.on 'data', (data)-> watcher.on 'data', (data)->
return unless client.room return unless client.room
client.room.watcher_buffers.push data client.room.watcher_buffers.push data
...@@ -444,12 +444,12 @@ if settings.modules.dialogues ...@@ -444,12 +444,12 @@ if settings.modules.dialogues
ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)-> ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
msg = buffer.readInt8(0) msg = buffer.readInt8(0)
if msg>=10 and msg<30 #SELECT开头的消息 if msg>=10 and msg<30 #SELECT开头的消息
client.room.waiting_for_player=client client.room.waiting_for_player=client
client.room.last_active_time=moment() client.room.last_active_time=moment()
#log.info("#{ygopro.constants.MSG[msg]}等待#{client.room.waiting_for_player.name}") #log.info("#{ygopro.constants.MSG[msg]}等待#{client.room.waiting_for_player.name}")
#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)
...@@ -465,7 +465,7 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)-> ...@@ -465,7 +465,7 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
#log.info {winner: pos, reason: reason} #log.info {winner: pos, reason: reason}
client.room.duels.push {winner: pos, reason: reason} client.room.duels.push {winner: pos, reason: reason}
### ###
#lp跟踪 #lp跟踪
if ygopro.constants.MSG[msg] == 'DAMAGE' and client.is_host if ygopro.constants.MSG[msg] == 'DAMAGE' and client.is_host
pos = buffer.readUInt8(1) pos = buffer.readUInt8(1)
...@@ -604,22 +604,22 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server)-> ...@@ -604,22 +604,22 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server)->
#log.warn 'ping', stdout #log.warn 'ping', stdout
ygopro.stoc_send_chat_to_room client.room, stdout ygopro.stoc_send_chat_to_room client.room, stdout
return return
when '/help' when '/help'
ygopro.stoc_send_chat(client,"YGOSrv233 指令帮助") ygopro.stoc_send_chat(client,"YGOSrv233 指令帮助")
ygopro.stoc_send_chat(client,"/help 显示这个帮助信息") ygopro.stoc_send_chat(client,"/help 显示这个帮助信息")
ygopro.stoc_send_chat(client,"/roomname 显示当前房间的名字") ygopro.stoc_send_chat(client,"/roomname 显示当前房间的名字")
ygopro.stoc_send_chat(client,"/tip 显示一条提示") if settings.modules.tips ygopro.stoc_send_chat(client,"/tip 显示一条提示") if settings.modules.tips
when '/tip' when '/tip'
ygopro.stoc_send_random_tip(client) if settings.modules.tips ygopro.stoc_send_random_tip(client) if settings.modules.tips
when '/roomname' 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' when '/test'
ygopro.stoc_send_hint_card_to_room(client.room, 2333365) ygopro.stoc_send_hint_card_to_room(client.room, 2333365)
return cancel return cancel
ygopro.ctos_follow 'UPDATE_DECK', false, (buffer, info, client, server)-> ygopro.ctos_follow 'UPDATE_DECK', false, (buffer, info, client, server)->
...@@ -655,7 +655,7 @@ ygopro.stoc_follow 'SELECT_HAND', false, (buffer, info, client, server)-> ...@@ -655,7 +655,7 @@ ygopro.stoc_follow 'SELECT_HAND', false, (buffer, info, client, server)->
client.room.waiting_for_player2=client client.room.waiting_for_player2=client
client.room.last_active_time=moment().subtract(settings.modules.hang_timeout-19, 's') client.room.last_active_time=moment().subtract(settings.modules.hang_timeout-19, 's')
return return
ygopro.stoc_follow 'SELECT_TP', false, (buffer, info, client, server)-> ygopro.stoc_follow 'SELECT_TP', false, (buffer, info, client, server)->
return unless client.room and client.room.random_type return unless client.room and client.room.random_type
client.room.waiting_for_player=client client.room.waiting_for_player=client
......
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