mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2026-04-26 20:11:42 +00:00
Added Fallback when connecting to invalid Server
This commit is contained in:
parent
a07102ba11
commit
9e43512526
3 changed files with 56 additions and 6 deletions
|
|
@ -24,6 +24,21 @@ void djui_panel_join_message_error(char* message) {
|
|||
}
|
||||
|
||||
void djui_panel_join_message_cancel(struct DjuiBase* caller) {
|
||||
// BungeeCord64: If we're in a BungeeCord switch, cancel immediately and fallback
|
||||
if (network_is_bungee_switching()) {
|
||||
network_bungee_switch_cancel();
|
||||
// If cancel triggered a reconnect to fallback, don't go back to menu
|
||||
if (network_is_reconnecting()) {
|
||||
return;
|
||||
}
|
||||
// No fallback available, disconnect completely
|
||||
network_reset_reconnect_and_rehost();
|
||||
network_shutdown(true, false, false, false);
|
||||
djui_panel_menu_back(caller);
|
||||
return;
|
||||
}
|
||||
|
||||
// Normal cancel (not a BungeeCord switch)
|
||||
if (network_is_reconnecting()) { return; }
|
||||
network_reset_reconnect_and_rehost();
|
||||
network_shutdown(true, false, false, false);
|
||||
|
|
|
|||
|
|
@ -597,9 +597,10 @@ static void network_bungee_execute_pending_switch(void) {
|
|||
static void network_bungee_connection_timeout_update(void) {
|
||||
if (sBungeeConnectionTimer == 0) { return; }
|
||||
|
||||
// If we're connected, cancel the timer
|
||||
if (gNetworkType == NT_CLIENT && gNetworkSentJoin) {
|
||||
LOG_INFO("BungeeCord64: Connection established, canceling timeout");
|
||||
// If we received a response from the server (gNetworkServerAddr is set when we get PACKET_MOD_LIST),
|
||||
// cancel the timeout - the server is reachable, just might take time to transfer mods
|
||||
if (gNetworkType == NT_CLIENT && gNetworkServerAddr != NULL) {
|
||||
LOG_INFO("BungeeCord64: Server responded, canceling connection timeout (mod transfer in progress)");
|
||||
sBungeeConnectionTimer = 0;
|
||||
sBungeeTargetPort = 0;
|
||||
return;
|
||||
|
|
@ -608,13 +609,13 @@ static void network_bungee_connection_timeout_update(void) {
|
|||
// Countdown
|
||||
sBungeeConnectionTimer--;
|
||||
|
||||
// If timer expired and we're still not connected, try fallback
|
||||
// If timer expired and we still haven't received any response, try fallback
|
||||
if (sBungeeConnectionTimer == 0) {
|
||||
u32 fbPort = network_get_bungee_fallback_port();
|
||||
|
||||
// Only try fallback if it's different from what we tried
|
||||
if (fbPort != 0 && fbPort != sBungeeTargetPort) {
|
||||
LOG_INFO("BungeeCord64: Connection to port %u timed out, trying fallback port %u",
|
||||
LOG_INFO("BungeeCord64: No response from port %u, trying fallback port %u",
|
||||
sBungeeTargetPort, fbPort);
|
||||
|
||||
sBungeeTargetPort = 0;
|
||||
|
|
@ -626,7 +627,7 @@ static void network_bungee_connection_timeout_update(void) {
|
|||
// Restart reconnect to fallback
|
||||
network_reconnect_begin();
|
||||
} else {
|
||||
LOG_INFO("BungeeCord64: Connection timed out, no fallback available");
|
||||
LOG_INFO("BungeeCord64: No response from server, no fallback available");
|
||||
sBungeeTargetPort = 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -656,6 +657,39 @@ u32 network_get_bungee_switch_target(void) {
|
|||
return configJoinPort;
|
||||
}
|
||||
|
||||
void network_bungee_switch_cancel(void) {
|
||||
// Cancel a BungeeCord switch and return to the fallback server
|
||||
// This is called when the user manually cancels during connection
|
||||
|
||||
if (!network_is_bungee_switching()) {
|
||||
return;
|
||||
}
|
||||
|
||||
u32 fbPort = network_get_bungee_fallback_port();
|
||||
u32 targetPort = sBungeeTargetPort != 0 ? sBungeeTargetPort : configJoinPort;
|
||||
|
||||
LOG_INFO("BungeeCord64: Switch cancelled - target was %u, fallback is %u", targetPort, fbPort);
|
||||
|
||||
// Reset switch state
|
||||
sBungeeConnectionTimer = 0;
|
||||
sBungeeTargetPort = 0;
|
||||
sBungeePendingSwitchPort = 0;
|
||||
sNetworkReconnectTimer = 0; // Cancel any pending reconnect
|
||||
|
||||
// If we have a valid fallback port that's different from what we were trying to connect to
|
||||
if (fbPort != 0 && fbPort != targetPort) {
|
||||
LOG_INFO("BungeeCord64: Returning to fallback port %u immediately", fbPort);
|
||||
|
||||
// Update config for fallback connection
|
||||
snprintf(configJoinIp, MAX_CONFIG_STRING, "127.0.0.1");
|
||||
configJoinPort = fbPort;
|
||||
|
||||
// Start reconnect immediately (timer = 1 for next frame execution)
|
||||
sNetworkReconnectTimer = 1;
|
||||
sNetworkReconnectType = NS_SOCKET;
|
||||
}
|
||||
}
|
||||
|
||||
void network_rehost_begin(void) {
|
||||
for (int i = 1; i < MAX_PLAYERS; i++) {
|
||||
struct NetworkPlayer* np = &gNetworkPlayers[i];
|
||||
|
|
|
|||
|
|
@ -137,6 +137,7 @@ void network_set_bungee_first_server_port(u32 port);
|
|||
// BungeeCord64 simple server switching (uses standard reconnect)
|
||||
void network_bungee_switch_begin(u32 targetPort);
|
||||
void network_bungee_switch_complete(void);
|
||||
void network_bungee_switch_cancel(void);
|
||||
bool network_is_bungee_switching(void);
|
||||
u8 network_get_bungee_switch_phase(void);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue