Commit 7b36b356 authored by nanahira's avatar nanahira

merge

parents 02fc8cdc 7e5b710c
......@@ -99,6 +99,7 @@
"reconnect": {
"enabled": true,
"auto_surrender_after_disconnect": false,
"allow_kick_reconnect": true,
"wait_time": 60000
},
"heartbeat_detection": {
......
......@@ -146,6 +146,7 @@
"deck_incorrect_reconnect": "Please pick your previous deck.",
"reconnect_failed": "Reconnect failed.",
"reconnecting_to_room": "Reconnecting to server...",
"reconnect_kicked": "You are kicked out because you're logined in on other devices.",
"challonge_user_not_found": "You are not a participant of the tournament.",
"challonge_match_load_failed": "Failed loading tournament info.",
"challonge_match_not_found": "Your current match was not found.",
......@@ -460,6 +461,7 @@
"deck_incorrect_reconnect": "请选择你在本局决斗中使用的卡组。",
"reconnect_failed": "重新连接失败。",
"reconnecting_to_room": "正在重新连接到服务器……",
"reconnect_kicked": "你的账号已经在其他设备登录,你被迫下线。",
"challonge_user_not_found": "未找到你的参赛信息。",
"challonge_match_load_failed": "读取比赛信息失败。",
"challonge_match_not_found": "你没有当前轮次的比赛。",
......
......@@ -49,6 +49,7 @@ import_datas = [
"is_post_watcher",
"retry_count",
"name",
"pass",
"is_first",
"lp",
"card_count",
......@@ -586,7 +587,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)
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.max_player and room.get_disconnected_count() >= room.max_player - 1)
return false
# for player in room.players
# if player != client and CLIENT_get_authorize_key(player) == CLIENT_get_authorize_key(client)
......@@ -656,7 +657,7 @@ CLIENT_is_player = (client, room) ->
break
return is_player and client.pos <= 3
CLIENT_is_able_to_reconnect = (client) ->
CLIENT_is_able_to_reconnect = (client, deckbuf) ->
unless settings.modules.reconnect.enabled
return false
if client.system_kicked
......@@ -668,13 +669,21 @@ CLIENT_is_able_to_reconnect = (client) ->
if !room
CLIENT_reconnect_unregister(client)
return false
# if disconnect_info.old_server.closed
# return false
# current_room = disconnect_info.room
# unless current_room and current_room.started
# return false
# if client.is_post_watcher or !CLIENT_is_player(client, current_room) or (room.windbot and client.is_local)
# return false
if deckbuf and !_.isEqual(deckbuf, disconnect_info.deckbuf)
return false
return true
CLIENT_get_kick_reconnect_target = (client, deckbuf) ->
for room in ROOM_all when room.started and !room.windbot
for player in room.get_playing_player() when !player.closed and player.name == client.name and player.pass == client.pass and (settings.modules.mycard.enabled or player.ip == client.ip) and (!deckbuf or _.isEqual(player.start_deckbuf, deckbuf))
return player
return null
CLIENT_is_able_to_kick_reconnect = (client, deckbuf) ->
unless settings.modules.reconnect.enabled and settings.modules.reconnect.allow_kick_reconnect
return false
if !CLIENT_get_kick_reconnect_target(client, deckbuf)
return false
return true
CLIENT_send_pre_reconnect_info = (client, room, old_client) ->
......@@ -718,14 +727,18 @@ CLIENT_send_reconnect_info = (client, server, room) ->
return
CLIENT_pre_reconnect = (client) ->
if !CLIENT_is_able_to_reconnect(client)
return
dinfo = disconnect_list[CLIENT_get_authorize_key(client)]
client.pre_deckbuf = dinfo.deckbuf
client.pre_reconnecting = true
client.pos = dinfo.old_client.pos
client.setTimeout(300000)
CLIENT_send_pre_reconnect_info(client, ROOM_all[dinfo.room_id], dinfo.old_client)
if CLIENT_is_able_to_reconnect(client)
dinfo = disconnect_list[CLIENT_get_authorize_key(client)]
client.pre_reconnecting = true
client.pos = dinfo.old_client.pos
client.setTimeout(300000)
CLIENT_send_pre_reconnect_info(client, ROOM_all[dinfo.room_id], dinfo.old_client)
else if CLIENT_is_able_to_kick_reconnect(client)
player = CLIENT_get_kick_reconnect_target(client)
client.pre_reconnecting = true
client.pos = player.pos
client.setTimeout(300000)
CLIENT_send_pre_reconnect_info(client, ROOM_all[player.rid], player)
return
CLIENT_reconnect = (client) ->
......@@ -754,6 +767,35 @@ CLIENT_reconnect = (client) ->
CLIENT_reconnect_unregister(client, true)
return
CLIENT_kick_reconnect = (client, deckbuf) ->
if !CLIENT_is_able_to_kick_reconnect(client)
ygopro.stoc_send_chat(client, "${reconnect_failed}", ygopro.constants.COLORS.RED)
CLIENT_kick(client)
return
client.pre_reconnecting = false
player = CLIENT_get_kick_reconnect_target(client, deckbuf)
room = ROOM_all[player.rid]
current_old_server = client.server
client.server = player.server
client.server.client = client
ygopro.stoc_send_chat(player, "${reconnect_kicked}", ygopro.constants.COLORS.RED)
player.server = null
player.had_new_reconnection = true
CLIENT_kick(player)
current_old_server.client = null
current_old_server.had_new_reconnection = true
current_old_server.destroy()
client.established = true
client.pre_establish_buffers = []
if room.random_type or room.arena
room.last_active_time = moment()
CLIENT_import_data(client, player, room)
CLIENT_send_reconnect_info(client, client.server, room)
#console.log("#{client.name} ${reconnect_to_game}")
ygopro.stoc_send_chat_to_room(room, "#{client.name} ${reconnect_to_game}")
CLIENT_reconnect_unregister(client, true)
return
if settings.modules.reconnect.enabled
disconnect_list = {} # {old_client, old_server, room_id, timeout, deckbuf}
......@@ -1061,13 +1103,12 @@ class Room
return
return host_player
is_has_disconnected_player: ->
get_disconnected_count: ->
if !settings.modules.reconnect.enabled
return false
found = false
return 0
found = 0
for player in @get_playing_player() when player.closed
found = true
break
found++
return found
add_windbot: (botdata)->
......@@ -1445,7 +1486,8 @@ ygopro.ctos_follow 'PLAYER_INFO', true, (buffer, info, client, server)->
ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
#log.info info
info.pass=info.pass.trim()
if CLIENT_is_able_to_reconnect(client)
client.pass = info.pass
if CLIENT_is_able_to_reconnect(client) or CLIENT_is_able_to_kick_reconnect(client)
CLIENT_pre_reconnect(client)
return
else if settings.modules.stop
......@@ -2756,8 +2798,13 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server)->
ygopro.ctos_follow 'UPDATE_DECK', true, (buffer, info, client, server)->
if settings.modules.reconnect.enabled and client.pre_reconnecting
if _.isEqual(buffer, client.pre_deckbuf)
if !CLIENT_is_able_to_reconnect(client) and !CLIENT_is_able_to_kick_reconnect(client)
ygopro.stoc_send_chat(client, "${reconnect_failed}", ygopro.constants.COLORS.RED)
CLIENT_kick(client)
else if CLIENT_is_able_to_reconnect(client, buffer)
CLIENT_reconnect(client)
else if CLIENT_is_able_to_kick_reconnect(client, buffer)
CLIENT_kick_reconnect(client, buffer)
else
ygopro.stoc_send_chat(client, "${deck_incorrect_reconnect}", ygopro.constants.COLORS.RED)
ygopro.stoc_send(client, 'ERROR_MSG', {
......@@ -3053,7 +3100,7 @@ ygopro.stoc_follow 'REPLAY', true, (buffer, info, client, server)->
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.is_has_disconnected_player()
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
time_passed = Math.floor((moment() - room.last_active_time) / 1000)
#log.info time_passed
if time_passed >= settings.modules.random_duel.hang_timeout
......@@ -3071,7 +3118,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.is_has_disconnected_player()
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
time_passed = Math.floor((moment() - room.last_active_time) / 1000)
#log.info time_passed
if time_passed >= settings.modules.random_duel.hang_timeout
......
This diff is collapsed.
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