Pārlūkot izejas kodu

- Added function parse_hostbyname() which takes a hostname and a char[4]. The hostname is resolved to an ip, whose individual components are stored in char[], the return value of the function is the inet_addr result of the lookup (or returns 0 when failed). Meant to be used in the rest of the code without the need to do socket/network related includes.
- Applied use of parse_hostbyname() in chrif.c to fix compilation errors.
- status_percent_change will now account for when the target's max hp/sp is above INT_MAX.


git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@7281 54d463be-8e91-2dee-dedb-b68131a5f0ec

skotlex 19 gadi atpakaļ
vecāks
revīzija
847d853332
8 mainītis faili ar 51 papildinājumiem un 13 dzēšanām
  1. 4 0
      Changelog-Trunk.txt
  2. 0 1
      conf-tmpl/char_athena.conf
  3. 0 1
      src/char/char.c
  4. 16 1
      src/common/socket.c
  5. 5 0
      src/common/socket.h
  6. 6 6
      src/map/chrif.c
  7. 4 4
      src/map/pc.c
  8. 16 0
      src/map/status.c

+ 4 - 0
Changelog-Trunk.txt

@@ -4,6 +4,10 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 
 2006/06/21
+	* Applied use of parse_hostbyname() in chrif.c to fix compilation errors.
+	  [Skotlex]
+	* status_percent_change will now account for when the target's max hp/sp is
+	  above INT_MAX. [Skotlex]
 	* [Added]:
 	  - DNS (WAN) sync for those pesky disconnections (dynamic ip renewal). [Lance]
 2006/06/20

+ 0 - 1
conf-tmpl/char_athena.conf

@@ -144,7 +144,6 @@ fame_list_taekwon: 10
 // to 200, the guild receives double the player's taxed exp.
 guild_exp_rate: 100
 
-
 // Name used for unknown characters
 unknown_char_name: Unknown
 

+ 0 - 1
src/char/char.c

@@ -2504,7 +2504,6 @@ int char_send_fame_list(int fd) {
 
 int search_mapserver(unsigned short map, long ip, short port);
 
-
 int parse_frommap(int fd) {
 	int i, j;
 	int id;

+ 16 - 1
src/common/socket.c

@@ -9,6 +9,7 @@
 #ifdef __WIN32
 #define __USE_W32_SOCKETS
 #include <windows.h>
+#include <winsock.h>
 #include <io.h>
 typedef int socklen_t;
 #else
@@ -16,9 +17,11 @@ typedef int socklen_t;
 #include <netinet/in.h>
 #include <netinet/tcp.h>
 #include <net/if.h>
-#include <sys/time.h>
 #include <unistd.h>
+#include <sys/time.h>
 #include <sys/ioctl.h>
+#include <netdb.h>
+#include <arpa/inet.h>
 
 #ifndef SIOCGIFCONF
 #include <sys/sockio.h> // SIOCGIFCONF on Solaris, maybe others? [Shinomori]
@@ -1388,3 +1391,15 @@ bool session_isActive(int fd)
 {
 	return ( session_isValid(fd) && !session[fd]->eof );
 }
+
+in_addr_t resolve_hostbyname(char* hostname, char *ip) {
+	struct hostent *h = gethostbyname(hostname);
+	char ip_str[16];
+	if (!h) return 0;
+	ip[0] = (unsigned char) h->h_addr[0];
+	ip[1]	= (unsigned char) h->h_addr[1];
+	ip[2] = (unsigned char) h->h_addr[2];
+	ip[3] = (unsigned char) h->h_addr[3];
+	sprintf(ip_str, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
+	return inet_addr(ip_str);
+}

+ 5 - 0
src/common/socket.h

@@ -154,6 +154,11 @@ int start_console(void);
 void set_defaultparse(int (*defaultparse)(int));
 void set_defaultconsoleparse(int (*defaultparse)(char*));
 
+//Resolves the hostname and stores the string representation of the string in ip.
+//Meant to simplify calls to gethostbyname without the need of all the
+//required network includes.
+int resolve_hostbyname(char* hostname, char *ip);
+
 extern unsigned int addr_[16];   // ip addresses of local host (host byte order)
 extern unsigned int naddr_;   // # of ip addresses
 

+ 6 - 6
src/map/chrif.c

@@ -1415,14 +1415,14 @@ int chrif_disconnect(int fd) {
 }
 
 void chrif_update_ip(int fd){
-	struct hostent *h = map_server_dns?gethostbyname(map_server_dns):NULL;
+	char ip[4];
 	ShowInfo("IP Sync in progress...\n");
-	if(h){
+	if (map_server_dns && resolve_hostbyname(map_server_dns, ip)) {
 		WFIFOW(fd, 0) = 0x2736;
-		WFIFOB(fd, 2) = h->h_addr[0];
-		WFIFOB(fd, 3) = h->h_addr[1];
-		WFIFOB(fd, 4) = h->h_addr[2];
-		WFIFOB(fd, 5) = h->h_addr[3];
+		WFIFOB(fd, 2) = ip[0];
+		WFIFOB(fd, 3) = ip[1];
+		WFIFOB(fd, 4) = ip[2];
+		WFIFOB(fd, 5) = ip[3];
 		WFIFOSET(fd, 6);
 	}
 }

+ 4 - 4
src/map/pc.c

@@ -1552,14 +1552,14 @@ int pc_bonus(struct map_session_data *sd,int type,int val)
 	case SP_NO_MAGIC_DAMAGE:
 		if(sd->state.lr_flag == 2)
 			break;
-			val+= sd->special_state.no_magic_damage;
-			sd->special_state.no_magic_damage = cap_value(val,0,100);
+		val+= sd->special_state.no_magic_damage;
+		sd->special_state.no_magic_damage = cap_value(val,0,100);
 		break;
 	case SP_NO_WEAPON_DAMAGE:
 		if(sd->state.lr_flag == 2)
 			break;
-			val+= sd->special_state.no_weapon_damage;
-			sd->special_state.no_weapon_damage = cap_value(val,0,100);
+		val+= sd->special_state.no_weapon_damage;
+		sd->special_state.no_weapon_damage = cap_value(val,0,100);
 		break;
 	case SP_NO_GEMSTONE:
 		if(sd->state.lr_flag != 2)

+ 16 - 0
src/map/status.c

@@ -767,6 +767,22 @@ int status_percent_change(struct block_list *src,struct block_list *target,signe
 	if (sp_rate && !sp)
 		sp = 1;
 
+	//Ugly check in case damage dealt is too much for the received args of
+	//status_heal / status_damage. [Skotlex]
+	if (hp > INT_MAX) {
+	  	hp -= INT_MAX;
+		if (flag)
+		  	status_heal(target, INT_MAX, 0, 0);
+		else
+			status_damage(src, target, INT_MAX, 0, 0, (!src||src==target?5:1));
+	}
+  	if (sp > INT_MAX) {
+		sp -= INT_MAX;
+		if (flag)
+		  	status_heal(target, 0, INT_MAX, 0);
+		else
+			status_damage(src, target, 0, INT_MAX, 0, (!src||src==target?5:1));
+	}	
 	if (flag) return status_heal(target, hp, sp, 0);
 	return status_damage(src, target, hp, sp, 0, (!src||src==target?5:1));
 }