Sfoglia il codice sorgente

committing my work on the login server (mostly SQL)
- removed the check_ip_flag from login&char (there since r1)
- removed the CMP_AUTHFIFO_IP and CMP_AUTHFIFO_LOGIN2 defines (also r1)
- removed dynamic_account_ban, gm_db settings, weren't doing anything at all
- modified the date_format setting to take the format string directly
- removed overly verbose config loading messages
- removed/simplified many more useless actions
- renamed the dynamic_pass_failure_ban_ settings to make more sense
- collected relevant config settings into a login_config structure and documented their purpose
- allowed usage of yes/no instead of the user-unfriendly 1/0 method in config settings (and added 1/0 as a possible option)
- fixed dnsbl which was always taking only the first entry into account

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@10021 54d463be-8e91-2dee-dedb-b68131a5f0ec

ultramage 18 anni fa
parent
commit
2a7f5aeb7f

+ 14 - 0
Changelog-Trunk.txt

@@ -3,6 +3,20 @@ Date	Added
 AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK.
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 
+2007/03/17
+	* committing my work on the login server (mostly SQL) [ultramage]
+	- removed the check_ip_flag from login&char (there since r1)
+	- removed the CMP_AUTHFIFO_IP and CMP_AUTHFIFO_LOGIN2 defines (also r1)
+	- removed dynamic_account_ban, gm_db settings, weren't doing anything at all
+	- modified the date_format setting to take the format string directly
+	- removed overly verbose config loading messages
+	- removed/simplified many more useless actions
+	- renamed the dynamic_pass_failure_ban_ settings to make more sense
+	- collected relevant config settings into a login_config structure
+	  and documented their purpose
+	- allowed usage of yes/no instead of the user-unfriendly 1/0 method
+	  in config settings (and added 1/0 as a possible option)
+	- fixed dnsbl which was always taking only the first entry into account
 2007/03/16
 	* Corrected the structure and added info on the skill fail packet (0x110).
 	* Added packet 0x223 as clif_upgrademessage (not used yet).

+ 5 - 1
conf-tmpl/Changelog.txt

@@ -1,13 +1,17 @@
 Date	Added
 
 2007/03/17
+	* Cleaned up the login & char config [ultramage]
+	- removed check_ip_flag
+	- changed date_format to input the format string directly
+	- changed many settings to allow yes/no instead of just 1/0
 	* Removed .gat from configs [Lupus]
 2007/03/14
 	* Changed the default of debuff_on_logout to 1 since food items shouldn't
 	  dispell on logout. [Skotlex]
 2007/03/08
 	* Adjustments for the new mapcache [DracoRPG]
-	- Removed "" from map names in maps_athena.conf
+	- Removed ".gat" from map names in maps_athena.conf
 	- Removed read_map_from_cache option as there's no more choice to do
 	- Removed afm_dir option as there's no more need for AFM/AF2 support
 2007/03/06

+ 0 - 8
conf-tmpl/char_athena.conf

@@ -100,14 +100,6 @@ online_check: yes
 // Minimum GM level that is allowed to bypass the server limit of users.
 gm_allow_level: 99
 
-// It's to check IP of a player between char-server and other servers (part of anti-hacking system)
-// If player doesn't have same IP, connection is refused.
-// Set to 0/off/no to not check IP of player.
-// Set to 1/on/yes if you want to check (default)
-// Note: if you enable this option, be sure that your (local/lan/wan) players use correct ip (in xml file) to contact servers,
-//       and that your LAN is correctly configured (!), and that LAN configuration of eathena is right.
-check_ip_flag: yes
-
 // How often should the server save all files? (In seconds)
 // Note: Applies to all data files on TXT servers.
 // On SQL servers, it applies to guilds (character save interval is defined on the map config)

+ 23 - 37
conf-tmpl/login_athena.conf

@@ -54,7 +54,7 @@ ladminallowip: all
 // This prevents usage of >& log.file
 console: off
 
-// Are login's case sensitive (SQL only)?
+// Are logins case sensitive? (SQL only)
 case_sensitive: on
 
 // Gamemaster password, used with the @gm command to obtain GM commands (level of gm set with level_new_gm parameter).
@@ -70,11 +70,10 @@ gm_pass: gm
 // - and normal player must give correct password when he use the @gm command
 level_new_gm: 60
 
-// Can you make new accounts on the server? (1 for Yes, 0 for no) 
-// (1 = _M/_F enabled, 0 = not enabled)
-new_account: 1
+// Can you use _M/_F to make new accounts on the server?
+new_account: yes
 
-// ********** account registration flood system **********
+// Account registration flood protection system
 // allowed_regs is the number of registrations allowed in time_allowed (in seconds)
 allowed_regs: 1
 time_allowed: 10
@@ -94,7 +93,7 @@ login_log_filename: log/login.log
 
 // To log the login server?
 // NOTE: The login-sql server needs the login logs to enable dynamic pass failure bans.
-log_login: 1
+log_login: yes
 
 // Name of the file of that logs the unknown packets (for debug or hack check)
 login_log_unknown_packets_filename: log/login_unknown_packets.log
@@ -124,11 +123,7 @@ display_parse_admin: 0
 display_parse_fromchar: 0
 
 // Indicate how to display date in logs, to players, etc.
-// 0: 31-12-2004 23:59:59
-// 1: 12-31-2004 23:59:59
-// 2: 2004-31-12 23:59:59
-// 3: 2004-12-31 23:59:59 (default)
-date_format: 3
+date_format: %Y-%m-%d %H:%M:%S
 
 // Indicate the minimum GM level of player that the server accepts to connection.
 // 0: all players (normal player are 0. it's default), 1-99: GM level at least with level x
