Fix mod cache issue where server wouldn't update the hash when it should

This commit is contained in:
MysterD 2022-06-06 19:34:44 -07:00
parent 3b626845e1
commit 29f3e8f1bf
3 changed files with 30 additions and 0 deletions

View File

@ -127,6 +127,12 @@ void mod_activate(struct Mod* mod) {
for (int i = 0; i < mod->fileCount; i++) { for (int i = 0; i < mod->fileCount; i++) {
struct ModFile* file = &mod->files[i]; struct ModFile* file = &mod->files[i];
mod_cache_add(mod, file, false); mod_cache_add(mod, file, false);
// forcefully update md5 hash
if (gNetworkType == NT_SERVER) {
mod_cache_update(mod, file);
}
if (str_ends_with(file->relativePath, ".bin")) { if (str_ends_with(file->relativePath, ".bin")) {
mod_activate_bin(file); mod_activate_bin(file);
} }

View File

@ -221,6 +221,29 @@ void mod_cache_add(struct Mod* mod, struct ModFile* file, bool useFilePath) {
mod_cache_add_internal(file->dataHash, 0, strdup(file->cachedPath)); mod_cache_add_internal(file->dataHash, 0, strdup(file->cachedPath));
} }
void mod_cache_update(struct Mod* mod, struct ModFile* file) {
// sanity check
if (mod == NULL || file == NULL) {
LOG_ERROR("Could not add to cache, mod or file is null");
return;
}
// build the path
char modFilePath[SYS_MAX_PATH] = { 0 };
if (!concat_path(modFilePath, mod->basePath, file->relativePath)) {
LOG_ERROR("Could not concat mod file path");
return;
}
// set path
normalize_path(modFilePath);
file->cachedPath = strdup(modFilePath);
// hash and cache
mod_cache_md5(file->cachedPath, file->dataHash);
mod_cache_add_internal(file->dataHash, 0, strdup(file->cachedPath));
}
void mod_cache_load(void) { void mod_cache_load(void) {
mod_cache_shutdown(); mod_cache_shutdown();
LOG_INFO("Loading mod cache"); LOG_INFO("Loading mod cache");

View File

@ -14,6 +14,7 @@ void mod_cache_shutdown(void);
struct ModCacheEntry* mod_cache_get_from_hash(u8* dataHash); struct ModCacheEntry* mod_cache_get_from_hash(u8* dataHash);
struct ModCacheEntry* mod_cache_get_from_path(const char* path, bool validate); struct ModCacheEntry* mod_cache_get_from_path(const char* path, bool validate);
void mod_cache_add(struct Mod* mod, struct ModFile* modFile, bool useFilePath); void mod_cache_add(struct Mod* mod, struct ModFile* modFile, bool useFilePath);
void mod_cache_update(struct Mod* mod, struct ModFile* file);
void mod_cache_load(void); void mod_cache_load(void);
void mod_cache_save(void); void mod_cache_save(void);