diff --git a/src/char/inter.c b/src/char/inter.c index cb136bcb89..0fc3e9847c 100644 --- a/src/char/inter.c +++ b/src/char/inter.c @@ -915,7 +915,6 @@ int mapif_parse_broadcast(int fd) int mapif_parse_WisRequest(int fd) { struct WisData* wd; - static int wisid = 0; char name[NAME_LENGTH]; char esc_name[NAME_LENGTH*2+1];// escaped name char* data; @@ -964,6 +963,7 @@ int mapif_parse_WisRequest(int fd) } else { + static int wisid = 0; CREATE(wd, struct WisData, 1); diff --git a/src/common/network.c b/src/common/network.c index 1f1621363b..68394dcc1a 100644 --- a/src/common/network.c +++ b/src/common/network.c @@ -68,13 +68,12 @@ void network_init(){ for(i = 0; i < MAXCONN; i++){ s = &g_Session[i]; - + s->type = NST_FREE; s->disconnect_in_progress = false; - } - // Initialize the correspondig event dispatcher + // Initialize the corresponding event dispatcher evdp_init(); // @@ -317,16 +316,18 @@ void network_disconnect(int32 fd){ int32 network_addlistener(bool v6, const char *addr, uint16 port){ SESSION *s; - int optval, fd; + int fd; +#ifdef SO_REUSEADDR + int optval; +#endif #if !defined(ENABLE_IPV6) if(v6 == true){ - ShowError("network_addlistener(%c, '%s', %u): this release has no IPV6 support.\n", (v6==true?'t':'f'), addr, port); + ShowError("network_addlistener(%c, '%s', %u): this release has no IPV6 support.\n", (v6==true?'t':'f'), addr, port); return -1; } #endif - #ifdef ENABLE_IPV6 if(v6 == true) fd = socket(AF_INET6, SOCK_STREAM, 0); @@ -336,7 +337,7 @@ int32 network_addlistener(bool v6, const char *addr, uint16 port){ // Error? if(fd == -1){ - ShowError("network_addlistener(%c, '%s', %u): socket() failed (errno: %u / %s)\n", (v6==true?'t':'f'), addr, port, errno, strerror(errno)); + ShowError("network_addlistener(%c, '%s', %u): socket() failed (errno: %u / %s)\n", (v6==true?'t':'f'), addr, port, errno, strerror(errno)); return -1; } @@ -346,16 +347,14 @@ int32 network_addlistener(bool v6, const char *addr, uint16 port){ close(fd); return -1; } - - + s = &g_Session[fd]; if(s->type != NST_FREE){ // additional checks.. :) - ShowError("network_addlistener(%c, '%s', %u): failed, got fd #%u which is already in use in local session table?!\n", (v6==true?'t':'f'), addr, port, fd); + ShowError("network_addlistener(%c, '%s', %u): failed, got fd #%u which is already in use in local session table?!\n", (v6==true?'t':'f'), addr, port, fd); close(fd); return -1; } - - + // Fill ip addr structs #ifdef ENABLE_IPV6 if(v6 == true){ @@ -363,11 +362,10 @@ int32 network_addlistener(bool v6, const char *addr, uint16 port){ s->addr.v6.sin6_family = AF_INET6; s->addr.v6.sin6_port = htons(port); if(inet_pton(AF_INET6, addr, &s->addr.v6.sin6_addr) != 1){ - ShowError("network_addlistener(%c, '%s', %u): failed to parse the given IPV6 address.\n", (v6==true?'t':'f'), addr, port); + ShowError("network_addlistener(%c, '%s', %u): failed to parse the given IPV6 address.\n", (v6==true?'t':'f'), addr, port); close(fd); return -1; } - }else{ #endif memset(&s->addr.v4, 0x00, sizeof(s->addr.v4)); @@ -377,12 +375,11 @@ int32 network_addlistener(bool v6, const char *addr, uint16 port){ #ifdef ENABLE_IPV6 } #endif - // if OS has support for SO_REUSEADDR, apply the flag // so the address could be used when there're still time_wait sockets outstanding from previous application run. #ifdef SO_REUSEADDR - optval=1; + optval = 1; setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)); #endif @@ -390,14 +387,14 @@ int32 network_addlistener(bool v6, const char *addr, uint16 port){ #ifdef ENABLE_IPV6 if(v6 == true){ if( bind(fd, (struct sockaddr*)&s->addr.v6, sizeof(s->addr.v6)) == -1) { - ShowError("network_addlistener(%c, '%s', %u): bind failed (errno: %u / %s)\n", (v6==true?'t':'f'), addr, port, errno, strerror(errno)); + ShowError("network_addlistener(%c, '%s', %u): bind failed (errno: %u / %s)\n", (v6==true?'t':'f'), addr, port, errno, strerror(errno)); close(fd); return -1; } }else{ #endif if( bind(fd, (struct sockaddr*)&s->addr.v4, sizeof(s->addr.v4)) == -1) { - ShowError("network_addlistener(%c, '%s', %u): bind failed (errno: %u / %s)\n", (v6==true?'t':'f'), addr, port, errno, strerror(errno)); + ShowError("network_addlistener(%c, '%s', %u): bind failed (errno: %u / %s)\n", (v6==true?'t':'f'), addr, port, errno, strerror(errno)); close(fd); return -1; } @@ -406,7 +403,7 @@ int32 network_addlistener(bool v6, const char *addr, uint16 port){ #endif if( listen(fd, l_ListenBacklog) == -1){ - ShowError("network_addlistener(%c, '%s', %u): listen failed (errno: %u / %s)\n", (v6==true?'t':'f'), addr, port, errno, strerror(errno)); + ShowError("network_addlistener(%c, '%s', %u): listen failed (errno: %u / %s)\n", (v6==true?'t':'f'), addr, port, errno, strerror(errno)); close(fd); return -1; } @@ -414,20 +411,18 @@ int32 network_addlistener(bool v6, const char *addr, uint16 port){ // Set to nonblock! if(_setnonblock(fd) == false){ - ShowError("network_addlistener(%c, '%s', %u): cannot set to nonblock (errno: %u / %s)\n", (v6==true?'t':'f'), addr, port, errno, strerror(errno)); + ShowError("network_addlistener(%c, '%s', %u): cannot set to nonblock (errno: %u / %s)\n", (v6==true?'t':'f'), addr, port, errno, strerror(errno)); close(fd); return -1; } - // Rgister @ evdp. if( evdp_addlistener(fd, &s->evdp_data) != true){ - ShowError("network_addlistener(%c, '%s', %u): eventdispatcher subsystem returned an error.\n", (v6==true?'t':'f'), addr, port); + ShowError("network_addlistener(%c, '%s', %u): eventdispatcher subsystem returned an error.\n", (v6==true?'t':'f'), addr, port); close(fd); return -1; } - - + // Apply flags on Session array for this conneciton. if(v6 == true) s->v6 = true; else s->v6 = false; @@ -507,8 +502,11 @@ int32 network_connect(bool v6, void (*onConnectionLooseHandler)(int32 fd) ){ register SESSION *s; - int32 fd, optval, ret; + int32 fd, ret; struct sockaddr_in ip4; +#ifdef SO_REUSEADDR + int optval; +#endif #ifdef ENABLE_IPV6 struct sockaddr_in6 ip6; #endif @@ -523,19 +521,18 @@ int32 network_connect(bool v6, #ifndef ENABLE_IPV6 // check.. if(v6 == true){ - ShowError("network_connect(%c, '%s', %u...): tried to create an ipv6 connection, IPV6 is not supported in this release.\n", (v6==true?'t':'f'), addr, port); + ShowError("network_connect(%c, '%s', %u...): tried to create an ipv6 connection, IPV6 is not supported in this release.\n", (v6==true?'t':'f'), addr, port); return -1; } #endif // check connection limits. if(fd >= MAXCONN){ - ShowError("network_connect(%c, '%s', %u...): cannot create new connection, exceeeds more than supported connections (%u)\n", (v6==true?'t':'f'), addr, port ); + ShowError("network_connect(%c, '%s', %u...): cannot create new connection, exceeeds more than supported connections (%u)\n", (v6==true?'t':'f'), addr, port ); close(fd); return -1; } - // Originating IP/Port pair given ? if(from_addr != NULL && *from_addr != 0){ //.. @@ -543,7 +540,7 @@ int32 network_connect(bool v6, optval=1; setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)); #endif - + #ifdef ENABLE_IPV6 if(v6 == true){ memset(&ip6, 0x00, sizeof(ip6)); @@ -551,16 +548,16 @@ int32 network_connect(bool v6, ip6.sin6_port = htons(from_port); if(inet_pton(AF_INET6, from_addr, &ip6.sin6_addr) != 1){ - ShowError("network_connect(%c, '%s', %u...): cannot parse originating (from) IPV6 address (errno: %u / %s)\n", (v6==true?'t':'f'), addr, port, errno, strerror(errno)); + ShowError("network_connect(%c, '%s', %u...): cannot parse originating (from) IPV6 address (errno: %u / %s)\n", (v6==true?'t':'f'), addr, port, errno, strerror(errno)); close(fd); return -1; } - + ret = bind(fd, (struct sockaddr*)&ip6, sizeof(ip6)); }else{ #endif memset(&ip4, 0x00, sizeof(ip4)); - + ip4.sin_family = AF_INET; ip4.sin_port = htons(from_port); ip4.sin_addr.s_addr = inet_addr(from_addr); @@ -570,11 +567,10 @@ int32 network_connect(bool v6, #endif } - // Set non block if(_setnonblock(fd) == false){ - ShowError("network_connect(%c, '%s', %u...): cannot set socket to nonblocking (errno: %u / %s)\n", (v6==true?'t':'f'), addr, port, errno, strerror(errno)); + ShowError("network_connect(%c, '%s', %u...): cannot set socket to nonblocking (errno: %u / %s)\n", (v6==true?'t':'f'), addr, port, errno, strerror(errno)); close(fd); return -1; } @@ -588,7 +584,7 @@ int32 network_connect(bool v6, ip6.sin6_port = htons(port); if(inet_pton(AF_INET6, addr, &ip6.sin6_addr) != 1){ - ShowError("network_connect(%c, '%s', %u...): cannot parse destination IPV6 address (errno: %u / %s)\n", (v6==true?'t':'f'), addr, port, errno, strerror(errno)); + ShowError("network_connect(%c, '%s', %u...): cannot parse destination IPV6 address (errno: %u / %s)\n", (v6==true?'t':'f'), addr, port, errno, strerror(errno)); close(fd); return -1; } @@ -604,7 +600,6 @@ int32 network_connect(bool v6, } #endif - // Assign Session.. s = &g_Session[fd]; s->type = NST_OUTGOING; @@ -622,7 +617,7 @@ int32 network_connect(bool v6, // Register @ EVDP. as outgoing (see doc of the function) if(evdp_addconnecting(fd, &s->evdp_data) == false){ - ShowError("network_connect(%c, '%s', %u...): eventdispatcher subsystem returned an error.\n", (v6==true?'t':'f'), addr, port); + ShowError("network_connect(%c, '%s', %u...): eventdispatcher subsystem returned an error.\n", (v6==true?'t':'f'), addr, port); // cleanup session x.x.. s->type = NST_FREE; @@ -635,7 +630,6 @@ int32 network_connect(bool v6, return -1; } - #ifdef ENABLE_IPV6 if(v6 == true) ret = connect(fd, (struct sockaddr*)&ip6, sizeof(ip6)); @@ -660,7 +654,6 @@ int32 network_connect(bool v6, return -1; } - // ! The Info Message :~D ShowStatus("network_connect fd#%u (%s:%u) in progress.. \n", fd, addr, port); diff --git a/src/common/strlib.c b/src/common/strlib.c index 97b6b19a41..c752a43fc5 100644 --- a/src/common/strlib.c +++ b/src/common/strlib.c @@ -155,14 +155,15 @@ char* trim(char* str) // that pointer with the returned value, since the original pointer must be // deallocated using the same allocator with which it was allocated. The return // value must NOT be deallocated using free() etc. -char *trim2(char *str,char flag){ - char *end; - if(flag&1){ // Trim leading space +char *trim2(char *str,char flag) { + if(flag&1) { // Trim leading space while(isspace(*str)) str++; if(*str == 0) // All spaces? return str; } - if(flag&2){ // Trim trailing space + if(flag&2) { // Trim trailing space + char *end; + end = str + strlen(str) - 1; while(end > str && isspace(*end)) end--; *(end+1) = 0; // Write new null terminator diff --git a/src/map/instance.c b/src/map/instance.c index 2a54f08794..df87ca2e56 100644 --- a/src/map/instance.c +++ b/src/map/instance.c @@ -407,7 +407,7 @@ int instance_destroy(short instance_id) { struct instance_data *im; struct party_data *p; - int i, type = 0, count = 0; + int i, type = 0; unsigned int now = (unsigned int)time(NULL); if(instance_id <= 0 || instance_id > MAX_INSTANCE_DATA) @@ -447,7 +447,7 @@ int instance_destroy(short instance_id) type = 3; for(i = 0; i < MAX_MAP_PER_INSTANCE; i++) - count += map_delinstancemap(im->map[i].m); + map_delinstancemap(im->map[i].m); } if(im->keep_timer != -1) { diff --git a/src/map/npc.c b/src/map/npc.c index fdce6df0e7..3955dfb973 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -2414,12 +2414,11 @@ static const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const switch(type) { case ITEMSHOP: { - struct item_data* tmp; if (sscanf(p,",%d:%d,",&nameid,&is_discount) < 1) { ShowError("npc_parse_shop: Invalid item cost definition in file '%s', line '%d'. Ignoring the rest of the line...\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer,start-buffer), w1, w2, w3, w4); return strchr(start,'\n'); // skip and continue } - if ((tmp = itemdb_exists(nameid)) == NULL) { + if (itemdb_exists(nameid) == NULL) { ShowWarning("npc_parse_shop: Invalid item ID cost in file '%s', line '%d' (id '%d').\n", filepath, strline(buffer,start-buffer), nameid); return strchr(start,'\n'); // skip and continue } @@ -3339,7 +3338,7 @@ static const char* npc_parse_mob(char* w1, char* w2, char* w3, char* w4, const c return strchr(start,'\n');// skip and continue } - if( (mob.state.size < 0 || mob.state.size > 2) && size != -1 ) + if( mob.state.size > 2 && size != -1 ) { ShowError("npc_parse_mob: Invalid size number %d for mob ID %d (file '%s', line '%d').\n", mob.state.size, class_, filepath, strline(buffer, start - buffer)); return strchr(start, '\n'); @@ -3812,7 +3811,6 @@ void npc_parsesrcfile(const char* filepath, bool runOnInit) // More info at http://unicode.org/faq/utf_bom.html#bom5 and http://en.wikipedia.org/wiki/Byte_order_mark#UTF-8 ShowError("npc_parsesrcfile: Detected unsupported UTF-8 BOM in file '%s'. Stopping (please consider using another character set).\n", filepath); aFree(buffer); - fclose(fp); return; } diff --git a/src/map/pet.c b/src/map/pet.c index 33d4e58dde..a684e96c68 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -863,7 +863,7 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns if (DIFF_TICK(tick, pd->ud.canmove_tick) < 0) return 0; //Can't move yet. pd->status.speed = (sd->battle_status.speed>>1); - if(pd->status.speed <= 0) + if(pd->status.speed == 0) pd->status.speed = 1; if (!unit_walktobl(&pd->bl, &sd->bl, 3, 0)) pet_randomwalk(pd,tick); diff --git a/src/map/script.c b/src/map/script.c index 7d919db227..0007b50d69 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -9464,7 +9464,7 @@ BUILDIN_FUNC(clone) TBL_PC *sd, *msd=NULL; int char_id,master_id=0,x,y, mode = 0, flag = 0, m; unsigned int duration = 0; - const char *map,*event=""; + const char *map,*event; map=script_getstr(st,2); x=script_getnum(st,3); @@ -18054,7 +18054,7 @@ static int atcommand_cleanfloor_sub(struct block_list *bl, va_list ap) BUILDIN_FUNC(cleanmap) { const char *map; - int16 m = -1; + int16 m; int16 x0 = 0, y0 = 0, x1 = 0, y1 = 0; map = script_getstr(st, 2);