int test4(void) { ConfFile conf_file; if (conf_file_create(&conf_file) < 0) { printf("test4: conf_file_create failed\n"); return -1; } if (conf_file_read(&conf_file, "conf_file_test4_input.conf", NULL, NULL) < 0) { printf("test4: conf_file_read failed\n"); return -1; } if (conf_file_write(&conf_file, "conf_file_test4_output.conf") < 0) { printf("test4: conf_file_write failed\n"); return -1; } if (compare_files("conf_file_test4_reference.conf", "conf_file_test4_output.conf") < 0) { printf("test4: compare_files failed\n"); return -1; } conf_file_destroy(&conf_file); return 0; }
int test2(void) { ConfFile conf_file; const char *reference = "\x20 blubb \n \xF3\x01?\x02 foobar \t --!"; const char *value; if (conf_file_create(&conf_file) < 0) { printf("test2: conf_file_create failed\n"); return -1; } if (conf_file_read(&conf_file, "conf_file_test2_reference.conf", NULL, NULL) < 0) { printf("test2: conf_file_read failed\n"); return -1; } value = conf_file_get_option_value(&conf_file, "foo#bar.blu=bb"); if (value == NULL) { printf("test2: conf_file_get_option_value failed\n"); return -1; } if (strlen(reference) != strlen(value)) { printf("test2: reference and value differ in length\n"); return -1; } if (memcmp(reference, value, strlen(reference)) != 0) { printf("test2: reference and value differ in content\n"); return -1; } conf_file_destroy(&conf_file); return 0; }
int main(int argc, char *argv[]) { FILE *fp; #if USING_DMALLOC dmalloc_debug(1); #endif /* start the clock (which is used by the Logit fnc) */ (void) refetch_ticker(); GetArgs(argc, argv); if (conf_file_read(confname)) { Logit("Failed to read config file \"%s\"", confname); strcpy(confname, "./nngs.cnf"); conf_file_write(confname); Logit("Created \"%s\"", confname); } Logit("Starting %s (%s %s) From: %s" , conffile.version_string, conffile.compile_date, conffile.compile_time, confname); if (daemonise()) { Logit("Failed to daemonise, giving up"); main_exit(1); } conf_file_write("written.cnf"); signal(SIGTERM, TerminateServer); signal(SIGINT, TerminateServer); #if 0 signal(SIGPIPE, SIG_IGN); #else signal(SIGPIPE, BrokenPipe); #endif signal(SIGCHLD, reapchild); mink_init(); startuptime = time(NULL); srand(startuptime); read_ban_ip_list(); if (!all_the_internets() ) { fprintf(stderr, "Network initialize failed on ports %s.\n" , conffile.server_ports); main_exit(1); } player_high = 0; game_high = 0; bytes_sent = 0; bytes_received = 0; #ifdef SGI /*mallopt(100, 1);*/ /* Turn on malloc(3X) debugging (Irix only) */ #endif command_init(); EmoteInit(conffile.emotes_file); help_init(); /*Logit("commands_init()");*/ commands_init(); /*Logit("channel_init()");*/ channel_init(); /*Logit("player_array_init()");*/ player_array_init(); player_init(); ladder_init(NUM_LADDERS); Ladder9 = ladder_new(LADDERSIZE); Ladder19 = ladder_new(LADDERSIZE); completed_games = 0; num_logins = num_logouts = new_players = 0; num_9 = 0; fp = xyfopen(FILENAME_LADDER9, "r"); if (fp) { num_9 = ladder_load(fp, Ladder9); Logit("%d players loaded from file %s", num_9, filename() ); fclose(fp); } num_19 = 0; fp = xyfopen(FILENAME_LADDER19, "r"); if (fp) { num_19 = ladder_load(fp, Ladder19); Logit("%d players loaded from file %s", num_19, filename() ); fclose(fp); } /* mink_init();*/ if (conffile.admin_name) create_admin_account(conffile.admin_name ); Logit("Server up and running."); main_event_loop(); Logit("Closing down."); net_closeAll(); main_exit(0); return 0; }