Added version checking to clients

This commit is contained in:
MysterD 2020-09-11 16:07:45 -07:00
parent 9db9e6f42d
commit 33d52ef31d
5 changed files with 28 additions and 5 deletions

View File

@ -147,11 +147,11 @@ VERSION_ASFLAGS := --defsym $(VERSION_DEF)=1
# Stuff for showing the git hash in the intro on nightly builds
# From https://stackoverflow.com/questions/44038428/include-git-commit-hash-and-or-branch-name-in-c-c-source
ifeq ($(shell git rev-parse --abbrev-ref HEAD),nightly)
#ifeq ($(shell git rev-parse --abbrev-ref HEAD),nightly)
GIT_HASH=`git rev-parse --short HEAD`
COMPILE_TIME=`date -u +'%Y-%m-%d %H:%M:%S UTC'`
VERSION_CFLAGS += -DNIGHTLY -DGIT_HASH="\"$(GIT_HASH)\"" -DCOMPILE_TIME="\"$(COMPILE_TIME)\""
endif
#endif
# Microcode

View File

@ -41,6 +41,8 @@
* special menu messages and phases, button states and button clicked checks.
*/
static u8 joinVersionMismatch = FALSE;
#ifdef VERSION_US
// The current sound mode is automatically centered on US due to
// the large length difference between options.
@ -437,6 +439,7 @@ void join_server_as_client(void) {
}
keyboard_stop_text_input();
joinVersionMismatch = FALSE;
network_init(NT_CLIENT, configJoinIp, configJoinPort);
}
@ -445,6 +448,11 @@ void joined_server_as_client(s16 fileIndex) {
sSelectedFileNum = fileIndex;
}
void joined_server_version_mismatch(void) {
if (gNetworkType != NT_CLIENT) { return; }
joinVersionMismatch = TRUE;
}
void render_network_mode_menu_buttons(struct Object* soundModeButton) {
#define NETWORK_BUTTON_Y 0
// Host option button
@ -561,7 +569,9 @@ void print_join_mode_menu_strings(void) {
print_generic_ascii_string(JOIN_LEVEL_NAME_X, 191 - (12 * 2), gTextInput);
// Print status
if (gNetworkType == NT_CLIENT) {
if (joinVersionMismatch) {
print_generic_ascii_string(JOIN_LEVEL_NAME_X, 191 - (12 * 14), "Error - versions don't match. Both should rebuild!");
} else if (gNetworkType == NT_CLIENT) {
print_generic_ascii_string(JOIN_LEVEL_NAME_X, 191 - (12 * 14), "Connecting...");
} else if (strlen(gTextInput) > 0) {
print_generic_ascii_string(JOIN_LEVEL_NAME_X, 191 - (12 * 14), "Press (ENTER) to join.");

View File

@ -144,5 +144,6 @@ Gfx *geo_file_select_strings_and_menu_cursor(s32 callContext, UNUSED struct Grap
s32 lvl_init_menu_values_and_cursor_pos(UNUSED s32 arg, UNUSED s32 unused);
s32 lvl_update_obj_and_load_file_selected(UNUSED s32 arg, UNUSED s32 unused);
void joined_server_as_client(s16 fileIndex);
void joined_server_version_mismatch(void);
#endif // FILE_SELECT_H

View File

@ -11,6 +11,7 @@
#include "src/pc/fs/fs.h"
#include "PR/os_eeprom.h"
#define HASH_LENGTH 8
extern u8* gOverrideEeprom;
static u8 eeprom[512] = { 0 };
@ -38,8 +39,11 @@ void network_send_save_file(void) {
fs_close(fp);
}
char hash[HASH_LENGTH] = GIT_HASH;
struct Packet p;
packet_init(&p, PACKET_SAVE_FILE, true);
packet_write(&p, &hash, sizeof(u8) * HASH_LENGTH);
packet_write(&p, &gCurrSaveFileNum, sizeof(s16));
packet_write(&p, &gServerSettings.playerInteractions, sizeof(u8));
packet_write(&p, &gServerSettings.playerKnockbackStrength, sizeof(u8));
@ -52,8 +56,11 @@ void network_receive_save_file(struct Packet* p) {
assert(gNetworkType == NT_CLIENT);
gOverrideEeprom = eeprom;
char hash[HASH_LENGTH] = GIT_HASH;
char remoteHash[HASH_LENGTH] = { 0 };
// find all reserved objects
packet_read(p, &remoteHash, sizeof(u8) * HASH_LENGTH);
packet_read(p, &gCurrSaveFileNum, sizeof(s16));
packet_read(p, &gServerSettings.playerInteractions, sizeof(u8));
packet_read(p, &gServerSettings.playerKnockbackStrength, sizeof(u8));
@ -61,5 +68,10 @@ void network_receive_save_file(struct Packet* p) {
packet_read(p, eeprom, sizeof(u8) * 512);
save_file_load_all(TRUE);
if (memcmp(hash, remoteHash, HASH_LENGTH) != 0) {
joined_server_version_mismatch();
network_shutdown();
return;
}
joined_server_as_client(gCurrSaveFileNum);
}

View File

@ -244,8 +244,8 @@ void main_func(void) {
char window_title[96] =
"Super Mario 64 EX coop (" RAPI_NAME ")"
#ifdef NIGHTLY
" nightly " GIT_HASH
#ifdef GIT_HASH
" [" GIT_HASH "]"
#endif
;