diff options
-rw-r--r-- | Changelog-Trunk.txt | 4 | ||||
-rw-r--r-- | conf-tmpl/lan_support.conf | 41 | ||||
-rw-r--r-- | conf-tmpl/subnet_athena.conf | 6 | ||||
-rw-r--r-- | src/char/char.c | 169 | ||||
-rw-r--r-- | src/char/char.h | 2 | ||||
-rw-r--r-- | src/char_sql/char.c | 133 | ||||
-rw-r--r-- | src/char_sql/char.h | 2 | ||||
-rw-r--r-- | src/login/login.c | 149 | ||||
-rw-r--r-- | src/login/login.h | 2 | ||||
-rw-r--r-- | src/login_sql/login.c | 140 | ||||
-rw-r--r-- | src/login_sql/login.h | 2 |
11 files changed, 304 insertions, 346 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt index b80338cba..e8c658999 100644 --- a/Changelog-Trunk.txt +++ b/Changelog-Trunk.txt @@ -4,7 +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. EVERYTHING ELSE
GOES INTO TRUNK AND WILL BE MERGED INTO STABLE BY VALARIS AND WIZPUTER. -- VALARIS
-
+2006/02/28
+ * Rewrote LAN support code. Changed configuration file name
+ lan_support.conf to subnet_athena.conf, changed it syntax. [LuzZza]
2006/02/24
* Prevented guild/party recall to work on GMs of greater level than
yourself. [Skotlex]
diff --git a/conf-tmpl/lan_support.conf b/conf-tmpl/lan_support.conf deleted file mode 100644 index 0f078352f..000000000 --- a/conf-tmpl/lan_support.conf +++ /dev/null @@ -1,41 +0,0 @@ -// Athena TXT version LAN configure file.
-// Support Client Connect to Local Area Network (LAN) IP Address Server.
-// put this fle into conf/ directory
-//
-// HOWTO:
-// To use this file, the login-server, char-server and map-server must be on the same subnetwork
-// (not necessary on the same computer). You can not use eAthena if you want to install the servers on 2 or more different LAN.
-//
-// First of all: you must configure your router to forward your WAN IP (one or more) and port (default: 6900, 6121 and 5121)
-// to the right concerned computer(s) (if default port, forward 6900 port to the (LAN IP) login-server, 6121 port to the (LAN IP) char-server, etc.).
-// After, set in char_athena.conf and map_athena.conf files the WAN IP and the right ports that you use.
-// Give to WAN people (client that are not on your LAN) your WAN IP to have an access to your server.
-// At this point, all players outside your LAN can access to your server(s).
-//
-// Now, you must parameter your LAN for the servers.
-// Set the LAN IP of the char-server and the map-server in this file (lan_char_ip and lan_map_ip).
-// Set the definition of your LAN in this file (subnet and subnetmask).
-// When you load/start login-server and char-server, read what the server displays, and specially the section ---LAN CONFIGURATION---.
-// If you see a warning or something not good, correct it.
-// Now LAN client can access to your server.
-//
-// NB: if you want that nobody of your LAN can access to your server, put 127.0.0.1 in IP and 255.255.255.255 for the mask.
-// So only the localhost computer would access to your server.
-// NB2: you can use LAN name if you have some instead of IP and/or mask.
-// NB3: if you want set your server only for LAN people, set your LAN IP instead of the WAN IP, and set 127.0.0.1/255.255.255.255 for the LAN IP.
-//
-// HOW THAT WORKS:
-// When someone tries to connect to your server(s), the login-server/char-server checks its IP with the LAN subnet (subnet and subnetmask parameters).
-// If it matches, the login-server sends the LAN IP of the char-server (lan_char_ip); and char-server do same for map-server (lan_map_ip).
-// If not, the login-server sends the WAN IP of the char-server that it have received (char_ip in char_athena.conf)
-// and the char-server sends the WAN IP of the map-server that it have received (map_ip in map_athena.conf)
-
-// put here the LAN IP of your char-server
-lan_char_ip: 127.0.0.1
-
-// put here the LAN IP of your map-server
-lan_map_ip: 127.0.0.1
-
-// put here the Subnet mask of your LAN
-subnet: 127.0.0.1
-subnetmask: 255.255.255.255
diff --git a/conf-tmpl/subnet_athena.conf b/conf-tmpl/subnet_athena.conf new file mode 100644 index 000000000..39855d991 --- /dev/null +++ b/conf-tmpl/subnet_athena.conf @@ -0,0 +1,6 @@ +// Subnet support file
+// Format is:
+// subnet: subnet/mask:char_ip:map_ip
+// you can add more than one that line
+
+subnet: 127.0.0.1/255.255.255.0:127.0.0.1:127.0.0.1
diff --git a/src/char/char.c b/src/char/char.c index 1cedc568c..d1c145077 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -75,10 +75,17 @@ 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";
-//Added for lan support
-char lan_map_ip[128];
-int subneti[4];
-int subnetmaski[4];
+
+// Advanced subnet check [LuzZza]
+struct _subnet {
+ long subnet;
+ long mask;
+ long char_ip;
+ long map_ip;
+} subnet[16];
+
+int subnet_count = 0;
+
int name_ignoring_case = 0; // Allow or not identical name for characters but with a different case by [Yor]
int char_name_option = 0; // Option to know which letters/symbols are authorised in the name of a character (0: all, 1: only those in char_name_letters, 2: all EXCEPT those in char_name_letters) by [Yor]
//The following are characters that are trimmed regardless because they cause confusion and problems on the servers. [Skotlex]
@@ -3003,34 +3010,43 @@ static int char_mapif_init(int fd) { return inter_mapif_init(fd);
}
-//-----------------------------------------------------
-// Test to know if an IP come from LAN or WAN. by [Yor]
-//-----------------------------------------------------
-int lan_ip_check(unsigned char *p){
+//--------------------------------------------
+// Test to know if an IP come from LAN or WAN.
+// Rewrote: Adnvanced subnet check [LuzZza]
+//--------------------------------------------
+int lan_subnetcheck(long *p) {
+
int i;
- int lancheck = 1;
-
-// printf("lan_ip_check: to compare: %d.%d.%d.%d, network: %d.%d.%d.%d/%d.%d.%d.%d\n",
-// p[0], p[1], p[2], p[3],
-// subneti[0], subneti[1], subneti[2], subneti[3],
-// subnetmaski[0], subnetmaski[1], subnetmaski[2], subnetmaski[3]);
- for(i = 0; i < 4; i++) {
- if ((subneti[i] & subnetmaski[i]) != (p[i] & subnetmaski[i])) {
- lancheck = 0;
- break;
+ unsigned char *sbn, *msk;
+
+ for(i=0; i<subnet_count; i++) {
+
+ if((subnet[i].subnet & subnet[i].mask) == (*p & subnet[i].mask)) {
+
+ sbn = (unsigned char *)&subnet[i].subnet;
+ msk = (unsigned char *)&subnet[i].mask;
+
+ ShowStatus("Subnet check result: "CL_CYAN"%u.%u.%u.%u/%u.%u.%u.%u"CL_RESET"\n",
+ sbn[0], sbn[1], sbn[2], sbn[3], msk[0], msk[1], msk[2], msk[3]);
+
+ return subnet[i].map_ip;
}
}
- ShowInfo("LAN test (result): %s source"CL_RESET".\n", (lancheck) ? CL_CYAN"LAN" : CL_GREEN"WAN");
- return lancheck;
+
+ ShowStatus("Subnet check result: "CL_CYAN"no matches."CL_RESET"\n");
+ return 0;
}
int parse_char(int fd) {
+
int i, ch;
unsigned short cmd;
char email[40];
int map_fd;
struct char_session_data *sd;
unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr;
+ long subnet_map_ip;
+
RFIFOHEAD(fd);
sd = (struct char_session_data*)session[fd]->session_data;
@@ -3271,10 +3287,13 @@ int parse_char(int fd) { WFIFOL(fd,2) = cd->char_id;
memcpy(WFIFOP(fd,6), mapindex_id2name(cd->last_point.map), MAP_NAME_LENGTH);
ShowInfo("Character selection '%s' (account: %d, slot: %d).\n", cd->name, sd->account_id, ch);
- if (lan_ip_check(p))
- WFIFOL(fd, 22) = inet_addr(lan_map_ip);
+
+ // Andvanced subnet check [LuzZza]
+ if((subnet_map_ip = lan_subnetcheck((long *)p)))
+ WFIFOL(fd,22) = subnet_map_ip;
else
- WFIFOL(fd, 22) = server[i].ip;
+ WFIFOL(fd,22) = server[i].ip;
+
WFIFOW(fd,26) = server[i].port;
WFIFOSET(fd,28);
if (auth_fifo_pos >= AUTH_FIFO_SIZE)
@@ -3760,92 +3779,56 @@ int config_switch(const char *str) { return atoi(str);
}
-//-------------------------------------------
-// Reading Lan Support configuration by [Yor]
-//-------------------------------------------
-int lan_config_read(const char *lancfgName) {
- int j;
- struct hostent * h = NULL;
- char line[1024], w1[1024], w2[1024];
- FILE *fp;
-
- // set default configuration
- strncpy(lan_map_ip, "127.0.0.1", sizeof(lan_map_ip));
- subneti[0] = 127;
- subneti[1] = 0;
- subneti[2] = 0;
- subneti[3] = 1;
- for(j = 0; j < 4; j++)
- subnetmaski[j] = 255;
+//----------------------------------
+// Reading Lan Support configuration
+// Rewrote: Anvanced subnet check [LuzZza]
+//----------------------------------
+int char_lan_config_read(const char *lancfgName) {
- fp = fopen(lancfgName, "r");
-
- if (fp == NULL) {
- ShowError("LAN support configuration file not found: %s\n", lancfgName);
+ FILE *fp;
+ int line_num = 0;
+ char line[1024], w1[64], w2[64], w3[64], w4[64], w5[64];
+
+ if((fp = fopen(lancfgName, "r")) == NULL) {
+ ShowWarning("LAN Support configuration file is not found: %s\n", lancfgName);
return 1;
}
- ShowInfo("reading configuration file %s...\n", lancfgName);
+ ShowInfo("Reading the configuration file %s...\n", lancfgName);
while(fgets(line, sizeof(line)-1, fp)) {
- if (line[0] == '/' && line[1] == '/')
+
+ line_num++;
+ if ((line[0] == '/' && line[1] == '/') || line[0] == '\n' || line[1] == '\n')
continue;
line[sizeof(line)-1] = '\0';
- if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2)
+ if(sscanf(line,"%[^:]: %[^/]/%[^:]:%[^:]:%[^\r\n]", w1, w2, w3, w4, w5) != 5) {
+
+ ShowWarning("Error syntax of configuration file %s in line %d.\n", lancfgName, line_num);
continue;
+ }
remove_control_chars((unsigned char *)w1);
remove_control_chars((unsigned char *)w2);
- if (strcmpi(w1, "lan_map_ip") == 0) { // Read map-server Lan IP Address
- h = gethostbyname(w2);
- if (h != NULL) {
- sprintf(lan_map_ip, "%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]);
- } else {
- strncpy(lan_map_ip, w2, sizeof(lan_map_ip));
- lan_map_ip[sizeof(lan_map_ip)-1] = 0;
- }
- ShowStatus("LAN IP of map-server: %s.\n", lan_map_ip);
- } else if (strcmpi(w1, "subnet") == 0) { // Read Subnetwork
- for(j = 0; j < 4; j++)
- subneti[j] = 0;
- h = gethostbyname(w2);
- if (h != NULL) {
- for(j = 0; j < 4; j++)
- subneti[j] = (unsigned char)h->h_addr[j];
- } else {
- sscanf(w2, "%d.%d.%d.%d", &subneti[0], &subneti[1], &subneti[2], &subneti[3]);
- }
- ShowStatus("Sub-network of the map-server: %d.%d.%d.%d.\n", subneti[0], subneti[1], subneti[2], subneti[3]);
- } else if (strcmpi(w1, "subnetmask") == 0){ // Read Subnetwork Mask
- for(j = 0; j < 4; j++)
- subnetmaski[j] = 255;
- h = gethostbyname(w2);
- if (h != NULL) {
- for(j = 0; j < 4; j++)
- subnetmaski[j] = (unsigned char)h->h_addr[j];
- } else {
- sscanf(w2, "%d.%d.%d.%d", &subnetmaski[0], &subnetmaski[1], &subnetmaski[2], &subnetmaski[3]);
- }
- ShowStatus("Sub-network mask of the map-server: %d.%d.%d.%d.\n", subnetmaski[0], subnetmaski[1], subnetmaski[2], subnetmaski[3]);
- }
- }
- fclose(fp);
+ remove_control_chars((unsigned char *)w3);
+ remove_control_chars((unsigned char *)w4);
+ remove_control_chars((unsigned char *)w5);
- // sub-network check of the map-server
- {
- unsigned int a0, a1, a2, a3;
- unsigned char p[4];
- sscanf(lan_map_ip, "%d.%d.%d.%d", &a0, &a1, &a2, &a3);
- p[0] = a0; p[1] = a1; p[2] = a2; p[3] = a3;
- ShowInfo("LAN test of LAN IP of the map-server...\n");
- if (lan_ip_check(p) == 0) {
- ShowError(CL_RED" LAN IP of the map-server doesn't belong to the specified Sub-network."CL_RESET"\n");
+ if(strcmpi(w1, "subnet") == 0) {
+
+ subnet[subnet_count].subnet = inet_addr(w2);
+ subnet[subnet_count].mask = inet_addr(w3);
+ subnet[subnet_count].char_ip = inet_addr(w4);
+ subnet[subnet_count].map_ip = inet_addr(w5);
+
+ subnet_count++;
}
- }
- ShowInfo("done reading %s.\n", lancfgName);
+ ShowStatus("Information about %d subnetworks readen.\n", subnet_count);
+ }
+ fclose(fp);
return 0;
}
@@ -4083,7 +4066,7 @@ int do_init(int argc, char **argv) { mapindex_init(); //Needed here for the start-point reading.
start_point.map = mapindex_name2id("new_1-1.gat");
char_config_read((argc < 2) ? CHAR_CONF_NAME : argv[1]);
- lan_config_read((argc > 1) ? argv[1] : LOGIN_LAN_CONF_NAME);
+ char_lan_config_read((argc > 1) ? argv[1] : LOGIN_LAN_CONF_NAME);
if (strcmp(userid, "s1")==0 && strcmp(passwd, "p1")==0) {
ShowError("Using the default user/password s1/p1 is NOT RECOMMENDED.\n");
diff --git a/src/char/char.h b/src/char/char.h index 743890c68..bd2a786e6 100644 --- a/src/char/char.h +++ b/src/char/char.h @@ -12,7 +12,7 @@ #define CHAR_CONF_NAME "conf/char_athena.conf"
-#define LOGIN_LAN_CONF_NAME "conf/lan_support.conf"
+#define LOGIN_LAN_CONF_NAME "conf/subnet_athena.conf"
#define DEFAULT_AUTOSAVE_INTERVAL 300*1000
diff --git a/src/char_sql/char.c b/src/char_sql/char.c index 0faf23e0a..f28ba008e 100644 --- a/src/char_sql/char.c +++ b/src/char_sql/char.c @@ -102,8 +102,16 @@ 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 lan_map_ip[128]; // Lan map ip added by kashy
-int subnetmaski[4]; // Subnetmask added by kashy
+// Advanced subnet check [LuzZza]
+struct _subnet {
+ long subnet;
+ long mask;
+ long char_ip;
+ long map_ip;
+} subnet[16];
+
+int subnet_count = 0;
+
char unknown_char_name[NAME_LENGTH] = "Unknown";
char db_path[1024]="db";
@@ -2852,32 +2860,35 @@ int char_mapif_init(int fd) { return inter_mapif_init(fd);
}
-//-----------------------------------------------------
-// Test to know if an IP come from LAN or WAN. by [Yor]
-//-----------------------------------------------------
-int lan_ip_check(unsigned char *p){
+//--------------------------------------------
+// Test to know if an IP come from LAN or WAN.
+// Rewrote: Adnvanced subnet check [LuzZza]
+//--------------------------------------------
+int lan_subnetcheck(long *p) {
+
int i;
- int lancheck = 1;
- int subneti[4];
- unsigned int k0, k1, k2, k3;
-
- sscanf(lan_map_ip, "%d.%d.%d.%d", &k0, &k1, &k2, &k3);
- subneti[0] = k0; subneti[1] = k1; subneti[2] = k2; subneti[3] = k3;
-
-// printf("lan_ip_check: to compare: %d.%d.%d.%d, network: %d.%d.%d.%d/%d.%d.%d.%d\n",
-// p[0], p[1], p[2], p[3],
-// subneti[0], subneti[1], subneti[2], subneti[3],
-// subnetmaski[0], subnetmaski[1], subnetmaski[2], subnetmaski[3]);
- for(i = 0; i < 4; i++) {
- if ((subneti[i] & subnetmaski[i]) != (p[i] & subnetmaski[i])) {
- lancheck = 0;
- break;
+ unsigned char *sbn, *msk;
+
+ for(i=0; i<subnet_count; i++) {
+
+ if((subnet[i].subnet & subnet[i].mask) == (*p & subnet[i].mask)) {
+
+ sbn = (unsigned char *)&subnet[i].subnet;
+ msk = (unsigned char *)&subnet[i].mask;
+
+ ShowStatus("Subnet check result: "CL_CYAN"%u.%u.%u.%u/%u.%u.%u.%u"CL_RESET"\n",
+ sbn[0], sbn[1], sbn[2], sbn[3], msk[0], msk[1], msk[2], msk[3]);
+
+ return subnet[i].char_ip;
}
}
- return lancheck;
+
+ ShowStatus("Subnet check result: "CL_CYAN"no matches."CL_RESET"\n");
+ return 0;
}
int parse_char(int fd) {
+
int i, ch = 0;
char email[40];
unsigned char buf[64];
@@ -2885,6 +2896,7 @@ int parse_char(int fd) { int map_fd;
struct char_session_data *sd;
unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr;
+ long subnet_map_ip;
sd = (struct char_session_data*)session[fd]->session_data;
@@ -3118,11 +3130,13 @@ int parse_char(int fd) { WFIFOW(fd, 0) =0x71;
WFIFOL(fd, 2) =char_dat[0].char_id;
memcpy(WFIFOP(fd,6), mapindex_id2name(char_dat[0].last_point.map), MAP_NAME_LENGTH);
- //Lan check added by Kashy
- if (lan_ip_check(p))
- WFIFOL(fd, 22) = inet_addr(lan_map_ip);
+
+ // Andvanced subnet check [LuzZza]
+ if((subnet_map_ip = lan_subnetcheck((long *)p)))
+ WFIFOL(fd,22) = subnet_map_ip;
else
- WFIFOL(fd, 22) = server[i].ip;
+ WFIFOL(fd,22) = server[i].ip;
+
WFIFOW(fd,26) = server[i].port;
WFIFOSET(fd,28);
if (auth_fifo_pos >= AUTH_FIFO_SIZE) {
@@ -3669,49 +3683,56 @@ int config_switch(const char *str) { return atoi(str);
}
-// Lan Support conf reading added by Kashy
-int char_lan_config_read(const char *lancfgName){
- char subnetmask[128];
- char line[1024], w1[1024], w2[1024];
- FILE *fp;
- struct hostent * h = NULL;
+//----------------------------------
+// Reading Lan Support configuration
+// Rewrote: Anvanced subnet check [LuzZza]
+//----------------------------------
+int char_lan_config_read(const char *lancfgName) {
- if ((fp = fopen(lancfgName, "r")) == NULL) {
- ShowError("file not found: %s\n", lancfgName);
+ FILE *fp;
+ int line_num = 0;
+ char line[1024], w1[64], w2[64], w3[64], w4[64], w5[64];
+
+ if((fp = fopen(lancfgName, "r")) == NULL) {
+ ShowWarning("LAN Support configuration file is not found: %s\n", lancfgName);
return 1;
}
- ShowInfo("Reading file %s...\n", lancfgName);
+ ShowInfo("Reading the configuration file %s...\n", lancfgName);
- while(fgets(line, sizeof(line)-1, fp)){
- if (line[0] == '/' && line[1] == '/')
- continue;
+ while(fgets(line, sizeof(line)-1, fp)) {
- if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2)
+ line_num++;
+ if ((line[0] == '/' && line[1] == '/') || line[0] == '\n' || line[1] == '\n')
continue;
- else if (strcmpi(w1, "lan_map_ip") == 0) {
- h = gethostbyname(w2);
- if (h != NULL) {
- sprintf(lan_map_ip, "%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]);
- } else {
- strncpy(lan_map_ip, w2, sizeof(lan_map_ip));
- lan_map_ip[sizeof(lan_map_ip)-1] = 0;
- }
- ShowStatus("set Lan_map_IP : %s\n", lan_map_ip);
+ line[sizeof(line)-1] = '\0';
+ if(sscanf(line,"%[^:]: %[^/]/%[^:]:%[^:]:%[^\r\n]", w1, w2, w3, w4, w5) != 5) {
+
+ ShowWarning("Error syntax of configuration file %s in line %d.\n", lancfgName, line_num);
+ continue;
}
- else if (strcmpi(w1, "subnetmask") == 0) {
- unsigned int k0, k1, k2, k3;
- strcpy(subnetmask, w2);
- sscanf(subnetmask, "%d.%d.%d.%d", &k0, &k1, &k2, &k3);
- subnetmaski[0] = k0; subnetmaski[1] = k1; subnetmaski[2] = k2; subnetmaski[3] = k3;
- ShowStatus("set subnetmask : %s\n", w2);
+ remove_control_chars((unsigned char *)w1);
+ remove_control_chars((unsigned char *)w2);
+ remove_control_chars((unsigned char *)w3);
+ remove_control_chars((unsigned char *)w4);
+ remove_control_chars((unsigned char *)w5);
+
+ if(strcmpi(w1, "subnet") == 0) {
+
+ subnet[subnet_count].subnet = inet_addr(w2);
+ subnet[subnet_count].mask = inet_addr(w3);
+ subnet[subnet_count].char_ip = inet_addr(w4);
+ subnet[subnet_count].map_ip = inet_addr(w5);
+
+ subnet_count++;
}
+
+ ShowStatus("Information about %d subnetworks readen.\n", subnet_count);
}
- fclose(fp);
- ShowInfo("Done reading %s.\n", lancfgName);
+ fclose(fp);
return 0;
}
diff --git a/src/char_sql/char.h b/src/char_sql/char.h index db1a0ca95..53550dcd3 100644 --- a/src/char_sql/char.h +++ b/src/char_sql/char.h @@ -15,7 +15,7 @@ #define START_CHAR_NUM 150000
#define MAX_MAP_SERVERS 30
-#define LAN_CONF_NAME "conf/lan_support.conf"
+#define LAN_CONF_NAME "conf/subnet_athena.conf"
#define DEFAULT_AUTOSAVE_INTERVAL 300*1000
diff --git a/src/login/login.c b/src/login/login.c index f24e16499..4f405449b 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -58,9 +58,16 @@ int new_account_flag = 0; int bind_ip_set_ = 0;
char bind_ip_str[128];
int login_port = 6900;
-char lan_char_ip[16];
-int subneti[4];
-int subnetmaski[4];
+
+// Advanced subnet check [LuzZza]
+struct _subnet {
+ long subnet;
+ long mask;
+ long char_ip;
+ long map_ip;
+} subnet[16];
+
+int subnet_count = 0;
char account_filename[1024] = "save/account.txt";
char GM_account_filename[1024] = "conf/GM_account.txt";
@@ -2972,34 +2979,44 @@ int parse_admin(int fd) { //--------------------------------------------
// Test to know if an IP come from LAN or WAN.
+// Rewrote: Adnvanced subnet check [LuzZza]
//--------------------------------------------
-int lan_ip_check(unsigned char *p) {
+int lan_subnetcheck(unsigned char *p) {
+
int i;
- int lancheck = 1;
-
-// printf("lan_ip_check: to compare: %d.%d.%d.%d, network: %d.%d.%d.%d/%d.%d.%d.%d\n",
-// p[0], p[1], p[2], p[3],
-// subneti[0], subneti[1], subneti[2], subneti[3],
-// subnetmaski[0], subnetmaski[1], subnetmaski[2], subnetmaski[3]);
- for(i = 0; i < 4; i++) {
- if ((subneti[i] & subnetmaski[i]) != (p[i] & subnetmaski[i])) {
- lancheck = 0;
- break;
+ char *sbn, *msk;
+
+ for(i=0; i<subnet_count; i++) {
+
+ printf("%ld - %ld - %ld", subnet[i].subnet, subnet[i].mask, (long)p);
+ if((subnet[i].subnet & subnet[i].mask) == ((long)p & subnet[i].mask)) {
+
+ sbn = (char *)&subnet[i].subnet;
+ msk = (char *)&subnet[i].mask;
+
+ ShowMessage("Subnet check result: "CL_CYAN"%d.%d.%d.%d/%d.%d.%d.%d"CL_RESET"\n",
+ sbn[0], sbn[1], sbn[2], sbn[3], msk[0], msk[1], msk[2], msk[3]);
+
+ return subnet[i].char_ip;
}
}
- ShowMessage("LAN test (result): "CL_CYAN"%s source"CL_RESET".\n", (lancheck) ? "LAN" : "WAN");
- return lancheck;
+
+ ShowMessage("Subnet check result: "CL_CYAN"no matches."CL_RESET"\n");
+ return 0;
}
//----------------------------------------------------------------------------------------
// Default packet parsing (normal players or administation/char-server connexion requests)
//----------------------------------------------------------------------------------------
int parse_login(int fd) {
+
struct mmo_account account;
int result, j;
unsigned int i;
unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr;
char ip[16];
+ long subnet_char_ip;
+
RFIFOHEAD(fd);
sprintf(ip, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
@@ -3089,11 +3106,12 @@ int parse_login(int fd) { else
ShowInfo("Connection of the account '%s' accepted.\n", account.userid);
server_num = 0;
- WFIFOHEAD(fd, 47+32*MAX_SERVERS);
+ WFIFOHEAD(fd, 47+32*MAX_SERVERS);
for(i = 0; i < MAX_SERVERS; i++) {
if (server_fd[i] >= 0) {
- if (lan_ip_check(p))
- WFIFOL(fd,47+server_num*32) = inet_addr(lan_char_ip);
+ // Andvanced subnet check [LuzZza]
+ if((subnet_char_ip = lan_subnetcheck(p)))
+ WFIFOL(fd,47+server_num*32) = subnet_char_ip;
else
WFIFOL(fd,47+server_num*32) = server[i].ip;
WFIFOW(fd,47+server_num*32+4) = server[i].port;
@@ -3443,25 +3461,14 @@ int config_switch(const char *str) { //----------------------------------
// Reading Lan Support configuration
+// Rewrote: Anvanced subnet check [LuzZza]
//----------------------------------
int login_lan_config_read(const char *lancfgName) {
- int j;
- struct hostent * h = NULL;
- char line[1024], w1[1024], w2[1024];
- FILE *fp;
- // set default configuration
- strncpy(lan_char_ip, "127.0.0.1", sizeof(lan_char_ip));
- subneti[0] = 127;
- subneti[1] = 0;
- subneti[2] = 0;
- subneti[3] = 1;
- for(j = 0; j < 4; j++)
- subnetmaski[j] = 255;
-
- fp = fopen(lancfgName, "r");
+ FILE *fp;
+ char line[1024], w1[64], w2[64], w3[64], w4[64], w5[64];
- if (fp == NULL) {
+ if((fp = fopen(lancfgName, "r")) == NULL) {
ShowWarning("LAN Support configuration file is not found: %s\n", lancfgName);
return 1;
}
@@ -3469,73 +3476,37 @@ int login_lan_config_read(const char *lancfgName) { ShowInfo("Reading the configuration file %s...\n", lancfgName);
while(fgets(line, sizeof(line)-1, fp)) {
+
if (line[0] == '/' && line[1] == '/')
continue;
line[sizeof(line)-1] = '\0';
- memset(w2, 0, sizeof(w2));
- if (sscanf(line,"%[^:]: %[^\r\n]", w1, w2) != 2)
+ if(sscanf(line,"%[^:]: %[^/]/%[^:]:%[^:]:%[^\r\n]", w1, w2, w3, w4, w5) != 5) {
+
+ ShowWarning("Error syntax of configuration file %s. Line skipped.\n", lancfgName);
continue;
+ }
remove_control_chars((unsigned char *)w1);
remove_control_chars((unsigned char *)w2);
- if (strcmpi(w1, "lan_char_ip") == 0) { // Read Char-Server Lan IP Address
- memset(lan_char_ip, 0, sizeof(lan_char_ip));
- h = gethostbyname(w2);
- if (h != NULL) {
- sprintf(lan_char_ip, "%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]);
- } else {
- strncpy(lan_char_ip, w2, sizeof(lan_char_ip));
- lan_char_ip[sizeof(lan_char_ip)-1] = '\0';
- }
- ShowStatus("LAN IP of char-server: %s.\n", lan_char_ip);
- } else if (strcmpi(w1, "subnet") == 0) { // Read Subnetwork
- for(j = 0; j < 4; j++)
- subneti[j] = 0;
- h = gethostbyname(w2);
- if (h != NULL) {
- for(j = 0; j < 4; j++)
- subneti[j] = (unsigned char)h->h_addr[j];
- } else {
- sscanf(w2, "%d.%d.%d.%d", &subneti[0], &subneti[1], &subneti[2], &subneti[3]);
- }
- ShowStatus("Sub-network of the char-server: %d.%d.%d.%d.\n", subneti[0], subneti[1], subneti[2], subneti[3]);
- } else if (strcmpi(w1, "subnetmask") == 0) { // Read Subnetwork Mask
- for(j = 0; j < 4; j++)
- subnetmaski[j] = 255;
- h = gethostbyname(w2);
- if (h != NULL) {
- for(j = 0; j < 4; j++)
- subnetmaski[j] = (unsigned char)h->h_addr[j];
- } else {
- sscanf(w2, "%d.%d.%d.%d", &subnetmaski[0], &subnetmaski[1], &subnetmaski[2], &subnetmaski[3]);
- }
- ShowStatus("Sub-network mask of the char-server: %d.%d.%d.%d.\n", subnetmaski[0], subnetmaski[1], subnetmaski[2], subnetmaski[3]);
- }
- }
- fclose(fp);
+ remove_control_chars((unsigned char *)w3);
+ remove_control_chars((unsigned char *)w4);
+ remove_control_chars((unsigned char *)w5);
- // log the LAN configuration
- login_log("The LAN configuration of the server is set:" RETCODE);
- login_log("- with LAN IP of char-server: %s." RETCODE, lan_char_ip);
- login_log("- with the sub-network of the char-server: %d.%d.%d.%d/%d.%d.%d.%d." RETCODE,
- subneti[0], subneti[1], subneti[2], subneti[3], subnetmaski[0], subnetmaski[1], subnetmaski[2], subnetmaski[3]);
-
- // sub-network check of the char-server
- {
- unsigned int a0, a1, a2, a3;
- unsigned char p[4];
- sscanf(lan_char_ip, "%d.%d.%d.%d", &a0, &a1, &a2, &a3);
- p[0] = a0; p[1] = a1; p[2] = a2; p[3] = a3;
- ShowInfo("LAN test of LAN IP of the char-server: ");
- if (lan_ip_check(p) == 0) {
- ShowError(CL_RED" LAN IP of the char-server doesn't belong to the specified Sub-network"CL_RESET"\n");
- login_log("***ERROR: LAN IP of the char-server doesn't belong to the specified Sub-network." RETCODE);
+ if(strcmpi(w1, "subnet") == 0) {
+
+ subnet[subnet_count].subnet = inet_addr(w2);
+ subnet[subnet_count].mask = inet_addr(w3);
+ subnet[subnet_count].char_ip = inet_addr(w4);
+ subnet[subnet_count].map_ip = inet_addr(w5);
+
+ subnet_count++;
}
- }
- ShowInfo("Finished reading %s.\n", lancfgName);
+ ShowStatus("Information about %d subnetworks readen.\n", subnet_count);
+ }
+ fclose(fp);
return 0;
}
diff --git a/src/login/login.h b/src/login/login.h index 119a91595..98f397605 100644 --- a/src/login/login.h +++ b/src/login/login.h @@ -7,7 +7,7 @@ #define MAX_SERVERS 30
#define LOGIN_CONF_NAME "conf/login_athena.conf"
-#define LAN_CONF_NAME "conf/lan_support.conf"
+#define LAN_CONF_NAME "conf/subnet_athena.conf"
#define PASSWORDENC 3 // A definition is given when making an encryption password correspond.
// It is 1 at the time of passwordencrypt.
// It is made into 2 at the time of passwordencrypt2.
diff --git a/src/login_sql/login.c b/src/login_sql/login.c index 9bbad06dc..72188dc57 100644 --- a/src/login_sql/login.c +++ b/src/login_sql/login.c @@ -69,8 +69,16 @@ int new_account_flag = 0; //Set from config too XD [Sirius] int bind_ip_set_ = 0;
char bind_ip_str[128];
int login_port = 6900;
-char lan_char_ip[128]; // Lan char ip added by kashy
-int subnetmaski[4]; // Subnetmask added by kashy
+
+// Advanced subnet check [LuzZza]
+struct _subnet {
+ long subnet;
+ long mask;
+ long char_ip;
+ long map_ip;
+} subnet[16];
+
+int subnet_count = 0;
struct mmo_char_server server[MAX_SERVERS];
int server_fd[MAX_SERVERS];
@@ -1345,23 +1353,31 @@ int parse_fromchar(int fd){ return 0;
}
-//Lan ip check added by Kashy
-int lan_ip_check(unsigned char *p) {
- int y;
- int lancheck = 1;
- int lancharip[4];
-
- unsigned int k0, k1, k2, k3;
- sscanf(lan_char_ip, "%d.%d.%d.%d", &k0, &k1, &k2, &k3);
- lancharip[0] = k0; lancharip[1] = k1; lancharip[2] = k2; lancharip[3] = k3;
+//--------------------------------------------
+// Test to know if an IP come from LAN or WAN.
+// Rewrote: Adnvanced subnet check [LuzZza]
+//--------------------------------------------
+int lan_subnetcheck(long *p) {
- for(y = 0; y < 4; y++) {
- if ((lancharip[y] & subnetmaski[y])!= (p[y]))
- lancheck = 0;
- break; }
-
- ShowInfo("LAN check: "CL_CYAN"%s"CL_RESET".\n", (lancheck) ? "LAN" : "WAN");
- return lancheck;
+ int i;
+ unsigned char *sbn, *msk;
+
+ for(i=0; i<subnet_count; i++) {
+
+ if((subnet[i].subnet & subnet[i].mask) == (*p & subnet[i].mask)) {
+
+ sbn = (unsigned char *)&subnet[i].subnet;
+ msk = (unsigned char *)&subnet[i].mask;
+
+ ShowStatus("Subnet check result: "CL_CYAN"%u.%u.%u.%u/%u.%u.%u.%u"CL_RESET"\n",
+ sbn[0], sbn[1], sbn[2], sbn[3], msk[0], msk[1], msk[2], msk[3]);
+
+ return subnet[i].char_ip;
+ }
+ }
+
+ ShowStatus("Subnet check result: "CL_CYAN"no matches."CL_RESET"\n");
+ return 0;
}
//----------------------------------------------------------------------------------------
@@ -1376,6 +1392,7 @@ int parse_login(int fd) { char t_uid[100];
//int sql_fields, sql_cnt;
struct mmo_account account;
+ long subnet_char_ip;
int result, i;
unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr;
@@ -1494,11 +1511,11 @@ int parse_login(int fd) { server_num=0;
for(i = 0; i < MAX_SERVERS; i++) {
if (server_fd[i] >= 0) {
- //Lan check added by Kashy
- if (lan_ip_check(p))
- WFIFOL(fd,47+server_num*32) = inet_addr(lan_char_ip);
- else
- WFIFOL(fd,47+server_num*32) = server[i].ip;
+ // Andvanced subnet check [LuzZza]
+ if((subnet_char_ip = lan_subnetcheck((long *)p)))
+ WFIFOL(fd,47+server_num*32) = subnet_char_ip;
+ else
+ WFIFOL(fd,47+server_num*32) = server[i].ip;
WFIFOW(fd,47+server_num*32+4) = server[i].port;
memcpy(WFIFOP(fd,47+server_num*32+6), server[i].name, 20);
WFIFOW(fd,47+server_num*32+26) = server[i].users;
@@ -1871,57 +1888,56 @@ int config_switch(const char *str) { }
-//Lan Support conf reading added by Kashy
-int login_lan_config_read(const char *lancfgName){
- int i;
- char subnetmask[128];
- char line[1024], w1[1024], w2[1024];
- FILE *fp;
-
- fp=fopen(lancfgName, "r");
+//----------------------------------
+// Reading Lan Support configuration
+// Rewrote: Anvanced subnet check [LuzZza]
+//----------------------------------
+int login_lan_config_read(const char *lancfgName) {
- if (fp == NULL) {
- ShowError("file not found: %s\n", lancfgName);
+ FILE *fp;
+ int line_num = 0;
+ char line[1024], w1[64], w2[64], w3[64], w4[64], w5[64];
+
+ if((fp = fopen(lancfgName, "r")) == NULL) {
+ ShowWarning("LAN Support configuration file is not found: %s\n", lancfgName);
return 1;
}
- ShowInfo("reading configuration file %s...\n", lancfgName);
- while(fgets(line, sizeof(line)-1, fp)){
- if (line[0] == '/' && line[1] == '/')
- continue;
- i = sscanf(line,"%[^:]: %[^\r\n]",w1,w2);
- if(i!=2)
- continue;
+ ShowInfo("Reading the configuration file %s...\n", lancfgName);
- else if(strcmpi(w1,"lan_char_ip")==0){
- strcpy(lan_char_ip, w2);
- ShowStatus("set Lan_Char_IP : %s\n",w2);
- }
+ while(fgets(line, sizeof(line)-1, fp)) {
- else if(strcmpi(w1,"subnetmask")==0){
- unsigned int k0, k1, k2, k3;
+ line_num++;
+ if ((line[0] == '/' && line[1] == '/') || line[0] == '\n' || line[1] == '\n')
+ continue;
- strcpy(subnetmask, w2);
- sscanf(subnetmask, "%d.%d.%d.%d", &k0, &k1, &k2, &k3);
- subnetmaski[0] = k0; subnetmaski[1] = k1; subnetmaski[2] = k2; subnetmaski[3] = k3;
- ShowStatus("set subnetmask : %s\n",w2);
- }
+ line[sizeof(line)-1] = '\0';
+ if(sscanf(line,"%[^:]: %[^/]/%[^:]:%[^:]:%[^\r\n]", w1, w2, w3, w4, w5) != 5) {
+
+ ShowWarning("Error syntax of configuration file %s in line %d.\n", lancfgName, line_num);
+ continue;
}
- fclose(fp);
- {
- unsigned int a0, a1, a2, a3;
- unsigned char p[4];
- sscanf(lan_char_ip, "%d.%d.%d.%d", &a0, &a1, &a2, &a3);
- p[0] = a0; p[1] = a1; p[2] = a2; p[3] = a3;
- ShowInfo("LAN test of LAN IP of the char-server:\n");
- if (lan_ip_check(p) == 0) {
- ShowError(CL_RED" LAN IP of the char-server doesn't belong to the specified Sub-network"CL_RESET"\n");
+ remove_control_chars((unsigned char *)w1);
+ remove_control_chars((unsigned char *)w2);
+ remove_control_chars((unsigned char *)w3);
+ remove_control_chars((unsigned char *)w4);
+ remove_control_chars((unsigned char *)w5);
+
+ if(strcmpi(w1, "subnet") == 0) {
+
+ subnet[subnet_count].subnet = inet_addr(w2);
+ subnet[subnet_count].mask = inet_addr(w3);
+ subnet[subnet_count].char_ip = inet_addr(w4);
+ subnet[subnet_count].map_ip = inet_addr(w5);
+
+ subnet_count++;
}
- }
- ShowInfo("Finished reading %s.\n",lancfgName);
+ ShowStatus("Information about %d subnetworks readen.\n", subnet_count);
+ }
+ fclose(fp);
return 0;
}
diff --git a/src/login_sql/login.h b/src/login_sql/login.h index c031b26bf..b1f6ee263 100644 --- a/src/login_sql/login.h +++ b/src/login_sql/login.h @@ -8,7 +8,7 @@ #define LOGIN_CONF_NAME "conf/login_athena.conf"
#define SQL_CONF_NAME "conf/inter_athena.conf"
-#define LAN_CONF_NAME "conf/lan_support.conf"
+#define LAN_CONF_NAME "conf/subnet_athena.conf"
#ifndef SQL_DEBUG
|