diff options
author | ai4rei <ai4rei@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2011-01-30 00:25:44 +0000 |
---|---|---|
committer | ai4rei <ai4rei@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2011-01-30 00:25:44 +0000 |
commit | 741230435bd23aa692f552649664b67a43a358c0 (patch) | |
tree | 2f659f9ff3ed0c2b3df3119315047b6f756ef135 /src/common | |
parent | d21f2f8479c618c15958ae1f9ac5811b9b035921 (diff) | |
download | hercules-741230435bd23aa692f552649664b67a43a358c0.tar.gz hercules-741230435bd23aa692f552649664b67a43a358c0.tar.bz2 hercules-741230435bd23aa692f552649664b67a43a358c0.tar.xz hercules-741230435bd23aa692f552649664b67a43a358c0.zip |
* Merged changes from trunk [14636:14686/trunk].
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/branches/renewal@14687 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/core.h | 2 | ||||
-rw-r--r-- | src/common/db.c | 4 | ||||
-rw-r--r-- | src/common/grfio.c | 134 | ||||
-rw-r--r-- | src/common/plugins.c | 2 | ||||
-rw-r--r-- | src/common/socket.c | 5 | ||||
-rw-r--r-- | src/common/socket.h | 7 | ||||
-rw-r--r-- | src/common/strlib.c | 10 |
7 files changed, 107 insertions, 57 deletions
diff --git a/src/common/core.h b/src/common/core.h index 68325505a..fc4af3e3e 100644 --- a/src/common/core.h +++ b/src/common/core.h @@ -11,7 +11,7 @@ extern int runflag; extern char *SERVER_NAME; extern char SERVER_TYPE; -extern int parse_console(char* buf); +extern int parse_console(const char* buf); extern const char *get_svn_revision(void); extern int do_init(int,char**); extern void set_server_type(void); diff --git a/src/common/db.c b/src/common/db.c index 4dcf1d0b0..595ed241d 100644 --- a/src/common/db.c +++ b/src/common/db.c @@ -697,7 +697,7 @@ static void db_free_add(DBMap_impl* db, DBNode node, DBNode *root) db->alloc_file, db->alloc_line); exit(EXIT_FAILURE); } - if (!(db->options&DB_OPT_DUP_KEY)) { // Make shure we have a key until the node is freed + if (!(db->options&DB_OPT_DUP_KEY)) { // Make sure we have a key until the node is freed old_key = node->key; node->key = db_dup_key(db, node->key); db->release(old_key, node->data, DB_RELEASE_KEY); @@ -1976,13 +1976,13 @@ static int db_obj_vclear(DBMap* self, DBApply func, va_list args) node->deleted = 1; } DB_COUNTSTAT(db_node_free); - ers_free(db->nodes, node); if (parent) { if (parent->left == node) parent->left = NULL; else parent->right = NULL; } + ers_free(db->nodes, node); node = parent; } db->ht[i] = NULL; diff --git a/src/common/grfio.c b/src/common/grfio.c index fe94e0803..3c0960f30 100644 --- a/src/common/grfio.c +++ b/src/common/grfio.c @@ -12,6 +12,8 @@ #include "../common/cbasetypes.h" #include "../common/showmsg.h" #include "../common/malloc.h" +#include "../common/strlib.h" +#include "../common/utils.h" //---------------------------- @@ -381,6 +383,35 @@ static void filelist_adjust(void) } } + +/// Combines are resource path with the data folder location to +/// create local resource path. +static void grfio_localpath_create(char* buffer, size_t size, const char* filename) +{ + unsigned int i; + size_t len; + + len = strlen(data_dir); + + if( data_dir[0] == 0 || data_dir[len-1] == '/' || data_dir[len-1] == '\\' ) + { + safesnprintf(buffer, size, "%s%s", data_dir, filename); + } + else + { + safesnprintf(buffer, size, "%s/%s", data_dir, filename); + } + + for( i = 0; buffer[i]; i++ ) + {// normalize path + if( buffer[i] == '\\' ) + { + buffer[i] = '/'; + } + } +} + + /*********************************************************** *** Grfio Sobroutines *** ***********************************************************/ @@ -398,13 +429,10 @@ int grfio_size(char* fname) FILELIST lentry; struct stat st; - sprintf(lfname, "%s%s", data_dir, fname); - - for (p = &lfname[0]; *p != 0; p++) - if (*p=='\\') *p = '/'; + grfio_localpath_create(lfname, sizeof(lfname), fname); if (stat(lfname, &st) == 0) { - strncpy(lentry.fn, fname, sizeof(lentry.fn) - 1); + safestrncpy(lentry.fn, fname, sizeof(lentry.fn)); lentry.fnd = NULL; lentry.declen = st.st_size; lentry.gentry = 0; // 0:LocalFile @@ -428,35 +456,28 @@ void* grfio_reads(char* fname, int* size) entry = filelist_find(fname); if (entry == NULL || entry->gentry <= 0) { // LocalFileCheck - char lfname[256], *p; - FILELIST lentry; + char lfname[256]; + int declen; - sprintf(lfname, "%s%s", data_dir, fname); - - for (p = &lfname[0]; *p != 0; p++) - if (*p == '\\') *p = '/'; + grfio_localpath_create(lfname, sizeof(lfname), ( entry && entry->fnd ) ? entry->fnd : fname); in = fopen(lfname, "rb"); if (in != NULL) { - if (entry != NULL && entry->gentry == 0) { - lentry.declen = entry->declen; - } else { - fseek(in,0,SEEK_END); - lentry.declen = ftell(in); - } + fseek(in,0,SEEK_END); + declen = ftell(in); fseek(in,0,SEEK_SET); - buf2 = (unsigned char *)aMallocA(lentry.declen + 1024); - fread(buf2, 1, lentry.declen, in); + buf2 = (unsigned char *)aMallocA(declen+1); // +1 for resnametable zero-termination + fread(buf2, 1, declen, in); fclose(in); - strncpy(lentry.fn, fname, sizeof(lentry.fn) - 1); - lentry.fnd = NULL; - lentry.gentry = 0; // 0:LocalFile - entry = filelist_modify(&lentry); + if( size ) + { + size[0] = declen; + } } else { if (entry != NULL && entry->gentry < 0) { entry->gentry = -entry->gentry; // local file checked } else { - ShowError("%s not found (grfio_reads - local file %s)\n", fname, lfname); + ShowError("grfio_reads: %s not found (local file: %s)\n", fname, lfname); return NULL; } } @@ -465,11 +486,11 @@ void* grfio_reads(char* fname, int* size) char* grfname = gentry_table[entry->gentry - 1]; in = fopen(grfname, "rb"); if(in != NULL) { - unsigned char *buf = (unsigned char *)aMallocA(entry->srclen_aligned + 1024); + unsigned char *buf = (unsigned char *)aMallocA(entry->srclen_aligned); fseek(in, entry->srcpos, 0); fread(buf, 1, entry->srclen_aligned, in); fclose(in); - buf2 = (unsigned char *)aMallocA(entry->declen + 1024); + buf2 = (unsigned char *)aMallocA(entry->declen+1); // +1 for resnametable zero-termination if (entry->type == 1 || entry->type == 3 || entry->type == 5) { uLongf len; if (entry->cycle >= 0) @@ -485,14 +506,16 @@ void* grfio_reads(char* fname, int* size) } else { memcpy(buf2, buf, entry->declen); } + if( size ) + { + size[0] = entry->declen; + } aFree(buf); } else { - ShowError("%s not found (grfio_reads - GRF file %s)\n", fname, grfname); + ShowError("grfio_reads: %s not found (GRF file: %s)\n", fname, grfname); return NULL; } } - if (size != NULL && entry != NULL) - *size = entry->declen; return buf2; } @@ -590,7 +613,7 @@ static int grfio_entryread(char* grfname, int gentry) aentry.srcpos = getlong(grf_filelist+ofs2+13)+0x2e; aentry.cycle = srccount; aentry.type = type; - strncpy(aentry.fn, fname,sizeof(aentry.fn)-1); + 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 @@ -657,7 +680,7 @@ static int grfio_entryread(char* grfname, int gentry) aentry.srcpos = getlong(grf_filelist+ofs2+13)+0x2e; aentry.cycle = srccount; aentry.type = type; - strncpy(aentry.fn,fname,sizeof(aentry.fn)-1); + 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 @@ -686,17 +709,16 @@ static int grfio_entryread(char* grfname, int gentry) *------------------------------------------*/ static void grfio_resourcecheck(void) { - char w1[256], w2[256], src[256], dst[256], restable[256], line[256]; + char w1[256], w2[256], src[256], dst[256], restable[256], line[256], local[256]; char *ptr, *buf; FILELIST* entry; + FILELIST fentry; int size; FILE* fp; int i = 0; // read resnametable from data directory and return if successful - sprintf(restable, "%sdata\\resnametable.txt", data_dir); - for (ptr = &restable[0]; *ptr != 0; ptr++) - if (*ptr == '\\') *ptr = '/'; + grfio_localpath_create(restable, sizeof(restable), "data\\resnametable.txt"); fp = fopen(restable, "rb"); if (fp) { @@ -710,14 +732,28 @@ static void grfio_resourcecheck(void) sprintf(dst, "data\\%s", w2); entry = filelist_find(dst); // create new entries reusing the original's info - if (entry != NULL) { - FILELIST fentry; + if (entry != NULL) + {// alias for GRF resource memcpy(&fentry, entry, sizeof(FILELIST)); - strncpy(fentry.fn, src, sizeof(fentry.fn) - 1); + safestrncpy(fentry.fn, src, sizeof(fentry.fn)); fentry.fnd = aStrdup(dst); filelist_modify(&fentry); i++; } + else + { + grfio_localpath_create(local, sizeof(local), dst); + + if( exists(local) ) + {// alias for local resource + memset(&fentry, 0, sizeof(fentry)); + //fentry.gentry = 0; + safestrncpy(fentry.fn, src, sizeof(fentry.fn)); + fentry.fnd = aStrdup(dst); + filelist_modify(&fentry); + i++; + } + } } } fclose(fp); @@ -738,14 +774,28 @@ static void grfio_resourcecheck(void) sprintf(src, "data\\%s", w1); sprintf(dst, "data\\%s", w2); entry = filelist_find(dst); - if (entry != NULL) { - FILELIST fentry; + if (entry != NULL) + {// alias for GRF resource memcpy(&fentry, entry, sizeof(FILELIST)); - strncpy(fentry.fn, src, sizeof(fentry.fn) - 1); + safestrncpy(fentry.fn, src, sizeof(fentry.fn)); fentry.fnd = aStrdup(dst); filelist_modify(&fentry); i++; } + else + { + grfio_localpath_create(local, sizeof(local), dst); + + if( exists(local) ) + {// alias for local resource + memset(&fentry, 0, sizeof(fentry)); + //fentry.gentry = 0; + safestrncpy(fentry.fn, src, sizeof(fentry.fn)); + fentry.fnd = aStrdup(dst); + filelist_modify(&fentry); + i++; + } + } } ptr = strchr(ptr, '\n'); // Next line if (!ptr) break; @@ -824,7 +874,7 @@ void grfio_init(char* fname) if(strcmp(w1, "grf") == 0) // GRF file grf_num += (grfio_add(w2) == 0); else if(strcmp(w1,"data_dir") == 0) { // Data directory - strcpy(data_dir, w2); + safestrncpy(data_dir, w2, sizeof(data_dir)); } } fclose(data_conf); diff --git a/src/common/plugins.c b/src/common/plugins.c index 2d81548a1..2d50fc9e8 100644 --- a/src/common/plugins.c +++ b/src/common/plugins.c @@ -251,6 +251,8 @@ Plugin* plugin_open(const char* filename) func = (Plugin_Event_Func*)DLL_SYM(plugin->dll, events[i].func_name); if (func) register_plugin_event(func, events[i].event_name); + else + ShowError("Failed to locate function '%s' in '%s'.\n", events[i].func_name, filename); } i++; } diff --git a/src/common/socket.c b/src/common/socket.c index 89c605c9d..ff667cf2e 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -996,10 +996,10 @@ int access_ipmask(const char* str, AccessControl* acc) (n == 5 && m[0] > 32) ){ // invalid bit mask return 0; } - ip = (uint32)(a[0] | (a[1] << 8) | (a[2] << 16) | (a[3] << 24)); + ip = MAKEIP(a[0],a[1],a[2],a[3]); if( n == 8 ) {// standard mask - mask = (uint32)(a[0] | (a[1] << 8) | (a[2] << 16) | (a[3] << 24)); + mask = MAKEIP(m[0],m[1],m[2],m[3]); } else if( n == 5 ) {// bit mask mask = 0; @@ -1007,7 +1007,6 @@ int access_ipmask(const char* str, AccessControl* acc) mask = (mask >> 1) | 0x80000000; --m[0]; } - mask = ntohl(mask); } else {// just this ip mask = 0xFFFFFFFF; diff --git a/src/common/socket.h b/src/common/socket.h index f7309f6d3..0a740a63f 100644 --- a/src/common/socket.h +++ b/src/common/socket.h @@ -135,6 +135,7 @@ uint32 host2ip(const char* hostname); const char* ip2str(uint32 ip, char ip_str[16]); uint32 str2ip(const char* ip_str); #define CONVIP(ip) ((ip)>>24)&0xFF,((ip)>>16)&0xFF,((ip)>>8)&0xFF,((ip)>>0)&0xFF +#define MAKEIP(a,b,c,d) (uint32)( ( ( (a)&0xFF ) << 24 ) | ( ( (b)&0xFF ) << 16 ) | ( ( (c)&0xFF ) << 8 ) | ( ( (d)&0xFF ) << 0 ) ) uint16 ntows(uint16 netshort); int socket_getips(uint32* ips, int max); @@ -152,12 +153,6 @@ void set_eof(int fd); #define SEND_SHORTLIST #ifdef SEND_SHORTLIST -struct send_shortlist_node { - struct send_shortlist_node *next; // Next node in the linked list - struct send_shortlist_node *prev; // Previous node in the linked list - int fd; // FD that needs sending. -}; - // Add a fd to the shortlist so that it'll be recognized as a fd that needs // sending done on it. void send_shortlist_add_fd(int fd); diff --git a/src/common/strlib.c b/src/common/strlib.c index 019e2d629..a0cba906c 100644 --- a/src/common/strlib.c +++ b/src/common/strlib.c @@ -925,6 +925,7 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc char** fields; // buffer for fields ([0] is reserved) int columns, fields_length; char path[1024], line[1024]; + char* match; snprintf(path, sizeof(path), "%s/%s", directory, filename); @@ -944,9 +945,12 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc while( fgets(line, sizeof(line), fp) ) { lines++; - if( line[0] == '/' && line[1] == '/' ) - continue; - //TODO: strip trailing // comment + + if( ( match = strstr(line, "//") ) != NULL ) + {// strip comments + match[0] = 0; + } + //TODO: strip trailing whitespace if( line[0] == '\0' || line[0] == '\n' || line[0] == '\r') continue; |