diff options
author | skotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-06-27 17:02:59 +0000 |
---|---|---|
committer | skotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-06-27 17:02:59 +0000 |
commit | 12f444137f5000c76f4a46ac7689ae8edc30d626 (patch) | |
tree | 0ddb63b1ea62a0c748b37d322638fe464135f0f4 /src/map | |
parent | 036bbfd9ae5a4a77031fb33a87264e58214c2ba0 (diff) | |
download | hercules-12f444137f5000c76f4a46ac7689ae8edc30d626.tar.gz hercules-12f444137f5000c76f4a46ac7689ae8edc30d626.tar.bz2 hercules-12f444137f5000c76f4a46ac7689ae8edc30d626.tar.xz hercules-12f444137f5000c76f4a46ac7689ae8edc30d626.zip |
- Cleaned up the IP sync code to...
- Use charif_sendallwos rather than manually altering the buffers of each server.
- Use the id variable for identifying current char-server instead of scanning the connected servers for it (it's doing the same work twice)
- Added config setting sync_ip_interval to specify how long to go before updating ip. Defaults to 0 (disabled)
- Sending ip update packets will only be done when the ip changed now.
- Removed dns_str variables, and now char_ip_str/login_ip_str/map_ip_str will hold the unresolved dns address (as these variables have no use otherwise)
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@7360 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/chrif.c | 32 | ||||
-rw-r--r-- | src/map/clif.c | 27 | ||||
-rw-r--r-- | src/map/clif.h | 1 | ||||
-rw-r--r-- | src/map/map.c | 2 |
4 files changed, 38 insertions, 24 deletions
diff --git a/src/map/chrif.c b/src/map/chrif.c index be0b2a25f..34279bb52 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -30,7 +30,6 @@ //Free Packets: F->2af8
struct dbt *auth_db;
-char *map_server_dns = NULL;
static const int packet_len_table[0x3d] = {
60, 3,-1,27,10,-1, 6,-1, // 2af8-2aff: U->2af8, U->2af9, U->2afa, U->2afb, U->2afc, U->2afd, U->2afe, U->2aff
@@ -88,8 +87,8 @@ static const int packet_len_table[0x3d] = { int chrif_connected;
int char_fd = 0; //Using 0 instead of -1 is safer against crashes. [Skotlex]
int srvinfo;
-static char char_ip_str[16];
-static int char_ip;
+static char char_ip_str[128];
+static in_addr_t char_ip= 0;
static int char_port = 6121;
static char userid[NAME_LENGTH], passwd[NAME_LENGTH];
static int chrif_state = 0;
@@ -145,13 +144,15 @@ void chrif_checkdefaultlogin(void) */
int chrif_setip(char *ip)
{
- char_ip = resolve_hostbyname(ip,NULL,char_ip_str);
+ char ip_str[16];
+ char_ip = resolve_hostbyname(ip,NULL,ip_str);
if (!char_ip) {
ShowWarning("Failed to Resolve Char Server Address! (%s)\n", ip);
return 0;
}
- ShowInfo("Char Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, char_ip_str);
+ strncpy(char_ip_str, ip, sizeof(char_ip_str));
+ ShowInfo("Char Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip_str);
return 1;
}
@@ -1411,16 +1412,17 @@ int chrif_disconnect(int fd) { }
void chrif_update_ip(int fd){
- char ip[4];
- if (map_server_dns && resolve_hostbyname(map_server_dns, ip, NULL)) {
- ShowInfo("IP Sync [%s] in progress...\n",map_server_dns);
- WFIFOW(fd, 0) = 0x2736;
- WFIFOB(fd, 2) = ip[0];
- WFIFOB(fd, 3) = ip[1];
- WFIFOB(fd, 4) = ip[2];
- WFIFOB(fd, 5) = ip[3];
- WFIFOSET(fd, 6);
- }
+ unsigned long new_ip;
+
+ new_ip = resolve_hostbyname(char_ip_str, NULL, NULL);
+ if (new_ip && new_ip != char_ip)
+ char_ip = new_ip; //Update char_ip
+
+ new_ip = clif_refresh_ip();
+ if (!new_ip) return; //No change
+ WFIFOW(fd, 0) = 0x2736;
+ WFIFOL(fd, 2) = new_ip;
+ WFIFOSET(fd, 6);
}
/*==========================================
diff --git a/src/map/clif.c b/src/map/clif.c index 1698045e2..6521dca6c 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -131,7 +131,7 @@ static const int packet_len_table[MAX_PACKET_DB] = { //To idenfity disguised characters.
#define disguised(bl) (bl->type==BL_PC && ((TBL_PC*)bl)->disguise)
-static char map_ip_str[16];
+static char map_ip_str[128];
static in_addr_t map_ip;
static in_addr_t bind_ip = INADDR_ANY;
static int map_port = 5121;
@@ -152,16 +152,15 @@ static void clif_hpmeter_single(int fd, struct map_session_data *sd); */
int clif_setip(char *ip)
{
- map_ip = resolve_hostbyname(ip,NULL,map_ip_str);
+ char ip_str[16];
+ map_ip = resolve_hostbyname(ip,NULL,ip_str);
if (!map_ip) {
ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
return 0;
}
- if(map_server_dns)
- aFree(map_server_dns);
- map_server_dns = aCalloc(strlen(ip)+1,1);
- strcpy(map_server_dns, ip);
- ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, map_ip_str);
+
+ strncpy(map_ip_str, ip, sizeof(map_ip_str));
+ ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip_str);
return 1;
}
@@ -200,6 +199,20 @@ unsigned long clif_getip_long(void) return (unsigned long)map_ip;
}
+//Refreshes map_server ip, returns the new ip if the ip changed, otherwise it
+//returns 0.
+unsigned long clif_refresh_ip(void) {
+ in_addr_t new_ip;
+
+ new_ip = resolve_hostbyname(map_ip_str, NULL, NULL);
+ if (new_ip && new_ip != map_ip) {
+ map_ip = new_ip;
+ ShowInfo("Updating IP resolution of [%s].\n",map_ip_str);
+ return (unsigned long)map_ip;
+ }
+ return 0;
+}
+
/*==========================================
* map鯖のport読み出し
*------------------------------------------
diff --git a/src/map/clif.h b/src/map/clif.h index 91f82662e..7cae56cdf 100644 --- a/src/map/clif.h +++ b/src/map/clif.h @@ -53,6 +53,7 @@ void clif_setbindip(char*); void clif_setport(int);
unsigned long clif_getip_long(void);
+unsigned long clif_refresh_ip(void);
int clif_getport(void);
int clif_countusers(void);
void clif_setwaitclose(int);
diff --git a/src/map/map.c b/src/map/map.c index e6ed26db6..0270b509d 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -3690,8 +3690,6 @@ void do_final(void) { pc_db->destroy(pc_db, NULL); charid_db->destroy(charid_db, NULL); - if(map_server_dns) aFree(map_server_dns); - //#endif #ifndef TXT_ONLY |