Network upgrade and new reconnection mode (#11527)

Network upgrade and new reconnection mode:
* users can disconnect or close app without game progress loose now;
* disconnect dialog will show active tables stats and additional options;
* all active tables will be restored on reconnect (tables, tourneys, games, drafts, sideboarding, constructing);
* user must use same server and username on next connection;
* there are few minutes for reconnect until server kick off a disconnected player from all player's tables (concede/loose);
* now you can safety reconnect after IP change (after proxy/vpn/wifi/router restart);

Other improvements and fixes:
* gui: main menu - improved switch panel button, added stats about current tables/panels;
* gui: improved data sync and updates (fixes many use cases with empty battlefield, not started games/drafts/tourneys, not updatable drafts, etc);
* gui: improved stability on game updates (fixes some random errors related to wrong threads);
* server: fixed miss messages about player's disconnection problems for other players in the chat;
* refactor: simplified and improved connection and network related code, deleted outdated code, added docs;
* tests: improved load test to support lands only set for more stable performance/network testing (set TEST_AI_RANDOM_DECK_SETS = PELP and run test_TwoAIPlayGame_Multiple);
This commit is contained in:
Oleg Agafonov 2023-12-07 19:56:52 +03:00 committed by GitHub
parent 7f0558ff3c
commit 960e896903
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
71 changed files with 1274 additions and 802 deletions

View file

@ -4,6 +4,7 @@ import com.google.common.collect.Sets;
import mage.client.MageFrame;
import mage.client.util.ClientDefaultSettings;
import java.util.Date;
import java.util.Set;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
@ -18,6 +19,7 @@ public final class MagePreferences {
private static final String KEY_EMAIL = "email";
private static final String KEY_AUTO_CONNECT = "autoConnect";
private static final String NODE_KEY_IGNORE_LIST = "ignoreListString";
private static final String NODE_KEY_RESTORE_SESSIONS_LIST = "restoreSessionsListString";
private static String lastServerAddress = "";
private static int lastServerPort = 0;
@ -64,6 +66,7 @@ public final class MagePreferences {
return userName;
}
// For clients older than 1.4.7, userName is stored without a serverAddress prefix.
// TODO: outdated code, can be removed, 2023-12-05
return prefs().get(KEY_USER_NAME, "");
}
@ -143,6 +146,19 @@ public final class MagePreferences {
return prefs().node(NODE_KEY_IGNORE_LIST).node(serverAddress);
}
private static Preferences restoreSessionsListNode(String serverAddress) {
return prefs().node(NODE_KEY_RESTORE_SESSIONS_LIST).node(serverAddress);
}
public static void saveRestoreSession(String serverAddress, String userName, String sessionId) {
restoreSessionsListNode(serverAddress).put(userName, sessionId);
restoreSessionsListNode(serverAddress).putLong("lastUpdated", new Date().getTime());
}
public static String findRestoreSession(String serverAddress, String userName) {
return restoreSessionsListNode(serverAddress).get(userName, "");
}
public static void saveLastServer() {
lastServerAddress = getServerAddressWithDefault(ClientDefaultSettings.serverName);
lastServerPort = getServerPortWithDefault(ClientDefaultSettings.port);