Example #1
0
/** Attempt to find a game with @a title in @a directory.
 *  @param title The game must match this title
 *  @param directory Look in this directory for *.game files
 *  @return The GameParams, or NULL if the title was not found
 */
static GameParams *server_find_title_in_directory(const gchar * title,
						  const gchar * directory)
{
	GDir *dir;
	const gchar *fname;
	gchar *fullname;

	log_message(MSG_INFO, _("Looking for games in '%s'\n"), directory);
	if ((dir = g_dir_open(directory, 0, NULL)) == NULL) {
		log_message(MSG_INFO, _("Game directory '%s' not found\n"),
			    directory);
		return NULL;
	}

	while ((fname = g_dir_read_name(dir))) {
		GameParams *params;
		gint len = strlen(fname);

		if (len < 6 || strcmp(fname + len - 5, ".game") != 0)
			continue;
		fullname = g_build_filename(directory, fname, NULL);
		params = load_game_desc(fullname);
		g_free(fullname);
		if (params) {
			if (strcmp(params->title, title) == 0) {
				g_dir_close(dir);
				return params;
			}
			params_free(params);
		}
	}
	g_dir_close(dir);
	return NULL;
}
Example #2
0
static void game_list_prepare_directory(const gchar * directory)
{
	GDir *dir;
	const gchar *fname;
	gchar *fullname;

	log_message(MSG_INFO, _("Looking for games in '%s'\n"), directory);
	if ((dir = g_dir_open(directory, 0, NULL)) == NULL) {
		log_message(MSG_INFO, _("Game directory '%s' not found\n"),
			    directory);
		return;
	}

	while ((fname = g_dir_read_name(dir))) {
		GameParams *params;
		gint len = strlen(fname);

		if (len < 6 || strcmp(fname + len - 5, ".game") != 0)
			continue;
		fullname = g_build_filename(directory, fname, NULL);
		params = load_game_desc(fullname);
		g_free(fullname);
		if (params) {
			if (!game_list_add_item(params))
				params_free(params);
		}
	}
	g_dir_close(dir);
}
Example #3
0
static void load_game(const gchar * file, gboolean is_reload)
{
	const gchar *gamefile;
	GameParams *new_params;
	gchar *new_filename;
	gint i;

	if (file == NULL)
		gamefile = default_game;
	else
		gamefile = file;

	new_params = params_load_file(gamefile);
	if (new_params == NULL) {
		error_dialog(_("Failed to load '%s'"), file);
		return;
	}

	if (file == NULL) {
		g_free(new_params->title);
		new_params->title = g_strdup("Untitled");
		map_free(new_params->map);
		new_params->map = map_new();
		for (i = 0; i < 6; i++) {
			map_modify_row_count(new_params->map,
					     MAP_MODIFY_INSERT,
					     MAP_MODIFY_ROW_BOTTOM);
		}
		for (i = 0; i < 11; i++) {
			map_modify_column_count(new_params->map,
						MAP_MODIFY_INSERT,
						MAP_MODIFY_COLUMN_RIGHT);
		}
		new_params->map->chits =
		    g_array_new(FALSE, FALSE, sizeof(gint));
		new_filename = NULL;
	} else {
		new_filename = g_strdup(file);
		config_set_string("editor/last-game", new_filename);
	}

	guimap_reset(gmap);
	if (params != NULL)
		params_free(params);
	params = new_params;
	apply_params(params);
	if (open_filename != NULL)
		g_free(open_filename);
	open_filename = new_filename;
	map_move_robber(gmap->map, -1, -1);
	fill_map(gmap->map);
	if (is_reload) {
		scale_map(gmap);
		guimap_display(gmap);
	}
	update_resize_buttons();
}
Example #4
0
void game_list_cleanup(void)
{
	GSList *games = _game_list;
	while (games) {
		params_free(games->data);
		games = g_slist_next(games);
	}
	g_slist_free(_game_list);
}
Example #5
0
void connection_free( connection_t* connection ) {
    params_free( &connection->request.params );
    if ( connection->request.post_body )
        free( connection->request.post_body );
    int i = -1;
    while ( connection->request.parts[++i] ) {
        if ( connection->request.parts[i]->post_body )
            free( connection->request.parts[i]->post_body );
        free( connection->request.parts[i] );
    }
    free( connection );
}
Example #6
0
void game_free(Game * game)
{
	if (game == NULL)
		return;

	server_stop(game);

	g_assert(game->player_list_use_count == 0);
	if (game->server_port != NULL)
		g_free(game->server_port);
	params_free(game->params);
	g_free(game);
}
Example #7
0
File: c_cmd.cpp Project: pouba/os
void* before_after(void* par) {
	run_params* params = (run_params*)(par);
	void (*function) (void*);

	function = (void (*) (void*))params->func;

	// before

	// function
	function((void*)params);

	//after
	pipe_close_in(params->out);
	pipe_close_in(params->err);
	pipe_close_out(params->in);

	params_free(params);

	return NULL;
}
Example #8
0
static void do_init(int argc, char *argv[])
{
	params = params_new();

	char opt;
	while ((opt = getopt(argc, argv, "ha:")) != -1)
	{
		switch (opt)
		{
			case 'a':
			{
				params->bind_address = strdup(optarg);
				break;
			}
			case 'h':
			{
				print_usage();

				params_free(params);
				exit(EXIT_SUCCESS);
			}
		}
	}
}