Ejemplo n.º 1
0
int
main(int argc, char *argv[])
{
    srand(time(NULL));

    char **gamepaths;
    int i;
    nh_bool init_ok;

    umask(0777 & ~FCMASK);

    /* this can change argc and *argv, so must come first */
    initialize_uncursed(&argc, argv);

    process_args(argc, argv);   /* grab -U, -H, -k, --help early */
    init_options();
    gamepaths = init_game_paths(argv[0]);

    nh_lib_init(&curses_windowprocs, (const char * const*)gamepaths);
    init_curses_ui(gamepaths[DATAPREFIX]);
    init_ok = read_nh_config();
    for (i = 0; i < PREFIX_COUNT; i++)
        free(gamepaths[i]);
    free(gamepaths);


    process_args(argc, argv);   /* other command line options */
    init_displaychars();

    if (init_ok)
        mainmenu();
    else
        curses_msgwin("Could not initialize game options!", krc_notification);

    exit_curses_ui();
    nh_lib_exit();
    free_displaychars();

    exit(EXIT_SUCCESS);
     /*NOTREACHED*/ return 0;
}
Ejemplo n.º 2
0
void exit_client(const char *err)
{
    const char *msg = err ? err : "";
    json_t *exit_obj;
    
    if (err)
	log_msg("Client error: %s. Exit.", err);
    
    if (outfd != -1) {
	exit_obj = json_object();
	
	json_object_set_new(exit_obj, "error", err ? json_true() : json_false());
	json_object_set_new(exit_obj, "message", json_string(msg));
	if (can_send_msg)
	    client_msg("server_error", exit_obj);
	else
	    json_decref(exit_obj);
	
	usleep(100); /* try to make sure the server process handles write() before close(). */
	close(infd);
	close(outfd);
	infd = outfd = -1;
    }
    
    termination_flag = 3; /* make sure the command loop exits if nh_exit_game jumps there */
    if (!sigsegv_flag)
	nh_exit_game(EXIT_FORCE_SAVE); /* might not return here */
    nh_lib_exit();
    close_database();
    if (user_info.username)
	free(user_info.username);
    free_config();
    reset_cached_diplaydata();
    end_logging();
    exit(err != NULL);
}