diff options
author | shennetsind <ind@henn.et> | 2013-05-04 17:22:57 -0300 |
---|---|---|
committer | shennetsind <ind@henn.et> | 2013-05-04 17:22:57 -0300 |
commit | 18b1965ce16909613f0a53515d40553742082ce2 (patch) | |
tree | c17d031f20d140f289113a5e632eb551961ad475 /src | |
parent | ad9a13be6ef115de1d5e124283a1d63a0bc5cd4d (diff) | |
download | hercules-18b1965ce16909613f0a53515d40553742082ce2.tar.gz hercules-18b1965ce16909613f0a53515d40553742082ce2.tar.bz2 hercules-18b1965ce16909613f0a53515d40553742082ce2.tar.xz hercules-18b1965ce16909613f0a53515d40553742082ce2.zip |
mapindex update
Fixed a mapindex_name2id problem that'd persistently not fix a broken mapindex data (e.g. char save/last map data being incorrect). It'll now align it to MAP_DEFAULT when such error occurs.
Also speeded up mapindex_name2id queries, replaced the loop by the red-black-tree db lookup.
Special Thanks to yommy~!
Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src')
-rw-r--r-- | src/char/char.c | 16 | ||||
-rw-r--r-- | src/common/mapindex.c | 58 | ||||
-rw-r--r-- | src/common/mapindex.h | 13 |
3 files changed, 51 insertions, 36 deletions
diff --git a/src/char/char.c b/src/char/char.c index ba3179ef9..d07995cc1 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -1170,6 +1170,18 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything p->last_point.map = mapindex_name2id(last_map); p->save_point.map = mapindex_name2id(save_map); + if( p->last_point.map == 0 ) { + p->last_point.map = strdb_iget(mapindex_db, MAP_DEFAULT); + p->last_point.x = MAP_DEFAULT_X; + p->last_point.y = MAP_DEFAULT_Y; + } + + if( p->save_point.map == 0 ) { + p->save_point.map = strdb_iget(mapindex_db, MAP_DEFAULT); + p->save_point.x = MAP_DEFAULT_X; + p->save_point.y = MAP_DEFAULT_Y; + } + strcat(t_msg, " status"); if (!load_everything) // For quick selection of data when displaying the char menu @@ -1188,8 +1200,7 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything || SQL_ERROR == SqlStmt_BindColumn(stmt, 2, SQLDT_SHORT, &tmp_point.y, 0, NULL, NULL) ) SqlStmt_ShowDebug(stmt); - for( i = 0; i < MAX_MEMOPOINTS && SQL_SUCCESS == SqlStmt_NextRow(stmt); ++i ) - { + for( i = 0; i < MAX_MEMOPOINTS && SQL_SUCCESS == SqlStmt_NextRow(stmt); ++i ) { tmp_point.map = mapindex_name2id(point_map); memcpy(&p->memo_point[i], &tmp_point, sizeof(tmp_point)); } @@ -3294,7 +3305,6 @@ int parse_frommap(int fd) WFIFOW(fd,0) = 0x2b24; WFIFOSET(fd,2); RFIFOSKIP(fd,2); - ShowDebug("Received 2b23, sending 2b24\n"); break; case 0x2b26: // auth request from map-server diff --git a/src/common/mapindex.c b/src/common/mapindex.c index 6af5f134f..336368604 100644 --- a/src/common/mapindex.c +++ b/src/common/mapindex.c @@ -6,6 +6,7 @@ #include "../common/showmsg.h" #include "../common/malloc.h" #include "../common/strlib.h" +#include "../common/db.h" #include "mapindex.h" #include <string.h> @@ -21,11 +22,9 @@ int max_index = 0; char mapindex_cfgfile[80] = "db/map_index.txt"; #define mapindex_exists(id) (indexes[id].name[0] != '\0') - /// Retrieves the map name from 'string' (removing .gat extension if present). /// Result gets placed either into 'buf' or in a static local buffer. -const char* mapindex_getmapname(const char* string, char* output) -{ +const char* mapindex_getmapname(const char* string, char* output) { static char buf[MAP_NAME_LENGTH]; char* dest = (output != NULL) ? output : buf; @@ -46,8 +45,7 @@ const char* mapindex_getmapname(const char* string, char* output) /// Retrieves the map name from 'string' (adding .gat extension if not already present). /// Result gets placed either into 'buf' or in a static local buffer. -const char* mapindex_getmapname_ext(const char* string, char* output) -{ +const char* mapindex_getmapname_ext(const char* string, char* output) { static char buf[MAP_NAME_LENGTH_EXT]; char* dest = (output != NULL) ? output : buf; @@ -76,13 +74,11 @@ const char* mapindex_getmapname_ext(const char* string, char* output) /// Adds a map to the specified index /// Returns 1 if successful, 0 oherwise -int mapindex_addmap(int index, const char* name) -{ +int mapindex_addmap(int index, const char* name) { char map_name[MAP_NAME_LENGTH]; if (index == -1){ - for (index = 1; index < max_index; index++) - { + for (index = 1; index < max_index; index++) { //if (strcmp(indexes[index].name,"#CLEARED#")==0) if (indexes[index].name[0] == '\0') break; @@ -106,29 +102,28 @@ int mapindex_addmap(int index, const char* name) return 0; } - if (mapindex_exists(index)) + if (mapindex_exists(index)) { ShowWarning("(mapindex_add) Overriding index %d: map \"%s\" -> \"%s\"\n", index, indexes[index].name, map_name); + strdb_remove(mapindex_db, indexes[index].name); + } safestrncpy(indexes[index].name, map_name, MAP_NAME_LENGTH); + strdb_iput(mapindex_db, map_name, index); if (max_index <= index) max_index = index+1; return index; } -unsigned short mapindex_name2id(const char* name) -{ - //TODO: Perhaps use a db to speed this up? [Skotlex] +unsigned short mapindex_name2id(const char* name) { int i; - char map_name[MAP_NAME_LENGTH]; + mapindex_getmapname(name, map_name); - for (i = 1; i < max_index; i++) - { - if (strcmpi(indexes[i].name,map_name)==0) - return i; - } + if( (i = strdb_iget(mapindex_db, name)) ) + return i; + ShowDebug("mapindex_name2id: Map \"%s\" not found in index list!\n", map_name); return 0; } @@ -141,27 +136,24 @@ const char* mapindex_id2name_sub(unsigned short id,const char *file, int line, c return indexes[id].name; } -void mapindex_init(void) -{ +void mapindex_init(void) { FILE *fp; char line[1024]; int last_index = -1; int index; - char map_name[1024]; + char map_name[12]; - memset (&indexes, 0, sizeof (indexes)); - fp=fopen(mapindex_cfgfile,"r"); - if(fp==NULL){ + 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. } - while(fgets(line, sizeof(line), fp)) - { + memset (&indexes, 0, sizeof (indexes)); + mapindex_db = strdb_alloc(DB_RELEASE_KEY, MAP_NAME_LENGTH); + while(fgets(line, sizeof(line), fp)) { if(line[0] == '/' && line[1] == '/') continue; - switch (sscanf(line, "%1023s\t%d", map_name, &index)) - { + switch (sscanf(line, "%12s\t%d", map_name, &index)) { case 1: //Map with no ID given, auto-assign index = last_index+1; case 2: //Map with ID given @@ -173,6 +165,10 @@ void mapindex_init(void) last_index = index; } fclose(fp); + + if( !strdb_iget(mapindex_db, MAP_DEFAULT) ) { + ShowError("mapindex_init: MAP_DEFAULT '%s' not found in cache! update mapindex.h MAP_DEFAULT var!!!\n",MAP_DEFAULT); + } } int mapindex_removemap(int index){ @@ -180,6 +176,6 @@ int mapindex_removemap(int index){ return 0; } -void mapindex_final(void) -{ +void mapindex_final(void) { + db_destroy(mapindex_db); } diff --git a/src/common/mapindex.h b/src/common/mapindex.h index 4c0641c56..d35d9899c 100644 --- a/src/common/mapindex.h +++ b/src/common/mapindex.h @@ -1,9 +1,18 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #ifndef _MAPINDEX_H_ #define _MAPINDEX_H_ +#include "../common/db.h" + +/* when a map index search fails, return results from what map? default:prontera */ +#define MAP_DEFAULT "prontera" +#define MAP_DEFAULT_X 150 +#define MAP_DEFAULT_Y 150 +DBMap *mapindex_db; + //File in charge of assigning a numberic ID to each map in existance for space saving when passing map info between servers. extern char mapindex_cfgfile[80]; |