summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2014-01-11 14:02:59 -0200
committershennetsind <ind@henn.et>2014-01-11 14:02:59 -0200
commit82b583b5ef4e729ad2c3c74b26adce16a145605a (patch)
tree5bb20b90edd899b06abe9853dba06383a9379c06 /src/common
parent56649bda4b2f62cf42847830546b5856234b3178 (diff)
downloadhercules-82b583b5ef4e729ad2c3c74b26adce16a145605a.tar.gz
hercules-82b583b5ef4e729ad2c3c74b26adce16a145605a.tar.bz2
hercules-82b583b5ef4e729ad2c3c74b26adce16a145605a.tar.xz
hercules-82b583b5ef4e729ad2c3c74b26adce16a145605a.zip
Hercules 1st 2014 MegaPatch
http://hercules.ws/board/topic/3886-hercules-1st-2014-megapatch/ Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/common')
-rw-r--r--src/common/db.c175
-rw-r--r--src/common/db.h124
-rw-r--r--src/common/mmo.h41
-rw-r--r--src/common/socket.c4
4 files changed, 270 insertions, 74 deletions
diff --git a/src/common/db.c b/src/common/db.c
index efe7ca8b2..ddfb032d4 100644
--- a/src/common/db.c
+++ b/src/common/db.c
@@ -47,6 +47,7 @@
* - create a db that organizes itself by splaying
*
* HISTORY:
+ * 2013/08/25 - Added int64/uint64 support for keys [Ind/Hercules]
* 2013/04/27 - Added ERS to speed up iterator memory allocation [Ind/Hercules]
* 2012/03/09 - Added enum for data types (int, uint, void*)
* 2008/02/19 - Fixed db_obj_get not handling deleted entries correctly.
@@ -236,10 +237,14 @@ static struct db_stats {
uint32 db_uint_alloc;
uint32 db_string_alloc;
uint32 db_istring_alloc;
+ uint32 db_int64_alloc;
+ uint32 db_uint64_alloc;
uint32 db_int_destroy;
uint32 db_uint_destroy;
uint32 db_string_destroy;
uint32 db_istring_destroy;
+ uint32 db_int64_destroy;
+ uint32 db_uint64_destroy;
// Function usage counters
uint32 db_rotate_left;
uint32 db_rotate_right;
@@ -256,10 +261,14 @@ static struct db_stats {
uint32 db_uint_cmp;
uint32 db_string_cmp;
uint32 db_istring_cmp;
+ uint32 db_int64_cmp;
+ uint32 db_uint64_cmp;
uint32 db_int_hash;
uint32 db_uint_hash;
uint32 db_string_hash;
uint32 db_istring_hash;
+ uint32 db_int64_hash;
+ uint32 db_uint64_hash;
uint32 db_release_nothing;
uint32 db_release_key;
uint32 db_release_data;
@@ -298,6 +307,8 @@ static struct db_stats {
uint32 db_i2key;
uint32 db_ui2key;
uint32 db_str2key;
+ uint32 db_i642key;
+ uint32 db_ui642key;
uint32 db_i2data;
uint32 db_ui2data;
uint32 db_ptr2data;
@@ -830,10 +841,14 @@ static void db_free_unlock(DBMap_impl* db)
* db_uint_cmp - Default comparator for DB_UINT databases. *
* db_string_cmp - Default comparator for DB_STRING databases. *
* db_istring_cmp - Default comparator for DB_ISTRING databases. *
+ * db_int64_cmp - Default comparator for DB_INT64 databases. *
+ * db_uint64_cmp - Default comparator for DB_UINT64 databases. *
* db_int_hash - Default hasher for DB_INT databases. *
* db_uint_hash - Default hasher for DB_UINT databases. *
* db_string_hash - Default hasher for DB_STRING databases. *
* db_istring_hash - Default hasher for DB_ISTRING databases. *
+ * db_int64_hash - Default hasher for DB_INT64 databases. *
+ * db_uint64_hash - Default hasher for DB_UINT64 databases. *
* db_release_nothing - Releaser that releases nothing. *
* db_release_key - Releaser that only releases the key. *
* db_release_data - Releaser that only releases the data. *
@@ -921,6 +936,51 @@ static int db_istring_cmp(DBKey key1, DBKey key2, unsigned short maxlen)
}
/**
+ * Default comparator for DB_INT64 databases.
+ * Compares key1 to key2.
+ * Return 0 if equal, negative if lower and positive if higher.
+ * <code>maxlen</code> is ignored.
+ * @param key1 Key to be compared
+ * @param key2 Key being compared to
+ * @param maxlen Maximum length of the key to hash
+ * @return 0 if equal, negative if lower and positive if higher
+ * @see DBType#DB_INT64
+ * @see #DBComparator
+ * @see #db_default_cmp(DBType)
+ */
+static int db_int64_cmp(DBKey key1, DBKey key2, unsigned short maxlen)
+{
+ (void)maxlen;//not used
+ DB_COUNTSTAT(db_int64_cmp);
+ if (key1.i64 < key2.i64) return -1;
+ if (key1.i64 > key2.i64) return 1;
+ return 0;
+}
+
+/**
+ * Default comparator for DB_UINT64 databases.
+ * Compares key1 to key2.
+ * Return 0 if equal, negative if lower and positive if higher.
+ * <code>maxlen</code> is ignored.
+ * @param key1 Key to be compared
+ * @param key2 Key being compared to
+ * @param maxlen Maximum length of the key to hash
+ * @return 0 if equal, negative if lower and positive if higher
+ * @see DBType#DB_UINT64
+ * @see #DBComparator
+ * @see #db_default_cmp(DBType)
+ */
+static int db_uint64_cmp(DBKey key1, DBKey key2, unsigned short maxlen)
+{
+ (void)maxlen;//not used
+ DB_COUNTSTAT(db_uint64_cmp);
+ if (key1.ui64 < key2.ui64) return -1;
+ if (key1.ui64 > key2.ui64) return 1;
+ return 0;
+}
+
+
+/**
* Default hasher for DB_INT databases.
* Returns the value of the key as an unsigned int.
* <code>maxlen</code> is ignored.
@@ -931,11 +991,11 @@ static int db_istring_cmp(DBKey key1, DBKey key2, unsigned short maxlen)
* @see #DBHasher
* @see #db_default_hash(DBType)
*/
-static unsigned int db_int_hash(DBKey key, unsigned short maxlen)
+static uint64 db_int_hash(DBKey key, unsigned short maxlen)
{
(void)maxlen;//not used
DB_COUNTSTAT(db_int_hash);
- return (unsigned int)key.i;
+ return (uint64)key.i;
}
/**
@@ -949,11 +1009,11 @@ static unsigned int db_int_hash(DBKey key, unsigned short maxlen)
* @see #DBHasher
* @see #db_default_hash(DBType)
*/
-static unsigned int db_uint_hash(DBKey key, unsigned short maxlen)
+static uint64 db_uint_hash(DBKey key, unsigned short maxlen)
{
(void)maxlen;//not used
DB_COUNTSTAT(db_uint_hash);
- return key.ui;
+ return (uint64)key.ui;
}
/**
@@ -965,7 +1025,7 @@ static unsigned int db_uint_hash(DBKey key, unsigned short maxlen)
* @see #DBHasher
* @see #db_default_hash(DBType)
*/
-static unsigned int db_string_hash(DBKey key, unsigned short maxlen)
+static uint64 db_string_hash(DBKey key, unsigned short maxlen)
{
const char *k = key.str;
unsigned int hash = 0;
@@ -980,7 +1040,7 @@ static unsigned int db_string_hash(DBKey key, unsigned short maxlen)
break;
}
- return hash;
+ return (uint64)hash;
}
/**
@@ -991,7 +1051,7 @@ static unsigned int db_string_hash(DBKey key, unsigned short maxlen)
* @see DBType#DB_ISTRING
* @see #db_default_hash(DBType)
*/
-static unsigned int db_istring_hash(DBKey key, unsigned short maxlen)
+static uint64 db_istring_hash(DBKey key, unsigned short maxlen)
{
const char *k = key.str;
unsigned int hash = 0;
@@ -1006,7 +1066,43 @@ static unsigned int db_istring_hash(DBKey key, unsigned short maxlen)
break;
}
- return hash;
+ return (uint64)hash;
+}
+
+/**
+ * Default hasher for DB_INT64 databases.
+ * Returns the value of the key as an unsigned int.
+ * <code>maxlen</code> is ignored.
+ * @param key Key to be hashed
+ * @param maxlen Maximum length of the key to hash
+ * @return hash of the key
+ * @see DBType#DB_INT64
+ * @see #DBHasher
+ * @see #db_default_hash(DBType)
+ */
+static uint64 db_int64_hash(DBKey key, unsigned short maxlen)
+{
+ (void)maxlen;//not used
+ DB_COUNTSTAT(db_int64_hash);
+ return (uint64)key.i64;
+}
+
+/**
+ * Default hasher for DB_UINT64 databases.
+ * Just returns the value of the key.
+ * <code>maxlen</code> is ignored.
+ * @param key Key to be hashed
+ * @param maxlen Maximum length of the key to hash
+ * @return hash of the key
+ * @see DBType#DB_UINT64
+ * @see #DBHasher
+ * @see #db_default_hash(DBType)
+ */
+static uint64 db_uint64_hash(DBKey key, unsigned short maxlen)
+{
+ (void)maxlen;//not used
+ DB_COUNTSTAT(db_uint64_hash);
+ return key.ui64;
}
/**
@@ -2122,6 +2218,8 @@ static int db_obj_vdestroy(DBMap* self, DBApply func, va_list args)
case DB_UINT: DB_COUNTSTAT(db_uint_destroy); break;
case DB_STRING: DB_COUNTSTAT(db_string_destroy); break;
case DB_ISTRING: DB_COUNTSTAT(db_istring_destroy); break;
+ case DB_INT64: DB_COUNTSTAT(db_int64_destroy); break;
+ case DB_UINT64: DB_COUNTSTAT(db_uint64_destroy); break;
}
#endif /* DB_ENABLE_STATS */
db_free_lock(db);
@@ -2246,6 +2344,8 @@ static DBOptions db_obj_options(DBMap* self)
* db_i2key - Manual cast from 'int' to 'DBKey'.
* db_ui2key - Manual cast from 'unsigned int' to 'DBKey'.
* db_str2key - Manual cast from 'unsigned char *' to 'DBKey'.
+ * db_i642key - Manual cast from 'int64' to 'DBKey'.
+ * db_ui642key - Manual cast from 'uin64' to 'DBKey'.
* db_i2data - Manual cast from 'int' to 'DBData'.
* db_ui2data - Manual cast from 'unsigned int' to 'DBData'.
* db_ptr2data - Manual cast from 'void*' to 'DBData'.
@@ -2272,7 +2372,9 @@ DBOptions db_fix_options(DBType type, DBOptions options)
DB_COUNTSTAT(db_fix_options);
switch (type) {
case DB_INT:
- case DB_UINT: // Numeric database, do nothing with the keys
+ case DB_UINT:
+ case DB_INT64:
+ case DB_UINT64: // Numeric database, do nothing with the keys
return (DBOptions)(options&~(DB_OPT_DUP_KEY|DB_OPT_RELEASE_KEY));
default:
@@ -2292,6 +2394,8 @@ DBOptions db_fix_options(DBType type, DBOptions options)
* @see #db_uint_cmp(DBKey,DBKey,unsigned short)
* @see #db_string_cmp(DBKey,DBKey,unsigned short)
* @see #db_istring_cmp(DBKey,DBKey,unsigned short)
+ * @see #db_int64_cmp(DBKey,DBKey,unsigned short)
+ * @see #db_uint64_cmp(DBKey,DBKey,unsigned short)
*/
DBComparator db_default_cmp(DBType type)
{
@@ -2301,6 +2405,8 @@ DBComparator db_default_cmp(DBType type)
case DB_UINT: return &db_uint_cmp;
case DB_STRING: return &db_string_cmp;
case DB_ISTRING: return &db_istring_cmp;
+ case DB_INT64: return &db_int64_cmp;
+ case DB_UINT64: return &db_uint64_cmp;
default:
ShowError("db_default_cmp: Unknown database type %u\n", type);
return NULL;
@@ -2316,6 +2422,8 @@ DBComparator db_default_cmp(DBType type)
* @see #db_uint_hash(DBKey,unsigned short)
* @see #db_string_hash(DBKey,unsigned short)
* @see #db_istring_hash(DBKey,unsigned short)
+ * @see #db_int64_hash(DBKey,unsigned short)
+ * @see #db_uint64_hash(DBKey,unsigned short)
*/
DBHasher db_default_hash(DBType type)
{
@@ -2325,6 +2433,8 @@ DBHasher db_default_hash(DBType type)
case DB_UINT: return &db_uint_hash;
case DB_STRING: return &db_string_hash;
case DB_ISTRING: return &db_istring_hash;
+ case DB_INT64: return &db_int64_hash;
+ case DB_UINT64: return &db_uint64_hash;
default:
ShowError("db_default_hash: Unknown database type %u\n", type);
return NULL;
@@ -2412,6 +2522,8 @@ DBMap* db_alloc(const char *file, const char *func, int line, DBType type, DBOpt
case DB_UINT: DB_COUNTSTAT(db_uint_alloc); break;
case DB_STRING: DB_COUNTSTAT(db_string_alloc); break;
case DB_ISTRING: DB_COUNTSTAT(db_istring_alloc); break;
+ case DB_INT64: DB_COUNTSTAT(db_int64_alloc); break;
+ case DB_UINT64: DB_COUNTSTAT(db_uint64_alloc); break;
}
#endif /* DB_ENABLE_STATS */
db = ers_alloc(db_alloc_ers, struct DBMap_impl);
@@ -2511,6 +2623,36 @@ DBKey db_str2key(const char *key)
}
/**
+ * Manual cast from 'int64' to the union DBKey.
+ * @param key Key to be casted
+ * @return The key as a DBKey union
+ * @public
+ */
+DBKey db_i642key(int64 key)
+{
+ DBKey ret;
+
+ DB_COUNTSTAT(db_i642key);
+ ret.i64 = key;
+ return ret;
+}
+
+/**
+ * Manual cast from 'uin64' to the union DBKey.
+ * @param key Key to be casted
+ * @return The key as a DBKey union
+ * @public
+ */
+DBKey db_ui642key(uint64 key)
+{
+ DBKey ret;
+
+ DB_COUNTSTAT(db_ui642key);
+ ret.ui64 = key;
+ return ret;
+}
+
+/**
* Manual cast from 'int' to the struct DBData.
* @param data Data to be casted
* @return The data as a DBData struct
@@ -2632,10 +2774,14 @@ void db_final(void)
"DB_UINT : allocated %10u, destroyed %10u\n"
"DB_STRING : allocated %10u, destroyed %10u\n"
"DB_ISTRING : allocated %10u, destroyed %10u\n",
+ "DB_INT64 : allocated %10u, destroyed %10u\n"
+ "DB_UINT64 : allocated %10u, destroyed %10u\n"
stats.db_int_alloc, stats.db_int_destroy,
stats.db_uint_alloc, stats.db_uint_destroy,
stats.db_string_alloc, stats.db_string_destroy,
- stats.db_istring_alloc, stats.db_istring_destroy);
+ stats.db_istring_alloc, stats.db_istring_destroy,
+ stats.db_int64_alloc, stats.db_int64_destroy,
+ stats.db_uint64_alloc, stats.db_uint64_destroy,);
ShowInfo(CL_WHITE"Database function counters"CL_RESET":\n"
"db_rotate_left %10u, db_rotate_right %10u,\n"
"db_rebalance %10u, db_rebalance_erase %10u,\n"
@@ -2645,8 +2791,10 @@ void db_final(void)
"db_free_lock %10u, db_free_unlock %10u,\n"
"db_int_cmp %10u, db_uint_cmp %10u,\n"
"db_string_cmp %10u, db_istring_cmp %10u,\n"
+ "db_int64_cmp %10u, db_uint64_cmp %10u,\n"
"db_int_hash %10u, db_uint_hash %10u,\n"
"db_string_hash %10u, db_istring_hash %10u,\n"
+ "db_int64_hash %10u, db_uint64_hash %10u,\n"
"db_release_nothing %10u, db_release_key %10u,\n"
"db_release_data %10u, db_release_both %10u,\n"
"dbit_first %10u, dbit_last %10u,\n"
@@ -2666,6 +2814,7 @@ void db_final(void)
"db_default_release %10u, db_custom_release %10u,\n"
"db_alloc %10u, db_i2key %10u,\n"
"db_ui2key %10u, db_str2key %10u,\n"
+ "db_i642key %10u, db_ui642key %10u,\n"
"db_i2data %10u, db_ui2data %10u,\n"
"db_ptr2data %10u, db_data2i %10u,\n"
"db_data2ui %10u, db_data2ptr %10u,\n"
@@ -2678,8 +2827,10 @@ void db_final(void)
stats.db_free_lock, stats.db_free_unlock,
stats.db_int_cmp, stats.db_uint_cmp,
stats.db_string_cmp, stats.db_istring_cmp,
+ stats.db_int64_cmp, stats.db_uint64_cmp,
stats.db_int_hash, stats.db_uint_hash,
stats.db_string_hash, stats.db_istring_hash,
+ stats.db_int64_hash, stats.db_uint64_hash,
stats.db_release_nothing, stats.db_release_key,
stats.db_release_data, stats.db_release_both,
stats.dbit_first, stats.dbit_last,
@@ -2699,6 +2850,7 @@ void db_final(void)
stats.db_default_release, stats.db_custom_release,
stats.db_alloc, stats.db_i2key,
stats.db_ui2key, stats.db_str2key,
+ stats.db_i642key, stats.db_ui642key,
stats.db_i2data, stats.db_ui2data,
stats.db_ptr2data, stats.db_data2i,
stats.db_data2ui, stats.db_data2ptr,
@@ -2855,4 +3007,7 @@ void db_defaults(void) {
DB->str2key = db_str2key;
DB->ui2data = db_ui2data;
DB->ui2key = db_ui2key;
+ DB->i642key = db_i642key;
+ DB->ui642key = db_ui642key;
+
}
diff --git a/src/common/db.h b/src/common/db.h
index 5f4478909..9d7bdda10 100644
--- a/src/common/db.h
+++ b/src/common/db.h
@@ -20,6 +20,7 @@
* - see what functions need or should be added to the database interface *
* *
* HISTORY: *
+ * 2013/08/25 - Added int64/uint64 support for keys *
* 2012/03/09 - Added enum for data types (int, uint, void*) *
* 2007/11/09 - Added an iterator to the database. *
* 2.1 (Athena build #???#) - Portability fix *
@@ -83,6 +84,8 @@ typedef enum DBRelease {
* @param DB_UINT Uses unsigned int's for keys
* @param DB_STRING Uses strings for keys.
* @param DB_ISTRING Uses case insensitive strings for keys.
+ * @param DB_INT64 Uses int64's for keys
+ * @param DB_UINT64 Uses uint64's for keys
* @public
* @see #DBOptions
* @see #DBKey
@@ -96,7 +99,9 @@ typedef enum DBType {
DB_INT,
DB_UINT,
DB_STRING,
- DB_ISTRING
+ DB_ISTRING,
+ DB_INT64,
+ DB_UINT64,
} DBType;
/**
@@ -145,6 +150,8 @@ typedef union DBKey {
int i;
unsigned int ui;
const char *str;
+ int64 i64;
+ uint64 ui64;
} DBKey;
/**
@@ -158,7 +165,7 @@ typedef union DBKey {
typedef enum DBDataType {
DB_DATA_INT,
DB_DATA_UINT,
- DB_DATA_PTR
+ DB_DATA_PTR,
} DBDataType;
/**
@@ -245,7 +252,7 @@ typedef int (*DBComparator)(DBKey key1, DBKey key2, unsigned short maxlen);
* @public
* @see #db_default_hash(DBType)
*/
-typedef unsigned int (*DBHasher)(DBKey key, unsigned short maxlen);
+typedef uint64 (*DBHasher)(DBKey key, unsigned short maxlen);
/**
* Format of the releaser used by the database system.
@@ -598,65 +605,86 @@ struct DBMap {
// For easy access to the common functions.
-#define db_exists(db,k) ( (db)->exists((db),(k)) )
-#define idb_exists(db,k) ( (db)->exists((db),DB->i2key(k)) )
-#define uidb_exists(db,k) ( (db)->exists((db),DB->ui2key(k)) )
-#define strdb_exists(db,k) ( (db)->exists((db),DB->str2key(k)) )
+#define db_exists(db,k) ( (db)->exists((db),(k)) )
+#define idb_exists(db,k) ( (db)->exists((db),DB->i2key(k)) )
+#define uidb_exists(db,k) ( (db)->exists((db),DB->ui2key(k)) )
+#define strdb_exists(db,k) ( (db)->exists((db),DB->str2key(k)) )
+#define i64db_exists(db,k) ( (db)->exists((db),DB->i642key(k)) )
+#define ui64db_exists(db,k) ( (db)->exists((db),DB->ui642key(k)) )
// Get pointer-type data from DBMaps of various key types
-#define db_get(db,k) ( DB->data2ptr((db)->get((db),(k))) )
-#define idb_get(db,k) ( DB->data2ptr((db)->get((db),DB->i2key(k))) )
-#define uidb_get(db,k) ( DB->data2ptr((db)->get((db),DB->ui2key(k))) )
-#define strdb_get(db,k) ( DB->data2ptr((db)->get((db),DB->str2key(k))) )
+#define db_get(db,k) ( DB->data2ptr((db)->get((db),(k))) )
+#define idb_get(db,k) ( DB->data2ptr((db)->get((db),DB->i2key(k))) )
+#define uidb_get(db,k) ( DB->data2ptr((db)->get((db),DB->ui2key(k))) )
+#define strdb_get(db,k) ( DB->data2ptr((db)->get((db),DB->str2key(k))) )
+#define i64db_get(db,k) ( DB->data2ptr((db)->get((db),DB->i642key(k))) )
+#define ui64db_get(db,k) ( DB->data2ptr((db)->get((db),DB->ui642key(k))) )
+
// Get int-type data from DBMaps of various key types
-#define db_iget(db,k) ( DB->data2i((db)->get((db),(k))) )
-#define idb_iget(db,k) ( DB->data2i((db)->get((db),DB->i2key(k))) )
-#define uidb_iget(db,k) ( DB->data2i((db)->get((db),DB->ui2key(k))) )
-#define strdb_iget(db,k) ( DB->data2i((db)->get((db),DB->str2key(k))) )
+#define db_iget(db,k) ( DB->data2i((db)->get((db),(k))) )
+#define idb_iget(db,k) ( DB->data2i((db)->get((db),DB->i2key(k))) )
+#define uidb_iget(db,k) ( DB->data2i((db)->get((db),DB->ui2key(k))) )
+#define strdb_iget(db,k) ( DB->data2i((db)->get((db),DB->str2key(k))) )
+#define i64db_iget(db,k) ( DB->data2i((db)->get((db),DB->i642key(k))) )
+#define ui64db_iget(db,k) ( DB->data2i((db)->get((db),DB->ui642key(k))) )
// Get uint-type data from DBMaps of various key types
-#define db_uiget(db,k) ( DB->data2ui((db)->get((db),(k))) )
-#define idb_uiget(db,k) ( DB->data2ui((db)->get((db),DB->i2key(k))) )
-#define uidb_uiget(db,k) ( DB->data2ui((db)->get((db),DB->ui2key(k))) )
-#define strdb_uiget(db,k) ( DB->data2ui((db)->get((db),DB->str2key(k))) )
+#define db_uiget(db,k) ( DB->data2ui((db)->get((db),(k))) )
+#define idb_uiget(db,k) ( DB->data2ui((db)->get((db),DB->i2key(k))) )
+#define uidb_uiget(db,k) ( DB->data2ui((db)->get((db),DB->ui2key(k))) )
+#define strdb_uiget(db,k) ( DB->data2ui((db)->get((db),DB->str2key(k))) )
+#define i64db_uiget(db,k) ( DB->data2ui((db)->get((db),DB->i642key(k))) )
+#define ui64db_uiget(db,k) ( DB->data2ui((db)->get((db),DB->ui642key(k))) )
// Put pointer-type data into DBMaps of various key types
-#define db_put(db,k,d) ( (db)->put((db),(k),DB->ptr2data(d),NULL) )
-#define idb_put(db,k,d) ( (db)->put((db),DB->i2key(k),DB->ptr2data(d),NULL) )
-#define uidb_put(db,k,d) ( (db)->put((db),DB->ui2key(k),DB->ptr2data(d),NULL) )
-#define strdb_put(db,k,d) ( (db)->put((db),DB->str2key(k),DB->ptr2data(d),NULL) )
+#define db_put(db,k,d) ( (db)->put((db),(k),DB->ptr2data(d),NULL) )
+#define idb_put(db,k,d) ( (db)->put((db),DB->i2key(k),DB->ptr2data(d),NULL) )
+#define uidb_put(db,k,d) ( (db)->put((db),DB->ui2key(k),DB->ptr2data(d),NULL) )
+#define strdb_put(db,k,d) ( (db)->put((db),DB->str2key(k),DB->ptr2data(d),NULL) )
+#define i64db_put(db,k,d) ( (db)->put((db),DB->i642key(k),DB->ptr2data(d),NULL) )
+#define ui64db_put(db,k,d) ( (db)->put((db),DB->ui642key(k),DB->ptr2data(d),NULL) )
// Put int-type data into DBMaps of various key types
-#define db_iput(db,k,d) ( (db)->put((db),(k),DB->i2data(d),NULL) )
-#define idb_iput(db,k,d) ( (db)->put((db),DB->i2key(k),DB->i2data(d),NULL) )
-#define uidb_iput(db,k,d) ( (db)->put((db),DB->ui2key(k),DB->i2data(d),NULL) )
-#define strdb_iput(db,k,d) ( (db)->put((db),DB->str2key(k),DB->i2data(d),NULL) )
+#define db_iput(db,k,d) ( (db)->put((db),(k),DB->i2data(d),NULL) )
+#define idb_iput(db,k,d) ( (db)->put((db),DB->i2key(k),DB->i2data(d),NULL) )
+#define uidb_iput(db,k,d) ( (db)->put((db),DB->ui2key(k),DB->i2data(d),NULL) )
+#define strdb_iput(db,k,d) ( (db)->put((db),DB->str2key(k),DB->i2data(d),NULL) )
+#define i64db_iput(db,k,d) ( (db)->put((db),DB->i642key(k),DB->i2data(d),NULL) )
+#define ui64db_iput(db,k,d) ( (db)->put((db),DB->ui642key(k),DB->i2data(d),NULL) )
// Put uint-type data into DBMaps of various key types
-#define db_uiput(db,k,d) ( (db)->put((db),(k),DB->ui2data(d),NULL) )
-#define idb_uiput(db,k,d) ( (db)->put((db),DB->i2key(k),DB->ui2data(d),NULL) )
-#define uidb_uiput(db,k,d) ( (db)->put((db),DB->ui2key(k),DB->ui2data(d),NULL) )
-#define strdb_uiput(db,k,d) ( (db)->put((db),DB->str2key(k),DB->ui2data(d),NULL) )
+#define db_uiput(db,k,d) ( (db)->put((db),(k),DB->ui2data(d),NULL) )
+#define idb_uiput(db,k,d) ( (db)->put((db),DB->i2key(k),DB->ui2data(d),NULL) )
+#define uidb_uiput(db,k,d) ( (db)->put((db),DB->ui2key(k),DB->ui2data(d),NULL) )
+#define strdb_uiput(db,k,d) ( (db)->put((db),DB->str2key(k),DB->ui2data(d),NULL) )
+#define i64db_uiput(db,k,d) ( (db)->put((db),DB->i642key(k),DB->ui2data(d),NULL) )
+#define ui64db_uiput(db,k,d) ( (db)->put((db),DB->ui642key(k),DB->ui2data(d),NULL) )
// Remove entry from DBMaps of various key types
-#define db_remove(db,k) ( (db)->remove((db),(k),NULL) )
-#define idb_remove(db,k) ( (db)->remove((db),DB->i2key(k),NULL) )
-#define uidb_remove(db,k) ( (db)->remove((db),DB->ui2key(k),NULL) )
-#define strdb_remove(db,k) ( (db)->remove((db),DB->str2key(k),NULL) )
+#define db_remove(db,k) ( (db)->remove((db),(k),NULL) )
+#define idb_remove(db,k) ( (db)->remove((db),DB->i2key(k),NULL) )
+#define uidb_remove(db,k) ( (db)->remove((db),DB->ui2key(k),NULL) )
+#define strdb_remove(db,k) ( (db)->remove((db),DB->str2key(k),NULL) )
+#define i64db_remove(db,k) ( (db)->remove((db),DB->i642key(k),NULL) )
+#define ui64db_remove(db,k) ( (db)->remove((db),DB->ui642key(k),NULL) )
//These are discarding the possible vargs you could send to the function, so those
//that require vargs must not use these defines.
-#define db_ensure(db,k,f) ( DB->data2ptr((db)->ensure((db),(k),(f))) )
-#define idb_ensure(db,k,f) ( DB->data2ptr((db)->ensure((db),DB->i2key(k),(f))) )
-#define uidb_ensure(db,k,f) ( DB->data2ptr((db)->ensure((db),DB->ui2key(k),(f))) )
-#define strdb_ensure(db,k,f) ( DB->data2ptr((db)->ensure((db),DB->str2key(k),(f))) )
+#define db_ensure(db,k,f) ( DB->data2ptr((db)->ensure((db),(k),(f))) )
+#define idb_ensure(db,k,f) ( DB->data2ptr((db)->ensure((db),DB->i2key(k),(f))) )
+#define uidb_ensure(db,k,f) ( DB->data2ptr((db)->ensure((db),DB->ui2key(k),(f))) )
+#define strdb_ensure(db,k,f) ( DB->data2ptr((db)->ensure((db),DB->str2key(k),(f))) )
+#define i64db_ensure(db,k,f) ( DB->data2ptr((db)->ensure((db),DB->i642key(k),(f))) )
+#define ui64db_ensure(db,k,f) ( DB->data2ptr((db)->ensure((db),DB->ui642key(k),(f))) )
// Database creation and destruction macros
#define idb_alloc(opt) DB->alloc(__FILE__,__func__,__LINE__,DB_INT,(opt),sizeof(int))
#define uidb_alloc(opt) DB->alloc(__FILE__,__func__,__LINE__,DB_UINT,(opt),sizeof(unsigned int))
#define strdb_alloc(opt,maxlen) DB->alloc(__FILE__,__func__,__LINE__,DB_STRING,(opt),(maxlen))
#define stridb_alloc(opt,maxlen) DB->alloc(__FILE__,__func__,__LINE__,DB_ISTRING,(opt),(maxlen))
+#define i64db_alloc(opt) DB->alloc(__FILE__,__func__,__LINE__,DB_INT64,(opt),sizeof(int64))
+#define ui64db_alloc(opt) DB->alloc(__FILE__,__func__,__LINE__,DB_UINT64,(opt),sizeof(uint64))
#define db_destroy(db) ( (db)->destroy((db),NULL) )
// Other macros
#define db_clear(db) ( (db)->clear((db),NULL) )
@@ -682,6 +710,8 @@ struct DBMap {
* db_i2key - Manual cast from 'int' to 'DBKey'. *
* db_ui2key - Manual cast from 'unsigned int' to 'DBKey'. *
* db_str2key - Manual cast from 'unsigned char *' to 'DBKey'. *
+ * db_i642key - Manual cast from 'int64' to 'DBKey'. *
+ * db_ui642key - Manual cast from 'uint64' to 'DBKey'. *
* db_i2data - Manual cast from 'int' to 'DBData'. *
* db_ui2data - Manual cast from 'unsigned int' to 'DBData'. *
* db_ptr2data - Manual cast from 'void*' to 'DBData'. *
@@ -803,6 +833,22 @@ DBKey (*ui2key) (unsigned int key);
DBKey (*str2key) (const char *key);
/**
+ * Manual cast from 'int64' to the union DBKey.
+ * @param key Key to be casted
+ * @return The key as a DBKey union
+ * @public
+ */
+DBKey (*i642key) (int64 key);
+
+/**
+ * Manual cast from 'uint64' to the union DBKey.
+ * @param key Key to be casted
+ * @return The key as a DBKey union
+ * @public
+ */
+DBKey (*ui642key) (uint64 key);
+
+/**
* Manual cast from 'int' to the struct DBData.
* @param data Data to be casted
* @return The data as a DBData struct
diff --git a/src/common/mmo.h b/src/common/mmo.h
index 273edc42b..594d1cb26 100644
--- a/src/common/mmo.h
+++ b/src/common/mmo.h
@@ -101,11 +101,6 @@
//Update this max as necessary. 55 is the value needed for Super Baby currently
//Raised to 84 since Expanded Super Novice needs it.
#define MAX_SKILL_TREE 84
-#define GLOBAL_REG_NUM 256 // Max permanent character variables per char
-#define ACCOUNT_REG_NUM 64 // Max permanent local account variables per account
-#define ACCOUNT_REG2_NUM 16 // Max permanent global account variables per account
-//Should hold the max of GLOBAL/ACCOUNT/ACCOUNT2 (needed for some arrays that hold all three)
-#define MAX_REG_NUM 256
#define DEFAULT_WALK_SPEED 150
#define MIN_WALK_SPEED 20 /* below 20 clips animation */
#define MAX_WALK_SPEED 1000
@@ -269,16 +264,19 @@ struct s_skill {
unsigned char flag; // See enum e_skill_flag
};
-struct global_reg {
- char str[32];
- char value[256];
+struct script_reg_state {
+ unsigned int type : 1;/* because I'm a memory hoarder and having them in the same struct would be a 8-byte/instance waste while ints outnumber str on a 10000-to-1 ratio. */
+ unsigned int update : 1;/* whether it needs to be sent to char server for insertion/update/delete */
};
-// Holds array of global registries, used by the char server and converter.
-struct accreg {
- int account_id, char_id;
- int reg_num;
- struct global_reg reg[MAX_REG_NUM];
+struct script_reg_num {
+ struct script_reg_state flag;
+ int value;
+};
+
+struct script_reg_str {
+ struct script_reg_state flag;
+ char *value;
};
// For saving status changes across sessions. [Skotlex]
@@ -483,15 +481,6 @@ struct auction_data {
int auction_end_timer;
};
-struct registry {
- int global_num;
- struct global_reg global[GLOBAL_REG_NUM];
- int account_num;
- struct global_reg account[ACCOUNT_REG_NUM];
- int account2_num;
- struct global_reg account2[ACCOUNT_REG2_NUM];
-};
-
struct party_member {
int account_id;
int char_id;
@@ -866,6 +855,14 @@ enum e_char_server_type {
CST_F2P = 4,
};
+enum e_pc_reg_loading {
+ PRL_NONE = 0x0,
+ PRL_CHAR = 0x1,
+ PRL_ACCL = 0x2,/* local */
+ PRL_ACCG = 0x4,/* global */
+ PRL_ALL = 0xFF,
+};
+
/* packet size constant for itemlist */
#if MAX_INVENTORY > MAX_STORAGE && MAX_INVENTORY > MAX_CART
#define MAX_ITEMLIST MAX_INVENTORY
diff --git a/src/common/socket.c b/src/common/socket.c
index 9c6938008..1ffa15708 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -1464,8 +1464,6 @@ void socket_datasync(int fd, bool send) {
{ sizeof(struct item) },
{ sizeof(struct point) },
{ sizeof(struct s_skill) },
- { sizeof(struct global_reg) },
- { sizeof(struct accreg) },
{ sizeof(struct status_change_data) },
{ sizeof(struct storage_data) },
{ sizeof(struct guild_storage) },
@@ -1476,7 +1474,6 @@ void socket_datasync(int fd, bool send) {
{ sizeof(struct s_friend) },
{ sizeof(struct mail_message) },
{ sizeof(struct mail_data) },
- { sizeof(struct registry) },
{ sizeof(struct party_member) },
{ sizeof(struct party) },
{ sizeof(struct guild_member) },
@@ -1487,6 +1484,7 @@ void socket_datasync(int fd, bool send) {
{ sizeof(struct guild) },
{ sizeof(struct guild_castle) },
{ sizeof(struct fame_list) },
+ { PACKETVER },
};
unsigned short i;
unsigned int alen = ARRAYLENGTH(data_list);