Raised Lua size limit from 64KB to 2MB

This commit is contained in:
MysterD 2022-03-02 00:40:53 -08:00
parent 822cc4a4a9
commit 92b5893871
5 changed files with 27 additions and 9 deletions

View file

@ -89,6 +89,7 @@ void smlua_init(void) {
smlua_cobject_init_globals();
// load scripts
mod_list_size_enforce();
LOG_INFO("Loading scripts:");
struct ModTable* table = gModTableCurrent;
for (int i = 0; i < table->entryCount; i++) {

View file

@ -253,6 +253,8 @@ void mod_list_update_selectable(void) {
}
}
}
mod_list_size_enforce();
}
static void mod_list_load_local(const char* path) {
@ -295,6 +297,15 @@ static void mod_list_load_local(const char* path) {
closedir(d);
}
void mod_list_size_enforce(void) {
for (int i = 0; i < gModTableLocal.entryCount; i++) {
if (gModTableLocal.entries[i].size >= MAX_MOD_SIZE) {
gModTableLocal.entries[i].enabled = false;
gModTableLocal.entries[i].selectable = false;
}
}
}
void mod_list_init(void) {
gModTableCurrent = &gModTableLocal;
srand(time(0));

View file

@ -9,6 +9,7 @@
#include "src/pc/platform.h"
#define MOD_PATH "./mods"
#define MAX_MOD_SIZE (2 * 1048576) // 2MB
struct ModListEntry {
char* name;
@ -43,6 +44,7 @@ void mod_table_clear(struct ModTable* table);
void mod_list_alloc(struct ModTable* table, u16 count);
void mod_list_update_selectable(void);
void mod_list_size_enforce(void);
void mod_list_init(void);
void mod_list_shutdown(void);

View file

@ -21,7 +21,6 @@ void network_send_next_download_request(void) {
network_send_download_request(i, entry->remoteIndex, entry->curOffset);
return;
}
//LOG_INFO("sending join request");
network_send_join_request();
djui_panel_modlist_create(NULL);
}
@ -134,7 +133,7 @@ void network_receive_download(struct Packet* p) {
packet_read(p, &chunkSize, sizeof(u16));
packet_read(p, chunk, chunkSize * sizeof(u8));
//LOG_ERROR("Received download %u:%llu", clientIndex, offset);
//LOG_INFO("Received download %u:%llu", clientIndex, offset);
if (clientIndex >= gModTableRemote.entryCount) {
LOG_ERROR("Received download of invalid index %u:%llu", clientIndex, offset);
@ -153,7 +152,7 @@ void network_receive_download(struct Packet* p) {
}
if ((offset + chunkSize) > entry->size) {
LOG_ERROR("Received download of invalid chunk size %u:%llu:%u", clientIndex, offset, chunkSize);
LOG_ERROR("Received download of invalid chunk size %u:%llu:%u -- %llu", clientIndex, offset, chunkSize, entry->size);
return;
}
@ -197,7 +196,7 @@ void network_receive_download(struct Packet* p) {
entry->complete = true;
}
entry->curOffset += CHUNK_SIZE * OFFSET_COUNT;
entry->curOffset += (u64)CHUNK_SIZE * OFFSET_COUNT;
network_send_next_download_request();
}
}

View file

@ -48,8 +48,8 @@ void network_send_mod_list(void) {
packet_write(&p, &i, sizeof(u16));
packet_write(&p, &nameLength, sizeof(u16));
packet_write(&p, entry->name, sizeof(u8) * nameLength);
packet_write(&p, &entry->size, sizeof(u16));
LOG_INFO(" '%s': %u", entry->name, (u16)entry->size);
packet_write(&p, &entry->size, sizeof(u64));
LOG_INFO(" '%s': %llu", entry->name, (u64)entry->size);
}
network_send_to(0, &p);
}
@ -107,12 +107,17 @@ void network_receive_mod_list(struct Packet* p) {
char* name = (char*)calloc(nameLength + 1, sizeof(char));
packet_read(p, name, nameLength * sizeof(u8));
u16 size = 0;
packet_read(p, &size, sizeof(u16));
u64 size = 0;
packet_read(p, &size, sizeof(u64));
if (size >= MAX_MOD_SIZE) {
djui_popup_create("Server had too large of a mod.\nQuitting.", 4);
network_shutdown(false);
return;
}
mod_list_add_tmp(i, remoteIndex, name, size);
LOG_INFO(" '%s': %u", name, size);
LOG_INFO(" '%s': %llu", name, size);
}
network_send_next_download_request();