Commit 848d8ffc authored by nanahira's avatar nanahira

add mid kick reconnect

parent 43f53052
......@@ -47,6 +47,7 @@ import_datas = [
"is_post_watcher",
"retry_count",
"name",
"pass",
"is_first",
"lp",
"card_count",
......@@ -567,14 +568,14 @@ CLIENT_is_able_to_reconnect = (client, deckbuf) ->
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 (!check_deck or player.start_deckbuf == deckbuf)
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) ->
CLIENT_is_able_to_kick_reconnect = (client, deckbuf) ->
unless settings.modules.reconnect.enabled and settings.modules.reconnect.allow_kick_reconnect
return false
for room in ROOM_all[disconnect_info.room_id]
if !room
CLIENT_reconnect_unregister(client)
if !CLIENT_get_kick_reconnect_target(client, deckbuf)
return false
return true
......@@ -619,14 +620,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) ->
......@@ -655,6 +660,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}
......@@ -1336,7 +1370,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
......@@ -2487,8 +2522,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 CLIENT_is_able_to_reconnect(client, 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', {
......
// Generated by CoffeeScript 1.12.7
(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');
......@@ -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');
......@@ -721,7 +721,7 @@
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;
if (!settings.modules.reconnect.enabled) {
return false;
......@@ -738,6 +738,36 @@
CLIENT_reconnect_unregister(client);
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;
};
......@@ -791,16 +821,20 @@
};
CLIENT_pre_reconnect = function(client) {
var dinfo;
if (!CLIENT_is_able_to_reconnect(client)) {
return;
var dinfo, player;
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);
}
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) {
......@@ -831,6 +865,37 @@
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) {
disconnect_list = {};
}
......@@ -1666,7 +1731,8 @@
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;
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);
return;
} else if (settings.modules.stop) {
......@@ -3088,8 +3154,13 @@
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;
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);
} 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', {
......
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