diff options
author | Lance <Lance@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-06-21 10:55:26 +0000 |
---|---|---|
committer | Lance <Lance@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-06-21 10:55:26 +0000 |
commit | bc03dcf3609194073da5fdf8e2e267a90f64cc48 (patch) | |
tree | e77c36250e9986b6b939bd875a0772db89d05df6 /src | |
parent | 3c585c70f62a60068cca56be027a4f02b958a787 (diff) | |
download | hercules-bc03dcf3609194073da5fdf8e2e267a90f64cc48.tar.gz hercules-bc03dcf3609194073da5fdf8e2e267a90f64cc48.tar.bz2 hercules-bc03dcf3609194073da5fdf8e2e267a90f64cc48.tar.xz hercules-bc03dcf3609194073da5fdf8e2e267a90f64cc48.zip |
* [Added]:
- DNS (WAN) sync for those pesky disconnections (dynamic ip renewal).
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@7275 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src')
-rw-r--r-- | src/char/char.c | 35 | ||||
-rw-r--r-- | src/char_sql/char.c | 38 | ||||
-rw-r--r-- | src/login/login.c | 26 | ||||
-rw-r--r-- | src/login_sql/login.c | 26 | ||||
-rw-r--r-- | src/map/atcommand.c | 2 | ||||
-rw-r--r-- | src/map/chrif.c | 17 | ||||
-rw-r--r-- | src/map/map.c | 6 | ||||
-rw-r--r-- | src/map/map.h | 1 |
8 files changed, 149 insertions, 2 deletions
diff --git a/src/char/char.c b/src/char/char.c index 527a68ac6..e0e6415fb 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -75,6 +75,7 @@ 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 {
@@ -1797,6 +1798,7 @@ static int char_delete(struct mmo_charstatus *cs) { int parse_tologin(int fd) {
int i;
struct char_session_data *sd;
+ struct hostent *h;
RFIFOHEAD(fd);
// only login-server can have an access to here.
@@ -2293,6 +2295,25 @@ int parse_tologin(int fd) { RFIFOSKIP(fd,6);
}
break;
+ case 0x2735:
+ ShowInfo("IP Sync in progress...\n");
+ h = char_server_dns?gethostbyname(char_server_dns):NULL;
+ if(h){
+ 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];
+ 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:
ShowWarning("Unknown packet 0x%04x received from login-server, disconnecting.\n", RFIFOW(fd,0));
session[fd]->eof = 1;
@@ -3055,6 +3076,15 @@ int parse_frommap(int fd) { RFIFOSKIP(fd, RFIFOW(fd, 2));
break;
}
+ case 0x2736:
+ for(i = 0; i < MAX_MAP_SERVERS; i++){
+ if(server_fd[i] == fd){
+ ShowInfo("IP Sync (Server #%d) successful.\n",i);
+ server[i].ip = RFIFOL(fd, 2);
+ }
+ }
+ RFIFOSKIP(fd,6);
+ break;
default:
// inter serverɓn
{
@@ -3967,6 +3997,10 @@ int char_config_read(const char *cfgName) { } else if (strcmpi(w1, "login_ip") == 0) {
login_ip_set_ = 1;
h = gethostbyname(w2);
+ if(char_server_dns)
+ aFree(char_server_dns);
+ char_server_dns = (char *)aCalloc(strlen(w2)+1, 1);
+ strcpy(char_server_dns, w2);
if (h != NULL) {
ShowStatus("Login server IP address : %s -> %d.%d.%d.%d\n", w2, (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
sprintf(login_ip_str, "%d.%d.%d.%d", (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
@@ -4137,6 +4171,7 @@ 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 0b7ea6464..51f40b498 100644 --- a/src/char_sql/char.c +++ b/src/char_sql/char.c @@ -104,6 +104,8 @@ 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;
@@ -1782,6 +1784,7 @@ int mmo_char_send006b(int fd, struct char_session_data *sd) { int parse_tologin(int fd) {
int i;
struct char_session_data *sd;
+ struct hostent *h;
// only login-server can have an access to here.
// so, if it isn't the login-server, we disconnect the session.
@@ -2178,6 +2181,26 @@ int parse_tologin(int fd) { }
break;
+ case 0x2735:
+ ShowInfo("IP Sync in progress...\n");
+ h = char_server_dns?gethostbyname(char_server_dns):NULL;
+ if(h){
+ 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];
+ 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:
ShowError("Unknown packet 0x%04x from login server, disconnecting.\n", RFIFOW(fd, 0));
session[fd]->eof = 1;
@@ -2971,6 +2994,16 @@ 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) successful.\n",i);
+ server[i].ip = RFIFOL(fd, 2);
+ }
+ }
+ RFIFOSKIP(fd,6);
+ break;
+
default:
// inter server - packet
{
@@ -3928,6 +3961,8 @@ 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);
@@ -4071,6 +4106,9 @@ int char_config_read(const char *cfgName) { } else if (strcmpi(w1, "login_ip") == 0) {
login_ip_set_ = 1;
h = gethostbyname (w2);
+ if(char_server_dns)
+ aFree(char_server_dns);
+ char_server_dns = (char *)aCalloc(strlen(w2)+1, 1);
if (h != NULL) {
ShowStatus("Login server IP address : %s -> %d.%d.%d.%d\n", w2, (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
sprintf(login_ip_str, "%d.%d.%d.%d", (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
diff --git a/src/login/login.c b/src/login/login.c index 0cd9b5b9b..949b1d80c 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -262,6 +262,18 @@ int waiting_disconnect_timer(int tid, unsigned int tick, int id, int data) return 0;
}
+static int sync_ip_addresses(int tid, unsigned int tick, int id, int data){
+ int i;
+ 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);
+ }
+ }
+ return 0;
+}
+
//----------------------------------------------------------------------
// Determine if an account (id) is a GM account
// and returns its level (or 0 if it isn't a GM account or if not found)
@@ -1958,6 +1970,16 @@ 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) successful.\n",i);
+ server[i].ip = RFIFOL(fd,2);
+ }
+ }
+ RFIFOSKIP(fd,6);
+ break;
+
case 0x3000: //change sex for chrif_changesex()
if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2))
return 0;
@@ -4166,6 +4188,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(console) {
set_defaultconsoleparse(parse_console);
start_console();
diff --git a/src/login_sql/login.c b/src/login_sql/login.c index f6365e0f2..14c71722c 100644 --- a/src/login_sql/login.c +++ b/src/login_sql/login.c @@ -210,6 +210,18 @@ int waiting_disconnect_timer(int tid, unsigned int tick, int id, int data) return 0;
}
+static int sync_ip_addresses(int tid, unsigned int tick, int id, int data){
+ int i;
+ 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);
+ }
+ }
+ return 0;
+}
+
//-----------------------------------------------------
// Read GM accounts
//-----------------------------------------------------
@@ -1403,6 +1415,16 @@ int parse_fromchar(int fd){ mysql_free_result(sql_res);
}
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) successful.\n",i);
+ server[i].ip = RFIFOL(fd,2);
+ }
+ }
+ RFIFOSKIP(fd,6);
+ break;
default:
ShowError("login: unknown packet %x! (from char).\n", RFIFOW(fd,0));
session[fd]->eof = 1;
@@ -2348,6 +2370,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 (console) {
set_defaultconsoleparse(parse_console);
start_console();
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 189b54f71..13e2ccee5 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -15,6 +15,7 @@ #include "../common/core.h"
#include "../common/showmsg.h"
+#include "atcommand.h"
#include "log.h"
#include "clif.h"
#include "chrif.h"
@@ -29,7 +30,6 @@ #include "battle.h"
#include "party.h"
#include "guild.h"
-#include "atcommand.h"
#include "script.h"
#include "npc.h"
#include "trade.h"
diff --git a/src/map/chrif.c b/src/map/chrif.c index 70dad71ab..485cffbf4 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -38,13 +38,14 @@ //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
6,-1,18, 7,-1,49,30,10, // 2b00-2b07: U->2b00, U->2b01, U->2b02, U->2b03, U->2b04, U->2b05, U->2b06, U->2b07
6,30,-1,10,86, 7,44,34, // 2b08-2b0f: U->2b08, U->2b09, U->2b0a, U->2b0b, U->2b0c, U->2b0d, U->2b0e, U->2b0f
0,-1,10, 6,11,-1, 0, 0, // 2b10-2b17: U->2b10, U->2b11, U->2b12, U->2b13, U->2b14, U->2b15, U->2b16, U->2b17
- -1,-1,-1,-1,-1,-1,-1, 7, // 2b18-2b1f: U->2b18, U->2b19, U->2b1a, U->2b1b, U->2b1c, U->2b1d, F->2b1e, U->2b1f
+ -1,-1,-1,-1,-1,-1,2, 7, // 2b18-2b1f: U->2b18, U->2b19, U->2b1a, U->2b1b, U->2b1c, U->2b1d, F->2b1e, U->2b1f
-1,-1,-1,-1,-1,-1,-1,-1, // 2b20-2b27: U->2b20, F->2b21, F->2b22, F->2b23, F->2b24, F->2b25, F->2b26, F->2b27
};
@@ -1413,6 +1414,19 @@ int chrif_disconnect(int fd) { return 0;
}
+void chrif_update_ip(int fd){
+ struct hostent *h = map_server_dns?gethostbyname(map_server_dns):NULL;
+ ShowInfo("IP Sync in progress...\n");
+ if(h){
+ 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];
+ WFIFOSET(fd, 6);
+ }
+}
+
/*==========================================
*
*------------------------------------------
@@ -1476,6 +1490,7 @@ int chrif_parse(int fd) case 0x2b15: chrif_recvgmaccounts(fd); break;
case 0x2b1b: chrif_recvfamelist(fd); break;
case 0x2b1d: chrif_load_scdata(fd); break;
+ case 0x2b1e: chrif_update_ip(fd); break;
case 0x2b1f: chrif_disconnectplayer(fd); break;
case 0x2b20: chrif_removemap(fd); break; //Remove maps of a server [Sirius]
diff --git a/src/map/map.c b/src/map/map.c index 70b9d290e..569c32f26 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -3297,6 +3297,10 @@ int map_config_read(char *cfgName) { } else if (strcmpi(w1, "map_ip") == 0) { map_ip_set_ = 1; h = gethostbyname (w2); + if(map_server_dns) + aFree(map_server_dns); + map_server_dns = aCalloc(strlen(w2)+1,1); + strcpy(map_server_dns, w2); if (h != NULL) { ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%d.%d.%d.%d"CL_RESET"'.\n", w2, (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]); sprintf(w2, "%d.%d.%d.%d", (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]); @@ -3709,6 +3713,8 @@ 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 diff --git a/src/map/map.h b/src/map/map.h index 6babe9883..a67a977cc 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -1354,6 +1354,7 @@ extern char *GRF_PATH_FILENAME; extern int charsave_method; //needed ..
+extern char *map_server_dns;
#ifndef TXT_ONLY
|