Пример #1
0
const char * option_get_string(const char var[]) {

   const char * val;

   val = option_get(var);

   return val;
}
Пример #2
0
double option_get_double(const char var[]) {

   const char * val;

   val = option_get(var);

   return atof(val);
}
Пример #3
0
int option_get_int(const char var[]) {

   const char * val;

   val = option_get(var);

   return atoi(val);
}
Пример #4
0
int option_get_int(option_list_t *option, const char name[]) {

   const char * value;

   value = option_get(option,name);

   return atoi(value);
}
Пример #5
0
const char * option_get_string(option_list_t *option, const char name[]) {

   const char * value;

   value = option_get(option,name);

   return value;
}
Пример #6
0
double option_get_double(option_list_t *option, const char name[]) {

   const char * value;

   value = option_get(option,name);

   return atof(value);
}
Пример #7
0
bool option_get_bool(const char var[]) {

   const char * val;

   val = option_get(var);

   if (false) {
   } else if (my_string_equal(val,"true") || my_string_equal(val,"yes") || my_string_equal(val,"1")) {
      return true;
   } else if (my_string_equal(val,"false") || my_string_equal(val,"no") || my_string_equal(val,"0")) {
      return false;
   }

   ASSERT(false);

   return false;
}
Пример #8
0
bool option_get_bool(option_list_t *option, const char name[]) {

   const char * value;

   value = option_get(option,name);

   if (FALSE) {
   } else if (my_string_case_equal(value,"true") || my_string_case_equal(value,"yes") || my_string_equal(value,"1")) {
      return TRUE;
   } else if (my_string_case_equal(value,"false") || my_string_case_equal(value,"no") || my_string_equal(value,"0")) {
      return FALSE;
   }

   ASSERT(FALSE);

   return FALSE;
}
Пример #9
0
static void display_fps()
{
	static Uint32 timer = 0;
	Uint32 new_timer;
	static char fps[64];
	double sample;
	option_t * option;
	static int num_frame = 0;

	if( frame_rate ) {
		option = option_get();
		if( option->show_fps ) {
			num_frame++;
			new_timer = SDL_GetTicks();
			if( timer + 1000 < new_timer ) {
				sample = (double)num_frame / ((double)new_timer - (double)timer ) * 1000.0;
				num_frame = 0;
				timer = new_timer;
				sprintf(fps,"%f",sample);
			}
			item_set_string(frame_rate,fps);
		}
	}
}
Пример #10
0
/******************************************************
create a list of item for the currently selected screen
******************************************************/
static void compose_scr(context_t * context)
{
	static TTF_Font * font = NULL;
	option_t * option = option_get();

	SDL_SetRenderDrawColor(context->render, 0, 0, 0, 255);

	switch(current_screen) {
	case SCREEN_SELECT:
		item_list = scr_select_compose(context);
		break;
	case SCREEN_PLAY:
		item_list = scr_play_compose(context);
		break;
	}

	if( option->show_fps ) {
		font = font_get(context,ITEM_FONT, ITEM_FONT_SIZE);
		frame_rate = item_list_add(&item_list);
		item_set_font(frame_rate,font);
		item_set_anim_shape(frame_rate,50,50,20,20);
		item_set_overlay(frame_rate,1);
	}
}
Пример #11
0
static int
config_ldap(void)
{
    int i = 0, j = 0;
    char *value;
    option_list *mapping;

    if (!config.configured) {
	/*
	syslog(LOG_NOTICE, "Configuring the LDAP settings for the first time");
	*/

	/* Search Base */
	value = option_get("", opt_ldap_searchbase, 1, NULL);
	if (value) {
	    config.searchbase = strdup(value);
	} else {
	    config_error(err_ldap_missing, opt_ldap_searchbase);
	    return -1;
	}

	/* Scope */
	value = option_get("", opt_ldap_scope, 1, NULL);
	if (value) {
	    if (strcasecmp(value, "subtree") == 0) {
		config.scope = LDAP_SCOPE_SUBTREE;
	    } else if (strcasecmp(value, "base") == 0) {
		config.scope = LDAP_SCOPE_BASE;
	    } else if (strcasecmp(value, "onelevel") == 0) {
		config.scope = LDAP_SCOPE_ONELEVEL;
	    } else {
		config_error(err_ldap_badvalue, opt_ldap_scope);
		return -1;
	    }
	} else {
	    config_error(err_ldap_missing, opt_ldap_scope);
	    return -1;
	}

	/* LDAP Server Hostname */
	value = option_get("", opt_ldap_ldaphost, 1, NULL);
	if (value) {
	    config.ldaphost = strdup(value);
	} else {
	    config_error(err_ldap_missing, opt_ldap_ldaphost);
	    return -1;
	}

	/* LDAP Server Port Number */
	value = option_get("", opt_ldap_ldapport, 1);
	if (value) {
	    config.ldapport = atoi(value);
	} else {
	    config.ldapport = LDAP_PORT;
	}

	/* Fullname Attribute */
	value = option_get("", opt_ldap_fullnameattr, 1, NULL);
	if (value) {
	    config.fullnameattr = strdup(value);
	} else {
	    config_error(err_ldap_missing, opt_ldap_fullnameattr);
	    return -1;
	}

	/* Unique Attribute */
	value = option_get("", opt_ldap_uniqueattr, 1, NULL);
	if (value) {
	    config.uniqueattr = strdup(value);
	} else {
	    config_error(err_ldap_missing, opt_ldap_uniqueattr);
	    return -1;
	}

	/* Default Search Filter */
	value = option_get("", opt_ldap_defaultfilter, 1, NULL);
	if (value) {
	    config.defaultfilter = strdup(value);
	} else {
	    config_error(err_ldap_missing, opt_ldap_defaultfilter);
	    return -1;
	}

	/* Mapping from IMSP fields to LDAP attributes */
	mapping = option_getlist("", opt_ldap_attrmap, 1);
	if (mapping == NULL) {
	    config_error(err_ldap_missing, opt_ldap_attrmap);
	    return -1;
	}
	/* there must be an even number of items to form pairs */
	if (mapping->count == 0 || 
	    (mapping->count % 2) != 0 ||
	    (mapping->count / 2) > ATTRMAPSIZE) {
	  config_error(err_ldap_badvalue, opt_ldap_attrmap);
	  return -1;
	}

	/* step through the items in the map option,
	   assigning them alternatively to the "field" and "value"
	   halfs of the map structure.
	*/
	for (i = 0; i < mapping->count; i++) {
	  if (strcasecmp(mapping->item[i], "null") == 0)
	    value = NULL;
	  else
	    value = strdup(mapping->item[i]);
	  if (i % 2 == 0)
	    config.map[i / 2].field = value;
	  else
	    config.map[i / 2].attr  = value;

	  config.map[i / 2].append = NULL;
	}
	/* add a null terminator pair at the end */
	config.map[i / 2].field = NULL;
	config.map[i / 2].attr  = NULL;

	/* appendmap */
	mapping = option_getlist("", opt_ldap_appendmap, 1);
	if (mapping != NULL) {
	  if (mapping->count == 0 ||
	    (mapping->count % 2) != 0 ||
	    (mapping->count / 2) > ATTRMAPSIZE) {
	    config_error(err_ldap_badvalue, opt_ldap_appendmap);
	    return -1;
	  }
	  /*
	   * step through the items in the appendmap,
	   * assigning them to the "append" field of the
	   * map structure, where necessary
	   */
	  for (i = 0; i < mapping->count; i++) {
	    for (j = 0; config.map[j].field != NULL ; j++) {
	      if (strcmp(mapping->item[i], config.map[j].field) == 0) {
		i++;
		config.map[j].append = strdup(mapping->item[i]);
	      }
	    }
	  }
	}

	/* Secondary search settings, if applicable */
	value = option_get("", opt_ldap_secondary_searchbase, 1, NULL);
	if (value) {
	  secondaryconfig.searchbase = strdup(value);

	  /* Scope */
	  value = option_get("", opt_ldap_secondary_scope, 1, NULL);
	  if (value) {
	    if (strcasecmp(value, "subtree") == 0) {
	      secondaryconfig.scope = LDAP_SCOPE_SUBTREE;
	    } else if (strcasecmp(value, "base") == 0) {
	      secondaryconfig.scope = LDAP_SCOPE_BASE;
	    } else if (strcasecmp(value, "onelevel") == 0) {
	      secondaryconfig.scope = LDAP_SCOPE_ONELEVEL;
	    } else {
	      config_error(err_ldap_badvalue, opt_ldap_secondary_scope);
	      return -1;
	    }
	  } else {
	    secondaryconfig.scope = config.scope;
	  }
	  
	  /* LDAP Server Hostname */
	  value = option_get("", opt_ldap_secondary_ldaphost, 1, NULL);
	  if (value) {
	    secondaryconfig.ldaphost = strdup(value);
	  } else {
	    secondaryconfig.ldaphost = strdup(config.ldaphost);
	  }
	  
	  /* LDAP Server Port Number */
	  value = option_get("", opt_ldap_secondary_ldapport, 1);
	  if (value) {
	    secondaryconfig.ldapport = atoi(value);
	  } else {
	    secondaryconfig.ldapport = config.ldapport;
	  }
	  
	  /* Fullname Attribute */
	  value = option_get("", opt_ldap_secondary_fullnameattr, 1, NULL);
	  if (value) {
	    secondaryconfig.fullnameattr = strdup(value);
	  } else {
	    secondaryconfig.fullnameattr = strdup(config.fullnameattr);
	  }
	  
	  /* Unique Attribute */
	  value = option_get("", opt_ldap_secondary_uniqueattr, 1, NULL);
	  if (value) {
	    secondaryconfig.uniqueattr = strdup(value);
	  } else {
	    secondaryconfig.uniqueattr = strdup(config.uniqueattr);
	  }
	  
	  /* Default Search Filter */
	  value = option_get("", opt_ldap_secondary_defaultfilter, 1, NULL);
	  if (value) {
	    secondaryconfig.defaultfilter = strdup(value);
	  } else {
	    secondaryconfig.defaultfilter = strdup(config.defaultfilter);
	  }
	  
	  /* Mapping from IMSP fields to LDAP attributes */
	  mapping = option_getlist("", opt_ldap_secondary_attrmap, 1);
	  if (mapping == NULL) {
	    mapping = mapping;
	  }
	  /* there must be an even number of items to form pairs */
	  if (mapping->count == 0 || 
	      (mapping->count % 2) != 0 ||
	      (mapping->count / 2) > ATTRMAPSIZE) {
	    config_error(err_ldap_badvalue, opt_ldap_secondary_attrmap);
	    return -1;
	  }
	  
	  /* step through the items in the map option,
	     assigning them alternatively to the "field" and "value"
	     halfs of the map structure.
	  */
	  for (i = 0; i < mapping->count; i++) {
	    if (strcasecmp(mapping->item[i], "null") == 0)
	      value = NULL;
	    else
	      value = strdup(mapping->item[i]);
	    if (i % 2 == 0)
	      secondaryconfig.map[i / 2].field = value;
	    else
	      secondaryconfig.map[i / 2].attr  = value;

	    secondaryconfig.map[i / 2].append = NULL;
	  }
	  /* add a null terminator pair at the end */
	  secondaryconfig.map[i / 2].field = NULL;
	  secondaryconfig.map[i / 2].attr  = NULL;

	  /* appendmap */
	  mapping = option_getlist("", opt_ldap_secondary_appendmap, 1);
	  if (mapping != NULL) {
	    if (mapping->count == 0 ||
		(mapping->count % 2) != 0 ||
		(mapping->count / 2) > ATTRMAPSIZE) {
	      config_error(err_ldap_badvalue, opt_ldap_secondary_appendmap);
	      return -1;
	    }
	    /*
	     * step through the items in the appendmap,
	     * assigning them to the "append" field of the
	     * map structure, where necessary
	     */
	    for (i = 0; i < mapping->count; i++) {
	      for (j = 0; secondaryconfig.map[j].field != NULL ; j++) {
		if (strcmp(mapping->item[i], secondaryconfig.map[j].field) == 0) {
		  i++;
		  secondaryconfig.map[j].append = strdup(mapping->item[i]);
		}
	      }
	    }
	  }

	  secondaryconfig.configured = 1;
	} else {
	  /* no secondary search defined */
	}
        config.configured = 1;
    }
    
    return 0;
}
Пример #12
0
/**********************************
Compose the character select screen
**********************************/
item_t * scr_play_compose(context_t * ctx)
{
	int bg_red = 0;
	int bg_blue = 0;
	int bg_green = 0;
	char * map_filename;
	int layer_index = 0;
	char * old_sfx = NULL;

	option = option_get();

	if(item_list) {
		item_list_free(item_list);
		item_list = NULL;
	}

	if(ctx->map == NULL ) {
		if(context_update_from_file(ctx) == RET_NOK) {
			return NULL;
		}
	}

	if(init) {
		/* Register this character to receive server notifications */
		network_request_start(ctx,ctx->id);
		ui_play_init();
		init = false;
	}

	sdl_free_keycb();
	sdl_free_mousecb();
	sdl_add_mousecb(MOUSE_WHEEL_UP,cb_zoom);
	sdl_add_mousecb(MOUSE_WHEEL_DOWN,cb_unzoom);

	change_map = ctx->change_map;

	if( change_map == true ) {
		map_filename = strconcat( MAP_TABLE,"/",ctx->map,NULL);
		network_send_req_file(ctx,map_filename);
		free(map_filename);
		if(default_layer) {
			map_layer_delete(default_layer);
		}
		default_layer = map_layer_new(ctx->map,DEFAULT_LAYER,NULL);
	}

	if( default_layer && default_layer->active ) { // Make sure map data are available
		for(layer_index = 0; layer_index < MAX_LAYER; layer_index++) {
			compose_map_set(ctx,layer_index);
			compose_map_scenery(ctx,layer_index);
			compose_item(ctx,layer_index);
			compose_sprite(ctx,layer_index);
			compose_type(ctx,layer_index);
		}
		compose_map_button(ctx);
		compose_select(ctx);

		ui_play_compose(ctx,item_list);

		// force virtual coordinate on map change
		if( change_map == true ) {
			sdl_force_virtual_x(map_t2p_x(ctx->pos_tx,ctx->pos_ty,default_layer) + default_layer->col_width[ctx->pos_tx%default_layer->col_num]/2 + default_layer->row_width[ctx->pos_ty%default_layer->row_num]/2 );
			sdl_force_virtual_y(map_t2p_y(ctx->pos_tx,ctx->pos_ty,default_layer) + default_layer->col_height[ctx->pos_tx%default_layer->col_num]/2 + default_layer->row_height[ctx->pos_ty%default_layer->row_num]/2 );
		}
		// set virtual coordinate on the same map
		else {
			sdl_set_virtual_x(map_t2p_x(ctx->pos_tx,ctx->pos_ty,default_layer) + default_layer->col_width[ctx->pos_tx%default_layer->col_num]/2 + default_layer->row_width[ctx->pos_ty%default_layer->row_num]/2 );
			sdl_set_virtual_y(map_t2p_y(ctx->pos_tx,ctx->pos_ty,default_layer) + default_layer->col_height[ctx->pos_tx%default_layer->col_num]/2 + default_layer->row_height[ctx->pos_ty%default_layer->row_num]/2 );
		}
	}

	entry_read_int(MAP_TABLE,ctx->map,&bg_red,MAP_KEY_BG_RED,NULL);
	entry_read_int(MAP_TABLE,ctx->map,&bg_blue,MAP_KEY_BG_BLUE,NULL);
	entry_read_int(MAP_TABLE,ctx->map,&bg_green,MAP_KEY_BG_GREEN,NULL);
	SDL_SetRenderDrawColor(ctx->render, bg_red, bg_blue, bg_green, 255);

	old_sfx = sfx;
	sfx = NULL;

	entry_read_string(MAP_TABLE,ctx->map,&sfx,MAP_SFX,NULL);

	if(old_sfx)  {
		if( sfx ) {
			if( strcmp(old_sfx,sfx) ) {
				sfx_stop(ctx,old_sfx);
			}
		} else  { // sfx == NULL
			sfx_stop(ctx,old_sfx);
		}
		free(old_sfx);
	}

	if( sfx && sfx[0]!=0 ) {
		sfx_play(ctx,sfx,NO_RESTART);
	}

	return item_list;
}