Commit 5094c73f authored by nanahira's avatar nanahira

Merge branch 'master' into tcg_random

parents 479d567c 254b36bd
{ {
"file": "./config/config.json", "file": "./config/config.json",
"port": 1262, "port": 514,
"version": 4930, "version": 4930,
"hostinfo": { "hostinfo": {
"lflist": 0, "lflist": 0,
...@@ -68,6 +68,9 @@ ...@@ -68,6 +68,9 @@
"enabled": false, "enabled": false,
"get": false "get": false
}, },
"koishi_roomlist": {
"enabled": false
},
"vip": { "vip": {
"enabled": false, "enabled": false,
"generate_count": 500 "generate_count": 500
...@@ -162,7 +165,7 @@ ...@@ -162,7 +165,7 @@
"show_ip": true, "show_ip": true,
"show_info": true, "show_info": true,
"log_save_path": "./config/", "log_save_path": "./config/",
"port": 1264 "port": 5142
}, },
"test_mode": { "test_mode": {
"watch_public_hand": false, "watch_public_hand": false,
...@@ -285,9 +288,9 @@ ...@@ -285,9 +288,9 @@
] ]
}, },
"http": { "http": {
"port": 1263, "port": 5141,
"websocket_roomlist": false, "websocket_roomlist": false,
"public_roomlist": true, "public_roomlist": false,
"show_ip": true, "show_ip": true,
"show_info": true, "show_info": true,
"quick_death_rule": 2, "quick_death_rule": 2,
......
...@@ -13,7 +13,9 @@ ...@@ -13,7 +13,9 @@
"start_lp": 8000, "start_lp": 8000,
"start_hand": 5, "start_hand": 5,
"draw_count": 1, "draw_count": 1,
"time_limit": 180 "time_limit": 180,
"no_watch": false,
"auto_death": false
}, },
"modules": { "modules": {
"welcome": "MyCard YGOPro Server", "welcome": "MyCard YGOPro Server",
...@@ -164,7 +166,12 @@ ...@@ -164,7 +166,12 @@
"ready_time": 30, "ready_time": 30,
"check_permit": "https://api.mycard.moe/ygopro/match/permit", "check_permit": "https://api.mycard.moe/ygopro/match/permit",
"post_score": false, "post_score": false,
"get_score": false "get_score": false,
"init_post": {
"enabled": false,
"url": "https://api.mycard.moe/ygopro/match/clear",
"accesskey": "momobako"
}
}, },
"tournament_mode": { "tournament_mode": {
"enabled": false, "enabled": false,
...@@ -299,7 +306,7 @@ ...@@ -299,7 +306,7 @@
"public_roomlist": false, "public_roomlist": false,
"show_ip": false, "show_ip": false,
"show_info": true, "show_info": true,
"quick_death_rule": false, "quick_death_rule": 2,
"ssl": { "ssl": {
"enabled": false, "enabled": false,
"port": 7923, "port": 7923,
......
...@@ -192,6 +192,8 @@ ...@@ -192,6 +192,8 @@
"invalid_side_rule": "Illegal cards are contained in your side deck.", "invalid_side_rule": "Illegal cards are contained in your side deck.",
"arena_wait_hint": "If you opponent does not appear within 25 seconds, you may quit without any penalty.", "arena_wait_hint": "If you opponent does not appear within 25 seconds, you may quit without any penalty.",
"arena_wait_timeout": "Your opponent did not appear, you may quit without any penalty.", "arena_wait_timeout": "Your opponent did not appear, you may quit without any penalty.",
"auto_death_part1": "This room is an auto-extra-duel room. The Extra Duel will begin after ",
"auto_death_part2": " minutes.",
"athletic_arena_tip": "During an athletic match, a game quit behavior is regarded as a surrender." "athletic_arena_tip": "During an athletic match, a game quit behavior is regarded as a surrender."
}, },
"es-es": { "es-es": {
...@@ -531,6 +533,8 @@ ...@@ -531,6 +533,8 @@
"invalid_side_rule": "副卡组中包含不允许换入副卡组的卡。", "invalid_side_rule": "副卡组中包含不允许换入副卡组的卡。",
"arena_wait_hint": "若对手在25秒内不进入游戏,您退房时不会进行扣分。", "arena_wait_hint": "若对手在25秒内不进入游戏,您退房时不会进行扣分。",
"arena_wait_timeout": "由于对手未能在30秒内进入游戏,此时您退出游戏不会扣分。", "arena_wait_timeout": "由于对手未能在30秒内进入游戏,此时您退出游戏不会扣分。",
"auto_death_part1": "本房间为自动加时赛房间。比赛开始",
"auto_death_part2": "分钟后,将自动进入加时赛。",
"athletic_arena_tip": "在竞技匹配中,比赛开始前退出游戏也会视为投降。" "athletic_arena_tip": "在竞技匹配中,比赛开始前退出游戏也会视为投降。"
}, },
"ko-kr": { "ko-kr": {
......
...@@ -415,6 +415,19 @@ if settings.modules.mycard.enabled ...@@ -415,6 +415,19 @@ if settings.modules.mycard.enabled
pg_client.on 'drain', pg_client.end.bind(pg_client) pg_client.on 'drain', pg_client.end.bind(pg_client)
log.info "loading mycard user..." log.info "loading mycard user..."
pg_client.connect() pg_client.connect()
if settings.modules.arena_mode.enabled and settings.modules.arena_mode.init_post.enabled
request.post { url : settings.modules.arena_mode.init_post.url , qs : {
ak: settings.modules.arena_mode.init_post.accesskey,
arena: settings.modules.arena_mode.mode
}}, (error, response, body)=>
if error
log.warn 'ARENA INIT POST ERROR', error
else
if response.statusCode >= 400
log.warn 'ARENA INIT POST FAIL', response.statusCode, response.statusMessage, body
#else
# log.info 'ARENA INIT POST OK', response.statusCode, response.statusMessage
return
if settings.modules.challonge.enabled if settings.modules.challonge.enabled
challonge_module_name = 'challonge' challonge_module_name = 'challonge'
...@@ -1271,7 +1284,14 @@ class Room ...@@ -1271,7 +1284,14 @@ class Room
@hostinfo.enable_priority = true @hostinfo.enable_priority = true
if (rule.match /(^|,|,)(NOWATCH|NW)(,|,|$)/) if (rule.match /(^|,|,)(NOWATCH|NW)(,|,|$)/)
@no_watch = true @hostinfo.no_watch = true
if (param = rule.match /(^|,|,)(DEATH|DH)(\d*)(,|,|$)/)
death_time = parseInt(param[3])
if death_time and death_time > 0
@hostinfo.auto_death = death_time
else
@hostinfo.auto_death = 40
@hostinfo.replay_mode = if settings.modules.tournament_mode.enabled and settings.modules.tournament_mode.replay_safe or @hostinfo.mode == 1 and settings.modules.replay_delay then 1 else 0 @hostinfo.replay_mode = if settings.modules.tournament_mode.enabled and settings.modules.tournament_mode.replay_safe or @hostinfo.mode == 1 and settings.modules.replay_delay then 1 else 0
...@@ -1571,6 +1591,52 @@ class Room ...@@ -1571,6 +1591,52 @@ class Room
client.server.destroy() client.server.destroy()
return return
start_death: () ->
unless @established and @started and !@death
return false
oppo_pos = if @hostinfo.mode == 2 then 2 else 1
if !@changing_side and (!@duel_count or @turn) # Extra duel started in duel
switch settings.modules.http.quick_death_rule
when 3
@death = -2
ygopro.stoc_send_chat_to_room(this, "${death_start_phase}", ygopro.constants.COLORS.BABYBLUE)
else
@death = (if @turn then @turn + 4 else 5)
ygopro.stoc_send_chat_to_room(this, "${death_start}", ygopro.constants.COLORS.BABYBLUE)
else # Extra duel started in siding
switch settings.modules.http.quick_death_rule
when 2,3
if @scores[@dueling_players[0].name_vpass] == @scores[@dueling_players[oppo_pos].name_vpass]
if settings.modules.http.quick_death_rule == 3
@death = -1
ygopro.stoc_send_chat_to_room(this, "${death_start_quick}", ygopro.constants.COLORS.BABYBLUE)
else
@death = 5
ygopro.stoc_send_chat_to_room(this, "${death_start_siding}", ygopro.constants.COLORS.BABYBLUE)
else
win_pos = if @scores[@dueling_players[0].name_vpass] > @scores[@dueling_players[oppo_pos].name_vpass] then 0 else oppo_pos
@finished_by_death = true
ygopro.stoc_send_chat_to_room(this, "${death2_finish_part1}" + @dueling_players[win_pos].name + "${death2_finish_part2}", ygopro.constants.COLORS.BABYBLUE)
CLIENT_send_replays(@dueling_players[oppo_pos - win_pos], this) if @hostinfo.mode == 1
ygopro.stoc_send(@dueling_players[oppo_pos - win_pos], 'DUEL_END')
ygopro.stoc_send(@dueling_players[oppo_pos - win_pos + 1], 'DUEL_END') if @hostinfo.mode == 2
@scores[@dueling_players[oppo_pos - win_pos].name_vpass] = -1
CLIENT_kick(@dueling_players[oppo_pos - win_pos])
CLIENT_kick(@dueling_players[oppo_pos - win_pos + 1]) if @hostinfo.mode == 2
when 1
@death = -1
ygopro.stoc_send_chat_to_room(this, "${death_start_quick}", ygopro.constants.COLORS.BABYBLUE)
else
@death = 5
ygopro.stoc_send_chat_to_room(this, "${death_start_siding}", ygopro.constants.COLORS.BABYBLUE)
return true
cancel_death: () ->
unless @established and @started and @death
return false
@death = 0
ygopro.stoc_send_chat_to_room(this, "${death_cancel}", ygopro.constants.COLORS.BABYBLUE)
return true
# 网络连接 # 网络连接
net.createServer (client) -> net.createServer (client) ->
...@@ -2086,6 +2152,8 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -2086,6 +2152,8 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
start_lp: opt2 start_lp: opt2
start_hand: opt3 >> 4 start_hand: opt3 >> 4
draw_count: opt3 & 0xF draw_count: opt3 & 0xF
no_watch: false
auto_death: false
} }
options.lflist = _.findIndex lflists, (list)-> ((options.rule == 1) == list.tcg) and list.date.isBefore() options.lflist = _.findIndex lflists, (list)-> ((options.rule == 1) == list.tcg) and list.date.isBefore()
room = new Room(name, options) room = new Room(name, options)
...@@ -2127,7 +2195,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -2127,7 +2195,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
else if room.error else if room.error
ygopro.stoc_die(client, room.error) ygopro.stoc_die(client, room.error)
else if room.started else if room.started
if settings.modules.cloud_replay.enable_halfway_watch and !room.no_watch if settings.modules.cloud_replay.enable_halfway_watch and !room.hostinfo.no_watch
client.setTimeout(300000) #连接后超时5分钟 client.setTimeout(300000) #连接后超时5分钟
client.rid = _.indexOf(ROOM_all, room) client.rid = _.indexOf(ROOM_all, room)
client.is_post_watcher = true client.is_post_watcher = true
...@@ -2144,7 +2212,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -2144,7 +2212,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
client.write buffer client.write buffer
else else
ygopro.stoc_die(client, "${watch_denied}") ygopro.stoc_die(client, "${watch_denied}")
else if room.no_watch and room.players.length >= (if room.hostinfo.mode == 2 then 4 else 2) else if room.hostinfo.no_watch and room.players.length >= (if room.hostinfo.mode == 2 then 4 else 2)
ygopro.stoc_die(client, "${watch_denied_room}") ygopro.stoc_die(client, "${watch_denied_room}")
else else
#client.room = room #client.room = room
...@@ -2197,7 +2265,8 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -2197,7 +2265,8 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
json: true, json: true,
qs: qs:
username: client.name, username: client.name,
password: info.pass password: info.pass,
arena: settings.modules.arena_mode.mode
, (error, response, body)-> , (error, response, body)->
if client.closed if client.closed
return return
...@@ -2213,7 +2282,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -2213,7 +2282,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
else if settings.modules.challonge.enabled else if settings.modules.challonge.enabled
pre_room = ROOM_find_by_name(info.pass) pre_room = ROOM_find_by_name(info.pass)
if pre_room and pre_room.started and settings.modules.cloud_replay.enable_halfway_watch and !pre_room.no_watch if pre_room and pre_room.started and settings.modules.cloud_replay.enable_halfway_watch and !pre_room.hostinfo.no_watch
room = pre_room room = pre_room
client.setTimeout(300000) #连接后超时5分钟 client.setTimeout(300000) #连接后超时5分钟
client.rid = _.indexOf(ROOM_all, room) client.rid = _.indexOf(ROOM_all, room)
...@@ -2276,7 +2345,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -2276,7 +2345,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
else if room.error else if room.error
ygopro.stoc_die(client, room.error) ygopro.stoc_die(client, room.error)
else if room.started else if room.started
if settings.modules.cloud_replay.enable_halfway_watch and !room.no_watch if settings.modules.cloud_replay.enable_halfway_watch and !room.hostinfo.no_watch
#client.setTimeout(300000) #连接后超时5分钟 #client.setTimeout(300000) #连接后超时5分钟
client.rid = _.indexOf(ROOM_all, room) client.rid = _.indexOf(ROOM_all, room)
client.is_post_watcher = true client.is_post_watcher = true
...@@ -2293,7 +2362,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -2293,7 +2362,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
client.write buffer client.write buffer
else else
ygopro.stoc_die(client, "${watch_denied}") ygopro.stoc_die(client, "${watch_denied}")
else if room.no_watch and room.players.length >= (if room.hostinfo.mode == 2 then 4 else 2) else if room.hostinfo.no_watch and room.players.length >= (if room.hostinfo.mode == 2 then 4 else 2)
ygopro.stoc_die(client, "${watch_denied_room}") ygopro.stoc_die(client, "${watch_denied_room}")
else else
for player in room.get_playing_player() when player and player != client and player.challonge_info.id == client.challonge_info.id for player in room.get_playing_player() when player and player != client and player.challonge_info.id == client.challonge_info.id
...@@ -2365,7 +2434,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -2365,7 +2434,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
else if room.error else if room.error
ygopro.stoc_die(client, room.error) ygopro.stoc_die(client, room.error)
else if room.started else if room.started
if settings.modules.cloud_replay.enable_halfway_watch and !room.no_watch if settings.modules.cloud_replay.enable_halfway_watch and !room.hostinfo.no_watch
client.setTimeout(300000) #连接后超时5分钟 client.setTimeout(300000) #连接后超时5分钟
client.rid = _.indexOf(ROOM_all, room) client.rid = _.indexOf(ROOM_all, room)
client.is_post_watcher = true client.is_post_watcher = true
...@@ -2382,7 +2451,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -2382,7 +2451,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
client.write buffer client.write buffer
else else
ygopro.stoc_die(client, "${watch_denied}") ygopro.stoc_die(client, "${watch_denied}")
else if room.no_watch and room.players.length >= (if room.hostinfo.mode == 2 then 4 else 2) else if room.hostinfo.no_watch and room.players.length >= (if room.hostinfo.mode == 2 then 4 else 2)
ygopro.stoc_die(client, "${watch_denied_room}") ygopro.stoc_die(client, "${watch_denied_room}")
else else
client.setTimeout(300000) #连接后超时5分钟 client.setTimeout(300000) #连接后超时5分钟
...@@ -2446,7 +2515,7 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -2446,7 +2515,7 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
recorder.on 'error', (error)-> recorder.on 'error', (error)->
return return
if settings.modules.cloud_replay.enable_halfway_watch and !room.watcher and !room.no_watch if settings.modules.cloud_replay.enable_halfway_watch and !room.watcher and !room.hostinfo.no_watch
room.watcher = watcher = if settings.modules.test_mode.watch_public_hand then room.recorder else net.connect room.port, -> room.watcher = watcher = if settings.modules.test_mode.watch_public_hand then room.recorder else net.connect room.port, ->
ygopro.ctos_send watcher, 'PLAYER_INFO', { ygopro.ctos_send watcher, 'PLAYER_INFO', {
name: "the Big Brother" name: "the Big Brother"
...@@ -2577,7 +2646,7 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)-> ...@@ -2577,7 +2646,7 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
room.selecting_tp = false room.selecting_tp = false
if client.pos == 0 if client.pos == 0
room.turn = 0 room.turn = 0
room.duel_count = room.duel_count + 1 room.duel_count++
if room.death and room.duel_count > 1 if room.death and room.duel_count > 1
if room.death == -1 if room.death == -1
ygopro.stoc_send_chat_to_room(room, "${death_start_final}", ygopro.constants.COLORS.BABYBLUE) ygopro.stoc_send_chat_to_room(room, "${death_start_final}", ygopro.constants.COLORS.BABYBLUE)
...@@ -2801,7 +2870,7 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)-> ...@@ -2801,7 +2870,7 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
ygopro.ctos_follow 'HS_TOOBSERVER', true, (buffer, info, client, server, datas)-> ygopro.ctos_follow 'HS_TOOBSERVER', true, (buffer, info, client, server, datas)->
room=ROOM_all[client.rid] room=ROOM_all[client.rid]
return unless room return unless room
if room.no_watch if room.hostinfo.no_watch
ygopro.stoc_send_chat(client, "${watch_denied_room}", ygopro.constants.COLORS.RED) ygopro.stoc_send_chat(client, "${watch_denied_room}", ygopro.constants.COLORS.RED)
return true return true
if (!room.arena and !settings.modules.challonge.enabled) or client.is_local if (!room.arena and !settings.modules.challonge.enabled) or client.is_local
...@@ -2833,7 +2902,7 @@ ygopro.ctos_follow 'HS_KICK', true, (buffer, info, client, server, datas)-> ...@@ -2833,7 +2902,7 @@ ygopro.ctos_follow 'HS_KICK', true, (buffer, info, client, server, datas)->
ygopro.stoc_follow 'TYPE_CHANGE', true, (buffer, info, client, server, datas)-> ygopro.stoc_follow 'TYPE_CHANGE', true, (buffer, info, client, server, datas)->
selftype = info.type & 0xf selftype = info.type & 0xf
is_host = ((info.type >> 4) & 0xf) != 0 is_host = ((info.type >> 4) & 0xf) != 0
# if room and room.no_watch and selftype == 7 # if room and room.hostinfo.no_watch and selftype == 7
# ygopro.stoc_die(client, "${watch_denied_room}") # ygopro.stoc_die(client, "${watch_denied_room}")
# return true # return true
client.is_host = is_host client.is_host = is_host
...@@ -3030,6 +3099,8 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server, datas)-> ...@@ -3030,6 +3099,8 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server, datas)->
if room.random_type == 'T' if room.random_type == 'T'
# 双打房不记录匹配过 # 双打房不记录匹配过
ROOM_players_oppentlist[player.ip] = null ROOM_players_oppentlist[player.ip] = null
if room.hostinfo.auto_death
ygopro.stoc_send_chat_to_room(room, "${auto_death_part1}#{room.hostinfo.auto_death}${auto_death_part2}", ygopro.constants.COLORS.BABYBLUE)
if settings.modules.hide_name and room.duel_count == 0 if settings.modules.hide_name and room.duel_count == 0
for player in room.get_playing_player() when player != client for player in room.get_playing_player() when player != client
ygopro.stoc_send(client, 'HS_PLAYER_ENTER', { ygopro.stoc_send(client, 'HS_PLAYER_ENTER', {
...@@ -3790,6 +3861,14 @@ if settings.modules.heartbeat_detection.enabled ...@@ -3790,6 +3861,14 @@ if settings.modules.heartbeat_detection.enabled
return return
, settings.modules.heartbeat_detection.interval , settings.modules.heartbeat_detection.interval
setInterval ()->
current_time = moment()
for room in ROOM_all when room and room.started and room.hostinfo.auto_death and !room.auto_death_triggered and current_time - moment(room.start_time) > 60000 * room.hostinfo.auto_death
room.auto_death_triggered = true
room.start_death()
, 1000
# spawn windbot # spawn windbot
windbot_looplimit = 0 windbot_looplimit = 0
...@@ -4078,43 +4157,9 @@ if settings.modules.http ...@@ -4078,43 +4157,9 @@ if settings.modules.http
response.end(addCallback(u.query.callback, "['密码错误', 0]")) response.end(addCallback(u.query.callback, "['密码错误', 0]"))
return return
death_room_found = false death_room_found = false
for room in ROOM_all when room and room.established and room.started and !room.death and (u.query.death == "all" or u.query.death == room.process_pid.toString() or u.query.death == room.name) for room in ROOM_all when room and (u.query.death == "all" or u.query.death == room.process_pid.toString() or u.query.death == room.name)
death_room_found = true if room.start_death()
oppo_pos = if room.hostinfo.mode == 2 then 2 else 1 death_room_found = true
if !room.changing_side and (!room.duel_count or room.turn)
switch settings.modules.http.quick_death_rule
when 3
room.death = -2
ygopro.stoc_send_chat_to_room(room, "${death_start_phase}", ygopro.constants.COLORS.BABYBLUE)
else
room.death = (if room.turn then room.turn + 4 else 5)
ygopro.stoc_send_chat_to_room(room, "${death_start}", ygopro.constants.COLORS.BABYBLUE)
else
switch settings.modules.http.quick_death_rule
when 2,3
if room.scores[room.dueling_players[0].name_vpass] == room.scores[room.dueling_players[oppo_pos].name_vpass]
if settings.modules.http.quick_death_rule == 3
room.death = -1
ygopro.stoc_send_chat_to_room(room, "${death_start_quick}", ygopro.constants.COLORS.BABYBLUE)
else
room.death = 5
ygopro.stoc_send_chat_to_room(room, "${death_start_siding}", ygopro.constants.COLORS.BABYBLUE)
else
win_pos = if room.scores[room.dueling_players[0].name_vpass] > room.scores[room.dueling_players[oppo_pos].name_vpass] then 0 else oppo_pos
room.finished_by_death = true
ygopro.stoc_send_chat_to_room(room, "${death2_finish_part1}" + room.dueling_players[win_pos].name + "${death2_finish_part2}", ygopro.constants.COLORS.BABYBLUE)
CLIENT_send_replays(room.dueling_players[oppo_pos - win_pos], room) if room.hostinfo.mode == 1
ygopro.stoc_send(room.dueling_players[oppo_pos - win_pos], 'DUEL_END')
ygopro.stoc_send(room.dueling_players[oppo_pos - win_pos + 1], 'DUEL_END') if room.hostinfo.mode == 2
room.scores[room.dueling_players[oppo_pos - win_pos].name_vpass] = -1
CLIENT_kick(room.dueling_players[oppo_pos - win_pos])
CLIENT_kick(room.dueling_players[oppo_pos - win_pos + 1]) if room.hostinfo.mode == 2
when 1
room.death = -1
ygopro.stoc_send_chat_to_room(room, "${death_start_quick}", ygopro.constants.COLORS.BABYBLUE)
else
room.death = 5
ygopro.stoc_send_chat_to_room(room, "${death_start_siding}", ygopro.constants.COLORS.BABYBLUE)
response.writeHead(200) response.writeHead(200)
if death_room_found if death_room_found
response.end(addCallback(u.query.callback, "['death ok', '" + u.query.death + "']")) response.end(addCallback(u.query.callback, "['death ok', '" + u.query.death + "']"))
...@@ -4127,10 +4172,9 @@ if settings.modules.http ...@@ -4127,10 +4172,9 @@ if settings.modules.http
response.end(addCallback(u.query.callback, "['密码错误', 0]")) response.end(addCallback(u.query.callback, "['密码错误', 0]"))
return return
death_room_found = false death_room_found = false
for room in ROOM_all when room and room.established and room.started and room.death and (u.query.deathcancel == "all" or u.query.deathcancel == room.process_pid.toString()) for room in ROOM_all when room and (u.query.death == "all" or u.query.death == room.process_pid.toString() or u.query.death == room.name)
death_room_found = true if room.cancel_death()
room.death = 0 death_room_found = true
ygopro.stoc_send_chat_to_room(room, "${death_cancel}", ygopro.constants.COLORS.BABYBLUE)
response.writeHead(200) response.writeHead(200)
if death_room_found if death_room_found
response.end(addCallback(u.query.callback, "['death cancel ok', '" + u.query.deathcancel + "']")) response.end(addCallback(u.query.callback, "['death cancel ok', '" + u.query.deathcancel + "']"))
......
...@@ -508,6 +508,25 @@ ...@@ -508,6 +508,25 @@
pg_client.on('drain', pg_client.end.bind(pg_client)); pg_client.on('drain', pg_client.end.bind(pg_client));
log.info("loading mycard user..."); log.info("loading mycard user...");
pg_client.connect(); pg_client.connect();
if (settings.modules.arena_mode.enabled && settings.modules.arena_mode.init_post.enabled) {
request.post({
url: settings.modules.arena_mode.init_post.url,
qs: {
ak: settings.modules.arena_mode.init_post.accesskey,
arena: settings.modules.arena_mode.mode
}
}, (function(_this) {
return function(error, response, body) {
if (error) {
log.warn('ARENA INIT POST ERROR', error);
} else {
if (response.statusCode >= 400) {
log.warn('ARENA INIT POST FAIL', response.statusCode, response.statusMessage, body);
}
}
};
})(this));
}
} }
if (settings.modules.challonge.enabled) { if (settings.modules.challonge.enabled) {
...@@ -1409,7 +1428,7 @@ ...@@ -1409,7 +1428,7 @@
Room = (function() { Room = (function() {
function Room(name, hostinfo) { function Room(name, hostinfo) {
var draw_count, error, lflist, list_official_to_pre, list_pre_to_official, official_database, param, pre_release_database, rule, start_hand, start_lp, temp_list, time_limit; var death_time, draw_count, error, lflist, list_official_to_pre, list_pre_to_official, official_database, param, pre_release_database, rule, start_hand, start_lp, temp_list, time_limit;
this.hostinfo = hostinfo; this.hostinfo = hostinfo;
this.name = name; this.name = name;
this.alive = true; this.alive = true;
...@@ -1630,7 +1649,15 @@ ...@@ -1630,7 +1649,15 @@
this.hostinfo.enable_priority = true; this.hostinfo.enable_priority = true;
} }
if (rule.match(/(^|,|,)(NOWATCH|NW)(,|,|$)/)) { if (rule.match(/(^|,|,)(NOWATCH|NW)(,|,|$)/)) {
this.no_watch = true; this.hostinfo.no_watch = true;
}
if ((param = rule.match(/(^|,|,)(DEATH|DH)(\d*)(,|,|$)/))) {
death_time = parseInt(param[3]);
if (death_time && death_time > 0) {
this.hostinfo.auto_death = death_time;
} else {
this.hostinfo.auto_death = 40;
}
} }
} }
this.hostinfo.replay_mode = settings.modules.tournament_mode.enabled && settings.modules.tournament_mode.replay_safe || this.hostinfo.mode === 1 && settings.modules.replay_delay ? 1 : 0; this.hostinfo.replay_mode = settings.modules.tournament_mode.enabled && settings.modules.tournament_mode.replay_safe || this.hostinfo.mode === 1 && settings.modules.replay_delay ? 1 : 0;
...@@ -2051,6 +2078,73 @@ ...@@ -2051,6 +2078,73 @@
} }
}; };
Room.prototype.start_death = function() {
var oppo_pos, win_pos;
if (!(this.established && this.started && !this.death)) {
return false;
}
oppo_pos = this.hostinfo.mode === 2 ? 2 : 1;
if (!this.changing_side && (!this.duel_count || this.turn)) {
switch (settings.modules.http.quick_death_rule) {
case 3:
this.death = -2;
ygopro.stoc_send_chat_to_room(this, "${death_start_phase}", ygopro.constants.COLORS.BABYBLUE);
break;
default:
this.death = (this.turn ? this.turn + 4 : 5);
ygopro.stoc_send_chat_to_room(this, "${death_start}", ygopro.constants.COLORS.BABYBLUE);
}
} else {
switch (settings.modules.http.quick_death_rule) {
case 2:
case 3:
if (this.scores[this.dueling_players[0].name_vpass] === this.scores[this.dueling_players[oppo_pos].name_vpass]) {
if (settings.modules.http.quick_death_rule === 3) {
this.death = -1;
ygopro.stoc_send_chat_to_room(this, "${death_start_quick}", ygopro.constants.COLORS.BABYBLUE);
} else {
this.death = 5;
ygopro.stoc_send_chat_to_room(this, "${death_start_siding}", ygopro.constants.COLORS.BABYBLUE);
}
} else {
win_pos = this.scores[this.dueling_players[0].name_vpass] > this.scores[this.dueling_players[oppo_pos].name_vpass] ? 0 : oppo_pos;
this.finished_by_death = true;
ygopro.stoc_send_chat_to_room(this, "${death2_finish_part1}" + this.dueling_players[win_pos].name + "${death2_finish_part2}", ygopro.constants.COLORS.BABYBLUE);
if (this.hostinfo.mode === 1) {
CLIENT_send_replays(this.dueling_players[oppo_pos - win_pos], this);
}
ygopro.stoc_send(this.dueling_players[oppo_pos - win_pos], 'DUEL_END');
if (this.hostinfo.mode === 2) {
ygopro.stoc_send(this.dueling_players[oppo_pos - win_pos + 1], 'DUEL_END');
}
this.scores[this.dueling_players[oppo_pos - win_pos].name_vpass] = -1;
CLIENT_kick(this.dueling_players[oppo_pos - win_pos]);
if (this.hostinfo.mode === 2) {
CLIENT_kick(this.dueling_players[oppo_pos - win_pos + 1]);
}
}
break;
case 1:
this.death = -1;
ygopro.stoc_send_chat_to_room(this, "${death_start_quick}", ygopro.constants.COLORS.BABYBLUE);
break;
default:
this.death = 5;
ygopro.stoc_send_chat_to_room(this, "${death_start_siding}", ygopro.constants.COLORS.BABYBLUE);
}
}
return true;
};
Room.prototype.cancel_death = function() {
if (!(this.established && this.started && this.death)) {
return false;
}
this.death = 0;
ygopro.stoc_send_chat_to_room(this, "${death_cancel}", ygopro.constants.COLORS.BABYBLUE);
return true;
};
return Room; return Room;
})(); })();
...@@ -2602,7 +2696,9 @@ ...@@ -2602,7 +2696,9 @@
no_shuffle_deck: !!(opt1 & 1), no_shuffle_deck: !!(opt1 & 1),
start_lp: opt2, start_lp: opt2,
start_hand: opt3 >> 4, start_hand: opt3 >> 4,
draw_count: opt3 & 0xF draw_count: opt3 & 0xF,
no_watch: false,
auto_death: false
}; };
options.lflist = _.findIndex(lflists, function(list) { options.lflist = _.findIndex(lflists, function(list) {
return ((options.rule === 1) === list.tcg) && list.date.isBefore(); return ((options.rule === 1) === list.tcg) && list.date.isBefore();
...@@ -2662,7 +2758,7 @@ ...@@ -2662,7 +2758,7 @@
} else if (room.error) { } else if (room.error) {
ygopro.stoc_die(client, room.error); ygopro.stoc_die(client, room.error);
} else if (room.started) { } else if (room.started) {
if (settings.modules.cloud_replay.enable_halfway_watch && !room.no_watch) { if (settings.modules.cloud_replay.enable_halfway_watch && !room.hostinfo.no_watch) {
client.setTimeout(300000); client.setTimeout(300000);
client.rid = _.indexOf(ROOM_all, room); client.rid = _.indexOf(ROOM_all, room);
client.is_post_watcher = true; client.is_post_watcher = true;
...@@ -2690,7 +2786,7 @@ ...@@ -2690,7 +2786,7 @@
} else { } else {
ygopro.stoc_die(client, "${watch_denied}"); ygopro.stoc_die(client, "${watch_denied}");
} }
} else if (room.no_watch && room.players.length >= (room.hostinfo.mode === 2 ? 4 : 2)) { } else if (room.hostinfo.no_watch && room.players.length >= (room.hostinfo.mode === 2 ? 4 : 2)) {
ygopro.stoc_die(client, "${watch_denied_room}"); ygopro.stoc_die(client, "${watch_denied_room}");
} else { } else {
client.setTimeout(300000); client.setTimeout(300000);
...@@ -2752,7 +2848,8 @@ ...@@ -2752,7 +2848,8 @@
json: true, json: true,
qs: { qs: {
username: client.name, username: client.name,
password: info.pass password: info.pass,
arena: settings.modules.arena_mode.mode
} }
}, function(error, response, body) { }, function(error, response, body) {
if (client.closed) { if (client.closed) {
...@@ -2770,7 +2867,7 @@ ...@@ -2770,7 +2867,7 @@
} }
} else if (settings.modules.challonge.enabled) { } else if (settings.modules.challonge.enabled) {
pre_room = ROOM_find_by_name(info.pass); pre_room = ROOM_find_by_name(info.pass);
if (pre_room && pre_room.started && settings.modules.cloud_replay.enable_halfway_watch && !pre_room.no_watch) { if (pre_room && pre_room.started && settings.modules.cloud_replay.enable_halfway_watch && !pre_room.hostinfo.no_watch) {
room = pre_room; room = pre_room;
client.setTimeout(300000); client.setTimeout(300000);
client.rid = _.indexOf(ROOM_all, room); client.rid = _.indexOf(ROOM_all, room);
...@@ -2849,7 +2946,7 @@ ...@@ -2849,7 +2946,7 @@
} else if (room.error) { } else if (room.error) {
ygopro.stoc_die(client, room.error); ygopro.stoc_die(client, room.error);
} else if (room.started) { } else if (room.started) {
if (settings.modules.cloud_replay.enable_halfway_watch && !room.no_watch) { if (settings.modules.cloud_replay.enable_halfway_watch && !room.hostinfo.no_watch) {
client.rid = _.indexOf(ROOM_all, room); client.rid = _.indexOf(ROOM_all, room);
client.is_post_watcher = true; client.is_post_watcher = true;
if (settings.modules.vip.enabled && client.vip && vip_info.players[client.name].words) { if (settings.modules.vip.enabled && client.vip && vip_info.players[client.name].words) {
...@@ -2876,7 +2973,7 @@ ...@@ -2876,7 +2973,7 @@
} else { } else {
ygopro.stoc_die(client, "${watch_denied}"); ygopro.stoc_die(client, "${watch_denied}");
} }
} else if (room.no_watch && room.players.length >= (room.hostinfo.mode === 2 ? 4 : 2)) { } else if (room.hostinfo.no_watch && room.players.length >= (room.hostinfo.mode === 2 ? 4 : 2)) {
ygopro.stoc_die(client, "${watch_denied_room}"); ygopro.stoc_die(client, "${watch_denied_room}");
} else { } else {
ref8 = room.get_playing_player(); ref8 = room.get_playing_player();
...@@ -2939,7 +3036,7 @@ ...@@ -2939,7 +3036,7 @@
} else if (room.error) { } else if (room.error) {
ygopro.stoc_die(client, room.error); ygopro.stoc_die(client, room.error);
} else if (room.started) { } else if (room.started) {
if (settings.modules.cloud_replay.enable_halfway_watch && !room.no_watch) { if (settings.modules.cloud_replay.enable_halfway_watch && !room.hostinfo.no_watch) {
client.setTimeout(300000); client.setTimeout(300000);
client.rid = _.indexOf(ROOM_all, room); client.rid = _.indexOf(ROOM_all, room);
client.is_post_watcher = true; client.is_post_watcher = true;
...@@ -2967,7 +3064,7 @@ ...@@ -2967,7 +3064,7 @@
} else { } else {
ygopro.stoc_die(client, "${watch_denied}"); ygopro.stoc_die(client, "${watch_denied}");
} }
} else if (room.no_watch && room.players.length >= (room.hostinfo.mode === 2 ? 4 : 2)) { } else if (room.hostinfo.no_watch && room.players.length >= (room.hostinfo.mode === 2 ? 4 : 2)) {
ygopro.stoc_die(client, "${watch_denied_room}"); ygopro.stoc_die(client, "${watch_denied_room}");
} else { } else {
client.setTimeout(300000); client.setTimeout(300000);
...@@ -3051,7 +3148,7 @@ ...@@ -3051,7 +3148,7 @@
}); });
recorder.on('error', function(error) {}); recorder.on('error', function(error) {});
} }
if (settings.modules.cloud_replay.enable_halfway_watch && !room.watcher && !room.no_watch) { if (settings.modules.cloud_replay.enable_halfway_watch && !room.watcher && !room.hostinfo.no_watch) {
room.watcher = watcher = settings.modules.test_mode.watch_public_hand ? room.recorder : net.connect(room.port, function() { room.watcher = watcher = settings.modules.test_mode.watch_public_hand ? room.recorder : net.connect(room.port, function() {
ygopro.ctos_send(watcher, 'PLAYER_INFO', { ygopro.ctos_send(watcher, 'PLAYER_INFO', {
name: "the Big Brother" name: "the Big Brother"
...@@ -3202,7 +3299,7 @@ ...@@ -3202,7 +3299,7 @@
room.selecting_tp = false; room.selecting_tp = false;
if (client.pos === 0) { if (client.pos === 0) {
room.turn = 0; room.turn = 0;
room.duel_count = room.duel_count + 1; room.duel_count++;
if (room.death && room.duel_count > 1) { if (room.death && room.duel_count > 1) {
if (room.death === -1) { if (room.death === -1) {
ygopro.stoc_send_chat_to_room(room, "${death_start_final}", ygopro.constants.COLORS.BABYBLUE); ygopro.stoc_send_chat_to_room(room, "${death_start_final}", ygopro.constants.COLORS.BABYBLUE);
...@@ -3510,7 +3607,7 @@ ...@@ -3510,7 +3607,7 @@
if (!room) { if (!room) {
return; return;
} }
if (room.no_watch) { if (room.hostinfo.no_watch) {
ygopro.stoc_send_chat(client, "${watch_denied_room}", ygopro.constants.COLORS.RED); ygopro.stoc_send_chat(client, "${watch_denied_room}", ygopro.constants.COLORS.RED);
return true; return true;
} }
...@@ -3869,6 +3966,9 @@ ...@@ -3869,6 +3966,9 @@
ROOM_players_oppentlist[player.ip] = null; ROOM_players_oppentlist[player.ip] = null;
} }
} }
if (room.hostinfo.auto_death) {
ygopro.stoc_send_chat_to_room(room, "${auto_death_part1}" + room.hostinfo.auto_death + "${auto_death_part2}", ygopro.constants.COLORS.BABYBLUE);
}
} }
if (settings.modules.hide_name && room.duel_count === 0) { if (settings.modules.hide_name && room.duel_count === 0) {
ref4 = room.get_playing_player(); ref4 = room.get_playing_player();
...@@ -4914,6 +5014,21 @@ ...@@ -4914,6 +5014,21 @@
}, settings.modules.heartbeat_detection.interval); }, settings.modules.heartbeat_detection.interval);
} }
setInterval(function() {
var current_time, len3, m, results, room;
current_time = moment();
results = [];
for (m = 0, len3 = ROOM_all.length; m < len3; m++) {
room = ROOM_all[m];
if (!(room && room.started && room.hostinfo.auto_death && !room.auto_death_triggered && current_time - moment(room.start_time) > 60000 * room.hostinfo.auto_death)) {
continue;
}
room.auto_death_triggered = true;
results.push(room.start_death());
}
return results;
}, 1000);
windbot_looplimit = 0; windbot_looplimit = 0;
spawn_windbot = function() { spawn_windbot = function() {
...@@ -4966,7 +5081,7 @@ ...@@ -4966,7 +5081,7 @@
return callback + "( " + text + " );"; return callback + "( " + text + " );";
}; };
requestListener = function(request, response) { requestListener = function(request, response) {
var archive_args, archive_name, archive_process, check, death_room_found, duellog, error, filename, getpath, key, kick_room_found, len3, len4, len5, len6, len7, len8, m, n, o, oppo_pos, p, parseQueryString, pass_validated, player, q, r, ref3, ref4, replay, ret_keys, room, roomsjson, u, win_pos; var archive_args, archive_name, archive_process, check, death_room_found, duellog, error, filename, getpath, key, kick_room_found, len3, len4, len5, len6, len7, len8, m, n, o, p, parseQueryString, pass_validated, player, q, r, ref3, ref4, replay, ret_keys, room, roomsjson, u;
parseQueryString = true; parseQueryString = true;
u = url.parse(request.url, parseQueryString); u = url.parse(request.url, parseQueryString);
if (u.pathname === '/api/getrooms') { if (u.pathname === '/api/getrooms') {
...@@ -5269,58 +5384,9 @@ ...@@ -5269,58 +5384,9 @@
death_room_found = false; death_room_found = false;
for (q = 0, len7 = ROOM_all.length; q < len7; q++) { for (q = 0, len7 = ROOM_all.length; q < len7; q++) {
room = ROOM_all[q]; room = ROOM_all[q];
if (!(room && room.established && room.started && !room.death && (u.query.death === "all" || u.query.death === room.process_pid.toString() || u.query.death === room.name))) { if (room && (u.query.death === "all" || u.query.death === room.process_pid.toString() || u.query.death === room.name)) {
continue; if (room.start_death()) {
} death_room_found = true;
death_room_found = true;
oppo_pos = room.hostinfo.mode === 2 ? 2 : 1;
if (!room.changing_side && (!room.duel_count || room.turn)) {
switch (settings.modules.http.quick_death_rule) {
case 3:
room.death = -2;
ygopro.stoc_send_chat_to_room(room, "${death_start_phase}", ygopro.constants.COLORS.BABYBLUE);
break;
default:
room.death = (room.turn ? room.turn + 4 : 5);
ygopro.stoc_send_chat_to_room(room, "${death_start}", ygopro.constants.COLORS.BABYBLUE);
}
} else {
switch (settings.modules.http.quick_death_rule) {
case 2:
case 3:
if (room.scores[room.dueling_players[0].name_vpass] === room.scores[room.dueling_players[oppo_pos].name_vpass]) {
if (settings.modules.http.quick_death_rule === 3) {
room.death = -1;
ygopro.stoc_send_chat_to_room(room, "${death_start_quick}", ygopro.constants.COLORS.BABYBLUE);
} else {
room.death = 5;
ygopro.stoc_send_chat_to_room(room, "${death_start_siding}", ygopro.constants.COLORS.BABYBLUE);
}
} else {
win_pos = room.scores[room.dueling_players[0].name_vpass] > room.scores[room.dueling_players[oppo_pos].name_vpass] ? 0 : oppo_pos;
room.finished_by_death = true;
ygopro.stoc_send_chat_to_room(room, "${death2_finish_part1}" + room.dueling_players[win_pos].name + "${death2_finish_part2}", ygopro.constants.COLORS.BABYBLUE);
if (room.hostinfo.mode === 1) {
CLIENT_send_replays(room.dueling_players[oppo_pos - win_pos], room);
}
ygopro.stoc_send(room.dueling_players[oppo_pos - win_pos], 'DUEL_END');
if (room.hostinfo.mode === 2) {
ygopro.stoc_send(room.dueling_players[oppo_pos - win_pos + 1], 'DUEL_END');
}
room.scores[room.dueling_players[oppo_pos - win_pos].name_vpass] = -1;
CLIENT_kick(room.dueling_players[oppo_pos - win_pos]);
if (room.hostinfo.mode === 2) {
CLIENT_kick(room.dueling_players[oppo_pos - win_pos + 1]);
}
}
break;
case 1:
room.death = -1;
ygopro.stoc_send_chat_to_room(room, "${death_start_quick}", ygopro.constants.COLORS.BABYBLUE);
break;
default:
room.death = 5;
ygopro.stoc_send_chat_to_room(room, "${death_start_siding}", ygopro.constants.COLORS.BABYBLUE);
} }
} }
} }
...@@ -5339,12 +5405,11 @@ ...@@ -5339,12 +5405,11 @@
death_room_found = false; death_room_found = false;
for (r = 0, len8 = ROOM_all.length; r < len8; r++) { for (r = 0, len8 = ROOM_all.length; r < len8; r++) {
room = ROOM_all[r]; room = ROOM_all[r];
if (!(room && room.established && room.started && room.death && (u.query.deathcancel === "all" || u.query.deathcancel === room.process_pid.toString()))) { if (room && (u.query.death === "all" || u.query.death === room.process_pid.toString() || u.query.death === room.name)) {
continue; if (room.cancel_death()) {
death_room_found = true;
}
} }
death_room_found = true;
room.death = 0;
ygopro.stoc_send_chat_to_room(room, "${death_cancel}", ygopro.constants.COLORS.BABYBLUE);
} }
response.writeHead(200); response.writeHead(200);
if (death_room_found) { if (death_room_found) {
......
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