Esempio n. 1
0
void mapindex_init(void)
{
	FILE *fp;
	char line[1024];
	int last_index = -1;
	int index;
	char map_name[1024];
	
	memset (&indexes, 0, sizeof (indexes));
	fp=fopen(mapindex_cfgfile,"r");
	if(fp==NULL){
		ShowFatalError("Unable to read mapindex config file %s!\n", mapindex_cfgfile);
		exit(EXIT_FAILURE); //Server can't really run without this file.
	}
	while(fgets(line, sizeof(line), fp))
	{
		if(line[0] == '/' && line[1] == '/')
			continue;

		switch (sscanf(line, "%1023s\t%d", map_name, &index))
		{
			case 1: //Map with no ID given, auto-assign
				index = last_index+1;
			case 2: //Map with ID given
				mapindex_addmap(index,map_name);
				break;
			default:
				continue;
		}
		last_index = index;
	}
	fclose(fp);
}
Esempio n. 2
0
void mapindex_init(void) {
	FILE *fp;
	char line[1024];
	int last_index = -1;
	int index;
	char map_name[MAP_NAME_LENGTH];

	if( ( fp = fopen(mapindex_cfgfile,"r") ) == NULL ){
		ShowFatalError("Unable to read mapindex config file %s!\n", mapindex_cfgfile);
		exit(EXIT_FAILURE); //Server can't really run without this file.
	}
	memset (&indexes, 0, sizeof (indexes));
	mapindex_db = strdb_alloc(DB_OPT_DUP_KEY, MAP_NAME_LENGTH);
	while(fgets(line, sizeof(line), fp)) {
		if(line[0] == '/' && line[1] == '/')
			continue;

		switch (sscanf(line, "%11s\t%d", map_name, &index)) {
			case 1: //Map with no ID given, auto-assign
				index = last_index+1;
			case 2: //Map with ID given
				mapindex_addmap(index,map_name);
				break;
			default:
				continue;
		}
		last_index = index;
	}
	fclose(fp);

	if( !strdb_iget(mapindex_db, MAP_DEFAULT) ) {
		ShowError("mapindex_init: MAP_DEFAULT '%s' not found in cache! Update MAP_DEFAULT in mapindex.h!\n",MAP_DEFAULT);
	}
}
Esempio n. 3
0
unsigned short mapindex_name2id(const char* name)
{
	//TODO: Perhaps use a db to speed this up? [Skotlex]
	int i;

	char map_name[MAP_NAME_LENGTH];
	mapindex_getmapname(name, map_name);

	for (i = 1; i < max_index; i++)
	{
		if (strcmp(indexes[i].name,map_name)==0)
			return i;
	}
#ifdef MAPINDEX_AUTOADD
	if( mapindex_addmap(i,map_name) )
	{
		ShowDebug("mapindex_name2id: Auto-added map \"%s\" to position %d\n", map_name, i);
		return i;
	}
	ShowWarning("mapindex_name2id: Failed to auto-add map \"%s\" to position %d!\n", map_name, i);
	return 0;
#else
	ShowDebug("mapindex_name2id: Map \"%s\" not found in index list!\n", map_name);
	return 0;
#endif
}
Esempio n. 4
0
unsigned short mapindex_name2id(const char* name) {
	//TODO: Perhaps use a db to speed this up? [Skotlex]
	int i;
	int length = strlen(name);
	char *ext = strstr(name, ".");
	if (ext)
		length = ext-name; //Base map-name length without the extension.
	for (i = 1; i < max_index; i++)
	{
		if (indexes[i].length == length && strncmp(indexes[i].name,name,length)==0)
			return i;
	}
#ifdef MAPINDEX_AUTOADD
	if( mapindex_addmap(i,name) )
	{
		ShowDebug("mapindex_name2id: Auto-added map \"%s\" to position %d\n", indexes[i], i);
		return i;
	}
	ShowWarning("mapindex_name2id: Failed to auto-add map \"%s\" to position %d!\n", name, i);
	return 0;
#else
	ShowDebug("mapindex_name2id: Map \"%s\" not found in index list!\n", name);
	return 0;
#endif
}
Esempio n. 5
0
void mapindex_init(void) {
	FILE *fp;
	char line[1024];
	int last_index = -1;
	int index;
	char map_name[MAP_NAME_LENGTH];
	char path[255];
	const char* mapindex_cfgfile[] = {
		"map_index.txt",
		DBIMPORT"/map_index.txt"
	};

	memset (&indexes, 0, sizeof (indexes));
	mapindex_db = strdb_alloc(DB_OPT_DUP_KEY, MAP_NAME_LENGTH);

	for( size_t i = 0; i < ARRAYLENGTH(mapindex_cfgfile); i++ ){
		sprintf( path, "%s/%s", db_path, mapindex_cfgfile[i] );

		if( ( fp = fopen( path, "r" ) ) == NULL ){
			// It is only fatal if it is the main file
			if( i == 0 ){
				ShowFatalError("Unable to read mapindex config file %s!\n", path );
				exit(EXIT_FAILURE); //Server can't really run without this file.
			}else{
				ShowWarning("Unable to read mapindex config file %s!\n", path );
				break;
			}
		}

		while(fgets(line, sizeof(line), fp)) {
			if(line[0] == '/' && line[1] == '/')
				continue;

			switch (sscanf(line, "%11s\t%d", map_name, &index)) {
				case 1: //Map with no ID given, auto-assign
					index = last_index+1;
				case 2: //Map with ID given
					mapindex_addmap(index,map_name);
					break;
				default:
					continue;
			}
			last_index = index;
		}
		fclose(fp);
	}
}
Esempio n. 6
0
/*--------------------------------------
 * Add a map to the instance using src map "name"
 *--------------------------------------*/
