From a2c45a8db6d724b98ab41fe9e75e1f7ea7523d5d Mon Sep 17 00:00:00 2001 From: shennetsind Date: Thu, 2 May 2013 17:14:01 -0300 Subject: Introducing Hercules Plugin Mananger http://hercules.ws/board/topic/549-introducing-hercules-plugin-manager/ Signed-off-by: shennetsind --- src/common/HPM.c | 348 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 348 insertions(+) create mode 100644 src/common/HPM.c (limited to 'src/common/HPM.c') diff --git a/src/common/HPM.c b/src/common/HPM.c new file mode 100644 index 000000000..ec5ba888e --- /dev/null +++ b/src/common/HPM.c @@ -0,0 +1,348 @@ +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file + +#include "../common/cbasetypes.h" +#include "../common/mmo.h" +#include "../common/core.h" +#include "../common/malloc.h" +#include "../common/showmsg.h" +#include "../common/socket.h" +#include "../common/timer.h" +#include "../common/conf.h" +#include "../common/utils.h" +#include "../common/console.h" +#include "HPM.h" + +#include +#include +#include +#ifndef WIN32 +#include +#endif + +void hplugin_trigger_event(enum hp_event_types type) { + unsigned int i; + for( i = 0; i < HPM->plugin_count; i++ ) { + if( HPM->plugins[i]->hpi->event[type] != NULL ) + (HPM->plugins[i]->hpi->event[type])(); + } +} + +void hplugin_export_symbol(void *var, char *name) { + RECREATE(HPM->symbols, struct hpm_symbol *, ++HPM->symbol_count); + CREATE(HPM->symbols[HPM->symbol_count - 1] ,struct hpm_symbol, 1); + HPM->symbols[HPM->symbol_count - 1]->name = name; + HPM->symbols[HPM->symbol_count - 1]->ptr = var; +} + +void *hplugin_import_symbol(char *name) { + unsigned int i; + + for( i = 0; i < HPM->symbol_count; i++ ) { + if( strcmp(HPM->symbols[i]->name,name) == 0 ) + return HPM->symbols[i]->ptr; + } + + ShowError("HPM:get_symbol: '"CL_WHITE"%s"CL_RESET"' not found!\n",name); + return NULL; +} + +bool hplugin_iscompatible(char* version) { + unsigned int req_major = 0, req_minor = 0; + + if( version == NULL ) + return false; + + sscanf(version, "%d.%d", &req_major, &req_minor); + + return ( req_major == HPM->version[0] && req_minor <= HPM->version[1] ) ? true : false; +} + +bool hplugin_exists(const char *filename) { + unsigned int i; + for(i = 0; i < HPM->plugin_count; i++) { + if( strcmpi(HPM->plugins[i]->filename,filename) == 0 ) + return true; + } + return false; +} +struct hplugin *hplugin_create(void) { + RECREATE(HPM->plugins, struct hplugin *, ++HPM->plugin_count); + CREATE(HPM->plugins[HPM->plugin_count - 1], struct hplugin, 1); + HPM->plugins[HPM->plugin_count - 1]->idx = HPM->plugin_count - 1; + HPM->plugins[HPM->plugin_count - 1]->filename = NULL; + return HPM->plugins[HPM->plugin_count - 1]; +} +bool hplugin_showmsg_populate(struct hplugin *plugin, const char *filename) { + void **ShowSub; + const char* ShowSubNames[9] = { + "ShowMessage", + "ShowStatus", + "ShowSQL", + "ShowInfo", + "ShowNotice", + "ShowWarning", + "ShowDebug", + "ShowError", + "ShowFatalError", + }; + void* ShowSubRef[9] = { + ShowMessage, + ShowStatus, + ShowSQL, + ShowInfo, + ShowNotice, + ShowWarning, + ShowDebug, + ShowError, + ShowFatalError, + }; + int i; + for(i = 0; i < 9; i++) { + if( !( ShowSub = plugin_import(plugin->dll, ShowSubNames[i],void **) ) ) { + ShowWarning("HPM:plugin_load: failed to retrieve '%s' for '"CL_WHITE"%s"CL_RESET"', skipping...\n", ShowSubNames[i], filename); + HPM->unload(plugin); + return false; + } + *ShowSub = ShowSubRef[i]; + } + return true; +} +void hplugin_load(const char* filename) { + struct hplugin *plugin; + struct hplugin_info *info; + struct HPMi_interface **HPMi; + bool anyEvent = false; + void **import_symbol_ref; + + if( HPM->exists(filename) ) { + ShowWarning("HPM:plugin_load: attempting to load duplicate '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename); + return; + } + + plugin = HPM->create(); + + if( !( plugin->dll = plugin_open(filename) ) ){ + ShowWarning("HPM:plugin_load: failed to load '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename); + HPM->unload(plugin); + return; + } + + if( !( info = plugin_import(plugin->dll, "pinfo",struct hplugin_info*) ) ) { + ShowDebug("HPM:plugin_load: failed to retrieve 'plugin_info' for '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename); + HPM->unload(plugin); + return; + } + + if( !(info->type & SERVER_TYPE) ) { + HPM->unload(plugin); + return; + } + + if( !HPM->iscompatible(info->req_version) ) { + ShowWarning("HPM:plugin_load: '"CL_WHITE"%s"CL_RESET"' incompatible version '%s' -> '%s', skipping...\n", filename, info->req_version, HPM_VERSION); + HPM->unload(plugin); + return; + } + + if( !( import_symbol_ref = plugin_import(plugin->dll, "import_symbol",void **) ) ) { + ShowWarning("HPM:plugin_load: failed to retrieve 'import_symbol' for '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename); + HPM->unload(plugin); + return; + } + + *import_symbol_ref = HPM->import_symbol; + + if( !( HPMi = plugin_import(plugin->dll, "HPMi",struct HPMi_interface **) ) ) { + ShowWarning("HPM:plugin_load: failed to retrieve 'HPMi' for '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename); + HPM->unload(plugin); + return; + } + + if( !( *HPMi = plugin_import(plugin->dll, "HPMi_s",struct HPMi_interface *) ) ) { + ShowWarning("HPM:plugin_load: failed to retrieve 'HPMi_s' for '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename); + HPM->unload(plugin); + return; + } + plugin->hpi = *HPMi; + + if( ( plugin->hpi->event[HPET_INIT] = plugin_import(plugin->dll, "plugin_init",void (*)(void)) ) ) + anyEvent = true; + + if( ( plugin->hpi->event[HPET_FINAL] = plugin_import(plugin->dll, "plugin_final",void (*)(void)) ) ) + anyEvent = true; + + if( ( plugin->hpi->event[HPET_READY] = plugin_import(plugin->dll, "server_online",void (*)(void)) ) ) + anyEvent = true; + + if( !anyEvent ) { + ShowWarning("HPM:plugin_load: no events found for '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename); + HPM->unload(plugin); + return; + } + + if( !HPM->showmsg_pop(plugin,filename) ) + return; + + if( SERVER_TYPE == SERVER_TYPE_MAP ) { + plugin->hpi->addCommand = HPM->import_symbol("addCommand"); + plugin->hpi->addScript = HPM->import_symbol("addScript"); + plugin->hpi->addCPCommand = HPM->import_symbol("addCPCommand"); + } + + plugin->info = info; + plugin->filename = aStrdup(filename); + + return; +} + +void hplugin_unload(struct hplugin* plugin) { + unsigned int i = plugin->idx, cursor = 0; + + if( plugin->filename ) + aFree(plugin->filename); + if( plugin->dll ) + plugin_close(plugin->dll); + + aFree(plugin); + if( !HPM->off ) { + HPM->plugins[i] = NULL; + for(i = 0; i < HPM->plugin_count; i++) { + if( HPM->plugins[i] == NULL ) + continue; + if( cursor != i ) + HPM->plugins[cursor] = HPM->plugins[i]; + cursor++; + } + if( !(HPM->plugin_count = cursor) ) { + aFree(HPM->plugins); + HPM->plugins = NULL; + } + } +} + +void hplugins_config_read(void) { + config_t plugins_conf; + config_setting_t *plist = NULL; + const char *config_filename = "conf/plugins.conf"; // FIXME hardcoded name + + if (conf_read_file(&plugins_conf, config_filename)) + return; + + if( HPM->symbol_defaults_sub ) + HPM->symbol_defaults_sub(); + + plist = config_lookup(&plugins_conf, "plugins_list"); + + if (plist != NULL) { + int length = config_setting_length(plist), i; + char filename[60]; + for(i = 0; i < length; i++) { + snprintf(filename, 60, "plugins/%s%s", config_setting_get_string_elem(plist,i), DLL_EXT); + HPM->load(filename); + } + config_destroy(&plugins_conf); + } + + if( HPM->plugin_count ) + ShowStatus("HPM: There are '"CL_WHITE"%d"CL_RESET"' plugins loaded, type '"CL_WHITE"plugins"CL_RESET"' to list them\n", HPM->plugin_count); +} +void hplugins_share_defaults(void) { + /* console */ + HPM->share(console->addCommand,"addCPCommand"); + /* core */ + HPM->share(&runflag,"runflag"); + HPM->share(arg_v,"arg_v"); + HPM->share(&arg_c,"arg_c"); + HPM->share(SERVER_NAME,"SERVER_NAME"); + HPM->share(&SERVER_TYPE,"SERVER_TYPE"); + HPM->share((void*)get_svn_revision,"get_svn_revision"); + HPM->share((void*)get_git_hash,"get_git_hash"); + /* socket */ + HPM->share(RFIFOSKIP,"RFIFOSKIP"); + HPM->share(WFIFOSET,"WFIFOSET"); + HPM->share(do_close,"do_close"); + HPM->share(make_connection,"make_connection"); + HPM->share(session,"session"); + HPM->share(&fd_max,"fd_max"); + HPM->share(addr_,"addr"); + /* 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"); +} +CPCMD(plugins) { + if( HPM->plugin_count == 0 ) { + ShowInfo("HPC: there are no plugins loaded\n"); + } else { + unsigned int i; + + ShowInfo("HPC: There are '"CL_WHITE"%d"CL_RESET"' plugins loaded\n",HPM->plugin_count); + + for(i = 0; i < HPM->plugin_count; i++) { + ShowInfo("HPC: - '"CL_WHITE"%s"CL_RESET"' (%s)\n",HPM->plugins[i]->info->name,HPM->plugins[i]->filename); + } + } +} +void hpm_init(void) { + HPM->symbols = NULL; + HPM->plugins = NULL; + HPM->plugin_count = HPM->symbol_count = 0; + HPM->off = false; + + sscanf(HPM_VERSION, "%d.%d", &HPM->version[0], &HPM->version[1]); + + if( HPM->version[0] == 0 && HPM->version[1] == 0 ) { + ShowError("HPM:init:failed to retrieve HPM version!!\n"); + return; + } + HPM->symbol_defaults(); + + console->addCommand("plugins",CPCMD_A(plugins)); + + return; +} + +void hpm_final(void) { + unsigned int i; + + HPM->off = true; + + for( i = 0; i < HPM->plugin_count; i++ ) { + HPM->unload(HPM->plugins[i]); + } + + if( HPM->plugins ) + aFree(HPM->plugins); + + for( i = 0; i < HPM->symbol_count; i++ ) { + aFree(HPM->symbols[i]); + } + + if( HPM->symbols ) + aFree(HPM->symbols); + + return; +} +void hpm_defaults(void) { + HPM = &HPM_s; + + HPM->init = hpm_init; + HPM->final = hpm_final; + + HPM->create = hplugin_create; + HPM->load = hplugin_load; + HPM->unload = hplugin_unload; + HPM->event = hplugin_trigger_event; + HPM->exists = hplugin_exists; + HPM->iscompatible = hplugin_iscompatible; + HPM->import_symbol = hplugin_import_symbol; + HPM->share = hplugin_export_symbol; + HPM->symbol_defaults = hplugins_share_defaults; + HPM->config_read = hplugins_config_read; + HPM->showmsg_pop = hplugin_showmsg_populate; + HPM->symbol_defaults_sub = NULL; +} \ No newline at end of file -- cgit v1.2.3-70-g09d2 From eac1a8a7537ae7ff78c45261f8916c2886762cd4 Mon Sep 17 00:00:00 2001 From: shennetsind Date: Fri, 3 May 2013 12:39:12 -0300 Subject: Fixed Bug #7212 http://hercules.ws/board/tracker/issue-7212-warning-while-recompiling-using-centos5/ Signed-off-by: shennetsind --- src/common/HPM.c | 2 +- src/common/HPM.h | 2 +- src/common/HPMi.h | 2 +- src/map/chrif.c | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src/common/HPM.c') diff --git a/src/common/HPM.c b/src/common/HPM.c index ec5ba888e..4802fbc61 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -345,4 +345,4 @@ void hpm_defaults(void) { HPM->config_read = hplugins_config_read; HPM->showmsg_pop = hplugin_showmsg_populate; HPM->symbol_defaults_sub = NULL; -} \ No newline at end of file +} diff --git a/src/common/HPM.h b/src/common/HPM.h index ac2c4050f..87d7bdac6 100644 --- a/src/common/HPM.h +++ b/src/common/HPM.h @@ -80,4 +80,4 @@ struct HPM_interface *HPM; void hpm_defaults(void); -#endif /* _HPM_H_ */ \ No newline at end of file +#endif /* _HPM_H_ */ diff --git a/src/common/HPMi.h b/src/common/HPMi.h index 517d9125d..f7832d0ec 100644 --- a/src/common/HPMi.h +++ b/src/common/HPMi.h @@ -64,4 +64,4 @@ struct HPMi_interface { struct HPMi_interface *HPMi; #endif -#endif /* _HPMi_H_ */ \ No newline at end of file +#endif /* _HPMi_H_ */ diff --git a/src/map/chrif.c b/src/map/chrif.c index e2ce37e28..cf7886422 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -1648,3 +1648,4 @@ int do_init_chrif(void) { return 0; } + -- cgit v1.2.3-70-g09d2 From c5986ba47dbd5034018ab288c39feee7ff5d7d1f Mon Sep 17 00:00:00 2001 From: shennetsind Date: Sat, 4 May 2013 15:40:59 -0300 Subject: Upgrading Stat Server from 2.5 to 3.0 also: modified encode_zip in grfio for a upcoming modification and some minor stuff in some other places. Signed-off-by: shennetsind --- src/char/char.c | 550 ++++++++++++++++++++++++++-------------------------- src/common/HPM.c | 2 +- src/common/grfio.c | 13 +- src/common/socket.c | 7 +- src/map/battle.c | 55 ++++-- src/map/chrif.c | 22 +-- 6 files changed, 337 insertions(+), 312 deletions(-) (limited to 'src/common/HPM.c') diff --git a/src/char/char.c b/src/char/char.c index f674cc0c7..ba3179ef9 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -2127,304 +2127,302 @@ int parse_fromlogin(int fd) { while(RFIFOREST(fd) >= 2) { uint16 command = RFIFOW(fd,0); + switch( command ) { - switch( command ) - { - - // acknowledgement of connect-to-loginserver request - case 0x2711: - if (RFIFOREST(fd) < 3) - return 0; + // acknowledgement of connect-to-loginserver request + case 0x2711: + if (RFIFOREST(fd) < 3) + return 0; - if (RFIFOB(fd,2)) { - //printf("connect login server error : %d\n", RFIFOB(fd,2)); - ShowError("Can not connect to login-server.\n"); - ShowError("The server communication passwords (default s1/p1) are probably invalid.\n"); - ShowError("Also, please make sure your login db has the correct communication username/passwords and the gender of the account is S.\n"); - ShowError("The communication passwords are set in /conf/map-server.conf and /conf/char-server.conf\n"); - set_eof(fd); - return 0; - } else { - ShowStatus("Connected to login-server (connection #%d).\n", fd); - loginif_on_ready(); - } - RFIFOSKIP(fd,3); - break; + if (RFIFOB(fd,2)) { + //printf("connect login server error : %d\n", RFIFOB(fd,2)); + ShowError("Can not connect to login-server.\n"); + ShowError("The server communication passwords (default s1/p1) are probably invalid.\n"); + ShowError("Also, please make sure your login db has the correct communication username/passwords and the gender of the account is S.\n"); + ShowError("The communication passwords are set in /conf/map-server.conf and /conf/char-server.conf\n"); + set_eof(fd); + return 0; + } else { + ShowStatus("Connected to login-server (connection #%d).\n", fd); + loginif_on_ready(); + } + RFIFOSKIP(fd,3); + break; - // acknowledgement of account authentication request - case 0x2713: - if (RFIFOREST(fd) < 25) - return 0; - { - int account_id = RFIFOL(fd,2); - uint32 login_id1 = RFIFOL(fd,6); - uint32 login_id2 = RFIFOL(fd,10); - uint8 sex = RFIFOB(fd,14); - uint8 result = RFIFOB(fd,15); - int request_id = RFIFOL(fd,16); - uint32 version = RFIFOL(fd,20); - uint8 clienttype = RFIFOB(fd,24); - RFIFOSKIP(fd,25); - - if( session_isActive(request_id) && (sd=(struct char_session_data*)session[request_id]->session_data) && - !sd->auth && sd->account_id == account_id && sd->login_id1 == login_id1 && sd->login_id2 == login_id2 && sd->sex == sex ) + // acknowledgement of account authentication request + case 0x2713: + if (RFIFOREST(fd) < 25) + return 0; { - int client_fd = request_id; - sd->version = version; - sd->clienttype = clienttype; - switch( result ) + int account_id = RFIFOL(fd,2); + uint32 login_id1 = RFIFOL(fd,6); + uint32 login_id2 = RFIFOL(fd,10); + uint8 sex = RFIFOB(fd,14); + uint8 result = RFIFOB(fd,15); + int request_id = RFIFOL(fd,16); + uint32 version = RFIFOL(fd,20); + uint8 clienttype = RFIFOB(fd,24); + RFIFOSKIP(fd,25); + + if( session_isActive(request_id) && (sd=(struct char_session_data*)session[request_id]->session_data) && + !sd->auth && sd->account_id == account_id && sd->login_id1 == login_id1 && sd->login_id2 == login_id2 && sd->sex == sex ) { - case 0:// ok - char_auth_ok(client_fd, sd); - break; - case 1:// auth failed - WFIFOHEAD(client_fd,3); - WFIFOW(client_fd,0) = 0x6c; - WFIFOB(client_fd,2) = 0;// rejected from server - WFIFOSET(client_fd,3); - break; + int client_fd = request_id; + sd->version = version; + sd->clienttype = clienttype; + switch( result ) + { + case 0:// ok + char_auth_ok(client_fd, sd); + break; + case 1:// auth failed + WFIFOHEAD(client_fd,3); + WFIFOW(client_fd,0) = 0x6c; + WFIFOB(client_fd,2) = 0;// rejected from server + WFIFOSET(client_fd,3); + break; + } } } - } - break; + break; - case 0x2717: // account data - if (RFIFOREST(fd) < 72) - return 0; + case 0x2717: // account data + if (RFIFOREST(fd) < 72) + return 0; - // find the authenticated session with this account id - ARR_FIND( 0, fd_max, i, session[i] && (sd = (struct char_session_data*)session[i]->session_data) && sd->auth && sd->account_id == RFIFOL(fd,2) ); - if( i < fd_max ) { - int server_id; - memcpy(sd->email, RFIFOP(fd,6), 40); - sd->expiration_time = (time_t)RFIFOL(fd,46); - sd->group_id = RFIFOB(fd,50); - sd->char_slots = RFIFOB(fd,51); - if( sd->char_slots > MAX_CHARS ) { - ShowError("Account '%d' `character_slots` column is higher than supported MAX_CHARS (%d), update MAX_CHARS in mmo.h! capping to MAX_CHARS...\n",sd->account_id,sd->char_slots); - sd->char_slots = MAX_CHARS;/* cap to maximum */ - } else if ( sd->char_slots <= 0 )/* no value aka 0 in sql */ - sd->char_slots = MAX_CHARS;/* cap to maximum */ - safestrncpy(sd->birthdate, (const char*)RFIFOP(fd,52), sizeof(sd->birthdate)); - safestrncpy(sd->pincode, (const char*)RFIFOP(fd,63), sizeof(sd->pincode)); - sd->pincode_change = RFIFOL(fd,68); - ARR_FIND( 0, ARRAYLENGTH(server), server_id, server[server_id].fd > 0 && server[server_id].map[0] ); - // continued from char_auth_ok... - if( server_id == ARRAYLENGTH(server) || //server not online, bugreport:2359 - (max_connect_user == 0 && sd->group_id != gm_allow_group) || - ( max_connect_user > 0 && count_users() >= max_connect_user && sd->group_id != gm_allow_group ) ) { - // refuse connection (over populated) - WFIFOHEAD(i,3); - WFIFOW(i,0) = 0x6c; - WFIFOW(i,2) = 0; - WFIFOSET(i,3); - } else { - // send characters to player -#if PACKETVER >= 20130000 - mmo_char_send082d(i, sd); -#else - mmo_char_send006b(i, sd); -#endif -#if PACKETVER >= 20110309 - pincode->handle(i, sd); -#endif + // find the authenticated session with this account id + ARR_FIND( 0, fd_max, i, session[i] && (sd = (struct char_session_data*)session[i]->session_data) && sd->auth && sd->account_id == RFIFOL(fd,2) ); + if( i < fd_max ) { + int server_id; + memcpy(sd->email, RFIFOP(fd,6), 40); + sd->expiration_time = (time_t)RFIFOL(fd,46); + sd->group_id = RFIFOB(fd,50); + sd->char_slots = RFIFOB(fd,51); + if( sd->char_slots > MAX_CHARS ) { + ShowError("Account '%d' `character_slots` column is higher than supported MAX_CHARS (%d), update MAX_CHARS in mmo.h! capping to MAX_CHARS...\n",sd->account_id,sd->char_slots); + sd->char_slots = MAX_CHARS;/* cap to maximum */ + } else if ( sd->char_slots <= 0 )/* no value aka 0 in sql */ + sd->char_slots = MAX_CHARS;/* cap to maximum */ + safestrncpy(sd->birthdate, (const char*)RFIFOP(fd,52), sizeof(sd->birthdate)); + safestrncpy(sd->pincode, (const char*)RFIFOP(fd,63), sizeof(sd->pincode)); + sd->pincode_change = RFIFOL(fd,68); + ARR_FIND( 0, ARRAYLENGTH(server), server_id, server[server_id].fd > 0 && server[server_id].map[0] ); + // continued from char_auth_ok... + if( server_id == ARRAYLENGTH(server) || //server not online, bugreport:2359 + (max_connect_user == 0 && sd->group_id != gm_allow_group) || + ( max_connect_user > 0 && count_users() >= max_connect_user && sd->group_id != gm_allow_group ) ) { + // refuse connection (over populated) + WFIFOHEAD(i,3); + WFIFOW(i,0) = 0x6c; + WFIFOW(i,2) = 0; + WFIFOSET(i,3); + } else { + // send characters to player + #if PACKETVER >= 20130000 + mmo_char_send082d(i, sd); + #else + mmo_char_send006b(i, sd); + #endif + #if PACKETVER >= 20110309 + pincode->handle(i, sd); + #endif + } } - } - RFIFOSKIP(fd,72); - break; + RFIFOSKIP(fd,72); + break; - // login-server alive packet - case 0x2718: - if (RFIFOREST(fd) < 2) - return 0; - RFIFOSKIP(fd,2); - session[fd]->flag.ping = 0; - break; + // login-server alive packet + case 0x2718: + if (RFIFOREST(fd) < 2) + return 0; + RFIFOSKIP(fd,2); + session[fd]->flag.ping = 0; + break; - // changesex reply - case 0x2723: - if (RFIFOREST(fd) < 7) - return 0; - { - unsigned char buf[7]; - - int acc = RFIFOL(fd,2); - int sex = RFIFOB(fd,6); - RFIFOSKIP(fd,7); - - if( acc > 0 ) - {// TODO: Is this even possible? - int char_id[MAX_CHARS]; - int class_[MAX_CHARS]; - int guild_id[MAX_CHARS]; - int num; - char* data; + // changesex reply + case 0x2723: + if (RFIFOREST(fd) < 7) + return 0; + { + unsigned char buf[7]; + + int acc = RFIFOL(fd,2); + int sex = RFIFOB(fd,6); + RFIFOSKIP(fd,7); + + if( acc > 0 ) + {// TODO: Is this even possible? + int char_id[MAX_CHARS]; + int class_[MAX_CHARS]; + int guild_id[MAX_CHARS]; + int num; + char* data; - struct auth_node* node = (struct auth_node*)idb_get(auth_db, acc); - if( node != NULL ) - node->sex = sex; + struct auth_node* node = (struct auth_node*)idb_get(auth_db, acc); + if( node != NULL ) + node->sex = sex; - // get characters - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `char_id`,`class`,`guild_id` FROM `%s` WHERE `account_id` = '%d'", char_db, acc) ) - Sql_ShowDebug(sql_handle); - for( i = 0; i < MAX_CHARS && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) - { - Sql_GetData(sql_handle, 0, &data, NULL); char_id[i] = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); class_[i] = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); guild_id[i] = atoi(data); - } - num = i; - for( i = 0; i < num; ++i ) - { - if( class_[i] == JOB_BARD || class_[i] == JOB_DANCER || - class_[i] == JOB_CLOWN || class_[i] == JOB_GYPSY || - class_[i] == JOB_BABY_BARD || class_[i] == JOB_BABY_DANCER || - class_[i] == JOB_MINSTREL || class_[i] == JOB_WANDERER || - class_[i] == JOB_MINSTREL_T || class_[i] == JOB_WANDERER_T || - class_[i] == JOB_BABY_MINSTREL || class_[i] == JOB_BABY_WANDERER || - class_[i] == JOB_KAGEROU || class_[i] == JOB_OBORO ) + // get characters + if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `char_id`,`class`,`guild_id` FROM `%s` WHERE `account_id` = '%d'", char_db, acc) ) + Sql_ShowDebug(sql_handle); + for( i = 0; i < MAX_CHARS && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) { - // job modification - if( class_[i] == JOB_BARD || class_[i] == JOB_DANCER ) - class_[i] = (sex ? JOB_BARD : JOB_DANCER); - else if( class_[i] == JOB_CLOWN || class_[i] == JOB_GYPSY ) - class_[i] = (sex ? JOB_CLOWN : JOB_GYPSY); - else if( class_[i] == JOB_BABY_BARD || class_[i] == JOB_BABY_DANCER ) - class_[i] = (sex ? JOB_BABY_BARD : JOB_BABY_DANCER); - else if( class_[i] == JOB_MINSTREL || class_[i] == JOB_WANDERER ) - class_[i] = (sex ? JOB_MINSTREL : JOB_WANDERER); - else if( class_[i] == JOB_MINSTREL_T || class_[i] == JOB_WANDERER_T ) - class_[i] = (sex ? JOB_MINSTREL_T : JOB_WANDERER_T); - else if( class_[i] == JOB_BABY_MINSTREL || class_[i] == JOB_BABY_WANDERER ) - class_[i] = (sex ? JOB_BABY_MINSTREL : JOB_BABY_WANDERER); - else if( class_[i] == JOB_KAGEROU || class_[i] == JOB_OBORO ) - class_[i] = (sex ? JOB_KAGEROU : JOB_OBORO); + Sql_GetData(sql_handle, 0, &data, NULL); char_id[i] = atoi(data); + Sql_GetData(sql_handle, 1, &data, NULL); class_[i] = atoi(data); + Sql_GetData(sql_handle, 2, &data, NULL); guild_id[i] = atoi(data); } + num = i; + for( i = 0; i < num; ++i ) + { + if( class_[i] == JOB_BARD || class_[i] == JOB_DANCER || + class_[i] == JOB_CLOWN || class_[i] == JOB_GYPSY || + class_[i] == JOB_BABY_BARD || class_[i] == JOB_BABY_DANCER || + class_[i] == JOB_MINSTREL || class_[i] == JOB_WANDERER || + class_[i] == JOB_MINSTREL_T || class_[i] == JOB_WANDERER_T || + class_[i] == JOB_BABY_MINSTREL || class_[i] == JOB_BABY_WANDERER || + class_[i] == JOB_KAGEROU || class_[i] == JOB_OBORO ) + { + // job modification + if( class_[i] == JOB_BARD || class_[i] == JOB_DANCER ) + class_[i] = (sex ? JOB_BARD : JOB_DANCER); + else if( class_[i] == JOB_CLOWN || class_[i] == JOB_GYPSY ) + class_[i] = (sex ? JOB_CLOWN : JOB_GYPSY); + else if( class_[i] == JOB_BABY_BARD || class_[i] == JOB_BABY_DANCER ) + class_[i] = (sex ? JOB_BABY_BARD : JOB_BABY_DANCER); + else if( class_[i] == JOB_MINSTREL || class_[i] == JOB_WANDERER ) + class_[i] = (sex ? JOB_MINSTREL : JOB_WANDERER); + else if( class_[i] == JOB_MINSTREL_T || class_[i] == JOB_WANDERER_T ) + class_[i] = (sex ? JOB_MINSTREL_T : JOB_WANDERER_T); + else if( class_[i] == JOB_BABY_MINSTREL || class_[i] == JOB_BABY_WANDERER ) + class_[i] = (sex ? JOB_BABY_MINSTREL : JOB_BABY_WANDERER); + else if( class_[i] == JOB_KAGEROU || class_[i] == JOB_OBORO ) + class_[i] = (sex ? JOB_KAGEROU : JOB_OBORO); + } - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `class`='%d', `weapon`='0', `shield`='0', `head_top`='0', `head_mid`='0', `head_bottom`='0' WHERE `char_id`='%d'", char_db, class_[i], char_id[i]) ) - Sql_ShowDebug(sql_handle); + if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `class`='%d', `weapon`='0', `shield`='0', `head_top`='0', `head_mid`='0', `head_bottom`='0' WHERE `char_id`='%d'", char_db, class_[i], char_id[i]) ) + Sql_ShowDebug(sql_handle); + + if( guild_id[i] )// If there is a guild, update the guild_member data [Skotlex] + inter_guild_sex_changed(guild_id[i], acc, char_id[i], sex); + } + Sql_FreeResult(sql_handle); - if( guild_id[i] )// If there is a guild, update the guild_member data [Skotlex] - inter_guild_sex_changed(guild_id[i], acc, char_id[i], sex); + // disconnect player if online on char-server + disconnect_player(acc); } - Sql_FreeResult(sql_handle); - // disconnect player if online on char-server - disconnect_player(acc); + // notify all mapservers about this change + WBUFW(buf,0) = 0x2b0d; + WBUFL(buf,2) = acc; + WBUFB(buf,6) = sex; + mapif_sendall(buf, 7); } + break; - // notify all mapservers about this change - WBUFW(buf,0) = 0x2b0d; - WBUFL(buf,2) = acc; - WBUFB(buf,6) = sex; - mapif_sendall(buf, 7); - } - break; - - // reply to an account_reg2 registry request - case 0x2729: - if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2)) - return 0; + // reply to an account_reg2 registry request + case 0x2729: + if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2)) + return 0; - { //Receive account_reg2 registry, forward to map servers. - unsigned char buf[13+ACCOUNT_REG2_NUM*sizeof(struct global_reg)]; - memcpy(buf,RFIFOP(fd,0), RFIFOW(fd,2)); - WBUFW(buf,0) = 0x3804; //Map server can now receive all kinds of reg values with the same packet. [Skotlex] - mapif_sendall(buf, WBUFW(buf,2)); - RFIFOSKIP(fd, RFIFOW(fd,2)); - } - break; + { //Receive account_reg2 registry, forward to map servers. + unsigned char buf[13+ACCOUNT_REG2_NUM*sizeof(struct global_reg)]; + memcpy(buf,RFIFOP(fd,0), RFIFOW(fd,2)); + WBUFW(buf,0) = 0x3804; //Map server can now receive all kinds of reg values with the same packet. [Skotlex] + mapif_sendall(buf, WBUFW(buf,2)); + RFIFOSKIP(fd, RFIFOW(fd,2)); + } + break; - // State change of account/ban notification (from login-server) - case 0x2731: - if (RFIFOREST(fd) < 11) - return 0; + // State change of account/ban notification (from login-server) + case 0x2731: + if (RFIFOREST(fd) < 11) + return 0; - { // send to all map-servers to disconnect the player - unsigned char buf[11]; - WBUFW(buf,0) = 0x2b14; - WBUFL(buf,2) = RFIFOL(fd,2); - WBUFB(buf,6) = RFIFOB(fd,6); // 0: change of statut, 1: ban - WBUFL(buf,7) = RFIFOL(fd,7); // status or final date of a banishment - mapif_sendall(buf, 11); - } - // disconnect player if online on char-server - disconnect_player(RFIFOL(fd,2)); + { // send to all map-servers to disconnect the player + unsigned char buf[11]; + WBUFW(buf,0) = 0x2b14; + WBUFL(buf,2) = RFIFOL(fd,2); + WBUFB(buf,6) = RFIFOB(fd,6); // 0: change of statut, 1: ban + WBUFL(buf,7) = RFIFOL(fd,7); // status or final date of a banishment + mapif_sendall(buf, 11); + } + // disconnect player if online on char-server + disconnect_player(RFIFOL(fd,2)); - RFIFOSKIP(fd,11); - break; + RFIFOSKIP(fd,11); + break; - // Login server request to kick a character out. [Skotlex] - case 0x2734: - if (RFIFOREST(fd) < 6) - return 0; - { - int aid = RFIFOL(fd,2); - struct online_char_data* character = (struct online_char_data*)idb_get(online_char_db, aid); - RFIFOSKIP(fd,6); - if( character != NULL ) - {// account is already marked as online! - if( character->server > -1 ) - { //Kick it from the map server it is on. - mapif_disconnectplayer(server[character->server].fd, character->account_id, character->char_id, 2); - if (character->waiting_disconnect == INVALID_TIMER) - character->waiting_disconnect = add_timer(gettick()+AUTH_TIMEOUT, chardb_waiting_disconnect, character->account_id, 0); - } - else - {// Manual kick from char server. - struct char_session_data *tsd; - int i; - ARR_FIND( 0, fd_max, i, session[i] && (tsd = (struct char_session_data*)session[i]->session_data) && tsd->account_id == aid ); - if( i < fd_max ) - { - WFIFOHEAD(i,3); - WFIFOW(i,0) = 0x81; - WFIFOB(i,2) = 2; // "Someone has already logged in with this id" - WFIFOSET(i,3); - set_eof(i); + // Login server request to kick a character out. [Skotlex] + case 0x2734: + if (RFIFOREST(fd) < 6) + return 0; + { + int aid = RFIFOL(fd,2); + struct online_char_data* character = (struct online_char_data*)idb_get(online_char_db, aid); + RFIFOSKIP(fd,6); + if( character != NULL ) + {// account is already marked as online! + if( character->server > -1 ) + { //Kick it from the map server it is on. + mapif_disconnectplayer(server[character->server].fd, character->account_id, character->char_id, 2); + if (character->waiting_disconnect == INVALID_TIMER) + character->waiting_disconnect = add_timer(gettick()+AUTH_TIMEOUT, chardb_waiting_disconnect, character->account_id, 0); + } + else + {// Manual kick from char server. + struct char_session_data *tsd; + int i; + ARR_FIND( 0, fd_max, i, session[i] && (tsd = (struct char_session_data*)session[i]->session_data) && tsd->account_id == aid ); + if( i < fd_max ) + { + WFIFOHEAD(i,3); + WFIFOW(i,0) = 0x81; + WFIFOB(i,2) = 2; // "Someone has already logged in with this id" + WFIFOSET(i,3); + set_eof(i); + } + else // still moving to the map-server + set_char_offline(-1, aid); } - else // still moving to the map-server - set_char_offline(-1, aid); } + idb_remove(auth_db, aid);// reject auth attempts from map-server } - idb_remove(auth_db, aid);// reject auth attempts from map-server - } - break; + break; - // ip address update signal from login server - case 0x2735: - { - unsigned char buf[2]; - uint32 new_ip = 0; - - WBUFW(buf,0) = 0x2b1e; - mapif_sendall(buf, 2); - - new_ip = host2ip(login_ip_str); - if (new_ip && new_ip != login_ip) - login_ip = new_ip; //Update login ip, too. - - new_ip = host2ip(char_ip_str); - if (new_ip && new_ip != char_ip) - { //Update ip. - char_ip = new_ip; - ShowInfo("Updating IP for [%s].\n", char_ip_str); - // notify login server about the change - WFIFOHEAD(fd,6); - WFIFOW(fd,0) = 0x2736; - WFIFOL(fd,2) = htonl(char_ip); - WFIFOSET(fd,6); - } + // ip address update signal from login server + case 0x2735: + { + unsigned char buf[2]; + uint32 new_ip = 0; + + WBUFW(buf,0) = 0x2b1e; + mapif_sendall(buf, 2); + + new_ip = host2ip(login_ip_str); + if (new_ip && new_ip != login_ip) + login_ip = new_ip; //Update login ip, too. + + new_ip = host2ip(char_ip_str); + if (new_ip && new_ip != char_ip) + { //Update ip. + char_ip = new_ip; + ShowInfo("Updating IP for [%s].\n", char_ip_str); + // notify login server about the change + WFIFOHEAD(fd,6); + WFIFOW(fd,0) = 0x2736; + WFIFOL(fd,2) = htonl(char_ip); + WFIFOSET(fd,6); + } - RFIFOSKIP(fd,2); - } - break; + RFIFOSKIP(fd,2); + } + break; - default: - ShowError("Unknown packet 0x%04x received from login-server, disconnecting.\n", command); - set_eof(fd); - return 0; - } + default: + ShowError("Unknown packet 0x%04x received from login-server, disconnecting.\n", command); + set_eof(fd); + return 0; + } } RFIFOFLUSH(fd); @@ -2670,14 +2668,12 @@ int parse_frommap(int fd) int id; ARR_FIND( 0, ARRAYLENGTH(server), id, server[id].fd == fd ); - if( id == ARRAYLENGTH(server) ) - {// not a map server + if( id == ARRAYLENGTH(server) ) {// not a map server ShowDebug("parse_frommap: Disconnecting invalid session #%d (is not a map-server)\n", fd); do_close(fd); return 0; } - if( session[fd]->flag.eof ) - { + if( session[fd]->flag.eof ) { do_close(fd); server[id].fd = -1; mapif_on_disconnect(id); @@ -2685,7 +2681,6 @@ int parse_frommap(int fd) } while(RFIFOREST(fd) >= 2) { - switch(RFIFOW(fd,0)) { case 0x2b0a: @@ -3299,6 +3294,7 @@ 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 @@ -3381,16 +3377,18 @@ int parse_frommap(int fd) if( RFIFOREST(fd) < RFIFOW(fd,4) ) return 0;/* packet wasn't fully received yet (still fragmented) */ else { - int sfd;/* stat server fd */ + int sfd;/* stat server fd */ RFIFOSKIP(fd, 2);/* we skip first 2 bytes which are the 0x3008, so we end up with a buffer equal to the one we send */ - if( (sfd = make_connection(host2ip("stats.hercules.ws"),(uint16)25421,true) ) == -1 ) { + if( (sfd = make_connection(host2ip("stats.hercules.ws"),(uint16)25427,true) ) == -1 ) { RFIFOSKIP(fd, RFIFOW(fd,2) );/* skip this packet */ + RFIFOFLUSH(fd); break;/* connection not possible, we drop the report */ } - + session[sfd]->flag.server = 1;/* to ensure we won't drop our own packet */ - + realloc_fifo(sfd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK); + WFIFOHEAD(sfd, RFIFOW(fd,2) ); memcpy((char*)WFIFOP(sfd,0), (char*)RFIFOP(fd, 0), RFIFOW(fd,2)); @@ -3400,8 +3398,9 @@ int parse_frommap(int fd) flush_fifo(sfd); do_close(sfd); - + RFIFOSKIP(fd, RFIFOW(fd,2) );/* skip this packet */ + RFIFOFLUSH(fd); } break; @@ -3728,6 +3727,7 @@ int parse_char(int fd) #define FIFOSD_CHECK(rest) { if(RFIFOREST(fd) < rest) return 0; if (sd==NULL || !sd->auth) { RFIFOSKIP(fd,rest); return 0; } } cmd = RFIFOW(fd,0); + switch( cmd ) { // request to connect diff --git a/src/common/HPM.c b/src/common/HPM.c index 4802fbc61..2df559c82 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -53,7 +53,7 @@ bool hplugin_iscompatible(char* version) { if( version == NULL ) return false; - sscanf(version, "%d.%d", &req_major, &req_minor); + sscanf(version, "%u.%u", &req_major, &req_minor); return ( req_major == HPM->version[0] && req_minor <= HPM->version[1] ) ? true : false; } diff --git a/src/common/grfio.c b/src/common/grfio.c index cc2f866f7..bf66dba52 100644 --- a/src/common/grfio.c +++ b/src/common/grfio.c @@ -1,5 +1,6 @@ -// 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 #include "../common/cbasetypes.h" #include "../common/des.h" @@ -250,8 +251,12 @@ int decode_zip(void* dest, unsigned long* destLen, const void* source, unsigned /// zlib compress -int encode_zip(void* dest, unsigned long* destLen, const void* source, unsigned long sourceLen) -{ +int encode_zip(void* dest, unsigned long* destLen, const void* source, unsigned long sourceLen) { + if( *destLen == 0 ) /* [Ind/Hercules] */ + *destLen = compressBound(sourceLen); + if( dest == NULL ) { /* [Ind/Hercules] */ + CREATE(dest, unsigned char, *destLen); + } return compress((Bytef*)dest, destLen, (const Bytef*)source, sourceLen); } diff --git a/src/common/socket.c b/src/common/socket.c index 79ccdf5dc..5126d231b 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -1,5 +1,6 @@ -// 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 #include "../common/cbasetypes.h" #include "../common/mmo.h" @@ -812,7 +813,7 @@ int do_sockets(int next) continue; // after parse, check client's RFIFO size to know if there is an invalid packet (too big and not parsed) - if (session[i]->rdata_size == RFIFO_SIZE && session[i]->max_rdata == RFIFO_SIZE) { + if (session[i]->rdata_size == session[i]->max_rdata) { set_eof(i); continue; } diff --git a/src/map/battle.c b/src/map/battle.c index ed0b87e6f..796938926 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -5940,9 +5940,10 @@ static const struct _battle_data { * Hercules anonymous statistic usage report -- packet is built here, and sent to char server to report. **/ void Hercules_report(char* date, char *time_c) { - int i, rev = 0, bd_size = ARRAYLENGTH(battle_data); + int i, bd_size = ARRAYLENGTH(battle_data); unsigned int config = 0; - const char* rev_str; + const char *svn = get_svn_revision(); + const char *git = get_git_hash(); char timestring[25]; time_t curtime; char* buf; @@ -5950,7 +5951,7 @@ void Hercules_report(char* date, char *time_c) { enum config_table { C_CIRCULAR_AREA = 0x0001, C_CELLNOSTACK = 0x0002, - //C_BETA_THREAD_TEST = 0x0004, (free slot) + C_CONSOLE_INPUT = 0x0004, C_SCRIPT_CALLFUNC_CHECK = 0x0008, C_OFFICIAL_WALKPATH = 0x0010, C_RENEWAL = 0x0020, @@ -5963,16 +5964,16 @@ void Hercules_report(char* date, char *time_c) { C_SECURE_NPCTIMEOUT = 0x1000, C_SQL_DBS = 0x2000, C_SQL_LOGS = 0x4000, + C_MEMWATCH = 0x8000, + C_DMALLOC = 0x10000, + C_GCOLLECT = 0x20000, + C_SEND_SHORTLIST = 0x40000, }; - if( (rev_str = get_svn_revision()) != 0 ) - rev = atoi(rev_str); - /* we get the current time */ time(&curtime); strftime(timestring, 24, "%Y-%m-%d %H:%M:%S", localtime(&curtime)); - - + #ifdef CIRCULAR_AREA config |= C_CIRCULAR_AREA; #endif @@ -5981,6 +5982,10 @@ void Hercules_report(char* date, char *time_c) { config |= C_CELLNOSTACK; #endif +#ifdef CONSOLE_INPUT + config |= C_CONSOLE_INPUT; +#endif + #ifdef SCRIPT_CALLFUNC_CHECK config |= C_SCRIPT_CALLFUNC_CHECK; #endif @@ -6028,32 +6033,46 @@ void Hercules_report(char* date, char *time_c) { if( logs->config.sql_logs ) config |= C_SQL_LOGS; +#ifdef MEMWATCH + config |= C_MEMWATCH; +#endif +#ifdef DMALLOC + config |= C_DMALLOC; +#endif +#ifdef GCOLLECT + config |= C_GCOLLECT; +#endif + +#ifdef SEND_SHORTLIST + config |= C_SEND_SHORTLIST; +#endif + #define BFLAG_LENGTH 35 - CREATE(buf, char, 6 + 12 + 9 + 24 + 4 + 4 + 4 + 4 + ( bd_size * ( BFLAG_LENGTH + 4 ) ) + 1 ); + CREATE(buf, char, 6 + 12 + 9 + 24 + 41 + 4 + 4 + 4 + ( bd_size * ( BFLAG_LENGTH + 4 ) ) + 1 ); /* build packet */ WBUFW(buf,0) = 0x3000; - WBUFW(buf,2) = 6 + 12 + 9 + 24 + 4 + 4 + 4 + 4 + ( bd_size * ( BFLAG_LENGTH + 4 ) ); - WBUFW(buf,4) = 0x9c; + WBUFW(buf,2) = 6 + 12 + 9 + 24 + 41 + 4 + 4 + 4 + ( bd_size * ( BFLAG_LENGTH + 4 ) ); + WBUFW(buf,4) = 0x9e; safestrncpy((char*)WBUFP(buf,6), date, 12); safestrncpy((char*)WBUFP(buf,6 + 12), time_c, 9); safestrncpy((char*)WBUFP(buf,6 + 12 + 9), timestring, 24); - WBUFL(buf,6 + 12 + 9 + 24) = rev; - WBUFL(buf,6 + 12 + 9 + 24 + 4) = map_getusers(); + safestrncpy((char*)WBUFP(buf,6 + 12 + 9 + 24), git[0] != HERC_UNKNOWN_VER ? git : svn[0] != HERC_UNKNOWN_VER ? svn : "Unknown", 41); + WBUFL(buf,6 + 12 + 9 + 24 + 41) = map_getusers(); - WBUFL(buf,6 + 12 + 9 + 24 + 4 + 4) = config; - WBUFL(buf,6 + 12 + 9 + 24 + 4 + 4 + 4) = bd_size; + WBUFL(buf,6 + 12 + 9 + 24 + 41 + 4) = config; + WBUFL(buf,6 + 12 + 9 + 24 + 41 + 4 + 4) = bd_size; for( i = 0; i < bd_size; i++ ) { - safestrncpy((char*)WBUFP(buf,6 + 12 + 9+ 24 + 4 + 4 + 4 + 4 + ( i * ( BFLAG_LENGTH + 4 ) ) ), battle_data[i].str, 35); - WBUFL(buf,6 + 12 + 9 + 24 + 4 + 4 + 4 + 4 + BFLAG_LENGTH + ( i * ( BFLAG_LENGTH + 4 ) ) ) = *battle_data[i].val; + safestrncpy((char*)WBUFP(buf,6 + 12 + 9 + 24 + 41 + 4 + 4 + 4 + ( i * ( BFLAG_LENGTH + 4 ) ) ), battle_data[i].str, 35); + WBUFL(buf,6 + 12 + 9 + 24 + 41 + 4 + 4 + 4 + BFLAG_LENGTH + ( i * ( BFLAG_LENGTH + 4 ) ) ) = *battle_data[i].val; } - chrif_send_report(buf, 6 + 12 + 9 + 24 + 4 + 4 + 4 + 4 + ( bd_size * ( BFLAG_LENGTH + 4 ) ) ); + chrif_send_report(buf, 6 + 12 + 9 + 24 + 41 + 4 + 4 + 4 + ( bd_size * ( BFLAG_LENGTH + 4 ) ) ); aFree(buf); diff --git a/src/map/chrif.c b/src/map/chrif.c index cf7886422..69fc79bb8 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -1577,19 +1577,19 @@ int chrif_removefriend(int char_id, int friend_id) { } void chrif_send_report(char* buf, int len) { - #ifndef STATS_OPT_OUT - WFIFOHEAD(char_fd,len + 2); - - WFIFOW(char_fd,0) = 0x3008; - - memcpy(WFIFOP(char_fd,2), buf, len); - - WFIFOSET(char_fd,len + 2); - - flush_fifo(char_fd); /* ensure it's sent now. */ + if( char_fd ) { + WFIFOHEAD(char_fd,len + 2); + + WFIFOW(char_fd,0) = 0x3008; + + memcpy(WFIFOP(char_fd,2), buf, len); + + WFIFOSET(char_fd,len + 2); + + flush_fifo(char_fd); /* ensure it's sent now. */ + } #endif - } /** -- cgit v1.2.3-70-g09d2 From 0aee4fd57f2f4135361f4182a08a98cf52ed9d10 Mon Sep 17 00:00:00 2001 From: shennetsind Date: Wed, 15 May 2013 16:47:08 -0300 Subject: HPM Update Made SQL and strlib functions HPM-friendly, special thanks to Yommy for bringing the issue up. Added partial map.c support, for the all-handy map[] array, beware that soon the whole map.c renewal design will be commit and when that happens your usage of map.c functions in plugins might require some updates. Signed-off-by: shennetsind --- src/char/char.c | 474 +++++++++++++++++++++++------------------------ src/char/int_auction.c | 83 +++++---- src/char/int_elemental.c | 51 ++--- src/char/int_guild.c | 268 +++++++++++++-------------- src/char/int_homun.c | 81 ++++---- src/char/int_mail.c | 161 ++++++++-------- src/char/int_mercenary.c | 59 +++--- src/char/int_party.c | 89 ++++----- src/char/int_pet.c | 40 ++-- src/char/int_quest.c | 11 +- src/char/int_storage.c | 93 +++++----- src/char/inter.c | 149 +++++++-------- src/char/inter.h | 7 +- src/common/HPM.c | 72 ++++--- src/common/HPM.h | 2 +- src/common/HPMi.h | 3 + src/common/core.c | 23 ++- src/common/mmo.h | 2 +- src/common/showmsg.c | 18 +- src/common/sql.c | 134 +++++++------- src/common/sql.h | 236 +++++++++-------------- src/common/strlib.c | 362 +++++++++++++++++------------------- src/common/strlib.h | 244 +++++++++++++----------- src/common/timer.c | 135 +++++++------- src/common/timer.h | 34 ++-- src/login/account_sql.c | 115 ++++++------ src/login/ipban_sql.c | 27 +-- src/login/loginlog_sql.c | 29 +-- src/map/atcommand.c | 182 +++++++++--------- src/map/chrif.c | 4 +- src/map/clif.c | 24 +-- src/map/guild.c | 21 ++- src/map/homunculus.c | 4 +- src/map/itemdb.c | 39 ++-- src/map/log.c | 6 +- src/map/map.c | 79 +++++--- src/map/map.h | 45 +++-- src/map/mapreg_sql.c | 20 +- src/map/mercenary.c | 4 +- src/map/mob.c | 26 +-- src/map/npc.c | 10 +- src/map/pc.c | 8 +- src/map/pc_groups.c | 4 +- src/map/script.c | 166 ++++++++--------- src/map/skill.c | 32 ++-- src/map/status.c | 10 +- 46 files changed, 1860 insertions(+), 1826 deletions(-) (limited to 'src/common/HPM.c') diff --git a/src/char/char.c b/src/char/char.c index 975b1d77b..f5a75964c 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -226,7 +226,7 @@ void set_char_online(int map_id, int char_id, int account_id) struct mmo_charstatus *cp; //Update DB - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `online`='1' WHERE `char_id`='%d' LIMIT 1", char_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `online`='1' WHERE `char_id`='%d' LIMIT 1", char_db, char_id) ) Sql_ShowDebug(sql_handle); //Check to see for online conflicts @@ -271,7 +271,7 @@ void set_char_offline(int char_id, int account_id) if ( char_id == -1 ) { - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `online`='0' WHERE `account_id`='%d'", char_db, account_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `online`='0' WHERE `account_id`='%d'", char_db, account_id) ) Sql_ShowDebug(sql_handle); } else @@ -281,7 +281,7 @@ void set_char_offline(int char_id, int account_id) if (cp) idb_remove(char_db_,char_id); - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `online`='0' WHERE `char_id`='%d' LIMIT 1", char_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `online`='0' WHERE `char_id`='%d' LIMIT 1", char_db, char_id) ) Sql_ShowDebug(sql_handle); } @@ -376,11 +376,11 @@ void set_all_offline(int id) void set_all_offline_sql(void) { //Set all players to 'OFFLINE' - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `online` = '0'", char_db) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `online` = '0'", char_db) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `online` = '0'", guild_member_db) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `online` = '0'", guild_member_db) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `connect_member` = '0'", guild_db) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `connect_member` = '0'", guild_db) ) Sql_ShowDebug(sql_handle); } @@ -411,7 +411,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p) cp = idb_ensure(char_db_, char_id, create_charstatus); - StringBuf_Init(&buf); + StrBuf->Init(&buf); memset(save_status, 0, sizeof(save_status)); //map inventory data @@ -464,7 +464,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p) if( p->show_equip ) opt |= OPT_SHOW_EQUIP; - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `base_level`='%d', `job_level`='%d'," + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `base_level`='%d', `job_level`='%d'," "`base_exp`='%u', `job_exp`='%u', `zeny`='%d'," "`max_hp`='%d',`hp`='%d',`max_sp`='%d',`sp`='%d',`status_point`='%d',`skill_point`='%d'," "`str`='%d',`agi`='%d',`vit`='%d',`int`='%d',`dex`='%d',`luk`='%d'," @@ -501,7 +501,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p) (p->fame != cp->fame) ) { - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `class`='%d'," + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `class`='%d'," "`hair`='%d',`hair_color`='%d',`clothes_color`='%d'," "`partner_id`='%d', `father`='%d', `mother`='%d', `child`='%d'," "`karma`='%d',`manner`='%d', `fame`='%d'" @@ -536,29 +536,29 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p) char esc_mapname[NAME_LENGTH*2+1]; //`memo` (`memo_id`,`char_id`,`map`,`x`,`y`) - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", memo_db, p->char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", memo_db, p->char_id) ) { Sql_ShowDebug(sql_handle); errors++; } //insert here. - StringBuf_Clear(&buf); - StringBuf_Printf(&buf, "INSERT INTO `%s`(`char_id`,`map`,`x`,`y`) VALUES ", memo_db); + StrBuf->Clear(&buf); + StrBuf->Printf(&buf, "INSERT INTO `%s`(`char_id`,`map`,`x`,`y`) VALUES ", memo_db); for( i = 0, count = 0; i < MAX_MEMOPOINTS; ++i ) { if( p->memo_point[i].map ) { if( count ) - StringBuf_AppendStr(&buf, ","); - Sql_EscapeString(sql_handle, esc_mapname, mapindex_id2name(p->memo_point[i].map)); - StringBuf_Printf(&buf, "('%d', '%s', '%d', '%d')", char_id, esc_mapname, p->memo_point[i].x, p->memo_point[i].y); + StrBuf->AppendStr(&buf, ","); + SQL->EscapeString(sql_handle, esc_mapname, mapindex_id2name(p->memo_point[i].map)); + StrBuf->Printf(&buf, "('%d', '%s', '%d', '%d')", char_id, esc_mapname, p->memo_point[i].x, p->memo_point[i].y); ++count; } } if( count ) { - if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) + if( SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) { Sql_ShowDebug(sql_handle); errors++; @@ -570,13 +570,13 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p) //skills if( memcmp(p->skill, cp->skill, sizeof(p->skill)) ) { //`skill` (`char_id`, `id`, `lv`) - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", skill_db, p->char_id) ) { + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", skill_db, p->char_id) ) { Sql_ShowDebug(sql_handle); errors++; } - StringBuf_Clear(&buf); - StringBuf_Printf(&buf, "INSERT INTO `%s`(`char_id`,`id`,`lv`,`flag`) VALUES ", skill_db); + StrBuf->Clear(&buf); + StrBuf->Printf(&buf, "INSERT INTO `%s`(`char_id`,`id`,`lv`,`flag`) VALUES ", skill_db); //insert here. for( i = 0, count = 0; i < MAX_SKILL; ++i ) { if( p->skill[i].id != 0 && p->skill[i].flag != SKILL_FLAG_TEMPORARY ) { @@ -586,8 +586,8 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p) if( p->skill[i].flag != SKILL_FLAG_PERMANENT && p->skill[i].flag != SKILL_FLAG_PERM_GRANTED && (p->skill[i].flag - SKILL_FLAG_REPLACED_LV_0) == 0 ) continue; if( count ) - StringBuf_AppendStr(&buf, ","); - StringBuf_Printf(&buf, "('%d','%d','%d','%d')", char_id, p->skill[i].id, + StrBuf->AppendStr(&buf, ","); + StrBuf->Printf(&buf, "('%d','%d','%d','%d')", char_id, p->skill[i].id, ( (p->skill[i].flag == SKILL_FLAG_PERMANENT || p->skill[i].flag == SKILL_FLAG_PERM_GRANTED) ? p->skill[i].lv : p->skill[i].flag - SKILL_FLAG_REPLACED_LV_0), p->skill[i].flag == SKILL_FLAG_PERM_GRANTED ? p->skill[i].flag : 0);/* other flags do not need to be saved */ ++count; @@ -595,7 +595,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p) } if( count ) { - if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) + if( SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) { Sql_ShowDebug(sql_handle); errors++; @@ -616,27 +616,27 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p) if(diff == 1) { //Save friends - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", friend_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", friend_db, char_id) ) { Sql_ShowDebug(sql_handle); errors++; } - StringBuf_Clear(&buf); - StringBuf_Printf(&buf, "INSERT INTO `%s` (`char_id`, `friend_account`, `friend_id`) VALUES ", friend_db); + StrBuf->Clear(&buf); + StrBuf->Printf(&buf, "INSERT INTO `%s` (`char_id`, `friend_account`, `friend_id`) VALUES ", friend_db); for( i = 0, count = 0; i < MAX_FRIENDS; ++i ) { if( p->friends[i].char_id > 0 ) { if( count ) - StringBuf_AppendStr(&buf, ","); - StringBuf_Printf(&buf, "('%d','%d','%d')", char_id, p->friends[i].account_id, p->friends[i].char_id); + StrBuf->AppendStr(&buf, ","); + StrBuf->Printf(&buf, "('%d','%d','%d')", char_id, p->friends[i].account_id, p->friends[i].char_id); count++; } } if( count ) { - if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) + if( SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) { Sql_ShowDebug(sql_handle); errors++; @@ -647,20 +647,20 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p) #ifdef HOTKEY_SAVING // hotkeys - StringBuf_Clear(&buf); - StringBuf_Printf(&buf, "REPLACE INTO `%s` (`char_id`, `hotkey`, `type`, `itemskill_id`, `skill_lvl`) VALUES ", hotkey_db); + StrBuf->Clear(&buf); + StrBuf->Printf(&buf, "REPLACE INTO `%s` (`char_id`, `hotkey`, `type`, `itemskill_id`, `skill_lvl`) VALUES ", hotkey_db); diff = 0; for(i = 0; i < ARRAYLENGTH(p->hotkeys); i++){ if(memcmp(&p->hotkeys[i], &cp->hotkeys[i], sizeof(struct hotkey))) { if( diff ) - StringBuf_AppendStr(&buf, ",");// not the first hotkey - StringBuf_Printf(&buf, "('%d','%u','%u','%u','%u')", char_id, (unsigned int)i, (unsigned int)p->hotkeys[i].type, p->hotkeys[i].id , (unsigned int)p->hotkeys[i].lv); + StrBuf->AppendStr(&buf, ",");// not the first hotkey + StrBuf->Printf(&buf, "('%d','%u','%u','%u','%u')", char_id, (unsigned int)i, (unsigned int)p->hotkeys[i].type, p->hotkeys[i].id , (unsigned int)p->hotkeys[i].lv); diff = 1; } } if(diff) { - if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) + if( SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) { Sql_ShowDebug(sql_handle); errors++; @@ -668,7 +668,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p) strcat(save_status, " hotkeys"); } #endif - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); if (save_status[0]!='\0' && save_log) ShowInfo("Saved char %d - %s:%s.\n", char_id, p->name, save_status); if (!errors) @@ -706,19 +706,19 @@ int memitemdata_to_sql(const struct item items[], int max, int id, int tableswit // This approach is more complicated than a trivial delete&insert, but // it significantly reduces cpu load on the database server. - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`"); + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`"); for( j = 0; j < MAX_SLOTS; ++j ) - StringBuf_Printf(&buf, ", `card%d`", j); - StringBuf_Printf(&buf, " FROM `%s` WHERE `%s`='%d'", tablename, selectoption, id); + StrBuf->Printf(&buf, ", `card%d`", j); + StrBuf->Printf(&buf, " FROM `%s` WHERE `%s`='%d'", tablename, selectoption, id); stmt = SqlStmt_Malloc(sql_handle); - if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) + if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StrBuf->Value(&buf)) || SQL_ERROR == SqlStmt_Execute(stmt) ) { SqlStmt_ShowDebug(stmt); SqlStmt_Free(stmt); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); return 1; } @@ -763,14 +763,14 @@ int memitemdata_to_sql(const struct item items[], int max, int id, int tableswit else { // update all fields. - StringBuf_Clear(&buf); - StringBuf_Printf(&buf, "UPDATE `%s` SET `amount`='%d', `equip`='%d', `identify`='%d', `refine`='%d',`attribute`='%d', `expire_time`='%u'", + StrBuf->Clear(&buf); + StrBuf->Printf(&buf, "UPDATE `%s` SET `amount`='%d', `equip`='%d', `identify`='%d', `refine`='%d',`attribute`='%d', `expire_time`='%u'", tablename, items[i].amount, items[i].equip, items[i].identify, items[i].refine, items[i].attribute, items[i].expire_time); for( j = 0; j < MAX_SLOTS; ++j ) - StringBuf_Printf(&buf, ", `card%d`=%d", j, items[i].card[j]); - StringBuf_Printf(&buf, " WHERE `id`='%d' LIMIT 1", item.id); + StrBuf->Printf(&buf, ", `card%d`=%d", j, items[i].card[j]); + StrBuf->Printf(&buf, " WHERE `id`='%d' LIMIT 1", item.id); - if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) + if( SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) { Sql_ShowDebug(sql_handle); errors++; @@ -783,7 +783,7 @@ int memitemdata_to_sql(const struct item items[], int max, int id, int tableswit } if( !found ) {// Item not present in inventory, remove it. - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE from `%s` where `id`='%d' LIMIT 1", tablename, item.id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE from `%s` where `id`='%d' LIMIT 1", tablename, item.id) ) { Sql_ShowDebug(sql_handle); errors++; @@ -792,11 +792,11 @@ int memitemdata_to_sql(const struct item items[], int max, int id, int tableswit } SqlStmt_Free(stmt); - StringBuf_Clear(&buf); - StringBuf_Printf(&buf, "INSERT INTO `%s`(`%s`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `unique_id`", tablename, selectoption); + StrBuf->Clear(&buf); + StrBuf->Printf(&buf, "INSERT INTO `%s`(`%s`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `unique_id`", tablename, selectoption); for( j = 0; j < MAX_SLOTS; ++j ) - StringBuf_Printf(&buf, ", `card%d`", j); - StringBuf_AppendStr(&buf, ") VALUES "); + StrBuf->Printf(&buf, ", `card%d`", j); + StrBuf->AppendStr(&buf, ") VALUES "); found = false; // insert non-matched items into the db as new items @@ -807,27 +807,27 @@ int memitemdata_to_sql(const struct item items[], int max, int id, int tableswit continue; if( found ) - StringBuf_AppendStr(&buf, ","); + StrBuf->AppendStr(&buf, ","); else found = true; - StringBuf_Printf(&buf, "('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%u', '%"PRIu64"'", + StrBuf->Printf(&buf, "('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%u', '%"PRIu64"'", id, items[i].nameid, items[i].amount, items[i].equip, items[i].identify, items[i].refine, items[i].attribute, items[i].expire_time, items[i].unique_id); for( j = 0; j < MAX_SLOTS; ++j ) - StringBuf_Printf(&buf, ", '%d'", items[i].card[j]); - StringBuf_AppendStr(&buf, ")"); + StrBuf->Printf(&buf, ", '%d'", items[i].card[j]); + StrBuf->AppendStr(&buf, ")"); updateLastUid(items[i].unique_id); // Unique Non Stackable Item ID } dbUpdateUid(sql_handle); // Unique Non Stackable Item ID - if( found && SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) + if( found && SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) { Sql_ShowDebug(sql_handle); errors++; } - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); aFree(flag); return errors; @@ -850,19 +850,19 @@ int inventory_to_sql(const struct item items[], int max, int id) { // This approach is more complicated than a trivial delete&insert, but // it significantly reduces cpu load on the database server. - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`"); + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`"); for( j = 0; j < MAX_SLOTS; ++j ) - StringBuf_Printf(&buf, ", `card%d`", j); - StringBuf_Printf(&buf, " FROM `%s` WHERE `char_id`='%d'", inventory_db, id); + StrBuf->Printf(&buf, ", `card%d`", j); + StrBuf->Printf(&buf, " FROM `%s` WHERE `char_id`='%d'", inventory_db, id); stmt = SqlStmt_Malloc(sql_handle); - if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) + if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StrBuf->Value(&buf)) || SQL_ERROR == SqlStmt_Execute(stmt) ) { SqlStmt_ShowDebug(stmt); SqlStmt_Free(stmt); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); return 1; } @@ -906,14 +906,14 @@ int inventory_to_sql(const struct item items[], int max, int id) { ; //Do nothing. else { // update all fields. - StringBuf_Clear(&buf); - StringBuf_Printf(&buf, "UPDATE `%s` SET `amount`='%d', `equip`='%d', `identify`='%d', `refine`='%d',`attribute`='%d', `expire_time`='%u', `favorite`='%d'", + StrBuf->Clear(&buf); + StrBuf->Printf(&buf, "UPDATE `%s` SET `amount`='%d', `equip`='%d', `identify`='%d', `refine`='%d',`attribute`='%d', `expire_time`='%u', `favorite`='%d'", inventory_db, items[i].amount, items[i].equip, items[i].identify, items[i].refine, items[i].attribute, items[i].expire_time, items[i].favorite); for( j = 0; j < MAX_SLOTS; ++j ) - StringBuf_Printf(&buf, ", `card%d`=%d", j, items[i].card[j]); - StringBuf_Printf(&buf, " WHERE `id`='%d' LIMIT 1", item.id); + StrBuf->Printf(&buf, ", `card%d`=%d", j, items[i].card[j]); + StrBuf->Printf(&buf, " WHERE `id`='%d' LIMIT 1", item.id); - if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) { + if( SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) { Sql_ShowDebug(sql_handle); errors++; } @@ -924,7 +924,7 @@ int inventory_to_sql(const struct item items[], int max, int id) { } } if( !found ) {// Item not present in inventory, remove it. - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE from `%s` where `id`='%d' LIMIT 1", inventory_db, item.id) ) { + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE from `%s` where `id`='%d' LIMIT 1", inventory_db, item.id) ) { Sql_ShowDebug(sql_handle); errors++; } @@ -932,11 +932,11 @@ int inventory_to_sql(const struct item items[], int max, int id) { } SqlStmt_Free(stmt); - StringBuf_Clear(&buf); - StringBuf_Printf(&buf, "INSERT INTO `%s` (`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`, `unique_id`", inventory_db); + StrBuf->Clear(&buf); + StrBuf->Printf(&buf, "INSERT INTO `%s` (`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`, `unique_id`", inventory_db); for( j = 0; j < MAX_SLOTS; ++j ) - StringBuf_Printf(&buf, ", `card%d`", j); - StringBuf_AppendStr(&buf, ") VALUES "); + StrBuf->Printf(&buf, ", `card%d`", j); + StrBuf->AppendStr(&buf, ") VALUES "); found = false; // insert non-matched items into the db as new items @@ -946,26 +946,26 @@ int inventory_to_sql(const struct item items[], int max, int id) { continue; if( found ) - StringBuf_AppendStr(&buf, ","); + StrBuf->AppendStr(&buf, ","); else found = true; - StringBuf_Printf(&buf, "('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%u', '%d', '%"PRIu64"'", + StrBuf->Printf(&buf, "('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%u', '%d', '%"PRIu64"'", id, items[i].nameid, items[i].amount, items[i].equip, items[i].identify, items[i].refine, items[i].attribute, items[i].expire_time, items[i].favorite, items[i].unique_id); for( j = 0; j < MAX_SLOTS; ++j ) - StringBuf_Printf(&buf, ", '%d'", items[i].card[j]); - StringBuf_AppendStr(&buf, ")"); + StrBuf->Printf(&buf, ", '%d'", items[i].card[j]); + StrBuf->AppendStr(&buf, ")"); updateLastUid(items[i].unique_id);// Unique Non Stackable Item ID } dbUpdateUid(sql_handle); - if( found && SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) { + if( found && SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) { Sql_ShowDebug(sql_handle); errors++; } - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); aFree(flag); return errors; @@ -1208,13 +1208,13 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything //read inventory //`inventory` (`id`,`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`, `expire_time`, `favorite`, `unique_id`) - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`, `unique_id`"); + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`, `unique_id`"); for( i = 0; i < MAX_SLOTS; ++i ) - StringBuf_Printf(&buf, ", `card%d`", i); - StringBuf_Printf(&buf, " FROM `%s` WHERE `char_id`=? LIMIT %d", inventory_db, MAX_INVENTORY); + StrBuf->Printf(&buf, ", `card%d`", i); + StrBuf->Printf(&buf, " FROM `%s` WHERE `char_id`=? LIMIT %d", inventory_db, MAX_INVENTORY); - if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) + if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StrBuf->Value(&buf)) || SQL_ERROR == SqlStmt_BindParam(stmt, 0, SQLDT_INT, &char_id, 0) || SQL_ERROR == SqlStmt_Execute(stmt) || SQL_ERROR == SqlStmt_BindColumn(stmt, 0, SQLDT_INT, &tmp_item.id, 0, NULL, NULL) @@ -1239,13 +1239,13 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything //read cart //`cart_inventory` (`id`,`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`, expire_time`, `unique_id`) - StringBuf_Clear(&buf); - StringBuf_AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `unique_id`"); + StrBuf->Clear(&buf); + StrBuf->AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `unique_id`"); for( j = 0; j < MAX_SLOTS; ++j ) - StringBuf_Printf(&buf, ", `card%d`", j); - StringBuf_Printf(&buf, " FROM `%s` WHERE `char_id`=? LIMIT %d", cart_db, MAX_CART); + StrBuf->Printf(&buf, ", `card%d`", j); + StrBuf->Printf(&buf, " FROM `%s` WHERE `char_id`=? LIMIT %d", cart_db, MAX_CART); - if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) + if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StrBuf->Value(&buf)) || SQL_ERROR == SqlStmt_BindParam(stmt, 0, SQLDT_INT, &char_id, 0) || SQL_ERROR == SqlStmt_Execute(stmt) || SQL_ERROR == SqlStmt_BindColumn(stmt, 0, SQLDT_INT, &tmp_item.id, 0, NULL, NULL) @@ -1334,7 +1334,7 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything if (save_log) ShowInfo("Loaded char (%d - %s): %s\n", char_id, p->name, t_msg); //ok. all data load successfuly! SqlStmt_Free(stmt); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); /* load options into proper vars */ if( opt & OPT_ALLOW_PARTY ) @@ -1382,14 +1382,14 @@ bool char_slotchange(struct char_session_data *sd, int fd, unsigned short from, if( sd->found_char[to] > 0 ) {/* moving char to occupied slot */ bool result = false; /* update both at once */ - if( SQL_SUCCESS != Sql_QueryStr(sql_handle, "START TRANSACTION") - || SQL_SUCCESS != Sql_Query(sql_handle, "UPDATE `%s` SET `char_num`='%d' WHERE `char_id`='%d' LIMIT 1", char_db, from, sd->found_char[to]) - || SQL_SUCCESS != Sql_Query(sql_handle, "UPDATE `%s` SET `char_num`='%d' WHERE `char_id`='%d' LIMIT 1", char_db, to, sd->found_char[from]) ) + if( SQL_SUCCESS != SQL->QueryStr(sql_handle, "START TRANSACTION") + || SQL_SUCCESS != SQL->Query(sql_handle, "UPDATE `%s` SET `char_num`='%d' WHERE `char_id`='%d' LIMIT 1", char_db, from, sd->found_char[to]) + || SQL_SUCCESS != SQL->Query(sql_handle, "UPDATE `%s` SET `char_num`='%d' WHERE `char_id`='%d' LIMIT 1", char_db, to, sd->found_char[from]) ) Sql_ShowDebug(sql_handle); else result = true; - if( SQL_ERROR == Sql_QueryStr(sql_handle, (result == true) ? "COMMIT" : "ROLLBACK") ) { + if( SQL_ERROR == SQL->QueryStr(sql_handle, (result == true) ? "COMMIT" : "ROLLBACK") ) { Sql_ShowDebug(sql_handle); result = false; } @@ -1397,14 +1397,14 @@ bool char_slotchange(struct char_session_data *sd, int fd, unsigned short from, return false; } else {/* slot is free. */ - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `char_num`='%d' WHERE `char_id`='%d' LIMIT 1", char_db, to, sd->found_char[from] ) ) { + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `char_num`='%d' WHERE `char_id`='%d' LIMIT 1", char_db, to, sd->found_char[from] ) ) { Sql_ShowDebug(sql_handle); return false; } } /* update count */ - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `slotchange`=`slotchange`-1 WHERE `char_id`='%d' LIMIT 1", char_db, from_id ) ) { + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `slotchange`=`slotchange`-1 WHERE `char_id`='%d' LIMIT 1", char_db, from_id ) ) { Sql_ShowDebug(sql_handle); return false; } @@ -1429,16 +1429,16 @@ int rename_char_sql(struct char_session_data *sd, int char_id) if( char_dat.rename == 0 ) return 1; - Sql_EscapeStringLen(sql_handle, esc_name, sd->new_name, strnlen(sd->new_name, NAME_LENGTH)); + SQL->EscapeStringLen(sql_handle, esc_name, sd->new_name, strnlen(sd->new_name, NAME_LENGTH)); // check if the char exist - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT 1 FROM `%s` WHERE `name` LIKE '%s' LIMIT 1", char_db, esc_name) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT 1 FROM `%s` WHERE `name` LIKE '%s' LIMIT 1", char_db, esc_name) ) { Sql_ShowDebug(sql_handle); return 4; } - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `name` = '%s', `rename` = '%d' WHERE `char_id` = '%d'", char_db, esc_name, --char_dat.rename, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `name` = '%s', `rename` = '%d' WHERE `char_id` = '%d'", char_db, esc_name, --char_dat.rename, char_id) ) { Sql_ShowDebug(sql_handle); return 3; @@ -1454,7 +1454,7 @@ int rename_char_sql(struct char_session_data *sd, int char_id) // log change if( log_char ) { - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` (`time`, `char_msg`,`account_id`,`char_num`,`name`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,`hair`,`hair_color`)" + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` (`time`, `char_msg`,`account_id`,`char_num`,`name`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,`hair`,`hair_color`)" "VALUES (NOW(), '%s', '%d', '%d', '%s', '0', '0', '0', '0', '0', '0', '0', '0')", charlog_db, "change char name", sd->account_id, char_dat.slot, esc_name) ) Sql_ShowDebug(sql_handle); @@ -1498,17 +1498,17 @@ int check_char_name(char * name, char * esc_name) return -2; } if( name_ignoring_case ) { - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT 1 FROM `%s` WHERE BINARY `name` = '%s' LIMIT 1", char_db, esc_name) ) { + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT 1 FROM `%s` WHERE BINARY `name` = '%s' LIMIT 1", char_db, esc_name) ) { Sql_ShowDebug(sql_handle); return -2; } } else { - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT 1 FROM `%s` WHERE `name` = '%s' LIMIT 1", char_db, esc_name) ) { + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT 1 FROM `%s` WHERE `name` = '%s' LIMIT 1", char_db, esc_name) ) { Sql_ShowDebug(sql_handle); return -2; } } - if( Sql_NumRows(sql_handle) > 0 ) + if( SQL->NumRows(sql_handle) > 0 ) return -1; // name already exists return 0; @@ -1530,7 +1530,7 @@ int make_new_char_sql(struct char_session_data* sd, char* name_, int str, int ag safestrncpy(name, name_, NAME_LENGTH); normalize_name(name,TRIM_CHARS); - Sql_EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); + SQL->EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); flag = check_char_name(name,esc_name); if( flag < 0 ) @@ -1557,14 +1557,14 @@ int make_new_char_sql(struct char_session_data* sd, char* name_, int str, int ag // validation success, log result if (log_char) { - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` (`time`, `char_msg`,`account_id`,`char_num`,`name`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,`hair`,`hair_color`)" + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` (`time`, `char_msg`,`account_id`,`char_num`,`name`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,`hair`,`hair_color`)" "VALUES (NOW(), '%s', '%d', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", charlog_db, "make new char", sd->account_id, slot, esc_name, str, agi, vit, int_, dex, luk, hair_style, hair_color) ) Sql_ShowDebug(sql_handle); } #if PACKETVER >= 20120307 //Insert the new char entry to the database - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` (`account_id`, `char_num`, `name`, `zeny`, `status_point`,`str`, `agi`, `vit`, `int`, `dex`, `luk`, `max_hp`, `hp`," + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` (`account_id`, `char_num`, `name`, `zeny`, `status_point`,`str`, `agi`, `vit`, `int`, `dex`, `luk`, `max_hp`, `hp`," "`max_sp`, `sp`, `hair`, `hair_color`, `last_map`, `last_x`, `last_y`, `save_map`, `save_x`, `save_y`) VALUES (" "'%d', '%d', '%s', '%d', '%d','%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d','%d', '%d','%d', '%d', '%s', '%d', '%d', '%s', '%d', '%d')", char_db, sd->account_id , slot, esc_name, start_zeny, 48, str, agi, vit, int_, dex, luk, @@ -1576,7 +1576,7 @@ int make_new_char_sql(struct char_session_data* sd, char* name_, int str, int ag } #else //Insert the new char entry to the database - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` (`account_id`, `char_num`, `name`, `zeny`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `max_hp`, `hp`," + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` (`account_id`, `char_num`, `name`, `zeny`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `max_hp`, `hp`," "`max_sp`, `sp`, `hair`, `hair_color`, `last_map`, `last_x`, `last_y`, `save_map`, `save_x`, `save_y`) VALUES (" "'%d', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d','%d', '%d','%d', '%d', '%s', '%d', '%d', '%s', '%d', '%d')", char_db, sd->account_id , slot, esc_name, start_zeny, str, agi, vit, int_, dex, luk, @@ -1588,11 +1588,11 @@ int make_new_char_sql(struct char_session_data* sd, char* name_, int str, int ag } #endif //Retrieve the newly auto-generated char id - char_id = (int)Sql_LastInsertId(sql_handle); + char_id = (int)SQL->NumRows(sql_handle); //Give the char the default items for (k = 0; k < ARRAYLENGTH(start_items) && start_items[k] != 0; k += 2) { - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` (`char_id`,`nameid`, `amount`, `identify`) VALUES ('%d', '%d', '%d', '%d')", inventory_db, char_id, start_items[k], start_items[k + 1], 1) ) + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` (`char_id`,`nameid`, `amount`, `identify`) VALUES ('%d', '%d', '%d', '%d')", inventory_db, char_id, start_items[k], start_items[k + 1], 1) ) Sql_ShowDebug(sql_handle); } @@ -1607,9 +1607,9 @@ int divorce_char_sql(int partner_id1, int partner_id2) { unsigned char buf[64]; - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `partner_id`='0' WHERE `char_id`='%d' OR `char_id`='%d' LIMIT 2", char_db, partner_id1, partner_id2) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `partner_id`='0' WHERE `char_id`='%d' OR `char_id`='%d' LIMIT 2", char_db, partner_id1, partner_id2) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE (`nameid`='%d' OR `nameid`='%d') AND (`char_id`='%d' OR `char_id`='%d') LIMIT 2", inventory_db, WEDDING_RING_M, WEDDING_RING_F, partner_id1, partner_id2) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE (`nameid`='%d' OR `nameid`='%d') AND (`char_id`='%d' OR `char_id`='%d') LIMIT 2", inventory_db, WEDDING_RING_M, WEDDING_RING_F, partner_id1, partner_id2) ) Sql_ShowDebug(sql_handle); WBUFW(buf,0) = 0x2b12; @@ -1634,30 +1634,30 @@ int delete_char_sql(int char_id) char *data; size_t len; - if (SQL_ERROR == Sql_Query(sql_handle, "SELECT `name`,`account_id`,`party_id`,`guild_id`,`base_level`,`homun_id`,`partner_id`,`father`,`mother`,`elemental_id` FROM `%s` WHERE `char_id`='%d'", char_db, char_id)) + if (SQL_ERROR == SQL->Query(sql_handle, "SELECT `name`,`account_id`,`party_id`,`guild_id`,`base_level`,`homun_id`,`partner_id`,`father`,`mother`,`elemental_id` FROM `%s` WHERE `char_id`='%d'", char_db, char_id)) Sql_ShowDebug(sql_handle); - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) { ShowError("delete_char_sql: Unable to fetch character data, deletion aborted.\n"); - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return -1; } - Sql_GetData(sql_handle, 0, &data, &len); safestrncpy(name, data, NAME_LENGTH); - Sql_GetData(sql_handle, 1, &data, NULL); account_id = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); party_id = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); guild_id = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); base_level = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); hom_id = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); partner_id = atoi(data); - Sql_GetData(sql_handle, 7, &data, NULL); father_id = atoi(data); - Sql_GetData(sql_handle, 8, &data, NULL); mother_id = atoi(data); - Sql_GetData(sql_handle, 9, &data, NULL); + SQL->GetData(sql_handle, 0, &data, &len); safestrncpy(name, data, NAME_LENGTH); + SQL->GetData(sql_handle, 1, &data, NULL); account_id = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); party_id = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); guild_id = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); base_level = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); hom_id = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); partner_id = atoi(data); + SQL->GetData(sql_handle, 7, &data, NULL); father_id = atoi(data); + SQL->GetData(sql_handle, 8, &data, NULL); mother_id = atoi(data); + SQL->GetData(sql_handle, 9, &data, NULL); elemental_id = atoi(data); - Sql_EscapeStringLen(sql_handle, esc_name, name, min(len, NAME_LENGTH)); - Sql_FreeResult(sql_handle); + SQL->EscapeStringLen(sql_handle, esc_name, name, min(len, NAME_LENGTH)); + SQL->FreeResult(sql_handle); //check for config char del condition [Lupus] // TODO: Move this out to packet processing (0x68/0x1fb). @@ -1677,9 +1677,9 @@ int delete_char_sql(int char_id) { // Char is Baby unsigned char buf[64]; - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `child`='0' WHERE `char_id`='%d' OR `char_id`='%d'", char_db, father_id, mother_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `child`='0' WHERE `char_id`='%d' OR `char_id`='%d'", char_db, father_id, mother_id) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '410'AND (`char_id`='%d' OR `char_id`='%d')", skill_db, father_id, mother_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '410'AND (`char_id`='%d' OR `char_id`='%d')", skill_db, father_id, mother_id) ) Sql_ShowDebug(sql_handle); WBUFW(buf,0) = 0x2b25; @@ -1695,13 +1695,13 @@ int delete_char_sql(int char_id) /* delete char's pet */ //Delete the hatched pet if you have one... - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d' AND `incuvate` = '0'", pet_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d' AND `incuvate` = '0'", pet_db, char_id) ) Sql_ShowDebug(sql_handle); //Delete all pets that are stored in eggs (inventory + cart) - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` USING `%s` JOIN `%s` ON `pet_id` = `card1`|`card2`<<16 WHERE `%s`.char_id = '%d' AND card0 = -256", pet_db, pet_db, inventory_db, inventory_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` USING `%s` JOIN `%s` ON `pet_id` = `card1`|`card2`<<16 WHERE `%s`.char_id = '%d' AND card0 = -256", pet_db, pet_db, inventory_db, inventory_db, char_id) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` USING `%s` JOIN `%s` ON `pet_id` = `card1`|`card2`<<16 WHERE `%s`.char_id = '%d' AND card0 = -256", pet_db, pet_db, cart_db, cart_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` USING `%s` JOIN `%s` ON `pet_id` = `card1`|`card2`<<16 WHERE `%s`.char_id = '%d' AND card0 = -256", pet_db, pet_db, cart_db, cart_db, char_id) ) Sql_ShowDebug(sql_handle); /* remove homunculus */ @@ -1716,69 +1716,69 @@ int delete_char_sql(int char_id) mercenary_owner_delete(char_id); /* delete char's friends list */ - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d'", friend_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d'", friend_db, char_id) ) Sql_ShowDebug(sql_handle); /* delete char from other's friend list */ //NOTE: Won't this cause problems for people who are already online? [Skotlex] - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `friend_id` = '%d'", friend_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `friend_id` = '%d'", friend_db, char_id) ) Sql_ShowDebug(sql_handle); #ifdef HOTKEY_SAVING /* delete hotkeys */ - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", hotkey_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", hotkey_db, char_id) ) Sql_ShowDebug(sql_handle); #endif /* delete inventory */ - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", inventory_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", inventory_db, char_id) ) Sql_ShowDebug(sql_handle); /* delete cart inventory */ - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", cart_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", cart_db, char_id) ) Sql_ShowDebug(sql_handle); /* delete memo areas */ - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", memo_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", memo_db, char_id) ) Sql_ShowDebug(sql_handle); /* delete character registry */ - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `type`=3 AND `char_id`='%d'", reg_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `type`=3 AND `char_id`='%d'", reg_db, char_id) ) Sql_ShowDebug(sql_handle); /* delete skills */ - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", skill_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", skill_db, char_id) ) Sql_ShowDebug(sql_handle); /* delete mails (only received) */ - if (SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `dest_id`='%d'", mail_db, char_id)) + if (SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `dest_id`='%d'", mail_db, char_id)) Sql_ShowDebug(sql_handle); #ifdef ENABLE_SC_SAVING /* status changes */ - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `char_id`='%d'", scdata_db, account_id, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `char_id`='%d'", scdata_db, account_id, char_id) ) Sql_ShowDebug(sql_handle); #endif if (log_char) { - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s`(`time`, `account_id`,`char_num`,`char_msg`,`name`) VALUES (NOW(), '%d', '%d', 'Deleted char (CID %d)', '%s')", + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s`(`time`, `account_id`,`char_num`,`char_msg`,`name`) VALUES (NOW(), '%d', '%d', 'Deleted char (CID %d)', '%s')", charlog_db, account_id, 0, char_id, esc_name) ) Sql_ShowDebug(sql_handle); } /* delete character */ - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", char_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", char_db, char_id) ) Sql_ShowDebug(sql_handle); /* No need as we used inter_guild_leave [Skotlex] // Also delete info from guildtables. - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", guild_member_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", guild_member_db, char_id) ) Sql_ShowDebug(sql_handle); */ - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `guild_id` FROM `%s` WHERE `char_id` = '%d'", guild_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `guild_id` FROM `%s` WHERE `char_id` = '%d'", guild_db, char_id) ) Sql_ShowDebug(sql_handle); - else if( Sql_NumRows(sql_handle) > 0 ) + else if( SQL->NumRows(sql_handle) > 0 ) mapif_parse_BreakGuild(0,guild_id); else if( guild_id ) inter_guild_leave(guild_id, account_id, char_id);// Leave your guild. @@ -1937,66 +1937,66 @@ int mmo_char_send006b(int fd, struct char_session_data* sd) int char_married(int pl1, int pl2) { - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `partner_id` FROM `%s` WHERE `char_id` = '%d'", char_db, pl1) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `partner_id` FROM `%s` WHERE `char_id` = '%d'", char_db, pl1) ) Sql_ShowDebug(sql_handle); - else if( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + else if( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { char* data; - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); if( pl2 == atoi(data) ) { - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return 1; } } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return 0; } int char_child(int parent_id, int child_id) { - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `child` FROM `%s` WHERE `char_id` = '%d'", char_db, parent_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `child` FROM `%s` WHERE `char_id` = '%d'", char_db, parent_id) ) Sql_ShowDebug(sql_handle); - else if( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + else if( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { char* data; - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); if( child_id == atoi(data) ) { - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return 1; } } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return 0; } int char_family(int cid1, int cid2, int cid3) { - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `char_id`,`partner_id`,`child` FROM `%s` WHERE `char_id` IN ('%d','%d','%d')", char_db, cid1, cid2, cid3) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `char_id`,`partner_id`,`child` FROM `%s` WHERE `char_id` IN ('%d','%d','%d')", char_db, cid1, cid2, cid3) ) Sql_ShowDebug(sql_handle); - else while( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + else while( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { int charid; int partnerid; int childid; char* data; - Sql_GetData(sql_handle, 0, &data, NULL); charid = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); partnerid = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); childid = atoi(data); + SQL->GetData(sql_handle, 0, &data, NULL); charid = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); partnerid = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); childid = atoi(data); if( (cid1 == charid && ((cid2 == partnerid && cid3 == childid ) || (cid2 == childid && cid3 == partnerid))) || (cid1 == partnerid && ((cid2 == charid && cid3 == childid ) || (cid2 == childid && cid3 == charid ))) || (cid1 == childid && ((cid2 == charid && cid3 == partnerid) || (cid2 == partnerid && cid3 == charid ))) ) { - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return childid; } } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return 0; } @@ -2279,13 +2279,13 @@ int parse_fromlogin(int fd) { node->sex = sex; // get characters - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `char_id`,`class`,`guild_id` FROM `%s` WHERE `account_id` = '%d'", char_db, acc) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `char_id`,`class`,`guild_id` FROM `%s` WHERE `account_id` = '%d'", char_db, acc) ) Sql_ShowDebug(sql_handle); - for( i = 0; i < MAX_CHARS && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for( i = 0; i < MAX_CHARS && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) { - Sql_GetData(sql_handle, 0, &data, NULL); char_id[i] = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); class_[i] = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); guild_id[i] = atoi(data); + SQL->GetData(sql_handle, 0, &data, NULL); char_id[i] = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); class_[i] = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); guild_id[i] = atoi(data); } num = i; for( i = 0; i < num; ++i ) @@ -2315,13 +2315,13 @@ int parse_fromlogin(int fd) { class_[i] = (sex ? JOB_KAGEROU : JOB_OBORO); } - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `class`='%d', `weapon`='0', `shield`='0', `head_top`='0', `head_mid`='0', `head_bottom`='0' WHERE `char_id`='%d'", char_db, class_[i], char_id[i]) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `class`='%d', `weapon`='0', `shield`='0', `head_top`='0', `head_mid`='0', `head_bottom`='0' WHERE `char_id`='%d'", char_db, class_[i], char_id[i]) ) Sql_ShowDebug(sql_handle); if( guild_id[i] )// If there is a guild, update the guild_member data [Skotlex] inter_guild_sex_changed(guild_id[i], acc, char_id[i], sex); } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); // disconnect player if online on char-server disconnect_player(acc); @@ -2506,51 +2506,51 @@ void char_read_fame_list(void) memset(chemist_fame_list, 0, sizeof(chemist_fame_list)); memset(taekwon_fame_list, 0, sizeof(taekwon_fame_list)); // Build Blacksmith ranking list - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `char_id`,`fame`,`name` FROM `%s` WHERE `fame`>0 AND (`class`='%d' OR `class`='%d' OR `class`='%d' OR `class`='%d' OR `class`='%d' OR `class`='%d') ORDER BY `fame` DESC LIMIT 0,%d", char_db, JOB_BLACKSMITH, JOB_WHITESMITH, JOB_BABY_BLACKSMITH, JOB_MECHANIC, JOB_MECHANIC_T, JOB_BABY_MECHANIC, fame_list_size_smith) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `char_id`,`fame`,`name` FROM `%s` WHERE `fame`>0 AND (`class`='%d' OR `class`='%d' OR `class`='%d' OR `class`='%d' OR `class`='%d' OR `class`='%d') ORDER BY `fame` DESC LIMIT 0,%d", char_db, JOB_BLACKSMITH, JOB_WHITESMITH, JOB_BABY_BLACKSMITH, JOB_MECHANIC, JOB_MECHANIC_T, JOB_BABY_MECHANIC, fame_list_size_smith) ) Sql_ShowDebug(sql_handle); - for( i = 0; i < fame_list_size_smith && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for( i = 0; i < fame_list_size_smith && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) { // char_id - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); smith_fame_list[i].id = atoi(data); // fame - Sql_GetData(sql_handle, 1, &data, &len); + SQL->GetData(sql_handle, 1, &data, &len); smith_fame_list[i].fame = atoi(data); // name - Sql_GetData(sql_handle, 2, &data, &len); + SQL->GetData(sql_handle, 2, &data, &len); memcpy(smith_fame_list[i].name, data, min(len, NAME_LENGTH)); } // Build Alchemist ranking list - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `char_id`,`fame`,`name` FROM `%s` WHERE `fame`>0 AND (`class`='%d' OR `class`='%d' OR `class`='%d' OR `class`='%d' OR `class`='%d' OR `class`='%d') ORDER BY `fame` DESC LIMIT 0,%d", char_db, JOB_ALCHEMIST, JOB_CREATOR, JOB_BABY_ALCHEMIST, JOB_GENETIC, JOB_GENETIC_T, JOB_BABY_GENETIC, fame_list_size_chemist) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `char_id`,`fame`,`name` FROM `%s` WHERE `fame`>0 AND (`class`='%d' OR `class`='%d' OR `class`='%d' OR `class`='%d' OR `class`='%d' OR `class`='%d') ORDER BY `fame` DESC LIMIT 0,%d", char_db, JOB_ALCHEMIST, JOB_CREATOR, JOB_BABY_ALCHEMIST, JOB_GENETIC, JOB_GENETIC_T, JOB_BABY_GENETIC, fame_list_size_chemist) ) Sql_ShowDebug(sql_handle); - for( i = 0; i < fame_list_size_chemist && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for( i = 0; i < fame_list_size_chemist && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) { // char_id - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); chemist_fame_list[i].id = atoi(data); // fame - Sql_GetData(sql_handle, 1, &data, &len); + SQL->GetData(sql_handle, 1, &data, &len); chemist_fame_list[i].fame = atoi(data); // name - Sql_GetData(sql_handle, 2, &data, &len); + SQL->GetData(sql_handle, 2, &data, &len); memcpy(chemist_fame_list[i].name, data, min(len, NAME_LENGTH)); } // Build Taekwon ranking list - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `char_id`,`fame`,`name` FROM `%s` WHERE `fame`>0 AND (`class`='%d') ORDER BY `fame` DESC LIMIT 0,%d", char_db, JOB_TAEKWON, fame_list_size_taekwon) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `char_id`,`fame`,`name` FROM `%s` WHERE `fame`>0 AND (`class`='%d') ORDER BY `fame` DESC LIMIT 0,%d", char_db, JOB_TAEKWON, fame_list_size_taekwon) ) Sql_ShowDebug(sql_handle); - for( i = 0; i < fame_list_size_taekwon && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for( i = 0; i < fame_list_size_taekwon && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) { // char_id - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); taekwon_fame_list[i].id = atoi(data); // fame - Sql_GetData(sql_handle, 1, &data, &len); + SQL->GetData(sql_handle, 1, &data, &len); taekwon_fame_list[i].fame = atoi(data); // name - Sql_GetData(sql_handle, 2, &data, &len); + SQL->GetData(sql_handle, 2, &data, &len); memcpy(taekwon_fame_list[i].name, data, min(len, NAME_LENGTH)); } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); } // Send map-servers the fame ranking lists @@ -2607,11 +2607,11 @@ int char_loadName(int char_id, char* name) char* data; size_t len; - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `name` FROM `%s` WHERE `char_id`='%d'", char_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `name` FROM `%s` WHERE `char_id`='%d'", char_db, char_id) ) Sql_ShowDebug(sql_handle); - else if( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + else if( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { - Sql_GetData(sql_handle, 0, &data, &len); + SQL->GetData(sql_handle, 0, &data, &len); safestrncpy(name, data, NAME_LENGTH); return 1; } @@ -2662,7 +2662,7 @@ void mapif_server_reset(int id) WBUFW(buf,2) = j * 4 + 10; mapif_sendallwos(fd, buf, WBUFW(buf,2)); } - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `index`='%d'", ragsrvinfo_db, server[id].fd) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `index`='%d'", ragsrvinfo_db, server[id].fd) ) Sql_ShowDebug(sql_handle); online_char_db->foreach(online_char_db,char_db_setoffline,id); //Tag relevant chars as 'in disconnected' server. mapif_server_destroy(id); @@ -2789,13 +2789,13 @@ int parse_frommap(int fd) int aid, cid; aid = RFIFOL(fd,2); cid = RFIFOL(fd,6); - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT type, tick, val1, val2, val3, val4 from `%s` WHERE `account_id` = '%d' AND `char_id`='%d'", + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT type, tick, val1, val2, val3, val4 from `%s` WHERE `account_id` = '%d' AND `char_id`='%d'", scdata_db, aid, cid) ) { Sql_ShowDebug(sql_handle); break; } - if( Sql_NumRows(sql_handle) > 0 ) + if( SQL->NumRows(sql_handle) > 0 ) { struct status_change_data scdata; int count; @@ -2805,14 +2805,14 @@ int parse_frommap(int fd) WFIFOW(fd,0) = 0x2b1d; WFIFOL(fd,4) = aid; WFIFOL(fd,8) = cid; - for( count = 0; count < 50 && SQL_SUCCESS == Sql_NextRow(sql_handle); ++count ) + for( count = 0; count < 50 && SQL_SUCCESS == SQL->NextRow(sql_handle); ++count ) { - Sql_GetData(sql_handle, 0, &data, NULL); scdata.type = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); scdata.tick = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); scdata.val1 = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); scdata.val2 = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); scdata.val3 = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); scdata.val4 = atoi(data); + SQL->GetData(sql_handle, 0, &data, NULL); scdata.type = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); scdata.tick = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); scdata.val1 = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); scdata.val2 = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); scdata.val3 = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); scdata.val4 = atoi(data); memcpy(WFIFOP(fd, 14+count*sizeof(struct status_change_data)), &scdata, sizeof(struct status_change_data)); } if (count >= 50) @@ -2824,11 +2824,11 @@ int parse_frommap(int fd) WFIFOSET(fd,WFIFOW(fd,2)); //Clear the data once loaded. - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `char_id`='%d'", scdata_db, aid, cid) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `char_id`='%d'", scdata_db, aid, cid) ) Sql_ShowDebug(sql_handle); } } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); #endif RFIFOSKIP(fd, 10); } @@ -3028,7 +3028,7 @@ int parse_frommap(int fd) int char_id, friend_id; char_id = RFIFOL(fd,2); friend_id = RFIFOL(fd,6); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d' AND `friend_id`='%d' LIMIT 1", + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d' AND `friend_id`='%d' LIMIT 1", friend_db, char_id, friend_id) ) { Sql_ShowDebug(sql_handle); break; @@ -3080,16 +3080,16 @@ int parse_frommap(int fd) short second = RFIFOW(fd,42); RFIFOSKIP(fd,44); - Sql_EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`name` FROM `%s` WHERE `name` = '%s'", char_db, esc_name) ) + SQL->EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id`,`name` FROM `%s` WHERE `name` = '%s'", char_db, esc_name) ) Sql_ShowDebug(sql_handle); else - if( Sql_NumRows(sql_handle) == 0 ) + if( SQL->NumRows(sql_handle) == 0 ) { result = 1; // 1-player not found } else - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) Sql_ShowDebug(sql_handle); //FIXME: set proper result value? else @@ -3098,8 +3098,8 @@ int parse_frommap(int fd) int account_id; char* data; - Sql_GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name)); + SQL->GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name)); if( login_fd <= 0 ) result = 3; // 3-login-server offline @@ -3150,7 +3150,7 @@ int parse_frommap(int fd) } } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); // send answer if a player ask, not if the server ask if( acc != -1 && type != 5) { // Don't send answer for changesex @@ -3233,9 +3233,9 @@ int parse_frommap(int fd) { char esc_server_name[sizeof(server_name)*2+1]; - Sql_EscapeString(sql_handle, esc_server_name, server_name); + SQL->EscapeString(sql_handle, esc_server_name, server_name); - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` SET `index`='%d',`name`='%s',`exp`='%d',`jexp`='%d',`drop`='%d'", + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` SET `index`='%d',`name`='%s',`exp`='%d',`jexp`='%d',`drop`='%d'", ragsrvinfo_db, fd, esc_server_name, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10)) ) Sql_ShowDebug(sql_handle); RFIFOSKIP(fd,14); @@ -3286,19 +3286,19 @@ int parse_frommap(int fd) StringBuf buf; int i; - StringBuf_Init(&buf); - StringBuf_Printf(&buf, "INSERT INTO `%s` (`account_id`, `char_id`, `type`, `tick`, `val1`, `val2`, `val3`, `val4`) VALUES ", scdata_db); + StrBuf->Init(&buf); + StrBuf->Printf(&buf, "INSERT INTO `%s` (`account_id`, `char_id`, `type`, `tick`, `val1`, `val2`, `val3`, `val4`) VALUES ", scdata_db); for( i = 0; i < count; ++i ) { memcpy (&data, RFIFOP(fd, 14+i*sizeof(struct status_change_data)), sizeof(struct status_change_data)); if( i > 0 ) - StringBuf_AppendStr(&buf, ", "); - StringBuf_Printf(&buf, "('%d','%d','%hu','%d','%d','%d','%d','%d')", aid, cid, + StrBuf->AppendStr(&buf, ", "); + StrBuf->Printf(&buf, "('%d','%d','%hu','%d','%d','%d','%d','%d')", aid, cid, data.type, data.tick, data.val1, data.val2, data.val3, data.val4); } - if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) + if( SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) Sql_ShowDebug(sql_handle); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); } #endif RFIFOSKIP(fd, RFIFOW(fd, 2)); @@ -3561,14 +3561,14 @@ static void char_delete2_req(int fd, struct char_session_data* sd) return; } - if( SQL_SUCCESS != Sql_Query(sql_handle, "SELECT `delete_date` FROM `%s` WHERE `char_id`='%d'", char_db, char_id) || SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->Query(sql_handle, "SELECT `delete_date` FROM `%s` WHERE `char_id`='%d'", char_db, char_id) || SQL_SUCCESS != SQL->NextRow(sql_handle) ) { Sql_ShowDebug(sql_handle); char_delete2_ack(fd, char_id, 3, 0); return; } - Sql_GetData(sql_handle, 0, &data, NULL); delete_date = strtoul(data, NULL, 10); + SQL->GetData(sql_handle, 0, &data, NULL); delete_date = strtoul(data, NULL, 10); if( delete_date ) {// character already queued for deletion char_delete2_ack(fd, char_id, 0, 0); @@ -3595,7 +3595,7 @@ static void char_delete2_req(int fd, struct char_session_data* sd) // success delete_date = time(NULL)+char_del_delay; - if( SQL_SUCCESS != Sql_Query(sql_handle, "UPDATE `%s` SET `delete_date`='%lu' WHERE `char_id`='%d'", char_db, (unsigned long)delete_date, char_id) ) + if( SQL_SUCCESS != SQL->Query(sql_handle, "UPDATE `%s` SET `delete_date`='%lu' WHERE `char_id`='%d'", char_db, (unsigned long)delete_date, char_id) ) { Sql_ShowDebug(sql_handle); char_delete2_ack(fd, char_id, 3, 0); @@ -3636,15 +3636,15 @@ static void char_delete2_accept(int fd, struct char_session_data* sd) return; } - if( SQL_SUCCESS != Sql_Query(sql_handle, "SELECT `base_level`,`delete_date` FROM `%s` WHERE `char_id`='%d'", char_db, char_id) || SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->Query(sql_handle, "SELECT `base_level`,`delete_date` FROM `%s` WHERE `char_id`='%d'", char_db, char_id) || SQL_SUCCESS != SQL->NextRow(sql_handle) ) {// data error Sql_ShowDebug(sql_handle); char_delete2_accept_ack(fd, char_id, 3); return; } - Sql_GetData(sql_handle, 0, &data, NULL); base_level = (unsigned int)strtoul(data, NULL, 10); - Sql_GetData(sql_handle, 1, &data, NULL); delete_date = strtoul(data, NULL, 10); + SQL->GetData(sql_handle, 0, &data, NULL); base_level = (unsigned int)strtoul(data, NULL, 10); + SQL->GetData(sql_handle, 1, &data, NULL); delete_date = strtoul(data, NULL, 10); if( !delete_date || delete_date>time(NULL) ) {// not queued or delay not yet passed @@ -3697,7 +3697,7 @@ static void char_delete2_cancel(int fd, struct char_session_data* sd) // there is no need to check, whether or not the character was // queued for deletion, as the client prints an error message by // itself, if it was not the case (@see char_delete2_cancel_ack) - if( SQL_SUCCESS != Sql_Query(sql_handle, "UPDATE `%s` SET `delete_date`='0' WHERE `char_id`='%d'", char_db, char_id) ) + if( SQL_SUCCESS != SQL->Query(sql_handle, "UPDATE `%s` SET `delete_date`='0' WHERE `char_id`='%d'", char_db, char_id) ) { Sql_ShowDebug(sql_handle); char_delete2_cancel_ack(fd, char_id, 2); @@ -3849,12 +3849,12 @@ int parse_char(int fd) } } #endif - if ( SQL_SUCCESS != Sql_Query(sql_handle, "SELECT `char_id` FROM `%s` WHERE `account_id`='%d' AND `char_num`='%d'", char_db, sd->account_id, slot) - || SQL_SUCCESS != Sql_NextRow(sql_handle) - || SQL_SUCCESS != Sql_GetData(sql_handle, 0, &data, NULL) ) + if ( SQL_SUCCESS != SQL->Query(sql_handle, "SELECT `char_id` FROM `%s` WHERE `account_id`='%d' AND `char_num`='%d'", char_db, sd->account_id, slot) + || SQL_SUCCESS != SQL->NextRow(sql_handle) + || SQL_SUCCESS != SQL->GetData(sql_handle, 0, &data, NULL) ) { //Not found?? May be forged packet. Sql_ShowDebug(sql_handle); - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); WFIFOHEAD(fd,3); WFIFOW(fd,0) = 0x6c; WFIFOB(fd,2) = 0; // rejected from server @@ -3863,7 +3863,7 @@ int parse_char(int fd) } char_id = atoi(data); - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); /* set char as online prior to loading its data so 3rd party applications will realise the sql data is not reliable */ set_char_online(-2,char_id,sd->account_id); @@ -3884,8 +3884,8 @@ int parse_char(int fd) if (log_char) { char esc_name[NAME_LENGTH*2+1]; - Sql_EscapeStringLen(sql_handle, esc_name, char_dat.name, strnlen(char_dat.name, NAME_LENGTH)); - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s`(`time`, `account_id`,`char_num`,`name`) VALUES (NOW(), '%d', '%d', '%s')", + SQL->EscapeStringLen(sql_handle, esc_name, char_dat.name, strnlen(char_dat.name, NAME_LENGTH)); + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s`(`time`, `account_id`,`char_num`,`name`) VALUES (NOW(), '%d', '%d', '%s')", charlog_db, sd->account_id, slot, esc_name) ) Sql_ShowDebug(sql_handle); } @@ -4130,7 +4130,7 @@ int parse_char(int fd) break; normalize_name(name,TRIM_CHARS); - Sql_EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); + SQL->EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); if( !check_char_name(name,esc_name) ) { i = 1; safestrncpy(sd->new_name, name, NAME_LENGTH); @@ -4162,7 +4162,7 @@ int parse_char(int fd) break; normalize_name(name,TRIM_CHARS); - Sql_EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); + SQL->EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); if( !check_char_name(name,esc_name) ) { i = 1; @@ -4872,7 +4872,7 @@ void do_final(void) do_final_mapif(); do_final_loginif(); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s`", ragsrvinfo_db) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s`", ragsrvinfo_db) ) Sql_ShowDebug(sql_handle); char_db_->destroy(char_db_, NULL); @@ -4885,7 +4885,7 @@ void do_final(void) char_fd = -1; } - Sql_Free(sql_handle); + SQL->Free(sql_handle); mapindex_final(); ShowStatus("Finished.\n"); @@ -4981,15 +4981,15 @@ int do_init(int argc, char **argv) { //Cleaning the tables for NULL entrys @ startup [Sirius] //Chardb clean - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '0'", char_db) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '0'", char_db) ) Sql_ShowDebug(sql_handle); //guilddb clean - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_lv` = '0' AND `max_member` = '0' AND `exp` = '0' AND `next_exp` = '0' AND `average_lv` = '0'", guild_db) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_lv` = '0' AND `max_member` = '0' AND `exp` = '0' AND `next_exp` = '0' AND `average_lv` = '0'", guild_db) ) Sql_ShowDebug(sql_handle); //guildmemberdb clean - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '0' AND `account_id` = '0' AND `char_id` = '0'", guild_member_db) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '0' AND `account_id` = '0' AND `char_id` = '0'", guild_member_db) ) Sql_ShowDebug(sql_handle); set_defaultparse(parse_char); diff --git a/src/char/int_auction.c b/src/char/int_auction.c index 06e238667..977638aad 100644 --- a/src/char/int_auction.c +++ b/src/char/int_auction.c @@ -1,5 +1,6 @@ -// 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 #include "../common/mmo.h" #include "../common/malloc.h" @@ -48,15 +49,15 @@ void auction_save(struct auction_data *auction) if( !auction ) return; - StringBuf_Init(&buf); - StringBuf_Printf(&buf, "UPDATE `%s` SET `seller_id` = '%d', `seller_name` = ?, `buyer_id` = '%d', `buyer_name` = ?, `price` = '%d', `buynow` = '%d', `hours` = '%d', `timestamp` = '%lu', `nameid` = '%d', `item_name` = ?, `type` = '%d', `refine` = '%d', `attribute` = '%d'", + StrBuf->Init(&buf); + StrBuf->Printf(&buf, "UPDATE `%s` SET `seller_id` = '%d', `seller_name` = ?, `buyer_id` = '%d', `buyer_name` = ?, `price` = '%d', `buynow` = '%d', `hours` = '%d', `timestamp` = '%lu', `nameid` = '%d', `item_name` = ?, `type` = '%d', `refine` = '%d', `attribute` = '%d'", auction_db, auction->seller_id, auction->buyer_id, auction->price, auction->buynow, auction->hours, (unsigned long)auction->timestamp, auction->item.nameid, auction->type, auction->item.refine, auction->item.attribute); for( j = 0; j < MAX_SLOTS; j++ ) - StringBuf_Printf(&buf, ", `card%d` = '%d'", j, auction->item.card[j]); - StringBuf_Printf(&buf, " WHERE `auction_id` = '%d'", auction->auction_id); + StrBuf->Printf(&buf, ", `card%d` = '%d'", j, auction->item.card[j]); + StrBuf->Printf(&buf, " WHERE `auction_id` = '%d'", auction->auction_id); stmt = SqlStmt_Malloc(sql_handle); - if( SQL_SUCCESS != SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) + if( SQL_SUCCESS != SqlStmt_PrepareStr(stmt, StrBuf->Value(&buf)) || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, auction->seller_name, strnlen(auction->seller_name, NAME_LENGTH)) || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, auction->buyer_name, strnlen(auction->buyer_name, NAME_LENGTH)) || SQL_SUCCESS != SqlStmt_BindParam(stmt, 2, SQLDT_STRING, auction->item_name, strnlen(auction->item_name, ITEM_NAME_LENGTH)) @@ -66,7 +67,7 @@ void auction_save(struct auction_data *auction) } SqlStmt_Free(stmt); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); } unsigned int auction_create(struct auction_data *auction) @@ -80,22 +81,22 @@ unsigned int auction_create(struct auction_data *auction) auction->timestamp = time(NULL) + (auction->hours * 3600); - StringBuf_Init(&buf); - StringBuf_Printf(&buf, "INSERT INTO `%s` (`seller_id`,`seller_name`,`buyer_id`,`buyer_name`,`price`,`buynow`,`hours`,`timestamp`,`nameid`,`item_name`,`type`,`refine`,`attribute`,`unique_id`", auction_db); + StrBuf->Init(&buf); + StrBuf->Printf(&buf, "INSERT INTO `%s` (`seller_id`,`seller_name`,`buyer_id`,`buyer_name`,`price`,`buynow`,`hours`,`timestamp`,`nameid`,`item_name`,`type`,`refine`,`attribute`,`unique_id`", auction_db); for( j = 0; j < MAX_SLOTS; j++ ) - StringBuf_Printf(&buf, ",`card%d`", j); - StringBuf_Printf(&buf, ") VALUES ('%d',?,'%d',?,'%d','%d','%d','%lu','%d',?,'%d','%d','%d','%"PRIu64"'", + StrBuf->Printf(&buf, ",`card%d`", j); + StrBuf->Printf(&buf, ") VALUES ('%d',?,'%d',?,'%d','%d','%d','%lu','%d',?,'%d','%d','%d','%"PRIu64"'", auction->seller_id, auction->buyer_id, auction->price, auction->buynow, auction->hours, (unsigned long)auction->timestamp, auction->item.nameid, auction->type, auction->item.refine, auction->item.attribute, auction->item.unique_id); for( j = 0; j < MAX_SLOTS; j++ ) - StringBuf_Printf(&buf, ",'%d'", auction->item.card[j]); - StringBuf_AppendStr(&buf, ")"); + StrBuf->Printf(&buf, ",'%d'", auction->item.card[j]); + StrBuf->AppendStr(&buf, ")"); //Unique Non Stackable Item ID updateLastUid(auction->item.unique_id); dbUpdateUid(sql_handle); stmt = SqlStmt_Malloc(sql_handle); - if( SQL_SUCCESS != SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) + if( SQL_SUCCESS != SqlStmt_PrepareStr(stmt, StrBuf->Value(&buf)) || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, auction->seller_name, strnlen(auction->seller_name, NAME_LENGTH)) || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, auction->buyer_name, strnlen(auction->buyer_name, NAME_LENGTH)) || SQL_SUCCESS != SqlStmt_BindParam(stmt, 2, SQLDT_STRING, auction->item_name, strnlen(auction->item_name, ITEM_NAME_LENGTH)) @@ -123,7 +124,7 @@ unsigned int auction_create(struct auction_data *auction) } SqlStmt_Free(stmt); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); return auction->auction_id; } @@ -165,7 +166,7 @@ void auction_delete(struct auction_data *auction) { unsigned int auction_id = auction->auction_id; - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `auction_id` = '%d'", auction_db, auction_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `auction_id` = '%d'", auction_db, auction_id) ) Sql_ShowDebug(sql_handle); if( auction->auction_end_timer != INVALID_TIMER ) @@ -184,39 +185,39 @@ void inter_auctions_fromsql(void) unsigned int tick = gettick(), endtick; time_t now = time(NULL); - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, "SELECT `auction_id`,`seller_id`,`seller_name`,`buyer_id`,`buyer_name`," + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, "SELECT `auction_id`,`seller_id`,`seller_name`,`buyer_id`,`buyer_name`," "`price`,`buynow`,`hours`,`timestamp`,`nameid`,`item_name`,`type`,`refine`,`attribute`,`unique_id`"); for( i = 0; i < MAX_SLOTS; i++ ) - StringBuf_Printf(&buf, ",`card%d`", i); - StringBuf_Printf(&buf, " FROM `%s` ORDER BY `auction_id` DESC", auction_db); + StrBuf->Printf(&buf, ",`card%d`", i); + StrBuf->Printf(&buf, " FROM `%s` ORDER BY `auction_id` DESC", auction_db); - if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) ) + if( SQL_ERROR == SQL->Query(sql_handle, StrBuf->Value(&buf)) ) Sql_ShowDebug(sql_handle); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); - while( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + while( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { CREATE(auction, struct auction_data, 1); - Sql_GetData(sql_handle, 0, &data, NULL); auction->auction_id = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); auction->seller_id = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); safestrncpy(auction->seller_name, data, NAME_LENGTH); - Sql_GetData(sql_handle, 3, &data, NULL); auction->buyer_id = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); safestrncpy(auction->buyer_name, data, NAME_LENGTH); - Sql_GetData(sql_handle, 5, &data, NULL); auction->price = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); auction->buynow = atoi(data); - Sql_GetData(sql_handle, 7, &data, NULL); auction->hours = atoi(data); - Sql_GetData(sql_handle, 8, &data, NULL); auction->timestamp = atoi(data); + SQL->GetData(sql_handle, 0, &data, NULL); auction->auction_id = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); auction->seller_id = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); safestrncpy(auction->seller_name, data, NAME_LENGTH); + SQL->GetData(sql_handle, 3, &data, NULL); auction->buyer_id = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); safestrncpy(auction->buyer_name, data, NAME_LENGTH); + SQL->GetData(sql_handle, 5, &data, NULL); auction->price = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); auction->buynow = atoi(data); + SQL->GetData(sql_handle, 7, &data, NULL); auction->hours = atoi(data); + SQL->GetData(sql_handle, 8, &data, NULL); auction->timestamp = atoi(data); item = &auction->item; - Sql_GetData(sql_handle, 9, &data, NULL); item->nameid = atoi(data); - Sql_GetData(sql_handle,10, &data, NULL); safestrncpy(auction->item_name, data, ITEM_NAME_LENGTH); - Sql_GetData(sql_handle,11, &data, NULL); auction->type = atoi(data); + SQL->GetData(sql_handle, 9, &data, NULL); item->nameid = atoi(data); + SQL->GetData(sql_handle,10, &data, NULL); safestrncpy(auction->item_name, data, ITEM_NAME_LENGTH); + SQL->GetData(sql_handle,11, &data, NULL); auction->type = atoi(data); - Sql_GetData(sql_handle,12, &data, NULL); item->refine = atoi(data); - Sql_GetData(sql_handle,13, &data, NULL); item->attribute = atoi(data); - Sql_GetData(sql_handle,14, &data, NULL); item->unique_id = strtoull(data, NULL, 10); + SQL->GetData(sql_handle,12, &data, NULL); item->refine = atoi(data); + SQL->GetData(sql_handle,13, &data, NULL); item->attribute = atoi(data); + SQL->GetData(sql_handle,14, &data, NULL); item->unique_id = strtoull(data, NULL, 10); item->identify = 1; item->amount = 1; @@ -224,7 +225,7 @@ void inter_auctions_fromsql(void) for( i = 0; i < MAX_SLOTS; i++ ) { - Sql_GetData(sql_handle, 15 + i, &data, NULL); + SQL->GetData(sql_handle, 15 + i, &data, NULL); item->card[i] = atoi(data); } @@ -237,7 +238,7 @@ void inter_auctions_fromsql(void) idb_put(auction_db_, auction->auction_id, auction); } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); } static void mapif_Auction_sendlist(int fd, int char_id, short count, short pages, unsigned char *buf) diff --git a/src/char/int_elemental.c b/src/char/int_elemental.c index 3c2f6672d..807924941 100644 --- a/src/char/int_elemental.c +++ b/src/char/int_elemental.c @@ -1,5 +1,6 @@ -// 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 #include "../common/mmo.h" #include "../common/malloc.h" @@ -19,7 +20,7 @@ bool mapif_elemental_save(struct s_elemental* ele) { bool flag = true; if( ele->elemental_id == 0 ) { // Create new DB entry - if( SQL_ERROR == Sql_Query(sql_handle, + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `elemental` (`char_id`,`class`,`mode`,`hp`,`sp`,`max_hp`,`max_sp`,`atk1`,`atk2`,`matk`,`aspd`,`def`,`mdef`,`flee`,`hit`,`life_time`)" "VALUES ('%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%u')", ele->char_id, ele->class_, ele->mode, ele->hp, ele->sp, ele->max_hp, ele->max_sp, ele->atk, ele->atk2, ele->matk, ele->amotion, ele->def, ele->mdef, ele->flee, ele->hit, ele->life_time) ) @@ -28,8 +29,8 @@ bool mapif_elemental_save(struct s_elemental* ele) { flag = false; } else - ele->elemental_id = (int)Sql_LastInsertId(sql_handle); - } else if( SQL_ERROR == Sql_Query(sql_handle, + ele->elemental_id = (int)SQL->NumRows(sql_handle); + } else if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `elemental` SET `char_id` = '%d', `class` = '%d', `mode` = '%d', `hp` = '%d', `sp` = '%d'," "`max_hp` = '%d', `max_sp` = '%d', `atk1` = '%d', `atk2` = '%d', `matk` = '%d', `aspd` = '%d', `def` = '%d'," "`mdef` = '%d', `flee` = '%d', `hit` = '%d', `life_time` = '%u' WHERE `ele_id` = '%d'", @@ -49,34 +50,34 @@ bool mapif_elemental_load(int ele_id, int char_id, struct s_elemental *ele) { ele->elemental_id = ele_id; ele->char_id = char_id; - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `class`, `mode`, `hp`, `sp`, `max_hp`, `max_sp`, `atk1`, `atk2`, `matk`, `aspd`," + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `class`, `mode`, `hp`, `sp`, `max_hp`, `max_sp`, `atk1`, `atk2`, `matk`, `aspd`," "`def`, `mdef`, `flee`, `hit`, `life_time` FROM `elemental` WHERE `ele_id` = '%d' AND `char_id` = '%d'", ele_id, char_id) ) { Sql_ShowDebug(sql_handle); return false; } - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) { - Sql_FreeResult(sql_handle); + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) { + SQL->FreeResult(sql_handle); return false; } - Sql_GetData(sql_handle, 0, &data, NULL); ele->class_ = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); ele->mode = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); ele->hp = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); ele->sp = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); ele->max_hp = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); ele->max_sp = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); ele->atk = atoi(data); - Sql_GetData(sql_handle, 7, &data, NULL); ele->atk2 = atoi(data); - Sql_GetData(sql_handle, 8, &data, NULL); ele->matk = atoi(data); - Sql_GetData(sql_handle, 9, &data, NULL); ele->amotion = atoi(data); - Sql_GetData(sql_handle, 10, &data, NULL); ele->def = atoi(data); - Sql_GetData(sql_handle, 11, &data, NULL); ele->mdef = atoi(data); - Sql_GetData(sql_handle, 12, &data, NULL); ele->flee = atoi(data); - Sql_GetData(sql_handle, 13, &data, NULL); ele->hit = atoi(data); - Sql_GetData(sql_handle, 14, &data, NULL); ele->life_time = atoi(data); - Sql_FreeResult(sql_handle); + SQL->GetData(sql_handle, 0, &data, NULL); ele->class_ = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); ele->mode = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); ele->hp = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); ele->sp = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); ele->max_hp = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); ele->max_sp = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); ele->atk = atoi(data); + SQL->GetData(sql_handle, 7, &data, NULL); ele->atk2 = atoi(data); + SQL->GetData(sql_handle, 8, &data, NULL); ele->matk = atoi(data); + SQL->GetData(sql_handle, 9, &data, NULL); ele->amotion = atoi(data); + SQL->GetData(sql_handle, 10, &data, NULL); ele->def = atoi(data); + SQL->GetData(sql_handle, 11, &data, NULL); ele->mdef = atoi(data); + SQL->GetData(sql_handle, 12, &data, NULL); ele->flee = atoi(data); + SQL->GetData(sql_handle, 13, &data, NULL); ele->hit = atoi(data); + SQL->GetData(sql_handle, 14, &data, NULL); ele->life_time = atoi(data); + SQL->FreeResult(sql_handle); if( save_log ) ShowInfo("Elemental loaded (%d - %d).\n", ele->elemental_id, ele->char_id); @@ -84,7 +85,7 @@ bool mapif_elemental_load(int ele_id, int char_id, struct s_elemental *ele) { } bool mapif_elemental_delete(int ele_id) { - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `elemental` WHERE `ele_id` = '%d'", ele_id) ) { + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `elemental` WHERE `ele_id` = '%d'", ele_id) ) { Sql_ShowDebug(sql_handle); return false; } diff --git a/src/char/int_guild.c b/src/char/int_guild.c index 46bba63db..d9d89206b 100644 --- a/src/char/int_guild.c +++ b/src/char/int_guild.c @@ -92,9 +92,9 @@ static int guild_save_timer(int tid, unsigned int tick, int id, intptr_t data) int inter_guild_removemember_tosql(int account_id, int char_id) { - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE from `%s` where `account_id` = '%d' and `char_id` = '%d'", guild_member_db, account_id, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE from `%s` where `account_id` = '%d' and `char_id` = '%d'", guild_member_db, account_id, char_id) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `guild_id` = '0' WHERE `char_id` = '%d'", char_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `guild_id` = '0' WHERE `char_id` = '%d'", char_db, char_id) ) Sql_ShowDebug(sql_handle); return 0; } @@ -129,8 +129,8 @@ int inter_guild_tosql(struct guild *g,int flag) ShowInfo("Save guild request ("CL_BOLD"%d"CL_RESET" - flag 0x%x).",g->guild_id, flag); #endif - Sql_EscapeStringLen(sql_handle, esc_name, g->name, strnlen(g->name, NAME_LENGTH)); - Sql_EscapeStringLen(sql_handle, esc_master, g->master, strnlen(g->master, NAME_LENGTH)); + SQL->EscapeStringLen(sql_handle, esc_name, g->name, strnlen(g->name, NAME_LENGTH)); + SQL->EscapeStringLen(sql_handle, esc_master, g->master, strnlen(g->master, NAME_LENGTH)); *t_info = '\0'; // Insert a new guild the guild @@ -139,7 +139,7 @@ int inter_guild_tosql(struct guild *g,int flag) strcat(t_info, " guild_create"); // Create a new guild - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` " + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` " "(`name`,`master`,`guild_lv`,`max_member`,`average_lv`,`char_id`) " "VALUES ('%s', '%s', '%d', '%d', '%d', '%d')", guild_db, esc_name, esc_master, g->guild_lv, g->max_member, g->average_lv, g->member[0].char_id) ) @@ -150,7 +150,7 @@ int inter_guild_tosql(struct guild *g,int flag) } else { - g->guild_id = (int)Sql_LastInsertId(sql_handle); + g->guild_id = (int)SQL->NumRows(sql_handle); new_guild = 1; } } @@ -161,8 +161,8 @@ int inter_guild_tosql(struct guild *g,int flag) StringBuf buf; bool add_comma = false; - StringBuf_Init(&buf); - StringBuf_Printf(&buf, "UPDATE `%s` SET ", guild_db); + StrBuf->Init(&buf); + StrBuf->Printf(&buf, "UPDATE `%s` SET ", guild_db); if (flag & GS_EMBLEM) { @@ -177,26 +177,26 @@ int inter_guild_tosql(struct guild *g,int flag) *pData++ = dataToHex[g->emblem_data[i] & 0x0F]; } *pData = 0; - StringBuf_Printf(&buf, "`emblem_len`=%d, `emblem_id`=%d, `emblem_data`='%s'", g->emblem_len, g->emblem_id, emblem_data); + StrBuf->Printf(&buf, "`emblem_len`=%d, `emblem_id`=%d, `emblem_data`='%s'", g->emblem_len, g->emblem_id, emblem_data); add_comma = true; } if (flag & GS_BASIC) { strcat(t_info, " basic"); if( add_comma ) - StringBuf_AppendStr(&buf, ", "); + StrBuf->AppendStr(&buf, ", "); else add_comma = true; - StringBuf_Printf(&buf, "`name`='%s', `master`='%s', `char_id`=%d", esc_name, esc_master, g->member[0].char_id); + StrBuf->Printf(&buf, "`name`='%s', `master`='%s', `char_id`=%d", esc_name, esc_master, g->member[0].char_id); } if (flag & GS_CONNECT) { strcat(t_info, " connect"); if( add_comma ) - StringBuf_AppendStr(&buf, ", "); + StrBuf->AppendStr(&buf, ", "); else add_comma = true; - StringBuf_Printf(&buf, "`connect_member`=%d, `average_lv`=%d", g->connect_member, g->average_lv); + StrBuf->Printf(&buf, "`connect_member`=%d, `average_lv`=%d", g->connect_member, g->average_lv); } if (flag & GS_MES) { @@ -205,26 +205,26 @@ int inter_guild_tosql(struct guild *g,int flag) strcat(t_info, " mes"); if( add_comma ) - StringBuf_AppendStr(&buf, ", "); + StrBuf->AppendStr(&buf, ", "); else add_comma = true; - Sql_EscapeStringLen(sql_handle, esc_mes1, g->mes1, strnlen(g->mes1, sizeof(g->mes1))); - Sql_EscapeStringLen(sql_handle, esc_mes2, g->mes2, strnlen(g->mes2, sizeof(g->mes2))); - StringBuf_Printf(&buf, "`mes1`='%s', `mes2`='%s'", esc_mes1, esc_mes2); + SQL->EscapeStringLen(sql_handle, esc_mes1, g->mes1, strnlen(g->mes1, sizeof(g->mes1))); + SQL->EscapeStringLen(sql_handle, esc_mes2, g->mes2, strnlen(g->mes2, sizeof(g->mes2))); + StrBuf->Printf(&buf, "`mes1`='%s', `mes2`='%s'", esc_mes1, esc_mes2); } if (flag & GS_LEVEL) { strcat(t_info, " level"); if( add_comma ) - StringBuf_AppendStr(&buf, ", "); + StrBuf->AppendStr(&buf, ", "); //else //last condition using add_coma setting // add_comma = true; - StringBuf_Printf(&buf, "`guild_lv`=%d, `skill_point`=%d, `exp`=%"PRIu64", `next_exp`=%u, `max_member`=%d", g->guild_lv, g->skill_point, g->exp, g->next_exp, g->max_member); + StrBuf->Printf(&buf, "`guild_lv`=%d, `skill_point`=%d, `exp`=%"PRIu64", `next_exp`=%u, `max_member`=%d", g->guild_lv, g->skill_point, g->exp, g->next_exp, g->max_member); } - StringBuf_Printf(&buf, " WHERE `guild_id`=%d", g->guild_id); - if( SQL_ERROR == Sql_Query(sql_handle, "%s", StringBuf_Value(&buf)) ) + StrBuf->Printf(&buf, " WHERE `guild_id`=%d", g->guild_id); + if( SQL_ERROR == SQL->Query(sql_handle, "%s", StrBuf->Value(&buf)) ) Sql_ShowDebug(sql_handle); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); } if (flag&GS_MEMBER) @@ -239,8 +239,8 @@ int inter_guild_tosql(struct guild *g,int flag) continue; if(m->account_id) { //Since nothing references guild member table as foreign keys, it's safe to use REPLACE INTO - Sql_EscapeStringLen(sql_handle, esc_name, m->name, strnlen(m->name, NAME_LENGTH)); - if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`account_id`,`char_id`,`hair`,`hair_color`,`gender`,`class`,`lv`,`exp`,`exp_payper`,`online`,`position`,`name`) " + SQL->EscapeStringLen(sql_handle, esc_name, m->name, strnlen(m->name, NAME_LENGTH)); + if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`account_id`,`char_id`,`hair`,`hair_color`,`gender`,`class`,`lv`,`exp`,`exp_payper`,`online`,`position`,`name`) " "VALUES ('%d','%d','%d','%d','%d','%d','%d','%d','%"PRIu64"','%d','%d','%d','%s')", guild_member_db, g->guild_id, m->account_id, m->char_id, m->hair, m->hair_color, m->gender, @@ -248,7 +248,7 @@ int inter_guild_tosql(struct guild *g,int flag) Sql_ShowDebug(sql_handle); if (m->modified&GS_MEMBER_NEW || new_guild == 1) { - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `guild_id` = '%d' WHERE `char_id` = '%d'", + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `guild_id` = '%d' WHERE `char_id` = '%d'", char_db, g->guild_id, m->char_id) ) Sql_ShowDebug(sql_handle); } @@ -264,8 +264,8 @@ int inter_guild_tosql(struct guild *g,int flag) struct guild_position *p = &g->position[i]; if (!p->modified) continue; - Sql_EscapeStringLen(sql_handle, esc_name, p->name, strnlen(p->name, NAME_LENGTH)); - if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`position`,`name`,`mode`,`exp_mode`) VALUES ('%d','%d','%s','%d','%d')", + SQL->EscapeStringLen(sql_handle, esc_name, p->name, strnlen(p->name, NAME_LENGTH)); + if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`position`,`name`,`mode`,`exp_mode`) VALUES ('%d','%d','%s','%d','%d')", guild_position_db, g->guild_id, i, esc_name, p->mode, p->exp_mode) ) Sql_ShowDebug(sql_handle); p->modified = GS_POSITION_UNMODIFIED; @@ -278,8 +278,8 @@ int inter_guild_tosql(struct guild *g,int flag) // NOTE: no need to do it on both sides since both guilds in memory had // their info changed, not to mention this would also mess up oppositions! // [Skotlex] - //if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id`='%d' OR `alliance_id`='%d'", guild_alliance_db, g->guild_id, g->guild_id) ) - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id`='%d'", guild_alliance_db, g->guild_id) ) + //if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id`='%d' OR `alliance_id`='%d'", guild_alliance_db, g->guild_id, g->guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id`='%d'", guild_alliance_db, g->guild_id) ) { Sql_ShowDebug(sql_handle); } @@ -291,8 +291,8 @@ int inter_guild_tosql(struct guild *g,int flag) struct guild_alliance *a=&g->alliance[i]; if(a->guild_id>0) { - Sql_EscapeStringLen(sql_handle, esc_name, a->name, strnlen(a->name, NAME_LENGTH)); - if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`opposition`,`alliance_id`,`name`) " + SQL->EscapeStringLen(sql_handle, esc_name, a->name, strnlen(a->name, NAME_LENGTH)); + if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`opposition`,`alliance_id`,`name`) " "VALUES ('%d','%d','%d','%s')", guild_alliance_db, g->guild_id, a->opposition, a->guild_id, esc_name) ) Sql_ShowDebug(sql_handle); @@ -309,9 +309,9 @@ int inter_guild_tosql(struct guild *g,int flag) if(e->account_id>0){ char esc_mes[sizeof(e->mes)*2+1]; - Sql_EscapeStringLen(sql_handle, esc_name, e->name, strnlen(e->name, NAME_LENGTH)); - Sql_EscapeStringLen(sql_handle, esc_mes, e->mes, strnlen(e->mes, sizeof(e->mes))); - if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`account_id`,`name`,`mes`) " + SQL->EscapeStringLen(sql_handle, esc_name, e->name, strnlen(e->name, NAME_LENGTH)); + SQL->EscapeStringLen(sql_handle, esc_mes, e->mes, strnlen(e->mes, sizeof(e->mes))); + if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`account_id`,`name`,`mes`) " "VALUES ('%d','%d','%s','%s')", guild_expulsion_db, g->guild_id, e->account_id, esc_name, esc_mes) ) Sql_ShowDebug(sql_handle); } @@ -323,7 +323,7 @@ int inter_guild_tosql(struct guild *g,int flag) //printf("- Insert guild %d to guild_skill\n",g->guild_id); for(i=0;iskill[i].id>0 && g->skill[i].lv>0){ - if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`id`,`lv`) VALUES ('%d','%d','%d')", + if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`id`,`lv`) VALUES ('%d','%d','%d')", guild_skill_db, g->guild_id, g->skill[i].id, g->skill[i].lv) ) Sql_ShowDebug(sql_handle); } @@ -355,38 +355,38 @@ struct guild * inter_guild_fromsql(int guild_id) ShowInfo("Guild load request (%d)...\n", guild_id); #endif - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT g.`name`,c.`name`,g.`guild_lv`,g.`connect_member`,g.`max_member`,g.`average_lv`,g.`exp`,g.`next_exp`,g.`skill_point`,g.`mes1`,g.`mes2`,g.`emblem_len`,g.`emblem_id`,g.`emblem_data` " + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT g.`name`,c.`name`,g.`guild_lv`,g.`connect_member`,g.`max_member`,g.`average_lv`,g.`exp`,g.`next_exp`,g.`skill_point`,g.`mes1`,g.`mes2`,g.`emblem_len`,g.`emblem_id`,g.`emblem_data` " "FROM `%s` g LEFT JOIN `%s` c ON c.`char_id` = g.`char_id` WHERE g.`guild_id`='%d'", guild_db, char_db, guild_id) ) { Sql_ShowDebug(sql_handle); return NULL; } - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) return NULL;// Guild does not exists. CREATE(g, struct guild, 1); g->guild_id = guild_id; - Sql_GetData(sql_handle, 0, &data, &len); memcpy(g->name, data, min(len, NAME_LENGTH)); - Sql_GetData(sql_handle, 1, &data, &len); memcpy(g->master, data, min(len, NAME_LENGTH)); - Sql_GetData(sql_handle, 2, &data, NULL); g->guild_lv = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); g->connect_member = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); g->max_member = atoi(data); + SQL->GetData(sql_handle, 0, &data, &len); memcpy(g->name, data, min(len, NAME_LENGTH)); + SQL->GetData(sql_handle, 1, &data, &len); memcpy(g->master, data, min(len, NAME_LENGTH)); + SQL->GetData(sql_handle, 2, &data, NULL); g->guild_lv = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); g->connect_member = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); g->max_member = atoi(data); if( g->max_member > MAX_GUILD ) { // Fix reduction of MAX_GUILD [PoW] ShowWarning("Guild %d:%s specifies higher capacity (%d) than MAX_GUILD (%d)\n", guild_id, g->name, g->max_member, MAX_GUILD); g->max_member = MAX_GUILD; } - Sql_GetData(sql_handle, 5, &data, NULL); g->average_lv = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); g->exp = strtoull(data, NULL, 10); - Sql_GetData(sql_handle, 7, &data, NULL); g->next_exp = (unsigned int)strtoul(data, NULL, 10); - Sql_GetData(sql_handle, 8, &data, NULL); g->skill_point = atoi(data); - Sql_GetData(sql_handle, 9, &data, &len); memcpy(g->mes1, data, min(len, sizeof(g->mes1))); - Sql_GetData(sql_handle, 10, &data, &len); memcpy(g->mes2, data, min(len, sizeof(g->mes2))); - Sql_GetData(sql_handle, 11, &data, &len); g->emblem_len = atoi(data); - Sql_GetData(sql_handle, 12, &data, &len); g->emblem_id = atoi(data); - Sql_GetData(sql_handle, 13, &data, &len); + SQL->GetData(sql_handle, 5, &data, NULL); g->average_lv = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); g->exp = strtoull(data, NULL, 10); + SQL->GetData(sql_handle, 7, &data, NULL); g->next_exp = (unsigned int)strtoul(data, NULL, 10); + SQL->GetData(sql_handle, 8, &data, NULL); g->skill_point = atoi(data); + SQL->GetData(sql_handle, 9, &data, &len); memcpy(g->mes1, data, min(len, sizeof(g->mes1))); + SQL->GetData(sql_handle, 10, &data, &len); memcpy(g->mes2, data, min(len, sizeof(g->mes2))); + SQL->GetData(sql_handle, 11, &data, &len); g->emblem_len = atoi(data); + SQL->GetData(sql_handle, 12, &data, &len); g->emblem_id = atoi(data); + SQL->GetData(sql_handle, 13, &data, &len); // convert emblem data from hexadecimal to binary //TODO: why not store it in the db as binary directly? [ultramage] for( i = 0, p = g->emblem_data; i < g->emblem_len; ++i, ++p ) @@ -410,90 +410,90 @@ struct guild * inter_guild_fromsql(int guild_id) } // load guild member info - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`char_id`,`hair`,`hair_color`,`gender`,`class`,`lv`,`exp`,`exp_payper`,`online`,`position`,`name` " + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id`,`char_id`,`hair`,`hair_color`,`gender`,`class`,`lv`,`exp`,`exp_payper`,`online`,`position`,`name` " "FROM `%s` WHERE `guild_id`='%d' ORDER BY `position`", guild_member_db, guild_id) ) { Sql_ShowDebug(sql_handle); aFree(g); return NULL; } - for( i = 0; i < g->max_member && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for( i = 0; i < g->max_member && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) { struct guild_member* m = &g->member[i]; - Sql_GetData(sql_handle, 0, &data, NULL); m->account_id = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); m->char_id = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); m->hair = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); m->hair_color = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); m->gender = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); m->class_ = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); m->lv = atoi(data); - Sql_GetData(sql_handle, 7, &data, NULL); m->exp = strtoull(data, NULL, 10); - Sql_GetData(sql_handle, 8, &data, NULL); m->exp_payper = (unsigned int)atoi(data); - Sql_GetData(sql_handle, 9, &data, NULL); m->online = atoi(data); - Sql_GetData(sql_handle, 10, &data, NULL); m->position = atoi(data); + SQL->GetData(sql_handle, 0, &data, NULL); m->account_id = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); m->char_id = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); m->hair = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); m->hair_color = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); m->gender = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); m->class_ = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); m->lv = atoi(data); + SQL->GetData(sql_handle, 7, &data, NULL); m->exp = strtoull(data, NULL, 10); + SQL->GetData(sql_handle, 8, &data, NULL); m->exp_payper = (unsigned int)atoi(data); + SQL->GetData(sql_handle, 9, &data, NULL); m->online = atoi(data); + SQL->GetData(sql_handle, 10, &data, NULL); m->position = atoi(data); if( m->position >= MAX_GUILDPOSITION ) // Fix reduction of MAX_GUILDPOSITION [PoW] m->position = MAX_GUILDPOSITION - 1; - Sql_GetData(sql_handle, 11, &data, &len); memcpy(m->name, data, min(len, NAME_LENGTH)); + SQL->GetData(sql_handle, 11, &data, &len); memcpy(m->name, data, min(len, NAME_LENGTH)); m->modified = GS_MEMBER_UNMODIFIED; } //printf("- Read guild_position %d from sql \n",guild_id); - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `position`,`name`,`mode`,`exp_mode` FROM `%s` WHERE `guild_id`='%d'", guild_position_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `position`,`name`,`mode`,`exp_mode` FROM `%s` WHERE `guild_id`='%d'", guild_position_db, guild_id) ) { Sql_ShowDebug(sql_handle); aFree(g); return NULL; } - while( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + while( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { int position; struct guild_position* p; - Sql_GetData(sql_handle, 0, &data, NULL); position = atoi(data); + SQL->GetData(sql_handle, 0, &data, NULL); position = atoi(data); if( position < 0 || position >= MAX_GUILDPOSITION ) continue;// invalid position p = &g->position[position]; - Sql_GetData(sql_handle, 1, &data, &len); memcpy(p->name, data, min(len, NAME_LENGTH)); - Sql_GetData(sql_handle, 2, &data, NULL); p->mode = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); p->exp_mode = atoi(data); + SQL->GetData(sql_handle, 1, &data, &len); memcpy(p->name, data, min(len, NAME_LENGTH)); + SQL->GetData(sql_handle, 2, &data, NULL); p->mode = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); p->exp_mode = atoi(data); p->modified = GS_POSITION_UNMODIFIED; } //printf("- Read guild_alliance %d from sql \n",guild_id); - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `opposition`,`alliance_id`,`name` FROM `%s` WHERE `guild_id`='%d'", guild_alliance_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `opposition`,`alliance_id`,`name` FROM `%s` WHERE `guild_id`='%d'", guild_alliance_db, guild_id) ) { Sql_ShowDebug(sql_handle); aFree(g); return NULL; } - for( i = 0; i < MAX_GUILDALLIANCE && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for( i = 0; i < MAX_GUILDALLIANCE && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) { struct guild_alliance* a = &g->alliance[i]; - Sql_GetData(sql_handle, 0, &data, NULL); a->opposition = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); a->guild_id = atoi(data); - Sql_GetData(sql_handle, 2, &data, &len); memcpy(a->name, data, min(len, NAME_LENGTH)); + SQL->GetData(sql_handle, 0, &data, NULL); a->opposition = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); a->guild_id = atoi(data); + SQL->GetData(sql_handle, 2, &data, &len); memcpy(a->name, data, min(len, NAME_LENGTH)); } //printf("- Read guild_expulsion %d from sql \n",guild_id); - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`name`,`mes` FROM `%s` WHERE `guild_id`='%d'", guild_expulsion_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id`,`name`,`mes` FROM `%s` WHERE `guild_id`='%d'", guild_expulsion_db, guild_id) ) { Sql_ShowDebug(sql_handle); aFree(g); return NULL; } - for( i = 0; i < MAX_GUILDEXPULSION && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for( i = 0; i < MAX_GUILDEXPULSION && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) { struct guild_expulsion *e = &g->expulsion[i]; - Sql_GetData(sql_handle, 0, &data, NULL); e->account_id = atoi(data); - Sql_GetData(sql_handle, 1, &data, &len); memcpy(e->name, data, min(len, NAME_LENGTH)); - Sql_GetData(sql_handle, 2, &data, &len); memcpy(e->mes, data, min(len, sizeof(e->mes))); + SQL->GetData(sql_handle, 0, &data, NULL); e->account_id = atoi(data); + SQL->GetData(sql_handle, 1, &data, &len); memcpy(e->name, data, min(len, NAME_LENGTH)); + SQL->GetData(sql_handle, 2, &data, &len); memcpy(e->mes, data, min(len, sizeof(e->mes))); } //printf("- Read guild_skill %d from sql \n",guild_id); - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `id`,`lv` FROM `%s` WHERE `guild_id`='%d' ORDER BY `id`", guild_skill_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `id`,`lv` FROM `%s` WHERE `guild_id`='%d' ORDER BY `id`", guild_skill_db, guild_id) ) { Sql_ShowDebug(sql_handle); aFree(g); @@ -505,15 +505,15 @@ struct guild * inter_guild_fromsql(int guild_id) g->skill[i].id = i + GD_SKILLBASE; } - while( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + while( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { int id; - Sql_GetData(sql_handle, 0, &data, NULL); id = atoi(data) - GD_SKILLBASE; + SQL->GetData(sql_handle, 0, &data, NULL); id = atoi(data) - GD_SKILLBASE; if( id < 0 || id >= MAX_GUILDSKILL ) continue;// invalid guild skill - Sql_GetData(sql_handle, 1, &data, NULL); g->skill[id].lv = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); g->skill[id].lv = atoi(data); } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); idb_put(guild_db_, guild_id, g); //Add to cache g->save_flag |= GS_REMOVE; //But set it to be removed, in case it is not needed for long. @@ -530,20 +530,20 @@ int inter_guildcastle_tosql(struct guild_castle *gc) StringBuf buf; int i; - StringBuf_Init(&buf); - StringBuf_Printf(&buf, "REPLACE INTO `%s` SET `castle_id`='%d', `guild_id`='%d', `economy`='%d', `defense`='%d', " + StrBuf->Init(&buf); + StrBuf->Printf(&buf, "REPLACE INTO `%s` SET `castle_id`='%d', `guild_id`='%d', `economy`='%d', `defense`='%d', " "`triggerE`='%d', `triggerD`='%d', `nextTime`='%d', `payTime`='%d', `createTime`='%d', `visibleC`='%d'", guild_castle_db, gc->castle_id, gc->guild_id, gc->economy, gc->defense, gc->triggerE, gc->triggerD, gc->nextTime, gc->payTime, gc->createTime, gc->visibleC); for (i = 0; i < MAX_GUARDIANS; ++i) - StringBuf_Printf(&buf, ", `visibleG%d`='%d'", i, gc->guardian[i].visible); + StrBuf->Printf(&buf, ", `visibleG%d`='%d'", i, gc->guardian[i].visible); - if (SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf))) + if (SQL_ERROR == SQL->Query(sql_handle, StrBuf->Value(&buf))) Sql_ShowDebug(sql_handle); else if(save_log) ShowInfo("Saved guild castle (%d)\n", gc->castle_id); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); return 0; } @@ -558,37 +558,37 @@ static struct guild_castle* inter_guildcastle_fromsql(int castle_id) if (gc != NULL) return gc; - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, "SELECT `castle_id`, `guild_id`, `economy`, `defense`, `triggerE`, " + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, "SELECT `castle_id`, `guild_id`, `economy`, `defense`, `triggerE`, " "`triggerD`, `nextTime`, `payTime`, `createTime`, `visibleC`"); for (i = 0; i < MAX_GUARDIANS; ++i) - StringBuf_Printf(&buf, ", `visibleG%d`", i); - StringBuf_Printf(&buf, " FROM `%s` WHERE `castle_id`='%d'", guild_castle_db, castle_id); - if (SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf))) { + StrBuf->Printf(&buf, ", `visibleG%d`", i); + StrBuf->Printf(&buf, " FROM `%s` WHERE `castle_id`='%d'", guild_castle_db, castle_id); + if (SQL_ERROR == SQL->Query(sql_handle, StrBuf->Value(&buf))) { Sql_ShowDebug(sql_handle); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); return NULL; } - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); CREATE(gc, struct guild_castle, 1); gc->castle_id = castle_id; - if (SQL_SUCCESS == Sql_NextRow(sql_handle)) { - Sql_GetData(sql_handle, 1, &data, NULL); gc->guild_id = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); gc->economy = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); gc->defense = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); gc->triggerE = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); gc->triggerD = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); gc->nextTime = atoi(data); - Sql_GetData(sql_handle, 7, &data, NULL); gc->payTime = atoi(data); - Sql_GetData(sql_handle, 8, &data, NULL); gc->createTime = atoi(data); - Sql_GetData(sql_handle, 9, &data, NULL); gc->visibleC = atoi(data); + if (SQL_SUCCESS == SQL->NextRow(sql_handle)) { + SQL->GetData(sql_handle, 1, &data, NULL); gc->guild_id = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); gc->economy = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); gc->defense = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); gc->triggerE = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); gc->triggerD = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); gc->nextTime = atoi(data); + SQL->GetData(sql_handle, 7, &data, NULL); gc->payTime = atoi(data); + SQL->GetData(sql_handle, 8, &data, NULL); gc->createTime = atoi(data); + SQL->GetData(sql_handle, 9, &data, NULL); gc->visibleC = atoi(data); for (i = 10; i < 10+MAX_GUARDIANS; i++) { - Sql_GetData(sql_handle, i, &data, NULL); gc->guardian[i-10].visible = atoi(data); + SQL->GetData(sql_handle, i, &data, NULL); gc->guardian[i-10].visible = atoi(data); } } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); idb_put(castle_db, castle_id, gc); @@ -621,24 +621,24 @@ int inter_guild_CharOnline(int char_id, int guild_id) if (guild_id == -1) { //Get guild_id from the database - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT guild_id FROM `%s` WHERE char_id='%d'", char_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT guild_id FROM `%s` WHERE char_id='%d'", char_db, char_id) ) { Sql_ShowDebug(sql_handle); return 0; } - if( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { char* data; - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); guild_id = atoi(data); } else { guild_id = 0; } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); } if (guild_id == 0) return 0; //No guild... @@ -672,24 +672,24 @@ int inter_guild_CharOffline(int char_id, int guild_id) if (guild_id == -1) { //Get guild_id from the database - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT guild_id FROM `%s` WHERE char_id='%d'", char_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT guild_id FROM `%s` WHERE char_id='%d'", char_db, char_id) ) { Sql_ShowDebug(sql_handle); return 0; } - if( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { char* data; - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); guild_id = atoi(data); } else { guild_id = 0; } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); } if (guild_id == 0) return 0; //No guild... @@ -727,7 +727,7 @@ int inter_guild_sql_init(void) castle_db = idb_alloc(DB_OPT_RELEASE_DATA); //Read exp file - sv_readdb("db", DBPATH"exp_guild.txt", ',', 1, 1, 100, exp_guild_parse_row); + sv->readdb("db", DBPATH"exp_guild.txt", ',', 1, 1, 100, exp_guild_parse_row); add_timer_func_list(guild_save_timer, "guild_save_timer"); add_timer(gettick() + 10000, guild_save_timer, 0, 0); @@ -760,26 +760,26 @@ int search_guildname(char *str) int guild_id; char esc_name[NAME_LENGTH*2+1]; - Sql_EscapeStringLen(sql_handle, esc_name, str, safestrnlen(str, NAME_LENGTH)); + SQL->EscapeStringLen(sql_handle, esc_name, str, safestrnlen(str, NAME_LENGTH)); //Lookup guilds with the same name - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT guild_id FROM `%s` WHERE name='%s'", guild_db, esc_name) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT guild_id FROM `%s` WHERE name='%s'", guild_db, esc_name) ) { Sql_ShowDebug(sql_handle); return -1; } - if( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { char* data; - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); guild_id = atoi(data); } else { guild_id = 0; } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return guild_id; } @@ -1268,7 +1268,7 @@ int mapif_parse_GuildLeave(int fd, int guild_id, int account_id, int char_id, in if( g == NULL ) { // Unknown guild, just update the player - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `guild_id`='0' WHERE `account_id`='%d' AND `char_id`='%d'", char_db, account_id, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `guild_id`='0' WHERE `account_id`='%d' AND `char_id`='%d'", char_db, account_id, char_id) ) Sql_ShowDebug(sql_handle); // mapif_guild_withdraw(guild_id,account_id,char_id,flag,g->member[i].name,mes); return 0; @@ -1381,32 +1381,32 @@ int mapif_parse_BreakGuild(int fd,int guild_id) // Delete guild from sql //printf("- Delete guild %d from guild\n",guild_id); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_db, guild_id) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_member_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_member_db, guild_id) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_castle_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_castle_db, guild_id) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_storage_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_storage_db, guild_id) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d' OR `alliance_id` = '%d'", guild_alliance_db, guild_id, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d' OR `alliance_id` = '%d'", guild_alliance_db, guild_id, guild_id) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_position_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_position_db, guild_id) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_skill_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_skill_db, guild_id) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_expulsion_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", guild_expulsion_db, guild_id) ) Sql_ShowDebug(sql_handle); //printf("- Update guild %d of char\n",guild_id); - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `guild_id`='0' WHERE `guild_id`='%d'", char_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `guild_id`='0' WHERE `guild_id`='%d'", char_db, guild_id) ) Sql_ShowDebug(sql_handle); mapif_guild_broken(guild_id,0); diff --git a/src/char/int_homun.c b/src/char/int_homun.c index 933661954..f06ace0b2 100644 --- a/src/char/int_homun.c +++ b/src/char/int_homun.c @@ -1,5 +1,6 @@ -// 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 #include "../common/mmo.h" #include "../common/malloc.h" @@ -88,11 +89,11 @@ bool mapif_homunculus_save(struct s_homunculus* hd) bool flag = true; char esc_name[NAME_LENGTH*2+1]; - Sql_EscapeStringLen(sql_handle, esc_name, hd->name, strnlen(hd->name, NAME_LENGTH)); + SQL->EscapeStringLen(sql_handle, esc_name, hd->name, strnlen(hd->name, NAME_LENGTH)); if( hd->hom_id == 0 ) {// new homunculus - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` " + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` " "(`char_id`, `class`,`prev_class`,`name`,`level`,`exp`,`intimacy`,`hunger`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`, `rename_flag`, `vaporize`) " "VALUES ('%d', '%d', '%d', '%s', '%d', '%u', '%u', '%d', '%d', %d, '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", homunculus_db, hd->char_id, hd->class_, hd->prev_class, esc_name, hd->level, hd->exp, hd->intimacy, hd->hunger, hd->str, hd->agi, hd->vit, hd->int_, hd->dex, hd->luk, @@ -103,12 +104,12 @@ bool mapif_homunculus_save(struct s_homunculus* hd) } else { - hd->hom_id = (int)Sql_LastInsertId(sql_handle); + hd->hom_id = (int)SQL->NumRows(sql_handle); } } else { - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `char_id`='%d', `class`='%d',`prev_class`='%d',`name`='%s',`level`='%d',`exp`='%u',`intimacy`='%u',`hunger`='%d', `str`='%d', `agi`='%d', `vit`='%d', `int`='%d', `dex`='%d', `luk`='%d', `hp`='%d',`max_hp`='%d',`sp`='%d',`max_sp`='%d',`skill_point`='%d', `rename_flag`='%d', `vaporize`='%d' WHERE `homun_id`='%d'", + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `char_id`='%d', `class`='%d',`prev_class`='%d',`name`='%s',`level`='%d',`exp`='%u',`intimacy`='%u',`hunger`='%d', `str`='%d', `agi`='%d', `vit`='%d', `int`='%d', `dex`='%d', `luk`='%d', `hp`='%d',`max_hp`='%d',`sp`='%d',`max_sp`='%d',`skill_point`='%d', `rename_flag`='%d', `vaporize`='%d' WHERE `homun_id`='%d'", homunculus_db, hd->char_id, hd->class_, hd->prev_class, esc_name, hd->level, hd->exp, hd->intimacy, hd->hunger, hd->str, hd->agi, hd->vit, hd->int_, hd->dex, hd->luk, hd->hp, hd->max_hp, hd->sp, hd->max_sp, hd->skillpts, hd->rename_flag, hd->vaporize, hd->hom_id) ) { @@ -156,61 +157,61 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd) memset(hd, 0, sizeof(*hd)); - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `homun_id`,`char_id`,`class`,`prev_class`,`name`,`level`,`exp`,`intimacy`,`hunger`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`,`rename_flag`, `vaporize` FROM `%s` WHERE `homun_id`='%u'", homunculus_db, homun_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `homun_id`,`char_id`,`class`,`prev_class`,`name`,`level`,`exp`,`intimacy`,`hunger`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`,`rename_flag`, `vaporize` FROM `%s` WHERE `homun_id`='%u'", homunculus_db, homun_id) ) { Sql_ShowDebug(sql_handle); return false; } - if( !Sql_NumRows(sql_handle) ) + if( !SQL->NumRows(sql_handle) ) { //No homunculus found. - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return false; } - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) { Sql_ShowDebug(sql_handle); - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return false; } hd->hom_id = homun_id; - Sql_GetData(sql_handle, 1, &data, NULL); hd->char_id = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); hd->class_ = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); hd->prev_class = atoi(data); - Sql_GetData(sql_handle, 4, &data, &len); safestrncpy(hd->name, data, sizeof(hd->name)); - Sql_GetData(sql_handle, 5, &data, NULL); hd->level = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); hd->exp = atoi(data); - Sql_GetData(sql_handle, 7, &data, NULL); hd->intimacy = (unsigned int)strtoul(data, NULL, 10); - Sql_GetData(sql_handle, 8, &data, NULL); hd->hunger = atoi(data); - Sql_GetData(sql_handle, 9, &data, NULL); hd->str = atoi(data); - Sql_GetData(sql_handle, 10, &data, NULL); hd->agi = atoi(data); - Sql_GetData(sql_handle, 11, &data, NULL); hd->vit = atoi(data); - Sql_GetData(sql_handle, 12, &data, NULL); hd->int_ = atoi(data); - Sql_GetData(sql_handle, 13, &data, NULL); hd->dex = atoi(data); - Sql_GetData(sql_handle, 14, &data, NULL); hd->luk = atoi(data); - Sql_GetData(sql_handle, 15, &data, NULL); hd->hp = atoi(data); - Sql_GetData(sql_handle, 16, &data, NULL); hd->max_hp = atoi(data); - Sql_GetData(sql_handle, 17, &data, NULL); hd->sp = atoi(data); - Sql_GetData(sql_handle, 18, &data, NULL); hd->max_sp = atoi(data); - Sql_GetData(sql_handle, 19, &data, NULL); hd->skillpts = atoi(data); - Sql_GetData(sql_handle, 20, &data, NULL); hd->rename_flag = atoi(data); - Sql_GetData(sql_handle, 21, &data, NULL); hd->vaporize = atoi(data); - Sql_FreeResult(sql_handle); + SQL->GetData(sql_handle, 1, &data, NULL); hd->char_id = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); hd->class_ = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); hd->prev_class = atoi(data); + SQL->GetData(sql_handle, 4, &data, &len); safestrncpy(hd->name, data, sizeof(hd->name)); + SQL->GetData(sql_handle, 5, &data, NULL); hd->level = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); hd->exp = atoi(data); + SQL->GetData(sql_handle, 7, &data, NULL); hd->intimacy = (unsigned int)strtoul(data, NULL, 10); + SQL->GetData(sql_handle, 8, &data, NULL); hd->hunger = atoi(data); + SQL->GetData(sql_handle, 9, &data, NULL); hd->str = atoi(data); + SQL->GetData(sql_handle, 10, &data, NULL); hd->agi = atoi(data); + SQL->GetData(sql_handle, 11, &data, NULL); hd->vit = atoi(data); + SQL->GetData(sql_handle, 12, &data, NULL); hd->int_ = atoi(data); + SQL->GetData(sql_handle, 13, &data, NULL); hd->dex = atoi(data); + SQL->GetData(sql_handle, 14, &data, NULL); hd->luk = atoi(data); + SQL->GetData(sql_handle, 15, &data, NULL); hd->hp = atoi(data); + SQL->GetData(sql_handle, 16, &data, NULL); hd->max_hp = atoi(data); + SQL->GetData(sql_handle, 17, &data, NULL); hd->sp = atoi(data); + SQL->GetData(sql_handle, 18, &data, NULL); hd->max_sp = atoi(data); + SQL->GetData(sql_handle, 19, &data, NULL); hd->skillpts = atoi(data); + SQL->GetData(sql_handle, 20, &data, NULL); hd->rename_flag = atoi(data); + SQL->GetData(sql_handle, 21, &data, NULL); hd->vaporize = atoi(data); + SQL->FreeResult(sql_handle); hd->intimacy = cap_value(hd->intimacy, 0, 100000); hd->hunger = cap_value(hd->hunger, 0, 100); // Load Homunculus Skill - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `id`,`lv` FROM `%s` WHERE `homun_id`=%d", skill_homunculus_db, homun_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `id`,`lv` FROM `%s` WHERE `homun_id`=%d", skill_homunculus_db, homun_id) ) { Sql_ShowDebug(sql_handle); return false; } - while( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + while( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { // id - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); i = atoi(data); if( i < HM_SKILLBASE || i >= HM_SKILLBASE + MAX_HOMUNSKILL ) continue;// invalid skill id @@ -218,10 +219,10 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd) hd->hskill[i].id = (unsigned short)atoi(data); // lv - Sql_GetData(sql_handle, 1, &data, NULL); + SQL->GetData(sql_handle, 1, &data, NULL); hd->hskill[i].lv = (unsigned char)atoi(data); } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); if( save_log ) ShowInfo("Homunculus loaded (%d - %s).\n", hd->hom_id, hd->name); @@ -231,8 +232,8 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd) bool mapif_homunculus_delete(int homun_id) { - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `homun_id` = '%u'", homunculus_db, homun_id) - || SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `homun_id` = '%u'", skill_homunculus_db, homun_id) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `homun_id` = '%u'", homunculus_db, homun_id) + || SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `homun_id` = '%u'", skill_homunculus_db, homun_id) ) { Sql_ShowDebug(sql_handle); return false; diff --git a/src/char/int_mail.c b/src/char/int_mail.c index 8d50c713f..9181b7db6 100644 --- a/src/char/int_mail.c +++ b/src/char/int_mail.c @@ -1,5 +1,6 @@ -// 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 #include "../common/mmo.h" #include "../common/malloc.h" @@ -27,54 +28,54 @@ static int mail_fromsql(int char_id, struct mail_data* md) md->amount = 0; md->full = false; - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, "SELECT `id`,`send_name`,`send_id`,`dest_name`,`dest_id`,`title`,`message`,`time`,`status`," + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, "SELECT `id`,`send_name`,`send_id`,`dest_name`,`dest_id`,`title`,`message`,`time`,`status`," "`zeny`,`amount`,`nameid`,`refine`,`attribute`,`identify`,`unique_id`"); for (i = 0; i < MAX_SLOTS; i++) - StringBuf_Printf(&buf, ",`card%d`", i); + StrBuf->Printf(&buf, ",`card%d`", i); // I keep the `status` < 3 just in case someone forget to apply the sqlfix - StringBuf_Printf(&buf, " FROM `%s` WHERE `dest_id`='%d' AND `status` < 3 ORDER BY `id` LIMIT %d", + StrBuf->Printf(&buf, " FROM `%s` WHERE `dest_id`='%d' AND `status` < 3 ORDER BY `id` LIMIT %d", mail_db, char_id, MAIL_MAX_INBOX + 1); - if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) ) + if( SQL_ERROR == SQL->Query(sql_handle, StrBuf->Value(&buf)) ) Sql_ShowDebug(sql_handle); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); - for (i = 0; i < MAIL_MAX_INBOX && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for (i = 0; i < MAIL_MAX_INBOX && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) { msg = &md->msg[i]; - Sql_GetData(sql_handle, 0, &data, NULL); msg->id = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(msg->send_name, data, NAME_LENGTH); - Sql_GetData(sql_handle, 2, &data, NULL); msg->send_id = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); safestrncpy(msg->dest_name, data, NAME_LENGTH); - Sql_GetData(sql_handle, 4, &data, NULL); msg->dest_id = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); safestrncpy(msg->title, data, MAIL_TITLE_LENGTH); - Sql_GetData(sql_handle, 6, &data, NULL); safestrncpy(msg->body, data, MAIL_BODY_LENGTH); - Sql_GetData(sql_handle, 7, &data, NULL); msg->timestamp = atoi(data); - Sql_GetData(sql_handle, 8, &data, NULL); msg->status = (mail_status)atoi(data); - Sql_GetData(sql_handle, 9, &data, NULL); msg->zeny = atoi(data); + SQL->GetData(sql_handle, 0, &data, NULL); msg->id = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(msg->send_name, data, NAME_LENGTH); + SQL->GetData(sql_handle, 2, &data, NULL); msg->send_id = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); safestrncpy(msg->dest_name, data, NAME_LENGTH); + SQL->GetData(sql_handle, 4, &data, NULL); msg->dest_id = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); safestrncpy(msg->title, data, MAIL_TITLE_LENGTH); + SQL->GetData(sql_handle, 6, &data, NULL); safestrncpy(msg->body, data, MAIL_BODY_LENGTH); + SQL->GetData(sql_handle, 7, &data, NULL); msg->timestamp = atoi(data); + SQL->GetData(sql_handle, 8, &data, NULL); msg->status = (mail_status)atoi(data); + SQL->GetData(sql_handle, 9, &data, NULL); msg->zeny = atoi(data); item = &msg->item; - Sql_GetData(sql_handle,10, &data, NULL); item->amount = (short)atoi(data); - Sql_GetData(sql_handle,11, &data, NULL); item->nameid = atoi(data); - Sql_GetData(sql_handle,12, &data, NULL); item->refine = atoi(data); - Sql_GetData(sql_handle,13, &data, NULL); item->attribute = atoi(data); - Sql_GetData(sql_handle,14, &data, NULL); item->identify = atoi(data); - Sql_GetData(sql_handle,15, &data, NULL); item->unique_id = strtoull(data, NULL, 10); + SQL->GetData(sql_handle,10, &data, NULL); item->amount = (short)atoi(data); + SQL->GetData(sql_handle,11, &data, NULL); item->nameid = atoi(data); + SQL->GetData(sql_handle,12, &data, NULL); item->refine = atoi(data); + SQL->GetData(sql_handle,13, &data, NULL); item->attribute = atoi(data); + SQL->GetData(sql_handle,14, &data, NULL); item->identify = atoi(data); + SQL->GetData(sql_handle,15, &data, NULL); item->unique_id = strtoull(data, NULL, 10); item->expire_time = 0; for (j = 0; j < MAX_SLOTS; j++) { - Sql_GetData(sql_handle, 16 + j, &data, NULL); + SQL->GetData(sql_handle, 16 + j, &data, NULL); item->card[j] = atoi(data); } } - md->full = ( Sql_NumRows(sql_handle) > MAIL_MAX_INBOX ); + md->full = ( SQL->NumRows(sql_handle) > MAIL_MAX_INBOX ); md->amount = i; - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); md->unchecked = 0; md->unread = 0; @@ -83,7 +84,7 @@ static int mail_fromsql(int char_id, struct mail_data* md) msg = &md->msg[i]; if( msg->status == MAIL_NEW ) { - if ( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `status` = '%d' WHERE `id` = '%d'", mail_db, MAIL_UNREAD, msg->id) ) + if ( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `status` = '%d' WHERE `id` = '%d'", mail_db, MAIL_UNREAD, msg->id) ) Sql_ShowDebug(sql_handle); msg->status = MAIL_UNREAD; @@ -106,15 +107,15 @@ int mail_savemessage(struct mail_message* msg) int j; // build message save query - StringBuf_Init(&buf); - StringBuf_Printf(&buf, "INSERT INTO `%s` (`send_name`, `send_id`, `dest_name`, `dest_id`, `title`, `message`, `time`, `status`, `zeny`, `amount`, `nameid`, `refine`, `attribute`, `identify`, `unique_id`", mail_db); + StrBuf->Init(&buf); + StrBuf->Printf(&buf, "INSERT INTO `%s` (`send_name`, `send_id`, `dest_name`, `dest_id`, `title`, `message`, `time`, `status`, `zeny`, `amount`, `nameid`, `refine`, `attribute`, `identify`, `unique_id`", mail_db); for (j = 0; j < MAX_SLOTS; j++) - StringBuf_Printf(&buf, ", `card%d`", j); - StringBuf_Printf(&buf, ") VALUES (?, '%d', ?, '%d', ?, ?, '%lu', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%"PRIu64"'", + StrBuf->Printf(&buf, ", `card%d`", j); + StrBuf->Printf(&buf, ") VALUES (?, '%d', ?, '%d', ?, ?, '%lu', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%"PRIu64"'", msg->send_id, msg->dest_id, (unsigned long)msg->timestamp, msg->status, msg->zeny, msg->item.amount, msg->item.nameid, msg->item.refine, msg->item.attribute, msg->item.identify, msg->item.unique_id); for (j = 0; j < MAX_SLOTS; j++) - StringBuf_Printf(&buf, ", '%d'", msg->item.card[j]); - StringBuf_AppendStr(&buf, ")"); + StrBuf->Printf(&buf, ", '%d'", msg->item.card[j]); + StrBuf->AppendStr(&buf, ")"); //Unique Non Stackable Item ID updateLastUid(msg->item.unique_id); @@ -122,7 +123,7 @@ int mail_savemessage(struct mail_message* msg) // prepare and execute query stmt = SqlStmt_Malloc(sql_handle); - if( SQL_SUCCESS != SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) + if( SQL_SUCCESS != SqlStmt_PrepareStr(stmt, StrBuf->Value(&buf)) || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, msg->send_name, strnlen(msg->send_name, NAME_LENGTH)) || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, msg->dest_name, strnlen(msg->dest_name, NAME_LENGTH)) || SQL_SUCCESS != SqlStmt_BindParam(stmt, 2, SQLDT_STRING, msg->title, strnlen(msg->title, MAIL_TITLE_LENGTH)) @@ -135,7 +136,7 @@ int mail_savemessage(struct mail_message* msg) msg->id = (int)SqlStmt_LastInsertId(stmt); SqlStmt_Free(stmt); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); return msg->id; } @@ -147,52 +148,52 @@ static bool mail_loadmessage(int mail_id, struct mail_message* msg) int j; StringBuf buf; - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, "SELECT `id`,`send_name`,`send_id`,`dest_name`,`dest_id`,`title`,`message`,`time`,`status`," + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, "SELECT `id`,`send_name`,`send_id`,`dest_name`,`dest_id`,`title`,`message`,`time`,`status`," "`zeny`,`amount`,`nameid`,`refine`,`attribute`,`identify`,`unique_id`"); for( j = 0; j < MAX_SLOTS; j++ ) - StringBuf_Printf(&buf, ",`card%d`", j); - StringBuf_Printf(&buf, " FROM `%s` WHERE `id` = '%d'", mail_db, mail_id); + StrBuf->Printf(&buf, ",`card%d`", j); + StrBuf->Printf(&buf, " FROM `%s` WHERE `id` = '%d'", mail_db, mail_id); - if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) - || SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_ERROR == SQL->Query(sql_handle, StrBuf->Value(&buf)) + || SQL_SUCCESS != SQL->NextRow(sql_handle) ) { Sql_ShowDebug(sql_handle); - Sql_FreeResult(sql_handle); - StringBuf_Destroy(&buf); + SQL->FreeResult(sql_handle); + StrBuf->Destroy(&buf); return false; } else { char* data; - Sql_GetData(sql_handle, 0, &data, NULL); msg->id = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(msg->send_name, data, NAME_LENGTH); - Sql_GetData(sql_handle, 2, &data, NULL); msg->send_id = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); safestrncpy(msg->dest_name, data, NAME_LENGTH); - Sql_GetData(sql_handle, 4, &data, NULL); msg->dest_id = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); safestrncpy(msg->title, data, MAIL_TITLE_LENGTH); - Sql_GetData(sql_handle, 6, &data, NULL); safestrncpy(msg->body, data, MAIL_BODY_LENGTH); - Sql_GetData(sql_handle, 7, &data, NULL); msg->timestamp = atoi(data); - Sql_GetData(sql_handle, 8, &data, NULL); msg->status = (mail_status)atoi(data); - Sql_GetData(sql_handle, 9, &data, NULL); msg->zeny = atoi(data); - Sql_GetData(sql_handle,10, &data, NULL); msg->item.amount = (short)atoi(data); - Sql_GetData(sql_handle,11, &data, NULL); msg->item.nameid = atoi(data); - Sql_GetData(sql_handle,12, &data, NULL); msg->item.refine = atoi(data); - Sql_GetData(sql_handle,13, &data, NULL); msg->item.attribute = atoi(data); - Sql_GetData(sql_handle,14, &data, NULL); msg->item.identify = atoi(data); - Sql_GetData(sql_handle,15, &data, NULL); msg->item.unique_id = strtoull(data, NULL, 10); + SQL->GetData(sql_handle, 0, &data, NULL); msg->id = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(msg->send_name, data, NAME_LENGTH); + SQL->GetData(sql_handle, 2, &data, NULL); msg->send_id = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); safestrncpy(msg->dest_name, data, NAME_LENGTH); + SQL->GetData(sql_handle, 4, &data, NULL); msg->dest_id = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); safestrncpy(msg->title, data, MAIL_TITLE_LENGTH); + SQL->GetData(sql_handle, 6, &data, NULL); safestrncpy(msg->body, data, MAIL_BODY_LENGTH); + SQL->GetData(sql_handle, 7, &data, NULL); msg->timestamp = atoi(data); + SQL->GetData(sql_handle, 8, &data, NULL); msg->status = (mail_status)atoi(data); + SQL->GetData(sql_handle, 9, &data, NULL); msg->zeny = atoi(data); + SQL->GetData(sql_handle,10, &data, NULL); msg->item.amount = (short)atoi(data); + SQL->GetData(sql_handle,11, &data, NULL); msg->item.nameid = atoi(data); + SQL->GetData(sql_handle,12, &data, NULL); msg->item.refine = atoi(data); + SQL->GetData(sql_handle,13, &data, NULL); msg->item.attribute = atoi(data); + SQL->GetData(sql_handle,14, &data, NULL); msg->item.identify = atoi(data); + SQL->GetData(sql_handle,15, &data, NULL); msg->item.unique_id = strtoull(data, NULL, 10); msg->item.expire_time = 0; for( j = 0; j < MAX_SLOTS; j++ ) { - Sql_GetData(sql_handle,16 + j, &data, NULL); + SQL->GetData(sql_handle,16 + j, &data, NULL); msg->item.card[j] = atoi(data); } } - StringBuf_Destroy(&buf); - Sql_FreeResult(sql_handle); + StrBuf->Destroy(&buf); + SQL->FreeResult(sql_handle); return true; } @@ -226,7 +227,7 @@ static void mapif_parse_Mail_requestinbox(int fd) static void mapif_parse_Mail_read(int fd) { int mail_id = RFIFOL(fd,2); - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `status` = '%d' WHERE `id` = '%d'", mail_db, MAIL_READ, mail_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `status` = '%d' WHERE `id` = '%d'", mail_db, MAIL_READ, mail_id) ) Sql_ShowDebug(sql_handle); } @@ -238,21 +239,21 @@ static bool mail_DeleteAttach(int mail_id) StringBuf buf; int i; - StringBuf_Init(&buf); - StringBuf_Printf(&buf, "UPDATE `%s` SET `zeny` = '0', `nameid` = '0', `amount` = '0', `refine` = '0', `attribute` = '0', `identify` = '0'", mail_db); + StrBuf->Init(&buf); + StrBuf->Printf(&buf, "UPDATE `%s` SET `zeny` = '0', `nameid` = '0', `amount` = '0', `refine` = '0', `attribute` = '0', `identify` = '0'", mail_db); for (i = 0; i < MAX_SLOTS; i++) - StringBuf_Printf(&buf, ", `card%d` = '0'", i); - StringBuf_Printf(&buf, " WHERE `id` = '%d'", mail_id); + StrBuf->Printf(&buf, ", `card%d` = '0'", i); + StrBuf->Printf(&buf, " WHERE `id` = '%d'", mail_id); - if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) ) + if( SQL_ERROR == SQL->Query(sql_handle, StrBuf->Value(&buf)) ) { Sql_ShowDebug(sql_handle); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); return false; } - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); return true; } @@ -295,7 +296,7 @@ static void mapif_parse_Mail_getattach(int fd) static void mapif_Mail_delete(int fd, int char_id, int mail_id) { bool failed = false; - if ( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '%d'", mail_db, mail_id) ) + if ( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '%d'", mail_db, mail_id) ) { Sql_ShowDebug(sql_handle); failed = true; @@ -344,7 +345,7 @@ static void mapif_Mail_return(int fd, int char_id, int mail_id) { if( msg.dest_id != char_id) return; - else if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '%d'", mail_db, mail_id) ) + else if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '%d'", mail_db, mail_id) ) Sql_ShowDebug(sql_handle); else { @@ -408,21 +409,21 @@ static void mapif_parse_Mail_send(int fd) memcpy(&msg, RFIFOP(fd,8), sizeof(struct mail_message)); // Try to find the Dest Char by Name - Sql_EscapeStringLen(sql_handle, esc_name, msg.dest_name, strnlen(msg.dest_name, NAME_LENGTH)); - if ( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`, `char_id` FROM `%s` WHERE `name` = '%s'", char_db, esc_name) ) + SQL->EscapeStringLen(sql_handle, esc_name, msg.dest_name, strnlen(msg.dest_name, NAME_LENGTH)); + if ( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id`, `char_id` FROM `%s` WHERE `name` = '%s'", char_db, esc_name) ) Sql_ShowDebug(sql_handle); else - if ( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + if ( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { char *data; - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); if (atoi(data) != account_id) { // Cannot send mail to char in the same account - Sql_GetData(sql_handle, 1, &data, NULL); + SQL->GetData(sql_handle, 1, &data, NULL); msg.dest_id = atoi(data); } } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); msg.status = MAIL_NEW; if( msg.dest_id > 0 ) diff --git a/src/char/int_mercenary.c b/src/char/int_mercenary.c index 3b3714416..11cc47062 100644 --- a/src/char/int_mercenary.c +++ b/src/char/int_mercenary.c @@ -1,5 +1,6 @@ -// 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 #include "../common/mmo.h" #include "../common/malloc.h" @@ -19,33 +20,33 @@ bool mercenary_owner_fromsql(int char_id, struct mmo_charstatus *status) { char* data; - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `merc_id`, `arch_calls`, `arch_faith`, `spear_calls`, `spear_faith`, `sword_calls`, `sword_faith` FROM `%s` WHERE `char_id` = '%d'", mercenary_owner_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `merc_id`, `arch_calls`, `arch_faith`, `spear_calls`, `spear_faith`, `sword_calls`, `sword_faith` FROM `%s` WHERE `char_id` = '%d'", mercenary_owner_db, char_id) ) { Sql_ShowDebug(sql_handle); return false; } - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) { - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return false; } - Sql_GetData(sql_handle, 0, &data, NULL); status->mer_id = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); status->arch_calls = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); status->arch_faith = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); status->spear_calls = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); status->spear_faith = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); status->sword_calls = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); status->sword_faith = atoi(data); - Sql_FreeResult(sql_handle); + SQL->GetData(sql_handle, 0, &data, NULL); status->mer_id = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); status->arch_calls = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); status->arch_faith = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); status->spear_calls = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); status->spear_faith = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); status->sword_calls = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); status->sword_faith = atoi(data); + SQL->FreeResult(sql_handle); return true; } bool mercenary_owner_tosql(int char_id, struct mmo_charstatus *status) { - if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`char_id`, `merc_id`, `arch_calls`, `arch_faith`, `spear_calls`, `spear_faith`, `sword_calls`, `sword_faith`) VALUES ('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", + if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`char_id`, `merc_id`, `arch_calls`, `arch_faith`, `spear_calls`, `spear_faith`, `sword_calls`, `sword_faith`) VALUES ('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", mercenary_owner_db, char_id, status->mer_id, status->arch_calls, status->arch_faith, status->spear_calls, status->spear_faith, status->sword_calls, status->sword_faith) ) { Sql_ShowDebug(sql_handle); @@ -57,10 +58,10 @@ bool mercenary_owner_tosql(int char_id, struct mmo_charstatus *status) bool mercenary_owner_delete(int char_id) { - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d'", mercenary_owner_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d'", mercenary_owner_db, char_id) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d'", mercenary_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d'", mercenary_db, char_id) ) Sql_ShowDebug(sql_handle); return true; @@ -72,7 +73,7 @@ bool mapif_mercenary_save(struct s_mercenary* merc) if( merc->mercenary_id == 0 ) { // Create new DB entry - if( SQL_ERROR == Sql_Query(sql_handle, + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` (`char_id`,`class`,`hp`,`sp`,`kill_counter`,`life_time`) VALUES ('%d','%d','%d','%d','%u','%u')", mercenary_db, merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time) ) { @@ -80,9 +81,9 @@ bool mapif_mercenary_save(struct s_mercenary* merc) flag = false; } else - merc->mercenary_id = (int)Sql_LastInsertId(sql_handle); + merc->mercenary_id = (int)SQL->NumRows(sql_handle); } - else if( SQL_ERROR == Sql_Query(sql_handle, + else if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `char_id` = '%d', `class` = '%d', `hp` = '%d', `sp` = '%d', `kill_counter` = '%u', `life_time` = '%u' WHERE `mer_id` = '%d'", mercenary_db, merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time, merc->mercenary_id) ) { // Update DB entry @@ -101,24 +102,24 @@ bool mapif_mercenary_load(int merc_id, int char_id, struct s_mercenary *merc) merc->mercenary_id = merc_id; merc->char_id = char_id; - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `class`, `hp`, `sp`, `kill_counter`, `life_time` FROM `%s` WHERE `mer_id` = '%d' AND `char_id` = '%d'", mercenary_db, merc_id, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `class`, `hp`, `sp`, `kill_counter`, `life_time` FROM `%s` WHERE `mer_id` = '%d' AND `char_id` = '%d'", mercenary_db, merc_id, char_id) ) { Sql_ShowDebug(sql_handle); return false; } - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) { - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return false; } - Sql_GetData(sql_handle, 0, &data, NULL); merc->class_ = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); merc->hp = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); merc->sp = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); merc->kill_count = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); merc->life_time = atoi(data); - Sql_FreeResult(sql_handle); + SQL->GetData(sql_handle, 0, &data, NULL); merc->class_ = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); merc->hp = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); merc->sp = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); merc->kill_count = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); merc->life_time = atoi(data); + SQL->FreeResult(sql_handle); if( save_log ) ShowInfo("Mercenary loaded (%d - %d).\n", merc->mercenary_id, merc->char_id); @@ -127,7 +128,7 @@ bool mapif_mercenary_load(int merc_id, int char_id, struct s_mercenary *merc) bool mapif_mercenary_delete(int merc_id) { - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `mer_id` = '%d'", mercenary_db, merc_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `mer_id` = '%d'", mercenary_db, merc_id) ) { Sql_ShowDebug(sql_handle); return false; diff --git a/src/char/int_party.c b/src/char/int_party.c index a88e5c586..7f99590ab 100644 --- a/src/char/int_party.c +++ b/src/char/int_party.c @@ -1,5 +1,6 @@ -// 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 #include "../common/cbasetypes.h" #include "../common/mmo.h" @@ -125,14 +126,14 @@ int inter_party_tosql(struct party *p, int flag, int index) #ifdef NOISY ShowInfo("Save party request ("CL_BOLD"%d"CL_RESET" - %s).\n", party_id, p->name); #endif - Sql_EscapeStringLen(sql_handle, esc_name, p->name, strnlen(p->name, NAME_LENGTH)); + SQL->EscapeStringLen(sql_handle, esc_name, p->name, strnlen(p->name, NAME_LENGTH)); if( flag & PS_BREAK ) {// Break the party // we'll skip name-checking and just reset everyone with the same party id [celest] - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d'", char_db, party_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d'", char_db, party_id) ) Sql_ShowDebug(sql_handle); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `party_id`='%d'", party_db, party_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `party_id`='%d'", party_db, party_id) ) Sql_ShowDebug(sql_handle); //Remove from memory idb_remove(party_db_, party_id); @@ -141,7 +142,7 @@ int inter_party_tosql(struct party *p, int flag, int index) if( flag & PS_CREATE ) {// Create party - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` " + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` " "(`name`, `exp`, `item`, `leader_id`, `leader_char`) " "VALUES ('%s', '%d', '%d', '%d', '%d')", party_db, esc_name, p->exp, p->item, p->member[index].account_id, p->member[index].char_id) ) @@ -149,33 +150,33 @@ int inter_party_tosql(struct party *p, int flag, int index) Sql_ShowDebug(sql_handle); return 0; } - party_id = p->party_id = (int)Sql_LastInsertId(sql_handle); + party_id = p->party_id = (int)SQL->NumRows(sql_handle); } if( flag & PS_BASIC ) {// Update party info. - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `name`='%s', `exp`='%d', `item`='%d' WHERE `party_id`='%d'", + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `name`='%s', `exp`='%d', `item`='%d' WHERE `party_id`='%d'", party_db, esc_name, p->exp, p->item, party_id) ) Sql_ShowDebug(sql_handle); } if( flag & PS_LEADER ) {// Update leader - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `leader_id`='%d', `leader_char`='%d' WHERE `party_id`='%d'", + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `leader_id`='%d', `leader_char`='%d' WHERE `party_id`='%d'", party_db, p->member[index].account_id, p->member[index].char_id, party_id) ) Sql_ShowDebug(sql_handle); } if( flag & PS_ADDMEMBER ) {// Add one party member. - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `party_id`='%d' WHERE `account_id`='%d' AND `char_id`='%d'", + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `party_id`='%d' WHERE `account_id`='%d' AND `char_id`='%d'", char_db, party_id, p->member[index].account_id, p->member[index].char_id) ) Sql_ShowDebug(sql_handle); } if( flag & PS_DELMEMBER ) {// Remove one party member. - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d' AND `account_id`='%d' AND `char_id`='%d'", + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d' AND `account_id`='%d' AND `char_id`='%d'", char_db, party_id, p->member[index].account_id, p->member[index].char_id) ) Sql_ShowDebug(sql_handle); } @@ -210,42 +211,42 @@ struct party_data *inter_party_fromsql(int party_id) p = party_pt; memset(p, 0, sizeof(struct party_data)); - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `party_id`, `name`,`exp`,`item`, `leader_id`, `leader_char` FROM `%s` WHERE `party_id`='%d'", party_db, party_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `party_id`, `name`,`exp`,`item`, `leader_id`, `leader_char` FROM `%s` WHERE `party_id`='%d'", party_db, party_id) ) { Sql_ShowDebug(sql_handle); return NULL; } - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) return NULL; p->party.party_id = party_id; - Sql_GetData(sql_handle, 1, &data, &len); memcpy(p->party.name, data, min(len, NAME_LENGTH)); - Sql_GetData(sql_handle, 2, &data, NULL); p->party.exp = (atoi(data) ? 1 : 0); - Sql_GetData(sql_handle, 3, &data, NULL); p->party.item = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); leader_id = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); leader_char = atoi(data); - Sql_FreeResult(sql_handle); + SQL->GetData(sql_handle, 1, &data, &len); memcpy(p->party.name, data, min(len, NAME_LENGTH)); + SQL->GetData(sql_handle, 2, &data, NULL); p->party.exp = (atoi(data) ? 1 : 0); + SQL->GetData(sql_handle, 3, &data, NULL); p->party.item = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); leader_id = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); leader_char = atoi(data); + SQL->FreeResult(sql_handle); // Load members - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`char_id`,`name`,`base_level`,`last_map`,`online`,`class` FROM `%s` WHERE `party_id`='%d'", char_db, party_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id`,`char_id`,`name`,`base_level`,`last_map`,`online`,`class` FROM `%s` WHERE `party_id`='%d'", char_db, party_id) ) { Sql_ShowDebug(sql_handle); return NULL; } - for( i = 0; i < MAX_PARTY && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for( i = 0; i < MAX_PARTY && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) { m = &p->party.member[i]; - Sql_GetData(sql_handle, 0, &data, NULL); m->account_id = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); m->char_id = atoi(data); - Sql_GetData(sql_handle, 2, &data, &len); memcpy(m->name, data, min(len, NAME_LENGTH)); - Sql_GetData(sql_handle, 3, &data, NULL); m->lv = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); m->map = mapindex_name2id(data); - Sql_GetData(sql_handle, 5, &data, NULL); m->online = (atoi(data) ? 1 : 0); - Sql_GetData(sql_handle, 6, &data, NULL); m->class_ = atoi(data); + SQL->GetData(sql_handle, 0, &data, NULL); m->account_id = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); m->char_id = atoi(data); + SQL->GetData(sql_handle, 2, &data, &len); memcpy(m->name, data, min(len, NAME_LENGTH)); + SQL->GetData(sql_handle, 3, &data, NULL); m->lv = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); m->map = mapindex_name2id(data); + SQL->GetData(sql_handle, 5, &data, NULL); m->online = (atoi(data) ? 1 : 0); + SQL->GetData(sql_handle, 6, &data, NULL); m->class_ = atoi(data); m->leader = (m->account_id == leader_id && m->char_id == leader_char ? 1 : 0); } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); if( save_log ) ShowInfo("Party loaded (%d - %s).\n", party_id, p->party.name); @@ -270,7 +271,7 @@ int inter_party_sql_init(void) /* Uncomment the following if you want to do a party_db cleanup (remove parties with no members) on startup.[Skotlex] ShowStatus("cleaning party table...\n"); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` USING `%s` LEFT JOIN `%s` ON `%s`.leader_id =`%s`.account_id AND `%s`.leader_char = `%s`.char_id WHERE `%s`.account_id IS NULL", + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` USING `%s` LEFT JOIN `%s` ON `%s`.leader_id =`%s`.account_id AND `%s`.leader_char = `%s`.char_id WHERE `%s`.account_id IS NULL", party_db, party_db, char_db, party_db, char_db, party_db, char_db, char_db) ) Sql_ShowDebug(sql_handle); */ @@ -291,15 +292,15 @@ struct party_data* search_partyname(char* str) char* data; struct party_data* p = NULL; - Sql_EscapeStringLen(sql_handle, esc_name, str, safestrnlen(str, NAME_LENGTH)); - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `party_id` FROM `%s` WHERE `name`='%s'", party_db, esc_name) ) + SQL->EscapeStringLen(sql_handle, esc_name, str, safestrnlen(str, NAME_LENGTH)); + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `party_id` FROM `%s` WHERE `name`='%s'", party_db, esc_name) ) Sql_ShowDebug(sql_handle); - else if( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + else if( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); p = inter_party_fromsql(atoi(data)); } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return p; } @@ -592,7 +593,7 @@ int mapif_parse_PartyLeave(int fd, int party_id, int account_id, int char_id) p = inter_party_fromsql(party_id); if( p == NULL ) {// Party does not exists? - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d'", char_db, party_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d'", char_db, party_id) ) Sql_ShowDebug(sql_handle); return 0; } @@ -777,18 +778,18 @@ int inter_party_CharOnline(int char_id, int party_id) {// Get party_id from the database char* data; - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT party_id FROM `%s` WHERE char_id='%d'", char_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT party_id FROM `%s` WHERE char_id='%d'", char_db, char_id) ) { Sql_ShowDebug(sql_handle); return 0; } - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) return 0; //Eh? No party? - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); party_id = atoi(data); - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); } if (party_id == 0) return 0; //No party... @@ -823,18 +824,18 @@ int inter_party_CharOffline(int char_id, int party_id) { {// Get guild_id from the database char* data; - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT party_id FROM `%s` WHERE char_id='%d'", char_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT party_id FROM `%s` WHERE char_id='%d'", char_db, char_id) ) { Sql_ShowDebug(sql_handle); return 0; } - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) return 0; //Eh? No party? - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); party_id = atoi(data); - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); } if (party_id == 0) return 0; //No party... diff --git a/src/char/int_pet.c b/src/char/int_pet.c index 311ccd4be..8d523a133 100644 --- a/src/char/int_pet.c +++ b/src/char/int_pet.c @@ -24,13 +24,13 @@ int inter_pet_tosql(int pet_id, struct s_pet* p) //`pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate`) char esc_name[NAME_LENGTH*2+1];// escaped pet name - Sql_EscapeStringLen(sql_handle, esc_name, p->name, strnlen(p->name, NAME_LENGTH)); + SQL->EscapeStringLen(sql_handle, esc_name, p->name, strnlen(p->name, NAME_LENGTH)); p->hungry = cap_value(p->hungry, 0, 100); p->intimate = cap_value(p->intimate, 0, 1000); if( pet_id == -1 ) {// New pet. - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` " + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` " "(`class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate`) " "VALUES ('%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", pet_db, p->class_, esc_name, p->account_id, p->char_id, p->level, p->egg_id, @@ -39,11 +39,11 @@ int inter_pet_tosql(int pet_id, struct s_pet* p) Sql_ShowDebug(sql_handle); return 0; } - p->pet_id = (int)Sql_LastInsertId(sql_handle); + p->pet_id = (int)SQL->NumRows(sql_handle); } else {// Update pet. - if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `class`='%d',`name`='%s',`account_id`='%d',`char_id`='%d',`level`='%d',`egg_id`='%d',`equip`='%d',`intimate`='%d',`hungry`='%d',`rename_flag`='%d',`incuvate`='%d' WHERE `pet_id`='%d'", + if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `class`='%d',`name`='%s',`account_id`='%d',`char_id`='%d',`level`='%d',`egg_id`='%d',`equip`='%d',`intimate`='%d',`hungry`='%d',`rename_flag`='%d',`incuvate`='%d' WHERE `pet_id`='%d'", pet_db, p->class_, esc_name, p->account_id, p->char_id, p->level, p->egg_id, p->equip, p->intimate, p->hungry, p->rename_flag, p->incuvate, p->pet_id) ) { @@ -69,28 +69,28 @@ int inter_pet_fromsql(int pet_id, struct s_pet* p) //`pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate`) - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate` FROM `%s` WHERE `pet_id`='%d'", pet_db, pet_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate` FROM `%s` WHERE `pet_id`='%d'", pet_db, pet_id) ) { Sql_ShowDebug(sql_handle); return 0; } - if( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { p->pet_id = pet_id; - Sql_GetData(sql_handle, 1, &data, NULL); p->class_ = atoi(data); - Sql_GetData(sql_handle, 2, &data, &len); memcpy(p->name, data, min(len, NAME_LENGTH)); - Sql_GetData(sql_handle, 3, &data, NULL); p->account_id = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); p->char_id = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); p->level = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); p->egg_id = atoi(data); - Sql_GetData(sql_handle, 7, &data, NULL); p->equip = atoi(data); - Sql_GetData(sql_handle, 8, &data, NULL); p->intimate = atoi(data); - Sql_GetData(sql_handle, 9, &data, NULL); p->hungry = atoi(data); - Sql_GetData(sql_handle, 10, &data, NULL); p->rename_flag = atoi(data); - Sql_GetData(sql_handle, 11, &data, NULL); p->incuvate = atoi(data); - - Sql_FreeResult(sql_handle); + SQL->GetData(sql_handle, 1, &data, NULL); p->class_ = atoi(data); + SQL->GetData(sql_handle, 2, &data, &len); memcpy(p->name, data, min(len, NAME_LENGTH)); + SQL->GetData(sql_handle, 3, &data, NULL); p->account_id = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); p->char_id = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); p->level = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); p->egg_id = atoi(data); + SQL->GetData(sql_handle, 7, &data, NULL); p->equip = atoi(data); + SQL->GetData(sql_handle, 8, &data, NULL); p->intimate = atoi(data); + SQL->GetData(sql_handle, 9, &data, NULL); p->hungry = atoi(data); + SQL->GetData(sql_handle, 10, &data, NULL); p->rename_flag = atoi(data); + SQL->GetData(sql_handle, 11, &data, NULL); p->incuvate = atoi(data); + + SQL->FreeResult(sql_handle); p->hungry = cap_value(p->hungry, 0, 100); p->intimate = cap_value(p->intimate, 0, 1000); @@ -115,7 +115,7 @@ void inter_pet_sql_final(void){ int inter_pet_delete(int pet_id){ ShowInfo("delete pet request: %d...\n",pet_id); - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `pet_id`='%d'", pet_db, pet_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `pet_id`='%d'", pet_db, pet_id) ) Sql_ShowDebug(sql_handle); return 0; } diff --git a/src/char/int_quest.c b/src/char/int_quest.c index 224205412..d771543cc 100644 --- a/src/char/int_quest.c +++ b/src/char/int_quest.c @@ -1,5 +1,6 @@ -// 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 #include "../common/mmo.h" #include "../common/db.h" @@ -55,7 +56,7 @@ int mapif_quests_fromsql(int char_id, struct quest questlog[]) //Delete a quest bool mapif_quest_delete(int char_id, int quest_id) { - if ( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `quest_id` = '%d' AND `char_id` = '%d'", quest_db, quest_id, char_id) ) + if ( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `quest_id` = '%d' AND `char_id` = '%d'", quest_db, quest_id, char_id) ) { Sql_ShowDebug(sql_handle); return false; @@ -67,7 +68,7 @@ bool mapif_quest_delete(int char_id, int quest_id) //Add a quest to a questlog bool mapif_quest_add(int char_id, struct quest qd) { - if ( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s`(`quest_id`, `char_id`, `state`, `time`, `count1`, `count2`, `count3`) VALUES ('%d', '%d', '%d','%d', '%d', '%d', '%d')", quest_db, qd.quest_id, char_id, qd.state, qd.time, qd.count[0], qd.count[1], qd.count[2]) ) + if ( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s`(`quest_id`, `char_id`, `state`, `time`, `count1`, `count2`, `count3`) VALUES ('%d', '%d', '%d','%d', '%d', '%d', '%d')", quest_db, qd.quest_id, char_id, qd.state, qd.time, qd.count[0], qd.count[1], qd.count[2]) ) { Sql_ShowDebug(sql_handle); return false; @@ -79,7 +80,7 @@ bool mapif_quest_add(int char_id, struct quest qd) //Update a questlog bool mapif_quest_update(int char_id, struct quest qd) { - if ( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `state`='%d', `count1`='%d', `count2`='%d', `count3`='%d' WHERE `quest_id` = '%d' AND `char_id` = '%d'", quest_db, qd.state, qd.count[0], qd.count[1], qd.count[2], qd.quest_id, char_id) ) + if ( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `state`='%d', `count1`='%d', `count2`='%d', `count3`='%d' WHERE `quest_id` = '%d' AND `char_id` = '%d'", quest_db, qd.state, qd.count[0], qd.count[1], qd.count[2], qd.quest_id, char_id) ) { Sql_ShowDebug(sql_handle); return false; diff --git a/src/char/int_storage.c b/src/char/int_storage.c index 68b588087..429b80105 100644 --- a/src/char/int_storage.c +++ b/src/char/int_storage.c @@ -1,5 +1,6 @@ -// 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 #include "../common/mmo.h" #include "../common/malloc.h" @@ -37,36 +38,36 @@ int storage_fromsql(int account_id, struct storage_data* p) p->storage_amount = 0; // storage {`account_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`} - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`expire_time`,`unique_id`"); + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`expire_time`,`unique_id`"); for( j = 0; j < MAX_SLOTS; ++j ) - StringBuf_Printf(&buf, ",`card%d`", j); - StringBuf_Printf(&buf, " FROM `%s` WHERE `account_id`='%d' ORDER BY `nameid`", storage_db, account_id); + StrBuf->Printf(&buf, ",`card%d`", j); + StrBuf->Printf(&buf, " FROM `%s` WHERE `account_id`='%d' ORDER BY `nameid`", storage_db, account_id); - if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) ) + if( SQL_ERROR == SQL->Query(sql_handle, StrBuf->Value(&buf)) ) Sql_ShowDebug(sql_handle); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); - for( i = 0; i < MAX_STORAGE && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for( i = 0; i < MAX_STORAGE && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) { item = &p->items[i]; - Sql_GetData(sql_handle, 0, &data, NULL); item->id = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); item->nameid = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); item->amount = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); item->equip = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); item->identify = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); item->refine = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); item->attribute = atoi(data); - Sql_GetData(sql_handle, 7, &data, NULL); item->expire_time = (unsigned int)atoi(data); - Sql_GetData(sql_handle, 8, &data, NULL); item->unique_id = strtoull(data, NULL, 10); + SQL->GetData(sql_handle, 0, &data, NULL); item->id = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); item->nameid = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); item->amount = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); item->equip = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); item->identify = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); item->refine = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); item->attribute = atoi(data); + SQL->GetData(sql_handle, 7, &data, NULL); item->expire_time = (unsigned int)atoi(data); + SQL->GetData(sql_handle, 8, &data, NULL); item->unique_id = strtoull(data, NULL, 10); for( j = 0; j < MAX_SLOTS; ++j ) { - Sql_GetData(sql_handle, 9+j, &data, NULL); item->card[j] = atoi(data); + SQL->GetData(sql_handle, 9+j, &data, NULL); item->card[j] = atoi(data); } } p->storage_amount = i; - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); ShowInfo("storage load complete from DB - id: %d (total: %d)\n", account_id, p->storage_amount); return 1; @@ -94,36 +95,36 @@ int guild_storage_fromsql(int guild_id, struct guild_storage* p) p->guild_id = guild_id; // storage {`guild_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`} - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`unique_id`"); + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`unique_id`"); for( j = 0; j < MAX_SLOTS; ++j ) - StringBuf_Printf(&buf, ",`card%d`", j); - StringBuf_Printf(&buf, " FROM `%s` WHERE `guild_id`='%d' ORDER BY `nameid`", guild_storage_db, guild_id); + StrBuf->Printf(&buf, ",`card%d`", j); + StrBuf->Printf(&buf, " FROM `%s` WHERE `guild_id`='%d' ORDER BY `nameid`", guild_storage_db, guild_id); - if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) ) + if( SQL_ERROR == SQL->Query(sql_handle, StrBuf->Value(&buf)) ) Sql_ShowDebug(sql_handle); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); - for( i = 0; i < MAX_GUILD_STORAGE && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for( i = 0; i < MAX_GUILD_STORAGE && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) { item = &p->items[i]; - Sql_GetData(sql_handle, 0, &data, NULL); item->id = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); item->nameid = atoi(data); - Sql_GetData(sql_handle, 2, &data, NULL); item->amount = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); item->equip = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); item->identify = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); item->refine = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); item->attribute = atoi(data); - Sql_GetData(sql_handle, 7, &data, NULL); item->unique_id = strtoull(data, NULL, 10); + SQL->GetData(sql_handle, 0, &data, NULL); item->id = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); item->nameid = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); item->amount = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); item->equip = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); item->identify = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); item->refine = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); item->attribute = atoi(data); + SQL->GetData(sql_handle, 7, &data, NULL); item->unique_id = strtoull(data, NULL, 10); item->expire_time = 0; for( j = 0; j < MAX_SLOTS; ++j ) { - Sql_GetData(sql_handle, 8+j, &data, NULL); item->card[j] = atoi(data); + SQL->GetData(sql_handle, 8+j, &data, NULL); item->card[j] = atoi(data); } } p->storage_amount = i; - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); ShowInfo("guild storage load complete from DB - id: %d (total: %d)\n", guild_id, p->storage_amount); return 0; @@ -144,13 +145,13 @@ void inter_storage_sql_final(void) // q?f[^? int inter_storage_delete(int account_id) { - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id`='%d'", storage_db, account_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id`='%d'", storage_db, account_id) ) Sql_ShowDebug(sql_handle); return 0; } int inter_guild_storage_delete(int guild_id) { - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id`='%d'", guild_storage_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id`='%d'", guild_storage_db, guild_id) ) Sql_ShowDebug(sql_handle); return 0; } @@ -160,9 +161,9 @@ int inter_guild_storage_delete(int guild_id) int mapif_load_guild_storage(int fd,int account_id,int guild_id) { - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `guild_id` FROM `%s` WHERE `guild_id`='%d'", guild_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `guild_id` FROM `%s` WHERE `guild_id`='%d'", guild_db, guild_id) ) Sql_ShowDebug(sql_handle); - else if( Sql_NumRows(sql_handle) > 0 ) + else if( SQL->NumRows(sql_handle) > 0 ) {// guild exists WFIFOHEAD(fd, sizeof(struct guild_storage)+12); WFIFOW(fd,0) = 0x3818; @@ -174,7 +175,7 @@ int mapif_load_guild_storage(int fd,int account_id,int guild_id) return 0; } // guild does not exist - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); WFIFOHEAD(fd, 12); WFIFOW(fd,0) = 0x3818; WFIFOW(fd,2) = 12; @@ -219,16 +220,16 @@ int mapif_parse_SaveGuildStorage(int fd) } else { - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `guild_id` FROM `%s` WHERE `guild_id`='%d'", guild_db, guild_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `guild_id` FROM `%s` WHERE `guild_id`='%d'", guild_db, guild_id) ) Sql_ShowDebug(sql_handle); - else if( Sql_NumRows(sql_handle) > 0 ) + else if( SQL->NumRows(sql_handle) > 0 ) {// guild exists - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); guild_storage_tosql(guild_id, (struct guild_storage*)RFIFOP(fd,12)); mapif_save_guild_storage_ack(fd, RFIFOL(fd,4), guild_id, 0); return 0; } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); } mapif_save_guild_storage_ack(fd, RFIFOL(fd,4), guild_id, 1); return 0; diff --git a/src/char/inter.c b/src/char/inter.c index 7fd1e089a..83989271e 100644 --- a/src/char/inter.c +++ b/src/char/inter.c @@ -1,5 +1,6 @@ -// 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 #include "../common/mmo.h" #include "../common/db.h" @@ -445,43 +446,43 @@ void mapif_parse_accinfo(int fd) { safestrncpy(query, (char*) RFIFOP(fd,14), NAME_LENGTH); - Sql_EscapeString(sql_handle, query_esq, query); + SQL->EscapeString(sql_handle, query_esq, query); account_id = atoi(query); if (account_id < START_ACCOUNT_NUM) { // is string - if ( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`name`,`class`,`base_level`,`job_level`,`online` FROM `char` WHERE `name` LIKE '%s' LIMIT 10", query_esq) - || Sql_NumRows(sql_handle) == 0 ) { - if( Sql_NumRows(sql_handle) == 0 ) { + if ( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id`,`name`,`class`,`base_level`,`job_level`,`online` FROM `char` WHERE `name` LIKE '%s' LIMIT 10", query_esq) + || SQL->NumRows(sql_handle) == 0 ) { + if( SQL->NumRows(sql_handle) == 0 ) { inter_to_fd(fd, u_fd, aid, "No matches were found for your criteria, '%s'",query); } else { Sql_ShowDebug(sql_handle); inter_to_fd(fd, u_fd, aid, "An error occured, bother your admin about it."); } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return; } else { - if( Sql_NumRows(sql_handle) == 1 ) {//we found a perfect match - Sql_NextRow(sql_handle); - Sql_GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); - Sql_FreeResult(sql_handle); + if( SQL->NumRows(sql_handle) == 1 ) {//we found a perfect match + SQL->NextRow(sql_handle); + SQL->GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); + SQL->FreeResult(sql_handle); } else {// more than one, listing... [Dekamaster/Nightroad] - inter_to_fd(fd, u_fd, aid, "Your query returned the following %d results, please be more specific...",(int)Sql_NumRows(sql_handle)); - while ( SQL_SUCCESS == Sql_NextRow(sql_handle) ) { + inter_to_fd(fd, u_fd, aid, "Your query returned the following %d results, please be more specific...",(int)SQL->NumRows(sql_handle)); + while ( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { int class_; short base_level, job_level, online; char name[NAME_LENGTH]; - Sql_GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name)); - Sql_GetData(sql_handle, 2, &data, NULL); class_ = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); base_level = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); job_level = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); online = atoi(data); + SQL->GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name)); + SQL->GetData(sql_handle, 2, &data, NULL); class_ = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); base_level = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); job_level = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); online = atoi(data); inter_to_fd(fd, u_fd, aid, "[AID: %d] %s | %s | Level: %d/%d | %s", account_id, name, job_name(class_), base_level, job_level, online?"Online":"Offline"); } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return; } } @@ -492,29 +493,29 @@ void mapif_parse_accinfo(int fd) { char userid[NAME_LENGTH], user_pass[NAME_LENGTH], email[40], last_ip[20], lastlogin[30], pincode[5], birthdate[11]; short level = -1; int logincount = 0,state = 0; - if ( SQL_ERROR == Sql_Query(sql_handle, "SELECT `userid`, `user_pass`, `email`, `last_ip`, `group_id`, `lastlogin`, `logincount`, `state`,`pincode`,`birthdate` FROM `login` WHERE `account_id` = '%d' LIMIT 1", account_id) - || Sql_NumRows(sql_handle) == 0 ) { - if( Sql_NumRows(sql_handle) == 0 ) { + if ( SQL_ERROR == SQL->Query(sql_handle, "SELECT `userid`, `user_pass`, `email`, `last_ip`, `group_id`, `lastlogin`, `logincount`, `state`,`pincode`,`birthdate` FROM `login` WHERE `account_id` = '%d' LIMIT 1", account_id) + || SQL->NumRows(sql_handle) == 0 ) { + if( SQL->NumRows(sql_handle) == 0 ) { inter_to_fd(fd, u_fd, aid, "No account with ID '%d' was found.", account_id ); } else { inter_to_fd(fd, u_fd, aid, "An error occured, bother your admin about it."); Sql_ShowDebug(sql_handle); } } else { - Sql_NextRow(sql_handle); - Sql_GetData(sql_handle, 0, &data, NULL); safestrncpy(userid, data, sizeof(userid)); - Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(user_pass, data, sizeof(user_pass)); - Sql_GetData(sql_handle, 2, &data, NULL); safestrncpy(email, data, sizeof(email)); - Sql_GetData(sql_handle, 3, &data, NULL); safestrncpy(last_ip, data, sizeof(last_ip)); - Sql_GetData(sql_handle, 4, &data, NULL); level = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); safestrncpy(lastlogin, data, sizeof(lastlogin)); - Sql_GetData(sql_handle, 6, &data, NULL); logincount = atoi(data); - Sql_GetData(sql_handle, 7, &data, NULL); state = atoi(data); - Sql_GetData(sql_handle, 8, &data, NULL); safestrncpy(pincode, data, sizeof(pincode)); - Sql_GetData(sql_handle, 9, &data, NULL); safestrncpy(birthdate, data, sizeof(birthdate)); + SQL->NextRow(sql_handle); + SQL->GetData(sql_handle, 0, &data, NULL); safestrncpy(userid, data, sizeof(userid)); + SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(user_pass, data, sizeof(user_pass)); + SQL->GetData(sql_handle, 2, &data, NULL); safestrncpy(email, data, sizeof(email)); + SQL->GetData(sql_handle, 3, &data, NULL); safestrncpy(last_ip, data, sizeof(last_ip)); + SQL->GetData(sql_handle, 4, &data, NULL); level = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); safestrncpy(lastlogin, data, sizeof(lastlogin)); + SQL->GetData(sql_handle, 6, &data, NULL); logincount = atoi(data); + SQL->GetData(sql_handle, 7, &data, NULL); state = atoi(data); + SQL->GetData(sql_handle, 8, &data, NULL); safestrncpy(pincode, data, sizeof(pincode)); + SQL->GetData(sql_handle, 9, &data, NULL); safestrncpy(birthdate, data, sizeof(birthdate)); } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); if (level == -1) return; @@ -535,10 +536,10 @@ void mapif_parse_accinfo(int fd) { inter_to_fd(fd, u_fd, aid, "-- Character Details --" ); - if ( SQL_ERROR == Sql_Query(sql_handle, "SELECT `char_id`, `name`, `char_num`, `class`, `base_level`, `job_level`, `online` FROM `char` WHERE `account_id` = '%d' ORDER BY `char_num` LIMIT %d", account_id, MAX_CHARS) - || Sql_NumRows(sql_handle) == 0 ) { + if ( SQL_ERROR == SQL->Query(sql_handle, "SELECT `char_id`, `name`, `char_num`, `class`, `base_level`, `job_level`, `online` FROM `char` WHERE `account_id` = '%d' ORDER BY `char_num` LIMIT %d", account_id, MAX_CHARS) + || SQL->NumRows(sql_handle) == 0 ) { - if( Sql_NumRows(sql_handle) == 0 ) + if( SQL->NumRows(sql_handle) == 0 ) inter_to_fd(fd, u_fd, aid,"This account doesn't have characters."); else { inter_to_fd(fd, u_fd, aid,"An error occured, bother your admin about it."); @@ -546,23 +547,23 @@ void mapif_parse_accinfo(int fd) { } } else { - while ( SQL_SUCCESS == Sql_NextRow(sql_handle) ) { + while ( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { int char_id, class_; short char_num, base_level, job_level, online; char name[NAME_LENGTH]; - Sql_GetData(sql_handle, 0, &data, NULL); char_id = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name)); - Sql_GetData(sql_handle, 2, &data, NULL); char_num = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); class_ = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); base_level = atoi(data); - Sql_GetData(sql_handle, 5, &data, NULL); job_level = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); online = atoi(data); + SQL->GetData(sql_handle, 0, &data, NULL); char_id = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name)); + SQL->GetData(sql_handle, 2, &data, NULL); char_num = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); class_ = atoi(data); + SQL->GetData(sql_handle, 4, &data, NULL); base_level = atoi(data); + SQL->GetData(sql_handle, 5, &data, NULL); job_level = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); online = atoi(data); inter_to_fd(fd, u_fd, aid, "[Slot/CID: %d/%d] %s | %s | Level: %d/%d | %s", char_num, char_id, name, job_name(class_), base_level, job_level, online?"On":"Off"); } } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); } return; @@ -584,12 +585,12 @@ int inter_accreg_tosql(int account_id, int char_id, struct accreg* reg, int type switch( type ) { case 3: //Char Reg - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `type`=3 AND `char_id`='%d'", reg_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `type`=3 AND `char_id`='%d'", reg_db, char_id) ) Sql_ShowDebug(sql_handle); account_id = 0; break; case 2: //Account Reg - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `type`=2 AND `account_id`='%d'", reg_db, account_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `type`=2 AND `account_id`='%d'", reg_db, account_id) ) Sql_ShowDebug(sql_handle); char_id = 0; break; @@ -604,8 +605,8 @@ int inter_accreg_tosql(int account_id, int char_id, struct accreg* reg, int type if( reg->reg_num <= 0 ) return 0; - StringBuf_Init(&buf); - StringBuf_Printf(&buf, "INSERT INTO `%s` (`type`,`account_id`,`char_id`,`str`,`value`) VALUES ", reg_db); + StrBuf->Init(&buf); + StrBuf->Printf(&buf, "INSERT INTO `%s` (`type`,`account_id`,`char_id`,`str`,`value`) VALUES ", reg_db); for( i = 0; i < reg->reg_num; ++i ) { r = ®->reg[i]; @@ -614,20 +615,20 @@ int inter_accreg_tosql(int account_id, int char_id, struct accreg* reg, int type char val[256]; if( i > 0 ) - StringBuf_AppendStr(&buf, ","); + StrBuf->AppendStr(&buf, ","); - Sql_EscapeString(sql_handle, str, r->str); - Sql_EscapeString(sql_handle, val, r->value); + SQL->EscapeString(sql_handle, str, r->str); + SQL->EscapeString(sql_handle, val, r->value); - StringBuf_Printf(&buf, "('%d','%d','%d','%s','%s')", type, account_id, char_id, str, val); + StrBuf->Printf(&buf, "('%d','%d','%d','%s','%s')", type, account_id, char_id, str, val); } } - if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) { + if( SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) { Sql_ShowDebug(sql_handle); } - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); return 1; } @@ -651,11 +652,11 @@ int inter_accreg_fromsql(int account_id,int char_id, struct accreg *reg, int typ switch( type ) { case 3: //char reg - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `str`, `value` FROM `%s` WHERE `type`=3 AND `char_id`='%d'", reg_db, char_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `str`, `value` FROM `%s` WHERE `type`=3 AND `char_id`='%d'", reg_db, char_id) ) Sql_ShowDebug(sql_handle); break; case 2: //account reg - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `str`, `value` FROM `%s` WHERE `type`=2 AND `account_id`='%d'", reg_db, account_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `str`, `value` FROM `%s` WHERE `type`=2 AND `account_id`='%d'", reg_db, account_id) ) Sql_ShowDebug(sql_handle); break; case 1: //account2 reg @@ -665,18 +666,18 @@ int inter_accreg_fromsql(int account_id,int char_id, struct accreg *reg, int typ ShowError("inter_accreg_fromsql: Invalid type %d\n", type); return 0; } - for( i = 0; i < MAX_REG_NUM && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for( i = 0; i < MAX_REG_NUM && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) { r = ®->reg[i]; // str - Sql_GetData(sql_handle, 0, &data, &len); + SQL->GetData(sql_handle, 0, &data, &len); memcpy(r->str, data, min(len, sizeof(r->str))); // value - Sql_GetData(sql_handle, 1, &data, &len); + SQL->GetData(sql_handle, 1, &data, &len); memcpy(r->value, data, min(len, sizeof(r->value))); } reg->reg_num = i; - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return 1; } @@ -752,8 +753,8 @@ int inter_log(char* fmt, ...) vsnprintf(str, sizeof(str), fmt, ap); va_end(ap); - Sql_EscapeStringLen(sql_handle, esc_str, str, strnlen(str, sizeof(str))); - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` (`time`, `log`) VALUES (NOW(), '%s')", interlog_db, esc_str) ) + SQL->EscapeStringLen(sql_handle, esc_str, str, strnlen(str, sizeof(str))); + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` (`time`, `log`) VALUES (NOW(), '%s')", interlog_db, esc_str) ) Sql_ShowDebug(sql_handle); return 0; @@ -767,17 +768,17 @@ int inter_init_sql(const char *file) inter_config_read(file); //DB connection initialized - sql_handle = Sql_Malloc(); + sql_handle = SQL->Malloc(); ShowInfo("Connect Character DB server.... (Character Server)\n"); - if( SQL_ERROR == Sql_Connect(sql_handle, char_server_id, char_server_pw, char_server_ip, (uint16)char_server_port, char_server_db) ) + if( SQL_ERROR == SQL->Connect(sql_handle, char_server_id, char_server_pw, char_server_ip, (uint16)char_server_port, char_server_db) ) { Sql_ShowDebug(sql_handle); - Sql_Free(sql_handle); + SQL->Free(sql_handle); exit(EXIT_FAILURE); } if( *default_codepage ) { - if( SQL_ERROR == Sql_SetEncoding(sql_handle, default_codepage) ) + if( SQL_ERROR == SQL->SetEncoding(sql_handle, default_codepage) ) Sql_ShowDebug(sql_handle); } @@ -996,12 +997,12 @@ int mapif_parse_WisRequest(int fd) safestrncpy(name, (char*)RFIFOP(fd,28), NAME_LENGTH); //Received name may be too large and not contain \0! [Skotlex] - Sql_EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `name` FROM `%s` WHERE `name`='%s'", char_db, esc_name) ) + SQL->EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `name` FROM `%s` WHERE `name`='%s'", char_db, esc_name) ) Sql_ShowDebug(sql_handle); // search if character exists before to ask all map-servers - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) { unsigned char buf[27]; WBUFW(buf, 0) = 0x3802; @@ -1012,7 +1013,7 @@ int mapif_parse_WisRequest(int fd) else {// Character exists. So, ask all map-servers // to be sure of the correct name, rewrite it - Sql_GetData(sql_handle, 0, &data, &len); + SQL->GetData(sql_handle, 0, &data, &len); memset(name, 0, NAME_LENGTH); memcpy(name, data, min(len, NAME_LENGTH)); // if source is destination, don't ask other servers. @@ -1044,7 +1045,7 @@ int mapif_parse_WisRequest(int fd) } } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return 0; } diff --git a/src/char/inter.h b/src/char/inter.h index e34c54c16..de27b0473 100644 --- a/src/char/inter.h +++ b/src/char/inter.h @@ -1,5 +1,6 @@ -// 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 _INTER_SQL_H_ #define _INTER_SQL_H_ @@ -31,7 +32,7 @@ uint64 inter_chk_lastuid(int8 flag, uint64 value); #define dbUpdateUid(handler_)\ { \ uint64 unique_id_ = inter_chk_lastuid(0, 0); \ - if (unique_id_ && SQL_ERROR == Sql_Query(handler_, "UPDATE `interreg` SET `value`='%"PRIu64"' WHERE `varname`='unique_id'", unique_id_)) \ + if (unique_id_ && SQL_ERROR == SQL->Query(handler_, "UPDATE `interreg` SET `value`='%"PRIu64"' WHERE `varname`='unique_id'", unique_id_)) \ Sql_ShowDebug(handler_);\ } #else diff --git a/src/common/HPM.c b/src/common/HPM.c index 2df559c82..af06811a5 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -11,6 +11,8 @@ #include "../common/conf.h" #include "../common/utils.h" #include "../common/console.h" +#include "../common/strlib.h" +#include "../common/sql.h" #include "HPM.h" #include @@ -73,39 +75,34 @@ struct hplugin *hplugin_create(void) { HPM->plugins[HPM->plugin_count - 1]->filename = NULL; return HPM->plugins[HPM->plugin_count - 1]; } -bool hplugin_showmsg_populate(struct hplugin *plugin, const char *filename) { - void **ShowSub; - const char* ShowSubNames[9] = { - "ShowMessage", - "ShowStatus", - "ShowSQL", - "ShowInfo", - "ShowNotice", - "ShowWarning", - "ShowDebug", - "ShowError", - "ShowFatalError", +#define HPM_POP(x) { #x , x } +bool hplugin_populate(struct hplugin *plugin, const char *filename) { + void **Link; + struct { + const char* name; + void *Ref; + } ToLink[] = { + HPM_POP(ShowMessage), + HPM_POP(ShowStatus), + HPM_POP(ShowSQL), + HPM_POP(ShowInfo), + HPM_POP(ShowNotice), + HPM_POP(ShowWarning), + HPM_POP(ShowDebug), + HPM_POP(ShowError), + HPM_POP(ShowFatalError), }; - void* ShowSubRef[9] = { - ShowMessage, - ShowStatus, - ShowSQL, - ShowInfo, - ShowNotice, - ShowWarning, - ShowDebug, - ShowError, - ShowFatalError, - }; - int i; - for(i = 0; i < 9; i++) { - if( !( ShowSub = plugin_import(plugin->dll, ShowSubNames[i],void **) ) ) { - ShowWarning("HPM:plugin_load: failed to retrieve '%s' for '"CL_WHITE"%s"CL_RESET"', skipping...\n", ShowSubNames[i], filename); + int i, length = ARRAYLENGTH(ToLink); + + for(i = 0; i < length; i++) { + if( !( Link = plugin_import(plugin->dll, ToLink[i].name,void **) ) ) { + ShowWarning("HPM:plugin_load: failed to retrieve '%s' for '"CL_WHITE"%s"CL_RESET"', skipping...\n", ToLink[i].name, filename); HPM->unload(plugin); return false; } - *ShowSub = ShowSubRef[i]; + *Link = ToLink[i].Ref; } + return true; } void hplugin_load(const char* filename) { @@ -114,6 +111,7 @@ void hplugin_load(const char* filename) { struct HPMi_interface **HPMi; bool anyEvent = false; void **import_symbol_ref; + Sql **sql_handle; if( HPM->exists(filename) ) { ShowWarning("HPM:plugin_load: attempting to load duplicate '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename); @@ -153,6 +151,14 @@ void hplugin_load(const char* filename) { *import_symbol_ref = HPM->import_symbol; + if( !( sql_handle = plugin_import(plugin->dll, "mysql_handle",Sql **) ) ) { + ShowWarning("HPM:plugin_load: failed to retrieve 'mysql_handle' for '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename); + HPM->unload(plugin); + return; + } + + *sql_handle = HPM->import_symbol("sql_handle"); + if( !( HPMi = plugin_import(plugin->dll, "HPMi",struct HPMi_interface **) ) ) { ShowWarning("HPM:plugin_load: failed to retrieve 'HPMi' for '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename); HPM->unload(plugin); @@ -181,7 +187,7 @@ void hplugin_load(const char* filename) { return; } - if( !HPM->showmsg_pop(plugin,filename) ) + if( !HPM->populate(plugin,filename) ) return; if( SERVER_TYPE == SERVER_TYPE_MAP ) { @@ -266,6 +272,12 @@ void hplugins_share_defaults(void) { HPM->share(session,"session"); HPM->share(&fd_max,"fd_max"); HPM->share(addr_,"addr"); + /* strlib */ + HPM->share(strlib,"strlib"); + HPM->share(sv,"sv"); + HPM->share(StrBuf,"StrBuf"); + /* sql */ + HPM->share(SQL,"SQL"); /* timer */ HPM->share(gettick,"gettick"); HPM->share(add_timer,"add_timer"); @@ -343,6 +355,6 @@ void hpm_defaults(void) { HPM->share = hplugin_export_symbol; HPM->symbol_defaults = hplugins_share_defaults; HPM->config_read = hplugins_config_read; - HPM->showmsg_pop = hplugin_showmsg_populate; + HPM->populate = hplugin_populate; HPM->symbol_defaults_sub = NULL; } diff --git a/src/common/HPM.h b/src/common/HPM.h index 87d7bdac6..10b1f0e79 100644 --- a/src/common/HPM.h +++ b/src/common/HPM.h @@ -72,7 +72,7 @@ struct HPM_interface { void (*share) (void *, char *); void (*symbol_defaults) (void); void (*config_read) (void); - bool (*showmsg_pop) (struct hplugin *plugin,const char *filename); + bool (*populate) (struct hplugin *plugin,const char *filename); void (*symbol_defaults_sub) (void); } HPM_s; diff --git a/src/common/HPMi.h b/src/common/HPMi.h index f7832d0ec..a58eeed38 100644 --- a/src/common/HPMi.h +++ b/src/common/HPMi.h @@ -7,6 +7,7 @@ #include "../common/cbasetypes.h" #include "../common/core.h" #include "../common/console.h" +#include "../common/sql.h" struct script_state; struct AtCommandInfo; @@ -42,6 +43,8 @@ struct hplugin_info { }; HPExport void *(*import_symbol) (char *name); +HPExport Sql *mysql_handle; + #define GET_SYMBOL(n) import_symbol(n) #define SERVER_TYPE_ALL SERVER_TYPE_LOGIN|SERVER_TYPE_CHAR|SERVER_TYPE_MAP diff --git a/src/common/core.c b/src/common/core.c index 9fd9747aa..8ed0b5801 100644 --- a/src/common/core.c +++ b/src/common/core.c @@ -278,27 +278,32 @@ void usercheck(void) { } #endif } - +void core_defaults(void) { +#ifndef MINICORE + hpm_defaults(); +#endif + console_defaults(); +#ifndef MINICORE + strlib_defaults(); + sql_defaults(); + timer_defaults(); +#endif +} /*====================================== * CORE : MAINROUTINE *--------------------------------------*/ -int main (int argc, char **argv) -{ +int main (int argc, char **argv) { {// initialize program arguments char *p1 = SERVER_NAME = argv[0]; char *p2 = p1; - while ((p1 = strchr(p2, '/')) != NULL || (p1 = strchr(p2, '\\')) != NULL) - { + while ((p1 = strchr(p2, '/')) != NULL || (p1 = strchr(p2, '\\')) != NULL) { SERVER_NAME = ++p1; p2 = p1; } arg_c = argc; arg_v = argv; } -#ifndef MINICORE - hpm_defaults(); -#endif - console_defaults(); + core_defaults(); malloc_init();// needed for Show* in display_title() [FlavioJS] diff --git a/src/common/mmo.h b/src/common/mmo.h index 257a3b42d..581a7a357 100644 --- a/src/common/mmo.h +++ b/src/common/mmo.h @@ -47,7 +47,7 @@ // 20120307 - 2012-03-07aRagexeRE+ - 0x970 #ifndef PACKETVER - #define PACKETVER 20120418 + #define PACKETVER 20130320 #endif //Remove/Comment this line to disable sc_data saving. [Skotlex] diff --git a/src/common/showmsg.c b/src/common/showmsg.c index 50fa972f0..2a3146d35 100644 --- a/src/common/showmsg.c +++ b/src/common/showmsg.c @@ -78,9 +78,9 @@ int console_msg_log = 0;//[Ind] msg error logging } \ else \ {/* dynamic buffer */ \ - buf.d_ = StringBuf_Malloc(); \ - buf.l_ = StringBuf_Vprintf(buf.d_, fmt, args); \ - buf.v_ = StringBuf_Value(buf.d_); \ + buf.d_ = StrBuf->Malloc(); \ + buf.l_ = StrBuf->Vprintf(buf.d_, fmt, args); \ + buf.v_ = StrBuf->Value(buf.d_); \ ShowDebug("showmsg: dynamic buffer used, increase the static buffer size to %d or more.\n", buf.l_+1);\ } \ //define BUFVPRINTF @@ -91,7 +91,7 @@ int console_msg_log = 0;//[Ind] msg error logging #define FREEBUF(buf) \ if( buf.d_ ) \ { \ - StringBuf_Free(buf.d_); \ + StrBuf->Free(buf.d_); \ buf.d_ = NULL; \ } \ buf.v_ = NULL; \ @@ -855,13 +855,13 @@ void ShowConfigWarning(config_setting_t *config, const char *string, ...) { StringBuf buf; va_list ap; - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, string); - StringBuf_Printf(&buf, " (%s:%d)\n", config_setting_source_file(config), config_setting_source_line(config)); + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, string); + StrBuf->Printf(&buf, " (%s:%d)\n", config_setting_source_file(config), config_setting_source_line(config)); va_start(ap, string); - _vShowMessage(MSG_WARNING, StringBuf_Value(&buf), ap); + _vShowMessage(MSG_WARNING, StrBuf->Value(&buf), ap); va_end(ap); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); } void ShowDebug(const char *string, ...) { va_list ap; diff --git a/src/common/sql.c b/src/common/sql.c index 3df9bc1c5..391211183 100644 --- a/src/common/sql.c +++ b/src/common/sql.c @@ -22,8 +22,7 @@ int mysql_reconnect_type; unsigned int mysql_reconnect_count; /// Sql handle -struct Sql -{ +struct Sql { StringBuf buf; MYSQL handle; MYSQL_RES* result; @@ -36,8 +35,7 @@ struct Sql // Column length receiver. // Takes care of the possible size missmatch between uint32 and unsigned long. -struct s_column_length -{ +struct s_column_length { uint32* out_length; unsigned long length; }; @@ -46,8 +44,7 @@ typedef struct s_column_length s_column_length; /// Sql statement -struct SqlStmt -{ +struct SqlStmt { StringBuf buf; MYSQL_STMT* stmt; MYSQL_BIND* params; @@ -74,7 +71,7 @@ Sql* Sql_Malloc(void) CREATE(self, Sql, 1); mysql_init(&self->handle); - StringBuf_Init(&self->buf); + StrBuf->Init(&self->buf); self->lengths = NULL; self->result = NULL; self->keepalive = INVALID_TIMER; @@ -92,7 +89,7 @@ int Sql_Connect(Sql* self, const char* user, const char* passwd, const char* hos if( self == NULL ) return SQL_ERROR; - StringBuf_Clear(&self->buf); + StrBuf->Clear(&self->buf); if( !mysql_real_connect(&self->handle, host, user, passwd, db, (unsigned int)port, NULL/*unix_socket*/, 0/*clientflag*/) ) { ShowSQL("%s\n", mysql_error(&self->handle)); @@ -114,18 +111,16 @@ int Sql_Connect(Sql* self, const char* user, const char* passwd, const char* hos /// Retrieves the timeout of the connection. int Sql_GetTimeout(Sql* self, uint32* out_timeout) { - if( self && out_timeout && SQL_SUCCESS == Sql_Query(self, "SHOW VARIABLES LIKE 'wait_timeout'") ) - { + if( self && out_timeout && SQL_SUCCESS == SQL->Query(self, "SHOW VARIABLES LIKE 'wait_timeout'") ) { char* data; size_t len; - if( SQL_SUCCESS == Sql_NextRow(self) && - SQL_SUCCESS == Sql_GetData(self, 1, &data, &len) ) - { + if( SQL_SUCCESS == SQL->NextRow(self) && + SQL_SUCCESS == SQL->GetData(self, 1, &data, &len) ) { *out_timeout = (uint32)strtoul(data, NULL, 10); - Sql_FreeResult(self); + SQL->FreeResult(self); return SQL_SUCCESS; } - Sql_FreeResult(self); + SQL->FreeResult(self); } return SQL_ERROR; } @@ -139,12 +134,11 @@ int Sql_GetColumnNames(Sql* self, const char* table, char* out_buf, size_t buf_l size_t len; size_t off = 0; - if( self == NULL || SQL_ERROR == Sql_Query(self, "EXPLAIN `%s`", table) ) + if( self == NULL || SQL_ERROR == SQL->Query(self, "EXPLAIN `%s`", table) ) return SQL_ERROR; out_buf[off] = '\0'; - while( SQL_SUCCESS == Sql_NextRow(self) && SQL_SUCCESS == Sql_GetData(self, 0, &data, &len) ) - { + while( SQL_SUCCESS == SQL->NextRow(self) && SQL_SUCCESS == SQL->GetData(self, 0, &data, &len) ) { len = strnlen(data, len); if( off + len + 2 > buf_len ) { @@ -157,7 +151,7 @@ int Sql_GetColumnNames(Sql* self, const char* table, char* out_buf, size_t buf_l out_buf[off++] = sep; } out_buf[off] = '\0'; - Sql_FreeResult(self); + SQL->FreeResult(self); return SQL_SUCCESS; } @@ -250,7 +244,7 @@ int Sql_Query(Sql* self, const char* query, ...) va_list args; va_start(args, query); - res = Sql_QueryV(self, query, args); + res = SQL->QueryV(self, query, args); va_end(args); return res; @@ -264,10 +258,10 @@ int Sql_QueryV(Sql* self, const char* query, va_list args) if( self == NULL ) return SQL_ERROR; - Sql_FreeResult(self); - StringBuf_Clear(&self->buf); - StringBuf_Vprintf(&self->buf, query, args); - if( mysql_real_query(&self->handle, StringBuf_Value(&self->buf), (unsigned long)StringBuf_Length(&self->buf)) ) + SQL->FreeResult(self); + StrBuf->Clear(&self->buf); + StrBuf->Vprintf(&self->buf, query, args); + if( mysql_real_query(&self->handle, StrBuf->Value(&self->buf), (unsigned long)StrBuf->Length(&self->buf)) ) { ShowSQL("DB error - %s\n", mysql_error(&self->handle)); hercules_mysql_error_handler(mysql_errno(&self->handle)); @@ -291,10 +285,10 @@ int Sql_QueryStr(Sql* self, const char* query) if( self == NULL ) return SQL_ERROR; - Sql_FreeResult(self); - StringBuf_Clear(&self->buf); - StringBuf_AppendStr(&self->buf, query); - if( mysql_real_query(&self->handle, StringBuf_Value(&self->buf), (unsigned long)StringBuf_Length(&self->buf)) ) + SQL->FreeResult(self); + StrBuf->Clear(&self->buf); + StrBuf->AppendStr(&self->buf, query); + if( mysql_real_query(&self->handle, StrBuf->Value(&self->buf), (unsigned long)StrBuf->Length(&self->buf)) ) { ShowSQL("DB error - %s\n", mysql_error(&self->handle)); hercules_mysql_error_handler(mysql_errno(&self->handle)); @@ -344,13 +338,10 @@ uint64 Sql_NumRows(Sql* self) /// Fetches the next row. -int Sql_NextRow(Sql* self) -{ - if( self && self->result ) - { +int Sql_NextRow(Sql* self) { + if( self && self->result ) { self->row = mysql_fetch_row(self->result); - if( self->row ) - { + if( self->row ) { self->lengths = mysql_fetch_lengths(self->result); return SQL_SUCCESS; } @@ -366,15 +357,11 @@ int Sql_NextRow(Sql* self) /// Gets the data of a column. int Sql_GetData(Sql* self, size_t col, char** out_buf, size_t* out_len) { - if( self && self->row ) - { - if( col < Sql_NumColumns(self) ) - { + if( self && self->row ) { + if( col < SQL->NumColumns(self) ) { if( out_buf ) *out_buf = self->row[col]; if( out_len ) *out_len = (size_t)self->lengths[col]; - } - else - {// out of range - ignore + } else {// out of range - ignore if( out_buf ) *out_buf = NULL; if( out_len ) *out_len = 0; } @@ -386,10 +373,8 @@ int Sql_GetData(Sql* self, size_t col, char** out_buf, size_t* out_len) /// Frees the result of the query. -void Sql_FreeResult(Sql* self) -{ - if( self && self->result ) - { +void Sql_FreeResult(Sql* self) { + if( self && self->result ) { mysql_free_result(self->result); self->result = NULL; self->row = NULL; @@ -404,8 +389,8 @@ void Sql_ShowDebug_(Sql* self, const char* debug_file, const unsigned long debug { if( self == NULL ) ShowDebug("at %s:%lu - self is NULL\n", debug_file, debug_line); - else if( StringBuf_Length(&self->buf) > 0 ) - ShowDebug("at %s:%lu - %s\n", debug_file, debug_line, StringBuf_Value(&self->buf)); + else if( StrBuf->Length(&self->buf) > 0 ) + ShowDebug("at %s:%lu - %s\n", debug_file, debug_line, StrBuf->Value(&self->buf)); else ShowDebug("at %s:%lu\n", debug_file, debug_line); } @@ -417,8 +402,8 @@ void Sql_Free(Sql* self) { if( self ) { - Sql_FreeResult(self); - StringBuf_Destroy(&self->buf); + SQL->FreeResult(self); + StrBuf->Destroy(&self->buf); if( self->keepalive != INVALID_TIMER ) delete_timer(self->keepalive, Sql_P_KeepaliveTimer); aFree(self); } @@ -590,8 +575,7 @@ static void SqlStmt_P_ShowDebugTruncatedColumn(SqlStmt* self, size_t i) /// Allocates and initializes a new SqlStmt handle. -SqlStmt* SqlStmt_Malloc(Sql* sql) -{ +SqlStmt* SqlStmt_Malloc(Sql* sql) { SqlStmt* self; MYSQL_STMT* stmt; @@ -599,13 +583,12 @@ SqlStmt* SqlStmt_Malloc(Sql* sql) return NULL; stmt = mysql_stmt_init(&sql->handle); - if( stmt == NULL ) - { + if( stmt == NULL ) { ShowSQL("DB error - %s\n", mysql_error(&sql->handle)); return NULL; } CREATE(self, SqlStmt, 1); - StringBuf_Init(&self->buf); + StrBuf->Init(&self->buf); self->stmt = stmt; self->params = NULL; self->columns = NULL; @@ -642,9 +625,9 @@ int SqlStmt_PrepareV(SqlStmt* self, const char* query, va_list args) return SQL_ERROR; SqlStmt_FreeResult(self); - StringBuf_Clear(&self->buf); - StringBuf_Vprintf(&self->buf, query, args); - if( mysql_stmt_prepare(self->stmt, StringBuf_Value(&self->buf), (unsigned long)StringBuf_Length(&self->buf)) ) + StrBuf->Clear(&self->buf); + StrBuf->Vprintf(&self->buf, query, args); + if( mysql_stmt_prepare(self->stmt, StrBuf->Value(&self->buf), (unsigned long)StrBuf->Length(&self->buf)) ) { ShowSQL("DB error - %s\n", mysql_stmt_error(self->stmt)); hercules_mysql_error_handler(mysql_stmt_errno(self->stmt)); @@ -664,9 +647,9 @@ int SqlStmt_PrepareStr(SqlStmt* self, const char* query) return SQL_ERROR; SqlStmt_FreeResult(self); - StringBuf_Clear(&self->buf); - StringBuf_AppendStr(&self->buf, query); - if( mysql_stmt_prepare(self->stmt, StringBuf_Value(&self->buf), (unsigned long)StringBuf_Length(&self->buf)) ) + StrBuf->Clear(&self->buf); + StrBuf->AppendStr(&self->buf, query); + if( mysql_stmt_prepare(self->stmt, StrBuf->Value(&self->buf), (unsigned long)StrBuf->Length(&self->buf)) ) { ShowSQL("DB error - %s\n", mysql_stmt_error(self->stmt)); hercules_mysql_error_handler(mysql_stmt_errno(self->stmt)); @@ -933,8 +916,8 @@ void SqlStmt_ShowDebug_(SqlStmt* self, const char* debug_file, const unsigned lo { if( self == NULL ) ShowDebug("at %s:%lu - self is NULL\n", debug_file, debug_line); - else if( StringBuf_Length(&self->buf) > 0 ) - ShowDebug("at %s:%lu - %s\n", debug_file, debug_line, StringBuf_Value(&self->buf)); + else if( StrBuf->Length(&self->buf) > 0 ) + ShowDebug("at %s:%lu - %s\n", debug_file, debug_line, StrBuf->Value(&self->buf)); else ShowDebug("at %s:%lu\n", debug_file, debug_line); } @@ -947,7 +930,7 @@ void SqlStmt_Free(SqlStmt* self) if( self ) { SqlStmt_FreeResult(self); - StringBuf_Destroy(&self->buf); + StrBuf->Destroy(&self->buf); mysql_stmt_close(self->stmt); if( self->params ) aFree(self->params); @@ -1048,7 +1031,7 @@ void Sql_HerculesUpdateCheck(Sql* self) { if( fgets(timestamp,sizeof(timestamp),ufp) ) { unsigned int timestampui = atol(timestamp); - if( SQL_ERROR == Sql_Query(self, "SELECT 1 FROM `sql_updates` WHERE `timestamp` = '%u' LIMIT 1", timestampui) ) + if( SQL_ERROR == SQL->Query(self, "SELECT 1 FROM `sql_updates` WHERE `timestamp` = '%u' LIMIT 1", timestampui) ) Sql_ShowDebug(self); if( Sql_NumRows(self) != 1 ) { ShowSQL("'"CL_WHITE"%s"CL_RESET"' wasn't applied to the database\n",path); @@ -1069,3 +1052,26 @@ void Sql_HerculesUpdateCheck(Sql* self) { void Sql_Init(void) { Sql_inter_server_read("conf/inter-server.conf",true); } +void sql_defaults(void) { + SQL = &sql_s; + + SQL->Connect = Sql_Connect; + SQL->GetTimeout = Sql_GetTimeout; + SQL->GetColumnNames = Sql_GetColumnNames; + SQL->SetEncoding = Sql_SetEncoding; + SQL->Ping = Sql_Ping; + SQL->EscapeString = Sql_EscapeString; + SQL->EscapeStringLen = Sql_EscapeStringLen; + SQL->Query = Sql_Query; + SQL->QueryV = Sql_QueryV; + SQL->QueryStr = Sql_QueryStr; + SQL->LastInsertId = Sql_LastInsertId; + SQL->NumColumns = Sql_NumColumns; + SQL->NumRows = Sql_NumRows; + SQL->NextRow = Sql_NextRow; + SQL->GetData = Sql_GetData; + SQL->FreeResult = Sql_FreeResult; + SQL->ShowDebug_ = Sql_ShowDebug_; + SQL->Free = Sql_Free; + SQL->Malloc = Sql_Malloc; +} diff --git a/src/common/sql.h b/src/common/sql.h index 319581504..d5a0eda2c 100644 --- a/src/common/sql.h +++ b/src/common/sql.h @@ -22,8 +22,7 @@ /// Data type identifier. /// String, enum and blob data types need the buffer length specified. -enum SqlDataType -{ +enum SqlDataType { SQLDT_NULL, // fixed size SQLDT_INT8, @@ -64,149 +63,96 @@ typedef enum SqlDataType SqlDataType; typedef struct Sql Sql; typedef struct SqlStmt SqlStmt; - -/// Allocates and initializes a new Sql handle. -struct Sql* Sql_Malloc(void); - - - -/// Establishes a connection. -/// -/// @return SQL_SUCCESS or SQL_ERROR -int Sql_Connect(Sql* self, const char* user, const char* passwd, const char* host, uint16 port, const char* db); - - - - -/// Retrieves the timeout of the connection. -/// -/// @return SQL_SUCCESS or SQL_ERROR -int Sql_GetTimeout(Sql* self, uint32* out_timeout); - - - - -/// Retrieves the name of the columns of a table into out_buf, with the separator after each name. -/// -/// @return SQL_SUCCESS or SQL_ERROR -int Sql_GetColumnNames(Sql* self, const char* table, char* out_buf, size_t buf_len, char sep); - - - - -/// Changes the encoding of the connection. -/// -/// @return SQL_SUCCESS or SQL_ERROR -int Sql_SetEncoding(Sql* self, const char* encoding); - - - -/// Pings the connection. -/// -/// @return SQL_SUCCESS or SQL_ERROR -int Sql_Ping(Sql* self); - - - -/// Escapes a string. -/// The output buffer must be at least strlen(from)*2+1 in size. -/// -/// @return The size of the escaped string -size_t Sql_EscapeString(Sql* self, char* out_to, const char* from); - - - -/// Escapes a string. -/// The output buffer must be at least from_len*2+1 in size. -/// -/// @return The size of the escaped string -size_t Sql_EscapeStringLen(Sql* self, char* out_to, const char* from, size_t from_len); - - - -/// Executes a query. -/// Any previous result is freed. -/// The query is constructed as if it was sprintf. -/// -/// @return SQL_SUCCESS or SQL_ERROR -int Sql_Query(Sql* self, const char* query, ...); - - - -/// Executes a query. -/// Any previous result is freed. -/// The query is constructed as if it was svprintf. -/// -/// @return SQL_SUCCESS or SQL_ERROR -int Sql_QueryV(Sql* self, const char* query, va_list args); - - - -/// Executes a query. -/// Any previous result is freed. -/// The query is used directly. -/// -/// @return SQL_SUCCESS or SQL_ERROR -int Sql_QueryStr(Sql* self, const char* query); - - - -/// Returns the number of the AUTO_INCREMENT column of the last INSERT/UPDATE query. -/// -/// @return Value of the auto-increment column -uint64 Sql_LastInsertId(Sql* self); - - - -/// Returns the number of columns in each row of the result. -/// -/// @return Number of columns -uint32 Sql_NumColumns(Sql* self); - - - -/// Returns the number of rows in the result. -/// -/// @return Number of rows -uint64 Sql_NumRows(Sql* self); - - - -/// Fetches the next row. -/// The data of the previous row is no longer valid. -/// -/// @return SQL_SUCCESS, SQL_ERROR or SQL_NO_DATA -int Sql_NextRow(Sql* self); - - - -/// Gets the data of a column. -/// The data remains valid until the next row is fetched or the result is freed. -/// -/// @return SQL_SUCCESS or SQL_ERROR -int Sql_GetData(Sql* self, size_t col, char** out_buf, size_t* out_len); - - - -/// Frees the result of the query. -void Sql_FreeResult(Sql* self); - - +struct sql_interface { + /// Establishes a connection. + /// + /// @return SQL_SUCCESS or SQL_ERROR + int (*Connect) (Sql* self, const char* user, const char* passwd, const char* host, uint16 port, const char* db); + /// Retrieves the timeout of the connection. + /// + /// @return SQL_SUCCESS or SQL_ERROR + int (*GetTimeout) (Sql* self, uint32* out_timeout); + /// Retrieves the name of the columns of a table into out_buf, with the separator after each name. + /// + /// @return SQL_SUCCESS or SQL_ERROR + int (*GetColumnNames) (Sql* self, const char* table, char* out_buf, size_t buf_len, char sep); + /// Changes the encoding of the connection. + /// + /// @return SQL_SUCCESS or SQL_ERROR + int (*SetEncoding) (Sql* self, const char* encoding); + /// Pings the connection. + /// + /// @return SQL_SUCCESS or SQL_ERROR + int (*Ping) (Sql* self); + /// Escapes a string. + /// The output buffer must be at least strlen(from)*2+1 in size. + /// + /// @return The size of the escaped string + size_t (*EscapeString) (Sql* self, char* out_to, const char* from); + /// Escapes a string. + /// The output buffer must be at least from_len*2+1 in size. + /// + /// @return The size of the escaped string + size_t (*EscapeStringLen) (Sql* self, char* out_to, const char* from, size_t from_len); + /// Executes a query. + /// Any previous result is freed. + /// The query is constructed as if it was sprintf. + /// + /// @return SQL_SUCCESS or SQL_ERROR + int (*Query) (Sql* self, const char* query, ...); + /// Executes a query. + /// Any previous result is freed. + /// The query is constructed as if it was svprintf. + /// + /// @return SQL_SUCCESS or SQL_ERROR + int (*QueryV) (Sql* self, const char* query, va_list args); + /// Executes a query. + /// Any previous result is freed. + /// The query is used directly. + /// + /// @return SQL_SUCCESS or SQL_ERROR + int (*QueryStr) (Sql* self, const char* query); + /// Returns the number of the AUTO_INCREMENT column of the last INSERT/UPDATE query. + /// + /// @return Value of the auto-increment column + uint64 (*LastInsertId) (Sql* self); + /// Returns the number of columns in each row of the result. + /// + /// @return Number of columns + uint32 (*NumColumns) (Sql* self); + /// Returns the number of rows in the result. + /// + /// @return Number of rows + uint64 (*NumRows) (Sql* self); + /// Fetches the next row. + /// The data of the previous row is no longer valid. + /// + /// @return SQL_SUCCESS, SQL_ERROR or SQL_NO_DATA + int (*NextRow) (Sql* self); + /// Gets the data of a column. + /// The data remains valid until the next row is fetched or the result is freed. + /// + /// @return SQL_SUCCESS or SQL_ERROR + int (*GetData) (Sql* self, size_t col, char** out_buf, size_t* out_len); + /// Frees the result of the query. + void (*FreeResult) (Sql* self); + /// Shows debug information (last query). + void (*ShowDebug_) (Sql* self, const char* debug_file, const unsigned long debug_line); + /// Frees a Sql handle returned by Sql_Malloc. + void (*Free) (Sql* self); + /// Allocates and initializes a new Sql handle. + struct Sql *(*Malloc) (void); +} sql_s; + +struct sql_interface *SQL; + +void sql_defaults(void); #if defined(SQL_REMOVE_SHOWDEBUG) -#define Sql_ShowDebug(self) (void)0 + #define Sql_ShowDebug(self) (void)0 #else -#define Sql_ShowDebug(self) Sql_ShowDebug_(self, __FILE__, __LINE__) + #define Sql_ShowDebug(self) SQL->ShowDebug_(self, __FILE__, __LINE__) #endif -/// Shows debug information (last query). -void Sql_ShowDebug_(Sql* self, const char* debug_file, const unsigned long debug_line); - - - -/// Frees a Sql handle returned by Sql_Malloc. -void Sql_Free(Sql* self); - - /////////////////////////////////////////////////////////////////////////////// // Prepared Statements @@ -221,8 +167,6 @@ void Sql_Free(Sql* self); // 1) SELECT col FROM table WHERE id=? // 2) INSERT INTO table(col1,col2) VALUES(?,?) - - /// Allocates and initializes a new SqlStmt handle. /// It uses the connection of the parent Sql handle. /// Queries in Sql and SqlStmt are independent and don't affect each other. @@ -239,8 +183,6 @@ struct SqlStmt* SqlStmt_Malloc(Sql* sql); /// @return SQL_SUCCESS or SQL_ERROR int SqlStmt_Prepare(SqlStmt* self, const char* query, ...); - - /// Prepares the statement. /// Any previous result is freed and all parameter bindings are removed. /// The query is constructed as if it was svprintf. @@ -328,9 +270,9 @@ void SqlStmt_FreeResult(SqlStmt* self); void Sql_HerculesUpdateCheck(Sql* self); #if defined(SQL_REMOVE_SHOWDEBUG) -#define SqlStmt_ShowDebug(self) (void)0 + #define SqlStmt_ShowDebug(self) (void)0 #else -#define SqlStmt_ShowDebug(self) SqlStmt_ShowDebug_(self, __FILE__, __LINE__) + #define SqlStmt_ShowDebug(self) SqlStmt_ShowDebug_(self, __FILE__, __LINE__) #endif /// Shows debug information (with statement). void SqlStmt_ShowDebug_(SqlStmt* self, const char* debug_file, const unsigned long debug_line); diff --git a/src/common/strlib.c b/src/common/strlib.c index dfacbf136..278542a24 100644 --- a/src/common/strlib.c +++ b/src/common/strlib.c @@ -1,9 +1,11 @@ -// 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 #include "../common/cbasetypes.h" #include "../common/malloc.h" #include "../common/showmsg.h" +#define STRLIB_C #include "strlib.h" #include @@ -14,8 +16,7 @@ #define J_MAX_MALLOC_SIZE 65535 // escapes a string in-place (' -> \' , \ -> \\ , % -> _) -char* jstrescape (char* pt) -{ +char* jstrescape (char* pt) { //copy from here char *ptr; int i = 0, j = 0; @@ -220,8 +221,7 @@ const char* stristr(const char* haystack, const char* needle) } #ifdef __WIN32 -char* _strtok_r(char *s1, const char *s2, char **lasts) -{ +char* _strtok_r(char *s1, const char *s2, char **lasts) { char *ret; if (s1 == NULL) @@ -618,8 +618,7 @@ int sv_parse_next(struct s_svstate* sv) /// @param npos Size of the pos array /// @param opt Options that determine the parsing behaviour /// @return Number of fields found in the string or -1 if an error occured -int sv_parse(const char* str, int len, int startoff, char delim, int* out_pos, int npos, enum e_svopt opt) -{ +int sv_parse(const char* str, int len, int startoff, char delim, int* out_pos, int npos, enum e_svopt opt) { struct s_svstate sv; int count; @@ -637,8 +636,7 @@ int sv_parse(const char* str, int len, int startoff, char delim, int* out_pos, i // parse count = 0; if( npos > 0 ) out_pos[0] = startoff; - while( !sv.done ) - { + while( !sv.done ) { ++count; if( sv_parse_next(&sv) <= 0 ) return -1;// error @@ -668,8 +666,7 @@ int sv_parse(const char* str, int len, int startoff, char delim, int* out_pos, i /// @param nfields Size of the field array /// @param opt Options that determine the parsing behaviour /// @return Number of fields found in the string or -1 if an error occured -int sv_split(char* str, int len, int startoff, char delim, char** out_fields, int nfields, enum e_svopt opt) -{ +int sv_split(char* str, int len, int startoff, char delim, char** out_fields, int nfields, enum e_svopt opt) { int pos[1024]; int i; int done; @@ -681,30 +678,21 @@ int sv_split(char* str, int len, int startoff, char delim, char** out_fields, in // next line end = str + pos[1]; - if( end[0] == '\0' ) - { + if( end[0] == '\0' ) { *out_fields = end; - } - else if( (opt&SV_TERMINATE_LF) && end[0] == '\n' ) - { + } else if( (opt&SV_TERMINATE_LF) && end[0] == '\n' ) { if( !(opt&SV_KEEP_TERMINATOR) ) end[0] = '\0'; *out_fields = end + 1; - } - else if( (opt&SV_TERMINATE_CRLF) && end[0] == '\r' && end[1] == '\n' ) - { + } else if( (opt&SV_TERMINATE_CRLF) && end[0] == '\r' && end[1] == '\n' ) { if( !(opt&SV_KEEP_TERMINATOR) ) end[0] = end[1] = '\0'; *out_fields = end + 2; - } - else if( (opt&SV_TERMINATE_CR) && end[0] == '\r' ) - { + } else if( (opt&SV_TERMINATE_CR) && end[0] == '\r' ) { if( !(opt&SV_KEEP_TERMINATOR) ) end[0] = '\0'; *out_fields = end + 1; - } - else - { + } else { ShowError("sv_split: unknown line delimiter 0x02%x.\n", (unsigned char)end[0]); return -1;// error } @@ -714,10 +702,8 @@ int sv_split(char* str, int len, int startoff, char delim, char** out_fields, in // fields i = 2; done = 0; - while( done < ret && nfields > 0 ) - { - if( i < ARRAYLENGTH(pos) ) - {// split field + while( done < ret && nfields > 0 ) { + if( i < ARRAYLENGTH(pos) ) { // split field *out_fields = str + pos[i]; end = str + pos[i+1]; *end = '\0'; @@ -726,9 +712,7 @@ int sv_split(char* str, int len, int startoff, char delim, char** out_fields, in ++done; ++out_fields; --nfields; - } - else - {// get more fields + } else { // get more fields sv_parse(str, len, pos[i-1] + 1, delim, pos, ARRAYLENGTH(pos), opt); i = 2; } @@ -748,65 +732,59 @@ int sv_split(char* str, int len, int startoff, char delim, char** out_fields, in /// @param len Length of the source string /// @param escapes Extra characters to be escaped /// @return Length of the escaped string -size_t sv_escape_c(char* out_dest, const char* src, size_t len, const char* escapes) -{ +size_t sv_escape_c(char* out_dest, const char* src, size_t len, const char* escapes) { size_t i; size_t j; if( out_dest == NULL ) return 0;// nothing to do - if( src == NULL ) - {// nothing to escape + if( src == NULL ) { // nothing to escape *out_dest = 0; return 0; } if( escapes == NULL ) escapes = ""; - for( i = 0, j = 0; i < len; ++i ) - { - switch( src[i] ) - { - case '\0':// octal 0 - out_dest[j++] = '\\'; - out_dest[j++] = '0'; - out_dest[j++] = '0'; - out_dest[j++] = '0'; - break; - case '\r':// carriage return - out_dest[j++] = '\\'; - out_dest[j++] = 'r'; - break; - case '\n':// line feed - out_dest[j++] = '\\'; - out_dest[j++] = 'n'; - break; - case '\\':// escape character - out_dest[j++] = '\\'; - out_dest[j++] = '\\'; - break; - default: - if( strchr(escapes,src[i]) ) - {// escape + for( i = 0, j = 0; i < len; ++i ) { + switch( src[i] ) { + case '\0':// octal 0 out_dest[j++] = '\\'; - switch( src[i] ) - { - case '\a': out_dest[j++] = 'a'; break; - case '\b': out_dest[j++] = 'b'; break; - case '\t': out_dest[j++] = 't'; break; - case '\v': out_dest[j++] = 'v'; break; - case '\f': out_dest[j++] = 'f'; break; - case '\?': out_dest[j++] = '?'; break; - default:// to octal - out_dest[j++] = '0'+((char)(((unsigned char)src[i]&0700)>>6)); - out_dest[j++] = '0'+((char)(((unsigned char)src[i]&0070)>>3)); - out_dest[j++] = '0'+((char)(((unsigned char)src[i]&0007) )); - break; + out_dest[j++] = '0'; + out_dest[j++] = '0'; + out_dest[j++] = '0'; + break; + case '\r':// carriage return + out_dest[j++] = '\\'; + out_dest[j++] = 'r'; + break; + case '\n':// line feed + out_dest[j++] = '\\'; + out_dest[j++] = 'n'; + break; + case '\\':// escape character + out_dest[j++] = '\\'; + out_dest[j++] = '\\'; + break; + default: + if( strchr(escapes,src[i]) ) {// escape + out_dest[j++] = '\\'; + switch( src[i] ) { + case '\a': out_dest[j++] = 'a'; break; + case '\b': out_dest[j++] = 'b'; break; + case '\t': out_dest[j++] = 't'; break; + case '\v': out_dest[j++] = 'v'; break; + case '\f': out_dest[j++] = 'f'; break; + case '\?': out_dest[j++] = '?'; break; + default:// to octal + out_dest[j++] = '0'+((char)(((unsigned char)src[i]&0700)>>6)); + out_dest[j++] = '0'+((char)(((unsigned char)src[i]&0070)>>3)); + out_dest[j++] = '0'+((char)(((unsigned char)src[i]&0007) )); + break; + } } - } - else - out_dest[j++] = src[i]; - break; + else + out_dest[j++] = src[i]; + break; } } out_dest[j] = 0; @@ -821,8 +799,7 @@ size_t sv_escape_c(char* out_dest, const char* src, size_t len, const char* esca /// @param src Source string /// @param len Length of the source string /// @return Length of the escaped string -size_t sv_unescape_c(char* out_dest, const char* src, size_t len) -{ +size_t sv_unescape_c(char* out_dest, const char* src, size_t len) { static unsigned char low2hex[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,// 0x0? 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,// 0x1? @@ -844,71 +821,58 @@ size_t sv_unescape_c(char* out_dest, const char* src, size_t len) size_t i; size_t j; - for( i = 0, j = 0; i < len; ) - { - if( src[i] == '\\' ) - { + for( i = 0, j = 0; i < len; ) { + if( src[i] == '\\' ) { ++i;// '\\' if( i >= len ) ShowWarning("sv_unescape_c: empty escape sequence\n"); - else if( src[i] == 'x' ) - {// hex escape sequence + else if( src[i] == 'x' ) {// hex escape sequence unsigned char c = 0; unsigned char inrange = 1; ++i;// 'x' - if( i >= len || !ISXDIGIT(src[i]) ) - { + if( i >= len || !ISXDIGIT(src[i]) ) { ShowWarning("sv_unescape_c: \\x with no following hex digits\n"); continue; } - do{ - if( c > 0x0F && inrange ) - { + do { + if( c > 0x0F && inrange ) { ShowWarning("sv_unescape_c: hex escape sequence out of range\n"); inrange = 0; } c = (c<<4)|low2hex[(unsigned char)src[i]];// hex digit ++i; - }while( i < len && ISXDIGIT(src[i]) ); + } while( i < len && ISXDIGIT(src[i]) ); out_dest[j++] = (char)c; - } - else if( src[i] == '0' || src[i] == '1' || src[i] == '2' || src[i] == '3' ) - {// octal escape sequence (255=0377) + } else if( src[i] == '0' || src[i] == '1' || src[i] == '2' || src[i] == '3' ) {// octal escape sequence (255=0377) unsigned char c = src[i]-'0'; ++i;// '0', '1', '2' or '3' - if( i < len && src[i] >= '0' && src[i] <= '7' ) - { + if( i < len && src[i] >= '0' && src[i] <= '7' ) { c = (c<<3)|(src[i]-'0'); ++i;// octal digit } - if( i < len && src[i] >= '0' && src[i] <= '7' ) - { + if( i < len && src[i] >= '0' && src[i] <= '7' ) { c = (c<<3)|(src[i]-'0'); ++i;// octal digit } out_dest[j++] = (char)c; - } - else - {// other escape sequence + } else { // other escape sequence if( strchr(SV_ESCAPE_C_SUPPORTED, src[i]) == NULL ) ShowWarning("sv_unescape_c: unknown escape sequence \\%c\n", src[i]); - switch( src[i] ) - { - case 'a': out_dest[j++] = '\a'; break; - case 'b': out_dest[j++] = '\b'; break; - case 't': out_dest[j++] = '\t'; break; - case 'n': out_dest[j++] = '\n'; break; - case 'v': out_dest[j++] = '\v'; break; - case 'f': out_dest[j++] = '\f'; break; - case 'r': out_dest[j++] = '\r'; break; - case '?': out_dest[j++] = '\?'; break; - default: out_dest[j++] = src[i]; break; + switch( src[i] ) { + case 'a': out_dest[j++] = '\a'; break; + case 'b': out_dest[j++] = '\b'; break; + case 't': out_dest[j++] = '\t'; break; + case 'n': out_dest[j++] = '\n'; break; + case 'v': out_dest[j++] = '\v'; break; + case 'f': out_dest[j++] = '\f'; break; + case 'r': out_dest[j++] = '\r'; break; + case '?': out_dest[j++] = '\?'; break; + default: out_dest[j++] = src[i]; break; } ++i;// escaped character } - } - else + } else out_dest[j++] = src[i++];// normal character } out_dest[j] = 0; @@ -916,31 +880,28 @@ size_t sv_unescape_c(char* out_dest, const char* src, size_t len) } /// Skips a C escape sequence (starting with '\\'). -const char* skip_escaped_c(const char* p) -{ - if( p && *p == '\\' ) - { +const char* skip_escaped_c(const char* p) { + if( p && *p == '\\' ) { ++p; - switch( *p ) - { - case 'x':// hexadecimal - ++p; - while( ISXDIGIT(*p) ) - ++p; - break; - case '0': - case '1': - case '2': - case '3':// octal - ++p; - if( *p >= '0' && *p <= '7' ) + switch( *p ) { + case 'x':// hexadecimal ++p; - if( *p >= '0' && *p <= '7' ) - ++p; - break; - default: - if( *p && strchr(SV_ESCAPE_C_SUPPORTED, *p) ) + while( ISXDIGIT(*p) ) + ++p; + break; + case '0': + case '1': + case '2': + case '3':// octal ++p; + if( *p >= '0' && *p <= '7' ) + ++p; + if( *p >= '0' && *p <= '7' ) + ++p; + break; + default: + if( *p && strchr(SV_ESCAPE_C_SUPPORTED, *p) ) + ++p; } } return p; @@ -958,8 +919,7 @@ const char* skip_escaped_c(const char* p) /// @param maxcols Maximum number of columns of a valid row /// @param parseproc User-supplied row processing function /// @return true on success, false if file could not be opened -bool sv_readdb(const char* directory, const char* filename, char delim, int mincols, int maxcols, int maxrows, bool (*parseproc)(char* fields[], int columns, int current)) -{ +bool sv_readdb(const char* directory, const char* filename, char delim, int mincols, int maxcols, int maxrows, bool (*parseproc)(char* fields[], int columns, int current)) { FILE* fp; int lines = 0; int entries = 0; @@ -971,9 +931,7 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc snprintf(path, sizeof(path), "%s/%s", directory, filename); // open file - fp = fopen(path, "r"); - if( fp == NULL ) - { + if( (fp = fopen(path, "r")) == NULL ) { ShowError("sv_readdb: can't read %s\n", path); return false; } @@ -983,12 +941,10 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc fields = (char**)aMalloc(fields_length*sizeof(char*)); // process rows one by one - while( fgets(line, sizeof(line), fp) ) - { + while( fgets(line, sizeof(line), fp) ) { lines++; - if( ( match = strstr(line, "//") ) != NULL ) - {// strip comments + if( ( match = strstr(line, "//") ) != NULL ) {// strip comments match[0] = 0; } @@ -998,25 +954,21 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc columns = sv_split(line, strlen(line), 0, delim, fields, fields_length, (e_svopt)(SV_TERMINATE_LF|SV_TERMINATE_CRLF)); - if( columns < mincols ) - { + if( columns < mincols ) { ShowError("sv_readdb: Insufficient columns in line %d of \"%s\" (found %d, need at least %d).\n", lines, path, columns, mincols); continue; // not enough columns } - if( columns > maxcols ) - { + if( columns > maxcols ) { ShowError("sv_readdb: Too many columns in line %d of \"%s\" (found %d, maximum is %d).\n", lines, path, columns, maxcols ); continue; // too many columns } - if( entries == maxrows ) - { + if( entries == maxrows ) { ShowError("sv_readdb: Reached the maximum allowed number of entries (%d) when parsing file \"%s\".\n", maxrows, path); break; } // parse this row - if( !parseproc(fields+1, columns, entries) ) - { + if( !parseproc(fields+1, columns, entries) ) { ShowError("sv_readdb: Could not process contents of line %d of \"%s\".\n", lines, path); continue; // invalid row contents } @@ -1039,41 +991,36 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc // @author MouseJstr (original) /// Allocates a StringBuf -StringBuf* StringBuf_Malloc() -{ +StringBuf* StringBuf_Malloc() { StringBuf* self; CREATE(self, StringBuf, 1); - StringBuf_Init(self); + StrBuf->Init(self); return self; } /// Initializes a previously allocated StringBuf -void StringBuf_Init(StringBuf* self) -{ +void StringBuf_Init(StringBuf* self) { self->max_ = 1024; self->ptr_ = self->buf_ = (char*)aMalloc(self->max_ + 1); } /// Appends the result of printf to the StringBuf -int StringBuf_Printf(StringBuf* self, const char* fmt, ...) -{ +int StringBuf_Printf(StringBuf* self, const char* fmt, ...) { int len; va_list ap; va_start(ap, fmt); - len = StringBuf_Vprintf(self, fmt, ap); + len = StrBuf->Vprintf(self, fmt, ap); va_end(ap); return len; } /// Appends the result of vprintf to the StringBuf -int StringBuf_Vprintf(StringBuf* self, const char* fmt, va_list ap) -{ +int StringBuf_Vprintf(StringBuf* self, const char* fmt, va_list ap) { int n, size, off; - for(;;) - { + for(;;) { va_list apcopy; /* Try to print in the allocated space. */ size = self->max_ - (self->ptr_ - self->buf_); @@ -1081,8 +1028,7 @@ int StringBuf_Vprintf(StringBuf* self, const char* fmt, va_list ap) n = vsnprintf(self->ptr_, size, fmt, apcopy); va_end(apcopy); /* If that worked, return the length. */ - if( n > -1 && n < size ) - { + if( n > -1 && n < size ) { self->ptr_ += n; return (int)(self->ptr_ - self->buf_); } @@ -1095,13 +1041,11 @@ int StringBuf_Vprintf(StringBuf* self, const char* fmt, va_list ap) } /// Appends the contents of another StringBuf to the StringBuf -int StringBuf_Append(StringBuf* self, const StringBuf* sbuf) -{ +int StringBuf_Append(StringBuf* self, const StringBuf* sbuf) { int available = self->max_ - (self->ptr_ - self->buf_); int needed = (int)(sbuf->ptr_ - sbuf->buf_); - if( needed >= available ) - { + if( needed >= available ) { int off = (int)(self->ptr_ - self->buf_); self->max_ += needed; self->buf_ = (char*)aRealloc(self->buf_, self->max_ + 1); @@ -1114,13 +1058,12 @@ int StringBuf_Append(StringBuf* self, const StringBuf* sbuf) } // Appends str to the StringBuf -int StringBuf_AppendStr(StringBuf* self, const char* str) -{ +int StringBuf_AppendStr(StringBuf* self, const char* str) { int available = self->max_ - (self->ptr_ - self->buf_); int needed = (int)strlen(str); - if( needed >= available ) - {// not enough space, expand the buffer (minimum expansion = 1024) + if( needed >= available ) { + // not enough space, expand the buffer (minimum expansion = 1024) int off = (int)(self->ptr_ - self->buf_); self->max_ += max(needed, 1024); self->buf_ = (char*)aRealloc(self->buf_, self->max_ + 1); @@ -1133,35 +1076,78 @@ int StringBuf_AppendStr(StringBuf* self, const char* str) } // Returns the length of the data in the Stringbuf -int StringBuf_Length(StringBuf* self) -{ +int StringBuf_Length(StringBuf* self) { return (int)(self->ptr_ - self->buf_); } /// Returns the data in the StringBuf -char* StringBuf_Value(StringBuf* self) -{ +char* StringBuf_Value(StringBuf* self) { *self->ptr_ = '\0'; return self->buf_; } /// Clears the contents of the StringBuf -void StringBuf_Clear(StringBuf* self) -{ +void StringBuf_Clear(StringBuf* self) { self->ptr_ = self->buf_; } /// Destroys the StringBuf -void StringBuf_Destroy(StringBuf* self) -{ +void StringBuf_Destroy(StringBuf* self) { aFree(self->buf_); self->ptr_ = self->buf_ = 0; self->max_ = 0; } // Frees a StringBuf returned by StringBuf_Malloc -void StringBuf_Free(StringBuf* self) -{ - StringBuf_Destroy(self); +void StringBuf_Free(StringBuf* self) { + StrBuf->Destroy(self); aFree(self); } +void strlib_defaults(void) { + /* connect */ + strlib = &strlib_s; + StrBuf = &stringbuf_s; + sv = &sv_s; + /* link~u! */ + strlib->jstrescape = jstrescape; + strlib->jmemescapecpy = jmemescapecpy; + strlib->remove_control_chars = remove_control_chars; + strlib->trim = trim; + strlib->normalize_name = normalize_name; + strlib->stristr = stristr; + +#if !(defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400) && !defined(HAVE_STRNLEN) + strlib->strnlen = strnlen; +#endif + +#if defined(WIN32) && defined(_MSC_VER) && _MSC_VER <= 1200 + strlib->strtoull = strtoull; +#endif + strlib->e_mail_check = e_mail_check; + strlib->config_switch = config_switch; + strlib->safestrncpy = safestrncpy; + strlib->safestrnlen = safestrnlen; + strlib->safesnprintf = safesnprintf; + strlib->strline = strline; + strlib->bin2hex = bin2hex; + + StrBuf->Malloc = StringBuf_Malloc; + StrBuf->Init = StringBuf_Init; + StrBuf->Printf = StringBuf_Printf; + StrBuf->Vprintf = StringBuf_Vprintf; + StrBuf->Append = StringBuf_Append; + StrBuf->AppendStr = StringBuf_AppendStr; + StrBuf->Length = StringBuf_Length; + StrBuf->Value = StringBuf_Value; + StrBuf->Clear = StringBuf_Clear; + StrBuf->Destroy = StringBuf_Destroy; + StrBuf->Free = StringBuf_Free; + + sv->parse_next = sv_parse_next; + sv->parse = sv_parse; + sv->split = sv_split; + sv->escape_c = sv_escape_c; + sv->unescape_c = sv_unescape_c; + sv->skip_escaped_c = skip_escaped_c; + sv->readdb = sv_readdb; +} diff --git a/src/common/strlib.h b/src/common/strlib.h index bbc2c6105..af0fb2764 100644 --- a/src/common/strlib.h +++ b/src/common/strlib.h @@ -1,5 +1,6 @@ -// 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 _STRLIB_H_ #define _STRLIB_H_ @@ -11,56 +12,14 @@ #include #undef __USE_GNU -char* jstrescape (char* pt); -char* jstrescapecpy (char* pt, const char* spt); -int jmemescapecpy (char* pt, const char* spt, int size); - -int remove_control_chars(char* str); -char* trim(char* str); -char* normalize_name(char* str,const char* delims); -const char *stristr(const char *haystack, const char *needle); - #ifdef WIN32 -#define HAVE_STRTOK_R -#define strtok_r(s,delim,save_ptr) _strtok_r((s),(delim),(save_ptr)) -char* _strtok_r(char* s1, const char* s2, char** lasts); -#endif - -#if !(defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400) && !defined(HAVE_STRNLEN) -size_t strnlen (const char* string, size_t maxlen); + #define HAVE_STRTOK_R + #define strtok_r(s,delim,save_ptr) _strtok_r((s),(delim),(save_ptr)) + char _strtok_r(char* s1, const char* s2, char** lasts); #endif -#if defined(WIN32) && defined(_MSC_VER) && _MSC_VER <= 1200 -uint64 strtoull(const char* str, char** endptr, int base); -#endif - -int e_mail_check(char* email); -int config_switch(const char* str); - -/// strncpy that always nul-terminates the string -char* safestrncpy(char* dst, const char* src, size_t n); - -/// doesn't crash on null pointer -size_t safestrnlen(const char* string, size_t maxlen); - -/// Works like snprintf, but always nul-terminates the buffer. -/// Returns the size of the string (without nul-terminator) -/// or -1 if the buffer is too small. -int safesnprintf(char* buf, size_t sz, const char* fmt, ...); - -/// Returns the line of the target position in the string. -/// Lines start at 1. -int strline(const char* str, size_t pos); - -/// Produces the hexadecimal representation of the given input. -/// The output buffer must be at least count*2+1 in size. -/// Returns true on success, false on failure. -bool bin2hex(char* output, unsigned char* input, size_t count); - - /// Bitfield determining the behaviour of sv_parse and sv_split. -typedef enum e_svopt -{ +typedef enum e_svopt { // default: no escapes and no line terminator SV_NOESCAPE_NOTERMINATE = 0, // Escapes according to the C compiler. @@ -78,8 +37,7 @@ typedef enum e_svopt /// Parse state. /// The field is [start,end[ -struct s_svstate -{ +struct s_svstate { const char* str; //< string to parse int len; //< string length int off; //< current offset in the string @@ -90,66 +48,144 @@ struct s_svstate bool done; //< if all the text has been parsed }; -/// Parses a single field in a delim-separated string. -/// The delimiter after the field is skipped. -/// -/// @param sv Parse state -/// @return 1 if a field was parsed, 0 if done, -1 on error. -int sv_parse_next(struct s_svstate* sv); - -/// Parses a delim-separated string. -/// Starts parsing at startoff and fills the pos array with position pairs. -/// out_pos[0] and out_pos[1] are the start and end of line. -/// Other position pairs are the start and end of fields. -/// Returns the number of fields found or -1 if an error occurs. -int sv_parse(const char* str, int len, int startoff, char delim, int* out_pos, int npos, enum e_svopt opt); - -/// Splits a delim-separated string. -/// WARNING: this function modifies the input string -/// Starts splitting at startoff and fills the out_fields array. -/// out_fields[0] is the start of the next line. -/// Other entries are the start of fields (nul-teminated). -/// Returns the number of fields found or -1 if an error occurs. -int sv_split(char* str, int len, int startoff, char delim, char** out_fields, int nfields, enum e_svopt opt); - -/// Escapes src to out_dest according to the format of the C compiler. -/// Returns the length of the escaped string. -/// out_dest should be len*4+1 in size. -size_t sv_escape_c(char* out_dest, const char* src, size_t len, const char* escapes); - -/// Unescapes src to out_dest according to the format of the C compiler. -/// Returns the length of the unescaped string. -/// out_dest should be len+1 in size and can be the same buffer as src. -size_t sv_unescape_c(char* out_dest, const char* src, size_t len); - -/// Skips a C escape sequence (starting with '\\'). -const char* skip_escaped_c(const char* p); - -/// Opens and parses a file containing delim-separated columns, feeding them to the specified callback function row by row. -/// Tracks the progress of the operation (current line number, number of successfully processed rows). -/// Returns 'true' if it was able to process the specified file, or 'false' if it could not be read. -bool sv_readdb(const char* directory, const char* filename, char delim, int mincols, int maxcols, int maxrows, bool (*parseproc)(char* fields[], int columns, int current)); - /// StringBuf - dynamic string -struct StringBuf -{ +struct StringBuf { char *buf_; char *ptr_; unsigned int max_; }; typedef struct StringBuf StringBuf; -StringBuf* StringBuf_Malloc(void); -void StringBuf_Init(StringBuf* self); -int StringBuf_Printf(StringBuf* self, const char* fmt, ...); -int StringBuf_Vprintf(StringBuf* self, const char* fmt, va_list args); -int StringBuf_Append(StringBuf* self, const StringBuf *sbuf); -int StringBuf_AppendStr(StringBuf* self, const char* str); -int StringBuf_Length(StringBuf* self); -char* StringBuf_Value(StringBuf* self); -void StringBuf_Clear(StringBuf* self); -void StringBuf_Destroy(StringBuf* self); -void StringBuf_Free(StringBuf* self); - +struct strlib_interface { + char *(*jstrescape) (char* pt); + char *(*jstrescapecpy) (char* pt, const char* spt); + int (*jmemescapecpy) (char* pt, const char* spt, int size); + int (*remove_control_chars) (char* str); + char *(*trim) (char* str); + char *(*normalize_name) (char* str,const char* delims); + const char *(*stristr) (const char *haystack, const char *needle); + +#if !(defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400) && !defined(HAVE_STRNLEN) + size_t (*strnlen) (const char* string, size_t maxlen); +#endif + +#if defined(WIN32) && defined(_MSC_VER) && _MSC_VER <= 1200 + uint64 (*strtoull) (const char* str, char** endptr, int base); +#endif + + int (*e_mail_check) (char* email); + int (*config_switch) (const char* str); + + /// strncpy that always nul-terminates the string + char *(*safestrncpy) (char* dst, const char* src, size_t n); + + /// doesn't crash on null pointer + size_t (*safestrnlen) (const char* string, size_t maxlen); + + /// Works like snprintf, but always nul-terminates the buffer. + /// Returns the size of the string (without nul-terminator) + /// or -1 if the buffer is too small. + int (*safesnprintf) (char* buf, size_t sz, const char* fmt, ...); + + /// Returns the line of the target position in the string. + /// Lines start at 1. + int (*strline) (const char* str, size_t pos); + + /// Produces the hexadecimal representation of the given input. + /// The output buffer must be at least count*2+1 in size. + /// Returns true on success, false on failure. + bool (*bin2hex) (char* output, unsigned char* input, size_t count); +} strlib_s; + +struct strlib_interface *strlib; + +struct stringbuf_interface { + StringBuf* (*Malloc) (void); + void (*Init) (StringBuf* self); + int (*Printf) (StringBuf* self, const char* fmt, ...); + int (*Vprintf) (StringBuf* self, const char* fmt, va_list args); + int (*Append) (StringBuf* self, const StringBuf *sbuf); + int (*AppendStr) (StringBuf* self, const char* str); + int (*Length) (StringBuf* self); + char* (*Value) (StringBuf* self); + void (*Clear) (StringBuf* self); + void (*Destroy) (StringBuf* self); + void (*Free) (StringBuf* self); +} stringbuf_s; + +struct stringbuf_interface *StrBuf; + +struct sv_interface { + /// Parses a single field in a delim-separated string. + /// The delimiter after the field is skipped. + /// + /// @param sv Parse state + /// @return 1 if a field was parsed, 0 if done, -1 on error. + int (*parse_next) (struct s_svstate* sv); + + /// Parses a delim-separated string. + /// Starts parsing at startoff and fills the pos array with position pairs. + /// out_pos[0] and out_pos[1] are the start and end of line. + /// Other position pairs are the start and end of fields. + /// Returns the number of fields found or -1 if an error occurs. + int (*parse) (const char* str, int len, int startoff, char delim, int* out_pos, int npos, enum e_svopt opt); + + /// Splits a delim-separated string. + /// WARNING: this function modifies the input string + /// Starts splitting at startoff and fills the out_fields array. + /// out_fields[0] is the start of the next line. + /// Other entries are the start of fields (nul-teminated). + /// Returns the number of fields found or -1 if an error occurs. + int (*split) (char* str, int len, int startoff, char delim, char** out_fields, int nfields, enum e_svopt opt); + + /// Escapes src to out_dest according to the format of the C compiler. + /// Returns the length of the escaped string. + /// out_dest should be len*4+1 in size. + size_t (*escape_c) (char* out_dest, const char* src, size_t len, const char* escapes); + + /// Unescapes src to out_dest according to the format of the C compiler. + /// Returns the length of the unescaped string. + /// out_dest should be len+1 in size and can be the same buffer as src. + size_t (*unescape_c) (char* out_dest, const char* src, size_t len); + + /// Skips a C escape sequence (starting with '\\'). + const char* (*skip_escaped_c) (const char* p); + + /// Opens and parses a file containing delim-separated columns, feeding them to the specified callback function row by row. + /// Tracks the progress of the operation (current line number, number of successfully processed rows). + /// Returns 'true' if it was able to process the specified file, or 'false' if it could not be read. + bool (*readdb) (const char* directory, const char* filename, char delim, int mincols, int maxcols, int maxrows, bool (*parseproc)(char* fields[], int columns, int current)); +} sv_s; + +struct sv_interface *sv; + +void strlib_defaults(void); + +/* the purpose of these macros is simply to not make calling them be an annoyance */ +#ifndef STRLIB_C + #define jstrescape(pt) strlib->jstrescape(pt) + #define jstrescapecpy(pt,spt) strlib->jstrescapecpy(pt,spt) + #define jmemescapecpy(pt,spt,size) strlib->jmemescapecpy(pt,spt,size) + #define remove_control_chars(str) strlib->remove_control_chars(str) + #define trim(str) strlib->trim(str) + #define normalize_name(str,delims) strlib->normalize_name(str,delims) + #define stristr(haystack,needle) strlib->stristr(haystack,needle) + + #if !(defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400) && !defined(HAVE_STRNLEN) + #define strnln(string,maxlen) strlib->strnlen(string,maxlen) + #endif + + #if defined(WIN32) && defined(_MSC_VER) && _MSC_VER <= 1200 + #define strtoull(str,endptr,base) strlib->strtoull(str,endptr,base) + #endif + + #define e_mail_check(email) strlib->e_mail_check(email) + #define config_switch(str) strlib->config_switch(str) + #define safestrncpy(dst,src,n) strlib->safestrncpy(dst,src,n) + #define safestrnlen(string,maxlen) strlib->safestrnlen(string,maxlen) + #define safesnprintf(buf,sz,fmt,...) strlib->safesnprintf(buf,sz,fmt,##__VA_ARGS__) + #define strline(str,pos) strlib->strline(str,pos) + #define bin2hex(output,input,count) strlib->bin2hex(output,input,count) +#endif /* STRLIB_C */ #endif /* _STRLIB_H_ */ diff --git a/src/common/timer.c b/src/common/timer.c index c239a9d70..1ea1a0d1c 100644 --- a/src/common/timer.c +++ b/src/common/timer.c @@ -1,5 +1,6 @@ -// 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 #include "../common/cbasetypes.h" #include "../common/db.h" @@ -62,7 +63,7 @@ struct timer_func_list { } *tfl_root = NULL; /// Sets the name of a timer function. -int add_timer_func_list(TimerFunc func, char* name) +int timer_add_func_list(TimerFunc func, char* name) { struct timer_func_list* tfl; @@ -70,9 +71,9 @@ int add_timer_func_list(TimerFunc func, char* name) for( tfl=tfl_root; tfl != NULL; tfl=tfl->next ) {// check suspicious cases if( func == tfl->func ) - ShowWarning("add_timer_func_list: duplicating function %p(%s) as %s.\n",tfl->func,tfl->name,name); + ShowWarning("timer_add_func_list: duplicating function %p(%s) as %s.\n",tfl->func,tfl->name,name); else if( strcmp(name,tfl->name) == 0 ) - ShowWarning("add_timer_func_list: function %p has the same name as %p(%s)\n",func,tfl->func,tfl->name); + ShowWarning("timer_add_func_list: function %p has the same name as %p(%s)\n",func,tfl->func,tfl->name); } CREATE(tfl,struct timer_func_list,1); tfl->next = tfl_root; @@ -137,8 +138,7 @@ static void rdtsc_calibrate(){ #endif /// platform-abstracted tick retrieval -static unsigned int tick(void) -{ +static unsigned int tick(void) { #if defined(WIN32) return GetTickCount(); #elif defined(ENABLE_RDTSC) @@ -163,28 +163,25 @@ static unsigned int tick(void) static unsigned int gettick_cache; static int gettick_count = 1; -unsigned int gettick_nocache(void) -{ +unsigned int timer_gettick_nocache(void) { gettick_count = TICK_CACHE; gettick_cache = tick(); return gettick_cache; } -unsigned int gettick(void) -{ +unsigned int timer_gettick(void) { return ( --gettick_count == 0 ) ? gettick_nocache() : gettick_cache; } ////////////////////////////// #else ////////////////////////////// // tick doesn't get cached -unsigned int gettick_nocache(void) +unsigned int timer_gettick_nocache(void) { return tick(); } -unsigned int gettick(void) -{ +unsigned int timer_gettick(void) { return tick(); } ////////////////////////////////////////////////////////////////////////// @@ -196,8 +193,7 @@ unsigned int gettick(void) *--------------------------------------*/ /// Adds a timer to the timer_heap -static void push_timer_heap(int tid) -{ +static void push_timer_heap(int tid) { BHEAP_ENSURE(timer_heap, 1, 256); BHEAP_PUSH(timer_heap, tid, DIFFTICK_MINTOPCMP); } @@ -207,8 +203,7 @@ static void push_timer_heap(int tid) *--------------------------*/ /// Returns a free timer id. -static int acquire_timer(void) -{ +static int acquire_timer(void) { int tid; // select a free timer @@ -240,8 +235,7 @@ static int acquire_timer(void) /// Starts a new timer that is deleted once it expires (single-use). /// Returns the timer's id. -int add_timer(unsigned int tick, TimerFunc func, int id, intptr_t data) -{ +int timer_add(unsigned int tick, TimerFunc func, int id, intptr_t data) { int tid; tid = acquire_timer(); @@ -258,13 +252,12 @@ int add_timer(unsigned int tick, TimerFunc func, int id, intptr_t data) /// Starts a new timer that automatically restarts itself (infinite loop until manually removed). /// Returns the timer's id, or INVALID_TIMER if it fails. -int add_timer_interval(unsigned int tick, TimerFunc func, int id, intptr_t data, int interval) +int timer_add_interval(unsigned int tick, TimerFunc func, int id, intptr_t data, int interval) { int tid; - if( interval < 1 ) - { - ShowError("add_timer_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())); + 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())); return INVALID_TIMER; } @@ -281,24 +274,20 @@ int add_timer_interval(unsigned int tick, TimerFunc func, int id, intptr_t data, } /// Retrieves internal timer data -const struct TimerData* get_timer(int tid) -{ +const struct TimerData* timer_get(int tid) { return ( tid >= 0 && tid < timer_data_num ) ? &timer_data[tid] : NULL; } /// Marks a timer specified by 'id' for immediate deletion once it expires. /// Param 'func' is used for debug/verification purposes. /// Returns 0 on success, < 0 on failure. -int delete_timer(int tid, TimerFunc func) -{ - if( tid < 0 || tid >= timer_data_num ) - { - ShowError("delete_timer error : no such timer %d (%p(%s))\n", tid, func, search_timer_func_list(func)); +int timer_delete(int tid, TimerFunc func) { + if( tid < 0 || tid >= timer_data_num ) { + ShowError("timer_delete error : no such timer %d (%p(%s))\n", tid, func, search_timer_func_list(func)); return -1; } - if( timer_data[tid].func != func ) - { - ShowError("delete_timer error : function mismatch %p(%s) != %p(%s)\n", timer_data[tid].func, search_timer_func_list(timer_data[tid].func), func, search_timer_func_list(func)); + if( timer_data[tid].func != func ) { + ShowError("timer_delete error : function mismatch %p(%s) != %p(%s)\n", timer_data[tid].func, search_timer_func_list(timer_data[tid].func), func, search_timer_func_list(func)); return -2; } @@ -310,22 +299,19 @@ int delete_timer(int tid, TimerFunc func) /// Adjusts a timer's expiration time. /// Returns the new tick value, or -1 if it fails. -int addtick_timer(int tid, unsigned int tick) -{ +int timer_addtick(int tid, unsigned int tick) { return 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). /// Returns the new tick value, or -1 if it fails. -int settick_timer(int tid, unsigned int tick) -{ +int timer_settick(int tid, unsigned int tick) { size_t i; // search timer position ARR_FIND(0, BHEAP_LENGTH(timer_heap), i, BHEAP_DATA(timer_heap)[i] == tid); - if( i == BHEAP_LENGTH(timer_heap) ) - { - ShowError("settick_timer: no such timer %d (%p(%s))\n", tid, timer_data[tid].func, search_timer_func_list(timer_data[tid].func)); + if( i == BHEAP_LENGTH(timer_heap) ) { + ShowError("timer_settick: no such timer %d (%p(%s))\n", tid, timer_data[tid].func, search_timer_func_list(timer_data[tid].func)); return -1; } @@ -344,13 +330,11 @@ int settick_timer(int tid, unsigned int tick) /// Executes all expired timers. /// Returns the value of the smallest non-expired timer (or 1 second if there aren't any). -int do_timer(unsigned int tick) -{ +int do_timer(unsigned int tick) { int diff = TIMER_MAX_INTERVAL; // return value // process all timers one by one - while( BHEAP_LENGTH(timer_heap) ) - { + while( BHEAP_LENGTH(timer_heap) ) { int tid = BHEAP_PEEK(timer_heap);// top element in heap (smallest tick) diff = DIFF_TICK(timer_data[tid].tick, tick); @@ -361,8 +345,7 @@ int do_timer(unsigned int tick) BHEAP_POP(timer_heap, DIFFTICK_MINTOPCMP); timer_data[tid].type |= TIMER_REMOVE_HEAP; - if( timer_data[tid].func ) - { + if( timer_data[tid].func ) { if( diff < -1000 ) // timer was delayed for more than 1 second, use current tick instead timer_data[tid].func(tid, tick, timer_data[tid].id, timer_data[tid].data); @@ -371,29 +354,27 @@ int do_timer(unsigned int tick) } // in the case the function didn't change anything... - if( timer_data[tid].type & TIMER_REMOVE_HEAP ) - { + if( timer_data[tid].type & TIMER_REMOVE_HEAP ) { timer_data[tid].type &= ~TIMER_REMOVE_HEAP; - switch( timer_data[tid].type ) - { - default: - case TIMER_ONCE_AUTODEL: - timer_data[tid].type = 0; - if (free_timer_list_pos >= free_timer_list_max) { - free_timer_list_max += 256; - RECREATE(free_timer_list,int,free_timer_list_max); - memset(free_timer_list + (free_timer_list_max - 256), 0, 256 * sizeof(int)); - } - free_timer_list[free_timer_list_pos++] = tid; - break; - case TIMER_INTERVAL: - if( DIFF_TICK(timer_data[tid].tick, tick) < -1000 ) - timer_data[tid].tick = tick + timer_data[tid].interval; - else - timer_data[tid].tick += timer_data[tid].interval; - push_timer_heap(tid); - break; + switch( timer_data[tid].type ) { + default: + case TIMER_ONCE_AUTODEL: + timer_data[tid].type = 0; + if (free_timer_list_pos >= free_timer_list_max) { + free_timer_list_max += 256; + RECREATE(free_timer_list,int,free_timer_list_max); + memset(free_timer_list + (free_timer_list_max - 256), 0, 256 * sizeof(int)); + } + free_timer_list[free_timer_list_pos++] = tid; + break; + case TIMER_INTERVAL: + if( DIFF_TICK(timer_data[tid].tick, tick) < -1000 ) + timer_data[tid].tick = tick + timer_data[tid].interval; + else + timer_data[tid].tick += timer_data[tid].interval; + push_timer_heap(tid); + break; } } } @@ -401,8 +382,7 @@ int do_timer(unsigned int tick) return cap_value(diff, TIMER_MIN_INTERVAL, TIMER_MAX_INTERVAL); } -unsigned long get_uptime(void) -{ +unsigned long timer_get_uptime(void) { return (unsigned long)difftime(time(NULL), start_time); } @@ -415,8 +395,7 @@ void timer_init(void) time(&start_time); } -void timer_final(void) -{ +void timer_final(void) { struct timer_func_list *tfl; struct timer_func_list *next; @@ -430,3 +409,15 @@ 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_delete; + addtick_timer = timer_addtick; + settick_timer = timer_settick; + get_uptime = timer_get_uptime; +} diff --git a/src/common/timer.h b/src/common/timer.h index d45c73d12..902679f51 100644 --- a/src/common/timer.h +++ b/src/common/timer.h @@ -1,5 +1,6 @@ -// 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 _TIMER_H_ #define _TIMER_H_ @@ -35,23 +36,26 @@ struct TimerData { // Function prototype declaration -unsigned int gettick(void); -unsigned int gettick_nocache(void); +int do_timer(unsigned int tick); +void timer_init(void); +void timer_final(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); +/* Hercules Renewal Phase One */ +unsigned int (*gettick) (void); +unsigned int (*gettick_nocache) (void); -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 timer_init(void); -void timer_final(void); +unsigned long (*get_uptime) (void); + +void timer_defaults(void); #endif /* _TIMER_H_ */ diff --git a/src/login/account_sql.c b/src/login/account_sql.c index 1d77f1975..565dd0460 100644 --- a/src/login/account_sql.c +++ b/src/login/account_sql.c @@ -1,5 +1,6 @@ -// 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 #include "../common/malloc.h" #include "../common/mmo.h" @@ -125,7 +126,7 @@ static bool account_db_sql_init(AccountDB* self) const char* database; const char* codepage; - db->accounts = Sql_Malloc(); + db->accounts = SQL->Malloc(); sql_handle = db->accounts; if( db->db_hostname[0] != '\0' ) @@ -147,15 +148,15 @@ static bool account_db_sql_init(AccountDB* self) codepage = db->global_codepage; } - if( SQL_ERROR == Sql_Connect(sql_handle, username, password, hostname, port, database) ) + if( SQL_ERROR == SQL->Connect(sql_handle, username, password, hostname, port, database) ) { Sql_ShowDebug(sql_handle); - Sql_Free(db->accounts); + SQL->Free(db->accounts); db->accounts = NULL; return false; } - if( codepage[0] != '\0' && SQL_ERROR == Sql_SetEncoding(sql_handle, codepage) ) + if( codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, codepage) ) Sql_ShowDebug(sql_handle); return true; @@ -166,7 +167,7 @@ static void account_db_sql_destroy(AccountDB* self) { AccountDB_SQL* db = (AccountDB_SQL*)self; - Sql_Free(db->accounts); + SQL->Free(db->accounts); db->accounts = NULL; aFree(db); } @@ -348,21 +349,21 @@ static bool account_db_sql_create(AccountDB* self, struct mmo_account* acc) char* data; size_t len; - if( SQL_SUCCESS != Sql_Query(sql_handle, "SELECT MAX(`account_id`)+1 FROM `%s`", db->account_db) ) + if( SQL_SUCCESS != SQL->Query(sql_handle, "SELECT MAX(`account_id`)+1 FROM `%s`", db->account_db) ) { Sql_ShowDebug(sql_handle); return false; } - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) { Sql_ShowDebug(sql_handle); - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return false; } - Sql_GetData(sql_handle, 0, &data, &len); + SQL->GetData(sql_handle, 0, &data, &len); account_id = ( data != NULL ) ? atoi(data) : 0; - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); if( account_id < START_ACCOUNT_NUM ) account_id = START_ACCOUNT_NUM; @@ -389,14 +390,14 @@ static bool account_db_sql_remove(AccountDB* self, const int account_id) Sql* sql_handle = db->accounts; bool result = false; - if( SQL_SUCCESS != Sql_QueryStr(sql_handle, "START TRANSACTION") - || SQL_SUCCESS != Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = %d", db->account_db, account_id) - || SQL_SUCCESS != Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = %d", db->accreg_db, account_id) ) + if( SQL_SUCCESS != SQL->QueryStr(sql_handle, "START TRANSACTION") + || SQL_SUCCESS != SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = %d", db->account_db, account_id) + || SQL_SUCCESS != SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = %d", db->accreg_db, account_id) ) Sql_ShowDebug(sql_handle); else result = true; - result &= ( SQL_SUCCESS == Sql_QueryStr(sql_handle, (result == true) ? "COMMIT" : "ROLLBACK") ); + result &= ( SQL_SUCCESS == SQL->QueryStr(sql_handle, (result == true) ? "COMMIT" : "ROLLBACK") ); return result; } @@ -424,30 +425,30 @@ static bool account_db_sql_load_str(AccountDB* self, struct mmo_account* acc, co int account_id; char* data; - Sql_EscapeString(sql_handle, esc_userid, userid); + SQL->EscapeString(sql_handle, esc_userid, userid); // get the list of account IDs for this user ID - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id` FROM `%s` WHERE `userid`= %s '%s'", + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id` FROM `%s` WHERE `userid`= %s '%s'", db->account_db, (db->case_sensitive ? "BINARY" : ""), esc_userid) ) { Sql_ShowDebug(sql_handle); return false; } - if( Sql_NumRows(sql_handle) > 1 ) + if( SQL->NumRows(sql_handle) > 1 ) {// serious problem - duplicit account ShowError("account_db_sql_load_str: multiple accounts found when retrieving data for account '%s'!\n", userid); - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return false; } - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) {// no such entry - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return false; } - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); return account_db_sql_load_num(self, acc, account_id); @@ -489,15 +490,15 @@ static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account char* data; // get next account ID - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id` FROM `%s` WHERE `account_id` > '%d' ORDER BY `account_id` ASC LIMIT 1", + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id` FROM `%s` WHERE `account_id` > '%d' ORDER BY `account_id` ASC LIMIT 1", db->account_db, iter->last_account_id) ) { Sql_ShowDebug(sql_handle); return false; } - if( SQL_SUCCESS == Sql_NextRow(sql_handle) && - SQL_SUCCESS == Sql_GetData(sql_handle, 0, &data, NULL) && + if( SQL_SUCCESS == SQL->NextRow(sql_handle) && + SQL_SUCCESS == SQL->GetData(sql_handle, 0, &data, NULL) && data != NULL ) {// get account data int account_id; @@ -505,11 +506,11 @@ static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account if( mmo_auth_fromsql(db, acc, account_id) ) { iter->last_account_id = account_id; - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return true; } } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return false; } @@ -521,7 +522,7 @@ static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int acc int i = 0; // retrieve login entry for the specified account - if( SQL_ERROR == Sql_Query(sql_handle, + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id`,`userid`,`user_pass`,`sex`,`email`,`group_id`,`state`,`unban_time`,`expiration_time`,`logincount`,`lastlogin`,`last_ip`,`birthdate`,`character_slots`,`pincode`,`pincode_change` FROM `%s` WHERE `account_id` = %d", db->account_db, account_id ) ) { @@ -529,49 +530,49 @@ static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int acc return false; } - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) {// no such entry - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return false; } - Sql_GetData(sql_handle, 0, &data, NULL); acc->account_id = atoi(data); - Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(acc->userid, data, sizeof(acc->userid)); - Sql_GetData(sql_handle, 2, &data, NULL); safestrncpy(acc->pass, data, sizeof(acc->pass)); - Sql_GetData(sql_handle, 3, &data, NULL); acc->sex = data[0]; - Sql_GetData(sql_handle, 4, &data, NULL); safestrncpy(acc->email, data, sizeof(acc->email)); - Sql_GetData(sql_handle, 5, &data, NULL); acc->group_id = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); acc->state = strtoul(data, NULL, 10); - Sql_GetData(sql_handle, 7, &data, NULL); acc->unban_time = atol(data); - Sql_GetData(sql_handle, 8, &data, NULL); acc->expiration_time = atol(data); - Sql_GetData(sql_handle, 9, &data, NULL); acc->logincount = strtoul(data, NULL, 10); - Sql_GetData(sql_handle, 10, &data, NULL); safestrncpy(acc->lastlogin, data, sizeof(acc->lastlogin)); - Sql_GetData(sql_handle, 11, &data, NULL); safestrncpy(acc->last_ip, data, sizeof(acc->last_ip)); - Sql_GetData(sql_handle, 12, &data, NULL); safestrncpy(acc->birthdate, data, sizeof(acc->birthdate)); - Sql_GetData(sql_handle, 13, &data, NULL); acc->char_slots = atoi(data); - Sql_GetData(sql_handle, 14, &data, NULL); safestrncpy(acc->pincode, data, sizeof(acc->pincode)); - Sql_GetData(sql_handle, 15, &data, NULL); acc->pincode_change = atol(data); + SQL->GetData(sql_handle, 0, &data, NULL); acc->account_id = atoi(data); + SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(acc->userid, data, sizeof(acc->userid)); + SQL->GetData(sql_handle, 2, &data, NULL); safestrncpy(acc->pass, data, sizeof(acc->pass)); + SQL->GetData(sql_handle, 3, &data, NULL); acc->sex = data[0]; + SQL->GetData(sql_handle, 4, &data, NULL); safestrncpy(acc->email, data, sizeof(acc->email)); + SQL->GetData(sql_handle, 5, &data, NULL); acc->group_id = atoi(data); + SQL->GetData(sql_handle, 6, &data, NULL); acc->state = strtoul(data, NULL, 10); + SQL->GetData(sql_handle, 7, &data, NULL); acc->unban_time = atol(data); + SQL->GetData(sql_handle, 8, &data, NULL); acc->expiration_time = atol(data); + SQL->GetData(sql_handle, 9, &data, NULL); acc->logincount = strtoul(data, NULL, 10); + SQL->GetData(sql_handle, 10, &data, NULL); safestrncpy(acc->lastlogin, data, sizeof(acc->lastlogin)); + SQL->GetData(sql_handle, 11, &data, NULL); safestrncpy(acc->last_ip, data, sizeof(acc->last_ip)); + SQL->GetData(sql_handle, 12, &data, NULL); safestrncpy(acc->birthdate, data, sizeof(acc->birthdate)); + SQL->GetData(sql_handle, 13, &data, NULL); acc->char_slots = atoi(data); + SQL->GetData(sql_handle, 14, &data, NULL); safestrncpy(acc->pincode, data, sizeof(acc->pincode)); + SQL->GetData(sql_handle, 15, &data, NULL); acc->pincode_change = atol(data); - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); // retrieve account regs for the specified user - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `str`,`value` FROM `%s` WHERE `type`='1' AND `account_id`='%d'", db->accreg_db, acc->account_id) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `str`,`value` FROM `%s` WHERE `type`='1' AND `account_id`='%d'", db->accreg_db, acc->account_id) ) { Sql_ShowDebug(sql_handle); return false; } - acc->account_reg2_num = (int)Sql_NumRows(sql_handle); + acc->account_reg2_num = (int)SQL->NumRows(sql_handle); - while( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + while( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { char* data; - Sql_GetData(sql_handle, 0, &data, NULL); safestrncpy(acc->account_reg2[i].str, data, sizeof(acc->account_reg2[i].str)); - Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(acc->account_reg2[i].value, data, sizeof(acc->account_reg2[i].value)); + SQL->GetData(sql_handle, 0, &data, NULL); safestrncpy(acc->account_reg2[i].str, data, sizeof(acc->account_reg2[i].str)); + SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(acc->account_reg2[i].value, data, sizeof(acc->account_reg2[i].value)); ++i; } - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); if( i != acc->account_reg2_num ) return false; @@ -590,7 +591,7 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo do { - if( SQL_SUCCESS != Sql_QueryStr(sql_handle, "START TRANSACTION") ) + if( SQL_SUCCESS != SQL->QueryStr(sql_handle, "START TRANSACTION") ) { Sql_ShowDebug(sql_handle); break; @@ -647,7 +648,7 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo } // remove old account regs - if( SQL_SUCCESS != Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `type`='1' AND `account_id`='%d'", db->accreg_db, acc->account_id) ) + if( SQL_SUCCESS != SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `type`='1' AND `account_id`='%d'", db->accreg_db, acc->account_id) ) { Sql_ShowDebug(sql_handle); break; @@ -680,7 +681,7 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo } while(0); // finally - result &= ( SQL_SUCCESS == Sql_QueryStr(sql_handle, (result == true) ? "COMMIT" : "ROLLBACK") ); + result &= ( SQL_SUCCESS == SQL->QueryStr(sql_handle, (result == true) ? "COMMIT" : "ROLLBACK") ); SqlStmt_Free(stmt); return result; diff --git a/src/login/ipban_sql.c b/src/login/ipban_sql.c index c75a1f956..701d3bc1d 100644 --- a/src/login/ipban_sql.c +++ b/src/login/ipban_sql.c @@ -1,5 +1,6 @@ -// 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 #include "../common/cbasetypes.h" #include "../common/db.h" @@ -73,14 +74,14 @@ void ipban_init(void) } // establish connections - sql_handle = Sql_Malloc(); - if( SQL_ERROR == Sql_Connect(sql_handle, username, password, hostname, port, database) ) + sql_handle = SQL->Malloc(); + if( SQL_ERROR == SQL->Connect(sql_handle, username, password, hostname, port, database) ) { Sql_ShowDebug(sql_handle); - Sql_Free(sql_handle); + SQL->Free(sql_handle); exit(EXIT_FAILURE); } - if( codepage[0] != '\0' && SQL_ERROR == Sql_SetEncoding(sql_handle, codepage) ) + if( codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, codepage) ) Sql_ShowDebug(sql_handle); if( login_config.ipban_cleanup_interval > 0 ) @@ -104,7 +105,7 @@ void ipban_final(void) ipban_cleanup(0,0,0,0); // always clean up on login-server stop // close connections - Sql_Free(sql_handle); + SQL->Free(sql_handle); sql_handle = NULL; } @@ -207,7 +208,7 @@ bool ipban_check(uint32 ip) if( !login_config.ipban ) return false;// ipban disabled - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT count(*) FROM `%s` WHERE `rtime` > NOW() AND (`list` = '%u.*.*.*' OR `list` = '%u.%u.*.*' OR `list` = '%u.%u.%u.*' OR `list` = '%u.%u.%u.%u')", + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT count(*) FROM `%s` WHERE `rtime` > NOW() AND (`list` = '%u.*.*.*' OR `list` = '%u.%u.*.*' OR `list` = '%u.%u.%u.*' OR `list` = '%u.%u.%u.%u')", ipban_table, p[3], p[3], p[2], p[3], p[2], p[1], p[3], p[2], p[1], p[0]) ) { Sql_ShowDebug(sql_handle); @@ -215,12 +216,12 @@ bool ipban_check(uint32 ip) return true; } - if( SQL_ERROR == Sql_NextRow(sql_handle) ) + if( SQL_ERROR == SQL->NextRow(sql_handle) ) return true;// Shouldn't happen, but just in case... - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); matches = atoi(data); - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); return( matches > 0 ); } @@ -239,7 +240,7 @@ void ipban_log(uint32 ip) if( failures >= login_config.dynamic_pass_failure_ban_limit ) { uint8* p = (uint8*)&ip; - if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s`(`list`,`btime`,`rtime`,`reason`) VALUES ('%u.%u.%u.*', NOW() , NOW() + INTERVAL %d MINUTE ,'Password error ban')", + if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s`(`list`,`btime`,`rtime`,`reason`) VALUES ('%u.%u.%u.*', NOW() , NOW() + INTERVAL %d MINUTE ,'Password error ban')", ipban_table, p[3], p[2], p[1], login_config.dynamic_pass_failure_ban_duration) ) Sql_ShowDebug(sql_handle); } @@ -251,7 +252,7 @@ int ipban_cleanup(int tid, unsigned int tick, int id, intptr_t data) if( !login_config.ipban ) return 0;// ipban disabled - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `ipbanlist` WHERE `rtime` <= NOW()") ) + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `ipbanlist` WHERE `rtime` <= NOW()") ) Sql_ShowDebug(sql_handle); return 0; diff --git a/src/login/loginlog_sql.c b/src/login/loginlog_sql.c index d61172697..231ac783b 100644 --- a/src/login/loginlog_sql.c +++ b/src/login/loginlog_sql.c @@ -1,5 +1,6 @@ -// 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 #include "../common/cbasetypes.h" #include "../common/mmo.h" @@ -37,16 +38,16 @@ unsigned long loginlog_failedattempts(uint32 ip, unsigned int minutes) if( !enabled ) return 0; - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT count(*) FROM `%s` WHERE `ip` = '%s' AND `rcode` = '1' AND `time` > NOW() - INTERVAL %d MINUTE", + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT count(*) FROM `%s` WHERE `ip` = '%s' AND `rcode` = '1' AND `time` > NOW() - INTERVAL %d MINUTE", log_login_db, ip2str(ip,NULL), minutes) )// how many times failed account? in one ip. Sql_ShowDebug(sql_handle); - if( SQL_SUCCESS == Sql_NextRow(sql_handle) ) + if( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { char* data; - Sql_GetData(sql_handle, 0, &data, NULL); + SQL->GetData(sql_handle, 0, &data, NULL); failures = strtoul(data, NULL, 10); - Sql_FreeResult(sql_handle); + SQL->FreeResult(sql_handle); } return failures; } @@ -64,10 +65,10 @@ void login_log(uint32 ip, const char* username, int rcode, const char* message) if( !enabled ) return; - Sql_EscapeStringLen(sql_handle, esc_username, username, strnlen(username, NAME_LENGTH)); - Sql_EscapeStringLen(sql_handle, esc_message, message, strnlen(message, 255)); + SQL->EscapeStringLen(sql_handle, esc_username, username, strnlen(username, NAME_LENGTH)); + SQL->EscapeStringLen(sql_handle, esc_message, message, strnlen(message, 255)); - retcode = Sql_Query(sql_handle, + retcode = SQL->Query(sql_handle, "INSERT INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '%s', '%s', '%d', '%s')", log_login_db, ip2str(ip,NULL), esc_username, rcode, esc_message); @@ -103,16 +104,16 @@ bool loginlog_init(void) codepage = global_codepage; } - sql_handle = Sql_Malloc(); + sql_handle = SQL->Malloc(); - if( SQL_ERROR == Sql_Connect(sql_handle, username, password, hostname, port, database) ) + if( SQL_ERROR == SQL->Connect(sql_handle, username, password, hostname, port, database) ) { Sql_ShowDebug(sql_handle); - Sql_Free(sql_handle); + SQL->Free(sql_handle); exit(EXIT_FAILURE); } - if( codepage[0] != '\0' && SQL_ERROR == Sql_SetEncoding(sql_handle, codepage) ) + if( codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, codepage) ) Sql_ShowDebug(sql_handle); enabled = true; @@ -122,7 +123,7 @@ bool loginlog_init(void) bool loginlog_final(void) { - Sql_Free(sql_handle); + SQL->Free(sql_handle); sql_handle = NULL; return true; } diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 6ffceac8e..428113c68 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -581,70 +581,70 @@ ACMD(who) display_type = 3; level = pc_get_group_level(sd); - StringBuf_Init(&buf); + StrBuf->Init(&buf); iter = mapit_getallusers(); - for (pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter)) { + for (pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter)) { if (!((pc_has_permission(pl_sd, PC_PERM_HIDE_SESSION) || (pl_sd->sc.option & OPTION_INVISIBLE)) && pc_get_group_level(pl_sd) > level)) { // you can look only lower or same level if (stristr(pl_sd->status.name, player_name) == NULL // search with no case sensitive || (map_id >= 0 && pl_sd->bl.m != map_id)) continue; switch (display_type) { case 2: { - StringBuf_Printf(&buf, msg_txt(343), pl_sd->status.name); // "Name: %s " + StrBuf->Printf(&buf, msg_txt(343), pl_sd->status.name); // "Name: %s " if (pc_get_group_id(pl_sd) > 0) // Player title, if exists - StringBuf_Printf(&buf, msg_txt(344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) " - StringBuf_Printf(&buf, msg_txt(347), pl_sd->status.base_level, pl_sd->status.job_level, + StrBuf->Printf(&buf, msg_txt(344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) " + StrBuf->Printf(&buf, msg_txt(347), pl_sd->status.base_level, pl_sd->status.job_level, job_name(pl_sd->status.class_)); // "| Lv:%d/%d | Job: %s" break; } case 3: { if (pc_has_permission(sd, PC_PERM_WHO_DISPLAY_AID)) - StringBuf_Printf(&buf, msg_txt(912), pl_sd->status.char_id, pl_sd->status.account_id); // "(CID:%d/AID:%d) " - StringBuf_Printf(&buf, msg_txt(343), pl_sd->status.name); // "Name: %s " + StrBuf->Printf(&buf, msg_txt(912), pl_sd->status.char_id, pl_sd->status.account_id); // "(CID:%d/AID:%d) " + StrBuf->Printf(&buf, msg_txt(343), pl_sd->status.name); // "Name: %s " if (pc_get_group_id(pl_sd) > 0) // Player title, if exists - StringBuf_Printf(&buf, msg_txt(344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) " - StringBuf_Printf(&buf, msg_txt(348), mapindex_id2name(pl_sd->mapindex), pl_sd->bl.x, pl_sd->bl.y); // "| Location: %s %d %d" + StrBuf->Printf(&buf, msg_txt(344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) " + StrBuf->Printf(&buf, msg_txt(348), mapindex_id2name(pl_sd->mapindex), pl_sd->bl.x, pl_sd->bl.y); // "| Location: %s %d %d" break; } default: { struct party_data *p = party_search(pl_sd->status.party_id); struct guild *g = pl_sd->guild; - StringBuf_Printf(&buf, msg_txt(343), pl_sd->status.name); // "Name: %s " + StrBuf->Printf(&buf, msg_txt(343), pl_sd->status.name); // "Name: %s " if (pc_get_group_id(pl_sd) > 0) // Player title, if exists - StringBuf_Printf(&buf, msg_txt(344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) " + StrBuf->Printf(&buf, msg_txt(344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) " if (p != NULL) - StringBuf_Printf(&buf, msg_txt(345), p->party.name); // " | Party: '%s'" + StrBuf->Printf(&buf, msg_txt(345), p->party.name); // " | Party: '%s'" if (g != NULL) - StringBuf_Printf(&buf, msg_txt(346), g->name); // " | Guild: '%s'" + StrBuf->Printf(&buf, msg_txt(346), g->name); // " | Guild: '%s'" break; } } - clif->message(fd, StringBuf_Value(&buf)); - StringBuf_Clear(&buf); + clif->message(fd, StrBuf->Value(&buf)); + StrBuf->Clear(&buf); count++; } } - mapit_free(iter); + mapit->free(iter); if (map_id < 0) { if (count == 0) - StringBuf_Printf(&buf, msg_txt(28)); // No player found. + StrBuf->Printf(&buf, msg_txt(28)); // No player found. else if (count == 1) - StringBuf_Printf(&buf, msg_txt(29)); // 1 player found. + StrBuf->Printf(&buf, msg_txt(29)); // 1 player found. else - StringBuf_Printf(&buf, msg_txt(30), count); // %d players found. + StrBuf->Printf(&buf, msg_txt(30), count); // %d players found. } else { if (count == 0) - StringBuf_Printf(&buf, msg_txt(54), map[map_id].name); // No player found in map '%s'. + StrBuf->Printf(&buf, msg_txt(54), map[map_id].name); // No player found in map '%s'. else if (count == 1) - StringBuf_Printf(&buf, msg_txt(55), map[map_id].name); // 1 player found in map '%s'. + StrBuf->Printf(&buf, msg_txt(55), map[map_id].name); // 1 player found in map '%s'. else - StringBuf_Printf(&buf, msg_txt(56), count, map[map_id].name); // %d players found in map '%s'. + StrBuf->Printf(&buf, msg_txt(56), count, map[map_id].name); // %d players found in map '%s'. } - clif->message(fd, StringBuf_Value(&buf)); - StringBuf_Destroy(&buf); + clif->message(fd, StrBuf->Value(&buf)); + StrBuf->Destroy(&buf); return true; } @@ -677,7 +677,7 @@ ACMD(whogm) level = pc_get_group_level(sd); iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { pl_level = pc_get_group_level(pl_sd); if (!pl_level) @@ -720,7 +720,7 @@ ACMD(whogm) clif->message(fd, atcmd_output); count++; } - mapit_free(iter); + mapit->free(iter); if (count == 0) clif->message(fd, msg_txt(150)); // No GM found. @@ -1427,20 +1427,20 @@ ACMD(help) { StringBuf buf; bool has_aliases = false; - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, msg_txt(990)); // Available aliases: + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, msg_txt(990)); // Available aliases: command_info = get_atcommandinfo_byname(command_name); iter = db_iterator(atcommand->alias_db); for (alias_info = dbi_first(iter); dbi_exists(iter); alias_info = dbi_next(iter)) { if (alias_info->command == command_info) { - StringBuf_Printf(&buf, " %s", alias_info->alias); + StrBuf->Printf(&buf, " %s", alias_info->alias); has_aliases = true; } } dbi_destroy(iter); if (has_aliases) - clif->message(fd, StringBuf_Value(&buf)); - StringBuf_Destroy(&buf); + clif->message(fd, StrBuf->Value(&buf)); + StrBuf->Destroy(&buf); } // Display help contents @@ -2936,7 +2936,7 @@ ACMD(doom) nullpo_retr(-1, sd); iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if (pl_sd->fd != fd && pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) { @@ -2945,7 +2945,7 @@ ACMD(doom) clif->message(pl_sd->fd, msg_txt(61)); // The holy messenger has given judgement. } } - mapit_free(iter); + mapit->free(iter); clif->message(fd, msg_txt(62)); // Judgement was made. @@ -2963,7 +2963,7 @@ ACMD(doommap) nullpo_retr(-1, sd); iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if (pl_sd->fd != fd && sd->bl.m == pl_sd->bl.m && pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) { @@ -2972,7 +2972,7 @@ ACMD(doommap) clif->message(pl_sd->fd, msg_txt(61)); // The holy messenger has given judgement. } } - mapit_free(iter); + mapit->free(iter); clif->message(fd, msg_txt(62)); // Judgement was made. @@ -3001,10 +3001,10 @@ ACMD(raise) nullpo_retr(-1, sd); iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) if( pc_isdead(pl_sd) ) atcommand_raise_sub(pl_sd); - mapit_free(iter); + mapit->free(iter); clif->message(fd, msg_txt(64)); // Mercy has been granted. @@ -3022,10 +3022,10 @@ ACMD(raisemap) nullpo_retr(-1, sd); iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) if (sd->bl.m == pl_sd->bl.m && pc_isdead(pl_sd) ) atcommand_raise_sub(pl_sd); - mapit_free(iter); + mapit->free(iter); clif->message(fd, msg_txt(64)); // Mercy has been granted. @@ -3074,14 +3074,14 @@ ACMD(kickall) nullpo_retr(-1, sd); iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if (pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) { // you can kick only lower or same gm level if (sd->status.account_id != pl_sd->status.account_id) clif->GM_kick(NULL, pl_sd); } } - mapit_free(iter); + mapit->free(iter); clif->message(fd, msg_txt(195)); // All players have been kicked! @@ -3431,7 +3431,7 @@ ACMD(recallall) count = 0; iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if (sd->status.account_id != pl_sd->status.account_id && pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) { @@ -3448,7 +3448,7 @@ ACMD(recallall) } } } - mapit_free(iter); + mapit->free(iter); clif->message(fd, msg_txt(92)); // All characters recalled! if (count) { @@ -3494,7 +3494,7 @@ ACMD(guildrecall) count = 0; iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if (sd->status.account_id != pl_sd->status.account_id && pl_sd->status.guild_id == g->guild_id) { @@ -3506,7 +3506,7 @@ ACMD(guildrecall) pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN); } } - mapit_free(iter); + mapit->free(iter); sprintf(atcmd_output, msg_txt(93), g->name); // All online characters of the %s guild have been recalled to your position. clif->message(fd, atcmd_output); @@ -3553,7 +3553,7 @@ ACMD(partyrecall) count = 0; iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if (sd->status.account_id != pl_sd->status.account_id && pl_sd->status.party_id == p->party.party_id) { @@ -3565,7 +3565,7 @@ ACMD(partyrecall) pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN); } } - mapit_free(iter); + mapit->free(iter); sprintf(atcmd_output, msg_txt(95), p->party.name); // All online characters of the %s party have been recalled to your position. clif->message(fd, atcmd_output); @@ -3792,7 +3792,7 @@ ACMD(mapinfo) { // count chats (for initial message) chat_num = 0; iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) { + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if( pl_sd->mapindex == m_index ) { if( pl_sd->state.vending ) vend_num++; @@ -3800,7 +3800,7 @@ ACMD(mapinfo) { chat_num++; } } - mapit_free(iter); + mapit->free(iter); sprintf(atcmd_output, msg_txt(1040), mapname, map[m_id].zone->name, map[m_id].users, map[m_id].npc_num, chat_num, vend_num); // Map: %s (Zone:%s) | Players: %d | NPCs: %d | Chats: %d | Vendings: %d clif->message(fd, atcmd_output); @@ -3935,7 +3935,7 @@ ACMD(mapinfo) { case 1: clif->message(fd, msg_txt(1098)); // ----- Players in Map ----- iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if (pl_sd->mapindex == m_index) { sprintf(atcmd_output, msg_txt(1099), // Player '%s' (session #%d) | Location: %d,%d @@ -3943,7 +3943,7 @@ ACMD(mapinfo) { clif->message(fd, atcmd_output); } } - mapit_free(iter); + mapit->free(iter); break; case 2: clif->message(fd, msg_txt(1100)); // ----- NPCs in Map ----- @@ -3974,7 +3974,7 @@ ACMD(mapinfo) { case 3: clif->message(fd, msg_txt(1113)); // ----- Chats in Map ----- iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if ((cd = (struct chat_data*)map_id2bl(pl_sd->chatID)) != NULL && pl_sd->mapindex == m_index && @@ -3988,7 +3988,7 @@ ACMD(mapinfo) { clif->message(fd, atcmd_output); } } - mapit_free(iter); + mapit->free(iter); break; default: // normally impossible to arrive here clif->message(fd, msg_txt(1118)); // Please enter at least one valid list number (usage: @mapinfo <0-3> ). @@ -4778,9 +4778,9 @@ ACMD(disguiseall) } iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) pc_disguise(pl_sd, mob_id); - mapit_free(iter); + mapit->free(iter); clif->message(fd, msg_txt(122)); // Disguise applied. return true; @@ -4860,10 +4860,10 @@ ACMD(undisguiseall) { nullpo_retr(-1, sd); iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) if( pl_sd->disguise != -1 ) pc_disguise(pl_sd, -1); - mapit_free(iter); + mapit->free(iter); clif->message(fd, msg_txt(124)); // Undisguise applied. @@ -6088,7 +6088,7 @@ ACMD(mobsearch) it = mapit_geteachmob(); for(;;) { - TBL_MOB* md = (TBL_MOB*)mapit_next(it); + TBL_MOB* md = (TBL_MOB*)mapit->next(it); if( md == NULL ) break;// no more mobs @@ -6104,7 +6104,7 @@ ACMD(mobsearch) snprintf(atcmd_output, sizeof(atcmd_output), "%2d[%s] %s", number, "dead", md->name); clif->message(fd, atcmd_output); } - mapit_free(it); + mapit->free(it); return true; } @@ -6270,7 +6270,7 @@ ACMD(users) iter = mapit_getallusers(); for(;;) { - struct map_session_data* sd2 = (struct map_session_data*)mapit_next(iter); + struct map_session_data* sd2 = (struct map_session_data*)mapit->next(iter); if( sd2 == NULL ) break;// no more users @@ -6280,7 +6280,7 @@ ACMD(users) if( users[sd2->mapindex] < INT_MAX ) ++users[sd2->mapindex]; if( users_all < INT_MAX ) ++users_all; } - mapit_free(iter); + mapit->free(iter); // display results for each map for( i = 0; i < MAX_MAPINDEX; ++i ) @@ -6564,9 +6564,9 @@ ACMD(refreshall) nullpo_retr(-1, sd); iter = mapit_getallusers(); - for (iter_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); iter_sd = (TBL_PC*)mapit_next(iter)) + for (iter_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); iter_sd = (TBL_PC*)mapit->next(iter)) clif->refresh(iter_sd); - mapit_free(iter); + mapit->free(iter); return true; } @@ -6808,7 +6808,7 @@ ACMD(showmobs) it = mapit_geteachmob(); for(;;) { - TBL_MOB* md = (TBL_MOB*)mapit_next(it); + TBL_MOB* md = (TBL_MOB*)mapit->next(it); if( md == NULL ) break;// no more mobs @@ -6824,7 +6824,7 @@ ACMD(showmobs) ++number; clif->viewpoint(sd, 1, 0, md->bl.x, md->bl.y, number, 0xFFFFFF); } - mapit_free(it); + mapit->free(it); return true; } @@ -7444,7 +7444,7 @@ ACMD(sizeall) size = cap_value(size,0,2); iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) { + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if( pl_sd->state.size != size ) { if( pl_sd->state.size ) { pl_sd->state.size = SZ_SMALL; @@ -7458,7 +7458,7 @@ ACMD(sizeall) clif->specialeffect(&pl_sd->bl,422,AREA); } } - mapit_free(iter); + mapit->free(iter); clif->message(fd, msg_txt(1303)); // Size change applied. return true; @@ -8124,7 +8124,7 @@ ACMD(itemlist) else return 1; - StringBuf_Init(&buf); + StrBuf->Init(&buf); count = 0; // total slots occupied counter = 0; // total items found @@ -8141,15 +8141,15 @@ ACMD(itemlist) if( count == 1 ) { - StringBuf_Printf(&buf, msg_txt(1332), location, sd->status.name); // ------ %s items list of '%s' ------ - clif->message(fd, StringBuf_Value(&buf)); - StringBuf_Clear(&buf); + StrBuf->Printf(&buf, msg_txt(1332), location, sd->status.name); // ------ %s items list of '%s' ------ + clif->message(fd, StrBuf->Value(&buf)); + StrBuf->Clear(&buf); } if( it->refine ) - StringBuf_Printf(&buf, "%d %s %+d (%s, id: %d)", it->amount, itd->jname, it->refine, itd->name, it->nameid); + StrBuf->Printf(&buf, "%d %s %+d (%s, id: %d)", it->amount, itd->jname, it->refine, itd->name, it->nameid); else - StringBuf_Printf(&buf, "%d %s (%s, id: %d)", it->amount, itd->jname, itd->name, it->nameid); + StrBuf->Printf(&buf, "%d %s (%s, id: %d)", it->amount, itd->jname, itd->name, it->nameid); if( it->equip ) { @@ -8185,28 +8185,28 @@ ACMD(itemlist) strcat(equipstr, msg_txt(1347)); // lower/mid/top head, // remove final ', ' equipstr[strlen(equipstr) - 2] = '\0'; - StringBuf_AppendStr(&buf, equipstr); + StrBuf->AppendStr(&buf, equipstr); } - clif->message(fd, StringBuf_Value(&buf)); - StringBuf_Clear(&buf); + clif->message(fd, StrBuf->Value(&buf)); + StrBuf->Clear(&buf); if( it->card[0] == CARD0_PET ) {// pet egg if (it->card[3]) - StringBuf_Printf(&buf, msg_txt(1348), (unsigned int)MakeDWord(it->card[1], it->card[2])); // -> (pet egg, pet id: %u, named) + StrBuf->Printf(&buf, msg_txt(1348), (unsigned int)MakeDWord(it->card[1], it->card[2])); // -> (pet egg, pet id: %u, named) else - StringBuf_Printf(&buf, msg_txt(1349), (unsigned int)MakeDWord(it->card[1], it->card[2])); // -> (pet egg, pet id: %u, unnamed) + StrBuf->Printf(&buf, msg_txt(1349), (unsigned int)MakeDWord(it->card[1], it->card[2])); // -> (pet egg, pet id: %u, unnamed) } else if(it->card[0] == CARD0_FORGE) {// forged item - StringBuf_Printf(&buf, msg_txt(1350), (unsigned int)MakeDWord(it->card[2], it->card[3]), it->card[1]>>8, it->card[1]&0x0f); // -> (crafted item, creator id: %u, star crumbs %d, element %d) + StrBuf->Printf(&buf, msg_txt(1350), (unsigned int)MakeDWord(it->card[2], it->card[3]), it->card[1]>>8, it->card[1]&0x0f); // -> (crafted item, creator id: %u, star crumbs %d, element %d) } else if(it->card[0] == CARD0_CREATE) {// created item - StringBuf_Printf(&buf, msg_txt(1351), (unsigned int)MakeDWord(it->card[2], it->card[3])); // -> (produced item, creator id: %u) + StrBuf->Printf(&buf, msg_txt(1351), (unsigned int)MakeDWord(it->card[2], it->card[3])); // -> (produced item, creator id: %u) } else {// normal item @@ -8222,32 +8222,32 @@ ACMD(itemlist) counter2++; if( counter2 == 1 ) - StringBuf_AppendStr(&buf, msg_txt(1352)); // -> (card(s): + StrBuf->AppendStr(&buf, msg_txt(1352)); // -> (card(s): if( counter2 != 1 ) - StringBuf_AppendStr(&buf, ", "); + StrBuf->AppendStr(&buf, ", "); - StringBuf_Printf(&buf, "#%d %s (id: %d)", counter2, card->jname, card->nameid); + StrBuf->Printf(&buf, "#%d %s (id: %d)", counter2, card->jname, card->nameid); } if( counter2 > 0 ) - StringBuf_AppendStr(&buf, ")"); + StrBuf->AppendStr(&buf, ")"); } - if( StringBuf_Length(&buf) > 0 ) - clif->message(fd, StringBuf_Value(&buf)); + if( StrBuf->Length(&buf) > 0 ) + clif->message(fd, StrBuf->Value(&buf)); - StringBuf_Clear(&buf); + StrBuf->Clear(&buf); } if( count == 0 ) - StringBuf_Printf(&buf, msg_txt(1353), location); // No item found in this player's %s. + StrBuf->Printf(&buf, msg_txt(1353), location); // No item found in this player's %s. else - StringBuf_Printf(&buf, msg_txt(1354), counter, count, location); // %d item(s) found in %d %s slots. + StrBuf->Printf(&buf, msg_txt(1354), counter, count, location); // %d item(s) found in %d %s slots. - clif->message(fd, StringBuf_Value(&buf)); + clif->message(fd, StrBuf->Value(&buf)); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); return true; } diff --git a/src/map/chrif.c b/src/map/chrif.c index eed7ba2a6..c5ff16713 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -1509,13 +1509,13 @@ int send_users_tochar(void) { iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) { + for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { WFIFOL(char_fd,6+8*i) = sd->status.account_id; WFIFOL(char_fd,6+8*i+4) = sd->status.char_id; i++; } - mapit_free(iter); + mapit->free(iter); WFIFOW(char_fd,2) = 6 + 8*users; WFIFOW(char_fd,4) = users; diff --git a/src/map/clif.c b/src/map/clif.c index 4edb1541d..06f180a35 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -336,24 +336,24 @@ int clif_send(const void* buf, int len, struct block_list* bl, enum send_target case ALL_CLIENT: //All player clients. iter = mapit_getallusers(); - while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL ) { + while( (tsd = (TBL_PC*)mapit->next(iter)) != NULL ) { WFIFOHEAD(tsd->fd, len); memcpy(WFIFOP(tsd->fd,0), buf, len); WFIFOSET(tsd->fd,len); } - mapit_free(iter); + mapit->free(iter); break; case ALL_SAMEMAP: //All players on the same map iter = mapit_getallusers(); - while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL ) { + while( (tsd = (TBL_PC*)mapit->next(iter)) != NULL ) { if( bl->m == tsd->bl.m ) { WFIFOHEAD(tsd->fd, len); memcpy(WFIFOP(tsd->fd,0), buf, len); WFIFOSET(tsd->fd,len); } } - mapit_free(iter); + mapit->free(iter); break; case AREA: @@ -431,14 +431,14 @@ int clif_send(const void* buf, int len, struct block_list* bl, enum send_target break; iter = mapit_getallusers(); - while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL ) { + while( (tsd = (TBL_PC*)mapit->next(iter)) != NULL ) { if( tsd->partyspy == p->party.party_id ) { WFIFOHEAD(tsd->fd, len); memcpy(WFIFOP(tsd->fd,0), buf, len); WFIFOSET(tsd->fd,len); } } - mapit_free(iter); + mapit->free(iter); } break; @@ -447,7 +447,7 @@ int clif_send(const void* buf, int len, struct block_list* bl, enum send_target if (!sd || !sd->duel_group) break; //Invalid usage. iter = mapit_getallusers(); - while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL ) { + while( (tsd = (TBL_PC*)mapit->next(iter)) != NULL ) { if( type == DUEL_WOS && bl->id == tsd->bl.id ) continue; if( sd->duel_group == tsd->duel_group ) { @@ -456,7 +456,7 @@ int clif_send(const void* buf, int len, struct block_list* bl, enum send_target WFIFOSET(tsd->fd,len); } } - mapit_free(iter); + mapit->free(iter); break; case SELF: @@ -508,14 +508,14 @@ int clif_send(const void* buf, int len, struct block_list* bl, enum send_target break; iter = mapit_getallusers(); - while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL ) { + while( (tsd = (TBL_PC*)mapit->next(iter)) != NULL ) { if( tsd->guildspy == g->guild_id ) { WFIFOHEAD(tsd->fd, len); memcpy(WFIFOP(tsd->fd,0), buf, len); WFIFOSET(tsd->fd,len); } } - mapit_free(iter); + mapit->free(iter); } break; @@ -1311,12 +1311,12 @@ void clif_weather(int16 m) struct map_session_data *sd=NULL; iter = mapit_getallusers(); - for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) ) + for( sd = (struct map_session_data*)mapit->first(iter); mapit->exists(iter); sd = (struct map_session_data*)mapit->next(iter) ) { if( sd->bl.m == m ) clif_weather_check(sd); } - mapit_free(iter); + mapit->free(iter); } /** * Main function to spawn a unit on the client (player/mob/pet/etc) diff --git a/src/map/guild.c b/src/map/guild.c index 5e8a5897a..a028cb201 100644 --- a/src/map/guild.c +++ b/src/map/guild.c @@ -1,5 +1,6 @@ -// 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 #include "../common/cbasetypes.h" #include "../common/timer.h" @@ -457,7 +458,7 @@ int guild_check_member(struct guild *g) nullpo_ret(g); iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) + for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { if( sd->status.guild_id != g->guild_id ) continue; @@ -469,7 +470,7 @@ int guild_check_member(struct guild *g) ShowWarning("guild: check_member %d[%s] is not member\n",sd->status.account_id,sd->status.name); } } - mapit_free(iter); + mapit->free(iter); return 0; } @@ -481,11 +482,11 @@ int guild_recv_noinfo(int guild_id) struct s_mapiterator* iter; iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) { + for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { if( sd->status.guild_id == guild_id ) sd->status.guild_id = 0; // erase guild } - mapit_free(iter); + mapit->free(iter); return 0; } @@ -523,7 +524,7 @@ int guild_recv_info(struct guild *sg) { tg[i] = guild_search(sg->alliance[i].guild_id); } - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) { + for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { if( sd->status.guild_id ) { if( sd->status.guild_id == sg->guild_id ) { clif->chsys_join(channel,sd); @@ -543,7 +544,7 @@ int guild_recv_info(struct guild *sg) { } } - mapit_free(iter); + mapit->free(iter); } @@ -2197,10 +2198,10 @@ void do_init_guild(void) { guild_flags_count = 0; - sv_readdb(db_path, "castle_db.txt", ',', 4, 5, -1, &guild_read_castledb); + sv->readdb(db_path, "castle_db.txt", ',', 4, 5, -1, &guild_read_castledb); memset(guild_skill_tree,0,sizeof(guild_skill_tree)); - sv_readdb(db_path, "guild_skill_tree.txt", ',', 2+MAX_GUILD_SKILL_REQUIRE*2, 2+MAX_GUILD_SKILL_REQUIRE*2, -1, &guild_read_guildskill_tree_db); //guild skill tree [Komurka] + sv->readdb(db_path, "guild_skill_tree.txt", ',', 2+MAX_GUILD_SKILL_REQUIRE*2, 2+MAX_GUILD_SKILL_REQUIRE*2, -1, &guild_read_guildskill_tree_db); //guild skill tree [Komurka] add_timer_func_list(guild_payexp_timer,"guild_payexp_timer"); add_timer_func_list(guild_send_xy_timer, "guild_send_xy_timer"); diff --git a/src/map/homunculus.c b/src/map/homunculus.c index 026b9a86c..e306e7f60 100644 --- a/src/map/homunculus.c +++ b/src/map/homunculus.c @@ -1134,7 +1134,7 @@ void homunculus_read_db(void) { } } - sv_readdb(db_path, filename[i], ',', 50, 50, MAX_HOMUNCULUS_CLASS, homun->read_db_sub); + sv->readdb(db_path, filename[i], ',', 50, 50, MAX_HOMUNCULUS_CLASS, homun->read_db_sub); } } @@ -1180,7 +1180,7 @@ bool homunculus_read_skill_db_sub(char* split[], int columns, int current) { void homunculus_skill_db_read(void) { memset(homun->skill_tree,0,sizeof(homun->skill_tree)); - sv_readdb(db_path, "homun_skill_tree.txt", ',', 13, 15, -1, homun->read_skill_db_sub); + sv->readdb(db_path, "homun_skill_tree.txt", ',', 13, 15, -1, homun->read_skill_db_sub); } diff --git a/src/map/itemdb.c b/src/map/itemdb.c index 0b4419e0c..590a0cf57 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -1,5 +1,6 @@ -// 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 #include "../common/nullpo.h" #include "../common/malloc.h" @@ -1236,19 +1237,19 @@ static int itemdb_read_sqldb(void) { uint32 lines = 0, count = 0; // retrieve all rows from the item database - if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT * FROM `%s`", item_db_name[fi]) ) { + if( SQL_ERROR == SQL->Query(mmysql_handle, "SELECT * FROM `%s`", item_db_name[fi]) ) { Sql_ShowDebug(mmysql_handle); continue; } // process rows one by one - while( SQL_SUCCESS == Sql_NextRow(mmysql_handle) ) {// wrap the result into a TXT-compatible format + while( SQL_SUCCESS == SQL->NextRow(mmysql_handle) ) {// wrap the result into a TXT-compatible format char* str[22]; char* dummy = ""; int i; ++lines; for( i = 0; i < 22; ++i ) { - Sql_GetData(mmysql_handle, i, &str[i], NULL); + SQL->GetData(mmysql_handle, i, &str[i], NULL); if( str[i] == NULL ) str[i] = dummy; // get rid of NULL columns } @@ -1259,7 +1260,7 @@ static int itemdb_read_sqldb(void) { } // free the query result - Sql_FreeResult(mmysql_handle); + SQL->FreeResult(mmysql_handle); ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, item_db_name[fi]); } @@ -1295,19 +1296,19 @@ uint64 itemdb_unique_id(int8 flag, int64 value) { int itemdb_uid_load(){ char * uid; - if (SQL_ERROR == Sql_Query(mmysql_handle, "SELECT `value` FROM `interreg` WHERE `varname`='unique_id'")) + if (SQL_ERROR == SQL->Query(mmysql_handle, "SELECT `value` FROM `interreg` WHERE `varname`='unique_id'")) Sql_ShowDebug(mmysql_handle); - if( SQL_SUCCESS != Sql_NextRow(mmysql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(mmysql_handle) ) { ShowError("itemdb_uid_load: Unable to fetch unique_id data\n"); - Sql_FreeResult(mmysql_handle); + SQL->FreeResult(mmysql_handle); return -1; } - Sql_GetData(mmysql_handle, 0, &uid, NULL); + SQL->GetData(mmysql_handle, 0, &uid, NULL); itemdb_unique_id(1, (uint64)strtoull(uid, NULL, 10)); - Sql_FreeResult(mmysql_handle); + SQL->FreeResult(mmysql_handle); return 0; } @@ -1324,12 +1325,12 @@ static void itemdb_read(void) { itemdb_read_combos(); itemdb_read_itemgroup(); - sv_readdb(db_path, "item_avail.txt", ',', 2, 2, -1, &itemdb_read_itemavail); - sv_readdb(db_path, DBPATH"item_trade.txt", ',', 3, 3, -1, &itemdb_read_itemtrade); - sv_readdb(db_path, "item_delay.txt", ',', 2, 2, -1, &itemdb_read_itemdelay); - sv_readdb(db_path, "item_stack.txt", ',', 3, 3, -1, &itemdb_read_stack); - sv_readdb(db_path, DBPATH"item_buyingstore.txt", ',', 1, 1, -1, &itemdb_read_buyingstore); - sv_readdb(db_path, "item_nouse.txt", ',', 3, 3, -1, &itemdb_read_nouse); + sv->readdb(db_path, "item_avail.txt", ',', 2, 2, -1, &itemdb_read_itemavail); + sv->readdb(db_path, DBPATH"item_trade.txt", ',', 3, 3, -1, &itemdb_read_itemtrade); + sv->readdb(db_path, "item_delay.txt", ',', 2, 2, -1, &itemdb_read_itemdelay); + sv->readdb(db_path, "item_stack.txt", ',', 3, 3, -1, &itemdb_read_stack); + sv->readdb(db_path, DBPATH"item_buyingstore.txt", ',', 1, 1, -1, &itemdb_read_buyingstore); + sv->readdb(db_path, "item_nouse.txt", ',', 3, 3, -1, &itemdb_read_nouse); itemdb_uid_load(); } @@ -1432,7 +1433,7 @@ void itemdb_reload(void) // readjust itemdb pointer cache for each player iter = mapit_geteachpc(); - for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) ) { + for( sd = (struct map_session_data*)mapit->first(iter); mapit->exists(iter); sd = (struct map_session_data*)mapit->next(iter) ) { memset(sd->item_delay, 0, sizeof(sd->item_delay)); // reset item delays pc_setinventorydata(sd); /* clear combo bonuses */ @@ -1447,7 +1448,7 @@ void itemdb_reload(void) } } - mapit_free(iter); + mapit->free(iter); } void do_final_itemdb(void) diff --git a/src/map/log.c b/src/map/log.c index 1cca0a098..f57b91a2a 100644 --- a/src/map/log.c +++ b/src/map/log.c @@ -152,7 +152,7 @@ void log_branch(struct map_session_data* sd) { logs->branch_sub(sd); } void log_pick_sub_sql(int id, int16 m, e_log_pick_type type, int amount, struct item* itm, struct item_data *data) { - if( SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`, `unique_id`) VALUES (NOW(), '%d', '%c', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s', '%"PRIu64"')", + if( SQL_ERROR == SQL->Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`, `unique_id`) VALUES (NOW(), '%d', '%c', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s', '%"PRIu64"')", logs->config.log_pick, id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], map[m].name?map[m].name:"", itm->unique_id) ) { Sql_ShowDebug(logmysql_handle); @@ -197,7 +197,7 @@ void log_pick_mob(struct mob_data* md, e_log_pick_type type, int amount, struct log_pick(md->class_, md->bl.m, type, amount, itm, data ? data : itemdb_exists(itm->nameid)); } void log_zeny_sub_sql(struct map_session_data* sd, e_log_pick_type type, struct map_session_data* src_sd, int amount) { - if( SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `src_id`, `type`, `amount`, `map`) VALUES (NOW(), '%d', '%d', '%c', '%d', '%s')", + if( SQL_ERROR == SQL->Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `src_id`, `type`, `amount`, `map`) VALUES (NOW(), '%d', '%d', '%c', '%d', '%s')", logs->config.log_zeny, sd->status.char_id, src_sd->status.char_id, log_picktype2char(type), amount, mapindex_id2name(sd->mapindex)) ) { Sql_ShowDebug(logmysql_handle); @@ -227,7 +227,7 @@ void log_zeny(struct map_session_data* sd, e_log_pick_type type, struct map_sess logs->zeny_sub(sd,type,src_sd,amount); } void log_mvpdrop_sub_sql(struct map_session_data* sd, int monster_id, int* log_mvp) { - if( SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`mvp_date`, `kill_char_id`, `monster_id`, `prize`, `mvpexp`, `map`) VALUES (NOW(), '%d', '%d', '%d', '%d', '%s') ", + if( SQL_ERROR == SQL->Query(logmysql_handle, LOG_QUERY " INTO `%s` (`mvp_date`, `kill_char_id`, `monster_id`, `prize`, `mvpexp`, `map`) VALUES (NOW(), '%d', '%d', '%d', '%d', '%s') ", logs->config.log_mvpdrop, sd->status.char_id, monster_id, log_mvp[0], log_mvp[1], mapindex_id2name(sd->mapindex)) ) { Sql_ShowDebug(logmysql_handle); diff --git a/src/map/map.c b/src/map/map.c index 313abb2c6..5b0a4ed27 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -117,7 +117,6 @@ static int block_free_count = 0, block_free_lock = 0; static struct block_list *bl_list[BL_LIST_MAX]; static int bl_list_count = 0; -struct map_data map[MAX_MAP_PER_SERVER]; int map_num = 0; int map_port=0; @@ -1826,7 +1825,7 @@ struct map_session_data * map_nick2sd(const char *nick) iter = mapit_getallusers(); found_sd = NULL; - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) + for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { if( battle_config.partial_name_scan ) {// partial name search @@ -1849,7 +1848,7 @@ struct map_session_data * map_nick2sd(const char *nick) break; } } - mapit_free(iter); + mapit->free(iter); if( battle_config.partial_name_scan && qty != 1 ) found_sd = NULL; @@ -1902,8 +1901,7 @@ struct mob_data * map_id2boss(int id) /// Applies func to all the players in the db. /// Stops iterating if func returns -1. -void map_foreachpc(int (*func)(struct map_session_data* sd, va_list args), ...) -{ +void map_map_foreachpc(int (*func)(struct map_session_data* sd, va_list args), ...) { DBIterator* iter; struct map_session_data* sd; @@ -1924,7 +1922,7 @@ void map_foreachpc(int (*func)(struct map_session_data* sd, va_list args), ...) /// Applies func to all the mobs in the db. /// Stops iterating if func returns -1. -void map_foreachmob(int (*func)(struct mob_data* md, va_list args), ...) +void map_map_foreachmob(int (*func)(struct mob_data* md, va_list args), ...) { DBIterator* iter; struct mob_data* md; @@ -1946,7 +1944,7 @@ void map_foreachmob(int (*func)(struct mob_data* md, va_list args), ...) /// Applies func to all the npcs in the db. /// Stops iterating if func returns -1. -void map_foreachnpc(int (*func)(struct npc_data* nd, va_list args), ...) +void map_map_foreachnpc(int (*func)(struct npc_data* nd, va_list args), ...) { DBIterator* iter; struct block_list* bl; @@ -1972,7 +1970,7 @@ void map_foreachnpc(int (*func)(struct npc_data* nd, va_list args), ...) /// Applies func to everything in the db. /// Stops iteratin gif func returns -1. -void map_foreachregen(int (*func)(struct block_list* bl, va_list args), ...) +void map_map_foreachregen(int (*func)(struct block_list* bl, va_list args), ...) { DBIterator* iter; struct block_list* bl; @@ -1994,7 +1992,7 @@ void map_foreachregen(int (*func)(struct block_list* bl, va_list args), ...) /// Applies func to everything in the db. /// Stops iterating if func returns -1. -void map_foreachiddb(int (*func)(struct block_list* bl, va_list args), ...) +void map_map_foreachiddb(int (*func)(struct block_list* bl, va_list args), ...) { DBIterator* iter; struct block_list* bl; @@ -3169,14 +3167,13 @@ void map_removemapdb(struct map_data *m) /*====================================== * Initiate maps loading stage *--------------------------------------*/ -int map_readallmaps (void) -{ +int map_readallmaps (void) { int i; FILE* fp=NULL; int maps_removed = 0; char *map_cache_buffer = NULL; // Has the uncompressed gat data of all maps, so just one allocation has to be made char map_cache_decode_buffer[MAX_MAP_SIZE]; - + if( enable_grf ) ShowStatus("Loading maps (using GRF files)...\n"); else { @@ -3509,15 +3506,15 @@ int inter_config_read(char *cfgName) int map_sql_init(void) { // main db connection - mmysql_handle = Sql_Malloc(); + mmysql_handle = SQL->Malloc(); ShowInfo("Connecting to the Map DB Server....\n"); - if( SQL_ERROR == Sql_Connect(mmysql_handle, map_server_id, map_server_pw, map_server_ip, map_server_port, map_server_db) ) + if( SQL_ERROR == SQL->Connect(mmysql_handle, map_server_id, map_server_pw, map_server_ip, map_server_port, map_server_db) ) exit(EXIT_FAILURE); ShowStatus("connect success! (Map Server Connection)\n"); if( strlen(default_codepage) > 0 ) - if ( SQL_ERROR == Sql_SetEncoding(mmysql_handle, default_codepage) ) + if ( SQL_ERROR == SQL->SetEncoding(mmysql_handle, default_codepage) ) Sql_ShowDebug(mmysql_handle); return 0; @@ -3526,11 +3523,11 @@ int map_sql_init(void) int map_sql_close(void) { ShowStatus("Close Map DB Connection....\n"); - Sql_Free(mmysql_handle); + SQL->Free(mmysql_handle); mmysql_handle = NULL; if (logs->config.sql_logs) { ShowStatus("Close Log DB Connection....\n"); - Sql_Free(logmysql_handle); + SQL->Free(logmysql_handle); logmysql_handle = NULL; } return 0; @@ -3539,15 +3536,15 @@ int map_sql_close(void) int log_sql_init(void) { // log db connection - logmysql_handle = Sql_Malloc(); + logmysql_handle = SQL->Malloc(); ShowInfo(""CL_WHITE"[SQL]"CL_RESET": Connecting to the Log Database "CL_WHITE"%s"CL_RESET" At "CL_WHITE"%s"CL_RESET"...\n",log_db_db,log_db_ip); - if ( SQL_ERROR == Sql_Connect(logmysql_handle, log_db_id, log_db_pw, log_db_ip, log_db_port, log_db_db) ) + if ( SQL_ERROR == SQL->Connect(logmysql_handle, log_db_id, log_db_pw, log_db_ip, log_db_port, log_db_db) ) exit(EXIT_FAILURE); ShowStatus(""CL_WHITE"[SQL]"CL_RESET": Successfully '"CL_GREEN"connected"CL_RESET"' to Database '"CL_WHITE"%s"CL_RESET"'.\n", log_db_db); if( strlen(default_codepage) > 0 ) - if ( SQL_ERROR == Sql_SetEncoding(logmysql_handle, default_codepage) ) + if ( SQL_ERROR == SQL->SetEncoding(logmysql_handle, default_codepage) ) Sql_ShowDebug(logmysql_handle); return 0; } @@ -4934,9 +4931,9 @@ void do_final(void) //Ladies and babies first. iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) + for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) map_quit(sd); - mapit_free(iter); + mapit->free(iter); /* prepares npcs for a faster shutdown process */ do_clear_npc(); @@ -4996,6 +4993,8 @@ void do_final(void) map_sql_close(); ers_destroy(map_iterator_ers); + + aFree(map); ShowStatus("Finished.\n"); } @@ -5083,9 +5082,9 @@ void do_shutdown(void) { struct map_session_data* sd; struct s_mapiterator* iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) + for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) clif->GM_kick(NULL, sd); - mapit_free(iter); + mapit->free(iter); flush_fifos(); } chrif_check_shutdown(); @@ -5164,9 +5163,38 @@ void map_hp_symbols(void) { HPM->share(searchstore,"searchstore"); HPM->share(skill,"skill"); HPM->share(vending,"vending"); + /* partial */ + HPM->share(mapit,"mapit"); + HPM->share(map_foreachpc,"map_foreachpc"); + HPM->share(map_foreachmob,"map_foreachmob"); + HPM->share(map_foreachnpc,"map_foreachnpc"); + HPM->share(map_foreachregen,"map_foreachregen"); + HPM->share(map_foreachiddb,"map_foreachiddb"); + /* sql link */ + HPM->share(mmysql_handle,"sql_handle"); /* specific */ HPM->share(atcommand->create,"addCommand"); HPM->share(script->addScript,"addScript"); + /* vars */ + HPM->share(map,"map"); +} +/* temporary until the map.c "Hercules Renewal Phase One" design is complete. */ +void map_defaults(void) { + mapit = &mapit_s; + + mapit->alloc = mapit_alloc; + mapit->free = mapit_free; + mapit->first = mapit_first; + mapit->last = mapit_last; + mapit->next = mapit_next; + mapit->prev = mapit_prev; + mapit->exists = mapit_exists; + + map_foreachpc = map_map_foreachpc; + map_foreachmob = map_map_foreachmob; + map_foreachnpc = map_map_foreachnpc; + map_foreachregen = map_map_foreachregen; + map_foreachiddb = map_map_foreachiddb; } void load_defaults(void) { atcommand_defaults(); @@ -5176,6 +5204,7 @@ void load_defaults(void) { homunculus_defaults(); ircbot_defaults(); log_defaults(); + map_defaults(); script_defaults(); searchstore_defaults(); skill_defaults(); @@ -5286,6 +5315,8 @@ int do_init(int argc, char *argv[]) } } + CREATE(map,struct map_data,MAX_MAP_PER_SERVER); + load_defaults(); map_config_read(MAP_CONF_NAME); diff --git a/src/map/map.h b/src/map/map.h index a8ce19713..a7bcb08db 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -693,7 +693,7 @@ int map_getcellp(struct map_data* m,int16 x,int16 y,cell_chk cellchk); void map_setcell(int16 m, int16 x, int16 y, cell_t cell, bool flag); void map_setgatcell(int16 m, int16 x, int16 y, int gat); -extern struct map_data map[]; +struct map_data *map; extern int map_num; extern int autosave_interval; @@ -776,11 +776,13 @@ int map_eraseipport(unsigned short map, uint32 ip, uint16 port); int map_eraseallipport(void); void map_addiddb(struct block_list *); void map_deliddb(struct block_list *bl); -void map_foreachpc(int (*func)(struct map_session_data* sd, va_list args), ...); -void map_foreachmob(int (*func)(struct mob_data* md, va_list args), ...); -void map_foreachnpc(int (*func)(struct npc_data* nd, va_list args), ...); -void map_foreachregen(int (*func)(struct block_list* bl, va_list args), ...); -void map_foreachiddb(int (*func)(struct block_list* bl, va_list args), ...); +/* temporary until the map.c "Hercules Renewal Phase One" design is complete. */ +void (*map_foreachpc) (int (*func)(struct map_session_data* sd, va_list args), ...); +void (*map_foreachmob) (int (*func)(struct mob_data* md, va_list args), ...); +void (*map_foreachnpc) (int (*func)(struct npc_data* nd, va_list args), ...); +void (*map_foreachregen) (int (*func)(struct block_list* bl, va_list args), ...); +void (*map_foreachiddb) (int (*func)(struct block_list* bl, va_list args), ...); +/* */ struct map_session_data * map_nick2sd(const char*); struct mob_data * map_getmob_boss(int16 m); struct mob_data * map_id2boss(int id); @@ -789,24 +791,27 @@ struct mob_data * map_id2boss(int id); void map_reloadnpc(bool clear); /// Bitfield of flags for the iterator. -enum e_mapitflags -{ +enum e_mapitflags { MAPIT_NORMAL = 0, // MAPIT_PCISPLAYING = 1,// Unneeded as pc_db/id_db will only hold auth'ed, active players. }; struct s_mapiterator; -struct s_mapiterator* mapit_alloc(enum e_mapitflags flags, enum bl_type types); -void mapit_free(struct s_mapiterator* mapit); -struct block_list* mapit_first(struct s_mapiterator* mapit); -struct block_list* mapit_last(struct s_mapiterator* mapit); -struct block_list* mapit_next(struct s_mapiterator* mapit); -struct block_list* mapit_prev(struct s_mapiterator* mapit); -bool mapit_exists(struct s_mapiterator* mapit); -#define mapit_getallusers() mapit_alloc(MAPIT_NORMAL,BL_PC) -#define mapit_geteachpc() mapit_alloc(MAPIT_NORMAL,BL_PC) -#define mapit_geteachmob() mapit_alloc(MAPIT_NORMAL,BL_MOB) -#define mapit_geteachnpc() mapit_alloc(MAPIT_NORMAL,BL_NPC) -#define mapit_geteachiddb() mapit_alloc(MAPIT_NORMAL,BL_ALL) +/* temporary until the map.c "Hercules Renewal Phase One" design is complete. */ +struct mapit_interface { + struct s_mapiterator* (*alloc) (enum e_mapitflags flags, enum bl_type types); + void (*free) (struct s_mapiterator* mapit); + struct block_list* (*first) (struct s_mapiterator* mapit); + struct block_list* (*last) (struct s_mapiterator* mapit); + struct block_list* (*next) (struct s_mapiterator* mapit); + struct block_list* (*prev) (struct s_mapiterator* mapit); + bool (*exists) (struct s_mapiterator* mapit); +} mapit_s; +struct mapit_interface *mapit; +#define mapit_getallusers() mapit->alloc(MAPIT_NORMAL,BL_PC) +#define mapit_geteachpc() mapit->alloc(MAPIT_NORMAL,BL_PC) +#define mapit_geteachmob() mapit->alloc(MAPIT_NORMAL,BL_MOB) +#define mapit_geteachnpc() mapit->alloc(MAPIT_NORMAL,BL_NPC) +#define mapit_geteachiddb() mapit->alloc(MAPIT_NORMAL,BL_ALL) int map_check_dir(int s_dir,int t_dir); uint8 map_calc_dir( struct block_list *src,int16 x,int16 y); diff --git a/src/map/mapreg_sql.c b/src/map/mapreg_sql.c index bac3cea13..484da5641 100644 --- a/src/map/mapreg_sql.c +++ b/src/map/mapreg_sql.c @@ -62,8 +62,8 @@ bool mapreg_setreg(int uid, int val) { if(name[1] != '@') {// write new variable to database char tmp_str[32*2+1]; - Sql_EscapeStringLen(mmysql_handle, tmp_str, name, strnlen(name, 32)); - if( SQL_ERROR == Sql_Query(mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%d','%d')", mapreg_table, tmp_str, i, val) ) + SQL->EscapeStringLen(mmysql_handle, tmp_str, name, strnlen(name, 32)); + if( SQL_ERROR == SQL->Query(mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%d','%d')", mapreg_table, tmp_str, i, val) ) Sql_ShowDebug(mmysql_handle); } idb_put(mapreg_db, uid, m); @@ -75,7 +75,7 @@ bool mapreg_setreg(int uid, int val) { idb_remove(mapreg_db,uid); if( name[1] != '@' ) {// Remove from database because it is unused. - if( SQL_ERROR == Sql_Query(mmysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%d'", mapreg_table, name, i) ) + if( SQL_ERROR == SQL->Query(mmysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%d'", mapreg_table, name, i) ) Sql_ShowDebug(mmysql_handle); } } @@ -92,7 +92,7 @@ bool mapreg_setregstr(int uid, const char* str) { if( str == NULL || *str == 0 ) { if(name[1] != '@') { - if( SQL_ERROR == Sql_Query(mmysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%d'", mapreg_table, name, i) ) + if( SQL_ERROR == SQL->Query(mmysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%d'", mapreg_table, name, i) ) Sql_ShowDebug(mmysql_handle); } if( (m = idb_get(mapregstr_db,uid)) ) { @@ -120,9 +120,9 @@ bool mapreg_setregstr(int uid, const char* str) { if(name[1] != '@') { //put returned null, so we must insert. char tmp_str[32*2+1]; char tmp_str2[255*2+1]; - Sql_EscapeStringLen(mmysql_handle, tmp_str, name, strnlen(name, 32)); - Sql_EscapeStringLen(mmysql_handle, tmp_str2, str, strnlen(str, 255)); - if( SQL_ERROR == Sql_Query(mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%d','%s')", mapreg_table, tmp_str, i, tmp_str2) ) + SQL->EscapeStringLen(mmysql_handle, tmp_str, name, strnlen(name, 32)); + SQL->EscapeStringLen(mmysql_handle, tmp_str2, str, strnlen(str, 255)); + if( SQL_ERROR == SQL->Query(mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%d','%s')", mapreg_table, tmp_str, i, tmp_str2) ) Sql_ShowDebug(mmysql_handle); } idb_put(mapregstr_db, uid, m); @@ -206,7 +206,7 @@ static void script_save_mapreg(void) { int i = (m->uid & 0xff000000) >> 24; const char* name = get_str(num); - if( SQL_ERROR == Sql_Query(mmysql_handle, "UPDATE `%s` SET `value`='%d' WHERE `varname`='%s' AND `index`='%d' LIMIT 1", mapreg_table, m->u.i, name, i) ) + if( SQL_ERROR == SQL->Query(mmysql_handle, "UPDATE `%s` SET `value`='%d' WHERE `varname`='%s' AND `index`='%d' LIMIT 1", mapreg_table, m->u.i, name, i) ) Sql_ShowDebug(mmysql_handle); m->save = false; } @@ -224,8 +224,8 @@ static void script_save_mapreg(void) { const char* name = get_str(num); char tmp_str2[2*255+1]; - Sql_EscapeStringLen(mmysql_handle, tmp_str2, m->u.str, safestrnlen(m->u.str, 255)); - if( SQL_ERROR == Sql_Query(mmysql_handle, "UPDATE `%s` SET `value`='%s' WHERE `varname`='%s' AND `index`='%d' LIMIT 1", mapreg_table, tmp_str2, name, i) ) + SQL->EscapeStringLen(mmysql_handle, tmp_str2, m->u.str, safestrnlen(m->u.str, 255)); + if( SQL_ERROR == SQL->Query(mmysql_handle, "UPDATE `%s` SET `value`='%s' WHERE `varname`='%s' AND `index`='%d' LIMIT 1", mapreg_table, tmp_str2, name, i) ) Sql_ShowDebug(mmysql_handle); m->save = false; } diff --git a/src/map/mercenary.c b/src/map/mercenary.c index f673ae5de..02fcea891 100644 --- a/src/map/mercenary.c +++ b/src/map/mercenary.c @@ -456,7 +456,7 @@ static bool read_mercenarydb_sub(char* str[], int columns, int current) int read_mercenarydb(void) { memset(mercenary_db,0,sizeof(mercenary_db)); - sv_readdb(db_path, "mercenary_db.txt", ',', 26, 26, MAX_MERCENARY_CLASS, &read_mercenarydb_sub); + sv->readdb(db_path, "mercenary_db.txt", ',', 26, 26, MAX_MERCENARY_CLASS, &read_mercenarydb_sub); return 0; } @@ -494,7 +494,7 @@ static bool read_mercenary_skilldb_sub(char* str[], int columns, int current) int read_mercenary_skilldb(void) { - sv_readdb(db_path, "mercenary_skill_db.txt", ',', 3, 3, -1, &read_mercenary_skilldb_sub); + sv->readdb(db_path, "mercenary_skill_db.txt", ',', 3, 3, -1, &read_mercenary_skilldb_sub); return 0; } diff --git a/src/map/mob.c b/src/map/mob.c index 86c0f8455..0f1ad0452 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -3907,7 +3907,7 @@ static void mob_readdb(void) } } - sv_readdb(db_path, filename[fi], ',', 31+2*MAX_MVP_DROP+2*MAX_MOB_DROP, 31+2*MAX_MVP_DROP+2*MAX_MOB_DROP, -1, &mob_readdb_sub); + sv->readdb(db_path, filename[fi], ',', 31+2*MAX_MVP_DROP+2*MAX_MOB_DROP, 31+2*MAX_MVP_DROP+2*MAX_MOB_DROP, -1, &mob_readdb_sub); } } @@ -3923,13 +3923,13 @@ static int mob_read_sqldb(void) uint32 lines = 0, count = 0; // retrieve all rows from the mob database - if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT * FROM `%s`", mob_db_name[fi]) ) { + if( SQL_ERROR == SQL->Query(mmysql_handle, "SELECT * FROM `%s`", mob_db_name[fi]) ) { Sql_ShowDebug(mmysql_handle); continue; } // process rows one by one - while( SQL_SUCCESS == Sql_NextRow(mmysql_handle) ) { + while( SQL_SUCCESS == SQL->NextRow(mmysql_handle) ) { // wrap the result into a TXT-compatible format char line[1024]; char* str[31+2*MAX_MVP_DROP+2*MAX_MOB_DROP]; @@ -3941,7 +3941,7 @@ static int mob_read_sqldb(void) { char* data; size_t len; - Sql_GetData(mmysql_handle, i, &data, &len); + SQL->GetData(mmysql_handle, i, &data, &len); strcpy(p, data); str[i] = p; @@ -3955,7 +3955,7 @@ static int mob_read_sqldb(void) } // free the query result - Sql_FreeResult(mmysql_handle); + SQL->FreeResult(mmysql_handle); ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, mob_db_name[fi]); } @@ -4471,7 +4471,7 @@ static void mob_readskilldb(void) { } } - sv_readdb(db_path, filename[fi], ',', 19, 19, -1, &mob_parse_row_mobskilldb); + sv->readdb(db_path, filename[fi], ',', 19, 19, -1, &mob_parse_row_mobskilldb); } } @@ -4495,13 +4495,13 @@ static int mob_read_sqlskilldb(void) uint32 lines = 0, count = 0; // retrieve all rows from the mob skill database - if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT * FROM `%s`", mob_skill_db_name[fi]) ) { + if( SQL_ERROR == SQL->Query(mmysql_handle, "SELECT * FROM `%s`", mob_skill_db_name[fi]) ) { Sql_ShowDebug(mmysql_handle); continue; } // process rows one by one - while( SQL_SUCCESS == Sql_NextRow(mmysql_handle) ) { + while( SQL_SUCCESS == SQL->NextRow(mmysql_handle) ) { // wrap the result into a TXT-compatible format char* str[19]; char* dummy = ""; @@ -4509,7 +4509,7 @@ static int mob_read_sqlskilldb(void) ++lines; for( i = 0; i < 19; ++i ) { - Sql_GetData(mmysql_handle, i, &str[i], NULL); + SQL->GetData(mmysql_handle, i, &str[i], NULL); if( str[i] == NULL ) str[i] = dummy; // get rid of NULL columns } @@ -4520,7 +4520,7 @@ static int mob_read_sqlskilldb(void) } // free the query result - Sql_FreeResult(mmysql_handle); + SQL->FreeResult(mmysql_handle); ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, mob_skill_db_name[fi]); } @@ -4586,7 +4586,7 @@ static bool mob_readdb_itemratio(char* str[], int columns, int current) */ static void mob_load(void) { - sv_readdb(db_path, "mob_item_ratio.txt", ',', 2, 2+MAX_ITEMRATIO_MOBS, -1, &mob_readdb_itemratio); // must be read before mobdb + sv->readdb(db_path, "mob_item_ratio.txt", ',', 2, 2+MAX_ITEMRATIO_MOBS, -1, &mob_readdb_itemratio); // must be read before mobdb mob_readchatdb(); if (db_use_sqldbs) { @@ -4598,9 +4598,9 @@ static void mob_load(void) mob_readdb(); mob_readskilldb(); } - sv_readdb(db_path, "mob_avail.txt", ',', 2, 12, -1, &mob_readdb_mobavail); + sv->readdb(db_path, "mob_avail.txt", ',', 2, 12, -1, &mob_readdb_mobavail); mob_read_randommonster(); - sv_readdb(db_path, DBPATH"mob_race2_db.txt", ',', 2, 20, -1, &mob_readdb_race2); + sv->readdb(db_path, DBPATH"mob_race2_db.txt", ',', 2, 20, -1, &mob_readdb_race2); } void mob_reload(void) { diff --git a/src/map/npc.c b/src/map/npc.c index a9fdb5ea6..3a3ae472d 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -1852,7 +1852,7 @@ int npc_unload(struct npc_data* nd, bool single) { ev_db->foreach(ev_db,npc_unload_ev,nd->exname); //Clean up all events related iter = mapit_geteachpc(); - for( bl = (struct block_list*)mapit_first(iter); mapit_exists(iter); bl = (struct block_list*)mapit_next(iter) ) { + for( bl = (struct block_list*)mapit->first(iter); mapit->exists(iter); bl = (struct block_list*)mapit->next(iter) ) { struct map_session_data *sd = ((TBL_PC*)bl); if( sd && sd->npc_timer_id != INVALID_TIMER ) { const struct TimerData *td = get_timer(sd->npc_timer_id); @@ -1866,7 +1866,7 @@ int npc_unload(struct npc_data* nd, bool single) { sd->npc_timer_id = INVALID_TIMER; } } - mapit_free(iter); + mapit->free(iter); if (nd->u.scr.timerid != INVALID_TIMER) { const struct TimerData *td; @@ -3606,7 +3606,7 @@ void npc_parsesrcfile(const char* filepath, bool runOnInit) lines++; // w1w2w3w4 - count = sv_parse(p, len+buffer-p, 0, '\t', pos, ARRAYLENGTH(pos), (e_svopt)(SV_TERMINATE_LF|SV_TERMINATE_CRLF)); + count = sv->parse(p, len+buffer-p, 0, '\t', pos, ARRAYLENGTH(pos), (e_svopt)(SV_TERMINATE_LF|SV_TERMINATE_CRLF)); if( count < 0 ) { ShowError("npc_parsesrcfile: Parse error in file '%s', line '%d'. Stopping...\n", filepath, strline(buffer,p-buffer)); @@ -3836,7 +3836,7 @@ int npc_reload(void) { //Remove all npcs/mobs. [Skotlex] iter = mapit_geteachiddb(); - for( bl = (struct block_list*)mapit_first(iter); mapit_exists(iter); bl = (struct block_list*)mapit_next(iter) ) { + for( bl = (struct block_list*)mapit->first(iter); mapit->exists(iter); bl = (struct block_list*)mapit->next(iter) ) { switch(bl->type) { case BL_NPC: if( bl->id != fake_nd->bl.id )// don't remove fake_nd @@ -3847,7 +3847,7 @@ int npc_reload(void) { break; } } - mapit_free(iter); + mapit->free(iter); if(battle_config.dynamic_mobs) {// dynamic check by [random] diff --git a/src/map/pc.c b/src/map/pc.c index 7d3b5c4a2..50188aeb3 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -9115,7 +9115,7 @@ int pc_autosave(int tid, unsigned int tick, int id, intptr_t data) save_flag = 1; //Noone was saved, so save first found char. iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) + for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { if(sd->bl.id == last_save_id && save_flag != 1) { save_flag = 1; @@ -9132,7 +9132,7 @@ int pc_autosave(int tid, unsigned int tick, int id, intptr_t data) chrif_save(sd,0); break; } - mapit_free(iter); + mapit->free(iter); interval = autosave_interval/(map_usercount()+1); if(interval < minsave_interval) @@ -9620,10 +9620,10 @@ int pc_readdb(void) count = 0; // Reset and read skilltree memset(skill_tree,0,sizeof(skill_tree)); - sv_readdb(db_path, DBPATH"skill_tree.txt", ',', 3+MAX_PC_SKILL_REQUIRE*2, 4+MAX_PC_SKILL_REQUIRE*2, -1, &pc_readdb_skilltree); + sv->readdb(db_path, DBPATH"skill_tree.txt", ',', 3+MAX_PC_SKILL_REQUIRE*2, 4+MAX_PC_SKILL_REQUIRE*2, -1, &pc_readdb_skilltree); #if defined(RENEWAL_DROP) || defined(RENEWAL_EXP) - sv_readdb(db_path, "re/level_penalty.txt", ',', 4, 4, -1, &pc_readdb_levelpenalty); + sv->readdb(db_path, "re/level_penalty.txt", ',', 4, 4, -1, &pc_readdb_levelpenalty); for( k=1; k < 3; k++ ){ // fill in the blanks for( j = 0; j < RC_MAX; j++ ){ int tmp = 0; diff --git a/src/map/pc_groups.c b/src/map/pc_groups.c index 42a068693..1a83c8b63 100644 --- a/src/map/pc_groups.c +++ b/src/map/pc_groups.c @@ -452,10 +452,10 @@ void pc_groups_reload(void) { /* refresh online users permissions */ iter = mapit_getallusers(); - for (sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter)) { + for (sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter)) { pc_group_pc_load(sd); } - mapit_free(iter); + mapit->free(iter); } diff --git a/src/map/script.c b/src/map/script.c index fd2e2654f..3d5045f02 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -1095,18 +1095,16 @@ const char* parse_simpleexpr(const char *p) add_scriptc(C_STR); p++; while( *p && *p != '"' ){ - if( (unsigned char)p[-1] <= 0x7e && *p == '\\' ) - { + if( (unsigned char)p[-1] <= 0x7e && *p == '\\' ) { char buf[8]; - size_t len = skip_escaped_c(p) - p; - size_t n = sv_unescape_c(buf, p, len); + size_t len = sv->skip_escaped_c(p) - p; + size_t n = sv->unescape_c(buf, p, len); if( n != 1 ) ShowDebug("parse_simpleexpr: unexpected length %d after unescape (\"%.*s\" -> %.*s)\n", (int)n, (int)len, p, (int)n, buf); p += len; add_scriptb(*buf); continue; - } - else if( *p == '\n' ) + } else if( *p == '\n' ) disp_error_message("parse_simpleexpr: unexpected newline @ string",p); add_scriptb(*p++); } @@ -2040,16 +2038,16 @@ static const char* script_print_line(StringBuf* buf, const char* p, const char* int i; if( p == NULL || !p[0] ) return NULL; if( line < 0 ) - StringBuf_Printf(buf, "*% 5d : ", -line); + StrBuf->Printf(buf, "*% 5d : ", -line); else - StringBuf_Printf(buf, " % 5d : ", line); + StrBuf->Printf(buf, " % 5d : ", line); for(i=0;p[i] && p[i] != '\n';i++){ if(p + i != mark) - StringBuf_Printf(buf, "%c", p[i]); + StrBuf->Printf(buf, "%c", p[i]); else - StringBuf_Printf(buf, "\'%c\'", p[i]); + StrBuf->Printf(buf, "\'%c\'", p[i]); } - StringBuf_AppendStr(buf, "\n"); + StrBuf->AppendStr(buf, "\n"); return p+i+(p[i] == '\n' ? 1 : 0); } @@ -2074,10 +2072,10 @@ void script_error(const char* src, const char* file, int start_line, const char* p=lineend+1; } - StringBuf_Init(&buf); - StringBuf_AppendStr(&buf, "\a\n"); - StringBuf_Printf(&buf, "script error on %s line %d\n", file, line); - StringBuf_Printf(&buf, " %s\n", error_msg); + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, "\a\n"); + StrBuf->Printf(&buf, "script error on %s line %d\n", file, line); + StrBuf->Printf(&buf, " %s\n", error_msg); for(j = 0; j < 5; j++ ) { script_print_line(&buf, linestart[j], NULL, line + j - 5); } @@ -2085,8 +2083,8 @@ void script_error(const char* src, const char* file, int start_line, const char* for(j = 0; j < 5; j++) { p = script_print_line(&buf, p, NULL, line + j + 1 ); } - ShowError("%s", StringBuf_Value(&buf)); - StringBuf_Destroy(&buf); + ShowError("%s", StrBuf->Value(&buf)); + StrBuf->Destroy(&buf); } /*========================================== @@ -4062,7 +4060,7 @@ BUILDIN(menu) return false; } - StringBuf_Init(&buf); + StrBuf->Init(&buf); sd->npc_menu = 0; for( i = 2; i < script_lastdata(st); i += 2 ) { @@ -4073,7 +4071,7 @@ BUILDIN(menu) data = script_getdata(st, i+1); if( !data_islabel(data) ) {// not a label - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); ShowError("script:menu: argument #%d (from 1) is not a label or label not found.\n", i); script_reportdata(data); st->state = END; @@ -4084,8 +4082,8 @@ BUILDIN(menu) if( text[0] == '\0' ) continue;// empty string, ignore if( sd->npc_menu > 0 ) - StringBuf_AppendStr(&buf, ":"); - StringBuf_AppendStr(&buf, text); + StrBuf->AppendStr(&buf, ":"); + StrBuf->AppendStr(&buf, text); sd->npc_menu += menu_countoptions(text, 0, NULL); } st->state = RERUNLINE; @@ -4094,18 +4092,18 @@ BUILDIN(menu) /** * menus beyond this length crash the client (see bugreport:6402) **/ - if( StringBuf_Length(&buf) >= 2047 ) { + if( StrBuf->Length(&buf) >= 2047 ) { struct npc_data * nd = map_id2nd(st->oid); char* menu; CREATE(menu, char, 2048); - safestrncpy(menu, StringBuf_Value(&buf), 2047); - ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StringBuf_Length(&buf)); + safestrncpy(menu, StrBuf->Value(&buf), 2047); + ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StrBuf->Length(&buf)); clif->scriptmenu(sd, st->oid, menu); aFree(menu); } else - clif->scriptmenu(sd, st->oid, StringBuf_Value(&buf)); + clif->scriptmenu(sd, st->oid, StrBuf->Value(&buf)); - StringBuf_Destroy(&buf); + StrBuf->Destroy(&buf); if( sd->npc_menu >= 0xff ) {// client supports only up to 254 entries; 0 is not used and 255 is reserved for cancel; excess entries are displayed but cause 'uint8' overflow @@ -4181,15 +4179,15 @@ BUILDIN(select) if( sd->state.menu_or_input == 0 ) { struct StringBuf buf; - StringBuf_Init(&buf); + StrBuf->Init(&buf); sd->npc_menu = 0; for( i = 2; i <= script_lastdata(st); ++i ) { text = script_getstr(st, i); if( sd->npc_menu > 0 ) - StringBuf_AppendStr(&buf, ":"); + StrBuf->AppendStr(&buf, ":"); - StringBuf_AppendStr(&buf, text); + StrBuf->AppendStr(&buf, text); sd->npc_menu += menu_countoptions(text, 0, NULL); } @@ -4199,17 +4197,17 @@ BUILDIN(select) /** * menus beyond this length crash the client (see bugreport:6402) **/ - if( StringBuf_Length(&buf) >= 2047 ) { + if( StrBuf->Length(&buf) >= 2047 ) { struct npc_data * nd = map_id2nd(st->oid); char* menu; CREATE(menu, char, 2048); - safestrncpy(menu, StringBuf_Value(&buf), 2047); - ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StringBuf_Length(&buf)); + safestrncpy(menu, StrBuf->Value(&buf), 2047); + ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StrBuf->Length(&buf)); clif->scriptmenu(sd, st->oid, menu); aFree(menu); } else - clif->scriptmenu(sd, st->oid, StringBuf_Value(&buf)); - StringBuf_Destroy(&buf); + clif->scriptmenu(sd, st->oid, StrBuf->Value(&buf)); + StrBuf->Destroy(&buf); if( sd->npc_menu >= 0xff ) { ShowWarning("buildin_select: Too many options specified (current=%d, max=254).\n", sd->npc_menu); @@ -4261,14 +4259,14 @@ BUILDIN(prompt) { struct StringBuf buf; - StringBuf_Init(&buf); + StrBuf->Init(&buf); sd->npc_menu = 0; for( i = 2; i <= script_lastdata(st); ++i ) { text = script_getstr(st, i); if( sd->npc_menu > 0 ) - StringBuf_AppendStr(&buf, ":"); - StringBuf_AppendStr(&buf, text); + StrBuf->AppendStr(&buf, ":"); + StrBuf->AppendStr(&buf, text); sd->npc_menu += menu_countoptions(text, 0, NULL); } @@ -4278,17 +4276,17 @@ BUILDIN(prompt) /** * menus beyond this length crash the client (see bugreport:6402) **/ - if( StringBuf_Length(&buf) >= 2047 ) { + if( StrBuf->Length(&buf) >= 2047 ) { struct npc_data * nd = map_id2nd(st->oid); char* menu; CREATE(menu, char, 2048); - safestrncpy(menu, StringBuf_Value(&buf), 2047); - ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StringBuf_Length(&buf)); + safestrncpy(menu, StrBuf->Value(&buf), 2047); + ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StrBuf->Length(&buf)); clif->scriptmenu(sd, st->oid, menu); aFree(menu); } else - clif->scriptmenu(sd, st->oid, StringBuf_Value(&buf)); - StringBuf_Destroy(&buf); + clif->scriptmenu(sd, st->oid, StrBuf->Value(&buf)); + StrBuf->Destroy(&buf); if( sd->npc_menu >= 0xff ) { @@ -4834,7 +4832,7 @@ BUILDIN(warpguild) } iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if( pl_sd->status.guild_id != gid ) continue; @@ -4859,7 +4857,7 @@ BUILDIN(warpguild) break; } } - mapit_free(iter); + mapit->free(iter); return true; } @@ -9292,7 +9290,7 @@ BUILDIN(getusersname) group_level = pc_get_group_level(sd); iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) + for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { if (pc_has_permission(pl_sd, PC_PERM_HIDE_SESSION) && pc_get_group_level(pl_sd) > group_level) continue; // skip hidden sessions @@ -9303,7 +9301,7 @@ BUILDIN(getusersname) clif->scriptnext(sd,st->oid);*/ clif->scriptmes(sd,st->oid,pl_sd->status.name); } - mapit_free(iter); + mapit->free(iter); return true; } @@ -10567,7 +10565,7 @@ BUILDIN(pvpon) return true; iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) + for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { if( sd->bl.m != m || sd->pvp_timer != INVALID_TIMER ) continue; // not applicable @@ -10579,7 +10577,7 @@ BUILDIN(pvpon) sd->pvp_won = 0; sd->pvp_lost = 0; } - mapit_free(iter); + mapit->free(iter); return true; } @@ -12303,7 +12301,7 @@ BUILDIN(recovery) struct s_mapiterator* iter; iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) + for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { if(pc_isdead(sd)) status_revive(&sd->bl, 100, 100); @@ -12311,7 +12309,7 @@ BUILDIN(recovery) status_percent_heal(&sd->bl, 100, 100); clif->message(sd->fd,msg_txt(680)); } - mapit_free(iter); + mapit->free(iter); return true; } /*========================================== @@ -13596,7 +13594,7 @@ BUILDIN(sprintf) safestrncpy(buf, format, len+1); // Issue sprintf for each parameter - StringBuf_Init(&final_buf); + StrBuf->Init(&final_buf); q = buf; while((p = strchr(q, '%'))!=NULL){ if(p!=q){ @@ -13606,12 +13604,12 @@ BUILDIN(sprintf) buf2_len = len; } safestrncpy(buf2, q, len); - StringBuf_AppendStr(&final_buf, buf2); + StrBuf->AppendStr(&final_buf, buf2); q = p; } p = q+1; if(*p=='%'){ // %% - StringBuf_AppendStr(&final_buf, "%"); + StrBuf->AppendStr(&final_buf, "%"); q+=2; continue; } @@ -13625,7 +13623,7 @@ BUILDIN(sprintf) ShowError("buildin_sprintf: Not enough arguments passed!\n"); if(buf) aFree(buf); if(buf2) aFree(buf2); - StringBuf_Destroy(&final_buf); + StrBuf->Destroy(&final_buf); script_pushconststr(st,""); return false; } @@ -13647,21 +13645,21 @@ BUILDIN(sprintf) // the scripter's responsibility. data = script_getdata(st, arg+3); if(data_isstring(data)){ // String - StringBuf_Printf(&final_buf, buf2, script_getstr(st, arg+3)); + StrBuf->Printf(&final_buf, buf2, script_getstr(st, arg+3)); }else if(data_isint(data)){ // Number - StringBuf_Printf(&final_buf, buf2, script_getnum(st, arg+3)); + StrBuf->Printf(&final_buf, buf2, script_getnum(st, arg+3)); }else if(data_isreference(data)){ // Variable char* name = reference_getname(data); if(name[strlen(name)-1]=='$'){ // var Str - StringBuf_Printf(&final_buf, buf2, script_getstr(st, arg+3)); + StrBuf->Printf(&final_buf, buf2, script_getstr(st, arg+3)); }else{ // var Int - StringBuf_Printf(&final_buf, buf2, script_getnum(st, arg+3)); + StrBuf->Printf(&final_buf, buf2, script_getnum(st, arg+3)); } }else{ // Unsupported type ShowError("buildin_sprintf: Unknown argument type!\n"); if(buf) aFree(buf); if(buf2) aFree(buf2); - StringBuf_Destroy(&final_buf); + StrBuf->Destroy(&final_buf); script_pushconststr(st,""); return false; } @@ -13670,7 +13668,7 @@ BUILDIN(sprintf) // Append anything left if(*q){ - StringBuf_AppendStr(&final_buf, q); + StrBuf->AppendStr(&final_buf, q); } // Passed more, than needed @@ -13679,11 +13677,11 @@ BUILDIN(sprintf) script_reportsrc(st); } - script_pushstrcopy(st, StringBuf_Value(&final_buf)); + script_pushstrcopy(st, StrBuf->Value(&final_buf)); if(buf) aFree(buf); if(buf2) aFree(buf2); - StringBuf_Destroy(&final_buf); + StrBuf->Destroy(&final_buf); return true; } @@ -13878,7 +13876,7 @@ BUILDIN(replacestr) } } - StringBuf_Init(&output); + StrBuf->Init(&output); for(; i < inputlen; i++) { if(count && count == numFinds) { //found enough, stop looking @@ -13888,19 +13886,19 @@ BUILDIN(replacestr) for(f = 0; f <= findlen; f++) { if(f == findlen) { //complete match numFinds++; - StringBuf_AppendStr(&output, replace); + StrBuf->AppendStr(&output, replace); i += findlen - 1; break; } else { if(usecase) { if((i + f) > inputlen || input[i + f] != find[f]) { - StringBuf_Printf(&output, "%c", input[i]); + StrBuf->Printf(&output, "%c", input[i]); break; } } else { if(((i + f) > inputlen || input[i + f] != find[f]) && TOUPPER(input[i+f]) != TOUPPER(find[f])) { - StringBuf_Printf(&output, "%c", input[i]); + StrBuf->Printf(&output, "%c", input[i]); break; } } @@ -13910,10 +13908,10 @@ BUILDIN(replacestr) //append excess after enough found if(i < inputlen) - StringBuf_AppendStr(&output, &(input[i])); + StrBuf->AppendStr(&output, &(input[i])); - script_pushstrcopy(st, StringBuf_Value(&output)); - StringBuf_Destroy(&output); + script_pushstrcopy(st, StrBuf->Value(&output)); + StrBuf->Destroy(&output); return true; } @@ -14173,20 +14171,20 @@ int buildin_query_sql_sub(struct script_state* st, Sql* handle) // Execute the query query = script_getstr(st,2); - if( SQL_ERROR == Sql_QueryStr(handle, query) ) { + if( SQL_ERROR == SQL->QueryStr(handle, query) ) { Sql_ShowDebug(handle); script_pushint(st, 0); return false; } - if( Sql_NumRows(handle) == 0 ) { // No data received - Sql_FreeResult(handle); + if( SQL->NumRows(handle) == 0 ) { // No data received + SQL->FreeResult(handle); script_pushint(st, 0); return true; } // Count the number of columns to store - num_cols = Sql_NumColumns(handle); + num_cols = SQL->NumColumns(handle); if( num_vars < num_cols ) { ShowWarning("script:query_sql: Too many columns, discarding last %u columns.\n", (unsigned int)(num_cols-num_vars)); script_reportsrc(st); @@ -14196,12 +14194,12 @@ int buildin_query_sql_sub(struct script_state* st, Sql* handle) } // Store data - for( i = 0; i < max_rows && SQL_SUCCESS == Sql_NextRow(handle); ++i ) { + for( i = 0; i < max_rows && SQL_SUCCESS == SQL->NextRow(handle); ++i ) { for( j = 0; j < num_vars; ++j ) { char* str = NULL; if( j < num_cols ) - Sql_GetData(handle, j, &str, NULL); + SQL->GetData(handle, j, &str, NULL); data = script_getdata(st, j+3); name = reference_getname(data); @@ -14211,13 +14209,13 @@ int buildin_query_sql_sub(struct script_state* st, Sql* handle) setd_sub(st, sd, name, i, (void *)__64BPTRSIZE((str?atoi(str):0)), reference_getref(data)); } } - if( i == max_rows && max_rows < Sql_NumRows(handle) ) { - ShowWarning("script:query_sql: Only %d/%u rows have been stored.\n", max_rows, (unsigned int)Sql_NumRows(handle)); + if( i == max_rows && max_rows < SQL->NumRows(handle) ) { + ShowWarning("script:query_sql: Only %d/%u rows have been stored.\n", max_rows, (unsigned int)SQL->NumRows(handle)); script_reportsrc(st); } // Free data - Sql_FreeResult(handle); + SQL->FreeResult(handle); script_pushint(st, i); return true; @@ -14245,7 +14243,7 @@ BUILDIN(escape_sql) str = script_getstr(st,2); len = strlen(str); esc_str = (char*)aMalloc(len*2+1); - Sql_EscapeStringLen(mmysql_handle, esc_str, str, len); + SQL->EscapeStringLen(mmysql_handle, esc_str, str, len); script_pushstr(st, esc_str); return true; } @@ -15006,12 +15004,12 @@ BUILDIN(unittalk) if( bl != NULL ) { struct StringBuf sbuf; - StringBuf_Init(&sbuf); - StringBuf_Printf(&sbuf, "%s : %s", status_get_name(bl), message); - clif->disp_overhead(bl, StringBuf_Value(&sbuf)); + StrBuf->Init(&sbuf); + StrBuf->Printf(&sbuf, "%s : %s", status_get_name(bl), message); + clif->disp_overhead(bl, StrBuf->Value(&sbuf)); if( bl->type == BL_PC ) - clif->message(((TBL_PC*)bl)->fd, StringBuf_Value(&sbuf)); - StringBuf_Destroy(&sbuf); + clif->message(((TBL_PC*)bl)->fd, StrBuf->Value(&sbuf)); + StrBuf->Destroy(&sbuf); } return true; diff --git a/src/map/skill.c b/src/map/skill.c index 828d600c1..d10cdb1a9 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -17770,27 +17770,27 @@ void skill_readdb(void) { safestrncpy(skill_db[0].name, "UNKNOWN_SKILL", sizeof(skill_db[0].name)); safestrncpy(skill_db[0].desc, "Unknown Skill", sizeof(skill_db[0].desc)); - sv_readdb(db_path, DBPATH"skill_db.txt" , ',', 17, 17, MAX_SKILL_DB, skill->parse_row_skilldb); - sv_readdb(db_path, DBPATH"skill_require_db.txt" , ',', 32, 32, MAX_SKILL_DB, skill->parse_row_requiredb); + sv->readdb(db_path, DBPATH"skill_db.txt" , ',', 17, 17, MAX_SKILL_DB, skill->parse_row_skilldb); + sv->readdb(db_path, DBPATH"skill_require_db.txt" , ',', 32, 32, MAX_SKILL_DB, skill->parse_row_requiredb); #ifdef RENEWAL_CAST - sv_readdb(db_path, "re/skill_cast_db.txt" , ',', 8, 8, MAX_SKILL_DB, skill->parse_row_castdb); + sv->readdb(db_path, "re/skill_cast_db.txt" , ',', 8, 8, MAX_SKILL_DB, skill->parse_row_castdb); #else - sv_readdb(db_path, "pre-re/skill_cast_db.txt" , ',', 7, 7, MAX_SKILL_DB, skill->parse_row_castdb); + sv->readdb(db_path, "pre-re/skill_cast_db.txt" , ',', 7, 7, MAX_SKILL_DB, skill->parse_row_castdb); #endif - sv_readdb(db_path, DBPATH"skill_castnodex_db.txt", ',', 2, 3, MAX_SKILL_DB, skill->parse_row_castnodexdb); - sv_readdb(db_path, DBPATH"skill_unit_db.txt" , ',', 8, 8, MAX_SKILL_DB, skill->parse_row_unitdb); + sv->readdb(db_path, DBPATH"skill_castnodex_db.txt", ',', 2, 3, MAX_SKILL_DB, skill->parse_row_castnodexdb); + sv->readdb(db_path, DBPATH"skill_unit_db.txt" , ',', 8, 8, MAX_SKILL_DB, skill->parse_row_unitdb); skill->init_unit_layout(); - sv_readdb(db_path, "produce_db.txt" , ',', 4, 4+2*MAX_PRODUCE_RESOURCE, MAX_SKILL_PRODUCE_DB, skill->parse_row_producedb); - sv_readdb(db_path, "create_arrow_db.txt" , ',', 1+2, 1+2*MAX_ARROW_RESOURCE, MAX_SKILL_ARROW_DB, skill->parse_row_createarrowdb); - sv_readdb(db_path, "abra_db.txt" , ',', 4, 4, MAX_SKILL_ABRA_DB, skill->parse_row_abradb); + sv->readdb(db_path, "produce_db.txt" , ',', 4, 4+2*MAX_PRODUCE_RESOURCE, MAX_SKILL_PRODUCE_DB, skill->parse_row_producedb); + sv->readdb(db_path, "create_arrow_db.txt" , ',', 1+2, 1+2*MAX_ARROW_RESOURCE, MAX_SKILL_ARROW_DB, skill->parse_row_createarrowdb); + sv->readdb(db_path, "abra_db.txt" , ',', 4, 4, MAX_SKILL_ABRA_DB, skill->parse_row_abradb); //Warlock - sv_readdb(db_path, "spellbook_db.txt" , ',', 3, 3, MAX_SKILL_SPELLBOOK_DB, skill->parse_row_spellbookdb); + sv->readdb(db_path, "spellbook_db.txt" , ',', 3, 3, MAX_SKILL_SPELLBOOK_DB, skill->parse_row_spellbookdb); //Guillotine Cross - sv_readdb(db_path, "magicmushroom_db.txt" , ',', 1, 1, MAX_SKILL_MAGICMUSHROOM_DB, skill->parse_row_magicmushroomdb); - sv_readdb(db_path, "skill_reproduce_db.txt", ',', 1, 1, MAX_SKILL_DB, skill->parse_row_reproducedb); - sv_readdb(db_path, "skill_improvise_db.txt" , ',', 2, 2, MAX_SKILL_IMPROVISE_DB, skill->parse_row_improvisedb); - sv_readdb(db_path, "skill_changematerial_db.txt" , ',', 4, 4+2*5, MAX_SKILL_PRODUCE_DB, skill->parse_row_changematerialdb); + sv->readdb(db_path, "magicmushroom_db.txt" , ',', 1, 1, MAX_SKILL_MAGICMUSHROOM_DB, skill->parse_row_magicmushroomdb); + sv->readdb(db_path, "skill_reproduce_db.txt", ',', 1, 1, MAX_SKILL_DB, skill->parse_row_reproducedb); + sv->readdb(db_path, "skill_improvise_db.txt" , ',', 2, 2, MAX_SKILL_IMPROVISE_DB, skill->parse_row_improvisedb); + sv->readdb(db_path, "skill_changematerial_db.txt" , ',', 4, 4+2*5, MAX_SKILL_PRODUCE_DB, skill->parse_row_changematerialdb); } void skill_reload (void) { @@ -17815,9 +17815,9 @@ void skill_reload (void) { chrif_skillid2idx(0); /* lets update all players skill tree : so that if any skill modes were changed they're properly updated */ iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) + for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) clif->skillinfoblock(sd); - mapit_free(iter); + mapit->free(iter); } diff --git a/src/map/status.c b/src/map/status.c index f13c1ce3a..9fbfe26fe 100644 --- a/src/map/status.c +++ b/src/map/status.c @@ -11282,13 +11282,13 @@ int status_readdb(void) #ifdef RENEWAL_ASPD - sv_readdb(db_path, "re/job_db1.txt", ',', 6+MAX_WEAPON_TYPE, 6+MAX_WEAPON_TYPE, -1, &status_readdb_job1); + sv->readdb(db_path, "re/job_db1.txt", ',', 6+MAX_WEAPON_TYPE, 6+MAX_WEAPON_TYPE, -1, &status_readdb_job1); #else - sv_readdb(db_path, "pre-re/job_db1.txt", ',', 5+MAX_WEAPON_TYPE, 5+MAX_WEAPON_TYPE, -1, &status_readdb_job1); + sv->readdb(db_path, "pre-re/job_db1.txt", ',', 5+MAX_WEAPON_TYPE, 5+MAX_WEAPON_TYPE, -1, &status_readdb_job1); #endif - sv_readdb(db_path, "job_db2.txt", ',', 1, 1+MAX_LEVEL, -1, &status_readdb_job2); - sv_readdb(db_path, "size_fix.txt", ',', MAX_WEAPON_TYPE, MAX_WEAPON_TYPE, ARRAYLENGTH(atkmods), &status_readdb_sizefix); - sv_readdb(db_path, DBPATH"refine_db.txt", ',', 4+MAX_REFINE, 4+MAX_REFINE, ARRAYLENGTH(refine_info), &status_readdb_refine); + sv->readdb(db_path, "job_db2.txt", ',', 1, 1+MAX_LEVEL, -1, &status_readdb_job2); + sv->readdb(db_path, "size_fix.txt", ',', MAX_WEAPON_TYPE, MAX_WEAPON_TYPE, ARRAYLENGTH(atkmods), &status_readdb_sizefix); + sv->readdb(db_path, DBPATH"refine_db.txt", ',', 4+MAX_REFINE, 4+MAX_REFINE, ARRAYLENGTH(refine_info), &status_readdb_refine); return 0; } -- cgit v1.2.3-70-g09d2 From 25e848f1a0f9317d63106cae048a1ef838411cb2 Mon Sep 17 00:00:00 2001 From: Susu Date: Fri, 17 May 2013 11:10:30 +0200 Subject: - Made DB and malloc lib HPM-friendly - Also fixed a bug preventing the plugins to be loeaded because HPMI and HPMI_s weren't HPExport --- src/char/char.c | 12 +- src/char/int_guild.c | 4 +- src/char/inter.c | 2 +- src/common/HPM.c | 4 +- src/common/HPMi.h | 4 +- src/common/console.c | 2 +- src/common/core.c | 10 +- src/common/db.c | 2001 ++++++++++++++++++++++++------------------------ src/common/db.h | 123 +-- src/common/malloc.c | 79 +- src/common/malloc.h | 72 +- src/login/login.c | 6 +- src/map/atcommand.c | 8 +- src/map/battleground.c | 2 +- src/map/chrif.c | 6 +- src/map/guild.c | 28 +- src/map/itemdb.c | 8 +- src/map/map.c | 14 +- src/map/npc.c | 14 +- src/map/script.c | 2 +- src/map/skill.c | 2 +- src/map/storage.c | 4 +- 22 files changed, 1228 insertions(+), 1179 deletions(-) (limited to 'src/common/HPM.c') diff --git a/src/char/char.c b/src/char/char.c index 6e0f5363e..00fc633df 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -187,7 +187,7 @@ static DBData create_online_char_data(DBKey key, va_list args) character->pincode_enable = -1; character->fd = -1; character->waiting_disconnect = INVALID_TIMER; - return db_ptr2data(character); + return DB->ptr2data(character); } void set_char_charselect(int account_id) @@ -321,7 +321,7 @@ void set_char_offline(int char_id, int account_id) */ static int char_db_setoffline(DBKey key, DBData *data, va_list ap) { - struct online_char_data* character = (struct online_char_data*)db_data2ptr(data); + struct online_char_data* character = (struct online_char_data*)DB->data2ptr(data); int server = va_arg(ap, int); if (server == -1) { character->char_id = -1; @@ -340,7 +340,7 @@ static int char_db_setoffline(DBKey key, DBData *data, va_list ap) */ static int char_db_kickoffline(DBKey key, DBData *data, va_list ap) { - struct online_char_data* character = (struct online_char_data*)db_data2ptr(data); + struct online_char_data* character = (struct online_char_data*)DB->data2ptr(data); int server_id = va_arg(ap, int); if (server_id > -1 && character->server != server_id) @@ -392,7 +392,7 @@ static DBData create_charstatus(DBKey key, va_list args) struct mmo_charstatus *cp; cp = (struct mmo_charstatus *) aCalloc(1,sizeof(struct mmo_charstatus)); cp->char_id = key.i; - return db_ptr2data(cp); + return DB->ptr2data(cp); } int inventory_to_sql(const struct item items[], int max, int id); @@ -4450,7 +4450,7 @@ int broadcast_user_count(int tid, unsigned int tick, int id, intptr_t data) */ static int send_accounts_tologin_sub(DBKey key, DBData *data, va_list ap) { - struct online_char_data* character = db_data2ptr(data); + struct online_char_data* character = DB->data2ptr(data); int* i = va_arg(ap, int*); if(character->server > -1) @@ -4532,7 +4532,7 @@ static int chardb_waiting_disconnect(int tid, unsigned int tick, int id, intptr_ */ static int online_data_cleanup_sub(DBKey key, DBData *data, va_list ap) { - struct online_char_data *character= db_data2ptr(data); + struct online_char_data *character= DB->data2ptr(data); if (character->fd != -1) return 0; //Character still connected if (character->server == -2) //Unknown server.. set them offline diff --git a/src/char/int_guild.c b/src/char/int_guild.c index b666cadae..e1e012725 100644 --- a/src/char/int_guild.c +++ b/src/char/int_guild.c @@ -57,7 +57,7 @@ static int guild_save_timer(int tid, unsigned int tick, int id, intptr_t data) if( last_id == 0 ) //Save the first guild in the list. state = 1; - for( g = db_data2ptr(iter->first(iter, &key)); dbi_exists(iter); g = db_data2ptr(iter->next(iter, &key)) ) + for( g = DB->data2ptr(iter->first(iter, &key)); dbi_exists(iter); g = DB->data2ptr(iter->next(iter, &key)) ) { if( state == 0 && g->guild_id == last_id ) state++; //Save next guild in the list. @@ -739,7 +739,7 @@ int inter_guild_sql_init(void) */ static int guild_db_final(DBKey key, DBData *data, va_list ap) { - struct guild *g = db_data2ptr(data); + struct guild *g = DB->data2ptr(data); if (g->save_flag&GS_MASK) { inter_guild_tosql(g, g->save_flag&GS_MASK); return 1; diff --git a/src/char/inter.c b/src/char/inter.c index 83989271e..a1b075a14 100644 --- a/src/char/inter.c +++ b/src/char/inter.c @@ -935,7 +935,7 @@ int mapif_disconnectplayer(int fd, int account_id, int char_id, int reason) int check_ttl_wisdata_sub(DBKey key, DBData *data, va_list ap) { unsigned long tick; - struct WisData *wd = db_data2ptr(data); + struct WisData *wd = DB->data2ptr(data); tick = va_arg(ap, unsigned long); if (DIFF_TICK(tick, wd->tick) > WISDATA_TTL && wis_delnum < WISDELLIST_MAX) diff --git a/src/common/HPM.c b/src/common/HPM.c index af06811a5..28ea8f413 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -264,6 +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"); /* socket */ HPM->share(RFIFOSKIP,"RFIFOSKIP"); HPM->share(WFIFOSET,"WFIFOSET"); @@ -284,7 +286,7 @@ void hplugins_share_defaults(void) { 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(get_uptime,"get_uptime"); } CPCMD(plugins) { if( HPM->plugin_count == 0 ) { diff --git a/src/common/HPMi.h b/src/common/HPMi.h index a58eeed38..3cdb804e0 100644 --- a/src/common/HPMi.h +++ b/src/common/HPMi.h @@ -57,14 +57,14 @@ enum hp_event_types { }; /* Hercules Plugin Mananger Include Interface */ -struct HPMi_interface { +HPExport struct HPMi_interface { void (*event[HPET_MAX]) (void); bool (*addCommand) (char *name, bool (*func)(const int fd, struct map_session_data* sd, const char* command, const char* message,struct AtCommandInfo *info)); bool (*addScript) (char *name, char *args, bool (*func)(struct script_state *st)); void (*addCPCommand) (char *name, CParseFunc func); } HPMi_s; #ifndef _HPM_H_ - struct HPMi_interface *HPMi; + HPExport struct HPMi_interface *HPMi; #endif #endif /* _HPMi_H_ */ diff --git a/src/common/console.c b/src/common/console.c index 248dd7b45..ba93b8e09 100644 --- a/src/common/console.c +++ b/src/common/console.c @@ -98,7 +98,7 @@ CPCMD(help) { } /* [Ind/Hercules] */ CPCMD(malloc_usage) { - unsigned int val = (unsigned int)malloc_usage(); + unsigned int val = (unsigned int)malloclib->usage(); ShowInfo("malloc_usage: %.2f MB\n",(double)(val)/1024); } #define CP_DEF_C(x) { #x , NULL , NULL, NULL } diff --git a/src/common/core.c b/src/common/core.c index 984815bc2..0959e6fc9 100644 --- a/src/common/core.c +++ b/src/common/core.c @@ -284,9 +284,11 @@ void core_defaults(void) { #endif console_defaults(); strlib_defaults(); + malloc_defaults(); #ifndef MINICORE sql_defaults(); timer_defaults(); + db_defaults(); #endif } /*====================================== @@ -305,7 +307,7 @@ int main (int argc, char **argv) { } core_defaults(); - malloc_init();// needed for Show* in display_title() [FlavioJS] + malloclib->init();// needed for Show* in display_title() [FlavioJS] console->display_title(); @@ -320,7 +322,7 @@ int main (int argc, char **argv) { Sql_Init(); rathread_init(); mempool_init(); - db_init(); + DB->init(); signals_init(); #ifdef _WIN32 @@ -354,12 +356,12 @@ int main (int argc, char **argv) { #endif timer_final(); socket_final(); - db_final(); + DB->final(); mempool_final(); rathread_final(); #endif - malloc_final(); + malloclib->final(); return 0; } diff --git a/src/common/db.c b/src/common/db.c index 7ac9b2dc7..579697a99 100644 --- a/src/common/db.c +++ b/src/common/db.c @@ -1,70 +1,70 @@ /*****************************************************************************\ - * Copyright (c) Athena Dev Teams - Licensed under GNU GPL - * For more information, see LICENCE in the main folder - * - * This file is separated in five sections: - * (1) Private typedefs, enums, structures, defines and gblobal variables - * (2) Private functions - * (3) Protected functions used internally - * (4) Protected functions used in the interface of the database - * (5) Public functions - * - * The databases are structured as a hashtable of RED-BLACK trees. - * - * Properties of the RED-BLACK trees being used: - * 1. The value of any node is greater than the value of its left child and - * less than the value of its right child. - * 2. Every node is colored either RED or BLACK. - * 3. Every red node that is not a leaf has only black children. - * 4. Every path from the root to a leaf contains the same number of black - * nodes. - * 5. The root node is black. - * An n node in a RED-BLACK tree has the property that its - * height is O(lg(n)). - * Another important property is that after adding a node to a RED-BLACK - * tree, the tree can be readjusted in O(lg(n)) time. - * Similarly, after deleting a node from a RED-BLACK tree, the tree can be - * readjusted in O(lg(n)) time. - * {@link http://www.cs.mcgill.ca/~cs251/OldCourses/1997/topic18/} - * - * How to add new database types: - * 1. Add the identifier of the new database type to the enum DBType - * 2. If not already there, add the data type of the key to the union DBKey - * 3. If the key can be considered NULL, update the function db_is_key_null - * 4. If the key can be duplicated, update the functions db_dup_key and - * db_dup_key_free - * 5. Create a comparator and update the function db_default_cmp - * 6. Create a hasher and update the function db_default_hash - * 7. If the new database type requires or does not support some options, - * update the function db_fix_options - * - * TODO: - * - create test cases to test the database system thoroughly - * - finish this header describing the database system - * - create custom database allocator - * - make the system thread friendly - * - change the structure of the database to T-Trees - * - create a db that organizes itself by splaying - * - * HISTORY: - * 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. - * 2007/11/09 - Added an iterator to the database. - * 2006/12/21 - Added 1-node cache to the database. - * 2.1 (Athena build #???#) - Portability fix - * - Fixed the portability of casting to union and added the functions - * ensure and clear to the database. - * 2.0 (Athena build 4859) - Transition version - * - Almost everything recoded with a strategy similar to objects, - * database structure is maintained. - * 1.0 (up to Athena build 4706) - * - Previous database system. - * - * @version 2006/12/21 - * @author Athena Dev team - * @encoding US-ASCII - * @see #db.h +* Copyright (c) Athena Dev Teams - Licensed under GNU GPL +* For more information, see LICENCE in the main folder +* +* This file is separated in five sections: +* (1) Private typedefs, enums, structures, defines and gblobal variables +* (2) Private functions +* (3) Protected functions used internally +* (4) Protected functions used in the interface of the database +* (5) Public functions +* +* The databases are structured as a hashtable of RED-BLACK trees. +* +* Properties of the RED-BLACK trees being used: +* 1. The value of any node is greater than the value of its left child and +* less than the value of its right child. +* 2. Every node is colored either RED or BLACK. +* 3. Every red node that is not a leaf has only black children. +* 4. Every path from the root to a leaf contains the same number of black +* nodes. +* 5. The root node is black. +* An n node in a RED-BLACK tree has the property that its +* height is O(lg(n)). +* Another important property is that after adding a node to a RED-BLACK +* tree, the tree can be readjusted in O(lg(n)) time. +* Similarly, after deleting a node from a RED-BLACK tree, the tree can be +* readjusted in O(lg(n)) time. +* {@link http://www.cs.mcgill.ca/~cs251/OldCourses/1997/topic18/} +* +* How to add new database types: +* 1. Add the identifier of the new database type to the enum DBType +* 2. If not already there, add the data type of the key to the union DBKey +* 3. If the key can be considered NULL, update the function db_is_key_null +* 4. If the key can be duplicated, update the functions db_dup_key and +* db_dup_key_free +* 5. Create a comparator and update the function db_default_cmp +* 6. Create a hasher and update the function db_default_hash +* 7. If the new database type requires or does not support some options, +* update the function db_fix_options +* +* TODO: +* - create test cases to test the database system thoroughly +* - finish this header describing the database system +* - create custom database allocator +* - make the system thread friendly +* - change the structure of the database to T-Trees +* - create a db that organizes itself by splaying +* +* HISTORY: +* 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. +* 2007/11/09 - Added an iterator to the database. +* 2006/12/21 - Added 1-node cache to the database. +* 2.1 (Athena build #???#) - Portability fix +* - Fixed the portability of casting to union and added the functions +* ensure and clear to the database. +* 2.0 (Athena build 4859) - Transition version +* - Almost everything recoded with a strategy similar to objects, +* database structure is maintained. +* 1.0 (up to Athena build 4706) +* - Previous database system. +* +* @version 2006/12/21 +* @author Athena Dev team +* @encoding US-ASCII +* @see #db.h \*****************************************************************************/ #include #include @@ -77,58 +77,58 @@ #include "../common/strlib.h" /*****************************************************************************\ - * (1) Private typedefs, enums, structures, defines and global variables of * - * the database system. * - * DB_ENABLE_STATS - Define to enable database statistics. * - * HASH_SIZE - Define with the size of the hashtable. * - * DBNColor - Enumeration of colors of the nodes. * - * DBNode - Structure of a node in RED-BLACK trees. * - * struct db_free - Structure that holds a deleted node to be freed. * - * DBMap_impl - Struture of the database. * - * stats - Statistics about the database system. * +* (1) Private typedefs, enums, structures, defines and global variables of * +* the database system. * +* DB_ENABLE_STATS - Define to enable database statistics. * +* HASH_SIZE - Define with the size of the hashtable. * +* DBNColor - Enumeration of colors of the nodes. * +* DBNode - Structure of a node in RED-BLACK trees. * +* struct db_free - Structure that holds a deleted node to be freed. * +* DBMap_impl - Struture of the database. * +* stats - Statistics about the database system. * \*****************************************************************************/ /** - * If defined statistics about database nodes, database creating/destruction - * and function usage are keept and displayed when finalizing the database - * system. - * WARNING: This adds overhead to every database operation (not shure how much). - * @private - * @see #DBStats - * @see #stats - * @see #db_final(void) - */ +* If defined statistics about database nodes, database creating/destruction +* and function usage are keept and displayed when finalizing the database +* system. +* WARNING: This adds overhead to every database operation (not shure how much). +* @private +* @see #DBStats +* @see #stats +* @see #db_final(void) +*/ //#define DB_ENABLE_STATS /** - * Size of the hashtable in the database. - * @private - * @see DBMap_impl#ht - */ +* Size of the hashtable in the database. +* @private +* @see DBMap_impl#ht +*/ #define HASH_SIZE (256+27) /** - * The color of individual nodes. - * @private - * @see struct dbn - */ +* The color of individual nodes. +* @private +* @see struct dbn +*/ typedef enum node_color { RED, BLACK } node_color; /** - * A node in a RED-BLACK tree of the database. - * @param parent Parent node - * @param left Left child node - * @param right Right child node - * @param key Key of this database entry - * @param data Data of this database entry - * @param deleted If the node is deleted - * @param color Color of the node - * @private - * @see DBMap_impl#ht - */ +* A node in a RED-BLACK tree of the database. +* @param parent Parent node +* @param left Left child node +* @param right Right child node +* @param key Key of this database entry +* @param data Data of this database entry +* @param deleted If the node is deleted +* @param color Color of the node +* @private +* @see DBMap_impl#ht +*/ typedef struct dbn { // Tree structure struct dbn *parent; @@ -143,39 +143,39 @@ typedef struct dbn { } *DBNode; /** - * Structure that holds a deleted node. - * @param node Deleted node - * @param root Address to the root of the tree - * @private - * @see DBMap_impl#free_list - */ +* Structure that holds a deleted node. +* @param node Deleted node +* @param root Address to the root of the tree +* @private +* @see DBMap_impl#free_list +*/ struct db_free { DBNode node; DBNode *root; }; /** - * Complete database structure. - * @param vtable Interface of the database - * @param alloc_file File where the database was allocated - * @param alloc_line Line in the file where the database was allocated - * @param free_list Array of deleted nodes to be freed - * @param free_count Number of deleted nodes in free_list - * @param free_max Current maximum capacity of free_list - * @param free_lock Lock for freeing the nodes - * @param nodes Manager of reusable tree nodes - * @param cmp Comparator of the database - * @param hash Hasher of the database - * @param release Releaser of the database - * @param ht Hashtable of RED-BLACK trees - * @param type Type of the database - * @param options Options of the database - * @param item_count Number of items in the database - * @param maxlen Maximum length of strings in DB_STRING and DB_ISTRING databases - * @param global_lock Global lock of the database - * @private - * @see #db_alloc(const char*,int,DBType,DBOptions,unsigned short) - */ +* Complete database structure. +* @param vtable Interface of the database +* @param alloc_file File where the database was allocated +* @param alloc_line Line in the file where the database was allocated +* @param free_list Array of deleted nodes to be freed +* @param free_count Number of deleted nodes in free_list +* @param free_max Current maximum capacity of free_list +* @param free_lock Lock for freeing the nodes +* @param nodes Manager of reusable tree nodes +* @param cmp Comparator of the database +* @param hash Hasher of the database +* @param release Releaser of the database +* @param ht Hashtable of RED-BLACK trees +* @param type Type of the database +* @param options Options of the database +* @param item_count Number of items in the database +* @param maxlen Maximum length of strings in DB_STRING and DB_ISTRING databases +* @param global_lock Global lock of the database +* @private +* @see #db_alloc(const char*,int,DBType,DBOptions,unsigned short) +*/ typedef struct DBMap_impl { // Database interface struct DBMap vtable; @@ -202,16 +202,16 @@ typedef struct DBMap_impl { } DBMap_impl; /** - * Complete iterator structure. - * @param vtable Interface of the iterator - * @param db Parent database - * @param ht_index Current index of the hashtable - * @param node Current node - * @private - * @see #DBIterator - * @see #DBMap_impl - * @see #DBNode - */ +* Complete iterator structure. +* @param vtable Interface of the iterator +* @param db Parent database +* @param ht_index Current index of the hashtable +* @param node Current node +* @private +* @see #DBIterator +* @see #DBMap_impl +* @see #DBNode +*/ typedef struct DBIterator_impl { // Iterator interface struct DBIterator vtable; @@ -222,11 +222,11 @@ typedef struct DBIterator_impl { #if defined(DB_ENABLE_STATS) /** - * Structure with what is counted when the database statistics are enabled. - * @private - * @see #DB_ENABLE_STATS - * @see #stats - */ +* Structure with what is counted when the database statistics are enabled. +* @private +* @see #DB_ENABLE_STATS +* @see #stats +*/ static struct db_stats { // Node alloc/free uint32 db_node_alloc; @@ -325,30 +325,30 @@ struct eri *db_iterator_ers; struct eri *db_alloc_ers; /*****************************************************************************\ - * (2) Section of private functions used by the database system. * - * db_rotate_left - Rotate a tree node to the left. * - * db_rotate_right - Rotate a tree node to the right. * - * db_rebalance - Rebalance the tree. * - * db_rebalance_erase - Rebalance the tree after a BLACK node was erased. * - * db_is_key_null - Returns not 0 if the key is considered NULL. * - * db_dup_key - Duplicate a key for internal use. * - * db_dup_key_free - Free the duplicated key. * - * db_free_add - Add a node to the free_list of a database. * - * db_free_remove - Remove a node from the free_list of a database. * - * db_free_lock - Increment the free_lock of a database. * - * db_free_unlock - Decrement the free_lock of a database. * - * If it was the last lock, frees the nodes in free_list. * - * NOTE: Keeps the database trees balanced. * +* (2) Section of private functions used by the database system. * +* db_rotate_left - Rotate a tree node to the left. * +* db_rotate_right - Rotate a tree node to the right. * +* db_rebalance - Rebalance the tree. * +* db_rebalance_erase - Rebalance the tree after a BLACK node was erased. * +* db_is_key_null - Returns not 0 if the key is considered NULL. * +* db_dup_key - Duplicate a key for internal use. * +* db_dup_key_free - Free the duplicated key. * +* db_free_add - Add a node to the free_list of a database. * +* db_free_remove - Remove a node from the free_list of a database. * +* db_free_lock - Increment the free_lock of a database. * +* db_free_unlock - Decrement the free_lock of a database. * +* If it was the last lock, frees the nodes in free_list. * +* NOTE: Keeps the database trees balanced. * \*****************************************************************************/ /** - * Rotate a node to the left. - * @param node Node to be rotated - * @param root Pointer to the root of the tree - * @private - * @see #db_rebalance(DBNode,DBNode *) - * @see #db_rebalance_erase(DBNode,DBNode *) - */ +* Rotate a node to the left. +* @param node Node to be rotated +* @param root Pointer to the root of the tree +* @private +* @see #db_rebalance(DBNode,DBNode *) +* @see #db_rebalance_erase(DBNode,DBNode *) +*/ static void db_rotate_left(DBNode node, DBNode *root) { DBNode y = node->right; @@ -373,13 +373,13 @@ static void db_rotate_left(DBNode node, DBNode *root) } /** - * Rotate a node to the right - * @param node Node to be rotated - * @param root Pointer to the root of the tree - * @private - * @see #db_rebalance(DBNode,DBNode *) - * @see #db_rebalance_erase(DBNode,DBNode *) - */ +* Rotate a node to the right +* @param node Node to be rotated +* @param root Pointer to the root of the tree +* @private +* @see #db_rebalance(DBNode,DBNode *) +* @see #db_rebalance_erase(DBNode,DBNode *) +*/ static void db_rotate_right(DBNode node, DBNode *root) { DBNode y = node->left; @@ -404,15 +404,15 @@ static void db_rotate_right(DBNode node, DBNode *root) } /** - * Rebalance the RED-BLACK tree. - * Called when the node and it's parent are both RED. - * @param node Node to be rebalanced - * @param root Pointer to the root of the tree - * @private - * @see #db_rotate_left(DBNode,DBNode *) - * @see #db_rotate_right(DBNode,DBNode *) - * @see #db_obj_put(DBMap*,DBKey,DBData) - */ +* Rebalance the RED-BLACK tree. +* Called when the node and it's parent are both RED. +* @param node Node to be rebalanced +* @param root Pointer to the root of the tree +* @private +* @see #db_rotate_left(DBNode,DBNode *) +* @see #db_rotate_right(DBNode,DBNode *) +* @see #db_obj_put(DBMap*,DBKey,DBData) +*/ static void db_rebalance(DBNode node, DBNode *root) { DBNode y; @@ -467,14 +467,14 @@ static void db_rebalance(DBNode node, DBNode *root) } /** - * Erase a node from the RED-BLACK tree, keeping the tree balanced. - * @param node Node to be erased from the tree - * @param root Root of the tree - * @private - * @see #db_rotate_left(DBNode,DBNode *) - * @see #db_rotate_right(DBNode,DBNode *) - * @see #db_free_unlock(DBMap_impl*) - */ +* Erase a node from the RED-BLACK tree, keeping the tree balanced. +* @param node Node to be erased from the tree +* @param root Root of the tree +* @private +* @see #db_rotate_left(DBNode,DBNode *) +* @see #db_rotate_right(DBNode,DBNode *) +* @see #db_free_unlock(DBMap_impl*) +*/ static void db_rebalance_erase(DBNode node, DBNode *root) { DBNode y = node; @@ -510,7 +510,7 @@ static void db_rebalance_erase(DBNode node, DBNode *root) // put the right of 'node' in 'y' y->right = node->right; node->right->parent = y; - // 'y' is a direct child of 'node' + // 'y' is a direct child of 'node' } else { x_parent = y; } @@ -558,9 +558,9 @@ static void db_rebalance_erase(DBNode node, DBNode *root) } if ((w->left == NULL || w->left->color == BLACK) && (w->right == NULL || w->right->color == BLACK)) { - w->color = RED; - x = x_parent; - x_parent = x_parent->parent; + w->color = RED; + x = x_parent; + x_parent = x_parent->parent; } else { if (w->right == NULL || w->right->color == BLACK) { if (w->left) w->left->color = BLACK; @@ -584,9 +584,9 @@ static void db_rebalance_erase(DBNode node, DBNode *root) } if ((w->right == NULL || w->right->color == BLACK) && (w->left == NULL || w->left->color == BLACK)) { - w->color = RED; - x = x_parent; - x_parent = x_parent->parent; + w->color = RED; + x = x_parent; + x_parent = x_parent->parent; } else { if (w->left == NULL || w->left->color == BLACK) { if (w->right) w->right->color = BLACK; @@ -607,39 +607,39 @@ static void db_rebalance_erase(DBNode node, DBNode *root) } /** - * Returns not 0 if the key is considered to be NULL. - * @param type Type of database - * @param key Key being tested - * @return not 0 if considered NULL, 0 otherwise - * @private - * @see #db_obj_get(DBMap*,DBKey) - * @see #db_obj_put(DBMap*,DBKey,DBData) - * @see #db_obj_remove(DBMap*,DBKey) - */ +* Returns not 0 if the key is considered to be NULL. +* @param type Type of database +* @param key Key being tested +* @return not 0 if considered NULL, 0 otherwise +* @private +* @see #db_obj_get(DBMap*,DBKey) +* @see #db_obj_put(DBMap*,DBKey,DBData) +* @see #db_obj_remove(DBMap*,DBKey) +*/ static int db_is_key_null(DBType type, DBKey key) { DB_COUNTSTAT(db_is_key_null); switch (type) { - case DB_STRING: - case DB_ISTRING: - return (key.str == NULL); + case DB_STRING: + case DB_ISTRING: + return (key.str == NULL); - default: // Not a pointer - return 0; + default: // Not a pointer + return 0; } } /** - * Duplicate the key used in the database. - * @param db Database the key is being used in - * @param key Key to be duplicated - * @param Duplicated key - * @private - * @see #db_free_add(DBMap_impl*,DBNode,DBNode *) - * @see #db_free_remove(DBMap_impl*,DBNode) - * @see #db_obj_put(DBMap*,DBKey,void *) - * @see #db_dup_key_free(DBMap_impl*,DBKey) - */ +* Duplicate the key used in the database. +* @param db Database the key is being used in +* @param key Key to be duplicated +* @param Duplicated key +* @private +* @see #db_free_add(DBMap_impl*,DBNode,DBNode *) +* @see #db_free_remove(DBMap_impl*,DBNode) +* @see #db_obj_put(DBMap*,DBKey,void *) +* @see #db_dup_key_free(DBMap_impl*,DBKey) +*/ static DBKey db_dup_key(DBMap_impl* db, DBKey key) { char *str; @@ -647,56 +647,56 @@ static DBKey db_dup_key(DBMap_impl* db, DBKey key) DB_COUNTSTAT(db_dup_key); switch (db->type) { - case DB_STRING: - case DB_ISTRING: - len = strnlen(key.str, db->maxlen); - str = (char*)aMalloc(len + 1); - memcpy(str, key.str, len); - str[len] = '\0'; - key.str = str; - return key; - - default: - return key; + case DB_STRING: + case DB_ISTRING: + len = strnlen(key.str, db->maxlen); + str = (char*)aMalloc(len + 1); + memcpy(str, key.str, len); + str[len] = '\0'; + key.str = str; + return key; + + default: + return key; } } /** - * Free a key duplicated by db_dup_key. - * @param db Database the key is being used in - * @param key Key to be freed - * @private - * @see #db_dup_key(DBMap_impl*,DBKey) - */ +* Free a key duplicated by db_dup_key. +* @param db Database the key is being used in +* @param key Key to be freed +* @private +* @see #db_dup_key(DBMap_impl*,DBKey) +*/ static void db_dup_key_free(DBMap_impl* db, DBKey key) { DB_COUNTSTAT(db_dup_key_free); switch (db->type) { - case DB_STRING: - case DB_ISTRING: - aFree((char*)key.str); - return; + case DB_STRING: + case DB_ISTRING: + aFree((char*)key.str); + return; - default: - return; + default: + return; } } /** - * Add a node to the free_list of the database. - * Marks the node as deleted. - * If the key isn't duplicated, the key is duplicated and released. - * @param db Target database - * @param root Root of the tree from the node - * @param node Target node - * @private - * @see #struct db_free - * @see DBMap_impl#free_list - * @see DBMap_impl#free_count - * @see DBMap_impl#free_max - * @see #db_obj_remove(DBMap*,DBKey) - * @see #db_free_remove(DBMap_impl*,DBNode) - */ +* Add a node to the free_list of the database. +* Marks the node as deleted. +* If the key isn't duplicated, the key is duplicated and released. +* @param db Target database +* @param root Root of the tree from the node +* @param node Target node +* @private +* @see #struct db_free +* @see DBMap_impl#free_list +* @see DBMap_impl#free_count +* @see DBMap_impl#free_max +* @see #db_obj_remove(DBMap*,DBKey) +* @see #db_free_remove(DBMap_impl*,DBNode) +*/ static void db_free_add(DBMap_impl* db, DBNode node, DBNode *root) { DBKey old_key; @@ -704,8 +704,8 @@ static void db_free_add(DBMap_impl* db, DBNode node, DBNode *root) DB_COUNTSTAT(db_free_add); if (db->free_lock == (unsigned int)~0) { ShowFatalError("db_free_add: free_lock overflow\n" - "Database allocated at %s:%d\n", - db->alloc_file, db->alloc_line); + "Database allocated at %s:%d\n", + db->alloc_file, db->alloc_line); exit(EXIT_FAILURE); } if (!(db->options&DB_OPT_DUP_KEY)) { // Make sure we have a key until the node is freed @@ -718,8 +718,8 @@ static void db_free_add(DBMap_impl* db, DBNode node, DBNode *root) if (db->free_max <= db->free_count) { if (db->free_count == (unsigned int)~0) { ShowFatalError("db_free_add: free_count overflow\n" - "Database allocated at %s:%d\n", - db->alloc_file, db->alloc_line); + "Database allocated at %s:%d\n", + db->alloc_file, db->alloc_line); exit(EXIT_FAILURE); } db->free_max = (unsigned int)~0; @@ -734,18 +734,18 @@ static void db_free_add(DBMap_impl* db, DBNode node, DBNode *root) } /** - * Remove a node from the free_list of the database. - * Marks the node as not deleted. - * NOTE: Frees the duplicated key of the node. - * @param db Target database - * @param node Node being removed from free_list - * @private - * @see #struct db_free - * @see DBMap_impl#free_list - * @see DBMap_impl#free_count - * @see #db_obj_put(DBMap*,DBKey,DBData) - * @see #db_free_add(DBMap_impl*,DBNode*,DBNode) - */ +* Remove a node from the free_list of the database. +* Marks the node as not deleted. +* NOTE: Frees the duplicated key of the node. +* @param db Target database +* @param node Node being removed from free_list +* @private +* @see #struct db_free +* @see DBMap_impl#free_list +* @see DBMap_impl#free_count +* @see #db_obj_put(DBMap*,DBKey,DBData) +* @see #db_free_add(DBMap_impl*,DBNode*,DBNode) +*/ static void db_free_remove(DBMap_impl* db, DBNode node) { unsigned int i; @@ -769,35 +769,35 @@ static void db_free_remove(DBMap_impl* db, DBNode node) } /** - * Increment the free_lock of the database. - * @param db Target database - * @private - * @see DBMap_impl#free_lock - * @see #db_unlock(DBMap_impl*) - */ +* Increment the free_lock of the database. +* @param db Target database +* @private +* @see DBMap_impl#free_lock +* @see #db_unlock(DBMap_impl*) +*/ static void db_free_lock(DBMap_impl* db) { DB_COUNTSTAT(db_free_lock); if (db->free_lock == (unsigned int)~0) { ShowFatalError("db_free_lock: free_lock overflow\n" - "Database allocated at %s:%d\n", - db->alloc_file, db->alloc_line); + "Database allocated at %s:%d\n", + db->alloc_file, db->alloc_line); exit(EXIT_FAILURE); } db->free_lock++; } /** - * Decrement the free_lock of the database. - * If it was the last lock, frees the nodes of the database. - * Keeps the tree balanced. - * NOTE: Frees the duplicated keys of the nodes - * @param db Target database - * @private - * @see DBMap_impl#free_lock - * @see #db_free_dbn(DBNode) - * @see #db_lock(DBMap_impl*) - */ +* Decrement the free_lock of the database. +* If it was the last lock, frees the nodes of the database. +* Keeps the tree balanced. +* NOTE: Frees the duplicated keys of the nodes +* @param db Target database +* @private +* @see DBMap_impl#free_lock +* @see #db_free_dbn(DBNode) +* @see #db_lock(DBMap_impl*) +*/ static void db_free_unlock(DBMap_impl* db) { unsigned int i; @@ -805,8 +805,8 @@ static void db_free_unlock(DBMap_impl* db) DB_COUNTSTAT(db_free_unlock); if (db->free_lock == 0) { ShowWarning("db_free_unlock: free_lock was already 0\n" - "Database allocated at %s:%d\n", - db->alloc_file, db->alloc_line); + "Database allocated at %s:%d\n", + db->alloc_file, db->alloc_line); } else { db->free_lock--; } @@ -823,36 +823,36 @@ static void db_free_unlock(DBMap_impl* db) } /*****************************************************************************\ - * (3) Section of protected functions used internally. * - * NOTE: the protected functions used in the database interface are in the * - * next section. * - * db_int_cmp - Default comparator for DB_INT databases. * - * 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_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_release_nothing - Releaser that releases nothing. * - * db_release_key - Releaser that only releases the key. * - * db_release_data - Releaser that only releases the data. * - * db_release_both - Releaser that releases key and data. * +* (3) Section of protected functions used internally. * +* NOTE: the protected functions used in the database interface are in the * +* next section. * +* db_int_cmp - Default comparator for DB_INT databases. * +* 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_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_release_nothing - Releaser that releases nothing. * +* db_release_key - Releaser that only releases the key. * +* db_release_data - Releaser that only releases the data. * +* db_release_both - Releaser that releases key and data. * \*****************************************************************************/ /** - * Default comparator for DB_INT databases. - * Compares key1 to key2. - * Return 0 if equal, negative if lower and positive if higher. - * maxlen 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_INT - * @see #DBComparator - * @see #db_default_cmp(DBType) - */ +* Default comparator for DB_INT databases. +* Compares key1 to key2. +* Return 0 if equal, negative if lower and positive if higher. +* maxlen 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_INT +* @see #DBComparator +* @see #db_default_cmp(DBType) +*/ static int db_int_cmp(DBKey key1, DBKey key2, unsigned short maxlen) { (void)maxlen;//not used @@ -863,18 +863,18 @@ static int db_int_cmp(DBKey key1, DBKey key2, unsigned short maxlen) } /** - * Default comparator for DB_UINT databases. - * Compares key1 to key2. - * Return 0 if equal, negative if lower and positive if higher. - * maxlen 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_UINT - * @see #DBComparator - * @see #db_default_cmp(DBType) - */ +* Default comparator for DB_UINT databases. +* Compares key1 to key2. +* Return 0 if equal, negative if lower and positive if higher. +* maxlen 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_UINT +* @see #DBComparator +* @see #db_default_cmp(DBType) +*/ static int db_uint_cmp(DBKey key1, DBKey key2, unsigned short maxlen) { (void)maxlen;//not used @@ -885,17 +885,17 @@ static int db_uint_cmp(DBKey key1, DBKey key2, unsigned short maxlen) } /** - * Default comparator for DB_STRING databases. - * Compares key1 to key2. - * Return 0 if equal, negative if lower and positive if higher. - * @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_STRING - * @see #DBComparator - * @see #db_default_cmp(DBType) - */ +* Default comparator for DB_STRING databases. +* Compares key1 to key2. +* Return 0 if equal, negative if lower and positive if higher. +* @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_STRING +* @see #DBComparator +* @see #db_default_cmp(DBType) +*/ static int db_string_cmp(DBKey key1, DBKey key2, unsigned short maxlen) { DB_COUNTSTAT(db_string_cmp); @@ -903,17 +903,17 @@ static int db_string_cmp(DBKey key1, DBKey key2, unsigned short maxlen) } /** - * Default comparator for DB_ISTRING databases. - * Compares key1 to key2 case insensitively. - * Return 0 if equal, negative if lower and positive if higher. - * @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_ISTRING - * @see #DBComparator - * @see #db_default_cmp(DBType) - */ +* Default comparator for DB_ISTRING databases. +* Compares key1 to key2 case insensitively. +* Return 0 if equal, negative if lower and positive if higher. +* @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_ISTRING +* @see #DBComparator +* @see #db_default_cmp(DBType) +*/ static int db_istring_cmp(DBKey key1, DBKey key2, unsigned short maxlen) { DB_COUNTSTAT(db_istring_cmp); @@ -921,16 +921,16 @@ static int db_istring_cmp(DBKey key1, DBKey key2, unsigned short maxlen) } /** - * Default hasher for DB_INT databases. - * Returns the value of the key as an unsigned int. - * maxlen 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_INT - * @see #DBHasher - * @see #db_default_hash(DBType) - */ +* Default hasher for DB_INT databases. +* Returns the value of the key as an unsigned int. +* maxlen 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_INT +* @see #DBHasher +* @see #db_default_hash(DBType) +*/ static unsigned int db_int_hash(DBKey key, unsigned short maxlen) { (void)maxlen;//not used @@ -939,16 +939,16 @@ static unsigned int db_int_hash(DBKey key, unsigned short maxlen) } /** - * Default hasher for DB_UINT databases. - * Just returns the value of the key. - * maxlen 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_UINT - * @see #DBHasher - * @see #db_default_hash(DBType) - */ +* Default hasher for DB_UINT databases. +* Just returns the value of the key. +* maxlen 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_UINT +* @see #DBHasher +* @see #db_default_hash(DBType) +*/ static unsigned int db_uint_hash(DBKey key, unsigned short maxlen) { (void)maxlen;//not used @@ -957,14 +957,14 @@ static unsigned int db_uint_hash(DBKey key, unsigned short maxlen) } /** - * Default hasher for DB_STRING databases. - * @param key Key to be hashed - * @param maxlen Maximum length of the key to hash - * @return hash of the key - * @see DBType#DB_STRING - * @see #DBHasher - * @see #db_default_hash(DBType) - */ +* Default hasher for DB_STRING databases. +* @param key Key to be hashed +* @param maxlen Maximum length of the key to hash +* @return hash of the key +* @see DBType#DB_STRING +* @see #DBHasher +* @see #db_default_hash(DBType) +*/ static unsigned int db_string_hash(DBKey key, unsigned short maxlen) { const char *k = key.str; @@ -984,13 +984,13 @@ static unsigned int db_string_hash(DBKey key, unsigned short maxlen) } /** - * Default hasher for DB_ISTRING databases. - * @param key Key to be hashed - * @param maxlen Maximum length of the key to hash - * @return hash of the key - * @see DBType#DB_ISTRING - * @see #db_default_hash(DBType) - */ +* Default hasher for DB_ISTRING databases. +* @param key Key to be hashed +* @param maxlen Maximum length of the key to hash +* @return hash of the key +* @see DBType#DB_ISTRING +* @see #db_default_hash(DBType) +*/ static unsigned int db_istring_hash(DBKey key, unsigned short maxlen) { const char *k = key.str; @@ -1010,14 +1010,14 @@ static unsigned int db_istring_hash(DBKey key, unsigned short maxlen) } /** - * Releaser that releases nothing. - * @param key Key of the database entry - * @param data Data of the database entry - * @param which What is being requested to be released - * @protected - * @see #DBReleaser - * @see #db_default_releaser(DBType,DBOptions) - */ +* Releaser that releases nothing. +* @param key Key of the database entry +* @param data Data of the database entry +* @param which What is being requested to be released +* @protected +* @see #DBReleaser +* @see #db_default_releaser(DBType,DBOptions) +*/ static void db_release_nothing(DBKey key, DBData data, DBRelease which) { (void)key;(void)data;(void)which;//not used @@ -1025,14 +1025,14 @@ static void db_release_nothing(DBKey key, DBData data, DBRelease which) } /** - * Releaser that only releases the key. - * @param key Key of the database entry - * @param data Data of the database entry - * @param which What is being requested to be released - * @protected - * @see #DBReleaser - * @see #db_default_release(DBType,DBOptions) - */ +* Releaser that only releases the key. +* @param key Key of the database entry +* @param data Data of the database entry +* @param which What is being requested to be released +* @protected +* @see #DBReleaser +* @see #db_default_release(DBType,DBOptions) +*/ static void db_release_key(DBKey key, DBData data, DBRelease which) { (void)data;//not used @@ -1041,16 +1041,16 @@ static void db_release_key(DBKey key, DBData data, DBRelease which) } /** - * Releaser that only releases the data. - * @param key Key of the database entry - * @param data Data of the database entry - * @param which What is being requested to be released - * @protected - * @see #DBData - * @see #DBRelease - * @see #DBReleaser - * @see #db_default_release(DBType,DBOptions) - */ +* Releaser that only releases the data. +* @param key Key of the database entry +* @param data Data of the database entry +* @param which What is being requested to be released +* @protected +* @see #DBData +* @see #DBRelease +* @see #DBReleaser +* @see #db_default_release(DBType,DBOptions) +*/ static void db_release_data(DBKey key, DBData data, DBRelease which) { (void)key;//not used @@ -1059,17 +1059,17 @@ static void db_release_data(DBKey key, DBData data, DBRelease which) } /** - * Releaser that releases both key and data. - * @param key Key of the database entry - * @param data Data of the database entry - * @param which What is being requested to be released - * @protected - * @see #DBKey - * @see #DBData - * @see #DBRelease - * @see #DBReleaser - * @see #db_default_release(DBType,DBOptions) - */ +* Releaser that releases both key and data. +* @param key Key of the database entry +* @param data Data of the database entry +* @param which What is being requested to be released +* @protected +* @see #DBKey +* @see #DBData +* @see #DBRelease +* @see #DBReleaser +* @see #db_default_release(DBType,DBOptions) +*/ static void db_release_both(DBKey key, DBData data, DBRelease which) { DB_COUNTSTAT(db_release_both); @@ -1078,52 +1078,52 @@ static void db_release_both(DBKey key, DBData data, DBRelease which) } /*****************************************************************************\ - * (4) Section with protected functions used in the interface of the * - * database and interface of the iterator. * - * dbit_obj_first - Fetches the first entry from the database. * - * dbit_obj_last - Fetches the last entry from the database. * - * dbit_obj_next - Fetches the next entry from the database. * - * dbit_obj_prev - Fetches the previous entry from the database. * - * dbit_obj_exists - Returns true if the current entry exists. * - * dbit_obj_remove - Remove the current entry from the database. * - * dbit_obj_destroy - Destroys the iterator, unlocking the database and * - * freeing used memory. * - * db_obj_iterator - Return a new database iterator. * - * db_obj_exists - Checks if an entry exists. * - * db_obj_get - Get the data identified by the key. * - * db_obj_vgetall - Get the data of the matched entries. * - * db_obj_getall - Get the data of the matched entries. * - * db_obj_vensure - Get the data identified by the key, creating if it * - * doesn't exist yet. * - * db_obj_ensure - Get the data identified by the key, creating if it * - * doesn't exist yet. * - * db_obj_put - Put data identified by the key in the database. * - * db_obj_remove - Remove an entry from the database. * - * db_obj_vforeach - Apply a function to every entry in the database. * - * db_obj_foreach - Apply a function to every entry in the database. * - * db_obj_vclear - Remove all entries from the database. * - * db_obj_clear - Remove all entries from the database. * - * db_obj_vdestroy - Destroy the database, freeing all the used memory. * - * db_obj_destroy - Destroy the database, freeing all the used memory. * - * db_obj_size - Return the size of the database. * - * db_obj_type - Return the type of the database. * - * db_obj_options - Return the options of the database. * +* (4) Section with protected functions used in the interface of the * +* database and interface of the iterator. * +* dbit_obj_first - Fetches the first entry from the database. * +* dbit_obj_last - Fetches the last entry from the database. * +* dbit_obj_next - Fetches the next entry from the database. * +* dbit_obj_prev - Fetches the previous entry from the database. * +* dbit_obj_exists - Returns true if the current entry exists. * +* dbit_obj_remove - Remove the current entry from the database. * +* dbit_obj_destroy - Destroys the iterator, unlocking the database and * +* freeing used memory. * +* db_obj_iterator - Return a new database iterator. * +* db_obj_exists - Checks if an entry exists. * +* db_obj_get - Get the data identified by the key. * +* db_obj_vgetall - Get the data of the matched entries. * +* db_obj_getall - Get the data of the matched entries. * +* db_obj_vensure - Get the data identified by the key, creating if it * +* doesn't exist yet. * +* db_obj_ensure - Get the data identified by the key, creating if it * +* doesn't exist yet. * +* db_obj_put - Put data identified by the key in the database. * +* db_obj_remove - Remove an entry from the database. * +* db_obj_vforeach - Apply a function to every entry in the database. * +* db_obj_foreach - Apply a function to every entry in the database. * +* db_obj_vclear - Remove all entries from the database. * +* db_obj_clear - Remove all entries from the database. * +* db_obj_vdestroy - Destroy the database, freeing all the used memory. * +* db_obj_destroy - Destroy the database, freeing all the used memory. * +* db_obj_size - Return the size of the database. * +* db_obj_type - Return the type of the database. * +* db_obj_options - Return the options of the database. * \*****************************************************************************/ /** - * Fetches the first entry in the database. - * Returns the data of the entry. - * Puts the key in out_key, if out_key is not NULL. - * @param self Iterator - * @param out_key Key of the entry - * @return Data of the entry - * @protected - * @see DBIterator#first - */ +* Fetches the first entry in the database. +* Returns the data of the entry. +* Puts the key in out_key, if out_key is not NULL. +* @param self Iterator +* @param out_key Key of the entry +* @return Data of the entry +* @protected +* @see DBIterator#first +*/ DBData* dbit_obj_first(DBIterator* self, DBKey* out_key) { DBIterator_impl* it = (DBIterator_impl*)self; - + DB_COUNTSTAT(dbit_first); // position before the first entry it->ht_index = -1; @@ -1133,19 +1133,19 @@ DBData* dbit_obj_first(DBIterator* self, DBKey* out_key) } /** - * Fetches the last entry in the database. - * Returns the data of the entry. - * Puts the key in out_key, if out_key is not NULL. - * @param self Iterator - * @param out_key Key of the entry - * @return Data of the entry - * @protected - * @see DBIterator#last - */ +* Fetches the last entry in the database. +* Returns the data of the entry. +* Puts the key in out_key, if out_key is not NULL. +* @param self Iterator +* @param out_key Key of the entry +* @return Data of the entry +* @protected +* @see DBIterator#last +*/ DBData* dbit_obj_last(DBIterator* self, DBKey* out_key) { DBIterator_impl* it = (DBIterator_impl*)self; - + DB_COUNTSTAT(dbit_last); // position after the last entry it->ht_index = HASH_SIZE; @@ -1155,15 +1155,15 @@ DBData* dbit_obj_last(DBIterator* self, DBKey* out_key) } /** - * Fetches the next entry in the database. - * Returns the data of the entry. - * Puts the key in out_key, if out_key is not NULL. - * @param self Iterator - * @param out_key Key of the entry - * @return Data of the entry - * @protected - * @see DBIterator#next - */ +* Fetches the next entry in the database. +* Returns the data of the entry. +* Puts the key in out_key, if out_key is not NULL. +* @param self Iterator +* @param out_key Key of the entry +* @return Data of the entry +* @protected +* @see DBIterator#next +*/ DBData* dbit_obj_next(DBIterator* self, DBKey* out_key) { DBIterator_impl* it = (DBIterator_impl*)self; @@ -1231,15 +1231,15 @@ DBData* dbit_obj_next(DBIterator* self, DBKey* out_key) } /** - * Fetches the previous entry in the database. - * Returns the data of the entry. - * Puts the key in out_key, if out_key is not NULL. - * @param self Iterator - * @param out_key Key of the entry - * @return Data of the entry - * @protected - * @see DBIterator#prev - */ +* Fetches the previous entry in the database. +* Returns the data of the entry. +* Puts the key in out_key, if out_key is not NULL. +* @param self Iterator +* @param out_key Key of the entry +* @return Data of the entry +* @protected +* @see DBIterator#prev +*/ DBData* dbit_obj_prev(DBIterator* self, DBKey* out_key) { DBIterator_impl* it = (DBIterator_impl*)self; @@ -1267,7 +1267,7 @@ DBData* dbit_obj_prev(DBIterator* self, DBKey* out_key) node = &fake; } - + while( node ) {// next node if( node->left ) @@ -1308,14 +1308,14 @@ DBData* dbit_obj_prev(DBIterator* self, DBKey* out_key) } /** - * Returns true if the fetched entry exists. - * The databases entries might have NULL data, so use this to to test if - * the iterator is done. - * @param self Iterator - * @return true if the entry exists - * @protected - * @see DBIterator#exists - */ +* Returns true if the fetched entry exists. +* The databases entries might have NULL data, so use this to to test if +* the iterator is done. +* @param self Iterator +* @return true if the entry exists +* @protected +* @see DBIterator#exists +*/ bool dbit_obj_exists(DBIterator* self) { DBIterator_impl* it = (DBIterator_impl*)self; @@ -1325,17 +1325,17 @@ bool dbit_obj_exists(DBIterator* self) } /** - * Removes the current entry from the database. - * NOTE: {@link DBIterator#exists} will return false until another entry - * is fetched - * Puts data of the removed entry in out_data, if out_data is not NULL. - * @param self Iterator - * @param out_data Data of the removed entry. - * @return 1 if entry was removed, 0 otherwise - * @protected - * @see DBMap#remove - * @see DBIterator#remove - */ +* Removes the current entry from the database. +* NOTE: {@link DBIterator#exists} will return false until another entry +* is fetched +* Puts data of the removed entry in out_data, if out_data is not NULL. +* @param self Iterator +* @param out_data Data of the removed entry. +* @return 1 if entry was removed, 0 otherwise +* @protected +* @see DBMap#remove +* @see DBIterator#remove +*/ int dbit_obj_remove(DBIterator* self, DBData *out_data) { DBIterator_impl* it = (DBIterator_impl*)self; @@ -1359,10 +1359,10 @@ int dbit_obj_remove(DBIterator* self, DBData *out_data) } /** - * Destroys this iterator and unlocks the database. - * @param self Iterator - * @protected - */ +* Destroys this iterator and unlocks the database. +* @param self Iterator +* @protected +*/ void dbit_obj_destroy(DBIterator* self) { DBIterator_impl* it = (DBIterator_impl*)self; @@ -1375,14 +1375,14 @@ void dbit_obj_destroy(DBIterator* self) } /** - * Returns a new iterator for this database. - * The iterator keeps the database locked until it is destroyed. - * The database will keep functioning normally but will only free internal - * memory when unlocked, so destroy the iterator as soon as possible. - * @param self Database - * @return New iterator - * @protected - */ +* Returns a new iterator for this database. +* The iterator keeps the database locked until it is destroyed. +* The database will keep functioning normally but will only free internal +* memory when unlocked, so destroy the iterator as soon as possible. +* @param self Database +* @return New iterator +* @protected +*/ static DBIterator* db_obj_iterator(DBMap* self) { DBMap_impl* db = (DBMap_impl*)self; @@ -1408,13 +1408,13 @@ static DBIterator* db_obj_iterator(DBMap* self) } /** - * Returns true if the entry exists. - * @param self Interface of the database - * @param key Key that identifies the entry - * @return true is the entry exists - * @protected - * @see DBMap#exists - */ +* Returns true if the entry exists. +* @param self Interface of the database +* @param key Key that identifies the entry +* @return true is the entry exists +* @protected +* @see DBMap#exists +*/ static bool db_obj_exists(DBMap* self, DBKey key) { DBMap_impl* db = (DBMap_impl*)self; @@ -1459,13 +1459,13 @@ static bool db_obj_exists(DBMap* self, DBKey key) } /** - * Get the data of the entry identified by the key. - * @param self Interface of the database - * @param key Key that identifies the entry - * @return Data of the entry or NULL if not found - * @protected - * @see DBMap#get - */ +* Get the data of the entry identified by the key. +* @param self Interface of the database +* @param key Key that identifies the entry +* @return Data of the entry or NULL if not found +* @protected +* @see DBMap#get +*/ static DBData* db_obj_get(DBMap* self, DBKey key) { DBMap_impl* db = (DBMap_impl*)self; @@ -1511,21 +1511,21 @@ static DBData* db_obj_get(DBMap* self, DBKey key) } /** - * Get the data of the entries matched by match. - * It puts a maximum of max entries into buf. - * If buf is NULL, it only counts the matches. - * Returns the number of entries that matched. - * NOTE: if the value returned is greater than max, only the - * first max entries found are put into the buffer. - * @param self Interface of the database - * @param buf Buffer to put the data of the matched entries - * @param max Maximum number of data entries to be put into buf - * @param match Function that matches the database entries - * @param ... Extra arguments for match - * @return The number of entries that matched - * @protected - * @see DBMap#vgetall - */ +* Get the data of the entries matched by match. +* It puts a maximum of max entries into buf. +* If buf is NULL, it only counts the matches. +* Returns the number of entries that matched. +* NOTE: if the value returned is greater than max, only the +* first max entries found are put into the buffer. +* @param self Interface of the database +* @param buf Buffer to put the data of the matched entries +* @param max Maximum number of data entries to be put into buf +* @param match Function that matches the database entries +* @param ... Extra arguments for match +* @return The number of entries that matched +* @protected +* @see DBMap#vgetall +*/ static unsigned int db_obj_vgetall(DBMap* self, DBData **buf, unsigned int max, DBMatcher match, va_list args) { DBMap_impl* db = (DBMap_impl*)self; @@ -1554,17 +1554,17 @@ static unsigned int db_obj_vgetall(DBMap* self, DBData **buf, unsigned int max, } va_end(argscopy); } - + if (node->left) { node = node->left; continue; } - + if (node->right) { node = node->right; continue; } - + while (node) { parent = node->parent; if (parent && parent->right && parent->left == node) { @@ -1581,23 +1581,23 @@ static unsigned int db_obj_vgetall(DBMap* self, DBData **buf, unsigned int max, } /** - * Just calls {@link DBMap#vgetall}. - * Get the data of the entries matched by match. - * It puts a maximum of max entries into buf. - * If buf is NULL, it only counts the matches. - * Returns the number of entries that matched. - * NOTE: if the value returned is greater than max, only the - * first max entries found are put into the buffer. - * @param self Interface of the database - * @param buf Buffer to put the data of the matched entries - * @param max Maximum number of data entries to be put into buf - * @param match Function that matches the database entries - * @param ... Extra arguments for match - * @return The number of entries that matched - * @protected - * @see DBMap#vgetall - * @see DBMap#getall - */ +* Just calls {@link DBMap#vgetall}. +* Get the data of the entries matched by match. +* It puts a maximum of max entries into buf. +* If buf is NULL, it only counts the matches. +* Returns the number of entries that matched. +* NOTE: if the value returned is greater than max, only the +* first max entries found are put into the buffer. +* @param self Interface of the database +* @param buf Buffer to put the data of the matched entries +* @param max Maximum number of data entries to be put into buf +* @param match Function that matches the database entries +* @param ... Extra arguments for match +* @return The number of entries that matched +* @protected +* @see DBMap#vgetall +* @see DBMap#getall +*/ static unsigned int db_obj_getall(DBMap* self, DBData **buf, unsigned int max, DBMatcher match, ...) { va_list args; @@ -1613,17 +1613,17 @@ static unsigned int db_obj_getall(DBMap* self, DBData **buf, unsigned int max, D } /** - * 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 - * create. - * @param self Interface of the database - * @param key Key that identifies the entry - * @param create Function used to create the data if the entry doesn't exist - * @param args Extra arguments for create - * @return Data of the entry - * @protected - * @see DBMap#vensure - */ +* 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 +* create. +* @param self Interface of the database +* @param key Key that identifies the entry +* @param create Function used to create the data if the entry doesn't exist +* @param args Extra arguments for create +* @return Data of the entry +* @protected +* @see DBMap#vensure +*/ static DBData* db_obj_vensure(DBMap* self, DBKey key, DBCreateData create, va_list args) { DBMap_impl* db = (DBMap_impl*)self; @@ -1666,9 +1666,9 @@ static DBData* db_obj_vensure(DBMap* self, DBKey key, DBCreateData create, va_li va_list argscopy; if (db->item_count == UINT32_MAX) { ShowError("db_vensure: item_count overflow, aborting item insertion.\n" - "Database allocated at %s:%d", - db->alloc_file, db->alloc_line); - return NULL; + "Database allocated at %s:%d", + db->alloc_file, db->alloc_line); + return NULL; } DB_COUNTSTAT(db_node_alloc); node = ers_alloc(db->nodes, struct dbn); @@ -1711,19 +1711,19 @@ static DBData* db_obj_vensure(DBMap* self, DBKey key, DBCreateData create, va_li } /** - * Just calls {@link DBMap#vensure}. - * 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 - * create. - * @param self Interface of the database - * @param key Key that identifies the entry - * @param create Function used to create the data if the entry doesn't exist - * @param ... Extra arguments for create - * @return Data of the entry - * @protected - * @see DBMap#vensure - * @see DBMap#ensure - */ +* Just calls {@link DBMap#vensure}. +* 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 +* create. +* @param self Interface of the database +* @param key Key that identifies the entry +* @param create Function used to create the data if the entry doesn't exist +* @param ... Extra arguments for create +* @return Data of the entry +* @protected +* @see DBMap#vensure +* @see DBMap#ensure +*/ static DBData* db_obj_ensure(DBMap* self, DBKey key, DBCreateData create, ...) { va_list args; @@ -1739,18 +1739,18 @@ static DBData* db_obj_ensure(DBMap* self, DBKey key, DBCreateData create, ...) } /** - * Put the data identified by the key in the database. - * Puts the previous data in out_data, if out_data is not NULL. - * NOTE: Uses the new key, the old one is released. - * @param self Interface of the database - * @param key Key that identifies the data - * @param data Data to be put in the database - * @param out_data Previous data if the entry exists - * @return 1 if if the entry already exists, 0 otherwise - * @protected - * @see #db_malloc_dbn(void) - * @see DBMap#put - */ +* Put the data identified by the key in the database. +* Puts the previous data in out_data, if out_data is not NULL. +* NOTE: Uses the new key, the old one is released. +* @param self Interface of the database +* @param key Key that identifies the data +* @param data Data to be put in the database +* @param out_data Previous data if the entry exists +* @return 1 if if the entry already exists, 0 otherwise +* @protected +* @see #db_malloc_dbn(void) +* @see DBMap#put +*/ static int db_obj_put(DBMap* self, DBKey key, DBData data, DBData *out_data) { DBMap_impl* db = (DBMap_impl*)self; @@ -1763,8 +1763,8 @@ static int db_obj_put(DBMap* self, DBKey key, DBData data, DBData *out_data) if (db == NULL) return 0; // nullpo candidate if (db->global_lock) { ShowError("db_put: Database is being destroyed, aborting entry insertion.\n" - "Database allocated at %s:%d\n", - db->alloc_file, db->alloc_line); + "Database allocated at %s:%d\n", + db->alloc_file, db->alloc_line); return 0; // nullpo candidate } if (!(db->options&DB_OPT_ALLOW_NULL_KEY) && db_is_key_null(db->type, key)) { @@ -1778,8 +1778,8 @@ static int db_obj_put(DBMap* self, DBKey key, DBData data, DBData *out_data) if (db->item_count == UINT32_MAX) { ShowError("db_put: item_count overflow, aborting item insertion.\n" - "Database allocated at %s:%d", - db->alloc_file, db->alloc_line); + "Database allocated at %s:%d", + db->alloc_file, db->alloc_line); return 0; } // search for an equal node @@ -1845,17 +1845,17 @@ static int db_obj_put(DBMap* self, DBKey key, DBData data, DBData *out_data) } /** - * Remove an entry from the database. - * Puts the previous data in out_data, if out_data is not NULL. - * NOTE: The key (of the database) is released in {@link #db_free_add(DBMap_impl*,DBNode,DBNode *)}. - * @param self Interface of the database - * @param key Key that identifies the entry - * @param out_data Previous data if the entry exists - * @return 1 if if the entry already exists, 0 otherwise - * @protected - * @see #db_free_add(DBMap_impl*,DBNode,DBNode *) - * @see DBMap#remove - */ +* Remove an entry from the database. +* Puts the previous data in out_data, if out_data is not NULL. +* NOTE: The key (of the database) is released in {@link #db_free_add(DBMap_impl*,DBNode,DBNode *)}. +* @param self Interface of the database +* @param key Key that identifies the entry +* @param out_data Previous data if the entry exists +* @return 1 if if the entry already exists, 0 otherwise +* @protected +* @see #db_free_add(DBMap_impl*,DBNode,DBNode *) +* @see DBMap#remove +*/ static int db_obj_remove(DBMap* self, DBKey key, DBData *out_data) { DBMap_impl* db = (DBMap_impl*)self; @@ -1867,8 +1867,8 @@ static int db_obj_remove(DBMap* self, DBKey key, DBData *out_data) if (db == NULL) return 0; // nullpo candidate if (db->global_lock) { ShowError("db_remove: Database is being destroyed. Aborting entry deletion.\n" - "Database allocated at %s:%d\n", - db->alloc_file, db->alloc_line); + "Database allocated at %s:%d\n", + db->alloc_file, db->alloc_line); return 0; // nullpo candidate } if (!(db->options&DB_OPT_ALLOW_NULL_KEY) && db_is_key_null(db->type, key)) { @@ -1902,15 +1902,15 @@ static int db_obj_remove(DBMap* self, DBKey key, DBData *out_data) } /** - * Apply func to every entry in the database. - * Returns the sum of values returned by func. - * @param self Interface of the database - * @param func Function to be applied - * @param args Extra arguments for func - * @return Sum of the values returned by func - * @protected - * @see DBMap#vforeach - */ +* Apply func to every entry in the database. +* Returns the sum of values returned by func. +* @param self Interface of the database +* @param func Function to be applied +* @param args Extra arguments for func +* @return Sum of the values returned by func +* @protected +* @see DBMap#vforeach +*/ static int db_obj_vforeach(DBMap* self, DBApply func, va_list args) { DBMap_impl* db = (DBMap_impl*)self; @@ -1960,17 +1960,17 @@ static int db_obj_vforeach(DBMap* self, DBApply func, va_list args) } /** - * Just calls {@link DBMap#vforeach}. - * Apply func to every entry in the database. - * Returns the sum of values returned by func. - * @param self Interface of the database - * @param func Function to be applyed - * @param ... Extra arguments for func - * @return Sum of the values returned by func - * @protected - * @see DBMap#vforeach - * @see DBMap#foreach - */ +* Just calls {@link DBMap#vforeach}. +* Apply func to every entry in the database. +* Returns the sum of values returned by func. +* @param self Interface of the database +* @param func Function to be applyed +* @param ... Extra arguments for func +* @return Sum of the values returned by func +* @protected +* @see DBMap#vforeach +* @see DBMap#foreach +*/ static int db_obj_foreach(DBMap* self, DBApply func, ...) { va_list args; @@ -1986,17 +1986,17 @@ static int db_obj_foreach(DBMap* self, DBApply func, ...) } /** - * Removes all entries from the database. - * Before deleting an entry, func is applied to it. - * Releases the key and the data. - * Returns the sum of values returned by func, if it exists. - * @param self Interface of the database - * @param func Function to be applied to every entry before deleting - * @param args Extra arguments for func - * @return Sum of values returned by func - * @protected - * @see DBMap#vclear - */ +* Removes all entries from the database. +* Before deleting an entry, func is applied to it. +* Releases the key and the data. +* Returns the sum of values returned by func, if it exists. +* @param self Interface of the database +* @param func Function to be applied to every entry before deleting +* @param args Extra arguments for func +* @return Sum of values returned by func +* @protected +* @see DBMap#vclear +*/ static int db_obj_vclear(DBMap* self, DBApply func, va_list args) { DBMap_impl* db = (DBMap_impl*)self; @@ -2056,21 +2056,21 @@ static int db_obj_vclear(DBMap* self, DBApply func, va_list args) } /** - * Just calls {@link DBMap#vclear}. - * Removes all entries from the database. - * Before deleting an entry, func is applied to it. - * Releases the key and the data. - * Returns the sum of values returned by func, if it exists. - * NOTE: This locks the database globally. Any attempt to insert or remove - * a database entry will give an error and be aborted (except for clearing). - * @param self Interface of the database - * @param func Function to be applied to every entry before deleting - * @param ... Extra arguments for func - * @return Sum of values returned by func - * @protected - * @see DBMap#vclear - * @see DBMap#clear - */ +* Just calls {@link DBMap#vclear}. +* Removes all entries from the database. +* Before deleting an entry, func is applied to it. +* Releases the key and the data. +* Returns the sum of values returned by func, if it exists. +* NOTE: This locks the database globally. Any attempt to insert or remove +* a database entry will give an error and be aborted (except for clearing). +* @param self Interface of the database +* @param func Function to be applied to every entry before deleting +* @param ... Extra arguments for func +* @return Sum of values returned by func +* @protected +* @see DBMap#vclear +* @see DBMap#clear +*/ static int db_obj_clear(DBMap* self, DBApply func, ...) { va_list args; @@ -2086,18 +2086,18 @@ static int db_obj_clear(DBMap* self, DBApply func, ...) } /** - * Finalize the database, feeing all the memory it uses. - * Before deleting an entry, func is applied to it. - * Returns the sum of values returned by func, if it exists. - * NOTE: This locks the database globally. Any attempt to insert or remove - * a database entry will give an error and be aborted (except for clearing). - * @param self Interface of the database - * @param func Function to be applied to every entry before deleting - * @param args Extra arguments for func - * @return Sum of values returned by func - * @protected - * @see DBMap#vdestroy - */ +* Finalize the database, feeing all the memory it uses. +* Before deleting an entry, func is applied to it. +* Returns the sum of values returned by func, if it exists. +* NOTE: This locks the database globally. Any attempt to insert or remove +* a database entry will give an error and be aborted (except for clearing). +* @param self Interface of the database +* @param func Function to be applied to every entry before deleting +* @param args Extra arguments for func +* @return Sum of values returned by func +* @protected +* @see DBMap#vdestroy +*/ static int db_obj_vdestroy(DBMap* self, DBApply func, va_list args) { DBMap_impl* db = (DBMap_impl*)self; @@ -2107,21 +2107,21 @@ static int db_obj_vdestroy(DBMap* self, DBApply func, va_list args) if (db == NULL) return 0; // nullpo candidate if (db->global_lock) { ShowError("db_vdestroy: Database is already locked for destruction. Aborting second database destruction.\n" - "Database allocated at %s:%d\n", - db->alloc_file, db->alloc_line); + "Database allocated at %s:%d\n", + db->alloc_file, db->alloc_line); return 0; } if (db->free_lock) ShowWarning("db_vdestroy: Database is still in use, %u lock(s) left. Continuing database destruction.\n" - "Database allocated at %s:%d\n", - db->free_lock, db->alloc_file, db->alloc_line); + "Database allocated at %s:%d\n", + db->free_lock, db->alloc_file, db->alloc_line); #ifdef DB_ENABLE_STATS switch (db->type) { - case DB_INT: DB_COUNTSTAT(db_int_destroy); break; - 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_INT: DB_COUNTSTAT(db_int_destroy); break; + 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; } #endif /* DB_ENABLE_STATS */ db_free_lock(db); @@ -2137,21 +2137,21 @@ static int db_obj_vdestroy(DBMap* self, DBApply func, va_list args) } /** - * Just calls {@link DBMap#db_vdestroy}. - * Finalize the database, feeing all the memory it uses. - * Before deleting an entry, func is applied to it. - * Releases the key and the data. - * Returns the sum of values returned by func, if it exists. - * NOTE: This locks the database globally. Any attempt to insert or remove - * a database entry will give an error and be aborted. - * @param self Database - * @param func Function to be applied to every entry before deleting - * @param ... Extra arguments for func - * @return Sum of values returned by func - * @protected - * @see DBMap#vdestroy - * @see DBMap#destroy - */ +* Just calls {@link DBMap#db_vdestroy}. +* Finalize the database, feeing all the memory it uses. +* Before deleting an entry, func is applied to it. +* Releases the key and the data. +* Returns the sum of values returned by func, if it exists. +* NOTE: This locks the database globally. Any attempt to insert or remove +* a database entry will give an error and be aborted. +* @param self Database +* @param func Function to be applied to every entry before deleting +* @param ... Extra arguments for func +* @return Sum of values returned by func +* @protected +* @see DBMap#vdestroy +* @see DBMap#destroy +*/ static int db_obj_destroy(DBMap* self, DBApply func, ...) { va_list args; @@ -2167,13 +2167,13 @@ static int db_obj_destroy(DBMap* self, DBApply func, ...) } /** - * Return the size of the database (number of items in the database). - * @param self Interface of the database - * @return Size of the database - * @protected - * @see DBMap_impl#item_count - * @see DBMap#size - */ +* Return the size of the database (number of items in the database). +* @param self Interface of the database +* @return Size of the database +* @protected +* @see DBMap_impl#item_count +* @see DBMap#size +*/ static unsigned int db_obj_size(DBMap* self) { DBMap_impl* db = (DBMap_impl*)self; @@ -2190,13 +2190,13 @@ static unsigned int db_obj_size(DBMap* self) } /** - * Return the type of database. - * @param self Interface of the database - * @return Type of the database - * @protected - * @see DBMap_impl#type - * @see DBMap#type - */ +* Return the type of database. +* @param self Interface of the database +* @return Type of the database +* @protected +* @see DBMap_impl#type +* @see DBMap#type +*/ static DBType db_obj_type(DBMap* self) { DBMap_impl* db = (DBMap_impl*)self; @@ -2213,13 +2213,13 @@ static DBType db_obj_type(DBMap* self) } /** - * Return the options of the database. - * @param self Interface of the database - * @return Options of the database - * @protected - * @see DBMap_impl#options - * @see DBMap#options - */ +* Return the options of the database. +* @param self Interface of the database +* @return Options of the database +* @protected +* @see DBMap_impl#options +* @see DBMap#options +*/ static DBOptions db_obj_options(DBMap* self) { DBMap_impl* db = (DBMap_impl*)self; @@ -2236,120 +2236,121 @@ static DBOptions db_obj_options(DBMap* self) } /*****************************************************************************\ - * (5) Section with public functions. - * db_fix_options - Apply database type restrictions to the options. - * db_default_cmp - Get the default comparator for a type of database. - * db_default_hash - Get the default hasher for a type of database. - * db_default_release - Get the default releaser for a type of database with the specified options. - * db_custom_release - Get a releaser that behaves a certains way. - * db_alloc - Allocate a new database. - * 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_i2data - Manual cast from 'int' to 'DBData'. - * db_ui2data - Manual cast from 'unsigned int' to 'DBData'. - * db_ptr2data - Manual cast from 'void*' to 'DBData'. - * db_data2i - Gets 'int' value from 'DBData'. - * db_data2ui - Gets 'unsigned int' value from 'DBData'. - * db_data2ptr - Gets 'void*' value from 'DBData'. - * db_init - Initializes the database system. - * db_final - Finalizes the database system. +* (5) Section with public functions. +* db_fix_options - Apply database type restrictions to the options. +* db_default_cmp - Get the default comparator for a type of database. +* db_default_hash - Get the default hasher for a type of database. +* db_default_release - Get the default releaser for a type of database with the specified options. +* db_custom_release - Get a releaser that behaves a certains way. +* db_alloc - Allocate a new database. +* 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_i2data - Manual cast from 'int' to 'DBData'. +* db_ui2data - Manual cast from 'unsigned int' to 'DBData'. +* db_ptr2data - Manual cast from 'void*' to 'DBData'. +* db_data2i - Gets 'int' value from 'DBData'. +* db_data2ui - Gets 'unsigned int' value from 'DBData'. +* db_data2ptr - Gets 'void*' value from 'DBData'. +* db_init - Initializes the database system. +* db_final - Finalizes the database system. \*****************************************************************************/ /** - * Returns the fixed options according to the database type. - * Sets required options and unsets unsupported options. - * For numeric databases DB_OPT_DUP_KEY and DB_OPT_RELEASE_KEY are unset. - * @param type Type of the database - * @param options Original options of the database - * @return Fixed options of the database - * @private - * @see #db_default_release(DBType,DBOptions) - * @see #db_alloc(const char *,int,DBType,DBOptions,unsigned short) - */ +* Returns the fixed options according to the database type. +* Sets required options and unsets unsupported options. +* For numeric databases DB_OPT_DUP_KEY and DB_OPT_RELEASE_KEY are unset. +* @param type Type of the database +* @param options Original options of the database +* @return Fixed options of the database +* @private +* @see #db_default_release(DBType,DBOptions) +* @see #db_alloc(const char *,int,DBType,DBOptions,unsigned short) +*/ 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 - return (DBOptions)(options&~(DB_OPT_DUP_KEY|DB_OPT_RELEASE_KEY)); - - default: - ShowError("db_fix_options: Unknown database type %u with options %x\n", type, options); - case DB_STRING: - case DB_ISTRING: // String databases, no fix required - return options; + case DB_INT: + case DB_UINT: // Numeric database, do nothing with the keys + return (DBOptions)(options&~(DB_OPT_DUP_KEY|DB_OPT_RELEASE_KEY)); + + default: + ShowError("db_fix_options: Unknown database type %u with options %x\n", type, options); + case DB_STRING: + case DB_ISTRING: // String databases, no fix required + return options; } } + /** - * Returns the default comparator for the specified type of database. - * @param type Type of database - * @return Comparator for the type of database or NULL if unknown database - * @public - * @see #db_int_cmp(DBKey,DBKey,unsigned short) - * @see #db_uint_cmp(DBKey,DBKey,unsigned short) - * @see #db_string_cmp(DBKey,DBKey,unsigned short) - * @see #db_istring_cmp(DBKey,DBKey,unsigned short) - */ +* Returns the default comparator for the specified type of database. +* @param type Type of database +* @return Comparator for the type of database or NULL if unknown database +* @public +* @see #db_int_cmp(DBKey,DBKey,unsigned short) +* @see #db_uint_cmp(DBKey,DBKey,unsigned short) +* @see #db_string_cmp(DBKey,DBKey,unsigned short) +* @see #db_istring_cmp(DBKey,DBKey,unsigned short) +*/ DBComparator db_default_cmp(DBType type) { DB_COUNTSTAT(db_default_cmp); switch (type) { - case DB_INT: return &db_int_cmp; - case DB_UINT: return &db_uint_cmp; - case DB_STRING: return &db_string_cmp; - case DB_ISTRING: return &db_istring_cmp; - default: - ShowError("db_default_cmp: Unknown database type %u\n", type); - return NULL; + case DB_INT: return &db_int_cmp; + case DB_UINT: return &db_uint_cmp; + case DB_STRING: return &db_string_cmp; + case DB_ISTRING: return &db_istring_cmp; + default: + ShowError("db_default_cmp: Unknown database type %u\n", type); + return NULL; } } /** - * Returns the default hasher for the specified type of database. - * @param type Type of database - * @return Hasher of the type of database or NULL if unknown database - * @public - * @see #db_int_hash(DBKey,unsigned short) - * @see #db_uint_hash(DBKey,unsigned short) - * @see #db_string_hash(DBKey,unsigned short) - * @see #db_istring_hash(DBKey,unsigned short) - */ +* Returns the default hasher for the specified type of database. +* @param type Type of database +* @return Hasher of the type of database or NULL if unknown database +* @public +* @see #db_int_hash(DBKey,unsigned short) +* @see #db_uint_hash(DBKey,unsigned short) +* @see #db_string_hash(DBKey,unsigned short) +* @see #db_istring_hash(DBKey,unsigned short) +*/ DBHasher db_default_hash(DBType type) { DB_COUNTSTAT(db_default_hash); switch (type) { - case DB_INT: return &db_int_hash; - case DB_UINT: return &db_uint_hash; - case DB_STRING: return &db_string_hash; - case DB_ISTRING: return &db_istring_hash; - default: - ShowError("db_default_hash: Unknown database type %u\n", type); - return NULL; + case DB_INT: return &db_int_hash; + case DB_UINT: return &db_uint_hash; + case DB_STRING: return &db_string_hash; + case DB_ISTRING: return &db_istring_hash; + default: + ShowError("db_default_hash: Unknown database type %u\n", type); + return NULL; } } /** - * Returns the default releaser for the specified type of database with the - * specified options. - * NOTE: the options are fixed with {@link #db_fix_options(DBType,DBOptions)} - * before choosing the releaser. - * @param type Type of database - * @param options Options of the database - * @return Default releaser for the type of database with the specified options - * @public - * @see #db_release_nothing(DBKey,DBData,DBRelease) - * @see #db_release_key(DBKey,DBData,DBRelease) - * @see #db_release_data(DBKey,DBData,DBRelease) - * @see #db_release_both(DBKey,DBData,DBRelease) - * @see #db_custom_release(DBRelease) - */ +* Returns the default releaser for the specified type of database with the +* specified options. +* NOTE: the options are fixed with {@link #db_fix_options(DBType,DBOptions)} +* before choosing the releaser. +* @param type Type of database +* @param options Options of the database +* @return Default releaser for the type of database with the specified options +* @public +* @see #db_release_nothing(DBKey,DBData,DBRelease) +* @see #db_release_key(DBKey,DBData,DBRelease) +* @see #db_release_data(DBKey,DBData,DBRelease) +* @see #db_release_both(DBKey,DBData,DBRelease) +* @see #db_custom_release(DBRelease) +*/ DBReleaser db_default_release(DBType type, DBOptions options) { DB_COUNTSTAT(db_default_release); - options = db_fix_options(type, options); + options = DB->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 @@ -2361,45 +2362,45 @@ DBReleaser db_default_release(DBType type, DBOptions options) } /** - * Returns the releaser that releases the specified release options. - * @param which Options that specified what the releaser releases - * @return Releaser for the specified release options - * @public - * @see #db_release_nothing(DBKey,DBData,DBRelease) - * @see #db_release_key(DBKey,DBData,DBRelease) - * @see #db_release_data(DBKey,DBData,DBRelease) - * @see #db_release_both(DBKey,DBData,DBRelease) - * @see #db_default_release(DBType,DBOptions) - */ +* Returns the releaser that releases the specified release options. +* @param which Options that specified what the releaser releases +* @return Releaser for the specified release options +* @public +* @see #db_release_nothing(DBKey,DBData,DBRelease) +* @see #db_release_key(DBKey,DBData,DBRelease) +* @see #db_release_data(DBKey,DBData,DBRelease) +* @see #db_release_both(DBKey,DBData,DBRelease) +* @see #db_default_release(DBType,DBOptions) +*/ DBReleaser db_custom_release(DBRelease which) { DB_COUNTSTAT(db_custom_release); switch (which) { - case DB_RELEASE_NOTHING: return &db_release_nothing; - case DB_RELEASE_KEY: return &db_release_key; - case DB_RELEASE_DATA: return &db_release_data; - case DB_RELEASE_BOTH: return &db_release_both; - default: - ShowError("db_custom_release: Unknown release options %u\n", which); - return NULL; + case DB_RELEASE_NOTHING: return &db_release_nothing; + case DB_RELEASE_KEY: return &db_release_key; + case DB_RELEASE_DATA: return &db_release_data; + case DB_RELEASE_BOTH: return &db_release_both; + default: + ShowError("db_custom_release: Unknown release options %u\n", which); + return NULL; } } /** - * Allocate a new database of the specified type. - * NOTE: the options are fixed by {@link #db_fix_options(DBType,DBOptions)} - * before creating the database. - * @param file File where the database is being allocated - * @param line Line of the file where the database is being allocated - * @param type Type of database - * @param options Options of the database - * @param maxlen Maximum length of the string to be used as key in string - * databases. If 0, the maximum number of maxlen is used (64K). - * @return The interface of the database - * @public - * @see #DBMap_impl - * @see #db_fix_options(DBType,DBOptions) - */ +* Allocate a new database of the specified type. +* NOTE: the options are fixed by {@link #db_fix_options(DBType,DBOptions)} +* before creating the database. +* @param file File where the database is being allocated +* @param line Line of the file where the database is being allocated +* @param type Type of database +* @param options Options of the database +* @param maxlen Maximum length of the string to be used as key in string +* databases. If 0, the maximum number of maxlen is used (64K). +* @return The interface of the database +* @public +* @see #DBMap_impl +* @see #db_fix_options(DBType,DBOptions) +*/ DBMap* db_alloc(const char *file, int line, DBType type, DBOptions options, unsigned short maxlen) { DBMap_impl* db; @@ -2408,15 +2409,15 @@ DBMap* db_alloc(const char *file, int line, DBType type, DBOptions options, unsi #ifdef DB_ENABLE_STATS DB_COUNTSTAT(db_alloc); switch (type) { - case DB_INT: DB_COUNTSTAT(db_int_alloc); break; - 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_INT: DB_COUNTSTAT(db_int_alloc); break; + 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; } #endif /* DB_ENABLE_STATS */ db = ers_alloc(db_alloc_ers, struct DBMap_impl); - options = db_fix_options(type, options); + options = DB->fix_options(type, options); /* Interface of the database */ db->vtable.iterator = db_obj_iterator; db->vtable.exists = db_obj_exists; @@ -2446,9 +2447,9 @@ DBMap* db_alloc(const char *file, int line, DBType type, DBOptions options, unsi db->free_lock = 0; /* Other */ db->nodes = ers_new(sizeof(struct dbn),"db.c::db_alloc",ERS_OPT_NONE); - db->cmp = db_default_cmp(type); - db->hash = db_default_hash(type); - db->release = db_default_release(type, options); + db->cmp = DB->default_cmp(type); + db->hash = DB->default_hash(type); + db->release = DB->default_release(type, options); for (i = 0; i < HASH_SIZE; i++) db->ht[i] = NULL; db->cache = NULL; @@ -2465,11 +2466,11 @@ DBMap* db_alloc(const char *file, int line, DBType type, DBOptions options, unsi } /** - * Manual cast from 'int' to the union DBKey. - * @param key Key to be casted - * @return The key as a DBKey union - * @public - */ +* Manual cast from 'int' to the union DBKey. +* @param key Key to be casted +* @return The key as a DBKey union +* @public +*/ DBKey db_i2key(int key) { DBKey ret; @@ -2480,11 +2481,11 @@ DBKey db_i2key(int key) } /** - * Manual cast from 'unsigned int' to the union DBKey. - * @param key Key to be casted - * @return The key as a DBKey union - * @public - */ +* Manual cast from 'unsigned int' to the union DBKey. +* @param key Key to be casted +* @return The key as a DBKey union +* @public +*/ DBKey db_ui2key(unsigned int key) { DBKey ret; @@ -2495,11 +2496,11 @@ DBKey db_ui2key(unsigned int key) } /** - * Manual cast from 'const char *' to the union DBKey. - * @param key Key to be casted - * @return The key as a DBKey union - * @public - */ +* Manual cast from 'const char *' to the union DBKey. +* @param key Key to be casted +* @return The key as a DBKey union +* @public +*/ DBKey db_str2key(const char *key) { DBKey ret; @@ -2510,11 +2511,11 @@ DBKey db_str2key(const char *key) } /** - * Manual cast from 'int' to the struct DBData. - * @param data Data to be casted - * @return The data as a DBData struct - * @public - */ +* Manual cast from 'int' to the struct DBData. +* @param data Data to be casted +* @return The data as a DBData struct +* @public +*/ DBData db_i2data(int data) { DBData ret; @@ -2526,11 +2527,11 @@ DBData db_i2data(int data) } /** - * Manual cast from 'unsigned int' to the struct DBData. - * @param data Data to be casted - * @return The data as a DBData struct - * @public - */ +* Manual cast from 'unsigned int' to the struct DBData. +* @param data Data to be casted +* @return The data as a DBData struct +* @public +*/ DBData db_ui2data(unsigned int data) { DBData ret; @@ -2542,11 +2543,11 @@ DBData db_ui2data(unsigned int data) } /** - * Manual cast from 'void *' to the struct DBData. - * @param data Data to be casted - * @return The data as a DBData struct - * @public - */ +* Manual cast from 'void *' to the struct DBData. +* @param data Data to be casted +* @return The data as a DBData struct +* @public +*/ DBData db_ptr2data(void *data) { DBData ret; @@ -2558,12 +2559,12 @@ DBData db_ptr2data(void *data) } /** - * Gets int type data from struct DBData. - * If data is not int type, returns 0. - * @param data Data - * @return Integer value of the data. - * @public - */ +* Gets int type data from struct DBData. +* If data is not int type, returns 0. +* @param data Data +* @return Integer value of the data. +* @public +*/ int db_data2i(DBData *data) { DB_COUNTSTAT(db_data2i); @@ -2573,12 +2574,12 @@ int db_data2i(DBData *data) } /** - * Gets unsigned int type data from struct DBData. - * If data is not unsigned int type, returns 0. - * @param data Data - * @return Unsigned int value of the data. - * @public - */ +* Gets unsigned int type data from struct DBData. +* If data is not unsigned int type, returns 0. +* @param data Data +* @return Unsigned int value of the data. +* @public +*/ unsigned int db_data2ui(DBData *data) { DB_COUNTSTAT(db_data2ui); @@ -2588,12 +2589,12 @@ unsigned int db_data2ui(DBData *data) } /** - * Gets void* type data from struct DBData. - * If data is not void* type, returns NULL. - * @param data Data - * @return Void* value of the data. - * @public - */ +* Gets void* type data from struct DBData. +* If data is not void* type, returns NULL. +* @param data Data +* @return Void* value of the data. +* @public +*/ void* db_data2ptr(DBData *data) { DB_COUNTSTAT(db_data2ptr); @@ -2603,10 +2604,10 @@ void* db_data2ptr(DBData *data) } /** - * Initializes the database system. - * @public - * @see #db_final(void) - */ +* Initializes the database system. +* @public +* @see #db_final(void) +*/ void db_init(void) { db_iterator_ers = ers_new(sizeof(struct DBIterator_impl),"db.c::db_iterator_ers",ERS_OPT_NONE); db_alloc_ers = ers_new(sizeof(struct DBMap_impl),"db.c::db_alloc_ers",ERS_OPT_NONE); @@ -2614,93 +2615,93 @@ void db_init(void) { } /** - * Finalizes the database system. - * @public - * @see #db_init(void) - */ +* Finalizes the database system. +* @public +* @see #db_init(void) +*/ void db_final(void) { #ifdef DB_ENABLE_STATS DB_COUNTSTAT(db_final); ShowInfo(CL_WHITE"Database nodes"CL_RESET":\n" - "allocated %u, freed %u\n", - stats.db_node_alloc, stats.db_node_free); + "allocated %u, freed %u\n", + stats.db_node_alloc, stats.db_node_free); ShowInfo(CL_WHITE"Database types"CL_RESET":\n" - "DB_INT : allocated %10u, destroyed %10u\n" - "DB_UINT : allocated %10u, destroyed %10u\n" - "DB_STRING : allocated %10u, destroyed %10u\n" - "DB_ISTRING : 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); + "DB_INT : allocated %10u, destroyed %10u\n" + "DB_UINT : allocated %10u, destroyed %10u\n" + "DB_STRING : allocated %10u, destroyed %10u\n" + "DB_ISTRING : 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); 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" - "db_is_key_null %10u,\n" - "db_dup_key %10u, db_dup_key_free %10u,\n" - "db_free_add %10u, db_free_remove %10u,\n" - "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_int_hash %10u, db_uint_hash %10u,\n" - "db_string_hash %10u, db_istring_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" - "dbit_next %10u, dbit_prev %10u,\n" - "dbit_exists %10u, dbit_remove %10u,\n" - "dbit_destroy %10u, db_iterator %10u,\n" - "db_exits %10u, db_get %10u,\n" - "db_getall %10u, db_vgetall %10u,\n" - "db_ensure %10u, db_vensure %10u,\n" - "db_put %10u, db_remove %10u,\n" - "db_foreach %10u, db_vforeach %10u,\n" - "db_clear %10u, db_vclear %10u,\n" - "db_destroy %10u, db_vdestroy %10u,\n" - "db_size %10u, db_type %10u,\n" - "db_options %10u, db_fix_options %10u,\n" - "db_default_cmp %10u, db_default_hash %10u,\n" - "db_default_release %10u, db_custom_release %10u,\n" - "db_alloc %10u, db_i2key %10u,\n" - "db_ui2key %10u, db_str2key %10u,\n" - "db_i2data %10u, db_ui2data %10u,\n" - "db_ptr2data %10u, db_data2i %10u,\n" - "db_data2ui %10u, db_data2ptr %10u,\n" - "db_init %10u, db_final %10u\n", - stats.db_rotate_left, stats.db_rotate_right, - stats.db_rebalance, stats.db_rebalance_erase, - stats.db_is_key_null, - stats.db_dup_key, stats.db_dup_key_free, - stats.db_free_add, stats.db_free_remove, - 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_int_hash, stats.db_uint_hash, - stats.db_string_hash, stats.db_istring_hash, - stats.db_release_nothing, stats.db_release_key, - stats.db_release_data, stats.db_release_both, - stats.dbit_first, stats.dbit_last, - stats.dbit_next, stats.dbit_prev, - stats.dbit_exists, stats.dbit_remove, - stats.dbit_destroy, stats.db_iterator, - stats.db_exists, stats.db_get, - stats.db_getall, stats.db_vgetall, - stats.db_ensure, stats.db_vensure, - stats.db_put, stats.db_remove, - stats.db_foreach, stats.db_vforeach, - stats.db_clear, stats.db_vclear, - stats.db_destroy, stats.db_vdestroy, - stats.db_size, stats.db_type, - stats.db_options, stats.db_fix_options, - stats.db_default_cmp, stats.db_default_hash, - stats.db_default_release, stats.db_custom_release, - stats.db_alloc, stats.db_i2key, - stats.db_ui2key, stats.db_str2key, - stats.db_i2data, stats.db_ui2data, - stats.db_ptr2data, stats.db_data2i, - stats.db_data2ui, stats.db_data2ptr, - stats.db_init, stats.db_final); + "db_rotate_left %10u, db_rotate_right %10u,\n" + "db_rebalance %10u, db_rebalance_erase %10u,\n" + "db_is_key_null %10u,\n" + "db_dup_key %10u, db_dup_key_free %10u,\n" + "db_free_add %10u, db_free_remove %10u,\n" + "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_int_hash %10u, db_uint_hash %10u,\n" + "db_string_hash %10u, db_istring_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" + "dbit_next %10u, dbit_prev %10u,\n" + "dbit_exists %10u, dbit_remove %10u,\n" + "dbit_destroy %10u, db_iterator %10u,\n" + "db_exits %10u, db_get %10u,\n" + "db_getall %10u, db_vgetall %10u,\n" + "db_ensure %10u, db_vensure %10u,\n" + "db_put %10u, db_remove %10u,\n" + "db_foreach %10u, db_vforeach %10u,\n" + "db_clear %10u, db_vclear %10u,\n" + "db_destroy %10u, db_vdestroy %10u,\n" + "db_size %10u, db_type %10u,\n" + "db_options %10u, db_fix_options %10u,\n" + "db_default_cmp %10u, db_default_hash %10u,\n" + "db_default_release %10u, db_custom_release %10u,\n" + "db_alloc %10u, db_i2key %10u,\n" + "db_ui2key %10u, db_str2key %10u,\n" + "db_i2data %10u, db_ui2data %10u,\n" + "db_ptr2data %10u, db_data2i %10u,\n" + "db_data2ui %10u, db_data2ptr %10u,\n" + "db_init %10u, db_final %10u\n", + stats.db_rotate_left, stats.db_rotate_right, + stats.db_rebalance, stats.db_rebalance_erase, + stats.db_is_key_null, + stats.db_dup_key, stats.db_dup_key_free, + stats.db_free_add, stats.db_free_remove, + 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_int_hash, stats.db_uint_hash, + stats.db_string_hash, stats.db_istring_hash, + stats.db_release_nothing, stats.db_release_key, + stats.db_release_data, stats.db_release_both, + stats.dbit_first, stats.dbit_last, + stats.dbit_next, stats.dbit_prev, + stats.dbit_exists, stats.dbit_remove, + stats.dbit_destroy, stats.db_iterator, + stats.db_exists, stats.db_get, + stats.db_getall, stats.db_vgetall, + stats.db_ensure, stats.db_vensure, + stats.db_put, stats.db_remove, + stats.db_foreach, stats.db_vforeach, + stats.db_clear, stats.db_vclear, + stats.db_destroy, stats.db_vdestroy, + stats.db_size, stats.db_type, + stats.db_options, stats.db_fix_options, + stats.db_default_cmp, stats.db_default_hash, + stats.db_default_release, stats.db_custom_release, + stats.db_alloc, stats.db_i2key, + stats.db_ui2key, stats.db_str2key, + stats.db_i2data, stats.db_ui2data, + stats.db_ptr2data, stats.db_data2i, + stats.db_data2ui, stats.db_data2ptr, + stats.db_init, stats.db_final); #endif /* DB_ENABLE_STATS */ ers_destroy(db_iterator_ers); ers_destroy(db_alloc_ers); @@ -2828,3 +2829,25 @@ 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; +} \ No newline at end of file diff --git a/src/common/db.h b/src/common/db.h index 4fe6a93d6..f1f6146be 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),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)) ) // 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))) ) // 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))) ) // 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))) ) // 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) ) // 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) ) // 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) ) // 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),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) ) //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))) ) // Database creation and destruction macros -#define idb_alloc(opt) db_alloc(__FILE__,__LINE__,DB_INT,(opt),sizeof(int)) -#define uidb_alloc(opt) db_alloc(__FILE__,__LINE__,DB_UINT,(opt),sizeof(unsigned int)) -#define strdb_alloc(opt,maxlen) db_alloc(__FILE__,__LINE__,DB_STRING,(opt),(maxlen)) -#define stridb_alloc(opt,maxlen) db_alloc(__FILE__,__LINE__,DB_ISTRING,(opt),(maxlen)) +#define idb_alloc(opt) DB->alloc(__FILE__,__LINE__,DB_INT,(opt),sizeof(int)) +#define uidb_alloc(opt) DB->alloc(__FILE__,__LINE__,DB_UINT,(opt),sizeof(unsigned int)) +#define strdb_alloc(opt,maxlen) DB->alloc(__FILE__,__LINE__,DB_STRING,(opt),(maxlen)) +#define stridb_alloc(opt,maxlen) DB->alloc(__FILE__,__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) ( 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_remove(dbi) ( (dbi)->remove(dbi,NULL) ) #define dbi_exists(dbi) ( (dbi)->exists(dbi) ) #define dbi_destroy(dbi) ( (dbi)->destroy(dbi) ) @@ -692,6 +692,7 @@ struct DBMap { * db_final - Finalizes the database system. * \*****************************************************************************/ +struct db_interface { /** * Returns the fixed options according to the database type. * Sets required options and unsets unsupported options. @@ -704,7 +705,7 @@ struct DBMap { * @see #DBOptions * @see #db_default_release(DBType,DBOptions) */ -DBOptions db_fix_options(DBType type, DBOptions options); +DBOptions (*fix_options) (DBType type, DBOptions options); /** * Returns the default comparator for the type of database. @@ -714,7 +715,7 @@ DBOptions db_fix_options(DBType type, DBOptions options); * @see #DBType * @see #DBComparator */ -DBComparator db_default_cmp(DBType type); +DBComparator (*default_cmp) (DBType type); /** * Returns the default hasher for the specified type of database. @@ -724,7 +725,7 @@ DBComparator db_default_cmp(DBType type); * @see #DBType * @see #DBHasher */ -DBHasher db_default_hash(DBType type); +DBHasher (*default_hash) (DBType type); /** * Returns the default releaser for the specified type of database with the @@ -741,7 +742,7 @@ DBHasher db_default_hash(DBType type); * @see #db_fix_options(DBType,DBOptions) * @see #db_custom_release(DBRelease) */ -DBReleaser db_default_release(DBType type, DBOptions options); +DBReleaser (*default_release) (DBType type, DBOptions options); /** * Returns the releaser that behaves as which specifies. @@ -752,7 +753,7 @@ DBReleaser db_default_release(DBType type, DBOptions options); * @see #DBReleaser * @see #db_default_release(DBType,DBOptions) */ -DBReleaser db_custom_release(DBRelease which); +DBReleaser (*custom_release) (DBRelease which); /** * Allocate a new database of the specified type. @@ -775,7 +776,7 @@ DBReleaser db_custom_release(DBRelease which); * @see #db_default_release(DBType,DBOptions) * @see #db_fix_options(DBType,DBOptions) */ -DBMap* db_alloc(const char *file, int line, DBType type, DBOptions options, unsigned short maxlen); +DBMap* (*alloc) (const char *file, int line, DBType type, DBOptions options, unsigned short maxlen); /** * Manual cast from 'int' to the union DBKey. @@ -783,7 +784,7 @@ DBMap* db_alloc(const char *file, int line, DBType type, DBOptions options, unsi * @return The key as a DBKey union * @public */ -DBKey db_i2key(int key); +DBKey (*i2key) (int key); /** * Manual cast from 'unsigned int' to the union DBKey. @@ -791,7 +792,7 @@ DBKey db_i2key(int key); * @return The key as a DBKey union * @public */ -DBKey db_ui2key(unsigned int key); +DBKey (*ui2key) (unsigned int key); /** * Manual cast from 'unsigned char *' to the union DBKey. @@ -799,7 +800,7 @@ DBKey db_ui2key(unsigned int key); * @return The key as a DBKey union * @public */ -DBKey db_str2key(const char *key); +DBKey (*str2key) (const char *key); /** * Manual cast from 'int' to the struct DBData. @@ -807,7 +808,7 @@ DBKey db_str2key(const char *key); * @return The data as a DBData struct * @public */ -DBData db_i2data(int data); +DBData (*i2data) (int data); /** * Manual cast from 'unsigned int' to the struct DBData. @@ -815,7 +816,7 @@ DBData db_i2data(int data); * @return The data as a DBData struct * @public */ -DBData db_ui2data(unsigned int data); +DBData (*ui2data) (unsigned int data); /** * Manual cast from 'void *' to the struct DBData. @@ -823,7 +824,7 @@ DBData db_ui2data(unsigned int data); * @return The data as a DBData struct * @public */ -DBData db_ptr2data(void *data); +DBData (*ptr2data) (void *data); /** * Gets int type data from struct DBData. @@ -832,7 +833,7 @@ DBData db_ptr2data(void *data); * @return Integer value of the data. * @public */ -int db_data2i(DBData *data); +int (*data2i) (DBData *data); /** * Gets unsigned int type data from struct DBData. @@ -841,7 +842,7 @@ int db_data2i(DBData *data); * @return Unsigned int value of the data. * @public */ -unsigned int db_data2ui(DBData *data); +unsigned int (*data2ui) (DBData *data); /** * Gets void* type data from struct DBData. @@ -850,14 +851,14 @@ unsigned int db_data2ui(DBData *data); * @return Void* value of the data. * @public */ -void* db_data2ptr(DBData *data); +void* (*data2ptr) (DBData *data); /** * Initialize the database system. * @public * @see #db_final(void) */ -void db_init(void); +void (*init) (void); /** * Finalize the database system. @@ -865,8 +866,12 @@ void db_init(void); * @public * @see #db_init(void) */ -void db_final(void); +void (*final) (void); +} DB_s; +struct db_interface *DB; + +void db_defaults(void); // Link DB System - From jAthena struct linkdb_node { struct linkdb_node *next; diff --git a/src/common/malloc.c b/src/common/malloc.c index d8799b2a1..77eef2508 100644 --- a/src/common/malloc.c +++ b/src/common/malloc.c @@ -130,21 +130,21 @@ void aFree_(void *p, const char *file, int line, const char *func) /* USE_MEMMGR */ /* - * Memory manager - * able to handle malloc and free efficiently - * Since the complex processing, I might be slightly heavier. - * - * (I'm sorry for the poor description ^ ^;) such as data structures - * Divided into "blocks" of a plurality of memory, "unit" of a plurality of blocks further - * I have to divide. Size of the unit, a plurality of distribution equal to the capacity of one block - * That's what you have. For example, if one unit of 32KB, one block 1 Yu 32Byte - * Knit, or are able to gather 1024, gathered 512 units 64Byte - * I can be or have. (Excluding padding, the unit_head) - * - * Lead-linked list (block_prev, block_next) in each other is the same size block - * Linked list (hash_prev, hash_nect) even among such one in the block with the figure - * I like to have. Thus, reuse of memory no longer needed can be performed efficiently. - */ +* Memory manager +* able to handle malloc and free efficiently +* Since the complex processing, I might be slightly heavier. +* +* (I'm sorry for the poor description ^ ^;) such as data structures +* Divided into "blocks" of a plurality of memory, "unit" of a plurality of blocks further +* I have to divide. Size of the unit, a plurality of distribution equal to the capacity of one block +* That's what you have. For example, if one unit of 32KB, one block 1 Yu 32Byte +* Knit, or are able to gather 1024, gathered 512 units 64Byte +* I can be or have. (Excluding padding, the unit_head) +* +* Lead-linked list (block_prev, block_next) in each other is the same size block +* Linked list (hash_prev, hash_nect) even among such one in the block with the figure +* I like to have. Thus, reuse of memory no longer needed can be performed efficiently. +*/ /* Alignment of the block */ #define BLOCK_ALIGNMENT1 16 @@ -210,7 +210,7 @@ static unsigned short size2hash( size_t size ) return (unsigned short)(size + BLOCK_ALIGNMENT1 - 1) / BLOCK_ALIGNMENT1; } else if( size <= BLOCK_DATA_SIZE ){ return (unsigned short)(size - BLOCK_DATA_SIZE1 + BLOCK_ALIGNMENT2 - 1) / BLOCK_ALIGNMENT2 - + BLOCK_DATA_COUNT1; + + BLOCK_DATA_COUNT1; } else { return 0xffff; // If it exceeds the block length hash I do not } @@ -235,7 +235,7 @@ void* _mmalloc(size_t size, const char *file, int line, const char *func ) ShowError("_mmalloc: %d\n", size); return NULL; } - + if(size == 0) { return NULL; } @@ -332,7 +332,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 = _mmalloc(num * size,file,line,func); + void *p = malloclib->malloc(num * size,file,line,func); memset(p,0,num * size); return p; } @@ -341,7 +341,7 @@ void* _mrealloc(void *memblock, size_t size, const char *file, int line, const c { size_t old_size; if(memblock == NULL) { - return _mmalloc(size,file,line,func); + return malloclib->malloc(size,file,line,func); } old_size = ((struct unit_head *)((char *)memblock - sizeof(struct unit_head) + sizeof(long)))->size; @@ -353,11 +353,11 @@ void* _mrealloc(void *memblock, size_t size, const char *file, int line, const c return memblock; } else { // Size Large - void *p = _mmalloc(size,file,line,func); + void *p = malloclib->malloc(size,file,line,func); if(p != NULL) { memcpy(p,memblock,old_size); } - _mfree(memblock,file,line,func); + malloclib->free(memblock,file,line,func); return p; } } @@ -368,7 +368,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 *)_mmalloc(len + 1,file,line,func); + char *string = (char *)malloclib->malloc(len + 1,file,line,func); memcpy(string,p,len+1); return string; } @@ -544,7 +544,7 @@ static void memmgr_log (char *buf) t = localtime(&raw); fprintf(log_fp, "\nMemory manager: Memory leaks found at %d/%02d/%02d %02dh%02dm%02ds (rev %s).\n", (t->tm_year+1900), (t->tm_mon+1), t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, - git[0] != HERC_UNKNOWN_VER ? git : svn[0] != HERC_UNKNOWN_VER ? svn : "Unknown"); + git[0] != HERC_UNKNOWN_VER ? git : svn[0] != HERC_UNKNOWN_VER ? svn : "Unknown"); } fprintf(log_fp, "%s", buf); return; @@ -621,7 +621,7 @@ static void memmgr_final (void) memmgr_log (buf); #endif /* LOG_MEMMGR */ // get block pointer and free it [celest] - _mfree(ptr, ALC_MARK); + malloclib->free(ptr, ALC_MARK); } } } @@ -663,9 +663,9 @@ static void memmgr_init (void) /*====================================== - * Initialise - *-------------------------------------- - */ +* Initialise +*-------------------------------------- +*/ /// Tests the memory for errors and memory leaks. @@ -719,3 +719,28 @@ void malloc_init (void) memmgr_init (); #endif } + +void malloc_defaults() +{ + 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; + +// Athena's built-in Memory Manager +#ifdef USE_MEMMGR + malloclib->malloc = _mmalloc; + malloclib->calloc = _mcalloc; + malloclib->realloc = _mrealloc; + malloclib->strdup = _mstrdup; + malloclib->free = _mfree; +#else + malloclib->malloc = aMalloc_; + malloclib->calloc = aCalloc_; + malloclib->realloc = aRealloc_; + malloclib->strdup = aStrdup_; + malloclib->free = aFree_; +#endif +} diff --git a/src/common/malloc.h b/src/common/malloc.h index 6b4e8e5c4..2e745481f 100644 --- a/src/common/malloc.h +++ b/src/common/malloc.h @@ -22,9 +22,6 @@ ////////////////////////////////////////////////////////////////////// -// Athena's built-in Memory Manager -#ifdef USE_MEMMGR - // Enable memory manager logging by default #define LOG_MEMMGR @@ -33,46 +30,24 @@ #undef LOG_MEMMGR #endif -# define aMalloc(n) _mmalloc(n,ALC_MARK) -# define aCalloc(m,n) _mcalloc(m,n,ALC_MARK) -# define aRealloc(p,n) _mrealloc(p,n,ALC_MARK) -# define aStrdup(p) _mstrdup(p,ALC_MARK) -# define aFree(p) _mfree(p,ALC_MARK) - - 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* _mrealloc (void *p, size_t size, const char *file, int line, const char *func); - char* _mstrdup (const char *p, const char *file, int line, const char *func); - void _mfree (void *p, const char *file, int line, const char *func); - -#else - -# define aMalloc(n) aMalloc_((n),ALC_MARK) -# define aCalloc(m,n) aCalloc_((m),(n),ALC_MARK) -# define aRealloc(p,n) aRealloc_(p,n,ALC_MARK) -# define aStrdup(p) aStrdup_(p,ALC_MARK) -# define aFree(p) aFree_(p,ALC_MARK) - - void* aMalloc_ (size_t size, const char *file, int line, const char *func); - void* aCalloc_ (size_t num, size_t size, const char *file, int line, const char *func); - void* aRealloc_ (void *p, size_t size, const char *file, int line, const char *func); - char* aStrdup_ (const char *p, const char *file, int line, const char *func); - void aFree_ (void *p, const char *file, int line, const char *func); - -#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->strdup (p,ALC_MARK) +# define aFree(p) malloclib->free (p,ALC_MARK) /////////////// Buffer Creation ///////////////// // Full credit for this goes to Shinomori [Ajarn] #ifdef __GNUC__ // GCC has variable length arrays - #define CREATE_BUFFER(name, type, size) type name[size] - #define DELETE_BUFFER(name) +#define CREATE_BUFFER(name, type, size) type name[size] +#define DELETE_BUFFER(name) #else // others don't, so we emulate them - #define CREATE_BUFFER(name, type, size) type *name = (type *) aCalloc (size, sizeof(type)) - #define DELETE_BUFFER(name) aFree(name) +#define CREATE_BUFFER(name, type, size) type *name = (type *) aCalloc (size, sizeof(type)) +#define DELETE_BUFFER(name) aFree(name) #endif @@ -83,10 +58,27 @@ //////////////////////////////////////////////// -void malloc_memory_check(void); -bool malloc_verify_ptr(void* ptr); -size_t malloc_usage (void); -void malloc_init (void); -void malloc_final (void); - +//void malloc_memory_check(void); +//bool malloc_verify_ptr(void* ptr); +//size_t malloc_usage (void); +//void malloc_init (void); +//void malloc_final (void); + +void malloc_defaults(void); + +struct malloc_interface { + void* (*malloc )(size_t size, const char *file, int line, const char *func); + void* (*calloc )(size_t num, size_t size, const char *file, int line, const char *func); + void* (*realloc )(void *p, size_t size, const char *file, int line, const char *func); + char* (*strdup )(const char *p, const char *file, int line, const char *func); + void (*free ) (void *p, const char *file, int line, const char *func); + + void (*memory_check)(void); + bool (*verify_ptr)(void* ptr); + size_t (*usage) (void); + void (*init) (void); + void (*final) (void); +} malloclib_s; + +struct malloc_interface *malloclib; #endif /* _MALLOC_H_ */ diff --git a/src/login/login.c b/src/login/login.c index 09dd938db..8dd5ce20a 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -109,7 +109,7 @@ static DBData create_online_user(DBKey key, va_list args) p->account_id = key.i; p->char_server = -1; p->waiting_disconnect = INVALID_TIMER; - return db_ptr2data(p); + return DB->ptr2data(p); } struct online_login_data* add_online_user(int char_server, int account_id) @@ -154,7 +154,7 @@ static int waiting_disconnect_timer(int tid, unsigned int tick, int id, intptr_t */ static int online_db_setoffline(DBKey key, DBData *data, va_list ap) { - struct online_login_data* p = db_data2ptr(data); + struct online_login_data* p = DB->data2ptr(data); int server = va_arg(ap, int); if( server == -1 ) { @@ -175,7 +175,7 @@ static int online_db_setoffline(DBKey key, DBData *data, va_list ap) */ static int online_data_cleanup_sub(DBKey key, DBData *data, va_list ap) { - struct online_login_data *character= db_data2ptr(data); + struct online_login_data *character= DB->data2ptr(data); if (character->char_server == -2) //Unknown server.. set them offline remove_online_user(character->account_id); return 0; diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 8a6399568..d923027dd 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -5350,12 +5350,12 @@ ACMD(skillid) { iter = db_iterator(skilldb_name2id); for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) ) { - idx = skill->get_index(db_data2i(data)); + idx = skill->get_index(DB->data2i(data)); if (strnicmp(key.str, message, skillen) == 0 || strnicmp(skill_db[idx].desc, message, skillen) == 0) { - sprintf(atcmd_output, msg_txt(1164), db_data2i(data), skill_db[idx].desc, key.str); // skill %d: %s (%s) + sprintf(atcmd_output, msg_txt(1164), DB->data2i(data), skill_db[idx].desc, key.str); // skill %d: %s (%s) clif->message(fd, atcmd_output); } else if ( found < MAX_SKILLID_PARTIAL_RESULTS && ( stristr(key.str,message) || stristr(skill_db[idx].desc,message) ) ) { - snprintf(partials[found++], MAX_SKILLID_PARTIAL_RESULTS_LEN, msg_txt(1164), db_data2i(data), skill_db[idx].desc, key.str); + snprintf(partials[found++], MAX_SKILLID_PARTIAL_RESULTS_LEN, msg_txt(1164), DB->data2i(data), skill_db[idx].desc, key.str); } } @@ -9206,7 +9206,7 @@ ACMD(channel) { iter = db_iterator(channel->banned); for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) ) { - struct hChSysBanEntry * entry = db_data2ptr(data); + struct hChSysBanEntry * entry = DB->data2ptr(data); if( !isA ) sprintf(atcmd_output, msg_txt(1444), entry->name);// - %s %s diff --git a/src/map/battleground.c b/src/map/battleground.c index fa4db436a..618679406 100644 --- a/src/map/battleground.c +++ b/src/map/battleground.c @@ -222,7 +222,7 @@ int bg_send_message(struct map_session_data *sd, const char *mes, int len) */ int bg_send_xy_timer_sub(DBKey key, DBData *data, va_list ap) { - struct battleground_data *bg = db_data2ptr(data); + struct battleground_data *bg = DB->data2ptr(data); struct map_session_data *sd; int i; nullpo_ret(bg); diff --git a/src/map/chrif.c b/src/map/chrif.c index 05f56029b..efe976942 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -479,7 +479,7 @@ int chrif_connectack(int fd) { * @see DBApply */ static int chrif_reconnect(DBKey key, DBData *data, va_list ap) { - struct auth_node *node = db_data2ptr(data); + struct auth_node *node = DB->data2ptr(data); switch (node->state) { case ST_LOGIN: @@ -687,7 +687,7 @@ void chrif_authfail(int fd) {/* HELLO WORLD. ip in RFIFOL 15 is not being used ( * @see DBApply */ int auth_db_cleanup_sub(DBKey key, DBData *data, va_list ap) { - struct auth_node *node = db_data2ptr(data); + struct auth_node *node = DB->data2ptr(data); const char* states[] = { "Login", "Logout", "Map change" }; if(DIFF_TICK(gettick(),node->node_created)>60000) { @@ -1596,7 +1596,7 @@ void chrif_send_report(char* buf, int len) { * @see DBApply */ int auth_db_final(DBKey key, DBData *data, va_list ap) { - struct auth_node *node = db_data2ptr(data); + struct auth_node *node = DB->data2ptr(data); if (node->char_dat) aFree(node->char_dat); diff --git a/src/map/guild.c b/src/map/guild.c index 9e7dc9b0f..b83f05f00 100644 --- a/src/map/guild.c +++ b/src/map/guild.c @@ -296,7 +296,7 @@ int guild_payexp_timer_sub(DBKey key, DBData *data, va_list ap) { struct guild_expcache *c; struct guild *g; - c = db_data2ptr(data); + c = DB->data2ptr(data); if ( (g = guild->search(c->guild_id)) == NULL || @@ -331,7 +331,7 @@ int guild_payexp_timer(int tid, unsigned int tick, int id, intptr_t data) */ int guild_send_xy_timer_sub(DBKey key, DBData *data, va_list ap) { - struct guild *g = db_data2ptr(data); + struct guild *g = DB->data2ptr(data); int i; nullpo_ret(g); @@ -439,8 +439,8 @@ int guild_npc_request_info(int guild_id,const char *event) ev=(struct eventlist *)aCalloc(sizeof(struct eventlist),1); memcpy(ev->name,event,strlen(event)); //The one in the db (if present) becomes the next event from this. - if (guild_infoevent_db->put(guild_infoevent_db, db_i2key(guild_id), db_ptr2data(ev), &prev)) - ev->next = db_data2ptr(&prev); + if (guild_infoevent_db->put(guild_infoevent_db, DB->i2key(guild_id), DB->ptr2data(ev), &prev)) + ev->next = DB->data2ptr(&prev); } return guild->request_info(guild_id); @@ -615,8 +615,8 @@ int guild_recv_info(struct guild *sg) { } //Occurrence of an event - if (guild_infoevent_db->remove(guild_infoevent_db, db_i2key(sg->guild_id), &data)) { - struct eventlist *ev = db_data2ptr(&data), *ev2; + if (guild_infoevent_db->remove(guild_infoevent_db, DB->i2key(sg->guild_id), &data)) { + struct eventlist *ev = DB->data2ptr(&data), *ev2; while(ev) { npc_event_do(ev->name); ev2=ev->next; @@ -1243,7 +1243,7 @@ static DBData create_expcache(DBKey key, va_list args) c->account_id = sd->status.account_id; c->char_id = sd->status.char_id; c->exp = 0; - return db_ptr2data(c); + return DB->ptr2data(c); } /*==================================================== @@ -1269,7 +1269,7 @@ unsigned int guild_payexp(struct map_session_data *sd,unsigned int exp) { exp = exp * per / 100; //Otherwise tax everything. - c = db_data2ptr(guild_expcache_db->ensure(guild_expcache_db, db_i2key(sd->status.char_id), create_expcache, sd)); + c = DB->data2ptr(guild_expcache_db->ensure(guild_expcache_db, DB->i2key(sd->status.char_id), create_expcache, sd)); if (c->exp > UINT64_MAX - exp) c->exp = UINT64_MAX; @@ -1292,7 +1292,7 @@ int guild_getexp(struct map_session_data *sd,int exp) if (sd->status.guild_id == 0 || sd->guild == NULL) return 0; - c = db_data2ptr(guild_expcache_db->ensure(guild_expcache_db, db_i2key(sd->status.char_id), create_expcache, sd)); + c = DB->data2ptr(guild_expcache_db->ensure(guild_expcache_db, DB->i2key(sd->status.char_id), create_expcache, sd)); if (c->exp > UINT64_MAX - exp) c->exp = UINT64_MAX; else @@ -1692,7 +1692,7 @@ int guild_allianceack(int guild_id1,int guild_id2,int account_id1,int account_id */ int guild_broken_sub(DBKey key, DBData *data, va_list ap) { - struct guild *g = db_data2ptr(data); + struct guild *g = DB->data2ptr(data); int guild_id=va_arg(ap,int); int i,j; struct map_session_data *sd=NULL; @@ -1717,7 +1717,7 @@ int guild_broken_sub(DBKey key, DBData *data, va_list ap) */ int castle_guild_broken_sub(DBKey key, DBData *data, va_list ap) { - struct guild_castle *gc = db_data2ptr(data); + struct guild_castle *gc = DB->data2ptr(data); int guild_id = va_arg(ap, int); nullpo_ret(gc); @@ -2145,7 +2145,7 @@ void guild_flag_remove(struct npc_data *nd) { */ static int eventlist_db_final(DBKey key, DBData *data, va_list ap) { struct eventlist *next = NULL; - struct eventlist *current = db_data2ptr(data); + struct eventlist *current = DB->data2ptr(data); while (current != NULL) { next = current->next; aFree(current); @@ -2158,7 +2158,7 @@ static int eventlist_db_final(DBKey key, DBData *data, va_list ap) { * @see DBApply */ static int guild_expcache_db_final(DBKey key, DBData *data, va_list ap) { - ers_free(expcache_ers, db_data2ptr(data)); + ers_free(expcache_ers, DB->data2ptr(data)); return 0; } @@ -2166,7 +2166,7 @@ static int guild_expcache_db_final(DBKey key, DBData *data, va_list ap) { * @see DBApply */ static int guild_castle_db_final(DBKey key, DBData *data, va_list ap) { - struct guild_castle* gc = db_data2ptr(data); + struct guild_castle* gc = DB->data2ptr(data); if( gc->temp_guardians ) aFree(gc->temp_guardians); aFree(gc); diff --git a/src/map/itemdb.c b/src/map/itemdb.c index 590a0cf57..2a5fa48de 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -30,7 +30,7 @@ struct item_data dummy_item; //This is the default dummy item used for non-exist */ static int itemdb_searchname_sub(DBKey key, DBData *data, va_list ap) { - struct item_data *item = db_data2ptr(data), **dst, **dst2; + struct item_data *item = DB->data2ptr(data), **dst, **dst2; char *str; str=va_arg(ap,char *); dst=va_arg(ap,struct item_data **); @@ -83,7 +83,7 @@ struct item_data* itemdb_searchname(const char *str) */ static int itemdb_searchname_array_sub(DBKey key, DBData data, va_list ap) { - struct item_data *item = db_data2ptr(&data); + struct item_data *item = DB->data2ptr(&data); char *str; str=va_arg(ap,char *); if (item == &dummy_item) @@ -127,7 +127,7 @@ int itemdb_searchname_array(struct item_data** data, int size, const char *str) size -= count; db_count = itemdb_other->getall(itemdb_other, (DBData**)&db_data, size, itemdb_searchname_array_sub, str); for (i = 0; i < db_count; i++) - data[count++] = db_data2ptr(db_data[i]); + data[count++] = DB->data2ptr(db_data[i]); count += db_count; } return count; @@ -1376,7 +1376,7 @@ static void destroy_item_data(struct item_data* self, int free_self) */ static int itemdb_final_sub(DBKey key, DBData *data, va_list ap) { - struct item_data *id = db_data2ptr(data); + struct item_data *id = DB->data2ptr(data); if( id != &dummy_item ) destroy_item_data(id, 1); diff --git a/src/map/map.c b/src/map/map.c index 49aef6c4c..6f61375fe 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -1479,7 +1479,7 @@ static DBData create_charid2nick(DBKey key, va_list args) { struct charid2nick *p; CREATE(p, struct charid2nick, 1); - return db_ptr2data(p); + return DB->ptr2data(p); } /// Adds(or replaces) the nick of charid to nick_db and fullfils pending requests. @@ -1515,7 +1515,7 @@ void map_delnickdb(int charid, const char* name) struct map_session_data* sd; DBData data; - if (!nick_db->remove(nick_db, db_i2key(charid), &data) || (p = db_data2ptr(&data)) == NULL) + if (!nick_db->remove(nick_db, DB->i2key(charid), &data) || (p = DB->data2ptr(&data)) == NULL) return; while( p->requests ) { @@ -2703,7 +2703,7 @@ static DBData create_map_data_other_server(DBKey key, va_list args) mdos=(struct map_data_other_server *)aCalloc(1,sizeof(struct map_data_other_server)); mdos->index = mapindex; memcpy(mdos->name, mapindex_id2name(mapindex), MAP_NAME_LENGTH); - return db_ptr2data(mdos); + return DB->ptr2data(mdos); } /*========================================== @@ -2733,7 +2733,7 @@ int map_setipport(unsigned short mapindex, uint32 ip, uint16 port) */ int map_eraseallipport_sub(DBKey key, DBData *data, va_list va) { - struct map_data_other_server *mdos = db_data2ptr(data); + struct map_data_other_server *mdos = DB->data2ptr(data); if(mdos->cell == NULL) { db_remove(map_db,key); aFree(mdos); @@ -4854,7 +4854,7 @@ void read_map_zone_db(void) { */ int map_db_final(DBKey key, DBData *data, va_list ap) { - struct map_data_other_server *mdos = db_data2ptr(data); + struct map_data_other_server *mdos = DB->data2ptr(data); if(mdos && mdos->cell == NULL) aFree(mdos); return 0; @@ -4865,7 +4865,7 @@ int map_db_final(DBKey key, DBData *data, va_list ap) */ int nick_db_final(DBKey key, DBData *data, va_list args) { - struct charid2nick* p = db_data2ptr(data); + struct charid2nick* p = DB->data2ptr(data); struct charid_request* req; if( p == NULL ) @@ -4913,7 +4913,7 @@ int cleanup_sub(struct block_list *bl, va_list ap) */ static int cleanup_db_sub(DBKey key, DBData *data, va_list va) { - return cleanup_sub(db_data2ptr(data), va); + return cleanup_sub(DB->data2ptr(data), va); } /*========================================== diff --git a/src/map/npc.c b/src/map/npc.c index 77ee8d486..090c03e58 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -353,7 +353,7 @@ int npc_event_doall_sub(DBKey key, DBData *data, va_list ap) const char* name; int rid; - nullpo_ret(ev = db_data2ptr(data)); + nullpo_ret(ev = DB->data2ptr(data)); nullpo_ret(c = va_arg(ap, int *)); nullpo_ret(name = va_arg(ap, const char *)); rid = va_arg(ap, int); @@ -381,7 +381,7 @@ static int npc_event_do_sub(DBKey key, DBData *data, va_list ap) int* c; const char* name; - nullpo_ret(ev = db_data2ptr(data)); + nullpo_ret(ev = DB->data2ptr(data)); nullpo_ret(c = va_arg(ap, int *)); nullpo_ret(name = va_arg(ap, const char *)); @@ -1785,7 +1785,7 @@ int npc_remove_map(struct npc_data* nd) */ static int npc_unload_ev(DBKey key, DBData *data, va_list ap) { - struct event_data* ev = db_data2ptr(data); + struct event_data* ev = DB->data2ptr(data); char* npcname = va_arg(ap, char *); if(strcmp(ev->nd->exname,npcname)==0){ @@ -2302,7 +2302,7 @@ static const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const int npc_convertlabel_db(DBKey key, DBData *data, va_list ap) { const char* lname = (const char*)key.str; - int lpos = db_data2i(data); + int lpos = DB->data2i(data); struct npc_label_list** label_list; int* label_list_num; const char* filepath; @@ -2972,9 +2972,9 @@ static const char* npc_parse_function(char* w1, char* w2, char* w3, char* w4, co return end; func_db = script_get_userfunc_db(); - if (func_db->put(func_db, db_str2key(w3), db_ptr2data(script), &old_data)) + if (func_db->put(func_db, DB->str2key(w3), DB->ptr2data(script), &old_data)) { - struct script_code *oldscript = (struct script_code*)db_data2ptr(&old_data); + struct script_code *oldscript = (struct script_code*)DB->data2ptr(&old_data); ShowInfo("npc_parse_function: Overwriting user function [%s] (%s:%d)\n", w3, filepath, strline(buffer,start-buffer)); script_free_vars(oldscript->script_vars); aFree(oldscript->script_buf); @@ -3776,7 +3776,7 @@ void npc_read_event_script(void) for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) ) { const char* p = key.str; - struct event_data* ed = db_data2ptr(data); + struct event_data* ed = DB->data2ptr(data); unsigned char count = script_event[i].event_count; if( count >= ARRAYLENGTH(script_event[i].event) ) diff --git a/src/map/script.c b/src/map/script.c index 76092f4ce..41f8e7472 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -3658,7 +3658,7 @@ int script_config_read(char *cfgName) */ static int db_script_free_code_sub(DBKey key, DBData *data, va_list ap) { - struct script_code *code = db_data2ptr(data); + struct script_code *code = DB->data2ptr(data); if (code) script_free_code(code); return 0; diff --git a/src/map/skill.c b/src/map/skill.c index bbc88d9d2..06bfca5f8 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -15363,7 +15363,7 @@ int skill_unit_timer_sub_onplace (struct block_list* bl, va_list ap) { * @see DBApply */ int skill_unit_timer_sub(DBKey key, DBData *data, va_list ap) { - struct skill_unit* unit = db_data2ptr(data); + struct skill_unit* unit = DB->data2ptr(data); struct skill_unit_group* group = unit->group; unsigned int tick = va_arg(ap,unsigned int); bool dissonance; diff --git a/src/map/storage.c b/src/map/storage.c index fda80735a..01da53907 100644 --- a/src/map/storage.c +++ b/src/map/storage.c @@ -73,7 +73,7 @@ void do_final_storage(void) // by [MC Cameri] */ static int storage_reconnect_sub(DBKey key, DBData *data, va_list ap) { - struct guild_storage *stor = db_data2ptr(data); + struct guild_storage *stor = DB->data2ptr(data); if (stor->dirty && stor->storage_status == 0) //Save closed storages. storage_guild_storagesave(0, stor->guild_id,0); @@ -352,7 +352,7 @@ static DBData create_guildstorage(DBKey key, va_list args) struct guild_storage *gs = NULL; gs = (struct guild_storage *) aCalloc(sizeof(struct guild_storage), 1); gs->guild_id=key.i; - return db_ptr2data(gs); + return DB->ptr2data(gs); } struct guild_storage *guild2storage(int guild_id) -- cgit v1.2.3-70-g09d2