Exemple #1
0
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;
}
Exemple #2
0
int main(int argc, char *argv[])
{
    int run_as_daemon;
    int debug;
    pid_t pid = 0;
    FILE *file_out;
    struct sigaction sv;

#if WITH_MALLOC_BOEHM_GC
    GC_find_leak = 1;
    GC_set_warn_proc(gc_warn_proc);
    GC_enable_incremental();
#endif

    run_as_daemon = 1;
    debug = 0;
    tools_init();

    /* set up some signal handlers */
    memset(&sv, 0, sizeof(sv));
    sigemptyset(&sv.sa_mask);
    sv.sa_handler = SIG_IGN;
    sigaction(SIGPIPE, &sv, NULL);
    sv.sa_handler = sigaction_rehash;
    sigaction(SIGHUP, &sv, NULL);
    sv.sa_handler = sigaction_writedb;
    sigaction(SIGINT, &sv, NULL);
    sv.sa_handler = sigaction_exit;
    sigaction(SIGQUIT, &sv, NULL);
    sv.sa_handler = sigaction_wait;
    sigaction(SIGCHLD, &sv, NULL);

    if (argc > 1) { /* parse command line, if any */
        int c;
        struct option options[] =
        {
            {"config", 1, 0, 'c'},
            {"debug", 0, 0, 'd'},
            {"foreground", 0, 0, 'f'},
            {"help", 0, 0, 'h'},
            {"check", 0, 0, 'k'},
            {"replay", 1, 0, 'r'},
            {"version", 0, 0, 'v'},
            {0, 0, 0, 0}
        };

        while ((c = getopt_long(argc, argv, "c:dfhkr:v", options, NULL)) != -1) {
            switch (c) {
            case 'c':
                services_config = optarg;
                break;
            case 'k':
                if (conf_read(services_config)) {
                    printf("%s appears to be a valid configuration file.\n", services_config);
                } else {
                    printf("%s is an invalid configuration file.\n", services_config);
                }
                exit(0);
            case 'r':
                replay_file = fopen(optarg, "r");
                if (!replay_file) {
                    fprintf(stderr, "Could not open %s for reading: %s (%d)\n",
                            optarg, strerror(errno), errno);
                    exit(0);
                }
                break;
            case 'd':
                debug = 1;
                break;
            case 'f':
                run_as_daemon = 0;
                break;
            case 'v':
                version();
                license();
                exit(0);
            case 'h':
            default:
                usage(argv[0]);
                exit(0);
            }
        }
    }

    version();

    if (replay_file) {
        /* We read a line here to "prime" the replay file parser, but
         * mostly to get the right value of "now" for when we do the
         * irc_introduce. */
        replay_read_line();
    } else {
        now = time(NULL);
    }
    boot_time = now;

    fprintf(stdout, "Initializing daemon...\n");
    if (!conf_read(services_config)) {
        fprintf(stderr, "Unable to read %s.\n", services_config);
        exit(1);
    }

    conf_register_reload(uplink_compile);

    if (run_as_daemon) {
        /* Attempt to fork into the background if daemon mode is on. */
        pid = fork();
        if (pid < 0) {
            fprintf(stderr, "Unable to fork: %s\n", strerror(errno));
        } else if (pid > 0) {
            fprintf(stdout, "Forking into the background (pid: %d)...\n", pid);
            exit(0);
        }
        setsid();
    }

    file_out = fopen(PID_FILE, "w");
    if (file_out == NULL) {
        /* Create the main process' pid file */
        fprintf(stderr, "Unable to create PID file: %s", strerror(errno));
    } else {
        fprintf(file_out, "%i\n", (int)getpid());
        fclose(file_out);
    }

    if (run_as_daemon) {
        /* Close these since we should not use them from now on. */
        fclose(stdin);
        fclose(stdout);
        fclose(stderr);
    }

    services_argc = argc;
    services_argv = argv;

    atexit(call_exit_funcs);
    reg_exit_func(main_shutdown, NULL);

    log_init();
    MAIN_LOG = log_register_type("x3", "file:main.log");
    if (debug)
        log_debug();
    ioset_init();
    init_structs();
    init_parse();
    modcmd_init();
    saxdb_init();
    sar_init();
    gline_init();
    shun_init();
    mail_init();
    helpfile_init();
    conf_globals(); /* initializes the core services */
    conf_rlimits();
    modules_init();
    message_register_table(msgtab);
    modcmd_finalize();
    saxdb_finalize();
    helpfile_finalize();
    modules_finalize();

    /* The first exit func to be called *should* be saxdb_write_all(). */
    reg_exit_func(saxdb_write_all, NULL);
    if (replay_file) {
        char *msg;
        log_module(MAIN_LOG, LOG_INFO, "Beginning replay...");
        srand(now);
        replay_event_loop();
        if ((msg = dict_sanity_check(clients))) {
            log_module(MAIN_LOG, LOG_ERROR, "Clients insanity: %s", msg);
            free(msg);
        }
        if ((msg = dict_sanity_check(channels))) {
            log_module(MAIN_LOG, LOG_ERROR, "Channels insanity: %s", msg);
            free(msg);
        }
        if ((msg = dict_sanity_check(servers))) {
            log_module(MAIN_LOG, LOG_ERROR, "Servers insanity: %s", msg);
            free(msg);
        }
    } else {
        now = time(NULL);
        srand(now);
        ioset_run();
    }
    return 0;
}