- 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://svn.code.sf.net/p/rathena/svn/trunk@7360 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
skotlex
2006-06-27 17:02:59 +00:00
parent 4f1911ae63
commit 6d354a4b06
10 changed files with 161 additions and 138 deletions

View File

@@ -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) {