From 7e72f0cee8867837be53cb2119b610b00e9bd587 Mon Sep 17 00:00:00 2001 From: shennetsind Date: Mon, 18 Feb 2013 00:30:28 -0300 Subject: Improvements all over the place Committing on the behalf of mkbu95 who is unable to do it himself, he coded it all and sent me the diff. Thanks mkbu95! Signed-off-by: shennetsind --- src/char/char.c | 14 +++++++------- src/char/int_guild.c | 11 ++++++----- src/common/core.c | 2 +- src/common/grfio.c | 16 +++++++++------- src/common/raconf.c | 6 +++--- src/common/socket.c | 6 +++--- src/login/account_sql.c | 2 +- src/login/login.c | 7 ++++--- src/map/atcommand.c | 43 ++++++++++++++++++++++--------------------- src/map/battle.c | 11 ++++++----- src/map/chat.c | 4 ++-- src/map/chrif.c | 3 ++- src/map/clif.c | 16 ++++++++-------- src/map/guild.c | 2 +- src/map/homunculus.c | 6 +++--- src/map/itemdb.c | 2 +- src/map/map.c | 4 ++-- src/map/mob.c | 20 ++++++++------------ src/map/npc.c | 14 ++++++++------ src/map/party.c | 5 ++--- src/map/pc.c | 33 ++++++++++++++++++--------------- src/map/pc_groups.c | 2 +- src/map/pet.c | 6 ++---- src/map/script.c | 15 ++++++++------- src/map/skill.c | 21 ++++++++++++--------- 25 files changed, 140 insertions(+), 131 deletions(-) diff --git a/src/char/char.c b/src/char/char.c index e7220aa36..cd1b1da66 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -2833,8 +2833,6 @@ int parse_frommap(int fd) if( RFIFOREST(fd) < 18 ) return 0; { - struct auth_node* node; - int account_id = RFIFOL(fd,2); uint32 login_id1 = RFIFOL(fd,6); uint32 login_id2 = RFIFOL(fd,10); @@ -2851,6 +2849,8 @@ int parse_frommap(int fd) } else { + struct auth_node* node; + // create temporary auth entry CREATE(node, struct auth_node, 1); node->account_id = account_id; @@ -2880,7 +2880,6 @@ int parse_frommap(int fd) return 0; { int map_id, map_fd = -1; - struct online_char_data* data; struct mmo_charstatus* char_data; struct mmo_charstatus char_dat; @@ -2898,6 +2897,7 @@ int parse_frommap(int fd) session_isActive(map_fd) && char_data ) { //Send the map server the auth of this player. + struct online_char_data* data; struct auth_node* node; //Update the "last map" as this is where the player must be spawned on the new map server. @@ -4571,25 +4571,25 @@ int char_config_read(const char* cfgName) safestrncpy(wisp_server_name, w2, sizeof(wisp_server_name)); } } else if (strcmpi(w1, "login_ip") == 0) { - char ip_str[16]; login_ip = host2ip(w2); if (login_ip) { + char ip_str[16]; safestrncpy(login_ip_str, w2, sizeof(login_ip_str)); ShowStatus("Login server IP address : %s -> %s\n", w2, ip2str(login_ip, ip_str)); } } else if (strcmpi(w1, "login_port") == 0) { login_port = atoi(w2); } else if (strcmpi(w1, "char_ip") == 0) { - char ip_str[16]; char_ip = host2ip(w2); - if (char_ip){ + if (char_ip) { + char ip_str[16]; safestrncpy(char_ip_str, w2, sizeof(char_ip_str)); ShowStatus("Character server IP address : %s -> %s\n", w2, ip2str(char_ip, ip_str)); } } else if (strcmpi(w1, "bind_ip") == 0) { - char ip_str[16]; bind_ip = host2ip(w2); if (bind_ip) { + char ip_str[16]; safestrncpy(bind_ip_str, w2, sizeof(bind_ip_str)); ShowStatus("Character server binding IP address : %s -> %s\n", w2, ip2str(bind_ip, ip_str)); } diff --git a/src/char/int_guild.c b/src/char/int_guild.c index 7c2086722..46bba63db 100644 --- a/src/char/int_guild.c +++ b/src/char/int_guild.c @@ -217,8 +217,8 @@ int inter_guild_tosql(struct guild *g,int flag) strcat(t_info, " level"); if( add_comma ) StringBuf_AppendStr(&buf, ", "); - else - add_comma = true; + //else //last condition using add_coma setting + // add_comma = true; StringBuf_Printf(&buf, "`guild_lv`=%d, `skill_point`=%d, `exp`=%"PRIu64", `next_exp`=%u, `max_member`=%d", g->guild_lv, g->skill_point, g->exp, g->next_exp, g->max_member); } StringBuf_Printf(&buf, " WHERE `guild_id`=%d", g->guild_id); @@ -509,7 +509,7 @@ struct guild * inter_guild_fromsql(int guild_id) { int id; Sql_GetData(sql_handle, 0, &data, NULL); id = atoi(data) - GD_SKILLBASE; - if( id < 0 && id >= MAX_GUILDSKILL ) + if( id < 0 || id >= MAX_GUILDSKILL ) continue;// invalid guild skill Sql_GetData(sql_handle, 1, &data, NULL); g->skill[id].lv = atoi(data); } @@ -604,7 +604,7 @@ static bool exp_guild_parse_row(char* split[], int column, int current) { unsigned int exp = (unsigned int)atol(split[0]); - if (exp < 0 || exp >= UINT_MAX) { + if (exp >= UINT_MAX) { ShowError("exp_guild: Invalid exp %d at line %d\n", exp, current); return false; } @@ -1262,7 +1262,7 @@ int mapif_parse_GuildAddMember(int fd,int guild_id,struct guild_member *m) // Delete member from guild int mapif_parse_GuildLeave(int fd, int guild_id, int account_id, int char_id, int flag, const char *mes) { - int i, j; + int i; struct guild* g = inter_guild_fromsql(guild_id); if( g == NULL ) @@ -1285,6 +1285,7 @@ int mapif_parse_GuildLeave(int fd, int guild_id, int account_id, int char_id, in if( flag ) { // Write expulsion reason // Find an empty slot + int j; ARR_FIND( 0, MAX_GUILDEXPULSION, j, g->expulsion[j].account_id == 0 ); if( j == MAX_GUILDEXPULSION ) { diff --git a/src/common/core.c b/src/common/core.c index 4495cf1a2..b004d2b96 100644 --- a/src/common/core.c +++ b/src/common/core.c @@ -272,7 +272,7 @@ const char *get_git_hash (void) { char line[64]; char *rev = malloc (sizeof (char) * 50); - if (fgets (line, sizeof (line), fp) && sscanf (line, "%s", rev)) + if (fgets (line, sizeof (line), fp) && sscanf (line, "%50s", rev)) snprintf (HerculesGitHash, sizeof (HerculesGitHash), "%s", rev); free (rev); diff --git a/src/common/grfio.c b/src/common/grfio.c index 8f430cfb9..cc2f866f7 100644 --- a/src/common/grfio.c +++ b/src/common/grfio.c @@ -393,12 +393,12 @@ void* grfio_reads(const char* fname, int* size) FILELIST* entry = filelist_find(fname); if( entry == NULL || entry->gentry <= 0 ) {// LocalFileCheck char lfname[256]; - int declen; FILE* in; grfio_localpath_create(lfname, sizeof(lfname), ( entry && entry->fnd ) ? entry->fnd : fname); in = fopen(lfname, "rb"); if( in != NULL ) { + int declen; fseek(in,0,SEEK_END); declen = ftell(in); fseek(in,0,SEEK_SET); @@ -475,14 +475,14 @@ static char* decode_filename(unsigned char* buf, int len) /// @return true if the file should undergo full mode 0 decryption, and true otherwise. static bool isFullEncrypt(const char* fname) { - static const char extensions[4][5] = { ".gnd", ".gat", ".act", ".str" }; - size_t i; - const char* ext = strrchr(fname, '.'); - if( ext != NULL ) + if( ext != NULL ) { + static const char extensions[4][5] = { ".gnd", ".gat", ".act", ".str" }; + size_t i; for( i = 0; i < ARRAYLENGTH(extensions); ++i ) if( strcmpi(ext, extensions[i]) == 0 ) return false; + } return true; } @@ -492,7 +492,7 @@ static bool isFullEncrypt(const char* fname) /// @param gentry index of the grf file name in the gentry_table static int grfio_entryread(const char* grfname, int gentry) { - long grf_size,list_size; + long grf_size; unsigned char grf_header[0x2e]; int entry,entrys,ofs,grf_version; unsigned char *grf_filelist; @@ -518,6 +518,7 @@ static int grfio_entryread(const char* grfname, int gentry) grf_version = getlong(grf_header+0x2a) >> 8; if( grf_version == 0x01 ) {// ****** Grf version 01xx ****** + long list_size; list_size = grf_size - ftell(fp); grf_filelist = (unsigned char *) aMalloc(list_size); if(fread(grf_filelist,1,list_size,fp) != list_size) { ShowError("Couldn't read all grf_filelist element of %s \n", grfname); } @@ -678,7 +679,7 @@ static bool grfio_parse_restable_row(const char* row) static void grfio_resourcecheck(void) { char restable[256]; - char *ptr, *buf; + char *buf; int size; FILE* fp; int i = 0; @@ -705,6 +706,7 @@ static void grfio_resourcecheck(void) buf = (char *)grfio_reads("data\\resnametable.txt", &size); if( buf != NULL ) { + char *ptr; buf[size] = '\0'; ptr = buf; diff --git a/src/common/raconf.c b/src/common/raconf.c index 2703560ff..f7d1284b7 100644 --- a/src/common/raconf.c +++ b/src/common/raconf.c @@ -41,12 +41,11 @@ struct conf_value{ static struct conf_value *makeValue(const char *key, char *val, size_t val_len){ struct conf_value *v; - char *p; - size_t sz; +/* size_t sz; sz = sizeof(struct conf_value); if(val_len >= sizeof(v->strval)) - sz += (val_len - sizeof(v->strval) + 1); + sz += (val_len - sizeof(v->strval) + 1);*/ v = (struct conf_value*)aCalloc(1, sizeof(struct conf_value)); if(v == NULL){ @@ -106,6 +105,7 @@ static struct conf_value *makeValue(const char *key, char *val, size_t val_len){ }else if( *val >='0' && *val <= '9'){ // begins with normal digit, so assume its dec. // is it float? bool is_float = false; + char *p; for(p = val; *p != '\0'; p++){ if(*p == '.'){ diff --git a/src/common/socket.c b/src/common/socket.c index 6977d4257..72633cf2b 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -1017,14 +1017,14 @@ int access_ipmask(const char* str, AccessControl* acc) { uint32 ip; uint32 mask; - unsigned int a[4]; - unsigned int m[4]; - int n; if( strcmp(str,"all") == 0 ) { ip = 0; mask = 0; } else { + unsigned int a[4]; + unsigned int m[4]; + int n; if( ((n=sscanf(str,"%u.%u.%u.%u/%u.%u.%u.%u",a,a+1,a+2,a+3,m,m+1,m+2,m+3)) != 8 && // not an ip + standard mask (n=sscanf(str,"%u.%u.%u.%u/%u",a,a+1,a+2,a+3,m)) != 5 && // not an ip + bit mask (n=sscanf(str,"%u.%u.%u.%u",a,a+1,a+2,a+3)) != 4 ) || // not an ip diff --git a/src/login/account_sql.c b/src/login/account_sql.c index ae80163af..f89147334 100644 --- a/src/login/account_sql.c +++ b/src/login/account_sql.c @@ -486,7 +486,6 @@ static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account AccountDBIterator_SQL* iter = (AccountDBIterator_SQL*)self; AccountDB_SQL* db = (AccountDB_SQL*)iter->db; Sql* sql_handle = db->accounts; - int account_id; char* data; // get next account ID @@ -501,6 +500,7 @@ static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account SQL_SUCCESS == Sql_GetData(sql_handle, 0, &data, NULL) && data != NULL ) {// get account data + int account_id; account_id = atoi(data); if( mmo_auth_fromsql(db, acc, account_id) ) { diff --git a/src/login/login.c b/src/login/login.c index 1ced8cb93..54f066b53 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -1606,10 +1606,11 @@ int login_config_read(const char* cfgName) ShowInfo("Console Silent Setting: %d\n", atoi(w2)); } else if( !strcmpi(w1, "bind_ip") ) { - char ip_str[16]; login_config.login_ip = host2ip(w2); - if( login_config.login_ip ) + if( login_config.login_ip ) { + char ip_str[16]; ShowStatus("Login server binding IP address : %s -> %s\n", w2, ip2str(login_config.login_ip, ip_str)); + } } else if( !strcmpi(w1, "login_port") ) { login_config.login_port = (uint16)atoi(w2); @@ -1654,10 +1655,10 @@ int login_config_read(const char* cfgName) else if(!strcmpi(w1, "client_hash")) { int group = 0; char md5[33]; - int i; if (sscanf(w2, "%d, %32s", &group, md5) == 2) { struct client_hash_node *nnode; + int i; CREATE(nnode, struct client_hash_node, 1); for (i = 0; i < 32; i += 2) { diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 320ca83ff..ed42fdad4 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -920,7 +920,7 @@ ACMD_FUNC(option) if (!message || !*message || sscanf(message, "%d %d %d", ¶m1, ¶m2, ¶m3) < 1 || param1 < 0 || param2 < 0 || param3 < 0) {// failed to match the parameters so inform the user of the options - const char* text = NULL; + const char* text; // attempt to find the setting information for this command text = atcommand_help_string( command ); @@ -1230,8 +1230,6 @@ ACMD_FUNC(item2) int item_id, number = 0; int identify = 0, refine = 0, attr = 0; int c1 = 0, c2 = 0, c3 = 0, c4 = 0; - int flag = 0; - int loop, get_count, i; nullpo_retr(-1, sd); memset(item_name, '\0', sizeof(item_name)); @@ -1254,6 +1252,8 @@ ACMD_FUNC(item2) item_id = item_data->nameid; if (item_id > 500) { + int flag = 0; + int loop, get_count, i; loop = 1; get_count = number; if (item_data->type == IT_WEAPON || item_data->type == IT_ARMOR || @@ -2161,7 +2161,6 @@ ACMD_FUNC(produce) { char item_name[100]; int item_id, attribute = 0, star = 0; - int flag = 0; struct item_data *item_data; struct item tmp_item; nullpo_retr(-1, sd); @@ -2186,6 +2185,7 @@ ACMD_FUNC(produce) item_id = item_data->nameid; if (itemdb_isequip2(item_data)) { + int flag = 0; if (attribute < MIN_ATTRIBUTE || attribute > MAX_ATTRIBUTE) attribute = ATTRIBUTE_NORMAL; if (star < MIN_STAR || star > MAX_STAR) @@ -2822,7 +2822,7 @@ ACMD_FUNC(char_ban) memset(atcmd_output, '\0', sizeof(atcmd_output)); memset(atcmd_player_name, '\0', sizeof(atcmd_player_name)); - if (!message || !*message || sscanf(message, "%s %23[^\n]", atcmd_output, atcmd_player_name) < 2) { + if (!message || !*message || sscanf(message, "%255s %23[^\n]", atcmd_output, atcmd_player_name) < 2) { clif_displaymessage(fd, msg_txt(1022)); // Please enter ban time and a player name (usage: @charban/@ban/@banish/@charbanish