Rewrote LAN support code. Changed configuration file name lan_support.conf to subnet_athena.conf, changed it syntax.
git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@5398 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
parent
65c4a503d8
commit
9bb0a7eedb
@ -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
|
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
|
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
|
2006/02/24
|
||||||
* Prevented guild/party recall to work on GMs of greater level than
|
* Prevented guild/party recall to work on GMs of greater level than
|
||||||
yourself. [Skotlex]
|
yourself. [Skotlex]
|
||||||
|
@ -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
|
|
6
conf-tmpl/subnet_athena.conf
Normal file
6
conf-tmpl/subnet_athena.conf
Normal file
@ -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
|
169
src/char/char.c
169
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 unknown_char_name[1024] = "Unknown";
|
||||||
char char_log_filename[1024] = "log/char.log";
|
char char_log_filename[1024] = "log/char.log";
|
||||||
char db_path[1024]="db";
|
char db_path[1024]="db";
|
||||||
//Added for lan support
|
|
||||||
char lan_map_ip[128];
|
// Advanced subnet check [LuzZza]
|
||||||
int subneti[4];
|
struct _subnet {
|
||||||
int subnetmaski[4];
|
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 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]
|
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]
|
//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);
|
return inter_mapif_init(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------
|
//--------------------------------------------
|
||||||
// Test to know if an IP come from LAN or WAN. by [Yor]
|
// Test to know if an IP come from LAN or WAN.
|
||||||
//-----------------------------------------------------
|
// Rewrote: Adnvanced subnet check [LuzZza]
|
||||||
int lan_ip_check(unsigned char *p){
|
//--------------------------------------------
|
||||||
int i;
|
int lan_subnetcheck(long *p) {
|
||||||
int lancheck = 1;
|
|
||||||
|
|
||||||
// printf("lan_ip_check: to compare: %d.%d.%d.%d, network: %d.%d.%d.%d/%d.%d.%d.%d\n",
|
int i;
|
||||||
// p[0], p[1], p[2], p[3],
|
unsigned char *sbn, *msk;
|
||||||
// subneti[0], subneti[1], subneti[2], subneti[3],
|
|
||||||
// subnetmaski[0], subnetmaski[1], subnetmaski[2], subnetmaski[3]);
|
for(i=0; i<subnet_count; i++) {
|
||||||
for(i = 0; i < 4; i++) {
|
|
||||||
if ((subneti[i] & subnetmaski[i]) != (p[i] & subnetmaski[i])) {
|
if((subnet[i].subnet & subnet[i].mask) == (*p & subnet[i].mask)) {
|
||||||
lancheck = 0;
|
|
||||||
break;
|
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 parse_char(int fd) {
|
||||||
|
|
||||||
int i, ch;
|
int i, ch;
|
||||||
unsigned short cmd;
|
unsigned short cmd;
|
||||||
char email[40];
|
char email[40];
|
||||||
int map_fd;
|
int map_fd;
|
||||||
struct char_session_data *sd;
|
struct char_session_data *sd;
|
||||||
unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr;
|
unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr;
|
||||||
|
long subnet_map_ip;
|
||||||
|
|
||||||
RFIFOHEAD(fd);
|
RFIFOHEAD(fd);
|
||||||
|
|
||||||
sd = (struct char_session_data*)session[fd]->session_data;
|
sd = (struct char_session_data*)session[fd]->session_data;
|
||||||
@ -3271,10 +3287,13 @@ int parse_char(int fd) {
|
|||||||
WFIFOL(fd,2) = cd->char_id;
|
WFIFOL(fd,2) = cd->char_id;
|
||||||
memcpy(WFIFOP(fd,6), mapindex_id2name(cd->last_point.map), MAP_NAME_LENGTH);
|
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);
|
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
|
else
|
||||||
WFIFOL(fd, 22) = server[i].ip;
|
WFIFOL(fd,22) = server[i].ip;
|
||||||
|
|
||||||
WFIFOW(fd,26) = server[i].port;
|
WFIFOW(fd,26) = server[i].port;
|
||||||
WFIFOSET(fd,28);
|
WFIFOSET(fd,28);
|
||||||
if (auth_fifo_pos >= AUTH_FIFO_SIZE)
|
if (auth_fifo_pos >= AUTH_FIFO_SIZE)
|
||||||
@ -3760,92 +3779,56 @@ int config_switch(const char *str) {
|
|||||||
return atoi(str);
|
return atoi(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------
|
//----------------------------------
|
||||||
// Reading Lan Support configuration by [Yor]
|
// Reading Lan Support configuration
|
||||||
//-------------------------------------------
|
// Rewrote: Anvanced subnet check [LuzZza]
|
||||||
int lan_config_read(const char *lancfgName) {
|
//----------------------------------
|
||||||
int j;
|
int char_lan_config_read(const char *lancfgName) {
|
||||||
struct hostent * h = NULL;
|
|
||||||
char line[1024], w1[1024], w2[1024];
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
int line_num = 0;
|
||||||
|
char line[1024], w1[64], w2[64], w3[64], w4[64], w5[64];
|
||||||
|
|
||||||
// set default configuration
|
if((fp = fopen(lancfgName, "r")) == NULL) {
|
||||||
strncpy(lan_map_ip, "127.0.0.1", sizeof(lan_map_ip));
|
ShowWarning("LAN Support configuration file is not found: %s\n", lancfgName);
|
||||||
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");
|
|
||||||
|
|
||||||
if (fp == NULL) {
|
|
||||||
ShowError("LAN support configuration file not found: %s\n", lancfgName);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShowInfo("reading configuration file %s...\n", lancfgName);
|
ShowInfo("Reading the configuration file %s...\n", lancfgName);
|
||||||
|
|
||||||
while(fgets(line, sizeof(line)-1, fp)) {
|
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;
|
continue;
|
||||||
|
|
||||||
line[sizeof(line)-1] = '\0';
|
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;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
remove_control_chars((unsigned char *)w1);
|
remove_control_chars((unsigned char *)w1);
|
||||||
remove_control_chars((unsigned char *)w2);
|
remove_control_chars((unsigned char *)w2);
|
||||||
if (strcmpi(w1, "lan_map_ip") == 0) { // Read map-server Lan IP Address
|
remove_control_chars((unsigned char *)w3);
|
||||||
h = gethostbyname(w2);
|
remove_control_chars((unsigned char *)w4);
|
||||||
if (h != NULL) {
|
remove_control_chars((unsigned char *)w5);
|
||||||
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 {
|
if(strcmpi(w1, "subnet") == 0) {
|
||||||
strncpy(lan_map_ip, w2, sizeof(lan_map_ip));
|
|
||||||
lan_map_ip[sizeof(lan_map_ip)-1] = 0;
|
subnet[subnet_count].subnet = inet_addr(w2);
|
||||||
}
|
subnet[subnet_count].mask = inet_addr(w3);
|
||||||
ShowStatus("LAN IP of map-server: %s.\n", lan_map_ip);
|
subnet[subnet_count].char_ip = inet_addr(w4);
|
||||||
} else if (strcmpi(w1, "subnet") == 0) { // Read Subnetwork
|
subnet[subnet_count].map_ip = inet_addr(w5);
|
||||||
for(j = 0; j < 4; j++)
|
|
||||||
subneti[j] = 0;
|
subnet_count++;
|
||||||
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]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ShowStatus("Information about %d subnetworks readen.\n", subnet_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
// 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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ShowInfo("done reading %s.\n", lancfgName);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4083,7 +4066,7 @@ int do_init(int argc, char **argv) {
|
|||||||
mapindex_init(); //Needed here for the start-point reading.
|
mapindex_init(); //Needed here for the start-point reading.
|
||||||
start_point.map = mapindex_name2id("new_1-1.gat");
|
start_point.map = mapindex_name2id("new_1-1.gat");
|
||||||
char_config_read((argc < 2) ? CHAR_CONF_NAME : argv[1]);
|
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) {
|
if (strcmp(userid, "s1")==0 && strcmp(passwd, "p1")==0) {
|
||||||
ShowError("Using the default user/password s1/p1 is NOT RECOMMENDED.\n");
|
ShowError("Using the default user/password s1/p1 is NOT RECOMMENDED.\n");
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
#define CHAR_CONF_NAME "conf/char_athena.conf"
|
#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
|
#define DEFAULT_AUTOSAVE_INTERVAL 300*1000
|
||||||
|
|
||||||
|
@ -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_char = 1; // loggin char or not [devil]
|
||||||
int log_inter = 1; // loggin inter or not [devil]
|
int log_inter = 1; // loggin inter or not [devil]
|
||||||
|
|
||||||
char lan_map_ip[128]; // Lan map ip added by kashy
|
// Advanced subnet check [LuzZza]
|
||||||
int subnetmaski[4]; // Subnetmask added by kashy
|
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 unknown_char_name[NAME_LENGTH] = "Unknown";
|
||||||
char db_path[1024]="db";
|
char db_path[1024]="db";
|
||||||
|
|
||||||
@ -2852,32 +2860,35 @@ int char_mapif_init(int fd) {
|
|||||||
return inter_mapif_init(fd);
|
return inter_mapif_init(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------
|
//--------------------------------------------
|
||||||
// Test to know if an IP come from LAN or WAN. by [Yor]
|
// 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(long *p) {
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
int lancheck = 1;
|
unsigned char *sbn, *msk;
|
||||||
int subneti[4];
|
|
||||||
unsigned int k0, k1, k2, k3;
|
|
||||||
|
|
||||||
sscanf(lan_map_ip, "%d.%d.%d.%d", &k0, &k1, &k2, &k3);
|
for(i=0; i<subnet_count; i++) {
|
||||||
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",
|
if((subnet[i].subnet & subnet[i].mask) == (*p & subnet[i].mask)) {
|
||||||
// p[0], p[1], p[2], p[3],
|
|
||||||
// subneti[0], subneti[1], subneti[2], subneti[3],
|
sbn = (unsigned char *)&subnet[i].subnet;
|
||||||
// subnetmaski[0], subnetmaski[1], subnetmaski[2], subnetmaski[3]);
|
msk = (unsigned char *)&subnet[i].mask;
|
||||||
for(i = 0; i < 4; i++) {
|
|
||||||
if ((subneti[i] & subnetmaski[i]) != (p[i] & subnetmaski[i])) {
|
ShowStatus("Subnet check result: "CL_CYAN"%u.%u.%u.%u/%u.%u.%u.%u"CL_RESET"\n",
|
||||||
lancheck = 0;
|
sbn[0], sbn[1], sbn[2], sbn[3], msk[0], msk[1], msk[2], msk[3]);
|
||||||
break;
|
|
||||||
|
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 parse_char(int fd) {
|
||||||
|
|
||||||
int i, ch = 0;
|
int i, ch = 0;
|
||||||
char email[40];
|
char email[40];
|
||||||
unsigned char buf[64];
|
unsigned char buf[64];
|
||||||
@ -2885,6 +2896,7 @@ int parse_char(int fd) {
|
|||||||
int map_fd;
|
int map_fd;
|
||||||
struct char_session_data *sd;
|
struct char_session_data *sd;
|
||||||
unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr;
|
unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr;
|
||||||
|
long subnet_map_ip;
|
||||||
|
|
||||||
sd = (struct char_session_data*)session[fd]->session_data;
|
sd = (struct char_session_data*)session[fd]->session_data;
|
||||||
|
|
||||||
@ -3118,11 +3130,13 @@ int parse_char(int fd) {
|
|||||||
WFIFOW(fd, 0) =0x71;
|
WFIFOW(fd, 0) =0x71;
|
||||||
WFIFOL(fd, 2) =char_dat[0].char_id;
|
WFIFOL(fd, 2) =char_dat[0].char_id;
|
||||||
memcpy(WFIFOP(fd,6), mapindex_id2name(char_dat[0].last_point.map), MAP_NAME_LENGTH);
|
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))
|
// Andvanced subnet check [LuzZza]
|
||||||
WFIFOL(fd, 22) = inet_addr(lan_map_ip);
|
if((subnet_map_ip = lan_subnetcheck((long *)p)))
|
||||||
|
WFIFOL(fd,22) = subnet_map_ip;
|
||||||
else
|
else
|
||||||
WFIFOL(fd, 22) = server[i].ip;
|
WFIFOL(fd,22) = server[i].ip;
|
||||||
|
|
||||||
WFIFOW(fd,26) = server[i].port;
|
WFIFOW(fd,26) = server[i].port;
|
||||||
WFIFOSET(fd,28);
|
WFIFOSET(fd,28);
|
||||||
if (auth_fifo_pos >= AUTH_FIFO_SIZE) {
|
if (auth_fifo_pos >= AUTH_FIFO_SIZE) {
|
||||||
@ -3669,49 +3683,56 @@ int config_switch(const char *str) {
|
|||||||
return atoi(str);
|
return atoi(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lan Support conf reading added by Kashy
|
//----------------------------------
|
||||||
int char_lan_config_read(const char *lancfgName){
|
// Reading Lan Support configuration
|
||||||
char subnetmask[128];
|
// Rewrote: Anvanced subnet check [LuzZza]
|
||||||
char line[1024], w1[1024], w2[1024];
|
//----------------------------------
|
||||||
FILE *fp;
|
int char_lan_config_read(const char *lancfgName) {
|
||||||
struct hostent * h = NULL;
|
|
||||||
|
|
||||||
if ((fp = fopen(lancfgName, "r")) == NULL) {
|
FILE *fp;
|
||||||
ShowError("file not found: %s\n", lancfgName);
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShowInfo("Reading file %s...\n", lancfgName);
|
ShowInfo("Reading the configuration file %s...\n", lancfgName);
|
||||||
|
|
||||||
while(fgets(line, sizeof(line)-1, fp)){
|
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;
|
continue;
|
||||||
|
|
||||||
if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2)
|
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;
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (strcmpi(w1, "subnetmask") == 0) {
|
remove_control_chars((unsigned char *)w1);
|
||||||
unsigned int k0, k1, k2, k3;
|
remove_control_chars((unsigned char *)w2);
|
||||||
strcpy(subnetmask, w2);
|
remove_control_chars((unsigned char *)w3);
|
||||||
sscanf(subnetmask, "%d.%d.%d.%d", &k0, &k1, &k2, &k3);
|
remove_control_chars((unsigned char *)w4);
|
||||||
subnetmaski[0] = k0; subnetmaski[1] = k1; subnetmaski[2] = k2; subnetmaski[3] = k3;
|
remove_control_chars((unsigned char *)w5);
|
||||||
ShowStatus("set subnetmask : %s\n", w2);
|
|
||||||
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
#define START_CHAR_NUM 150000
|
#define START_CHAR_NUM 150000
|
||||||
#define MAX_MAP_SERVERS 30
|
#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
|
#define DEFAULT_AUTOSAVE_INTERVAL 300*1000
|
||||||
|
|
||||||
|
@ -58,9 +58,16 @@ int new_account_flag = 0;
|
|||||||
int bind_ip_set_ = 0;
|
int bind_ip_set_ = 0;
|
||||||
char bind_ip_str[128];
|
char bind_ip_str[128];
|
||||||
int login_port = 6900;
|
int login_port = 6900;
|
||||||
char lan_char_ip[16];
|
|
||||||
int subneti[4];
|
// Advanced subnet check [LuzZza]
|
||||||
int subnetmaski[4];
|
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 account_filename[1024] = "save/account.txt";
|
||||||
char GM_account_filename[1024] = "conf/GM_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.
|
// 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",
|
int i;
|
||||||
// p[0], p[1], p[2], p[3],
|
char *sbn, *msk;
|
||||||
// subneti[0], subneti[1], subneti[2], subneti[3],
|
|
||||||
// subnetmaski[0], subnetmaski[1], subnetmaski[2], subnetmaski[3]);
|
for(i=0; i<subnet_count; i++) {
|
||||||
for(i = 0; i < 4; i++) {
|
|
||||||
if ((subneti[i] & subnetmaski[i]) != (p[i] & subnetmaski[i])) {
|
printf("%ld - %ld - %ld", subnet[i].subnet, subnet[i].mask, (long)p);
|
||||||
lancheck = 0;
|
if((subnet[i].subnet & subnet[i].mask) == ((long)p & subnet[i].mask)) {
|
||||||
break;
|
|
||||||
|
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)
|
// Default packet parsing (normal players or administation/char-server connexion requests)
|
||||||
//----------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------
|
||||||
int parse_login(int fd) {
|
int parse_login(int fd) {
|
||||||
|
|
||||||
struct mmo_account account;
|
struct mmo_account account;
|
||||||
int result, j;
|
int result, j;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr;
|
unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr;
|
||||||
char ip[16];
|
char ip[16];
|
||||||
|
long subnet_char_ip;
|
||||||
|
|
||||||
RFIFOHEAD(fd);
|
RFIFOHEAD(fd);
|
||||||
|
|
||||||
sprintf(ip, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
|
sprintf(ip, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
|
||||||
@ -3089,11 +3106,12 @@ int parse_login(int fd) {
|
|||||||
else
|
else
|
||||||
ShowInfo("Connection of the account '%s' accepted.\n", account.userid);
|
ShowInfo("Connection of the account '%s' accepted.\n", account.userid);
|
||||||
server_num = 0;
|
server_num = 0;
|
||||||
WFIFOHEAD(fd, 47+32*MAX_SERVERS);
|
WFIFOHEAD(fd, 47+32*MAX_SERVERS);
|
||||||
for(i = 0; i < MAX_SERVERS; i++) {
|
for(i = 0; i < MAX_SERVERS; i++) {
|
||||||
if (server_fd[i] >= 0) {
|
if (server_fd[i] >= 0) {
|
||||||
if (lan_ip_check(p))
|
// Andvanced subnet check [LuzZza]
|
||||||
WFIFOL(fd,47+server_num*32) = inet_addr(lan_char_ip);
|
if((subnet_char_ip = lan_subnetcheck(p)))
|
||||||
|
WFIFOL(fd,47+server_num*32) = subnet_char_ip;
|
||||||
else
|
else
|
||||||
WFIFOL(fd,47+server_num*32) = server[i].ip;
|
WFIFOL(fd,47+server_num*32) = server[i].ip;
|
||||||
WFIFOW(fd,47+server_num*32+4) = server[i].port;
|
WFIFOW(fd,47+server_num*32+4) = server[i].port;
|
||||||
@ -3443,25 +3461,14 @@ int config_switch(const char *str) {
|
|||||||
|
|
||||||
//----------------------------------
|
//----------------------------------
|
||||||
// Reading Lan Support configuration
|
// Reading Lan Support configuration
|
||||||
|
// Rewrote: Anvanced subnet check [LuzZza]
|
||||||
//----------------------------------
|
//----------------------------------
|
||||||
int login_lan_config_read(const char *lancfgName) {
|
int login_lan_config_read(const char *lancfgName) {
|
||||||
int j;
|
|
||||||
struct hostent * h = NULL;
|
|
||||||
char line[1024], w1[1024], w2[1024];
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
char line[1024], w1[64], w2[64], w3[64], w4[64], w5[64];
|
||||||
|
|
||||||
// set default configuration
|
if((fp = fopen(lancfgName, "r")) == NULL) {
|
||||||
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");
|
|
||||||
|
|
||||||
if (fp == NULL) {
|
|
||||||
ShowWarning("LAN Support configuration file is not found: %s\n", lancfgName);
|
ShowWarning("LAN Support configuration file is not found: %s\n", lancfgName);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -3469,73 +3476,37 @@ int login_lan_config_read(const char *lancfgName) {
|
|||||||
ShowInfo("Reading the configuration file %s...\n", lancfgName);
|
ShowInfo("Reading the configuration file %s...\n", lancfgName);
|
||||||
|
|
||||||
while(fgets(line, sizeof(line)-1, fp)) {
|
while(fgets(line, sizeof(line)-1, fp)) {
|
||||||
|
|
||||||
if (line[0] == '/' && line[1] == '/')
|
if (line[0] == '/' && line[1] == '/')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
line[sizeof(line)-1] = '\0';
|
line[sizeof(line)-1] = '\0';
|
||||||
memset(w2, 0, sizeof(w2));
|
if(sscanf(line,"%[^:]: %[^/]/%[^:]:%[^:]:%[^\r\n]", w1, w2, w3, w4, w5) != 5) {
|
||||||
if (sscanf(line,"%[^:]: %[^\r\n]", w1, w2) != 2)
|
|
||||||
|
ShowWarning("Error syntax of configuration file %s. Line skipped.\n", lancfgName);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
remove_control_chars((unsigned char *)w1);
|
remove_control_chars((unsigned char *)w1);
|
||||||
remove_control_chars((unsigned char *)w2);
|
remove_control_chars((unsigned char *)w2);
|
||||||
if (strcmpi(w1, "lan_char_ip") == 0) { // Read Char-Server Lan IP Address
|
remove_control_chars((unsigned char *)w3);
|
||||||
memset(lan_char_ip, 0, sizeof(lan_char_ip));
|
remove_control_chars((unsigned char *)w4);
|
||||||
h = gethostbyname(w2);
|
remove_control_chars((unsigned char *)w5);
|
||||||
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]);
|
if(strcmpi(w1, "subnet") == 0) {
|
||||||
} else {
|
|
||||||
strncpy(lan_char_ip, w2, sizeof(lan_char_ip));
|
subnet[subnet_count].subnet = inet_addr(w2);
|
||||||
lan_char_ip[sizeof(lan_char_ip)-1] = '\0';
|
subnet[subnet_count].mask = inet_addr(w3);
|
||||||
}
|
subnet[subnet_count].char_ip = inet_addr(w4);
|
||||||
ShowStatus("LAN IP of char-server: %s.\n", lan_char_ip);
|
subnet[subnet_count].map_ip = inet_addr(w5);
|
||||||
} else if (strcmpi(w1, "subnet") == 0) { // Read Subnetwork
|
|
||||||
for(j = 0; j < 4; j++)
|
subnet_count++;
|
||||||
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]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ShowStatus("Information about %d subnetworks readen.\n", subnet_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ShowInfo("Finished reading %s.\n", lancfgName);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#define MAX_SERVERS 30
|
#define MAX_SERVERS 30
|
||||||
|
|
||||||
#define LOGIN_CONF_NAME "conf/login_athena.conf"
|
#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.
|
#define PASSWORDENC 3 // A definition is given when making an encryption password correspond.
|
||||||
// It is 1 at the time of passwordencrypt.
|
// It is 1 at the time of passwordencrypt.
|
||||||
// It is made into 2 at the time of passwordencrypt2.
|
// It is made into 2 at the time of passwordencrypt2.
|
||||||
|
@ -69,8 +69,16 @@ int new_account_flag = 0; //Set from config too XD [Sirius]
|
|||||||
int bind_ip_set_ = 0;
|
int bind_ip_set_ = 0;
|
||||||
char bind_ip_str[128];
|
char bind_ip_str[128];
|
||||||
int login_port = 6900;
|
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];
|
struct mmo_char_server server[MAX_SERVERS];
|
||||||
int server_fd[MAX_SERVERS];
|
int server_fd[MAX_SERVERS];
|
||||||
@ -1345,23 +1353,31 @@ int parse_fromchar(int fd){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Lan ip check added by Kashy
|
//--------------------------------------------
|
||||||
int lan_ip_check(unsigned char *p) {
|
// Test to know if an IP come from LAN or WAN.
|
||||||
int y;
|
// Rewrote: Adnvanced subnet check [LuzZza]
|
||||||
int lancheck = 1;
|
//--------------------------------------------
|
||||||
int lancharip[4];
|
int lan_subnetcheck(long *p) {
|
||||||
|
|
||||||
unsigned int k0, k1, k2, k3;
|
int i;
|
||||||
sscanf(lan_char_ip, "%d.%d.%d.%d", &k0, &k1, &k2, &k3);
|
unsigned char *sbn, *msk;
|
||||||
lancharip[0] = k0; lancharip[1] = k1; lancharip[2] = k2; lancharip[3] = k3;
|
|
||||||
|
|
||||||
for(y = 0; y < 4; y++) {
|
for(i=0; i<subnet_count; i++) {
|
||||||
if ((lancharip[y] & subnetmaski[y])!= (p[y]))
|
|
||||||
lancheck = 0;
|
|
||||||
break; }
|
|
||||||
|
|
||||||
ShowInfo("LAN check: "CL_CYAN"%s"CL_RESET".\n", (lancheck) ? "LAN" : "WAN");
|
if((subnet[i].subnet & subnet[i].mask) == (*p & subnet[i].mask)) {
|
||||||
return lancheck;
|
|
||||||
|
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];
|
char t_uid[100];
|
||||||
//int sql_fields, sql_cnt;
|
//int sql_fields, sql_cnt;
|
||||||
struct mmo_account account;
|
struct mmo_account account;
|
||||||
|
long subnet_char_ip;
|
||||||
|
|
||||||
int result, i;
|
int result, i;
|
||||||
unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr;
|
unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr;
|
||||||
@ -1494,11 +1511,11 @@ int parse_login(int fd) {
|
|||||||
server_num=0;
|
server_num=0;
|
||||||
for(i = 0; i < MAX_SERVERS; i++) {
|
for(i = 0; i < MAX_SERVERS; i++) {
|
||||||
if (server_fd[i] >= 0) {
|
if (server_fd[i] >= 0) {
|
||||||
//Lan check added by Kashy
|
// Andvanced subnet check [LuzZza]
|
||||||
if (lan_ip_check(p))
|
if((subnet_char_ip = lan_subnetcheck((long *)p)))
|
||||||
WFIFOL(fd,47+server_num*32) = inet_addr(lan_char_ip);
|
WFIFOL(fd,47+server_num*32) = subnet_char_ip;
|
||||||
else
|
else
|
||||||
WFIFOL(fd,47+server_num*32) = server[i].ip;
|
WFIFOL(fd,47+server_num*32) = server[i].ip;
|
||||||
WFIFOW(fd,47+server_num*32+4) = server[i].port;
|
WFIFOW(fd,47+server_num*32+4) = server[i].port;
|
||||||
memcpy(WFIFOP(fd,47+server_num*32+6), server[i].name, 20);
|
memcpy(WFIFOP(fd,47+server_num*32+6), server[i].name, 20);
|
||||||
WFIFOW(fd,47+server_num*32+26) = server[i].users;
|
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){
|
// Reading Lan Support configuration
|
||||||
int i;
|
// Rewrote: Anvanced subnet check [LuzZza]
|
||||||
char subnetmask[128];
|
//----------------------------------
|
||||||
char line[1024], w1[1024], w2[1024];
|
int login_lan_config_read(const char *lancfgName) {
|
||||||
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
int line_num = 0;
|
||||||
|
char line[1024], w1[64], w2[64], w3[64], w4[64], w5[64];
|
||||||
|
|
||||||
fp=fopen(lancfgName, "r");
|
if((fp = fopen(lancfgName, "r")) == NULL) {
|
||||||
|
ShowWarning("LAN Support configuration file is not found: %s\n", lancfgName);
|
||||||
if (fp == NULL) {
|
|
||||||
ShowError("file not found: %s\n", lancfgName);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
ShowInfo("reading configuration file %s...\n", lancfgName);
|
|
||||||
while(fgets(line, sizeof(line)-1, fp)){
|
ShowInfo("Reading the configuration file %s...\n", lancfgName);
|
||||||
if (line[0] == '/' && line[1] == '/')
|
|
||||||
|
while(fgets(line, sizeof(line)-1, fp)) {
|
||||||
|
|
||||||
|
line_num++;
|
||||||
|
if ((line[0] == '/' && line[1] == '/') || line[0] == '\n' || line[1] == '\n')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
i = sscanf(line,"%[^:]: %[^\r\n]",w1,w2);
|
line[sizeof(line)-1] = '\0';
|
||||||
if(i!=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;
|
continue;
|
||||||
|
|
||||||
else if(strcmpi(w1,"lan_char_ip")==0){
|
|
||||||
strcpy(lan_char_ip, w2);
|
|
||||||
ShowStatus("set Lan_Char_IP : %s\n",w2);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
{
|
remove_control_chars((unsigned char *)w1);
|
||||||
unsigned int a0, a1, a2, a3;
|
remove_control_chars((unsigned char *)w2);
|
||||||
unsigned char p[4];
|
remove_control_chars((unsigned char *)w3);
|
||||||
sscanf(lan_char_ip, "%d.%d.%d.%d", &a0, &a1, &a2, &a3);
|
remove_control_chars((unsigned char *)w4);
|
||||||
p[0] = a0; p[1] = a1; p[2] = a2; p[3] = a3;
|
remove_control_chars((unsigned char *)w5);
|
||||||
ShowInfo("LAN test of LAN IP of the char-server:\n");
|
|
||||||
if (lan_ip_check(p) == 0) {
|
if(strcmpi(w1, "subnet") == 0) {
|
||||||
ShowError(CL_RED" LAN IP of the char-server doesn't belong to the specified Sub-network"CL_RESET"\n");
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
ShowInfo("Finished reading %s.\n",lancfgName);
|
fclose(fp);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#define LOGIN_CONF_NAME "conf/login_athena.conf"
|
#define LOGIN_CONF_NAME "conf/login_athena.conf"
|
||||||
#define SQL_CONF_NAME "conf/inter_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
|
#ifndef SQL_DEBUG
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user