diff --git a/src/fios.h b/src/fios.h index b26fe00925..fc39f63604 100644 --- a/src/fios.h +++ b/src/fios.h @@ -92,9 +92,11 @@ enum FileSlots { /** First slot usable for (New)GRFs used during the game. */ FIRST_GRF_SLOT = 2, /** Last slot usable for (New)GRFs used during the game. */ - LAST_GRF_SLOT = 63, + LAST_GRF_SLOT = 255, /** Maximum number of slots. */ - MAX_FILE_SLOTS = 64 + MAX_FILE_SLOTS = 256, + /** Maximum number of slots for network game */ + MAX_FILE_SLOTS_IN_NETWORK = 63 }; /** Mode of the file dialogue window. */ diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 013b375bda..8cadcda6be 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -31,6 +31,8 @@ #include "../core/geometry_func.hpp" #include "../genworld.h" #include "../map_type.h" +#include "../newgrf.h" +#include "../error.h" #include "../widgets/network_widget.h" @@ -1177,6 +1179,10 @@ struct NetworkStartServerWindow : public Window { } case WID_NSS_GENERATE_GAME: // Start game + if (CountSelectedGRFs (_grfconfig_newgame) >= MAX_FILE_SLOTS_IN_NETWORK) { + ShowErrorMessage(STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED, INVALID_STRING_ID, WL_ERROR); + break; + } _is_network_server = true; if (_ctrl_pressed) { StartNewGameWithoutGUI(GENERATE_NEW_SEED); diff --git a/src/newgrf.cpp b/src/newgrf.cpp index c9a78deb90..20c88e4a76 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -9299,3 +9299,16 @@ void LoadNewGRF(uint load_index, uint file_index) _tick_counter = tick_counter; _display_opt = display_opt; } + +/** + * Returns amount of user selected NewGRFs files. + */ +int CountSelectedGRFs(GRFConfig *grfconf) +{ + int i = 0; + + /* Find last entry in the list */ + for (const GRFConfig *list = grfconf; list != NULL; list = list->next, i++) { + } + return i; +} diff --git a/src/newgrf.h b/src/newgrf.h index 752873a60e..d0d64d35ec 100644 --- a/src/newgrf.h +++ b/src/newgrf.h @@ -195,5 +195,6 @@ bool GetGlobalVariable(byte param, uint32 *value, const GRFFile *grffile); StringID MapGRFStringID(uint32 grfid, StringID str); void ShowNewGRFError(); +int CountSelectedGRFs(GRFConfig *grfconf); #endif /* NEWGRF_H */ diff --git a/src/openttd.cpp b/src/openttd.cpp index c149ebbd4d..e16cad7e93 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -56,6 +56,7 @@ #include "core/backup_type.hpp" #include "hotkeys.h" #include "newgrf.h" +#include "newgrf_commons.h" #include "misc/getoptdata.h" #include "game/game.hpp" #include "game/game_config.hpp" @@ -845,6 +846,13 @@ int openttd_main(int argc, char *argv[]) DriverFactoryBase::SelectDriver(musicdriver, Driver::DT_MUSIC); free(musicdriver); + // Check if not too much GRFs are loaded for network game + if (dedicated && CountSelectedGRFs( _grfconfig ) >= MAX_FILE_SLOTS_IN_NETWORK) { + DEBUG(net, 0, "Too many GRF loaded. Max %d are allowed.\nExiting ...", MAX_FILE_SLOTS_IN_NETWORK); + ShutdownGame(); + goto exit_normal; + } + /* Take our initial lock on whatever we might want to do! */ _modal_progress_paint_mutex->BeginCritical(); _modal_progress_work_mutex->BeginCritical();