void Instance::LoadModListFromDir(const wxFileName& dir, bool mlMod) { ModList *list; if (mlMod) list = &mlModList; else list = &modList; wxDir modDir(dir.GetFullPath()); if (!modDir.IsOpened()) { wxLogError(_("Failed to open directory: ") + dir.GetFullPath()); return; } wxString currentFile; if (modDir.GetFirst(¤tFile)) { do { currentFile = Path::Combine(modDir.GetName(), currentFile); if (wxFileExists(currentFile) || mlMod) { Mod mod(currentFile); if (mlMod || !Any(list->begin(), list->end(), [¤tFile] (Mod mod) -> bool { return mod.GetFileName().SameAs(wxFileName(currentFile)); })) { if (!mlMod) SetNeedsRebuild(); list->push_back(mod); } } else if (wxDirExists(currentFile)) { LoadModListFromDir(wxFileName(currentFile), mlMod); } } while (modDir.GetNext(¤tFile)); } }
int main(int argc, char* argv[]) { #ifdef VAULTMP_DEBUG #ifdef __WIN32__ if (LoadLibrary("exchndl.dll") == NULL) return 0; #else system("ulimit -c unlimited"); #endif #endif #ifdef __WIN32__ printf("Vault-Tec dedicated server %s (Windows)\n----------------------------------------------------------\n", DEDICATED_VERSION); #else printf("Vault-Tec dedicated server %s (Unix)\n----------------------------------------------------------\n", DEDICATED_VERSION); #endif unsigned char game; int port; int players; int fileslots; bool query; bool files; const char* announce; const char* scripts; const char* mods; const char* savegame; dictionary* config = iniparser_load(argc > 1 ? argv[1] : "vaultserver.ini"); const char* game_str = iniparser_getstring(config, "general:game", "fallout3"); if (stricmp(game_str, "newvegas") == 0) game = NEWVEGAS; else game = FALLOUT3; port = iniparser_getint(config, "general:port", RAKNET_STANDARD_PORT); players = iniparser_getint(config, "general:players", RAKNET_STANDARD_CONNECTIONS); query = (bool) iniparser_getboolean(config, "general:query", 1); files = (bool) iniparser_getboolean(config, "general:fileserve", 0); fileslots = iniparser_getint(config, "general:fileslots", 8); announce = iniparser_getstring(config, "general:master", "vaultmp.com"); savegame = iniparser_getstring(config, "general:save", "default.fos"); scripts = iniparser_getstring(config, "scripts:scripts", ""); mods = iniparser_getstring(config, "mods:mods", ""); ServerEntry* self = new ServerEntry(game); self->SetServerRule("version", DEDICATED_VERSION); Dedicated::SetServerEntry(self); char base[MAX_PATH]; _getcwd(base, sizeof(base)); try { putenv(PWNFILES_PATH); char _scripts[strlen(scripts) + 1]; snprintf(_scripts, sizeof(_scripts), "%s", scripts); Script::LoadScripts(_scripts, base); } catch (std::exception& e) { try { VaultException& vaulterror = dynamic_cast<VaultException&>(e); vaulterror.Console(); } catch (std::bad_cast& no_vaulterror) { VaultException vaulterror(e.what()); vaulterror.Console(); } } try { char file[MAX_PATH]; snprintf(file, sizeof(file), "%s/%s/%s", base, SAVEGAME_PATH, savegame); unsigned int crc; if (!Utils::crc32file(file, &crc)) throw VaultException("Could not find savegame %s in folder %s", savegame, SAVEGAME_PATH); Dedicated::SetSavegame(Savegame(string(savegame), crc)); char buf[strlen(mods) + 1]; strcpy(buf, mods); char* token = strtok(buf, ","); ModList modfiles; while (token != NULL) { snprintf(file, sizeof(file), "%s/%s/%s", base, MODFILES_PATH, token); if (!Utils::crc32file(file, &crc)) throw VaultException("Could not find modfile %s in folder %s", token, MODFILES_PATH); modfiles.push_back(pair<string, unsigned int>(string(token), crc)); token = strtok(NULL, ","); } Dedicated::SetModfiles(modfiles); thread hDedicatedThread = Dedicated::InitializeServer(port, players, announce, query, files, fileslots); thread hInputThread = thread(InputThread); hDedicatedThread.join(); if (hInputThread.joinable()) hInputThread.join(); } catch (std::exception& e) { try { VaultException& vaulterror = dynamic_cast<VaultException&>(e); vaulterror.Console(); } catch (std::bad_cast& no_vaulterror) { VaultException vaulterror(e.what()); vaulterror.Console(); } } Script::UnloadScripts(); iniparser_freedict(config); delete self; #ifdef __WIN32__ system("PAUSE"); #endif return 0; }