Solve crashing for disconnected players (#566)

* Prevent crashes for disconnected players with disabled mod list panel

* Allow disconnected players (gNetworkType = NT_NONE) to successfully close the game

* Kick the player back to the Main Menu if network init failed
This commit is contained in:
Radek Krzyśków 2024-12-20 04:08:26 +01:00 committed by GitHub
parent f61ff7613c
commit e20d704604
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 10 deletions

View file

@ -64,8 +64,12 @@ static void playerlist_update_row(u8 i, struct NetworkPlayer *np) {
void djui_panel_playerlist_on_render_pre(UNUSED struct DjuiBase* base, UNUSED bool* skipRender) {
if (gDjuiInMainMenu || gNetworkType == NT_NONE) {
djui_base_set_visible(&gDjuiPlayerList->base, false);
djui_base_set_visible(&gDjuiModList->base, false);
if (gDjuiPlayerList != NULL) {
djui_base_set_visible(&gDjuiPlayerList->base, false);
}
if (gDjuiModList != NULL) {
djui_base_set_visible(&gDjuiModList->base, false);
}
return;
}

View file

@ -144,8 +144,9 @@ bool network_init(enum NetworkType inNetworkType, bool reconnecting) {
// initialize the network system
gNetworkSentJoin = false;
int rc = gNetworkSystem->initialize(inNetworkType, reconnecting);
if (!rc) {
if (!rc && inNetworkType != NT_NONE) {
LOG_ERROR("failed to initialize network system");
djui_popup_create(DLANG(NOTIF, DISCONNECT_CLOSED), 2);
return false;
}
if (gNetworkServerAddr != NULL) {
@ -625,6 +626,11 @@ void network_update(void) {
}
}*/
// Kick the player back to the Main Menu if network init failed
if ((gNetworkType == NT_NONE) && !gDjuiInMainMenu) {
network_reset_reconnect_and_rehost();
network_shutdown(true, false, false, false);
}
}
void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnecting) {
@ -638,13 +644,13 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnect
gNetworkSentJoin = false;
network_forget_all_reliable();
if (gNetworkType == NT_NONE) { return; }
if (gNetworkSystem == NULL) { LOG_ERROR("no network system attached"); return; }
if (gNetworkPlayerLocal != NULL && sendLeaving) { network_send_leaving(gNetworkPlayerLocal->globalIndex); }
network_player_shutdown(popup);
gNetworkSystem->shutdown(reconnecting);
if (gNetworkSystem == NULL) {
LOG_ERROR("no network system attached");
} else {
if (gNetworkPlayerLocal != NULL && sendLeaving) { network_send_leaving(gNetworkPlayerLocal->globalIndex); }
network_player_shutdown(popup);
gNetworkSystem->shutdown(reconnecting);
}
if (gNetworkServerAddr != NULL) {
free(gNetworkServerAddr);
gNetworkServerAddr = NULL;