Commit 44af210f authored by nanahira's avatar nanahira

Merge branch 'mc'

parents 8302930d a88f32ab
......@@ -269,6 +269,14 @@
"LINK_MARKER_TOP": 128,
"LINK_MARKER_TOP_RIGHT": 256
},
"DUEL_STAGE": {
"BEGIN": 0,
"FINGER": 1,
"FIRSTGO": 2,
"DUELING": 3,
"SIDING": 4,
"END": 5
},
"COLORS": {
"LIGHTBLUE": 8,
"RED": 11,
......@@ -282,6 +290,3 @@
"DARKGRAY": 19
}
}
......@@ -672,7 +672,7 @@ ROOM_find_or_create_random = (type, player_ip)->
max_player = if type == 'T' then 4 else 2
playerbanned = (bannedplayer and bannedplayer.count > 3 and moment() < bannedplayer.time)
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
room.get_playing_player().length < max_player and
(settings.modules.random_duel.no_rematch_check or room.get_host() == null or
......@@ -801,7 +801,7 @@ CLIENT_reconnect_register = (client, room_id, error) ->
room = ROOM_all[room_id]
if client.had_new_reconnection
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
# for player in room.players
# if player != client and CLIENT_get_authorize_key(player) == CLIENT_get_authorize_key(client)
......@@ -824,7 +824,7 @@ CLIENT_reconnect_register = (client, room_id, error) ->
if client.time_confirm_required
client.time_confirm_required = false
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')
return true
......@@ -888,7 +888,7 @@ CLIENT_is_able_to_reconnect = (client, deckbuf) ->
return true
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))
return player
return null
......@@ -919,25 +919,28 @@ CLIENT_send_pre_reconnect_info = (client, room, old_client) ->
CLIENT_send_reconnect_info = (client, server, room) ->
client.reconnecting = true
ygopro.stoc_send_chat(client, "${reconnecting_to_room}", ygopro.constants.COLORS.BABYBLUE)
if room.turn and room.turn > 0
ygopro.ctos_send(server, 'REQUEST_FIELD')
else if room.changing_side
ygopro.stoc_send(client, 'DUEL_START')
if !client.selected_preduel
ygopro.stoc_send(client, 'CHANGE_SIDE')
client.reconnecting = false
else if room.selecting_hand
ygopro.stoc_send(client, 'DUEL_START')
if (room.hostinfo.mode != 2 or client.pos == 0 or client.pos == 2) and !client.selected_preduel
ygopro.stoc_send(client, 'SELECT_HAND')
client.reconnecting = false
else if room.selecting_tp
ygopro.stoc_send(client, 'DUEL_START')
if client == room.selecting_tp # and !client.selected_preduel
ygopro.stoc_send(client, 'SELECT_TP')
client.reconnecting = false
else
ygopro.ctos_send(server, 'REQUEST_FIELD')
switch room.duel_stage
when ygopro.constants.DUEL_STAGE.FINGER
ygopro.stoc_send(client, 'DUEL_START')
if (room.hostinfo.mode != 2 or client.pos == 0 or client.pos == 2) and !client.selected_preduel
ygopro.stoc_send(client, 'SELECT_HAND')
client.reconnecting = false
break
when ygopro.constants.DUEL_STAGE.FIRSTGO
ygopro.stoc_send(client, 'DUEL_START')
if client == room.selecting_tp # and !client.selected_preduel
ygopro.stoc_send(client, 'SELECT_TP')
client.reconnecting = false
break
when ygopro.constants.DUEL_STAGE.SIDING
ygopro.stoc_send(client, 'DUEL_START')
if !client.selected_preduel
ygopro.stoc_send(client, 'CHANGE_SIDE')
client.reconnecting = false
break
else
ygopro.ctos_send(server, 'REQUEST_FIELD')
break
return
CLIENT_pre_reconnect = (client) ->
......@@ -1103,11 +1106,11 @@ replace_buffer = (buffer, list, start_pos) ->
class Room
constructor: (name, @hostinfo) ->
@name = name
@alive = true
#@alive = true
@players = []
@player_datas = []
@status = 'starting'
@started = false
#@started = false
@established = false
@watcher_buffers = []
@recorder_buffers = []
......@@ -1120,6 +1123,7 @@ class Room
@duel_count = 0
@death = 0
@turn = 0
@duel_stage = ygopro.constants.DUEL_STAGE.BEGIN
if settings.modules.replay_delay
@replays = []
ROOM_all.push this
......@@ -1373,7 +1377,7 @@ class Room
# log.info 'SCORE POST OK', response.statusCode, response.statusMessage, @name, body
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
challonge.matches._update({
id: settings.modules.challonge.tournament_id,
......@@ -1457,7 +1461,7 @@ class Room
return found
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
challonge_duel_log = {}
if @scores[@dueling_players[0].name_vpass] > @scores[@dueling_players[1].name_vpass]
......@@ -1519,7 +1523,7 @@ class Room
ROOM_players_oppentlist[client.ip] = null
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.write buffer for buffer in client.pre_establish_buffers
client.established = true
......@@ -1537,8 +1541,8 @@ class Room
#client.room = null
client.server.destroy()
else
#log.info(client.name, @started, @disconnector, @random_type, @players.length)
if @arena and !@started and @disconnector != 'server' and !@arena_score_handled
#log.info(client.name, @duel_stage != ygopro.constants.DUEL_STAGE.BEGIN, @disconnector, @random_type, @players.length)
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
for player in @players when player.pos != 7
@scores[player.name_vpass] = 0
......@@ -1549,7 +1553,7 @@ class Room
@arena_score_handled = true
index = _.indexOf(@players, client)
@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
if !@finished_by_death
@scores[client.name_vpass] = -9
......@@ -1557,10 +1561,10 @@ class Room
ROOM_ban_player(client.name, client.ip, "${random_ban_reason_flee}")
if settings.modules.random_duel.record_match_scores and @random_type == 'M'
ROOM_player_flee(client.name_vpass)
if @players.length and !(@windbot and client.is_host) and !(@arena and !@started and client.pos <= 3)
left_name = (if settings.modules.hide_name and !@started then "********" else client.name)
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 @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 ''
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
else
@send_replays()
......@@ -1572,10 +1576,10 @@ class Room
return
start_death: () ->
unless @established and @started and !@death
if @duel_stage == ygopro.constants.DUEL_STAGE.BEGIN or @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
if @duel_stage == ygopro.constants.DUEL_STAGE.DUELING
switch settings.modules.http.quick_death_rule
when 3
@death = -2
......@@ -1612,7 +1616,7 @@ class Room
return true
cancel_death: () ->
unless @established and @started and @death
if @duel_stage == ygopro.constants.DUEL_STAGE.BEGIN or !@death
return false
@death = 0
ygopro.stoc_send_chat_to_room(this, "${death_cancel}", ygopro.constants.COLORS.BABYBLUE)
......@@ -1988,7 +1992,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
room_buffer.write(room.name, buffer_pos, 64, "utf8")
buffer_pos += 64
oppo_pos = if room.hostinfo.mode == 2 then 2 else 1
room_buffer.writeUInt8((if !room.started then 0 else if room.changing_side then 2 else 1), buffer_pos)
room_buffer.writeUInt8((if room.duel_stage == ygopro.constants.DUEL_STAGE.BEGIN then 0 else if room.duel_stage == ygopro.constants.DUEL_STAGE.SIDING then 2 else 1), buffer_pos)
buffer_pos++
room_buffer.writeInt8(room.duel_count, buffer_pos)
buffer_pos++
......@@ -2004,7 +2008,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
player_string = player_string + "+" + (if room_players[1] then room_players[1].name else "???")
room_buffer.write(player_string, buffer_pos, 128, "utf8")
buffer_pos += 128
if room.started
if room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN
room_buffer.writeInt8((if room_players[0] and room.scores[room_players[0].name_vpass]? then room.scores[room_players[0].name_vpass] else 0), buffer_pos)
buffer_pos++
room_buffer.writeInt32LE((if room_players[0] and room_players[0].lp? then room_players[0].lp else room.hostinfo.start_lp), buffer_pos)
......@@ -2021,7 +2025,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
player_string = player_string + "+" + (if room_players[oppo_pos + 1] then room_players[oppo_pos + 1].name else "???")
room_buffer.write(player_string, buffer_pos, 128, "utf8")
buffer_pos += 128
if room.started
if room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN
room_buffer.writeInt8((if room_players[oppo_pos] and room.scores[room_players[oppo_pos].name_vpass]? then room.scores[room_players[oppo_pos].name_vpass] else 0), buffer_pos)
buffer_pos++
room_buffer.writeInt32LE((if room_players[oppo_pos] and room_players[oppo_pos].lp? then room_players[oppo_pos].lp else room.hostinfo.start_lp), buffer_pos)
......@@ -2174,7 +2178,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
ygopro.stoc_die(client, "${server_full}")
else if 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
client.setTimeout(300000) #连接后超时5分钟
client.rid = _.indexOf(ROOM_all, room)
......@@ -2262,7 +2266,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
else if settings.modules.challonge.enabled
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
client.setTimeout(300000) #连接后超时5分钟
client.rid = _.indexOf(ROOM_all, room)
......@@ -2324,7 +2328,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
ygopro.stoc_die(client, "${server_full}")
else if 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
#client.setTimeout(300000) #连接后超时5分钟
client.rid = _.indexOf(ROOM_all, room)
......@@ -2413,7 +2417,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
ygopro.stoc_die(client, "${server_full}")
else if 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
client.setTimeout(300000) #连接后超时5分钟
client.rid = _.indexOf(ROOM_all, room)
......@@ -2623,7 +2627,7 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
client.is_first = !(playertype & 0xf)
client.lp = room.hostinfo.start_lp
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
room.turn = 0
room.duel_count++
......@@ -2646,7 +2650,7 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
if ygopro.constants.MSG[msg] == 'NEW_TURN'
r_player = buffer.readUInt8(1)
if client.pos == 0 and (r_player & 0x2) == 0
room.turn = room.turn + 1
room.turn++
if room.death and room.death != -2
if room.turn >= room.death
oppo_pos = if room.hostinfo.mode == 2 then 2 else 1
......@@ -2677,13 +2681,14 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
if ygopro.constants.MSG[msg] == 'WIN' and client.pos == 0
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
reason = buffer.readUInt8(2)
#log.info {winner: pos, reason: reason}
#room.duels.push {winner: pos, reason: reason}
room.winner = pos
room.turn = 0
room.duel_stage = ygopro.constants.DUEL_STAGE.END
if settings.modules.heartbeat_detection.enabled
for player in room.players
player.heartbeat_protected = false
......@@ -2898,7 +2903,7 @@ ygopro.stoc_follow 'TYPE_CHANGE', true, (buffer, info, client, server, datas)->
ygopro.stoc_follow 'HS_PLAYER_ENTER', true, (buffer, info, client, server, datas)->
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
if pos < 4 and pos != client.pos
struct = ygopro.structs["STOC_HS_PlayerEnter"]
......@@ -2981,7 +2986,7 @@ ygopro.stoc_follow 'DUEL_END', false, (buffer, info, client, server, datas)->
CLIENT_send_replays(player, room)
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
if time
unless time % 5
......@@ -2996,7 +3001,7 @@ wait_room_start = (room, time)->
return
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
if room.waiting_for_player_time > 0
unless room.waiting_for_player_time % 5
......@@ -3064,15 +3069,15 @@ if settings.modules.tips.get_zh
if settings.modules.tips.enabled
setInterval ()->
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
, 30000
ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server, datas)->
room=ROOM_all[client.rid]
return unless room and !client.reconnecting
unless room.started #first start
room.started = true
if room.duel_stage == ygopro.constants.DUEL_STAGE.BEGIN #first start
room.duel_stage = ygopro.constants.DUEL_STAGE.FINGER
room.start_time = moment().format()
room.turn = 0
roomlist.start room if !room.windbot and settings.modules.http.websocket_roomlist
......@@ -3138,7 +3143,7 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server, datas)->
ygopro.ctos_follow 'SURRENDER', true, (buffer, info, client, server, datas)->
room=ROOM_all[client.rid]
return unless room
if !room.started
if room.duel_stage == ygopro.constants.DUEL_STAGE.BEGIN
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)
ygopro.stoc_send_chat(client, "${surrender_denied}", ygopro.constants.COLORS.BABYBLUE)
......@@ -3184,7 +3189,7 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server, datas)->
cmd = msg.split(' ')
switch cmd[0]
when '/投降', '/surrender'
if !room.started or (room.hostinfo.mode==2 and !settings.modules.tag_duel_surrender)
if room.duel_stage == ygopro.constants.DUEL_STAGE.BEGIN or (room.hostinfo.mode==2 and !settings.modules.tag_duel_surrender)
return cancel
if room.random_type and room.turn < 3 and !client.flee_free
ygopro.stoc_send_chat(client, "${surrender_denied}", ygopro.constants.COLORS.BABYBLUE)
......@@ -3383,7 +3388,7 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server, datas)->
else
client.abuse_count=client.abuse_count+4
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
#ygopro.stoc_send_chat(client, "${chat_warn_level0}", ygopro.constants.COLORS.RED)
cancel = true
......@@ -3462,7 +3467,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])
client.main = buff_main
client.side = buff_side
if room.started
if room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN
client.selected_preduel = true
if client.side_tcount
clearInterval client.side_interval
......@@ -3471,7 +3476,7 @@ ygopro.ctos_follow 'UPDATE_DECK', true, (buffer, info, client, server, datas)->
else
client.start_deckbuf = Buffer.from(buffer)
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
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)
......@@ -3482,7 +3487,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 + 1]) if room.hostinfo.mode == 2
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
if _.indexOf(buff_side, code) > -1 or (settings.modules.pre_release_compat.enabled and _.indexOf(buff_side, room.list_pre_to_official[code]) > -1)
ygopro.stoc_send_chat_to_room(room, "${invalid_side_rule}", ygopro.constants.COLORS.RED)
......@@ -3497,7 +3502,7 @@ ygopro.ctos_follow 'UPDATE_DECK', true, (buffer, info, client, server, datas)->
if client.pos == 0
room.waiting_for_player = room.waiting_for_player2
room.last_active_time = moment()
else if !room.started 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 settings.modules.tournament_mode.enabled and settings.modules.tournament_mode.deck_check and fs.readdirSync(settings.modules.tournament_mode.deck_path).length
struct.set("mainc", 1)
struct.set("sidec", 1)
struct.set("deckbuf", [4392470, 4392470])
......@@ -3561,7 +3566,7 @@ ygopro.ctos_follow 'UPDATE_DECK', true, (buffer, info, client, server, datas)->
buffer = struct.buffer
client.main = buff_main_new
client.side = buff_side_new
if !room.started
if room.duel_stage == ygopro.constants.DUEL_STAGE.BEGIN
client.is_using_pre_release = found or client.vpass == "COMPAT"
if client.is_using_pre_release
ygopro.stoc_send_chat(client, "${pre_release_compat_hint}", ygopro.constants.COLORS.BABYBLUE)
......@@ -3586,7 +3591,7 @@ ygopro.stoc_follow 'TIME_LIMIT', true, (buffer, info, client, server, datas)->
return true
else
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
if room.hostinfo.mode != 2
check = (client.is_first and info.player == 0) or (!client.is_first and info.player == 1)
......@@ -3652,8 +3657,8 @@ ygopro.ctos_follow 'TP_RESULT', false, (buffer, info, client, server, datas)->
ygopro.stoc_follow 'CHAT', true, (buffer, info, client, server, datas)->
room=ROOM_all[client.rid]
pid = info.player
return unless room and pid < 4 and settings.modules.chat_color.enabled and (!settings.modules.hide_name or room.started)
if room.started and room.turn > 0 and !room.dueling_players[0].is_first
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.duel_stage == ygopro.constants.DUEL_STAGE.DUELING and !room.dueling_players[0].is_first
if room.hostinfo.mode == 2
pid = {
0: 2,
......@@ -3680,8 +3685,7 @@ ygopro.stoc_follow 'SELECT_HAND', false, (buffer, info, client, server, datas)->
return unless room
client.selected_preduel = false
if client.pos == 0
room.selecting_hand = true
room.changing_side = false
room.duel_stage = ygopro.constants.DUEL_STAGE.FINGER
return unless room.random_type or room.arena
if client.pos == 0
room.waiting_for_player = client
......@@ -3694,8 +3698,7 @@ ygopro.stoc_follow 'SELECT_TP', false, (buffer, info, client, server, datas)->
room=ROOM_all[client.rid]
return unless room
client.selected_preduel = false
room.changing_side = false
room.selecting_hand = false
room.duel_stage = ygopro.constants.DUEL_STAGE.FIRSTGO
room.selecting_tp = client
if room.random_type or room.arena
room.waiting_for_player = client
......@@ -3705,13 +3708,14 @@ ygopro.stoc_follow 'SELECT_TP', false, (buffer, info, client, server, datas)->
ygopro.stoc_follow 'CHANGE_SIDE', false, (buffer, info, client, server, datas)->
room=ROOM_all[client.rid]
return unless room
room.changing_side = true
if client.pos == 0
room.duel_stage = ygopro.constants.DUEL_STAGE.SIDING
client.selected_preduel = false
if 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)
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
return
if client.side_tcount == 1
......@@ -3793,7 +3797,7 @@ ygopro.stoc_follow 'REPLAY', true, (buffer, info, client, server, datas)->
if settings.modules.random_duel.enabled
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)
#log.info time_passed
if time_passed >= settings.modules.random_duel.hang_timeout
......@@ -3812,7 +3816,7 @@ if settings.modules.random_duel.enabled
if settings.modules.mycard.enabled
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)
#log.info time_passed
if time_passed >= settings.modules.random_duel.hang_timeout
......@@ -3825,7 +3829,7 @@ if settings.modules.mycard.enabled
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)
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]
if player and player.join_time and !player.arena_quit_free
waited_time = moment() - player.join_time
......@@ -3839,15 +3843,15 @@ if settings.modules.mycard.enabled
if settings.modules.heartbeat_detection.enabled
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 player in room.get_playing_player() when player and (!room.changing_side or player.selected_preduel)
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.duel_stage != ygopro.constants.DUEL_STAGE.SIDING or player.selected_preduel)
CLIENT_heartbeat_register(player, true)
return
, 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
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.start_death()
......@@ -3922,14 +3926,14 @@ if settings.modules.http
id: (-1).toString(),
name: player.name,
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],
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
) else null,
pos: player.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
response.end(addCallback(u.query.callback, roomsjson))
......@@ -4124,7 +4128,7 @@ if settings.modules.http
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)
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[1].name_vpass] = 0
room.kicked = true
......@@ -4158,7 +4162,7 @@ if settings.modules.http
response.end(addCallback(u.query.callback, "['密码错误', 0]"))
return
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()
death_room_found = true
response.writeHead(200)
......@@ -4173,7 +4177,7 @@ if settings.modules.http
response.end(addCallback(u.query.callback, "['密码错误', 0]"))
return
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[1].name_vpass] = 0
room.kicked = true
......
......@@ -865,7 +865,7 @@
max_player = type === 'T' ? 4 : 2;
playerbanned = bannedplayer && bannedplayer.count > 3 && moment() < bannedplayer.time;
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) {
result.welcome = '${random_duel_enter_room_waiting}';
......@@ -1040,7 +1040,7 @@
if (client.had_new_reconnection) {
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;
}
dinfo = {
......@@ -1060,7 +1060,7 @@
client.time_confirm_required = false;
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');
}
return true;
......@@ -1164,7 +1164,7 @@
var len3, len4, m, n, player, ref3, room;
for (m = 0, len3 = ROOM_all.length; m < len3; m++) {
room = ROOM_all[m];
if (room && room.started && !room.windbot) {
if (room && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && !room.windbot) {
ref3 = room.get_playing_player();
for (n = 0, len4 = ref3.length; n < len4; n++) {
player = ref3[n];
......@@ -1211,28 +1211,31 @@
CLIENT_send_reconnect_info = function(client, server, room) {
client.reconnecting = true;
ygopro.stoc_send_chat(client, "${reconnecting_to_room}", ygopro.constants.COLORS.BABYBLUE);
if (room.turn && room.turn > 0) {
ygopro.ctos_send(server, 'REQUEST_FIELD');
} else if (room.changing_side) {
ygopro.stoc_send(client, 'DUEL_START');
if (!client.selected_preduel) {
ygopro.stoc_send(client, 'CHANGE_SIDE');
}
client.reconnecting = false;
} else if (room.selecting_hand) {
ygopro.stoc_send(client, 'DUEL_START');
if ((room.hostinfo.mode !== 2 || client.pos === 0 || client.pos === 2) && !client.selected_preduel) {
ygopro.stoc_send(client, 'SELECT_HAND');
}
client.reconnecting = false;
} else if (room.selecting_tp) {
ygopro.stoc_send(client, 'DUEL_START');
if (client === room.selecting_tp) {
ygopro.stoc_send(client, 'SELECT_TP');
}
client.reconnecting = false;
} else {
ygopro.ctos_send(server, 'REQUEST_FIELD');
switch (room.duel_stage) {
case ygopro.constants.DUEL_STAGE.FINGER:
ygopro.stoc_send(client, 'DUEL_START');
if ((room.hostinfo.mode !== 2 || client.pos === 0 || client.pos === 2) && !client.selected_preduel) {
ygopro.stoc_send(client, 'SELECT_HAND');
}
client.reconnecting = false;
break;
case ygopro.constants.DUEL_STAGE.FIRSTGO:
ygopro.stoc_send(client, 'DUEL_START');
if (client === room.selecting_tp) {
ygopro.stoc_send(client, 'SELECT_TP');
}
client.reconnecting = false;
break;
case ygopro.constants.DUEL_STAGE.SIDING:
ygopro.stoc_send(client, 'DUEL_START');
if (!client.selected_preduel) {
ygopro.stoc_send(client, 'CHANGE_SIDE');
}
client.reconnecting = false;
break;
default:
ygopro.ctos_send(server, 'REQUEST_FIELD');
break;
}
};
......@@ -1440,11 +1443,9 @@
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.name = name;
this.alive = true;
this.players = [];
this.player_datas = [];
this.status = 'starting';
this.started = false;
this.established = false;
this.watcher_buffers = [];
this.recorder_buffers = [];
......@@ -1457,6 +1458,7 @@
this.duel_count = 0;
this.death = 0;
this.turn = 0;
this.duel_stage = ygopro.constants.DUEL_STAGE.BEGIN;
if (settings.modules.replay_delay) {
this.replays = [];
}
......@@ -1786,7 +1788,7 @@
};
})(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;
challonge.matches._update({
id: settings.modules.challonge.tournament_id,
......@@ -1895,7 +1897,7 @@
Room.prototype.get_challonge_score = function() {
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;
}
challonge_duel_log = {};
......@@ -1974,7 +1976,7 @@
}
}
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);
}
client.server.connect(this.port, '127.0.0.1', function() {
......@@ -2003,7 +2005,7 @@
}
client.server.destroy();
} 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) {
ref3 = this.players;
for (m = 0, len3 = ref3.length; m < len3; m++) {
......@@ -2028,7 +2030,7 @@
if (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;
if (!this.finished_by_death) {
this.scores[client.name_vpass] = -9;
......@@ -2040,10 +2042,10 @@
}
}
}
if (this.players.length && !(this.windbot && client.is_host) && !(this.arena && !this.started && client.pos <= 3)) {
left_name = (settings.modules.hide_name && !this.started ? "********" : client.name);
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.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN ? "********" : client.name);
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);
}
} else {
......@@ -2059,11 +2061,11 @@
Room.prototype.start_death = function() {
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;
}
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) {
case 3:
this.death = -2;
......@@ -2116,7 +2118,7 @@
};
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;
}
this.death = 0;
......@@ -2532,7 +2534,7 @@
room_buffer.write(room.name, buffer_pos, 64, "utf8");
buffer_pos += 64;
oppo_pos = room.hostinfo.mode === 2 ? 2 : 1;
room_buffer.writeUInt8((!room.started ? 0 : room.changing_side ? 2 : 1), buffer_pos);
room_buffer.writeUInt8((room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN ? 0 : room.duel_stage === ygopro.constants.DUEL_STAGE.SIDING ? 2 : 1), buffer_pos);
buffer_pos++;
room_buffer.writeInt8(room.duel_count, buffer_pos);
buffer_pos++;
......@@ -2555,7 +2557,7 @@
}
room_buffer.write(player_string, buffer_pos, 128, "utf8");
buffer_pos += 128;
if (room.started) {
if (room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) {
room_buffer.writeInt8((room_players[0] && (room.scores[room_players[0].name_vpass] != null) ? room.scores[room_players[0].name_vpass] : 0), buffer_pos);
buffer_pos++;
room_buffer.writeInt32LE((room_players[0] && (room_players[0].lp != null) ? room_players[0].lp : room.hostinfo.start_lp), buffer_pos);
......@@ -2575,7 +2577,7 @@
}
room_buffer.write(player_string, buffer_pos, 128, "utf8");
buffer_pos += 128;
if (room.started) {
if (room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) {
room_buffer.writeInt8((room_players[oppo_pos] && (room.scores[room_players[oppo_pos].name_vpass] != null) ? room.scores[room_players[oppo_pos].name_vpass] : 0), buffer_pos);
buffer_pos++;
room_buffer.writeInt32LE((room_players[oppo_pos] && (room_players[oppo_pos].lp != null) ? room_players[oppo_pos].lp : room.hostinfo.start_lp), buffer_pos);
......@@ -2736,7 +2738,7 @@
ygopro.stoc_die(client, "${server_full}");
} else if (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) {
client.setTimeout(300000);
client.rid = _.indexOf(ROOM_all, room);
......@@ -2846,7 +2848,7 @@
}
} else if (settings.modules.challonge.enabled) {
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;
client.setTimeout(300000);
client.rid = _.indexOf(ROOM_all, room);
......@@ -2924,7 +2926,7 @@
ygopro.stoc_die(client, "${server_full}");
} else if (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) {
client.rid = _.indexOf(ROOM_all, room);
client.is_post_watcher = true;
......@@ -3014,7 +3016,7 @@
ygopro.stoc_die(client, "${server_full}");
} else if (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) {
client.setTimeout(300000);
client.rid = _.indexOf(ROOM_all, room);
......@@ -3275,7 +3277,7 @@
if (room.hostinfo.mode !== 2) {
client.card_count = 0;
}
room.selecting_tp = false;
room.duel_stage = ygopro.constants.DUEL_STAGE.DUELING;
if (client.pos === 0) {
room.turn = 0;
room.duel_count++;
......@@ -3301,7 +3303,7 @@
if (ygopro.constants.MSG[msg] === 'NEW_TURN') {
r_player = buffer.readUInt8(1);
if (client.pos === 0 && (r_player & 0x2) === 0) {
room.turn = room.turn + 1;
room.turn++;
if (room.death && room.death !== -2) {
if (room.turn >= room.death) {
oppo_pos = room.hostinfo.mode === 2 ? 2 : 1;
......@@ -3339,7 +3341,7 @@
}
if (ygopro.constants.MSG[msg] === 'WIN' && client.pos === 0) {
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;
}
if (pos >= 0 && room.hostinfo.mode === 2) {
......@@ -3348,6 +3350,7 @@
reason = buffer.readUInt8(2);
room.winner = pos;
room.turn = 0;
room.duel_stage = ygopro.constants.DUEL_STAGE.END;
if (settings.modules.heartbeat_detection.enabled) {
ref3 = room.players;
for (m = 0, len3 = ref3.length; m < len3; m++) {
......@@ -3651,7 +3654,7 @@
ygopro.stoc_follow('HS_PLAYER_ENTER', true, function(buffer, info, client, server, datas) {
var pos, room, struct;
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;
}
pos = info.pos;
......@@ -3787,7 +3790,7 @@
wait_room_start = function(room, time) {
var len3, m, player, ref3;
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;
if (time) {
if (!(time % 5)) {
......@@ -3812,7 +3815,7 @@
wait_room_start_arena = function(room) {
var display_name, len3, m, player, ref3;
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;
if (room.waiting_for_player_time > 0) {
if (!(room.waiting_for_player_time % 5)) {
......@@ -3914,7 +3917,7 @@
for (m = 0, len3 = ROOM_all.length; m < len3; m++) {
room = ROOM_all[m];
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);
}
}
......@@ -3928,8 +3931,8 @@
if (!(room && !client.reconnecting)) {
return;
}
if (!room.started) {
room.started = true;
if (room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN) {
room.duel_stage = ygopro.constants.DUEL_STAGE.FINGER;
room.start_time = moment().format();
room.turn = 0;
if (!room.windbot && settings.modules.http.websocket_roomlist) {
......@@ -4026,7 +4029,7 @@
if (!room) {
return;
}
if (!room.started) {
if (room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN) {
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)) {
......@@ -4088,7 +4091,7 @@
switch (cmd[0]) {
case '/投降':
case '/surrender':
if (!room.started || (room.hostinfo.mode === 2 && !settings.modules.tag_duel_surrender)) {
if (room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN || (room.hostinfo.mode === 2 && !settings.modules.tag_duel_surrender)) {
return cancel;
}
if (room.random_type && room.turn < 3 && !client.flee_free) {
......@@ -4352,7 +4355,7 @@
client.abuse_count = client.abuse_count + 4;
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;
cancel = true;
} else if (_.any(settings.ban.spam_word, function(badword) {
......@@ -4455,7 +4458,7 @@
})();
client.main = buff_main;
client.side = buff_side;
if (room.started) {
if (room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) {
client.selected_preduel = true;
if (client.side_tcount) {
clearInterval(client.side_interval);
......@@ -4466,7 +4469,7 @@
client.start_deckbuf = Buffer.from(buffer);
}
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;
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);
......@@ -4484,7 +4487,7 @@
}
return true;
}
if (settings.modules.side_restrict.enabled && room.started) {
if (settings.modules.side_restrict.enabled && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN) {
ref3 = settings.modules.side_restrict.restrict_cards;
for (m = 0, len3 = ref3.length; m < len3; m++) {
code = ref3[m];
......@@ -4505,7 +4508,7 @@
room.waiting_for_player = room.waiting_for_player2;
}
room.last_active_time = moment();
} else if (!room.started && 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 && settings.modules.tournament_mode.enabled && settings.modules.tournament_mode.deck_check && fs.readdirSync(settings.modules.tournament_mode.deck_path).length) {
struct.set("mainc", 1);
struct.set("sidec", 1);
struct.set("deckbuf", [4392470, 4392470]);
......@@ -4586,7 +4589,7 @@
client.main = buff_main_new;
client.side = buff_side_new;
}
if (!room.started) {
if (room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN) {
client.is_using_pre_release = found || client.vpass === "COMPAT";
if (client.is_using_pre_release) {
ygopro.stoc_send_chat(client, "${pre_release_compat_hint}", ygopro.constants.COLORS.BABYBLUE);
......@@ -4625,7 +4628,7 @@
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;
}
check = false;
......@@ -4720,10 +4723,10 @@
var len3, m, pid, player, ref3, room, tcolor, tplayer;
room = ROOM_all[client.rid];
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;
}
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) {
pid = {
0: 2,
......@@ -4763,8 +4766,7 @@
}
client.selected_preduel = false;
if (client.pos === 0) {
room.selecting_hand = true;
room.changing_side = false;
room.duel_stage = ygopro.constants.DUEL_STAGE.FINGER;
}
if (!(room.random_type || room.arena)) {
return;
......@@ -4784,8 +4786,7 @@
return;
}
client.selected_preduel = false;
room.changing_side = false;
room.selecting_hand = false;
room.duel_stage = ygopro.constants.DUEL_STAGE.FIRSTGO;
room.selecting_tp = client;
if (room.random_type || room.arena) {
room.waiting_for_player = client;
......@@ -4799,13 +4800,15 @@
if (!room) {
return;
}
room.changing_side = true;
if (client.pos === 0) {
room.duel_stage = ygopro.constants.DUEL_STAGE.SIDING;
}
client.selected_preduel = false;
if (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);
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);
return;
}
......@@ -4922,7 +4925,7 @@
var len3, m, room, time_passed;
for (m = 0, len3 = ROOM_all.length; m < len3; 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;
}
time_passed = Math.floor((moment() - room.last_active_time) / 1000);
......@@ -4946,7 +4949,7 @@
var len3, len4, m, n, player, room, time_passed, waited_time;
for (m = 0, len3 = ROOM_all.length; m < len3; 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;
}
time_passed = Math.floor((moment() - room.last_active_time) / 1000);
......@@ -4963,7 +4966,7 @@
if (settings.modules.arena_mode.punish_quit_before_match) {
for (n = 0, len4 = ROOM_all.length; n < len4; 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;
}
player = room.get_playing_player()[0];
......@@ -4986,11 +4989,11 @@
var len3, len4, m, n, player, ref3, room;
for (m = 0, len3 = ROOM_all.length; m < len3; 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) {
ref3 = room.get_playing_player();
for (n = 0, len4 = ref3.length; n < len4; n++) {
player = ref3[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);
}
}
......@@ -5005,7 +5008,7 @@
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)) {
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;
}
room.auto_death_triggered = true;
......@@ -5103,7 +5106,7 @@
id: (-1).toString(),
name: player.name,
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],
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
......@@ -5114,7 +5117,7 @@
}
return results1;
})(), "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'
});
}
}
......@@ -5349,7 +5352,7 @@
continue;
}
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[1].name_vpass] = 0;
}
......@@ -5394,7 +5397,7 @@
death_room_found = false;
for (r = 0, len8 = ROOM_all.length; r < len8; r++) {
room = ROOM_all[r];
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()) {
death_room_found = true;
}
......@@ -5417,7 +5420,7 @@
if (!(room)) {
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[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