int instance_add_map(const char *name, int instance_id, bool usebasename)
{
	int m = map_mapname2mapid(name), i, im = -1;
	size_t num_cell, size;

	if( m < 0 )
		return -1; // source map not found

	if( !instance_is_valid(instance_id) )
	{
		ShowError("instance_add_map: trying to attach '%s' map to non-existing instance %d.\n", name, instance_id);
		return -1;
	}
	if( instance[instance_id].num_map >= MAX_MAP_PER_INSTANCE )
	{
		ShowError("instance_add_map: trying to add '%s' map to instance %d (%s) failed. Please increase MAX_MAP_PER_INSTANCE.\n", name, instance_id, instance[instance_id].name);
		return -2;
	}
	if( map[m].instance_id != 0 )
	{ // Source map already belong to a Instance.
		ShowError("instance_add_map: trying to instance already instanced map %s.\n", name);
		return -4;
	}

	ARR_FIND( instance_start, map_num, i, !map[i].name[0] ); // Searching for a Free Map
	if( i < map_num ) im = i; // Unused map found (old instance)
	else if( map_num - 1 >= MAX_MAP_PER_SERVER )
	{ // No more free maps
		ShowError("instance_add_map: no more free space to create maps on this server.\n");
		return -5;
	}
	else im = map_num++; // Using next map index

	memcpy( &map[im], &map[m], sizeof(struct map_data) ); // Copy source map
	snprintf(map[im].name, MAP_NAME_LENGTH, (usebasename ? "%.3d#%s" : "%.3d%s"), instance_id, name); // Generate Name for Instance Map
	map[im].index = mapindex_addmap(-1, map[im].name); // Add map index

	if( !map[im].index )
	{
		map[im].name[0] = '\0';
		ShowError("instance_add_map: no more free map indexes.\n");
		return -3; // No free map index
	}

	// Reallocate cells
	num_cell = map[im].xs * map[im].ys;
	CREATE( map[im].cell, struct mapcell, num_cell );
	memcpy( map[im].cell, map[m].cell, num_cell * sizeof(struct mapcell) );

	size = map[im].bxs * map[im].bys * sizeof(struct block_list*);
	map[im].block = (struct block_list**)aCalloc(size, 1);
	map[im].block_mob = (struct block_list**)aCalloc(size, 1);

	memset(map[im].npc, 0x00, sizeof(map[i].npc));
	map[im].npc_num = 0;

	memset(map[im].moblist, 0x00, sizeof(map[im].moblist));
	map[im].mob_delete_timer = INVALID_TIMER;

	map[im].m = im;
	map[im].instance_id = instance_id;
	map[im].instance_src_map = m;
	map[m].flag.src4instance = 1; // Flag this map as a src map for instances

	instance[instance_id].map[instance[instance_id].num_map++] = im; // Attach to actual instance
	map_addmap2db(&map[im]);

	return im;
}