game_description* init_game_description(int id){
	game_description* g;
	if((g = malloc(sizeof(game_description))) == NULL){
		perror("malloc");
		exit(1);
	}
	if((g->name = malloc(GAME_NAME_MAXSIZE + 1)) == NULL){
		perror("malloc");
		exit(1);
	}
	g->white = NULL;
	g->black = NULL;
	g->spectators = init_dynamic_array(sizeof(login_entry));
	g->id = (uint32_t)id;
	g->moves_made = 0;
	g->game_log = open_game_log(g->id);
	g->state = GAME_STATE_WAITING_FOR_PLAYERS;
	init_desk(g);
	return g;
}
Пример #2
0
my_bool init_dynamic_string_array(DYNAMIC_STRING_ARRAY *array, 
                                  uint init_alloc, 
                                  uint alloc_increment)
{  
    DBUG_ENTER("init_dynamic_string_array");
    if (!array) {
        DBUG_RETURN(TRUE);
    }

    if (!(array->pos_info_arr = (DYNAMIC_ARRAY *) my_malloc(sizeof(DYNAMIC_ARRAY), MYF(0)))) {
        // TODO: print err
        DBUG_RETURN(TRUE);
    }
   
    if (!(array->dynstr = (DYNAMIC_STRING *) my_malloc(sizeof(DYNAMIC_STRING), MYF(0)))) {
        // TODO: print err
        DBUG_RETURN(TRUE);
    }

    init_dynamic_array(array->pos_info_arr, sizeof(dynstr_pos_info), init_alloc, alloc_increment);
    array->cur_idx = 0;
    DBUG_RETURN(init_dynamic_string(array->dynstr, "", 0, 0) ? TRUE : FALSE);
}