@@ -144,14 +139,7 @@ add_to_unlimited_account: off
 // 0 or more: new accounts was created by addition of the value (in sec) to the actual time (to set first limited time)
 start_limited_time: -1
 
-// It's to check IP of a player between login-server and char-server (part of anti-hacking system)
-// If player doesn't have same IP, connection is refused.
-// Set to 0/off/no to not check IP of player.
-// Set to 1/on/yes if you want to check (default)
-// Note: if you enable this option, be sure that your (local/lan/wan) players use correct ip (in xml file) to contact servers,
-//       and that your LAN is correctly configured (!), and that LAN configuration of eathena is right.
-//       if not correct, you can read list of char-servers, but not look slots of characters (rejected by server).
-check_ip_flag: yes
+// Ipban features (TXT only):
 
 // Specify order of IP control if necessary (option: 'deny,allow', 'allow,deny', or 'mutual-failture')
 // (how to use 'allow' and 'deny' information)
@@ -169,32 +157,30 @@ check_ip_flag: yes
 //deny: 123.123.123.123
 //deny: 234.234.234.234
 
-//Check The clientversion set in the clientinfo ?
+// Check The clientversion set in the clientinfo ?
 check_client_version: no
 
-//What version we would allow to connect? (if the options above is enabled..)
+// What version we would allow to connect? (if the options above is enabled..)
 client_version_to_connect: 20
 
-//Passwords in Login DB are MD5 - <passwordencrypt> cannot b used on client with this on
+// Passwords in Login DB are MD5 - <passwordencrypt> cannot b used on client with this on
 use_MD5_passwords: no
 
-//Ban features: read readme for more info if you dont know this.
-ipban: 1
-dynamic_pass_failure_ban: 1
-dynamic_pass_failure_ban_time: 5
-dynamic_pass_failure_ban_how_many: 7
-dynamic_pass_failure_ban_how_long: 5
-dynamic_account_ban: 1
-dynamic_account_ban_class: 0
-
-//Interval (in minutes) to execute a DNS/IP update. Disabled by default.
-//Enable it if your server uses a dynamic IP which changes with time.
-//ip_sync_interval: 10
+// Ipban features (SQL only)
+ipban: yes
+dynamic_pass_failure_ban: yes
+dynamic_pass_failure_ban_interval: 5
+dynamic_pass_failure_ban_limit: 7
+dynamic_pass_failure_ban_duration: 5
 
-//DNS Blacklist Blocking (on: 1, off: 0)
-use_dnsbl: 0
+// Interval (in minutes) to execute a DNS/IP update. Disabled by default.
+// Enable it if your server uses a dynamic IP which changes with time.
+//ip_sync_interval: 10
 
-//DNS Servers (seperated by a comma)
+// DNS Blacklist Blocking
+// If enabled, each incoming connection will be tested against the blacklists
+// on the specified dnsbl_servers (comma-separated list)
+use_dnsbl: no
 dnsbl_servers: dnsbl.deltaanime.net
 
 import: conf/import/login_conf.txt

+ 0 - 24
httpd/index.html

@@ -1,24 +0,0 @@
-<html><head><title>Athena http server</title></head><body>
-
-<h1>Athena http server</h1>
-
-<p>Welcome to Athena http server.</p>
-
-<h2>Server status</h2>
-
-<p><a href="/graph">here</a></p>
-
-<h2>Add account(login server only)</h2>
-
-<form action="/account" method="GET">
-
-<table border>
-	<tr><th>User ID</th><td><input type="text" name="userid"></td></tr>
-	<tr><th>Password</th><td><input type="password" name="passwd" ></td></tr>
-	<tr><th>Gender</th><td><input type="radio" name="gender" value="male">Male <input type="radio" name="gender" value="female">Female</td></tr>
-	<tr><td colspan="2"><input type="submit" name="add" value="Make Account"><input type="submit" name="check" value="Check UserID"></td></tr>
-</table>
-
-</form>
-
-</body></html>

+ 2 - 8
src/char/char.c

@@ -111,7 +111,6 @@ struct {
 } auth_fifo[AUTH_FIFO_SIZE];
 int auth_fifo_pos = 0;
 
-int check_ip_flag = 1; // It's to check IP of a player between char-server and other servers (part of anti-hacking system)
 static int online_check = 1; //If one, it won't let players connect when their account is already registered online and will send the relevant map server a kick user request. [Skotlex]
 
 int char_id_count = START_CHAR_NUM;
