From 925b181de6d2c6a1ae3a1ed11d806bfe5785379c Mon Sep 17 00:00:00 2001 From: LuzZza Date: Tue, 28 Feb 2006 00:41:00 +0000 Subject: Rewrote LAN support code. Changed configuration file name lan_support.conf to subnet_athena.conf, changed it syntax. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@5398 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/char/char.c | 169 +++++++++++++++++++++++--------------------------- src/char/char.h | 2 +- src/char_sql/char.c | 133 ++++++++++++++++++++++----------------- src/char_sql/char.h | 2 +- src/login/login.c | 149 ++++++++++++++++++-------------------------- src/login/login.h | 2 +- src/login_sql/login.c | 140 +++++++++++++++++++++++------------------ src/login_sql/login.h | 2 +- 8 files changed, 295 insertions(+), 304 deletions(-) (limited to 'src') 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; iclient_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; iclient_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; iclient_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; iclient_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 -- cgit v1.2.3-70-g09d2