- Cosmetic changes to db.
- Fixed the unused MAPINDEX_AUTOADD section in mapindex.c (mapindex.h wasn't being included) git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@9515 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
parent
628683cd41
commit
dd6a713c36
@ -3,6 +3,10 @@ Date Added
|
|||||||
AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK.
|
AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK.
|
||||||
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
|
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
|
||||||
|
|
||||||
|
2006/12/18
|
||||||
|
* Cosmetic changes to db.
|
||||||
|
* Fixed the unused MAPINDEX_AUTOADD section in mapindex.c (mapindex.h
|
||||||
|
wasn't being included) [FlavioJS]
|
||||||
2006/12/16
|
2006/12/16
|
||||||
* Moved packet_len_table values to packet_db[SERVER].
|
* Moved packet_len_table values to packet_db[SERVER].
|
||||||
* When an invalid packet_ver is found, all it's entries are discarted
|
* When an invalid packet_ver is found, all it's entries are discarted
|
||||||
|
596
src/common/db.c
596
src/common/db.c
File diff suppressed because it is too large
Load Diff
201
src/common/db.h
201
src/common/db.h
@ -23,8 +23,8 @@
|
|||||||
* HISTORY: *
|
* HISTORY: *
|
||||||
* 2.1 (Athena build #???#) - Portability fix *
|
* 2.1 (Athena build #???#) - Portability fix *
|
||||||
* - Fixed the portability of casting to union and added the functions *
|
* - Fixed the portability of casting to union and added the functions *
|
||||||
* {@link DBInterface#ensure(DBInterface,DBKey,DBCreateData,...)} and *
|
* {@link DB#ensure(DB,DBKey,DBCreateData,...)} and *
|
||||||
* {@link DBInterface#clear(DBInterface,DBApply,...)}. *
|
* {@link DB#clear(DB,DBApply,...)}. *
|
||||||
* 2.0 (Athena build 4859) - Transition version *
|
* 2.0 (Athena build 4859) - Transition version *
|
||||||
* - Almost everything recoded with a strategy similar to objects, *
|
* - Almost everything recoded with a strategy similar to objects, *
|
||||||
* database structure is maintained. *
|
* database structure is maintained. *
|
||||||
@ -51,11 +51,11 @@
|
|||||||
* DBOptions - Bitfield enumeration of database options. *
|
* DBOptions - Bitfield enumeration of database options. *
|
||||||
* DBKey - Union of used key types. *
|
* DBKey - Union of used key types. *
|
||||||
* DBApply - Format of functions applyed to the databases. *
|
* DBApply - Format of functions applyed to the databases. *
|
||||||
* DBMatcher - Format of matchers used in DBInterface->getall. *
|
* DBMatcher - Format of matchers used in DB::getall. *
|
||||||
* DBComparator - Format of the comparators used by the databases. *
|
* DBComparator - Format of the comparators used by the databases. *
|
||||||
* DBHasher - Format of the hashers used by the databases. *
|
* DBHasher - Format of the hashers used by the databases. *
|
||||||
* DBReleaser - Format of the releasers used by the databases. *
|
* DBReleaser - Format of the releasers used by the databases. *
|
||||||
* DBInterface - Structure of the interface of the database. *
|
* DB - Database interface. *
|
||||||
\*****************************************************************************/
|
\*****************************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -120,7 +120,7 @@ typedef enum {
|
|||||||
* @param DB_OPT_RELEASE_KEY Releases the key.
|
* @param DB_OPT_RELEASE_KEY Releases the key.
|
||||||
* @param DB_OPT_RELEASE_DATA Releases the data whenever an entry is removed
|
* @param DB_OPT_RELEASE_DATA Releases the data whenever an entry is removed
|
||||||
* from the database.
|
* from the database.
|
||||||
* WARNING: for funtions that return the data (like DBInterface->remove),
|
* WARNING: for funtions that return the data (like DB::remove),
|
||||||
* a dangling pointer will be returned.
|
* a dangling pointer will be returned.
|
||||||
* @param DB_OPT_RELEASE_BOTH Releases both key and data.
|
* @param DB_OPT_RELEASE_BOTH Releases both key and data.
|
||||||
* @param DB_OPT_ALLOW_NULL_KEY Allow NULL keys in the database.
|
* @param DB_OPT_ALLOW_NULL_KEY Allow NULL keys in the database.
|
||||||
@ -147,16 +147,11 @@ typedef enum {
|
|||||||
* @param str Type of key for DB_STRING and DB_ISTRING databases
|
* @param str Type of key for DB_STRING and DB_ISTRING databases
|
||||||
* @public
|
* @public
|
||||||
* @see #DBType
|
* @see #DBType
|
||||||
* @see #DBApply(DBKey,void *,va_list)
|
* @see DB#get
|
||||||
* @see #DBMatcher(DBKey,void *,va_list)
|
* @see DB#put
|
||||||
* @see #DBComparator(DBKey,DBKey,unsigned short)
|
* @see DB#remove
|
||||||
* @see #DBHasher(DBKey,unsigned short)
|
|
||||||
* @see #DBReleaser(DBKey,void *,DBRelease)
|
|
||||||
* @see DBInterface#get(DBInterface,DBKey)
|
|
||||||
* @see DBInterface#put(DBInterface,DBKey,void *)
|
|
||||||
* @see DBInterface#remove(DBInterface,DBKey)
|
|
||||||
*/
|
*/
|
||||||
typedef union {
|
typedef union dbkey {
|
||||||
int i;
|
int i;
|
||||||
unsigned int ui;
|
unsigned int ui;
|
||||||
unsigned char *str;//## TODO change to 'const char *'
|
unsigned char *str;//## TODO change to 'const char *'
|
||||||
@ -169,9 +164,8 @@ typedef union {
|
|||||||
* @param args Extra arguments of the funtion
|
* @param args Extra arguments of the funtion
|
||||||
* @return Data identified by the key to be put in the database
|
* @return Data identified by the key to be put in the database
|
||||||
* @public
|
* @public
|
||||||
* @see #DBKey
|
* @see DB#vensure
|
||||||
* @see DBInterface#vensure(DBInterface,DBKey,DBCreateData,va_list)
|
* @see DB#ensure
|
||||||
* @see DBInterface#ensure(DBInterface,DBKey,DBCreateData,...)
|
|
||||||
*/
|
*/
|
||||||
typedef void *(*DBCreateData)(DBKey key, va_list args);
|
typedef void *(*DBCreateData)(DBKey key, va_list args);
|
||||||
|
|
||||||
@ -185,11 +179,10 @@ typedef void *(*DBCreateData)(DBKey key, va_list args);
|
|||||||
* @param args Extra arguments of the funtion
|
* @param args Extra arguments of the funtion
|
||||||
* @return Value to be added up by the funtion that is applying this
|
* @return Value to be added up by the funtion that is applying this
|
||||||
* @public
|
* @public
|
||||||
* @see #DBKey
|
* @see DB#vforeach
|
||||||
* @see DBInterface#vforeach(DBInterface,DBApply,va_list)
|
* @see DB#foreach
|
||||||
* @see DBInterface#foreach(DBInterface,DBApply,...)
|
* @see DB#vdestroy
|
||||||
* @see DBInterface#vdestroy(DBInterface,DBApply,va_list)
|
* @see DB#destroy
|
||||||
* @see DBInterface#destroy(DBInterface,DBApply,...)
|
|
||||||
*/
|
*/
|
||||||
typedef int (*DBApply)(DBKey key, void *data, va_list args);
|
typedef int (*DBApply)(DBKey key, void *data, va_list args);
|
||||||
|
|
||||||
@ -202,8 +195,7 @@ typedef int (*DBApply)(DBKey key, void *data, va_list args);
|
|||||||
* @param args Extra arguments of the function
|
* @param args Extra arguments of the function
|
||||||
* @return 0 if a match, another number otherwise
|
* @return 0 if a match, another number otherwise
|
||||||
* @public
|
* @public
|
||||||
* @see #DBKey
|
* @see DB#getall
|
||||||
* @see DBInterface#getall(DBInterface,void **,unsigned int,DBMatcher,...)
|
|
||||||
*/
|
*/
|
||||||
typedef int (*DBMatcher)(DBKey key, void *data, va_list args);
|
typedef int (*DBMatcher)(DBKey key, void *data, va_list args);
|
||||||
|
|
||||||
@ -219,7 +211,6 @@ typedef int (*DBMatcher)(DBKey key, void *data, va_list args);
|
|||||||
* databases.
|
* databases.
|
||||||
* @return 0 if equal, negative if lower and positive if higher
|
* @return 0 if equal, negative if lower and positive if higher
|
||||||
* @public
|
* @public
|
||||||
* @see #DBKey
|
|
||||||
* @see #db_default_cmp(DBType)
|
* @see #db_default_cmp(DBType)
|
||||||
*/
|
*/
|
||||||
typedef int (*DBComparator)(DBKey key1, DBKey key2, unsigned short maxlen);
|
typedef int (*DBComparator)(DBKey key1, DBKey key2, unsigned short maxlen);
|
||||||
@ -234,7 +225,6 @@ typedef int (*DBComparator)(DBKey key1, DBKey key2, unsigned short maxlen);
|
|||||||
* databases.
|
* databases.
|
||||||
* @return Hash of the key
|
* @return Hash of the key
|
||||||
* @public
|
* @public
|
||||||
* @see #DBKey
|
|
||||||
* @see #db_default_hash(DBType)
|
* @see #db_default_hash(DBType)
|
||||||
*/
|
*/
|
||||||
typedef unsigned int (*DBHasher)(DBKey key, unsigned short maxlen);
|
typedef unsigned int (*DBHasher)(DBKey key, unsigned short maxlen);
|
||||||
@ -248,7 +238,6 @@ typedef unsigned int (*DBHasher)(DBKey key, unsigned short maxlen);
|
|||||||
* @param which What is being requested to be released
|
* @param which What is being requested to be released
|
||||||
* @public
|
* @public
|
||||||
* @see #DBRelease
|
* @see #DBRelease
|
||||||
* @see #DBKey
|
|
||||||
* @see #db_default_releaser(DBType,DBOptions)
|
* @see #db_default_releaser(DBType,DBOptions)
|
||||||
* @see #db_custom_release(DBRelease)
|
* @see #db_custom_release(DBRelease)
|
||||||
*/
|
*/
|
||||||
@ -258,21 +247,22 @@ typedef void (*DBReleaser)(DBKey key, void *data, DBRelease which);
|
|||||||
* Public interface of a database. Only contains funtions.
|
* Public interface of a database. Only contains funtions.
|
||||||
* All the functions take the interface as the first argument.
|
* All the functions take the interface as the first argument.
|
||||||
* @public
|
* @public
|
||||||
* @see DBInterface#get(DBInterface,DBKey)
|
* @see DB#get(DB,DBKey)
|
||||||
* @see DBInterface#getall(DBInterface,void **,unsigned int,DBMatch,...)
|
* @see DB#getall(DB,void **,unsigned int,DBMatch,...)
|
||||||
* @see DBInterface#vgetall(DBInterface,void **,unsigned int,DBMatch,va_list)
|
* @see DB#vgetall(DB,void **,unsigned int,DBMatch,va_list)
|
||||||
* @see DBInterface#put(DBInterface,DBKey,void *)
|
* @see DB#put(DB,DBKey,void *)
|
||||||
* @see DBInterface#remove(DBInterface,DBKey)
|
* @see DB#remove(DB,DBKey)
|
||||||
* @see DBInterface#foreach(DBInterface,DBApply,...)
|
* @see DB#foreach(DB,DBApply,...)
|
||||||
* @see DBInterface#vforeach(DBInterface,DBApply,va_list)
|
* @see DB#vforeach(DB,DBApply,va_list)
|
||||||
* @see DBInterface#destroy(DBInterface,DBApply,...)
|
* @see DB#destroy(DB,DBApply,...)
|
||||||
* @see DBInterface#destroy(DBInterface,DBApply,va_list)
|
* @see DB#destroy(DB,DBApply,va_list)
|
||||||
* @see DBInterface#size(DBInterface)
|
* @see DB#size(DB)
|
||||||
* @see DBInterface#type(DBInterface)
|
* @see DB#type(DB)
|
||||||
* @see DBInterface#options(DBInterface)
|
* @see DB#options(DB)
|
||||||
* @see #db_alloc(const char *,int,DBType,DBOptions,unsigned short)
|
* @see #db_alloc(const char *,int,DBType,DBOptions,unsigned short)
|
||||||
*/
|
*/
|
||||||
typedef struct dbt {
|
typedef struct dbt *DB;
|
||||||
|
struct dbt {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the data of the entry identifid by the key.
|
* Get the data of the entry identifid by the key.
|
||||||
@ -280,14 +270,12 @@ typedef struct dbt {
|
|||||||
* @param key Key that identifies the entry
|
* @param key Key that identifies the entry
|
||||||
* @return Data of the entry or NULL if not found
|
* @return Data of the entry or NULL if not found
|
||||||
* @protected
|
* @protected
|
||||||
* @see #DBKey
|
* @see #db_get(DB,DBKey)
|
||||||
* @see #DBInterface
|
|
||||||
* @see common\db.c#db_get(DBInterface,DBKey)
|
|
||||||
*/
|
*/
|
||||||
void *(*get)(struct dbt *dbi, DBKey key);
|
void *(*get)(struct dbt *dbi, DBKey key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Just calls {@link DBInterface#vgetall(DBInterface,void **,unsigned int,DBMatch,va_list)}.
|
* Just calls {@link DB#vgetall(DB,void **,unsigned int,DBMatch,va_list)}.
|
||||||
* Get the data of the entries matched by <code>match</code>.
|
* Get the data of the entries matched by <code>match</code>.
|
||||||
* It puts a maximum of <code>max</code> entries into <code>buf</code>.
|
* It puts a maximum of <code>max</code> entries into <code>buf</code>.
|
||||||
* If <code>buf</code> is NULL, it only counts the matches.
|
* If <code>buf</code> is NULL, it only counts the matches.
|
||||||
@ -301,12 +289,10 @@ typedef struct dbt {
|
|||||||
* @param ... Extra arguments for match
|
* @param ... Extra arguments for match
|
||||||
* @return The number of entries that matched
|
* @return The number of entries that matched
|
||||||
* @protected
|
* @protected
|
||||||
* @see #DBMatcher(DBKey key, void *data, va_list args)
|
* @see DB#vgetall
|
||||||
* @see #DBInterface
|
* @see #db_getall(DB,void **,unsigned int,DBMatch,...)
|
||||||
* @see DBInterface#vgetall(DBInterface,void **,unsigned int,DBMatch,va_list)
|
|
||||||
* @see common\db.c#db_getall(DBInterface,void **,unsigned int,DBMatch,...)
|
|
||||||
*/
|
*/
|
||||||
unsigned int (*getall)(struct dbt *dbi, void **buf, unsigned int max, DBMatcher match, ...);
|
unsigned int (*getall)(DB self, void **buf, unsigned int max, DBMatcher match, ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the data of the entries matched by <code>match</code>.
|
* Get the data of the entries matched by <code>match</code>.
|
||||||
@ -322,15 +308,13 @@ typedef struct dbt {
|
|||||||
* @param ... Extra arguments for match
|
* @param ... Extra arguments for match
|
||||||
* @return The number of entries that matched
|
* @return The number of entries that matched
|
||||||
* @protected
|
* @protected
|
||||||
* @see #DBMatcher(DBKey key, void *data, va_list args)
|
* @see DB#getall
|
||||||
* @see #DBInterface
|
* @see #db_vgetall(DB,void **,unsigned int,DBMatch,va_list)
|
||||||
* @see DBInterface#getall(DBInterface,void **,unsigned int,DBMatch,...)
|
|
||||||
* @see common\db.c#db_vgetall(DBInterface,void **,unsigned int,DBMatch,va_list)
|
|
||||||
*/
|
*/
|
||||||
unsigned int (*vgetall)(struct dbt *dbi, void **buf, unsigned int max, DBMatcher match, va_list args);
|
unsigned int (*vgetall)(DB self, void **buf, unsigned int max, DBMatcher match, va_list args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Just calls {@link common\db.h\DBInterface#vensure(DBInterface,DBKey,DBCreateData,va_list)}.
|
* Just calls {@link common\db.h\DB#vensure(DB,DBKey,DBCreateData,va_list)}.
|
||||||
* Get the data of the entry identified by the key.
|
* Get the data of the entry identified by the key.
|
||||||
* If the entry does not exist, an entry is added with the data returned by
|
* If the entry does not exist, an entry is added with the data returned by
|
||||||
* <code>create</code>.
|
* <code>create</code>.
|
||||||
@ -340,13 +324,10 @@ typedef struct dbt {
|
|||||||
* @param ... Extra arguments for create
|
* @param ... Extra arguments for create
|
||||||
* @return Data of the entry
|
* @return Data of the entry
|
||||||
* @protected
|
* @protected
|
||||||
* @see #DBKey
|
* @see DB#vensure(DB,DBKey,DBCreateData,va_list)
|
||||||
* @see #DBCreateData
|
* @see #db_ensure(DB,DBKey,DBCreateData,...)
|
||||||
* @see #DBInterface
|
|
||||||
* @see DBInterface#vensure(DBInterface,DBKey,DBCreateData,va_list)
|
|
||||||
* @see common\db.c#db_ensure(DBInterface,DBKey,DBCreateData,...)
|
|
||||||
*/
|
*/
|
||||||
void *(*ensure)(struct dbt *dbi, DBKey key, DBCreateData create, ...);
|
void *(*ensure)(DB self, DBKey key, DBCreateData create, ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the data of the entry identified by the key.
|
* Get the data of the entry identified by the key.
|
||||||
@ -358,13 +339,10 @@ typedef struct dbt {
|
|||||||
* @param args Extra arguments for create
|
* @param args Extra arguments for create
|
||||||
* @return Data of the entry
|
* @return Data of the entry
|
||||||
* @protected
|
* @protected
|
||||||
* @see #DBKey
|
* @see DB#ensure(DB,DBKey,DBCreateData,...)
|
||||||
* @see #DBCreateData
|
* @see #db_vensure(DB,DBKey,DBCreateData,va_list)
|
||||||
* @see #DBInterface
|
|
||||||
* @see DBInterface#ensure(DBInterface,DBKey,DBCreateData,...)
|
|
||||||
* @see common\db.c#db_vensure(DBInterface,DBKey,DBCreateData,va_list)
|
|
||||||
*/
|
*/
|
||||||
void *(*vensure)(struct dbt *dbi, DBKey key, DBCreateData create, va_list args);
|
void *(*vensure)(DB self, DBKey key, DBCreateData create, va_list args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put the data identified by the key in the database.
|
* Put the data identified by the key in the database.
|
||||||
@ -375,11 +353,9 @@ typedef struct dbt {
|
|||||||
* @param data Data to be put in the database
|
* @param data Data to be put in the database
|
||||||
* @return The previous data if the entry exists or NULL
|
* @return The previous data if the entry exists or NULL
|
||||||
* @protected
|
* @protected
|
||||||
* @see #DBKey
|
* @see #db_put(DB,DBKey,void *)
|
||||||
* @see #DBInterface
|
|
||||||
* @see common\db.c#db_put(DBInterface,DBKey,void *)
|
|
||||||
*/
|
*/
|
||||||
void *(*put)(struct dbt *dbi, DBKey key, void *data);
|
void *(*put)(DB self, DBKey key, void *data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove an entry from the database.
|
* Remove an entry from the database.
|
||||||
@ -389,14 +365,12 @@ typedef struct dbt {
|
|||||||
* @param key Key that identifies the entry
|
* @param key Key that identifies the entry
|
||||||
* @return The data of the entry or NULL if not found
|
* @return The data of the entry or NULL if not found
|
||||||
* @protected
|
* @protected
|
||||||
* @see #DBKey
|
* @see #db_remove(DB,DBKey)
|
||||||
* @see #DBInterface
|
|
||||||
* @see common\db.c#db_remove(DBInterface,DBKey)
|
|
||||||
*/
|
*/
|
||||||
void *(*remove)(struct dbt *dbi, DBKey key);
|
void *(*remove)(DB self, DBKey key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Just calls {@link DBInterface#vforeach(DBInterface,DBApply,va_list)}.
|
* Just calls {@link DB#vforeach(DB,DBApply,va_list)}.
|
||||||
* Apply <code>func</code> to every entry in the database.
|
* Apply <code>func</code> to every entry in the database.
|
||||||
* Returns the sum of values returned by func.
|
* Returns the sum of values returned by func.
|
||||||
* @param dbi Interface of the database
|
* @param dbi Interface of the database
|
||||||
@ -404,12 +378,10 @@ typedef struct dbt {
|
|||||||
* @param ... Extra arguments for func
|
* @param ... Extra arguments for func
|
||||||
* @return Sum of the values returned by func
|
* @return Sum of the values returned by func
|
||||||
* @protected
|
* @protected
|
||||||
* @see #DBInterface
|
* @see DB#vforeach
|
||||||
* @see #DBApply(DBKey,void *,va_list)
|
* @see #db_foreach(DB,DBApply,...)
|
||||||
* @see DBInterface#vforeach(DBInterface,DBApply,va_list)
|
|
||||||
* @see common\db.c#db_foreach(DBInterface,DBApply,...)
|
|
||||||
*/
|
*/
|
||||||
int (*foreach)(struct dbt *dbi, DBApply func, ...);
|
int (*foreach)(DB self, DBApply func, ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply <code>func</code> to every entry in the database.
|
* Apply <code>func</code> to every entry in the database.
|
||||||
@ -419,15 +391,13 @@ typedef struct dbt {
|
|||||||
* @param args Extra arguments for func
|
* @param args Extra arguments for func
|
||||||
* @return Sum of the values returned by func
|
* @return Sum of the values returned by func
|
||||||
* @protected
|
* @protected
|
||||||
* @see #DBApply(DBKey,void *,va_list)
|
* @see DB#foreach
|
||||||
* @see #DBInterface
|
* @see #db_vforeach(DB,DBApply,va_list)
|
||||||
* @see DBInterface#foreach(DBInterface,DBApply,...)
|
|
||||||
* @see common\db.c#db_vforeach(DBInterface,DBApply,va_list)
|
|
||||||
*/
|
*/
|
||||||
int (*vforeach)(struct dbt *dbi, DBApply func, va_list args);
|
int (*vforeach)(DB self, DBApply func, va_list args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Just calls {@link DBInterface#vclear(DBInterface,DBApply,va_list)}.
|
* Just calls {@link DB#vclear(DB,DBApply,va_list)}.
|
||||||
* Removes all entries from the database.
|
* Removes all entries from the database.
|
||||||
* Before deleting an entry, func is applyed to it.
|
* Before deleting an entry, func is applyed to it.
|
||||||
* Releases the key and the data.
|
* Releases the key and the data.
|
||||||
@ -437,12 +407,10 @@ typedef struct dbt {
|
|||||||
* @param ... Extra arguments for func
|
* @param ... Extra arguments for func
|
||||||
* @return Sum of values returned by func
|
* @return Sum of values returned by func
|
||||||
* @protected
|
* @protected
|
||||||
* @see #DBApply(DBKey,void *,va_list)
|
* @see DB#vclear
|
||||||
* @see #DBInterface
|
* @see #db_clear(DB,DBApply,...)
|
||||||
* @see DBInterface#vclear(DBInterface,DBApply,va_list)
|
|
||||||
* @see common\db.c#db_clear(DBInterface,DBApply,...)
|
|
||||||
*/
|
*/
|
||||||
int (*clear)(struct dbt *dbi, DBApply func, ...);
|
int (*clear)(DB self, DBApply func, ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all entries from the database.
|
* Removes all entries from the database.
|
||||||
@ -454,15 +422,13 @@ typedef struct dbt {
|
|||||||
* @param args Extra arguments for func
|
* @param args Extra arguments for func
|
||||||
* @return Sum of values returned by func
|
* @return Sum of values returned by func
|
||||||
* @protected
|
* @protected
|
||||||
* @see #DBApply(DBKey,void *,va_list)
|
* @see DB#clear
|
||||||
* @see #DBInterface
|
* @see #vclear(DB,DBApply,va_list)
|
||||||
* @see DBInterface#clear(DBInterface,DBApply,...)
|
|
||||||
* @see common\db.c#vclear(DBInterface,DBApply,va_list)
|
|
||||||
*/
|
*/
|
||||||
int (*vclear)(struct dbt *dbi, DBApply func, va_list args);
|
int (*vclear)(DB self, DBApply func, va_list args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Just calls {@link DBInterface#vdestroy(DBInterface,DBApply,va_list)}.
|
* Just calls {@link DB#vdestroy(DB,DBApply,va_list)}.
|
||||||
* Finalize the database, feeing all the memory it uses.
|
* Finalize the database, feeing all the memory it uses.
|
||||||
* Before deleting an entry, func is applyed to it.
|
* Before deleting an entry, func is applyed to it.
|
||||||
* Releases the key and the data.
|
* Releases the key and the data.
|
||||||
@ -474,12 +440,10 @@ typedef struct dbt {
|
|||||||
* @param ... Extra arguments for func
|
* @param ... Extra arguments for func
|
||||||
* @return Sum of values returned by func
|
* @return Sum of values returned by func
|
||||||
* @protected
|
* @protected
|
||||||
* @see #DBApply(DBKey,void *,va_list)
|
* @see DB#vdestroy
|
||||||
* @see #DBInterface
|
* @see #db_destroy(DB,DBApply,...)
|
||||||
* @see DBInterface#vdestroy(DBInterface,DBApply,va_list)
|
|
||||||
* @see common\db.c#db_destroy(DBInterface,DBApply,...)
|
|
||||||
*/
|
*/
|
||||||
int (*destroy)(struct dbt *dbi, DBApply func, ...);
|
int (*destroy)(DB self, DBApply func, ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finalize the database, feeing all the memory it uses.
|
* Finalize the database, feeing all the memory it uses.
|
||||||
@ -492,46 +456,39 @@ typedef struct dbt {
|
|||||||
* @param args Extra arguments for func
|
* @param args Extra arguments for func
|
||||||
* @return Sum of values returned by func
|
* @return Sum of values returned by func
|
||||||
* @protected
|
* @protected
|
||||||
* @see #DBInterface
|
* @see DB#destroy
|
||||||
* @see #DBApply(DBKey,void *,va_list)
|
* @see #db_vdestroy(DB,DBApply,va_list)
|
||||||
* @see DBInterface#destroy(DBInterface,DBApply,...)
|
|
||||||
* @see common\db.c#db_vdestroy(DBInterface,DBApply,va_list)
|
|
||||||
*/
|
*/
|
||||||
int (*vdestroy)(struct dbt *dbi, DBApply func, va_list args);
|
int (*vdestroy)(DB self, DBApply func, va_list args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the size of the database (number of items in the database).
|
* Return the size of the database (number of items in the database).
|
||||||
* @param dbi Interface of the database
|
* @param dbi Interface of the database
|
||||||
* @return Size of the database
|
* @return Size of the database
|
||||||
* @protected
|
* @protected
|
||||||
* @see #DBInterface
|
* @see #db_size(DB)
|
||||||
* @see common\db.c#db_size(DBInterface)
|
|
||||||
*/
|
*/
|
||||||
unsigned int (*size)(struct dbt *dbi);
|
unsigned int (*size)(DB self);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the type of the database.
|
* Return the type of the database.
|
||||||
* @param dbi Interface of the database
|
* @param dbi Interface of the database
|
||||||
* @return Type of the database
|
* @return Type of the database
|
||||||
* @protected
|
* @protected
|
||||||
* @see #DBType
|
* @see #db_type(DB)
|
||||||
* @see #DBInterface
|
|
||||||
* @see common\db.c#db_type(DBInterface)
|
|
||||||
*/
|
*/
|
||||||
DBType (*type)(struct dbt *dbi);
|
DBType (*type)(DB self);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the options of the database.
|
* Return the options of the database.
|
||||||
* @param dbi Interface of the database
|
* @param dbi Interface of the database
|
||||||
* @return Options of the database
|
* @return Options of the database
|
||||||
* @protected
|
* @protected
|
||||||
* @see #DBOptions
|
* @see #db_options(DB)
|
||||||
* @see #DBInterface
|
|
||||||
* @see common\db.c#db_options(DBInterface)
|
|
||||||
*/
|
*/
|
||||||
DBOptions (*options)(struct dbt *dbi);
|
DBOptions (*options)(DB self);
|
||||||
|
|
||||||
} *DBInterface;
|
};
|
||||||
|
|
||||||
//For easy access to the common functions.
|
//For easy access to the common functions.
|
||||||
#ifdef DB_MANUAL_CAST_TO_UNION
|
#ifdef DB_MANUAL_CAST_TO_UNION
|
||||||
@ -664,14 +621,14 @@ DBReleaser db_custom_release(DBRelease which);
|
|||||||
* @return The interface of the database
|
* @return The interface of the database
|
||||||
* @public
|
* @public
|
||||||
* @see #DBType
|
* @see #DBType
|
||||||
* @see #DBInterface
|
* @see #DB
|
||||||
* @see #db_default_cmp(DBType)
|
* @see #db_default_cmp(DBType)
|
||||||
* @see #db_default_hash(DBType)
|
* @see #db_default_hash(DBType)
|
||||||
* @see #db_default_release(DBType,DBOptions)
|
* @see #db_default_release(DBType,DBOptions)
|
||||||
* @see #db_fix_options(DBType,DBOptions)
|
* @see #db_fix_options(DBType,DBOptions)
|
||||||
* @see common\db.c#db_alloc(const char *,int,DBType,DBOptions,unsigned short)
|
* @see common\db.c#db_alloc(const char *,int,DBType,DBOptions,unsigned short)
|
||||||
*/
|
*/
|
||||||
DBInterface db_alloc(const char *file, int line, DBType type, DBOptions options, unsigned short maxlen);
|
DB db_alloc(const char *file, int line, DBType type, DBOptions options, unsigned short maxlen);
|
||||||
|
|
||||||
#ifdef DB_MANUAL_CAST_TO_UNION
|
#ifdef DB_MANUAL_CAST_TO_UNION
|
||||||
/**
|
/**
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
#include "mmo.h"
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "showmsg.h"
|
|
||||||
|
#include "mapindex.h"
|
||||||
|
#include "../common/mmo.h"
|
||||||
|
#include "../common/showmsg.h"
|
||||||
#include "../common/malloc.h"
|
#include "../common/malloc.h"
|
||||||
|
|
||||||
#define MAX_MAPINDEX 2000
|
#define MAX_MAPINDEX 2000
|
||||||
|
|
||||||
//Leave an extra char of space to hold the terminator, in case for the strncpy(mapindex_id2name()) calls.
|
//Leave an extra char of space to hold the terminator, in case for the strncpy(mapindex_id2name()) calls.
|
||||||
struct {
|
struct indexes {
|
||||||
char name[MAP_NAME_LENGTH+1]; //Stores map name
|
char name[MAP_NAME_LENGTH+1]; //Stores map name
|
||||||
int length; //Stores string length WITHOUT the extension for quick lookup.
|
int length; //Stores string length WITHOUT the extension for quick lookup.
|
||||||
} indexes[MAX_MAPINDEX];
|
} indexes[MAX_MAPINDEX];
|
||||||
@ -17,6 +19,52 @@ static unsigned short max_index = 0;
|
|||||||
|
|
||||||
char mapindex_cfgfile[80] = "db/map_index.txt";
|
char mapindex_cfgfile[80] = "db/map_index.txt";
|
||||||
|
|
||||||
|
/// Adds a map to the specified index
|
||||||
|
/// Returns 1 if successful, 0 oherwise
|
||||||
|
static int mapindex_addmap(int index, const char *name)
|
||||||
|
{
|
||||||
|
char map_name[1024];
|
||||||
|
char *ext;
|
||||||
|
int length;
|
||||||
|
|
||||||
|
if (index < 0 || index >= MAX_MAPINDEX) {
|
||||||
|
ShowError("(mapindex_add) Map index (%d) for \"%s\" out of range (max is %d)\n", index, name, MAX_MAPINDEX);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
snprintf(map_name, 1024, "%s", name);
|
||||||
|
map_name[1023] = 0;
|
||||||
|
length = strlen(map_name);
|
||||||
|
if (length > MAP_NAME_LENGTH) {
|
||||||
|
ShowError("(mapindex_add) Map name %s is too long. Maps are limited to %d characters.\n", map_name, MAP_NAME_LENGTH);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if ((ext = strstr(map_name, ".gat")) != NULL) { //Gat map
|
||||||
|
length = ext-map_name;
|
||||||
|
} else if ((ext = strstr(map_name, ".afm")) != NULL || (ext = strstr(map_name, ".af2")) != NULL) { //afm map
|
||||||
|
length = ext-map_name;
|
||||||
|
sprintf(ext, ".gat"); //Change the extension to gat
|
||||||
|
} else if ((ext = strstr(map_name, ".")) != NULL) { //Generic extension?
|
||||||
|
length = ext-map_name;
|
||||||
|
sprintf(ext, ".gat");
|
||||||
|
} else { //No extension?
|
||||||
|
length = strlen(map_name);
|
||||||
|
strcat(map_name, ".gat");
|
||||||
|
}
|
||||||
|
if (length > MAP_NAME_LENGTH - 4) {
|
||||||
|
ShowError("(mapindex_add) Adjusted Map name %s is too long. Maps are limited to %d characters.\n", map_name, MAP_NAME_LENGTH);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (indexes[index].length)
|
||||||
|
ShowWarning("(mapindex_add) Overriding index %d: map \"%s\" -> \"%s\"\n", indexes[index].name, map_name);
|
||||||
|
|
||||||
|
strncpy(indexes[index].name, map_name, MAP_NAME_LENGTH);
|
||||||
|
indexes[index].length = length;
|
||||||
|
if (max_index <= index)
|
||||||
|
max_index = index+1;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned short mapindex_name2id(char* name) {
|
unsigned short mapindex_name2id(char* name) {
|
||||||
//TODO: Perhaps use a db to speed this up? [Skotlex]
|
//TODO: Perhaps use a db to speed this up? [Skotlex]
|
||||||
int i;
|
int i;
|
||||||
@ -30,32 +78,20 @@ unsigned short mapindex_name2id(char* name) {
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
#ifdef MAPINDEX_AUTOADD
|
#ifdef MAPINDEX_AUTOADD
|
||||||
if (i < MAX_MAPINDEX) {
|
if( mapindex_addmap(i,name) )
|
||||||
char map_name[MAP_NAME_LENGTH+5];
|
{
|
||||||
length = strlen(name);
|
ShowDebug("mapindex_name2id: Auto-added map \"%s\" to position %d\n", indexes[i], i);
|
||||||
if (length > MAP_NAME_LENGTH)
|
|
||||||
return;
|
|
||||||
memcpy(map_name, name, length+1);
|
|
||||||
if ((ext = strstr(map_name, ".")) != NULL) {
|
|
||||||
length = ext-map_name;
|
|
||||||
sprintf(ext, ".gat");
|
|
||||||
} else { //No extension?
|
|
||||||
length = strlen(map_name);
|
|
||||||
strcat(map_name, ".gat");
|
|
||||||
}
|
|
||||||
if (length > MAP_NAME_LENGTH - 4)
|
|
||||||
return 0; //Can't be added.
|
|
||||||
strncpy(indexes[i].name, map_name, MAP_NAME_LENGTH);
|
|
||||||
indexes[i].length = strlen(map_name);
|
|
||||||
ShowDebug("mapindex_name2id: Added map \"%s\" to position %d\n", indexes[i], i);
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
#endif
|
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);
|
ShowDebug("mapindex_name2id: Map \"%s\" not found in index list!\n", name);
|
||||||
return 0;
|
return 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
char* mapindex_id2name(unsigned short id) {
|
const char* mapindex_id2name(unsigned short id) {
|
||||||
if (id > MAX_MAPINDEX || !indexes[id].length) {
|
if (id > MAX_MAPINDEX || !indexes[id].length) {
|
||||||
ShowDebug("mapindex_id2name: Requested name for non-existant map index [%d] in cache.\n", id);
|
ShowDebug("mapindex_id2name: Requested name for non-existant map index [%d] in cache.\n", id);
|
||||||
return indexes[0].name; //Theorically this should never happen, hence we return this string to prevent null pointer crashes.
|
return indexes[0].name; //Theorically this should never happen, hence we return this string to prevent null pointer crashes.
|
||||||
@ -66,9 +102,8 @@ char* mapindex_id2name(unsigned short id) {
|
|||||||
void mapindex_init(void) {
|
void mapindex_init(void) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char line[1024];
|
char line[1024];
|
||||||
char *ext;
|
|
||||||
int last_index = -1;
|
int last_index = -1;
|
||||||
int index, length;
|
int index;
|
||||||
char map_name[1024];
|
char map_name[1024];
|
||||||
|
|
||||||
malloc_tsetdword (&indexes, 0, sizeof (indexes));
|
malloc_tsetdword (&indexes, 0, sizeof (indexes));
|
||||||
@ -85,39 +120,7 @@ void mapindex_init(void) {
|
|||||||
case 1: //Map with no ID given, auto-assign
|
case 1: //Map with no ID given, auto-assign
|
||||||
index = last_index+1;
|
index = last_index+1;
|
||||||
case 2: //Map with ID given
|
case 2: //Map with ID given
|
||||||
if (index < 0 || index >= MAX_MAPINDEX) {
|
mapindex_addmap(index,map_name);
|
||||||
ShowError("(mapindex_init) Map index (%d) for \"%s\" out of range (max is %d)\n", index, map_name, MAX_MAPINDEX);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
length = strlen(map_name);
|
|
||||||
if (length > MAP_NAME_LENGTH) {
|
|
||||||
ShowError("(mapindex_init) Map name %s is too long. Maps are limited to %d characters.\n", map_name, MAP_NAME_LENGTH);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ((ext = strstr(map_name, ".gat")) != NULL) { //Gat map
|
|
||||||
length = ext-map_name;
|
|
||||||
} else if ((ext = strstr(map_name, ".afm")) != NULL || (ext = strstr(map_name, ".af2")) != NULL) { //afm map
|
|
||||||
length = ext-map_name;
|
|
||||||
sprintf(ext, ".gat"); //Change the extension to gat
|
|
||||||
} else if ((ext = strstr(map_name, ".")) != NULL) { //Generic extension?
|
|
||||||
length = ext-map_name;
|
|
||||||
sprintf(ext, ".gat");
|
|
||||||
} else { //No extension?
|
|
||||||
length = strlen(map_name);
|
|
||||||
strcat(map_name, ".gat");
|
|
||||||
}
|
|
||||||
if (length > MAP_NAME_LENGTH - 4) {
|
|
||||||
ShowError("(mapindex_init) Adjusted Map name %s is too long. Maps are limited to %d characters.\n", map_name, MAP_NAME_LENGTH);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (indexes[index].length)
|
|
||||||
ShowWarning("(mapindex_init) Overriding index %d: map \"%s\" -> \"%s\"\n", indexes[index].name, map_name);
|
|
||||||
|
|
||||||
strncpy(indexes[index].name, map_name, MAP_NAME_LENGTH);
|
|
||||||
indexes[index].length = length;
|
|
||||||
if (max_index <= index)
|
|
||||||
max_index = index+1;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
continue;
|
continue;
|
||||||
@ -129,4 +132,3 @@ void mapindex_init(void) {
|
|||||||
|
|
||||||
void mapindex_final(void) {
|
void mapindex_final(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
extern char mapindex_cfgfile[80];
|
extern char mapindex_cfgfile[80];
|
||||||
|
|
||||||
//whether to enable auto-adding of maps during run. Not so secure as the map indexes will vary!
|
//whether to enable auto-adding of maps during run. Not so secure as the map indexes will vary!
|
||||||
#define MAPINDEX_AUTOADD
|
// disabled - since mapindex.h wasn't included in mapindex.c it never got enabled anyway... [FlavioJS]
|
||||||
|
//#define MAPINDEX_AUTOADD
|
||||||
|
|
||||||
//Some definitions for the mayor city maps.
|
//Some definitions for the mayor city maps.
|
||||||
#define MAP_PRONTERA "prontera.gat"
|
#define MAP_PRONTERA "prontera.gat"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user