@@ -3433,10 +3432,8 @@ int parse_char(int fd) {
 			for(i = 0; i < AUTH_FIFO_SIZE && !(
 				auth_fifo[i].account_id == sd->account_id &&
 				auth_fifo[i].login_id1 == sd->login_id1 &&
-#if CMP_AUTHFIFO_LOGIN2 != 0
 				auth_fifo[i].login_id2 == sd->login_id2 && // relate to the versions higher than 18
-#endif
-				(!check_ip_flag || auth_fifo[i].ip == session[fd]->client_addr.sin_addr.s_addr) &&
+				auth_fifo[i].ip == session[fd]->client_addr.sin_addr.s_addr &&
 				auth_fifo[i].delflag == 2)
 				; i++);
 
@@ -4087,9 +4084,8 @@ int char_config_read(const char *cfgName) {
 		if(strcmpi(w1,"timestamp_format") == 0) {
 			strncpy(timestamp_format, w2, 20);
 		} else if(strcmpi(w1,"console_silent")==0){
-			msg_silent = 0; //To always allow the next line to show up.
-			ShowInfo("Console Silent Setting: %d\n", atoi(w2));
 			msg_silent = atoi(w2);
+			ShowInfo("Console Silent Setting: %d\n", msg_silent);
 #ifndef TXT_SQL_CONVERT
 		} else if(strcmpi(w1,"stdout_with_ansisequence")==0){
 			stdout_with_ansisequence = config_switch(w2);
@@ -4159,8 +4155,6 @@ int char_config_read(const char *cfgName) {
 			gm_allow_level = atoi(w2);
 			if(gm_allow_level < 0)
 				gm_allow_level = 99;
-		} else if (strcmpi(w1, "check_ip_flag") == 0) {
-			check_ip_flag = config_switch(w2);
 		} else if (strcmpi(w1, "online_check") == 0) {
 			online_check = config_switch(w2);
 		} else if (strcmpi(w1, "autosave_time") == 0) {

+ 3 - 12
src/char_sql/char.c

@@ -140,8 +140,6 @@ struct {
 } auth_fifo[AUTH_FIFO_SIZE];
 int auth_fifo_pos = 0;
 
-int check_ip_flag = 1; // It's to check IP of a player between char-server and other servers (part of anti-hacking system)
-
 struct mmo_charstatus char_dat;
 int char_num,char_max;
 int max_connect_user = 0;
@@ -1871,7 +1869,7 @@ int parse_tologin(int fd) {
 				//printf("connect login server error : %d\n", RFIFOB(fd, 2));
 				ShowError("Can not connect to login-server.\n");
 				ShowError("The server communication passwords (default s1/p1) are probably invalid.\n");
-				ShowError("Also, please make sure your login db has the correct coounication username/passwords and the gender of the account is S.\n");
+				ShowError("Also, please make sure your login db has the correct communication username/passwords and the gender of the account is S.\n");
 				ShowError("The communication passwords are set in map_athena.conf and char_athena.conf\n");
 				return 0;
 				//exit(1); //fixed for server shutdown.
@@ -3245,10 +3243,8 @@ int parse_char(int fd) {
 				i < AUTH_FIFO_SIZE && !(
 				auth_fifo[i].account_id == sd->account_id &&
 				auth_fifo[i].login_id1 == sd->login_id1 &&
-#if CMP_AUTHFIFO_LOGIN2 != 0
 				auth_fifo[i].login_id2 == sd->login_id2 && // relate to the versions higher than 18
-#endif
-				(!check_ip_flag || auth_fifo[i].ip == session[fd]->client_addr.sin_addr.s_addr) &&
+				auth_fifo[i].ip == session[fd]->client_addr.sin_addr.s_addr &&
 				auth_fifo[i].delflag == 2)
 				; i++);
 		  
@@ -4028,9 +4024,8 @@ int char_config_read(const char *cfgName) {
 		if(strcmpi(w1,"timestamp_format")==0) {
 			strncpy(timestamp_format, w2, 20);
 		} else if(strcmpi(w1,"console_silent")==0){
-			msg_silent = 0; //To always allow the next line to show up.
-			ShowInfo("Console Silent Setting: %d\n", atoi(w2));
 			msg_silent = atoi(w2);
+			ShowInfo("Console Silent Setting: %d\n", msg_silent);
 		} else if(strcmpi(w1,"stdout_with_ansisequence")==0){
 			stdout_with_ansisequence = config_switch(w2);
 		} else if (strcmpi(w1, "userid") == 0) {
@@ -4085,8 +4080,6 @@ int char_config_read(const char *cfgName) {
 			gm_allow_level = atoi(w2);
 			if(gm_allow_level < 0)
 				gm_allow_level = 99;
-		} else if (strcmpi(w1, "check_ip_flag") == 0) {
-			check_ip_flag = config_switch(w2);
 		} else if (strcmpi(w1, "online_check") == 0) {
 			online_check = config_switch(w2);
 		} else if (strcmpi(w1, "autosave_time") == 0) {
@@ -4130,8 +4123,6 @@ int char_config_read(const char *cfgName) {
 			char_name_option = atoi(w2);
 		} else if (strcmpi(w1, "char_name_letters") == 0) {
 			strcpy(char_name_letters, w2);
-		} else if (strcmpi(w1, "check_ip_flag") == 0) {
-			check_ip_flag = config_switch(w2);
 		} else if (strcmpi(w1, "chars_per_account") == 0) { //maxchars per account [Sirius]
 			char_per_account = atoi(w2);
 		} else if (strcmpi(w1, "char_del_level") == 0) { //disable/enable char deletion by its level condition [Lupus]

+ 0 - 6
src/common/mmo.h

@@ -15,12 +15,6 @@
 
 #define FIFOSIZE_SERVERLINK	256*1024
 
-// set to 0 to not check IP of player between each server.
-// set to another value if you want to check (1)
-#define CMP_AUTHFIFO_IP 1
-
-#define CMP_AUTHFIFO_LOGIN2 1
-
 //Remove/Comment this line to disable sc_data saving. [Skotlex]
 #define ENABLE_SC_SAVING 
 

+ 1 - 1
src/common/showmsg.c

@@ -49,7 +49,7 @@
 /// if false removes the escape sequences
 int stdout_with_ansisequence = 0;
 
-int msg_silent; //Specifies how silent the console is.
+int msg_silent = 0; //Specifies how silent the console is.
 
 ///////////////////////////////////////////////////////////////////////////////
 /// static/dynamic buffer for the messages

+ 108 - 204
src/login/login.c

@@ -1,18 +1,19 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-// new version of the login-server by [Yor]
-
 #include <sys/types.h>
+
 #ifdef __WIN32
-#define WIN32_LEAN_AND_MEAN
-#include <winsock2.h>
+	#define WIN32_LEAN_AND_MEAN
+	#include <windows.h>
+	#include <winsock2.h>
 #else
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
+	#include <sys/socket.h>
+	#include <netinet/in.h>
+	#include <arpa/inet.h>
+	#include <netdb.h>
 #endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/stat.h> // for stat/lstat/fstat
@@ -32,17 +33,13 @@
 #include "../common/malloc.h"
 #include "../common/strlib.h"
 #include "../common/showmsg.h"
-#include "login.h"
-
-#ifdef PASSWORDENC
 #include "../common/md5calc.h"
-#endif
+#include "login.h"
 
 int account_id_count = START_ACCOUNT_NUM;
 int server_num;
 int new_account_flag = 0;
-in_addr_t bind_ip= 0;
-char bind_ip_str[128];
+in_addr_t login_ip = INADDR_ANY;
 int login_port = 6900;
 
 // Advanced subnet check [LuzZza]
@@ -105,7 +102,6 @@ char *access_ladmin_allow = NULL;
 int min_level_to_connect = 0; // minimum level of player/GM (0: player, 1-99: gm) to connect on the server
 int add_to_unlimited_account = 0; // Give possibility or not to adjust (ladmin command: timeadd) the time of an unlimited account.
 int start_limited_time = -1; // Starting additional sec from now for the limited time at creation of accounts (-1: unlimited time, 0 or more: additional sec from now)
-int check_ip_flag = 1; // It's to check IP of a player between login-server and char-server (part of anti-hacking system)
 
 int check_client_version = 0; //Client version check ON/OFF .. (sirius)
 int client_version_to_connect = 20; //Client version needed to connect ..(sirius)
@@ -158,20 +154,15 @@ int auth_before_save_file = 0; // Counter. First save when 1st char-server do co
 
 int admin_state = 0;
 char admin_pass[24] = "";
-unsigned int GM_num;
-unsigned int GM_max=256;
+unsigned int GM_num = 0;
+unsigned int GM_max = 0;
 char gm_pass[64] = "";
 int level_new_gm = 60;
 
-struct gm_account *gm_account_db;
+struct gm_account* gm_account_db = NULL;
 
 static struct dbt *online_db;
 
-int dynamic_pass_failure_ban = 1;
-int dynamic_pass_failure_ban_time = 5;
-int dynamic_pass_failure_ban_how_many = 3;
-int dynamic_pass_failure_ban_how_long = 1;
-
 int use_md5_passwds = 0;
 
 int console = 0;
@@ -195,8 +186,6 @@ int login_log(char *fmt, ...) {
 				fprintf(log_fp, RETCODE);
 			else {
 				va_start(ap, fmt);
-				// Platform/Compiler dependant clock() for time check is removed. [Lance]
-				// clock() is originally used to track processing ticks on program execution.
 				time(&raw_time);
 				strftime(tmpstr, 24, date_format, localtime(&raw_time));
 				sprintf(tmpstr + strlen(tmpstr), ": %s", fmt);
@@ -1139,71 +1128,73 @@ int mmo_auth_new(struct mmo_account* account, char sex, char* email) {
 //---------------------------------------
 // Check/authentification of a connection
 //---------------------------------------
-int mmo_auth(struct mmo_account* account, int fd) {
-	char *dnsbl_serv;
+int mmo_auth(struct mmo_account* account, int fd)
+{
 	unsigned int i;
 	time_t raw_time;
 	char tmpstr[256];
-	int len, newaccount = 0;
+	int len;
+	int newaccount = 0;
 #ifdef PASSWORDENC
 	struct login_session_data *ld;
 #endif
 	int encpasswdok;
 	char md5str[64], md5bin[32];
-	char ip[16];
-	unsigned char *sin_addr = (unsigned char *)&session[fd]->client_addr.sin_addr;
 	char user_password[256];
-	char r_ip[16]; // [Zido]
-	char ip_dnsbl[256]; // [Zido]
 
+	char ip[16];
+	unsigned char *sin_addr = (unsigned char *)&session[fd]->client_addr.sin_addr;
 	sprintf(ip, "%d.%d.%d.%d", sin_addr[0], sin_addr[1], sin_addr[2], sin_addr[3]);
 
-	// Start DNS Blacklist check [Zido]
-	if(use_dnsbl) {
-		sprintf(r_ip, "%d.%d.%d.%d", sin_addr[3], sin_addr[2], sin_addr[1], sin_addr[0]);
+	// DNS Blacklist check
+	if(use_dnsbl)
+	{
+		char r_ip[16];
+		char ip_dnsbl[256];
+		char *dnsbl_serv;
+		bool matched = false;
 
-		dnsbl_serv=strtok(dnsbl_servs,",");
-		sprintf(ip_dnsbl,"%s.%s",r_ip,dnsbl_serv);
-// Using directly gethostbyname should be quicker. [Skotlex]
-//		if(resolve_hostbyname(ip_dnsbl, NULL, NULL)) {
-		if(gethostbyname(ip_dnsbl)) {
-			ShowInfo("DNSBL: (%s) Blacklisted. User Kicked.\n",ip);
-			return 3;
-		}
+		sprintf(r_ip, "%d.%d.%d.%d", sin_addr[3], sin_addr[2], sin_addr[1], sin_addr[0]);
 
-		while((dnsbl_serv=strtok(dnsbl_servs,","))) {
-			sprintf(ip_dnsbl,"%s.%s",r_ip,dnsbl_serv);
-// Using directly gethostbyname should be quicker. [Skotlex]
-//			if(resolve_hostbyname(ip_dnsbl,NULL,NULL)!=0) {
-			if(gethostbyname(ip_dnsbl)) {
-				ShowInfo("DNSBL: (%s) Blacklisted. User Kicked.\n",ip);
-				return 3;
+		for (dnsbl_serv = strtok(dnsbl_servs,","); dnsbl_serv != NULL; dnsbl_serv = strtok(NULL,","))
+		{
+			if (!matched) {
+				sprintf(ip_dnsbl, "%s.%s", r_ip, dnsbl_serv);
+				if(gethostbyname(ip_dnsbl))
+					matched = true;
 			}
 		}
 
+		if (matched) {
+			ShowInfo("DNSBL: (%s) Blacklisted. User Kicked.\n", r_ip);
+			return 3;
+		}
 	}
-	// End DNS Blacklist check [Zido]
 
 
 	len = strlen(account->userid) - 2;
+
 	// Account creation with _M/_F
-	if (account->passwdenc == 0 && account->userid[len] == '_' &&
-		(account->userid[len+1] == 'F' || account->userid[len+1] == 'M' ||
-		account->userid[len+1] == 'f' || account->userid[len+1] == 'm')
-		&& new_account_flag && account_id_count <= END_ACCOUNT_NUM && len >= 4 && strlen(account->passwd) >= 4) {
-						
-		//only continue if amount in this time limit is allowed (account registration flood protection)[Kevin]
-		if(DIFF_TICK(gettick(), new_reg_tick) < 0 && num_regs >= allowed_regs) {
-			ShowNotice("Account registration denied (registration limit exceeded) to %s!\n", ip);
-			login_log("Notice: Account registration denied (registration limit exceeded) to %s!", ip);
-			return 3;
+	if (new_account_flag) 
+	{
+		if (account->passwdenc == 0 && account->userid[len] == '_' &&
+		   (account->userid[len+1] == 'F' || account->userid[len+1] == 'M' ||
+			account->userid[len+1] == 'f' || account->userid[len+1] == 'm') &&
+			account_id_count <= END_ACCOUNT_NUM && len >= 4 && strlen(account->passwd) >= 4)
+		{
+			//only continue if amount in this time limit is allowed (account registration flood protection)[Kevin]
+			if(DIFF_TICK(gettick(), new_reg_tick) < 0 && num_regs >= allowed_regs) {
+				ShowNotice("Account registration denied (registration limit exceeded) to %s!\n", ip);
+				login_log("Notice: Account registration denied (registration limit exceeded) to %s!", ip);
+				return 3;
+			}
+			newaccount = 1;
+			account->userid[len] = '\0';
 		}
-		newaccount = 1;
-		account->userid[len] = '\0';
 	}
 	
 	//EXE Version check [Sirius]
-	if (check_client_version == 1 && account->version != 0 &&
+	if (check_client_version && account->version != 0 &&
 		account->version != client_version_to_connect)
 		return 5;
 	
@@ -1457,16 +1448,14 @@ int parse_fromchar(int fd) {
 			if (RFIFOREST(fd) < 19)
 				return 0;
 		  {
-			int acc;
-			acc = RFIFOL(fd,2); // speed up
+			int account_id;
+			account_id = RFIFOL(fd,2); // speed up
 			for(i = 0; i < AUTH_FIFO_SIZE; i++) {
-				if (auth_fifo[i].account_id == acc &&
+				if (auth_fifo[i].account_id == account_id &&
 				    auth_fifo[i].login_id1 == RFIFOL(fd,6) &&
-#if CMP_AUTHFIFO_LOGIN2 != 0
 				    auth_fifo[i].login_id2 == RFIFOL(fd,10) && // relate to the versions higher than 18
-#endif
 				    auth_fifo[i].sex == RFIFOB(fd,14) &&
-				    (!check_ip_flag || auth_fifo[i].ip == RFIFOL(fd,15)) &&
+				    auth_fifo[i].ip == RFIFOL(fd,15) &&
 				    !auth_fifo[i].delflag) {
 					unsigned int k;
 					time_t connect_until_time = 0;
@@ -1474,17 +1463,17 @@ int parse_fromchar(int fd) {
 					WFIFOHEAD(fd,51);
 					auth_fifo[i].delflag = 1;
 					login_log("Char-server '%s': authentification of the account %d accepted (ip: %s)." RETCODE,
-					          server[id].name, acc, ip);
+					          server[id].name, account_id, ip);
 //					printf("%d\n", i);
 					for(k = 0; k < auth_num; k++) {
-						if (auth_dat[k].account_id == acc) {
+						if (auth_dat[k].account_id == account_id) {
 							strcpy(email, auth_dat[k].email);
 							connect_until_time = auth_dat[k].connect_until_time;
 							break;
 						}
 					}
 					WFIFOW(fd,0) = 0x2713;
-					WFIFOL(fd,2) = acc;
+					WFIFOL(fd,2) = account_id;
 					WFIFOB(fd,6) = 0;
 					memcpy(WFIFOP(fd, 7), email, 40);
 					WFIFOL(fd,47) = (unsigned long)connect_until_time;
@@ -1495,10 +1484,10 @@ int parse_fromchar(int fd) {
 			// authentification not found
 			if (i == AUTH_FIFO_SIZE) {
 				login_log("Char-server '%s': authentification of the account %d REFUSED (ip: %s)." RETCODE,
-				          server[id].name, acc, ip);
+				          server[id].name, account_id, ip);
                                 WFIFOHEAD(fd, 51);
 				WFIFOW(fd,0) = 0x2713;
-				WFIFOL(fd,2) = acc;
+				WFIFOL(fd,2) = account_id;
 				WFIFOB(fd,6) = 1;
 				// It is unnecessary to send email
 				// It is unnecessary to send validity date of the account
@@ -3026,28 +3015,17 @@ int parse_admin(int fd) {
 
 //--------------------------------------------
 // Test to know if an IP come from LAN or WAN.
-// Rewrote: Adnvanced subnet check [LuzZza]
 //--------------------------------------------
 int lan_subnetcheck(long *p) {
 
 	int i;
-	unsigned char *sbn, *msk/*, *src = (unsigned char *)p*/;
 	
 	for(i=0; i<subnet_count; i++) {
-	
 		if(subnet[i].subnet == (*p & subnet[i].mask)) {
-			
-			sbn = (char *)&subnet[i].subnet;
-			msk = (char *)&subnet[i].mask;
-/*			
-			ShowInfo("Subnet check [%u.%u.%u.%u]: Matches "CL_CYAN"%u.%u.%u.%u/%u.%u.%u.%u"CL_RESET"\n",
-				src[0], src[1], src[2], src[3], sbn[0], sbn[1], sbn[2], sbn[3], msk[0], msk[1], msk[2], msk[3]);
-*/
 			return subnet[i].char_ip;
 		}
 	}
 	
-//	ShowInfo("Subnet check [%u.%u.%u.%u]: "CL_CYAN"WAN"CL_RESET"\n", src[0], src[1], src[2], src[3]);
 	return 0;
 }
 
@@ -3099,7 +3077,7 @@ int parse_login(int fd) {
 			RFIFOSKIP(fd,18);
 			break;
 
-		case 0x277: // New login packet
+		case 0x277:		// New login packet
 		case 0x64:		// request client login
 		case 0x01dd:	// request client login with encrypt
 		{
@@ -3505,14 +3483,16 @@ static int online_data_cleanup(int tid, unsigned int tick, int id, int data)
 	online_db->foreach(online_db, online_data_cleanup_sub);
 	return 0;
 } 
+
 //-------------------------------------------------
 // Return numerical value of a switch configuration
-// on/off, english, français, deutsch, español
+// 1/0, on/off, english, français, deutsch
 //-------------------------------------------------
-int config_switch(const char *str) {
-	if (strcmpi(str, "on") == 0 || strcmpi(str, "yes") == 0 || strcmpi(str, "oui") == 0 || strcmpi(str, "ja") == 0 || strcmpi(str, "si") == 0)
+int config_switch(const char *str)
+{
+	if (strcmpi(str, "1") == 0 || strcmpi(str, "on") == 0 || strcmpi(str, "yes") == 0 || strcmpi(str, "oui") == 0 || strcmpi(str, "ja") == 0)
 		return 1;
-	if (strcmpi(str, "off") == 0 || strcmpi(str, "no") == 0 || strcmpi(str, "non") == 0 || strcmpi(str, "nein") == 0)
+	if (strcmpi(str, "0") == 0 || strcmpi(str, "off") == 0 || strcmpi(str, "no") == 0 || strcmpi(str, "non") == 0 || strcmpi(str, "nein") == 0)
 		return 0;
 
 	return atoi(str);
@@ -3520,10 +3500,9 @@ int config_switch(const char *str) {
 
 //----------------------------------
 // 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)
+{
 	FILE *fp;
 	int line_num = 0;
 	char line[1024], w1[64], w2[64], w3[64], w4[64];
@@ -3575,25 +3554,29 @@ int login_lan_config_read(const char *lancfgName) {
 }
 
 //-----------------------------------
-// Reading general configuration file
+// Reading main configuration file
 //-----------------------------------
-int login_config_read(const char *cfgName) {
+int login_config_read(const char* cfgName)
+{
 	char line[1024], w1[1024], w2[1024];
-	FILE *fp;
-
-	if ((fp = fopen(cfgName, "r")) == NULL) {
+	FILE* fp = fopen(cfgName, "r");
+	if (fp == NULL) {
 		ShowError("Configuration file (%s) not found.\n", cfgName);
 		return 1;
 	}
-
 	ShowInfo("Reading configuration file %s...\n", cfgName);
-	while(fgets(line, sizeof(line)-1, fp)) {
+	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) < 2)
+			continue;
+
+		//TODO: unindent
 			remove_control_chars((unsigned char *)w1);
 			remove_control_chars((unsigned char *)w2);
 
@@ -3602,9 +3585,8 @@ int login_config_read(const char *cfgName) {
 			} else if(strcmpi(w1,"stdout_with_ansisequence")==0){
 				stdout_with_ansisequence = config_switch(w2);
 			} else if(strcmpi(w1,"console_silent")==0){
-				msg_silent = 0; //To always allow the next line to show up.
-				ShowInfo("Console Silent Setting: %d\n", atoi(w2));
 				msg_silent = atoi(w2);
+				ShowInfo("Console Silent Setting: %d\n", msg_silent);
 			} else if (strcmpi(w1, "admin_state") == 0) {
 				admin_state = config_switch(w2);
 			} else if (strcmpi(w1, "admin_pass") == 0) {
@@ -3644,9 +3626,10 @@ int login_config_read(const char *cfgName) {
 			} else if (strcmpi(w1, "new_account") == 0) {
 				new_account_flag = config_switch(w2);
 			} else if (strcmpi(w1, "bind_ip") == 0) {
-				bind_ip = resolve_hostbyname(w2, NULL, bind_ip_str);
-				if (bind_ip) 
-					ShowStatus("Login server binding IP address : %s -> %s\n", w2, bind_ip_str);
+				char login_ip_str[128];
+				login_ip = resolve_hostbyname(w2, NULL, login_ip_str);
+				if (login_ip) 
+					ShowStatus("Login server binding IP address : %s -> %s\n", w2, login_ip_str);
 			} else if (strcmpi(w1, "login_port") == 0) {
 				login_port = atoi(w2);
 			} else if (strcmpi(w1, "account_filename") == 0) {
@@ -3666,7 +3649,7 @@ int login_config_read(const char *cfgName) {
 				strncpy(login_log_filename, w2, sizeof(login_log_filename));
 				login_log_filename[sizeof(login_log_filename)-1] = '\0';
 			} else if (strcmpi(w1, "log_login") == 0) {
-				log_login = atoi(w2);
+				log_login = config_switch(w2);
 			} else if (strcmpi(w1, "login_log_unknown_packets_filename") == 0) {
 				memset(login_log_unknown_packets_filename, 0, sizeof(login_log_unknown_packets_filename));
 				strncpy(login_log_unknown_packets_filename, w2, sizeof(login_log_unknown_packets_filename));
@@ -3674,35 +3657,19 @@ int login_config_read(const char *cfgName) {
 			} else if (strcmpi(w1, "save_unknown_packets") == 0) {
 				save_unknown_packets = config_switch(w2);
 			} else if (strcmpi(w1, "display_parse_login") == 0) {
-				display_parse_login = config_switch(w2); // 0: no, 1: yes
+				display_parse_login = config_switch(w2);
 			} else if (strcmpi(w1, "display_parse_admin") == 0) {
-				display_parse_admin = config_switch(w2); // 0: no, 1: yes
+				display_parse_admin = config_switch(w2);
 			} else if (strcmpi(w1, "display_parse_fromchar") == 0) {
 				display_parse_fromchar = config_switch(w2); // 0: no, 1: yes (without packet 0x2714), 2: all packets
-			} else if (strcmpi(w1, "date_format") == 0) { // note: never have more than 19 char for the date!
-				memset(date_format, 0, sizeof(date_format));
-				switch (atoi(w2)) {
-				case 0:
-					strcpy(date_format, "%d-%m-%Y %H:%M:%S"); // 31-12-2004 23:59:59
-					break;
-				case 1:
-					strcpy(date_format, "%m-%d-%Y %H:%M:%S"); // 12-31-2004 23:59:59
-					break;
-				case 2:
-					strcpy(date_format, "%Y-%d-%m %H:%M:%S"); // 2004-31-12 23:59:59
-					break;
-				case 3:
-					strcpy(date_format, "%Y-%m-%d %H:%M:%S"); // 2004-12-31 23:59:59
-					break;
-				}
+			} else if (!strcmpi(w1, "date_format")) {
+				strncpy(date_format, w2, sizeof(date_format));
 			} else if (strcmpi(w1, "min_level_to_connect") == 0) {
 				min_level_to_connect = atoi(w2);
 			} else if (strcmpi(w1, "add_to_unlimited_account") == 0) {
 				add_to_unlimited_account = config_switch(w2);
 			} else if (strcmpi(w1, "start_limited_time") == 0) {
 				start_limited_time = atoi(w2);
-			} else if (strcmpi(w1, "check_ip_flag") == 0) {
-				check_ip_flag = config_switch(w2);
 			} else if (strcmpi(w1, "order") == 0) {
 				access_order = atoi(w2);
 				if (strcmpi(w2, "deny,allow") == 0 ||
@@ -3759,53 +3726,30 @@ int login_config_read(const char *cfgName) {
 						access_deny[access_denynum * ACO_STRSIZE - 1] = '\0';
 					}
 				}
-			// dynamic password error ban
-			} else if (strcmpi(w1, "dynamic_pass_failure_ban") == 0) {
-				dynamic_pass_failure_ban = config_switch(w2);
-			} else if (strcmpi(w1, "dynamic_pass_failure_ban_time") == 0) {
-				dynamic_pass_failure_ban_time = atoi(w2);
-			} else if (strcmpi(w1, "dynamic_pass_failure_ban_how_many") == 0) {
-				dynamic_pass_failure_ban_how_many = atoi(w2);
-			} else if (strcmpi(w1, "dynamic_pass_failure_ban_how_long") == 0) {
-				dynamic_pass_failure_ban_how_long = atoi(w2);
-			} else if(strcmpi(w1, "check_client_version") == 0){		//Added by Sirius for client version check
-				if(strcmpi(w2,"on") == 0 || strcmpi(w2,"yes") == 0 ){
-					check_client_version = 1;
-				}
-				if(strcmpi(w2,"off") == 0 || strcmpi(w2,"no") == 0 ){
-					check_client_version = 0;
-				}
-			}else if(strcmpi(w1, "client_version_to_connect") == 0){	//Added by Sirius for client version check
-				client_version_to_connect = atoi(w2);			//Added by Sirius for client version check
+			} else if(strcmpi(w1, "check_client_version") == 0) {
+				check_client_version = config_switch(w2);
+			} else if(strcmpi(w1, "client_version_to_connect") == 0) {
+				client_version_to_connect = atoi(w2);
 			} else if (strcmpi(w1, "console") == 0) {
-				if(strcmpi(w2,"on") == 0 || strcmpi(w2,"yes") == 0 )
-					console = 1;
-			} else if (strcmpi(w1, "allowed_regs") == 0) { //account flood protection system [Kevin]
+				console = config_switch(w2);
+			} else if (strcmpi(w1, "allowed_regs") == 0) { //account flood protection system
 				allowed_regs = atoi(w2);
 			} else if (strcmpi(w1, "time_allowed") == 0) {
 				time_allowed = atoi(w2);
 			} else if (strcmpi(w1, "online_check") == 0) {
-				if(strcmpi(w2,"on") == 0 || strcmpi(w2,"yes") == 0 )
-					online_check = 1;
-				else if(strcmpi(w2,"off") == 0 || strcmpi(w2,"no") == 0 )
-					online_check = 0;
-				else
-					online_check = atoi(w2);
-			} else if (strcmpi(w1, "import") == 0) {
-				login_config_read(w2);
-			} else if(strcmpi(w1,"use_dnsbl")==0) { // [Zido]
-				use_dnsbl=atoi(w2);
-			} else if(strcmpi(w1,"dnsbl_servers")==0) { // [Zido]
+				online_check = config_switch(w2);
+			} else if(strcmpi(w1,"use_dnsbl")==0) {
+				use_dnsbl=config_switch(w2);
+			} else if(strcmpi(w1,"dnsbl_servers")==0) {
 				strcpy(dnsbl_servs,w2);
 			} else if(strcmpi(w1,"ip_sync_interval")==0) {
 				ip_sync_interval = 1000*60*atoi(w2); //w2 comes in minutes.
+			} else if (strcmpi(w1, "import") == 0) {
+				login_config_read(w2);
 			}
-		}
 	}
 	fclose(fp);
-
 	ShowInfo("Finished reading %s.\n", cfgName);
-
 	return 0;
 }
 
@@ -3898,12 +3842,6 @@ void display_conf_warnings(void) {
 		start_limited_time = -1;
 	}
 
-	if (check_ip_flag != 0 && check_ip_flag != 1) { // 0: no, 1: yes
-		ShowWarning("Invalid value for check_ip_flag parameter\n");
-		ShowWarning("  -> setting to 1 (check players ip between login-server & char-server).\n");
-		check_ip_flag = 1;
-	}
-
 	if (access_order == ACO_DENY_ALLOW) {
 		if (access_denynum == 1 && access_deny[0] == '\0') {
 			ShowWarning("The IP security order is 'deny,allow' (allow if not deny) and you refuse ALL IP.\n");
@@ -3924,24 +3862,6 @@ void display_conf_warnings(void) {
 		}
 	}
 
-	if (dynamic_pass_failure_ban != 0) {
-		if (dynamic_pass_failure_ban_time < 1) {
-			ShowWarning("Invalid value for dynamic_pass_failure_ban_time (%d) parameter\n", dynamic_pass_failure_ban_time);
-			ShowWarning("  -> setting to 5 (5 minutes to look number of invalid passwords.\n");
-			dynamic_pass_failure_ban_time = 5;
-		}
-		if (dynamic_pass_failure_ban_how_many < 1) {
-			ShowWarning("Invalid value for dynamic_pass_failure_ban_how_many (%d) parameter\n", dynamic_pass_failure_ban_how_many);
-			ShowWarning("  -> setting to 3 (3 invalid passwords before to temporarily ban.\n");
-			dynamic_pass_failure_ban_how_many = 3;
-		}
-		if (dynamic_pass_failure_ban_how_long < 1) {
-			ShowWarning("Invalid value for dynamic_pass_failure_ban_how_long (%d) parameter\n", dynamic_pass_failure_ban_how_long);
-			ShowWarning("  -> setting to 1 (1 minute of temporarily ban.\n");
-			dynamic_pass_failure_ban_how_long = 1;
-		}
-	}
-
 	return;
 }
 
@@ -4041,11 +3961,6 @@ void save_config_in_log(void) {
 	else
 		login_log("- to create new accounts with a limited time: time of creation + %d second(s)." RETCODE, start_limited_time);
 
-	if (check_ip_flag)
-		login_log("- with control of players IP between login-server and char-server." RETCODE);
-	else
-		login_log("- to not check players IP between login-server and char-server." RETCODE);
-
 	if (access_order == ACO_DENY_ALLOW) {
 		if (access_denynum == 0) {
 			login_log("- with the IP security order: 'deny,allow' (allow if not deny). You refuse no IP." RETCODE);
@@ -4085,14 +4000,6 @@ void save_config_in_log(void) {
 				login_log("    %s" RETCODE, (char *)(access_deny + i * ACO_STRSIZE));
 		}
 
-		// dynamic password error ban
-		if (dynamic_pass_failure_ban == 0)
-			login_log("- with NO dynamic password error ban." RETCODE);
-		else {
-			login_log("- with a dynamic password error ban:" RETCODE);
-			login_log("  After %d invalid password in %d minutes" RETCODE, dynamic_pass_failure_ban_how_many, dynamic_pass_failure_ban_time);
-			login_log("  IP is banned for %d minutes" RETCODE, dynamic_pass_failure_ban_how_long);
-		}
 	}
 }
 
@@ -4150,9 +4057,6 @@ int do_init(int argc, char **argv) {
 	for(i = 0; i < MAX_SERVERS; i++)
 		server_fd[i] = -1;
 
-	gm_account_db = NULL;
-	GM_num = 0;
-	GM_max = 0;
 	mmo_auth_init();
 	read_gm_account();
 	set_defaultparse(parse_login);
@@ -4160,7 +4064,7 @@ int do_init(int argc, char **argv) {
 	online_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));	// reinitialise
 	add_timer_func_list(waiting_disconnect_timer, "waiting_disconnect_timer");
 
-	login_fd = make_listen_bind(bind_ip?bind_ip:INADDR_ANY,login_port);
+	login_fd = make_listen_bind(login_ip, login_port);
 
 	add_timer_func_list(check_auth_sync, "check_auth_sync");
 	add_timer_interval(gettick() + 60000, check_auth_sync, 0, 0, 60000); // every 60 sec we check if we must save accounts file (only if necessary to save)

File diff suppressed because it is too large
+ 226 - 374
src/login_sql/login.c


+ 3 - 5
src/login_sql/login.h

@@ -12,7 +12,7 @@
 
 #ifndef SQL_DEBUG
 
-#define mysql_query(_x, _y) mysql_real_query(_x, _y, strlen(_y)) //supports ' in names and runs faster [Kevin]
+#define mysql_query(_x, _y) mysql_query(_x, _y)
 
 #else 
 
@@ -26,19 +26,18 @@
 							// When it is made 3, it corresponds to both.
 
 struct mmo_account {
-	int version;	//Added by sirius for versioncheck
+	int version;
 	char userid[NAME_LENGTH];
 	char passwd[NAME_LENGTH];
 	int passwdenc;
 	
-	
 	long account_id;
 	long login_id1;
 	long login_id2;
 	long char_id;
 	char lastlogin[24];
 	int sex;
-	int level; // added [zzo]
+	int level;
 };
 
 struct mmo_char_server {
@@ -50,5 +49,4 @@ struct mmo_char_server {
 	int new_;
 };
 
-
 #endif /* _LOGIN_SQL_H_ */

Some files were not shown because too many files changed in this diff