Commit 1c7b1d0d authored by nanahira's avatar nanahira

Merge branch 'kick_reconnect' into mc

parents 72179db2 848d8ffc
...@@ -89,6 +89,7 @@ ...@@ -89,6 +89,7 @@
"reconnect": { "reconnect": {
"enabled": true, "enabled": true,
"auto_surrender_after_disconnect": false, "auto_surrender_after_disconnect": false,
"allow_kick_reconnect": true,
"wait_time": 60000 "wait_time": 60000
}, },
"heartbeat_detection": { "heartbeat_detection": {
......
...@@ -138,6 +138,7 @@ ...@@ -138,6 +138,7 @@
"deck_incorrect_reconnect": "Please pick your previous deck.", "deck_incorrect_reconnect": "Please pick your previous deck.",
"reconnect_failed": "Reconnect failed.", "reconnect_failed": "Reconnect failed.",
"reconnecting_to_room": "Reconnecting to server...", "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_user_not_found": "You are not a participant of the tournament.",
"challonge_match_load_failed": "Failed loading tournament info.", "challonge_match_load_failed": "Failed loading tournament info.",
"challonge_match_not_found": "Your current match was not found.", "challonge_match_not_found": "Your current match was not found.",
...@@ -422,6 +423,7 @@ ...@@ -422,6 +423,7 @@
"deck_incorrect_reconnect": "请选择你在本局决斗中使用的卡组。", "deck_incorrect_reconnect": "请选择你在本局决斗中使用的卡组。",
"reconnect_failed": "重新连接失败。", "reconnect_failed": "重新连接失败。",
"reconnecting_to_room": "正在重新连接到服务器……", "reconnecting_to_room": "正在重新连接到服务器……",
"reconnect_kicked": "你的账号已经在其他设备登录,你被迫下线。",
"challonge_user_not_found": "未找到你的参赛信息。", "challonge_user_not_found": "未找到你的参赛信息。",
"challonge_match_load_failed": "读取比赛信息失败。", "challonge_match_load_failed": "读取比赛信息失败。",
"challonge_match_not_found": "你没有当前轮次的比赛。", "challonge_match_not_found": "你没有当前轮次的比赛。",
......
...@@ -47,6 +47,7 @@ import_datas = [ ...@@ -47,6 +47,7 @@ import_datas = [
"is_post_watcher", "is_post_watcher",
"retry_count", "retry_count",
"name", "name",
"pass",
"is_first", "is_first",
"lp", "lp",
"card_count", "card_count",
...@@ -549,7 +550,7 @@ CLIENT_is_player = (client, room) -> ...@@ -549,7 +550,7 @@ CLIENT_is_player = (client, room) ->
break break
return is_player and client.pos <= 3 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 unless settings.modules.reconnect.enabled
return false return false
if client.system_kicked if client.system_kicked
...@@ -561,13 +562,21 @@ CLIENT_is_able_to_reconnect = (client) -> ...@@ -561,13 +562,21 @@ CLIENT_is_able_to_reconnect = (client) ->
if !room if !room
CLIENT_reconnect_unregister(client) CLIENT_reconnect_unregister(client)
return false return false
# if disconnect_info.old_server.closed if deckbuf and !_.isEqual(deckbuf, disconnect_info.deckbuf)
# return false return false
# current_room = disconnect_info.room return true
# unless current_room and current_room.started
# return false CLIENT_get_kick_reconnect_target = (client, deckbuf) ->
# if client.is_post_watcher or !CLIENT_is_player(client, current_room) or (room.windbot and client.is_local) for room in ROOM_all when room.started and !room.windbot
# return false 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 return true
CLIENT_send_pre_reconnect_info = (client, room, old_client) -> CLIENT_send_pre_reconnect_info = (client, room, old_client) ->
...@@ -611,14 +620,18 @@ CLIENT_send_reconnect_info = (client, server, room) -> ...@@ -611,14 +620,18 @@ CLIENT_send_reconnect_info = (client, server, room) ->
return return
CLIENT_pre_reconnect = (client) -> CLIENT_pre_reconnect = (client) ->
if !CLIENT_is_able_to_reconnect(client) if CLIENT_is_able_to_reconnect(client)
return dinfo = disconnect_list[CLIENT_get_authorize_key(client)]
dinfo = disconnect_list[CLIENT_get_authorize_key(client)] client.pre_reconnecting = true
client.pre_deckbuf = dinfo.deckbuf client.pos = dinfo.old_client.pos
client.pre_reconnecting = true client.setTimeout(300000)
client.pos = dinfo.old_client.pos CLIENT_send_pre_reconnect_info(client, ROOM_all[dinfo.room_id], dinfo.old_client)
client.setTimeout(300000) else if CLIENT_is_able_to_kick_reconnect(client)
CLIENT_send_pre_reconnect_info(client, ROOM_all[dinfo.room_id], dinfo.old_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 return
CLIENT_reconnect = (client) -> CLIENT_reconnect = (client) ->
...@@ -647,6 +660,35 @@ CLIENT_reconnect = (client) -> ...@@ -647,6 +660,35 @@ CLIENT_reconnect = (client) ->
CLIENT_reconnect_unregister(client, true) CLIENT_reconnect_unregister(client, true)
return 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 if settings.modules.reconnect.enabled
disconnect_list = {} # {old_client, old_server, room_id, timeout, deckbuf} disconnect_list = {} # {old_client, old_server, room_id, timeout, deckbuf}
...@@ -1328,7 +1370,8 @@ ygopro.ctos_follow 'PLAYER_INFO', true, (buffer, info, client, server)-> ...@@ -1328,7 +1370,8 @@ ygopro.ctos_follow 'PLAYER_INFO', true, (buffer, info, client, server)->
ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
#log.info info #log.info info
info.pass=info.pass.trim() 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) CLIENT_pre_reconnect(client)
return return
else if settings.modules.stop else if settings.modules.stop
...@@ -2479,8 +2522,13 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server)-> ...@@ -2479,8 +2522,13 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server)->
ygopro.ctos_follow 'UPDATE_DECK', 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 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) CLIENT_reconnect(client)
else if CLIENT_is_able_to_kick_reconnect(client, buffer)
CLIENT_kick_reconnect(client, buffer)
else else
ygopro.stoc_send_chat(client, "${deck_incorrect_reconnect}", ygopro.constants.COLORS.RED) ygopro.stoc_send_chat(client, "${deck_incorrect_reconnect}", ygopro.constants.COLORS.RED)
ygopro.stoc_send(client, 'ERROR_MSG', { ygopro.stoc_send(client, 'ERROR_MSG', {
......
// Generated by CoffeeScript 1.12.7 // Generated by CoffeeScript 1.12.7
(function() { (function() {
var CLIENT_get_authorize_key, CLIENT_heartbeat_register, CLIENT_heartbeat_unregister, CLIENT_import_data, CLIENT_is_able_to_reconnect, CLIENT_is_player, CLIENT_kick, CLIENT_pre_reconnect, CLIENT_reconnect, CLIENT_reconnect_register, CLIENT_reconnect_unregister, CLIENT_send_pre_reconnect_info, CLIENT_send_reconnect_info, Cloud_replay_ids, ROOM_all, ROOM_bad_ip, ROOM_ban_player, ROOM_clear_disconnect, ROOM_connected_ip, ROOM_find_by_name, 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_players_banned, ROOM_players_oppentlist, ROOM_unwelcome, ROOM_validate, Room, SERVER_clear_disconnect, _, addCallback, badwords, ban_user, bunyan, challonge, chat_color, config, cppversion, crypto, date, default_config, default_data, dialogues, disconnect_list, duel_log, e, exec, execFile, fs, geoip, get_memory_usage, http, http_server, https, https_server, import_datas, j, l, len, len1, lflists, list, loadJSON, load_dialogues, load_tips, log, long_resolve_cards, memory_usage, merge, moment, net, oldbadwords, oldconfig, olddialogues, oldduellog, oldtips, options, os, path, pgClient, pg_client, pg_query, redis, redisdb, ref, ref1, release_disconnect, report_to_big_brother, request, requestListener, roomlist, setting_change, setting_save, settings, spawn, spawnSync, tips, url, users_cache, wait_room_start, wait_room_start_arena, windbot_bin, windbot_parameters, windbot_process, windbots, ygopro, zlib; var CLIENT_get_authorize_key, CLIENT_get_kick_reconnect_target, CLIENT_heartbeat_register, CLIENT_heartbeat_unregister, CLIENT_import_data, CLIENT_is_able_to_kick_reconnect, CLIENT_is_able_to_reconnect, 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, Cloud_replay_ids, ROOM_all, ROOM_bad_ip, ROOM_ban_player, ROOM_clear_disconnect, ROOM_connected_ip, ROOM_find_by_name, 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_players_banned, ROOM_players_oppentlist, ROOM_unwelcome, ROOM_validate, Room, SERVER_clear_disconnect, _, addCallback, badwords, ban_user, bunyan, challonge, chat_color, config, cppversion, crypto, date, default_config, default_data, dialogues, disconnect_list, duel_log, e, exec, execFile, fs, geoip, get_memory_usage, http, http_server, https, https_server, import_datas, j, l, len, len1, lflists, list, loadJSON, load_dialogues, load_tips, log, long_resolve_cards, memory_usage, merge, moment, net, oldbadwords, oldconfig, olddialogues, oldduellog, oldtips, options, os, path, pgClient, pg_client, pg_query, redis, redisdb, ref, ref1, release_disconnect, report_to_big_brother, request, requestListener, roomlist, setting_change, setting_save, settings, spawn, spawnSync, tips, url, users_cache, wait_room_start, wait_room_start_arena, windbot_bin, windbot_parameters, windbot_process, windbots, ygopro, zlib;
net = require('net'); net = require('net');
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
} }
}); });
import_datas = ["abuse_count", "rag", "rid", "is_post_watcher", "retry_count", "name", "is_first", "lp", "card_count", "is_host", "pos", "surrend_confirm", "kick_count", "deck_saved", "main", "side", "side_interval", "side_tcount", "selected_preduel", "last_game_msg", "last_game_msg_title", "last_hint_msg", "start_deckbuf", "challonge_info", "ready_trap"]; import_datas = ["abuse_count", "rag", "rid", "is_post_watcher", "retry_count", "name", "pass", "is_first", "lp", "card_count", "is_host", "pos", "surrend_confirm", "kick_count", "deck_saved", "main", "side", "side_interval", "side_tcount", "selected_preduel", "last_game_msg", "last_game_msg_title", "last_hint_msg", "start_deckbuf", "challonge_info", "ready_trap"];
merge = require('deepmerge'); merge = require('deepmerge');
...@@ -721,7 +721,7 @@ ...@@ -721,7 +721,7 @@
return is_player && client.pos <= 3; return is_player && client.pos <= 3;
}; };
CLIENT_is_able_to_reconnect = function(client) { CLIENT_is_able_to_reconnect = function(client, deckbuf) {
var disconnect_info, room; var disconnect_info, room;
if (!settings.modules.reconnect.enabled) { if (!settings.modules.reconnect.enabled) {
return false; return false;
...@@ -738,6 +738,36 @@ ...@@ -738,6 +738,36 @@
CLIENT_reconnect_unregister(client); CLIENT_reconnect_unregister(client);
return false; return false;
} }
if (deckbuf && !_.isEqual(deckbuf, disconnect_info.deckbuf)) {
return false;
}
return true;
};
CLIENT_get_kick_reconnect_target = function(client, deckbuf) {
var len2, len3, m, n, player, ref2, room;
for (m = 0, len2 = ROOM_all.length; m < len2; m++) {
room = ROOM_all[m];
if (room.started && !room.windbot) {
ref2 = room.get_playing_player();
for (n = 0, len3 = ref2.length; n < len3; n++) {
player = ref2[n];
if (!player.closed && player.name === client.name && player.pass === client.pass && (settings.modules.mycard.enabled || player.ip === client.ip) && (!deckbuf || _.isEqual(player.start_deckbuf, deckbuf))) {
return player;
}
}
}
}
return null;
};
CLIENT_is_able_to_kick_reconnect = function(client, deckbuf) {
if (!(settings.modules.reconnect.enabled && settings.modules.reconnect.allow_kick_reconnect)) {
return false;
}
if (!CLIENT_get_kick_reconnect_target(client, deckbuf)) {
return false;
}
return true; return true;
}; };
...@@ -791,16 +821,20 @@ ...@@ -791,16 +821,20 @@
}; };
CLIENT_pre_reconnect = function(client) { CLIENT_pre_reconnect = function(client) {
var dinfo; var dinfo, player;
if (!CLIENT_is_able_to_reconnect(client)) { if (CLIENT_is_able_to_reconnect(client)) {
return; 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);
} }
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);
}; };
CLIENT_reconnect = function(client) { CLIENT_reconnect = function(client) {
...@@ -831,6 +865,37 @@ ...@@ -831,6 +865,37 @@
CLIENT_reconnect_unregister(client, true); CLIENT_reconnect_unregister(client, true);
}; };
CLIENT_kick_reconnect = function(client, deckbuf) {
var current_old_server, player, room;
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 || room.arena) {
room.last_active_time = moment();
}
CLIENT_import_data(client, player, room);
CLIENT_send_reconnect_info(client, client.server, room);
ygopro.stoc_send_chat_to_room(room, client.name + " ${reconnect_to_game}");
CLIENT_reconnect_unregister(client, true);
};
if (settings.modules.reconnect.enabled) { if (settings.modules.reconnect.enabled) {
disconnect_list = {}; disconnect_list = {};
} }
...@@ -1666,7 +1731,8 @@ ...@@ -1666,7 +1731,8 @@
ygopro.ctos_follow('JOIN_GAME', false, function(buffer, info, client, server) { ygopro.ctos_follow('JOIN_GAME', false, function(buffer, info, client, server) {
var check, decrypted_buffer, finish, i, id, len2, len3, len4, m, n, name, o, pre_room, ref2, ref3, ref4, replay_id, room, secret; var check, decrypted_buffer, finish, i, id, len2, len3, len4, m, n, name, o, pre_room, ref2, ref3, ref4, replay_id, room, secret;
info.pass = info.pass.trim(); info.pass = info.pass.trim();
if (CLIENT_is_able_to_reconnect(client)) { client.pass = info.pass;
if (CLIENT_is_able_to_reconnect(client) || CLIENT_is_able_to_kick_reconnect(client)) {
CLIENT_pre_reconnect(client); CLIENT_pre_reconnect(client);
return; return;
} else if (settings.modules.stop) { } else if (settings.modules.stop) {
...@@ -3088,8 +3154,13 @@ ...@@ -3088,8 +3154,13 @@
ygopro.ctos_follow('UPDATE_DECK', true, function(buffer, info, client, server) { ygopro.ctos_follow('UPDATE_DECK', true, function(buffer, info, client, server) {
var buff_main, buff_side, card, current_deck, deck, deck_array, deck_main, deck_side, deck_text, deckbuf, decks, found_deck, i, len2, len3, line, m, n, oppo_pos, room, struct, win_pos; var buff_main, buff_side, card, current_deck, deck, deck_array, deck_main, deck_side, deck_text, deckbuf, decks, found_deck, i, len2, len3, line, m, n, oppo_pos, room, struct, win_pos;
if (settings.modules.reconnect.enabled && client.pre_reconnecting) { if (settings.modules.reconnect.enabled && client.pre_reconnecting) {
if (_.isEqual(buffer, client.pre_deckbuf)) { if (!CLIENT_is_able_to_reconnect(client) && !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); CLIENT_reconnect(client);
} else if (CLIENT_is_able_to_kick_reconnect(client, buffer)) {
CLIENT_kick_reconnect(client, buffer);
} else { } else {
ygopro.stoc_send_chat(client, "${deck_incorrect_reconnect}", ygopro.constants.COLORS.RED); ygopro.stoc_send_chat(client, "${deck_incorrect_reconnect}", ygopro.constants.COLORS.RED);
ygopro.stoc_send(client, 'ERROR_MSG', { ygopro.stoc_send(client, 'ERROR_MSG', {
......
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