Make lobby hosting detect the largest mod by lua size

This commit is contained in:
MysterD 2023-04-14 11:59:35 -07:00
parent b1aace4f04
commit 6a577d691f
5 changed files with 36 additions and 1 deletions

View file

@ -7,6 +7,19 @@
#include "pc/utils/md5.h"
#include "pc/debuglog.h"
size_t mod_get_lua_size(struct Mod* mod) {
if (!mod) { return 0; }
size_t size = 0;
for (int i = 0; i < mod->fileCount; i++) {
struct ModFile* file = &mod->files[i];
if (!str_ends_with(file->relativePath, ".lua")) { continue; }
size += file->size;
}
return size;
}
static void mod_activate_bin(struct ModFile* file) {
// copy geo name
char geoName[64] = { 0 };

View file

@ -32,6 +32,7 @@ struct Mod {
size_t size;
};
size_t mod_get_lua_size(struct Mod* mod);
void mod_activate(struct Mod* mod);
void mod_clear(struct Mod* mod);
bool mod_load(struct Mods* mods, char* basePath, char* modName);

View file

@ -20,6 +20,23 @@ struct LocalEnabledPath {
struct LocalEnabledPath* sLocalEnabledPaths = NULL;
void mods_get_main_mod_name(char* destination, u32 maxSize) {
struct Mod* picked = NULL;
size_t pickedSize = 0;
for (unsigned int i = 0; i < gLocalMods.entryCount; i++) {
struct Mod* mod = gLocalMods.entries[i];
if (!mod->enabled) { continue; }
size_t size = mod_get_lua_size(mod);
if (size > pickedSize) {
picked = mod;
pickedSize = size;
}
}
snprintf(destination, maxSize, "%s", picked ? picked->name : "Super Mario 64");
}
static void mods_local_store_enabled(void) {
assert(sLocalEnabledPaths == NULL);
struct LocalEnabledPath* prev = NULL;

View file

@ -22,6 +22,7 @@ extern struct Mods gActiveMods;
extern char gRemoteModsBasePath[];
void mods_get_main_mod_name(char* destination, u32 maxSize);
bool mods_generate_remote_base_path(void);
void mods_activate(struct Mods* mods);
void mods_clear(struct Mods* mods);

View file

@ -5,6 +5,7 @@
#include "pc/network/version.h"
#include "pc/djui/djui_language.h"
#include "pc/djui/djui_popup.h"
#include "pc/mods/mods.h"
#include "pc/debuglog.h"
#ifdef COOPNET
@ -100,7 +101,9 @@ void ns_coopnet_update(void) {
if (gNetworkType != NT_NONE && sNetworkType != NT_NONE) {
if (sNetworkType == NT_SERVER) {
LOG_INFO("Create lobby");
coopnet_lobby_create(CN_GAME_STR, get_version(), configPlayerName, "Super Mario 64", (uint16_t)configAmountofPlayers, "");
char mode[64] = "";
mods_get_main_mod_name(mode, 64);
coopnet_lobby_create(CN_GAME_STR, get_version(), configPlayerName, mode, (uint16_t)configAmountofPlayers, "");
} else if (sNetworkType == NT_CLIENT) {
LOG_INFO("Join lobby");
coopnet_lobby_join(gCoopNetDesiredLobby, "");