summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changelog-Trunk.txt3
-rw-r--r--conf-tmpl/login_athena.conf4
-rw-r--r--src/char/char.c81
-rw-r--r--src/char_sql/char.c78
-rw-r--r--src/login/login.c37
-rw-r--r--src/login_sql/login.c32
-rw-r--r--src/map/chrif.c32
-rw-r--r--src/map/clif.c27
-rw-r--r--src/map/clif.h1
-rw-r--r--src/map/map.c2
10 files changed, 160 insertions, 137 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt
index 7dd377acb..da15dde19 100644
--- a/Changelog-Trunk.txt
+++ b/Changelog-Trunk.txt
@@ -4,6 +4,9 @@ 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/05/27
+ * Cleaned up and optimized the IP sync code. New login_athena config
+ setting sync_ip_interval specifies how often to sync the ip. The default is
+ 0 (disabled). [Skotlex]
* Added mapflag "loadevent", now load-map script events will ONLY trigger
on maps with this mapflag on, rather than every map. [Skotlex]
* High Jump can now be used in all versus maps. [Skotlex]
diff --git a/conf-tmpl/login_athena.conf b/conf-tmpl/login_athena.conf
index 7d8db3538..e0b7c5875 100644
--- a/conf-tmpl/login_athena.conf
+++ b/conf-tmpl/login_athena.conf
@@ -179,6 +179,10 @@ dynamic_pass_failure_ban_how_long: 60
dynamic_account_ban: 1
dynamic_account_ban_class: 0
+//Interval (in minutes) to execute a DNS/IP update. Disabled by default.
+//Enable it if your server uses a dynamic IP which changes with time.
+//ip_sync_interval: 10
+
//DNS Blacklist Blocking (on: 1, off: 0)
use_dnsbl: 0
diff --git a/src/char/char.c b/src/char/char.c
index 0d863e46c..491e24f4e 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -49,12 +49,12 @@ char userid[24];
char passwd[24];
char server_name[20];
char wisp_server_name[NAME_LENGTH] = "Server";
-char login_ip_str[16];
+char login_ip_str[128];
in_addr_t login_ip;
int login_port = 6900;
-char char_ip_str[16];
+char char_ip_str[128];
in_addr_t char_ip;
-char bind_ip_str[16];
+char bind_ip_str[128];
in_addr_t bind_ip;
int char_port = 6121;
int char_maintenance;
@@ -68,7 +68,6 @@ char backup_txt_flag = 0; // The backup_txt file was created because char deleti
char unknown_char_name[1024] = "Unknown";
char char_log_filename[1024] = "log/char.log";
char db_path[1024]="db";
-char *char_server_dns = NULL;
// Advanced subnet check [LuzZza]
struct _subnet {
@@ -2289,24 +2288,26 @@ int parse_tologin(int fd) {
break;
case 0x2735:
{
- unsigned char ip[4];
- if (char_server_dns && resolve_hostbyname(char_server_dns, ip, NULL))
- {
- ShowInfo("IP Sync [%s] in progress...\n",char_server_dns);
+ unsigned char buf[2];
+ in_addr_t new_ip = 0;
+ RFIFOSKIP(fd,2);
+
+ WBUFW(buf,0) = 0x2b1e;
+ mapif_sendall(buf, 2);
+
+ new_ip = resolve_hostbyname(login_ip_str, NULL, NULL);
+ if (new_ip && new_ip != login_ip)
+ login_ip = new_ip; //Update login up.
+
+ new_ip = resolve_hostbyname(char_ip_str, NULL, NULL);
+ if (new_ip && new_ip != char_ip)
+ { //Update ip.
+ char_ip = new_ip;
+ ShowInfo("Updating IP for [%s].\n",char_ip_str);
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);
- }
- for(i = 0; i < MAX_MAP_SERVERS; i++){
- if(server_fd[i] >= 0){
- WFIFOW(server_fd[i], 0) = 0x2b1e;
- WFIFOSET(server_fd[i], 2);
- }
+ WFIFOL(fd,2) = char_ip;
+ WFIFOSET(fd,6);
}
- RFIFOSKIP(fd,2);
break;
}
default:
@@ -3071,12 +3072,11 @@ int parse_frommap(int fd) {
break;
}
case 0x2736:
- for(i = 0; i < MAX_MAP_SERVERS; i++){
- if(server_fd[i] == fd){
- ShowInfo("IP Sync (Server #%d %d.%d.%d.%d) successful.\n",i,(int)RFIFOB(fd,2),(int)RFIFOB(fd,3),(int)RFIFOB(fd,4),(int)RFIFOB(fd,5));
- server[i].ip = RFIFOL(fd, 2);
- }
- }
+ if (RFIFOREST(fd) < 6) return 0;
+ ShowInfo("Updated IP address of Server #%d to %d.%d.%d.%d.\n",i,
+ (int)RFIFOB(fd,2),(int)RFIFOB(fd,3),
+ (int)RFIFOB(fd,4),(int)RFIFOB(fd,5));
+ server[id].ip = RFIFOL(fd, 2);
RFIFOSKIP(fd,6);
break;
default:
@@ -3988,24 +3988,28 @@ int char_config_read(const char *cfgName) {
wisp_server_name[sizeof(wisp_server_name) - 1] = '\0';
}
} else if (strcmpi(w1, "login_ip") == 0) {
- login_ip = resolve_hostbyname(w2, NULL, login_ip_str);
- if (login_ip)
- ShowStatus("Login server IP address : %s -> %s\n", w2, login_ip_str);
+ char ip_str[16];
+ login_ip = resolve_hostbyname(w2, NULL, ip_str);
+ if (login_ip) {
+ strncpy(login_ip_str, w2, sizeof(login_ip_str));
+ ShowStatus("Login server IP address : %s -> %s\n", w2, ip_str);
+ }
} else if (strcmpi(w1, "login_port") == 0) {
login_port = atoi(w2);
} else if (strcmpi(w1, "char_ip") == 0) {
- char_ip = resolve_hostbyname(w2, NULL, char_ip_str);
+ char ip_str[16];
+ char_ip = resolve_hostbyname(w2, NULL, ip_str);
if (char_ip){
- if(char_server_dns)
- aFree(char_server_dns);
- char_server_dns = (char *)aCalloc(strlen(w2)+1, 1);
- strcpy(char_server_dns, w2);
- ShowStatus("Character server IP address : %s -> %s\n", w2, char_ip_str);
+ strncpy(char_ip_str, w2, sizeof(char_ip_str));
+ ShowStatus("Character server IP address : %s -> %s\n", w2, ip_str);
}
} else if (strcmpi(w1, "bind_ip") == 0) {
- bind_ip = resolve_hostbyname(w2, NULL, bind_ip_str);
- if (bind_ip)
- ShowStatus("Character server binding IP address : %s -> %s\n", w2, bind_ip_str);
+ char ip_str[16];
+ bind_ip = resolve_hostbyname(w2, NULL, ip_str);
+ if (bind_ip) {
+ strncpy(bind_ip_str, w2, sizeof(bind_ip_str));
+ ShowStatus("Character server binding IP address : %s -> %s\n", w2, ip_str);
+ }
} else if (strcmpi(w1, "char_port") == 0) {
char_port = atoi(w2);
} else if (strcmpi(w1, "char_maintenance") == 0) {
@@ -4153,7 +4157,6 @@ void do_final(void) {
if(gm_account) aFree(gm_account);
if(char_dat) aFree(char_dat);
- if(char_server_dns) aFree(char_server_dns);
delete_session(login_fd);
delete_session(char_fd);
diff --git a/src/char_sql/char.c b/src/char_sql/char.c
index 77b0119e2..91ded9909 100644
--- a/src/char_sql/char.c
+++ b/src/char_sql/char.c
@@ -96,8 +96,6 @@ int char_per_account = 0; //Maximum charas per account (default unlimited) [Siri
int log_char = 1; // loggin char or not [devil]
int log_inter = 1; // loggin inter or not [devil]
-char *char_server_dns = NULL;
-
// Advanced subnet check [LuzZza]
struct _subnet {
long subnet;
@@ -2174,24 +2172,26 @@ int parse_tologin(int fd) {
case 0x2735:
{
- unsigned char ip_str[4];
- if (char_server_dns && resolve_hostbyname(char_server_dns, ip_str, NULL))
- {
- ShowInfo("IP Sync [%s] in progress...\n",char_server_dns);
+ unsigned char buf[2];
+ in_addr_t new_ip = 0;
+ RFIFOSKIP(fd,2);
+
+ WBUFW(buf,0) = 0x2b1e;
+ mapif_sendall(buf, 2);
+
+ new_ip = resolve_hostbyname(login_ip_str, NULL, NULL);
+ if (new_ip && new_ip != login_ip) //Update login ip, too.
+ login_ip = new_ip;
+
+ new_ip = resolve_hostbyname(char_ip_str, NULL, NULL);
+ if (new_ip && new_ip != char_ip)
+ { //Update ip.
+ char_ip = new_ip;
+ ShowInfo("Updating IP for [%s].\n",char_ip_str);
WFIFOW(fd,0) = 0x2736;
- WFIFOB(fd,2) = ip_str[0];
- WFIFOB(fd,3) = ip_str[1];
- WFIFOB(fd,4) = ip_str[2];
- WFIFOB(fd,5) = ip_str[3];
+ WFIFOL(fd,2) = char_ip;
WFIFOSET(fd,6);
}
- for(i = 0; i < MAX_MAP_SERVERS; i++){
- if(server_fd[i] >= 0){
- WFIFOW(server_fd[i], 0) = 0x2b1e;
- WFIFOSET(server_fd[i], 2);
- }
- }
- RFIFOSKIP(fd,2);
break;
}
default:
@@ -2988,12 +2988,11 @@ int parse_frommap(int fd) {
}
case 0x2736:
- for(i = 0; i < MAX_MAP_SERVERS; i++){
- if(server_fd[i] == fd){
- ShowInfo("IP Sync (Server #%d %d.%d.%d.%d) successful.\n",i,(int)RFIFOB(fd,2),(int)RFIFOB(fd,3),(int)RFIFOB(fd,4),(int)RFIFOB(fd,5));
- server[i].ip = RFIFOL(fd, 2);
- }
- }
+ if (RFIFOREST(fd) < 6) return 0;
+ ShowInfo("Updated IP address of Server #%d to %d.%d.%d.%d.\n",i,
+ (int)RFIFOB(fd,2),(int)RFIFOB(fd,3),
+ (int)RFIFOB(fd,4),(int)RFIFOB(fd,5));
+ server[id].ip = RFIFOL(fd, 2);
RFIFOSKIP(fd,6);
break;
@@ -3954,8 +3953,6 @@ void do_final(void) {
char_db_->destroy(char_db_, NULL);
online_char_db->destroy(online_char_db, NULL);
- if(char_server_dns) aFree(char_server_dns);
-
mysql_close(&mysql_handle);
if(char_gm_read)
mysql_close(&lmysql_handle);
@@ -4096,27 +4093,28 @@ int char_config_read(const char *cfgName) {
wisp_server_name[sizeof(wisp_server_name) - 1] = '\0';
}
} else if (strcmpi(w1, "login_ip") == 0) {
- unsigned char ip_str[4];
- login_ip = resolve_hostbyname(w2, ip_str, login_ip_str);
- if (login_ip)
- ShowStatus("Login server IP address : %s -> %s\n", w2, login_ip_str);
+ unsigned char ip_str[16];
+ login_ip = resolve_hostbyname(w2, NULL, ip_str);
+ if (login_ip) {
+ strncpy(login_ip_str, w2, sizeof(login_ip_str));
+ ShowStatus("Login server IP address : %s -> %s\n", w2, ip_str);
+ }
} else if (strcmpi(w1, "login_port") == 0) {
login_port=atoi(w2);
} else if (strcmpi(w1, "char_ip") == 0) {
- unsigned char ip_str[4];
- char_ip = resolve_hostbyname(w2, ip_str, char_ip_str);
+ unsigned char ip_str[16];
+ char_ip = resolve_hostbyname(w2, NULL, ip_str);
if (char_ip){
- if(char_server_dns)
- aFree(char_server_dns);
- char_server_dns = (char *)aCalloc(strlen(w2)+1, 1);
- strcpy(char_server_dns, w2);
- ShowStatus("Character server IP address : %s -> %s\n", w2, char_ip_str);
+ strncpy(char_ip_str, w2, sizeof(char_ip_str));
+ ShowStatus("Character server IP address : %s -> %s\n", w2, ip_str);
}
} else if (strcmpi(w1, "bind_ip") == 0) {
- unsigned char ip_str[4];
- bind_ip = resolve_hostbyname(w2, ip_str, bind_ip_str);
- if (bind_ip)
- ShowStatus("Character server binging IP address : %s -> %s\n", w2, bind_ip_str);
+ unsigned char ip_str[16];
+ bind_ip = resolve_hostbyname(w2, NULL, ip_str);
+ if (bind_ip) {
+ strncpy(bind_ip_str, w2, sizeof(bind_ip_str));
+ ShowStatus("Character server binding IP address : %s -> %s\n", w2, ip_str);
+ }
} else if (strcmpi(w1, "char_port") == 0) {
char_port = atoi(w2);
} else if (strcmpi(w1, "char_maintenance") == 0) {
diff --git a/src/login/login.c b/src/login/login.c
index 45c18f7b3..197c40dda 100644
--- a/src/login/login.c
+++ b/src/login/login.c
@@ -108,7 +108,7 @@ int check_ip_flag = 1; // It's to check IP of a player between login-server and
int check_client_version = 0; //Client version check ON/OFF .. (sirius)
int client_version_to_connect = 20; //Client version needed to connect ..(sirius)
-
+static int ip_sync_interval = 0;
struct login_session_data {
@@ -248,14 +248,10 @@ int waiting_disconnect_timer(int tid, unsigned int tick, int id, int data)
}
static int sync_ip_addresses(int tid, unsigned int tick, int id, int data){
- int i;
+ unsigned char buf[2];
ShowInfo("IP Sync in progress...\n");
- for(i = 0; i < MAX_SERVERS; i++) {
- if (server_fd[i] >= 0) {
- WFIFOW(server_fd[i], 0) = 0x2735;
- WFIFOSET(server_fd[i],2);
- }
- }
+ WBUFW(buf,0) = 0x2735;
+ charif_sendallwos(-1, buf, 2);
return 0;
}
@@ -1956,12 +1952,12 @@ int parse_fromchar(int fd) {
break;
case 0x2736: // WAN IP update from char-server
- for(i = 0; i < MAX_SERVERS; i++) {
- if (server_fd[i] == fd) {
- ShowInfo("IP Sync (Server #%d %d.%d.%d.%d) successful.\n",i,(int)RFIFOB(fd,2),(int)RFIFOB(fd,3),(int)RFIFOB(fd,4),(int)RFIFOB(fd,5));
- server[i].ip = RFIFOL(fd,2);
- }
- }
+ if (RFIFOREST(fd) < 6)
+ return 0;
+ ShowInfo("Updated IP of Server #%d to %d.%d.%d.%d.\n",i,
+ (int)RFIFOB(fd,2),(int)RFIFOB(fd,3),
+ (int)RFIFOB(fd,4),(int)RFIFOB(fd,5));
+ server[id].ip = RFIFOL(fd,2);
RFIFOSKIP(fd,6);
break;
@@ -3788,7 +3784,10 @@ int login_config_read(const char *cfgName) {
use_dnsbl=atoi(w2);
} else if(strcmpi(w1,"dnsbl_servers")==0) { // [Zido]
strcpy(dnsbl_servs,w2);
+ } else if(strcmpi(w1,"ip_sync_interval")==0) {
+ ip_sync_interval = 1000*60*atoi(w2); //w2 comes in minutes.
}
+
}
}
fclose(fp);
@@ -4165,10 +4164,12 @@ int do_init(int argc, char **argv) {
add_timer_func_list(online_data_cleanup, "online_data_cleanup");
add_timer_interval(gettick() + 600*1000, online_data_cleanup, 0, 0, 600*1000); // every 10 minutes cleanup online account db.
-
- add_timer_func_list(sync_ip_addresses, "sync_ip_addresses");
- add_timer_interval(gettick() + 600*1000, sync_ip_addresses, 0, 0, 600*1000); // Every 10 minutes to sync IPs.
-
+
+
+ if (ip_sync_interval) {
+ add_timer_func_list(sync_ip_addresses, "sync_ip_addresses");
+ add_timer_interval(gettick() + ip_sync_interval, sync_ip_addresses, 0, 0, ip_sync_interval);
+ }
if(console) {
set_defaultconsoleparse(parse_console);
start_console();
diff --git a/src/login_sql/login.c b/src/login_sql/login.c
index 180ac9c08..7bc4d124e 100644
--- a/src/login_sql/login.c
+++ b/src/login_sql/login.c
@@ -85,6 +85,7 @@ int check_ip_flag = 1; // It's to check IP of a player between login-server and
int check_client_version = 0; //Client version check ON/OFF .. (sirius)
int client_version_to_connect = 20; //Client version needed to connect ..(sirius)
static int online_check=1; //When set to 1, login server rejects incoming players that are already registered as online. [Skotlex]
+static int ip_sync_interval = 0;
MYSQL mysql_handle;
@@ -194,14 +195,10 @@ int waiting_disconnect_timer(int tid, unsigned int tick, int id, int data)
}
static int sync_ip_addresses(int tid, unsigned int tick, int id, int data){
- int i;
+ unsigned char buf[2];
ShowInfo("IP Sync in progress...\n");
- for(i = 0; i < MAX_SERVERS; i++) {
- if (server_fd[i] >= 0) {
- WFIFOW(server_fd[i], 0) = 0x2735;
- WFIFOSET(server_fd[i],2);
- }
- }
+ WBUFW(buf,0) = 0x2735;
+ charif_sendallwos(-1, buf, 2);
return 0;
}
@@ -1396,12 +1393,12 @@ int parse_fromchar(int fd){
break;
case 0x2736: // WAN IP update from char-server
- for(i = 0; i < MAX_SERVERS; i++) {
- if (server_fd[i] == fd) {
- ShowInfo("IP Sync (Server #%d %d.%d.%d.%d) successful.\n",i,(int)RFIFOB(fd,2),(int)RFIFOB(fd,3),(int)RFIFOB(fd,4),(int)RFIFOB(fd,5));
- server[i].ip = RFIFOL(fd,2);
- }
- }
+ if (RFIFOREST(fd) < 6)
+ return 0;
+ ShowInfo("Updated IP of Server #%d to %d.%d.%d.%d.\n",i,
+ (int)RFIFOB(fd,2),(int)RFIFOB(fd,3),
+ (int)RFIFOB(fd,4),(int)RFIFOB(fd,5));
+ server[id].ip = RFIFOL(fd,2);
RFIFOSKIP(fd,6);
break;
default:
@@ -2182,6 +2179,8 @@ int login_config_read(const char *cfgName){
use_dnsbl=atoi(w2);
} else if(strcmpi(w1,"dnsbl_servers")==0) { // [Zido]
strcpy(dnsbl_servs,w2);
+ } else if(strcmpi(w1,"ip_sync_interval")==0) {
+ ip_sync_interval = 1000*60*atoi(w2); //w2 comes in minutes.
}
}
fclose(fp);
@@ -2340,9 +2339,10 @@ int do_init(int argc,char **argv){
add_timer_func_list(online_data_cleanup, "online_data_cleanup");
add_timer_interval(gettick() + 600*1000, online_data_cleanup, 0, 0, 600*1000); // every 10 minutes cleanup online account db.
- add_timer_func_list(sync_ip_addresses, "sync_ip_addresses");
- add_timer_interval(gettick() + 600*1000, sync_ip_addresses, 0, 0, 600*1000); // Every 10 minutes to sync IPs.
-
+ if (ip_sync_interval) {
+ add_timer_func_list(sync_ip_addresses, "sync_ip_addresses");
+ add_timer_interval(gettick() + ip_sync_interval, sync_ip_addresses, 0, 0, ip_sync_interval);
+ }
if (console) {
set_defaultconsoleparse(parse_console);
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