📄 main.c
字号:
if (pidfile) {#ifdef HAVE_GETPID FILE * fp; if (!(fp = fopen(pidfile,"w"))) { eventlog(eventlog_level_error,__FUNCTION__,"unable to open pid file \"%s\" for writing (fopen: %s)",pidfile,pstrerror(errno)); xfree((void *)pidfile); /* avoid warning */ return NULL; } else { fprintf(fp,"%u",(unsigned int)getpid()); if (fclose(fp)<0) eventlog(eventlog_level_error,__FUNCTION__,"could not close pid file \"%s\" after writing (fclose: %s)",pidfile,pstrerror(errno)); }#else eventlog(eventlog_level_warn,__FUNCTION__,"no getpid() system call, disable pid file in bnetd.conf"); xfree((void *)pidfile); /* avoid warning */ return NULL;#endif } return pidfile;}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;}void post_server_shutdown(int status){ switch (status) { case 0: topiclist_unload(); realmlist_destroy(); teamlist_unload(); clanlist_unload(); tournament_destroy(); anongame_infos_unload(); trans_unload(); aliasfile_unload(); command_groups_unload(); tracker_set_servers(NULL); characterlist_destroy(); ladder_destroyxptable(); case STATUS_WAR3XPTABLES_FAILURE: case STATUS_LADDERLIST_FAILURE: ladder_update_all_accounts(); ladders_destroy(); output_dispose_filename(); accountlist_destroy(); attrlayer_cleanup(); watchlist_destroy(); news_unload(); versioncheck_unload(); autoupdate_unload(); adbannerlist_destroy(); ipbanlist_save(prefs_get_ipbanfile()); ipbanlist_destroy(); helpfile_unload(); channellist_destroy(); server_clear_hostname(); timerlist_destroy(); gamelist_destroy(); connlist_destroy(); fdwatch_close(); case STATUS_FDWATCH_FAILURE: anongame_matchlists_destroy(); case STATUS_MATCHLISTS_FAILURE: anongame_maplists_destroy(); case STATUS_MAPLISTS_FAILURE: case STATUS_SUPPORT_FAILURE: if (psock_deinit()) eventlog(eventlog_level_error, __FUNCTION__, "got error from psock_deinit()"); case STATUS_PSOCK_FAILURE: storage_close(); case STATUS_STORAGE_FAILURE: oom_free(); case STATUS_OOM_FAILURE: case -1: break; default: eventlog(eventlog_level_error,__FUNCTION__,"got bad status \"%d\" during shutdown",status); } return;} void pvpgn_greeting(void){#ifdef HAVE_GETPID eventlog(eventlog_level_info,__FUNCTION__,PVPGN_SOFTWARE" version "PVPGN_VERSION" process %u",(unsigned int)getpid());#else eventlog(eventlog_level_info,__FUNCTION__,PVPGN_SOFTWARE" version "PVPGN_VERSION);#endif printf("You are currently Running "PVPGN_SOFTWARE" "PVPGN_VERSION"\n"); printf("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n"); printf("If you need support:\n"); printf(" * READ the documentation at http://pvpgndocs.berlios.de/\n"); printf(" * you can subscribe to the pvpgn-users mailing list at \n"); printf(" https://lists.berlios.de/mailman/listinfo/pvpgn-users\n"); printf(" * check out the forums at http://forums.pvpgn.org\n"); printf(" * visit us on IRC on irc.pvpgn.org channel #pvpgn\n"); printf("\nServer is now running.\n"); printf("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n"); return;}#ifdef WIN32_GUIextern int server_main(int argc, char * * argv)#elseextern int main(int argc, char * * argv)#endif{ int a; char *pidfile; if ((a = cmdline_load(argc, argv)) != 1) return a;#ifdef DO_DAEMONIZE if ((a = fork_bnetd(cmdline_get_foreground())) != 0) return a < 0 ? a : 0; /* dont return code != 0 when things are OK! */#endif eventlog_set(stderr); /* errors to eventlog from here on... */ if (prefs_load(cmdline_get_preffile())<0) { eventlog(eventlog_level_fatal,__FUNCTION__,"could not parse configuration file (exiting)"); return -1; } /* Start logging to log file */ if (eventlog_startup() == -1) return -1; /* eventlog goes to log file from here on... */ /* Give up root privileges */ /* Hakan: That's way too late to give up root privileges... Have to look for a better place */ if (give_up_root_privileges(prefs_get_effective_user(),prefs_get_effective_group())<0) { eventlog(eventlog_level_fatal,__FUNCTION__,"could not give up privileges (exiting)"); return -1; } /* Write the pidfile */ pidfile = write_to_pidfile(); if (cmdline_get_hexfile()) { if (!(hexstrm = fopen(cmdline_get_hexfile(),"w"))) eventlog(eventlog_level_error,__FUNCTION__,"could not open file \"%s\" for writing the hexdump (fopen: %s)",cmdline_get_hexfile(),pstrerror(errno)); else fprintf(hexstrm,"# dump generated by "PVPGN_SOFTWARE" version "PVPGN_VERSION"\n"); } /* Run the pre server stuff */ a = pre_server_startup(); /* now process connections and network traffic */ if (a == 0) { if (server_process() < 0) eventlog(eventlog_level_fatal,__FUNCTION__,"failed to initialize network (exiting)"); } // run post server stuff and exit post_server_shutdown(a); // Close hexfile if (hexstrm) { fprintf(hexstrm,"# end of dump\n"); if (fclose(hexstrm)<0) eventlog(eventlog_level_error,__FUNCTION__,"could not close hexdump file \"%s\" after writing (fclose: %s)",cmdline_get_hexfile(),pstrerror(errno)); }// Delete pidfile if (pidfile) { if (remove(pidfile)<0) eventlog(eventlog_level_error,__FUNCTION__,"could not remove pid file \"%s\" (remove: %s)",pidfile,pstrerror(errno)); xfree((void *)pidfile); /* avoid warning */ } if (a == 0) eventlog(eventlog_level_info,__FUNCTION__,"server has shut down"); prefs_unload(); eventlog_close(); cmdline_unload(); if (a == 0) return 0; return -1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -