diff options
Diffstat (limited to 'src/common')
51 files changed, 2423 insertions, 1569 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c index 6e73d1b2a..23265fa24 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -3,28 +3,30 @@ #define HERCULES_CORE -#include "../config/core.h" // CONSOLE_INPUT +#include "config/core.h" // CONSOLE_INPUT #include "HPM.h" +#include "common/cbasetypes.h" +#include "common/conf.h" +#include "common/console.h" +#include "common/core.h" +#include "common/db.h" +#include "common/malloc.h" +#include "common/mapindex.h" +#include "common/mmo.h" +#include "common/showmsg.h" +#include "common/socket.h" +#include "common/sql.h" +#include "common/strlib.h" +#include "common/sysinfo.h" +#include "common/timer.h" +#include "common/utils.h" +#include "common/nullpo.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "../common/cbasetypes.h" -#include "../common/conf.h" -#include "../common/console.h" -#include "../common/core.h" -#include "../common/malloc.h" -#include "../common/mmo.h" -#include "../common/showmsg.h" -#include "../common/socket.h" -#include "../common/sql.h" -#include "../common/strlib.h" -#include "../common/sysinfo.h" -#include "../common/timer.h" -#include "../common/utils.h" -#include "../common/nullpo.h" - #ifndef WIN32 # include <unistd.h> #endif @@ -32,6 +34,7 @@ struct malloc_interface iMalloc_HPM; struct malloc_interface *HPMiMalloc; struct HPM_interface HPM_s; +struct HPM_interface *HPM; /** * (char*) data name -> (unsigned int) HPMDataCheck[] index @@ -93,47 +96,260 @@ struct hplugin *hplugin_create(void) { HPM->plugins[HPM->plugin_count - 1]->filename = NULL; return HPM->plugins[HPM->plugin_count - 1]; } -#define HPM_POP(x) { #x , x } -bool hplugin_populate(struct hplugin *plugin, const char *filename) { - 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), - }; - int i, length = ARRAYLENGTH(ToLink); - for(i = 0; i < length; i++) { - void **Link; - 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); +bool hplugins_addpacket(unsigned short cmd, unsigned short length, void (*receive) (int fd), unsigned int point,unsigned int pluginID) { + struct HPluginPacket *packet; + unsigned int i; + + if( point >= hpPHP_MAX ) { + ShowError("HPM->addPacket:%s: unknown point '%u' specified for packet 0x%04x (len %d)\n",HPM->pid2name(pluginID),point,cmd,length); + return false; + } + + for(i = 0; i < HPM->packetsc[point]; i++) { + if( HPM->packets[point][i].cmd == cmd ) { + ShowError("HPM->addPacket:%s: can't add packet 0x%04x, already in use by '%s'!",HPM->pid2name(pluginID),cmd,HPM->pid2name(HPM->packets[point][i].pluginID)); + return false; + } + } + + RECREATE(HPM->packets[point], struct HPluginPacket, ++HPM->packetsc[point]); + packet = &HPM->packets[point][HPM->packetsc[point] - 1]; + + packet->pluginID = pluginID; + packet->cmd = cmd; + packet->len = length; + packet->receive = receive; + + return true; +} + +void hplugins_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr) +{ + /* record address */ + switch (type) { + /* core-handled */ + case HPDT_SESSION: + ret->HPDataSRCPtr = (void**)(&((struct socket_data *)ptr)->hdata); + ret->hdatac = &((struct socket_data *)ptr)->hdatac; + break; + /* goes to sub */ + default: + if (HPM->grabHPDataSub) { + if (HPM->grabHPDataSub(ret,type,ptr)) + return; + ShowError("HPM:HPM:grabHPData failed, unknown type %d!\n",type); + } else { + ShowError("HPM:grabHPData failed, type %d needs sub-handler!\n",type); + } + ret->HPDataSRCPtr = NULL; + ret->hdatac = NULL; + return; + } +} + +void hplugins_addToHPData(enum HPluginDataTypes type, unsigned int pluginID, void *ptr, void *data, unsigned int index, bool autofree) +{ + struct HPluginData *HPData, **HPDataSRC; + struct HPDataOperationStorage action; + unsigned int i, max; + + HPM->grabHPData(&action,type,ptr); + + if (action.hdatac == NULL) { /* woo it failed! */ + ShowError("HPM:addToHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index); + return; + } + + /* flag */ + HPDataSRC = *(action.HPDataSRCPtr); + max = *(action.hdatac); + + /* duplicate check */ + for (i = 0; i < max; i++) { + if (HPDataSRC[i]->pluginID == pluginID && HPDataSRC[i]->type == index) { + ShowError("HPM:addToHPData:%s: error! attempting to insert duplicate struct of id %u and index %u\n",HPM->pid2name(pluginID),pluginID,index); + return; + } + } + + /* HPluginData is always same size, probably better to use the ERS (with reasonable chunk size e.g. 10/25/50) */ + CREATE(HPData, struct HPluginData, 1); + + /* input */ + HPData->pluginID = pluginID; + HPData->type = index; + HPData->flag.free = autofree ? 1 : 0; + HPData->data = data; + + /* resize */ + *(action.hdatac) += 1; + RECREATE(*(action.HPDataSRCPtr),struct HPluginData *,*(action.hdatac)); + + /* RECREATE modified the address */ + HPDataSRC = *(action.HPDataSRCPtr); + HPDataSRC[*(action.hdatac) - 1] = HPData; +} + +void *hplugins_getFromHPData(enum HPluginDataTypes type, unsigned int pluginID, void *ptr, unsigned int index) +{ + struct HPDataOperationStorage action; + struct HPluginData **HPDataSRC; + unsigned int i, max; + + HPM->grabHPData(&action,type,ptr); + + if (action.hdatac == NULL) { /* woo it failed! */ + ShowError("HPM:getFromHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index); + return NULL; + } + + /* flag */ + HPDataSRC = *(action.HPDataSRCPtr); + max = *(action.hdatac); + + for (i = 0; i < max; i++) { + if (HPDataSRC[i]->pluginID == pluginID && HPDataSRC[i]->type == index) + return HPDataSRC[i]->data; + } + + return NULL; +} + +void hplugins_removeFromHPData(enum HPluginDataTypes type, unsigned int pluginID, void *ptr, unsigned int index) +{ + struct HPDataOperationStorage action; + struct HPluginData **HPDataSRC; + unsigned int i, max; + + HPM->grabHPData(&action,type,ptr); + + if (action.hdatac == NULL) { /* woo it failed! */ + ShowError("HPM:removeFromHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index); + return; + } + + /* flag */ + HPDataSRC = *(action.HPDataSRCPtr); + max = *(action.hdatac); + + for (i = 0; i < max; i++) { + if (HPDataSRC[i]->pluginID == pluginID && HPDataSRC[i]->type == index) + break; + } + + if (i != max) { + unsigned int cursor; + + aFree(HPDataSRC[i]->data);/* when its removed we delete it regardless of autofree */ + aFree(HPDataSRC[i]); + HPDataSRC[i] = NULL; + + for (i = 0, cursor = 0; i < max; i++) { + if (HPDataSRC[i] == NULL) + continue; + if (i != cursor) + HPDataSRC[cursor] = HPDataSRC[i]; + cursor++; + } + *(action.hdatac) = cursor; + } +} + +/* TODO: add ability for tracking using pID for the upcoming runtime load/unload support. */ +bool HPM_AddHook(enum HPluginHookType type, const char *target, void *hook, unsigned int pID) +{ + if (!HPM->hooking) { + ShowError("HPM:AddHook Fail! '%s' tried to hook to '%s' but HPMHooking is disabled!\n",HPM->pid2name(pID),target); + return false; + } + /* search if target is a known hook point within 'common' */ + /* if not check if a sub-hooking list is available (from the server) and run it by */ + if (HPM->addhook_sub && HPM->addhook_sub(type,target,hook,pID)) + return true; + + ShowError("HPM:AddHook: unknown Hooking Point '%s'!\n",target); + + return false; +} + +void HPM_HookStop(const char *func, unsigned int pID) +{ + /* track? */ + HPM->force_return = true; +} + +bool HPM_HookStopped (void) +{ + return HPM->force_return; +} + +/** + * Adds a plugin-defined command-line argument. + * + * @param pluginID the current plugin's ID. + * @param name the command line argument's name, including the leading '--'. + * @param has_param whether the command line argument expects to be followed by a value. + * @param func the triggered function. + * @param help the help string to be displayed by '--help', if any. + * @return the success status. + */ +bool hpm_add_arg(unsigned int pluginID, char *name, bool has_param, CmdlineExecFunc func, const char *help) +{ + int i; + + if (!name || strlen(name) < 3 || name[0] != '-' || name[1] != '-') { + ShowError("HPM:add_arg:%s invalid argument name: arguments must begin with '--' (from %s)\n", name, HPM->pid2name(pluginID)); + return false; + } + + ARR_FIND(0, cmdline->args_data_count, i, strcmp(cmdline->args_data[i].name, name) == 0); + + if (i < cmdline->args_data_count) { + ShowError("HPM:add_arg:%s duplicate! (from %s)\n",name,HPM->pid2name(pluginID)); + return false; + } + + return cmdline->arg_add(pluginID, name, '\0', func, help, has_param ? CMDLINE_OPT_PARAM : CMDLINE_OPT_NORMAL); +} + +bool hplugins_addconf(unsigned int pluginID, enum HPluginConfType type, char *name, void (*func) (const char *val)) +{ + struct HPConfListenStorage *conf; + unsigned int i; + + if (type >= HPCT_MAX) { + ShowError("HPM->addConf:%s: unknown point '%u' specified for config '%s'\n",HPM->pid2name(pluginID),type,name); + return false; + } + + for (i = 0; i < HPM->confsc[type]; i++) { + if (!strcmpi(name,HPM->confs[type][i].key)) { + ShowError("HPM->addConf:%s: duplicate '%s', already in use by '%s'!",HPM->pid2name(pluginID),name,HPM->pid2name(HPM->confs[type][i].pluginID)); return false; } - *Link = ToLink[i].Ref; } + RECREATE(HPM->confs[type], struct HPConfListenStorage, ++HPM->confsc[type]); + conf = &HPM->confs[type][HPM->confsc[type] - 1]; + + conf->pluginID = pluginID; + safestrncpy(conf->key, name, HPM_ADDCONF_LENGTH); + conf->func = func; + return true; } -#undef HPM_POP + struct hplugin *hplugin_load(const char* filename) { struct hplugin *plugin; struct hplugin_info *info; struct HPMi_interface **HPMi; bool anyEvent = false; void **import_symbol_ref; - Sql **sql_handle; int *HPMDataCheckVer; unsigned int *HPMDataCheckLen; struct s_HPMDataCheck *HPMDataCheck; + const char *(*HPMLoadEvent)(int server_type); if( HPM->exists(filename) ) { ShowWarning("HPM:plugin_load: attempting to load duplicate '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename); @@ -144,15 +360,13 @@ struct hplugin *hplugin_load(const char* filename) { if (!(plugin->dll = plugin_open(filename))) { char buf[1024]; - ShowWarning("HPM:plugin_load: failed to load '"CL_WHITE"%s"CL_RESET"' (error: %s), skipping...\n", filename, plugin_geterror(buf)); - HPM->unload(plugin); - return NULL; + ShowFatalError("HPM:plugin_load: failed to load '"CL_WHITE"%s"CL_RESET"' (error: %s)!\n", filename, plugin_geterror(buf)); + exit(EXIT_FAILURE); } 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 NULL; + ShowFatalError("HPM:plugin_load: failed to retrieve 'plugin_info' for '"CL_WHITE"%s"CL_RESET"'!\n", filename); + exit(EXIT_FAILURE); } if( !(info->type & SERVER_TYPE) ) { @@ -161,40 +375,28 @@ struct hplugin *hplugin_load(const char* filename) { } 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 NULL; + ShowFatalError("HPM:plugin_load: '"CL_WHITE"%s"CL_RESET"' incompatible version '%s' -> '%s'!\n", filename, info->req_version, HPM_VERSION); + exit(EXIT_FAILURE); } plugin->info = info; plugin->filename = aStrdup(filename); 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 NULL; + ShowFatalError("HPM:plugin_load: failed to retrieve 'import_symbol' for '"CL_WHITE"%s"CL_RESET"'!\n", filename); + exit(EXIT_FAILURE); } *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 NULL; - } - - *sql_handle = HPM->import_symbol("sql_handle",plugin->idx); - 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 NULL; + ShowFatalError("HPM:plugin_load: failed to retrieve 'HPMi' for '"CL_WHITE"%s"CL_RESET"'!\n", filename); + exit(EXIT_FAILURE); } 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 NULL; + ShowFatalError("HPM:plugin_load: failed to retrieve 'HPMi_s' for '"CL_WHITE"%s"CL_RESET"'!\n", filename); + exit(EXIT_FAILURE); } plugin->hpi = *HPMi; @@ -214,84 +416,93 @@ struct hplugin *hplugin_load(const char* filename) { anyEvent = true; if( !anyEvent ) { - ShowWarning("HPM:plugin_load: no events found for '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename); - HPM->unload(plugin); - return NULL; + ShowWarning("HPM:plugin_load: no events found for '"CL_WHITE"%s"CL_RESET"'!\n", filename); + exit(EXIT_FAILURE); } - if( !HPM->populate(plugin,filename) ) - return NULL; + if (!(HPMLoadEvent = plugin_import(plugin->dll, "HPM_shared_symbols", const char *(*)(int)))) { + ShowFatalError("HPM:plugin_load: failed to retrieve 'HPM_shared_symbols' for '"CL_WHITE"%s"CL_RESET"', most likely not including HPMDataCheck.h!\n", filename); + exit(EXIT_FAILURE); + } + { + const char *failure = HPMLoadEvent(SERVER_TYPE); + if (failure) { + ShowFatalError("HPM:plugin_load: failed to import symbol '%s' into '"CL_WHITE"%s"CL_RESET"'.\n", failure, filename); + exit(EXIT_FAILURE); + } + } if( !( HPMDataCheckLen = plugin_import(plugin->dll, "HPMDataCheckLen", unsigned int *) ) ) { - ShowWarning("HPM:plugin_load: failed to retrieve 'HPMDataCheckLen' for '"CL_WHITE"%s"CL_RESET"', most likely not including HPMDataCheck.h, skipping...\n", filename); - HPM->unload(plugin); - return NULL; + ShowFatalError("HPM:plugin_load: failed to retrieve 'HPMDataCheckLen' for '"CL_WHITE"%s"CL_RESET"', most likely not including HPMDataCheck.h!\n", filename); + exit(EXIT_FAILURE); } if( !( HPMDataCheckVer = plugin_import(plugin->dll, "HPMDataCheckVer", int *) ) ) { - ShowWarning("HPM:plugin_load: failed to retrieve 'HPMDataCheckVer' for '"CL_WHITE"%s"CL_RESET"', most likely an outdated plugin, skipping...\n", filename); - HPM->unload(plugin); - return NULL; + ShowFatalError("HPM:plugin_load: failed to retrieve 'HPMDataCheckVer' for '"CL_WHITE"%s"CL_RESET"', most likely an outdated plugin!\n", filename); + exit(EXIT_FAILURE); } if( !( HPMDataCheck = plugin_import(plugin->dll, "HPMDataCheck", struct s_HPMDataCheck *) ) ) { - ShowWarning("HPM:plugin_load: failed to retrieve 'HPMDataCheck' for '"CL_WHITE"%s"CL_RESET"', most likely not including HPMDataCheck.h, skipping...\n", filename); - HPM->unload(plugin); - return NULL; + ShowFatalError("HPM:plugin_load: failed to retrieve 'HPMDataCheck' for '"CL_WHITE"%s"CL_RESET"', most likely not including HPMDataCheck.h!\n", filename); + exit(EXIT_FAILURE); } // TODO: Remove the HPM->DataCheck != NULL check once login and char support is complete if (HPM->DataCheck != NULL && !HPM->DataCheck(HPMDataCheck,*HPMDataCheckLen,*HPMDataCheckVer,plugin->info->name)) { - ShowWarning("HPM:plugin_load: '"CL_WHITE"%s"CL_RESET"' failed DataCheck, out of sync from the core (recompile plugin), skipping...\n", filename); - HPM->unload(plugin); - return NULL; + ShowFatalError("HPM:plugin_load: '"CL_WHITE"%s"CL_RESET"' failed DataCheck, out of sync from the core (recompile plugin)!\n", filename); + exit(EXIT_FAILURE); } /* id */ plugin->hpi->pid = plugin->idx; /* core */ - plugin->hpi->addCPCommand = HPM->import_symbol("addCPCommand",plugin->idx); - plugin->hpi->addPacket = HPM->import_symbol("addPacket",plugin->idx); - plugin->hpi->addToHPData = HPM->import_symbol("addToHPData",plugin->idx); - plugin->hpi->getFromHPData = HPM->import_symbol("getFromHPData",plugin->idx); - plugin->hpi->removeFromHPData = HPM->import_symbol("removeFromHPData",plugin->idx); - plugin->hpi->AddHook = HPM->import_symbol("AddHook",plugin->idx); - plugin->hpi->HookStop = HPM->import_symbol("HookStop",plugin->idx); - plugin->hpi->HookStopped = HPM->import_symbol("HookStopped",plugin->idx); - plugin->hpi->addArg = HPM->import_symbol("addArg",plugin->idx); - plugin->hpi->addConf = HPM->import_symbol("addConf",plugin->idx); +#ifdef CONSOLE_INPUT + plugin->hpi->addCPCommand = console->input->addCommand; +#endif // CONSOLE_INPUT + plugin->hpi->addPacket = hplugins_addpacket; + plugin->hpi->addToHPData = hplugins_addToHPData; + plugin->hpi->getFromHPData = hplugins_getFromHPData; + plugin->hpi->removeFromHPData = hplugins_removeFromHPData; + plugin->hpi->AddHook = HPM_AddHook; + plugin->hpi->HookStop = HPM_HookStop; + plugin->hpi->HookStopped = HPM_HookStopped; + plugin->hpi->addArg = hpm_add_arg; + plugin->hpi->addConf = hplugins_addconf; /* server specific */ if( HPM->load_sub ) HPM->load_sub(plugin); + ShowStatus("HPM: Loaded plugin '"CL_WHITE"%s"CL_RESET"' (%s).\n", plugin->info->name, plugin->info->version); + return plugin; } -void hplugin_unload(struct hplugin* plugin) { - unsigned int i = plugin->idx; - - if( plugin->filename ) +void hplugin_unload(struct hplugin* plugin) +{ + if (plugin->filename) aFree(plugin->filename); - if( plugin->dll ) + if (plugin->dll) plugin_close(plugin->dll); /* TODO: for manual packet unload */ /* - Go through known packets and unlink any belonging to the plugin being removed */ - aFree(plugin); if (!HPM->off) { - int cursor = 0; - HPM->plugins[i] = NULL; - for(i = 0; i < HPM->plugin_count; i++) { - if( HPM->plugins[i] == NULL ) + int i, cursor; + for (cursor = 0; cursor < HPM->plugin_count; cursor++) { + if (HPM->plugins[cursor]->idx != plugin->idx) continue; - if( cursor != i ) - HPM->plugins[cursor] = HPM->plugins[i]; + HPM->plugins[cursor] = NULL; + break; + } + for(i = cursor + 1; i < HPM->plugin_count; i++) { + HPM->plugins[cursor] = HPM->plugins[i]; cursor++; } - if( !(HPM->plugin_count = cursor) ) { + if (!(HPM->plugin_count = cursor)) { aFree(HPM->plugins); HPM->plugins = NULL; } } + aFree(plugin); } /** @@ -323,9 +534,6 @@ void hplugins_config_read(void) { if (libconfig->read_file(&plugins_conf, config_filename)) return; - if( HPM->symbol_defaults_sub ) - HPM->symbol_defaults_sub(); - plist = libconfig->lookup(&plugins_conf, "plugins_list"); for (i = 0; i < HPM->cmdline_plugins_count; i++) { config_setting_t *entry = libconfig->setting_add(plist, NULL, CONFIG_TYPE_STRING); @@ -351,11 +559,14 @@ void hplugins_config_read(void) { struct hplugin *plugin; snprintf(filename, 60, "plugins/%s%s", hooking_plugin_name, DLL_EXT); if ((plugin = HPM->load(filename))) { - bool (*func)(bool *fr); + const char * (*func)(bool *fr); bool (*addhook_sub) (enum HPluginHookType type, const char *target, void *hook, unsigned int pID); - if ((func = plugin_import(plugin->dll, "Hooked",bool (*)(bool *))) - && (addhook_sub = plugin_import(plugin->dll, "HPM_Plugin_AddHook",bool (*)(enum HPluginHookType, const char *, void *, unsigned int)))) { - if (func(&HPM->force_return)) { + if ((func = plugin_import(plugin->dll, "Hooked",const char * (*)(bool *))) != NULL + && (addhook_sub = plugin_import(plugin->dll, "HPM_Plugin_AddHook",bool (*)(enum HPluginHookType, const char *, void *, unsigned int))) != NULL) { + const char *failed = func(&HPM->force_return); + if (failed) { + ShowError("HPM: failed to retrieve '%s' for '"CL_WHITE"%s"CL_RESET"'!\n", failed, plugin_name); + } else { HPM->hooking = true; HPM->addhook_sub = addhook_sub; } @@ -370,8 +581,8 @@ void hplugins_config_read(void) { snprintf(filename, 60, "plugins/%s%s", libconfig->setting_get_string_elem(plist,i), DLL_EXT); HPM->load(filename); } - libconfig->destroy(&plugins_conf); } + libconfig->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); @@ -389,160 +600,7 @@ CPCMD(plugins) { } } } -void hplugins_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr) { - /* record address */ - switch( type ) { - /* core-handled */ - case HPDT_SESSION: - ret->HPDataSRCPtr = (void**)(&((struct socket_data *)ptr)->hdata); - ret->hdatac = &((struct socket_data *)ptr)->hdatac; - break; - /* goes to sub */ - default: - if( HPM->grabHPDataSub ) { - if( HPM->grabHPDataSub(ret,type,ptr) ) - return; - else { - ShowError("HPM:HPM:grabHPData failed, unknown type %d!\n",type); - } - } else - ShowError("HPM:grabHPData failed, type %d needs sub-handler!\n",type); - ret->HPDataSRCPtr = NULL; - ret->hdatac = NULL; - return; - } -} -void hplugins_addToHPData(enum HPluginDataTypes type, unsigned int pluginID, void *ptr, void *data, unsigned int index, bool autofree) { - struct HPluginData *HPData, **HPDataSRC; - struct HPDataOperationStorage action; - unsigned int i, max; - - HPM->grabHPData(&action,type,ptr); - - if( action.hdatac == NULL ) { /* woo it failed! */ - ShowError("HPM:addToHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index); - return; - } - - /* flag */ - HPDataSRC = *(action.HPDataSRCPtr); - max = *(action.hdatac); - - /* duplicate check */ - for(i = 0; i < max; i++) { - if( HPDataSRC[i]->pluginID == pluginID && HPDataSRC[i]->type == index ) { - ShowError("HPM:addToHPData:%s: error! attempting to insert duplicate struct of id %u and index %u\n",HPM->pid2name(pluginID),pluginID,index); - return; - } - } - - /* HPluginData is always same size, probably better to use the ERS (with reasonable chunk size e.g. 10/25/50) */ - CREATE(HPData, struct HPluginData, 1); - - /* input */ - HPData->pluginID = pluginID; - HPData->type = index; - HPData->flag.free = autofree ? 1 : 0; - HPData->data = data; - - /* resize */ - *(action.hdatac) += 1; - RECREATE(*(action.HPDataSRCPtr),struct HPluginData *,*(action.hdatac)); - - /* RECREATE modified the address */ - HPDataSRC = *(action.HPDataSRCPtr); - HPDataSRC[*(action.hdatac) - 1] = HPData; -} - -void *hplugins_getFromHPData(enum HPluginDataTypes type, unsigned int pluginID, void *ptr, unsigned int index) { - struct HPDataOperationStorage action; - struct HPluginData **HPDataSRC; - unsigned int i, max; - - HPM->grabHPData(&action,type,ptr); - - if( action.hdatac == NULL ) { /* woo it failed! */ - ShowError("HPM:getFromHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index); - return NULL; - } - - /* flag */ - HPDataSRC = *(action.HPDataSRCPtr); - max = *(action.hdatac); - - for(i = 0; i < max; i++) { - if( HPDataSRC[i]->pluginID == pluginID && HPDataSRC[i]->type == index ) - return HPDataSRC[i]->data; - } - - return NULL; -} - -void hplugins_removeFromHPData(enum HPluginDataTypes type, unsigned int pluginID, void *ptr, unsigned int index) { - struct HPDataOperationStorage action; - struct HPluginData **HPDataSRC; - unsigned int i, max; - - HPM->grabHPData(&action,type,ptr); - - if( action.hdatac == NULL ) { /* woo it failed! */ - ShowError("HPM:removeFromHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index); - return; - } - - /* flag */ - HPDataSRC = *(action.HPDataSRCPtr); - max = *(action.hdatac); - for(i = 0; i < max; i++) { - if( HPDataSRC[i]->pluginID == pluginID && HPDataSRC[i]->type == index ) - break; - } - - if( i != max ) { - unsigned int cursor; - - aFree(HPDataSRC[i]->data);/* when its removed we delete it regardless of autofree */ - aFree(HPDataSRC[i]); - HPDataSRC[i] = NULL; - - for(i = 0, cursor = 0; i < max; i++) { - if( HPDataSRC[i] == NULL ) - continue; - if( i != cursor ) - HPDataSRC[cursor] = HPDataSRC[i]; - cursor++; - } - *(action.hdatac) = cursor; - } -} - -bool hplugins_addpacket(unsigned short cmd, short length,void (*receive) (int fd),unsigned int point,unsigned int pluginID) { - struct HPluginPacket *packet; - unsigned int i; - - if( point >= hpPHP_MAX ) { - ShowError("HPM->addPacket:%s: unknown point '%u' specified for packet 0x%04x (len %d)\n",HPM->pid2name(pluginID),point,cmd,length); - return false; - } - - for(i = 0; i < HPM->packetsc[point]; i++) { - if( HPM->packets[point][i].cmd == cmd ) { - ShowError("HPM->addPacket:%s: can't add packet 0x%04x, already in use by '%s'!",HPM->pid2name(pluginID),cmd,HPM->pid2name(HPM->packets[point][i].pluginID)); - return false; - } - } - - RECREATE(HPM->packets[point], struct HPluginPacket, ++HPM->packetsc[point]); - packet = &HPM->packets[point][HPM->packetsc[point] - 1]; - - packet->pluginID = pluginID; - packet->cmd = cmd; - packet->len = length; - packet->receive = receive; - - return true; -} /* 0 = unknown 1 = OK @@ -619,80 +677,7 @@ void* HPM_reallocz(void *p, size_t size, const char *file, int line, const char char* HPM_astrdup(const char *p, const char *file, int line, const char *func) { return iMalloc->astrdup(p,HPM_file2ptr(file),line,func); } -/* TODO: add ability for tracking using pID for the upcoming runtime load/unload support. */ -bool HPM_AddHook(enum HPluginHookType type, const char *target, void *hook, unsigned int pID) { - if( !HPM->hooking ) { - ShowError("HPM:AddHook Fail! '%s' tried to hook to '%s' but HPMHooking is disabled!\n",HPM->pid2name(pID),target); - return false; - } - /* search if target is a known hook point within 'common' */ - /* if not check if a sub-hooking list is available (from the server) and run it by */ - if( HPM->addhook_sub && HPM->addhook_sub(type,target,hook,pID) ) - return true; - ShowError("HPM:AddHook: unknown Hooking Point '%s'!\n",target); - - return false; -} -void HPM_HookStop (const char *func, unsigned int pID) { - /* track? */ - HPM->force_return = true; -} -bool HPM_HookStopped (void) { - return HPM->force_return; -} -/** - * Adds a plugin-defined command-line argument. - * - * @param pluginID the current plugin's ID. - * @param name the command line argument's name, including the leading '--'. - * @param has_param whether the command line argument expects to be followed by a value. - * @param func the triggered function. - * @param help the help string to be displayed by '--help', if any. - * @return the success status. - */ -bool hpm_add_arg(unsigned int pluginID, char *name, bool has_param, CmdlineExecFunc func, const char *help) { - int i; - - if (!name || strlen(name) < 3 || name[0] != '-' || name[1] != '-') { - ShowError("HPM:add_arg:%s invalid argument name: arguments must begin with '--' (from %s)\n", name, HPM->pid2name(pluginID)); - return false; - } - - ARR_FIND(0, cmdline->args_data_count, i, strcmp(cmdline->args_data[i].name, name) == 0); - - if (i < cmdline->args_data_count) { - ShowError("HPM:add_arg:%s duplicate! (from %s)\n",name,HPM->pid2name(pluginID)); - return false; - } - - return cmdline->arg_add(pluginID, name, '\0', func, help, has_param ? CMDLINE_OPT_PARAM : CMDLINE_OPT_NORMAL); -} -bool hplugins_addconf(unsigned int pluginID, enum HPluginConfType type, char *name, void (*func) (const char *val)) { - struct HPConfListenStorage *conf; - unsigned int i; - - if( type >= HPCT_MAX ) { - ShowError("HPM->addConf:%s: unknown point '%u' specified for config '%s'\n",HPM->pid2name(pluginID),type,name); - return false; - } - - for(i = 0; i < HPM->confsc[type]; i++) { - if( !strcmpi(name,HPM->confs[type][i].key) ) { - ShowError("HPM->addConf:%s: duplicate '%s', already in use by '%s'!",HPM->pid2name(pluginID),name,HPM->pid2name(HPM->confs[type][i].pluginID)); - return false; - } - } - - RECREATE(HPM->confs[type], struct HPConfListenStorage, ++HPM->confsc[type]); - conf = &HPM->confs[type][HPM->confsc[type] - 1]; - - conf->pluginID = pluginID; - safestrncpy(conf->key, name, HPM_ADDCONF_LENGTH); - conf->func = func; - - return true; -} bool hplugins_parse_conf(const char *w1, const char *w2, enum HPluginConfType point) { unsigned int i; @@ -723,7 +708,7 @@ bool HPM_DataCheck(struct s_HPMDataCheck *src, unsigned int size, int version, c } for (i = 0; i < size; i++) { - if (!(src[i].type|SERVER_TYPE)) + if (!(src[i].type&SERVER_TYPE)) continue; if (!strdb_exists(datacheck_db, src[i].name)) { @@ -761,46 +746,6 @@ void HPM_datacheck_final(void) { db_destroy(datacheck_db); } -void hplugins_share_defaults(void) { - /* console */ -#ifdef CONSOLE_INPUT - HPM->share(console->input->addCommand,"addCPCommand"); -#endif - /* our own */ - HPM->share(hplugins_addpacket,"addPacket"); - HPM->share(hplugins_addToHPData,"addToHPData"); - HPM->share(hplugins_getFromHPData,"getFromHPData"); - HPM->share(hplugins_removeFromHPData,"removeFromHPData"); - HPM->share(HPM_AddHook,"AddHook"); - HPM->share(HPM_HookStop,"HookStop"); - HPM->share(HPM_HookStopped,"HookStopped"); - HPM->share(hpm_add_arg,"addArg"); - HPM->share(hplugins_addconf,"addConf"); - /* 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(DB, "DB"); - HPM->share(HPMiMalloc, "iMalloc"); - HPM->share(nullpo,"nullpo"); - /* socket */ - HPM->share(sockt,"sockt"); - /* strlib */ - HPM->share(strlib,"strlib"); - HPM->share(sv,"sv"); - HPM->share(StrBuf,"StrBuf"); - /* sql */ - HPM->share(SQL,"SQL"); - /* timer */ - HPM->share(timer,"timer"); - /* libconfig */ - HPM->share(libconfig,"libconfig"); - /* sysinfo */ - HPM->share(sysinfo,"sysinfo"); -} - void hpm_init(void) { unsigned int i; datacheck_db = NULL; @@ -832,8 +777,6 @@ void hpm_init(void) { HPM->packetsc[i] = 0; } - HPM->symbol_defaults(); - #ifdef CONSOLE_INPUT console->input->addCommand("plugins",CPCMD_A(plugins)); #endif @@ -928,10 +871,7 @@ void hpm_defaults(void) { 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->populate = hplugin_populate; - HPM->symbol_defaults_sub = NULL; HPM->pid2name = hplugins_id2name; HPM->parse_packets = hplugins_parse_packets; HPM->load_sub = NULL; diff --git a/src/common/HPM.h b/src/common/HPM.h index e99b0f2ae..c13132cfc 100644 --- a/src/common/HPM.h +++ b/src/common/HPM.h @@ -8,8 +8,8 @@ #error You should never include HPM.h from a plugin. #endif -#include "../common/HPMi.h" -#include "../common/cbasetypes.h" +#include "common/hercules.h" +#include "common/HPMi.h" #ifdef WIN32 #ifndef WIN32_LEAN_AND_MEAN @@ -129,10 +129,7 @@ struct HPM_interface { void (*event) (enum hp_event_types type); void *(*import_symbol) (char *name, unsigned int pID); void (*share) (void *, char *); - void (*symbol_defaults) (void); void (*config_read) (void); - bool (*populate) (struct hplugin *plugin,const char *filename); - void (*symbol_defaults_sub) (void);//TODO drop char *(*pid2name) (unsigned int pid); unsigned char (*parse_packets) (int fd, enum HPluginPacketHookingPoints point); void (*load_sub) (struct hplugin *plugin); @@ -150,7 +147,7 @@ struct HPM_interface { CMDLINEARG(loadplugin); -struct HPM_interface *HPM; +extern struct HPM_interface *HPM; void hpm_defaults(void); diff --git a/src/common/HPMDataCheck.h b/src/common/HPMDataCheck.h index 970e2449d..4fd16114b 100644 --- a/src/common/HPMDataCheck.h +++ b/src/common/HPMDataCheck.h @@ -6,10 +6,20 @@ #ifndef HPM_DATA_CHECK_H #define HPM_DATA_CHECK_H +#if !defined(HPMHOOKGEN) +#include "common/HPMSymbols.inc.h" +#endif // ! HPMHOOKGEN +#ifdef HPM_SYMBOL +#undef HPM_SYMBOL +#endif // HPM_SYMBOL HPExport const struct s_HPMDataCheck HPMDataCheck[] = { #ifdef CHAR_CHAR_H + { "char_auth_node", sizeof(struct char_auth_node), SERVER_TYPE_CHAR }, { "char_interface", sizeof(struct char_interface), SERVER_TYPE_CHAR }, + { "char_session_data", sizeof(struct char_session_data), SERVER_TYPE_CHAR }, + { "mmo_map_server", sizeof(struct mmo_map_server), SERVER_TYPE_CHAR }, + { "online_char_data", sizeof(struct online_char_data), SERVER_TYPE_CHAR }, #else #define CHAR_CHAR_H #endif // CHAR_CHAR_H @@ -94,10 +104,26 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = { #else #define COMMON_CONF_H #endif // COMMON_CONF_H + #ifdef COMMON_CONSOLE_H + { "CParseEntry", sizeof(struct CParseEntry), SERVER_TYPE_ALL }, + { "console_input_interface", sizeof(struct console_input_interface), SERVER_TYPE_ALL }, + { "console_interface", sizeof(struct console_interface), SERVER_TYPE_ALL }, + #else + #define COMMON_CONSOLE_H + #endif // COMMON_CONSOLE_H + #ifdef COMMON_CORE_H + { "CmdlineArgData", sizeof(struct CmdlineArgData), SERVER_TYPE_ALL }, + { "cmdline_interface", sizeof(struct cmdline_interface), SERVER_TYPE_ALL }, + { "core_interface", sizeof(struct core_interface), SERVER_TYPE_ALL }, + #else + #define COMMON_CORE_H + #endif // COMMON_CORE_H #ifdef COMMON_DB_H { "DBData", sizeof(struct DBData), SERVER_TYPE_ALL }, { "DBIterator", sizeof(struct DBIterator), SERVER_TYPE_ALL }, { "DBMap", sizeof(struct DBMap), SERVER_TYPE_ALL }, + { "db_interface", sizeof(struct db_interface), SERVER_TYPE_ALL }, + { "linkdb_node", sizeof(struct linkdb_node), SERVER_TYPE_ALL }, #else #define COMMON_DB_H #endif // COMMON_DB_H @@ -111,24 +137,91 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = { #else #define COMMON_ERS_H #endif // COMMON_ERS_H + #ifdef COMMON_HPMI_H + { "HPMi_interface", sizeof(struct HPMi_interface), SERVER_TYPE_ALL }, + { "hplugin_info", sizeof(struct hplugin_info), SERVER_TYPE_ALL }, + { "s_HPMDataCheck", sizeof(struct s_HPMDataCheck), SERVER_TYPE_ALL }, + #else + #define COMMON_HPMI_H + #endif // COMMON_HPMI_H + #ifdef COMMON_MALLOC_H + { "malloc_interface", sizeof(struct malloc_interface), SERVER_TYPE_ALL }, + #else + #define COMMON_MALLOC_H + #endif // COMMON_MALLOC_H #ifdef COMMON_MAPINDEX_H - { "mapindex_interface", sizeof(struct mapindex_interface), SERVER_TYPE_ALL }, + { "mapindex_interface", sizeof(struct mapindex_interface), SERVER_TYPE_CHAR|SERVER_TYPE_MAP }, #else #define COMMON_MAPINDEX_H #endif // COMMON_MAPINDEX_H #ifdef COMMON_MMO_H + { "auction_data", sizeof(struct auction_data), SERVER_TYPE_ALL }, + { "fame_list", sizeof(struct fame_list), SERVER_TYPE_ALL }, + { "guild", sizeof(struct guild), SERVER_TYPE_ALL }, + { "guild_alliance", sizeof(struct guild_alliance), SERVER_TYPE_ALL }, + { "guild_castle", sizeof(struct guild_castle), SERVER_TYPE_ALL }, + { "guild_expulsion", sizeof(struct guild_expulsion), SERVER_TYPE_ALL }, + { "guild_member", sizeof(struct guild_member), SERVER_TYPE_ALL }, + { "guild_position", sizeof(struct guild_position), SERVER_TYPE_ALL }, + { "guild_skill", sizeof(struct guild_skill), SERVER_TYPE_ALL }, + { "guild_storage", sizeof(struct guild_storage), SERVER_TYPE_ALL }, + { "hotkey", sizeof(struct hotkey), SERVER_TYPE_ALL }, + { "item", sizeof(struct item), SERVER_TYPE_ALL }, + { "mail_data", sizeof(struct mail_data), SERVER_TYPE_ALL }, + { "mail_message", sizeof(struct mail_message), SERVER_TYPE_ALL }, + { "mmo_charstatus", sizeof(struct mmo_charstatus), SERVER_TYPE_ALL }, + { "party", sizeof(struct party), SERVER_TYPE_ALL }, + { "party_member", sizeof(struct party_member), SERVER_TYPE_ALL }, + { "point", sizeof(struct point), SERVER_TYPE_ALL }, { "quest", sizeof(struct quest), SERVER_TYPE_ALL }, + { "s_elemental", sizeof(struct s_elemental), SERVER_TYPE_ALL }, + { "s_friend", sizeof(struct s_friend), SERVER_TYPE_ALL }, + { "s_homunculus", sizeof(struct s_homunculus), SERVER_TYPE_ALL }, + { "s_mercenary", sizeof(struct s_mercenary), SERVER_TYPE_ALL }, + { "s_pet", sizeof(struct s_pet), SERVER_TYPE_ALL }, + { "s_skill", sizeof(struct s_skill), SERVER_TYPE_ALL }, + { "script_reg_num", sizeof(struct script_reg_num), SERVER_TYPE_ALL }, + { "script_reg_state", sizeof(struct script_reg_state), SERVER_TYPE_ALL }, + { "script_reg_str", sizeof(struct script_reg_str), SERVER_TYPE_ALL }, + { "status_change_data", sizeof(struct status_change_data), SERVER_TYPE_ALL }, + { "storage_data", sizeof(struct storage_data), SERVER_TYPE_ALL }, #else #define COMMON_MMO_H #endif // COMMON_MMO_H + #ifdef COMMON_NULLPO_H + { "nullpo_interface", sizeof(struct nullpo_interface), SERVER_TYPE_ALL }, + #else + #define COMMON_NULLPO_H + #endif // COMMON_NULLPO_H + #ifdef COMMON_SHOWMSG_H + { "showmsg_interface", sizeof(struct showmsg_interface), SERVER_TYPE_ALL }, + #else + #define COMMON_SHOWMSG_H + #endif // COMMON_SHOWMSG_H #ifdef COMMON_SOCKET_H + { "hSockOpt", sizeof(struct hSockOpt), SERVER_TYPE_ALL }, + { "s_subnet", sizeof(struct s_subnet), SERVER_TYPE_ALL }, + { "socket_data", sizeof(struct socket_data), SERVER_TYPE_ALL }, { "socket_interface", sizeof(struct socket_interface), SERVER_TYPE_ALL }, #else #define COMMON_SOCKET_H #endif // COMMON_SOCKET_H + #ifdef COMMON_SPINLOCK_H + { "SPIN_LOCK", sizeof(struct SPIN_LOCK), SERVER_TYPE_ALL }, + #else + #define COMMON_SPINLOCK_H + #endif // COMMON_SPINLOCK_H + #ifdef COMMON_SQL_H + { "sql_interface", sizeof(struct sql_interface), SERVER_TYPE_ALL }, + #else + #define COMMON_SQL_H + #endif // COMMON_SQL_H #ifdef COMMON_STRLIB_H { "StringBuf", sizeof(struct StringBuf), SERVER_TYPE_ALL }, { "s_svstate", sizeof(struct s_svstate), SERVER_TYPE_ALL }, + { "stringbuf_interface", sizeof(struct stringbuf_interface), SERVER_TYPE_ALL }, + { "strlib_interface", sizeof(struct strlib_interface), SERVER_TYPE_ALL }, + { "sv_interface", sizeof(struct sv_interface), SERVER_TYPE_ALL }, #else #define COMMON_STRLIB_H #endif // COMMON_STRLIB_H @@ -137,97 +230,448 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = { #else #define COMMON_SYSINFO_H #endif // COMMON_SYSINFO_H + #ifdef COMMON_TIMER_H + { "TimerData", sizeof(struct TimerData), SERVER_TYPE_ALL }, + { "timer_interface", sizeof(struct timer_interface), SERVER_TYPE_ALL }, + #else + #define COMMON_TIMER_H + #endif // COMMON_TIMER_H + #ifdef COMMON_UTILS_H + { "HCache_interface", sizeof(struct HCache_interface), SERVER_TYPE_ALL }, + #else + #define COMMON_UTILS_H + #endif // COMMON_UTILS_H + #ifdef LOGIN_ACCOUNT_H + { "Account_engine", sizeof(struct Account_engine), SERVER_TYPE_LOGIN }, + { "AccountDB", sizeof(struct AccountDB), SERVER_TYPE_LOGIN }, + { "AccountDBIterator", sizeof(struct AccountDBIterator), SERVER_TYPE_LOGIN }, + { "mmo_account", sizeof(struct mmo_account), SERVER_TYPE_LOGIN }, + #else + #define LOGIN_ACCOUNT_H + #endif // LOGIN_ACCOUNT_H #ifdef LOGIN_LOGIN_H + { "Login_Config", sizeof(struct Login_Config), SERVER_TYPE_LOGIN }, + { "client_hash_node", sizeof(struct client_hash_node), SERVER_TYPE_LOGIN }, + { "login_auth_node", sizeof(struct login_auth_node), SERVER_TYPE_LOGIN }, { "login_interface", sizeof(struct login_interface), SERVER_TYPE_LOGIN }, + { "login_session_data", sizeof(struct login_session_data), SERVER_TYPE_LOGIN }, + { "mmo_char_server", sizeof(struct mmo_char_server), SERVER_TYPE_LOGIN }, + { "online_login_data", sizeof(struct online_login_data), SERVER_TYPE_LOGIN }, #else #define LOGIN_LOGIN_H #endif // LOGIN_LOGIN_H #ifdef MAP_ATCOMMAND_H { "AliasInfo", sizeof(struct AliasInfo), SERVER_TYPE_MAP }, + { "AtCommandInfo", sizeof(struct AtCommandInfo), SERVER_TYPE_MAP }, + { "atcmd_binding_data", sizeof(struct atcmd_binding_data), SERVER_TYPE_MAP }, { "atcommand_interface", sizeof(struct atcommand_interface), SERVER_TYPE_MAP }, #else #define MAP_ATCOMMAND_H #endif // MAP_ATCOMMAND_H + #ifdef MAP_BATTLEGROUND_H + { "battleground_data", sizeof(struct battleground_data), SERVER_TYPE_MAP }, + { "battleground_interface", sizeof(struct battleground_interface), SERVER_TYPE_MAP }, + { "battleground_member_data", sizeof(struct battleground_member_data), SERVER_TYPE_MAP }, + { "bg_arena", sizeof(struct bg_arena), SERVER_TYPE_MAP }, + #else + #define MAP_BATTLEGROUND_H + #endif // MAP_BATTLEGROUND_H #ifdef MAP_BATTLE_H + { "Battle_Config", sizeof(struct Battle_Config), SERVER_TYPE_MAP }, { "Damage", sizeof(struct Damage), SERVER_TYPE_MAP }, { "battle_interface", sizeof(struct battle_interface), SERVER_TYPE_MAP }, + { "delay_damage", sizeof(struct delay_damage), SERVER_TYPE_MAP }, #else #define MAP_BATTLE_H #endif // MAP_BATTLE_H #ifdef MAP_BUYINGSTORE_H { "buyingstore_interface", sizeof(struct buyingstore_interface), SERVER_TYPE_MAP }, + { "s_buyingstore", sizeof(struct s_buyingstore), SERVER_TYPE_MAP }, { "s_buyingstore_item", sizeof(struct s_buyingstore_item), SERVER_TYPE_MAP }, #else #define MAP_BUYINGSTORE_H #endif // MAP_BUYINGSTORE_H #ifdef MAP_CHANNEL_H { "Channel_Config", sizeof(struct Channel_Config), SERVER_TYPE_MAP }, + { "channel_ban_entry", sizeof(struct channel_ban_entry), SERVER_TYPE_MAP }, + { "channel_data", sizeof(struct channel_data), SERVER_TYPE_MAP }, + { "channel_interface", sizeof(struct channel_interface), SERVER_TYPE_MAP }, #else #define MAP_CHANNEL_H #endif // MAP_CHANNEL_H + #ifdef MAP_CHAT_H + { "chat_data", sizeof(struct chat_data), SERVER_TYPE_MAP }, + { "chat_interface", sizeof(struct chat_interface), SERVER_TYPE_MAP }, + #else + #define MAP_CHAT_H + #endif // MAP_CHAT_H #ifdef MAP_CHRIF_H { "auth_node", sizeof(struct auth_node), SERVER_TYPE_MAP }, + { "chrif_interface", sizeof(struct chrif_interface), SERVER_TYPE_MAP }, #else #define MAP_CHRIF_H #endif // MAP_CHRIF_H #ifdef MAP_CLIF_H + { "cdelayed_damage", sizeof(struct cdelayed_damage), SERVER_TYPE_MAP }, { "clif_interface", sizeof(struct clif_interface), SERVER_TYPE_MAP }, + { "hCSData", sizeof(struct hCSData), SERVER_TYPE_MAP }, + { "merge_item", sizeof(struct merge_item), SERVER_TYPE_MAP }, + { "s_packet_db", sizeof(struct s_packet_db), SERVER_TYPE_MAP }, #else #define MAP_CLIF_H #endif // MAP_CLIF_H + #ifdef MAP_DUEL_H + { "duel", sizeof(struct duel), SERVER_TYPE_MAP }, + { "duel_interface", sizeof(struct duel_interface), SERVER_TYPE_MAP }, + #else + #define MAP_DUEL_H + #endif // MAP_DUEL_H #ifdef MAP_ELEMENTAL_H + { "elemental_data", sizeof(struct elemental_data), SERVER_TYPE_MAP }, + { "elemental_interface", sizeof(struct elemental_interface), SERVER_TYPE_MAP }, { "elemental_skill", sizeof(struct elemental_skill), SERVER_TYPE_MAP }, + { "s_elemental_db", sizeof(struct s_elemental_db), SERVER_TYPE_MAP }, #else #define MAP_ELEMENTAL_H #endif // MAP_ELEMENTAL_H #ifdef MAP_GUILD_H { "eventlist", sizeof(struct eventlist), SERVER_TYPE_MAP }, { "guardian_data", sizeof(struct guardian_data), SERVER_TYPE_MAP }, + { "guild_expcache", sizeof(struct guild_expcache), SERVER_TYPE_MAP }, + { "guild_interface", sizeof(struct guild_interface), SERVER_TYPE_MAP }, + { "s_guild_skill_tree", sizeof(struct s_guild_skill_tree), SERVER_TYPE_MAP }, #else #define MAP_GUILD_H #endif // MAP_GUILD_H + #ifdef MAP_HOMUNCULUS_H + { "h_stats", sizeof(struct h_stats), SERVER_TYPE_MAP }, + { "homun_data", sizeof(struct homun_data), SERVER_TYPE_MAP }, + { "homun_dbs", sizeof(struct homun_dbs), SERVER_TYPE_MAP }, + { "homun_skill_tree_entry", sizeof(struct homun_skill_tree_entry), SERVER_TYPE_MAP }, + { "homunculus_interface", sizeof(struct homunculus_interface), SERVER_TYPE_MAP }, + { "s_homunculus_db", sizeof(struct s_homunculus_db), SERVER_TYPE_MAP }, + #else + #define MAP_HOMUNCULUS_H + #endif // MAP_HOMUNCULUS_H + #ifdef MAP_INSTANCE_H + { "instance_data", sizeof(struct instance_data), SERVER_TYPE_MAP }, + { "instance_interface", sizeof(struct instance_interface), SERVER_TYPE_MAP }, + #else + #define MAP_INSTANCE_H + #endif // MAP_INSTANCE_H + #ifdef MAP_INTIF_H + { "intif_interface", sizeof(struct intif_interface), SERVER_TYPE_MAP }, + #else + #define MAP_INTIF_H + #endif // MAP_INTIF_H + #ifdef MAP_IRC_BOT_H + { "irc_bot_interface", sizeof(struct irc_bot_interface), SERVER_TYPE_MAP }, + { "irc_func", sizeof(struct irc_func), SERVER_TYPE_MAP }, + #else + #define MAP_IRC_BOT_H + #endif // MAP_IRC_BOT_H + #ifdef MAP_ITEMDB_H + { "item_chain", sizeof(struct item_chain), SERVER_TYPE_MAP }, + { "item_chain_entry", sizeof(struct item_chain_entry), SERVER_TYPE_MAP }, + { "item_combo", sizeof(struct item_combo), SERVER_TYPE_MAP }, + { "item_data", sizeof(struct item_data), SERVER_TYPE_MAP }, + { "item_group", sizeof(struct item_group), SERVER_TYPE_MAP }, + { "item_package", sizeof(struct item_package), SERVER_TYPE_MAP }, + { "item_package_must_entry", sizeof(struct item_package_must_entry), SERVER_TYPE_MAP }, + { "item_package_rand_entry", sizeof(struct item_package_rand_entry), SERVER_TYPE_MAP }, + { "item_package_rand_group", sizeof(struct item_package_rand_group), SERVER_TYPE_MAP }, + { "itemdb_interface", sizeof(struct itemdb_interface), SERVER_TYPE_MAP }, + #else + #define MAP_ITEMDB_H + #endif // MAP_ITEMDB_H + #ifdef MAP_LOG_H + { "log_interface", sizeof(struct log_interface), SERVER_TYPE_MAP }, + #else + #define MAP_LOG_H + #endif // MAP_LOG_H + #ifdef MAP_MAIL_H + { "mail_interface", sizeof(struct mail_interface), SERVER_TYPE_MAP }, + #else + #define MAP_MAIL_H + #endif // MAP_MAIL_H #ifdef MAP_MAPREG_H + { "mapreg_interface", sizeof(struct mapreg_interface), SERVER_TYPE_MAP }, { "mapreg_save", sizeof(struct mapreg_save), SERVER_TYPE_MAP }, #else #define MAP_MAPREG_H #endif // MAP_MAPREG_H #ifdef MAP_MAP_H + { "block_list", sizeof(struct block_list), SERVER_TYPE_MAP }, + { "charid2nick", sizeof(struct charid2nick), SERVER_TYPE_MAP }, + { "charid_request", sizeof(struct charid_request), SERVER_TYPE_MAP }, + { "flooritem_data", sizeof(struct flooritem_data), SERVER_TYPE_MAP }, + { "iwall_data", sizeof(struct iwall_data), SERVER_TYPE_MAP }, + { "map_cache_main_header", sizeof(struct map_cache_main_header), SERVER_TYPE_MAP }, + { "map_cache_map_info", sizeof(struct map_cache_map_info), SERVER_TYPE_MAP }, + { "map_data", sizeof(struct map_data), SERVER_TYPE_MAP }, { "map_data_other_server", sizeof(struct map_data_other_server), SERVER_TYPE_MAP }, + { "map_drop_list", sizeof(struct map_drop_list), SERVER_TYPE_MAP }, + { "map_interface", sizeof(struct map_interface), SERVER_TYPE_MAP }, + { "map_zone_data", sizeof(struct map_zone_data), SERVER_TYPE_MAP }, + { "map_zone_disabled_command_entry", sizeof(struct map_zone_disabled_command_entry), SERVER_TYPE_MAP }, + { "map_zone_disabled_skill_entry", sizeof(struct map_zone_disabled_skill_entry), SERVER_TYPE_MAP }, + { "map_zone_skill_damage_cap_entry", sizeof(struct map_zone_skill_damage_cap_entry), SERVER_TYPE_MAP }, + { "mapcell", sizeof(struct mapcell), SERVER_TYPE_MAP }, + { "mapflag_skill_adjust", sizeof(struct mapflag_skill_adjust), SERVER_TYPE_MAP }, + { "mapit_interface", sizeof(struct mapit_interface), SERVER_TYPE_MAP }, + { "questinfo", sizeof(struct questinfo), SERVER_TYPE_MAP }, + { "spawn_data", sizeof(struct spawn_data), SERVER_TYPE_MAP }, #else #define MAP_MAP_H #endif // MAP_MAP_H + #ifdef MAP_MERCENARY_H + { "mercenary_data", sizeof(struct mercenary_data), SERVER_TYPE_MAP }, + { "mercenary_interface", sizeof(struct mercenary_interface), SERVER_TYPE_MAP }, + { "s_mercenary_db", sizeof(struct s_mercenary_db), SERVER_TYPE_MAP }, + #else + #define MAP_MERCENARY_H + #endif // MAP_MERCENARY_H + #ifdef MAP_MOB_H + { "item_drop", sizeof(struct item_drop), SERVER_TYPE_MAP }, + { "item_drop_list", sizeof(struct item_drop_list), SERVER_TYPE_MAP }, + { "mob_chat", sizeof(struct mob_chat), SERVER_TYPE_MAP }, + { "mob_data", sizeof(struct mob_data), SERVER_TYPE_MAP }, + { "mob_db", sizeof(struct mob_db), SERVER_TYPE_MAP }, + { "mob_interface", sizeof(struct mob_interface), SERVER_TYPE_MAP }, + { "mob_skill", sizeof(struct mob_skill), SERVER_TYPE_MAP }, + { "spawn_info", sizeof(struct spawn_info), SERVER_TYPE_MAP }, + #else + #define MAP_MOB_H + #endif // MAP_MOB_H + #ifdef MAP_NPC_H + { "event_data", sizeof(struct event_data), SERVER_TYPE_MAP }, + { "npc_data", sizeof(struct npc_data), SERVER_TYPE_MAP }, + { "npc_interface", sizeof(struct npc_interface), SERVER_TYPE_MAP }, + { "npc_item_list", sizeof(struct npc_item_list), SERVER_TYPE_MAP }, + { "npc_label_list", sizeof(struct npc_label_list), SERVER_TYPE_MAP }, + { "npc_path_data", sizeof(struct npc_path_data), SERVER_TYPE_MAP }, + { "npc_shop_data", sizeof(struct npc_shop_data), SERVER_TYPE_MAP }, + { "npc_src_list", sizeof(struct npc_src_list), SERVER_TYPE_MAP }, + { "npc_timerevent_list", sizeof(struct npc_timerevent_list), SERVER_TYPE_MAP }, + #else + #define MAP_NPC_H + #endif // MAP_NPC_H #ifdef MAP_PACKETS_STRUCT_H + { "EQUIPITEM_INFO", sizeof(struct EQUIPITEM_INFO), SERVER_TYPE_MAP }, { "EQUIPSLOTINFO", sizeof(struct EQUIPSLOTINFO), SERVER_TYPE_MAP }, + { "NORMALITEM_INFO", sizeof(struct NORMALITEM_INFO), SERVER_TYPE_MAP }, + { "RndOptions", sizeof(struct RndOptions), SERVER_TYPE_MAP }, + { "packet_additem", sizeof(struct packet_additem), SERVER_TYPE_MAP }, + { "packet_authok", sizeof(struct packet_authok), SERVER_TYPE_MAP }, + { "packet_banking_check", sizeof(struct packet_banking_check), SERVER_TYPE_MAP }, + { "packet_banking_deposit_ack", sizeof(struct packet_banking_deposit_ack), SERVER_TYPE_MAP }, + { "packet_banking_deposit_req", sizeof(struct packet_banking_deposit_req), SERVER_TYPE_MAP }, + { "packet_banking_withdraw_ack", sizeof(struct packet_banking_withdraw_ack), SERVER_TYPE_MAP }, + { "packet_banking_withdraw_req", sizeof(struct packet_banking_withdraw_req), SERVER_TYPE_MAP }, + { "packet_bgqueue_ack", sizeof(struct packet_bgqueue_ack), SERVER_TYPE_MAP }, + { "packet_bgqueue_battlebegin_ack", sizeof(struct packet_bgqueue_battlebegin_ack), SERVER_TYPE_MAP }, + { "packet_bgqueue_battlebegins", sizeof(struct packet_bgqueue_battlebegins), SERVER_TYPE_MAP }, + { "packet_bgqueue_checkstate", sizeof(struct packet_bgqueue_checkstate), SERVER_TYPE_MAP }, + { "packet_bgqueue_notice_delete", sizeof(struct packet_bgqueue_notice_delete), SERVER_TYPE_MAP }, + { "packet_bgqueue_notify_entry", sizeof(struct packet_bgqueue_notify_entry), SERVER_TYPE_MAP }, + { "packet_bgqueue_register", sizeof(struct packet_bgqueue_register), SERVER_TYPE_MAP }, + { "packet_bgqueue_revoke_req", sizeof(struct packet_bgqueue_revoke_req), SERVER_TYPE_MAP }, + { "packet_bgqueue_update_info", sizeof(struct packet_bgqueue_update_info), SERVER_TYPE_MAP }, + { "packet_cart_additem_ack", sizeof(struct packet_cart_additem_ack), SERVER_TYPE_MAP }, + { "packet_damage", sizeof(struct packet_damage), SERVER_TYPE_MAP }, + { "packet_dropflooritem", sizeof(struct packet_dropflooritem), SERVER_TYPE_MAP }, + { "packet_equip_item", sizeof(struct packet_equip_item), SERVER_TYPE_MAP }, + { "packet_equipitem_ack", sizeof(struct packet_equipitem_ack), SERVER_TYPE_MAP }, + { "packet_gm_monster_item", sizeof(struct packet_gm_monster_item), SERVER_TYPE_MAP }, + { "packet_graffiti_entry", sizeof(struct packet_graffiti_entry), SERVER_TYPE_MAP }, + { "packet_hotkey", sizeof(struct packet_hotkey), SERVER_TYPE_MAP }, + { "packet_idle_unit", sizeof(struct packet_idle_unit), SERVER_TYPE_MAP }, + { "packet_idle_unit2", sizeof(struct packet_idle_unit2), SERVER_TYPE_MAP }, + { "packet_item_drop_announce", sizeof(struct packet_item_drop_announce), SERVER_TYPE_MAP }, + { "packet_itemlist_equip", sizeof(struct packet_itemlist_equip), SERVER_TYPE_MAP }, + { "packet_itemlist_normal", sizeof(struct packet_itemlist_normal), SERVER_TYPE_MAP }, + { "packet_maptypeproperty2", sizeof(struct packet_maptypeproperty2), SERVER_TYPE_MAP }, + { "packet_monster_hp", sizeof(struct packet_monster_hp), SERVER_TYPE_MAP }, + { "packet_notify_bounditem", sizeof(struct packet_notify_bounditem), SERVER_TYPE_MAP }, + { "packet_npc_market_open", sizeof(struct packet_npc_market_open), SERVER_TYPE_MAP }, + { "packet_npc_market_purchase", sizeof(struct packet_npc_market_purchase), SERVER_TYPE_MAP }, + { "packet_npc_market_result_ack", sizeof(struct packet_npc_market_result_ack), SERVER_TYPE_MAP }, + { "packet_package_item_announce", sizeof(struct packet_package_item_announce), SERVER_TYPE_MAP }, + { "packet_party_leader_changed", sizeof(struct packet_party_leader_changed), SERVER_TYPE_MAP }, + { "packet_roulette_close_ack", sizeof(struct packet_roulette_close_ack), SERVER_TYPE_MAP }, + { "packet_roulette_generate_ack", sizeof(struct packet_roulette_generate_ack), SERVER_TYPE_MAP }, + { "packet_roulette_info_ack", sizeof(struct packet_roulette_info_ack), SERVER_TYPE_MAP }, + { "packet_roulette_itemrecv_ack", sizeof(struct packet_roulette_itemrecv_ack), SERVER_TYPE_MAP }, + { "packet_roulette_itemrecv_req", sizeof(struct packet_roulette_itemrecv_req), SERVER_TYPE_MAP }, + { "packet_roulette_open_ack", sizeof(struct packet_roulette_open_ack), SERVER_TYPE_MAP }, + { "packet_sc_notick", sizeof(struct packet_sc_notick), SERVER_TYPE_MAP }, + { "packet_script_clear", sizeof(struct packet_script_clear), SERVER_TYPE_MAP }, + { "packet_skill_entry", sizeof(struct packet_skill_entry), SERVER_TYPE_MAP }, + { "packet_spawn_unit", sizeof(struct packet_spawn_unit), SERVER_TYPE_MAP }, + { "packet_spawn_unit2", sizeof(struct packet_spawn_unit2), SERVER_TYPE_MAP }, + { "packet_status_change", sizeof(struct packet_status_change), SERVER_TYPE_MAP }, + { "packet_status_change2", sizeof(struct packet_status_change2), SERVER_TYPE_MAP }, + { "packet_status_change_end", sizeof(struct packet_status_change_end), SERVER_TYPE_MAP }, + { "packet_storelist_equip", sizeof(struct packet_storelist_equip), SERVER_TYPE_MAP }, + { "packet_storelist_normal", sizeof(struct packet_storelist_normal), SERVER_TYPE_MAP }, + { "packet_unequipitem_ack", sizeof(struct packet_unequipitem_ack), SERVER_TYPE_MAP }, + { "packet_unit_walking", sizeof(struct packet_unit_walking), SERVER_TYPE_MAP }, + { "packet_viewequip_ack", sizeof(struct packet_viewequip_ack), SERVER_TYPE_MAP }, + { "packet_wis_end", sizeof(struct packet_wis_end), SERVER_TYPE_MAP }, #else #define MAP_PACKETS_STRUCT_H #endif // MAP_PACKETS_STRUCT_H + #ifdef MAP_PARTY_H + { "party_booking_ad_info", sizeof(struct party_booking_ad_info), SERVER_TYPE_MAP }, + { "party_booking_detail", sizeof(struct party_booking_detail), SERVER_TYPE_MAP }, + { "party_data", sizeof(struct party_data), SERVER_TYPE_MAP }, + { "party_interface", sizeof(struct party_interface), SERVER_TYPE_MAP }, + { "party_member_data", sizeof(struct party_member_data), SERVER_TYPE_MAP }, + #else + #define MAP_PARTY_H + #endif // MAP_PARTY_H + #ifdef MAP_PATH_H + { "path_interface", sizeof(struct path_interface), SERVER_TYPE_MAP }, + { "shootpath_data", sizeof(struct shootpath_data), SERVER_TYPE_MAP }, + { "walkpath_data", sizeof(struct walkpath_data), SERVER_TYPE_MAP }, + #else + #define MAP_PATH_H + #endif // MAP_PATH_H + #ifdef MAP_PC_GROUPS_H + { "GroupSettings", sizeof(struct GroupSettings), SERVER_TYPE_MAP }, + { "pc_groups_interface", sizeof(struct pc_groups_interface), SERVER_TYPE_MAP }, + { "pc_groups_new_permission", sizeof(struct pc_groups_new_permission), SERVER_TYPE_MAP }, + { "pc_groups_permission_table", sizeof(struct pc_groups_permission_table), SERVER_TYPE_MAP }, + #else + #define MAP_PC_GROUPS_H + #endif // MAP_PC_GROUPS_H #ifdef MAP_PC_H { "autotrade_vending", sizeof(struct autotrade_vending), SERVER_TYPE_MAP }, { "item_cd", sizeof(struct item_cd), SERVER_TYPE_MAP }, + { "map_session_data", sizeof(struct map_session_data), SERVER_TYPE_MAP }, + { "pc_combos", sizeof(struct pc_combos), SERVER_TYPE_MAP }, + { "pc_interface", sizeof(struct pc_interface), SERVER_TYPE_MAP }, + { "s_add_drop", sizeof(struct s_add_drop), SERVER_TYPE_MAP }, { "s_addeffect", sizeof(struct s_addeffect), SERVER_TYPE_MAP }, + { "s_addeffectonskill", sizeof(struct s_addeffectonskill), SERVER_TYPE_MAP }, + { "s_autobonus", sizeof(struct s_autobonus), SERVER_TYPE_MAP }, + { "s_autospell", sizeof(struct s_autospell), SERVER_TYPE_MAP }, + { "sg_data", sizeof(struct sg_data), SERVER_TYPE_MAP }, + { "skill_tree_entry", sizeof(struct skill_tree_entry), SERVER_TYPE_MAP }, + { "weapon_data", sizeof(struct weapon_data), SERVER_TYPE_MAP }, #else #define MAP_PC_H #endif // MAP_PC_H + #ifdef MAP_PET_H + { "pet_bonus", sizeof(struct pet_bonus), SERVER_TYPE_MAP }, + { "pet_data", sizeof(struct pet_data), SERVER_TYPE_MAP }, + { "pet_interface", sizeof(struct pet_interface), SERVER_TYPE_MAP }, + { "pet_loot", sizeof(struct pet_loot), SERVER_TYPE_MAP }, + { "pet_recovery", sizeof(struct pet_recovery), SERVER_TYPE_MAP }, + { "pet_skill_attack", sizeof(struct pet_skill_attack), SERVER_TYPE_MAP }, + { "pet_skill_support", sizeof(struct pet_skill_support), SERVER_TYPE_MAP }, + { "s_pet_db", sizeof(struct s_pet_db), SERVER_TYPE_MAP }, + #else + #define MAP_PET_H + #endif // MAP_PET_H + #ifdef MAP_QUEST_H + { "quest_db", sizeof(struct quest_db), SERVER_TYPE_MAP }, + { "quest_dropitem", sizeof(struct quest_dropitem), SERVER_TYPE_MAP }, + { "quest_interface", sizeof(struct quest_interface), SERVER_TYPE_MAP }, + { "quest_objective", sizeof(struct quest_objective), SERVER_TYPE_MAP }, + #else + #define MAP_QUEST_H + #endif // MAP_QUEST_H #ifdef MAP_SCRIPT_H { "Script_Config", sizeof(struct Script_Config), SERVER_TYPE_MAP }, + { "casecheck_data", sizeof(struct casecheck_data), SERVER_TYPE_MAP }, + { "hQueue", sizeof(struct hQueue), SERVER_TYPE_MAP }, + { "hQueueIterator", sizeof(struct hQueueIterator), SERVER_TYPE_MAP }, { "reg_db", sizeof(struct reg_db), SERVER_TYPE_MAP }, + { "script_array", sizeof(struct script_array), SERVER_TYPE_MAP }, + { "script_code", sizeof(struct script_code), SERVER_TYPE_MAP }, + { "script_data", sizeof(struct script_data), SERVER_TYPE_MAP }, + { "script_function", sizeof(struct script_function), SERVER_TYPE_MAP }, { "script_interface", sizeof(struct script_interface), SERVER_TYPE_MAP }, + { "script_label_entry", sizeof(struct script_label_entry), SERVER_TYPE_MAP }, + { "script_retinfo", sizeof(struct script_retinfo), SERVER_TYPE_MAP }, + { "script_stack", sizeof(struct script_stack), SERVER_TYPE_MAP }, + { "script_state", sizeof(struct script_state), SERVER_TYPE_MAP }, + { "script_string_buf", sizeof(struct script_string_buf), SERVER_TYPE_MAP }, + { "script_syntax_data", sizeof(struct script_syntax_data), SERVER_TYPE_MAP }, + { "str_data_struct", sizeof(struct str_data_struct), SERVER_TYPE_MAP }, + { "string_translation", sizeof(struct string_translation), SERVER_TYPE_MAP }, #else #define MAP_SCRIPT_H #endif // MAP_SCRIPT_H #ifdef MAP_SEARCHSTORE_H + { "s_search_store_info", sizeof(struct s_search_store_info), SERVER_TYPE_MAP }, + { "s_search_store_info_item", sizeof(struct s_search_store_info_item), SERVER_TYPE_MAP }, { "searchstore_interface", sizeof(struct searchstore_interface), SERVER_TYPE_MAP }, #else #define MAP_SEARCHSTORE_H #endif // MAP_SEARCHSTORE_H #ifdef MAP_SKILL_H + { "s_skill_abra_db", sizeof(struct s_skill_abra_db), SERVER_TYPE_MAP }, + { "s_skill_arrow_db", sizeof(struct s_skill_arrow_db), SERVER_TYPE_MAP }, + { "s_skill_changematerial_db", sizeof(struct s_skill_changematerial_db), SERVER_TYPE_MAP }, + { "s_skill_db", sizeof(struct s_skill_db), SERVER_TYPE_MAP }, + { "s_skill_dbs", sizeof(struct s_skill_dbs), SERVER_TYPE_MAP }, + { "s_skill_improvise_db", sizeof(struct s_skill_improvise_db), SERVER_TYPE_MAP }, + { "s_skill_magicmushroom_db", sizeof(struct s_skill_magicmushroom_db), SERVER_TYPE_MAP }, + { "s_skill_produce_db", sizeof(struct s_skill_produce_db), SERVER_TYPE_MAP }, + { "s_skill_spellbook_db", sizeof(struct s_skill_spellbook_db), SERVER_TYPE_MAP }, + { "s_skill_unit_layout", sizeof(struct s_skill_unit_layout), SERVER_TYPE_MAP }, { "skill_cd", sizeof(struct skill_cd), SERVER_TYPE_MAP }, + { "skill_cd_entry", sizeof(struct skill_cd_entry), SERVER_TYPE_MAP }, { "skill_condition", sizeof(struct skill_condition), SERVER_TYPE_MAP }, { "skill_interface", sizeof(struct skill_interface), SERVER_TYPE_MAP }, + { "skill_timerskill", sizeof(struct skill_timerskill), SERVER_TYPE_MAP }, + { "skill_unit", sizeof(struct skill_unit), SERVER_TYPE_MAP }, + { "skill_unit_group", sizeof(struct skill_unit_group), SERVER_TYPE_MAP }, + { "skill_unit_group_tickset", sizeof(struct skill_unit_group_tickset), SERVER_TYPE_MAP }, { "skill_unit_save", sizeof(struct skill_unit_save), SERVER_TYPE_MAP }, #else #define MAP_SKILL_H #endif // MAP_SKILL_H + #ifdef MAP_STATUS_H + { "regen_data", sizeof(struct regen_data), SERVER_TYPE_MAP }, + { "regen_data_sub", sizeof(struct regen_data_sub), SERVER_TYPE_MAP }, + { "s_refine_info", sizeof(struct s_refine_info), SERVER_TYPE_MAP }, + { "s_status_dbs", sizeof(struct s_status_dbs), SERVER_TYPE_MAP }, + { "sc_display_entry", sizeof(struct sc_display_entry), SERVER_TYPE_MAP }, + { "status_change", sizeof(struct status_change), SERVER_TYPE_MAP }, + { "status_change_entry", sizeof(struct status_change_entry), SERVER_TYPE_MAP }, + { "status_data", sizeof(struct status_data), SERVER_TYPE_MAP }, + { "status_interface", sizeof(struct status_interface), SERVER_TYPE_MAP }, + { "weapon_atk", sizeof(struct weapon_atk), SERVER_TYPE_MAP }, + #else + #define MAP_STATUS_H + #endif // MAP_STATUS_H + #ifdef MAP_STORAGE_H + { "guild_storage_interface", sizeof(struct guild_storage_interface), SERVER_TYPE_MAP }, + { "storage_interface", sizeof(struct storage_interface), SERVER_TYPE_MAP }, + #else + #define MAP_STORAGE_H + #endif // MAP_STORAGE_H + #ifdef MAP_TRADE_H + { "trade_interface", sizeof(struct trade_interface), SERVER_TYPE_MAP }, + #else + #define MAP_TRADE_H + #endif // MAP_TRADE_H + #ifdef MAP_UNIT_H + { "unit_data", sizeof(struct unit_data), SERVER_TYPE_MAP }, + { "unit_interface", sizeof(struct unit_interface), SERVER_TYPE_MAP }, + { "view_data", sizeof(struct view_data), SERVER_TYPE_MAP }, + #else + #define MAP_UNIT_H + #endif // MAP_UNIT_H + #ifdef MAP_VENDING_H + { "s_vending", sizeof(struct s_vending), SERVER_TYPE_MAP }, + { "vending_interface", sizeof(struct vending_interface), SERVER_TYPE_MAP }, + #else + #define MAP_VENDING_H + #endif // MAP_VENDING_H }; HPExport unsigned int HPMDataCheckLen = ARRAYLENGTH(HPMDataCheck); HPExport int HPMDataCheckVer = 1; diff --git a/src/common/HPMSymbols.inc.h b/src/common/HPMSymbols.inc.h new file mode 100644 index 000000000..3a4c5852c --- /dev/null +++ b/src/common/HPMSymbols.inc.h @@ -0,0 +1,451 @@ +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// +// NOTE: This file was auto-generated and should never be manually edited, +// as it will get overwritten. + +#if !defined(HERCULES_CORE) +#ifdef COMMON_UTILS_H /* HCache */ +struct HCache_interface *HCache; +#endif // COMMON_UTILS_H +#ifdef MAP_ATCOMMAND_H /* atcommand */ +struct atcommand_interface *atcommand; +#endif // MAP_ATCOMMAND_H +#ifdef MAP_BATTLE_H /* battle */ +struct battle_interface *battle; +#endif // MAP_BATTLE_H +#ifdef MAP_BATTLEGROUND_H /* bg */ +struct battleground_interface *bg; +#endif // MAP_BATTLEGROUND_H +#ifdef MAP_BUYINGSTORE_H /* buyingstore */ +struct buyingstore_interface *buyingstore; +#endif // MAP_BUYINGSTORE_H +#ifdef MAP_CHANNEL_H /* channel */ +struct channel_interface *channel; +#endif // MAP_CHANNEL_H +#ifdef CHAR_CHAR_H /* chr */ +struct char_interface *chr; +#endif // CHAR_CHAR_H +#ifdef MAP_CHAT_H /* chat */ +struct chat_interface *chat; +#endif // MAP_CHAT_H +#ifdef MAP_CHRIF_H /* chrif */ +struct chrif_interface *chrif; +#endif // MAP_CHRIF_H +#ifdef MAP_CLIF_H /* clif */ +struct clif_interface *clif; +#endif // MAP_CLIF_H +#ifdef COMMON_CORE_H /* cmdline */ +struct cmdline_interface *cmdline; +#endif // COMMON_CORE_H +#ifdef COMMON_CONSOLE_H /* console */ +struct console_interface *console; +#endif // COMMON_CONSOLE_H +#ifdef COMMON_CORE_H /* core */ +struct core_interface *core; +#endif // COMMON_CORE_H +#ifdef COMMON_DB_H /* DB */ +struct db_interface *DB; +#endif // COMMON_DB_H +#ifdef MAP_DUEL_H /* duel */ +struct duel_interface *duel; +#endif // MAP_DUEL_H +#ifdef MAP_ELEMENTAL_H /* elemental */ +struct elemental_interface *elemental; +#endif // MAP_ELEMENTAL_H +#ifdef CHAR_GEOIP_H /* geoip */ +struct geoip_interface *geoip; +#endif // CHAR_GEOIP_H +#ifdef MAP_GUILD_H /* guild */ +struct guild_interface *guild; +#endif // MAP_GUILD_H +#ifdef MAP_STORAGE_H /* gstorage */ +struct guild_storage_interface *gstorage; +#endif // MAP_STORAGE_H +#ifdef MAP_HOMUNCULUS_H /* homun */ +struct homunculus_interface *homun; +#endif // MAP_HOMUNCULUS_H +#ifdef MAP_INSTANCE_H /* instance */ +struct instance_interface *instance; +#endif // MAP_INSTANCE_H +#ifdef CHAR_INT_AUCTION_H /* inter_auction */ +struct inter_auction_interface *inter_auction; +#endif // CHAR_INT_AUCTION_H +#ifdef CHAR_INT_ELEMENTAL_H /* inter_elemental */ +struct inter_elemental_interface *inter_elemental; +#endif // CHAR_INT_ELEMENTAL_H +#ifdef CHAR_INT_GUILD_H /* inter_guild */ +struct inter_guild_interface *inter_guild; +#endif // CHAR_INT_GUILD_H +#ifdef CHAR_INT_HOMUN_H /* inter_homunculus */ +struct inter_homunculus_interface *inter_homunculus; +#endif // CHAR_INT_HOMUN_H +#ifdef CHAR_INTER_H /* inter */ +struct inter_interface *inter; +#endif // CHAR_INTER_H +#ifdef CHAR_INT_MAIL_H /* inter_mail */ +struct inter_mail_interface *inter_mail; +#endif // CHAR_INT_MAIL_H +#ifdef CHAR_INT_MERCENARY_H /* inter_mercenary */ +struct inter_mercenary_interface *inter_mercenary; +#endif // CHAR_INT_MERCENARY_H +#ifdef CHAR_INT_PARTY_H /* inter_party */ +struct inter_party_interface *inter_party; +#endif // CHAR_INT_PARTY_H +#ifdef CHAR_INT_PET_H /* inter_pet */ +struct inter_pet_interface *inter_pet; +#endif // CHAR_INT_PET_H +#ifdef CHAR_INT_QUEST_H /* inter_quest */ +struct inter_quest_interface *inter_quest; +#endif // CHAR_INT_QUEST_H +#ifdef CHAR_INT_STORAGE_H /* inter_storage */ +struct inter_storage_interface *inter_storage; +#endif // CHAR_INT_STORAGE_H +#ifdef MAP_INTIF_H /* intif */ +struct intif_interface *intif; +#endif // MAP_INTIF_H +#ifdef MAP_IRC_BOT_H /* ircbot */ +struct irc_bot_interface *ircbot; +#endif // MAP_IRC_BOT_H +#ifdef MAP_ITEMDB_H /* itemdb */ +struct itemdb_interface *itemdb; +#endif // MAP_ITEMDB_H +#ifdef COMMON_CONF_H /* libconfig */ +struct libconfig_interface *libconfig; +#endif // COMMON_CONF_H +#ifdef MAP_LOG_H /* logs */ +struct log_interface *logs; +#endif // MAP_LOG_H +#ifdef LOGIN_LOGIN_H /* login */ +struct login_interface *login; +#endif // LOGIN_LOGIN_H +#ifdef CHAR_LOGINIF_H /* loginif */ +struct loginif_interface *loginif; +#endif // CHAR_LOGINIF_H +#ifdef MAP_MAIL_H /* mail */ +struct mail_interface *mail; +#endif // MAP_MAIL_H +#ifdef COMMON_MALLOC_H /* iMalloc */ +struct malloc_interface *iMalloc; +#endif // COMMON_MALLOC_H +#ifdef MAP_MAP_H /* map */ +struct map_interface *map; +#endif // MAP_MAP_H +#ifdef CHAR_MAPIF_H /* mapif */ +struct mapif_interface *mapif; +#endif // CHAR_MAPIF_H +#ifdef COMMON_MAPINDEX_H /* mapindex */ +struct mapindex_interface *mapindex; +#endif // COMMON_MAPINDEX_H +#ifdef MAP_MAP_H /* mapit */ +struct mapit_interface *mapit; +#endif // MAP_MAP_H +#ifdef MAP_MAPREG_H /* mapreg */ +struct mapreg_interface *mapreg; +#endif // MAP_MAPREG_H +#ifdef MAP_MERCENARY_H /* mercenary */ +struct mercenary_interface *mercenary; +#endif // MAP_MERCENARY_H +#ifdef MAP_MOB_H /* mob */ +struct mob_interface *mob; +#endif // MAP_MOB_H +#ifdef MAP_NPC_H /* npc */ +struct npc_interface *npc; +#endif // MAP_NPC_H +#ifdef COMMON_NULLPO_H /* nullpo */ +struct nullpo_interface *nullpo; +#endif // COMMON_NULLPO_H +#ifdef MAP_PARTY_H /* party */ +struct party_interface *party; +#endif // MAP_PARTY_H +#ifdef MAP_PATH_H /* path */ +struct path_interface *path; +#endif // MAP_PATH_H +#ifdef MAP_PC_GROUPS_H /* pcg */ +struct pc_groups_interface *pcg; +#endif // MAP_PC_GROUPS_H +#ifdef MAP_PC_H /* pc */ +struct pc_interface *pc; +#endif // MAP_PC_H +#ifdef MAP_PET_H /* pet */ +struct pet_interface *pet; +#endif // MAP_PET_H +#ifdef CHAR_PINCODE_H /* pincode */ +struct pincode_interface *pincode; +#endif // CHAR_PINCODE_H +#ifdef MAP_QUEST_H /* quest */ +struct quest_interface *quest; +#endif // MAP_QUEST_H +#ifdef MAP_SCRIPT_H /* script */ +struct script_interface *script; +#endif // MAP_SCRIPT_H +#ifdef MAP_SEARCHSTORE_H /* searchstore */ +struct searchstore_interface *searchstore; +#endif // MAP_SEARCHSTORE_H +#ifdef COMMON_SHOWMSG_H /* showmsg */ +struct showmsg_interface *showmsg; +#endif // COMMON_SHOWMSG_H +#ifdef MAP_SKILL_H /* skill */ +struct skill_interface *skill; +#endif // MAP_SKILL_H +#ifdef COMMON_SOCKET_H /* sockt */ +struct socket_interface *sockt; +#endif // COMMON_SOCKET_H +#ifdef COMMON_SQL_H /* SQL */ +struct sql_interface *SQL; +#endif // COMMON_SQL_H +#ifdef MAP_STATUS_H /* status */ +struct status_interface *status; +#endif // MAP_STATUS_H +#ifdef MAP_STORAGE_H /* storage */ +struct storage_interface *storage; +#endif // MAP_STORAGE_H +#ifdef COMMON_STRLIB_H /* StrBuf */ +struct stringbuf_interface *StrBuf; +#endif // COMMON_STRLIB_H +#ifdef COMMON_STRLIB_H /* strlib */ +struct strlib_interface *strlib; +#endif // COMMON_STRLIB_H +#ifdef COMMON_STRLIB_H /* sv */ +struct sv_interface *sv; +#endif // COMMON_STRLIB_H +#ifdef COMMON_SYSINFO_H /* sysinfo */ +struct sysinfo_interface *sysinfo; +#endif // COMMON_SYSINFO_H +#ifdef COMMON_TIMER_H /* timer */ +struct timer_interface *timer; +#endif // COMMON_TIMER_H +#ifdef MAP_TRADE_H /* trade */ +struct trade_interface *trade; +#endif // MAP_TRADE_H +#ifdef MAP_UNIT_H /* unit */ +struct unit_interface *unit; +#endif // MAP_UNIT_H +#ifdef MAP_VENDING_H /* vending */ +struct vending_interface *vending; +#endif // MAP_VENDING_H +#endif // ! HERCULES_CORE + +HPExport const char *HPM_shared_symbols(int server_type) +{ +#ifdef COMMON_UTILS_H /* HCache */ +if ((server_type&(SERVER_TYPE_ALL)) && !HPM_SYMBOL("HCache", HCache)) return "HCache"; +#endif // COMMON_UTILS_H +#ifdef MAP_ATCOMMAND_H /* atcommand */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("atcommand", atcommand)) return "atcommand"; +#endif // MAP_ATCOMMAND_H +#ifdef MAP_BATTLE_H /* battle */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("battle", battle)) return "battle"; +#endif // MAP_BATTLE_H +#ifdef MAP_BATTLEGROUND_H /* bg */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("battlegrounds", bg)) return "battlegrounds"; +#endif // MAP_BATTLEGROUND_H +#ifdef MAP_BUYINGSTORE_H /* buyingstore */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("buyingstore", buyingstore)) return "buyingstore"; +#endif // MAP_BUYINGSTORE_H +#ifdef MAP_CHANNEL_H /* channel */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("channel", channel)) return "channel"; +#endif // MAP_CHANNEL_H +#ifdef CHAR_CHAR_H /* chr */ +if ((server_type&(SERVER_TYPE_CHAR)) && !HPM_SYMBOL("chr", chr)) return "chr"; +#endif // CHAR_CHAR_H +#ifdef MAP_CHAT_H /* chat */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("chat", chat)) return "chat"; +#endif // MAP_CHAT_H +#ifdef MAP_CHRIF_H /* chrif */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("chrif", chrif)) return "chrif"; +#endif // MAP_CHRIF_H +#ifdef MAP_CLIF_H /* clif */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("clif", clif)) return "clif"; +#endif // MAP_CLIF_H +#ifdef COMMON_CORE_H /* cmdline */ +if ((server_type&(SERVER_TYPE_ALL)) && !HPM_SYMBOL("cmdline", cmdline)) return "cmdline"; +#endif // COMMON_CORE_H +#ifdef COMMON_CONSOLE_H /* console */ +if ((server_type&(SERVER_TYPE_ALL)) && !HPM_SYMBOL("console", console)) return "console"; +#endif // COMMON_CONSOLE_H +#ifdef COMMON_CORE_H /* core */ +if ((server_type&(SERVER_TYPE_ALL)) && !HPM_SYMBOL("core", core)) return "core"; +#endif // COMMON_CORE_H +#ifdef COMMON_DB_H /* DB */ +if ((server_type&(SERVER_TYPE_ALL)) && !HPM_SYMBOL("DB", DB)) return "DB"; +#endif // COMMON_DB_H +#ifdef MAP_DUEL_H /* duel */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("duel", duel)) return "duel"; +#endif // MAP_DUEL_H +#ifdef MAP_ELEMENTAL_H /* elemental */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("elemental", elemental)) return "elemental"; +#endif // MAP_ELEMENTAL_H +#ifdef CHAR_GEOIP_H /* geoip */ +if ((server_type&(SERVER_TYPE_CHAR)) && !HPM_SYMBOL("geoip", geoip)) return "geoip"; +#endif // CHAR_GEOIP_H +#ifdef MAP_GUILD_H /* guild */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("guild", guild)) return "guild"; +#endif // MAP_GUILD_H +#ifdef MAP_STORAGE_H /* gstorage */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("gstorage", gstorage)) return "gstorage"; +#endif // MAP_STORAGE_H +#ifdef MAP_HOMUNCULUS_H /* homun */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("homun", homun)) return "homun"; +#endif // MAP_HOMUNCULUS_H +#ifdef MAP_INSTANCE_H /* instance */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("instance", instance)) return "instance"; +#endif // MAP_INSTANCE_H +#ifdef CHAR_INT_AUCTION_H /* inter_auction */ +if ((server_type&(SERVER_TYPE_CHAR)) && !HPM_SYMBOL("inter_auction", inter_auction)) return "inter_auction"; +#endif // CHAR_INT_AUCTION_H +#ifdef CHAR_INT_ELEMENTAL_H /* inter_elemental */ +if ((server_type&(SERVER_TYPE_CHAR)) && !HPM_SYMBOL("inter_elemental", inter_elemental)) return "inter_elemental"; +#endif // CHAR_INT_ELEMENTAL_H +#ifdef CHAR_INT_GUILD_H /* inter_guild */ +if ((server_type&(SERVER_TYPE_CHAR)) && !HPM_SYMBOL("inter_guild", inter_guild)) return "inter_guild"; +#endif // CHAR_INT_GUILD_H +#ifdef CHAR_INT_HOMUN_H /* inter_homunculus */ +if ((server_type&(SERVER_TYPE_CHAR)) && !HPM_SYMBOL("inter_homunculus", inter_homunculus)) return "inter_homunculus"; +#endif // CHAR_INT_HOMUN_H +#ifdef CHAR_INTER_H /* inter */ +if ((server_type&(SERVER_TYPE_CHAR)) && !HPM_SYMBOL("inter", inter)) return "inter"; +#endif // CHAR_INTER_H +#ifdef CHAR_INT_MAIL_H /* inter_mail */ +if ((server_type&(SERVER_TYPE_CHAR)) && !HPM_SYMBOL("inter_mail", inter_mail)) return "inter_mail"; +#endif // CHAR_INT_MAIL_H +#ifdef CHAR_INT_MERCENARY_H /* inter_mercenary */ +if ((server_type&(SERVER_TYPE_CHAR)) && !HPM_SYMBOL("inter_mercenary", inter_mercenary)) return "inter_mercenary"; +#endif // CHAR_INT_MERCENARY_H +#ifdef CHAR_INT_PARTY_H /* inter_party */ +if ((server_type&(SERVER_TYPE_CHAR)) && !HPM_SYMBOL("inter_party", inter_party)) return "inter_party"; +#endif // CHAR_INT_PARTY_H +#ifdef CHAR_INT_PET_H /* inter_pet */ +if ((server_type&(SERVER_TYPE_CHAR)) && !HPM_SYMBOL("inter_pet", inter_pet)) return "inter_pet"; +#endif // CHAR_INT_PET_H +#ifdef CHAR_INT_QUEST_H /* inter_quest */ +if ((server_type&(SERVER_TYPE_CHAR)) && !HPM_SYMBOL("inter_quest", inter_quest)) return "inter_quest"; +#endif // CHAR_INT_QUEST_H +#ifdef CHAR_INT_STORAGE_H /* inter_storage */ +if ((server_type&(SERVER_TYPE_CHAR)) && !HPM_SYMBOL("inter_storage", inter_storage)) return "inter_storage"; +#endif // CHAR_INT_STORAGE_H +#ifdef MAP_INTIF_H /* intif */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("intif", intif)) return "intif"; +#endif // MAP_INTIF_H +#ifdef MAP_IRC_BOT_H /* ircbot */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("ircbot", ircbot)) return "ircbot"; +#endif // MAP_IRC_BOT_H +#ifdef MAP_ITEMDB_H /* itemdb */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("itemdb", itemdb)) return "itemdb"; +#endif // MAP_ITEMDB_H +#ifdef COMMON_CONF_H /* libconfig */ +if ((server_type&(SERVER_TYPE_ALL)) && !HPM_SYMBOL("libconfig", libconfig)) return "libconfig"; +#endif // COMMON_CONF_H +#ifdef MAP_LOG_H /* logs */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("logs", logs)) return "logs"; +#endif // MAP_LOG_H +#ifdef LOGIN_LOGIN_H /* login */ +if ((server_type&(SERVER_TYPE_LOGIN)) && !HPM_SYMBOL("login", login)) return "login"; +#endif // LOGIN_LOGIN_H +#ifdef CHAR_LOGINIF_H /* loginif */ +if ((server_type&(SERVER_TYPE_CHAR)) && !HPM_SYMBOL("loginif", loginif)) return "loginif"; +#endif // CHAR_LOGINIF_H +#ifdef MAP_MAIL_H /* mail */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("mail", mail)) return "mail"; +#endif // MAP_MAIL_H +#ifdef COMMON_MALLOC_H /* iMalloc */ +if ((server_type&(SERVER_TYPE_ALL)) && !HPM_SYMBOL("iMalloc", iMalloc)) return "iMalloc"; +#endif // COMMON_MALLOC_H +#ifdef MAP_MAP_H /* map */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("map", map)) return "map"; +#endif // MAP_MAP_H +#ifdef CHAR_MAPIF_H /* mapif */ +if ((server_type&(SERVER_TYPE_CHAR)) && !HPM_SYMBOL("mapif", mapif)) return "mapif"; +#endif // CHAR_MAPIF_H +#ifdef COMMON_MAPINDEX_H /* mapindex */ +if ((server_type&(SERVER_TYPE_MAP|SERVER_TYPE_CHAR)) && !HPM_SYMBOL("mapindex", mapindex)) return "mapindex"; +#endif // COMMON_MAPINDEX_H +#ifdef MAP_MAP_H /* mapit */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("mapit", mapit)) return "mapit"; +#endif // MAP_MAP_H +#ifdef MAP_MAPREG_H /* mapreg */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("mapreg", mapreg)) return "mapreg"; +#endif // MAP_MAPREG_H +#ifdef MAP_MERCENARY_H /* mercenary */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("mercenary", mercenary)) return "mercenary"; +#endif // MAP_MERCENARY_H +#ifdef MAP_MOB_H /* mob */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("mob", mob)) return "mob"; +#endif // MAP_MOB_H +#ifdef MAP_NPC_H /* npc */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("npc", npc)) return "npc"; +#endif // MAP_NPC_H +#ifdef COMMON_NULLPO_H /* nullpo */ +if ((server_type&(SERVER_TYPE_ALL)) && !HPM_SYMBOL("nullpo", nullpo)) return "nullpo"; +#endif // COMMON_NULLPO_H +#ifdef MAP_PARTY_H /* party */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("party", party)) return "party"; +#endif // MAP_PARTY_H +#ifdef MAP_PATH_H /* path */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("path", path)) return "path"; +#endif // MAP_PATH_H +#ifdef MAP_PC_GROUPS_H /* pcg */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("pc_groups", pcg)) return "pc_groups"; +#endif // MAP_PC_GROUPS_H +#ifdef MAP_PC_H /* pc */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("pc", pc)) return "pc"; +#endif // MAP_PC_H +#ifdef MAP_PET_H /* pet */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("pet", pet)) return "pet"; +#endif // MAP_PET_H +#ifdef CHAR_PINCODE_H /* pincode */ +if ((server_type&(SERVER_TYPE_CHAR)) && !HPM_SYMBOL("pincode", pincode)) return "pincode"; +#endif // CHAR_PINCODE_H +#ifdef MAP_QUEST_H /* quest */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("quest", quest)) return "quest"; +#endif // MAP_QUEST_H +#ifdef MAP_SCRIPT_H /* script */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("script", script)) return "script"; +#endif // MAP_SCRIPT_H +#ifdef MAP_SEARCHSTORE_H /* searchstore */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("searchstore", searchstore)) return "searchstore"; +#endif // MAP_SEARCHSTORE_H +#ifdef COMMON_SHOWMSG_H /* showmsg */ +if ((server_type&(SERVER_TYPE_ALL)) && !HPM_SYMBOL("showmsg", showmsg)) return "showmsg"; +#endif // COMMON_SHOWMSG_H +#ifdef MAP_SKILL_H /* skill */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("skill", skill)) return "skill"; +#endif // MAP_SKILL_H +#ifdef COMMON_SOCKET_H /* sockt */ +if ((server_type&(SERVER_TYPE_ALL)) && !HPM_SYMBOL("sockt", sockt)) return "sockt"; +#endif // COMMON_SOCKET_H +#ifdef COMMON_SQL_H /* SQL */ +if ((server_type&(SERVER_TYPE_ALL)) && !HPM_SYMBOL("SQL", SQL)) return "SQL"; +#endif // COMMON_SQL_H +#ifdef MAP_STATUS_H /* status */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("status", status)) return "status"; +#endif // MAP_STATUS_H +#ifdef MAP_STORAGE_H /* storage */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("storage", storage)) return "storage"; +#endif // MAP_STORAGE_H +#ifdef COMMON_STRLIB_H /* StrBuf */ +if ((server_type&(SERVER_TYPE_ALL)) && !HPM_SYMBOL("StrBuf", StrBuf)) return "StrBuf"; +#endif // COMMON_STRLIB_H +#ifdef COMMON_STRLIB_H /* strlib */ +if ((server_type&(SERVER_TYPE_ALL)) && !HPM_SYMBOL("strlib", strlib)) return "strlib"; +#endif // COMMON_STRLIB_H +#ifdef COMMON_STRLIB_H /* sv */ +if ((server_type&(SERVER_TYPE_ALL)) && !HPM_SYMBOL("sv", sv)) return "sv"; +#endif // COMMON_STRLIB_H +#ifdef COMMON_SYSINFO_H /* sysinfo */ +if ((server_type&(SERVER_TYPE_ALL)) && !HPM_SYMBOL("sysinfo", sysinfo)) return "sysinfo"; +#endif // COMMON_SYSINFO_H +#ifdef COMMON_TIMER_H /* timer */ +if ((server_type&(SERVER_TYPE_ALL)) && !HPM_SYMBOL("timer", timer)) return "timer"; +#endif // COMMON_TIMER_H +#ifdef MAP_TRADE_H /* trade */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("trade", trade)) return "trade"; +#endif // MAP_TRADE_H +#ifdef MAP_UNIT_H /* unit */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("unit", unit)) return "unit"; +#endif // MAP_UNIT_H +#ifdef MAP_VENDING_H /* vending */ +if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("vending", vending)) return "vending"; +#endif // MAP_VENDING_H + return NULL; +} diff --git a/src/common/HPMi.h b/src/common/HPMi.h index 10cf4fd9f..e03f52e3b 100644 --- a/src/common/HPMi.h +++ b/src/common/HPMi.h @@ -4,26 +4,18 @@ #ifndef COMMON_HPMI_H #define COMMON_HPMI_H -#include "../common/cbasetypes.h" -#include "../common/console.h" -#include "../common/core.h" -#include "../common/sql.h" +#include "common/hercules.h" +#include "common/console.h" +#include "common/core.h" +#include "common/showmsg.h" +#include "common/sql.h" struct script_state; struct AtCommandInfo; struct socket_data; struct map_session_data; -#ifdef WIN32 - #define HPExport __declspec(dllexport) -#else - #define HPExport -#endif - -/* after */ -#include "../common/showmsg.h" - -#define HPM_VERSION "1.0" +#define HPM_VERSION "1.1" #define HPM_ADDCONF_LENGTH 40 struct hplugin_info { @@ -39,11 +31,6 @@ struct s_HPMDataCheck { int type; }; -HPExport void *(*import_symbol) (char *name, unsigned int pID); -HPExport Sql *mysql_handle; - -#define GET_SYMBOL(n) import_symbol((n),HPMi->pid) - #define SERVER_TYPE_ALL (SERVER_TYPE_LOGIN|SERVER_TYPE_CHAR|SERVER_TYPE_MAP) enum hp_event_types { @@ -84,11 +71,12 @@ enum HPluginDataTypes { HPDT_MOBDATA, HPDT_ITEMDATA, HPDT_BGDATA, + HPDT_AUTOTRADE_VEND, }; /* used in macros and conf storage */ enum HPluginConfType { - HPCT_BATTLE, /* battle-conf (map-server */ + HPCT_BATTLE, /* battle-conf (map-server) */ HPCT_LOGIN, /* login-server.conf (login-server) */ HPCT_CHAR, /* char-server.conf (char-server) */ HPCT_CHAR_INTER, /* inter-server.conf (char-server) */ @@ -151,34 +139,42 @@ enum HPluginConfType { #define addToBGDATA(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_BGDATA,HPMi->pid,(ptr),(data),(index),(autofree))) #define getFromBGDATA(ptr,index) (HPMi->getFromHPData(HPDT_BGDATA,HPMi->pid,(ptr),(index))) #define removeFromBGDATA(ptr,index) (HPMi->removeFromHPData(HPDT_BGDATA,HPMi->pid,(ptr),(index))) - -/* HPMi->addCommand */ -#define addAtcommand(cname,funcname) \ - if ( HPMi->addCommand != NULL ) { \ +/* autotrade_vending */ +#define addToATVEND(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_AUTOTRADE_VEND,HPMi->pid,(ptr),(data),(index),(autofree))) +#define getFromATVEND(ptr,index) (HPMi->getFromHPData(HPDT_AUTOTRADE_VEND,HPMi->pid,(ptr),(index))) +#define removeFromATVEND(ptr,index) (HPMi->removeFromHPData(HPDT_AUTOTRADE_VEND,HPMi->pid,(ptr),(index))) + +/// HPMi->addCommand +#define addAtcommand(cname,funcname) do { \ + if (HPMi->addCommand != NULL) { \ HPMi->addCommand(cname,atcommand_ ## funcname); \ } else { \ ShowWarning("HPM (%s):addAtcommand(\"%s\",%s) failed, addCommand sub is NULL!\n",pinfo.name,cname,# funcname);\ - } -/* HPMi->addScript */ -#define addScriptCommand(cname,scinfo,funcname) \ - if ( HPMi->addScript != NULL ) { \ + } \ +} while(0) +/// HPMi->addScript +#define addScriptCommand(cname,scinfo,funcname) do { \ + if (HPMi->addScript != NULL) { \ HPMi->addScript(cname,scinfo,buildin_ ## funcname, false); \ } else { \ ShowWarning("HPM (%s):addScriptCommand(\"%s\",\"%s\",%s) failed, addScript sub is NULL!\n",pinfo.name,cname,scinfo,# funcname);\ - } -#define addScriptCommandDeprecated(cname,scinfo,funcname) \ - if ( HPMi->addScript != NULL ) { \ + } \ +} while(0) +#define addScriptCommandDeprecated(cname,scinfo,funcname) do { \ + if (HPMi->addScript != NULL) { \ HPMi->addScript(cname,scinfo,buildin_ ## funcname, true); \ } else { \ ShowWarning("HPM (%s):addScriptCommandDeprecated(\"%s\",\"%s\",%s) failed, addScript sub is NULL!\n",pinfo.name,cname,scinfo,# funcname);\ - } -/* HPMi->addCPCommand */ -#define addCPCommand(cname,funcname) \ - if ( HPMi->addCPCommand != NULL ) { \ + } \ +} while(0) +/// HPMi->addCPCommand +#define addCPCommand(cname,funcname) do { \ + if (HPMi->addCPCommand != NULL) { \ HPMi->addCPCommand(cname,console_parse_ ## funcname); \ } else { \ ShowWarning("HPM (%s):addCPCommand(\"%s\",%s) failed, addCPCommand sub is NULL!\n",pinfo.name,cname,# funcname);\ - } + } \ +} while(0) /* HPMi->addPacket */ #define addPacket(cmd,len,receive,point) HPMi->addPacket(cmd,len,receive,point,HPMi->pid) /* HPMi->addBattleConf */ @@ -200,7 +196,7 @@ enum HPluginConfType { #define addGroupPermission(pcgname,maskptr) HPMi->addPCGPermission(HPMi->pid,pcgname,&maskptr) /* Hercules Plugin Mananger Include Interface */ -HPExport struct HPMi_interface { +struct HPMi_interface { /* */ unsigned int pid; /* */ @@ -224,10 +220,17 @@ HPExport struct HPMi_interface { bool (*addConf) (unsigned int pluginID, enum HPluginConfType type, char *name, void (*func) (const char *val)); /* pc group permission */ void (*addPCGPermission) (unsigned int pluginID, char *name, unsigned int *mask); + + Sql *sql_handle; }; -#ifndef HERCULES_CORE +#ifdef HERCULES_CORE +#define HPM_SYMBOL(n, s) (HPM->share((s), (n)), true) +#else // ! HERCULES_CORE HPExport struct HPMi_interface HPMi_s; HPExport struct HPMi_interface *HPMi; -#endif +HPExport void *(*import_symbol) (char *name, unsigned int pID); +#define HPM_SYMBOL(n, s) ((s) = import_symbol((n),HPMi->pid)) +#endif // !HERCULES_CORE + #endif /* COMMON_HPMI_H */ diff --git a/src/common/Makefile.in b/src/common/Makefile.in index 5dfdd35bd..208d3b111 100644 --- a/src/common/Makefile.in +++ b/src/common/Makefile.in @@ -6,17 +6,20 @@ CONFIG_D = ../config CONFIG_H = $(wildcard $(CONFIG_D)/*.h) $(wildcard $(CONFIG_D)/*/*.h) -LIBCONFIG_D = ../../3rdparty/libconfig +COMMON_INCLUDE = -I.. + +THIRDPARTY_D = ../../3rdparty +THIRDPARTY_INCLUDE = -I$(THIRDPARTY_D) + +LIBCONFIG_D = $(THIRDPARTY_D)/libconfig LIBCONFIG_OBJ = $(addprefix $(LIBCONFIG_D)/, libconfig.o grammar.o scanctx.o \ scanner.o strbuf.o) LIBCONFIG_H = $(addprefix $(LIBCONFIG_D)/, libconfig.h grammar.h parsectx.h \ scanctx.h scanner.h strbuf.h wincompat.h) -LIBCONFIG_INCLUDE = -I$(LIBCONFIG_D) -MT19937AR_D = ../../3rdparty/mt19937ar +MT19937AR_D = $(THIRDPARTY_D)/mt19937ar MT19937AR_OBJ = $(MT19937AR_D)/mt19937ar.o MT19937AR_H = $(MT19937AR_D)/mt19937ar.h -MT19937AR_INCLUDE = -I$(MT19937AR_D) COMMON_SHARED_C = conf.c db.c des.c ers.c grfio.c HPM.c mapindex.c md5calc.c \ mutex.c nullpo.c random.c showmsg.c strlib.c sysinfo.c \ @@ -29,9 +32,9 @@ COMMON_MINI_OBJ = $(addprefix obj_all/, $(COMMON_SHARED_OBJ) \ miniconsole.o minicore.o minimalloc.o minisocket.o) COMMON_C += console.c core.c malloc.c socket.c COMMON_H = atomic.h cbasetypes.h conf.h console.h core.h db.h des.h ers.h \ - grfio.h HPM.h HPMi.h malloc.h mapindex.h md5calc.h mmo.h mutex.h \ - nullpo.h random.h showmsg.h socket.h spinlock.h sql.h strlib.h \ - sysinfo.h thread.h timer.h utils.h winapi.h + grfio.h hercules.h HPM.h HPMi.h malloc.h mapindex.h md5calc.h \ + mmo.h mutex.h nullpo.h random.h showmsg.h socket.h spinlock.h \ + sql.h strlib.h sysinfo.h thread.h timer.h utils.h winapi.h COMMON_SQL_OBJ = obj_sql/sql.o COMMON_SQL_H = sql.h @@ -116,15 +119,15 @@ obj_all/sysinfo.o: sysinfo.c $(COMMON_H) $(CONFIG_H) $(MT19937AR_H) $(LIBCONFIG_ obj_all/%.o: %.c $(COMMON_H) $(CONFIG_H) $(MT19937AR_H) $(LIBCONFIG_H) | $(SYSINFO_INC) obj_all @echo " CC $<" - @$(CC) @CFLAGS@ @DEFS@ $(MT19937AR_INCLUDE) $(LIBCONFIG_INCLUDE) @CPPFLAGS@ -c $(OUTPUT_OPTION) $< + @$(CC) @CFLAGS@ @DEFS@ $(COMMON_INCLUDE) $(THIRDPARTY_INCLUDE) @CPPFLAGS@ -c $(OUTPUT_OPTION) $< obj_all/mini%.o: %.c $(COMMON_H) $(CONFIG_H) $(MT19937AR_H) $(LIBCONFIG_H) | $(SYSINFO_INC) obj_all @echo " CC $<" - @$(CC) @CFLAGS@ @DEFS@ $(MT19937AR_INCLUDE) $(LIBCONFIG_INCLUDE) -DMINICORE @CPPFLAGS@ -c $(OUTPUT_OPTION) $< + @$(CC) @CFLAGS@ @DEFS@ $(COMMON_INCLUDE) $(THIRDPARTY_INCLUDE) -DMINICORE @CPPFLAGS@ -c $(OUTPUT_OPTION) $< obj_sql/%.o: %.c $(COMMON_H) $(COMMON_SQL_H) $(CONFIG_H) $(LIBCONFIG_H) | $(SYSINFO_INC) obj_sql @echo " CC $<" - @$(CC) @CFLAGS@ @DEFS@ $(LIBCONFIG_INCLUDE) @MYSQL_CFLAGS@ @CPPFLAGS@ -c $(OUTPUT_OPTION) $< + @$(CC) @CFLAGS@ @DEFS@ $(COMMON_INCLUDE) $(THIRDPARTY_INCLUDE) @MYSQL_CFLAGS@ @CPPFLAGS@ -c $(OUTPUT_OPTION) $< # missing object files $(MT19937AR_OBJ): diff --git a/src/common/atomic.h b/src/common/atomic.h index a42dfad1c..1bb859b29 100644 --- a/src/common/atomic.h +++ b/src/common/atomic.h @@ -14,10 +14,10 @@ // // our Abstraction is fully API-Compatible to Microsoft's implementation @ NT5.0+ // -#include "../common/cbasetypes.h" +#include "common/cbasetypes.h" #if defined(_MSC_VER) -#include "../common/winapi.h" +#include "common/winapi.h" // This checks if C/C++ Compiler Version is 18.00 #if _MSC_VER < 1800 @@ -40,7 +40,6 @@ forceinline int64 InterlockedCompareExchange64(volatile int64 *dest, int64 exch, } } - forceinline volatile int64 InterlockedIncrement64(volatile int64 *addend){ __int64 old; do{ @@ -50,8 +49,6 @@ forceinline volatile int64 InterlockedIncrement64(volatile int64 *addend){ return (old + 1); } - - forceinline volatile int64 InterlockedDecrement64(volatile int64 *addend){ __int64 old; @@ -97,53 +94,42 @@ static forceinline int64 InterlockedExchangeAdd64(volatile int64 *addend, int64 return __sync_fetch_and_add(addend, increment); }//end: InterlockedExchangeAdd64() - static forceinline int32 InterlockedExchangeAdd(volatile int32 *addend, int32 increment){ return __sync_fetch_and_add(addend, increment); }//end: InterlockedExchangeAdd() - static forceinline int64 InterlockedIncrement64(volatile int64 *addend){ return __sync_add_and_fetch(addend, 1); }//end: InterlockedIncrement64() - static forceinline int32 InterlockedIncrement(volatile int32 *addend){ return __sync_add_and_fetch(addend, 1); }//end: InterlockedIncrement() - static forceinline int64 InterlockedDecrement64(volatile int64 *addend){ return __sync_sub_and_fetch(addend, 1); }//end: InterlockedDecrement64() - static forceinline int32 InterlockedDecrement(volatile int32 *addend){ return __sync_sub_and_fetch(addend, 1); }//end: InterlockedDecrement() - static forceinline int64 InterlockedCompareExchange64(volatile int64 *dest, int64 exch, int64 cmp){ return __sync_val_compare_and_swap(dest, cmp, exch); }//end: InterlockedCompareExchange64() - static forceinline int32 InterlockedCompareExchange(volatile int32 *dest, int32 exch, int32 cmp){ return __sync_val_compare_and_swap(dest, cmp, exch); }//end: InterlockedCompareExchnage() - static forceinline int64 InterlockedExchange64(volatile int64 *target, int64 val){ return __sync_lock_test_and_set(target, val); }//end: InterlockedExchange64() - static forceinline int32 InterlockedExchange(volatile int32 *target, int32 val){ return __sync_lock_test_and_set(target, val); }//end: InterlockedExchange() - #endif //endif compiler decision - #endif /* COMMON_ATOMIC_H */ diff --git a/src/common/cbasetypes.h b/src/common/cbasetypes.h index 3ff0db795..575428f96 100644 --- a/src/common/cbasetypes.h +++ b/src/common/cbasetypes.h @@ -97,6 +97,7 @@ #include <inttypes.h> #include <stdint.h> #include <limits.h> +#include <time.h> // temporary fix for bugreport:4961 (unintended conversion from signed to unsigned) // (-20 >= UCHAR_MAX) returns true @@ -239,7 +240,9 @@ typedef uintptr_t uintptr; #define strcasecmp stricmp #define strncasecmp strnicmp #define strncmpi strnicmp +#if defined(__BORLANDC__) || _MSC_VER < 1900 #define snprintf _snprintf +#endif #if defined(_MSC_VER) && _MSC_VER < 1400 #define vsnprintf _vsnprintf #endif @@ -419,4 +422,10 @@ typedef char bool; #define h64BPTRSIZE(y) (y) #endif +/** Support macros for marking blocks to memset to 0 */ +#define BEGIN_ZEROED_BLOCK int8 HERC__zeroed_block_BEGIN +#define END_ZEROED_BLOCK int8 HERC__zeroed_block_END +#define ZEROED_BLOCK_POS(x) (&(x)->HERC__zeroed_block_BEGIN) +#define ZEROED_BLOCK_SIZE(x) ((char*)&((x)->HERC__zeroed_block_END) - (char*)&((x)->HERC__zeroed_block_BEGIN) + sizeof((x)->HERC__zeroed_block_END)) + #endif /* COMMON_CBASETYPES_H */ diff --git a/src/common/conf.c b/src/common/conf.c index c974decf9..d9367dc9e 100644 --- a/src/common/conf.c +++ b/src/common/conf.c @@ -6,13 +6,13 @@ #include "conf.h" -#include "../../3rdparty/libconfig/libconfig.h" +#include "common/showmsg.h" // ShowError -#include "../common/showmsg.h" // ShowError +#include <libconfig/libconfig.h> /* interface source */ struct libconfig_interface libconfig_s; - +struct libconfig_interface *libconfig; int conf_read_file(config_t *config, const char *config_filename) { libconfig->init(config); diff --git a/src/common/conf.h b/src/common/conf.h index bd97d5c1e..ac97a5427 100644 --- a/src/common/conf.h +++ b/src/common/conf.h @@ -5,9 +5,9 @@ #ifndef COMMON_CONF_H #define COMMON_CONF_H -#include "../common/cbasetypes.h" +#include "common/hercules.h" -#include "../../3rdparty/libconfig/libconfig.h" +#include <libconfig/libconfig.h> /** * The libconfig interface -- specially for plugins, but we enforce it throughout the core to be consistent @@ -74,13 +74,13 @@ struct libconfig_interface { int (*setting_remove_elem) (config_setting_t *parent, unsigned int idx); void (*setting_set_hook) (config_setting_t *setting, void *hook); - config_setting_t * (*lookup) (const config_t *config, const char *path); - config_setting_t * (*lookup_from) (config_setting_t *setting, const char *path); - int (*lookup_int) (const config_t *config, const char *path, int *value); - int (*lookup_int64) (const config_t *config, const char *path, long long *value); - int (*lookup_float) (const config_t *config, const char *path, double *value); - int (*lookup_bool) (const config_t *config, const char *path, int *value); - int (*lookup_string) (const config_t *config, const char *path, const char **value); + config_setting_t * (*lookup) (const config_t *config, const char *filepath); + config_setting_t * (*lookup_from) (config_setting_t *setting, const char *filepath); + int (*lookup_int) (const config_t *config, const char *filepath, int *value); + int (*lookup_int64) (const config_t *config, const char *filepath, long long *value); + int (*lookup_float) (const config_t *config, const char *filepath, double *value); + int (*lookup_bool) (const config_t *config, const char *filepath, int *value); + int (*lookup_string) (const config_t *config, const char *filepath, const char **value); /* those are custom and are from src/common/conf.c */ /* Functions to copy settings from libconfig/contrib */ @@ -91,10 +91,10 @@ struct libconfig_interface { int (*setting_copy) (config_setting_t *parent, const config_setting_t *src); }; -struct libconfig_interface *libconfig; - #ifdef HERCULES_CORE void libconfig_defaults(void); #endif // HERCULES_CORE +HPShared struct libconfig_interface *libconfig; + #endif // COMMON_CONF_H diff --git a/src/common/console.c b/src/common/console.c index 97ca0650e..eb55d7462 100644 --- a/src/common/console.c +++ b/src/common/console.c @@ -4,40 +4,40 @@ #define HERCULES_CORE -#include "../config/core.h" // CONSOLE_INPUT, MAX_CONSOLE_INPUT +#include "config/core.h" // CONSOLE_INPUT, MAX_CONSOLE_INPUT #include "console.h" -#include <stdio.h> -#include <stdlib.h> - -#include "../common/cbasetypes.h" -#include "../common/core.h" -#include "../common/showmsg.h" -#include "../common/sysinfo.h" +#include "common/cbasetypes.h" +#include "common/core.h" +#include "common/showmsg.h" +#include "common/sysinfo.h" #ifndef MINICORE -# include "../common/atomic.h" -# include "../common/ers.h" -# include "../common/malloc.h" -# include "../common/mutex.h" -# include "../common/spinlock.h" -# include "../common/sql.h" -# include "../common/strlib.h" -# include "../common/thread.h" -# include "../common/timer.h" +# include "common/atomic.h" +# include "common/ers.h" +# include "common/malloc.h" +# include "common/mutex.h" +# include "common/spinlock.h" +# include "common/sql.h" +# include "common/strlib.h" +# include "common/thread.h" +# include "common/timer.h" #endif +#include <stdio.h> +#include <stdlib.h> #if !defined(WIN32) # include <sys/time.h> # include <unistd.h> #else -# include "../common/winapi.h" // Console close event handling +# include "common/winapi.h" // Console close event handling # ifdef CONSOLE_INPUT # include <conio.h> /* _kbhit() */ # endif #endif struct console_interface console_s; +struct console_interface *console; #ifdef CONSOLE_INPUT struct console_input_interface console_input_s; @@ -63,7 +63,7 @@ void display_title(void) { ShowMessage(""CL_BG_RED""CL_BT_WHITE" | | | | __/ | | (__| |_| | | __/\\__ \\ "CL_CLL""CL_NORMAL"\n"); ShowMessage(""CL_BG_RED""CL_BT_WHITE" \\_| |_/\\___|_| \\___|\\__,_|_|\\___||___/ "CL_CLL""CL_NORMAL"\n"); ShowMessage(""CL_BG_RED""CL_BT_WHITE" "CL_CLL""CL_NORMAL"\n"); - ShowMessage(""CL_BG_RED""CL_BT_WHITE" http://hercules.ws/board/ "CL_CLL""CL_NORMAL"\n"); + ShowMessage(""CL_BG_RED""CL_BT_WHITE" http://herc.ws/board/ "CL_CLL""CL_NORMAL"\n"); ShowMessage(""CL_BG_RED""CL_BT_WHITE" "CL_CLL""CL_NORMAL"\n"); ShowInfo("Hercules %d-bit for %s\n", sysinfo->is64bit() ? 64 : 32, sysinfo->platform()); @@ -75,12 +75,11 @@ void display_title(void) { ShowInfo("Compile Flags: %s\n", sysinfo->cflags()); } #ifdef CONSOLE_INPUT -#if defined(WIN32) -int console_parse_key_pressed(void) { +int console_parse_key_pressed(void) +{ +#ifdef WIN32 return _kbhit(); -} -#else /* WIN32 */ -int console_parse_key_pressed(void) { +#else // ! WIN32 struct timeval tv; fd_set fds; tv.tv_sec = 0; @@ -92,8 +91,8 @@ int console_parse_key_pressed(void) { select(STDIN_FILENO+1, &fds, NULL, NULL, &tv); return FD_ISSET(STDIN_FILENO, &fds); +#endif // WIN32 } -#endif /* _WIN32 */ /*====================================== * CORE: Console commands @@ -103,7 +102,7 @@ int console_parse_key_pressed(void) { * Stops server **/ CPCMD_C(exit,server) { - runflag = 0; + core->runflag = 0; } /** @@ -159,41 +158,41 @@ CPCMD_C(skip,update) { } /** - * Defines a main category. - * - * Categories can't be used as commands! - * E.G. - * - sql update skip - * 'sql' is the main category - * CP_DEF_C(category) + * Loads console commands list **/ +void console_load_defaults(void) +{ + /** + * Defines a main category. + * + * Categories can't be used as commands! + * E.G. + * - sql update skip + * 'sql' is the main category + * CP_DEF_C(category) + **/ #define CP_DEF_C(x) { #x , NULL , NULL, NULL } -/** - * Defines a sub-category. - * - * Sub-categories can't be used as commands! - * E.G. - * - sql update skip - * 'update' is a sub-category - * CP_DEF_C2(command, category) - **/ + /** + * Defines a sub-category. + * + * Sub-categories can't be used as commands! + * E.G. + * - sql update skip + * 'update' is a sub-category + * CP_DEF_C2(command, category) + **/ #define CP_DEF_C2(x,y) { #x , NULL , #y, NULL } -/** - * Defines a command that is inside a category or sub-category - * CP_DEF_S(command, category/sub-category) - **/ + /** + * Defines a command that is inside a category or sub-category + * CP_DEF_S(command, category/sub-category) + **/ #define CP_DEF_S(x,y) { #x, CPCMD_C_A(x,y), #y, NULL } -/** - * Defines a command that is _not_ inside any category - * CP_DEF_S(command) - **/ + /** + * Defines a command that is _not_ inside any category + * CP_DEF_S(command) + **/ #define CP_DEF(x) { #x , CPCMD_A(x), NULL, NULL } -/** - * Loads console commands list - * See CP_DEF_C, CP_DEF_C2, CP_DEF_S, CP_DEF - **/ -void console_load_defaults(void) { struct { char *name; CParseFunc func; @@ -255,11 +254,12 @@ void console_load_defaults(void) { } } } -} #undef CP_DEF_C #undef CP_DEF_C2 #undef CP_DEF_S #undef CP_DEF +} + void console_parse_create(char *name, CParseFunc func) { unsigned int i; char *tok; diff --git a/src/common/console.h b/src/common/console.h index 3d3c8e9dd..ffb4a165b 100644 --- a/src/common/console.h +++ b/src/common/console.h @@ -4,13 +4,11 @@ #ifndef COMMON_CONSOLE_H #define COMMON_CONSOLE_H -#include "../config/core.h" // MAX_CONSOLE_INPUT - -#include "../common/cbasetypes.h" -#include "../common/mutex.h" -#include "../common/spinlock.h" -#include "../common/sql.h" -#include "../common/thread.h" +#include "common/hercules.h" +#include "common/mutex.h" +#include "common/spinlock.h" +#include "common/sql.h" +#include "common/thread.h" /** * Queue Max @@ -84,10 +82,10 @@ struct console_interface { struct console_input_interface *input; }; -struct console_interface *console; - #ifdef HERCULES_CORE void console_defaults(void); #endif // HERCULES_CORE +HPShared struct console_interface *console; + #endif /* COMMON_CONSOLE_H */ diff --git a/src/common/core.c b/src/common/core.c index 8bf381589..dcc96fa41 100644 --- a/src/common/core.c +++ b/src/common/core.c @@ -4,50 +4,45 @@ #define HERCULES_CORE -#include "../config/core.h" +#include "config/core.h" #include "core.h" -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "../common/cbasetypes.h" -#include "../common/console.h" -#include "../common/malloc.h" -#include "../common/mmo.h" -#include "../common/random.h" -#include "../common/showmsg.h" -#include "../common/strlib.h" -#include "../common/sysinfo.h" -#include "../common/nullpo.h" +#include "common/cbasetypes.h" +#include "common/console.h" +#include "common/db.h" +#include "common/malloc.h" +#include "common/mmo.h" +#include "common/random.h" +#include "common/showmsg.h" +#include "common/strlib.h" +#include "common/sysinfo.h" +#include "common/nullpo.h" #ifndef MINICORE -# include "../common/HPM.h" -# include "../common/conf.h" -# include "../common/db.h" -# include "../common/ers.h" -# include "../common/socket.h" -# include "../common/sql.h" -# include "../common/thread.h" -# include "../common/timer.h" -# include "../common/utils.h" +# include "common/HPM.h" +# include "common/conf.h" +# include "common/ers.h" +# include "common/socket.h" +# include "common/sql.h" +# include "common/thread.h" +# include "common/timer.h" +# include "common/utils.h" #endif #ifndef _WIN32 # include <unistd.h> #else -# include "../common/winapi.h" // Console close event handling +# include "common/winapi.h" // Console close event handling #endif +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> /// Called when a terminate signal is received. void (*shutdown_callback)(void) = NULL; -int runflag = CORE_ST_RUN; -int arg_c = 0; -char **arg_v = NULL; - -char *SERVER_NAME = NULL; +struct core_interface core_s; +struct core_interface *core = &core_s; #ifndef MINICORE // minimalist Core // Added by Gabuzomeu @@ -92,7 +87,7 @@ static BOOL WINAPI console_handler(DWORD c_event) { if( shutdown_callback != NULL ) shutdown_callback(); else - runflag = CORE_ST_STOP;// auto-shutdown + core->runflag = CORE_ST_STOP;// auto-shutdown break; default: return FALSE; @@ -120,7 +115,7 @@ static void sig_proc(int sn) { if( shutdown_callback != NULL ) shutdown_callback(); else - runflag = CORE_ST_STOP;// auto-shutdown + core->runflag = CORE_ST_STOP;// auto-shutdown break; case SIGSEGV: case SIGFPE: @@ -178,6 +173,7 @@ void core_defaults(void) { console_defaults(); strlib_defaults(); malloc_defaults(); + showmsg_defaults(); cmdline_defaults(); #ifndef MINICORE libconfig_defaults(); @@ -210,7 +206,7 @@ const char *cmdline_arg_source(struct CmdlineArgData *arg) { */ bool cmdline_arg_add(unsigned int pluginID, const char *name, char shortname, CmdlineExecFunc func, const char *help, unsigned int options) { struct CmdlineArgData *data = NULL; - + RECREATE(cmdline->args_data, struct CmdlineArgData, ++cmdline->args_data_count); data = &cmdline->args_data[cmdline->args_data_count-1]; data->pluginID = pluginID; @@ -231,7 +227,7 @@ static CMDLINEARG(help) ShowInfo("Usage: %s [options]\n", SERVER_NAME); ShowInfo("\n"); ShowInfo("Options:\n"); - + for (i = 0; i < cmdline->args_data_count; i++) { struct CmdlineArgData *data = &cmdline->args_data[i]; char altname[16], paramnames[256]; @@ -250,7 +246,7 @@ static CMDLINEARG(help) */ static CMDLINEARG(version) { - ShowInfo(CL_GREEN"Website/Forum:"CL_RESET"\thttp://hercules.ws/\n"); + ShowInfo(CL_GREEN"Website/Forum:"CL_RESET"\thttp://herc.ws/\n"); ShowInfo(CL_GREEN"IRC Channel:"CL_RESET"\tirc://irc.rizon.net/#Hercules\n"); ShowInfo("Open "CL_WHITE"readme.txt"CL_RESET" for more information.\n"); return false; @@ -319,7 +315,7 @@ int cmdline_exec(int argc, char **argv, unsigned int options) } if (options&CMDLINE_OPT_SILENT) { if (data->options&CMDLINE_OPT_SILENT) { - msg_silent = 0x7; // silence information and status messages + showmsg->silent = 0x7; // silence information and status messages break; } } else if ((data->options&CMDLINE_OPT_PREINIT) == (options&CMDLINE_OPT_PREINIT)) { @@ -362,6 +358,7 @@ void cmdline_final(void) } struct cmdline_interface cmdline_s; +struct cmdline_interface *cmdline; void cmdline_defaults(void) { @@ -389,22 +386,24 @@ int main (int argc, char **argv) { SERVER_NAME = ++p1; p2 = p1; } - arg_c = argc; - arg_v = argv; + core->arg_c = argc; + core->arg_v = argv; + core->runflag = CORE_ST_RUN; } core_defaults(); iMalloc->init();// needed for Show* in display_title() [FlavioJS] + showmsg->init(); cmdline->init(); cmdline->exec(argc, argv, CMDLINE_OPT_SILENT); iMalloc->init_messages(); // Initialization messages (after buying us some time to suppress them if needed) - + sysinfo->init(); - if (!(msg_silent&0x1)) + if (!(showmsg->silent&0x1)) console->display_title(); usercheck(); @@ -441,7 +440,7 @@ int main (int argc, char **argv) { do_init(argc,argv); // Main runtime cycle - while (runflag != CORE_ST_STOP) { + while (core->runflag != CORE_ST_STOP) { int next = timer->perform(timer->gettick_nocache()); sockt->perform(next); } @@ -460,6 +459,7 @@ int main (int argc, char **argv) { //sysinfo->final(); Called by iMalloc->final() iMalloc->final(); + showmsg->final(); // Should be after iMalloc->final() return retval; } diff --git a/src/common/core.h b/src/common/core.h index 827d345ba..c92bf4fa6 100644 --- a/src/common/core.h +++ b/src/common/core.h @@ -5,9 +5,7 @@ #ifndef COMMON_CORE_H #define COMMON_CORE_H -#include "../common/cbasetypes.h" -#include "../common/db.h" -#include "../common/mmo.h" +#include "common/hercules.h" /* so that developers with --enable-debug can raise signals from any section of the code they'd like */ #ifdef DEBUG @@ -30,27 +28,6 @@ enum E_CORE_ST { CORE_ST_LAST }; -#ifdef HERCULES_CORE -extern int arg_c; -extern char **arg_v; - -/// @see E_CORE_ST -extern int runflag; -extern char *SERVER_NAME; - -enum server_types SERVER_TYPE; - -extern void cmdline_args_init_local(void); -extern int do_init(int,char**); -extern void set_server_type(void); -extern void do_abort(void); -extern int do_final(void); - -/// Called when a terminate signal is received. (Ctrl+C pressed) -/// If NULL, runflag is set to CORE_ST_STOP instead. -extern void (*shutdown_callback)(void); -#endif // HERCULES_CORE - /// Options for command line argument handlers. enum cmdline_options { CMDLINE_OPT_NORMAL = 0x0, ///< No special options. @@ -80,10 +57,30 @@ struct cmdline_interface { const char *(*arg_source) (struct CmdlineArgData *arg); }; -struct cmdline_interface *cmdline; +struct core_interface { + int arg_c; + char **arg_v; + /// @see E_CORE_ST + int runflag; + char *server_name; + enum server_types server_type; + + /// Called when a terminate signal is received. (Ctrl+C pressed) + /// If NULL, runflag is set to CORE_ST_STOP instead. + void (*shutdown_callback)(void); +}; #define CMDLINEARG(x) bool cmdline_arg_ ## x (const char *name, const char *params) +#define SERVER_NAME (core->server_name) +#define SERVER_TYPE (core->server_type) + #ifdef HERCULES_CORE +extern void cmdline_args_init_local(void); +extern int do_init(int,char**); +extern void set_server_type(void); +extern void do_abort(void); +extern int do_final(void); + /// Special plugin ID assigned to the Hercules core #define HPM_PID_CORE ((unsigned int)-1) @@ -93,4 +90,7 @@ struct cmdline_interface *cmdline; void cmdline_defaults(void); #endif // HERCULES_CORE +HPShared struct core_interface *core; +HPShared struct cmdline_interface *cmdline; + #endif /* COMMON_CORE_H */ diff --git a/src/common/db.c b/src/common/db.c index 69e2333a9..4df5c08db 100644 --- a/src/common/db.c +++ b/src/common/db.c @@ -72,16 +72,17 @@ #include "db.h" +#include "common/ers.h" +#include "common/malloc.h" +#include "common/mmo.h" +#include "common/showmsg.h" +#include "common/strlib.h" + #include <stdio.h> #include <stdlib.h> -#include "../common/ers.h" -#include "../common/malloc.h" -#include "../common/mmo.h" -#include "../common/showmsg.h" -#include "../common/strlib.h" - struct db_interface DB_s; +struct db_interface *DB; /*****************************************************************************\ * (1) Private typedefs, enums, structures, defines and global variables of * diff --git a/src/common/db.h b/src/common/db.h index cd61e1543..73d44a755 100644 --- a/src/common/db.h +++ b/src/common/db.h @@ -42,9 +42,9 @@ #ifndef COMMON_DB_H #define COMMON_DB_H -#include <stdarg.h> +#include "common/hercules.h" -#include "../common/cbasetypes.h" +#include <stdarg.h> /*****************************************************************************\ * (1) Section with public typedefs, enums, unions, structures and defines. * @@ -71,10 +71,10 @@ * @see #db_custom_release(DBRelease) */ typedef enum DBRelease { - DB_RELEASE_NOTHING = 0, - DB_RELEASE_KEY = 1, - DB_RELEASE_DATA = 2, - DB_RELEASE_BOTH = 3 + DB_RELEASE_NOTHING = 0x0, + DB_RELEASE_KEY = 0x1, + DB_RELEASE_DATA = 0x2, + DB_RELEASE_BOTH = DB_RELEASE_KEY|DB_RELEASE_DATA, } DBRelease; /** @@ -127,13 +127,13 @@ typedef enum DBType { * @see #db_alloc(const char *,int,DBType,DBOptions,unsigned short) */ typedef enum DBOptions { - DB_OPT_BASE = 0, - DB_OPT_DUP_KEY = 1, - DB_OPT_RELEASE_KEY = 2, - DB_OPT_RELEASE_DATA = 4, - DB_OPT_RELEASE_BOTH = 6, - DB_OPT_ALLOW_NULL_KEY = 8, - DB_OPT_ALLOW_NULL_DATA = 16, + DB_OPT_BASE = 0x00, + DB_OPT_DUP_KEY = 0x01, + DB_OPT_RELEASE_KEY = 0x02, + DB_OPT_RELEASE_DATA = 0x04, + DB_OPT_RELEASE_BOTH = DB_OPT_RELEASE_KEY|DB_OPT_RELEASE_DATA, + DB_OPT_ALLOW_NULL_KEY = 0x08, + DB_OPT_ALLOW_NULL_DATA = 0x10, } DBOptions; /** @@ -269,13 +269,9 @@ typedef uint64 (*DBHasher)(DBKey key, unsigned short maxlen); */ typedef void (*DBReleaser)(DBKey key, DBData data, DBRelease which); - - typedef struct DBIterator DBIterator; typedef struct DBMap DBMap; - - /** * Database iterator. * Supports forward iteration, backward iteration and removing entries from the database. @@ -621,7 +617,6 @@ struct DBMap { #define i64db_get(db,k) ( DB->data2ptr((db)->get((db),DB->i642key(k))) ) #define ui64db_get(db,k) ( DB->data2ptr((db)->get((db),DB->ui642key(k))) ) - // Get int-type data from DBMaps of various key types #define db_iget(db,k) ( DB->data2i((db)->get((db),(k))) ) #define idb_iget(db,k) ( DB->data2i((db)->get((db),DB->i2key(k))) ) @@ -916,9 +911,6 @@ void (*init) (void); void (*final) (void); }; -struct db_interface *DB; - -void db_defaults(void); // Link DB System - From jAthena struct linkdb_node { struct linkdb_node *next; @@ -937,9 +929,11 @@ void* linkdb_erase (struct linkdb_node** head, void *key); void linkdb_final (struct linkdb_node** head); void linkdb_vforeach(struct linkdb_node** head, LinkDBFunc func, va_list ap); void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); -#endif // HERCULES_CORE +void db_defaults(void); +#endif // HERCULES_CORE +HPShared struct db_interface *DB; /// Finds an entry in an array. /// ex: ARR_FIND(0, size, i, list[i] == target); @@ -955,8 +949,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); break; \ }while(0) - - /// Moves an entry of the array. /// Use ARR_MOVERIGHT/ARR_MOVELEFT if __from and __to are direct numbers. /// ex: ARR_MOVE(i, 0, list, int);// move index i to index 0 @@ -980,8 +972,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); } \ }while(0) - - /// Moves an entry of the array to the right. /// ex: ARR_MOVERIGHT(1, 4, list, int);// move index 1 to index 4 /// @@ -997,8 +987,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); memmove((__arr)+(__to), &__backup__, sizeof(__type)); \ }while(0) - - /// Moves an entry of the array to the left. /// ex: ARR_MOVELEFT(3, 0, list, int);// move index 3 to index 0 /// @@ -1014,14 +1002,10 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); memmove((__arr)+(__to), &__backup__, sizeof(__type)); \ }while(0) - - ///////////////////////////////////////////////////////////////////// // Vector library based on defines. (dynamic array) // uses aMalloc, aRealloc, aFree - - /// Declares an anonymous vector struct. /// /// @param __type Type of data @@ -1032,8 +1016,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); __type* _data_; \ } - - /// Declares a named vector struct. /// /// @param __name Structure name @@ -1045,8 +1027,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); __type* _data_; \ } - - /// Declares and initializes an anonymous vector variable. /// /// @param __type Type of data @@ -1054,8 +1034,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); #define VECTOR_VAR(__type,__var) \ VECTOR_DECL(__type) __var = {0,0,NULL} - - /// Declares and initializes a named vector variable. /// /// @param __name Structure name @@ -1063,16 +1041,12 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); #define VECTOR_STRUCT_VAR(__name,__var) \ struct __name __var = {0,0,NULL} - - /// Initializes a vector. /// /// @param __vec Vector #define VECTOR_INIT(__vec) \ memset(&(__vec), 0, sizeof(__vec)) - - /// Returns the internal array of values. /// /// @param __vec Vector @@ -1080,8 +1054,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); #define VECTOR_DATA(__vec) \ ( (__vec)._data_ ) - - /// Returns the length of the vector. /// /// @param __vec Vector @@ -1089,8 +1061,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); #define VECTOR_LENGTH(__vec) \ ( (__vec)._len_ ) - - /// Returns the capacity of the vector. /// /// @param __vec Vector @@ -1098,8 +1068,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); #define VECTOR_CAPACITY(__vec) \ ( (__vec)._max_ ) - - /// Returns the value at the target index. /// Assumes the index exists. /// @@ -1109,8 +1077,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); #define VECTOR_INDEX(__vec,__idx) \ ( VECTOR_DATA(__vec)[__idx] ) - - /// Returns the first value of the vector. /// Assumes the array is not empty. /// @@ -1119,8 +1085,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); #define VECTOR_FIRST(__vec) \ ( VECTOR_INDEX(__vec,0) ) - - /// Returns the last value of the vector. /// Assumes the array is not empty. /// @@ -1129,8 +1093,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); #define VECTOR_LAST(__vec) \ ( VECTOR_INDEX(__vec,VECTOR_LENGTH(__vec)-1) ) - - /// Resizes the vector. /// Excess values are discarded, new positions are zeroed. /// @@ -1159,8 +1121,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); } \ }while(0) - - /// Ensures that the array has the target number of empty positions. /// Increases the capacity in multiples of __step. /// @@ -1176,8 +1136,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); } \ }while(0) - - /// Inserts a zeroed value in the target index. /// Assumes the index is valid and there is enough capacity. /// @@ -1191,8 +1149,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); ++VECTOR_LENGTH(__vec); /* increase length */ \ }while(0) - - /// Inserts a value in the target index. (using the '=' operator) /// Assumes the index is valid and there is enough capacity. /// @@ -1207,8 +1163,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); ++VECTOR_LENGTH(__vec); /* increase length */ \ }while(0) - - /// Inserts a value in the target index. (using memcpy) /// Assumes the index is valid and there is enough capacity. /// @@ -1218,8 +1172,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); #define VECTOR_INSERTCOPY(__vec,__idx,__val) \ VECTOR_INSERTARRAY(__vec,__idx,&(__val),1) - - /// Inserts the values of the array in the target index. (using memcpy) /// Assumes the index is valid and there is enough capacity. /// @@ -1235,8 +1187,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); VECTOR_LENGTH(__vec) += (__n); /* increase length */ \ }while(0) - - /// Inserts a zeroed value in the end of the vector. /// Assumes there is enough capacity. /// @@ -1247,7 +1197,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); ++VECTOR_LENGTH(__vec); /* increase length */ \ }while(0) - /// Inserts a value in the end of the vector. (using the '=' operator) /// Assumes there is enough capacity. /// @@ -1259,8 +1208,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); ++VECTOR_LENGTH(__vec); /* increase length */ \ }while(0) - - /// Inserts a value in the end of the vector. (using memcpy) /// Assumes there is enough capacity. /// @@ -1269,8 +1216,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); #define VECTOR_PUSHCOPY(__vec,__val) \ VECTOR_PUSHARRAY(__vec,&(__val),1) - - /// Inserts the values of the array in the end of the vector. (using memcpy) /// Assumes there is enough capacity. /// @@ -1283,8 +1228,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); VECTOR_LENGTH(__vec) += (__n); /* increase length */ \ }while(0) - - /// Removes and returns the last value of the vector. /// Assumes the array is not empty. /// @@ -1293,8 +1236,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); #define VECTOR_POP(__vec) \ ( VECTOR_INDEX(__vec,--VECTOR_LENGTH(__vec)) ) - - /// Removes the last N values of the vector and returns the value of the last pop. /// Assumes there are enough values. /// @@ -1304,8 +1245,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); #define VECTOR_POPN(__vec,__n) \ ( VECTOR_INDEX(__vec,(VECTOR_LENGTH(__vec)-=(__n))) ) - - /// Removes the target index from the vector. /// Assumes the index is valid and there are enough values. /// @@ -1314,8 +1253,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); #define VECTOR_ERASE(__vec,__idx) \ VECTOR_ERASEN(__vec,__idx,1) - - /// Removes N values from the target index of the vector. /// Assumes the index is valid and there are enough values. /// @@ -1329,8 +1266,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); VECTOR_LENGTH(__vec) -= (__n); /* decrease length */ \ }while(0) - - /// Clears the vector, freeing allocated data. /// /// @param __vec Vector @@ -1344,77 +1279,57 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); } \ }while(0) - - ///////////////////////////////////////////////////////////////////// // Binary heap library based on defines. (uses the vector defines above) // uses aMalloc, aRealloc, aFree // WARNING: BHEAP implementation details affect behaviour of A* pathfinding - - /// Declares an anonymous binary heap struct. /// /// @param __type Type of data #define BHEAP_DECL(__type) VECTOR_DECL(__type) - - /// Declares a named binary heap struct. /// /// @param __name Structure name /// @param __type Type of data #define BHEAP_STRUCT_DECL(__name,__type) VECTOR_STRUCT_DECL(__name,__type) - - /// Declares and initializes an anonymous binary heap variable. /// /// @param __type Type of data /// @param __var Variable name #define BHEAP_VAR(__type,__var) VECTOR_VAR(__type,__var) - - /// Declares and initializes a named binary heap variable. /// /// @param __name Structure name /// @param __var Variable name #define BHEAP_STRUCT_VAR(__name,__var) VECTOR_STRUCT_VAR(__name,__var) - - /// Initializes a heap. /// /// @param __heap Binary heap #define BHEAP_INIT(__heap) VECTOR_INIT(__heap) - - /// Returns the internal array of values. /// /// @param __heap Binary heap /// @return Array of values #define BHEAP_DATA(__heap) VECTOR_DATA(__heap) - - /// Returns the length of the heap. /// /// @param __heap Binary heap /// @return Length #define BHEAP_LENGTH(__heap) VECTOR_LENGTH(__heap) - - /// Returns the capacity of the heap. /// /// @param __heap Binary heap /// @return Capacity #define BHEAP_CAPACITY(__heap) VECTOR_CAPACITY(__heap) - - /// Ensures that the heap has the target number of empty positions. /// Increases the capacity in multiples of __step. /// @@ -1423,8 +1338,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); /// @param __step Increase #define BHEAP_ENSURE(__heap,__n,__step) VECTOR_ENSURE(__heap,__n,__step) - - /// Returns the top value of the heap. /// Assumes the heap is not empty. /// @@ -1432,8 +1345,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); /// @return Value at the top #define BHEAP_PEEK(__heap) VECTOR_INDEX(__heap,0) - - /// Inserts a value in the heap. (using the '=' operator) /// Assumes there is enough capacity. /// @@ -1460,8 +1371,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); } \ }while(0) - - /// See BHEAP_PUSH. Version used by A* implementation, matching client bheap. /// /// @param __heap Binary heap @@ -1475,8 +1384,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); BHEAP_SIFTDOWN(__heap,0,_i_,__topcmp,__swp); \ }while(0) - - /// Removes the top value of the heap. (using the '=' operator) /// Assumes the heap is not empty. /// @@ -1490,8 +1397,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); /// @param __swp Swapper #define BHEAP_POP(__heap,__topcmp,__swp) BHEAP_POPINDEX(__heap,0,__topcmp,__swp) - - /// See BHEAP_POP. Version used by A* implementation, matching client bheap. /// /// @param __heap Binary heap @@ -1505,8 +1410,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); BHEAP_SIFTUP(__heap,0,__topcmp,__swp); \ }while(0) - - /// Removes the target value of the heap. (using the '=' operator) /// Assumes the index exists. /// @@ -1553,8 +1456,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); } \ }while(0) - - /// Follow path up towards (but not all the way to) the root, swapping nodes until finding /// a place where the new item that was placed at __idx fits. /// Only goes as high as __startidx (usually 0). @@ -1577,8 +1478,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); } \ }while(0) - - /// Repeatedly swap the smaller child with parent, after placing a new item at __idx. /// /// @param __heap Binary heap @@ -1607,8 +1506,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); BHEAP_SIFTDOWN(__heap,__idx,_i_,__topcmp,__swp); \ }while(0) - - /// Call this after modifying the item at __idx__ to restore the heap /// /// @param __heap Binary heap @@ -1621,15 +1518,11 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); BHEAP_SIFTUP(__heap,__idx,__topcmp,__swp); \ }while(0) - - /// Clears the binary heap, freeing allocated data. /// /// @param __heap Binary heap #define BHEAP_CLEAR(__heap) VECTOR_CLEAR(__heap) - - /// Generic comparator for a min-heap. (minimum value at top) /// Returns -1 if v1 is smaller, 1 if v2 is smaller, 0 if equal. /// @@ -1638,8 +1531,6 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); /// @return negative if v1 is top, positive if v2 is top, 0 if equal #define BHEAP_MINTOPCMP(v1,v2) ( v1 == v2 ? 0 : v1 < v2 ? -1 : 1 ) - - /// Generic comparator for a max-heap. (maximum value at top) /// Returns -1 if v1 is bigger, 1 if v2 is bigger, 0 if equal. /// @@ -1648,6 +1539,4 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); /// @return negative if v1 is top, positive if v2 is top, 0 if equal #define BHEAP_MAXTOPCMP(v1,v2) ( v1 == v2 ? 0 : v1 > v2 ? -1 : 1 ) - - #endif /* COMMON_DB_H */ diff --git a/src/common/des.c b/src/common/des.c index 89a920bc9..0a702bfdf 100644 --- a/src/common/des.c +++ b/src/common/des.c @@ -5,7 +5,7 @@ #include "des.h" -#include "../common/cbasetypes.h" +#include "common/cbasetypes.h" /// DES (Data Encryption Standard) algorithm, modified version. /// @see http://www.eathena.ws/board/index.php?autocom=bugtracker&showbug=5099. diff --git a/src/common/des.h b/src/common/des.h index 9e6aec4fd..6f54b36f2 100644 --- a/src/common/des.h +++ b/src/common/des.h @@ -3,7 +3,7 @@ #ifndef COMMON_DES_H #define COMMON_DES_H -#include "../common/cbasetypes.h" +#include "common/cbasetypes.h" /// One 64-bit block. typedef struct BIT64 { uint8_t b[8]; } BIT64; diff --git a/src/common/ers.c b/src/common/ers.c index 52cba0fe5..91fc6ccfb 100644 --- a/src/common/ers.c +++ b/src/common/ers.c @@ -44,14 +44,14 @@ #include "ers.h" +#include "common/cbasetypes.h" +#include "common/malloc.h" // CREATE, RECREATE, aMalloc, aFree +#include "common/nullpo.h" +#include "common/showmsg.h" // ShowMessage, ShowError, ShowFatalError, CL_BOLD, CL_NORMAL + #include <stdlib.h> #include <string.h> -#include "../common/cbasetypes.h" -#include "../common/malloc.h" // CREATE, RECREATE, aMalloc, aFree -#include "../common/nullpo.h" -#include "../common/showmsg.h" // ShowMessage, ShowError, ShowFatalError, CL_BOLD, CL_NORMAL - #ifndef DISABLE_ERS #define ERS_BLOCK_ENTRIES 2048 diff --git a/src/common/ers.h b/src/common/ers.h index 85ddfed7a..09290186e 100644 --- a/src/common/ers.h +++ b/src/common/ers.h @@ -40,7 +40,7 @@ #ifndef COMMON_ERS_H #define COMMON_ERS_H -#include "../common/cbasetypes.h" +#include "common/cbasetypes.h" /*****************************************************************************\ * (1) All public parts of the Entry Reusage System. * @@ -71,11 +71,11 @@ #endif /* not ERS_ALIGN_ENTRY */ enum ERSOptions { - ERS_OPT_NONE = 0x0, - ERS_OPT_CLEAR = 0x1,/* silently clears any entries left in the manager upon destruction */ - ERS_OPT_WAIT = 0x2,/* wait for entries to come in order to list! */ - ERS_OPT_FREE_NAME = 0x4,/* name is dynamic memory, and should be freed */ - ERS_OPT_CLEAN = 0x8,/* clears used memory upon ers_free so that its all new to be reused on the next alloc */ + ERS_OPT_NONE = 0x00, + ERS_OPT_CLEAR = 0x01,/* silently clears any entries left in the manager upon destruction */ + ERS_OPT_WAIT = 0x02,/* wait for entries to come in order to list! */ + ERS_OPT_FREE_NAME = 0x04,/* name is dynamic memory, and should be freed */ + ERS_OPT_CLEAN = 0x08,/* clears used memory upon ers_free so that its all new to be reused on the next alloc */ ERS_OPT_FLEX_CHUNK = 0x10,/* signs that it should look for its own cache given it'll have a dynamic chunk size, so that it doesn't affect the other ERS it'd otherwise be sharing */ /* Compound, is used to determine whether it should be looking for a cache of matching options */ diff --git a/src/common/grfio.c b/src/common/grfio.c index e95163569..b59c2b63d 100644 --- a/src/common/grfio.c +++ b/src/common/grfio.c @@ -6,20 +6,19 @@ #include "grfio.h" +#include "common/cbasetypes.h" +#include "common/des.h" +#include "common/malloc.h" +#include "common/nullpo.h" +#include "common/showmsg.h" +#include "common/strlib.h" +#include "common/utils.h" + #include <stdio.h> #include <stdlib.h> -#include <string.h> #include <sys/stat.h> #include <zlib.h> -#include "../common/cbasetypes.h" -#include "../common/des.h" -#include "../common/malloc.h" -#include "../common/nullpo.h" -#include "../common/showmsg.h" -#include "../common/strlib.h" -#include "../common/utils.h" - //---------------------------- // file entry table struct //---------------------------- @@ -36,8 +35,8 @@ typedef struct FILELIST { } FILELIST; #define FILELIST_TYPE_FILE 0x01 // entry is a file -#define FILELIST_TYPE_ENCRYPT_HEADER 0x04 // encryption mode 1 (header DES only) #define FILELIST_TYPE_ENCRYPT_MIXED 0x02 // encryption mode 0 (header DES + periodic DES/shuffle) +#define FILELIST_TYPE_ENCRYPT_HEADER 0x04 // encryption mode 1 (header DES only) //gentry ... > 0 : data read from a grf file (gentry_table[gentry-1]) //gentry ... 0 : data read from a local file (data directory) @@ -48,7 +47,6 @@ typedef struct FILELIST { // (NOTE: probably meant to be used to override grf contents by files in the data directory) //#define GRFIO_LOCAL - // stores info about every loaded file FILELIST* filelist = NULL; int filelist_entrys = 0; @@ -62,14 +60,12 @@ int gentry_maxentry = 0; // the path to the data directory char data_dir[1024] = ""; - // little endian char array to uint conversion static unsigned int getlong(unsigned char* p) { return (p[0] << 0 | p[1] << 8 | p[2] << 16 | p[3] << 24); } - static void NibbleSwap(unsigned char* src, int len) { while( len > 0 ) @@ -80,7 +76,6 @@ static void NibbleSwap(unsigned char* src, int len) } } - /// Substitutes some specific values for others, leaves rest intact. Obfuscation. /// NOTE: Operation is symmetric (calling it twice gives back the original input). static uint8_t grf_substitution(uint8_t in) @@ -143,7 +138,6 @@ static void grf_shuffle_dec(BIT64* src) *src = out; } - static void grf_decode_header(unsigned char* buf, size_t len) { BIT64* p = (BIT64*)buf; @@ -157,7 +151,6 @@ static void grf_decode_header(unsigned char* buf, size_t len) // the rest is plaintext, done. } - static void grf_decode_full(unsigned char* buf, size_t len, int cycle) { BIT64* p = (BIT64*)buf; @@ -196,7 +189,6 @@ static void grf_decode_full(unsigned char* buf, size_t len, int cycle) } } - /// Decodes grf data. /// @param buf data to decode (in-place) /// @param len length of the data @@ -236,7 +228,6 @@ static void grf_decode(unsigned char* buf, size_t len, char entry_type, int entr } } - /****************************************************** *** Zlib Subroutines *** ******************************************************/ @@ -247,14 +238,12 @@ unsigned long grfio_crc32(const unsigned char* buf, unsigned int len) return crc32(crc32(0L, Z_NULL, 0), buf, len); } - /// zlib uncompress int decode_zip(void* dest, unsigned long* destLen, const void* source, unsigned long sourceLen) { return uncompress((Bytef*)dest, destLen, (const Bytef*)source, sourceLen); } - /// zlib compress int encode_zip(void* dest, unsigned long* destLen, const void* source, unsigned long sourceLen) { if( *destLen == 0 ) /* [Ind/Hercules] */ @@ -265,7 +254,6 @@ int encode_zip(void* dest, unsigned long* destLen, const void* source, unsigned return compress((Bytef*)dest, destLen, (const Bytef*)source, sourceLen); } - /*********************************************************** *** File List Subroutines *** ***********************************************************/ @@ -371,12 +359,10 @@ static void filelist_compact(void) } } - /*********************************************************** *** Grfio Subroutines *** ***********************************************************/ - /// Combines are resource path with the data folder location to create local resource path. static void grfio_localpath_create(char* buffer, size_t size, const char* filename) { @@ -400,7 +386,6 @@ static void grfio_localpath_create(char* buffer, size_t size, const char* filena buffer[i] = '/'; } - /// Reads a file into a newly allocated buffer (from grf or data directory). void *grfio_reads(const char *fname, int *size) { @@ -450,7 +435,7 @@ void *grfio_reads(const char *fname, int *size) // Archive[GRF] File Read char *grfname = gentry_table[entry->gentry - 1]; FILE *in = fopen(grfname, "rb"); - + if (in != NULL) { int fsize = entry->srclen_aligned; unsigned char *buf = (unsigned char *)aMalloc(fsize); @@ -497,7 +482,6 @@ void *grfio_reads(const char *fname, int *size) return NULL; } - /// Decodes encrypted filename from a version 01xx grf index. static char* decode_filename(unsigned char* buf, int len) { @@ -509,7 +493,6 @@ static char* decode_filename(unsigned char* buf, int len) return (char*)buf; } - /// Compares file extension against known large file types. /// @return true if the file should undergo full mode 0 decryption, and true otherwise. static bool isFullEncrypt(const char* fname) @@ -526,7 +509,6 @@ static bool isFullEncrypt(const char* fname) return true; } - /// Loads all entries in the specified grf file into the filelist. /// @param gentry index of the grf file name in the gentry_table static int grfio_entryread(const char *grfname, int gentry) @@ -692,7 +674,6 @@ static int grfio_entryread(const char *grfname, int gentry) return 0; // 0:no error } - static bool grfio_parse_restable_row(const char* row) { char w1[256], w2[256]; @@ -734,7 +715,6 @@ static bool grfio_parse_restable_row(const char* row) return false; } - /// Grfio Resource file check. static void grfio_resourcecheck(void) { @@ -786,7 +766,6 @@ static void grfio_resourcecheck(void) } } - /// Reads a grf file and adds it to the list. static int grfio_add(const char* fname) { @@ -803,7 +782,6 @@ static int grfio_add(const char* fname) return grfio_entryread(fname, gentry_entrys - 1); } - /// Finalizes grfio. void grfio_final(void) { @@ -830,7 +808,6 @@ void grfio_final(void) gentry_entrys = gentry_maxentry = 0; } - /// Initializes grfio. void grfio_init(const char* fname) { diff --git a/src/common/hercules.h b/src/common/hercules.h new file mode 100644 index 000000000..678577690 --- /dev/null +++ b/src/common/hercules.h @@ -0,0 +1,23 @@ +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Base author: Haru <haru@dotalux.com> + +#ifndef COMMON_HERCULES_H +#define COMMON_HERCULES_H + +#include "config/core.h" +#include "common/cbasetypes.h" + +#ifdef WIN32 + #define HPExport __declspec(dllexport) +#else + #define HPExport __attribute__((visibility("default"))) +#endif + +#define HPShared extern + +#ifndef HERCULES_CORE +#include "common/HPMi.h" +#endif // HERCULES_CORE + +#endif // COMMON_HERCULES_H diff --git a/src/common/malloc.c b/src/common/malloc.c index c647dc18f..63de90cb3 100644 --- a/src/common/malloc.c +++ b/src/common/malloc.c @@ -6,23 +6,24 @@ #include "malloc.h" +#include "common/cbasetypes.h" +#include "common/core.h" +#include "common/showmsg.h" +#include "common/sysinfo.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <time.h> - -#include "../common/core.h" -#include "../common/showmsg.h" -#include "../common/sysinfo.h" struct malloc_interface iMalloc_s; +struct malloc_interface *iMalloc; ////////////// Memory Libraries ////////////////// #if defined(MEMWATCH) # include <string.h> -# include "memwatch.h" +# include <memwatch.h> # define MALLOC(n,file,line,func) mwMalloc((n),(file),(line)) # define CALLOC(m,n,file,line,func) mwCalloc((m),(n),(file),(line)) # define REALLOC(p,n,file,line,func) mwRealloc((p),(n),(file),(line)) @@ -36,7 +37,7 @@ struct malloc_interface iMalloc_s; # include <string.h> # include <stdlib.h> -# include "dmalloc.h" +# include <dmalloc.h> # define MALLOC(n,file,line,func) dmalloc_malloc((file),(line),(n),DMALLOC_FUNC_MALLOC,0,0) # define CALLOC(m,n,file,line,func) dmalloc_malloc((file),(line),(m)*(n),DMALLOC_FUNC_CALLOC,0,0) # define REALLOC(p,n,file,line,func) dmalloc_realloc((file),(line),(p),(n),DMALLOC_FUNC_REALLOC,0) @@ -48,7 +49,7 @@ struct malloc_interface iMalloc_s; #elif defined(GCOLLECT) -# include "gc.h" +# include <gc.h> # ifdef GC_ADD_CALLER # define RETURN_ADDR 0, # else @@ -342,7 +343,8 @@ 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 = iMalloc->malloc(num * size,file,line,func); - memset(p,0,num * size); + if (p) + memset(p, 0, num * size); return p; } diff --git a/src/common/malloc.h b/src/common/malloc.h index 7ed2fb19c..b194c7cf3 100644 --- a/src/common/malloc.h +++ b/src/common/malloc.h @@ -4,7 +4,7 @@ #ifndef COMMON_MALLOC_H #define COMMON_MALLOC_H -#include "../common/cbasetypes.h" +#include "common/hercules.h" #define ALC_MARK __FILE__, __LINE__, __func__ @@ -59,12 +59,6 @@ //////////////////////////////////////////////// -#ifdef HERCULES_CORE -void malloc_defaults(void); - -void memmgr_report(int extra); -#endif // HERCULES_CORE - struct malloc_interface { void (*init) (void); void (*final) (void); @@ -84,5 +78,12 @@ struct malloc_interface { void (*init_messages) (void); }; -struct malloc_interface *iMalloc; +#ifdef HERCULES_CORE +void malloc_defaults(void); + +void memmgr_report(int extra); +#endif // HERCULES_CORE + +HPShared struct malloc_interface *iMalloc; + #endif /* COMMON_MALLOC_H */ diff --git a/src/common/mapindex.c b/src/common/mapindex.c index 035518f68..aa31d8090 100644 --- a/src/common/mapindex.c +++ b/src/common/mapindex.c @@ -6,18 +6,18 @@ #include "mapindex.h" +#include "common/cbasetypes.h" +#include "common/db.h" +#include "common/mmo.h" +#include "common/showmsg.h" +#include "common/strlib.h" + #include <stdio.h> #include <stdlib.h> -#include <string.h> - -#include "../common/db.h" -#include "../common/malloc.h" -#include "../common/mmo.h" -#include "../common/showmsg.h" -#include "../common/strlib.h" /* mapindex.c interface source */ struct mapindex_interface mapindex_s; +struct mapindex_interface *mapindex; /// Retrieves the map name from 'string' (removing .gat extension if present). /// Result gets placed either into 'buf' or in a static local buffer. @@ -125,7 +125,7 @@ unsigned short mapindex_name2id(const char* name) { return 0; } -const char* mapindex_id2name_sub(unsigned short id,const char *file, int line, const char *func) { +const char *mapindex_id2name_sub(uint16 id, const char *file, int line, const char *func) { if (id >= MAX_MAPINDEX || !mapindex_exists(id)) { ShowDebug("mapindex_id2name: Requested name for non-existant map index [%d] in cache. %s:%s:%d\n", id,file,func,line); return mapindex->list[0].name; // dummy empty string so that the callee doesn't crash @@ -193,7 +193,7 @@ void mapindex_defaults(void) { mapindex = &mapindex_s; /* TODO: place it in inter-server.conf? */ - snprintf(mapindex->config_file, 80, "%s","db/map_index.txt"); + snprintf(mapindex->config_file, sizeof(mapindex->config_file), "%s","db/map_index.txt"); /* */ mapindex->db = NULL; mapindex->num = 0; diff --git a/src/common/mapindex.h b/src/common/mapindex.h index 87a275f57..ff19630a1 100644 --- a/src/common/mapindex.h +++ b/src/common/mapindex.h @@ -5,8 +5,9 @@ #ifndef COMMON_MAPINDEX_H #define COMMON_MAPINDEX_H -#include "../common/db.h" -#include "../common/mmo.h" +#include "common/hercules.h" +#include "common/db.h" +#include "common/mmo.h" #define MAX_MAPINDEX 2000 @@ -90,14 +91,14 @@ struct mapindex_interface { const char* (*getmapname_ext) (const char* string, char* output); /* TODO: Hello World! make up your mind, this thing is int on some places and unsigned short on others */ unsigned short (*name2id) (const char*); - const char* (*id2name) (unsigned short,const char *file, int line, const char *func); + const char * (*id2name) (uint16 id, const char *file, int line, const char *func); bool (*check_default) (void); }; -struct mapindex_interface *mapindex; - #ifdef HERCULES_CORE void mapindex_defaults(void); #endif // HERCULES_CORE +HPShared struct mapindex_interface *mapindex; + #endif /* COMMON_MAPINDEX_H */ diff --git a/src/common/md5calc.c b/src/common/md5calc.c index 7b31a38d6..e594c364f 100644 --- a/src/common/md5calc.c +++ b/src/common/md5calc.c @@ -10,16 +10,13 @@ #include "md5calc.h" +#include "common/cbasetypes.h" +#include "common/random.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "../common/random.h" - -#ifndef UINT_MAX -#define UINT_MAX 4294967295U -#endif - // Global variable static unsigned int *pX; diff --git a/src/common/mmo.h b/src/common/mmo.h index 48eba0041..75b62fdc4 100644 --- a/src/common/mmo.h +++ b/src/common/mmo.h @@ -5,10 +5,8 @@ #ifndef COMMON_MMO_H #define COMMON_MMO_H -#include <time.h> - -#include "../common/cbasetypes.h" -#include "../common/db.h" +#include "config/core.h" +#include "common/cbasetypes.h" // server->client protocol version // 0 - pre-? @@ -118,15 +116,16 @@ #define MAX_STORAGE 600 #define MAX_GUILD_STORAGE 600 #define MAX_PARTY 12 -#define MAX_GUILD (16+10*6) // Increased max guild members +6 per 1 extension levels [Lupus] -#define MAX_GUILDPOSITION 20 // Increased max guild positions to accommodate for all members [Valaris] (removed) [PoW] +#define BASE_GUILD_SIZE 16 // Base guild members (without GD_EXTENSION) +#define MAX_GUILD (BASE_GUILD_SIZE+10*6) // Increased max guild members +6 per 1 extension levels [Lupus] +#define MAX_GUILDPOSITION 20 // Increased max guild positions to accomodate for all members [Valaris] (removed) [PoW] #define MAX_GUILDEXPULSION 32 #define MAX_GUILDALLIANCE 16 -#define MAX_GUILDSKILL 15 // Increased max guild skills because of new skills [Sara-chan] +#define MAX_GUILDSKILL 15 // Increased max guild skills because of new skills [Sara-chan] #define MAX_GUILDLEVEL 50 -#define MAX_GUARDIANS 8 // Local max per castle. [Skotlex] -#define MAX_QUEST_OBJECTIVES 3 // Max quest objectives for a quest -#define MAX_START_ITEMS 32 // Max number of items allowed to be given to a char whenever it's created. [mkbu95] +#define MAX_GUARDIANS 8 // Local max per castle. [Skotlex] +#define MAX_QUEST_OBJECTIVES 3 // Max quest objectives for a quest +#define MAX_START_ITEMS 32 // Max number of items allowed to be given to a char whenever it's created. [mkbu95] // for produce #define MIN_ATTRIBUTE 0 @@ -189,6 +188,16 @@ #define EL_CLASS_BASE 2114 #define EL_CLASS_MAX (EL_CLASS_BASE+MAX_ELEMENTAL_CLASS-1) +// The following system marks a different job ID system used by the map server, +// which makes a lot more sense than the normal one. [Skotlex] +// These marks the "level" of the job. +#define JOBL_2_1 0x100 //256 +#define JOBL_2_2 0x200 //512 +#define JOBL_2 0x300 +#define JOBL_UPPER 0x1000 //4096 +#define JOBL_BABY 0x2000 //8192 +#define JOBL_THIRD 0x4000 //16384 + struct HPluginData; enum item_types { @@ -298,6 +307,46 @@ enum e_item_bound_type { IBT_MAX = 0x4, }; +enum { + OPTION_NOTHING = 0x00000000, + OPTION_SIGHT = 0x00000001, + OPTION_HIDE = 0x00000002, + OPTION_CLOAK = 0x00000004, + OPTION_FALCON = 0x00000010, + OPTION_RIDING = 0x00000020, + OPTION_INVISIBLE = 0x00000040, + OPTION_ORCISH = 0x00000800, + OPTION_WEDDING = 0x00001000, + OPTION_RUWACH = 0x00002000, + OPTION_CHASEWALK = 0x00004000, + OPTION_FLYING = 0x00008000, //Note that clientside Flying and Xmas are 0x8000 for clients prior to 2007. + OPTION_XMAS = 0x00010000, + OPTION_TRANSFORM = 0x00020000, + OPTION_SUMMER = 0x00040000, + OPTION_DRAGON1 = 0x00080000, + OPTION_WUG = 0x00100000, + OPTION_WUGRIDER = 0x00200000, + OPTION_MADOGEAR = 0x00400000, + OPTION_DRAGON2 = 0x00800000, + OPTION_DRAGON3 = 0x01000000, + OPTION_DRAGON4 = 0x02000000, + OPTION_DRAGON5 = 0x04000000, + OPTION_HANBOK = 0x08000000, + OPTION_OKTOBERFEST = 0x10000000, +#ifndef NEW_CARTS + OPTION_CART1 = 0x00000008, + OPTION_CART2 = 0x00000080, + OPTION_CART3 = 0x00000100, + OPTION_CART4 = 0x00000200, + OPTION_CART5 = 0x00000400, + /* compound constant for older carts */ + OPTION_CART = OPTION_CART1|OPTION_CART2|OPTION_CART3|OPTION_CART4|OPTION_CART5, +#endif + // compound constants + OPTION_DRAGON = OPTION_DRAGON1|OPTION_DRAGON2|OPTION_DRAGON3|OPTION_DRAGON4|OPTION_DRAGON5, + OPTION_COSTUME = OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER|OPTION_HANBOK|OPTION_OKTOBERFEST, +}; + struct s_skill { unsigned short id; unsigned char lv; @@ -481,6 +530,8 @@ struct mmo_charstatus { unsigned char font; uint32 uniqueitem_counter; + + unsigned char hotkey_rowshift; }; typedef enum mail_status { @@ -677,6 +728,12 @@ enum { //Change Member Infos GMI_LEVEL, }; +enum guild_permission { // Guild permissions + GPERM_INVITE = 0x01, + GPERM_EXPEL = 0x10, + GPERM_BOTH = GPERM_INVITE|GPERM_EXPEL, +}; + enum { GD_SKILLBASE=10000, GD_APPROVAL=10000, @@ -697,7 +754,6 @@ enum { GD_MAX, }; - //These mark the ID of the jobs, as expected by the client. [Skotlex] enum { JOB_NOVICE, @@ -927,6 +983,30 @@ enum e_pc_reg_loading { PRL_ALL = 0xFF, }; +/** + * Values to be used as operation_type in chrif_char_ask_name + */ +enum zh_char_ask_name_type { + CHAR_ASK_NAME_BLOCK = 1, // account block + CHAR_ASK_NAME_BAN = 2, // account ban + CHAR_ASK_NAME_UNBLOCK = 3, // account unblock + CHAR_ASK_NAME_UNBAN = 4, // account unban + CHAR_ASK_NAME_CHANGESEX = 5, // change sex + CHAR_ASK_NAME_CHARBAN = 6, // character ban + CHAR_ASK_NAME_CHARUNBAN = 7, // character unban + CHAR_ASK_NAME_CHANGECHARSEX = 8, // change character sex +}; + +/** + * Values to be used as answer in chrig_char_ask_name_answer + */ +enum hz_char_ask_name_answer { + CHAR_ASK_NAME_ANS_DONE = 0, // login-server request done + CHAR_ASK_NAME_ANS_NOTFOUND = 1, // player not found + CHAR_ASK_NAME_ANS_GMLOW = 2, // gm level too low + CHAR_ASK_NAME_ANS_OFFLINE = 3, // login-server offline +}; + /* packet size constant for itemlist */ #if MAX_INVENTORY > MAX_STORAGE && MAX_INVENTORY > MAX_CART #define MAX_ITEMLIST MAX_INVENTORY diff --git a/src/common/mutex.c b/src/common/mutex.c index 7307f5f15..715609628 100644 --- a/src/common/mutex.c +++ b/src/common/mutex.c @@ -5,20 +5,18 @@ #include "mutex.h" -#include "../common/cbasetypes.h" // for WIN32 +#include "common/cbasetypes.h" // for WIN32 +#include "common/malloc.h" +#include "common/showmsg.h" +#include "common/timer.h" #ifdef WIN32 -#include "../common/winapi.h" +#include "common/winapi.h" #else #include <pthread.h> -#include <time.h> #include <sys/time.h> #endif -#include "../common/malloc.h" -#include "../common/showmsg.h" -#include "../common/timer.h" - struct ramutex{ #ifdef WIN32 CRITICAL_SECTION hMutex; @@ -27,7 +25,6 @@ struct ramutex{ #endif }; - struct racond{ #ifdef WIN32 HANDLE events[2]; @@ -42,14 +39,12 @@ struct racond{ #endif }; - //////////////////// // Mutex // // Implementation: // - ramutex *ramutex_create(void) { struct ramutex *m; @@ -68,7 +63,6 @@ ramutex *ramutex_create(void) { return m; }//end: ramutex_create() - void ramutex_destroy(ramutex *m) { #ifdef WIN32 @@ -81,7 +75,6 @@ void ramutex_destroy(ramutex *m) { }//end: ramutex_destroy() - void ramutex_lock(ramutex *m) { #ifdef WIN32 @@ -91,7 +84,6 @@ void ramutex_lock(ramutex *m) { #endif }//end: ramutex_lock - bool ramutex_trylock(ramutex *m) { #ifdef WIN32 if(TryEnterCriticalSection(&m->hMutex) != FALSE) @@ -106,7 +98,6 @@ bool ramutex_trylock(ramutex *m) { #endif }//end: ramutex_trylock() - void ramutex_unlock(ramutex *m) { #ifdef WIN32 LeaveCriticalSection(&m->hMutex); @@ -116,8 +107,6 @@ void ramutex_unlock(ramutex *m) { }//end: ramutex_unlock() - - /////////////// // Condition Variables // @@ -145,7 +134,6 @@ racond *racond_create(void) { return c; }//end: racond_create() - void racond_destroy(racond *c) { #ifdef WIN32 CloseHandle( c->events[ EVENT_COND_SIGNAL ] ); @@ -158,14 +146,12 @@ void racond_destroy(racond *c) { aFree(c); }//end: racond_destroy() - void racond_wait(racond *c, ramutex *m, sysint timeout_ticks) { #ifdef WIN32 register DWORD ms; int result; bool is_last = false; - EnterCriticalSection(&c->waiters_lock); c->nWaiters++; LeaveCriticalSection(&c->waiters_lock); @@ -193,7 +179,6 @@ void racond_wait(racond *c, ramutex *m, sysint timeout_ticks) { if(is_last == true) ResetEvent( c->events[EVENT_COND_BROADCAST] ); - ramutex_lock(m); #else @@ -212,7 +197,6 @@ void racond_wait(racond *c, ramutex *m, sysint timeout_ticks) { #endif }//end: racond_wait() - void racond_signal(racond *c) { #ifdef WIN32 # if 0 @@ -230,7 +214,6 @@ void racond_signal(racond *c) { #endif }//end: racond_signal() - void racond_broadcast(racond *c) { #ifdef WIN32 # if 0 @@ -247,5 +230,3 @@ void racond_broadcast(racond *c) { pthread_cond_broadcast(&c->hCond); #endif }//end: racond_broadcast() - - diff --git a/src/common/mutex.h b/src/common/mutex.h index fa8170c98..a70f0e8fd 100644 --- a/src/common/mutex.h +++ b/src/common/mutex.h @@ -4,7 +4,7 @@ #ifndef COMMON_MUTEX_H #define COMMON_MUTEX_H -#include "../common/cbasetypes.h" +#include "common/cbasetypes.h" typedef struct ramutex ramutex; // Mutex typedef struct racond racond; // Condition Var diff --git a/src/common/nullpo.c b/src/common/nullpo.c index e61d52257..98faa9f06 100644 --- a/src/common/nullpo.c +++ b/src/common/nullpo.c @@ -6,13 +6,18 @@ #include "nullpo.h" +#include "common/showmsg.h" + #include <stdio.h> #include <stdarg.h> +#include <stdlib.h> #include <string.h> - -#include "../common/showmsg.h" +#ifdef HAVE_EXECINFO +#include <execinfo.h> +#endif // HAVE_EXECINFO struct nullpo_interface nullpo_s; +struct nullpo_interface *nullpo; /** * Reports failed assertions or NULL pointers @@ -24,6 +29,12 @@ struct nullpo_interface nullpo_s; * @param title Message title to display (i.e. failed assertion or nullpo info) */ void assert_report(const char *file, int line, const char *func, const char *targetname, const char *title) { +#ifdef HAVE_EXECINFO + void *array[10]; + int size; + char **strings; + int i; +#endif // HAVE_EXECINFO if (file == NULL) file = "??"; @@ -32,6 +43,13 @@ void assert_report(const char *file, int line, const char *func, const char *tar ShowError("--- %s --------------------------------------------\n", title); ShowError("%s:%d: '%s' in function `%s'\n", file, line, targetname, func); +#ifdef HAVE_EXECINFO + size = (int)backtrace(array, 10); + strings = backtrace_symbols(array, size); + for (i = 0; i < size; i++) + ShowError("%s\n", strings[i]); + free(strings); +#endif // HAVE_EXECINFO ShowError("--- end %s ----------------------------------------\n", title); } @@ -40,6 +58,5 @@ void assert_report(const char *file, int line, const char *func, const char *tar **/ void nullpo_defaults(void) { nullpo = &nullpo_s; - nullpo->assert_report = assert_report; } diff --git a/src/common/nullpo.h b/src/common/nullpo.h index 573e351e0..52e9fba39 100644 --- a/src/common/nullpo.h +++ b/src/common/nullpo.h @@ -5,7 +5,7 @@ #ifndef COMMON_NULLPO_H #define COMMON_NULLPO_H -#include "../common/cbasetypes.h" +#include "common/hercules.h" // enabled by default on debug builds #if defined(DEBUG) && !defined(NULLPO_CHECK) @@ -127,10 +127,10 @@ struct nullpo_interface { void (*assert_report) (const char *file, int line, const char *func, const char *targetname, const char *title); }; -struct nullpo_interface *nullpo; - #ifdef HERCULES_CORE void nullpo_defaults(void); #endif // HERCULES_CORE +HPShared struct nullpo_interface *nullpo; + #endif /* COMMON_NULLPO_H */ diff --git a/src/common/random.c b/src/common/random.c index 88d5748cf..a4d7c5d34 100644 --- a/src/common/random.c +++ b/src/common/random.c @@ -5,16 +5,14 @@ #include "random.h" -#include <time.h> // time +#include "common/cbasetypes.h" // for WIN32 +#include "common/showmsg.h" +#include "common/timer.h" // gettick -#include <mt19937ar.h> // init_genrand, genrand_int32, genrand_res53 - -#include "../common/cbasetypes.h" // for WIN32 -#include "../common/showmsg.h" -#include "../common/timer.h" // gettick +#include <mt19937ar/mt19937ar.h> // init_genrand, genrand_int32, genrand_res53 #if defined(WIN32) -# include "../common/winapi.h" +# include "common/winapi.h" #elif defined(HAVE_GETPID) || defined(HAVE_GETTID) # include <sys/types.h> # include <unistd.h> diff --git a/src/common/random.h b/src/common/random.h index 0ca375d28..379e675b2 100644 --- a/src/common/random.h +++ b/src/common/random.h @@ -4,7 +4,7 @@ #ifndef COMMON_RANDOM_H #define COMMON_RANDOM_H -#include "../common/cbasetypes.h" +#include "common/cbasetypes.h" #ifdef HERCULES_CORE void rnd_init(void); diff --git a/src/common/showmsg.c b/src/common/showmsg.c index 0dd645eeb..27fb0b635 100644 --- a/src/common/showmsg.c +++ b/src/common/showmsg.c @@ -6,20 +6,18 @@ #include "showmsg.h" +#include "common/cbasetypes.h" +#include "common/core.h" //[Ind] - For SERVER_TYPE +#include "common/strlib.h" // StringBuf + +#include <libconfig/libconfig.h> + #include <stdarg.h> #include <stdio.h> #include <stdlib.h> // atexit -#include <string.h> -#include <time.h> - -#include "../../3rdparty/libconfig/libconfig.h" - -#include "../common/cbasetypes.h" -#include "../common/core.h" //[Ind] - For SERVER_TYPE -#include "../common/strlib.h" // StringBuf #ifdef WIN32 -# include "../common/winapi.h" +# include "common/winapi.h" #else // not WIN32 # include <unistd.h> #endif // WIN32 @@ -32,16 +30,8 @@ #define DEBUGLOGPATH "log"PATHSEP_STR"login-server.log" #endif -/////////////////////////////////////////////////////////////////////////////// -/// behavioral parameter. -/// when redirecting output: -/// if true prints escape sequences -/// if false removes the escape sequences -int stdout_with_ansisequence = 0; - -int msg_silent = 0; //Specifies how silent the console is. - -int console_msg_log = 0;//[Ind] msg error logging +struct showmsg_interface showmsg_s; +struct showmsg_interface *showmsg; /////////////////////////////////////////////////////////////////////////////// /// static/dynamic buffer for the messages @@ -199,8 +189,7 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr) // Print everything to the buffer BUFVPRINTF(tempbuf,fmt,argptr); - if( !is_console(handle) && stdout_with_ansisequence ) - { + if (!is_console(handle) && showmsg->stdout_with_ansisequence) { WriteFile(handle, BUFVAL(tempbuf), BUFLEN(tempbuf), &written, 0); return 0; } @@ -492,8 +481,7 @@ int VFPRINTF(FILE *file, const char *fmt, va_list argptr) if(!fmt || !*fmt) return 0; - if( is_console(file) || stdout_with_ansisequence ) - { + if (is_console(file) || showmsg->stdout_with_ansisequence) { vfprintf(file, fmt, argptr); return 0; } @@ -598,9 +586,6 @@ int FPRINTF(FILE *file, const char *fmt, ...) { #endif// not _WIN32 - -char timestamp_format[20] = ""; //For displaying Timestamps - int vShowMessage_(enum msg_type flag, const char *string, va_list ap) { va_list apcopy; @@ -614,9 +599,9 @@ int vShowMessage_(enum msg_type flag, const char *string, va_list ap) return 1; } if( - ( flag == MSG_WARNING && console_msg_log&1 ) || - ( ( flag == MSG_ERROR || flag == MSG_SQL ) && console_msg_log&2 ) || - ( flag == MSG_DEBUG && console_msg_log&4 ) ) {//[Ind] + ( flag == MSG_WARNING && showmsg->console_log&1 ) || + ( ( flag == MSG_ERROR || flag == MSG_SQL ) && showmsg->console_log&2 ) || + ( flag == MSG_DEBUG && showmsg->console_log&4 ) ) {//[Ind] FILE *log = NULL; if( (log = fopen(SERVER_TYPE == SERVER_TYPE_MAP ? "./log/map-msg_log.log" : "./log/unknown.log","a+")) ) { char timestring[255]; @@ -637,20 +622,20 @@ int vShowMessage_(enum msg_type flag, const char *string, va_list ap) } } if( - (flag == MSG_INFORMATION && msg_silent&1) || - (flag == MSG_STATUS && msg_silent&2) || - (flag == MSG_NOTICE && msg_silent&4) || - (flag == MSG_WARNING && msg_silent&8) || - (flag == MSG_ERROR && msg_silent&16) || - (flag == MSG_SQL && msg_silent&16) || - (flag == MSG_DEBUG && msg_silent&32) + (flag == MSG_INFORMATION && showmsg->silent&1) || + (flag == MSG_STATUS && showmsg->silent&2) || + (flag == MSG_NOTICE && showmsg->silent&4) || + (flag == MSG_WARNING && showmsg->silent&8) || + (flag == MSG_ERROR && showmsg->silent&16) || + (flag == MSG_SQL && showmsg->silent&16) || + (flag == MSG_DEBUG && showmsg->silent&32) ) return 0; //Do not print it. - if (timestamp_format[0] && flag != MSG_NONE) { + if (showmsg->timestamp_format[0] && flag != MSG_NONE) { //Display time format. [Skotlex] time_t t = time(NULL); - strftime(prefix, 80, timestamp_format, localtime(&t)); + strftime(prefix, 80, showmsg->timestamp_format, localtime(&t)); } else prefix[0]='\0'; switch (flag) { @@ -723,7 +708,17 @@ int vShowMessage_(enum msg_type flag, const char *string, va_list ap) return 0; } -void ClearScreen(void) +int showmsg_vShowMessage(const char *string, va_list ap) +{ + int ret; + va_list apcopy; + va_copy(apcopy, ap); + ret = vShowMessage_(MSG_NONE, string, apcopy); + va_end(apcopy); + return ret; +} + +void showmsg_clearScreen(void) { #ifndef _WIN32 ShowMessage(CL_CLS); // to prevent empty string passed messages @@ -740,50 +735,57 @@ int ShowMessage_(enum msg_type flag, const char *string, ...) { } // direct printf replacement -void ShowMessage(const char *string, ...) __attribute__((format(printf, 1, 2))); -void ShowMessage(const char *string, ...) { +void showmsg_showMessage(const char *string, ...) __attribute__((format(printf, 1, 2))); +void showmsg_showMessage(const char *string, ...) +{ va_list ap; va_start(ap, string); vShowMessage_(MSG_NONE, string, ap); va_end(ap); } -void ShowStatus(const char *string, ...) __attribute__((format(printf, 1, 2))); -void ShowStatus(const char *string, ...) { +void showmsg_showStatus(const char *string, ...) __attribute__((format(printf, 1, 2))); +void showmsg_showStatus(const char *string, ...) +{ va_list ap; va_start(ap, string); vShowMessage_(MSG_STATUS, string, ap); va_end(ap); } -void ShowSQL(const char *string, ...) __attribute__((format(printf, 1, 2))); -void ShowSQL(const char *string, ...) { +void showmsg_showSQL(const char *string, ...) __attribute__((format(printf, 1, 2))); +void showmsg_showSQL(const char *string, ...) +{ va_list ap; va_start(ap, string); vShowMessage_(MSG_SQL, string, ap); va_end(ap); } -void ShowInfo(const char *string, ...) __attribute__((format(printf, 1, 2))); -void ShowInfo(const char *string, ...) { +void showmsg_showInfo(const char *string, ...) __attribute__((format(printf, 1, 2))); +void showmsg_showInfo(const char *string, ...) +{ va_list ap; va_start(ap, string); vShowMessage_(MSG_INFORMATION, string, ap); va_end(ap); } -void ShowNotice(const char *string, ...) __attribute__((format(printf, 1, 2))); -void ShowNotice(const char *string, ...) { +void showmsg_showNotice(const char *string, ...) __attribute__((format(printf, 1, 2))); +void showmsg_showNotice(const char *string, ...) +{ va_list ap; va_start(ap, string); vShowMessage_(MSG_NOTICE, string, ap); va_end(ap); } -void ShowWarning(const char *string, ...) __attribute__((format(printf, 1, 2))); -void ShowWarning(const char *string, ...) { +void showmsg_showWarning(const char *string, ...) __attribute__((format(printf, 1, 2))); +void showmsg_showWarning(const char *string, ...) +{ va_list ap; va_start(ap, string); vShowMessage_(MSG_WARNING, string, ap); va_end(ap); } -void ShowConfigWarning(config_setting_t *config, const char *string, ...) __attribute__((format(printf, 2, 3))); -void ShowConfigWarning(config_setting_t *config, const char *string, ...) { +void showmsg_showConfigWarning(config_setting_t *config, const char *string, ...) __attribute__((format(printf, 2, 3))); +void showmsg_showConfigWarning(config_setting_t *config, const char *string, ...) +{ StringBuf buf; va_list ap; StrBuf->Init(&buf); @@ -794,24 +796,70 @@ void ShowConfigWarning(config_setting_t *config, const char *string, ...) { va_end(ap); StrBuf->Destroy(&buf); } -void ShowDebug(const char *string, ...) __attribute__((format(printf, 1, 2))); -void ShowDebug(const char *string, ...) { +void showmsg_showDebug(const char *string, ...) __attribute__((format(printf, 1, 2))); +void showmsg_showDebug(const char *string, ...) +{ va_list ap; va_start(ap, string); vShowMessage_(MSG_DEBUG, string, ap); va_end(ap); } -void ShowError(const char *string, ...) __attribute__((format(printf, 1, 2))); -void ShowError(const char *string, ...) { +void showmsg_showError(const char *string, ...) __attribute__((format(printf, 1, 2))); +void showmsg_showError(const char *string, ...) +{ va_list ap; va_start(ap, string); vShowMessage_(MSG_ERROR, string, ap); va_end(ap); } -void ShowFatalError(const char *string, ...) __attribute__((format(printf, 1, 2))); -void ShowFatalError(const char *string, ...) { +void showmsg_showFatalError(const char *string, ...) __attribute__((format(printf, 1, 2))); +void showmsg_showFatalError(const char *string, ...) +{ va_list ap; va_start(ap, string); vShowMessage_(MSG_FATALERROR, string, ap); va_end(ap); } + +void showmsg_init(void) +{ +} + +void showmsg_final(void) +{ +} + +void showmsg_defaults(void) +{ + showmsg = &showmsg_s; + + /////////////////////////////////////////////////////////////////////////////// + /// behavioral parameter. + /// when redirecting output: + /// if true prints escape sequences + /// if false removes the escape sequences + showmsg->stdout_with_ansisequence = false; + + showmsg->silent = 0; //Specifies how silent the console is. + + showmsg->console_log = 0;//[Ind] msg error logging + + memset(showmsg->timestamp_format, '\0', sizeof(showmsg->timestamp_format)); + + showmsg->init = showmsg_init; + showmsg->final = showmsg_final; + + showmsg->clearScreen = showmsg_clearScreen; + showmsg->showMessageV = showmsg_vShowMessage; + + showmsg->showMessage = showmsg_showMessage; + showmsg->showStatus = showmsg_showStatus; + showmsg->showSQL = showmsg_showSQL; + showmsg->showInfo = showmsg_showInfo; + showmsg->showNotice = showmsg_showNotice; + showmsg->showWarning = showmsg_showWarning; + showmsg->showDebug = showmsg_showDebug; + showmsg->showError = showmsg_showError; + showmsg->showFatalError = showmsg_showFatalError; + showmsg->showConfigWarning = showmsg_showConfigWarning; +} diff --git a/src/common/showmsg.h b/src/common/showmsg.h index 48e763c25..728691ba3 100644 --- a/src/common/showmsg.h +++ b/src/common/showmsg.h @@ -5,15 +5,11 @@ #ifndef COMMON_SHOWMSG_H #define COMMON_SHOWMSG_H -#include <stdarg.h> +#include "common/hercules.h" -#include "../common/cbasetypes.h" +#include <libconfig/libconfig.h> -#ifdef HERCULES_CORE -# include "../../3rdparty/libconfig/libconfig.h" -#else -# include "../common/HPMi.h" -#endif +#include <stdarg.h> // for help with the console colors look here: // http://www.edoceo.com/liberum/?doc=printf-with-color @@ -23,58 +19,55 @@ // \033[0m : reset color parameter // \033[1m : use bold for font -#define CL_RESET "\033[0m" -#define CL_CLS "\033[2J" -#define CL_CLL "\033[K" +#define CL_RESET "\033[0m" +#define CL_CLS "\033[2J" +#define CL_CLL "\033[K" // font settings -#define CL_BOLD "\033[1m" -#define CL_NORM CL_RESET -#define CL_NORMAL CL_RESET -#define CL_NONE CL_RESET -// foreground color and bold font (bright color on windows) -#define CL_WHITE "\033[1;37m" -#define CL_GRAY "\033[1;30m" -#define CL_RED "\033[1;31m" -#define CL_GREEN "\033[1;32m" -#define CL_YELLOW "\033[1;33m" -#define CL_BLUE "\033[1;34m" -#define CL_MAGENTA "\033[1;35m" -#define CL_CYAN "\033[1;36m" +#define CL_BOLD "\033[1m" +#define CL_NORM CL_RESET +#define CL_NORMAL CL_RESET +#define CL_NONE CL_RESET // background color -#define CL_BG_BLACK "\033[40m" -#define CL_BG_RED "\033[41m" -#define CL_BG_GREEN "\033[42m" -#define CL_BG_YELLOW "\033[43m" -#define CL_BG_BLUE "\033[44m" -#define CL_BG_MAGENTA "\033[45m" -#define CL_BG_CYAN "\033[46m" -#define CL_BG_WHITE "\033[47m" +#define CL_BG_BLACK "\033[40m" +#define CL_BG_RED "\033[41m" +#define CL_BG_GREEN "\033[42m" +#define CL_BG_YELLOW "\033[43m" +#define CL_BG_BLUE "\033[44m" +#define CL_BG_MAGENTA "\033[45m" +#define CL_BG_CYAN "\033[46m" +#define CL_BG_WHITE "\033[47m" // foreground color and normal font (normal color on windows) -#define CL_LT_BLACK "\033[0;30m" -#define CL_LT_RED "\033[0;31m" -#define CL_LT_GREEN "\033[0;32m" -#define CL_LT_YELLOW "\033[0;33m" -#define CL_LT_BLUE "\033[0;34m" -#define CL_LT_MAGENTA "\033[0;35m" -#define CL_LT_CYAN "\033[0;36m" -#define CL_LT_WHITE "\033[0;37m" +#define CL_LT_BLACK "\033[0;30m" +#define CL_LT_RED "\033[0;31m" +#define CL_LT_GREEN "\033[0;32m" +#define CL_LT_YELLOW "\033[0;33m" +#define CL_LT_BLUE "\033[0;34m" +#define CL_LT_MAGENTA "\033[0;35m" +#define CL_LT_CYAN "\033[0;36m" +#define CL_LT_WHITE "\033[0;37m" // foreground color and bold font (bright color on windows) -#define CL_BT_BLACK "\033[1;30m" -#define CL_BT_RED "\033[1;31m" -#define CL_BT_GREEN "\033[1;32m" -#define CL_BT_YELLOW "\033[1;33m" -#define CL_BT_BLUE "\033[1;34m" -#define CL_BT_MAGENTA "\033[1;35m" -#define CL_BT_CYAN "\033[1;36m" -#define CL_BT_WHITE "\033[1;37m" +#define CL_BT_BLACK "\033[1;30m" +#define CL_BT_RED "\033[1;31m" +#define CL_BT_GREEN "\033[1;32m" +#define CL_BT_YELLOW "\033[1;33m" +#define CL_BT_BLUE "\033[1;34m" +#define CL_BT_MAGENTA "\033[1;35m" +#define CL_BT_CYAN "\033[1;36m" +#define CL_BT_WHITE "\033[1;37m" -#define CL_WTBL "\033[37;44m" // white on blue -#define CL_XXBL "\033[0;44m" // default on blue -#define CL_PASS "\033[0;32;42m" // green on green +// foreground color and bold font (bright color on windows) +#define CL_WHITE CL_BT_WHITE +#define CL_GRAY CL_BT_BLACK +#define CL_RED CL_BT_RED +#define CL_GREEN CL_BT_GREEN +#define CL_YELLOW CL_BT_YELLOW +#define CL_BLUE CL_BT_BLUE +#define CL_MAGENTA CL_BT_MAGENTA +#define CL_CYAN CL_BT_CYAN -#define CL_SPACE " " // space equivalent of the print messages +#define CL_SPACE " " // space aquivalent of the print messages enum msg_type { MSG_NONE, @@ -88,35 +81,48 @@ enum msg_type { MSG_FATALERROR }; +struct showmsg_interface { + bool stdout_with_ansisequence; //If the color ANSI sequences are to be used. [flaviojs] + int silent; //Specifies how silent the console is. [Skotlex] + int console_log; //Specifies what error messages to log. [Ind] + char timestamp_format[20]; //For displaying Timestamps [Skotlex] + + void (*init) (void); + void (*final) (void); + + void (*clearScreen) (void); + int (*showMessageV) (const char *string, va_list ap); + + void (*showMessage) (const char *, ...) __attribute__((format(printf, 1, 2))); + void (*showStatus) (const char *, ...) __attribute__((format(printf, 1, 2))); + void (*showSQL) (const char *, ...) __attribute__((format(printf, 1, 2))); + void (*showInfo) (const char *, ...) __attribute__((format(printf, 1, 2))); + void (*showNotice) (const char *, ...) __attribute__((format(printf, 1, 2))); + void (*showWarning) (const char *, ...) __attribute__((format(printf, 1, 2))); + void (*showDebug) (const char *, ...) __attribute__((format(printf, 1, 2))); + void (*showError) (const char *, ...) __attribute__((format(printf, 1, 2))); + void (*showFatalError) (const char *, ...) __attribute__((format(printf, 1, 2))); + void (*showConfigWarning) (config_setting_t *config, const char *string, ...) __attribute__((format(printf, 2, 3))); +}; + +/* the purpose of these macros is simply to not make calling them be an annoyance */ +#define ClearScreen() (showmsg->clearScreen()) +#define vShowMessage(fmt, list) (showmsg->showMessageV((fmt), (list))) +#define ShowMessage(fmt, ...) (showmsg->showMessage((fmt), ##__VA_ARGS__)) +#define ShowStatus(fmt, ...) (showmsg->showStatus((fmt), ##__VA_ARGS__)) +#define ShowSQL(fmt, ...) (showmsg->showSQL((fmt), ##__VA_ARGS__)) +#define ShowInfo(fmt, ...) (showmsg->showInfo((fmt), ##__VA_ARGS__)) +#define ShowNotice(fmt, ...) (showmsg->showNotice((fmt), ##__VA_ARGS__)) +#define ShowWarning(fmt, ...) (showmsg->showWarning((fmt), ##__VA_ARGS__)) +#define ShowDebug(fmt, ...) (showmsg->showDebug((fmt), ##__VA_ARGS__)) +#define ShowError(fmt, ...) (showmsg->showError((fmt), ##__VA_ARGS__)) +#define ShowFatalError(fmt, ...) (showmsg->showFatalError((fmt), ##__VA_ARGS__)) +#define ShowConfigWarning(config, fmt, ...) (showmsg->showConfigWarning((config), (fmt), ##__VA_ARGS__)) + #ifdef HERCULES_CORE -extern int stdout_with_ansisequence; //If the color ANSI sequences are to be used. [flaviojs] -extern int msg_silent; //Specifies how silent the console is. [Skotlex] -extern int console_msg_log; //Specifies what error messages to log. [Ind] -extern char timestamp_format[20]; //For displaying Timestamps [Skotlex] - -extern void ClearScreen(void); -extern int vShowMessage_(enum msg_type flag, const char *string, va_list ap); - - extern void ShowMessage(const char *, ...) __attribute__((format(printf, 1, 2))); - extern void ShowStatus(const char *, ...) __attribute__((format(printf, 1, 2))); - extern void ShowSQL(const char *, ...) __attribute__((format(printf, 1, 2))); - extern void ShowInfo(const char *, ...) __attribute__((format(printf, 1, 2))); - extern void ShowNotice(const char *, ...) __attribute__((format(printf, 1, 2))); - extern void ShowWarning(const char *, ...) __attribute__((format(printf, 1, 2))); - extern void ShowDebug(const char *, ...) __attribute__((format(printf, 1, 2))); - extern void ShowError(const char *, ...) __attribute__((format(printf, 1, 2))); - extern void ShowFatalError(const char *, ...) __attribute__((format(printf, 1, 2))); - extern void ShowConfigWarning(config_setting_t *config, const char *string, ...) __attribute__((format(printf, 2, 3))); -#else - HPExport void (*ShowMessage) (const char *, ...) __attribute__((format(printf, 1, 2))); - HPExport void (*ShowStatus) (const char *, ...) __attribute__((format(printf, 1, 2))); - HPExport void (*ShowSQL) (const char *, ...) __attribute__((format(printf, 1, 2))); - HPExport void (*ShowInfo) (const char *, ...) __attribute__((format(printf, 1, 2))); - HPExport void (*ShowNotice) (const char *, ...) __attribute__((format(printf, 1, 2))); - HPExport void (*ShowWarning) (const char *, ...) __attribute__((format(printf, 1, 2))); - HPExport void (*ShowDebug) (const char *, ...) __attribute__((format(printf, 1, 2))); - HPExport void (*ShowError) (const char *, ...) __attribute__((format(printf, 1, 2))); - HPExport void (*ShowFatalError) (const char *, ...) __attribute__((format(printf, 1, 2))); -#endif +void showmsg_defaults(void); +#endif // HERCULES_CORE + +HPShared struct showmsg_interface *showmsg; #endif /* COMMON_SHOWMSG_H */ diff --git a/src/common/socket.c b/src/common/socket.c index 1b7f36f8b..de8ca4682 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -4,26 +4,25 @@ #define HERCULES_CORE -#include "../config/core.h" // SHOW_SERVER_STATS -#define H_SOCKET_C +#include "config/core.h" // SHOW_SERVER_STATS #include "socket.h" -#undef H_SOCKET_C + +#include "common/HPM.h" +#include "common/cbasetypes.h" +#include "common/db.h" +#include "common/malloc.h" +#include "common/mmo.h" +#include "common/nullpo.h" +#include "common/showmsg.h" +#include "common/strlib.h" +#include "common/timer.h" #include <stdio.h> #include <stdlib.h> -#include <string.h> #include <sys/types.h> -#include "../common/HPM.h" -#include "../common/cbasetypes.h" -#include "../common/malloc.h" -#include "../common/mmo.h" -#include "../common/showmsg.h" -#include "../common/strlib.h" -#include "../common/timer.h" - #ifdef WIN32 -# include "../common/winapi.h" +# include "common/winapi.h" #else # include <arpa/inet.h> # include <errno.h> @@ -56,6 +55,9 @@ * Socket Interface Source **/ struct socket_interface sockt_s; +struct socket_interface *sockt; + +struct socket_data **session; #ifdef SEND_SHORTLIST // Add a fd to the shortlist so that it'll be recognized as a fd that needs @@ -111,7 +113,6 @@ int sock2fd(SOCKET s) return fd; } - /// Inserts the socket into the global array of sockets. /// Returns a new fd associated with the socket. /// If there are too many sockets it closes the socket, sets an error and @@ -291,7 +292,6 @@ void set_defaultparse(ParseFunc defaultparse) default_func_parse = defaultparse; } - /*====================================== * CORE : Socket options *--------------------------------------*/ @@ -358,13 +358,12 @@ void setsocketopts(int fd, struct hSockOpt *opt) { *--------------------------------------*/ void set_eof(int fd) { - if( sockt->session_isActive(fd) ) - { + if (sockt->session_is_active(fd)) { #ifdef SEND_SHORTLIST // Add this socket to the shortlist for eof handling. send_shortlist_add_fd(fd); #endif - session[fd]->flag.eof = 1; + sockt->session[fd]->flag.eof = 1; } } @@ -372,32 +371,32 @@ int recv_to_fifo(int fd) { ssize_t len; - if( !sockt->session_isActive(fd) ) + if (!sockt->session_is_active(fd)) return -1; - len = sRecv(fd, (char *) session[fd]->rdata + session[fd]->rdata_size, (int)RFIFOSPACE(fd), 0); + len = sRecv(fd, (char *) sockt->session[fd]->rdata + sockt->session[fd]->rdata_size, (int)RFIFOSPACE(fd), 0); if( len == SOCKET_ERROR ) {//An exception has occurred if( sErrno != S_EWOULDBLOCK ) { //ShowDebug("recv_to_fifo: %s, closing connection #%d\n", error_msg(), fd); - set_eof(fd); + sockt->eof(fd); } return 0; } if( len == 0 ) {//Normal connection end. - set_eof(fd); + sockt->eof(fd); return 0; } - session[fd]->rdata_size += len; - session[fd]->rdata_tick = sockt->last_tick; + sockt->session[fd]->rdata_size += len; + sockt->session[fd]->rdata_tick = sockt->last_tick; #ifdef SHOW_SERVER_STATS socket_data_i += len; socket_data_qi += len; - if (!session[fd]->flag.server) + if (!sockt->session[fd]->flag.server) { socket_data_ci += len; } @@ -409,23 +408,23 @@ int send_from_fifo(int fd) { ssize_t len; - if( !sockt->session_isValid(fd) ) + if (!sockt->session_is_valid(fd)) return -1; - if( session[fd]->wdata_size == 0 ) + if( sockt->session[fd]->wdata_size == 0 ) return 0; // nothing to send - len = sSend(fd, (const char *) session[fd]->wdata, (int)session[fd]->wdata_size, MSG_NOSIGNAL); + len = sSend(fd, (const char *) sockt->session[fd]->wdata, (int)sockt->session[fd]->wdata_size, MSG_NOSIGNAL); if( len == SOCKET_ERROR ) {//An exception has occurred if( sErrno != S_EWOULDBLOCK ) { //ShowDebug("send_from_fifo: %s, ending connection #%d\n", error_msg(), fd); #ifdef SHOW_SERVER_STATS - socket_data_qo -= session[fd]->wdata_size; + socket_data_qo -= sockt->session[fd]->wdata_size; #endif - session[fd]->wdata_size = 0; //Clear the send queue as we can't send anymore. [Skotlex] - set_eof(fd); + sockt->session[fd]->wdata_size = 0; //Clear the send queue as we can't send anymore. [Skotlex] + sockt->eof(fd); } return 0; } @@ -434,14 +433,14 @@ int send_from_fifo(int fd) { // some data could not be transferred? // shift unsent data to the beginning of the queue - if( (size_t)len < session[fd]->wdata_size ) - memmove(session[fd]->wdata, session[fd]->wdata + len, session[fd]->wdata_size - len); + if( (size_t)len < sockt->session[fd]->wdata_size ) + memmove(sockt->session[fd]->wdata, sockt->session[fd]->wdata + len, sockt->session[fd]->wdata_size - len); - session[fd]->wdata_size -= len; + sockt->session[fd]->wdata_size -= len; #ifdef SHOW_SERVER_STATS socket_data_o += len; socket_data_qo -= len; - if (!session[fd]->flag.server) + if (!sockt->session[fd]->flag.server) { socket_data_co += len; } @@ -454,15 +453,15 @@ int send_from_fifo(int fd) /// Best effort - there's no warranty that the data will be sent. void flush_fifo(int fd) { - if(session[fd] != NULL) - session[fd]->func_send(fd); + if(sockt->session[fd] != NULL) + sockt->session[fd]->func_send(fd); } void flush_fifos(void) { int i; for(i = 1; i < sockt->fd_max; i++) - sockt->flush_fifo(i); + sockt->flush(i); } /*====================================== @@ -492,7 +491,7 @@ int connect_client(int listen_fd) { } setsocketopts(fd,NULL); - set_nonblocking(fd, 1); + sockt->set_nonblocking(fd, 1); #ifndef MINICORE if( ip_rules && !connect_check(ntohl(client_address.sin_addr.s_addr)) ) { @@ -505,7 +504,7 @@ int connect_client(int listen_fd) { sFD_SET(fd,&readfds); create_session(fd, recv_to_fifo, send_from_fifo, default_func_parse); - session[fd]->client_addr = ntohl(client_address.sin_addr.s_addr); + sockt->session[fd]->client_addr = ntohl(client_address.sin_addr.s_addr); return fd; } @@ -534,7 +533,7 @@ int make_listen_bind(uint32 ip, uint16 port) } setsocketopts(fd,NULL); - set_nonblocking(fd, 1); + sockt->set_nonblocking(fd, 1); server_address.sin_family = AF_INET; server_address.sin_addr.s_addr = htonl(ip); @@ -555,8 +554,8 @@ int make_listen_bind(uint32 ip, uint16 port) sFD_SET(fd, &readfds); create_session(fd, connect_client, null_send, null_parse); - session[fd]->client_addr = 0; // just listens - session[fd]->rdata_tick = 0; // disable timeouts on this socket + sockt->session[fd]->client_addr = 0; // just listens + sockt->session[fd]->rdata_tick = 0; // disable timeouts on this socket return fd; } @@ -600,73 +599,73 @@ int make_connection(uint32 ip, uint16 port, struct hSockOpt *opt) { return -1; } //Now the socket can be made non-blocking. [Skotlex] - set_nonblocking(fd, 1); + sockt->set_nonblocking(fd, 1); if (sockt->fd_max <= fd) sockt->fd_max = fd + 1; sFD_SET(fd,&readfds); create_session(fd, recv_to_fifo, send_from_fifo, default_func_parse); - session[fd]->client_addr = ntohl(remote_address.sin_addr.s_addr); + sockt->session[fd]->client_addr = ntohl(remote_address.sin_addr.s_addr); return fd; } static int create_session(int fd, RecvFunc func_recv, SendFunc func_send, ParseFunc func_parse) { - CREATE(session[fd], struct socket_data, 1); - CREATE(session[fd]->rdata, unsigned char, RFIFO_SIZE); - CREATE(session[fd]->wdata, unsigned char, WFIFO_SIZE); - session[fd]->max_rdata = RFIFO_SIZE; - session[fd]->max_wdata = WFIFO_SIZE; - session[fd]->func_recv = func_recv; - session[fd]->func_send = func_send; - session[fd]->func_parse = func_parse; - session[fd]->rdata_tick = sockt->last_tick; - session[fd]->session_data = NULL; - session[fd]->hdata = NULL; - session[fd]->hdatac = 0; + CREATE(sockt->session[fd], struct socket_data, 1); + CREATE(sockt->session[fd]->rdata, unsigned char, RFIFO_SIZE); + CREATE(sockt->session[fd]->wdata, unsigned char, WFIFO_SIZE); + sockt->session[fd]->max_rdata = RFIFO_SIZE; + sockt->session[fd]->max_wdata = WFIFO_SIZE; + sockt->session[fd]->func_recv = func_recv; + sockt->session[fd]->func_send = func_send; + sockt->session[fd]->func_parse = func_parse; + sockt->session[fd]->rdata_tick = sockt->last_tick; + sockt->session[fd]->session_data = NULL; + sockt->session[fd]->hdata = NULL; + sockt->session[fd]->hdatac = 0; return 0; } static void delete_session(int fd) { - if( sockt->session_isValid(fd) ) { + if (sockt->session_is_valid(fd)) { #ifdef SHOW_SERVER_STATS - socket_data_qi -= session[fd]->rdata_size - session[fd]->rdata_pos; - socket_data_qo -= session[fd]->wdata_size; + socket_data_qi -= sockt->session[fd]->rdata_size - sockt->session[fd]->rdata_pos; + socket_data_qo -= sockt->session[fd]->wdata_size; #endif - aFree(session[fd]->rdata); - aFree(session[fd]->wdata); - if( session[fd]->session_data ) - aFree(session[fd]->session_data); - if (session[fd]->hdata) { + aFree(sockt->session[fd]->rdata); + aFree(sockt->session[fd]->wdata); + if( sockt->session[fd]->session_data ) + aFree(sockt->session[fd]->session_data); + if (sockt->session[fd]->hdata) { unsigned int i; - for(i = 0; i < session[fd]->hdatac; i++) { - if( session[fd]->hdata[i]->flag.free ) { - aFree(session[fd]->hdata[i]->data); + for(i = 0; i < sockt->session[fd]->hdatac; i++) { + if( sockt->session[fd]->hdata[i]->flag.free ) { + aFree(sockt->session[fd]->hdata[i]->data); } - aFree(session[fd]->hdata[i]); + aFree(sockt->session[fd]->hdata[i]); } - aFree(session[fd]->hdata); + aFree(sockt->session[fd]->hdata); } - aFree(session[fd]); - session[fd] = NULL; + aFree(sockt->session[fd]); + sockt->session[fd] = NULL; } } int realloc_fifo(int fd, unsigned int rfifo_size, unsigned int wfifo_size) { - if( !sockt->session_isValid(fd) ) + if (!sockt->session_is_valid(fd)) return 0; - if( session[fd]->max_rdata != rfifo_size && session[fd]->rdata_size < rfifo_size) { - RECREATE(session[fd]->rdata, unsigned char, rfifo_size); - session[fd]->max_rdata = rfifo_size; + if( sockt->session[fd]->max_rdata != rfifo_size && sockt->session[fd]->rdata_size < rfifo_size) { + RECREATE(sockt->session[fd]->rdata, unsigned char, rfifo_size); + sockt->session[fd]->max_rdata = rfifo_size; } - if( session[fd]->max_wdata != wfifo_size && session[fd]->wdata_size < wfifo_size) { - RECREATE(session[fd]->wdata, unsigned char, wfifo_size); - session[fd]->max_wdata = wfifo_size; + if( sockt->session[fd]->max_wdata != wfifo_size && sockt->session[fd]->wdata_size < wfifo_size) { + RECREATE(sockt->session[fd]->wdata, unsigned char, wfifo_size); + sockt->session[fd]->max_wdata = wfifo_size; } return 0; } @@ -675,38 +674,38 @@ int realloc_writefifo(int fd, size_t addition) { size_t newsize; - if( !sockt->session_isValid(fd) ) // might not happen + if (!sockt->session_is_valid(fd)) // might not happen return 0; - if (session[fd]->wdata_size + addition > session[fd]->max_wdata) { + if (sockt->session[fd]->wdata_size + addition > sockt->session[fd]->max_wdata) { // grow rule; grow in multiples of WFIFO_SIZE newsize = WFIFO_SIZE; - while( session[fd]->wdata_size + addition > newsize ) newsize += WFIFO_SIZE; - } else if (session[fd]->max_wdata >= (size_t)2*(session[fd]->flag.server?FIFOSIZE_SERVERLINK:WFIFO_SIZE) - && (session[fd]->wdata_size+addition)*4 < session[fd]->max_wdata + while( sockt->session[fd]->wdata_size + addition > newsize ) newsize += WFIFO_SIZE; + } else if (sockt->session[fd]->max_wdata >= (size_t)2*(sockt->session[fd]->flag.server?FIFOSIZE_SERVERLINK:WFIFO_SIZE) + && (sockt->session[fd]->wdata_size+addition)*4 < sockt->session[fd]->max_wdata ) { // shrink rule, shrink by 2 when only a quarter of the fifo is used, don't shrink below nominal size. - newsize = session[fd]->max_wdata / 2; + newsize = sockt->session[fd]->max_wdata / 2; } else { // no change return 0; } - RECREATE(session[fd]->wdata, unsigned char, newsize); - session[fd]->max_wdata = newsize; + RECREATE(sockt->session[fd]->wdata, unsigned char, newsize); + sockt->session[fd]->max_wdata = newsize; return 0; } /// advance the RFIFO cursor (marking 'len' bytes as processed) -int RFIFOSKIP(int fd, size_t len) +int rfifoskip(int fd, size_t len) { struct socket_data *s; - if ( !sockt->session_isActive(fd) ) + if (!sockt->session_is_active(fd)) return 0; - s = session[fd]; + s = sockt->session[fd]; if (s->rdata_size < s->rdata_pos + len) { ShowError("RFIFOSKIP: skipped past end of read buffer! Adjusting from %"PRIuS" to %"PRIuS" (session #%d)\n", len, RFIFOREST(fd), fd); @@ -721,12 +720,12 @@ int RFIFOSKIP(int fd, size_t len) } /// advance the WFIFO cursor (marking 'len' bytes for sending) -int WFIFOSET(int fd, size_t len) +int wfifoset(int fd, size_t len) { size_t newreserve; - struct socket_data* s = session[fd]; + struct socket_data* s = sockt->session[fd]; - if( !sockt->session_isValid(fd) || s->wdata == NULL ) + if (!sockt->session_is_valid(fd) || s->wdata == NULL) return 0; // we have written len bytes to the buffer already before calling WFIFOSET @@ -770,14 +769,14 @@ int WFIFOSET(int fd, size_t len) #endif //If the interserver has 200% of its normal size full, flush the data. if( s->flag.server && s->wdata_size >= 2*FIFOSIZE_SERVERLINK ) - flush_fifo(fd); + sockt->flush(fd); // always keep a WFIFO_SIZE reserve in the buffer // For inter-server connections, let the reserve be 1/4th of the link size. newreserve = s->flag.server ? FIFOSIZE_SERVERLINK / 4 : WFIFO_SIZE; // readjust the buffer to include the chosen reserve - realloc_writefifo(fd, newreserve); + sockt->realloc_writefifo(fd, newreserve); #ifdef SEND_SHORTLIST send_shortlist_add_fd(fd); @@ -799,11 +798,11 @@ int do_sockets(int next) #else for (i = 1; i < sockt->fd_max; i++) { - if(!session[i]) + if(!sockt->session[fd] continue; - if(session[i]->wdata_size) - session[i]->func_send(i); + if(sockt->session[fd]>wdata_size) + sockt->session[fd]>func_send(i); } #endif @@ -831,16 +830,16 @@ int do_sockets(int next) for( i = 0; i < (int)rfd.fd_count; ++i ) { int fd = sock2fd(rfd.fd_array[i]); - if( session[fd] ) - session[fd]->func_recv(fd); + if( sockt->session[fd] ) + sockt->session[fd]->func_recv(fd); } #else // otherwise assume that the fd_set is a bit-array and enumerate it in a standard way for( i = 1; ret && i < sockt->fd_max; ++i ) { - if(sFD_ISSET(i,&rfd) && session[i]) + if(sFD_ISSET(i,&rfd) && sockt->session[i]) { - session[i]->func_recv(i); + sockt->session[i]->func_recv(i); --ret; } } @@ -852,15 +851,15 @@ int do_sockets(int next) #else for (i = 1; i < sockt->fd_max; i++) { - if(!session[i]) + if(!sockt->session[i]) continue; - if(session[i]->wdata_size) - session[i]->func_send(i); + if(sockt->session[i]->wdata_size) + sockt->session[i]->func_send(i); - if (session[i]->flag.eof) { //func_send can't free a session, this is safe. + if (sockt->session[i]->flag.eof) { //func_send can't free a session, this is safe. //Finally, even if there is no data to parse, connections signaled eof should be closed, so we call parse_func [Skotlex] - session[i]->func_parse(i); //This should close the session immediately. + sockt->session[i]->func_parse(i); //This should close the session immediately. } } #endif @@ -868,32 +867,32 @@ int do_sockets(int next) // parse input data on each socket for(i = 1; i < sockt->fd_max; i++) { - if(!session[i]) + if(!sockt->session[i]) continue; - if (session[i]->rdata_tick && DIFF_TICK(sockt->last_tick, session[i]->rdata_tick) > sockt->stall_time) { - if( session[i]->flag.server ) {/* server is special */ - if( session[i]->flag.ping != 2 )/* only update if necessary otherwise it'd resend the ping unnecessarily */ - session[i]->flag.ping = 1; + if (sockt->session[i]->rdata_tick && DIFF_TICK(sockt->last_tick, sockt->session[i]->rdata_tick) > sockt->stall_time) { + if( sockt->session[i]->flag.server ) {/* server is special */ + if( sockt->session[i]->flag.ping != 2 )/* only update if necessary otherwise it'd resend the ping unnecessarily */ + sockt->session[i]->flag.ping = 1; } else { ShowInfo("Session #%d timed out\n", i); - set_eof(i); + sockt->eof(i); } } #ifdef __clang_analyzer__ - // Let Clang's static analyzer know this never happens (it thinks it might because of a NULL check in session_isValid) - if (!session[i]) continue; + // Let Clang's static analyzer know this never happens (it thinks it might because of a NULL check in session_is_valid) + if (!sockt->session[i]) continue; #endif // __clang_analyzer__ - session[i]->func_parse(i); + sockt->session[i]->func_parse(i); - if(!session[i]) + if(!sockt->session[i]) continue; RFIFOFLUSH(i); // 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 == session[i]->max_rdata) { - set_eof(i); + if (sockt->session[i]->rdata_size == sockt->session[i]->max_rdata) { + sockt->eof(i); continue; } } @@ -1065,12 +1064,12 @@ static int connect_check_clear(int tid, int64 tick, int id, intptr_t data) { int list = 0; ConnectHistory *hist = NULL; DBIterator *iter; - + if( !db_size(connect_history) ) return 0; - + iter = db_iterator(connect_history); - + for( hist = dbi_first(iter); dbi_exists(iter); hist = dbi_next(iter) ){ if( (!hist->ddos && DIFF_TICK(tick,hist->tick) > ddos_interval*3) || (hist->ddos && DIFF_TICK(tick,hist->tick) > ddos_autoreset) ) @@ -1080,13 +1079,12 @@ static int connect_check_clear(int tid, int64 tick, int id, intptr_t data) { } list++; } - dbi_destroy(iter); - + if( access_debug ){ ShowInfo("connect_check_clear: Cleared %d of %d from IP list.\n", clear, list); } - + return list; } @@ -1205,7 +1203,6 @@ int socket_config_read(const char* cfgName) return 0; } - void socket_final(void) { int i; @@ -1219,28 +1216,43 @@ void socket_final(void) #endif for( i = 1; i < sockt->fd_max; i++ ) - if(session[i]) + if(sockt->session[i]) sockt->close(i); - // session[0] - aFree(session[0]->rdata); - aFree(session[0]->wdata); - aFree(session[0]); + // sockt->session[0] + aFree(sockt->session[0]->rdata); + aFree(sockt->session[0]->wdata); + aFree(sockt->session[0]); + + aFree(sockt->session); + + if (sockt->lan_subnet) + aFree(sockt->lan_subnet); + sockt->lan_subnet = NULL; + sockt->lan_subnet_count = 0; - aFree(session); + if (sockt->allowed_ip) + aFree(sockt->allowed_ip); + sockt->allowed_ip = NULL; + sockt->allowed_ip_count = 0; + + if (sockt->trusted_ip) + aFree(sockt->trusted_ip); + sockt->trusted_ip = NULL; + sockt->trusted_ip_count = 0; } /// Closes a socket. -void do_close(int fd) +void socket_close(int fd) { if( fd <= 0 ||fd >= FD_SETSIZE ) return;// invalid - flush_fifo(fd); // Try to send what's left (although it might not succeed since it's a nonblocking socket) + sockt->flush(fd); // Try to send what's left (although it might not succeed since it's a nonblocking socket) sFD_CLR(fd, &readfds);// this needs to be done before closing the socket sShutdown(fd, SHUT_RDWR); // Disallow further reads/writes sClose(fd); // We don't really care if these closing functions return an error, we are just shutting down and not reusing this socket. - if (session[fd]) delete_session(fd); + if (sockt->session[fd]) delete_session(fd); } /// Retrieve local ips in host byte order. @@ -1377,21 +1389,21 @@ void socket_init(void) #endif // Get initial local ips - sockt->naddr_ = socket_getips(sockt->addr_,16); + sockt->naddr_ = sockt->getips(sockt->addr_,16); sFD_ZERO(&readfds); #if defined(SEND_SHORTLIST) memset(send_shortlist_set, 0, sizeof(send_shortlist_set)); #endif - CREATE(session, struct socket_data *, FD_SETSIZE); + CREATE(sockt->session, struct socket_data *, FD_SETSIZE); socket_config_read(SOCKET_CONF_FILENAME); // initialize last send-receive tick sockt->last_tick = time(NULL); - // session[0] is now currently used for disconnected sessions of the map server, and as such, + // sockt->session[0] is now currently used for disconnected sessions of the map server, and as such, // should hold enough buffer (it is a vacuum so to speak) as it is never flushed. [Skotlex] create_session(0, null_recv, null_send, null_parse); @@ -1403,19 +1415,16 @@ void socket_init(void) #endif ShowInfo("Server supports up to '"CL_WHITE"%"PRId64""CL_RESET"' concurrent connections.\n", rlim_cur); - - /* Hercules Plugin Manager */ - HPM->share(session,"session"); } -bool session_isValid(int fd) +bool session_is_valid(int fd) { - return ( fd > 0 && fd < FD_SETSIZE && session[fd] != NULL ); + return ( fd > 0 && fd < FD_SETSIZE && sockt->session[fd] != NULL ); } -bool session_isActive(int fd) +bool session_is_active(int fd) { - return ( sockt->session_isValid(fd) && !session[fd]->flag.eof ); + return ( sockt->session_is_valid(fd) && !sockt->session[fd]->flag.eof ); } // Resolves hostname into a numeric ip. @@ -1425,9 +1434,15 @@ uint32 host2ip(const char* hostname) return (h != NULL) ? ntohl(*(uint32*)h->h_addr) : 0; } -// Converts a numeric ip into a dot-formatted string. -// Result is placed either into a user-provided buffer or a static system buffer. -const char* ip2str(uint32 ip, char ip_str[16]) +/** + * Converts a numeric ip into a dot-formatted string. + * + * @param ip Numeric IP to convert. + * @param ip_str Output buffer, optional (if provided, must have size greater or equal to 16). + * + * @return A pointer to the output string. + */ +const char *ip2str(uint32 ip, char *ip_str) { struct in_addr addr; addr.s_addr = htonl(ip); @@ -1502,7 +1517,7 @@ void socket_datasync(int fd, bool send) { WFIFOW(fd, 2) = 8; WFIFOL(fd, 4) = 0; WFIFOSET(fd, 8); - flush_fifo(fd); + sockt->flush(fd); /* shut down */ ShowFatalError("Servers are out of sync! recompile from scratch (%d)\n",i); exit(EXIT_FAILURE); @@ -1519,7 +1534,7 @@ void send_shortlist_add_fd(int fd) int i; int bit; - if( !sockt->session_isValid(fd) ) + if (!sockt->session_is_valid(fd)) return;// out of range i = fd/32; @@ -1569,26 +1584,184 @@ void send_shortlist_do_sends() send_shortlist_set[idx]&=~(1<<bit);// unset fd // If this session still exists, perform send operations on it and // check for the eof state. - if( session[fd] ) + if( sockt->session[fd] ) { // Send data - if( session[fd]->wdata_size ) - session[fd]->func_send(fd); + if( sockt->session[fd]->wdata_size ) + sockt->session[fd]->func_send(fd); // If it's been marked as eof, call the parse func on it so that // the socket will be immediately closed. - if( session[fd]->flag.eof ) - session[fd]->func_parse(fd); + if( sockt->session[fd]->flag.eof ) + sockt->session[fd]->func_parse(fd); // If the session still exists, is not eof and has things left to // be sent from it we'll re-add it to the shortlist. - if( session[fd] && !session[fd]->flag.eof && session[fd]->wdata_size ) + if( sockt->session[fd] && !sockt->session[fd]->flag.eof && sockt->session[fd]->wdata_size ) send_shortlist_add_fd(fd); } } } #endif +/** + * Checks whether the given IP comes from LAN or WAN. + * + * @param[in] ip IP address to check. + * @param[out] info Verbose output, if requested. Filled with the matching entry. Ignored if NULL. + * @retval 0 if it is a WAN IP. + * @return the appropriate LAN server address to send, if it is a LAN IP. + */ +uint32 socket_lan_subnet_check(uint32 ip, struct s_subnet *info) +{ + int i; + ARR_FIND(0, sockt->lan_subnet_count, i, (sockt->lan_subnet[i].ip & sockt->lan_subnet[i].mask) == (ip & sockt->lan_subnet[i].mask)); + if (i < sockt->lan_subnet_count) { + if (info) { + info->ip = sockt->lan_subnet[i].ip; + info->mask = sockt->lan_subnet[i].mask; + } + return sockt->lan_subnet[i].ip; + } + if (info) { + info->ip = info->mask = 0; + } + return 0; +} + +/** + * Checks whether the given IP is allowed to connect as a server. + * + * @param ip IP address to check. + * @retval true if we allow server connections from the given IP. + * @retval false otherwise. + */ +bool socket_allowed_ip_check(uint32 ip) +{ + int i; + ARR_FIND(0, sockt->allowed_ip_count, i, (sockt->allowed_ip[i].ip & sockt->allowed_ip[i].mask) == (ip & sockt->allowed_ip[i].mask) ); + if (i < sockt->allowed_ip_count) + return true; + return sockt->trusted_ip_check(ip); // If an address is trusted, it's automatically also allowed. +} + +/** + * Checks whether the given IP is trusted and can skip ipban checks. + * + * @param ip IP address to check. + * @retval true if we trust the given IP. + * @retval false otherwise. + */ +bool socket_trusted_ip_check(uint32 ip) +{ + int i; + ARR_FIND(0, sockt->trusted_ip_count, i, (sockt->trusted_ip[i].ip & sockt->trusted_ip[i].mask) == (ip & sockt->trusted_ip[i].mask)); + if (i < sockt->trusted_ip_count) + return true; + return false; +} + +/** + * Helper function to read a list of network.conf values. + * + * Entries will be appended to the variable-size array pointed to by list/count. + * + * @param[in] t The list to parse. + * @param[in,out] list Pointer to the head of the output array to append to. Must not be NULL (but the array may be empty). + * @param[in,out] count Pointer to the counter of the output array to append to. Must not be NULL (but it may contain zero). + * @param[in] filename Current filename, for output/logging reasons. + * @param[in] groupname Current group name, for output/logging reasons. + * @return The amount of entries read, zero in case of errors. + */ +int socket_net_config_read_sub(config_setting_t *t, struct s_subnet **list, int *count, const char *filename, const char *groupname) +{ + int i, len; + char ipbuf[64], maskbuf[64]; + + nullpo_retr(0, list); + nullpo_retr(0, count); + + if (t == NULL) + return 0; + + len = libconfig->setting_length(t); + + for (i = 0; i < len; ++i) { + const char *subnet = libconfig->setting_get_string_elem(t, i); + struct s_subnet *l = NULL; + + if (sscanf(subnet, "%63[^:]:%63[^:]", ipbuf, maskbuf) != 2) { + ShowWarning("Invalid IP:Subnet entry in configuration file %s: '%s' (%s)\n", filename, subnet, groupname); + } + RECREATE(*list, struct s_subnet, *count + 1); + l = *list; + l[*count].ip = sockt->str2ip(ipbuf); + l[*count].mask = sockt->str2ip(maskbuf); + ++*count; + } + return *count; +} + +/** + * Reads the network configuration file. + * + * @param filename The filename to read from. + */ +void socket_net_config_read(const char *filename) +{ + config_t network_config; + int i; + nullpo_retv(filename); + + if (libconfig->read_file(&network_config, filename)) { + ShowError("LAN Support configuration file is not found: '%s'. This server won't be able to accept connections from any servers.\n", filename); + return; + } + + if (sockt->lan_subnet) { + aFree(sockt->lan_subnet); + sockt->lan_subnet = NULL; + } + sockt->lan_subnet_count = 0; + if (sockt->net_config_read_sub(libconfig->lookup(&network_config, "lan_subnets"), &sockt->lan_subnet, &sockt->lan_subnet_count, filename, "lan_subnets") > 0) + ShowStatus("Read information about %d LAN subnets.\n", sockt->lan_subnet_count); + + if (sockt->trusted_ip) { + aFree(sockt->trusted_ip); + sockt->trusted_ip = NULL; + } + sockt->trusted_ip_count = 0; + if (sockt->net_config_read_sub(libconfig->lookup(&network_config, "trusted"), &sockt->trusted_ip, &sockt->trusted_ip_count, filename, "trusted") > 0) + ShowStatus("Read information about %d trusted IP ranges.\n", sockt->trusted_ip_count); + for (i = 0; i < sockt->allowed_ip_count; ++i) { + if ((sockt->allowed_ip[i].ip & sockt->allowed_ip[i].mask) == 0) { + ShowError("Using a wildcard IP range in the trusted server IPs is NOT RECOMMENDED.\n"); + ShowNotice("Please edit your '%s' trusted list to fit your network configuration.\n", filename); + break; + } + } + + if (sockt->allowed_ip) { + aFree(sockt->allowed_ip); + sockt->allowed_ip = NULL; + } + sockt->allowed_ip_count = 0; + if (sockt->net_config_read_sub(libconfig->lookup(&network_config, "allowed"), &sockt->allowed_ip, &sockt->allowed_ip_count, filename, "allowed") > 0) + ShowStatus("Read information about %d allowed server IP ranges.\n", sockt->allowed_ip_count); + if (sockt->allowed_ip_count == 0) { + ShowError("No allowed server IP ranges configured. This server won't be able to accept connections from any char servers.\n"); + } + for (i = 0; i < sockt->allowed_ip_count; ++i) { + if ((sockt->allowed_ip[i].ip & sockt->allowed_ip[i].mask) == 0) { + ShowWarning("Using a wildcard IP range in the allowed server IPs is NOT RECOMMENDED.\n"); + ShowNotice("Please edit your '%s' allowed list to fit your network configuration.\n", filename); + break; + } + } + libconfig->destroy(&network_config); + return; +} + void socket_defaults(void) { sockt = &sockt_s; @@ -1600,6 +1773,13 @@ void socket_defaults(void) { memset(&sockt->addr_, 0, sizeof(sockt->addr_)); sockt->naddr_ = 0; /* */ + sockt->lan_subnet_count = 0; + sockt->lan_subnet = NULL; + sockt->allowed_ip_count = 0; + sockt->allowed_ip = NULL; + sockt->trusted_ip_count = 0; + sockt->trusted_ip = NULL; + sockt->init = socket_init; sockt->final = socket_final; /* */ @@ -1611,14 +1791,14 @@ void socket_defaults(void) { sockt->make_connection = make_connection; sockt->realloc_fifo = realloc_fifo; sockt->realloc_writefifo = realloc_writefifo; - sockt->WFIFOSET = WFIFOSET; - sockt->RFIFOSKIP = RFIFOSKIP; - sockt->close = do_close; + sockt->wfifoset = wfifoset; + sockt->rfifoskip = rfifoskip; + sockt->close = socket_close; /* */ - sockt->session_isValid = session_isValid; - sockt->session_isActive = session_isActive; + sockt->session_is_valid = session_is_valid; + sockt->session_is_active = session_is_active; /* */ - sockt->flush_fifo = flush_fifo; + sockt->flush = flush_fifo; sockt->flush_fifos = flush_fifos; sockt->set_nonblocking = set_nonblocking; sockt->set_defaultparse = set_defaultparse; @@ -1627,5 +1807,11 @@ void socket_defaults(void) { sockt->str2ip = str2ip; sockt->ntows = ntows; sockt->getips = socket_getips; - sockt->set_eof = set_eof; + sockt->eof = set_eof; + + sockt->lan_subnet_check = socket_lan_subnet_check; + sockt->allowed_ip_check = socket_allowed_ip_check; + sockt->trusted_ip_check = socket_trusted_ip_check; + sockt->net_config_read_sub = socket_net_config_read_sub; + sockt->net_config_read = socket_net_config_read; } diff --git a/src/common/socket.h b/src/common/socket.h index 6323a6862..a995bffc8 100644 --- a/src/common/socket.h +++ b/src/common/socket.h @@ -5,12 +5,11 @@ #ifndef COMMON_SOCKET_H #define COMMON_SOCKET_H -#include <time.h> - -#include "../common/cbasetypes.h" +#include "common/hercules.h" +#include "common/conf.h" #ifdef WIN32 -# include "../common/winapi.h" +# include "common/winapi.h" typedef long in_addr_t; #else # include <netinet/in.h> @@ -24,9 +23,14 @@ struct HPluginData; // socket I/O macros #define RFIFOHEAD(fd) -#define WFIFOHEAD(fd, size) do{ if((fd) && session[fd]->wdata_size + (size) > session[fd]->max_wdata ) realloc_writefifo((fd), (size)); }while(0) -#define RFIFOP(fd,pos) (session[fd]->rdata + session[fd]->rdata_pos + (pos)) -#define WFIFOP(fd,pos) (session[fd]->wdata + session[fd]->wdata_size + (pos)) +#define WFIFOHEAD(fd, size) \ + do{ \ + if ((fd) && sockt->session[fd]->wdata_size + (size) > sockt->session[fd]->max_wdata) \ + sockt->realloc_writefifo((fd), (size)); \ + } while(0) + +#define RFIFOP(fd,pos) (sockt->session[fd]->rdata + sockt->session[fd]->rdata_pos + (pos)) +#define WFIFOP(fd,pos) (sockt->session[fd]->wdata + sockt->session[fd]->wdata_size + (pos)) #define RFIFOB(fd,pos) (*(uint8*)RFIFOP((fd),(pos))) #define WFIFOB(fd,pos) (*(uint8*)WFIFOP((fd),(pos))) @@ -36,23 +40,26 @@ struct HPluginData; #define WFIFOL(fd,pos) (*(uint32*)WFIFOP((fd),(pos))) #define RFIFOQ(fd,pos) (*(uint64*)RFIFOP((fd),(pos))) #define WFIFOQ(fd,pos) (*(uint64*)WFIFOP((fd),(pos))) -#define RFIFOSPACE(fd) (session[fd]->max_rdata - session[fd]->rdata_size) -#define WFIFOSPACE(fd) (session[fd]->max_wdata - session[fd]->wdata_size) +#define RFIFOSPACE(fd) (sockt->session[fd]->max_rdata - sockt->session[fd]->rdata_size) +#define WFIFOSPACE(fd) (sockt->session[fd]->max_wdata - sockt->session[fd]->wdata_size) -#define RFIFOREST(fd) (session[fd]->flag.eof ? 0 : session[fd]->rdata_size - session[fd]->rdata_pos) +#define RFIFOREST(fd) (sockt->session[fd]->flag.eof ? 0 : sockt->session[fd]->rdata_size - sockt->session[fd]->rdata_pos) #define RFIFOFLUSH(fd) \ do { \ - if(session[fd]->rdata_size == session[fd]->rdata_pos){ \ - session[fd]->rdata_size = session[fd]->rdata_pos = 0; \ + if(sockt->session[fd]->rdata_size == sockt->session[fd]->rdata_pos){ \ + sockt->session[fd]->rdata_size = sockt->session[fd]->rdata_pos = 0; \ } else { \ - session[fd]->rdata_size -= session[fd]->rdata_pos; \ - memmove(session[fd]->rdata, session[fd]->rdata+session[fd]->rdata_pos, session[fd]->rdata_size); \ - session[fd]->rdata_pos = 0; \ + sockt->session[fd]->rdata_size -= sockt->session[fd]->rdata_pos; \ + memmove(sockt->session[fd]->rdata, sockt->session[fd]->rdata+sockt->session[fd]->rdata_pos, sockt->session[fd]->rdata_size); \ + sockt->session[fd]->rdata_pos = 0; \ } \ } while(0) +#define WFIFOSET(fd, len) (sockt->wfifoset(fd, len)) +#define RFIFOSKIP(fd, len) (sockt->rfifoskip(fd, len)) + /* [Ind/Hercules] */ -#define RFIFO2PTR(fd) (void*)(session[fd]->rdata + session[fd]->rdata_pos) +#define RFIFO2PTR(fd) (void*)(sockt->session[fd]->rdata + sockt->session[fd]->rdata_pos) // buffer I/O macros #define RBUFP(p,pos) (((uint8*)(p)) + (pos)) @@ -107,6 +114,12 @@ struct hSockOpt { unsigned int setTimeo : 1; }; +/// Subnet/IP range in the IP/Mask format. +struct s_subnet { + uint32 ip; + uint32 mask; +}; + /// Use a shortlist of sockets instead of iterating all sessions for sockets /// that have data to send or need eof handling. /// Adapted to use a static array instead of a linked list. @@ -119,11 +132,6 @@ struct hSockOpt { #define MAKEIP(a,b,c,d) ((uint32)( ( ( (a)&0xFF ) << 24 ) | ( ( (b)&0xFF ) << 16 ) | ( ( (c)&0xFF ) << 8 ) | ( ( (d)&0xFF ) << 0 ) )) /** - * This stays out of the interface. - **/ -struct socket_data **session; - -/** * Socket.c interface, mostly for reading however. **/ struct socket_interface { @@ -134,6 +142,16 @@ struct socket_interface { /* */ uint32 addr_[16]; // ip addresses of local host (host byte order) int naddr_; // # of ip addresses + + struct socket_data **session; + + struct s_subnet *lan_subnet; ///< LAN subnets array + int lan_subnet_count; ///< LAN subnets count + struct s_subnet *trusted_ip; ///< Trusted IP ranges array + int trusted_ip_count; ///< Trusted IP ranges count + struct s_subnet *allowed_ip; ///< Allowed server IP ranges array + int allowed_ip_count; ///< Allowed server IP ranges count + /* */ void (*init) (void); void (*final) (void); @@ -146,56 +164,39 @@ struct socket_interface { int (*make_connection) (uint32 ip, uint16 port, struct hSockOpt *opt); int (*realloc_fifo) (int fd, unsigned int rfifo_size, unsigned int wfifo_size); int (*realloc_writefifo) (int fd, size_t addition); - int (*WFIFOSET) (int fd, size_t len); - int (*RFIFOSKIP) (int fd, size_t len); + int (*wfifoset) (int fd, size_t len); + int (*rfifoskip) (int fd, size_t len); void (*close) (int fd); /* */ - bool (*session_isValid) (int fd); - bool (*session_isActive) (int fd); + bool (*session_is_valid) (int fd); + bool (*session_is_active) (int fd); /* */ - void (*flush_fifo) (int fd); + void (*flush) (int fd); void (*flush_fifos) (void); void (*set_nonblocking) (int fd, unsigned long yes); void (*set_defaultparse) (ParseFunc defaultparse); /* hostname/ip conversion functions */ uint32 (*host2ip) (const char* hostname); - const char * (*ip2str) (uint32 ip, char ip_str[16]); + const char * (*ip2str) (uint32 ip, char *ip_str); uint32 (*str2ip) (const char* ip_str); /* */ uint16 (*ntows) (uint16 netshort); /* */ int (*getips) (uint32* ips, int max); /* */ - void (*set_eof) (int fd); -}; + void (*eof) (int fd); -struct socket_interface *sockt; + uint32 (*lan_subnet_check) (uint32 ip, struct s_subnet *info); + bool (*allowed_ip_check) (uint32 ip); + bool (*trusted_ip_check) (uint32 ip); + int (*net_config_read_sub) (config_setting_t *t, struct s_subnet **list, int *count, const char *filename, const char *groupname); + void (*net_config_read) (const char *filename); +}; #ifdef HERCULES_CORE void socket_defaults(void); #endif // HERCULES_CORE -/* the purpose of these macros is simply to not make calling them be an annoyance */ -#ifndef H_SOCKET_C - #define make_listen_bind(ip, port) ( sockt->make_listen_bind(ip, port) ) - #define make_connection(ip, port, opt) ( sockt->make_connection(ip, port, opt) ) - #define realloc_fifo(fd, rfifo_size, wfifo_size) ( sockt->realloc_fifo(fd, rfifo_size, wfifo_size) ) - #define realloc_writefifo(fd, addition) ( sockt->realloc_writefifo(fd, addition) ) - #define WFIFOSET(fd, len) ( sockt->WFIFOSET(fd, len) ) - #define RFIFOSKIP(fd, len) ( sockt->RFIFOSKIP(fd, len) ) - #define do_close(fd) ( sockt->close(fd) ) - #define session_isValid(fd) ( sockt->session_isValid(fd) ) - #define session_isActive(fd) ( sockt->session_isActive(fd) ) - #define flush_fifo(fd) ( sockt->flush_fifo(fd) ) - #define flush_fifos() ( sockt->flush_fifos() ) - #define set_nonblocking(fd, yes) ( sockt->set_nonblocking(fd, yes) ) - #define set_defaultparse(defaultparse) ( sockt->set_defaultparse(defaultparse) ) - #define host2ip(hostname) ( sockt->host2ip(hostname) ) - #define ip2str(ip, ip_str) ( sockt->ip2str(ip, ip_str) ) - #define str2ip(ip_str) ( sockt->str2ip(ip_str) ) - #define ntows(netshort) ( sockt->ntows(netshort) ) - #define getips(ips, max) ( sockt->getips(ips, max) ) - #define set_eof(fd) ( sockt->set_eof(fd) ) -#endif /* H_SOCKET_C */ +HPShared struct socket_interface *sockt; #endif /* COMMON_SOCKET_H */ diff --git a/src/common/spinlock.h b/src/common/spinlock.h index 413067b68..811b239df 100644 --- a/src/common/spinlock.h +++ b/src/common/spinlock.h @@ -14,12 +14,12 @@ // // -#include "../common/atomic.h" -#include "../common/cbasetypes.h" -#include "../common/thread.h" +#include "common/atomic.h" +#include "common/cbasetypes.h" +#include "common/thread.h" #ifdef WIN32 -#include "../common/winapi.h" +#include "common/winapi.h" #endif #ifdef WIN32 diff --git a/src/common/sql.c b/src/common/sql.c index 4ca14d43b..ee759eb61 100644 --- a/src/common/sql.c +++ b/src/common/sql.c @@ -6,19 +6,17 @@ #include "sql.h" -#include <stdlib.h> // strtoul -#include <string.h> // strlen/strnlen/memcpy/memset - -#include "../common/cbasetypes.h" -#include "../common/malloc.h" -#include "../common/showmsg.h" -#include "../common/strlib.h" -#include "../common/timer.h" +#include "common/cbasetypes.h" +#include "common/malloc.h" +#include "common/showmsg.h" +#include "common/strlib.h" +#include "common/timer.h" #ifdef WIN32 -# include "../common/winapi.h" // Needed before mysql.h +# include "common/winapi.h" // Needed before mysql.h #endif #include <mysql.h> +#include <stdlib.h> // strtoul void hercules_mysql_error_handler(unsigned int ecode); @@ -26,6 +24,7 @@ int mysql_reconnect_type; unsigned int mysql_reconnect_count; struct sql_interface sql_s; +struct sql_interface *SQL; /// Sql handle struct Sql { @@ -37,8 +36,6 @@ struct Sql { int keepalive; }; - - // Column length receiver. // Takes care of the possible size mismatch between uint32 and unsigned long. struct s_column_length { @@ -47,8 +44,6 @@ struct s_column_length { }; typedef struct s_column_length s_column_length; - - /// Sql statement struct SqlStmt { StringBuf buf; @@ -62,14 +57,10 @@ struct SqlStmt { bool bind_columns; }; - - /////////////////////////////////////////////////////////////////////////////// // Sql Handle /////////////////////////////////////////////////////////////////////////////// - - /// Allocates and initializes a new Sql handle. Sql* Sql_Malloc(void) { @@ -85,8 +76,6 @@ Sql* Sql_Malloc(void) return self; } - - static int Sql_P_Keepalive(Sql* self); /// Establishes a connection. @@ -112,8 +101,6 @@ int Sql_Connect(Sql* self, const char* user, const char* passwd, const char* hos return SQL_SUCCESS; } - - /// Retrieves the timeout of the connection. int Sql_GetTimeout(Sql* self, uint32* out_timeout) { @@ -131,8 +118,6 @@ int Sql_GetTimeout(Sql* self, uint32* out_timeout) return SQL_ERROR; } - - /// Retrieves the name of the columns of a table into out_buf, with the separator after each name. int Sql_GetColumnNames(Sql* self, const char* table, char* out_buf, size_t buf_len, char sep) { @@ -161,8 +146,6 @@ int Sql_GetColumnNames(Sql* self, const char* table, char* out_buf, size_t buf_l return SQL_SUCCESS; } - - /// Changes the encoding of the connection. int Sql_SetEncoding(Sql* self, const char* encoding) { @@ -171,8 +154,6 @@ int Sql_SetEncoding(Sql* self, const char* encoding) return SQL_ERROR; } - - /// Pings the connection. int Sql_Ping(Sql* self) { @@ -181,8 +162,6 @@ int Sql_Ping(Sql* self) return SQL_ERROR; } - - /// Wrapper function for Sql_Ping. /// /// @private @@ -194,8 +173,6 @@ static int Sql_P_KeepaliveTimer(int tid, int64 tick, int id, intptr_t data) return 0; } - - /// Establishes keepalive (periodic ping) on the connection. /// /// @return the keepalive timer id, or INVALID_TIMER @@ -219,8 +196,6 @@ static int Sql_P_Keepalive(Sql* self) return timer->add_interval(timer->gettick() + ping_interval*1000, Sql_P_KeepaliveTimer, 0, (intptr_t)self, ping_interval*1000); } - - /// Escapes a string. size_t Sql_EscapeString(Sql* self, char *out_to, const char *from) { @@ -230,8 +205,6 @@ size_t Sql_EscapeString(Sql* self, char *out_to, const char *from) return (size_t)mysql_escape_string(out_to, from, (unsigned long)strlen(from)); } - - /// Escapes a string. size_t Sql_EscapeStringLen(Sql* self, char *out_to, const char *from, size_t from_len) { @@ -241,8 +214,6 @@ size_t Sql_EscapeStringLen(Sql* self, char *out_to, const char *from, size_t fro return (size_t)mysql_escape_string(out_to, from, (unsigned long)from_len); } - - /// Executes a query. int Sql_Query(Sql *self, const char *query, ...) __attribute__((format(printf, 2, 3))); int Sql_Query(Sql *self, const char *query, ...) { @@ -256,8 +227,6 @@ int Sql_Query(Sql *self, const char *query, ...) { return res; } - - /// Executes a query. int Sql_QueryV(Sql* self, const char* query, va_list args) { @@ -283,8 +252,6 @@ int Sql_QueryV(Sql* self, const char* query, va_list args) return SQL_SUCCESS; } - - /// Executes a query. int Sql_QueryStr(Sql* self, const char* query) { @@ -310,8 +277,6 @@ int Sql_QueryStr(Sql* self, const char* query) return SQL_SUCCESS; } - - /// Returns the number of the AUTO_INCREMENT column of the last INSERT/UPDATE query. uint64 Sql_LastInsertId(Sql* self) { @@ -321,8 +286,6 @@ uint64 Sql_LastInsertId(Sql* self) return 0; } - - /// Returns the number of columns in each row of the result. uint32 Sql_NumColumns(Sql* self) { @@ -331,8 +294,6 @@ uint32 Sql_NumColumns(Sql* self) return 0; } - - /// Returns the number of rows in the result. uint64 Sql_NumRows(Sql* self) { @@ -341,8 +302,6 @@ uint64 Sql_NumRows(Sql* self) return 0; } - - /// Fetches the next row. int Sql_NextRow(Sql* self) { if( self && self->result ) { @@ -358,8 +317,6 @@ int Sql_NextRow(Sql* self) { return SQL_ERROR; } - - /// Gets the data of a column. int Sql_GetData(Sql* self, size_t col, char** out_buf, size_t* out_len) { @@ -376,8 +333,6 @@ int Sql_GetData(Sql* self, size_t col, char** out_buf, size_t* out_len) return SQL_ERROR; } - - /// Frees the result of the query. void Sql_FreeResult(Sql* self) { if( self && self->result ) { @@ -388,8 +343,6 @@ void Sql_FreeResult(Sql* self) { } } - - /// Shows debug information (last query). void Sql_ShowDebug_(Sql* self, const char* debug_file, const unsigned long debug_line) { @@ -401,8 +354,6 @@ void Sql_ShowDebug_(Sql* self, const char* debug_file, const unsigned long debug ShowDebug("at %s:%lu\n", debug_file, debug_line); } - - /// Frees a Sql handle returned by Sql_Malloc. void Sql_Free(Sql* self) { if( self ) @@ -415,14 +366,10 @@ void Sql_Free(Sql* self) { } } - - /////////////////////////////////////////////////////////////////////////////// // Prepared Statements /////////////////////////////////////////////////////////////////////////////// - - /// Returns the mysql integer type for the target size. /// /// @private @@ -440,8 +387,6 @@ static enum enum_field_types Sql_P_SizeToMysqlIntType(int sz) } } - - /// Binds a parameter/result. /// /// @private @@ -515,8 +460,6 @@ static int Sql_P_BindSqlDataType(MYSQL_BIND* bind, enum SqlDataType buffer_type, return SQL_SUCCESS; } - - /// Prints debug information about a field (type and length). /// /// @private @@ -552,8 +495,6 @@ static void Sql_P_ShowDebugMysqlFieldInfo(const char* prefix, enum enum_field_ty ShowDebug("%stype=%s%s, length=%lu%s\n", prefix, sign, type_string, length, length_postfix); } - - /// Reports debug information about a truncated column. /// /// @private @@ -576,8 +517,6 @@ static void SqlStmt_P_ShowDebugTruncatedColumn(SqlStmt* self, size_t i) mysql_free_result(meta); } - - /// Allocates and initializes a new SqlStmt handle. SqlStmt* SqlStmt_Malloc(Sql* sql) { SqlStmt* self; @@ -605,8 +544,6 @@ SqlStmt* SqlStmt_Malloc(Sql* sql) { return self; } - - /// Prepares the statement. int SqlStmt_Prepare(SqlStmt *self, const char *query, ...) __attribute__((format(printf, 2, 3))); int SqlStmt_Prepare(SqlStmt *self, const char *query, ...) { @@ -620,8 +557,6 @@ int SqlStmt_Prepare(SqlStmt *self, const char *query, ...) { return res; } - - /// Prepares the statement. int SqlStmt_PrepareV(SqlStmt* self, const char* query, va_list args) { @@ -642,8 +577,6 @@ int SqlStmt_PrepareV(SqlStmt* self, const char* query, va_list args) return SQL_SUCCESS; } - - /// Prepares the statement. int SqlStmt_PrepareStr(SqlStmt* self, const char* query) { @@ -664,8 +597,6 @@ int SqlStmt_PrepareStr(SqlStmt* self, const char* query) return SQL_SUCCESS; } - - /// Returns the number of parameters in the prepared statement. size_t SqlStmt_NumParams(SqlStmt* self) { @@ -675,8 +606,6 @@ size_t SqlStmt_NumParams(SqlStmt* self) return 0; } - - /// Binds a parameter to a buffer. int SqlStmt_BindParam(SqlStmt* self, size_t idx, enum SqlDataType buffer_type, void* buffer, size_t buffer_len) { @@ -705,8 +634,6 @@ int SqlStmt_BindParam(SqlStmt* self, size_t idx, enum SqlDataType buffer_type, v return SQL_SUCCESS;// out of range - ignore } - - /// Executes the prepared statement. int SqlStmt_Execute(SqlStmt* self) { @@ -732,8 +659,6 @@ int SqlStmt_Execute(SqlStmt* self) return SQL_SUCCESS; } - - /// Returns the number of the AUTO_INCREMENT column of the last INSERT/UPDATE statement. uint64 SqlStmt_LastInsertId(SqlStmt* self) { @@ -743,8 +668,6 @@ uint64 SqlStmt_LastInsertId(SqlStmt* self) return 0; } - - /// Returns the number of columns in each row of the result. size_t SqlStmt_NumColumns(SqlStmt* self) { @@ -754,8 +677,6 @@ size_t SqlStmt_NumColumns(SqlStmt* self) return 0; } - - /// Binds the result of a column to a buffer. int SqlStmt_BindColumn(SqlStmt *self, size_t idx, enum SqlDataType buffer_type, void *buffer, size_t buffer_len, uint32 *out_length, int8 *out_is_null) { if (self == NULL) @@ -797,8 +718,6 @@ int SqlStmt_BindColumn(SqlStmt *self, size_t idx, enum SqlDataType buffer_type, } } - - /// Returns the number of rows in the result. uint64 SqlStmt_NumRows(SqlStmt* self) { @@ -808,8 +727,6 @@ uint64 SqlStmt_NumRows(SqlStmt* self) return 0; } - - /// Fetches the next row. int SqlStmt_NextRow(SqlStmt* self) { @@ -893,8 +810,6 @@ int SqlStmt_NextRow(SqlStmt* self) return SQL_SUCCESS; } - - /// Frees the result of the statement execution. void SqlStmt_FreeResult(SqlStmt* self) { @@ -902,8 +817,6 @@ void SqlStmt_FreeResult(SqlStmt* self) mysql_stmt_free_result(self->stmt); } - - /// Shows debug information (with statement). void SqlStmt_ShowDebug_(SqlStmt* self, const char* debug_file, const unsigned long debug_line) { @@ -915,8 +828,6 @@ void SqlStmt_ShowDebug_(SqlStmt* self, const char* debug_file, const unsigned lo ShowDebug("at %s:%lu\n", debug_file, debug_line); } - - /// Frees a SqlStmt returned by SqlStmt_Malloc. void SqlStmt_Free(SqlStmt* self) { diff --git a/src/common/sql.h b/src/common/sql.h index c3598273e..fc1562347 100644 --- a/src/common/sql.h +++ b/src/common/sql.h @@ -5,9 +5,9 @@ #ifndef COMMON_SQL_H #define COMMON_SQL_H -#include <stdarg.h>// va_list +#include "common/hercules.h" -#include "../common/cbasetypes.h" +#include <stdarg.h>// va_list // Return codes #define SQL_ERROR (-1) @@ -142,8 +142,6 @@ struct sql_interface { /// Allocates and initializes a new Sql handle. struct Sql *(*Malloc) (void); - - /////////////////////////////////////////////////////////////////////////////// // Prepared Statements /////////////////////////////////////////////////////////////////////////////// @@ -157,7 +155,6 @@ struct sql_interface { // 1) SELECT col FROM table WHERE id=? // 2) INSERT INTO table(col1,col2) VALUES(?,?) - /*===================================== SQL Statement interface [Susu] *-------------------------------------*/ @@ -169,8 +166,6 @@ struct sql_interface { /// @return SqlStmt handle or NULL if an error occurred struct SqlStmt* (*StmtMalloc)(Sql* sql); - - /// Prepares the statement. /// Any previous result is freed and all parameter bindings are removed. /// The query is constructed as if it was sprintf. @@ -185,8 +180,6 @@ struct sql_interface { /// @return SQL_SUCCESS or SQL_ERROR int (*StmtPrepareV)(SqlStmt* self, const char* query, va_list args); - - /// Prepares the statement. /// Any previous result is freed and all parameter bindings are removed. /// The query is used directly. @@ -194,15 +187,11 @@ struct sql_interface { /// @return SQL_SUCCESS or SQL_ERROR int (*StmtPrepareStr)(SqlStmt* self, const char* query); - - /// Returns the number of parameters in the prepared statement. /// /// @return Number or parameters size_t (*StmtNumParams)(SqlStmt* self); - - /// Binds a parameter to a buffer. /// The buffer data will be used when the statement is executed. /// All parameters should have bindings. @@ -210,30 +199,22 @@ struct sql_interface { /// @return SQL_SUCCESS or SQL_ERROR int (*StmtBindParam)(SqlStmt* self, size_t idx, SqlDataType buffer_type, void* buffer, size_t buffer_len); - - /// Executes the prepared statement. /// Any previous result is freed and all column bindings are removed. /// /// @return SQL_SUCCESS or SQL_ERROR int (*StmtExecute)(SqlStmt* self); - - /// Returns the number of the AUTO_INCREMENT column of the last INSERT/UPDATE statement. /// /// @return Value of the auto-increment column uint64 (*StmtLastInsertId)(SqlStmt* self); - - /// Returns the number of columns in each row of the result. /// /// @return Number of columns size_t (*StmtNumColumns)(SqlStmt* self); - - /// Binds the result of a column to a buffer. /// The buffer will be filled with data when the next row is fetched. /// For string/enum buffer types there has to be enough space for the data @@ -242,23 +223,17 @@ struct sql_interface { /// @return SQL_SUCCESS or SQL_ERROR int (*StmtBindColumn)(SqlStmt* self, size_t idx, SqlDataType buffer_type, void* buffer, size_t buffer_len, uint32* out_length, int8* out_is_null); - - /// Returns the number of rows in the result. /// /// @return Number of rows uint64 (*StmtNumRows)(SqlStmt* self); - - /// Fetches the next row. /// All column bindings will be filled with data. /// /// @return SQL_SUCCESS, SQL_ERROR or SQL_NO_DATA int (*StmtNextRow)(SqlStmt* self); - - /// Frees the result of the statement execution. void (*StmtFreeResult)(SqlStmt* self); @@ -269,8 +244,6 @@ struct sql_interface { }; -struct sql_interface *SQL; - #ifdef HERCULES_CORE void sql_defaults(void); @@ -280,6 +253,8 @@ void Sql_HerculesUpdateCheck(Sql* self); void Sql_HerculesUpdateSkip(Sql* self,const char *filename); #endif // HERCULES_CORE +HPShared struct sql_interface *SQL; + #if defined(SQL_REMOVE_SHOWDEBUG) #define Sql_ShowDebug(self) (void)0 #else diff --git a/src/common/strlib.c b/src/common/strlib.c index b5fcff576..fcd1b483b 100644 --- a/src/common/strlib.c +++ b/src/common/strlib.c @@ -4,24 +4,26 @@ #define HERCULES_CORE -#define H_STRLIB_C #include "strlib.h" -#undef H_STRLIB_C + +#include "common/cbasetypes.h" +#include "common/malloc.h" +#include "common/showmsg.h" #include <errno.h> #include <stdio.h> #include <stdlib.h> -#include "../common/cbasetypes.h" -#include "../common/malloc.h" -#include "../common/showmsg.h" - #define J_MAX_MALLOC_SIZE 65535 struct strlib_interface strlib_s; struct stringbuf_interface stringbuf_s; struct sv_interface sv_s; +struct strlib_interface *strlib; +struct stringbuf_interface *StrBuf; +struct sv_interface *sv; + // escapes a string in-place (' -> \' , \ -> \\ , % -> _) char* jstrescape (char* pt) { //copy from here @@ -117,7 +119,7 @@ int jmemescapecpy (char* pt, const char* spt, int size) } // Function to suppress control characters in a string. -int remove_control_chars(char* str) +int strlib_remove_control_chars(char *str) { int i; int change = 0; @@ -134,7 +136,7 @@ int remove_control_chars(char* str) // Removes characters identified by ISSPACE from the start and end of the string // NOTE: make sure the string is not const!! -char* trim(char* str) +char *strlib_trim(char *str) { size_t start; size_t end; @@ -162,7 +164,7 @@ char* trim(char* str) // Converts one or more consecutive occurrences of the delimiters into a single space // and removes such occurrences from the beginning and end of string // NOTE: make sure the string is not const!! -char* normalize_name(char* str,const char* delims) +char *strlib_normalize_name(char *str, const char *delims) { char* in = str; char* out = str; @@ -200,7 +202,7 @@ char* normalize_name(char* str,const char* delims) //stristr: Case insensitive version of strstr, code taken from //http://www.daniweb.com/code/snippet313.html, Dave Sinkula // -const char* stristr(const char* haystack, const char* needle) +const char *strlib_stristr(const char *haystack, const char *needle) { if ( !*needle ) { @@ -228,8 +230,9 @@ const char* stristr(const char* haystack, const char* needle) return 0; } +char* strlib_strtok_r(char *s1, const char *s2, char **lasts) +{ #ifdef __WIN32 -char* strtok_r_(char *s1, const char *s2, char **lasts) { char *ret; if (s1 == NULL) @@ -245,9 +248,13 @@ char* strtok_r_(char *s1, const char *s2, char **lasts) { *s1++ = '\0'; *lasts = s1; return ret; -} +#else + return strtok_r(s1, s2, lasts); #endif +} +size_t strlib_strnlen(const char *string, size_t maxlen) +{ // TODO: The _MSC_VER check can probably be removed (we no longer support VS // versions <= 2003, do we?), but this implementation might be still necessary // for NetBSD 5.x and possibly some Solaris versions. @@ -255,60 +262,17 @@ char* strtok_r_(char *s1, const char *s2, char **lasts) { /* Find the length of STRING, but scan at most MAXLEN characters. * If no '\0' terminator is found in that many characters, return MAXLEN. */ -size_t strnlen(const char* string, size_t maxlen) { const char* end = (const char*)memchr(string, '\0', maxlen); return end ? (size_t) (end - string) : maxlen; -} +#else + return strnlen(string, maxlen); #endif - -// TODO: This should probably be removed, I don't think we support MSVC++ 6.0 anymore. -#if defined(WIN32) && defined(_MSC_VER) && _MSC_VER <= 1200 -uint64 strtoull(const char* str, char** endptr, int base) -{ - uint64 result; - int count; - int n; - - if( base == 0 ) - { - if( str[0] == '0' && (str[1] == 'x' || str[1] == 'X') ) - base = 16; - else - if( str[0] == '0' ) - base = 8; - else - base = 10; - } - - if( base == 8 ) - count = sscanf(str, "%I64o%n", &result, &n); - else - if( base == 10 ) - count = sscanf(str, "%I64u%n", &result, &n); - else - if( base == 16 ) - count = sscanf(str, "%I64x%n", &result, &n); - else - count = 0; // fail - - if( count < 1 ) - { - errno = EINVAL; - result = 0; - n = 0; - } - - if( endptr ) - *endptr = (char*)str + n; - - return result; } -#endif //---------------------------------------------------- // E-mail check: return 0 (not correct) or 1 (valid). //---------------------------------------------------- -int e_mail_check(char* email) +int strlib_e_mail_check(char *email) { char ch; char* last_arobas; @@ -345,7 +309,7 @@ int e_mail_check(char* email) // Return numerical value of a switch configuration // on/off, yes/no, true/false, number //-------------------------------------------------- -int config_switch(const char* str) { +int strlib_config_switch(const char *str) { size_t len = strlen(str); if ((len == 2 && strcmpi(str, "on") == 0) || (len == 3 && strcmpi(str, "yes") == 0) @@ -365,7 +329,7 @@ int config_switch(const char* str) { } /// strncpy that always null-terminates the string -char* safestrncpy(char* dst, const char* src, size_t n) +char *strlib_safestrncpy(char *dst, const char *src, size_t n) { if( n > 0 ) { @@ -386,7 +350,7 @@ 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) +size_t strlib_safestrnlen(const char *string, size_t maxlen) { return ( string != NULL ) ? strnlen(string, maxlen) : 0; } @@ -400,8 +364,9 @@ size_t safestrnlen(const char* string, size_t maxlen) /// @param fmt Format string /// @param ... Format arguments /// @return The size of the string or -1 if the buffer is too small -int safesnprintf(char *buf, size_t sz, const char *fmt, ...) __attribute__((format(printf, 3, 4))); -int safesnprintf(char *buf, size_t sz, const char *fmt, ...) { +int strlib_safesnprintf(char *buf, size_t sz, const char *fmt, ...) __attribute__((format(printf, 3, 4))); +int strlib_safesnprintf(char *buf, size_t sz, const char *fmt, ...) +{ va_list ap; int ret; @@ -417,7 +382,7 @@ 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) +int strlib_strline(const char *str, size_t pos) { const char* target; int line; @@ -443,7 +408,7 @@ int strline(const char* str, size_t pos) /// @param output Output string /// @param input Binary input buffer /// @param count Number of bytes to convert -bool bin2hex(char* output, unsigned char* input, size_t count) +bool strlib_bin2hex(char *output, unsigned char *input, size_t count) { char toHex[] = "0123456789abcdef"; size_t i; @@ -458,8 +423,6 @@ bool bin2hex(char* output, unsigned char* input, size_t count) return true; } - - ///////////////////////////////////////////////////////////////////// /// Parses a single field in a delim-separated string. /// The delimiter after the field is skipped. @@ -617,7 +580,6 @@ int sv_parse_next(struct s_svstate* svstate) return 1; } - /// 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. @@ -927,7 +889,6 @@ const char* skip_escaped_c(const char* p) { return 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. @@ -1005,7 +966,6 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc return true; } - ///////////////////////////////////////////////////////////////////// // StringBuf - dynamic string // @@ -1133,29 +1093,30 @@ void strlib_defaults(void) { strlib->jstrescape = jstrescape; strlib->jstrescapecpy = jstrescapecpy; strlib->jmemescapecpy = jmemescapecpy; - strlib->remove_control_chars = remove_control_chars; - strlib->trim = trim; - strlib->normalize_name = normalize_name; - strlib->stristr = stristr; + strlib->remove_control_chars_ = strlib_remove_control_chars; + strlib->trim_ = strlib_trim; + strlib->normalize_name_ = strlib_normalize_name; + strlib->stristr_ = strlib_stristr; #if !(defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400) && !defined(HAVE_STRNLEN) - strlib->strnlen = strnlen; + strlib->strnlen_ = strlib_strnlen; #else - strlib->strnlen = NULL; + strlib->strnlen_ = NULL; #endif -#if defined(WIN32) && defined(_MSC_VER) && _MSC_VER <= 1200 - strlib->strtoull = strtoull; +#ifdef WIN32 + strlib->strtok_r_ = strlib_strtok_r; #else - strlib->strtoull = NULL; + strlib->strtok_r_ = NULL; #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; + + strlib->e_mail_check_ = strlib_e_mail_check; + strlib->config_switch_ = strlib_config_switch; + strlib->safestrncpy_ = strlib_safestrncpy; + strlib->safestrnlen_ = strlib_safestrnlen; + strlib->safesnprintf_ = strlib_safesnprintf; + strlib->strline_ = strlib_strline; + strlib->bin2hex_ = strlib_bin2hex; StrBuf->Malloc = StringBuf_Malloc; StrBuf->Init = StringBuf_Init; diff --git a/src/common/strlib.h b/src/common/strlib.h index c687d9e17..cd9e105fb 100644 --- a/src/common/strlib.h +++ b/src/common/strlib.h @@ -5,17 +5,35 @@ #ifndef COMMON_STRLIB_H #define COMMON_STRLIB_H +#include "common/hercules.h" + #include <stdarg.h> #include <string.h> -#include "../common/cbasetypes.h" +/// Convenience macros + +#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 strnlen(string,maxlen) (strlib->strnlen_((string),(maxlen))) +#endif #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); + #define strtok_r(s,delim,save_ptr) strlib->strtok_r_((s),(delim),(save_ptr)) #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))) + /// Bitfield determining the behavior of sv_parse and sv_split. typedef enum e_svopt { // default: no escapes and no line terminator @@ -59,43 +77,41 @@ 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); + 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); /* only used when '!(defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400) && !defined(HAVE_STRNLEN)', needs to be defined at all times however */ - size_t (*strnlen) (const char* string, size_t maxlen); + size_t (*strnlen_) (const char* string, size_t maxlen); - /* only used when 'defined(WIN32) && defined(_MSC_VER) && _MSC_VER <= 1200', needs to be defined at all times however */ - uint64 (*strtoull) (const char* str, char** endptr, int base); + /* only used when 'WIN32' */ + char * (*strtok_r_) (char *s1, const char *s2, char **lasts); - int (*e_mail_check) (char* email); - int (*config_switch) (const char* str); + int (*e_mail_check_) (char* email); + int (*config_switch_) (const char* str); /// strncpy that always null-terminates the string - char *(*safestrncpy) (char* dst, const char* src, size_t n); + 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); + size_t (*safestrnlen_) (const char* string, size_t maxlen); /// Works like snprintf, but always null-terminates the buffer. /// Returns the size of the string (without null-terminator) /// or -1 if the buffer is too small. - int (*safesnprintf) (char *buf, size_t sz, const char *fmt, ...) __attribute__((format(printf, 3, 4))); + int (*safesnprintf_) (char *buf, size_t sz, const char *fmt, ...) __attribute__((format(printf, 3, 4))); /// Returns the line of the target position in the string. /// Lines start at 1. - int (*strline) (const char* str, size_t pos); + 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); + bool (*bin2hex_) (char* output, unsigned char* input, size_t count); }; -struct strlib_interface *strlib; - struct stringbuf_interface { StringBuf* (*Malloc) (void); void (*Init) (StringBuf* self); @@ -110,8 +126,6 @@ struct stringbuf_interface { void (*Free) (StringBuf* self); }; -struct stringbuf_interface *StrBuf; - struct sv_interface { /// Parses a single field in a delim-separated string. /// The delimiter after the field is skipped. @@ -154,37 +168,12 @@ struct sv_interface { bool (*readdb) (const char* directory, const char* filename, char delim, int mincols, int maxcols, int maxrows, bool (*parseproc)(char* fields[], int columns, int current)); }; -struct sv_interface *sv; - #ifdef HERCULES_CORE void strlib_defaults(void); #endif // HERCULES_CORE -/* the purpose of these macros is simply to not make calling them be an annoyance */ -#ifndef H_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 strnlen(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 /* H_STRLIB_C */ +HPShared struct strlib_interface *strlib; +HPShared struct stringbuf_interface *StrBuf; +HPShared struct sv_interface *sv; #endif /* COMMON_STRLIB_H */ diff --git a/src/common/sysinfo.c b/src/common/sysinfo.c index a1dbed4d1..d218e6e99 100644 --- a/src/common/sysinfo.c +++ b/src/common/sysinfo.c @@ -1,6 +1,6 @@ // Copyright (c) Hercules Dev Team, licensed under GNU GPL. // See the LICENSE file -// Base Author: Haru @ http://hercules.ws +// Base Author: Haru @ http://herc.ws /// See sysinfo.h for a description of this file @@ -8,16 +8,14 @@ #include "sysinfo.h" +#include "common/cbasetypes.h" +#include "common/core.h" +#include "common/malloc.h" +#include "common/strlib.h" + #include <stdio.h> // fopen #include <stdlib.h> // atoi - -#include "../common/cbasetypes.h" -#include "../common/core.h" -#include "../common/malloc.h" -#include "../common/strlib.h" - #ifdef WIN32 -# include <string.h> // strlen # include <windows.h> #else # include <unistd.h> @@ -42,6 +40,8 @@ struct sysinfo_private { struct sysinfo_interface sysinfo_s; struct sysinfo_private sysinfo_p; +struct sysinfo_interface *sysinfo; + #define VCSTYPE_UNKNOWN 0 #define VCSTYPE_GIT 1 #define VCSTYPE_SVN 2 @@ -199,7 +199,9 @@ enum windows_ver_suite { #define SYSINFO_COMPILER "Microsoft Visual C++ 2012 (v" EXPAND_AND_QUOTE(_MSC_VER) ")" #elif _MSC_VER >= 1800 && _MSC_VER < 1900 #define SYSINFO_COMPILER "Microsoft Visual C++ 2013 (v" EXPAND_AND_QUOTE(_MSC_VER) ")" -#else // < 1300 || >= 1900 +#elif _MSC_VER >= 1900 && _MSC_VER < 2000 +#define SYSINFO_COMPILER "Microsoft Visual C++ 2015 (v" EXPAND_AND_QUOTE(_MSC_VER) ")" +#else // < 1300 || >= 2000 #define SYSINFO_COMPILER "Microsoft Visual C++ v" EXPAND_AND_QUOTE(_MSC_VER) #endif #else diff --git a/src/common/sysinfo.h b/src/common/sysinfo.h index 70f665071..7d47398a3 100644 --- a/src/common/sysinfo.h +++ b/src/common/sysinfo.h @@ -1,6 +1,6 @@ // Copyright (c) Hercules Dev Team, licensed under GNU GPL. // See the LICENSE file -// Base Author: Haru @ http://hercules.ws +// Base Author: Haru @ http://herc.ws #ifndef COMMON_SYSINFO_H #define COMMON_SYSINFO_H @@ -11,7 +11,7 @@ * cached at compile time) */ -#include "../common/cbasetypes.h" +#include "common/hercules.h" struct sysinfo_private; @@ -44,10 +44,10 @@ struct sysinfo_interface { void (*final) (void); }; -struct sysinfo_interface *sysinfo; - #ifdef HERCULES_CORE void sysinfo_defaults(void); #endif // HERCULES_CORE +HPShared struct sysinfo_interface *sysinfo; + #endif /* COMMON_SYSINFO_H */ diff --git a/src/common/thread.c b/src/common/thread.c index 95212b4b0..d5bbd7f97 100644 --- a/src/common/thread.c +++ b/src/common/thread.c @@ -10,10 +10,13 @@ #include "thread.h" -#include "../common/cbasetypes.h" +#include "common/cbasetypes.h" +#include "common/malloc.h" +#include "common/showmsg.h" +#include "common/sysinfo.h" // sysinfo->getpagesize() #ifdef WIN32 -# include "../common/winapi.h" +# include "common/winapi.h" # define __thread __declspec( thread ) #else # include <pthread.h> @@ -24,10 +27,6 @@ # include <unistd.h> #endif -#include "../common/malloc.h" -#include "../common/showmsg.h" -#include "../common/sysinfo.h" // sysinfo->getpagesize() - // When Compiling using MSC (on win32..) we know we have support in any case! #ifdef _MSC_VER #define HAS_TLS @@ -49,12 +48,10 @@ struct rAthread { #endif }; - #ifdef HAS_TLS __thread int g_rathread_ID = -1; #endif - /// /// Subystem Code /// @@ -77,8 +74,6 @@ void rathread_init(void) { }//end: rathread_init() - - void rathread_final(void) { register unsigned int i; @@ -95,8 +90,6 @@ void rathread_final(void) { }//end: rathread_final() - - // gets called whenever a thread terminated .. static void rat_thread_terminated(rAthread *handle) { // Preserve handle->myID and handle->hThread, set everything else to its default value @@ -132,7 +125,6 @@ static void *raThreadMainRedirector( void *p ){ #endif - ret = ((rAthread*)p)->proc( ((rAthread*)p)->param ) ; #ifdef WIN32 @@ -147,10 +139,6 @@ static void *raThreadMainRedirector( void *p ){ #endif }//end: raThreadMainRedirector() - - - - /// /// API Level /// @@ -158,7 +146,6 @@ rAthread *rathread_create(rAthreadProc entryPoint, void *param) { return rathread_createEx( entryPoint, param, (1<<23) /*8MB*/, RAT_PRIO_NORMAL ); }//end: rathread_create() - rAthread *rathread_createEx(rAthreadProc entryPoint, void *param, size_t szStack, RATHREAD_PRIO prio) { #ifndef WIN32 pthread_attr_t attr; @@ -167,13 +154,11 @@ rAthread *rathread_createEx(rAthreadProc entryPoint, void *param, size_t szStack unsigned int i; rAthread *handle = NULL; - // given stacksize aligned to systems pagesize? tmp = szStack % sysinfo->getpagesize(); if(tmp != 0) szStack += tmp; - // Get a free Thread Slot. for(i = 0; i < RA_THREADS_MAX; i++){ if(l_threads[i].proc == NULL){ @@ -209,7 +194,6 @@ rAthread *rathread_createEx(rAthreadProc entryPoint, void *param, size_t szStack return handle; }//end: rathread_createEx - void rathread_destroy(rAthread *handle) { #ifdef WIN32 if( TerminateThread(handle->hThread, 0) != FALSE){ @@ -254,7 +238,6 @@ rAthread *rathread_self(void) { return NULL; }//end: rathread_self() - int rathread_get_tid(void) { #ifdef HAS_TLS @@ -270,7 +253,6 @@ int rathread_get_tid(void) { }//end: rathread_get_tid() - bool rathread_wait(rAthread *handle, void **out_exitCode) { // Hint: // no thread data cleanup routine call here! @@ -287,18 +269,15 @@ bool rathread_wait(rAthread *handle, void **out_exitCode) { }//end: rathread_wait() - void rathread_prio_set(rAthread *handle, RATHREAD_PRIO prio) { handle->prio = RAT_PRIO_NORMAL; //@TODO }//end: rathread_prio_set() - RATHREAD_PRIO rathread_prio_get(rAthread *handle) { return handle->prio; }//end: rathread_prio_get() - void rathread_yield(void) { #ifdef WIN32 SwitchToThread(); diff --git a/src/common/thread.h b/src/common/thread.h index f79eb77f9..36ea006b3 100644 --- a/src/common/thread.h +++ b/src/common/thread.h @@ -4,7 +4,7 @@ #ifndef COMMON_THREAD_H #define COMMON_THREAD_H -#include "../common/cbasetypes.h" +#include "common/cbasetypes.h" typedef struct rAthread rAthread; typedef void* (*rAthreadProc)(void*); diff --git a/src/common/timer.c b/src/common/timer.c index 45dbb9f50..793706511 100644 --- a/src/common/timer.c +++ b/src/common/timer.c @@ -6,25 +6,25 @@ #include "timer.h" -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> - -#include "../common/cbasetypes.h" -#include "../common/db.h" -#include "../common/malloc.h" -#include "../common/showmsg.h" -#include "../common/utils.h" +#include "common/cbasetypes.h" +#include "common/db.h" +#include "common/malloc.h" +#include "common/showmsg.h" +#include "common/utils.h" #ifdef WIN32 -# include "../common/winapi.h" // GetTickCount() +# include "common/winapi.h" // GetTickCount() #else # include <sys/time.h> // struct timeval, gettimeofday() # include <unistd.h> #endif +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + struct timer_interface timer_s; +struct timer_interface *timer; // If the server can't handle processing thousands of monsters // or many connected clients, please increase TIMER_MIN_INTERVAL. diff --git a/src/common/timer.h b/src/common/timer.h index 6e8a72389..c00a4362b 100644 --- a/src/common/timer.h +++ b/src/common/timer.h @@ -5,7 +5,7 @@ #ifndef COMMON_TIMER_H #define COMMON_TIMER_H -#include "../common/cbasetypes.h" +#include "common/hercules.h" #define DIFF_TICK(a,b) ((a)-(b)) #define DIFF_TICK32(a,b) ((int32)((a)-(b))) @@ -63,10 +63,10 @@ struct timer_interface { void (*final) (void); }; -struct timer_interface *timer; - #ifdef HERCULES_CORE void timer_defaults(void); #endif // HERCULES_CORE +HPShared struct timer_interface *timer; + #endif /* COMMON_TIMER_H */ diff --git a/src/common/utils.c b/src/common/utils.c index ad68706ca..f5eecb65d 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -6,33 +6,30 @@ #include "utils.h" -#include <math.h> // floor() -#include <stdarg.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/stat.h> // cache purposes [Ind/Hercules] - -#include "../common/cbasetypes.h" -#include "../common/core.h" -#include "../common/malloc.h" -#include "../common/mmo.h" -#include "../common/showmsg.h" -#include "../common/socket.h" -#include "../common/strlib.h" +#include "common/cbasetypes.h" +#include "common/core.h" +#include "common/mmo.h" +#include "common/showmsg.h" +#include "common/socket.h" +#include "common/strlib.h" #ifdef WIN32 -# include "../common/winapi.h" +# include "common/winapi.h" # ifndef F_OK # define F_OK 0x0 # endif /* F_OK */ #else # include <dirent.h> -# include <sys/stat.h> # include <unistd.h> #endif +#include <math.h> // floor() +#include <stdio.h> +#include <stdlib.h> +#include <sys/stat.h> // cache purposes [Ind/Hercules] + struct HCache_interface HCache_s; +struct HCache_interface *HCache; /// Dumps given buffer into file pointed to by a handle. void WriteDump(FILE* fp, const void* buffer, size_t length) @@ -63,7 +60,6 @@ void WriteDump(FILE* fp, const void* buffer, size_t length) } } - /// Dumps given buffer on the console. void ShowDump(const void *buffer, size_t length) { size_t i; @@ -89,7 +85,6 @@ void ShowDump(const void *buffer, size_t length) { } } - #ifdef WIN32 static char* checkpath(char *path, const char *srcpath) @@ -140,7 +135,6 @@ void findfile(const char *p, const char *pat, void (func)(const char*)) func( tmppath ); } - if( FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { findfile(tmppath, pat, func); @@ -158,7 +152,7 @@ static char* checkpath(char *path, const char*srcpath) { // just make sure the char*path is not const char *p=path; - + if(NULL!=path && NULL!=srcpath) { while(*srcpath) { if (*srcpath=='\\') { @@ -352,7 +346,6 @@ const char* timestamp2string(char* str, size_t size, time_t timestamp, const cha return str; } - /* [Ind/Hercules] Caching */ bool HCache_check(const char *file) { diff --git a/src/common/utils.h b/src/common/utils.h index e6102f184..6296f6235 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -5,10 +5,9 @@ #ifndef COMMON_UTILS_H #define COMMON_UTILS_H -#include <stdio.h> // FILE* -#include <time.h> +#include "common/hercules.h" -#include "../common/cbasetypes.h" +#include <stdio.h> // FILE* /* [HCache] 1-byte key to ensure our method is the latest, we can modify to ensure the method matches */ #define HCACHE_KEY 'k' @@ -52,6 +51,12 @@ size_t hread(void * ptr, size_t size, size_t count, FILE * stream); size_t hwrite(const void * ptr, size_t size, size_t count, FILE * stream); #endif // HERCULES_CORE +#ifdef WIN32 +#define HSleep(x) Sleep(1000 * (x)) +#else // ! WIN32 +#define HSleep(x) sleep(x) +#endif + /* [Ind/Hercules] Caching */ struct HCache_interface { void (*init) (void); @@ -63,10 +68,10 @@ struct HCache_interface { bool enabled; }; -struct HCache_interface *HCache; - #ifdef HERCULES_CORE void HCache_defaults(void); #endif // HERCULES_CORE +HPShared struct HCache_interface *HCache; + #endif /* COMMON_UTILS_H */ |