summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2014-11-16 06:35:51 +0100
committerHaru <haru@dotalux.com>2014-11-16 07:16:23 +0100
commit02fcaed6bd32b0ffbc4f03b8f9de6f0720e6253f (patch)
tree3161fd5786bb563c32059068eb3b4876d2ae11ca /src/common
parent31bff051ee3c353fb7ee5e544d68feeaefd4941f (diff)
downloadhercules-02fcaed6bd32b0ffbc4f03b8f9de6f0720e6253f.tar.gz
hercules-02fcaed6bd32b0ffbc4f03b8f9de6f0720e6253f.tar.bz2
hercules-02fcaed6bd32b0ffbc4f03b8f9de6f0720e6253f.tar.xz
hercules-02fcaed6bd32b0ffbc4f03b8f9de6f0720e6253f.zip
Whitespace cleanup (no code changes)
This includes, and is not limited to: mixed or wrong indentation, excess whitespace (horizontal and vertical), misalignment, trailing spaces. Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/common')
-rw-r--r--src/common/HPM.c240
-rw-r--r--src/common/atomic.h14
-rw-r--r--src/common/cbasetypes.h113
-rw-r--r--src/common/conf.c11
-rw-r--r--src/common/conf.h28
-rw-r--r--src/common/console.c90
-rw-r--r--src/common/core.c30
-rw-r--r--src/common/db.c21
-rw-r--r--src/common/db.h6
-rw-r--r--src/common/des.c16
-rw-r--r--src/common/ers.c40
-rw-r--r--src/common/ers.h2
-rw-r--r--src/common/grfio.c91
-rw-r--r--src/common/malloc.c74
-rw-r--r--src/common/malloc.h20
-rw-r--r--src/common/mapindex.c24
-rw-r--r--src/common/md5calc.c224
-rw-r--r--src/common/mmo.h22
-rw-r--r--src/common/mutex.c60
-rw-r--r--src/common/nullpo.c4
-rw-r--r--src/common/showmsg.c361
-rw-r--r--src/common/socket.c60
-rw-r--r--src/common/socket.h2
-rw-r--r--src/common/spinlock.h26
-rw-r--r--src/common/sql.c16
-rw-r--r--src/common/strlib.c16
-rw-r--r--src/common/strlib.h26
-rw-r--r--src/common/thread.c37
-rw-r--r--src/common/thread.h4
-rw-r--r--src/common/timer.c36
-rw-r--r--src/common/utils.c66
-rw-r--r--src/common/winapi.h6
32 files changed, 859 insertions, 927 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c
index 003f2d935..e38451161 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -56,22 +56,22 @@ void hplugin_export_symbol(void *var, char *name) {
void *hplugin_import_symbol(char *name, unsigned int pID) {
unsigned int i;
-
+
for( i = 0; i < HPM->symbol_count; i++ ) {
if( strcmp(HPM->symbols[i]->name,name) == 0 )
return HPM->symbols[i]->ptr;
}
-
+
ShowError("HPM:get_symbol:%s: '"CL_WHITE"%s"CL_RESET"' not found!\n",HPM->pid2name(pID),name);
return NULL;
}
bool hplugin_iscompatible(char* version) {
unsigned int req_major = 0, req_minor = 0;
-
+
if( version == NULL )
return false;
-
+
sscanf(version, "%u.%u", &req_major, &req_minor);
return ( req_major == HPM->version[0] && req_minor <= HPM->version[1] ) ? true : false;
@@ -110,7 +110,7 @@ bool hplugin_populate(struct hplugin *plugin, const char *filename) {
HPM_POP(ShowFatalError),
};
int i, length = ARRAYLENGTH(ToLink);
-
+
for(i = 0; i < length; i++) {
if( !( Link = plugin_import(plugin->dll, ToLink[i].name,void **) ) ) {
ShowWarning("HPM:plugin_load: failed to retrieve '%s' for '"CL_WHITE"%s"CL_RESET"', skipping...\n", ToLink[i].name, filename);
@@ -119,7 +119,7 @@ bool hplugin_populate(struct hplugin *plugin, const char *filename) {
}
*Link = ToLink[i].Ref;
}
-
+
return true;
}
#undef HPM_POP
@@ -133,54 +133,54 @@ struct hplugin *hplugin_load(const char* filename) {
int *HPMDataCheckVer;
unsigned int *HPMDataCheckLen;
struct s_HPMDataCheck *HPMDataCheck;
-
+
if( HPM->exists(filename) ) {
ShowWarning("HPM:plugin_load: attempting to load duplicate '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename);
return NULL;
}
-
+
plugin = HPM->create();
-
+
if( !( plugin->dll = plugin_open(filename) ) ){
ShowWarning("HPM:plugin_load: failed to load '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename);
HPM->unload(plugin);
return NULL;
}
-
+
if( !( info = plugin_import(plugin->dll, "pinfo",struct hplugin_info*) ) ) {
ShowDebug("HPM:plugin_load: failed to retrieve 'plugin_info' for '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename);
HPM->unload(plugin);
return NULL;
}
-
+
if( !(info->type & SERVER_TYPE) ) {
HPM->unload(plugin);
return NULL;
}
-
+
if( !HPM->iscompatible(info->req_version) ) {
ShowWarning("HPM:plugin_load: '"CL_WHITE"%s"CL_RESET"' incompatible version '%s' -> '%s', skipping...\n", filename, info->req_version, HPM_VERSION);
HPM->unload(plugin);
return NULL;
}
-
+
plugin->info = info;
plugin->filename = aStrdup(filename);
-
+
if( !( import_symbol_ref = plugin_import(plugin->dll, "import_symbol",void **) ) ) {
ShowWarning("HPM:plugin_load: failed to retrieve 'import_symbol' for '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename);
HPM->unload(plugin);
return NULL;
}
-
+
*import_symbol_ref = HPM->import_symbol;
-
+
if( !( sql_handle = plugin_import(plugin->dll, "mysql_handle",Sql **) ) ) {
ShowWarning("HPM:plugin_load: failed to retrieve 'mysql_handle' for '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename);
HPM->unload(plugin);
return NULL;
}
-
+
*sql_handle = HPM->import_symbol("sql_handle",plugin->idx);
if( !( HPMi = plugin_import(plugin->dll, "HPMi",struct HPMi_interface **) ) ) {
@@ -188,44 +188,44 @@ struct hplugin *hplugin_load(const char* filename) {
HPM->unload(plugin);
return NULL;
}
-
+
if( !( *HPMi = plugin_import(plugin->dll, "HPMi_s",struct HPMi_interface *) ) ) {
ShowWarning("HPM:plugin_load: failed to retrieve 'HPMi_s' for '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename);
HPM->unload(plugin);
return NULL;
}
plugin->hpi = *HPMi;
-
+
if( ( plugin->hpi->event[HPET_INIT] = plugin_import(plugin->dll, "plugin_init",void (*)(void)) ) )
anyEvent = true;
-
+
if( ( plugin->hpi->event[HPET_FINAL] = plugin_import(plugin->dll, "plugin_final",void (*)(void)) ) )
anyEvent = true;
-
+
if( ( plugin->hpi->event[HPET_READY] = plugin_import(plugin->dll, "server_online",void (*)(void)) ) )
anyEvent = true;
-
+
if( ( plugin->hpi->event[HPET_POST_FINAL] = plugin_import(plugin->dll, "server_post_final",void (*)(void)) ) )
anyEvent = true;
-
+
if( ( plugin->hpi->event[HPET_PRE_INIT] = plugin_import(plugin->dll, "server_preinit",void (*)(void)) ) )
anyEvent = true;
-
+
if( !anyEvent ) {
ShowWarning("HPM:plugin_load: no events found for '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename);
HPM->unload(plugin);
return NULL;
}
-
+
if( !HPM->populate(plugin,filename) )
return NULL;
-
+
if( !( HPMDataCheckLen = plugin_import(plugin->dll, "HPMDataCheckLen", unsigned int *) ) ) {
ShowWarning("HPM:plugin_load: failed to retrieve 'HPMDataCheckLen' for '"CL_WHITE"%s"CL_RESET"', most likely not including HPMDataCheck.h, skipping...\n", filename);
HPM->unload(plugin);
return NULL;
}
-
+
if( !( HPMDataCheckVer = plugin_import(plugin->dll, "HPMDataCheckVer", int *) ) ) {
ShowWarning("HPM:plugin_load: failed to retrieve 'HPMDataCheckVer' for '"CL_WHITE"%s"CL_RESET"', most likely an outdated plugin, skipping...\n", filename);
HPM->unload(plugin);
@@ -237,14 +237,14 @@ struct hplugin *hplugin_load(const char* filename) {
HPM->unload(plugin);
return NULL;
}
-
+
// TODO: Remove the HPM->DataCheck != NULL check once login and char support is complete
if (HPM->DataCheck != NULL && !HPM->DataCheck(HPMDataCheck,*HPMDataCheckLen,*HPMDataCheckVer,plugin->info->name)) {
ShowWarning("HPM:plugin_load: '"CL_WHITE"%s"CL_RESET"' failed DataCheck, out of sync from the core (recompile plugin), skipping...\n", filename);
HPM->unload(plugin);
return NULL;
}
-
+
/* id */
plugin->hpi->pid = plugin->idx;
/* core */
@@ -261,13 +261,13 @@ struct hplugin *hplugin_load(const char* filename) {
/* server specific */
if( HPM->load_sub )
HPM->load_sub(plugin);
-
+
return plugin;
}
void hplugin_unload(struct hplugin* plugin) {
unsigned int i = plugin->idx, cursor = 0;
-
+
if( plugin->filename )
aFree(plugin->filename);
if( plugin->dll )
@@ -297,25 +297,25 @@ void hplugins_config_read(const char * const *extra_plugins, int extra_plugins_c
const char *config_filename = "conf/plugins.conf"; // FIXME hardcoded name
FILE *fp;
int i;
-
+
/* yes its ugly, its temporary and will be gone as soon as the new inter-server.conf is set */
if( (fp = fopen("conf/import/plugins.conf","r")) ) {
config_filename = "conf/import/plugins.conf";
fclose(fp);
}
-
+
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 < extra_plugins_count; i++) {
config_setting_t *entry = libconfig->setting_add(plist, NULL, CONFIG_TYPE_STRING);
config_setting_set_string(entry, extra_plugins[i]);
}
-
+
if (plist != NULL) {
int length = libconfig->setting_length(plist);
char filename[60];
@@ -356,7 +356,7 @@ void hplugins_config_read(const char * const *extra_plugins, int extra_plugins_c
}
libconfig->destroy(&plugins_conf);
}
-
+
if( HPM->plugin_count )
ShowStatus("HPM: There are '"CL_WHITE"%d"CL_RESET"' plugins loaded, type '"CL_WHITE"plugins"CL_RESET"' to list them\n", HPM->plugin_count);
}
@@ -365,9 +365,9 @@ CPCMD(plugins) {
ShowInfo("HPC: there are no plugins loaded\n");
} else {
unsigned int i;
-
+
ShowInfo("HPC: There are '"CL_WHITE"%d"CL_RESET"' plugins loaded\n",HPM->plugin_count);
-
+
for(i = 0; i < HPM->plugin_count; i++) {
ShowInfo("HPC: - '"CL_WHITE"%s"CL_RESET"' (%s)\n",HPM->plugins[i]->info->name,HPM->plugins[i]->filename);
}
@@ -400,18 +400,18 @@ void hplugins_addToHPData(enum HPluginDataTypes type, unsigned int pluginID, voi
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 ) {
@@ -419,20 +419,20 @@ void hplugins_addToHPData(enum HPluginDataTypes type, unsigned int pluginID, voi
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;
@@ -442,23 +442,23 @@ void *hplugins_getFromHPData(enum HPluginDataTypes type, unsigned int pluginID,
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;
}
@@ -466,30 +466,30 @@ void hplugins_removeFromHPData(enum HPluginDataTypes type, unsigned int pluginID
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;
@@ -499,13 +499,12 @@ void hplugins_removeFromHPData(enum HPluginDataTypes type, unsigned int pluginID
}
*(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;
@@ -517,15 +516,15 @@ bool hplugins_addpacket(unsigned short cmd, short length,void (*receive) (int fd
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;
}
/*
@@ -535,52 +534,52 @@ bool hplugins_addpacket(unsigned short cmd, short length,void (*receive) (int fd
*/
unsigned char hplugins_parse_packets(int fd, enum HPluginPacketHookingPoints point) {
unsigned int i;
-
+
for(i = 0; i < HPM->packetsc[point]; i++) {
if( HPM->packets[point][i].cmd == RFIFOW(fd,0) )
break;
}
-
+
if( i != HPM->packetsc[point] ) {
struct HPluginPacket *packet = &HPM->packets[point][i];
short length;
-
+
if( (length = packet->len) == -1 ) {
if( (length = RFIFOW(fd, 2)) > (int)RFIFOREST(fd) )
- return 2;
+ return 2;
}
-
+
packet->receive(fd);
RFIFOSKIP(fd, length);
return 1;
}
-
+
return 0;
}
char *hplugins_id2name (unsigned int pid) {
unsigned int i;
-
+
for( i = 0; i < HPM->plugin_count; i++ ) {
if( HPM->plugins[i]->idx == pid )
return HPM->plugins[i]->info->name;
}
-
+
return "UnknownPlugin";
}
char* HPM_file2ptr(const char *file) {
unsigned int i;
-
+
for(i = 0; i < HPM->fnamec; i++) {
if( HPM->fnames[i].addr == file )
return HPM->fnames[i].name;
}
-
+
i = HPM->fnamec;
-
+
/* we handle this memory outside of the server's memory manager because we need it to exist after the memory manager goes down */
HPM->fnames = realloc(HPM->fnames,(++HPM->fnamec)*sizeof(struct HPMFileNameCache));
-
+
HPM->fnames[i].addr = file;
HPM->fnames[i].name = strdup(file);
@@ -611,9 +610,9 @@ bool HPM_AddHook(enum HPluginHookType type, const char *target, void *hook, unsi
/* 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) {
@@ -632,82 +631,82 @@ bool hpm_parse_arg(const char *arg, int *index, char *argv[], bool param) {
if( data->has_param && param ) *index += 1;
return true;
}
-
+
return false;
}
void hpm_arg_help(void) {
DBIterator *iter = db_iterator(HPM->arg_db);
struct HPMArgData *data = NULL;
-
+
for( data = dbi_first(iter); dbi_exists(iter); data = dbi_next(iter) ) {
if( data->help != NULL )
data->help();
else
ShowInfo(" %s (%s)\t\t<no description provided>\n",data->name,HPM->pid2name(data->pluginID));
}
-
+
dbi_destroy(iter);
}
bool hpm_add_arg(unsigned int pluginID, char *name, bool has_param, void (*func) (char *param),void (*help) (void)) {
struct HPMArgData *data = NULL;
-
+
if( strdb_exists(HPM->arg_db, name) ) {
ShowError("HPM:add_arg:%s duplicate! (from %s)\n",name,HPM->pid2name(pluginID));
return false;
}
-
+
CREATE(data, struct HPMArgData, 1);
-
+
data->pluginID = pluginID;
data->name = aStrdup(name);
data->func = func;
data->help = help;
data->has_param = has_param;
-
+
strdb_put(HPM->arg_db, data->name, data);
-
+
return true;
}
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;
-
+
/* exists? */
for(i = 0; i < HPM->confsc[point]; i++) {
if( !strcmpi(w1,HPM->confs[point][i].key) )
break;
}
-
+
/* trigger and we're set! */
if( i != HPM->confsc[point] ) {
HPM->confs[point][i].func(w2);
return true;
}
-
+
return false;
}
@@ -721,7 +720,7 @@ bool HPM_DataCheck(struct s_HPMDataCheck *src, unsigned int size, int version, c
ShowError("HPMDataCheck:%s: DataCheck API version mismatch %d != %d\n", name, datacheck_version, version);
return false;
}
-
+
for (i = 0; i < size; i++) {
if (!(src[i].type|SERVER_TYPE))
continue;
@@ -737,7 +736,7 @@ bool HPM_DataCheck(struct s_HPMDataCheck *src, unsigned int size, int version, c
}
}
}
-
+
return true;
}
@@ -746,12 +745,12 @@ void HPM_datacheck_init(const struct s_HPMDataCheck *src, unsigned int length, i
datacheck_version = version;
datacheck_data = src;
-
+
/**
* Populates datacheck_db for easy lookup later on
**/
datacheck_db = strdb_alloc(DB_OPT_BASE,0);
-
+
for(i = 0; i < length; i++) {
strdb_uiput(datacheck_db, src[i].name, i);
}
@@ -805,12 +804,12 @@ void hpm_init(void) {
datacheck_db = NULL;
datacheck_data = NULL;
datacheck_version = 0;
-
+
HPM->symbols = NULL;
HPM->plugins = NULL;
HPM->plugin_count = HPM->symbol_count = 0;
HPM->off = false;
-
+
memcpy(&iMalloc_HPM, iMalloc, sizeof(struct malloc_interface));
HPMiMalloc = &iMalloc_HPM;
HPMiMalloc->malloc = HPM_mmalloc;
@@ -820,21 +819,21 @@ void hpm_init(void) {
HPMiMalloc->astrdup = HPM_astrdup;
sscanf(HPM_VERSION, "%u.%u", &HPM->version[0], &HPM->version[1]);
-
+
if( HPM->version[0] == 0 && HPM->version[1] == 0 ) {
ShowError("HPM:init:failed to retrieve HPM version!!\n");
return;
}
-
+
for(i = 0; i < hpPHP_MAX; i++) {
HPM->packets[i] = NULL;
HPM->packetsc[i] = 0;
}
-
+
HPM->arg_db = strdb_alloc(DB_OPT_RELEASE_DATA, 0);
-
+
HPM->symbol_defaults();
-
+
#ifdef CONSOLE_INPUT
console->input->addCommand("plugins",CPCMD_A(plugins));
#endif
@@ -842,64 +841,63 @@ void hpm_init(void) {
}
void hpm_memdown(void) {
unsigned int i;
-
+
/* this memory is handled outside of the server's memory manager and thus cleared after memory manager goes down */
-
+
for( i = 0; i < HPM->fnamec; i++ ) {
free(HPM->fnames[i].name);
}
-
+
if( HPM->fnames )
free(HPM->fnames);
-
}
int hpm_arg_db_clear_sub(DBKey key, DBData *data, va_list args) {
struct HPMArgData *a = DB->data2ptr(data);
-
+
aFree(a->name);
-
+
return 0;
}
void hpm_final(void) {
unsigned int i;
-
+
HPM->off = true;
-
+
for( i = 0; i < HPM->plugin_count; i++ ) {
HPM->unload(HPM->plugins[i]);
}
-
+
if( HPM->plugins )
aFree(HPM->plugins);
-
+
for( i = 0; i < HPM->symbol_count; i++ ) {
aFree(HPM->symbols[i]);
}
-
+
if( HPM->symbols )
aFree(HPM->symbols);
-
+
for( i = 0; i < hpPHP_MAX; i++ ) {
if( HPM->packets[i] )
aFree(HPM->packets[i]);
}
-
+
for( i = 0; i < HPCT_MAX; i++ ) {
if( HPM->confsc[i] )
aFree(HPM->confs[i]);
}
-
+
HPM->arg_db->destroy(HPM->arg_db,HPM->arg_db_clear_sub);
-
+
/* HPM->fnames is cleared after the memory manager goes down */
iMalloc->post_shutdown = hpm_memdown;
-
+
return;
}
void hpm_defaults(void) {
unsigned int i;
HPM = &HPM_s;
-
+
HPM->fnames = NULL;
HPM->fnamec = 0;
HPM->force_return = false;
@@ -919,7 +917,7 @@ void hpm_defaults(void) {
/* */
HPM->init = hpm_init;
HPM->final = hpm_final;
-
+
HPM->create = hplugin_create;
HPM->load = hplugin_load;
HPM->unload = hplugin_unload;
diff --git a/src/common/atomic.h b/src/common/atomic.h
index e73b1c464..a42dfad1c 100644
--- a/src/common/atomic.h
+++ b/src/common/atomic.h
@@ -8,9 +8,9 @@
// (Interlocked CompareExchange, Add .. and so on ..)
//
// Implementation varies / depends on:
-// - Architecture
-// - Compiler
-// - Operating System
+// - Architecture
+// - Compiler
+// - Operating System
//
// our Abstraction is fully API-Compatible to Microsoft's implementation @ NT5.0+
//
@@ -29,13 +29,13 @@ forceinline int64 InterlockedCompareExchange64(volatile int64 *dest, int64 exch,
_asm{
lea esi,_cmp;
lea edi,exch;
-
+
mov eax,[esi];
mov edx,4[esi];
mov ebx,[edi];
mov ecx,4[edi];
mov esi,dest;
-
+
lock CMPXCHG8B [esi];
}
}
@@ -109,7 +109,7 @@ static forceinline int64 InterlockedIncrement64(volatile int64 *addend){
static forceinline int32 InterlockedIncrement(volatile int32 *addend){
- return __sync_add_and_fetch(addend, 1);
+ return __sync_add_and_fetch(addend, 1);
}//end: InterlockedIncrement()
@@ -139,7 +139,7 @@ static forceinline int64 InterlockedExchange64(volatile int64 *target, int64 val
static forceinline int32 InterlockedExchange(volatile int32 *target, int32 val){
- return __sync_lock_test_and_set(target, val);
+ return __sync_lock_test_and_set(target, val);
}//end: InterlockedExchange()
diff --git a/src/common/cbasetypes.h b/src/common/cbasetypes.h
index 18bc0b8cb..df1d364d4 100644
--- a/src/common/cbasetypes.h
+++ b/src/common/cbasetypes.h
@@ -117,56 +117,56 @@
// Integers with guaranteed _exact_ size.
//////////////////////////////////////////////////////////////////////////
-typedef int8_t int8;
-typedef int16_t int16;
-typedef int32_t int32;
-typedef int64_t int64;
+typedef int8_t int8;
+typedef int16_t int16;
+typedef int32_t int32;
+typedef int64_t int64;
-typedef int8_t sint8;
-typedef int16_t sint16;
-typedef int32_t sint32;
-typedef int64_t sint64;
+typedef int8_t sint8;
+typedef int16_t sint16;
+typedef int32_t sint32;
+typedef int64_t sint64;
-typedef uint8_t uint8;
-typedef uint16_t uint16;
-typedef uint32_t uint32;
-typedef uint64_t uint64;
+typedef uint8_t uint8;
+typedef uint16_t uint16;
+typedef uint32_t uint32;
+typedef uint64_t uint64;
#undef UINT8_MIN
#undef UINT16_MIN
#undef UINT32_MIN
#undef UINT64_MIN
-#define UINT8_MIN ((uint8) UINT8_C(0x00))
-#define UINT16_MIN ((uint16)UINT16_C(0x0000))
-#define UINT32_MIN ((uint32)UINT32_C(0x00000000))
-#define UINT64_MIN ((uint64)UINT64_C(0x0000000000000000))
+#define UINT8_MIN ((uint8) UINT8_C(0x00))
+#define UINT16_MIN ((uint16)UINT16_C(0x0000))
+#define UINT32_MIN ((uint32)UINT32_C(0x00000000))
+#define UINT64_MIN ((uint64)UINT64_C(0x0000000000000000))
#undef UINT8_MAX
#undef UINT16_MAX
#undef UINT32_MAX
#undef UINT64_MAX
-#define UINT8_MAX ((uint8) UINT8_C(0xFF))
-#define UINT16_MAX ((uint16)UINT16_C(0xFFFF))
-#define UINT32_MAX ((uint32)UINT32_C(0xFFFFFFFF))
-#define UINT64_MAX ((uint64)UINT64_C(0xFFFFFFFFFFFFFFFF))
+#define UINT8_MAX ((uint8) UINT8_C(0xFF))
+#define UINT16_MAX ((uint16)UINT16_C(0xFFFF))
+#define UINT32_MAX ((uint32)UINT32_C(0xFFFFFFFF))
+#define UINT64_MAX ((uint64)UINT64_C(0xFFFFFFFFFFFFFFFF))
#undef SINT8_MIN
#undef SINT16_MIN
#undef SINT32_MIN
#undef SINT64_MIN
-#define SINT8_MIN ((sint8) INT8_C(0x80))
-#define SINT16_MIN ((sint16)INT16_C(0x8000))
-#define SINT32_MIN ((sint32)INT32_C(0x80000000))
-#define SINT64_MIN ((sint32)INT64_C(0x8000000000000000))
+#define SINT8_MIN ((sint8) INT8_C(0x80))
+#define SINT16_MIN ((sint16)INT16_C(0x8000))
+#define SINT32_MIN ((sint32)INT32_C(0x80000000))
+#define SINT64_MIN ((sint32)INT64_C(0x8000000000000000))
#undef SINT8_MAX
#undef SINT16_MAX
#undef SINT32_MAX
#undef SINT64_MAX
-#define SINT8_MAX ((sint8) INT8_C(0x7F))
-#define SINT16_MAX ((sint16)INT16_C(0x7FFF))
-#define SINT32_MAX ((sint32)INT32_C(0x7FFFFFFF))
-#define SINT64_MAX ((sint64)INT64_C(0x7FFFFFFFFFFFFFFF))
+#define SINT8_MAX ((sint8) INT8_C(0x7F))
+#define SINT16_MAX ((sint16)INT16_C(0x7FFF))
+#define SINT32_MAX ((sint32)INT32_C(0x7FFFFFFF))
+#define SINT64_MAX ((sint64)INT64_C(0x7FFFFFFFFFFFFFFF))
//////////////////////////////////////////////////////////////////////////
// Integers with guaranteed _minimum_ size.
@@ -191,10 +191,10 @@ typedef unsigned long int ppuint32;
#if defined(WIN32) && !defined(MINGW) // does not have a signed size_t
//////////////////////////////
-#if defined(_WIN64) // native 64bit windows platform
-typedef __int64 ssize_t;
+#if defined(_WIN64) // native 64bit windows platform
+typedef __int64 ssize_t;
#else
-typedef int ssize_t;
+typedef int ssize_t;
#endif
//////////////////////////////
#endif
@@ -236,22 +236,22 @@ typedef uintptr_t uintptr;
// some redefine of function redefines for some Compilers
//////////////////////////////////////////////////////////////////////////
#if defined(_MSC_VER) || defined(__BORLANDC__)
-#define strcasecmp stricmp
-#define strncasecmp strnicmp
-#define strncmpi strnicmp
-#define snprintf _snprintf
+#define strcasecmp stricmp
+#define strncasecmp strnicmp
+#define strncmpi strnicmp
+#define snprintf _snprintf
#if defined(_MSC_VER) && _MSC_VER < 1400
-#define vsnprintf _vsnprintf
+#define vsnprintf _vsnprintf
#endif
#else
-#define strcmpi strcasecmp
-#define stricmp strcasecmp
-#define strncmpi strncasecmp
-#define strnicmp strncasecmp
+#define strcmpi strcasecmp
+#define stricmp strcasecmp
+#define strncmpi strncasecmp
+#define strnicmp strncasecmp
#endif
#if defined(_MSC_VER) && _MSC_VER > 1200
-#define strtoull _strtoui64
-#define strtoll _strtoi64
+#define strtoull _strtoui64
+#define strtoll _strtoi64
#endif
// keyword replacement
@@ -286,8 +286,8 @@ typedef uintptr_t uintptr;
#ifndef __bool_true_false_are_defined
// If stdbool.h is not available or does not define this
typedef char bool;
-#define false (1==0)
-#define true (1==1)
+#define false (1==0)
+#define true (1==1)
#define __bool_true_false_are_defined
#endif // __bool_true_false_are_defined
@@ -308,18 +308,17 @@ typedef char bool;
#if 0 //to be activated soon, more tests needed on how VS works with the macro above
#ifdef WIN32
#undef swap
-#define swap(a,b)__asm \
-{ \
- __asm mov eax, dword ptr [a] \
- __asm cmp eax, dword ptr [b] \
- __asm je _ret \
- __asm xor eax, dword ptr [b] \
- __asm mov dword ptr [a], eax \
- __asm xor eax, dword ptr [b] \
- __asm mov dword ptr [b], eax \
- __asm xor eax, dword ptr [a] \
- __asm mov dword ptr [a], eax \
- __asm _ret: \
+#define swap(a,b)__asm { \
+ __asm mov eax, dword ptr [a] \
+ __asm cmp eax, dword ptr [b] \
+ __asm je _ret \
+ __asm xor eax, dword ptr [b] \
+ __asm mov dword ptr [a], eax \
+ __asm xor eax, dword ptr [b] \
+ __asm mov dword ptr [b], eax \
+ __asm xor eax, dword ptr [a] \
+ __asm mov dword ptr [a], eax \
+ __asm _ret: \
}
#endif
#endif
@@ -343,7 +342,7 @@ typedef char bool;
//////////////////////////////////////////////////////////////////////////
// number of bits in a byte
#ifndef NBBY
-#define NBBY 8
+#define NBBY 8
#endif
//////////////////////////////////////////////////////////////////////////
diff --git a/src/common/conf.c b/src/common/conf.c
index 34d1cacbf..c974decf9 100644
--- a/src/common/conf.c
+++ b/src/common/conf.c
@@ -34,10 +34,10 @@ void config_setting_copy_simple(config_setting_t *parent, const config_setting_t
}
else {
config_setting_t *set;
-
+
if( libconfig->setting_get_member(parent, config_setting_name(src)) != NULL )
return;
-
+
if ((set = libconfig->setting_add(parent, config_setting_name(src), config_setting_type(src))) == NULL)
return;
@@ -83,14 +83,14 @@ void config_setting_copy_aggregate(config_setting_t *parent, const config_settin
if( libconfig->setting_get_member(parent, config_setting_name(src)) != NULL )
return;
-
+
newAgg = libconfig->setting_add(parent, config_setting_name(src), config_setting_type(src));
if (newAgg == NULL)
return;
n = config_setting_length(src);
-
+
for (i = 0; i < n; i++) {
if (config_setting_is_group(src)) {
libconfig->setting_copy_simple(newAgg, libconfig->setting_get_elem(src, i));
@@ -101,7 +101,6 @@ void config_setting_copy_aggregate(config_setting_t *parent, const config_settin
}
int config_setting_copy(config_setting_t *parent, const config_setting_t *src) {
-
if (!config_setting_is_group(parent) && !config_setting_is_list(parent))
return CONFIG_FALSE;
@@ -115,7 +114,7 @@ int config_setting_copy(config_setting_t *parent, const config_setting_t *src) {
void libconfig_defaults(void) {
libconfig = &libconfig_s;
-
+
libconfig->read = config_read;
libconfig->write = config_write;
/* */
diff --git a/src/common/conf.h b/src/common/conf.h
index c232a035c..9ea5f5b72 100644
--- a/src/common/conf.h
+++ b/src/common/conf.h
@@ -22,21 +22,21 @@ struct libconfig_interface {
int (*read_string) (config_t *config, const char *str);
int (*read_file_src) (config_t *config, const char *filename);
int (*write_file) (config_t *config, const char *filename);
-
+
void (*set_destructor) (config_t *config, void (*destructor)(void *));
void (*set_include_dir) (config_t *config, const char *include_dir);
-
+
void (*init) (config_t *config);
void (*destroy) (config_t *config);
-
+
int (*setting_get_int) (const config_setting_t *setting);
long long (*setting_get_int64) (const config_setting_t *setting);
double (*setting_get_float) (const config_setting_t *setting);
-
+
int (*setting_get_bool) (const config_setting_t *setting);
-
+
const char * (*setting_get_string) (const config_setting_t *setting);
-
+
int (*setting_lookup_int) (const config_setting_t *setting, const char *name, int *value);
int (*setting_lookup_int64) (const config_setting_t *setting, const char *name, long long *value);
int (*setting_lookup_float) (const config_setting_t *setting, const char *name, double *value);
@@ -47,10 +47,10 @@ struct libconfig_interface {
int (*setting_set_float) (config_setting_t *setting, double value);
int (*setting_set_bool) (config_setting_t *setting, int value);
int (*setting_set_string) (config_setting_t *setting, const char *value);
-
+
int (*setting_set_format) (config_setting_t *setting, short format);
short (*setting_get_format) (const config_setting_t *setting);
-
+
int (*setting_get_int_elem) (const config_setting_t *setting, int idx);
long long (*setting_get_int64_elem) (const config_setting_t *setting, int idx);
double (*setting_get_float_elem) (const config_setting_t *setting, int idx);
@@ -61,19 +61,19 @@ struct libconfig_interface {
config_setting_t * (*setting_set_float_elem) (config_setting_t *setting, int idx, double value);
config_setting_t * (*setting_set_bool_elem) (config_setting_t *setting, int idx, int value);
config_setting_t * (*setting_set_string_elem) (config_setting_t *setting, int idx, const char *value);
-
+
int (*setting_index) (const config_setting_t *setting);
int (*setting_length) (const config_setting_t *setting);
-
+
config_setting_t * (*setting_get_elem) (const config_setting_t *setting, unsigned int idx);
config_setting_t * (*setting_get_member) (const config_setting_t *setting, const char *name);
-
+
config_setting_t * (*setting_add) (config_setting_t *parent, const char *name, int type);
int (*setting_remove) (config_setting_t *parent, const char *name);
-
+
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);
@@ -81,7 +81,7 @@ struct libconfig_interface {
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);
-
+
/* those are custom and are from src/common/conf.c */
/* Functions to copy settings from libconfig/contrib */
int (*read_file) (config_t *config, const char *config_filename);
diff --git a/src/common/console.c b/src/common/console.c
index 6a82db555..577d1a3f0 100644
--- a/src/common/console.c
+++ b/src/common/console.c
@@ -43,7 +43,7 @@ struct console_input_interface console_input_s;
#endif
/*======================================
- * CORE : Display title
+ * CORE : Display title
*--------------------------------------*/
void display_title(void) {
const char *vcstype = sysinfo->vcstype();
@@ -80,18 +80,18 @@ int console_parse_key_pressed(void) {
fd_set fds;
tv.tv_sec = 0;
tv.tv_usec = 0;
-
+
FD_ZERO(&fds);
FD_SET(STDIN_FILENO, &fds);
-
+
select(STDIN_FILENO+1, &fds, NULL, NULL, &tv);
-
+
return FD_ISSET(STDIN_FILENO, &fds);
}
#endif /* _WIN32 */
/*======================================
- * CORE: Console commands
+ * CORE: Console commands
*--------------------------------------*/
/**
@@ -152,20 +152,22 @@ CPCMD_C(skip,update) {
}
/**
- * Defines a main category
- * Categories can't be used as commands!
+ * Defines a main category.
+ *
+ * Categories can't be used as commands!
* E.G.
- * sql update skip
- * 'sql' is the main category
+ * - 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!
+ * Defines a sub-category.
+ *
+ * Sub-categories can't be used as commands!
* E.G.
- * sql update skip
- * 'update' is a sub-category
+ * - sql update skip
+ * 'update' is a sub-category
* CP_DEF_C2(command, category)
**/
#define CP_DEF_C2(x,y) { #x , NULL , #y, NULL }
@@ -209,21 +211,21 @@ void console_load_defaults(void) {
};
unsigned int i, len = ARRAYLENGTH(default_list);
struct CParseEntry *cmd;
-
+
RECREATE(console->input->cmds,struct CParseEntry *, len);
-
+
for(i = 0; i < len; i++) {
CREATE(cmd, struct CParseEntry, 1);
-
+
safestrncpy(cmd->cmd, default_list[i].name, CP_CMD_LENGTH);
-
+
if( default_list[i].func )
cmd->u.func = default_list[i].func;
else
cmd->u.next = NULL;
-
+
cmd->next_count = 0;
-
+
console->input->cmd_count++;
console->input->cmds[i] = cmd;
default_list[i].self = cmd;
@@ -232,7 +234,7 @@ void console_load_defaults(void) {
console->input->cmd_list[console->input->cmd_list_count - 1] = cmd;
}
}
-
+
for(i = 0; i < len; i++) {
unsigned int k;
if( !default_list[i].connect )
@@ -256,10 +258,10 @@ void console_parse_create(char *name, CParseFunc func) {
char *tok;
char sublist[CP_CMD_LENGTH * 5];
struct CParseEntry *cmd;
-
+
safestrncpy(sublist, name, CP_CMD_LENGTH * 5);
tok = strtok(sublist,":");
-
+
for ( i = 0; i < console->input->cmd_list_count; i++ ) {
if( strcmpi(tok,console->input->cmd_list[i]->cmd) == 0 )
break;
@@ -278,12 +280,11 @@ void console_parse_create(char *name, CParseFunc func) {
cmd = console->input->cmd_list[i];
while( ( tok = strtok(NULL, ":") ) != NULL ) {
-
for(i = 0; i < cmd->next_count; i++) {
if( strcmpi(cmd->u.next[i]->cmd,tok) == 0 )
break;
}
-
+
if ( i == cmd->next_count ) {
RECREATE(console->input->cmds,struct CParseEntry *, ++console->input->cmd_count);
CREATE(console->input->cmds[console->input->cmd_count-1], struct CParseEntry, 1);
@@ -294,7 +295,6 @@ void console_parse_create(char *name, CParseFunc func) {
cmd = console->input->cmds[console->input->cmd_count-1];
continue;
}
-
}
cmd->u.func = func;
}
@@ -320,24 +320,24 @@ void console_parse_sub(char *line) {
char *tok;
char sublist[CP_CMD_LENGTH * 5];
unsigned int i, len = 0;
-
+
memcpy(bline, line, 200);
tok = strtok(line, " ");
-
+
for ( i = 0; i < console->input->cmd_list_count; i++ ) {
if( strcmpi(tok,console->input->cmd_list[i]->cmd) == 0 )
break;
}
-
+
if( i == console->input->cmd_list_count ) {
ShowError("'"CL_WHITE"%s"CL_RESET"' is not a known command, type '"CL_WHITE"help"CL_RESET"' to list all commands\n",line);
return;
}
-
+
cmd = console->input->cmd_list[i];
-
+
len += snprintf(sublist,CP_CMD_LENGTH * 5,"%s", cmd->cmd) + 1;
-
+
if( cmd->next_count == 0 && console->input->cmd_list[i]->u.func ) {
char *r = NULL;
if( (tok = strtok(NULL, " ")) ) {
@@ -381,8 +381,8 @@ void console_parse_sub(char *line) {
}
}
void console_parse(char* line) {
- int c, i = 0, len = MAX_CONSOLE_INPUT - 1;/* we leave room for the \0 :P */
-
+ int c, i = 0, len = MAX_CONSOLE_INPUT - 1;/* we leave room for the \0 :P */
+
while( (c = fgetc(stdin)) != EOF ) {
if( --len == 0 )
break;
@@ -391,33 +391,32 @@ void console_parse(char* line) {
break;/* new line~! we leave it for the next cycle */
}
}
-
+
line[i++] = '\0';
}
void *cThread_main(void *x) {
-
while( console->input->ptstate ) {/* loopx */
if( console->input->key_pressed() ) {
char input[MAX_CONSOLE_INPUT];
-
+
console->input->parse(input);
if( input[0] != '\0' ) {/* did we get something? */
EnterSpinLock(&console->input->ptlock);
-
+
if( cinput.count == CONSOLE_PARSE_SIZE ) {
LeaveSpinLock(&console->input->ptlock);
continue;/* drop */
}
-
+
safestrncpy(cinput.queue[cinput.count++],input,MAX_CONSOLE_INPUT);
LeaveSpinLock(&console->input->ptlock);
}
}
ramutex_lock( console->input->ptmutex );
- racond_wait( console->input->ptcond, console->input->ptmutex, -1 );
+ racond_wait( console->input->ptcond, console->input->ptmutex, -1 );
ramutex_unlock( console->input->ptmutex );
}
-
+
return NULL;
}
int console_parse_timer(int tid, int64 tick, int id, intptr_t data) {
@@ -435,7 +434,7 @@ void console_parse_final(void) {
if( console->input->ptstate ) {
InterlockedDecrement(&console->input->ptstate);
racond_signal(console->input->ptcond);
-
+
/* wait for thread to close */
rathread_wait(console->input->pthread, NULL);
@@ -445,22 +444,21 @@ void console_parse_final(void) {
}
void console_parse_init(void) {
cinput.count = 0;
-
+
console->input->ptstate = 1;
InitializeSpinLock(&console->input->ptlock);
-
+
console->input->ptmutex = ramutex_create();
console->input->ptcond = racond_create();
-
+
if( (console->input->pthread = rathread_create(console->input->pthread_main, NULL)) == NULL ){
ShowFatalError("console_parse_init: failed to spawn console_parse thread.\n");
exit(EXIT_FAILURE);
}
-
+
timer->add_func_list(console->input->parse_timer, "console_parse_timer");
timer->add_interval(timer->gettick() + 1000, console->input->parse_timer, 0, 0, 500);/* start listening in 1s; re-try every 0.5s */
-
}
void console_setSQL(Sql *SQL_handle) {
console->input->SQL = SQL_handle;
diff --git a/src/common/core.c b/src/common/core.c
index 99dbc36ec..04434a5dd 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -48,14 +48,14 @@ char **arg_v = NULL;
char *SERVER_NAME = NULL;
-#ifndef MINICORE // minimalist Core
+#ifndef MINICORE // minimalist Core
// Added by Gabuzomeu
//
// This is an implementation of signal() using sigaction() for portability.
// (sigaction() is POSIX; signal() is not.) Taken from Stevens' _Advanced
// Programming in the UNIX Environment_.
//
-#ifdef WIN32 // windows don't have SIGPIPE
+#ifdef WIN32 // windows don't have SIGPIPE
#define SIGPIPE SIGINT
#endif
@@ -69,7 +69,7 @@ sigfunc *compat_signal(int signo, sigfunc *func) {
sigemptyset(&sact.sa_mask);
sact.sa_flags = 0;
#ifdef SA_INTERRUPT
- sact.sa_flags |= SA_INTERRUPT; /* SunOS */
+ sact.sa_flags |= SA_INTERRUPT; /* SunOS */
#endif
if (sigaction(signo, &sact, &oact) < 0)
@@ -80,7 +80,7 @@ sigfunc *compat_signal(int signo, sigfunc *func) {
#endif
/*======================================
- * CORE : Console events for Windows
+ * CORE : Console events for Windows
*--------------------------------------*/
#ifdef _WIN32
static BOOL WINAPI console_handler(DWORD c_event) {
@@ -106,7 +106,7 @@ static void cevents_init(void) {
#endif
/*======================================
- * CORE : Signal Sub Function
+ * CORE : Signal Sub Function
*--------------------------------------*/
static void sig_proc(int sn) {
static int is_called = 0;
@@ -132,11 +132,11 @@ static void sig_proc(int sn) {
case SIGXFSZ:
// ignore and allow it to set errno to EFBIG
ShowWarning ("Max file size reached!\n");
- //run_flag = 0; // should we quit?
+ //run_flag = 0; // should we quit?
break;
case SIGPIPE:
- //ShowInfo ("Broken pipe found... closing socket\n"); // set to eof in socket.c
- break; // does nothing here
+ //ShowInfo ("Broken pipe found... closing socket\n"); // set to eof in socket.c
+ break; // does nothing here
#endif
}
}
@@ -185,7 +185,7 @@ void core_defaults(void) {
#endif
}
/*======================================
- * CORE : MAINROUTINE
+ * CORE : MAINROUTINE
*--------------------------------------*/
int main (int argc, char **argv) {
int retval = EXIT_SUCCESS;
@@ -209,7 +209,7 @@ int main (int argc, char **argv) {
}
}
}
-
+
iMalloc->init();// needed for Show* in display_title() [FlavioJS]
sysinfo->init();
@@ -229,7 +229,7 @@ int main (int argc, char **argv) {
rathread_init();
DB->init();
signals_init();
-
+
#ifdef _WIN32
cevents_init();
#endif
@@ -239,11 +239,11 @@ int main (int argc, char **argv) {
/* timer first */
rnd_init();
srand((unsigned int)timer->gettick());
-
+
console->init();
-
+
HCache->init();
-
+
HPM->init();
sockt->init();
@@ -258,7 +258,7 @@ int main (int argc, char **argv) {
}
console->final();
-
+
retval = do_final();
HPM->final();
timer->final();
diff --git a/src/common/db.c b/src/common/db.c
index b227d66bc..044df19aa 100644
--- a/src/common/db.c
+++ b/src/common/db.c
@@ -579,7 +579,7 @@ static void db_rebalance_erase(DBNode *node, DBNode **root)
x = x_parent;
x_parent = x_parent->parent;
} else {
- if (w->right == NULL || w->right->color == BLACK) {
+ if (w->right == NULL || w->right->color == BLACK) {
if (w->left) w->left->color = BLACK;
w->color = RED;
db_rotate_right(w, root);
@@ -1231,7 +1231,7 @@ static void db_release_both(DBKey key, DBData data, DBRelease which)
DBData* dbit_obj_first(DBIterator* self, DBKey* out_key)
{
DBIterator_impl* it = (DBIterator_impl*)self;
-
+
DB_COUNTSTAT(dbit_first);
// position before the first entry
it->ht_index = -1;
@@ -1253,7 +1253,7 @@ DBData* dbit_obj_first(DBIterator* self, DBKey* out_key)
DBData* dbit_obj_last(DBIterator* self, DBKey* out_key)
{
DBIterator_impl* it = (DBIterator_impl*)self;
-
+
DB_COUNTSTAT(dbit_last);
// position after the last entry
it->ht_index = HASH_SIZE;
@@ -1375,7 +1375,6 @@ DBData* dbit_obj_prev(DBIterator* self, DBKey* out_key)
node = &fake;
}
-
while( node )
{// next node
if( node->left )
@@ -1662,17 +1661,17 @@ static unsigned int db_obj_vgetall(DBMap* self, DBData **buf, unsigned int max,
}
va_end(argscopy);
}
-
+
if (node->left) {
node = node->left;
continue;
}
-
+
if (node->right) {
node = node->right;
continue;
}
-
+
while (node) {
parent = node->parent;
if (parent && parent->right && parent->left == node) {
@@ -1859,7 +1858,7 @@ static DBData* db_obj_ensure(DBMap* self, DBKey key, DBCreateData create, ...)
* @see #db_malloc_dbn(void)
* @see DBMap#put
* FIXME: If this method fails shouldn't it return another value?
- * Other functions rely on this to know if they were able to put something [Panikon]
+ * Other functions rely on this to know if they were able to put something [Panikon]
*/
static int db_obj_put(DBMap* self, DBKey key, DBData data, DBData *out_data)
{
@@ -1981,7 +1980,7 @@ static int db_obj_remove(DBMap* self, DBKey key, DBData *out_data)
db->alloc_file, db->alloc_line);
return 0; // nullpo candidate
}
- if (!(db->options&DB_OPT_ALLOW_NULL_KEY) && db_is_key_null(db->type, key)) {
+ if (!(db->options&DB_OPT_ALLOW_NULL_KEY) && db_is_key_null(db->type, key)) {
ShowError("db_remove: Attempted to use non-allowed NULL key for db allocated at %s:%d\n",db->alloc_file, db->alloc_line);
return 0; // nullpo candidate
}
@@ -2645,7 +2644,7 @@ DBKey db_str2key(const char *key)
DBKey db_i642key(int64 key)
{
DBKey ret;
-
+
DB_COUNTSTAT(db_i642key);
ret.i64 = key;
return ret;
@@ -2660,7 +2659,7 @@ DBKey db_i642key(int64 key)
DBKey db_ui642key(uint64 key)
{
DBKey ret;
-
+
DB_COUNTSTAT(db_ui642key);
ret.ui64 = key;
return ret;
diff --git a/src/common/db.h b/src/common/db.h
index f500520a9..88265c3e8 100644
--- a/src/common/db.h
+++ b/src/common/db.h
@@ -848,7 +848,7 @@ DBKey (*i642key) (int64 key);
* @public
*/
DBKey (*ui642key) (uint64 key);
-
+
/**
* Manual cast from 'int' to the struct DBData.
* @param data Data to be casted
@@ -1500,7 +1500,7 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...);
VECTOR_INDEX(__heap,0) = VECTOR_POP(__heap); /* put last at index */ \
if( !VECTOR_LENGTH(__heap) ) /* removed last, nothing to do */ \
break; \
- BHEAP_SIFTUP(__heap,0,__topcmp,__swp); \
+ BHEAP_SIFTUP(__heap,0,__topcmp,__swp); \
}while(0)
@@ -1562,7 +1562,7 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...);
/// @param __idx Index of an inserted element
/// @param __topcmp Comparator
/// @param __swp Swapper
-#define BHEAP_SIFTDOWN(__heap,__startidx,__idx,__topcmp,__swp) \
+#define BHEAP_SIFTDOWN(__heap,__startidx,__idx,__topcmp,__swp) \
do{ \
size_t _i2_ = __idx; \
while( _i2_ > __startidx ) \
diff --git a/src/common/des.c b/src/common/des.c
index 7f952be76..89a920bc9 100644
--- a/src/common/des.c
+++ b/src/common/des.c
@@ -103,14 +103,14 @@ static void E(BIT64* src)
}
#endif
// optimized
- tmp.b[0] = ((src->b[7]<<5) | (src->b[4]>>3)) & 0x3f; // ..0 vutsr
- tmp.b[1] = ((src->b[4]<<1) | (src->b[5]>>7)) & 0x3f; // ..srqpo n
- tmp.b[2] = ((src->b[4]<<5) | (src->b[5]>>3)) & 0x3f; // ..o nmlkj
- tmp.b[3] = ((src->b[5]<<1) | (src->b[6]>>7)) & 0x3f; // ..kjihg f
- tmp.b[4] = ((src->b[5]<<5) | (src->b[6]>>3)) & 0x3f; // ..g fedcb
- tmp.b[5] = ((src->b[6]<<1) | (src->b[7]>>7)) & 0x3f; // ..cba98 7
- tmp.b[6] = ((src->b[6]<<5) | (src->b[7]>>3)) & 0x3f; // ..8 76543
- tmp.b[7] = ((src->b[7]<<1) | (src->b[4]>>7)) & 0x3f; // ..43210 v
+ tmp.b[0] = ((src->b[7]<<5) | (src->b[4]>>3)) & 0x3f; // ..0 vutsr
+ tmp.b[1] = ((src->b[4]<<1) | (src->b[5]>>7)) & 0x3f; // ..srqpo n
+ tmp.b[2] = ((src->b[4]<<5) | (src->b[5]>>3)) & 0x3f; // ..o nmlkj
+ tmp.b[3] = ((src->b[5]<<1) | (src->b[6]>>7)) & 0x3f; // ..kjihg f
+ tmp.b[4] = ((src->b[5]<<5) | (src->b[6]>>3)) & 0x3f; // ..g fedcb
+ tmp.b[5] = ((src->b[6]<<1) | (src->b[7]>>7)) & 0x3f; // ..cba98 7
+ tmp.b[6] = ((src->b[6]<<5) | (src->b[7]>>3)) & 0x3f; // ..8 76543
+ tmp.b[7] = ((src->b[7]<<1) | (src->b[4]>>7)) & 0x3f; // ..43210 v
*src = tmp;
}
diff --git a/src/common/ers.c b/src/common/ers.c
index c8a11d2a9..489d8f7ae 100644
--- a/src/common/ers.c
+++ b/src/common/ers.c
@@ -83,19 +83,19 @@ typedef struct ers_cache
// Free objects count
unsigned int Free;
-
+
// Used blocks count
unsigned int Used;
-
+
// Objects in-use count
unsigned int UsedObjs;
-
+
// Default = ERS_BLOCK_ENTRIES, can be adjusted for performance for individual cache sizes.
unsigned int ChunkSize;
-
+
// Misc options, some options are shared from the instance
enum ERSOptions Options;
-
+
// Linked list
struct ers_cache *Next, *Prev;
} ers_cache_t;
@@ -103,10 +103,10 @@ typedef struct ers_cache
struct ers_instance_t {
// Interface to ERS
struct eri VTable;
-
+
// Name, used for debugging purposes
char *Name;
-
+
// Misc options
enum ERSOptions Options;
@@ -115,7 +115,7 @@ struct ers_instance_t {
// Count of objects in use, used for detecting memory leaks
unsigned int Count;
-
+
#ifdef DEBUG
/* for data analysis [Ind/Hercules] */
unsigned int Peak;
@@ -149,7 +149,7 @@ static ers_cache_t *ers_find_cache(unsigned int size, enum ERSOptions Options) {
cache->Max = 0;
cache->ChunkSize = ERS_BLOCK_ENTRIES;
cache->Options = (Options & ERS_CACHE_OPTIONS);
-
+
if (CacheList == NULL)
{
CacheList = cache;
@@ -181,7 +181,7 @@ static void ers_free_cache(ers_cache_t *cache, bool remove)
CacheList = cache->Next;
aFree(cache->Blocks);
-
+
aFree(cache);
}
@@ -216,7 +216,7 @@ static void *ers_obj_alloc_entry(ERS *self)
instance->Count++;
instance->Cache->UsedObjs++;
-
+
#ifdef DEBUG
if( instance->Count > instance->Peak )
instance->Peak = instance->Count;
@@ -240,7 +240,7 @@ static void ers_obj_free_entry(ERS *self, void *entry)
if( instance->Cache->Options & ERS_OPT_CLEAN )
memset((unsigned char*)reuse + sizeof(struct ers_list), 0, instance->Cache->ObjectSize - sizeof(struct ers_list));
-
+
reuse->Next = instance->Cache->ReuseList;
instance->Cache->ReuseList = reuse;
instance->Count--;
@@ -277,27 +277,27 @@ static void ers_obj_destroy(ERS *self)
if (instance->Next)
instance->Next->Prev = instance->Prev;
-
+
if (instance->Prev)
instance->Prev->Next = instance->Next;
else
InstanceList = instance->Next;
-
+
if( instance->Options & ERS_OPT_FREE_NAME )
aFree(instance->Name);
-
+
aFree(instance);
}
void ers_cache_size(ERS *self, unsigned int new_size) {
struct ers_instance_t *instance = (struct ers_instance_t *)self;
-
+
nullpo_retv(instance);
-
+
if( !(instance->Cache->Options&ERS_OPT_FLEX_CHUNK) ) {
ShowWarning("ers_cache_size: '%s' has adjusted its chunk size to '%d', however ERS_OPT_FLEX_CHUNK is missing!\n",instance->Name,new_size);
}
-
+
instance->Cache->ChunkSize = new_size;
}
@@ -321,7 +321,7 @@ ERS *ers_new(uint32 size, char *name, enum ERSOptions options)
instance->Options = options;
instance->Cache = ers_find_cache(size,instance->Options);
-
+
instance->Cache->ReferenceCount++;
if (InstanceList == NULL) {
@@ -384,7 +384,7 @@ void ers_report(void) {
**/
void ers_final(void) {
struct ers_instance_t *instance = InstanceList, *next;
-
+
while( instance ) {
next = instance->Next;
ers_obj_destroy((ERS*)instance);
diff --git a/src/common/ers.h b/src/common/ers.h
index 904f7fb81..8c56118ae 100644
--- a/src/common/ers.h
+++ b/src/common/ers.h
@@ -77,7 +77,7 @@ enum ERSOptions {
ERS_OPT_FREE_NAME = 0x4,/* name is dynamic memory, and should be freed */
ERS_OPT_CLEAN = 0x8,/* clears used memory upon ers_free so that its all new to be reused on the next alloc */
ERS_OPT_FLEX_CHUNK = 0x10,/* signs that it should look for its own cache given it'll have a dynamic chunk size, so that it doesn't affect the other ERS it'd otherwise be sharing */
-
+
/* Compound, is used to determine whether it should be looking for a cache of matching options */
ERS_CACHE_OPTIONS = ERS_OPT_CLEAN|ERS_OPT_FLEX_CHUNK,
};
diff --git a/src/common/grfio.c b/src/common/grfio.c
index 5be0c8237..eeda7e4b5 100644
--- a/src/common/grfio.c
+++ b/src/common/grfio.c
@@ -21,7 +21,7 @@
#include "../common/utils.h"
//----------------------------
-// file entry table struct
+// file entry table struct
//----------------------------
typedef struct FILELIST {
int srclen; ///< compressed size
@@ -50,14 +50,14 @@ typedef struct FILELIST {
// stores info about every loaded file
-FILELIST* filelist = NULL;
-int filelist_entrys = 0;
-int filelist_maxentry = 0;
+FILELIST* filelist = NULL;
+int filelist_entrys = 0;
+int filelist_maxentry = 0;
// stores grf file names
-char** gentry_table = NULL;
-int gentry_entrys = 0;
-int gentry_maxentry = 0;
+char** gentry_table = NULL;
+int gentry_entrys = 0;
+int gentry_maxentry = 0;
// the path to the data directory
char data_dir[1024] = "";
@@ -109,22 +109,23 @@ static uint8_t grf_substitution(uint8_t in)
return out;
}
-/* this is not used anywhere, is it ok to delete? */
-//static void grf_shuffle_enc(BIT64* src) {
-// BIT64 out;
-//
-// out.b[0] = src->b[3];
-// out.b[1] = src->b[4];
-// out.b[2] = src->b[5];
-// out.b[3] = src->b[0];
-// out.b[4] = src->b[1];
-// out.b[5] = src->b[6];
-// out.b[6] = src->b[2];
-// out.b[7] = grf_substitution(src->b[7]);
-//
-// *src = out;
-//}
+#if 0 /* this is not used anywhere, is it ok to delete? */
+static void grf_shuffle_enc(BIT64* src)
+{
+ BIT64 out;
+ out.b[0] = src->b[3];
+ out.b[1] = src->b[4];
+ out.b[2] = src->b[5];
+ out.b[3] = src->b[0];
+ out.b[4] = src->b[1];
+ out.b[5] = src->b[6];
+ out.b[6] = src->b[2];
+ out.b[7] = grf_substitution(src->b[7]);
+
+ *src = out;
+}
+#endif // 0
static void grf_shuffle_dec(BIT64* src)
{
@@ -425,7 +426,7 @@ void* grfio_reads(const char* fname, int* size)
*size = declen;
} else {
if (entry != NULL && entry->gentry < 0) {
- entry->gentry = -entry->gentry; // local file checked
+ entry->gentry = -entry->gentry; // local file checked
} else {
ShowError("grfio_reads: %s not found (local file: %s)\n", fname, lfname);
return NULL;
@@ -515,7 +516,7 @@ static int grfio_entryread(const char* grfname, int gentry)
FILE* fp = fopen(grfname, "rb");
if( fp == NULL ) {
ShowWarning("GRF data file not found: '%s'\n",grfname);
- return 1; // 1:not found error
+ return 1; // 1:not found error
} else
ShowInfo("GRF data file found: '%s'\n",grfname);
@@ -527,7 +528,7 @@ static int grfio_entryread(const char* grfname, int gentry)
if( strcmp((const char*)grf_header,"Master of Magic") != 0 || fseek(fp,getlong(grf_header+0x1e),SEEK_CUR) != 0 ) {
fclose(fp);
ShowError("GRF %s read error\n", grfname);
- return 2; // 2:file format error
+ return 2; // 2:file format error
}
grf_version = getlong(grf_header+0x2a) >> 8;
@@ -565,11 +566,11 @@ static int grfio_entryread(const char* grfname, int gentry)
aentry.srcpos = getlong(grf_filelist+ofs2+13)+0x2e;
aentry.type = type;
safestrncpy(aentry.fn, fname, sizeof(aentry.fn));
- aentry.fnd = NULL;
-#ifdef GRFIO_LOCAL
- aentry.gentry = -(gentry+1); // As Flag for making it a negative number carrying out the first time LocalFileCheck
+ aentry.fnd = NULL;
+#ifdef GRFIO_LOCAL
+ aentry.gentry = -(gentry+1); // As Flag for making it a negative number carrying out the first time LocalFileCheck
#else
- aentry.gentry = (char)(gentry+1); // With no first time LocalFileCheck
+ aentry.gentry = (char)(gentry+1); // With no first time LocalFileCheck
#endif
filelist_modify(&aentry);
}
@@ -584,8 +585,8 @@ static int grfio_entryread(const char* grfname, int gentry)
uLongf rSize, eSize;
if(fread(eheader,1,8,fp) != 8) ShowError("An error occurred in fread while reading header buffer\n");
- rSize = getlong(eheader); // Read Size
- eSize = getlong(eheader+4); // Extend Size
+ rSize = getlong(eheader); // Read Size
+ eSize = getlong(eheader+4); // Extend Size
if( (long)rSize > grf_size-ftell(fp) ) {
fclose(fp);
@@ -593,11 +594,11 @@ static int grfio_entryread(const char* grfname, int gentry)
return 4;
}
- rBuf = (unsigned char *)aMalloc(rSize); // Get a Read Size
- grf_filelist = (unsigned char *)aMalloc(eSize); // Get a Extend Size
+ rBuf = (unsigned char *)aMalloc(rSize); // Get a Read Size
+ grf_filelist = (unsigned char *)aMalloc(eSize); // Get a Extend Size
if(fread(rBuf,1,rSize,fp) != rSize) ShowError("An error occurred in fread \n");
fclose(fp);
- decode_zip(grf_filelist, &eSize, rBuf, rSize); // Decode function
+ decode_zip(grf_filelist, &eSize, rBuf, rSize); // Decode function
aFree(rBuf);
entrys = getlong(grf_header+0x26) - 7;
@@ -623,11 +624,11 @@ static int grfio_entryread(const char* grfname, int gentry)
aentry.srcpos = getlong(grf_filelist+ofs2+13)+0x2e;
aentry.type = (char)type;
safestrncpy(aentry.fn, fname, sizeof(aentry.fn));
- aentry.fnd = NULL;
-#ifdef GRFIO_LOCAL
- aentry.gentry = -(gentry+1); // As Flag for making it a negative number carrying out the first time LocalFileCheck
+ aentry.fnd = NULL;
+#ifdef GRFIO_LOCAL
+ aentry.gentry = -(gentry+1); // As Flag for making it a negative number carrying out the first time LocalFileCheck
#else
- aentry.gentry = (char)(gentry+1); // With no first time LocalFileCheck
+ aentry.gentry = (char)(gentry+1); // With no first time LocalFileCheck
#endif
filelist_modify(&aentry);
}
@@ -642,9 +643,9 @@ static int grfio_entryread(const char* grfname, int gentry)
return 4;
}
- filelist_compact(); // Unnecessary area release of filelist
+ filelist_compact(); // Unnecessary area release of filelist
- return 0; // 0:no error
+ return 0; // 0:no error
}
@@ -714,7 +715,7 @@ static void grfio_resourcecheck(void)
fclose(fp);
ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", i, "resnametable.txt");
- return; // we're done here!
+ return; // we're done here!
}
// read resnametable from loaded GRF's, only if it cannot be loaded from the data directory
@@ -745,12 +746,12 @@ static void grfio_resourcecheck(void)
/// Reads a grf file and adds it to the list.
static int grfio_add(const char* fname)
{
- if( gentry_entrys >= gentry_maxentry )
- {
- #define GENTRY_ADDS 4 // The number increment of gentry_table entries
+ if (gentry_entrys >= gentry_maxentry) {
+#define GENTRY_ADDS 4 // The number increment of gentry_table entries
gentry_maxentry += GENTRY_ADDS;
gentry_table = (char**)aRealloc(gentry_table, gentry_maxentry * sizeof(char*));
memset(gentry_table + (gentry_maxentry - GENTRY_ADDS), 0, sizeof(char*) * GENTRY_ADDS);
+#undef GENTRY_ADDS
}
gentry_table[gentry_entrys++] = aStrdup(fname);
@@ -792,7 +793,7 @@ void grfio_init(const char* fname)
FILE* data_conf;
int grf_num = 0;
- hashinit(); // hash table initialization
+ hashinit(); // hash table initialization
data_conf = fopen(fname, "r");
if( data_conf != NULL )
diff --git a/src/common/malloc.c b/src/common/malloc.c
index eae9ad423..625875b76 100644
--- a/src/common/malloc.c
+++ b/src/common/malloc.c
@@ -143,7 +143,7 @@ void aFree_(void *p, const char *file, int line, const char *func)
* Since the complex processing, I might be slightly heavier.
*
* (I'm sorry for the poor description ^ ^;) such as data structures
-* Divided into "blocks" of a plurality of memory, "unit" of a plurality of blocks further
+* Divided into "blocks" of a plurality of memory, "unit" of a plurality of blocks further
* I have to divide. Size of the unit, a plurality of distribution equal to the capacity of one block
* That's what you have. For example, if one unit of 32KB, one block 1 Yu 32Byte
* Knit, or are able to gather 1024, gathered 512 units 64Byte
@@ -155,33 +155,33 @@ void aFree_(void *p, const char *file, int line, const char *func)
*/
/* Alignment of the block */
-#define BLOCK_ALIGNMENT1 16
-#define BLOCK_ALIGNMENT2 64
+#define BLOCK_ALIGNMENT1 16
+#define BLOCK_ALIGNMENT2 64
/* Amount of data entering a block */
-#define BLOCK_DATA_COUNT1 128
-#define BLOCK_DATA_COUNT2 608
+#define BLOCK_DATA_COUNT1 128
+#define BLOCK_DATA_COUNT2 608
/* The size of the block: 16*128 + 64*576 = 40KB */
-#define BLOCK_DATA_SIZE1 ( BLOCK_ALIGNMENT1 * BLOCK_DATA_COUNT1 )
-#define BLOCK_DATA_SIZE2 ( BLOCK_ALIGNMENT2 * BLOCK_DATA_COUNT2 )
-#define BLOCK_DATA_SIZE ( BLOCK_DATA_SIZE1 + BLOCK_DATA_SIZE2 )
+#define BLOCK_DATA_SIZE1 ( BLOCK_ALIGNMENT1 * BLOCK_DATA_COUNT1 )
+#define BLOCK_DATA_SIZE2 ( BLOCK_ALIGNMENT2 * BLOCK_DATA_COUNT2 )
+#define BLOCK_DATA_SIZE ( BLOCK_DATA_SIZE1 + BLOCK_DATA_SIZE2 )
/* The number of blocks to be allocated at a time. */
-#define BLOCK_ALLOC 104
+#define BLOCK_ALLOC 104
/* block */
struct block {
- struct block* block_next; /* Then the allocated area */
- struct block* unfill_prev; /* The previous area not filled */
- struct block* unfill_next; /* The next area not filled */
- unsigned short unit_size; /* The size of the unit */
- unsigned short unit_hash; /* The hash of the unit */
- unsigned short unit_count; /* The number of units */
- unsigned short unit_used; /* The number of used units */
- unsigned short unit_unfill; /* The number of unused units */
- unsigned short unit_maxused; /* The maximum value of units used */
- char data[ BLOCK_DATA_SIZE ];
+ struct block *block_next; ///< Then the allocated area
+ struct block *unfill_prev; ///< The previous area not filled
+ struct block *unfill_next; ///< The next area not filled
+ unsigned short unit_size; ///< The size of the unit
+ unsigned short unit_hash; ///< The hash of the unit
+ unsigned short unit_count; ///< The number of units
+ unsigned short unit_used; ///< The number of used units
+ unsigned short unit_unfill; ///< The number of unused units
+ unsigned short unit_maxused; ///< The maximum value of units used
+ char data[BLOCK_DATA_SIZE];
};
struct unit_head {
@@ -222,7 +222,7 @@ static unsigned short size2hash( size_t size )
return (unsigned short)(size - BLOCK_DATA_SIZE1 + BLOCK_ALIGNMENT2 - 1) / BLOCK_ALIGNMENT2
+ BLOCK_DATA_COUNT1;
} else {
- return 0xffff; // If it exceeds the block length hash I do not
+ return 0xffff; // If it exceeds the block length hash I do not
}
}
@@ -375,13 +375,13 @@ void *mrealloc_(void *memblock, size_t size, const char *file, int line, const c
void *mreallocz_(void *memblock, size_t size, const char *file, int line, const char *func) {
size_t old_size;
void *p = NULL;
-
+
if(memblock == NULL) {
p = iMalloc->malloc(size,file,line,func);
memset(p,0,size);
return p;
}
-
+
old_size = ((struct unit_head *)((char *)memblock - sizeof(struct unit_head) + sizeof(long)))->size;
if( old_size == 0 ) {
old_size = ((struct unit_head_large *)((char *)memblock - sizeof(struct unit_head_large) + sizeof(long)))->size;
@@ -702,7 +702,7 @@ void memmgr_report (int extra) {
unsigned int count;
} data[100];
memset(&data, 0, sizeof(data));
-
+
if( extra != 0 )
msize = extra;
@@ -732,7 +732,7 @@ void memmgr_report (int extra) {
}
block = block->block_next;
}
-
+
while(large) {
if( large->size > msize ) {
for( j = 0; j < 100; j++ ) {
@@ -760,7 +760,7 @@ void memmgr_report (int extra) {
}
ShowMessage("[malloc] : reporting %u instances | %.2f MB\n",count,(double)((size)/1024)/1024);
ShowMessage("[malloc] : internal usage %.2f MB | %.2f MB\n",(double)((memmgr_usage_bytes_t-memmgr_usage_bytes)/1024)/1024,(double)((memmgr_usage_bytes_t)/1024)/1024);
-
+
if (extra) {
ShowMessage("[malloc] : unit_head_large: %"PRIuS" bytes\n", sizeof(struct unit_head_large));
ShowMessage("[malloc] : unit_head: %"PRIuS" bytes\n", sizeof(struct unit_head));
@@ -848,19 +848,19 @@ void malloc_defaults(void) {
// Athena's built-in Memory Manager
#ifdef USE_MEMMGR
- iMalloc->malloc = mmalloc_;
- iMalloc->calloc = mcalloc_;
- iMalloc->realloc = mrealloc_;
- iMalloc->reallocz= mreallocz_;
- iMalloc->astrdup = mstrdup_;
- iMalloc->free = mfree_;
+ iMalloc->malloc = mmalloc_;
+ iMalloc->calloc = mcalloc_;
+ iMalloc->realloc = mrealloc_;
+ iMalloc->reallocz = mreallocz_;
+ iMalloc->astrdup = mstrdup_;
+ iMalloc->free = mfree_;
#else
- iMalloc->malloc = aMalloc_;
- iMalloc->calloc = aCalloc_;
- iMalloc->realloc = aRealloc_;
- iMalloc->reallocz= aRealloc_;/* not using memory manager huhum o.o perhaps we could still do something about */
- iMalloc->astrdup = aStrdup_;
- iMalloc->free = aFree_;
+ iMalloc->malloc = aMalloc_;
+ iMalloc->calloc = aCalloc_;
+ iMalloc->realloc = aRealloc_;
+ iMalloc->reallocz = aRealloc_;/* not using memory manager huhum o.o perhaps we could still do something about */
+ iMalloc->astrdup = aStrdup_;
+ iMalloc->free = aFree_;
#endif
iMalloc->post_shutdown = NULL;
}
diff --git a/src/common/malloc.h b/src/common/malloc.h
index 8dace2d68..53d2ebdd2 100644
--- a/src/common/malloc.h
+++ b/src/common/malloc.h
@@ -68,19 +68,19 @@
void malloc_defaults(void);
struct malloc_interface {
- void (*init) (void);
- void (*final) (void);
+ void (*init) (void);
+ void (*final) (void);
/* */
- void* (*malloc )(size_t size, const char *file, int line, const char *func);
- void* (*calloc )(size_t num, size_t size, const char *file, int line, const char *func);
- void* (*realloc )(void *p, size_t size, const char *file, int line, const char *func);
+ void* (*malloc)(size_t size, const char *file, int line, const char *func);
+ void* (*calloc)(size_t num, size_t size, const char *file, int line, const char *func);
+ void* (*realloc)(void *p, size_t size, const char *file, int line, const char *func);
void* (*reallocz)(void *p, size_t size, const char *file, int line, const char *func);
- char* (*astrdup )(const char *p, const char *file, int line, const char *func);
- void (*free )(void *p, const char *file, int line, const char *func);
+ char* (*astrdup)(const char *p, const char *file, int line, const char *func);
+ void (*free)(void *p, const char *file, int line, const char *func);
/* */
- void (*memory_check)(void);
- bool (*verify_ptr)(void* ptr);
- size_t (*usage) (void);
+ void (*memory_check)(void);
+ bool (*verify_ptr)(void* ptr);
+ size_t (*usage) (void);
/* */
void (*post_shutdown) (void);
};
diff --git a/src/common/mapindex.c b/src/common/mapindex.c
index 0873b3e59..ec829ee56 100644
--- a/src/common/mapindex.c
+++ b/src/common/mapindex.c
@@ -24,7 +24,7 @@ struct mapindex_interface mapindex_s;
const char* mapindex_getmapname(const char* string, char* output) {
static char buf[MAP_NAME_LENGTH];
char* dest = (output != NULL) ? output : buf;
-
+
size_t len = strnlen(string, MAP_NAME_LENGTH_EXT);
if (len == MAP_NAME_LENGTH_EXT) {
ShowWarning("(mapindex_normalize_name) Map name '%*s' is too long!\n", 2*MAP_NAME_LENGTH_EXT, string);
@@ -32,11 +32,11 @@ const char* mapindex_getmapname(const char* string, char* output) {
}
if (len >= 4 && stricmp(&string[len-4], ".gat") == 0)
len -= 4; // strip .gat extension
-
+
len = min(len, MAP_NAME_LENGTH-1);
safestrncpy(dest, string, len+1);
memset(&dest[len], '\0', MAP_NAME_LENGTH-len);
-
+
return dest;
}
@@ -65,7 +65,7 @@ const char* mapindex_getmapname_ext(const char* string, char* output) {
}
memset(&dest[len], '\0', MAP_NAME_LENGTH_EXT-len);
-
+
return dest;
}
@@ -105,7 +105,7 @@ int mapindex_addmap(int index, const char* name) {
safestrncpy(mapindex->list[index].name, map_name, MAP_NAME_LENGTH);
strdb_iput(mapindex->db, map_name, index);
-
+
if (mapindex->num <= index)
mapindex->num = index+1;
@@ -115,12 +115,12 @@ int mapindex_addmap(int index, const char* name) {
unsigned short mapindex_name2id(const char* name) {
int i;
char map_name[MAP_NAME_LENGTH];
-
+
mapindex->getmapname(name, map_name);
if( (i = strdb_iget(mapindex->db, map_name)) )
return i;
-
+
ShowDebug("mapindex_name2id: Map \"%s\" not found in index list!\n", map_name);
return 0;
}
@@ -139,14 +139,14 @@ int mapindex_init(void) {
int last_index = -1;
int index, total = 0;
char map_name[13];
-
+
if( ( fp = fopen(mapindex->config_file,"r") ) == NULL ){
ShowFatalError("Unable to read mapindex config file %s!\n", mapindex->config_file);
exit(EXIT_FAILURE); //Server can't really run without this file.
}
mapindex->db = strdb_alloc(DB_OPT_DUP_KEY, MAP_NAME_LENGTH);
-
+
while(fgets(line, sizeof(line), fp)) {
if(line[0] == '/' && line[1] == '/')
continue;
@@ -168,7 +168,7 @@ int mapindex_init(void) {
if( !strdb_iget(mapindex->db, MAP_DEFAULT) ) {
ShowError("mapindex_init: MAP_DEFAULT '%s' not found in cache! update mapindex.h MAP_DEFAULT var!!!\n",MAP_DEFAULT);
}
-
+
return total;
}
@@ -183,14 +183,14 @@ void mapindex_final(void) {
void mapindex_defaults(void) {
mapindex = &mapindex_s;
-
+
/* TODO: place it in inter-server.conf? */
snprintf(mapindex->config_file, 80, "%s","db/map_index.txt");
/* */
mapindex->db = NULL;
mapindex->num = 0;
memset (&mapindex->list, 0, sizeof (mapindex->list));
-
+
/* */
mapindex->init = mapindex_init;
mapindex->final = mapindex_final;
diff --git a/src/common/md5calc.c b/src/common/md5calc.c
index e7b506e27..18e502da2 100644
--- a/src/common/md5calc.c
+++ b/src/common/md5calc.c
@@ -25,22 +25,22 @@ static unsigned int *pX;
// String Table
static const unsigned int T[] = {
- 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, //0
- 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, //4
- 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, //8
- 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, //12
- 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, //16
- 0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8, //20
- 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, //24
- 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, //28
- 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, //32
- 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, //36
- 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x4881d05, //40
- 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, //44
- 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, //48
- 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, //52
- 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, //56
- 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391 //60
+ 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, //0
+ 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, //4
+ 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, //8
+ 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, //12
+ 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, //16
+ 0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8, //20
+ 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, //24
+ 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, //28
+ 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, //32
+ 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, //36
+ 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x4881d05, //40
+ 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, //44
+ 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, //48
+ 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, //52
+ 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, //56
+ 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391 //60
};
// ROTATE_LEFT The left is made to rotate x [ n-bit ]. This is diverted as it is from RFC.
@@ -49,25 +49,25 @@ static const unsigned int T[] = {
// The function used for other calculation
static unsigned int F(unsigned int X, unsigned int Y, unsigned int Z)
{
- return (X & Y) | (~X & Z);
+ return (X & Y) | (~X & Z);
}
static unsigned int G(unsigned int X, unsigned int Y, unsigned int Z)
{
- return (X & Z) | (Y & ~Z);
+ return (X & Z) | (Y & ~Z);
}
static unsigned int H(unsigned int X, unsigned int Y, unsigned int Z)
{
- return X ^ Y ^ Z;
+ return X ^ Y ^ Z;
}
static unsigned int I(unsigned int X, unsigned int Y, unsigned int Z)
{
- return Y ^ (X | ~Z);
+ return Y ^ (X | ~Z);
}
static unsigned int Round(unsigned int a, unsigned int b, unsigned int FGHI,
- unsigned int k, unsigned int s, unsigned int i)
+ unsigned int k, unsigned int s, unsigned int i)
{
- return b + ROTATE_LEFT(a + FGHI + pX[k] + T[i], s);
+ return b + ROTATE_LEFT(a + FGHI + pX[k] + T[i], s);
}
static void Round1(unsigned int *a, unsigned int b, unsigned int c,
@@ -113,103 +113,103 @@ static void MD5_Round_Calculate(const unsigned char *block,
| ( ((unsigned int )block[j+3]) << 24 );
- //Round 1
- Round1(&A,B,C,D, 0, 7, 0); Round1(&D,A,B,C, 1, 12, 1); Round1(&C,D,A,B, 2, 17, 2); Round1(&B,C,D,A, 3, 22, 3);
- Round1(&A,B,C,D, 4, 7, 4); Round1(&D,A,B,C, 5, 12, 5); Round1(&C,D,A,B, 6, 17, 6); Round1(&B,C,D,A, 7, 22, 7);
- Round1(&A,B,C,D, 8, 7, 8); Round1(&D,A,B,C, 9, 12, 9); Round1(&C,D,A,B, 10, 17, 10); Round1(&B,C,D,A, 11, 22, 11);
- Round1(&A,B,C,D, 12, 7, 12); Round1(&D,A,B,C, 13, 12, 13); Round1(&C,D,A,B, 14, 17, 14); Round1(&B,C,D,A, 15, 22, 15);
-
- //Round 2
- Round2(&A,B,C,D, 1, 5, 16); Round2(&D,A,B,C, 6, 9, 17); Round2(&C,D,A,B, 11, 14, 18); Round2(&B,C,D,A, 0, 20, 19);
- Round2(&A,B,C,D, 5, 5, 20); Round2(&D,A,B,C, 10, 9, 21); Round2(&C,D,A,B, 15, 14, 22); Round2(&B,C,D,A, 4, 20, 23);
- Round2(&A,B,C,D, 9, 5, 24); Round2(&D,A,B,C, 14, 9, 25); Round2(&C,D,A,B, 3, 14, 26); Round2(&B,C,D,A, 8, 20, 27);
- Round2(&A,B,C,D, 13, 5, 28); Round2(&D,A,B,C, 2, 9, 29); Round2(&C,D,A,B, 7, 14, 30); Round2(&B,C,D,A, 12, 20, 31);
-
- //Round 3
- Round3(&A,B,C,D, 5, 4, 32); Round3(&D,A,B,C, 8, 11, 33); Round3(&C,D,A,B, 11, 16, 34); Round3(&B,C,D,A, 14, 23, 35);
- Round3(&A,B,C,D, 1, 4, 36); Round3(&D,A,B,C, 4, 11, 37); Round3(&C,D,A,B, 7, 16, 38); Round3(&B,C,D,A, 10, 23, 39);
- Round3(&A,B,C,D, 13, 4, 40); Round3(&D,A,B,C, 0, 11, 41); Round3(&C,D,A,B, 3, 16, 42); Round3(&B,C,D,A, 6, 23, 43);
- Round3(&A,B,C,D, 9, 4, 44); Round3(&D,A,B,C, 12, 11, 45); Round3(&C,D,A,B, 15, 16, 46); Round3(&B,C,D,A, 2, 23, 47);
-
- //Round 4
- Round4(&A,B,C,D, 0, 6, 48); Round4(&D,A,B,C, 7, 10, 49); Round4(&C,D,A,B, 14, 15, 50); Round4(&B,C,D,A, 5, 21, 51);
- Round4(&A,B,C,D, 12, 6, 52); Round4(&D,A,B,C, 3, 10, 53); Round4(&C,D,A,B, 10, 15, 54); Round4(&B,C,D,A, 1, 21, 55);
- Round4(&A,B,C,D, 8, 6, 56); Round4(&D,A,B,C, 15, 10, 57); Round4(&C,D,A,B, 6, 15, 58); Round4(&B,C,D,A, 13, 21, 59);
- Round4(&A,B,C,D, 4, 6, 60); Round4(&D,A,B,C, 11, 10, 61); Round4(&C,D,A,B, 2, 15, 62); Round4(&B,C,D,A, 9, 21, 63);
-
- // Then perform the following additions. (let's add)
- *A2 = A + AA;
- *B2 = B + BB;
- *C2 = C + CC;
- *D2 = D + DD;
-
- //The clearance of confidential information
- memset(pX, 0, sizeof(X));
+ //Round 1
+ Round1(&A,B,C,D, 0, 7, 0); Round1(&D,A,B,C, 1, 12, 1); Round1(&C,D,A,B, 2, 17, 2); Round1(&B,C,D,A, 3, 22, 3);
+ Round1(&A,B,C,D, 4, 7, 4); Round1(&D,A,B,C, 5, 12, 5); Round1(&C,D,A,B, 6, 17, 6); Round1(&B,C,D,A, 7, 22, 7);
+ Round1(&A,B,C,D, 8, 7, 8); Round1(&D,A,B,C, 9, 12, 9); Round1(&C,D,A,B, 10, 17, 10); Round1(&B,C,D,A, 11, 22, 11);
+ Round1(&A,B,C,D, 12, 7, 12); Round1(&D,A,B,C, 13, 12, 13); Round1(&C,D,A,B, 14, 17, 14); Round1(&B,C,D,A, 15, 22, 15);
+
+ //Round 2
+ Round2(&A,B,C,D, 1, 5, 16); Round2(&D,A,B,C, 6, 9, 17); Round2(&C,D,A,B, 11, 14, 18); Round2(&B,C,D,A, 0, 20, 19);
+ Round2(&A,B,C,D, 5, 5, 20); Round2(&D,A,B,C, 10, 9, 21); Round2(&C,D,A,B, 15, 14, 22); Round2(&B,C,D,A, 4, 20, 23);
+ Round2(&A,B,C,D, 9, 5, 24); Round2(&D,A,B,C, 14, 9, 25); Round2(&C,D,A,B, 3, 14, 26); Round2(&B,C,D,A, 8, 20, 27);
+ Round2(&A,B,C,D, 13, 5, 28); Round2(&D,A,B,C, 2, 9, 29); Round2(&C,D,A,B, 7, 14, 30); Round2(&B,C,D,A, 12, 20, 31);
+
+ //Round 3
+ Round3(&A,B,C,D, 5, 4, 32); Round3(&D,A,B,C, 8, 11, 33); Round3(&C,D,A,B, 11, 16, 34); Round3(&B,C,D,A, 14, 23, 35);
+ Round3(&A,B,C,D, 1, 4, 36); Round3(&D,A,B,C, 4, 11, 37); Round3(&C,D,A,B, 7, 16, 38); Round3(&B,C,D,A, 10, 23, 39);
+ Round3(&A,B,C,D, 13, 4, 40); Round3(&D,A,B,C, 0, 11, 41); Round3(&C,D,A,B, 3, 16, 42); Round3(&B,C,D,A, 6, 23, 43);
+ Round3(&A,B,C,D, 9, 4, 44); Round3(&D,A,B,C, 12, 11, 45); Round3(&C,D,A,B, 15, 16, 46); Round3(&B,C,D,A, 2, 23, 47);
+
+ //Round 4
+ Round4(&A,B,C,D, 0, 6, 48); Round4(&D,A,B,C, 7, 10, 49); Round4(&C,D,A,B, 14, 15, 50); Round4(&B,C,D,A, 5, 21, 51);
+ Round4(&A,B,C,D, 12, 6, 52); Round4(&D,A,B,C, 3, 10, 53); Round4(&C,D,A,B, 10, 15, 54); Round4(&B,C,D,A, 1, 21, 55);
+ Round4(&A,B,C,D, 8, 6, 56); Round4(&D,A,B,C, 15, 10, 57); Round4(&C,D,A,B, 6, 15, 58); Round4(&B,C,D,A, 13, 21, 59);
+ Round4(&A,B,C,D, 4, 6, 60); Round4(&D,A,B,C, 11, 10, 61); Round4(&C,D,A,B, 2, 15, 62); Round4(&B,C,D,A, 9, 21, 63);
+
+ // Then perform the following additions. (let's add)
+ *A2 = A + AA;
+ *B2 = B + BB;
+ *C2 = C + CC;
+ *D2 = D + DD;
+
+ //The clearance of confidential information
+ memset(pX, 0, sizeof(X));
}
static void MD5_String2binary(const char * string, unsigned char * output)
{
//var
- /*8bit*/
- unsigned char padding_message[64]; //Extended message 512bit 64byte
- unsigned char *pstring; //The position of string in the present scanning notes is held.
-
- /*32bit*/
- unsigned int string_byte_len, //The byte chief of string is held.
- string_bit_len, //The bit length of string is held.
- copy_len, //The number of bytes which is used by 1-3 and which remained
- msg_digest[4]; //Message digest 128bit 4byte
- unsigned int *A = &msg_digest[0], //The message digest in accordance with RFC (reference)
- *B = &msg_digest[1],
- *C = &msg_digest[2],
- *D = &msg_digest[3];
+ /*8bit*/
+ unsigned char padding_message[64]; //Extended message 512bit 64byte
+ unsigned char *pstring; //The position of string in the present scanning notes is held.
+
+ /*32bit*/
+ unsigned int string_byte_len, //The byte chief of string is held.
+ string_bit_len, //The bit length of string is held.
+ copy_len, //The number of bytes which is used by 1-3 and which remained
+ msg_digest[4]; //Message digest 128bit 4byte
+ unsigned int *A = &msg_digest[0], //The message digest in accordance with RFC (reference)
+ *B = &msg_digest[1],
+ *C = &msg_digest[2],
+ *D = &msg_digest[3];
int i;
//prog
- //Step 3.Initialize MD Buffer (although it is the initialization; step 3 of A, B, C, and D -- unavoidable -- a head)
- *A = 0x67452301;
- *B = 0xefcdab89;
- *C = 0x98badcfe;
- *D = 0x10325476;
-
- //Step 1.Append Padding Bits (extension of a mark bit)
- //1-1
- string_byte_len = (unsigned int)strlen(string); //The byte chief of a character sequence is acquired.
- pstring = (unsigned char *)string; //The position of the present character sequence is set.
-
- //1-2 Repeat calculation until length becomes less than 64 bytes.
- for (i=string_byte_len; 64<=i; i-=64,pstring+=64)
- MD5_Round_Calculate(pstring, A,B,C,D);
-
- //1-3
- copy_len = string_byte_len % 64; //The number of bytes which remained is computed.
- strncpy((char *)padding_message, (char *)pstring, copy_len); //A message is copied to an extended bit sequence.
- memset(padding_message+copy_len, 0, 64 - copy_len); //It buries by 0 until it becomes extended bit length.
- padding_message[copy_len] |= 0x80; //The next of a message is 1.
-
- //1-4
- //If 56 bytes or more (less than 64 bytes) of remainder becomes, it will calculate by extending to 64 bytes.
- if (56 <= copy_len) {
- MD5_Round_Calculate(padding_message, A,B,C,D);
- memset(padding_message, 0, 56); //56 bytes is newly fill uped with 0.
- }
-
- //Step 2.Append Length (the information on length is added)
- string_bit_len = string_byte_len * 8; //From the byte chief to bit length (32 bytes of low rank)
- memcpy(&padding_message[56], &string_bit_len, 4); //32 bytes of low rank is set.
-
- //When bit length cannot be expressed in 32 bytes of low rank, it is a beam raising to a higher rank.
- if (UINT_MAX / 8 < string_byte_len) {
- unsigned int high = (string_byte_len - UINT_MAX / 8) * 8;
- memcpy(&padding_message[60], &high, 4);
- } else
- memset(&padding_message[60], 0, 4); //In this case, it is good for a higher rank at 0.
-
- //Step 4.Process Message in 16-Word Blocks (calculation of MD5)
- MD5_Round_Calculate(padding_message, A,B,C,D);
-
- //Step 5.Output (output)
- memcpy(output,msg_digest,16);
+ //Step 3.Initialize MD Buffer (although it is the initialization; step 3 of A, B, C, and D -- unavoidable -- a head)
+ *A = 0x67452301;
+ *B = 0xefcdab89;
+ *C = 0x98badcfe;
+ *D = 0x10325476;
+
+ //Step 1.Append Padding Bits (extension of a mark bit)
+ //1-1
+ string_byte_len = (unsigned int)strlen(string); //The byte chief of a character sequence is acquired.
+ pstring = (unsigned char *)string; //The position of the present character sequence is set.
+
+ //1-2 Repeat calculation until length becomes less than 64 bytes.
+ for (i=string_byte_len; 64<=i; i-=64,pstring+=64)
+ MD5_Round_Calculate(pstring, A,B,C,D);
+
+ //1-3
+ copy_len = string_byte_len % 64; //The number of bytes which remained is computed.
+ strncpy((char *)padding_message, (char *)pstring, copy_len); //A message is copied to an extended bit sequence.
+ memset(padding_message+copy_len, 0, 64 - copy_len); //It buries by 0 until it becomes extended bit length.
+ padding_message[copy_len] |= 0x80; //The next of a message is 1.
+
+ //1-4
+ //If 56 bytes or more (less than 64 bytes) of remainder becomes, it will calculate by extending to 64 bytes.
+ if (56 <= copy_len) {
+ MD5_Round_Calculate(padding_message, A,B,C,D);
+ memset(padding_message, 0, 56); //56 bytes is newly fill uped with 0.
+ }
+
+ //Step 2.Append Length (the information on length is added)
+ string_bit_len = string_byte_len * 8; //From the byte chief to bit length (32 bytes of low rank)
+ memcpy(&padding_message[56], &string_bit_len, 4); //32 bytes of low rank is set.
+
+ //When bit length cannot be expressed in 32 bytes of low rank, it is a beam raising to a higher rank.
+ if (UINT_MAX / 8 < string_byte_len) {
+ unsigned int high = (string_byte_len - UINT_MAX / 8) * 8;
+ memcpy(&padding_message[60], &high, 4);
+ } else
+ memset(&padding_message[60], 0, 4); //In this case, it is good for a higher rank at 0.
+
+ //Step 4.Process Message in 16-Word Blocks (calculation of MD5)
+ MD5_Round_Calculate(padding_message, A,B,C,D);
+
+ //Step 5.Output (output)
+ memcpy(output,msg_digest,16);
}
//-------------------------------------------------------------------
@@ -227,7 +227,7 @@ void MD5_String(const char * string, char * output)
unsigned char digest[16];
MD5_String2binary(string,digest);
- sprintf(output, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
+ sprintf(output, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
digest[ 0], digest[ 1], digest[ 2], digest[ 3],
digest[ 4], digest[ 5], digest[ 6], digest[ 7],
digest[ 8], digest[ 9], digest[10], digest[11],
diff --git a/src/common/mmo.h b/src/common/mmo.h
index 597b25126..fd054ba91 100644
--- a/src/common/mmo.h
+++ b/src/common/mmo.h
@@ -73,14 +73,14 @@
#define HOTKEY_SAVING
#if PACKETVER < 20090603
- // (27 = 9 skills x 3 bars) (0x02b9,191)
- #define MAX_HOTKEYS 27
+ // (27 = 9 skills x 3 bars) (0x02b9,191)
+ #define MAX_HOTKEYS 27
#elif PACKETVER < 20090617
- // (36 = 9 skills x 4 bars) (0x07d9,254)
- #define MAX_HOTKEYS 36
+ // (36 = 9 skills x 4 bars) (0x07d9,254)
+ #define MAX_HOTKEYS 36
#else // >= 20090617
- // (38 = 9 skills x 4 bars & 2 Quickslots)(0x07d9,268)
- #define MAX_HOTKEYS 38
+ // (38 = 9 skills x 4 bars & 2 Quickslots)(0x07d9,268)
+ #define MAX_HOTKEYS 38
#endif // 20090603
#endif // 20070227
@@ -469,7 +469,7 @@ struct mmo_charstatus {
/* `account_data` modifiers */
unsigned short mod_exp,mod_drop,mod_death;
-
+
unsigned char font;
uint32 uniqueitem_counter;
@@ -593,15 +593,15 @@ struct guild {
struct guild_alliance alliance[MAX_GUILDALLIANCE];
struct guild_expulsion expulsion[MAX_GUILDEXPULSION];
struct guild_skill skill[MAX_GUILDSKILL];
-
+
/* used on char.c to state what kind of data is being saved/processed */
unsigned short save_flag;
-
+
short *instance;
unsigned short instances;
-
+
struct hChSysCh *channel;
-
+
/* HPM Custom Struct */
struct HPluginData **hdata;
unsigned int hdatac;
diff --git a/src/common/mutex.c b/src/common/mutex.c
index f046febf6..31202d440 100644
--- a/src/common/mutex.c
+++ b/src/common/mutex.c
@@ -52,19 +52,19 @@ struct racond{
ramutex *ramutex_create(void) {
struct ramutex *m;
-
+
m = (struct ramutex*)aMalloc( sizeof(struct ramutex) );
if (m == NULL) {
ShowFatalError("ramutex_create: OOM while allocating %"PRIuS" bytes.\n", sizeof(struct ramutex));
return NULL;
}
-
+
#ifdef WIN32
InitializeCriticalSection(&m->hMutex);
#else
pthread_mutex_init(&m->hMutex, NULL);
#endif
-
+
return m;
}//end: ramutex_create()
@@ -101,7 +101,7 @@ bool ramutex_trylock(ramutex *m) {
#else
if(pthread_mutex_trylock(&m->hMutex) == 0)
return true;
-
+
return false;
#endif
}//end: ramutex_trylock()
@@ -126,7 +126,7 @@ void ramutex_unlock(ramutex *m) {
racond *racond_create(void) {
struct racond *c;
-
+
c = (struct racond*)aMalloc( sizeof(struct racond) );
if (c == NULL) {
ShowFatalError("racond_create: OOM while allocating %"PRIuS" bytes\n", sizeof(struct racond));
@@ -135,13 +135,13 @@ racond *racond_create(void) {
#ifdef WIN32
c->nWaiters = 0;
- c->events[ EVENT_COND_SIGNAL ] = CreateEvent( NULL, FALSE, FALSE, NULL );
- c->events[ EVENT_COND_BROADCAST ] = CreateEvent( NULL, TRUE, FALSE, NULL );
+ c->events[EVENT_COND_SIGNAL] = CreateEvent(NULL, FALSE, FALSE, NULL);
+ c->events[EVENT_COND_BROADCAST] = CreateEvent(NULL, TRUE, FALSE, NULL);
InitializeCriticalSection( &c->waiters_lock );
#else
pthread_cond_init(&c->hCond, NULL);
#endif
-
+
return c;
}//end: racond_create()
@@ -174,24 +174,20 @@ void racond_wait(racond *c, ramutex *m, sysint timeout_ticks) {
ms = INFINITE;
else
ms = (timeout_ticks > MAXDWORD) ? (MAXDWORD - 1) : (DWORD)timeout_ticks;
-
-
+
// we can release the mutex (m) here, cause win's
// manual reset events maintain state when used with
// SetEvent()
ramutex_unlock(m);
result = WaitForMultipleObjects(2, c->events, FALSE, ms);
-
-
+
EnterCriticalSection(&c->waiters_lock);
c->nWaiters--;
if( (result == WAIT_OBJECT_0 + EVENT_COND_BROADCAST) && (c->nWaiters == 0) )
is_last = true; // Broadcast called!
LeaveCriticalSection(&c->waiters_lock);
-
-
// we are the last waiter that has to be notified, or to stop waiting
// so we have to do a manual reset
if(is_last == true)
@@ -206,10 +202,10 @@ void racond_wait(racond *c, ramutex *m, sysint timeout_ticks) {
}else{
struct timespec wtime;
int64 exact_timeout = timer->gettick() + timeout_ticks;
-
+
wtime.tv_sec = exact_timeout/1000;
wtime.tv_nsec = (exact_timeout%1000)*1000000;
-
+
pthread_cond_timedwait( &c->hCond, &m->hMutex, &wtime);
}
@@ -219,13 +215,15 @@ void racond_wait(racond *c, ramutex *m, sysint timeout_ticks) {
void racond_signal(racond *c) {
#ifdef WIN32
-// bool has_waiters = false;
-// EnterCriticalSection(&c->waiters_lock);
-// if(c->nWaiters > 0)
-// has_waiters = true;
-// LeaveCriticalSection(&c->waiters_lock);
-
-// if(has_waiters == true)
+# if 0
+ bool has_waiters = false;
+ EnterCriticalSection(&c->waiters_lock);
+ if(c->nWaiters > 0)
+ has_waiters = true;
+ LeaveCriticalSection(&c->waiters_lock);
+
+ if(has_waiters == true)
+# endif // 0
SetEvent( c->events[ EVENT_COND_SIGNAL ] );
#else
pthread_cond_signal(&c->hCond);
@@ -235,13 +233,15 @@ void racond_signal(racond *c) {
void racond_broadcast(racond *c) {
#ifdef WIN32
-// bool has_waiters = false;
-// EnterCriticalSection(&c->waiters_lock);
-// if(c->nWaiters > 0)
-// has_waiters = true;
-// LeaveCriticalSection(&c->waiters_lock);
-
-// if(has_waiters == true)
+# if 0
+ bool has_waiters = false;
+ EnterCriticalSection(&c->waiters_lock);
+ if(c->nWaiters > 0)
+ has_waiters = true;
+ LeaveCriticalSection(&c->waiters_lock);
+
+ if(has_waiters == true)
+# endif // 0
SetEvent( c->events[ EVENT_COND_BROADCAST ] );
#else
pthread_cond_broadcast(&c->hCond);
diff --git a/src/common/nullpo.c b/src/common/nullpo.c
index a3471b00d..0333c02ef 100644
--- a/src/common/nullpo.c
+++ b/src/common/nullpo.c
@@ -24,10 +24,10 @@
void assert_report(const char *file, int line, const char *func, const char *targetname, const char *title) {
if (file == NULL)
file = "??";
-
+
if (func == NULL || *func == '\0')
func = "unknown";
-
+
ShowError("--- %s --------------------------------------------\n", title);
ShowError("%s:%d: '%s' in function `%s'\n", file, line, targetname, func);
ShowError("--- end %s ----------------------------------------\n", title);
diff --git a/src/common/showmsg.c b/src/common/showmsg.c
index f3982d364..0dd645eeb 100644
--- a/src/common/showmsg.c
+++ b/src/common/showmsg.c
@@ -93,20 +93,20 @@ int console_msg_log = 0;//[Ind] msg error logging
//
// \033[#;...;#m - Set Graphics Rendition (SGR)
//
-// printf("\x1b[1;31;40m"); // Bright red on black
-// printf("\x1b[3;33;45m"); // Blinking yellow on magenta (blink not implemented)
-// printf("\x1b[1;30;47m"); // Bright black (grey) on dim white
+// printf("\x1b[1;31;40m"); // Bright red on black
+// printf("\x1b[3;33;45m"); // Blinking yellow on magenta (blink not implemented)
+// printf("\x1b[1;30;47m"); // Bright black (grey) on dim white
//
// Style Foreground Background
-// 1st Digit 2nd Digit 3rd Digit RGB
-// 0 - Reset 30 - Black 40 - Black 000
-// 1 - FG Bright 31 - Red 41 - Red 100
-// 2 - Unknown 32 - Green 42 - Green 010
-// 3 - Blink 33 - Yellow 43 - Yellow 110
-// 4 - Underline 34 - Blue 44 - Blue 001
-// 5 - BG Bright 35 - Magenta 45 - Magenta 101
-// 6 - Unknown 36 - Cyan 46 - Cyan 011
-// 7 - Reverse 37 - White 47 - White 111
+// 1st Digit 2nd Digit 3rd Digit RGB
+// 0 - Reset 30 - Black 40 - Black 000
+// 1 - FG Bright 31 - Red 41 - Red 100
+// 2 - Unknown 32 - Green 42 - Green 010
+// 3 - Blink 33 - Yellow 43 - Yellow 110
+// 4 - Underline 34 - Blue 44 - Blue 001
+// 5 - BG Bright 35 - Magenta 45 - Magenta 101
+// 6 - Unknown 36 - Cyan 46 - Cyan 011
+// 7 - Reverse 37 - White 47 - White 111
// 8 - Concealed (invisible)
//
// \033[#A - Cursor Up (CUU)
@@ -181,7 +181,7 @@ Escape sequences for Select Character Set
#define is_console(handle) (FILE_TYPE_CHAR==GetFileType(handle))
///////////////////////////////////////////////////////////////////////////////
-int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr)
+int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr)
{
/////////////////////////////////////////////////////////////////
/* XXX Two streams are being used. Disabled to avoid inconsistency [flaviojs]
@@ -207,19 +207,18 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr)
// start with processing
p = BUFVAL(tempbuf);
- while ((q = strchr(p, 0x1b)) != NULL)
- { // find the escape character
+ while ((q = strchr(p, 0x1b)) != NULL) {
+ // find the escape character
if( 0==WriteConsole(handle, p, (DWORD)(q-p), &written, 0) ) // write up to the escape
WriteFile(handle, p, (DWORD)(q-p), &written, 0);
- if( q[1]!='[' )
- { // write the escape char (whatever purpose it has)
+ if (q[1]!='[') {
+ // write the escape char (whatever purpose it has)
if(0==WriteConsole(handle, q, 1, &written, 0) )
WriteFile(handle,q, 1, &written, 0);
- p=q+1; //and start searching again
- }
- else
- { // from here, we will skip the '\033['
+ p=q+1; //and start searching again
+ } else {
+ // from here, we will skip the '\033['
// we break at the first unprocessible position
// assuming regular text is starting there
uint8 numbers[16], numpoint=0;
@@ -231,84 +230,72 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr)
// skip escape and bracket
q=q+2;
- for(;;)
- {
- if( ISDIGIT(*q) )
- { // add number to number array, only accept 2digits, shift out the rest
+ for (;;) {
+ if (ISDIGIT(*q)) {
+ // add number to number array, only accept 2digits, shift out the rest
// so // \033[123456789m will become \033[89m
numbers[numpoint] = (numbers[numpoint]<<4) | (*q-'0');
++q;
// and next character
continue;
- }
- else if( *q == ';' )
- { // delimiter
- if(numpoint<sizeof(numbers)/sizeof(*numbers))
- { // go to next array position
+ } else if (*q == ';') {
+ // delimiter
+ if (numpoint < sizeof(numbers)/sizeof(*numbers)) {
+ // go to next array position
numpoint++;
- }
- else
- { // array is full, so we 'forget' the first value
+ } else {
+ // array is full, so we 'forget' the first value
memmove(numbers,numbers+1,sizeof(numbers)/sizeof(*numbers)-1);
numbers[sizeof(numbers)/sizeof(*numbers)-1]=0;
}
++q;
// and next number
continue;
- }
- else if( *q == 'm' )
- { // \033[#;...;#m - Set Graphics Rendition (SGR)
+ } else if (*q == 'm') {
+ // \033[#;...;#m - Set Graphics Rendition (SGR)
uint8 i;
- for(i=0; i<= numpoint; ++i)
- {
- if( 0x00 == (0xF0 & numbers[i]) )
- { // upper nibble 0
- if( 0 == numbers[i] )
- { // reset
+ for (i=0; i<= numpoint; ++i) {
+ if (0x00 == (0xF0 & numbers[i])) {
+ // upper nibble 0
+ if (0 == numbers[i]) {
+ // reset
info.wAttributes = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
- }
- else if( 1==numbers[i] )
- { // set foreground intensity
+ } else if (1 == numbers[i]) {
+ // set foreground intensity
info.wAttributes |= FOREGROUND_INTENSITY;
- }
- else if( 5==numbers[i] )
- { // set background intensity
+ } else if (5 == numbers[i]) {
+ // set background intensity
info.wAttributes |= BACKGROUND_INTENSITY;
- }
- else if( 7==numbers[i] )
- { // reverse colors (just xor them)
+ } else if (7 == numbers[i]) {
+ // reverse colors (just xor them)
info.wAttributes ^= FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE |
- BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE;
+ BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE;
}
//case '2': // not existing
- //case '3': // blinking (not implemented)
- //case '4': // underline (not implemented)
+ //case '3': // blinking (not implemented)
+ //case '4': // underline (not implemented)
//case '6': // not existing
//case '8': // concealed (not implemented)
//case '9': // not existing
- }
- else if( 0x20 == (0xF0 & numbers[i]) )
- { // off
+ } else if (0x20 == (0xF0 & numbers[i])) {
+ // off
- if( 1==numbers[i] )
- { // set foreground intensity off
+ if (1 == numbers[i]) {
+ // set foreground intensity off
info.wAttributes &= ~FOREGROUND_INTENSITY;
- }
- else if( 5==numbers[i] )
- { // set background intensity off
+ } else if (5 == numbers[i]) {
+ // set background intensity off
info.wAttributes &= ~BACKGROUND_INTENSITY;
- }
- else if( 7==numbers[i] )
- { // reverse colors (just xor them)
+ } else if (7 == numbers[i]) {
+ // reverse colors (just xor them)
info.wAttributes ^= FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE |
- BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE;
+ BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE;
}
- }
- else if( 0x30 == (0xF0 & numbers[i]) )
- { // foreground
+ } else if (0x30 == (0xF0 & numbers[i])) {
+ // foreground
uint8 num = numbers[i]&0x0F;
if(num==9) info.wAttributes |= FOREGROUND_INTENSITY;
- if(num>7) num=7; // set white for 37, 38 and 39
+ if(num>7) num=7; // set white for 37, 38 and 39
info.wAttributes &= ~(FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
if( (num & 0x01)>0 ) // lowest bit set = red
info.wAttributes |= FOREGROUND_RED;
@@ -316,12 +303,11 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr)
info.wAttributes |= FOREGROUND_GREEN;
if( (num & 0x04)>0 ) // third bit set = blue
info.wAttributes |= FOREGROUND_BLUE;
- }
- else if( 0x40 == (0xF0 & numbers[i]) )
- { // background
+ } else if (0x40 == (0xF0 & numbers[i])) {
+ // background
uint8 num = numbers[i]&0x0F;
if(num==9) info.wAttributes |= BACKGROUND_INTENSITY;
- if(num>7) num=7; // set white for 47, 48 and 49
+ if(num>7) num=7; // set white for 47, 48 and 49
info.wAttributes &= ~(BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE);
if( (num & 0x01)>0 ) // lowest bit set = red
info.wAttributes |= BACKGROUND_RED;
@@ -333,61 +319,51 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr)
}
// set the attributes
SetConsoleTextAttribute(handle, info.wAttributes);
- }
- else if( *q=='J' )
- { // \033[#J - Erase Display (ED)
- // \033[0J - Clears the screen from cursor to end of display. The cursor position is unchanged.
- // \033[1J - Clears the screen from start to cursor. The cursor position is unchanged.
- // \033[2J - Clears the screen and moves the cursor to the home position (line 1, column 1).
+ } else if (*q=='J') {
+ // \033[#J - Erase Display (ED)
+ // \033[0J - Clears the screen from cursor to end of display. The cursor position is unchanged.
+ // \033[1J - Clears the screen from start to cursor. The cursor position is unchanged.
+ // \033[2J - Clears the screen and moves the cursor to the home position (line 1, column 1).
uint8 num = (numbers[numpoint]>>4)*10+(numbers[numpoint]&0x0F);
int cnt;
DWORD tmp;
COORD origin = {0,0};
- if(num==1)
- { // chars from start up to and including cursor
+ if (num == 1) {
+ // chars from start up to and including cursor
cnt = info.dwSize.X * info.dwCursorPosition.Y + info.dwCursorPosition.X + 1;
- }
- else if(num==2)
- { // Number of chars on screen.
+ } else if (num == 2) {
+ // Number of chars on screen.
cnt = info.dwSize.X * info.dwSize.Y;
SetConsoleCursorPosition(handle, origin);
- }
- else// 0 and default
- { // number of chars from cursor to end
+ } else { /* 0 and default */
+ // number of chars from cursor to end
origin = info.dwCursorPosition;
cnt = info.dwSize.X * (info.dwSize.Y - info.dwCursorPosition.Y) - info.dwCursorPosition.X;
}
FillConsoleOutputAttribute(handle, info.wAttributes, cnt, origin, &tmp);
FillConsoleOutputCharacter(handle, ' ', cnt, origin, &tmp);
- }
- else if( *q=='K' )
- { // \033[K : clear line from actual position to end of the line
- // \033[0K - Clears all characters from the cursor position to the end of the line.
- // \033[1K - Clears all characters from start of line to the cursor position.
- // \033[2K - Clears all characters of the whole line.
+ } else if (*q=='K') {
+ // \033[K : clear line from actual position to end of the line
+ // \033[0K - Clears all characters from the cursor position to the end of the line.
+ // \033[1K - Clears all characters from start of line to the cursor position.
+ // \033[2K - Clears all characters of the whole line.
uint8 num = (numbers[numpoint]>>4)*10+(numbers[numpoint]&0x0F);
COORD origin = {0,info.dwCursorPosition.Y}; //warning C4204
SHORT cnt;
DWORD tmp;
- if(num==1)
- {
+ if (num == 1) {
cnt = info.dwCursorPosition.X + 1;
- }
- else if(num==2)
- {
+ } else if (num == 2) {
cnt = info.dwSize.X;
- }
- else// 0 and default
- {
+ } else { /* 0 and default */
origin = info.dwCursorPosition;
cnt = info.dwSize.X - info.dwCursorPosition.X; // how many spaces until line is full
}
FillConsoleOutputAttribute(handle, info.wAttributes, cnt, origin, &tmp);
FillConsoleOutputCharacter(handle, ' ', cnt, origin, &tmp);
- }
- else if( *q == 'H' || *q == 'f' )
- { // \033[#;#H - Cursor Position (CUP)
+ } else if (*q == 'H' || *q == 'f') {
+ // \033[#;#H - Cursor Position (CUP)
// \033[#;#f - Horizontal & Vertical Position
// The first # specifies the line number, the second # specifies the column.
// The default for both is 1
@@ -397,59 +373,52 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr)
if( info.dwCursorPosition.X >= info.dwSize.X ) info.dwCursorPosition.Y = info.dwSize.X-1;
if( info.dwCursorPosition.Y >= info.dwSize.Y ) info.dwCursorPosition.Y = info.dwSize.Y-1;
SetConsoleCursorPosition(handle, info.dwCursorPosition);
- }
- else if( *q=='s' )
- { // \033[s - Save Cursor Position (SCP)
+ } else if (*q=='s') {
+ // \033[s - Save Cursor Position (SCP)
/* XXX Two streams are being used. Disabled to avoid inconsistency [flaviojs]
CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo(handle, &info);
saveposition = info.dwCursorPosition;
*/
- }
- else if( *q=='u' )
- { // \033[u - Restore cursor position (RCP)
+ } else if (*q=='u') {
+ // \033[u - Restore cursor position (RCP)
/* XXX Two streams are being used. Disabled to avoid inconsistency [flaviojs]
SetConsoleCursorPosition(handle, saveposition);
*/
- }
- else if( *q == 'A' )
- { // \033[#A - Cursor Up (CUU)
+ } else if (*q == 'A') {
+ // \033[#A - Cursor Up (CUU)
// Moves the cursor UP # number of lines
info.dwCursorPosition.Y -= (numbers[numpoint])?(numbers[numpoint]>>4)*10+(numbers[numpoint]&0x0F):1;
if( info.dwCursorPosition.Y < 0 )
info.dwCursorPosition.Y = 0;
SetConsoleCursorPosition(handle, info.dwCursorPosition);
- }
- else if( *q == 'B' )
- { // \033[#B - Cursor Down (CUD)
+ } else if (*q == 'B') {
+ // \033[#B - Cursor Down (CUD)
// Moves the cursor DOWN # number of lines
info.dwCursorPosition.Y += (numbers[numpoint])?(numbers[numpoint]>>4)*10+(numbers[numpoint]&0x0F):1;
if( info.dwCursorPosition.Y >= info.dwSize.Y )
info.dwCursorPosition.Y = info.dwSize.Y-1;
SetConsoleCursorPosition(handle, info.dwCursorPosition);
- }
- else if( *q == 'C' )
- { // \033[#C - Cursor Forward (CUF)
+ } else if (*q == 'C') {
+ // \033[#C - Cursor Forward (CUF)
// Moves the cursor RIGHT # number of columns
info.dwCursorPosition.X += (numbers[numpoint])?(numbers[numpoint]>>4)*10+(numbers[numpoint]&0x0F):1;
if( info.dwCursorPosition.X >= info.dwSize.X )
info.dwCursorPosition.X = info.dwSize.X-1;
SetConsoleCursorPosition(handle, info.dwCursorPosition);
- }
- else if( *q == 'D' )
- { // \033[#D - Cursor Backward (CUB)
+ } else if (*q == 'D') {
+ // \033[#D - Cursor Backward (CUB)
// Moves the cursor LEFT # number of columns
info.dwCursorPosition.X -= (numbers[numpoint])?(numbers[numpoint]>>4)*10+(numbers[numpoint]&0x0F):1;
if( info.dwCursorPosition.X < 0 )
info.dwCursorPosition.X = 0;
SetConsoleCursorPosition(handle, info.dwCursorPosition);
- }
- else if( *q == 'E' )
- { // \033[#E - Cursor Next Line (CNL)
+ } else if (*q == 'E') {
+ // \033[#E - Cursor Next Line (CNL)
// Moves the cursor down the indicated # of rows, to column 1
info.dwCursorPosition.Y += (numbers[numpoint])?(numbers[numpoint]>>4)*10+(numbers[numpoint]&0x0F):1;
info.dwCursorPosition.X = 0;
@@ -457,9 +426,8 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr)
if( info.dwCursorPosition.Y >= info.dwSize.Y )
info.dwCursorPosition.Y = info.dwSize.Y-1;
SetConsoleCursorPosition(handle, info.dwCursorPosition);
- }
- else if( *q == 'F' )
- { // \033[#F - Cursor Preceding Line (CPL)
+ } else if (*q == 'F') {
+ // \033[#F - Cursor Preceding Line (CPL)
// Moves the cursor up the indicated # of rows, to column 1.
info.dwCursorPosition.Y -= (numbers[numpoint])?(numbers[numpoint]>>4)*10+(numbers[numpoint]&0x0F):1;
info.dwCursorPosition.X = 0;
@@ -467,21 +435,18 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr)
if( info.dwCursorPosition.Y < 0 )
info.dwCursorPosition.Y = 0;
SetConsoleCursorPosition(handle, info.dwCursorPosition);
- }
- else if( *q == 'G' )
- { // \033[#G - Cursor Horizontal Absolute (CHA)
+ } else if (*q == 'G') {
+ // \033[#G - Cursor Horizontal Absolute (CHA)
// Moves the cursor to indicated column in current row.
info.dwCursorPosition.X = (numbers[numpoint])?(numbers[numpoint]>>4)*10+((numbers[numpoint]&0x0F)-1):0;
if( info.dwCursorPosition.X >= info.dwSize.X )
info.dwCursorPosition.X = info.dwSize.X-1;
SetConsoleCursorPosition(handle, info.dwCursorPosition);
- }
- else if( *q == 'L' || *q == 'M' || *q == '@' || *q == 'P')
- { // not implemented, just skip
- }
- else
- { // no number nor valid sequencer
+ } else if (*q == 'L' || *q == 'M' || *q == '@' || *q == 'P') {
+ // not implemented, just skip
+ } else {
+ // no number nor valid sequencer
// something is fishy, we break and give the current char free
--q;
}
@@ -491,7 +456,7 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr)
}// end while
}
}
- if (*p) // write the rest of the buffer
+ if (*p) // write the rest of the buffer
if( 0==WriteConsole(handle, p, (DWORD)strlen(p), &written, 0) )
WriteFile(handle, p, (DWORD)strlen(p), &written, 0);
FREEBUF(tempbuf);
@@ -519,7 +484,7 @@ int FPRINTF(HANDLE handle, const char *fmt, ...) {
#define is_console(file) (0!=isatty(fileno(file)))
//vprintf_without_ansiformats
-int VFPRINTF(FILE *file, const char *fmt, va_list argptr)
+int VFPRINTF(FILE *file, const char *fmt, va_list argptr)
{
char *p, *q;
NEWBUF(tempbuf); // temporary buffer
@@ -538,88 +503,70 @@ int VFPRINTF(FILE *file, const char *fmt, va_list argptr)
// start with processing
p = BUFVAL(tempbuf);
- while ((q = strchr(p, 0x1b)) != NULL)
- { // find the escape character
+ while ((q = strchr(p, 0x1b)) != NULL) {
+ // find the escape character
fprintf(file, "%.*s", (int)(q-p), p); // write up to the escape
- if( q[1]!='[' )
- { // write the escape char (whatever purpose it has)
+ if (q[1]!='[') {
+ // write the escape char (whatever purpose it has)
fprintf(file, "%.*s", 1, q);
- p=q+1; //and start searching again
- }
- else
- { // from here, we will skip the '\033['
+ p=q+1; //and start searching again
+ } else {
+ // from here, we will skip the '\033['
// we break at the first unprocessible position
// assuming regular text is starting there
// skip escape and bracket
q=q+2;
- while(1)
- {
- if( ISDIGIT(*q) )
- {
+ while(1) {
+ if (ISDIGIT(*q)) {
++q;
// and next character
continue;
- }
- else if( *q == ';' )
- { // delimiter
+ } else if (*q == ';') {
+ // delimiter
++q;
// and next number
continue;
- }
- else if( *q == 'm' )
- { // \033[#;...;#m - Set Graphics Rendition (SGR)
+ } else if (*q == 'm') {
+ // \033[#;...;#m - Set Graphics Rendition (SGR)
// set the attributes
+ } else if (*q=='J') {
+ // \033[#J - Erase Display (ED)
}
- else if( *q=='J' )
- { // \033[#J - Erase Display (ED)
- }
- else if( *q=='K' )
- { // \033[K : clear line from actual position to end of the line
- }
- else if( *q == 'H' || *q == 'f' )
- { // \033[#;#H - Cursor Position (CUP)
+ else if (*q=='K') {
+ // \033[K : clear line from actual position to end of the line
+ } else if (*q == 'H' || *q == 'f') {
+ // \033[#;#H - Cursor Position (CUP)
// \033[#;#f - Horizontal & Vertical Position
- }
- else if( *q=='s' )
- { // \033[s - Save Cursor Position (SCP)
- }
- else if( *q=='u' )
- { // \033[u - Restore cursor position (RCP)
- }
- else if( *q == 'A' )
- { // \033[#A - Cursor Up (CUU)
+ } else if (*q=='s') {
+ // \033[s - Save Cursor Position (SCP)
+ } else if (*q=='u') {
+ // \033[u - Restore cursor position (RCP)
+ } else if (*q == 'A') {
+ // \033[#A - Cursor Up (CUU)
// Moves the cursor UP # number of lines
- }
- else if( *q == 'B' )
- { // \033[#B - Cursor Down (CUD)
+ } else if (*q == 'B') {
+ // \033[#B - Cursor Down (CUD)
// Moves the cursor DOWN # number of lines
- }
- else if( *q == 'C' )
- { // \033[#C - Cursor Forward (CUF)
+ } else if (*q == 'C') {
+ // \033[#C - Cursor Forward (CUF)
// Moves the cursor RIGHT # number of columns
- }
- else if( *q == 'D' )
- { // \033[#D - Cursor Backward (CUB)
+ } else if (*q == 'D') {
+ // \033[#D - Cursor Backward (CUB)
// Moves the cursor LEFT # number of columns
- }
- else if( *q == 'E' )
- { // \033[#E - Cursor Next Line (CNL)
+ } else if (*q == 'E') {
+ // \033[#E - Cursor Next Line (CNL)
// Moves the cursor down the indicated # of rows, to column 1
- }
- else if( *q == 'F' )
- { // \033[#F - Cursor Preceding Line (CPL)
+ } else if (*q == 'F') {
+ // \033[#F - Cursor Preceding Line (CPL)
// Moves the cursor up the indicated # of rows, to column 1.
- }
- else if( *q == 'G' )
- { // \033[#G - Cursor Horizontal Absolute (CHA)
+ } else if (*q == 'G') {
+ // \033[#G - Cursor Horizontal Absolute (CHA)
// Moves the cursor to indicated column in current row.
- }
- else if( *q == 'L' || *q == 'M' || *q == '@' || *q == 'P')
- { // not implemented, just skip
- }
- else
- { // no number nor valid sequencer
+ } else if (*q == 'L' || *q == 'M' || *q == '@' || *q == 'P') {
+ // not implemented, just skip
+ } else {
+ // no number nor valid sequencer
// something is fishy, we break and give the current char free
--q;
}
@@ -629,7 +576,7 @@ int VFPRINTF(FILE *file, const char *fmt, va_list argptr)
}// end while
}
}
- if (*p) // write the rest of the buffer
+ if (*p) // write the rest of the buffer
fprintf(file, "%s", p);
FREEBUF(tempbuf);
return 0;
@@ -661,7 +608,7 @@ int vShowMessage_(enum msg_type flag, const char *string, va_list ap)
#if defined(DEBUGLOGMAP) || defined(DEBUGLOGCHAR) || defined(DEBUGLOGLOGIN)
FILE *fp;
#endif
-
+
if (!string || *string == '\0') {
ShowError("Empty string passed to vShowMessage_().\n");
return 1;
@@ -700,8 +647,8 @@ int vShowMessage_(enum msg_type flag, const char *string, va_list ap)
)
return 0; //Do not print it.
- if (timestamp_format[0] && flag != MSG_NONE)
- { //Display time format. [Skotlex]
+ if (timestamp_format[0] && flag != MSG_NONE) {
+ //Display time format. [Skotlex]
time_t t = time(NULL);
strftime(prefix, 80, timestamp_format, localtime(&t));
} else prefix[0]='\0';
@@ -738,8 +685,8 @@ int vShowMessage_(enum msg_type flag, const char *string, va_list ap)
return 1;
}
- if (flag == MSG_ERROR || flag == MSG_FATALERROR || flag == MSG_SQL)
- { //Send Errors to StdErr [Skotlex]
+ if (flag == MSG_ERROR || flag == MSG_FATALERROR || flag == MSG_SQL) {
+ //Send Errors to StdErr [Skotlex]
FPRINTF(STDERR, "%s ", prefix);
va_copy(apcopy, ap);
VFPRINTF(STDERR, string, apcopy);
@@ -757,7 +704,7 @@ int vShowMessage_(enum msg_type flag, const char *string, va_list ap)
#if defined(DEBUGLOGMAP) || defined(DEBUGLOGCHAR) || defined(DEBUGLOGLOGIN)
if(strlen(DEBUGLOGPATH) > 0) {
fp=fopen(DEBUGLOGPATH,"a");
- if (fp == NULL) {
+ if (fp == NULL) {
FPRINTF(STDERR, CL_RED"[ERROR]"CL_RESET": Could not open '"CL_WHITE"%s"CL_RESET"', access denied.\n", DEBUGLOGPATH);
FFLUSH(STDERR);
} else {
@@ -779,7 +726,7 @@ int vShowMessage_(enum msg_type flag, const char *string, va_list ap)
void ClearScreen(void)
{
#ifndef _WIN32
- ShowMessage(CL_CLS); // to prevent empty string passed messages
+ ShowMessage(CL_CLS); // to prevent empty string passed messages
#endif
}
int ShowMessage_(enum msg_type flag, const char *string, ...) __attribute__((format(printf, 2, 3)));
diff --git a/src/common/socket.c b/src/common/socket.c
index c57cba32d..f307dc4a9 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -274,7 +274,7 @@ const char* error_msg(void)
}
/*======================================
- * CORE : Default processing functions
+ * CORE : Default processing functions
*--------------------------------------*/
int null_recv(int fd) { return 0; }
int null_send(int fd) { return 0; }
@@ -289,7 +289,7 @@ void set_defaultparse(ParseFunc defaultparse)
/*======================================
- * CORE : Socket options
+ * CORE : Socket options
*--------------------------------------*/
void set_nonblocking(int fd, unsigned long yes)
{
@@ -302,7 +302,7 @@ void set_nonblocking(int fd, unsigned long yes)
void setsocketopts(int fd, struct hSockOpt *opt) {
int yes = 1; // reuse fix
struct linger lopt;
-
+
#if !defined(WIN32)
// set SO_REAUSEADDR to true, unix only. on windows this option causes
// the previous owner of the socket to give up, which is not desirable
@@ -319,14 +319,14 @@ void setsocketopts(int fd, struct hSockOpt *opt) {
if( opt && opt->setTimeo ) {
struct timeval timeout;
-
+
timeout.tv_sec = 5;
timeout.tv_usec = 0;
-
+
sSetsockopt(fd,SOL_SOCKET,SO_RCVTIMEO,(char *)&timeout,sizeof(timeout));
sSetsockopt(fd,SOL_SOCKET,SO_SNDTIMEO,(char *)&timeout,sizeof(timeout));
}
-
+
// force the socket into no-wait, graceful-close mode (should be the default, but better make sure)
//(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/closesocket_2.asp)
lopt.l_onoff = 0; // SO_DONTLINGER
@@ -336,7 +336,7 @@ void setsocketopts(int fd, struct hSockOpt *opt) {
}
/*======================================
- * CORE : Socket Sub Function
+ * CORE : Socket Sub Function
*--------------------------------------*/
void set_eof(int fd)
{
@@ -448,7 +448,7 @@ void flush_fifos(void)
}
/*======================================
- * CORE : Connection functions
+ * CORE : Connection functions
*--------------------------------------*/
int connect_client(int listen_fd) {
int fd;
@@ -659,19 +659,19 @@ int realloc_writefifo(int fd, size_t addition)
if( !sockt->session_isValid(fd) ) // might not happen
return 0;
- if( session[fd]->wdata_size + addition > session[fd]->max_wdata )
- { // grow rule; grow in multiples of WFIFO_SIZE
+ if (session[fd]->wdata_size + addition > 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 )
- { // shrink rule, shrink by 2 when only a quarter of the fifo is used, don't shrink below nominal 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
+ ) {
+ // 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;
- }
- else // no change
+ } else {
+ // no change
return 0;
+ }
RECREATE(session[fd]->wdata, unsigned char, newsize);
session[fd]->max_wdata = newsize;
@@ -682,7 +682,7 @@ int realloc_writefifo(int fd, size_t addition)
/// advance the RFIFO cursor (marking 'len' bytes as processed)
int RFIFOSKIP(int fd, size_t len)
{
- struct socket_data *s;
+ struct socket_data *s;
if ( !sockt->session_isActive(fd) )
return 0;
@@ -711,8 +711,8 @@ int WFIFOSET(int fd, size_t len)
return 0;
// we have written len bytes to the buffer already before calling WFIFOSET
- if(s->wdata_size+len > s->max_wdata)
- { // actually there was a buffer overflow already
+ if (s->wdata_size+len > s->max_wdata) {
+ // actually there was a buffer overflow already
uint32 ip = s->client_addr;
ShowFatalError("WFIFOSET: Write Buffer Overflow. Connection %d (%d.%d.%d.%d) has written %u bytes on a %u/%u bytes buffer.\n", fd, CONVIP(ip), (unsigned int)len, (unsigned int)s->wdata_size, (unsigned int)s->max_wdata);
ShowDebug("Likely command that caused it: 0x%x\n", (*(uint16*)(s->wdata + s->wdata_size)));
@@ -839,8 +839,8 @@ int do_sockets(int next)
if(session[i]->wdata_size)
session[i]->func_send(i);
- if(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]
+ if (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.
}
}
@@ -870,7 +870,7 @@ int do_sockets(int next)
if(!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) {
@@ -883,7 +883,7 @@ int do_sockets(int next)
if (sockt->last_tick != socket_data_last_tick)
{
char buf[1024];
-
+
sprintf(buf, "In: %.03f kB/s (%.03f kB/s, Q: %.03f kB) | Out: %.03f kB/s (%.03f kB/s, Q: %.03f kB) | RAM: %.03f MB", socket_data_i/1024., socket_data_ci/1024., socket_data_qi/1024., socket_data_o/1024., socket_data_co/1024., socket_data_qo/1024., iMalloc->usage()/1024.);
#ifdef _WIN32
SetConsoleTitle(buf);
@@ -1232,7 +1232,7 @@ void socket_final(void)
aFree(session[0]->rdata);
aFree(session[0]->wdata);
aFree(session[0]);
-
+
aFree(session);
}
@@ -1396,7 +1396,7 @@ void socket_init(void)
#endif
CREATE(session, struct socket_data *, FD_SETSIZE);
-
+
socket_config_read(SOCKET_CONF_FILENAME);
// initialize last send-receive tick
@@ -1414,7 +1414,7 @@ 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");
}
@@ -1498,11 +1498,11 @@ void socket_datasync(int fd, bool send) {
WFIFOW(fd, 0) = 0x2b0a;
WFIFOW(fd, 2) = p_len;
-
+
for( i = 0; i < alen; i++ ) {
WFIFOL(fd, 4 + ( i * 4 ) ) = data_list[i].length;
}
-
+
WFIFOSET(fd, p_len);
} else {
for( i = 0; i < alen; i++ ) {
@@ -1602,7 +1602,7 @@ void send_shortlist_do_sends()
void socket_defaults(void) {
sockt = &sockt_s;
-
+
sockt->fd_max = 0;
/* */
sockt->stall_time = 60;
diff --git a/src/common/socket.h b/src/common/socket.h
index 42b0efe3b..b9c562a29 100644
--- a/src/common/socket.h
+++ b/src/common/socket.h
@@ -97,7 +97,7 @@ struct socket_data {
ParseFunc func_parse;
void* session_data; // stores application-specific data related to the session
-
+
struct HPluginData **hdata;
unsigned int hdatac;
};
diff --git a/src/common/spinlock.h b/src/common/spinlock.h
index bde36b8e5..85a78ed33 100644
--- a/src/common/spinlock.h
+++ b/src/common/spinlock.h
@@ -13,7 +13,7 @@
// For more information, see LICENCE in the main folder
//
//
-
+
#include "../common/atomic.h"
#include "../common/cbasetypes.h"
#include "../common/thread.h"
@@ -33,7 +33,7 @@ typedef struct __declspec( align(64) ) SPIN_LOCK{
typedef struct SPIN_LOCK{
volatile int32 lock;
volatile int32 nest; // nesting level.
-
+
volatile int32 sync_lock;
} __attribute__((aligned(64))) SPIN_LOCK;
#endif
@@ -56,7 +56,7 @@ static forceinline void FinalizeSpinLock(SPIN_LOCK *lck){
static forceinline void EnterSpinLock(SPIN_LOCK *lck){
int tid = rathread_get_tid();
-
+
// Get Sync Lock && Check if the requester thread already owns the lock.
// if it owns, increase nesting level
getsynclock(&lck->sync_lock);
@@ -67,18 +67,14 @@ static forceinline void EnterSpinLock(SPIN_LOCK *lck){
}
// drop sync lock
dropsynclock(&lck->sync_lock);
-
-
+
// Spin until we've got it !
while(1){
-
- if(InterlockedCompareExchange(&lck->lock, tid, 0) == 0){
-
- InterlockedIncrement(&lck->nest);
- return; // Got Lock
- }
-
- rathread_yield(); // Force ctxswitch to another thread.
+ if(InterlockedCompareExchange(&lck->lock, tid, 0) == 0){
+ InterlockedIncrement(&lck->nest);
+ return; // Got Lock
+ }
+ rathread_yield(); // Force ctxswitch to another thread.
}
}
@@ -88,12 +84,12 @@ static forceinline void LeaveSpinLock(SPIN_LOCK *lck){
int tid = rathread_get_tid();
getsynclock(&lck->sync_lock);
-
+
if(InterlockedCompareExchange(&lck->lock, tid, tid) == tid){ // this thread owns the lock.
if(InterlockedDecrement(&lck->nest) == 0)
InterlockedExchange(&lck->lock, 0); // Unlock!
}
-
+
dropsynclock(&lck->sync_lock);
}
diff --git a/src/common/sql.c b/src/common/sql.c
index c75b90cec..7f89e9828 100644
--- a/src/common/sql.c
+++ b/src/common/sql.c
@@ -1004,10 +1004,10 @@ void Sql_HerculesUpdateCheck(Sql* self) {
FILE* ifp;/* index fp */
unsigned int performed = 0;
StringBuf buf;
-
+
if( self == NULL )
return;/* return silently, build has no mysql connection */
-
+
if( !( ifp = fopen("sql-files/upgrades/index.txt", "r") ) ) {
ShowError("SQL upgrade index was not found!\n");
return;
@@ -1055,7 +1055,7 @@ void Sql_HerculesUpdateCheck(Sql* self) {
ShowMessage("%s",StrBuf->Value(&buf));
ShowSQL("To manually skip, type: 'sql update skip <file name>'\n");
}
-
+
StrBuf->Destroy(&buf);
}
@@ -1063,21 +1063,21 @@ void Sql_HerculesUpdateSkip(Sql* self,const char *filename) {
char path[41];// "sql-files/upgrades/" (19) + "yyyy-mm-dd--hh-mm" (17) + ".sql" (4) + 1
char timestamp[11];// "1360186680" (10) + 1
FILE* ifp;/* index fp */
-
+
if( !self ) {
ShowError("SQL not hooked!\n");
return;
}
-
+
snprintf(path,41,"sql-files/upgrades/%s",filename);
-
+
if( !( ifp = fopen(path, "r") ) ) {
ShowError("Upgrade file '%s' was not found!\n",filename);
return;
}
-
+
fseek (ifp,1,SEEK_SET);/* woo. skip the # */
-
+
if( fgets(timestamp,sizeof(timestamp),ifp) ) {
unsigned int timestampui = (unsigned int)atol(timestamp);
if( SQL_ERROR == SQL->Query(self, "SELECT 1 FROM `sql_updates` WHERE `timestamp` = '%u' LIMIT 1", timestampui) )
diff --git a/src/common/strlib.c b/src/common/strlib.c
index 35e0c63b0..8b63b4161 100644
--- a/src/common/strlib.c
+++ b/src/common/strlib.c
@@ -62,11 +62,12 @@ char* jstrescapecpy (char* pt, const char* spt)
//a escape character is found, the target's final length increases! [Skotlex]
int i =0, j=0;
- if (!spt) { //Return an empty string [Skotlex]
+ if (!spt) {
+ //Return an empty string [Skotlex]
pt[0] = '\0';
return &pt[0];
}
-
+
while (spt[i] != '\0') {
switch (spt[i]) {
case '\'':
@@ -252,7 +253,8 @@ char* strtok_r_(char *s1, const char *s2, char **lasts) {
// for NetBSD 5.x and possibly some Solaris versions.
#if !(defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400) && !defined(HAVE_STRNLEN)
/* Find the length of STRING, but scan at most MAXLEN characters.
- If no '\0' terminator is found in that many characters, return MAXLEN. */
+ * 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;
@@ -1136,13 +1138,13 @@ void strlib_defaults(void) {
strlib->trim = trim;
strlib->normalize_name = normalize_name;
strlib->stristr = stristr;
-
+
#if !(defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400) && !defined(HAVE_STRNLEN)
strlib->strnlen = strnlen;
#else
strlib->strnlen = NULL;
#endif
-
+
#if defined(WIN32) && defined(_MSC_VER) && _MSC_VER <= 1200
strlib->strtoull = strtoull;
#else
@@ -1155,7 +1157,7 @@ void strlib_defaults(void) {
strlib->safesnprintf = safesnprintf;
strlib->strline = strline;
strlib->bin2hex = bin2hex;
-
+
StrBuf->Malloc = StringBuf_Malloc;
StrBuf->Init = StringBuf_Init;
StrBuf->Printf = StringBuf_Printf;
@@ -1167,7 +1169,7 @@ void strlib_defaults(void) {
StrBuf->Clear = StringBuf_Clear;
StrBuf->Destroy = StringBuf_Destroy;
StrBuf->Free = StringBuf_Free;
-
+
sv->parse_next = sv_parse_next;
sv->parse = sv_parse;
sv->split = sv_split;
diff --git a/src/common/strlib.h b/src/common/strlib.h
index 8f61470cf..0c596cb8f 100644
--- a/src/common/strlib.h
+++ b/src/common/strlib.h
@@ -63,31 +63,31 @@ struct strlib_interface {
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);
/* 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);
-
+
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);
-
+
/// doesn't crash on null pointer
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)));
-
+
/// Returns the line of the target position in the string.
/// Lines start at 1.
int (*strline) (const char* str, size_t pos);
-
+
/// Produces the hexadecimal representation of the given input.
/// The output buffer must be at least count*2+1 in size.
/// Returns true on success, false on failure.
@@ -119,14 +119,14 @@ struct sv_interface {
/// @param svstate Parse state
/// @return 1 if a field was parsed, 0 if done, -1 on error.
int (*parse_next) (struct s_svstate* svstate);
-
+
/// Parses a delim-separated string.
/// Starts parsing at startoff and fills the pos array with position pairs.
/// out_pos[0] and out_pos[1] are the start and end of line.
/// Other position pairs are the start and end of fields.
/// Returns the number of fields found or -1 if an error occurs.
int (*parse) (const char* str, int len, int startoff, char delim, int* out_pos, int npos, enum e_svopt opt);
-
+
/// Splits a delim-separated string.
/// WARNING: this function modifies the input string
/// Starts splitting at startoff and fills the out_fields array.
@@ -134,20 +134,20 @@ struct sv_interface {
/// Other entries are the start of fields (null-terminated).
/// Returns the number of fields found or -1 if an error occurs.
int (*split) (char* str, int len, int startoff, char delim, char** out_fields, int nfields, enum e_svopt opt);
-
+
/// Escapes src to out_dest according to the format of the C compiler.
/// Returns the length of the escaped string.
/// out_dest should be len*4+1 in size.
size_t (*escape_c) (char* out_dest, const char* src, size_t len, const char* escapes);
-
+
/// Unescapes src to out_dest according to the format of the C compiler.
/// Returns the length of the unescaped string.
/// out_dest should be len+1 in size and can be the same buffer as src.
size_t (*unescape_c) (char* out_dest, const char* src, size_t len);
-
+
/// Skips a C escape sequence (starting with '\\').
const char* (*skip_escaped_c) (const char* p);
-
+
/// Opens and parses a file containing delim-separated columns, feeding them to the specified callback function row by row.
/// Tracks the progress of the operation (current line number, number of successfully processed rows).
/// Returns 'true' if it was able to process the specified file, or 'false' if it could not be read.
diff --git a/src/common/thread.c b/src/common/thread.c
index 1d0285302..a00bd6333 100644
--- a/src/common/thread.c
+++ b/src/common/thread.c
@@ -36,7 +36,7 @@
struct rAthread {
unsigned int myID;
-
+
RATHREAD_PRIO prio;
rAthreadProc proc;
void *param;
@@ -62,7 +62,7 @@ static struct rAthread l_threads[RA_THREADS_MAX];
void rathread_init(void) {
register unsigned int i;
memset(&l_threads, 0x00, RA_THREADS_MAX * sizeof(struct rAthread) );
-
+
for(i = 0; i < RA_THREADS_MAX; i++){
l_threads[i].myID = i;
}
@@ -80,7 +80,7 @@ void rathread_init(void) {
void rathread_final(void) {
register unsigned int i;
-
+
// Unterminated Threads Left?
// Shouldn't happen ..
// Kill 'em all!
@@ -91,8 +91,7 @@ void rathread_final(void) {
rathread_destroy(&l_threads[i]);
}
}
-
-
+
}//end: rathread_final()
@@ -112,7 +111,7 @@ static void *raThreadMainRedirector( void *p ){
sigset_t set; // on Posix Thread platforms
#endif
void *ret;
-
+
// Update myID @ TLS to right id.
#ifdef HAS_TLS
g_rathread_ID = ((rAthread*)p)->myID;
@@ -129,7 +128,7 @@ static void *raThreadMainRedirector( void *p ){
sigaddset(&set, SIGPIPE);
pthread_sigmask(SIG_BLOCK, &set, NULL);
-
+
#endif
@@ -181,14 +180,12 @@ rAthread *rathread_createEx(rAthreadProc entryPoint, void *param, size_t szStack
break;
}
}
-
+
if(handle == NULL){
ShowError("rAthread: cannot create new thread (entryPoint: %p) - no free thread slot found!", entryPoint);
return NULL;
}
-
-
-
+
handle->proc = entryPoint;
handle->param = param;
@@ -197,7 +194,7 @@ rAthread *rathread_createEx(rAthreadProc entryPoint, void *param, size_t szStack
#else
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, szStack);
-
+
if(pthread_create(&handle->hThread, &attr, raThreadMainRedirector, (void*)handle) != 0){
handle->proc = NULL;
handle->param = NULL;
@@ -207,7 +204,7 @@ rAthread *rathread_createEx(rAthreadProc entryPoint, void *param, size_t szStack
#endif
rathread_prio_set( handle, prio );
-
+
return handle;
}//end: rathread_createEx
@@ -220,10 +217,9 @@ void rathread_destroy(rAthread *handle) {
}
#else
if( pthread_cancel( handle->hThread ) == 0){
-
// We have to join it, otherwise pthread wont re-cycle its internal resources assoc. with this thread.
pthread_join( handle->hThread, NULL );
-
+
// Tell our manager to release resources ;)
rat_thread_terminated(handle);
}
@@ -233,7 +229,7 @@ void rathread_destroy(rAthread *handle) {
rAthread *rathread_self(void) {
#ifdef HAS_TLS
rAthread *handle = &l_threads[g_rathread_ID];
-
+
if(handle->proc != NULL) // entry point set, so its used!
return handle;
#else
@@ -247,14 +243,13 @@ rAthread *rathread_self(void) {
pthread_t hSelf;
hSelf = pthread_self();
#endif
-
+
for(i = 0; i < RA_THREADS_MAX; i++){
if(l_threads[i].hThread == hSelf && l_threads[i].proc != NULL)
return &l_threads[i];
}
-
#endif
-
+
return NULL;
}//end: rathread_self()
@@ -270,14 +265,12 @@ int rathread_get_tid(void) {
#else
return (intptr_t)pthread_self();
#endif
-
#endif
-
+
}//end: rathread_get_tid()
bool rathread_wait(rAthread *handle, void **out_exitCode) {
-
// Hint:
// no thread data cleanup routine call here!
// its managed by the callProxy itself..
diff --git a/src/common/thread.h b/src/common/thread.h
index c7582366d..f00e7290d 100644
--- a/src/common/thread.h
+++ b/src/common/thread.h
@@ -104,8 +104,8 @@ RATHREAD_PRIO rathread_prio_get(rAthread *handle);
* Tells the OS scheduler to yield the execution of the calling thread
*
* @note: this will not "pause" the thread,
- * it just allows the OS to spent the remaining time
- * of the slice to another thread.
+ * it just allows the OS to spend the remaining time
+ * of the slice to another thread.
*/
void rathread_yield(void);
diff --git a/src/common/timer.c b/src/common/timer.c
index 5d0a45b99..f2bfa98b3 100644
--- a/src/common/timer.c
+++ b/src/common/timer.c
@@ -59,7 +59,7 @@ time_t start_time;
/*----------------------------
- * Timer debugging
+ * Timer debugging
*----------------------------*/
struct timer_func_list {
struct timer_func_list* next;
@@ -101,31 +101,31 @@ char* search_timer_func_list(TimerFunc func)
}
/*----------------------------
- * Get tick time
+ * Get tick time
*----------------------------*/
#if defined(ENABLE_RDTSC)
static uint64 RDTSC_BEGINTICK = 0, RDTSC_CLOCK = 0;
static __inline uint64 rdtsc_(void) {
- register union{
- uint64 qw;
- uint32 dw[2];
+ register union {
+ uint64 qw;
+ uint32 dw[2];
} t;
asm volatile("rdtsc":"=a"(t.dw[0]), "=d"(t.dw[1]) );
-
+
return t.qw;
}
static void rdtsc_calibrate(void){
uint64 t1, t2;
int32 i;
-
+
ShowStatus("Calibrating Timer Source, please wait... ");
-
+
RDTSC_CLOCK = 0;
-
+
for(i = 0; i < 5; i++){
t1 = rdtsc_();
usleep(1000000); //1000 MS
@@ -133,9 +133,9 @@ static void rdtsc_calibrate(void){
RDTSC_CLOCK += (t2 - t1) / 1000;
}
RDTSC_CLOCK /= 5;
-
+
RDTSC_BEGINTICK = rdtsc_();
-
+
ShowMessage(" done. (Frequency: %u Mhz)\n", (uint32)(RDTSC_CLOCK/1000) );
}
@@ -233,7 +233,7 @@ int64 timer_gettick(void) {
//////////////////////////////////////////////////////////////////////////
/*======================================
- * CORE : Timer Heap
+ * CORE : Timer Heap
*--------------------------------------*/
/// Adds a timer to the timer_heap
@@ -243,7 +243,7 @@ static void push_timer_heap(int tid) {
}
/*==========================
- * Timer Management
+ * Timer Management
*--------------------------*/
/// Returns a free timer id.
@@ -281,7 +281,7 @@ static int acquire_timer(void) {
/// Returns the timer's id.
int timer_add(int64 tick, TimerFunc func, int id, intptr_t data) {
int tid;
-
+
tid = acquire_timer();
timer_data[tid].tick = tick;
timer_data[tid].func = func;
@@ -304,7 +304,7 @@ int timer_add_interval(int64 tick, TimerFunc func, int id, intptr_t data, int in
tick, func, search_timer_func_list(func), id, data, DIFF_TICK(tick, timer->gettick()));
return INVALID_TIMER;
}
-
+
tid = acquire_timer();
timer_data[tid].tick = tick;
timer_data[tid].func = func;
@@ -351,7 +351,7 @@ int64 timer_addtick(int tid, int64 tick) {
/// Returns the new tick value, or -1 if it fails.
int64 timer_settick(int tid, int64 tick) {
size_t i;
-
+
// search timer position
ARR_FIND(0, BHEAP_LENGTH(timer_heap), i, BHEAP_DATA(timer_heap)[i] == tid);
if( i == BHEAP_LENGTH(timer_heap) ) {
@@ -444,8 +444,8 @@ void timer_final(void) {
struct timer_func_list *next;
for( tfl=tfl_root; tfl != NULL; tfl = next ) {
- next = tfl->next; // copy next pointer
- aFree(tfl->name); // free structures
+ next = tfl->next; // copy next pointer
+ aFree(tfl->name); // free structures
aFree(tfl);
}
diff --git a/src/common/utils.c b/src/common/utils.c
index 79232b25c..d73aab066 100644
--- a/src/common/utils.c
+++ b/src/common/utils.c
@@ -92,7 +92,8 @@ void ShowDump(const void *buffer, size_t length) {
#ifdef WIN32
static char* checkpath(char *path, const char *srcpath)
-{ // just make sure the char*path is not const
+{
+ // just make sure the char*path is not const
char *p=path;
if(NULL!=path && NULL!=srcpath)
while(*srcpath) {
@@ -112,16 +113,15 @@ void findfile(const char *p, const char *pat, void (func)(const char*))
WIN32_FIND_DATAA FindFileData;
HANDLE hFind;
char tmppath[MAX_PATH+1];
-
const char *path = (p ==NULL)? "." : p;
const char *pattern = (pat==NULL)? "" : pat;
-
+
checkpath(tmppath,path);
if( PATHSEP != tmppath[strlen(tmppath)-1])
strcat(tmppath, "\\*");
else
strcat(tmppath, "*");
-
+
hFind = FindFirstFileA(tmppath, &FindFileData);
if (hFind != INVALID_HANDLE_VALUE)
{
@@ -153,7 +153,8 @@ void findfile(const char *p, const char *pat, void (func)(const char*))
#define MAX_DIR_PATH 2048
static char* checkpath(char *path, const char*srcpath)
-{ // just make sure the char*path is not const
+{
+ // just make sure the char*path is not const
char *p=path;
if(NULL!=path && NULL!=srcpath)
while(*srcpath) {
@@ -170,9 +171,9 @@ static char* checkpath(char *path, const char*srcpath)
void findfile(const char *p, const char *pat, void (func)(const char*))
{
- DIR* dir; // pointer to the scanned directory.
- struct dirent* entry; // pointer to one directory entry.
- struct stat dir_stat; // used by stat().
+ DIR* dir; ///< pointer to the scanned directory.
+ struct dirent* entry; ///< pointer to one directory entry.
+ struct stat dir_stat; ///< used by stat().
char tmppath[MAX_DIR_PATH+1];
char path[MAX_DIR_PATH+1]= ".";
const char *pattern = (pat==NULL)? "" : pat;
@@ -289,17 +290,17 @@ int32 MakeLongLE(int32 val)
// Reads an uint16 in little-endian from the buffer
uint16 GetUShort(const unsigned char* buf)
{
- return ( ((uint16)(buf[0])) )
- |( ((uint16)(buf[1])) << 0x08 );
+ return ( ((uint16)(buf[0])) )
+ | ( ((uint16)(buf[1])) << 0x08 );
}
// Reads an uint32 in little-endian from the buffer
uint32 GetULong(const unsigned char* buf)
{
- return ( ((uint32)(buf[0])) )
- |( ((uint32)(buf[1])) << 0x08 )
- |( ((uint32)(buf[2])) << 0x10 )
- |( ((uint32)(buf[3])) << 0x18 );
+ return ( ((uint32)(buf[0])) )
+ | ( ((uint32)(buf[1])) << 0x08 )
+ | ( ((uint32)(buf[2])) << 0x10 )
+ | ( ((uint32)(buf[3])) << 0x18 );
}
// Reads an int32 in little-endian from the buffer
@@ -356,15 +357,15 @@ bool HCache_check(const char *file) {
time_t rtime;
if( !(first = fopen(file,"rb")) )
- return false;
+ return false;
if( file[0] == '.' && file[1] == '/' )
- file += 2;
+ file += 2;
else if( file[0] == '.' )
- file++;
-
+ file++;
+
snprintf(s_path, 255, "./cache/%s", file);
-
+
if( !(second = fopen(s_path,"rb")) ) {
fclose(first);
return false;
@@ -375,34 +376,34 @@ bool HCache_check(const char *file) {
fclose(second);
return false;
}
-
+
fstat(fileno(first), &bufa);
fstat(fileno(second), &bufb);
-
+
fclose(first);
fclose(second);
-
+
if( bufa.st_mtime > bufb.st_mtime )
return false;
-
+
return true;
}
FILE *HCache_open(const char *file, const char *opt) {
FILE *first;
char s_path[255];
-
+
if( file[0] == '.' && file[1] == '/' )
file += 2;
else if( file[0] == '.' )
file++;
-
+
snprintf(s_path, 255, "./cache/%s", file);
-
+
if( !(first = fopen(s_path,opt)) ) {
return NULL;
}
-
+
if( opt[0] != 'r' ) {
char dT[1];/* 1-byte key to ensure our method is the latest, we can modify to ensure the method matches */
dT[0] = HCACHE_KEY;
@@ -410,19 +411,19 @@ FILE *HCache_open(const char *file, const char *opt) {
hwrite(&HCache->recompile_time,sizeof(HCache->recompile_time),1,first);
}
fseek(first, 20, SEEK_SET);/* skip first 20, might wanna store something else later */
-
+
return first;
}
void HCache_init(void) {
FILE *server;
-
+
if( (server = fopen(SERVER_NAME,"rb")) ) {
struct stat buf;
-
+
fstat(fileno(server), &buf);
HCache->recompile_time = buf.st_mtime;
fclose(server);
-
+
HCache->enabled = true;
} else
ShowWarning("Unable to open '%s', caching capabilities have been disabled!\n",SERVER_NAME);
@@ -437,11 +438,10 @@ size_t hwrite(const void * ptr, size_t size, size_t count, FILE * stream) {
}
void HCache_defaults(void) {
-
HCache = &HCache_s;
HCache->init = HCache_init;
-
+
HCache->check = HCache_check;
HCache->open = HCache_open;
HCache->recompile_time = 0;
diff --git a/src/common/winapi.h b/src/common/winapi.h
index a8a38f30e..f53d9cbbd 100644
--- a/src/common/winapi.h
+++ b/src/common/winapi.h
@@ -2,10 +2,10 @@
#define STRICT
-#define NTDDI_VERSION NTDDI_WIN2K
+#define NTDDI_VERSION NTDDI_WIN2K
#define _WIN32_WINNT 0x0500
-#define WINVER 0x0500
-#define _WIN32_IE 0x0600
+#define WINVER 0x0500
+#define _WIN32_IE 0x0600
#define WIN32_LEAN_AND_MEAN
#define NOCOMM
#define NOKANJI