static char * file_find_default(const char *rawname) { /* Add new default files here */ const char * defaultfiles[]={"termsofservice-",".txt", "newaccount-",".txt", "chathelp-war3-",".txt", "matchmaking-war3-",".dat", "tos_",".txt", "tos-unicode_", ".txt", NULL,NULL}; const char ** pattern, **extension; char *filename = NULL; for (pattern = defaultfiles, extension = defaultfiles + 1; *pattern; pattern+=2, extension+=2) if (!std::strncmp(rawname, *pattern,std::strlen(*pattern))) { /* Check if there is a default file available for this kind of file */ filename = (char*)xmalloc(std::strlen(prefs_get_filedir()) + 1 + std::strlen(*pattern) + 7 + std::strlen(*extension) + 1); std::strcpy(filename, prefs_get_filedir()); std::strcat(filename, "/"); std::strcat(filename, *pattern); std::strcat(filename, "default"); std::strcat(filename, *extension); break; } return filename; }
extern int support_check_files(char const * supportfile) { FILE *fp; char *buff; unsigned int line; int filedirlen; char * namebuff; if (!(supportfile)) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL supportfile"); return -1; } if (!(fp = fopen(supportfile,"r"))) { eventlog(eventlog_level_error,__FUNCTION__,"could not open file \"%s\" for reading (fopen: %s)",supportfile,pstrerror(errno)); eventlog(eventlog_level_error,__FUNCTION__,"can't guarantee that everything will run smooth"); return 0; } filedirlen = strlen(prefs_get_filedir()); for (line=1; (buff = file_get_line(fp)); line++) { if (buff[0]=='#' || buff[0]=='\0') { continue; } namebuff = (char*)xmalloc(filedirlen + 1 + strlen(buff) + 1); sprintf(namebuff,"%s/%s",prefs_get_filedir(),buff); if (access(namebuff, F_OK) < 0) { eventlog(eventlog_level_fatal,__FUNCTION__,"necessary file \"%s\" missing",namebuff); xfree((void *)namebuff); fclose(fp); return -1; } xfree((void *)namebuff); } file_get_line(NULL); // clear file_get_line buffer fclose(fp); return 0; }
static char const * file_get_info(char const * rawname, unsigned int * len, bn_long * modtime) { char *filename; t_bnettime bt; struct stat sfile; if (!rawname) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL rawname"); return NULL; } if (!len) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL len"); return NULL; } if (!modtime) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL modtime"); return NULL; } if (std::strchr(rawname,'/') || std::strchr(rawname,'\\')) { eventlog(eventlog_level_warn,__FUNCTION__,"got rawname containing '/' or '\\' \"%s\"",rawname); return NULL; } filename = buildpath(prefs_get_filedir(), rawname); if (stat(filename, &sfile)<0) { /* if it doesn't exist, try to replace with default file */ xfree((void*)filename); filename = file_find_default(rawname); if (!filename) return NULL; /* no default version */ if (stat(filename, &sfile)<0) { /* try again */ /* FIXME: check for lower-case version of filename */ xfree(filename); return NULL; } } *len = (unsigned int)sfile.st_size; bt = time_to_bnettime(sfile.st_mtime,0); bnettime_to_bn_long(bt,modtime); return filename; }
static char const * file_get_info(char const * rawname, unsigned int * len, bn_long * modtime) { const char *filename; t_bnettime bt; struct stat sfile; if (!rawname) { eventlog(eventlog_level_error, __FUNCTION__, "got NULL rawname"); return NULL; } if (!len) { eventlog(eventlog_level_error, __FUNCTION__, "got NULL len"); return NULL; } if (!modtime) { eventlog(eventlog_level_error, __FUNCTION__, "got NULL modtime"); return NULL; } if (std::strchr(rawname, '/') || std::strchr(rawname, '\\')) { eventlog(eventlog_level_warn, __FUNCTION__, "got rawname containing '/' or '\\' \"%s\"", rawname); return NULL; } filename = file_find_localized(rawname); // if localized file not found in "i18n" if (!filename || stat(filename, &sfile) < 0) { // try find it in "files" filename = buildpath(prefs_get_filedir(), rawname); if (stat(filename, &sfile) < 0) { /* try again */ /* FIXME: check for lower-case version of filename */ return NULL; } } *len = (unsigned int)sfile.st_size; bt = time_to_bnettime(sfile.st_mtime, 0); bnettime_to_bn_long(bt, modtime); return filename; }
int pre_server_startup(void) { pvpgn_greeting(); if (oom_setup() < 0) { eventlog(eventlog_level_error, __FUNCTION__, "OOM init failed"); return STATUS_OOM_FAILURE; } if (storage_init(prefs_get_storage_path()) < 0) { eventlog(eventlog_level_error, "pre_server_startup", "storage init failed"); return STATUS_STORAGE_FAILURE; } if (psock_init() < 0) { eventlog(eventlog_level_error, __FUNCTION__, "could not initialize socket functions"); return STATUS_PSOCK_FAILURE; } if (support_check_files(prefs_get_supportfile()) < 0) { eventlog(eventlog_level_error, "pre_server_startup","some needed files are missing"); eventlog(eventlog_level_error, "pre_server_startup","please make sure you installed the supportfiles in %s",prefs_get_filedir()); return STATUS_SUPPORT_FAILURE; } if (anongame_maplists_create() < 0) { eventlog(eventlog_level_error, "pre_server_startup", "could not load maps"); return STATUS_MAPLISTS_FAILURE; } if (anongame_matchlists_create() < 0) { eventlog(eventlog_level_error, "pre_server_startup", "could not create matchlists"); return STATUS_MATCHLISTS_FAILURE; } if (fdwatch_init(prefs_get_max_connections())) { eventlog(eventlog_level_error, __FUNCTION__, "error initilizing fdwatch"); return STATUS_FDWATCH_FAILURE; } connlist_create(); gamelist_create(); timerlist_create(); server_set_hostname(); channellist_create(); if (helpfile_init(prefs_get_helpfile())<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load helpfile"); ipbanlist_create(); if (ipbanlist_load(prefs_get_ipbanfile())<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load IP ban list"); if (adbannerlist_create(prefs_get_adfile())<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load adbanner list"); if (autoupdate_load(prefs_get_mpqfile())<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load autoupdate list"); if (versioncheck_load(prefs_get_versioncheck_file())<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load versioncheck list"); if (news_load(prefs_get_newsfile())<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load news list"); watchlist_create(); output_init(); attrlayer_init(); accountlist_create(); if (ladder_createxptable(prefs_get_xplevel_file(),prefs_get_xpcalc_file())<0) { eventlog(eventlog_level_error, "pre_server_startup", "could not load WAR3 xp calc tables"); return STATUS_WAR3XPTABLES_FAILURE; } ladders_init(); ladders_load_accounts_to_ladderlists(); ladder_update_all_accounts(); if (characterlist_create("")<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load character list"); if (prefs_get_track()) /* setup the tracking mechanism */ tracker_set_servers(prefs_get_trackserv_addrs()); if (command_groups_load(prefs_get_command_groups_file())<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load command_groups list"); aliasfile_load(prefs_get_aliasfile()); if (trans_load(prefs_get_transfile(),TRANS_BNETD)<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load trans list"); tournament_init(prefs_get_tournament_file()); anongame_infos_load(prefs_get_anongame_infos_file()); clanlist_load(); teamlist_load(); if (realmlist_create(prefs_get_realmfile())<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load realm list"); topiclist_load(prefs_get_topicfile()); return 0; }