diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/HPM.c | 12 | ||||
-rw-r--r-- | src/common/console.c | 6 | ||||
-rw-r--r-- | src/common/core.c | 14 | ||||
-rw-r--r-- | src/common/db.c | 46 | ||||
-rw-r--r-- | src/common/db.h | 88 | ||||
-rw-r--r-- | src/common/malloc.c | 44 | ||||
-rw-r--r-- | src/common/malloc.h | 14 | ||||
-rw-r--r-- | src/common/mutex.c | 2 | ||||
-rw-r--r-- | src/common/random.c | 2 | ||||
-rw-r--r-- | src/common/socket.c | 12 | ||||
-rw-r--r-- | src/common/sql.c | 4 | ||||
-rw-r--r-- | src/common/timer.c | 37 | ||||
-rw-r--r-- | src/common/timer.h | 39 |
13 files changed, 168 insertions, 152 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c index 28ea8f413..ed6151c95 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -264,8 +264,8 @@ void hplugins_share_defaults(void) { HPM->share(&SERVER_TYPE,"SERVER_TYPE"); HPM->share((void*)get_svn_revision,"get_svn_revision"); HPM->share((void*)get_git_hash,"get_git_hash"); - HPM->share(DB, "DB"); - HPM->share(malloclib, "malloclib"); + HPM->share(iDB, "iDB"); + HPM->share(iMalloc, "iMalloc"); /* socket */ HPM->share(RFIFOSKIP,"RFIFOSKIP"); HPM->share(WFIFOSET,"WFIFOSET"); @@ -281,12 +281,8 @@ void hplugins_share_defaults(void) { /* sql */ HPM->share(SQL,"SQL"); /* timer */ - HPM->share(gettick,"gettick"); - HPM->share(add_timer,"add_timer"); - HPM->share(add_timer_interval,"add_timer_interval"); - HPM->share(add_timer_func_list,"add_timer_func_list"); - HPM->share(delete_timer,"delete_timer"); - HPM->share(get_uptime,"get_uptime"); + HPM->share(iTimer,"iTimer"); + } CPCMD(plugins) { if( HPM->plugin_count == 0 ) { diff --git a/src/common/console.c b/src/common/console.c index 33d485497..08daec04e 100644 --- a/src/common/console.c +++ b/src/common/console.c @@ -101,7 +101,7 @@ CPCMD(help) { } /* [Ind/Hercules] */ CPCMD(malloc_usage) { - unsigned int val = (unsigned int)malloclib->usage(); + unsigned int val = (unsigned int)iMalloc->usage(); ShowInfo("malloc_usage: %.2f MB\n",(double)(val)/1024); } #define CP_DEF_C(x) { #x , NULL , NULL, NULL } @@ -369,8 +369,8 @@ void console_parse_init(void) { exit(EXIT_FAILURE); } - add_timer_func_list(console->parse_timer, "console_parse_timer"); - add_timer_interval(gettick() + 1000, console->parse_timer, 0, 0, 500);/* start listening in 1s; re-try every 0.5s */ + iTimer->add_timer_func_list(console->parse_timer, "console_parse_timer"); + iTimer->add_timer_interval(iTimer->gettick() + 1000, console->parse_timer, 0, 0, 500);/* start listening in 1s; re-try every 0.5s */ } #endif /* CONSOLE_INPUT */ diff --git a/src/common/core.c b/src/common/core.c index 0959e6fc9..d6cfff662 100644 --- a/src/common/core.c +++ b/src/common/core.c @@ -307,7 +307,7 @@ int main (int argc, char **argv) { } core_defaults(); - malloclib->init();// needed for Show* in display_title() [FlavioJS] + iMalloc->init();// needed for Show* in display_title() [FlavioJS] console->display_title(); @@ -322,14 +322,14 @@ int main (int argc, char **argv) { Sql_Init(); rathread_init(); mempool_init(); - DB->init(); + iDB->init(); signals_init(); #ifdef _WIN32 cevents_init(); #endif - timer_init(); + iTimer->init(); console->init(); @@ -343,7 +343,7 @@ int main (int argc, char **argv) { {// Main runtime cycle int next; while (runflag != CORE_ST_STOP) { - next = do_timer(gettick_nocache()); + next = iTimer->do_timer(iTimer->gettick_nocache()); do_sockets(next); } } @@ -354,14 +354,14 @@ int main (int argc, char **argv) { #ifndef MINICORE HPM->final(); #endif - timer_final(); + iTimer->final(); socket_final(); - DB->final(); + iDB->final(); mempool_final(); rathread_final(); #endif - malloclib->final(); + iMalloc->final(); return 0; } diff --git a/src/common/db.c b/src/common/db.c index 561371787..b1fe22a4a 100644 --- a/src/common/db.c +++ b/src/common/db.c @@ -2349,7 +2349,7 @@ DBHasher db_default_hash(DBType type) DBReleaser db_default_release(DBType type, DBOptions options) { DB_COUNTSTAT(db_default_release); - options = DB->fix_options(type, options); + options = iDB->fix_options(type, options); if (options&DB_OPT_RELEASE_DATA) { // Release data, what about the key? if (options&(DB_OPT_DUP_KEY|DB_OPT_RELEASE_KEY)) return &db_release_both; // Release both key and data @@ -2416,7 +2416,7 @@ DBMap* db_alloc(const char *file, const char *func, int line, DBType type, DBOpt #endif /* DB_ENABLE_STATS */ db = ers_alloc(db_alloc_ers, struct DBMap_impl); - options = DB->fix_options(type, options); + options = iDB->fix_options(type, options); /* Interface of the database */ db->vtable.iterator = db_obj_iterator; db->vtable.exists = db_obj_exists; @@ -2447,9 +2447,9 @@ DBMap* db_alloc(const char *file, const char *func, int line, DBType type, DBOpt /* Other */ snprintf(ers_name, 50, "db_alloc:nodes:%s:%s:%d",func,file,line); db->nodes = ers_new(sizeof(struct dbn),ers_name,ERS_OPT_WAIT|ERS_OPT_FREE_NAME); - db->cmp = DB->default_cmp(type); - db->hash = DB->default_hash(type); - db->release = DB->default_release(type, options); + db->cmp = iDB->default_cmp(type); + db->hash = iDB->default_hash(type); + db->release = iDB->default_release(type, options); for (i = 0; i < HASH_SIZE; i++) db->ht[i] = NULL; db->cache = NULL; @@ -2830,22 +2830,22 @@ void linkdb_final( struct linkdb_node** head ) *head = NULL; } void db_defaults(void) { - DB = &DB_s; - DB->alloc = db_alloc; - DB->custom_release = db_custom_release; - DB->data2i = db_data2i; - DB->data2ptr = db_data2ptr; - DB->data2ui = db_data2ui; - DB->default_cmp = db_default_cmp; - DB->default_hash = db_default_hash; - DB->default_release = db_default_release; - DB->final = db_final; - DB->fix_options = db_fix_options; - DB->i2data = db_i2data; - DB->i2key = db_i2key; - DB->init = db_init; - DB->ptr2data = db_ptr2data; - DB->str2key = db_str2key; - DB->ui2data = db_ui2data; - DB->ui2key = db_ui2key; + iDB = &iDB_s; + iDB->alloc = db_alloc; + iDB->custom_release = db_custom_release; + iDB->data2i = db_data2i; + iDB->data2ptr = db_data2ptr; + iDB->data2ui = db_data2ui; + iDB->default_cmp = db_default_cmp; + iDB->default_hash = db_default_hash; + iDB->default_release = db_default_release; + iDB->final = db_final; + iDB->fix_options = db_fix_options; + iDB->i2data = db_i2data; + iDB->i2key = db_i2key; + iDB->init = db_init; + iDB->ptr2data = db_ptr2data; + iDB->str2key = db_str2key; + iDB->ui2data = db_ui2data; + iDB->ui2key = db_ui2key; } diff --git a/src/common/db.h b/src/common/db.h index 5a555b2fa..8ad033cce 100644 --- a/src/common/db.h +++ b/src/common/db.h @@ -599,73 +599,73 @@ 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 idb_exists(db,k) ( (db)->exists((db),iDB->i2key(k)) ) +#define uidb_exists(db,k) ( (db)->exists((db),iDB->ui2key(k)) ) +#define strdb_exists(db,k) ( (db)->exists((db),iDB->str2key(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) ( iDB->data2ptr((db)->get((db),(k))) ) +#define idb_get(db,k) ( iDB->data2ptr((db)->get((db),iDB->i2key(k))) ) +#define uidb_get(db,k) ( iDB->data2ptr((db)->get((db),iDB->ui2key(k))) ) +#define strdb_get(db,k) ( iDB->data2ptr((db)->get((db),iDB->str2key(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) ( iDB->data2i((db)->get((db),(k))) ) +#define idb_iget(db,k) ( iDB->data2i((db)->get((db),iDB->i2key(k))) ) +#define uidb_iget(db,k) ( iDB->data2i((db)->get((db),iDB->ui2key(k))) ) +#define strdb_iget(db,k) ( iDB->data2i((db)->get((db),iDB->str2key(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) ( iDB->data2ui((db)->get((db),(k))) ) +#define idb_uiget(db,k) ( iDB->data2ui((db)->get((db),iDB->i2key(k))) ) +#define uidb_uiget(db,k) ( iDB->data2ui((db)->get((db),iDB->ui2key(k))) ) +#define strdb_uiget(db,k) ( iDB->data2ui((db)->get((db),iDB->str2key(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),iDB->ptr2data(d),NULL) ) +#define idb_put(db,k,d) ( (db)->put((db),iDB->i2key(k),iDB->ptr2data(d),NULL) ) +#define uidb_put(db,k,d) ( (db)->put((db),iDB->ui2key(k),iDB->ptr2data(d),NULL) ) +#define strdb_put(db,k,d) ( (db)->put((db),iDB->str2key(k),iDB->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),iDB->i2data(d),NULL) ) +#define idb_iput(db,k,d) ( (db)->put((db),iDB->i2key(k),iDB->i2data(d),NULL) ) +#define uidb_iput(db,k,d) ( (db)->put((db),iDB->ui2key(k),iDB->i2data(d),NULL) ) +#define strdb_iput(db,k,d) ( (db)->put((db),iDB->str2key(k),iDB->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),iDB->ui2data(d),NULL) ) +#define idb_uiput(db,k,d) ( (db)->put((db),iDB->i2key(k),iDB->ui2data(d),NULL) ) +#define uidb_uiput(db,k,d) ( (db)->put((db),iDB->ui2key(k),iDB->ui2data(d),NULL) ) +#define strdb_uiput(db,k,d) ( (db)->put((db),iDB->str2key(k),iDB->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 idb_remove(db,k) ( (db)->remove((db),iDB->i2key(k),NULL) ) +#define uidb_remove(db,k) ( (db)->remove((db),iDB->ui2key(k),NULL) ) +#define strdb_remove(db,k) ( (db)->remove((db),iDB->str2key(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) ( iDB->data2ptr((db)->ensure((db),(k),(f))) ) +#define idb_ensure(db,k,f) ( iDB->data2ptr((db)->ensure((db),iDB->i2key(k),(f))) ) +#define uidb_ensure(db,k,f) ( iDB->data2ptr((db)->ensure((db),iDB->ui2key(k),(f))) ) +#define strdb_ensure(db,k,f) ( iDB->data2ptr((db)->ensure((db),iDB->str2key(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 idb_alloc(opt) iDB->alloc(__FILE__,__func__,__LINE__,DB_INT,(opt),sizeof(int)) +#define uidb_alloc(opt) iDB->alloc(__FILE__,__func__,__LINE__,DB_UINT,(opt),sizeof(unsigned int)) +#define strdb_alloc(opt,maxlen) iDB->alloc(__FILE__,__func__,__LINE__,DB_STRING,(opt),(maxlen)) +#define stridb_alloc(opt,maxlen) iDB->alloc(__FILE__,__func__,__LINE__,DB_ISTRING,(opt),(maxlen)) #define db_destroy(db) ( (db)->destroy((db),NULL) ) // Other macros #define db_clear(db) ( (db)->clear(db,NULL) ) #define db_size(db) ( (db)->size(db) ) #define db_iterator(db) ( (db)->iterator(db) ) -#define dbi_first(dbi) ( DB->data2ptr((dbi)->first(dbi,NULL)) ) -#define dbi_last(dbi) ( DB->data2ptr((dbi)->last(dbi,NULL)) ) -#define dbi_next(dbi) ( DB->data2ptr((dbi)->next(dbi,NULL)) ) -#define dbi_prev(dbi) ( DB->data2ptr((dbi)->prev(dbi,NULL)) ) +#define dbi_first(dbi) ( iDB->data2ptr((dbi)->first(dbi,NULL)) ) +#define dbi_last(dbi) ( iDB->data2ptr((dbi)->last(dbi,NULL)) ) +#define dbi_next(dbi) ( iDB->data2ptr((dbi)->next(dbi,NULL)) ) +#define dbi_prev(dbi) ( iDB->data2ptr((dbi)->prev(dbi,NULL)) ) #define dbi_remove(dbi) ( (dbi)->remove(dbi,NULL) ) #define dbi_exists(dbi) ( (dbi)->exists(dbi) ) #define dbi_destroy(dbi) ( (dbi)->destroy(dbi) ) @@ -867,9 +867,9 @@ void (*init) (void); * @see #db_init(void) */ void (*final) (void); -} DB_s; +} iDB_s; -struct db_interface *DB; +struct db_interface *iDB; void db_defaults(void); // Link DB System - From jAthena diff --git a/src/common/malloc.c b/src/common/malloc.c index 372991fbe..d629aa63f 100644 --- a/src/common/malloc.c +++ b/src/common/malloc.c @@ -335,7 +335,7 @@ void* _mmalloc(size_t size, const char *file, int line, const char *func ) void* _mcalloc(size_t num, size_t size, const char *file, int line, const char *func ) { - void *p = malloclib->malloc(num * size,file,line,func); + void *p = iMalloc->malloc(num * size,file,line,func); memset(p,0,num * size); return p; } @@ -344,7 +344,7 @@ void* _mrealloc(void *memblock, size_t size, const char *file, int line, const c { size_t old_size; if(memblock == NULL) { - return malloclib->malloc(size,file,line,func); + return iMalloc->malloc(size,file,line,func); } old_size = ((struct unit_head *)((char *)memblock - sizeof(struct unit_head) + sizeof(long)))->size; @@ -356,11 +356,11 @@ void* _mrealloc(void *memblock, size_t size, const char *file, int line, const c return memblock; } else { // Size Large - void *p = malloclib->malloc(size,file,line,func); + void *p = iMalloc->malloc(size,file,line,func); if(p != NULL) { memcpy(p,memblock,old_size); } - malloclib->free(memblock,file,line,func); + iMalloc->free(memblock,file,line,func); return p; } } @@ -371,7 +371,7 @@ char* _mstrdup(const char *p, const char *file, int line, const char *func ) return NULL; } else { size_t len = strlen(p); - char *string = (char *)malloclib->malloc(len + 1,file,line,func); + char *string = (char *)iMalloc->malloc(len + 1,file,line,func); memcpy(string,p,len+1); return string; } @@ -626,7 +626,7 @@ static void memmgr_final (void) memmgr_log (buf); #endif /* LOG_MEMMGR */ // get block pointer and free it [celest] - malloclib->free(ptr, ALC_MARK); + iMalloc->free(ptr, ALC_MARK); } } } @@ -804,25 +804,25 @@ void malloc_init (void) { } void malloc_defaults(void) { - malloclib = &malloclib_s; - malloclib->init = malloc_init; - malloclib->final = malloc_final; - malloclib->memory_check = malloc_memory_check; - malloclib->usage = malloc_usage; - malloclib->verify_ptr = malloc_verify_ptr; + iMalloc = &iMalloc_s; + iMalloc->init = malloc_init; + iMalloc->final = malloc_final; + iMalloc->memory_check = malloc_memory_check; + iMalloc->usage = malloc_usage; + iMalloc->verify_ptr = malloc_verify_ptr; // Athena's built-in Memory Manager #ifdef USE_MEMMGR - malloclib->malloc = _mmalloc; - malloclib->calloc = _mcalloc; - malloclib->realloc = _mrealloc; - malloclib->astrdup = _mstrdup; - malloclib->free = _mfree; + iMalloc->malloc = _mmalloc; + iMalloc->calloc = _mcalloc; + iMalloc->realloc = _mrealloc; + iMalloc->astrdup = _mstrdup; + iMalloc->free = _mfree; #else - malloclib->malloc = aMalloc_; - malloclib->calloc = aCalloc_; - malloclib->realloc = aRealloc_; - malloclib->astrdup = aStrdup_; - malloclib->free = aFree_; + iMalloc->malloc = aMalloc_; + iMalloc->calloc = aCalloc_; + iMalloc->realloc = aRealloc_; + iMalloc->astrdup = aStrdup_; + iMalloc->free = aFree_; #endif } diff --git a/src/common/malloc.h b/src/common/malloc.h index 1b8e82bd9..834781905 100644 --- a/src/common/malloc.h +++ b/src/common/malloc.h @@ -30,11 +30,11 @@ #undef LOG_MEMMGR #endif -# define aMalloc(n) malloclib->malloc (n,ALC_MARK) -# define aCalloc(m,n) malloclib->calloc (m,n,ALC_MARK) -# define aRealloc(p,n) malloclib->realloc (p,n,ALC_MARK) -# define aStrdup(p) malloclib->astrdup (p,ALC_MARK) -# define aFree(p) malloclib->free (p,ALC_MARK) +# define aMalloc(n) iMalloc->malloc (n,ALC_MARK) +# define aCalloc(m,n) iMalloc->calloc (m,n,ALC_MARK) +# define aRealloc(p,n) iMalloc->realloc (p,n,ALC_MARK) +# define aStrdup(p) iMalloc->astrdup (p,ALC_MARK) +# define aFree(p) iMalloc->free (p,ALC_MARK) /////////////// Buffer Creation ///////////////// // Full credit for this goes to Shinomori [Ajarn] @@ -78,9 +78,9 @@ struct malloc_interface { size_t (*usage) (void); void (*init) (void); void (*final) (void); -} malloclib_s; +} iMalloc_s; void memmgr_report (int extra); -struct malloc_interface *malloclib; +struct malloc_interface *iMalloc; #endif /* _MALLOC_H_ */ diff --git a/src/common/mutex.c b/src/common/mutex.c index 6b4f55119..6bb1efdab 100644 --- a/src/common/mutex.c +++ b/src/common/mutex.c @@ -201,7 +201,7 @@ void racond_wait( racond c, ramutex m, sysint timeout_ticks){ pthread_cond_wait( &c->hCond, &m->hMutex ); }else{ struct timespec wtime; - int64 exact_timeout = gettick() + timeout_ticks; + int64 exact_timeout = iTimer->gettick() + timeout_ticks; wtime.tv_sec = exact_timeout/1000; wtime.tv_nsec = (exact_timeout%1000)*1000000; diff --git a/src/common/random.c b/src/common/random.c index 5c048c7eb..a7d432e34 100644 --- a/src/common/random.c +++ b/src/common/random.c @@ -17,7 +17,7 @@ /// Initializes the random number generator with an appropriate seed. void rnd_init(void) { - uint32 seed = gettick(); + uint32 seed = iTimer->gettick(); seed += (uint32)time(NULL); #if defined(WIN32) seed += GetCurrentProcessId(); diff --git a/src/common/socket.c b/src/common/socket.c index 0459004cc..15b20b16f 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -947,9 +947,9 @@ static int connect_check_(uint32 ip) if( hist->ddos ) {// flagged as DDoS return (connect_ok == 2 ? 1 : 0); - } else if( DIFF_TICK(gettick(),hist->tick) < ddos_interval ) + } else if( DIFF_TICK(iTimer->gettick(),hist->tick) < ddos_interval ) {// connection within ddos_interval - hist->tick = gettick(); + hist->tick = iTimer->gettick(); if( hist->count++ >= ddos_count ) {// DDoS attack detected hist->ddos = 1; @@ -959,7 +959,7 @@ static int connect_check_(uint32 ip) return connect_ok; } else {// not within ddos_interval, clear data - hist->tick = gettick(); + hist->tick = iTimer->gettick(); hist->count = 0; return connect_ok; } @@ -970,7 +970,7 @@ static int connect_check_(uint32 ip) CREATE(hist, ConnectHistory, 1); memset(hist, 0, sizeof(ConnectHistory)); hist->ip = ip; - hist->tick = gettick(); + hist->tick = iTimer->gettick(); hist->next = connect_history[ip&0xFFFF]; connect_history[ip&0xFFFF] = hist; return connect_ok; @@ -1331,8 +1331,8 @@ void socket_init(void) #ifndef MINICORE // Delete old connection history every 5 minutes memset(connect_history, 0, sizeof(connect_history)); - add_timer_func_list(connect_check_clear, "connect_check_clear"); - add_timer_interval(gettick()+1000, connect_check_clear, 0, 0, 5*60*1000); + iTimer->add_timer_func_list(connect_check_clear, "connect_check_clear"); + iTimer->add_timer_interval(iTimer->gettick()+1000, connect_check_clear, 0, 0, 5*60*1000); #endif ShowInfo("Server supports up to '"CL_WHITE"%u"CL_RESET"' concurrent connections.\n", rlim_cur); diff --git a/src/common/sql.c b/src/common/sql.c index 391211183..d4bea7c12 100644 --- a/src/common/sql.c +++ b/src/common/sql.c @@ -210,7 +210,7 @@ static int Sql_P_Keepalive(Sql* self) // establish keepalive ping_interval = timeout - 30; // 30-second reserve //add_timer_func_list(Sql_P_KeepaliveTimer, "Sql_P_KeepaliveTimer"); - return add_timer_interval(gettick() + ping_interval*1000, Sql_P_KeepaliveTimer, 0, (intptr_t)self, ping_interval*1000); + return iTimer->add_timer_interval(iTimer->gettick() + ping_interval*1000, Sql_P_KeepaliveTimer, 0, (intptr_t)self, ping_interval*1000); } @@ -404,7 +404,7 @@ void Sql_Free(Sql* self) { SQL->FreeResult(self); StrBuf->Destroy(&self->buf); - if( self->keepalive != INVALID_TIMER ) delete_timer(self->keepalive, Sql_P_KeepaliveTimer); + if( self->keepalive != INVALID_TIMER ) iTimer->delete_timer(self->keepalive, Sql_P_KeepaliveTimer); aFree(self); } } diff --git a/src/common/timer.c b/src/common/timer.c index edb46bd71..955a971c8 100644 --- a/src/common/timer.c +++ b/src/common/timer.c @@ -257,7 +257,7 @@ int timer_add_interval(unsigned int tick, TimerFunc func, int id, intptr_t data, int tid; if( interval < 1 ) { - ShowError("timer_add_interval: invalid interval (tick=%u %p[%s] id=%d data=%d diff_tick=%d)\n", tick, func, search_timer_func_list(func), id, data, DIFF_TICK(tick, gettick())); + ShowError("timer_add_interval: invalid interval (tick=%u %p[%s] id=%d data=%d diff_tick=%d)\n", tick, func, search_timer_func_list(func), id, data, DIFF_TICK(tick, iTimer->gettick())); return INVALID_TIMER; } @@ -300,7 +300,7 @@ int timer_do_delete(int tid, TimerFunc func) { /// Adjusts a timer's expiration time. /// Returns the new tick value, or -1 if it fails. int timer_addtick(int tid, unsigned int tick) { - return settick_timer(tid, timer_data[tid].tick+tick); + return iTimer->settick_timer(tid, timer_data[tid].tick+tick); } /// Modifies a timer's expiration time (an alternative to deleting a timer and starting a new one). @@ -409,15 +409,26 @@ void timer_final(void) { BHEAP_CLEAR(timer_heap); if (free_timer_list) aFree(free_timer_list); } -void timer_defaults(void) { - gettick = timer_gettick; - gettick_nocache = timer_gettick_nocache; - add_timer = timer_add; - add_timer_interval = timer_add_interval; - add_timer_func_list = timer_add_func_list; - get_timer = timer_get; - delete_timer = timer_do_delete; - addtick_timer = timer_addtick; - settick_timer = timer_settick; - get_uptime = timer_get_uptime; +/*===================================== +* Default Functions : timer.h +* Generated by HerculesInterfaceMaker +* created by Susu +*-------------------------------------*/ +void timer_defaults(void) { + iTimer = &iTimer_s; + + /* funcs */ + iTimer->gettick = timer_gettick; + iTimer->gettick_nocache = timer_gettick_nocache; + iTimer->add_timer = timer_add; + iTimer->add_timer_interval = timer_add_interval; + iTimer->add_timer_func_list = timer_add_func_list; + iTimer->get_timer = timer_get; + iTimer->delete_timer = timer_do_delete; + iTimer->addtick_timer = timer_addtick; + iTimer->settick_timer = timer_settick; + iTimer->get_uptime = timer_get_uptime; + iTimer->do_timer = do_timer; + iTimer->init = timer_init; + iTimer->final = timer_final; } diff --git a/src/common/timer.h b/src/common/timer.h index 902679f51..d68b5ed0f 100644 --- a/src/common/timer.h +++ b/src/common/timer.h @@ -34,27 +34,36 @@ struct TimerData { intptr_t data; }; -// Function prototype declaration +/* Hercules Renewal Phase One */ +/*===================================== +* Interface : timer.h +* Generated by HerculesInterfaceMaker +* created by Susu +*-------------------------------------*/ +struct timer_interface { -int do_timer(unsigned int tick); -void timer_init(void); -void timer_final(void); + /* funcs */ + unsigned int (*gettick) (void); + unsigned int (*gettick_nocache) (void); -/* Hercules Renewal Phase One */ -unsigned int (*gettick) (void); -unsigned int (*gettick_nocache) (void); + int (*add_timer) (unsigned int tick, TimerFunc func, int id, intptr_t data); + int (*add_timer_interval) (unsigned int tick, TimerFunc func, int id, intptr_t data, int interval); + const struct TimerData *(*get_timer) (int tid); + int (*delete_timer) (int tid, TimerFunc func); + + int (*addtick_timer) (int tid, unsigned int tick); + int (*settick_timer) (int tid, unsigned int tick); -int (*add_timer) (unsigned int tick, TimerFunc func, int id, intptr_t data); -int (*add_timer_interval) (unsigned int tick, TimerFunc func, int id, intptr_t data, int interval); -const struct TimerData *(*get_timer) (int tid); -int (*delete_timer) (int tid, TimerFunc func); + int (*add_timer_func_list) (TimerFunc func, char* name); -int (*addtick_timer) (int tid, unsigned int tick); -int (*settick_timer) (int tid, unsigned int tick); + unsigned long (*get_uptime) (void); -int (*add_timer_func_list) (TimerFunc func, char* name); + int (*do_timer) (unsigned int tick); + void (*init) (void); + void (*final) (void); +} iTimer_s; -unsigned long (*get_uptime) (void); +struct timer_interface *iTimer; void timer_defaults(void); |