summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-08-15 02:28:24 +0300
committerAndrei Karas <akaras@inbox.ru>2015-08-15 02:28:24 +0300
commit94df0300da69e3dde9bc05f32137dd90c43040e8 (patch)
tree53b540f7483533a281ffb66e0c39765a8f65508a /src/common
parent6795414243a08d47bc111e23c9c0f09218260ccf (diff)
parentd95f3b14d78305ea48834212684c73086555f74f (diff)
downloadhercules-94df0300da69e3dde9bc05f32137dd90c43040e8.tar.gz
hercules-94df0300da69e3dde9bc05f32137dd90c43040e8.tar.bz2
hercules-94df0300da69e3dde9bc05f32137dd90c43040e8.tar.xz
hercules-94df0300da69e3dde9bc05f32137dd90c43040e8.zip
Merge pull request #643 from HerculesWS/hpmfixes_v2
HPM Compatibility Improvements
Diffstat (limited to 'src/common')
-rw-r--r--src/common/HPM.c584
-rw-r--r--src/common/HPM.h7
-rw-r--r--src/common/HPMDataCheck.h14
-rw-r--r--src/common/HPMSymbols.inc.h451
-rw-r--r--src/common/HPMi.h64
-rw-r--r--src/common/Makefile.in6
-rw-r--r--src/common/conf.c2
-rw-r--r--src/common/conf.h20
-rw-r--r--src/common/console.c75
-rw-r--r--src/common/console.h8
-rw-r--r--src/common/core.c26
-rw-r--r--src/common/core.h48
-rw-r--r--src/common/db.c1
-rw-r--r--src/common/db.h8
-rw-r--r--src/common/hercules.h23
-rw-r--r--src/common/malloc.c1
-rw-r--r--src/common/malloc.h17
-rw-r--r--src/common/mapindex.c3
-rw-r--r--src/common/mapindex.h8
-rw-r--r--src/common/nullpo.c1
-rw-r--r--src/common/nullpo.h6
-rw-r--r--src/common/showmsg.c150
-rw-r--r--src/common/showmsg.h79
-rw-r--r--src/common/socket.c293
-rw-r--r--src/common/socket.h80
-rw-r--r--src/common/sql.c1
-rw-r--r--src/common/sql.h6
-rw-r--r--src/common/strlib.c120
-rw-r--r--src/common/strlib.h87
-rw-r--r--src/common/sysinfo.c2
-rw-r--r--src/common/sysinfo.h6
-rw-r--r--src/common/timer.c1
-rw-r--r--src/common/timer.h6
-rw-r--r--src/common/utils.c1
-rw-r--r--src/common/utils.h6
35 files changed, 1325 insertions, 886 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c
index cdd9bb769..a78f03daa 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -12,6 +12,7 @@
#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"
@@ -33,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
@@ -94,46 +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 **))) {
- ShowFatalError("HPM:plugin_load: failed to retrieve '%s' for '"CL_WHITE"%s"CL_RESET"'!\n", ToLink[i].name, filename);
- exit(EXIT_FAILURE);
+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;
}
- *Link = ToLink[i].Ref;
}
+ 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;
}
-#undef HPM_POP
+
+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;
+ }
+ }
+
+ 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;
+}
+
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);
@@ -173,13 +389,6 @@ struct hplugin *hplugin_load(const char* filename) {
*import_symbol_ref = HPM->import_symbol;
- if( !( sql_handle = plugin_import(plugin->dll, "mysql_handle",Sql **) ) ) {
- ShowFatalError("HPM:plugin_load: failed to retrieve 'mysql_handle' for '"CL_WHITE"%s"CL_RESET"'!\n", filename);
- exit(EXIT_FAILURE);
- }
-
- *sql_handle = HPM->import_symbol("sql_handle",plugin->idx);
-
if( !( HPMi = plugin_import(plugin->dll, "HPMi",struct HPMi_interface **) ) ) {
ShowFatalError("HPM:plugin_load: failed to retrieve 'HPMi' for '"CL_WHITE"%s"CL_RESET"'!\n", filename);
exit(EXIT_FAILURE);
@@ -211,8 +420,17 @@ struct hplugin *hplugin_load(const char* 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 *) ) ) {
ShowFatalError("HPM:plugin_load: failed to retrieve 'HPMDataCheckLen' for '"CL_WHITE"%s"CL_RESET"', most likely not including HPMDataCheck.h!\n", filename);
@@ -238,16 +456,18 @@ struct hplugin *hplugin_load(const char* filename) {
/* 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);
@@ -313,9 +533,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);
@@ -382,160 +599,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
@@ -612,80 +676,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;
@@ -716,7 +707,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)) {
@@ -754,46 +745,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;
@@ -825,8 +776,6 @@ void hpm_init(void) {
HPM->packetsc[i] = 0;
}
- HPM->symbol_defaults();
-
#ifdef CONSOLE_INPUT
console->input->addCommand("plugins",CPCMD_A(plugins));
#endif
@@ -921,10 +870,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 1358f19dc..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/hercules.h"
#include "common/HPMi.h"
-#include "common/cbasetypes.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 584cab5c9..7e737103c 100644
--- a/src/common/HPMDataCheck.h
+++ b/src/common/HPMDataCheck.h
@@ -6,6 +6,12 @@
#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
@@ -107,6 +113,7 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = {
#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
@@ -142,7 +149,7 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = {
#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
@@ -185,6 +192,11 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = {
#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 },
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 bf4eb83c8..bd8d8fe64 100644
--- a/src/common/HPMi.h
+++ b/src/common/HPMi.h
@@ -4,9 +4,10 @@
#ifndef COMMON_HPMI_H
#define COMMON_HPMI_H
-#include "common/cbasetypes.h"
+#include "common/hercules.h"
#include "common/console.h"
#include "common/core.h"
+#include "common/showmsg.h"
#include "common/sql.h"
struct script_state;
@@ -14,16 +15,7 @@ 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 {
@@ -152,33 +139,37 @@ enum HPluginConfType {
#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 ) { \
+/// 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 */
@@ -224,10 +215,17 @@ 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 f6f993165..208d3b111 100644
--- a/src/common/Makefile.in
+++ b/src/common/Makefile.in
@@ -32,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
diff --git a/src/common/conf.c b/src/common/conf.c
index cb0194c3a..d9367dc9e 100644
--- a/src/common/conf.c
+++ b/src/common/conf.c
@@ -12,7 +12,7 @@
/* 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 1889aeb3a..ac97a5427 100644
--- a/src/common/conf.h
+++ b/src/common/conf.h
@@ -5,7 +5,7 @@
#ifndef COMMON_CONF_H
#define COMMON_CONF_H
-#include "common/cbasetypes.h"
+#include "common/hercules.h"
#include <libconfig/libconfig.h>
@@ -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 95d1e69fe..0dd225d4d 100644
--- a/src/common/console.c
+++ b/src/common/console.c
@@ -37,6 +37,7 @@
#endif
struct console_interface console_s;
+struct console_interface *console;
#ifdef CONSOLE_INPUT
struct console_input_interface console_input_s;
@@ -74,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;
@@ -91,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
@@ -102,7 +102,7 @@ int console_parse_key_pressed(void) {
* Stops server
**/
CPCMD_C(exit,server) {
- runflag = 0;
+ core->runflag = 0;
}
/**
@@ -158,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;
@@ -254,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 643edc3d9..ffb4a165b 100644
--- a/src/common/console.h
+++ b/src/common/console.h
@@ -4,9 +4,7 @@
#ifndef COMMON_CONSOLE_H
#define COMMON_CONSOLE_H
-#include "config/core.h" // MAX_CONSOLE_INPUT
-
-#include "common/cbasetypes.h"
+#include "common/hercules.h"
#include "common/mutex.h"
#include "common/spinlock.h"
#include "common/sql.h"
@@ -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 e663c4e4c..7f5a1da53 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -41,11 +41,8 @@
/// 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
@@ -90,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;
@@ -118,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:
@@ -176,6 +173,7 @@ void core_defaults(void) {
console_defaults();
strlib_defaults();
malloc_defaults();
+ showmsg_defaults();
cmdline_defaults();
#ifndef MINICORE
libconfig_defaults();
@@ -317,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)) {
@@ -360,6 +358,7 @@ void cmdline_final(void)
}
struct cmdline_interface cmdline_s;
+struct cmdline_interface *cmdline;
void cmdline_defaults(void)
{
@@ -387,12 +386,14 @@ 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();
@@ -402,7 +403,7 @@ int main (int argc, char **argv) {
sysinfo->init();
- if (!(msg_silent&0x1))
+ if (!(showmsg->silent&0x1))
console->display_title();
usercheck();
@@ -439,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);
}
@@ -458,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 c2a8d9e58..c92bf4fa6 100644
--- a/src/common/core.h
+++ b/src/common/core.h
@@ -5,7 +5,7 @@
#ifndef COMMON_CORE_H
#define COMMON_CORE_H
-#include "common/cbasetypes.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
@@ -28,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.
@@ -78,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)
@@ -91,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 5063425e6..4df5c08db 100644
--- a/src/common/db.c
+++ b/src/common/db.c
@@ -82,6 +82,7 @@
#include <stdlib.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 f75cbd8dc..9b9cba8f8 100644
--- a/src/common/db.h
+++ b/src/common/db.h
@@ -42,7 +42,7 @@
#ifndef COMMON_DB_H
#define COMMON_DB_H
-#include "common/cbasetypes.h"
+#include "common/hercules.h"
#include <stdarg.h>
@@ -916,9 +916,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,8 +934,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, ...);
+
+void db_defaults(void);
#endif // HERCULES_CORE
+HPShared struct db_interface *DB;
/// Finds an entry in an array.
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 ec0467495..d5a979e77 100644
--- a/src/common/malloc.c
+++ b/src/common/malloc.c
@@ -16,6 +16,7 @@
#include <string.h>
struct malloc_interface iMalloc_s;
+struct malloc_interface *iMalloc;
////////////// Memory Libraries //////////////////
diff --git a/src/common/malloc.h b/src/common/malloc.h
index 20260de84..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 18aa413cc..aa31d8090 100644
--- a/src/common/mapindex.c
+++ b/src/common/mapindex.c
@@ -17,6 +17,7 @@
/* 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.
@@ -124,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
diff --git a/src/common/mapindex.h b/src/common/mapindex.h
index c334e7cca..ff19630a1 100644
--- a/src/common/mapindex.h
+++ b/src/common/mapindex.h
@@ -5,7 +5,7 @@
#ifndef COMMON_MAPINDEX_H
#define COMMON_MAPINDEX_H
-#include "common/cbasetypes.h"
+#include "common/hercules.h"
#include "common/db.h"
#include "common/mmo.h"
@@ -91,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/nullpo.c b/src/common/nullpo.c
index 0db714ae1..829ba4aab 100644
--- a/src/common/nullpo.c
+++ b/src/common/nullpo.c
@@ -17,6 +17,7 @@
#endif // HAVE_EXECINFO
struct nullpo_interface nullpo_s;
+struct nullpo_interface *nullpo;
/**
* Reports failed assertions or NULL pointers
diff --git a/src/common/nullpo.h b/src/common/nullpo.h
index a59c2ac2b..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/showmsg.c b/src/common/showmsg.c
index 01dc0b01a..27fb0b635 100644
--- a/src/common/showmsg.c
+++ b/src/common/showmsg.c
@@ -30,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
@@ -197,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;
}
@@ -490,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;
}
@@ -596,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;
@@ -612,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];
@@ -635,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) {
@@ -721,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
@@ -738,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);
@@ -792,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 63e42ab57..728691ba3 100644
--- a/src/common/showmsg.h
+++ b/src/common/showmsg.h
@@ -5,13 +5,9 @@
#ifndef COMMON_SHOWMSG_H
#define COMMON_SHOWMSG_H
-#include "common/cbasetypes.h"
+#include "common/hercules.h"
-#ifdef HERCULES_CORE
-# include <libconfig/libconfig.h>
-#else
-# include "common/HPMi.h"
-#endif
+#include <libconfig/libconfig.h>
#include <stdarg.h>
@@ -85,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 830877044..c4cc4a329 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -5,9 +5,7 @@
#define HERCULES_CORE
#include "config/core.h" // SHOW_SERVER_STATS
-#define H_SOCKET_C
#include "socket.h"
-#undef H_SOCKET_C
#include "common/HPM.h"
#include "common/cbasetypes.h"
@@ -57,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
@@ -359,13 +360,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;
}
}
@@ -373,32 +373,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;
}
@@ -410,23 +410,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;
}
@@ -435,14 +435,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;
}
@@ -455,15 +455,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);
}
/*======================================
@@ -493,7 +493,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)) ) {
@@ -506,7 +506,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;
}
@@ -535,7 +535,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);
@@ -556,8 +556,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;
}
@@ -601,73 +601,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;
}
@@ -676,38 +676,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);
@@ -722,12 +722,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
@@ -771,14 +771,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);
@@ -800,11 +800,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
@@ -832,16 +832,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;
}
}
@@ -853,15 +853,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
@@ -869,32 +869,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;
}
}
@@ -1220,15 +1220,15 @@ 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(session);
+ aFree(sockt->session);
if (sockt->lan_subnet)
aFree(sockt->lan_subnet);
@@ -1247,16 +1247,16 @@ void socket_final(void)
}
/// 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.
@@ -1393,21 +1393,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);
@@ -1419,19 +1419,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.
@@ -1441,9 +1438,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);
@@ -1518,7 +1521,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);
@@ -1535,7 +1538,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;
@@ -1585,20 +1588,20 @@ 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);
}
}
@@ -1696,8 +1699,8 @@ int socket_net_config_read_sub(config_setting_t *t, struct s_subnet **list, int
}
RECREATE(*list, struct s_subnet, *count + 1);
l = *list;
- l[*count].ip = str2ip(ipbuf);
- l[*count].mask = str2ip(maskbuf);
+ l[*count].ip = sockt->str2ip(ipbuf);
+ l[*count].mask = sockt->str2ip(maskbuf);
++*count;
}
return *count;
@@ -1792,14 +1795,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;
@@ -1808,7 +1811,7 @@ 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;
diff --git a/src/common/socket.h b/src/common/socket.h
index 26b674d43..a995bffc8 100644
--- a/src/common/socket.h
+++ b/src/common/socket.h
@@ -5,7 +5,7 @@
#ifndef COMMON_SOCKET_H
#define COMMON_SOCKET_H
-#include "common/cbasetypes.h"
+#include "common/hercules.h"
#include "common/conf.h"
#ifdef WIN32
@@ -23,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)))
@@ -35,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))
@@ -124,11 +132,6 @@ struct s_subnet {
#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 {
@@ -140,6 +143,8 @@ 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
@@ -159,27 +164,27 @@ 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);
uint32 (*lan_subnet_check) (uint32 ip, struct s_subnet *info);
bool (*allowed_ip_check) (uint32 ip);
@@ -188,33 +193,10 @@ struct socket_interface {
void (*net_config_read) (const char *filename);
};
-struct socket_interface *sockt;
-
#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/sql.c b/src/common/sql.c
index a93092533..0ca51e272 100644
--- a/src/common/sql.c
+++ b/src/common/sql.c
@@ -24,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 {
diff --git a/src/common/sql.h b/src/common/sql.h
index d76b4f9d4..7fb4aabe8 100644
--- a/src/common/sql.h
+++ b/src/common/sql.h
@@ -5,7 +5,7 @@
#ifndef COMMON_SQL_H
#define COMMON_SQL_H
-#include "common/cbasetypes.h"
+#include "common/hercules.h"
#include <stdarg.h>// va_list
@@ -269,8 +269,6 @@ struct sql_interface {
};
-struct sql_interface *SQL;
-
#ifdef HERCULES_CORE
void sql_defaults(void);
@@ -280,6 +278,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 555f591e6..024b73e59 100644
--- a/src/common/strlib.c
+++ b/src/common/strlib.c
@@ -4,9 +4,7 @@
#define HERCULES_CORE
-#define H_STRLIB_C
#include "strlib.h"
-#undef H_STRLIB_C
#include "common/cbasetypes.h"
#include "common/malloc.h"
@@ -22,6 +20,10 @@ 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;
@@ -1133,29 +1098,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 a768ebff5..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/cbasetypes.h"
+#include "common/hercules.h"
#include <stdarg.h>
#include <string.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 105f300ad..d218e6e99 100644
--- a/src/common/sysinfo.c
+++ b/src/common/sysinfo.c
@@ -40,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
diff --git a/src/common/sysinfo.h b/src/common/sysinfo.h
index 3c0d01ca1..7d47398a3 100644
--- a/src/common/sysinfo.h
+++ b/src/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/timer.c b/src/common/timer.c
index 06309642e..793706511 100644
--- a/src/common/timer.c
+++ b/src/common/timer.c
@@ -24,6 +24,7 @@
#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 46a036ec7..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 07e2e9fdf..3606c6755 100644
--- a/src/common/utils.c
+++ b/src/common/utils.c
@@ -29,6 +29,7 @@
#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)
diff --git a/src/common/utils.h b/src/common/utils.h
index e2b0dacc9..6296f6235 100644
--- a/src/common/utils.h
+++ b/src/common/utils.h
@@ -5,7 +5,7 @@
#ifndef COMMON_UTILS_H
#define COMMON_UTILS_H
-#include "common/cbasetypes.h"
+#include "common/hercules.h"
#include <stdio.h> // FILE*
@@ -68,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 */