Commit a865ad8b authored by nanahira's avatar nanahira

Merge branch 'mc'

parents 87dece5b 55afc8da
Pipeline #4748 passed with stages
in 10 minutes and 20 seconds
......@@ -32,6 +32,7 @@ test*
*.tmp
*.bak
*.log
log.*
*.map
......
......@@ -20,7 +20,8 @@
},
"modules": {
"welcome": "MyCard YGOPro Server",
"update": "请更新游戏版本",
"update": "请更新你的客户端版本",
"wait_update": "你的客户端版本高于服务器版本,请等待服务器更新",
"stop": false,
"side_timeout": false,
"tag_duel_surrender": true,
......
......@@ -237,6 +237,10 @@ dataManager = null
windbots = []
disconnect_list = {} # {old_client, old_server, room_id, timeout, deckbuf}
moment_now = global.moment_now = null
moment_now_string = global.moment_now_string = null
moment_long_ago_string = global.moment_long_ago_string = null
challonge = null
challonge_cache = {
participants: null
......@@ -474,6 +478,13 @@ init = () ->
await loadLFList('ygopro/expansions/lflist.conf')
await loadLFList('ygopro/lflist.conf')
setInterval ()->
moment_now = moment()
moment_now_string = moment_now.format()
moment_long_ago_string = moment().subtract(settings.modules.random_duel.hang_timeout - 19, 's').format()
return
, 500
if settings.modules.windbot.enabled
log.info("Reading bot list.")
windbots = global.windbots = (await loadJSONAsync(settings.modules.windbot.botlist)).windbots
......@@ -560,11 +571,11 @@ init = () ->
resolve_data = new ResolveData(_data.callback)
if settings.modules.challonge.cache_ttl and !_data.no_cache and challonge_cache[challonge_type]
resolve_data.resolve(null, challonge_cache[challonge_type])
else if is_challonge_requesting[challonge_type] and moment() - is_challonge_requesting[challonge_type] <= 5000
else if is_challonge_requesting[challonge_type] and moment_now.diff(is_challonge_requesting[challonge_type]) <= 5000
challonge_queue_callbacks[challonge_type].push(resolve_data)
else
_data.callback = get_callback(challonge_type, resolve_data)
is_challonge_requesting[challonge_type] = moment()
is_challonge_requesting[challonge_type] = moment_now_string
try
challonge[challonge_type].index(_data)
catch err
......@@ -624,10 +635,10 @@ init = () ->
if settings.modules.random_duel.enabled
setInterval ()->
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 and (!settings.modules.side_timeout or room.duel_stage != ygopro.constants.DUEL_STAGE.SIDING) and !room.recovered
time_passed = Math.floor((moment() - room.last_active_time) / 1000)
time_passed = Math.floor(moment_now.diff(room.last_active_time) / 1000)
#log.info time_passed
if time_passed >= settings.modules.random_duel.hang_timeout
room.last_active_time = moment()
room.last_active_time = moment_now_string
await ROOM_ban_player(room.waiting_for_player.name, room.waiting_for_player.ip, "${random_ban_reason_AFK}")
room.scores[room.waiting_for_player.name_vpass] = -9
#log.info room.waiting_for_player.name, room.scores[room.waiting_for_player.name_vpass]
......@@ -643,10 +654,10 @@ init = () ->
if settings.modules.mycard.enabled
setInterval ()->
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 and (!settings.modules.side_timeout or room.duel_stage != ygopro.constants.DUEL_STAGE.SIDING) and !room.recovered
time_passed = Math.floor((moment() - room.last_active_time) / 1000)
time_passed = Math.floor(moment_now.diff(room.last_active_time) / 1000)
#log.info time_passed
if time_passed >= settings.modules.random_duel.hang_timeout
room.last_active_time = moment()
room.last_active_time = moment_now_string
ygopro.stoc_send_chat_to_room(room, "#{room.waiting_for_player.name} ${kicked_by_system}", ygopro.constants.COLORS.RED)
room.scores[room.waiting_for_player.name_vpass] = -9
#log.info room.waiting_for_player.name, room.scores[room.waiting_for_player.name_vpass]
......@@ -659,7 +670,7 @@ init = () ->
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
waited_time = moment_now.diff(player.join_time)
if waited_time >= 30000
ygopro.stoc_send_chat(player, "${arena_wait_timeout}", ygopro.constants.COLORS.BABYBLUE)
player.arena_quit_free = true
......@@ -680,8 +691,7 @@ init = () ->
spawn_windbot()
setInterval ()->
current_time = moment()
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
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 moment_now.diff(room.start_time) > 60000 * room.hostinfo.auto_death
room.auto_death_triggered = true
room.start_death()
......@@ -826,9 +836,9 @@ ROOM_find_or_create_random = global.ROOM_find_or_create_random = (type, player_i
if settings.modules.mysql.enabled
randomDuelBanRecord = await dataManager.getRandomDuelBan(player_ip)
if randomDuelBanRecord
if randomDuelBanRecord.count > 6 and moment().isBefore(randomDuelBanRecord.time)
if randomDuelBanRecord.count > 6 and moment_now.isBefore(randomDuelBanRecord.time)
return {"error": "${random_banned_part1}#{randomDuelBanRecord.reasons.join('${random_ban_reason_separator}')}${random_banned_part2}#{moment(randomDuelBanRecord.time).fromNow(true)}${random_banned_part3}"}
if randomDuelBanRecord.count > 3 and moment().isBefore(randomDuelBanRecord.time) and randomDuelBanRecord.getNeedTip() and type != 'T'
if randomDuelBanRecord.count > 3 and moment_now.isBefore(randomDuelBanRecord.time) and randomDuelBanRecord.getNeedTip() and type != 'T'
randomDuelBanRecord.setNeedTip(false)
await dataManager.updateRandomDuelBan(randomDuelBanRecord)
return {"error": "${random_deprecated_part1}#{randomDuelBanRecord.reasons.join('${random_ban_reason_separator}')}${random_deprecated_part2}#{moment(randomDuelBanRecord.time).fromNow(true)}${random_deprecated_part3}"}
......@@ -840,7 +850,7 @@ ROOM_find_or_create_random = global.ROOM_find_or_create_random = (type, player_i
randomDuelBanRecord.setNeedTip(true)
await dataManager.updateRandomDuelBan(randomDuelBanRecord)
max_player = if type == 'T' then 4 else 2
playerbanned = (randomDuelBanRecord and randomDuelBanRecord.count > 3 and moment() < randomDuelBanRecord.time)
playerbanned = (randomDuelBanRecord and randomDuelBanRecord.count > 3 and moment_now < randomDuelBanRecord.time)
result = _.find ROOM_all, (room)->
return room and room.random_type != '' and room.duel_stage == ygopro.constants.DUEL_STAGE.BEGIN and !room.windbot and
((type == '' and
......@@ -1170,7 +1180,7 @@ CLIENT_reconnect = global.CLIENT_reconnect = (client) ->
client.established = true
client.pre_establish_buffers = []
if room.random_type or room.arena
room.last_active_time = moment()
room.last_active_time = moment_now_string
CLIENT_import_data(client, dinfo.old_client, room)
CLIENT_send_reconnect_info(client, client.server, room)
#console.log("#{client.name} ${reconnect_to_game}")
......@@ -1199,7 +1209,7 @@ CLIENT_kick_reconnect = global.CLIENT_kick_reconnect = (client, deckbuf) ->
client.established = true
client.pre_establish_buffers = []
if room.random_type or room.arena
room.last_active_time = moment()
room.last_active_time = moment_now_string
CLIENT_import_data(client, player, room)
CLIENT_send_reconnect_info(client, client.server, room)
#console.log("#{client.name} ${reconnect_to_game}")
......@@ -1239,7 +1249,7 @@ CLIENT_heartbeat_register = global.CLIENT_heartbeat_register = (client, send) ->
return true
CLIENT_is_banned_by_mc = global.CLIENT_is_banned_by_mc = (client) ->
return client.ban_mc and client.ban_mc.banned and moment().isBefore(client.ban_mc.until)
return client.ban_mc and client.ban_mc.banned and moment_now.isBefore(client.ban_mc.until)
CLIENT_get_absolute_pos = global.CLIENT_get_absolute_pos = (client) ->
room = ROOM_all[client.rid]
......@@ -1285,7 +1295,7 @@ getSeedTimet = global.getSeedTimet = (count) ->
while !curTime or _.any(ret, (time) ->
return time == curTime.unix()
)
curTime = moment()
curTime = moment_now
offset = Math.floor(Math.random() * 240) - 120
if offset > 0
curTime = curTime.add(offset, "s")
......@@ -1578,7 +1588,7 @@ class Room
ROOM_player_lose(score_array[0].name_vpass)
if settings.modules.arena_mode.enabled and @arena
#log.info 'SCORE', score_array, @start_time
end_time = moment().format()
end_time = moment_now_string
if !@start_time
@start_time = end_time
if score_array.length != 2
......@@ -1748,7 +1758,7 @@ class Room
connect: (client)->
@players.push client
client.join_time = moment()
client.join_time = moment_now_string
if @random_type
client.abuse_count = 0
host_player = @get_host()
......@@ -2237,7 +2247,7 @@ ygopro.ctos_follow 'JOIN_GAME', true, (buffer, info, client, server, datas)->
await client.open_cloud_replay(replay)
else if info.version != settings.version and !settings.alternative_versions.includes(info.version)
ygopro.stoc_send_chat(client, settings.modules.update, ygopro.constants.COLORS.RED)
ygopro.stoc_send_chat(client, (if info.version < settings.version then settings.modules.update else settings.modules.wait_update), ygopro.constants.COLORS.RED)
ygopro.stoc_send client, 'ERROR_MSG', {
msg: 4
code: settings.version
......@@ -2693,12 +2703,13 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
room=ROOM_all[client.rid]
return unless room and !client.reconnecting
msg = buffer.readInt8(0)
#console.log client.pos, "MSG", ygopro.constants.MSG[msg]
if ygopro.constants.MSG[msg] == 'RETRY' and room.recovering
msg_name = ygopro.constants.MSG[msg]
#console.log client.pos, "MSG", msg_name
if msg_name == 'RETRY' and room.recovering
room.finish_recover(true)
return true
if settings.modules.retry_handle.enabled
if ygopro.constants.MSG[msg] == 'RETRY'
if msg_name == 'RETRY'
if !client.retry_count?
client.retry_count = 0
client.retry_count++
......@@ -2720,11 +2731,11 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
return true
else
client.last_game_msg = buffer
client.last_game_msg_title = ygopro.constants.MSG[msg]
client.last_game_msg_title = msg_name
# log.info(client.name, client.last_game_msg_title)
else if ygopro.constants.MSG[msg] != 'RETRY'
else if msg_name != 'RETRY'
client.last_game_msg = buffer
client.last_game_msg_title = ygopro.constants.MSG[msg]
client.last_game_msg_title = msg_name
# log.info(client.name, client.last_game_msg_title)
if (msg >= 10 and msg < 30) or msg == 132 or (msg >= 140 and msg <= 144) #SELECT和ANNOUNCE开头的消息
......@@ -2735,11 +2746,11 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
return true
else
room.waiting_for_player = client
room.last_active_time = moment()
#log.info("#{ygopro.constants.MSG[msg]}等待#{room.waiting_for_player.name}")
room.last_active_time = moment_now_string
#log.info("#{msg_name}等待#{room.waiting_for_player.name}")
#log.info 'MSG', ygopro.constants.MSG[msg]
if ygopro.constants.MSG[msg] == 'START'
#log.info 'MSG', msg_name
if msg_name == 'START'
playertype = buffer.readUInt8(1)
client.is_first = !(playertype & 0xf)
client.lp = room.hostinfo.start_lp
......@@ -2765,12 +2776,12 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
#ygopro.stoc_send_chat_to_room(room, "LP跟踪调试信息: #{client.name} 初始LP #{client.lp}")
if ygopro.constants.MSG[msg] == 'HINT'
if msg_name == 'HINT'
hint_type = buffer.readUInt8(1)
if hint_type == 3
client.last_hint_msg = buffer
if ygopro.constants.MSG[msg] == 'NEW_TURN'
if msg_name == 'NEW_TURN'
r_player = buffer.readUInt8(1)
if client.pos == 0 and (r_player & 0x2) == 0
room.turn++
......@@ -2792,7 +2803,7 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
client.surrend_confirm = false
ygopro.stoc_send_chat(client, "${surrender_canceled}", ygopro.constants.COLORS.BABYBLUE)
if ygopro.constants.MSG[msg] == 'NEW_PHASE'
if msg_name == 'NEW_PHASE'
phase = buffer.readInt16LE(1)
oppo_pos = if room.hostinfo.mode == 2 then 2 else 1
if client.pos == 0 and room.death == -2 and not (phase == 0x1 and room.turn < 2)
......@@ -2804,7 +2815,7 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
room.death = -1
ygopro.stoc_send_chat_to_room(room, "${death_remain_final}", ygopro.constants.COLORS.BABYBLUE)
if ygopro.constants.MSG[msg] == 'WIN' and client.pos == 0
if msg_name == 'WIN' and client.pos == 0
if room.recovering
room.finish_recover(true)
return true
......@@ -2842,11 +2853,11 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
else
room.death = 5
if ygopro.constants.MSG[msg] == 'MATCH_KILL' and client.pos == 0
if msg_name == 'MATCH_KILL' and client.pos == 0
room.match_kill = true
#lp跟踪
if ygopro.constants.MSG[msg] == 'DAMAGE' and client.pos == 0
if msg_name == 'DAMAGE' and client.pos == 0
pos = buffer.readUInt8(1)
pos = 1 - pos unless client.is_first
pos = pos * 2 if pos >= 0 and room.hostinfo.mode == 2
......@@ -2856,21 +2867,21 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
if 0 < room.dueling_players[pos].lp <= 100
ygopro.stoc_send_chat_to_room(room, "${lp_low_opponent}", ygopro.constants.COLORS.PINK)
if ygopro.constants.MSG[msg] == 'RECOVER' and client.pos == 0
if msg_name == 'RECOVER' and client.pos == 0
pos = buffer.readUInt8(1)
pos = 1 - pos unless client.is_first
pos = pos * 2 if pos >= 0 and room.hostinfo.mode == 2
val = buffer.readInt32LE(2)
room.dueling_players[pos].lp += val
if ygopro.constants.MSG[msg] == 'LPUPDATE' and client.pos == 0
if msg_name == 'LPUPDATE' and client.pos == 0
pos = buffer.readUInt8(1)
pos = 1 - pos unless client.is_first
pos = pos * 2 if pos >= 0 and room.hostinfo.mode == 2
val = buffer.readInt32LE(2)
room.dueling_players[pos].lp = val
if ygopro.constants.MSG[msg] == 'PAY_LPCOST' and client.pos == 0
if msg_name == 'PAY_LPCOST' and client.pos == 0
pos = buffer.readUInt8(1)
pos = 1 - pos unless client.is_first
pos = pos * 2 if pos >= 0 and room.hostinfo.mode == 2
......@@ -2882,7 +2893,7 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
#track card count
#todo: track card count in tag mode
if ygopro.constants.MSG[msg] == 'MOVE' and room.hostinfo.mode != 2
if msg_name == 'MOVE' and room.hostinfo.mode != 2
pos = buffer.readUInt8(5)
pos = 1 - pos unless client.is_first
loc = buffer.readUInt8(6)
......@@ -2892,7 +2903,7 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
loc = buffer.readUInt8(10)
client.card_count++ if (loc & 0xe) and pos == 0
if ygopro.constants.MSG[msg] == 'DRAW' and room.hostinfo.mode != 2
if msg_name == 'DRAW' and room.hostinfo.mode != 2
pos = buffer.readUInt8(1)
pos = 1 - pos unless client.is_first
if pos == 0
......@@ -2900,7 +2911,7 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
client.card_count += count
# check panel confirming cards in heartbeat
if settings.modules.heartbeat_detection.enabled and ygopro.constants.MSG[msg] == 'CONFIRM_CARDS'
if settings.modules.heartbeat_detection.enabled and msg_name == 'CONFIRM_CARDS'
check = false
count = buffer.readInt8(2)
max_loop = 3 + (count - 1) * 7
......@@ -2921,7 +2932,7 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
# chain detection
if settings.modules.heartbeat_detection.enabled and client.pos == 0
if ygopro.constants.MSG[msg] == 'CHAINING'
if msg_name == 'CHAINING'
card = buffer.readUInt32LE(1)
found = false
for id in long_resolve_cards when id == card
......@@ -2932,39 +2943,39 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
# console.log(0,card)
else
delete room.long_resolve_card
else if ygopro.constants.MSG[msg] == 'CHAINED' and room.long_resolve_card
else if msg_name == 'CHAINED' and room.long_resolve_card
chain = buffer.readInt8(1)
if !room.long_resolve_chain
room.long_resolve_chain = []
room.long_resolve_chain[chain] = true
# console.log(1,chain)
delete room.long_resolve_card
else if ygopro.constants.MSG[msg] == 'CHAIN_SOLVING' and room.long_resolve_chain
else if msg_name == 'CHAIN_SOLVING' and room.long_resolve_chain
chain = buffer.readInt8(1)
# console.log(2,chain)
if room.long_resolve_chain[chain]
for player in room.get_playing_player()
player.heartbeat_protected = true
else if (ygopro.constants.MSG[msg] == 'CHAIN_NEGATED' or ygopro.constants.MSG[msg] == 'CHAIN_DISABLED') and room.long_resolve_chain
else if (msg_name == 'CHAIN_NEGATED' or msg_name == 'CHAIN_DISABLED') and room.long_resolve_chain
chain = buffer.readInt8(1)
# console.log(3,chain)
delete room.long_resolve_chain[chain]
else if ygopro.constants.MSG[msg] == 'CHAIN_END'
else if msg_name == 'CHAIN_END'
# console.log(4,chain)
delete room.long_resolve_card
delete room.long_resolve_chain
#登场台词
if (settings.modules.dialogues.enabled or settings.modules.vip.enabled) and !room.recovering
if ygopro.constants.MSG[msg] == 'SUMMONING' or ygopro.constants.MSG[msg] == 'SPSUMMONING' or ygopro.constants.MSG[msg] == 'CHAINING'
if msg_name == 'SUMMONING' or msg_name == 'SPSUMMONING' or msg_name == 'CHAINING'
card = buffer.readUInt32LE(1)
trigger_location = buffer.readUInt8(6)
act_pos = buffer.readUInt8(if ygopro.constants.MSG[msg] == 'CHAINING' then 9 else 5)
act_pos = buffer.readUInt8(if msg_name == 'CHAINING' then 9 else 5)
if !room.dueling_players[0].is_first
act_pos = 1 - act_pos
if room.hostinfo.mode == 2
act_pos = act_pos * 2
if ygopro.constants.MSG[msg] != 'CHAINING' or (trigger_location & 0x8) and client.ready_trap
if msg_name != 'CHAINING' or (trigger_location & 0x8) and client.ready_trap
if settings.modules.vip.enabled and await CLIENT_check_vip(room.dueling_players[act_pos]) and dialogText = await dataManager.getUserDialogueText(CLIENT_get_authorize_key(room.dueling_players[act_pos]), card)
client.playLines dialogText
else if settings.modules.vip.enabled and room.hostinfo.mode == 2 and await CLIENT_check_vip(room.dueling_players[act_pos + 1]) and dialogText = await dataManager.getUserDialogueText(CLIENT_get_authorize_key(room.dueling_players[act_pos + 1]), card)
......@@ -2973,16 +2984,16 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
client.playLines dialogues.dialogues[card][Math.floor(Math.random() * dialogues.dialogues[card].length)]
else if settings.modules.dialogues.enabled and dialogues.dialogues_custom[card]
client.playLines dialogues.dialogues_custom[card][Math.floor(Math.random() * dialogues.dialogues_custom[card].length)]
if ygopro.constants.MSG[msg] == 'POS_CHANGE'
if msg_name == 'POS_CHANGE'
loc = buffer.readUInt8(6)
ppos = buffer.readUInt8(8)
cpos = buffer.readUInt8(9)
client.ready_trap = !!(loc & 0x8) and !!(ppos & 0xa) and !!(cpos & 0x5)
else if ygopro.constants.MSG[msg] != 'UPDATE_CARD' and ygopro.constants.MSG[msg] != 'WAITING'
else if msg_name != 'UPDATE_CARD' and msg_name != 'WAITING'
client.ready_trap = false
if room.recovering and client.pos < 4
if ygopro.constants.MSG[msg] != 'WAITING'
if msg_name != 'WAITING'
room.recover_buffers[client.pos].push(buffer)
return true
......@@ -3195,7 +3206,7 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server, datas)->
return unless room and !client.reconnecting
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.start_time = moment_now_string
room.turn = 0
roomlist.start room if !room.windbot and settings.modules.http.websocket_roomlist
#room.duels = []
......@@ -3246,7 +3257,7 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server, datas)->
deck_arena = deck_arena + 'custom'
#log.info "DECK LOG START", client.name, room.arena
if settings.modules.deck_log.local
deck_name = moment().format('YYYY-MM-DD HH-mm-ss') + ' ' + room.process_pid + ' ' + client.pos + ' ' + client.ip.slice(7) + ' ' + client.name.replace(/[\/\\\?\*]/g, '_')
deck_name = moment_now.format('YYYY-MM-DD HH-mm-ss') + ' ' + room.process_pid + ' ' + client.pos + ' ' + client.ip.slice(7) + ' ' + client.name.replace(/[\/\\\?\*]/g, '_')
fs.writeFile settings.modules.deck_log.local + deck_name + '.ydk', deck_text, 'utf-8', (err) ->
if err
log.warn 'DECK SAVE ERROR', err
......@@ -3313,7 +3324,7 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server, datas)->
return unless room
msg = _.trim(info.msg)
cancel = _.startsWith(msg, "/")
room.last_active_time = moment() unless cancel or not (room.random_type or room.arena) or room.duel_stage == ygopro.constants.DUEL_STAGE.FINGER or room.duel_stage == ygopro.constants.DUEL_STAGE.FIRSTGO or room.duel_stage == ygopro.constants.DUEL_STAGE.SIDING
room.last_active_time = moment_now_string unless cancel or not (room.random_type or room.arena) or room.duel_stage == ygopro.constants.DUEL_STAGE.FINGER or room.duel_stage == ygopro.constants.DUEL_STAGE.FIRSTGO or room.duel_stage == ygopro.constants.DUEL_STAGE.SIDING
cmd = msg.split(' ')
isVip = await CLIENT_check_vip(client)
switch cmd[0]
......@@ -3607,7 +3618,7 @@ ygopro.ctos_follow 'UPDATE_DECK', true, (buffer, info, client, server, datas)->
if room.random_type or room.arena
if client.pos == 0
room.waiting_for_player = room.waiting_for_player2
room.last_active_time = moment()
room.last_active_time = moment_now_string
if room.duel_stage == ygopro.constants.DUEL_STAGE.BEGIN and room.recovering
recover_player_data = _.find(room.recover_duel_log.players, (player) ->
return player.realName == client.name_vpass and buffer.compare(Buffer.from(player.startDeckBuffer, "base64")) == 0
......@@ -3665,7 +3676,7 @@ ygopro.ctos_follow 'UPDATE_DECK', true, (buffer, info, client, server, datas)->
ygopro.ctos_follow 'RESPONSE', false, (buffer, info, client, server, datas)->
room=ROOM_all[client.rid]
return unless room and (room.random_type or room.arena)
room.last_active_time = moment()
room.last_active_time = moment_now_string
await return
ygopro.stoc_follow 'TIME_LIMIT', true, (buffer, info, client, server, datas)->
......@@ -3734,7 +3745,7 @@ ygopro.ctos_follow 'HAND_RESULT', false, (buffer, info, client, server, datas)->
if room.random_type or room.arena
if client.pos == 0
room.waiting_for_player = room.waiting_for_player2
room.last_active_time = moment().subtract(settings.modules.random_duel.hang_timeout - 19, 's')
room.last_active_time = moment_long_ago_string
await return
ygopro.ctos_follow 'TP_RESULT', false, (buffer, info, client, server, datas)->
......@@ -3743,7 +3754,7 @@ ygopro.ctos_follow 'TP_RESULT', false, (buffer, info, client, server, datas)->
client.selected_preduel = true
# room.selecting_tp = false
return unless room.random_type or room.arena
room.last_active_time = moment()
room.last_active_time = moment_now_string
await return
ygopro.stoc_follow 'CHAT', true, (buffer, info, client, server, datas)->
......@@ -3782,7 +3793,7 @@ ygopro.stoc_follow 'SELECT_HAND', true, (buffer, info, client, server, datas)->
room.waiting_for_player = client
else
room.waiting_for_player2 = client
room.last_active_time = moment().subtract(settings.modules.random_duel.hang_timeout - 19, 's')
room.last_active_time = moment_long_ago_string
if room.determine_firstgo
ygopro.ctos_send(server, "HAND_RESULT", {
res: if client.pos == 0 then 2 else 1
......@@ -3803,7 +3814,7 @@ ygopro.stoc_follow 'SELECT_TP', true, (buffer, info, client, server, datas)->
room.duel_stage = ygopro.constants.DUEL_STAGE.FIRSTGO
if room.random_type or room.arena
room.waiting_for_player = client
room.last_active_time = moment()
room.last_active_time = moment_now_string
if room.determine_firstgo
ygopro.ctos_send(server, "TP_RESULT", {
res: if room.determine_firstgo == client then 1 else 0
......@@ -3859,7 +3870,7 @@ ygopro.stoc_follow 'CHANGE_SIDE', false, (buffer, info, client, server, datas)->
room.waiting_for_player = client
else
room.waiting_for_player2 = client
room.last_active_time = moment()
room.last_active_time = moment_now_string
await return
ygopro.stoc_follow 'REPLAY', true, (buffer, info, client, server, datas)->
......@@ -3868,9 +3879,9 @@ ygopro.stoc_follow 'REPLAY', true, (buffer, info, client, server, datas)->
if !room.replays[room.duel_count - 1]
# console.log("Replay saved: ", room.duel_count - 1, client.pos)
room.replays[room.duel_count - 1] = buffer
if settings.modules.mysql.enabled
if settings.modules.mysql.enabled or room.has_ygopro_error
if client.pos == 0
replay_filename=moment().format("YYYY-MM-DD HH-mm-ss")
replay_filename=moment_now.format("YYYY-MM-DD HH-mm-ss")
if room.hostinfo.mode != 2
for player,i in room.dueling_players
replay_filename=replay_filename + (if i > 0 then " VS " else " ") + player.name
......@@ -3878,29 +3889,30 @@ ygopro.stoc_follow 'REPLAY', true, (buffer, info, client, server, datas)->
for player,i in room.dueling_players
replay_filename=replay_filename + (if i > 0 then (if i == 2 then " VS " else " & ") else " ") + player.name
replay_filename=replay_filename.replace(/[\/\\\?\*]/g, '_')+".yrp"
playerInfos = room.dueling_players.map((player) ->
return {
name: player.name
pos: player.pos
realName: player.name_vpass
startDeckBuffer: player.start_deckbuf
deck: {
main: player.main,
side: player.side
}
isFirst: player.is_first
winner: player.pos == room.winner
ip: player.ip
score: room.scores[player.name_vpass]
lp: if player.lp? then player.lp else room.hostinfo.start_lp
cardCount: if player.card_count? then player.card_count else room.hostinfo.start_hand
}
)
fs.writeFile(settings.modules.tournament_mode.replay_path + replay_filename, buffer, (err)->
if err then log.warn "SAVE REPLAY ERROR", replay_filename, err
)
dataManager.saveDuelLog(room.name, room.process_pid, room.cloud_replay_id, replay_filename, room.hostinfo.mode, room.duel_count, playerInfos) # no synchronize here because too slow
if settings.modules.cloud_replay.enabled and settings.modules.tournament_mode.enabled and settings.modules.tournament_mode.replay_safe
if settings.modules.mysql.enabled
playerInfos = room.dueling_players.map((player) ->
return {
name: player.name
pos: player.pos
realName: player.name_vpass
startDeckBuffer: player.start_deckbuf
deck: {
main: player.main,
side: player.side
}
isFirst: player.is_first
winner: player.pos == room.winner
ip: player.ip
score: room.scores[player.name_vpass]
lp: if player.lp? then player.lp else room.hostinfo.start_lp
cardCount: if player.card_count? then player.card_count else room.hostinfo.start_hand
}
)
dataManager.saveDuelLog(room.name, room.process_pid, room.cloud_replay_id, replay_filename, room.hostinfo.mode, room.duel_count, playerInfos) # no synchronize here because too slow
if settings.modules.mysql.enabled && settings.modules.cloud_replay.enabled and settings.modules.tournament_mode.enabled and settings.modules.tournament_mode.replay_safe
ygopro.stoc_send_chat(client, "${cloud_replay_delay_part1}R##{room.cloud_replay_id}${cloud_replay_delay_part2}", ygopro.constants.COLORS.BABYBLUE)
await return settings.modules.tournament_mode.enabled and settings.modules.tournament_mode.block_replay_to_player or settings.modules.replay_delay and room.hostinfo.mode == 1
else
......@@ -4060,7 +4072,7 @@ if true
else
response.writeHead(200)
if settings.modules.tournament_mode.log_save_path
fs.writeFile(settings.modules.tournament_mode.log_save_path + 'duel_log.' + moment().format('YYYY-MM-DD HH-mm-ss') + '.json', JSON.stringify(await dataManager.getDuelLogJSON(settings.modules.tournament_mode), null, 2), (err) ->
fs.writeFile(settings.modules.tournament_mode.log_save_path + 'duel_log.' + moment_now.format('YYYY-MM-DD HH-mm-ss') + '.json', JSON.stringify(await dataManager.getDuelLogJSON(settings.modules.tournament_mode), null, 2), (err) ->
if err
log.warn 'DUEL LOG SAVE ERROR', err
)
......
// Generated by CoffeeScript 2.5.1
(function() {
// 标准库
var CLIENT_check_vip, CLIENT_get_absolute_pos, CLIENT_get_authorize_key, CLIENT_get_kick_reconnect_target, CLIENT_get_partner, CLIENT_get_save_data, CLIENT_heartbeat_register, CLIENT_heartbeat_unregister, CLIENT_import_data, CLIENT_is_able_to_kick_reconnect, CLIENT_is_able_to_reconnect, CLIENT_is_banned_by_mc, CLIENT_is_player, CLIENT_kick, CLIENT_kick_reconnect, CLIENT_pre_reconnect, CLIENT_reconnect, CLIENT_reconnect_register, CLIENT_reconnect_unregister, CLIENT_send_pre_reconnect_info, CLIENT_send_reconnect_info, CLIENT_send_replays, CLIENT_send_vip_status, CLIENT_use_cdkey, Q, ROOM_all, ROOM_bad_ip, ROOM_ban_player, ROOM_clear_disconnect, ROOM_connected_ip, ROOM_find_by_name, ROOM_find_by_pid, ROOM_find_by_port, ROOM_find_by_title, ROOM_find_or_create_ai, ROOM_find_or_create_by_name, ROOM_find_or_create_random, ROOM_kick, ROOM_player_flee, ROOM_player_get_score, ROOM_player_lose, ROOM_player_win, ROOM_players_oppentlist, ROOM_unwelcome, ROOM_validate, ReplayParser, ResolveData, Room, SERVER_clear_disconnect, SERVER_kick, SOCKET_flush_data, VIP_generate_cdkeys, _, _async, addCallback, athleticChecker, auth, axios, badwords, ban_user, bunyan, challonge, challonge_cache, challonge_queue_callbacks, checkFileExists, concat_name, createDirectoryIfNotExists, crypto, dataManager, deck_name_match, dialogues, disconnect_list, exec, execFile, fs, geoip, getDuelLogQueryFromQs, getSeedTimet, get_callback, get_memory_usage, http, httpRequestListener, importOldConfig, import_datas, init, is_challonge_requesting, lflists, loadJSON, loadJSONAsync, loadLFList, loadRemoteData, load_dialogues, load_dialogues_custom, load_tips, load_tips_zh, load_words, log, long_resolve_cards, memory_usage, merge, moment, net, netRequestHandler, os, osu, path, qs, real_windbot_server_ip, refresh_challonge_cache, release_disconnect, replaced_index, report_to_big_brother, request, roomlist, setting_change, setting_save, settings, spawn, spawnSync, spawn_windbot, tips, url, users_cache, util, wait_room_start, wait_room_start_arena, windbot_looplimit, windbot_process, windbots, words, ygopro, zlib;
var CLIENT_check_vip, CLIENT_get_absolute_pos, CLIENT_get_authorize_key, CLIENT_get_kick_reconnect_target, CLIENT_get_partner, CLIENT_get_save_data, CLIENT_heartbeat_register, CLIENT_heartbeat_unregister, CLIENT_import_data, CLIENT_is_able_to_kick_reconnect, CLIENT_is_able_to_reconnect, CLIENT_is_banned_by_mc, CLIENT_is_player, CLIENT_kick, CLIENT_kick_reconnect, CLIENT_pre_reconnect, CLIENT_reconnect, CLIENT_reconnect_register, CLIENT_reconnect_unregister, CLIENT_send_pre_reconnect_info, CLIENT_send_reconnect_info, CLIENT_send_replays, CLIENT_send_vip_status, CLIENT_use_cdkey, Q, ROOM_all, ROOM_bad_ip, ROOM_ban_player, ROOM_clear_disconnect, ROOM_connected_ip, ROOM_find_by_name, ROOM_find_by_pid, ROOM_find_by_port, ROOM_find_by_title, ROOM_find_or_create_ai, ROOM_find_or_create_by_name, ROOM_find_or_create_random, ROOM_kick, ROOM_player_flee, ROOM_player_get_score, ROOM_player_lose, ROOM_player_win, ROOM_players_oppentlist, ROOM_unwelcome, ROOM_validate, ReplayParser, ResolveData, Room, SERVER_clear_disconnect, SERVER_kick, SOCKET_flush_data, VIP_generate_cdkeys, _, _async, addCallback, athleticChecker, auth, axios, badwords, ban_user, bunyan, challonge, challonge_cache, challonge_queue_callbacks, checkFileExists, concat_name, createDirectoryIfNotExists, crypto, dataManager, deck_name_match, dialogues, disconnect_list, exec, execFile, fs, geoip, getDuelLogQueryFromQs, getSeedTimet, get_callback, get_memory_usage, http, httpRequestListener, importOldConfig, import_datas, init, is_challonge_requesting, lflists, loadJSON, loadJSONAsync, loadLFList, loadRemoteData, load_dialogues, load_dialogues_custom, load_tips, load_tips_zh, load_words, log, long_resolve_cards, memory_usage, merge, moment, moment_long_ago_string, moment_now, moment_now_string, net, netRequestHandler, os, osu, path, qs, real_windbot_server_ip, refresh_challonge_cache, release_disconnect, replaced_index, report_to_big_brother, request, roomlist, setting_change, setting_save, settings, spawn, spawnSync, spawn_windbot, tips, url, users_cache, util, wait_room_start, wait_room_start_arena, windbot_looplimit, windbot_process, windbots, words, ygopro, zlib;
net = require('net');
......@@ -296,6 +296,12 @@
disconnect_list = {}; // {old_client, old_server, room_id, timeout, deckbuf}
moment_now = global.moment_now = null;
moment_now_string = global.moment_now_string = null;
moment_long_ago_string = global.moment_long_ago_string = null;
challonge = null;
challonge_cache = {
......@@ -604,6 +610,11 @@
log.info("Reading banlists.");
await loadLFList('ygopro/expansions/lflist.conf');
await loadLFList('ygopro/lflist.conf');
setInterval(function() {
moment_now = moment();
moment_now_string = moment_now.format();
moment_long_ago_string = moment().subtract(settings.modules.random_duel.hang_timeout - 19, 's').format();
}, 500);
if (settings.modules.windbot.enabled) {
log.info("Reading bot list.");
windbots = global.windbots = ((await loadJSONAsync(settings.modules.windbot.botlist))).windbots;
......@@ -701,11 +712,11 @@
resolve_data = new ResolveData(_data.callback);
if (settings.modules.challonge.cache_ttl && !_data.no_cache && challonge_cache[challonge_type]) {
resolve_data.resolve(null, challonge_cache[challonge_type]);
} else if (is_challonge_requesting[challonge_type] && moment() - is_challonge_requesting[challonge_type] <= 5000) {
} else if (is_challonge_requesting[challonge_type] && moment_now.diff(is_challonge_requesting[challonge_type]) <= 5000) {
challonge_queue_callbacks[challonge_type].push(resolve_data);
} else {
_data.callback = get_callback(challonge_type, resolve_data);
is_challonge_requesting[challonge_type] = moment();
is_challonge_requesting[challonge_type] = moment_now_string;
try {
challonge[challonge_type].index(_data);
} catch (error1) {
......@@ -791,10 +802,10 @@
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 && (!settings.modules.side_timeout || room.duel_stage !== ygopro.constants.DUEL_STAGE.SIDING) && !room.recovered)) {
continue;
}
time_passed = Math.floor((moment() - room.last_active_time) / 1000);
time_passed = Math.floor(moment_now.diff(room.last_active_time) / 1000);
//log.info time_passed
if (time_passed >= settings.modules.random_duel.hang_timeout) {
room.last_active_time = moment();
room.last_active_time = moment_now_string;
await ROOM_ban_player(room.waiting_for_player.name, room.waiting_for_player.ip, "${random_ban_reason_AFK}");
room.scores[room.waiting_for_player.name_vpass] = -9;
//log.info room.waiting_for_player.name, room.scores[room.waiting_for_player.name_vpass]
......@@ -816,10 +827,10 @@
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 && (!settings.modules.side_timeout || room.duel_stage !== ygopro.constants.DUEL_STAGE.SIDING) && !room.recovered)) {
continue;
}
time_passed = Math.floor((moment() - room.last_active_time) / 1000);
time_passed = Math.floor(moment_now.diff(room.last_active_time) / 1000);
//log.info time_passed
if (time_passed >= settings.modules.random_duel.hang_timeout) {
room.last_active_time = moment();
room.last_active_time = moment_now_string;
ygopro.stoc_send_chat_to_room(room, `${room.waiting_for_player.name} \${kicked_by_system}`, ygopro.constants.COLORS.RED);
room.scores[room.waiting_for_player.name_vpass] = -9;
//log.info room.waiting_for_player.name, room.scores[room.waiting_for_player.name_vpass]
......@@ -837,7 +848,7 @@
}
player = room.get_playing_player()[0];
if (player && player.join_time && !player.arena_quit_free) {
waited_time = moment() - player.join_time;
waited_time = moment_now.diff(player.join_time);
if (waited_time >= 30000) {
ygopro.stoc_send_chat(player, "${arena_wait_timeout}", ygopro.constants.COLORS.BABYBLUE);
player.arena_quit_free = true;
......@@ -870,12 +881,11 @@
spawn_windbot();
}
setInterval(function() {
var current_time, l, len1, results, room;
current_time = moment();
var l, len1, results, room;
results = [];
for (l = 0, len1 = ROOM_all.length; l < len1; l++) {
room = ROOM_all[l];
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)) {
if (!(room && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && room.hostinfo.auto_death && !room.auto_death_triggered && moment_now.diff(room.start_time) > 60000 * room.hostinfo.auto_death)) {
continue;
}
room.auto_death_triggered = true;
......@@ -1061,12 +1071,12 @@
if (settings.modules.mysql.enabled) {
randomDuelBanRecord = (await dataManager.getRandomDuelBan(player_ip));
if (randomDuelBanRecord) {
if (randomDuelBanRecord.count > 6 && moment().isBefore(randomDuelBanRecord.time)) {
if (randomDuelBanRecord.count > 6 && moment_now.isBefore(randomDuelBanRecord.time)) {
return {
"error": `\${random_banned_part1}${randomDuelBanRecord.reasons.join('${random_ban_reason_separator}')}\${random_banned_part2}${moment(randomDuelBanRecord.time).fromNow(true)}\${random_banned_part3}`
};
}
if (randomDuelBanRecord.count > 3 && moment().isBefore(randomDuelBanRecord.time) && randomDuelBanRecord.getNeedTip() && type !== 'T') {
if (randomDuelBanRecord.count > 3 && moment_now.isBefore(randomDuelBanRecord.time) && randomDuelBanRecord.getNeedTip() && type !== 'T') {
randomDuelBanRecord.setNeedTip(false);
await dataManager.updateRandomDuelBan(randomDuelBanRecord);
return {
......@@ -1085,7 +1095,7 @@
}
}
max_player = type === 'T' ? 4 : 2;
playerbanned = randomDuelBanRecord && randomDuelBanRecord.count > 3 && moment() < randomDuelBanRecord.time;
playerbanned = randomDuelBanRecord && randomDuelBanRecord.count > 3 && moment_now < randomDuelBanRecord.time;
result = _.find(ROOM_all, function(room) {
return room && room.random_type !== '' && room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN && !room.windbot && ((type === '' && (room.random_type === settings.modules.random_duel.default_type || settings.modules.random_duel.blank_pass_modes[room.random_type])) || 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');
});
......@@ -1540,7 +1550,7 @@
client.established = true;
client.pre_establish_buffers = [];
if (room.random_type || room.arena) {
room.last_active_time = moment();
room.last_active_time = moment_now_string;
}
CLIENT_import_data(client, dinfo.old_client, room);
CLIENT_send_reconnect_info(client, client.server, room);
......@@ -1572,7 +1582,7 @@
client.established = true;
client.pre_establish_buffers = [];
if (room.random_type || room.arena) {
room.last_active_time = moment();
room.last_active_time = moment_now_string;
}
CLIENT_import_data(client, player, room);
CLIENT_send_reconnect_info(client, client.server, room);
......@@ -1620,7 +1630,7 @@
};
CLIENT_is_banned_by_mc = global.CLIENT_is_banned_by_mc = function(client) {
return client.ban_mc && client.ban_mc.banned && moment().isBefore(client.ban_mc.until);
return client.ban_mc && client.ban_mc.banned && moment_now.isBefore(client.ban_mc.until);
};
CLIENT_get_absolute_pos = global.CLIENT_get_absolute_pos = function(client) {
......@@ -1688,7 +1698,7 @@
while (!curTime || _.any(ret, function(time) {
return time === curTime.unix();
})) {
curTime = moment();
curTime = moment_now;
offset = Math.floor(Math.random() * 240) - 120;
if (offset > 0) {
curTime = curTime.add(offset, "s");
......@@ -2054,7 +2064,7 @@
}
if (settings.modules.arena_mode.enabled && this.arena) {
//log.info 'SCORE', score_array, @start_time
end_time = moment().format();
end_time = moment_now_string;
if (!this.start_time) {
this.start_time = end_time;
}
......@@ -2303,7 +2313,7 @@
connect(client) {
var host_player;
this.players.push(client);
client.join_time = moment();
client.join_time = moment_now_string;
if (this.random_type) {
client.abuse_count = 0;
host_player = this.get_host();
......@@ -2978,7 +2988,7 @@
replay = (await dataManager.getRandomCloudReplay());
await client.open_cloud_replay(replay);
} else if (info.version !== settings.version && !settings.alternative_versions.includes(info.version)) {
ygopro.stoc_send_chat(client, settings.modules.update, ygopro.constants.COLORS.RED);
ygopro.stoc_send_chat(client, (info.version < settings.version ? settings.modules.update : settings.modules.wait_update), ygopro.constants.COLORS.RED);
ygopro.stoc_send(client, 'ERROR_MSG', {
msg: 4,
code: settings.version
......@@ -3510,19 +3520,20 @@
};
ygopro.stoc_follow('GAME_MSG', true, async function(buffer, info, client, server, datas) {
var act_pos, card, chain, check, count, cpos, deck_found, dialogText, found, hint_type, i, id, j, l, len, len1, len2, len3, limbo_found, loc, m, max_loop, msg, n, o, oppo_pos, phase, player, playertype, pos, ppos, r_player, reason, ref, ref1, ref2, ref3, ref4, room, trigger_location, val, victoryWordPlayerList, win_pos;
var act_pos, card, chain, check, count, cpos, deck_found, dialogText, found, hint_type, i, id, j, l, len, len1, len2, len3, limbo_found, loc, m, max_loop, msg, msg_name, n, o, oppo_pos, phase, player, playertype, pos, ppos, r_player, reason, ref, ref1, ref2, ref3, ref4, room, trigger_location, val, victoryWordPlayerList, win_pos;
room = ROOM_all[client.rid];
if (!(room && !client.reconnecting)) {
return;
}
msg = buffer.readInt8(0);
//console.log client.pos, "MSG", ygopro.constants.MSG[msg]
if (ygopro.constants.MSG[msg] === 'RETRY' && room.recovering) {
msg_name = ygopro.constants.MSG[msg];
//console.log client.pos, "MSG", msg_name
if (msg_name === 'RETRY' && room.recovering) {
room.finish_recover(true);
return true;
}
if (settings.modules.retry_handle.enabled) {
if (ygopro.constants.MSG[msg] === 'RETRY') {
if (msg_name === 'RETRY') {
if (client.retry_count == null) {
client.retry_count = 0;
}
......@@ -3549,12 +3560,12 @@
}
} else {
client.last_game_msg = buffer;
client.last_game_msg_title = ygopro.constants.MSG[msg];
client.last_game_msg_title = msg_name;
}
// log.info(client.name, client.last_game_msg_title)
} else if (ygopro.constants.MSG[msg] !== 'RETRY') {
} else if (msg_name !== 'RETRY') {
client.last_game_msg = buffer;
client.last_game_msg_title = ygopro.constants.MSG[msg];
client.last_game_msg_title = msg_name;
}
// log.info(client.name, client.last_game_msg_title)
if ((msg >= 10 && msg < 30) || msg === 132 || (msg >= 140 && msg <= 144)) { //SELECT和ANNOUNCE开头的消息
......@@ -3566,13 +3577,13 @@
return true;
} else {
room.waiting_for_player = client;
room.last_active_time = moment();
room.last_active_time = moment_now_string;
}
}
//log.info("#{ygopro.constants.MSG[msg]}等待#{room.waiting_for_player.name}")
//log.info("#{msg_name}等待#{room.waiting_for_player.name}")
//log.info 'MSG', ygopro.constants.MSG[msg]
if (ygopro.constants.MSG[msg] === 'START') {
//log.info 'MSG', msg_name
if (msg_name === 'START') {
playertype = buffer.readUInt8(1);
client.is_first = !(playertype & 0xf);
client.lp = room.hostinfo.start_lp;
......@@ -3606,13 +3617,13 @@
}
}
//ygopro.stoc_send_chat_to_room(room, "LP跟踪调试信息: #{client.name} 初始LP #{client.lp}")
if (ygopro.constants.MSG[msg] === 'HINT') {
if (msg_name === 'HINT') {
hint_type = buffer.readUInt8(1);
if (hint_type === 3) {
client.last_hint_msg = buffer;
}
}
if (ygopro.constants.MSG[msg] === 'NEW_TURN') {
if (msg_name === 'NEW_TURN') {
r_player = buffer.readUInt8(1);
if (client.pos === 0 && (r_player & 0x2) === 0) {
room.turn++;
......@@ -3640,7 +3651,7 @@
ygopro.stoc_send_chat(client, "${surrender_canceled}", ygopro.constants.COLORS.BABYBLUE);
}
}
if (ygopro.constants.MSG[msg] === 'NEW_PHASE') {
if (msg_name === 'NEW_PHASE') {
phase = buffer.readInt16LE(1);
oppo_pos = room.hostinfo.mode === 2 ? 2 : 1;
if (client.pos === 0 && room.death === -2 && !(phase === 0x1 && room.turn < 2)) {
......@@ -3654,7 +3665,7 @@
}
}
}
if (ygopro.constants.MSG[msg] === 'WIN' && client.pos === 0) {
if (msg_name === 'WIN' && client.pos === 0) {
if (room.recovering) {
room.finish_recover(true);
return true;
......@@ -3712,11 +3723,11 @@
}
}
}
if (ygopro.constants.MSG[msg] === 'MATCH_KILL' && client.pos === 0) {
if (msg_name === 'MATCH_KILL' && client.pos === 0) {
room.match_kill = true;
}
//lp跟踪
if (ygopro.constants.MSG[msg] === 'DAMAGE' && client.pos === 0) {
if (msg_name === 'DAMAGE' && client.pos === 0) {
pos = buffer.readUInt8(1);
if (!client.is_first) {
pos = 1 - pos;
......@@ -3733,7 +3744,7 @@
ygopro.stoc_send_chat_to_room(room, "${lp_low_opponent}", ygopro.constants.COLORS.PINK);
}
}
if (ygopro.constants.MSG[msg] === 'RECOVER' && client.pos === 0) {
if (msg_name === 'RECOVER' && client.pos === 0) {
pos = buffer.readUInt8(1);
if (!client.is_first) {
pos = 1 - pos;
......@@ -3744,7 +3755,7 @@
val = buffer.readInt32LE(2);
room.dueling_players[pos].lp += val;
}
if (ygopro.constants.MSG[msg] === 'LPUPDATE' && client.pos === 0) {
if (msg_name === 'LPUPDATE' && client.pos === 0) {
pos = buffer.readUInt8(1);
if (!client.is_first) {
pos = 1 - pos;
......@@ -3755,7 +3766,7 @@
val = buffer.readInt32LE(2);
room.dueling_players[pos].lp = val;
}
if (ygopro.constants.MSG[msg] === 'PAY_LPCOST' && client.pos === 0) {
if (msg_name === 'PAY_LPCOST' && client.pos === 0) {
pos = buffer.readUInt8(1);
if (!client.is_first) {
pos = 1 - pos;
......@@ -3774,7 +3785,7 @@
}
//track card count
//todo: track card count in tag mode
if (ygopro.constants.MSG[msg] === 'MOVE' && room.hostinfo.mode !== 2) {
if (msg_name === 'MOVE' && room.hostinfo.mode !== 2) {
pos = buffer.readUInt8(5);
if (!client.is_first) {
pos = 1 - pos;
......@@ -3792,7 +3803,7 @@
client.card_count++;
}
}
if (ygopro.constants.MSG[msg] === 'DRAW' && room.hostinfo.mode !== 2) {
if (msg_name === 'DRAW' && room.hostinfo.mode !== 2) {
pos = buffer.readUInt8(1);
if (!client.is_first) {
pos = 1 - pos;
......@@ -3803,7 +3814,7 @@
}
}
// check panel confirming cards in heartbeat
if (settings.modules.heartbeat_detection.enabled && ygopro.constants.MSG[msg] === 'CONFIRM_CARDS') {
if (settings.modules.heartbeat_detection.enabled && msg_name === 'CONFIRM_CARDS') {
check = false;
count = buffer.readInt8(2);
max_loop = 3 + (count - 1) * 7;
......@@ -3828,7 +3839,7 @@
}
// chain detection
if (settings.modules.heartbeat_detection.enabled && client.pos === 0) {
if (ygopro.constants.MSG[msg] === 'CHAINING') {
if (msg_name === 'CHAINING') {
card = buffer.readUInt32LE(1);
found = false;
for (n = 0, len2 = long_resolve_cards.length; n < len2; n++) {
......@@ -3845,7 +3856,7 @@
// console.log(0,card)
delete room.long_resolve_card;
}
} else if (ygopro.constants.MSG[msg] === 'CHAINED' && room.long_resolve_card) {
} else if (msg_name === 'CHAINED' && room.long_resolve_card) {
chain = buffer.readInt8(1);
if (!room.long_resolve_chain) {
room.long_resolve_chain = [];
......@@ -3853,7 +3864,7 @@
room.long_resolve_chain[chain] = true;
// console.log(1,chain)
delete room.long_resolve_card;
} else if (ygopro.constants.MSG[msg] === 'CHAIN_SOLVING' && room.long_resolve_chain) {
} else if (msg_name === 'CHAIN_SOLVING' && room.long_resolve_chain) {
chain = buffer.readInt8(1);
// console.log(2,chain)
if (room.long_resolve_chain[chain]) {
......@@ -3863,11 +3874,11 @@
player.heartbeat_protected = true;
}
}
} else if ((ygopro.constants.MSG[msg] === 'CHAIN_NEGATED' || ygopro.constants.MSG[msg] === 'CHAIN_DISABLED') && room.long_resolve_chain) {
} else if ((msg_name === 'CHAIN_NEGATED' || msg_name === 'CHAIN_DISABLED') && room.long_resolve_chain) {
chain = buffer.readInt8(1);
// console.log(3,chain)
delete room.long_resolve_chain[chain];
} else if (ygopro.constants.MSG[msg] === 'CHAIN_END') {
} else if (msg_name === 'CHAIN_END') {
// console.log(4,chain)
delete room.long_resolve_card;
delete room.long_resolve_chain;
......@@ -3875,17 +3886,17 @@
}
//登场台词
if ((settings.modules.dialogues.enabled || settings.modules.vip.enabled) && !room.recovering) {
if (ygopro.constants.MSG[msg] === 'SUMMONING' || ygopro.constants.MSG[msg] === 'SPSUMMONING' || ygopro.constants.MSG[msg] === 'CHAINING') {
if (msg_name === 'SUMMONING' || msg_name === 'SPSUMMONING' || msg_name === 'CHAINING') {
card = buffer.readUInt32LE(1);
trigger_location = buffer.readUInt8(6);
act_pos = buffer.readUInt8(ygopro.constants.MSG[msg] === 'CHAINING' ? 9 : 5);
act_pos = buffer.readUInt8(msg_name === 'CHAINING' ? 9 : 5);
if (!room.dueling_players[0].is_first) {
act_pos = 1 - act_pos;
}
if (room.hostinfo.mode === 2) {
act_pos = act_pos * 2;
}
if (ygopro.constants.MSG[msg] !== 'CHAINING' || (trigger_location & 0x8) && client.ready_trap) {
if (msg_name !== 'CHAINING' || (trigger_location & 0x8) && client.ready_trap) {
if (settings.modules.vip.enabled && (await CLIENT_check_vip(room.dueling_players[act_pos])) && (dialogText = (await dataManager.getUserDialogueText(CLIENT_get_authorize_key(room.dueling_players[act_pos]), card)))) {
client.playLines(dialogText);
} else if (settings.modules.vip.enabled && room.hostinfo.mode === 2 && (await CLIENT_check_vip(room.dueling_players[act_pos + 1])) && (dialogText = (await dataManager.getUserDialogueText(CLIENT_get_authorize_key(room.dueling_players[act_pos + 1]), card)))) {
......@@ -3897,17 +3908,17 @@
}
}
}
if (ygopro.constants.MSG[msg] === 'POS_CHANGE') {
if (msg_name === 'POS_CHANGE') {
loc = buffer.readUInt8(6);
ppos = buffer.readUInt8(8);
cpos = buffer.readUInt8(9);
client.ready_trap = !!(loc & 0x8) && !!(ppos & 0xa) && !!(cpos & 0x5);
} else if (ygopro.constants.MSG[msg] !== 'UPDATE_CARD' && ygopro.constants.MSG[msg] !== 'WAITING') {
} else if (msg_name !== 'UPDATE_CARD' && msg_name !== 'WAITING') {
client.ready_trap = false;
}
}
if (room.recovering && client.pos < 4) {
if (ygopro.constants.MSG[msg] !== 'WAITING') {
if (msg_name !== 'WAITING') {
room.recover_buffers[client.pos].push(buffer);
}
return true;
......@@ -4243,7 +4254,7 @@
}
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.start_time = moment_now_string;
room.turn = 0;
if (!room.windbot && settings.modules.http.websocket_roomlist) {
roomlist.start(room);
......@@ -4317,7 +4328,7 @@
}
//log.info "DECK LOG START", client.name, room.arena
if (settings.modules.deck_log.local) {
deck_name = moment().format('YYYY-MM-DD HH-mm-ss') + ' ' + room.process_pid + ' ' + client.pos + ' ' + client.ip.slice(7) + ' ' + client.name.replace(/[\/\\\?\*]/g, '_');
deck_name = moment_now.format('YYYY-MM-DD HH-mm-ss') + ' ' + room.process_pid + ' ' + client.pos + ' ' + client.ip.slice(7) + ' ' + client.name.replace(/[\/\\\?\*]/g, '_');
fs.writeFile(settings.modules.deck_log.local + deck_name + '.ydk', deck_text, 'utf-8', function(err) {
if (err) {
return log.warn('DECK SAVE ERROR', err);
......@@ -4413,7 +4424,7 @@
msg = _.trim(info.msg);
cancel = _.startsWith(msg, "/");
if (!(cancel || !(room.random_type || room.arena) || room.duel_stage === ygopro.constants.DUEL_STAGE.FINGER || room.duel_stage === ygopro.constants.DUEL_STAGE.FIRSTGO || room.duel_stage === ygopro.constants.DUEL_STAGE.SIDING)) {
room.last_active_time = moment();
room.last_active_time = moment_now_string;
}
cmd = msg.split(' ');
isVip = (await CLIENT_check_vip(client));
......@@ -4810,7 +4821,7 @@
if (client.pos === 0) {
room.waiting_for_player = room.waiting_for_player2;
}
room.last_active_time = moment();
room.last_active_time = moment_now_string;
}
if (room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN && room.recovering) {
recover_player_data = _.find(room.recover_duel_log.players, function(player) {
......@@ -4889,7 +4900,7 @@
if (!(room && (room.random_type || room.arena))) {
return;
}
room.last_active_time = moment();
room.last_active_time = moment_now_string;
});
ygopro.stoc_follow('TIME_LIMIT', true, async function(buffer, info, client, server, datas) {
......@@ -4988,7 +4999,7 @@
if (client.pos === 0) {
room.waiting_for_player = room.waiting_for_player2;
}
room.last_active_time = moment().subtract(settings.modules.random_duel.hang_timeout - 19, 's');
room.last_active_time = moment_long_ago_string;
}
});
......@@ -5003,7 +5014,7 @@
if (!(room.random_type || room.arena)) {
return;
}
room.last_active_time = moment();
room.last_active_time = moment_now_string;
});
ygopro.stoc_follow('CHAT', true, async function(buffer, info, client, server, datas) {
......@@ -5060,7 +5071,7 @@
} else {
room.waiting_for_player2 = client;
}
room.last_active_time = moment().subtract(settings.modules.random_duel.hang_timeout - 19, 's');
room.last_active_time = moment_long_ago_string;
}
if (room.determine_firstgo) {
ygopro.ctos_send(server, "HAND_RESULT", {
......@@ -5091,7 +5102,7 @@
room.duel_stage = ygopro.constants.DUEL_STAGE.FIRSTGO;
if (room.random_type || room.arena) {
room.waiting_for_player = client;
room.last_active_time = moment();
room.last_active_time = moment_now_string;
}
if (room.determine_firstgo) {
ygopro.ctos_send(server, "TP_RESULT", {
......@@ -5160,7 +5171,7 @@
} else {
room.waiting_for_player2 = client;
}
room.last_active_time = moment();
room.last_active_time = moment_now_string;
}
});
......@@ -5174,9 +5185,9 @@
// console.log("Replay saved: ", room.duel_count - 1, client.pos)
room.replays[room.duel_count - 1] = buffer;
}
if (settings.modules.mysql.enabled) {
if (settings.modules.mysql.enabled || room.has_ygopro_error) {
if (client.pos === 0) {
replay_filename = moment().format("YYYY-MM-DD HH-mm-ss");
replay_filename = moment_now.format("YYYY-MM-DD HH-mm-ss");
if (room.hostinfo.mode !== 2) {
ref = room.dueling_players;
for (i = j = 0, len = ref.length; j < len; i = ++j) {
......@@ -5191,32 +5202,34 @@
}
}
replay_filename = replay_filename.replace(/[\/\\\?\*]/g, '_') + ".yrp";
playerInfos = room.dueling_players.map(function(player) {
return {
name: player.name,
pos: player.pos,
realName: player.name_vpass,
startDeckBuffer: player.start_deckbuf,
deck: {
main: player.main,
side: player.side
},
isFirst: player.is_first,
winner: player.pos === room.winner,
ip: player.ip,
score: room.scores[player.name_vpass],
lp: player.lp != null ? player.lp : room.hostinfo.start_lp,
cardCount: player.card_count != null ? player.card_count : room.hostinfo.start_hand
};
});
fs.writeFile(settings.modules.tournament_mode.replay_path + replay_filename, buffer, function(err) {
if (err) {
return log.warn("SAVE REPLAY ERROR", replay_filename, err);
}
});
dataManager.saveDuelLog(room.name, room.process_pid, room.cloud_replay_id, replay_filename, room.hostinfo.mode, room.duel_count, playerInfos); // no synchronize here because too slow
if (settings.modules.mysql.enabled) {
playerInfos = room.dueling_players.map(function(player) {
return {
name: player.name,
pos: player.pos,
realName: player.name_vpass,
startDeckBuffer: player.start_deckbuf,
deck: {
main: player.main,
side: player.side
},
isFirst: player.is_first,
winner: player.pos === room.winner,
ip: player.ip,
score: room.scores[player.name_vpass],
lp: player.lp != null ? player.lp : room.hostinfo.start_lp,
cardCount: player.card_count != null ? player.card_count : room.hostinfo.start_hand
};
});
dataManager.saveDuelLog(room.name, room.process_pid, room.cloud_replay_id, replay_filename, room.hostinfo.mode, room.duel_count, playerInfos); // no synchronize here because too slow
}
}
if (settings.modules.cloud_replay.enabled && settings.modules.tournament_mode.enabled && settings.modules.tournament_mode.replay_safe) {
if (settings.modules.mysql.enabled && settings.modules.cloud_replay.enabled && settings.modules.tournament_mode.enabled && settings.modules.tournament_mode.replay_safe) {
ygopro.stoc_send_chat(client, `\${cloud_replay_delay_part1}R#${room.cloud_replay_id}\${cloud_replay_delay_part2}`, ygopro.constants.COLORS.BABYBLUE);
}
return settings.modules.tournament_mode.enabled && settings.modules.tournament_mode.block_replay_to_player || settings.modules.replay_delay && room.hostinfo.mode === 1;
......@@ -5419,7 +5432,7 @@
} else {
response.writeHead(200);
if (settings.modules.tournament_mode.log_save_path) {
fs.writeFile(settings.modules.tournament_mode.log_save_path + 'duel_log.' + moment().format('YYYY-MM-DD HH-mm-ss') + '.json', JSON.stringify((await dataManager.getDuelLogJSON(settings.modules.tournament_mode)), null, 2), function(err) {
fs.writeFile(settings.modules.tournament_mode.log_save_path + 'duel_log.' + moment_now.format('YYYY-MM-DD HH-mm-ss') + '.json', JSON.stringify((await dataManager.getDuelLogJSON(settings.modules.tournament_mode)), null, 2), function(err) {
if (err) {
return log.warn('DUEL LOG SAVE ERROR', err);
}
......
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