Commit a88f32ab authored by nanahira's avatar nanahira

use duel_stage for room status

parent a27b3ec8
...@@ -268,6 +268,14 @@ ...@@ -268,6 +268,14 @@
"LINK_MARKER_TOP": 128, "LINK_MARKER_TOP": 128,
"LINK_MARKER_TOP_RIGHT": 256 "LINK_MARKER_TOP_RIGHT": 256
}, },
"DUEL_STAGE": {
"BEGIN": 0,
"FINGER": 1,
"FIRSTGO": 2,
"DUELING": 3,
"SIDING": 4,
"END": 5
},
"COLORS": { "COLORS": {
"LIGHTBLUE": 8, "LIGHTBLUE": 8,
"RED": 11, "RED": 11,
...@@ -281,6 +289,3 @@ ...@@ -281,6 +289,3 @@
"DARKGRAY": 19 "DARKGRAY": 19
} }
} }
...@@ -560,7 +560,7 @@ ROOM_find_or_create_random = (type, player_ip)-> ...@@ -560,7 +560,7 @@ ROOM_find_or_create_random = (type, player_ip)->
max_player = if type == 'T' then 4 else 2 max_player = if type == 'T' then 4 else 2
playerbanned = (bannedplayer and bannedplayer.count > 3 and moment() < bannedplayer.time) playerbanned = (bannedplayer and bannedplayer.count > 3 and moment() < bannedplayer.time)
result = _.find ROOM_all, (room)-> result = _.find ROOM_all, (room)->
return room and room.random_type != '' and !room.started and !room.windbot and return room and room.random_type != '' and room.duel_stage == ygopro.constants.DUEL_STAGE.BEGIN and !room.windbot and
((type == '' and (room.random_type == 'S' or (settings.modules.random_duel.blank_pass_match and room.random_type != 'T'))) or room.random_type == type) and ((type == '' and (room.random_type == 'S' or (settings.modules.random_duel.blank_pass_match and room.random_type != 'T'))) or room.random_type == type) and
room.get_playing_player().length < max_player and room.get_playing_player().length < max_player and
(settings.modules.random_duel.no_rematch_check or room.get_host() == null or (settings.modules.random_duel.no_rematch_check or room.get_host() == null or
...@@ -689,7 +689,7 @@ CLIENT_reconnect_register = (client, room_id, error) -> ...@@ -689,7 +689,7 @@ CLIENT_reconnect_register = (client, room_id, error) ->
room = ROOM_all[room_id] room = ROOM_all[room_id]
if client.had_new_reconnection if client.had_new_reconnection
return false return false
if !settings.modules.reconnect.enabled or !room or client.system_kicked or client.flee_free or disconnect_list[CLIENT_get_authorize_key(client)] or client.is_post_watcher or !CLIENT_is_player(client, room) or !room.started or room.windbot or (settings.modules.reconnect.auto_surrender_after_disconnect and room.hostinfo.mode != 1) or (room.random_type and room.get_disconnected_count() > 1) if !settings.modules.reconnect.enabled or !room or client.system_kicked or client.flee_free or disconnect_list[CLIENT_get_authorize_key(client)] or client.is_post_watcher or !CLIENT_is_player(client, room) or room.duel_stage == ygopro.constants.DUEL_STAGE.BEGIN or room.windbot or (settings.modules.reconnect.auto_surrender_after_disconnect and room.hostinfo.mode != 1) or (room.random_type and room.get_disconnected_count() > 1)
return false return false
# for player in room.players # for player in room.players
# if player != client and CLIENT_get_authorize_key(player) == CLIENT_get_authorize_key(client) # if player != client and CLIENT_get_authorize_key(player) == CLIENT_get_authorize_key(client)
...@@ -712,7 +712,7 @@ CLIENT_reconnect_register = (client, room_id, error) -> ...@@ -712,7 +712,7 @@ CLIENT_reconnect_register = (client, room_id, error) ->
if client.time_confirm_required if client.time_confirm_required
client.time_confirm_required = false client.time_confirm_required = false
ygopro.ctos_send(client.server, 'TIME_CONFIRM') ygopro.ctos_send(client.server, 'TIME_CONFIRM')
if settings.modules.reconnect.auto_surrender_after_disconnect and room.turn and room.turn > 0 if settings.modules.reconnect.auto_surrender_after_disconnect and room.duel_stage == ygopro.constants.DUEL_STAGE.DUELING
ygopro.ctos_send(client.server, 'SURRENDER') ygopro.ctos_send(client.server, 'SURRENDER')
return true return true
...@@ -776,7 +776,7 @@ CLIENT_is_able_to_reconnect = (client, deckbuf) -> ...@@ -776,7 +776,7 @@ CLIENT_is_able_to_reconnect = (client, deckbuf) ->
return true return true
CLIENT_get_kick_reconnect_target = (client, deckbuf) -> CLIENT_get_kick_reconnect_target = (client, deckbuf) ->
for room in ROOM_all when room and room.started and !room.windbot for room in ROOM_all when room and room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN and !room.windbot
for player in room.get_playing_player() when !player.closed and player.name == client.name and (settings.modules.challonge.enabled or player.pass == client.pass) and (settings.modules.mycard.enabled or settings.modules.tournament_mode.enabled or player.ip == client.ip or (client.vpass and client.vpass == player.vpass)) and (!deckbuf or _.isEqual(player.start_deckbuf, deckbuf)) for player in room.get_playing_player() when !player.closed and player.name == client.name and (settings.modules.challonge.enabled or player.pass == client.pass) and (settings.modules.mycard.enabled or settings.modules.tournament_mode.enabled or player.ip == client.ip or (client.vpass and client.vpass == player.vpass)) and (!deckbuf or _.isEqual(player.start_deckbuf, deckbuf))
return player return player
return null return null
...@@ -807,25 +807,28 @@ CLIENT_send_pre_reconnect_info = (client, room, old_client) -> ...@@ -807,25 +807,28 @@ CLIENT_send_pre_reconnect_info = (client, room, old_client) ->
CLIENT_send_reconnect_info = (client, server, room) -> CLIENT_send_reconnect_info = (client, server, room) ->
client.reconnecting = true client.reconnecting = true
ygopro.stoc_send_chat(client, "${reconnecting_to_room}", ygopro.constants.COLORS.BABYBLUE) ygopro.stoc_send_chat(client, "${reconnecting_to_room}", ygopro.constants.COLORS.BABYBLUE)
if room.turn and room.turn > 0 switch room.duel_stage
ygopro.ctos_send(server, 'REQUEST_FIELD') when ygopro.constants.DUEL_STAGE.FINGER
else if room.changing_side ygopro.stoc_send(client, 'DUEL_START')
ygopro.stoc_send(client, 'DUEL_START') if (room.hostinfo.mode != 2 or client.pos == 0 or client.pos == 2) and !client.selected_preduel
if !client.selected_preduel ygopro.stoc_send(client, 'SELECT_HAND')
ygopro.stoc_send(client, 'CHANGE_SIDE') client.reconnecting = false
client.reconnecting = false break
else if room.selecting_hand when ygopro.constants.DUEL_STAGE.FIRSTGO
ygopro.stoc_send(client, 'DUEL_START') ygopro.stoc_send(client, 'DUEL_START')
if (room.hostinfo.mode != 2 or client.pos == 0 or client.pos == 2) and !client.selected_preduel if client == room.selecting_tp # and !client.selected_preduel
ygopro.stoc_send(client, 'SELECT_HAND') ygopro.stoc_send(client, 'SELECT_TP')
client.reconnecting = false client.reconnecting = false
else if room.selecting_tp break
ygopro.stoc_send(client, 'DUEL_START') when ygopro.constants.DUEL_STAGE.SIDING
if client == room.selecting_tp # and !client.selected_preduel ygopro.stoc_send(client, 'DUEL_START')
ygopro.stoc_send(client, 'SELECT_TP') if !client.selected_preduel
client.reconnecting = false ygopro.stoc_send(client, 'CHANGE_SIDE')
else client.reconnecting = false
ygopro.ctos_send(server, 'REQUEST_FIELD') break
else
ygopro.ctos_send(server, 'REQUEST_FIELD')
break
return return
CLIENT_pre_reconnect = (client) -> CLIENT_pre_reconnect = (client) ->
...@@ -957,11 +960,11 @@ SOCKET_flush_data = (sk, datas) -> ...@@ -957,11 +960,11 @@ SOCKET_flush_data = (sk, datas) ->
class Room class Room
constructor: (name, @hostinfo) -> constructor: (name, @hostinfo) ->
@name = name @name = name
@alive = true #@alive = true
@players = [] @players = []
@player_datas = [] @player_datas = []
@status = 'starting' @status = 'starting'
@started = false #@started = false
@established = false @established = false
@watcher_buffers = [] @watcher_buffers = []
@recorder_buffers = [] @recorder_buffers = []
...@@ -974,6 +977,7 @@ class Room ...@@ -974,6 +977,7 @@ class Room
@duel_count = 0 @duel_count = 0
@death = 0 @death = 0
@turn = 0 @turn = 0
@duel_stage = ygopro.constants.DUEL_STAGE.BEGIN
if settings.modules.replay_delay if settings.modules.replay_delay
@replays = [] @replays = []
ROOM_all.push this ROOM_all.push this
...@@ -1188,7 +1192,7 @@ class Room ...@@ -1188,7 +1192,7 @@ class Room
# log.info 'SCORE POST OK', response.statusCode, response.statusMessage, @name, body # log.info 'SCORE POST OK', response.statusCode, response.statusMessage, @name, body
return return
if settings.modules.challonge.enabled and @started and @hostinfo.mode != 2 and !@kicked if settings.modules.challonge.enabled and @duel_stage != ygopro.constants.DUEL_STAGE.BEGIN and @hostinfo.mode != 2 and !@kicked
room_name = @name room_name = @name
challonge.matches._update({ challonge.matches._update({
id: settings.modules.challonge.tournament_id, id: settings.modules.challonge.tournament_id,
...@@ -1272,7 +1276,7 @@ class Room ...@@ -1272,7 +1276,7 @@ class Room
return found return found
get_challonge_score: -> get_challonge_score: ->
if !settings.modules.challonge.enabled or !@started or @hostinfo.mode == 2 if !settings.modules.challonge.enabled or @duel_stage == ygopro.constants.DUEL_STAGE.BEGIN or @hostinfo.mode == 2
return null return null
challonge_duel_log = {} challonge_duel_log = {}
if @scores[@dueling_players[0].name_vpass] > @scores[@dueling_players[1].name_vpass] if @scores[@dueling_players[0].name_vpass] > @scores[@dueling_players[1].name_vpass]
...@@ -1334,7 +1338,7 @@ class Room ...@@ -1334,7 +1338,7 @@ class Room
ROOM_players_oppentlist[client.ip] = null ROOM_players_oppentlist[client.ip] = null
if @established if @established
roomlist.update(this) if !@windbot and !@started and settings.modules.http.websocket_roomlist roomlist.update(this) if !@windbot and @duel_stage == ygopro.constants.DUEL_STAGE.BEGIN and settings.modules.http.websocket_roomlist
client.server.connect @port, '127.0.0.1', -> client.server.connect @port, '127.0.0.1', ->
client.server.write buffer for buffer in client.pre_establish_buffers client.server.write buffer for buffer in client.pre_establish_buffers
client.established = true client.established = true
...@@ -1352,8 +1356,8 @@ class Room ...@@ -1352,8 +1356,8 @@ class Room
#client.room = null #client.room = null
client.server.destroy() client.server.destroy()
else else
#log.info(client.name, @started, @disconnector, @random_type, @players.length) #log.info(client.name, @duel_stage != ygopro.constants.DUEL_STAGE.BEGIN, @disconnector, @random_type, @players.length)
if @arena and !@started and @disconnector != 'server' and !@arena_score_handled if @arena and @duel_stage == ygopro.constants.DUEL_STAGE.BEGIN and @disconnector != 'server' and !@arena_score_handled
if settings.modules.arena_mode.punish_quit_before_match and @players.length == 2 and !client.arena_quit_free if settings.modules.arena_mode.punish_quit_before_match and @players.length == 2 and !client.arena_quit_free
for player in @players when player.pos != 7 for player in @players when player.pos != 7
@scores[player.name_vpass] = 0 @scores[player.name_vpass] = 0
...@@ -1364,7 +1368,7 @@ class Room ...@@ -1364,7 +1368,7 @@ class Room
@arena_score_handled = true @arena_score_handled = true
index = _.indexOf(@players, client) index = _.indexOf(@players, client)
@players.splice(index, 1) unless index == -1 @players.splice(index, 1) unless index == -1
if @started and @disconnector != 'server' and client.pos < 4 if @duel_stage != ygopro.constants.DUEL_STAGE.BEGIN and @disconnector != 'server' and client.pos < 4
@finished = true @finished = true
if !@finished_by_death if !@finished_by_death
@scores[client.name_vpass] = -9 @scores[client.name_vpass] = -9
...@@ -1372,10 +1376,10 @@ class Room ...@@ -1372,10 +1376,10 @@ class Room
ROOM_ban_player(client.name, client.ip, "${random_ban_reason_flee}") ROOM_ban_player(client.name, client.ip, "${random_ban_reason_flee}")
if settings.modules.random_duel.record_match_scores and @random_type == 'M' if settings.modules.random_duel.record_match_scores and @random_type == 'M'
ROOM_player_flee(client.name_vpass) ROOM_player_flee(client.name_vpass)
if @players.length and !(@windbot and client.is_host) and !(@arena and !@started and client.pos <= 3) if @players.length and !(@windbot and client.is_host) and !(@arena and @duel_stage == ygopro.constants.DUEL_STAGE.BEGIN and client.pos <= 3)
left_name = (if settings.modules.hide_name and !@started then "********" else client.name) left_name = (if settings.modules.hide_name and @duel_stage == ygopro.constants.DUEL_STAGE.BEGIN then "********" else client.name)
ygopro.stoc_send_chat_to_room this, "#{left_name} ${left_game}" + if error then ": #{error}" else '' ygopro.stoc_send_chat_to_room this, "#{left_name} ${left_game}" + if error then ": #{error}" else ''
roomlist.update(this) if !@windbot and !@started and settings.modules.http.websocket_roomlist roomlist.update(this) if !@windbot and @duel_stage == ygopro.constants.DUEL_STAGE.BEGIN and settings.modules.http.websocket_roomlist
#client.room = null #client.room = null
else else
@send_replays() @send_replays()
...@@ -1387,10 +1391,10 @@ class Room ...@@ -1387,10 +1391,10 @@ class Room
return return
start_death: () -> start_death: () ->
unless @established and @started and !@death if @duel_stage == ygopro.constants.DUEL_STAGE.BEGIN or @death
return false return false
oppo_pos = if @hostinfo.mode == 2 then 2 else 1 oppo_pos = if @hostinfo.mode == 2 then 2 else 1
if !@changing_side and (!@duel_count or @turn) # Extra duel started in duel if @duel_stage == ygopro.constants.DUEL_STAGE.DUELING
switch settings.modules.http.quick_death_rule switch settings.modules.http.quick_death_rule
when 3 when 3
@death = -2 @death = -2
...@@ -1427,7 +1431,7 @@ class Room ...@@ -1427,7 +1431,7 @@ class Room
return true return true
cancel_death: () -> cancel_death: () ->
unless @established and @started and @death if @duel_stage == ygopro.constants.DUEL_STAGE.BEGIN or !@death
return false return false
@death = 0 @death = 0
ygopro.stoc_send_chat_to_room(this, "${death_cancel}", ygopro.constants.COLORS.BABYBLUE) ygopro.stoc_send_chat_to_room(this, "${death_cancel}", ygopro.constants.COLORS.BABYBLUE)
...@@ -1916,7 +1920,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -1916,7 +1920,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
ygopro.stoc_die(client, "${server_full}") ygopro.stoc_die(client, "${server_full}")
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.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN
if settings.modules.cloud_replay.enable_halfway_watch and !room.hostinfo.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)
...@@ -1998,7 +2002,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -1998,7 +2002,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.hostinfo.no_watch if pre_room and pre_room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN 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)
...@@ -2060,7 +2064,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -2060,7 +2064,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
ygopro.stoc_die(client, "${server_full}") ygopro.stoc_die(client, "${server_full}")
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.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN
if settings.modules.cloud_replay.enable_halfway_watch and !room.hostinfo.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)
...@@ -2143,7 +2147,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -2143,7 +2147,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
ygopro.stoc_die(client, "${server_full}") ygopro.stoc_die(client, "${server_full}")
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.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN
if settings.modules.cloud_replay.enable_halfway_watch and !room.hostinfo.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)
...@@ -2302,7 +2306,7 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)-> ...@@ -2302,7 +2306,7 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
client.is_first = !(playertype & 0xf) client.is_first = !(playertype & 0xf)
client.lp = room.hostinfo.start_lp client.lp = room.hostinfo.start_lp
client.card_count = 0 if room.hostinfo.mode != 2 client.card_count = 0 if room.hostinfo.mode != 2
room.selecting_tp = false room.duel_stage = ygopro.constants.DUEL_STAGE.DUELING
if client.pos == 0 if client.pos == 0
room.turn = 0 room.turn = 0
room.duel_count++ room.duel_count++
...@@ -2324,7 +2328,7 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)-> ...@@ -2324,7 +2328,7 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
if ygopro.constants.MSG[msg] == 'NEW_TURN' if ygopro.constants.MSG[msg] == 'NEW_TURN'
if client.pos == 0 if client.pos == 0
room.turn = room.turn + 1 room.turn++
if room.death and room.death != -2 if room.death and room.death != -2
if room.turn >= room.death if room.turn >= room.death
oppo_pos = if room.hostinfo.mode == 2 then 2 else 1 oppo_pos = if room.hostinfo.mode == 2 then 2 else 1
...@@ -2371,13 +2375,14 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)-> ...@@ -2371,13 +2375,14 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
if ygopro.constants.MSG[msg] == 'WIN' and client.pos == 0 if ygopro.constants.MSG[msg] == 'WIN' and client.pos == 0
pos = buffer.readUInt8(1) pos = buffer.readUInt8(1)
pos = 1 - pos unless client.is_first or pos == 2 or room.turn <= 0 or !room.turn pos = 1 - pos unless client.is_first or pos == 2 or room.duel_stage != ygopro.constants.DUEL_STAGE.DUELING
pos = pos * 2 if pos >= 0 and room.hostinfo.mode == 2 pos = pos * 2 if pos >= 0 and room.hostinfo.mode == 2
reason = buffer.readUInt8(2) reason = buffer.readUInt8(2)
#log.info {winner: pos, reason: reason} #log.info {winner: pos, reason: reason}
#room.duels.push {winner: pos, reason: reason} #room.duels.push {winner: pos, reason: reason}
room.winner = pos room.winner = pos
room.turn = 0 room.turn = 0
room.duel_stage = ygopro.constants.DUEL_STAGE.END
if settings.modules.heartbeat_detection.enabled if settings.modules.heartbeat_detection.enabled
for player in room.players for player in room.players
player.heartbeat_protected = false player.heartbeat_protected = false
...@@ -2571,7 +2576,7 @@ ygopro.stoc_follow 'TYPE_CHANGE', true, (buffer, info, client, server, datas)-> ...@@ -2571,7 +2576,7 @@ ygopro.stoc_follow 'TYPE_CHANGE', true, (buffer, info, client, server, datas)->
ygopro.stoc_follow 'HS_PLAYER_ENTER', true, (buffer, info, client, server, datas)-> ygopro.stoc_follow 'HS_PLAYER_ENTER', true, (buffer, info, client, server, datas)->
room=ROOM_all[client.rid] room=ROOM_all[client.rid]
return false unless room and settings.modules.hide_name and !room.started return false unless room and settings.modules.hide_name and room.duel_stage == ygopro.constants.DUEL_STAGE.BEGIN
pos = info.pos pos = info.pos
if pos < 4 and pos != client.pos if pos < 4 and pos != client.pos
struct = ygopro.structs["STOC_HS_PlayerEnter"] struct = ygopro.structs["STOC_HS_PlayerEnter"]
...@@ -2654,7 +2659,7 @@ ygopro.stoc_follow 'DUEL_END', false, (buffer, info, client, server, datas)-> ...@@ -2654,7 +2659,7 @@ ygopro.stoc_follow 'DUEL_END', false, (buffer, info, client, server, datas)->
CLIENT_send_replays(player, room) CLIENT_send_replays(player, room)
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 if room and room.duel_stage == ygopro.constants.DUEL_STAGE.BEGIN and room.ready_player_count_without_host >= room.max_player - 1
time -= 1 time -= 1
if time if time
unless time % 5 unless time % 5
...@@ -2669,7 +2674,7 @@ wait_room_start = (room, time)-> ...@@ -2669,7 +2674,7 @@ wait_room_start = (room, time)->
return return
wait_room_start_arena = (room)-> wait_room_start_arena = (room)->
unless !room or room.started or !room.waiting_for_player if room and room.duel_stage == ygopro.constants.DUEL_STAGE.BEGIN and room.waiting_for_player
room.waiting_for_player_time = room.waiting_for_player_time - 1 room.waiting_for_player_time = room.waiting_for_player_time - 1
if room.waiting_for_player_time > 0 if room.waiting_for_player_time > 0
unless room.waiting_for_player_time % 5 unless room.waiting_for_player_time % 5
...@@ -2713,15 +2718,15 @@ if settings.modules.tips.get ...@@ -2713,15 +2718,15 @@ if settings.modules.tips.get
load_tips() load_tips()
setInterval ()-> setInterval ()->
for room in ROOM_all when room and room.established for room in ROOM_all when room and room.established
ygopro.stoc_send_random_tip_to_room(room) if !room.started or room.changing_side ygopro.stoc_send_random_tip_to_room(room) if room.duel_stage == ygopro.constants.DUEL_STAGE.SIDING or room.duel_stage == ygopro.constants.DUEL_STAGE.BEGIN
return return
, 30000 , 30000
ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server, datas)-> ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server, datas)->
room=ROOM_all[client.rid] room=ROOM_all[client.rid]
return unless room and !client.reconnecting return unless room and !client.reconnecting
unless room.started #first start if room.duel_stage == ygopro.constants.DUEL_STAGE.BEGIN #first start
room.started = true room.duel_stage = ygopro.constants.DUEL_STAGE.FINGER
room.start_time = moment().format() room.start_time = moment().format()
room.turn = 0 room.turn = 0
roomlist.start room if !room.windbot and settings.modules.http.websocket_roomlist roomlist.start room if !room.windbot and settings.modules.http.websocket_roomlist
...@@ -2787,7 +2792,7 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server, datas)-> ...@@ -2787,7 +2792,7 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server, datas)->
ygopro.ctos_follow 'SURRENDER', true, (buffer, info, client, server, datas)-> ygopro.ctos_follow 'SURRENDER', true, (buffer, info, client, server, datas)->
room=ROOM_all[client.rid] room=ROOM_all[client.rid]
return unless room return unless room
if !room.started or room.hostinfo.mode==2 if room.duel_stage == ygopro.constants.DUEL_STAGE.BEGIN or room.hostinfo.mode == 2
return true return true
if room.random_type and room.turn < 3 and not client.flee_free and not settings.modules.test_mode.surrender_anytime and not (room.random_type=='M' and settings.modules.random_duel.record_match_scores) if room.random_type and room.turn < 3 and not client.flee_free and not settings.modules.test_mode.surrender_anytime and not (room.random_type=='M' and settings.modules.random_duel.record_match_scores)
ygopro.stoc_send_chat(client, "${surrender_denied}", ygopro.constants.COLORS.BABYBLUE) ygopro.stoc_send_chat(client, "${surrender_denied}", ygopro.constants.COLORS.BABYBLUE)
...@@ -2824,7 +2829,7 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server, datas)-> ...@@ -2824,7 +2829,7 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server, datas)->
cmd = msg.split(' ') cmd = msg.split(' ')
switch cmd[0] switch cmd[0]
when '/投降', '/surrender' when '/投降', '/surrender'
if !room.started or room.hostinfo.mode==2 if room.duel_stage == ygopro.constants.DUEL_STAGE.BEGIN or room.hostinfo.mode == 2
return cancel return cancel
if room.random_type and room.turn < 3 if room.random_type and room.turn < 3
ygopro.stoc_send_chat(client, "${surrender_denied}", ygopro.constants.COLORS.BABYBLUE) ygopro.stoc_send_chat(client, "${surrender_denied}", ygopro.constants.COLORS.BABYBLUE)
...@@ -2921,7 +2926,7 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server, datas)-> ...@@ -2921,7 +2926,7 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server, datas)->
else else
client.abuse_count=client.abuse_count+4 client.abuse_count=client.abuse_count+4
ygopro.stoc_send_chat(client, "${chat_warn_level2}", ygopro.constants.COLORS.RED) ygopro.stoc_send_chat(client, "${chat_warn_level2}", ygopro.constants.COLORS.RED)
else if (client.rag and room.started) else if (client.rag and room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN)
client.rag = false client.rag = false
#ygopro.stoc_send_chat(client, "${chat_warn_level0}", ygopro.constants.COLORS.RED) #ygopro.stoc_send_chat(client, "${chat_warn_level0}", ygopro.constants.COLORS.RED)
cancel = true cancel = true
...@@ -3000,7 +3005,7 @@ ygopro.ctos_follow 'UPDATE_DECK', true, (buffer, info, client, server, datas)-> ...@@ -3000,7 +3005,7 @@ ygopro.ctos_follow 'UPDATE_DECK', true, (buffer, info, client, server, datas)->
buff_side = (info.deckbuf[i] for i in [info.mainc...info.mainc + info.sidec]) buff_side = (info.deckbuf[i] for i in [info.mainc...info.mainc + info.sidec])
client.main = buff_main client.main = buff_main
client.side = buff_side client.side = buff_side
if room.started if room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN
client.selected_preduel = true client.selected_preduel = true
if client.side_tcount if client.side_tcount
clearInterval client.side_interval clearInterval client.side_interval
...@@ -3009,7 +3014,7 @@ ygopro.ctos_follow 'UPDATE_DECK', true, (buffer, info, client, server, datas)-> ...@@ -3009,7 +3014,7 @@ ygopro.ctos_follow 'UPDATE_DECK', true, (buffer, info, client, server, datas)->
else else
client.start_deckbuf = Buffer.from(buffer) client.start_deckbuf = Buffer.from(buffer)
oppo_pos = if room.hostinfo.mode == 2 then 2 else 1 oppo_pos = if room.hostinfo.mode == 2 then 2 else 1
if settings.modules.http.quick_death_rule >= 2 and room.started and room.death and room.scores[room.dueling_players[0].name_vpass] != room.scores[room.dueling_players[oppo_pos].name_vpass] if settings.modules.http.quick_death_rule >= 2 and room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN and room.death and room.scores[room.dueling_players[0].name_vpass] != room.scores[room.dueling_players[oppo_pos].name_vpass]
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 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 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) ygopro.stoc_send_chat_to_room(room, "${death2_finish_part1}" + room.dueling_players[win_pos].name + "${death2_finish_part2}", ygopro.constants.COLORS.BABYBLUE)
...@@ -3020,7 +3025,7 @@ ygopro.ctos_follow 'UPDATE_DECK', true, (buffer, info, client, server, datas)-> ...@@ -3020,7 +3025,7 @@ ygopro.ctos_follow 'UPDATE_DECK', true, (buffer, info, client, server, datas)->
CLIENT_kick(room.dueling_players[oppo_pos - win_pos]) CLIENT_kick(room.dueling_players[oppo_pos - win_pos])
CLIENT_kick(room.dueling_players[oppo_pos - win_pos + 1]) if room.hostinfo.mode == 2 CLIENT_kick(room.dueling_players[oppo_pos - win_pos + 1]) if room.hostinfo.mode == 2
return true return true
if settings.modules.side_restrict.enabled and room.started if settings.modules.side_restrict.enabled and room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN
for code in settings.modules.side_restrict.restrict_cards for code in settings.modules.side_restrict.restrict_cards
if _.indexOf(buff_side, code) > -1 if _.indexOf(buff_side, code) > -1
ygopro.stoc_send_chat_to_room(room, "${invalid_side_rule}", ygopro.constants.COLORS.RED) ygopro.stoc_send_chat_to_room(room, "${invalid_side_rule}", ygopro.constants.COLORS.RED)
...@@ -3033,7 +3038,7 @@ ygopro.ctos_follow 'UPDATE_DECK', true, (buffer, info, client, server, datas)-> ...@@ -3033,7 +3038,7 @@ ygopro.ctos_follow 'UPDATE_DECK', true, (buffer, info, client, server, datas)->
if client.pos == 0 if client.pos == 0
room.waiting_for_player = room.waiting_for_player2 room.waiting_for_player = room.waiting_for_player2
room.last_active_time = moment() room.last_active_time = moment()
else if !room.started and room.hostinfo.mode == 1 and settings.modules.tournament_mode.enabled and settings.modules.tournament_mode.deck_check and fs.readdirSync(settings.modules.tournament_mode.deck_path).length else if room.duel_stage == ygopro.constants.DUEL_STAGE.BEGIN and room.hostinfo.mode == 1 and settings.modules.tournament_mode.enabled and settings.modules.tournament_mode.deck_check and fs.readdirSync(settings.modules.tournament_mode.deck_path).length
struct = ygopro.structs["deck"] struct = ygopro.structs["deck"]
struct._setBuff(buffer) struct._setBuff(buffer)
struct.set("mainc", 1) struct.set("mainc", 1)
...@@ -3089,7 +3094,7 @@ ygopro.stoc_follow 'TIME_LIMIT', true, (buffer, info, client, server, datas)-> ...@@ -3089,7 +3094,7 @@ ygopro.stoc_follow 'TIME_LIMIT', true, (buffer, info, client, server, datas)->
return true return true
else else
client.time_confirm_required = true client.time_confirm_required = true
return unless settings.modules.heartbeat_detection.enabled and room.turn and room.turn > 0 and !room.windbot return unless settings.modules.heartbeat_detection.enabled and room.duel_stage == ygopro.constants.DUEL_STAGE.DUELING and !room.windbot
check = false check = false
if room.hostinfo.mode != 2 if room.hostinfo.mode != 2
check = (client.is_first and info.player == 0) or (!client.is_first and info.player == 1) check = (client.is_first and info.player == 0) or (!client.is_first and info.player == 1)
...@@ -3155,8 +3160,8 @@ ygopro.ctos_follow 'TP_RESULT', false, (buffer, info, client, server, datas)-> ...@@ -3155,8 +3160,8 @@ ygopro.ctos_follow 'TP_RESULT', false, (buffer, info, client, server, datas)->
ygopro.stoc_follow 'CHAT', true, (buffer, info, client, server, datas)-> ygopro.stoc_follow 'CHAT', true, (buffer, info, client, server, datas)->
room=ROOM_all[client.rid] room=ROOM_all[client.rid]
pid = info.player pid = info.player
return unless room and pid < 4 and settings.modules.chat_color.enabled and (!settings.modules.hide_name or room.started) return unless room and pid < 4 and settings.modules.chat_color.enabled and (!settings.modules.hide_name or room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN)
if room.started and room.turn > 0 and !room.dueling_players[0].is_first if room.duel_stage == ygopro.constants.DUEL_STAGE.DUELING and !room.dueling_players[0].is_first
if room.hostinfo.mode == 2 if room.hostinfo.mode == 2
pid = { pid = {
0: 2, 0: 2,
...@@ -3183,8 +3188,7 @@ ygopro.stoc_follow 'SELECT_HAND', false, (buffer, info, client, server, datas)-> ...@@ -3183,8 +3188,7 @@ ygopro.stoc_follow 'SELECT_HAND', false, (buffer, info, client, server, datas)->
return unless room return unless room
client.selected_preduel = false client.selected_preduel = false
if client.pos == 0 if client.pos == 0
room.selecting_hand = true room.duel_stage = ygopro.constants.DUEL_STAGE.FINGER
room.changing_side = false
return unless room.random_type or room.arena return unless room.random_type or room.arena
if client.pos == 0 if client.pos == 0
room.waiting_for_player = client room.waiting_for_player = client
...@@ -3197,8 +3201,7 @@ ygopro.stoc_follow 'SELECT_TP', false, (buffer, info, client, server, datas)-> ...@@ -3197,8 +3201,7 @@ ygopro.stoc_follow 'SELECT_TP', false, (buffer, info, client, server, datas)->
room=ROOM_all[client.rid] room=ROOM_all[client.rid]
return unless room return unless room
client.selected_preduel = false client.selected_preduel = false
room.changing_side = false room.duel_stage = ygopro.constants.DUEL_STAGE.FIRSTGO
room.selecting_hand = false
room.selecting_tp = client room.selecting_tp = client
if room.random_type or room.arena if room.random_type or room.arena
room.waiting_for_player = client room.waiting_for_player = client
...@@ -3208,13 +3211,14 @@ ygopro.stoc_follow 'SELECT_TP', false, (buffer, info, client, server, datas)-> ...@@ -3208,13 +3211,14 @@ ygopro.stoc_follow 'SELECT_TP', false, (buffer, info, client, server, datas)->
ygopro.stoc_follow 'CHANGE_SIDE', false, (buffer, info, client, server, datas)-> ygopro.stoc_follow 'CHANGE_SIDE', false, (buffer, info, client, server, datas)->
room=ROOM_all[client.rid] room=ROOM_all[client.rid]
return unless room return unless room
room.changing_side = true if client.pos == 0
room.duel_stage = ygopro.constants.DUEL_STAGE.SIDING
client.selected_preduel = false client.selected_preduel = false
if settings.modules.side_timeout if settings.modules.side_timeout
client.side_tcount = settings.modules.side_timeout client.side_tcount = settings.modules.side_timeout
ygopro.stoc_send_chat(client, "${side_timeout_part1}#{settings.modules.side_timeout}${side_timeout_part2}", ygopro.constants.COLORS.BABYBLUE) ygopro.stoc_send_chat(client, "${side_timeout_part1}#{settings.modules.side_timeout}${side_timeout_part2}", ygopro.constants.COLORS.BABYBLUE)
sinterval = setInterval ()-> sinterval = setInterval ()->
if not (room and room.started and client and client.side_tcount and room.changing_side) if not (room and client and client.side_tcount and room.duel_stage == ygopro.constants.DUEL_STAGE.SIDING)
clearInterval sinterval clearInterval sinterval
return return
if client.side_tcount == 1 if client.side_tcount == 1
...@@ -3296,7 +3300,7 @@ ygopro.stoc_follow 'REPLAY', true, (buffer, info, client, server, datas)-> ...@@ -3296,7 +3300,7 @@ ygopro.stoc_follow 'REPLAY', true, (buffer, info, client, server, datas)->
if settings.modules.random_duel.enabled if settings.modules.random_duel.enabled
setInterval ()-> 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 and room.get_disconnected_count() == 0 for room in ROOM_all when room and room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN and room.random_type and room.last_active_time and room.waiting_for_player and room.get_disconnected_count() == 0
time_passed = Math.floor((moment() - room.last_active_time) / 1000) time_passed = Math.floor((moment() - room.last_active_time) / 1000)
#log.info time_passed #log.info time_passed
if time_passed >= settings.modules.random_duel.hang_timeout if time_passed >= settings.modules.random_duel.hang_timeout
...@@ -3315,7 +3319,7 @@ if settings.modules.random_duel.enabled ...@@ -3315,7 +3319,7 @@ if settings.modules.random_duel.enabled
if settings.modules.mycard.enabled if settings.modules.mycard.enabled
setInterval ()-> setInterval ()->
for room in ROOM_all when room and room.started and room.arena and room.last_active_time and room.waiting_for_player and room.get_disconnected_count() == 0 for room in ROOM_all when room and room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN and room.arena and room.last_active_time and room.waiting_for_player and room.get_disconnected_count() == 0
time_passed = Math.floor((moment() - room.last_active_time) / 1000) time_passed = Math.floor((moment() - room.last_active_time) / 1000)
#log.info time_passed #log.info time_passed
if time_passed >= settings.modules.random_duel.hang_timeout if time_passed >= settings.modules.random_duel.hang_timeout
...@@ -3328,7 +3332,7 @@ if settings.modules.mycard.enabled ...@@ -3328,7 +3332,7 @@ if settings.modules.mycard.enabled
else if time_passed >= (settings.modules.random_duel.hang_timeout - 20) and not (time_passed % 10) else if time_passed >= (settings.modules.random_duel.hang_timeout - 20) and not (time_passed % 10)
ygopro.stoc_send_chat_to_room(room, "#{room.waiting_for_player.name} ${afk_warn_part1}#{settings.modules.random_duel.hang_timeout - time_passed}${afk_warn_part2}", ygopro.constants.COLORS.RED) ygopro.stoc_send_chat_to_room(room, "#{room.waiting_for_player.name} ${afk_warn_part1}#{settings.modules.random_duel.hang_timeout - time_passed}${afk_warn_part2}", ygopro.constants.COLORS.RED)
if settings.modules.arena_mode.punish_quit_before_match if settings.modules.arena_mode.punish_quit_before_match
for room in ROOM_all when room and room.arena and !room.started and room.get_playing_player().length < 2 for room in ROOM_all when room and room.arena and room.duel_stage == ygopro.constants.DUEL_STAGE.BEGIN and room.get_playing_player().length < 2
player = room.get_playing_player()[0] player = room.get_playing_player()[0]
if player and player.join_time and !player.arena_quit_free if player and player.join_time and !player.arena_quit_free
waited_time = moment() - player.join_time waited_time = moment() - player.join_time
...@@ -3342,15 +3346,15 @@ if settings.modules.mycard.enabled ...@@ -3342,15 +3346,15 @@ if settings.modules.mycard.enabled
if settings.modules.heartbeat_detection.enabled if settings.modules.heartbeat_detection.enabled
setInterval ()-> setInterval ()->
for room in ROOM_all when room and room.started and (room.hostinfo.time_limit == 0 or !room.turn or room.turn <= 0) and !room.windbot for room in ROOM_all when room and room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN and (room.hostinfo.time_limit == 0 or room.duel_stage != ygopro.constants.DUEL_STAGE.DUELING) and !room.windbot
for player in room.get_playing_player() when player and (!room.changing_side or player.selected_preduel) for player in room.get_playing_player() when player and (room.duel_stage != ygopro.constants.DUEL_STAGE.SIDING or player.selected_preduel)
CLIENT_heartbeat_register(player, true) CLIENT_heartbeat_register(player, true)
return return
, settings.modules.heartbeat_detection.interval , settings.modules.heartbeat_detection.interval
setInterval ()-> setInterval ()->
current_time = moment() 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 for room in ROOM_all when room and room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN 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.auto_death_triggered = true
room.start_death() room.start_death()
...@@ -3425,14 +3429,14 @@ if settings.modules.http ...@@ -3425,14 +3429,14 @@ if settings.modules.http
id: (-1).toString(), id: (-1).toString(),
name: player.name, name: player.name,
ip: if settings.modules.http.show_ip and pass_validated and !player.is_local then player.ip.slice(7) else null, ip: if settings.modules.http.show_ip and pass_validated and !player.is_local then player.ip.slice(7) else null,
status: if settings.modules.http.show_info and room.started and player.pos != 7 then ( status: if settings.modules.http.show_info and room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN and player.pos != 7 then (
score: room.scores[player.name_vpass], score: room.scores[player.name_vpass],
lp: if player.lp? then player.lp else room.hostinfo.start_lp, lp: if player.lp? then player.lp else room.hostinfo.start_lp,
cards: if room.hostinfo.mode != 2 then (if player.card_count? then player.card_count else room.hostinfo.start_hand) else null cards: if room.hostinfo.mode != 2 then (if player.card_count? then player.card_count else room.hostinfo.start_hand) else null
) else null, ) else null,
pos: player.pos pos: player.pos
), "pos"), ), "pos"),
istart: if room.started then (if settings.modules.http.show_info then ("Duel:" + room.duel_count + " " + (if room.changing_side then "Siding" else "Turn:" + (if room.turn? then room.turn else 0) + (if room.death then "/" + (if room.death > 0 then room.death - 1 else "Death") else ""))) else 'start') else 'wait' istart: if room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN then (if settings.modules.http.show_info then ("Duel:" + room.duel_count + " " + (if room.duel_stage == ygopro.constants.DUEL_STAGE.SIDING then "Siding" else "Turn:" + (if room.turn? then room.turn else 0) + (if room.death then "/" + (if room.death > 0 then room.death - 1 else "Death") else ""))) else 'start') else 'wait'
), null, 2 ), null, 2
response.end(addCallback(u.query.callback, roomsjson)) response.end(addCallback(u.query.callback, roomsjson))
...@@ -3602,7 +3606,7 @@ if settings.modules.http ...@@ -3602,7 +3606,7 @@ if settings.modules.http
kick_room_found = false kick_room_found = false
for room in ROOM_all when room and room.established and (u.query.kick == "all" or u.query.kick == room.process_pid.toString() or u.query.kick == room.name) for room in ROOM_all when room and room.established and (u.query.kick == "all" or u.query.kick == room.process_pid.toString() or u.query.kick == room.name)
kick_room_found = true kick_room_found = true
if room.started if room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN
room.scores[room.dueling_players[0].name_vpass] = 0 room.scores[room.dueling_players[0].name_vpass] = 0
room.scores[room.dueling_players[1].name_vpass] = 0 room.scores[room.dueling_players[1].name_vpass] = 0
room.kicked = true room.kicked = true
...@@ -3636,7 +3640,7 @@ if settings.modules.http ...@@ -3636,7 +3640,7 @@ 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 (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.deathcancel == "all" or u.query.deathcancel == room.process_pid.toString() or u.query.deathcancel == room.name)
if room.cancel_death() if room.cancel_death()
death_room_found = true death_room_found = true
response.writeHead(200) response.writeHead(200)
...@@ -3651,7 +3655,7 @@ if settings.modules.http ...@@ -3651,7 +3655,7 @@ if settings.modules.http
response.end(addCallback(u.query.callback, "['密码错误', 0]")) response.end(addCallback(u.query.callback, "['密码错误', 0]"))
return return
for room in ROOM_all when room for room in ROOM_all when room
if room.started if room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN
room.scores[room.dueling_players[0].name_vpass] = 0 room.scores[room.dueling_players[0].name_vpass] = 0
room.scores[room.dueling_players[1].name_vpass] = 0 room.scores[room.dueling_players[1].name_vpass] = 0
room.kicked = true room.kicked = true
......
...@@ -703,7 +703,7 @@ ...@@ -703,7 +703,7 @@
max_player = type === 'T' ? 4 : 2; max_player = type === 'T' ? 4 : 2;
playerbanned = bannedplayer && bannedplayer.count > 3 && moment() < bannedplayer.time; playerbanned = bannedplayer && bannedplayer.count > 3 && moment() < bannedplayer.time;
result = _.find(ROOM_all, function(room) { result = _.find(ROOM_all, function(room) {
return room && room.random_type !== '' && !room.started && !room.windbot && ((type === '' && (room.random_type === 'S' || (settings.modules.random_duel.blank_pass_match && room.random_type !== 'T'))) || room.random_type === type) && room.get_playing_player().length < max_player && (settings.modules.random_duel.no_rematch_check || room.get_host() === null || room.get_host().ip !== ROOM_players_oppentlist[player_ip]) && (playerbanned === room.deprecated || type === 'T'); return room && room.random_type !== '' && room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN && !room.windbot && ((type === '' && (room.random_type === 'S' || (settings.modules.random_duel.blank_pass_match && room.random_type !== 'T'))) || room.random_type === type) && room.get_playing_player().length < max_player && (settings.modules.random_duel.no_rematch_check || room.get_host() === null || room.get_host().ip !== ROOM_players_oppentlist[player_ip]) && (playerbanned === room.deprecated || type === 'T');
}); });
if (result) { if (result) {
result.welcome = '${random_duel_enter_room_waiting}'; result.welcome = '${random_duel_enter_room_waiting}';
...@@ -878,7 +878,7 @@ ...@@ -878,7 +878,7 @@
if (client.had_new_reconnection) { if (client.had_new_reconnection) {
return false; return false;
} }
if (!settings.modules.reconnect.enabled || !room || client.system_kicked || client.flee_free || disconnect_list[CLIENT_get_authorize_key(client)] || client.is_post_watcher || !CLIENT_is_player(client, room) || !room.started || room.windbot || (settings.modules.reconnect.auto_surrender_after_disconnect && room.hostinfo.mode !== 1) || (room.random_type && room.get_disconnected_count() > 1)) { if (!settings.modules.reconnect.enabled || !room || client.system_kicked || client.flee_free || disconnect_list[CLIENT_get_authorize_key(client)] || client.is_post_watcher || !CLIENT_is_player(client, room) || room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN || room.windbot || (settings.modules.reconnect.auto_surrender_after_disconnect && room.hostinfo.mode !== 1) || (room.random_type && room.get_disconnected_count() > 1)) {
return false; return false;
} }
dinfo = { dinfo = {
...@@ -898,7 +898,7 @@ ...@@ -898,7 +898,7 @@
client.time_confirm_required = false; client.time_confirm_required = false;
ygopro.ctos_send(client.server, 'TIME_CONFIRM'); ygopro.ctos_send(client.server, 'TIME_CONFIRM');
} }
if (settings.modules.reconnect.auto_surrender_after_disconnect && room.turn && room.turn > 0) { if (settings.modules.reconnect.auto_surrender_after_disconnect && room.duel_stage === ygopro.constants.DUEL_STAGE.DUELING) {
ygopro.ctos_send(client.server, 'SURRENDER'); ygopro.ctos_send(client.server, 'SURRENDER');
} }
return true; return true;
...@@ -1004,7 +1004,7 @@ ...@@ -1004,7 +1004,7 @@
var len2, len3, m, n, player, ref2, room; var len2, len3, m, n, player, ref2, room;
for (m = 0, len2 = ROOM_all.length; m < len2; m++) { for (m = 0, len2 = ROOM_all.length; m < len2; m++) {
room = ROOM_all[m]; room = ROOM_all[m];
if (room && room.started && !room.windbot) { if (room && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && !room.windbot) {
ref2 = room.get_playing_player(); ref2 = room.get_playing_player();
for (n = 0, len3 = ref2.length; n < len3; n++) { for (n = 0, len3 = ref2.length; n < len3; n++) {
player = ref2[n]; player = ref2[n];
...@@ -1051,28 +1051,31 @@ ...@@ -1051,28 +1051,31 @@
CLIENT_send_reconnect_info = function(client, server, room) { CLIENT_send_reconnect_info = function(client, server, room) {
client.reconnecting = true; client.reconnecting = true;
ygopro.stoc_send_chat(client, "${reconnecting_to_room}", ygopro.constants.COLORS.BABYBLUE); ygopro.stoc_send_chat(client, "${reconnecting_to_room}", ygopro.constants.COLORS.BABYBLUE);
if (room.turn && room.turn > 0) { switch (room.duel_stage) {
ygopro.ctos_send(server, 'REQUEST_FIELD'); case ygopro.constants.DUEL_STAGE.FINGER:
} else if (room.changing_side) { ygopro.stoc_send(client, 'DUEL_START');
ygopro.stoc_send(client, 'DUEL_START'); if ((room.hostinfo.mode !== 2 || client.pos === 0 || client.pos === 2) && !client.selected_preduel) {
if (!client.selected_preduel) { ygopro.stoc_send(client, 'SELECT_HAND');
ygopro.stoc_send(client, 'CHANGE_SIDE'); }
} client.reconnecting = false;
client.reconnecting = false; break;
} else if (room.selecting_hand) { case ygopro.constants.DUEL_STAGE.FIRSTGO:
ygopro.stoc_send(client, 'DUEL_START'); ygopro.stoc_send(client, 'DUEL_START');
if ((room.hostinfo.mode !== 2 || client.pos === 0 || client.pos === 2) && !client.selected_preduel) { if (client === room.selecting_tp) {
ygopro.stoc_send(client, 'SELECT_HAND'); ygopro.stoc_send(client, 'SELECT_TP');
} }
client.reconnecting = false; client.reconnecting = false;
} else if (room.selecting_tp) { break;
ygopro.stoc_send(client, 'DUEL_START'); case ygopro.constants.DUEL_STAGE.SIDING:
if (client === room.selecting_tp) { ygopro.stoc_send(client, 'DUEL_START');
ygopro.stoc_send(client, 'SELECT_TP'); if (!client.selected_preduel) {
} ygopro.stoc_send(client, 'CHANGE_SIDE');
client.reconnecting = false; }
} else { client.reconnecting = false;
ygopro.ctos_send(server, 'REQUEST_FIELD'); break;
default:
ygopro.ctos_send(server, 'REQUEST_FIELD');
break;
} }
}; };
...@@ -1233,11 +1236,9 @@ ...@@ -1233,11 +1236,9 @@
var death_time, draw_count, lflist, param, rule, start_hand, start_lp, time_limit; var death_time, draw_count, lflist, param, rule, start_hand, start_lp, time_limit;
this.hostinfo = hostinfo; this.hostinfo = hostinfo;
this.name = name; this.name = name;
this.alive = true;
this.players = []; this.players = [];
this.player_datas = []; this.player_datas = [];
this.status = 'starting'; this.status = 'starting';
this.started = false;
this.established = false; this.established = false;
this.watcher_buffers = []; this.watcher_buffers = [];
this.recorder_buffers = []; this.recorder_buffers = [];
...@@ -1250,6 +1251,7 @@ ...@@ -1250,6 +1251,7 @@
this.duel_count = 0; this.duel_count = 0;
this.death = 0; this.death = 0;
this.turn = 0; this.turn = 0;
this.duel_stage = ygopro.constants.DUEL_STAGE.BEGIN;
if (settings.modules.replay_delay) { if (settings.modules.replay_delay) {
this.replays = []; this.replays = [];
} }
...@@ -1537,7 +1539,7 @@ ...@@ -1537,7 +1539,7 @@
}; };
})(this)); })(this));
} }
if (settings.modules.challonge.enabled && this.started && this.hostinfo.mode !== 2 && !this.kicked) { if (settings.modules.challonge.enabled && this.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && this.hostinfo.mode !== 2 && !this.kicked) {
room_name = this.name; room_name = this.name;
challonge.matches._update({ challonge.matches._update({
id: settings.modules.challonge.tournament_id, id: settings.modules.challonge.tournament_id,
...@@ -1646,7 +1648,7 @@ ...@@ -1646,7 +1648,7 @@
Room.prototype.get_challonge_score = function() { Room.prototype.get_challonge_score = function() {
var challonge_duel_log; var challonge_duel_log;
if (!settings.modules.challonge.enabled || !this.started || this.hostinfo.mode === 2) { if (!settings.modules.challonge.enabled || this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN || this.hostinfo.mode === 2) {
return null; return null;
} }
challonge_duel_log = {}; challonge_duel_log = {};
...@@ -1725,7 +1727,7 @@ ...@@ -1725,7 +1727,7 @@
} }
} }
if (this.established) { if (this.established) {
if (!this.windbot && !this.started && settings.modules.http.websocket_roomlist) { if (!this.windbot && this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN && settings.modules.http.websocket_roomlist) {
roomlist.update(this); roomlist.update(this);
} }
client.server.connect(this.port, '127.0.0.1', function() { client.server.connect(this.port, '127.0.0.1', function() {
...@@ -1754,7 +1756,7 @@ ...@@ -1754,7 +1756,7 @@
} }
client.server.destroy(); client.server.destroy();
} else { } else {
if (this.arena && !this.started && this.disconnector !== 'server' && !this.arena_score_handled) { if (this.arena && this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN && this.disconnector !== 'server' && !this.arena_score_handled) {
if (settings.modules.arena_mode.punish_quit_before_match && this.players.length === 2 && !client.arena_quit_free) { if (settings.modules.arena_mode.punish_quit_before_match && this.players.length === 2 && !client.arena_quit_free) {
ref2 = this.players; ref2 = this.players;
for (m = 0, len2 = ref2.length; m < len2; m++) { for (m = 0, len2 = ref2.length; m < len2; m++) {
...@@ -1779,7 +1781,7 @@ ...@@ -1779,7 +1781,7 @@
if (index !== -1) { if (index !== -1) {
this.players.splice(index, 1); this.players.splice(index, 1);
} }
if (this.started && this.disconnector !== 'server' && client.pos < 4) { if (this.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && this.disconnector !== 'server' && client.pos < 4) {
this.finished = true; this.finished = true;
if (!this.finished_by_death) { if (!this.finished_by_death) {
this.scores[client.name_vpass] = -9; this.scores[client.name_vpass] = -9;
...@@ -1791,10 +1793,10 @@ ...@@ -1791,10 +1793,10 @@
} }
} }
} }
if (this.players.length && !(this.windbot && client.is_host) && !(this.arena && !this.started && client.pos <= 3)) { if (this.players.length && !(this.windbot && client.is_host) && !(this.arena && this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN && client.pos <= 3)) {
left_name = (settings.modules.hide_name && !this.started ? "********" : client.name); left_name = (settings.modules.hide_name && this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN ? "********" : client.name);
ygopro.stoc_send_chat_to_room(this, (left_name + " ${left_game}") + (error ? ": " + error : '')); ygopro.stoc_send_chat_to_room(this, (left_name + " ${left_game}") + (error ? ": " + error : ''));
if (!this.windbot && !this.started && settings.modules.http.websocket_roomlist) { if (!this.windbot && this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN && settings.modules.http.websocket_roomlist) {
roomlist.update(this); roomlist.update(this);
} }
} else { } else {
...@@ -1810,11 +1812,11 @@ ...@@ -1810,11 +1812,11 @@
Room.prototype.start_death = function() { Room.prototype.start_death = function() {
var oppo_pos, win_pos; var oppo_pos, win_pos;
if (!(this.established && this.started && !this.death)) { if (this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN || this.death) {
return false; return false;
} }
oppo_pos = this.hostinfo.mode === 2 ? 2 : 1; oppo_pos = this.hostinfo.mode === 2 ? 2 : 1;
if (!this.changing_side && (!this.duel_count || this.turn)) { if (this.duel_stage === ygopro.constants.DUEL_STAGE.DUELING) {
switch (settings.modules.http.quick_death_rule) { switch (settings.modules.http.quick_death_rule) {
case 3: case 3:
this.death = -2; this.death = -2;
...@@ -1867,7 +1869,7 @@ ...@@ -1867,7 +1869,7 @@
}; };
Room.prototype.cancel_death = function() { Room.prototype.cancel_death = function() {
if (!(this.established && this.started && this.death)) { if (this.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN || !this.death) {
return false; return false;
} }
this.death = 0; this.death = 0;
...@@ -2400,7 +2402,7 @@ ...@@ -2400,7 +2402,7 @@
ygopro.stoc_die(client, "${server_full}"); ygopro.stoc_die(client, "${server_full}");
} 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.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) {
if (settings.modules.cloud_replay.enable_halfway_watch && !room.hostinfo.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);
...@@ -2497,7 +2499,7 @@ ...@@ -2497,7 +2499,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.hostinfo.no_watch) { if (pre_room && pre_room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && 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);
...@@ -2575,7 +2577,7 @@ ...@@ -2575,7 +2577,7 @@
ygopro.stoc_die(client, "${server_full}"); ygopro.stoc_die(client, "${server_full}");
} 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.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) {
if (settings.modules.cloud_replay.enable_halfway_watch && !room.hostinfo.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;
...@@ -2652,7 +2654,7 @@ ...@@ -2652,7 +2654,7 @@
ygopro.stoc_die(client, "${server_full}"); ygopro.stoc_die(client, "${server_full}");
} 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.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) {
if (settings.modules.cloud_replay.enable_halfway_watch && !room.hostinfo.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);
...@@ -2841,7 +2843,7 @@ ...@@ -2841,7 +2843,7 @@
if (room.hostinfo.mode !== 2) { if (room.hostinfo.mode !== 2) {
client.card_count = 0; client.card_count = 0;
} }
room.selecting_tp = false; room.duel_stage = ygopro.constants.DUEL_STAGE.DUELING;
if (client.pos === 0) { if (client.pos === 0) {
room.turn = 0; room.turn = 0;
room.duel_count++; room.duel_count++;
...@@ -2866,7 +2868,7 @@ ...@@ -2866,7 +2868,7 @@
} }
if (ygopro.constants.MSG[msg] === 'NEW_TURN') { if (ygopro.constants.MSG[msg] === 'NEW_TURN') {
if (client.pos === 0) { if (client.pos === 0) {
room.turn = room.turn + 1; room.turn++;
if (room.death && room.death !== -2) { if (room.death && room.death !== -2) {
if (room.turn >= room.death) { if (room.turn >= room.death) {
oppo_pos = room.hostinfo.mode === 2 ? 2 : 1; oppo_pos = room.hostinfo.mode === 2 ? 2 : 1;
...@@ -2922,7 +2924,7 @@ ...@@ -2922,7 +2924,7 @@
} }
if (ygopro.constants.MSG[msg] === 'WIN' && client.pos === 0) { if (ygopro.constants.MSG[msg] === 'WIN' && client.pos === 0) {
pos = buffer.readUInt8(1); pos = buffer.readUInt8(1);
if (!(client.is_first || pos === 2 || room.turn <= 0 || !room.turn)) { if (!(client.is_first || pos === 2 || room.duel_stage !== ygopro.constants.DUEL_STAGE.DUELING)) {
pos = 1 - pos; pos = 1 - pos;
} }
if (pos >= 0 && room.hostinfo.mode === 2) { if (pos >= 0 && room.hostinfo.mode === 2) {
...@@ -2931,6 +2933,7 @@ ...@@ -2931,6 +2933,7 @@
reason = buffer.readUInt8(2); reason = buffer.readUInt8(2);
room.winner = pos; room.winner = pos;
room.turn = 0; room.turn = 0;
room.duel_stage = ygopro.constants.DUEL_STAGE.END;
if (settings.modules.heartbeat_detection.enabled) { if (settings.modules.heartbeat_detection.enabled) {
ref2 = room.players; ref2 = room.players;
for (m = 0, len2 = ref2.length; m < len2; m++) { for (m = 0, len2 = ref2.length; m < len2; m++) {
...@@ -3194,7 +3197,7 @@ ...@@ -3194,7 +3197,7 @@
ygopro.stoc_follow('HS_PLAYER_ENTER', true, function(buffer, info, client, server, datas) { ygopro.stoc_follow('HS_PLAYER_ENTER', true, function(buffer, info, client, server, datas) {
var pos, room, struct; var pos, room, struct;
room = ROOM_all[client.rid]; room = ROOM_all[client.rid];
if (!(room && settings.modules.hide_name && !room.started)) { if (!(room && settings.modules.hide_name && room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN)) {
return false; return false;
} }
pos = info.pos; pos = info.pos;
...@@ -3330,7 +3333,7 @@ ...@@ -3330,7 +3333,7 @@
wait_room_start = function(room, time) { wait_room_start = function(room, time) {
var len2, m, player, ref2; var len2, m, player, ref2;
if (!(!room || room.started || room.ready_player_count_without_host < room.max_player - 1)) { if (room && room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN && room.ready_player_count_without_host >= room.max_player - 1) {
time -= 1; time -= 1;
if (time) { if (time) {
if (!(time % 5)) { if (!(time % 5)) {
...@@ -3355,7 +3358,7 @@ ...@@ -3355,7 +3358,7 @@
wait_room_start_arena = function(room) { wait_room_start_arena = function(room) {
var display_name, len2, m, player, ref2; var display_name, len2, m, player, ref2;
if (!(!room || room.started || !room.waiting_for_player)) { if (room && room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN && room.waiting_for_player) {
room.waiting_for_player_time = room.waiting_for_player_time - 1; room.waiting_for_player_time = room.waiting_for_player_time - 1;
if (room.waiting_for_player_time > 0) { if (room.waiting_for_player_time > 0) {
if (!(room.waiting_for_player_time % 5)) { if (!(room.waiting_for_player_time % 5)) {
...@@ -3415,7 +3418,7 @@ ...@@ -3415,7 +3418,7 @@
for (m = 0, len2 = ROOM_all.length; m < len2; m++) { for (m = 0, len2 = ROOM_all.length; m < len2; m++) {
room = ROOM_all[m]; room = ROOM_all[m];
if (room && room.established) { if (room && room.established) {
if (!room.started || room.changing_side) { if (room.duel_stage === ygopro.constants.DUEL_STAGE.SIDING || room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN) {
ygopro.stoc_send_random_tip_to_room(room); ygopro.stoc_send_random_tip_to_room(room);
} }
} }
...@@ -3429,8 +3432,8 @@ ...@@ -3429,8 +3432,8 @@
if (!(room && !client.reconnecting)) { if (!(room && !client.reconnecting)) {
return; return;
} }
if (!room.started) { if (room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN) {
room.started = true; room.duel_stage = ygopro.constants.DUEL_STAGE.FINGER;
room.start_time = moment().format(); room.start_time = moment().format();
room.turn = 0; room.turn = 0;
if (!room.windbot && settings.modules.http.websocket_roomlist) { if (!room.windbot && settings.modules.http.websocket_roomlist) {
...@@ -3527,7 +3530,7 @@ ...@@ -3527,7 +3530,7 @@
if (!room) { if (!room) {
return; return;
} }
if (!room.started || room.hostinfo.mode === 2) { if (room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN || room.hostinfo.mode === 2) {
return true; return true;
} }
if (room.random_type && room.turn < 3 && !client.flee_free && !settings.modules.test_mode.surrender_anytime && !(room.random_type === 'M' && settings.modules.random_duel.record_match_scores)) { if (room.random_type && room.turn < 3 && !client.flee_free && !settings.modules.test_mode.surrender_anytime && !(room.random_type === 'M' && settings.modules.random_duel.record_match_scores)) {
...@@ -3578,7 +3581,7 @@ ...@@ -3578,7 +3581,7 @@
switch (cmd[0]) { switch (cmd[0]) {
case '/投降': case '/投降':
case '/surrender': case '/surrender':
if (!room.started || room.hostinfo.mode === 2) { if (room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN || room.hostinfo.mode === 2) {
return cancel; return cancel;
} }
if (room.random_type && room.turn < 3) { if (room.random_type && room.turn < 3) {
...@@ -3712,7 +3715,7 @@ ...@@ -3712,7 +3715,7 @@
client.abuse_count = client.abuse_count + 4; client.abuse_count = client.abuse_count + 4;
ygopro.stoc_send_chat(client, "${chat_warn_level2}", ygopro.constants.COLORS.RED); ygopro.stoc_send_chat(client, "${chat_warn_level2}", ygopro.constants.COLORS.RED);
} }
} else if (client.rag && room.started) { } else if (client.rag && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) {
client.rag = false; client.rag = false;
cancel = true; cancel = true;
} else if (_.any(settings.ban.spam_word, function(badword) { } else if (_.any(settings.ban.spam_word, function(badword) {
...@@ -3815,7 +3818,7 @@ ...@@ -3815,7 +3818,7 @@
})(); })();
client.main = buff_main; client.main = buff_main;
client.side = buff_side; client.side = buff_side;
if (room.started) { if (room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) {
client.selected_preduel = true; client.selected_preduel = true;
if (client.side_tcount) { if (client.side_tcount) {
clearInterval(client.side_interval); clearInterval(client.side_interval);
...@@ -3826,7 +3829,7 @@ ...@@ -3826,7 +3829,7 @@
client.start_deckbuf = Buffer.from(buffer); client.start_deckbuf = Buffer.from(buffer);
} }
oppo_pos = room.hostinfo.mode === 2 ? 2 : 1; oppo_pos = room.hostinfo.mode === 2 ? 2 : 1;
if (settings.modules.http.quick_death_rule >= 2 && room.started && room.death && room.scores[room.dueling_players[0].name_vpass] !== room.scores[room.dueling_players[oppo_pos].name_vpass]) { if (settings.modules.http.quick_death_rule >= 2 && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && room.death && room.scores[room.dueling_players[0].name_vpass] !== room.scores[room.dueling_players[oppo_pos].name_vpass]) {
win_pos = room.scores[room.dueling_players[0].name_vpass] > room.scores[room.dueling_players[oppo_pos].name_vpass] ? 0 : oppo_pos; 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; 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); ygopro.stoc_send_chat_to_room(room, "${death2_finish_part1}" + room.dueling_players[win_pos].name + "${death2_finish_part2}", ygopro.constants.COLORS.BABYBLUE);
...@@ -3844,7 +3847,7 @@ ...@@ -3844,7 +3847,7 @@
} }
return true; return true;
} }
if (settings.modules.side_restrict.enabled && room.started) { if (settings.modules.side_restrict.enabled && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) {
ref2 = settings.modules.side_restrict.restrict_cards; ref2 = settings.modules.side_restrict.restrict_cards;
for (m = 0, len2 = ref2.length; m < len2; m++) { for (m = 0, len2 = ref2.length; m < len2; m++) {
code = ref2[m]; code = ref2[m];
...@@ -3863,7 +3866,7 @@ ...@@ -3863,7 +3866,7 @@
room.waiting_for_player = room.waiting_for_player2; room.waiting_for_player = room.waiting_for_player2;
} }
room.last_active_time = moment(); room.last_active_time = moment();
} else if (!room.started && room.hostinfo.mode === 1 && settings.modules.tournament_mode.enabled && settings.modules.tournament_mode.deck_check && fs.readdirSync(settings.modules.tournament_mode.deck_path).length) { } else if (room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN && room.hostinfo.mode === 1 && settings.modules.tournament_mode.enabled && settings.modules.tournament_mode.deck_check && fs.readdirSync(settings.modules.tournament_mode.deck_path).length) {
struct = ygopro.structs["deck"]; struct = ygopro.structs["deck"];
struct._setBuff(buffer); struct._setBuff(buffer);
struct.set("mainc", 1); struct.set("mainc", 1);
...@@ -3939,7 +3942,7 @@ ...@@ -3939,7 +3942,7 @@
client.time_confirm_required = true; client.time_confirm_required = true;
} }
} }
if (!(settings.modules.heartbeat_detection.enabled && room.turn && room.turn > 0 && !room.windbot)) { if (!(settings.modules.heartbeat_detection.enabled && room.duel_stage === ygopro.constants.DUEL_STAGE.DUELING && !room.windbot)) {
return; return;
} }
check = false; check = false;
...@@ -4034,10 +4037,10 @@ ...@@ -4034,10 +4037,10 @@
var len2, m, pid, player, ref2, room, tcolor, tplayer; var len2, m, pid, player, ref2, room, tcolor, tplayer;
room = ROOM_all[client.rid]; room = ROOM_all[client.rid];
pid = info.player; pid = info.player;
if (!(room && pid < 4 && settings.modules.chat_color.enabled && (!settings.modules.hide_name || room.started))) { if (!(room && pid < 4 && settings.modules.chat_color.enabled && (!settings.modules.hide_name || room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN))) {
return; return;
} }
if (room.started && room.turn > 0 && !room.dueling_players[0].is_first) { if (room.duel_stage === ygopro.constants.DUEL_STAGE.DUELING && !room.dueling_players[0].is_first) {
if (room.hostinfo.mode === 2) { if (room.hostinfo.mode === 2) {
pid = { pid = {
0: 2, 0: 2,
...@@ -4077,8 +4080,7 @@ ...@@ -4077,8 +4080,7 @@
} }
client.selected_preduel = false; client.selected_preduel = false;
if (client.pos === 0) { if (client.pos === 0) {
room.selecting_hand = true; room.duel_stage = ygopro.constants.DUEL_STAGE.FINGER;
room.changing_side = false;
} }
if (!(room.random_type || room.arena)) { if (!(room.random_type || room.arena)) {
return; return;
...@@ -4098,8 +4100,7 @@ ...@@ -4098,8 +4100,7 @@
return; return;
} }
client.selected_preduel = false; client.selected_preduel = false;
room.changing_side = false; room.duel_stage = ygopro.constants.DUEL_STAGE.FIRSTGO;
room.selecting_hand = false;
room.selecting_tp = client; room.selecting_tp = client;
if (room.random_type || room.arena) { if (room.random_type || room.arena) {
room.waiting_for_player = client; room.waiting_for_player = client;
...@@ -4113,13 +4114,15 @@ ...@@ -4113,13 +4114,15 @@
if (!room) { if (!room) {
return; return;
} }
room.changing_side = true; if (client.pos === 0) {
room.duel_stage = ygopro.constants.DUEL_STAGE.SIDING;
}
client.selected_preduel = false; client.selected_preduel = false;
if (settings.modules.side_timeout) { if (settings.modules.side_timeout) {
client.side_tcount = settings.modules.side_timeout; client.side_tcount = settings.modules.side_timeout;
ygopro.stoc_send_chat(client, "${side_timeout_part1}" + settings.modules.side_timeout + "${side_timeout_part2}", ygopro.constants.COLORS.BABYBLUE); ygopro.stoc_send_chat(client, "${side_timeout_part1}" + settings.modules.side_timeout + "${side_timeout_part2}", ygopro.constants.COLORS.BABYBLUE);
sinterval = setInterval(function() { sinterval = setInterval(function() {
if (!(room && room.started && client && client.side_tcount && room.changing_side)) { if (!(room && client && client.side_tcount && room.duel_stage === ygopro.constants.DUEL_STAGE.SIDING)) {
clearInterval(sinterval); clearInterval(sinterval);
return; return;
} }
...@@ -4236,7 +4239,7 @@ ...@@ -4236,7 +4239,7 @@
var len2, m, room, time_passed; var len2, m, room, time_passed;
for (m = 0, len2 = ROOM_all.length; m < len2; m++) { for (m = 0, len2 = ROOM_all.length; m < len2; m++) {
room = ROOM_all[m]; room = ROOM_all[m];
if (!(room && room.started && room.random_type && room.last_active_time && room.waiting_for_player && room.get_disconnected_count() === 0)) { if (!(room && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && room.random_type && room.last_active_time && room.waiting_for_player && room.get_disconnected_count() === 0)) {
continue; continue;
} }
time_passed = Math.floor((moment() - room.last_active_time) / 1000); time_passed = Math.floor((moment() - room.last_active_time) / 1000);
...@@ -4260,7 +4263,7 @@ ...@@ -4260,7 +4263,7 @@
var len2, len3, m, n, player, room, time_passed, waited_time; var len2, len3, m, n, player, room, time_passed, waited_time;
for (m = 0, len2 = ROOM_all.length; m < len2; m++) { for (m = 0, len2 = ROOM_all.length; m < len2; m++) {
room = ROOM_all[m]; room = ROOM_all[m];
if (!(room && room.started && room.arena && room.last_active_time && room.waiting_for_player && room.get_disconnected_count() === 0)) { if (!(room && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && room.arena && room.last_active_time && room.waiting_for_player && room.get_disconnected_count() === 0)) {
continue; continue;
} }
time_passed = Math.floor((moment() - room.last_active_time) / 1000); time_passed = Math.floor((moment() - room.last_active_time) / 1000);
...@@ -4277,7 +4280,7 @@ ...@@ -4277,7 +4280,7 @@
if (settings.modules.arena_mode.punish_quit_before_match) { if (settings.modules.arena_mode.punish_quit_before_match) {
for (n = 0, len3 = ROOM_all.length; n < len3; n++) { for (n = 0, len3 = ROOM_all.length; n < len3; n++) {
room = ROOM_all[n]; room = ROOM_all[n];
if (!(room && room.arena && !room.started && room.get_playing_player().length < 2)) { if (!(room && room.arena && room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN && room.get_playing_player().length < 2)) {
continue; continue;
} }
player = room.get_playing_player()[0]; player = room.get_playing_player()[0];
...@@ -4300,11 +4303,11 @@ ...@@ -4300,11 +4303,11 @@
var len2, len3, m, n, player, ref2, room; var len2, len3, m, n, player, ref2, room;
for (m = 0, len2 = ROOM_all.length; m < len2; m++) { for (m = 0, len2 = ROOM_all.length; m < len2; m++) {
room = ROOM_all[m]; room = ROOM_all[m];
if (room && room.started && (room.hostinfo.time_limit === 0 || !room.turn || room.turn <= 0) && !room.windbot) { if (room && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && (room.hostinfo.time_limit === 0 || room.duel_stage !== ygopro.constants.DUEL_STAGE.DUELING) && !room.windbot) {
ref2 = room.get_playing_player(); ref2 = room.get_playing_player();
for (n = 0, len3 = ref2.length; n < len3; n++) { for (n = 0, len3 = ref2.length; n < len3; n++) {
player = ref2[n]; player = ref2[n];
if (player && (!room.changing_side || player.selected_preduel)) { if (player && (room.duel_stage !== ygopro.constants.DUEL_STAGE.SIDING || player.selected_preduel)) {
CLIENT_heartbeat_register(player, true); CLIENT_heartbeat_register(player, true);
} }
} }
...@@ -4319,7 +4322,7 @@ ...@@ -4319,7 +4322,7 @@
results = []; results = [];
for (m = 0, len2 = ROOM_all.length; m < len2; m++) { for (m = 0, len2 = ROOM_all.length; m < len2; m++) {
room = ROOM_all[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)) { if (!(room && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && room.hostinfo.auto_death && !room.auto_death_triggered && current_time - moment(room.start_time) > 60000 * room.hostinfo.auto_death)) {
continue; continue;
} }
room.auto_death_triggered = true; room.auto_death_triggered = true;
...@@ -4417,7 +4420,7 @@ ...@@ -4417,7 +4420,7 @@
id: (-1).toString(), id: (-1).toString(),
name: player.name, name: player.name,
ip: settings.modules.http.show_ip && pass_validated && !player.is_local ? player.ip.slice(7) : null, ip: settings.modules.http.show_ip && pass_validated && !player.is_local ? player.ip.slice(7) : null,
status: settings.modules.http.show_info && room.started && player.pos !== 7 ? { status: settings.modules.http.show_info && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && player.pos !== 7 ? {
score: room.scores[player.name_vpass], score: room.scores[player.name_vpass],
lp: player.lp != null ? player.lp : room.hostinfo.start_lp, lp: player.lp != null ? player.lp : room.hostinfo.start_lp,
cards: room.hostinfo.mode !== 2 ? (player.card_count != null ? player.card_count : room.hostinfo.start_hand) : null cards: room.hostinfo.mode !== 2 ? (player.card_count != null ? player.card_count : room.hostinfo.start_hand) : null
...@@ -4428,7 +4431,7 @@ ...@@ -4428,7 +4431,7 @@
} }
return results1; return results1;
})(), "pos"), })(), "pos"),
istart: room.started ? (settings.modules.http.show_info ? "Duel:" + room.duel_count + " " + (room.changing_side ? "Siding" : "Turn:" + (room.turn != null ? room.turn : 0) + (room.death ? "/" + (room.death > 0 ? room.death - 1 : "Death") : "")) : 'start') : 'wait' istart: room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN ? (settings.modules.http.show_info ? "Duel:" + room.duel_count + " " + (room.duel_stage === ygopro.constants.DUEL_STAGE.SIDING ? "Siding" : "Turn:" + (room.turn != null ? room.turn : 0) + (room.death ? "/" + (room.death > 0 ? room.death - 1 : "Death") : "")) : 'start') : 'wait'
}); });
} }
} }
...@@ -4634,7 +4637,7 @@ ...@@ -4634,7 +4637,7 @@
continue; continue;
} }
kick_room_found = true; kick_room_found = true;
if (room.started) { if (room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) {
room.scores[room.dueling_players[0].name_vpass] = 0; room.scores[room.dueling_players[0].name_vpass] = 0;
room.scores[room.dueling_players[1].name_vpass] = 0; room.scores[room.dueling_players[1].name_vpass] = 0;
} }
...@@ -4679,7 +4682,7 @@ ...@@ -4679,7 +4682,7 @@
death_room_found = false; death_room_found = false;
for (q = 0, len6 = ROOM_all.length; q < len6; q++) { for (q = 0, len6 = ROOM_all.length; q < len6; q++) {
room = ROOM_all[q]; room = ROOM_all[q];
if (room && (u.query.death === "all" || u.query.death === room.process_pid.toString() || u.query.death === room.name)) { if (room && (u.query.deathcancel === "all" || u.query.deathcancel === room.process_pid.toString() || u.query.deathcancel === room.name)) {
if (room.cancel_death()) { if (room.cancel_death()) {
death_room_found = true; death_room_found = true;
} }
...@@ -4702,7 +4705,7 @@ ...@@ -4702,7 +4705,7 @@
if (!(room)) { if (!(room)) {
continue; continue;
} }
if (room.started) { if (room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) {
room.scores[room.dueling_players[0].name_vpass] = 0; room.scores[room.dueling_players[0].name_vpass] = 0;
room.scores[room.dueling_players[1].name_vpass] = 0; room.scores[room.dueling_players[1].name_vpass] = 0;
} }
......
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