mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-25 13:35:12 +00:00
Made it so changing server settings works in CoopNet
This commit is contained in:
parent
875cde68e1
commit
8e2cd25617
16 changed files with 72 additions and 69 deletions
|
@ -14,7 +14,7 @@
|
||||||
#include "audio/external.h"
|
#include "audio/external.h"
|
||||||
#include "sounds.h"
|
#include "sounds.h"
|
||||||
|
|
||||||
void djui_panel_do_host(void) {
|
void djui_panel_do_host(bool reconnecting) {
|
||||||
stop_demo(NULL);
|
stop_demo(NULL);
|
||||||
djui_panel_shutdown();
|
djui_panel_shutdown();
|
||||||
extern s16 gCurrSaveFileNum;
|
extern s16 gCurrSaveFileNum;
|
||||||
|
@ -30,7 +30,7 @@ void djui_panel_do_host(void) {
|
||||||
if (configNetworkSystem >= NS_MAX) { configNetworkSystem = NS_MAX; }
|
if (configNetworkSystem >= NS_MAX) { configNetworkSystem = NS_MAX; }
|
||||||
network_set_system(configNetworkSystem);
|
network_set_system(configNetworkSystem);
|
||||||
|
|
||||||
network_init(NT_SERVER);
|
network_init(NT_SERVER, reconnecting);
|
||||||
djui_panel_modlist_create(NULL);
|
djui_panel_modlist_create(NULL);
|
||||||
fake_lvl_init_from_save_file();
|
fake_lvl_init_from_save_file();
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ void djui_panel_do_host(void) {
|
||||||
|
|
||||||
void djui_panel_host_message_do_host(UNUSED struct DjuiBase* caller) {
|
void djui_panel_host_message_do_host(UNUSED struct DjuiBase* caller) {
|
||||||
network_reset_reconnect_and_rehost();
|
network_reset_reconnect_and_rehost();
|
||||||
djui_panel_do_host();
|
djui_panel_do_host(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void djui_panel_host_message_create(struct DjuiBase* caller) {
|
void djui_panel_host_message_create(struct DjuiBase* caller) {
|
||||||
|
|
|
@ -147,7 +147,7 @@ void djui_panel_join_direct_do_join(struct DjuiBase* caller) {
|
||||||
network_reset_reconnect_and_rehost();
|
network_reset_reconnect_and_rehost();
|
||||||
djui_panel_join_direct_ip_text_set_new();
|
djui_panel_join_direct_ip_text_set_new();
|
||||||
network_set_system(NS_SOCKET);
|
network_set_system(NS_SOCKET);
|
||||||
network_init(NT_CLIENT);
|
network_init(NT_CLIENT, false);
|
||||||
djui_panel_join_message_create(caller);
|
djui_panel_join_message_create(caller);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ void djui_panel_join_lobby(struct DjuiBase* caller) {
|
||||||
gCoopNetDesiredLobby = (uint64_t)caller->tag;
|
gCoopNetDesiredLobby = (uint64_t)caller->tag;
|
||||||
network_reset_reconnect_and_rehost();
|
network_reset_reconnect_and_rehost();
|
||||||
network_set_system(NS_COOPNET);
|
network_set_system(NS_COOPNET);
|
||||||
network_init(NT_CLIENT);
|
network_init(NT_CLIENT, false);
|
||||||
djui_panel_join_message_create(caller);
|
djui_panel_join_message_create(caller);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ void djui_panel_join_message_error(char* message) {
|
||||||
void djui_panel_join_message_cancel(struct DjuiBase* caller) {
|
void djui_panel_join_message_cancel(struct DjuiBase* caller) {
|
||||||
if (network_is_reconnecting()) { return; }
|
if (network_is_reconnecting()) { return; }
|
||||||
network_reset_reconnect_and_rehost();
|
network_reset_reconnect_and_rehost();
|
||||||
network_shutdown(true, false, false);
|
network_shutdown(true, false, false, false);
|
||||||
djui_panel_menu_back(caller);
|
djui_panel_menu_back(caller);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ static void djui_panel_pause_resume(UNUSED struct DjuiBase* caller) {
|
||||||
|
|
||||||
static void djui_panel_pause_quit_yes(UNUSED struct DjuiBase* caller) {
|
static void djui_panel_pause_quit_yes(UNUSED struct DjuiBase* caller) {
|
||||||
network_reset_reconnect_and_rehost();
|
network_reset_reconnect_and_rehost();
|
||||||
network_shutdown(true, false, false);
|
network_shutdown(true, false, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void djui_panel_pause_quit(struct DjuiBase* caller) {
|
static void djui_panel_pause_quit(struct DjuiBase* caller) {
|
||||||
|
|
|
@ -17,6 +17,7 @@ uint64_t gCoopNetDesiredLobby = 0;
|
||||||
static uint64_t sLocalLobbyId = 0;
|
static uint64_t sLocalLobbyId = 0;
|
||||||
static uint64_t sLocalLobbyOwnerId = 0;
|
static uint64_t sLocalLobbyOwnerId = 0;
|
||||||
static enum NetworkType sNetworkType;
|
static enum NetworkType sNetworkType;
|
||||||
|
static bool sReconecting = false;
|
||||||
|
|
||||||
static CoopNetRc coopnet_initialize(void);
|
static CoopNetRc coopnet_initialize(void);
|
||||||
|
|
||||||
|
@ -74,12 +75,14 @@ static void coopnet_on_lobby_left(uint64_t lobbyId, uint64_t userId) {
|
||||||
LOG_INFO("coopnet_on_lobby_left!");
|
LOG_INFO("coopnet_on_lobby_left!");
|
||||||
coopnet_clear_dest_id(userId);
|
coopnet_clear_dest_id(userId);
|
||||||
if (lobbyId == sLocalLobbyId && userId == coopnet_get_local_user_id()) {
|
if (lobbyId == sLocalLobbyId && userId == coopnet_get_local_user_id()) {
|
||||||
network_shutdown(false, false, true);
|
network_shutdown(false, false, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ns_coopnet_initialize(enum NetworkType networkType) {
|
static bool ns_coopnet_initialize(enum NetworkType networkType, bool reconnecting) {
|
||||||
sNetworkType = networkType;
|
sNetworkType = networkType;
|
||||||
|
sReconecting = reconnecting;
|
||||||
|
if (reconnecting) { return true; }
|
||||||
return coopnet_is_connected()
|
return coopnet_is_connected()
|
||||||
? true
|
? true
|
||||||
: (coopnet_initialize() == COOPNET_OK);
|
: (coopnet_initialize() == COOPNET_OK);
|
||||||
|
@ -111,10 +114,14 @@ void ns_coopnet_update(void) {
|
||||||
coopnet_update();
|
coopnet_update();
|
||||||
if (gNetworkType != NT_NONE && sNetworkType != NT_NONE) {
|
if (gNetworkType != NT_NONE && sNetworkType != NT_NONE) {
|
||||||
if (sNetworkType == NT_SERVER) {
|
if (sNetworkType == NT_SERVER) {
|
||||||
|
if (sReconecting) {
|
||||||
|
|
||||||
|
} else {
|
||||||
LOG_INFO("Create lobby");
|
LOG_INFO("Create lobby");
|
||||||
char mode[64] = "";
|
char mode[64] = "";
|
||||||
mods_get_main_mod_name(mode, 64);
|
mods_get_main_mod_name(mode, 64);
|
||||||
coopnet_lobby_create(CN_GAME_STR, get_version(), configPlayerName, mode, (uint16_t)configAmountofPlayers, configPassword);
|
coopnet_lobby_create(CN_GAME_STR, get_version(), configPlayerName, mode, (uint16_t)configAmountofPlayers, configPassword);
|
||||||
|
}
|
||||||
} else if (sNetworkType == NT_CLIENT) {
|
} else if (sNetworkType == NT_CLIENT) {
|
||||||
LOG_INFO("Join lobby");
|
LOG_INFO("Join lobby");
|
||||||
coopnet_lobby_join(gCoopNetDesiredLobby, "");
|
coopnet_lobby_join(gCoopNetDesiredLobby, "");
|
||||||
|
@ -133,7 +140,8 @@ static int ns_coopnet_network_send(u8 localIndex, void* address, u8* data, u16 d
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ns_coopnet_shutdown(void) {
|
static void ns_coopnet_shutdown(bool reconnecting) {
|
||||||
|
if (reconnecting) { return; }
|
||||||
LOG_INFO("Coopnet shutdown!");
|
LOG_INFO("Coopnet shutdown!");
|
||||||
coopnet_shutdown();
|
coopnet_shutdown();
|
||||||
gCoopNetCallbacks.OnLobbyListGot = NULL;
|
gCoopNetCallbacks.OnLobbyListGot = NULL;
|
||||||
|
|
|
@ -25,7 +25,7 @@ static void on_activity_join_callback(UNUSED void* data, enum EDiscordResult res
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
network_reset_reconnect_and_rehost();
|
network_reset_reconnect_and_rehost();
|
||||||
network_init(NT_CLIENT);
|
network_init(NT_CLIENT, false);
|
||||||
|
|
||||||
gCurActivity.type = DiscordActivityType_Playing;
|
gCurActivity.type = DiscordActivityType_Playing;
|
||||||
if (snprintf(gCurActivity.party.id, 128, DISCORD_ID_FORMAT, lobby->id) < 0) {
|
if (snprintf(gCurActivity.party.id, 128, DISCORD_ID_FORMAT, lobby->id) < 0) {
|
||||||
|
|
|
@ -106,8 +106,8 @@ static void ns_discord_update(void) {
|
||||||
discord_network_flush();
|
discord_network_flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ns_discord_initialize(enum NetworkType networkType) {
|
static bool ns_discord_initialize(enum NetworkType networkType, bool reconnecting) {
|
||||||
if (gDiscordReconnecting) { return true; }
|
if (reconnecting) { return true; }
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
set_instance_env_variable();
|
set_instance_env_variable();
|
||||||
#endif
|
#endif
|
||||||
|
@ -179,8 +179,8 @@ static bool ns_discord_initialize(enum NetworkType networkType) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ns_discord_shutdown(void) {
|
static void ns_discord_shutdown(bool reconnecting) {
|
||||||
if (gDiscordReconnecting) { return; }
|
if (reconnecting) { return; }
|
||||||
if (!gDiscordInitialized) { return; }
|
if (!gDiscordInitialized) { return; }
|
||||||
discord_lobby_leave();
|
discord_lobby_leave();
|
||||||
gActivityLock = false;
|
gActivityLock = false;
|
||||||
|
|
|
@ -58,7 +58,6 @@ u32 gNetworkAreaTimer = 0;
|
||||||
void* gNetworkServerAddr = NULL;
|
void* gNetworkServerAddr = NULL;
|
||||||
bool gNetworkSentJoin = false;
|
bool gNetworkSentJoin = false;
|
||||||
u16 gNetworkRequestLocationTimer = 0;
|
u16 gNetworkRequestLocationTimer = 0;
|
||||||
bool gDiscordReconnecting = false;
|
|
||||||
|
|
||||||
u8 gDebugPacketIdBuffer[256] = { 0xFF };
|
u8 gDebugPacketIdBuffer[256] = { 0xFF };
|
||||||
u8 gDebugPacketSentBuffer[256] = { 0 };
|
u8 gDebugPacketSentBuffer[256] = { 0 };
|
||||||
|
@ -101,7 +100,7 @@ void network_set_system(enum NetworkSystemType nsType) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool network_init(enum NetworkType inNetworkType) {
|
bool network_init(enum NetworkType inNetworkType, bool reconnecting) {
|
||||||
// reset override hide hud
|
// reset override hide hud
|
||||||
extern u8 gOverrideHideHud;
|
extern u8 gOverrideHideHud;
|
||||||
gOverrideHideHud = 0;
|
gOverrideHideHud = 0;
|
||||||
|
@ -132,7 +131,7 @@ bool network_init(enum NetworkType inNetworkType) {
|
||||||
|
|
||||||
// initialize the network system
|
// initialize the network system
|
||||||
gNetworkSentJoin = false;
|
gNetworkSentJoin = false;
|
||||||
int rc = gNetworkSystem->initialize(inNetworkType);
|
int rc = gNetworkSystem->initialize(inNetworkType, reconnecting);
|
||||||
if (!rc) {
|
if (!rc) {
|
||||||
LOG_ERROR("failed to initialize network system");
|
LOG_ERROR("failed to initialize network system");
|
||||||
return false;
|
return false;
|
||||||
|
@ -415,7 +414,6 @@ void network_reset_reconnect_and_rehost(void) {
|
||||||
sNetworkReconnectTimer = 0;
|
sNetworkReconnectTimer = 0;
|
||||||
sNetworkRehostTimer = 0;
|
sNetworkRehostTimer = 0;
|
||||||
sNetworkReconnectType = NS_SOCKET;
|
sNetworkReconnectType = NS_SOCKET;
|
||||||
gDiscordReconnecting = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void network_reconnect_begin(void) {
|
void network_reconnect_begin(void) {
|
||||||
|
@ -425,17 +423,15 @@ void network_reconnect_begin(void) {
|
||||||
|
|
||||||
sNetworkReconnectTimer = 2 * 30;
|
sNetworkReconnectTimer = 2 * 30;
|
||||||
|
|
||||||
#ifdef DISCORD_SDK
|
#ifdef COOPNET
|
||||||
sNetworkReconnectType = (gNetworkSystem == &gNetworkSystemDiscord)
|
sNetworkReconnectType = (gNetworkSystem == &gNetworkSystemCoopNet)
|
||||||
? NS_DISCORD
|
? NS_COOPNET
|
||||||
: NS_SOCKET;
|
: NS_SOCKET;
|
||||||
#else
|
#else
|
||||||
sNetworkReconnectType = NS_SOCKET;
|
sNetworkReconnectType = NS_SOCKET;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gDiscordReconnecting = true;
|
network_shutdown(false, false, false, true);
|
||||||
network_shutdown(false, false, false);
|
|
||||||
gDiscordReconnecting = false;
|
|
||||||
|
|
||||||
djui_connect_menu_open();
|
djui_connect_menu_open();
|
||||||
}
|
}
|
||||||
|
@ -446,11 +442,11 @@ static void network_reconnect_update(void) {
|
||||||
|
|
||||||
if (sNetworkReconnectType == NS_SOCKET) {
|
if (sNetworkReconnectType == NS_SOCKET) {
|
||||||
network_set_system(NS_SOCKET);
|
network_set_system(NS_SOCKET);
|
||||||
|
} else if (sNetworkReconnectType == NS_COOPNET) {
|
||||||
|
network_set_system(NS_COOPNET);
|
||||||
}
|
}
|
||||||
|
|
||||||
gDiscordReconnecting = true;
|
network_init(NT_CLIENT, true);
|
||||||
network_init(NT_CLIENT);
|
|
||||||
gDiscordReconnecting = false;
|
|
||||||
|
|
||||||
network_send_mod_list_request();
|
network_send_mod_list_request();
|
||||||
}
|
}
|
||||||
|
@ -468,21 +464,17 @@ void network_rehost_begin(void) {
|
||||||
network_player_disconnected(i);
|
network_player_disconnected(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
gDiscordReconnecting = true;
|
network_shutdown(false, false, false, true);
|
||||||
network_shutdown(false, false, false);
|
|
||||||
gDiscordReconnecting = false;
|
|
||||||
|
|
||||||
sNetworkRehostTimer = 2;
|
sNetworkRehostTimer = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void network_rehost_update(void) {
|
static void network_rehost_update(void) {
|
||||||
extern void djui_panel_do_host(void);
|
extern void djui_panel_do_host(bool reconnecting);
|
||||||
if (sNetworkRehostTimer <= 0) { return; }
|
if (sNetworkRehostTimer <= 0) { return; }
|
||||||
if (--sNetworkRehostTimer != 0) { return; }
|
if (--sNetworkRehostTimer != 0) { return; }
|
||||||
|
|
||||||
gDiscordReconnecting = true;
|
djui_panel_do_host(true);
|
||||||
djui_panel_do_host();
|
|
||||||
gDiscordReconnecting = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void network_update_area_timer(void) {
|
static void network_update_area_timer(void) {
|
||||||
|
@ -605,7 +597,7 @@ void network_register_mod(char* modName) {
|
||||||
string_linked_list_append(&gRegisteredMods, modName);
|
string_linked_list_append(&gRegisteredMods, modName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void network_shutdown(bool sendLeaving, bool exiting, bool popup) {
|
void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnecting) {
|
||||||
if (gDjuiChatBox != NULL) {
|
if (gDjuiChatBox != NULL) {
|
||||||
djui_base_destroy(&gDjuiChatBox->base);
|
djui_base_destroy(&gDjuiChatBox->base);
|
||||||
gDjuiChatBox = NULL;
|
gDjuiChatBox = NULL;
|
||||||
|
@ -619,7 +611,7 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup) {
|
||||||
|
|
||||||
if (gNetworkPlayerLocal != NULL && sendLeaving) { network_send_leaving(gNetworkPlayerLocal->globalIndex); }
|
if (gNetworkPlayerLocal != NULL && sendLeaving) { network_send_leaving(gNetworkPlayerLocal->globalIndex); }
|
||||||
network_player_shutdown(popup);
|
network_player_shutdown(popup);
|
||||||
gNetworkSystem->shutdown();
|
gNetworkSystem->shutdown(reconnecting);
|
||||||
|
|
||||||
if (gNetworkServerAddr != NULL) {
|
if (gNetworkServerAddr != NULL) {
|
||||||
free(gNetworkServerAddr);
|
free(gNetworkServerAddr);
|
||||||
|
@ -627,7 +619,7 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup) {
|
||||||
}
|
}
|
||||||
gNetworkPlayerServer = NULL;
|
gNetworkPlayerServer = NULL;
|
||||||
|
|
||||||
if (sNetworkReconnectTimer <= 0 || sNetworkReconnectType != NS_DISCORD) {
|
if (sNetworkReconnectTimer <= 0 || sNetworkReconnectType != NS_COOPNET) {
|
||||||
gNetworkType = NT_NONE;
|
gNetworkType = NT_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ enum NetworkSystemType {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NetworkSystem {
|
struct NetworkSystem {
|
||||||
bool (*initialize)(enum NetworkType);
|
bool (*initialize)(enum NetworkType, bool reconnecting);
|
||||||
s64 (*get_id)(u8 localIndex);
|
s64 (*get_id)(u8 localIndex);
|
||||||
char* (*get_id_str)(u8 localIndex);
|
char* (*get_id_str)(u8 localIndex);
|
||||||
void (*save_id)(u8 localIndex, s64 networkId);
|
void (*save_id)(u8 localIndex, s64 networkId);
|
||||||
|
@ -51,7 +51,7 @@ struct NetworkSystem {
|
||||||
bool (*match_addr)(void* addr1, void* addr2);
|
bool (*match_addr)(void* addr1, void* addr2);
|
||||||
void (*update)(void);
|
void (*update)(void);
|
||||||
int (*send)(u8 localIndex, void* addr, u8* data, u16 dataLength);
|
int (*send)(u8 localIndex, void* addr, u8* data, u16 dataLength);
|
||||||
void (*shutdown)(void);
|
void (*shutdown)(bool reconnecting);
|
||||||
bool requireServerBroadcast;
|
bool requireServerBroadcast;
|
||||||
char* name;
|
char* name;
|
||||||
};
|
};
|
||||||
|
@ -91,11 +91,10 @@ extern u8 gDebugPacketIdBuffer[];
|
||||||
extern u8 gDebugPacketSentBuffer[];
|
extern u8 gDebugPacketSentBuffer[];
|
||||||
extern u8 gDebugPacketOnBuffer;
|
extern u8 gDebugPacketOnBuffer;
|
||||||
extern u32 gNetworkStartupTimer;
|
extern u32 gNetworkStartupTimer;
|
||||||
extern bool gDiscordReconnecting;
|
|
||||||
|
|
||||||
// network.c
|
// network.c
|
||||||
void network_set_system(enum NetworkSystemType nsType);
|
void network_set_system(enum NetworkSystemType nsType);
|
||||||
bool network_init(enum NetworkType inNetworkType);
|
bool network_init(enum NetworkType inNetworkType, bool reconnecting);
|
||||||
void network_on_init_area(void);
|
void network_on_init_area(void);
|
||||||
void network_on_loaded_area(void);
|
void network_on_loaded_area(void);
|
||||||
bool network_allow_unknown_local_index(enum PacketType packetType);
|
bool network_allow_unknown_local_index(enum PacketType packetType);
|
||||||
|
@ -109,6 +108,6 @@ bool network_is_reconnecting(void);
|
||||||
void network_rehost_begin(void);
|
void network_rehost_begin(void);
|
||||||
void network_update(void);
|
void network_update(void);
|
||||||
void network_register_mod(char* modName);
|
void network_register_mod(char* modName);
|
||||||
void network_shutdown(bool sendLeaving, bool exiting, bool popup);
|
void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnecting);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -196,7 +196,7 @@ void network_player_update(void) {
|
||||||
#ifndef DEVELOPMENT
|
#ifndef DEVELOPMENT
|
||||||
if (elapsed > NETWORK_PLAYER_TIMEOUT * 1.5f) {
|
if (elapsed > NETWORK_PLAYER_TIMEOUT * 1.5f) {
|
||||||
LOG_INFO("dropping due to no server connectivity");
|
LOG_INFO("dropping due to no server connectivity");
|
||||||
network_shutdown(false, false, true);
|
network_shutdown(false, false, true, false);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -321,7 +321,7 @@ u8 network_player_disconnected(u8 globalIndex) {
|
||||||
LOG_ERROR("player disconnected, but it's local.. this shouldn't happen!");
|
LOG_ERROR("player disconnected, but it's local.. this shouldn't happen!");
|
||||||
return UNKNOWN_GLOBAL_INDEX;
|
return UNKNOWN_GLOBAL_INDEX;
|
||||||
} else {
|
} else {
|
||||||
network_shutdown(true, false, true);
|
network_shutdown(true, false, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,7 @@ void network_receive_join(struct Packet* p) {
|
||||||
packet_read(p, &remoteVersion, sizeof(u8) * MAX_VERSION_LENGTH);
|
packet_read(p, &remoteVersion, sizeof(u8) * MAX_VERSION_LENGTH);
|
||||||
LOG_INFO("server has version: %s", version);
|
LOG_INFO("server has version: %s", version);
|
||||||
if (memcmp(version, remoteVersion, MAX_VERSION_LENGTH) != 0) {
|
if (memcmp(version, remoteVersion, MAX_VERSION_LENGTH) != 0) {
|
||||||
network_shutdown(true, false, false);
|
network_shutdown(true, false, false, false);
|
||||||
LOG_ERROR("version mismatch");
|
LOG_ERROR("version mismatch");
|
||||||
char mismatchMessage[256] = { 0 };
|
char mismatchMessage[256] = { 0 };
|
||||||
snprintf(mismatchMessage, 256, "\\#ffa0a0\\Error:\\#c8c8c8\\ Version mismatch.\n\nYour version: \\#a0a0ff\\%s\\#c8c8c8\\\nTheir version: \\#a0a0ff\\%s\\#c8c8c8\\\n\nSomeone is out of date!\n", version, remoteVersion);
|
snprintf(mismatchMessage, 256, "\\#ffa0a0\\Error:\\#c8c8c8\\ Version mismatch.\n\nYour version: \\#a0a0ff\\%s\\#c8c8c8\\\nTheir version: \\#a0a0ff\\%s\\#c8c8c8\\\n\nSomeone is out of date!\n", version, remoteVersion);
|
||||||
|
@ -196,7 +196,7 @@ void network_receive_join(struct Packet* p) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string_linked_list_mismatch(&gRegisteredMods, &head)) {
|
if (string_linked_list_mismatch(&gRegisteredMods, &head)) {
|
||||||
network_shutdown(true, false, false);
|
network_shutdown(true, false, false, false);
|
||||||
|
|
||||||
struct StringBuilder* builder = string_builder_create(512);
|
struct StringBuilder* builder = string_builder_create(512);
|
||||||
string_builder_append(builder, "\\#ffa0a0\\Error:\\#c8c8c8\\ mods don't match.\n\n");
|
string_builder_append(builder, "\\#ffa0a0\\Error:\\#c8c8c8\\ mods don't match.\n\n");
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
#include "pc/djui/djui.h"
|
#include "pc/djui/djui.h"
|
||||||
#include "pc/utils/misc.h"
|
#include "pc/utils/misc.h"
|
||||||
|
|
||||||
f32 lastReconnectTime = -9999999;
|
f32 sLastReconnectTime = -9999999;
|
||||||
|
f32 sLastNotifyTime = -9999999;
|
||||||
|
|
||||||
void network_send_kick(u8 localIndex, enum KickReasonType kickReason) {
|
void network_send_kick(u8 localIndex, enum KickReasonType kickReason) {
|
||||||
u8 kickReasonType = kickReason;
|
u8 kickReasonType = kickReason;
|
||||||
|
@ -30,21 +31,24 @@ void network_receive_kick(struct Packet* p) {
|
||||||
packet_read(p, &kickReasonType, sizeof(u8));
|
packet_read(p, &kickReasonType, sizeof(u8));
|
||||||
enum KickReasonType kickReason = kickReasonType;
|
enum KickReasonType kickReason = kickReasonType;
|
||||||
|
|
||||||
|
f32 now = clock_elapsed();
|
||||||
|
if ((now - sLastNotifyTime) > 3) {
|
||||||
|
sLastNotifyTime = now;
|
||||||
switch (kickReason) {
|
switch (kickReason) {
|
||||||
case EKT_FULL_PARTY: djui_popup_create(DLANG(NOTIF, DISCONNECT_FULL), 1); break;
|
case EKT_FULL_PARTY: djui_popup_create(DLANG(NOTIF, DISCONNECT_FULL), 1); break;
|
||||||
case EKT_KICKED: djui_popup_create(DLANG(NOTIF, DISCONNECT_KICK), 1); break;
|
case EKT_KICKED: djui_popup_create(DLANG(NOTIF, DISCONNECT_KICK), 1); break;
|
||||||
case EKT_BANNED: djui_popup_create(DLANG(NOTIF, DISCONNECT_BAN), 1); break;
|
case EKT_BANNED: djui_popup_create(DLANG(NOTIF, DISCONNECT_BAN), 1); break;
|
||||||
default: djui_popup_create(DLANG(NOTIF, DISCONNECT_CLOSED), 1); break;
|
default: djui_popup_create(DLANG(NOTIF, DISCONNECT_CLOSED), 1); break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (kickReason == EKT_REJOIN) {
|
if (kickReason == EKT_REJOIN) {
|
||||||
f32 now = clock_elapsed();
|
if ((now - sLastReconnectTime) > 3) {
|
||||||
if ((now - lastReconnectTime) > 3) {
|
sLastReconnectTime = now;
|
||||||
lastReconnectTime = now;
|
|
||||||
network_reconnect_begin();
|
network_reconnect_begin();
|
||||||
djui_popup_create(DLANG(NOTIF, DISCONNECT_REJOIN), 1);
|
djui_popup_create(DLANG(NOTIF, DISCONNECT_REJOIN), 1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
network_shutdown(false, false, false);
|
network_shutdown(false, false, false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@ void network_receive_mod_list(struct Packet* p) {
|
||||||
packet_read(p, &remoteVersion, sizeof(u8) * MAX_VERSION_LENGTH);
|
packet_read(p, &remoteVersion, sizeof(u8) * MAX_VERSION_LENGTH);
|
||||||
LOG_INFO("server has version: %s", version);
|
LOG_INFO("server has version: %s", version);
|
||||||
if (memcmp(version, remoteVersion, MAX_VERSION_LENGTH) != 0) {
|
if (memcmp(version, remoteVersion, MAX_VERSION_LENGTH) != 0) {
|
||||||
network_shutdown(true, false, false);
|
network_shutdown(true, false, false, false);
|
||||||
LOG_ERROR("version mismatch");
|
LOG_ERROR("version mismatch");
|
||||||
char mismatchMessage[256] = { 0 };
|
char mismatchMessage[256] = { 0 };
|
||||||
snprintf(mismatchMessage, 256, "\\#ffa0a0\\Error:\\#c8c8c8\\ Version mismatch.\n\nYour version: \\#a0a0ff\\%s\\#c8c8c8\\\nTheir version: \\#a0a0ff\\%s\\#c8c8c8\\\n\nSomeone is out of date!\n", version, remoteVersion);
|
snprintf(mismatchMessage, 256, "\\#ffa0a0\\Error:\\#c8c8c8\\ Version mismatch.\n\nYour version: \\#a0a0ff\\%s\\#c8c8c8\\\nTheir version: \\#a0a0ff\\%s\\#c8c8c8\\\n\nSomeone is out of date!\n", version, remoteVersion);
|
||||||
|
@ -241,7 +241,7 @@ void network_receive_mod_list_entry(struct Packet* p) {
|
||||||
// sanity check mod size
|
// sanity check mod size
|
||||||
if (mod->size >= MAX_MOD_SIZE) {
|
if (mod->size >= MAX_MOD_SIZE) {
|
||||||
djui_popup_create(DLANG(NOTIF, DISCONNECT_BIG_MOD), 4);
|
djui_popup_create(DLANG(NOTIF, DISCONNECT_BIG_MOD), 4);
|
||||||
network_shutdown(false, false, false);
|
network_shutdown(false, false, false, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ static int socket_receive(SOCKET socket, struct sockaddr_in* rxAddr, u8* buffer,
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ns_socket_initialize(enum NetworkType networkType) {
|
static bool ns_socket_initialize(enum NetworkType networkType, UNUSED bool reconnecting) {
|
||||||
|
|
||||||
// sanity check port
|
// sanity check port
|
||||||
unsigned int port = (networkType == NT_CLIENT) ? configJoinPort : configHostPort;
|
unsigned int port = (networkType == NT_CLIENT) ? configJoinPort : configHostPort;
|
||||||
|
@ -180,7 +180,7 @@ static int ns_socket_send(u8 localIndex, void* address, u8* data, u16 dataLength
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ns_socket_shutdown(void) {
|
static void ns_socket_shutdown(UNUSED bool reconnecting) {
|
||||||
socket_shutdown(sCurSocket);
|
socket_shutdown(sCurSocket);
|
||||||
sCurSocket = INVALID_SOCKET;
|
sCurSocket = INVALID_SOCKET;
|
||||||
for (u16 i = 0; i < MAX_PLAYERS; i++) {
|
for (u16 i = 0; i < MAX_PLAYERS; i++) {
|
||||||
|
|
|
@ -254,7 +254,7 @@ void game_deinit(void) {
|
||||||
audio_custom_shutdown();
|
audio_custom_shutdown();
|
||||||
audio_shutdown();
|
audio_shutdown();
|
||||||
gfx_shutdown();
|
gfx_shutdown();
|
||||||
network_shutdown(true, true, false);
|
network_shutdown(true, true, false, false);
|
||||||
smlua_shutdown();
|
smlua_shutdown();
|
||||||
mods_shutdown();
|
mods_shutdown();
|
||||||
inited = false;
|
inited = false;
|
||||||
|
@ -367,15 +367,15 @@ void main_func(void) {
|
||||||
snprintf(gGetHostName, MAX_CONFIG_STRING, "%s", gCLIOpts.JoinIp);
|
snprintf(gGetHostName, MAX_CONFIG_STRING, "%s", gCLIOpts.JoinIp);
|
||||||
snprintf(configJoinIp, MAX_CONFIG_STRING, "%s", gCLIOpts.JoinIp);
|
snprintf(configJoinIp, MAX_CONFIG_STRING, "%s", gCLIOpts.JoinIp);
|
||||||
configJoinPort = gCLIOpts.NetworkPort;
|
configJoinPort = gCLIOpts.NetworkPort;
|
||||||
network_init(NT_CLIENT);
|
network_init(NT_CLIENT, false);
|
||||||
} else if (gCLIOpts.Network == NT_SERVER) {
|
} else if (gCLIOpts.Network == NT_SERVER) {
|
||||||
network_set_system(NS_SOCKET);
|
network_set_system(NS_SOCKET);
|
||||||
configHostPort = gCLIOpts.NetworkPort;
|
configHostPort = gCLIOpts.NetworkPort;
|
||||||
network_init(NT_SERVER);
|
network_init(NT_SERVER, false);
|
||||||
djui_panel_shutdown();
|
djui_panel_shutdown();
|
||||||
djui_panel_modlist_create(NULL);
|
djui_panel_modlist_create(NULL);
|
||||||
} else {
|
} else {
|
||||||
network_init(NT_NONE);
|
network_init(NT_NONE, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
audio_init();
|
audio_init();
|
||||||
|
|
Loading…
Reference in a new issue