Jelajahi Sumber

* Added 'birthdate' field to account data. For SQL apply upgrade_svn14672.sql to upgrade table `login`; for TXT no action is necessary, as it upgrades itself.
- Control panel developers are encouraged to enable players to modify this value, as it is required for new character deletion (2010-08-03aRagexeRE and later, not yet implemented).

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

ai4rei 14 tahun lalu
induk
melakukan
7919c7d9fc

+ 2 - 0
Changelog-Trunk.txt

@@ -1,6 +1,8 @@
 Date	Added
 
 2011/01/14
+	* Added 'birthdate' field to account data. For SQL apply upgrade_svn14672.sql to upgrade table `login`; for TXT no action is necessary, as it upgrades itself. [Ai4rei]
+	- Control panel developers are encouraged to enable players to modify this value, as it is required for new character deletion (2010-08-03aRagexeRE and later, not yet implemented).
 	* Removed unconditional redundant status change checks before status_change_end calls (follow up to r12890). [Ai4rei]
 	* Replaced remaining occurences of '-1' with 'INVALID_TIMER', where appropriate (follow up to r12998). [Ai4rei]
 	* Removed 'gui' plug-in (support plug-in for 3rd party eAthena GUI front-ends) (topic:262934). [Ai4rei]

+ 8 - 8
save-tmpl/account.txt

@@ -1,16 +1,16 @@
-20080409
+20110114
 // Accounts file: here are saved all information about the accounts.
-// Structure: account ID, username, password, sex, email, level, state, unban time, expiration time, # of logins, last login time, last (accepted) login ip, repeated(register key, register value)
+// Structure: account ID, username, password, sex, email, level, state, unban time, expiration time, # of logins, last login time, last (accepted) login ip, birth date, repeated(register key, register value)
 // where:
 //   sex             : M or F for normal accounts, S for server accounts
 //   level           : this account's gm level
 //   state           : 0: account is ok, 1 to 256: error code of packet 0x006a + 1
 //   unban time      : 0: no ban, <other value>: banned until the date (unix timestamp)
 //   expiration time : 0: unlimited account, <other value>: account expires on the date (unix timestamp)
-1	s1	p1	S	a@a.com	0	0	0	0	0	0000-00-00 00:00:00	-	
-2	s2	p2	S	a@a.com	0	0	0	0	0	0000-00-00 00:00:00	-	
-3	s3	p3	S	a@a.com	0	0	0	0	0	0000-00-00 00:00:00	-	
-4	s4	p4	S	a@a.com	0	0	0	0	0	0000-00-00 00:00:00	-	
-5	s5	p5	S	a@a.com	0	0	0	0	0	0000-00-00 00:00:00	-	
-2000001	Test	Test	M	a@a.com	0	0	0	0	0	0000-00-00 00:00:00	-	
+1	s1	p1	S	a@a.com	0	0	0	0	0	0000-00-00 00:00:00	-	0000-00-00	
+2	s2	p2	S	a@a.com	0	0	0	0	0	0000-00-00 00:00:00	-	0000-00-00	
+3	s3	p3	S	a@a.com	0	0	0	0	0	0000-00-00 00:00:00	-	0000-00-00	
+4	s4	p4	S	a@a.com	0	0	0	0	0	0000-00-00 00:00:00	-	0000-00-00	
+5	s5	p5	S	a@a.com	0	0	0	0	0	0000-00-00 00:00:00	-	0000-00-00	
+2000001	Test	Test	M	a@a.com	0	0	0	0	0	0000-00-00 00:00:00	-	0000-00-00	
 2000002	%newid%

+ 1 - 0
sql-files/main.sql

@@ -406,6 +406,7 @@ CREATE TABLE IF NOT EXISTS `login` (
   `logincount` mediumint(9) unsigned NOT NULL default '0',
   `lastlogin` datetime NOT NULL default '0000-00-00 00:00:00',
   `last_ip` varchar(100) NOT NULL default '',
+  `birthdate` DATE NOT NULL DEFAULT '0000-00-00',
   PRIMARY KEY  (`account_id`),
   KEY `name` (`userid`)
 ) ENGINE=MyISAM AUTO_INCREMENT=2000000; 

+ 1 - 0
sql-files/upgrade_svn14672.sql

@@ -0,0 +1 @@
+ALTER TABLE `login` ADD `birthdate` DATE NOT NULL DEFAULT '0000-00-00';

+ 2 - 1
src/login/account.h

@@ -41,7 +41,7 @@ AccountDB* ACCOUNTDB_CONSTRUCTOR(ACCOUNTDB_ENGINE_4)(void);
 struct mmo_account
 {
 	int account_id;
-	char userid[24];
+	char userid[NAME_LENGTH];
 	char pass[32+1];        // 23+1 for plaintext, 32+1 for md5-ed passwords
 	char sex;               // gender (M/F/S)
 	char email[40];         // e-mail (by default: a@a.com)
@@ -52,6 +52,7 @@ struct mmo_account
 	unsigned int logincount;// number of successful auth attempts
 	char lastlogin[24];     // date+time of last successful login
 	char last_ip[16];       // save of last IP of connection
+	char birthdate[10+1];   // assigned birth date (format: YYYY-MM-DD, default: 0000-00-00)
 	int account_reg2_num;
 	struct global_reg account_reg2[ACCOUNT_REG2_NUM]; // account script variables (stored on login server)
 };

+ 6 - 3
src/login/account_sql.c

@@ -522,7 +522,7 @@ static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int acc
 
 	// retrieve login entry for the specified account
 	if( SQL_ERROR == Sql_Query(sql_handle,
-	    "SELECT `account_id`,`userid`,`user_pass`,`sex`,`email`,`level`,`state`,`unban_time`,`expiration_time`,`logincount`,`lastlogin`,`last_ip` FROM `%s` WHERE `account_id` = %d",
+	    "SELECT `account_id`,`userid`,`user_pass`,`sex`,`email`,`level`,`state`,`unban_time`,`expiration_time`,`logincount`,`lastlogin`,`last_ip`,`birthdate` FROM `%s` WHERE `account_id` = %d",
 		db->account_db, account_id )
 	) {
 		Sql_ShowDebug(sql_handle);
@@ -547,6 +547,7 @@ static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int acc
 	Sql_GetData(sql_handle,  9, &data, NULL); acc->logincount = strtoul(data, NULL, 10);
 	Sql_GetData(sql_handle, 10, &data, NULL); safestrncpy(acc->lastlogin, data, sizeof(acc->lastlogin));
 	Sql_GetData(sql_handle, 11, &data, NULL); safestrncpy(acc->last_ip, data, sizeof(acc->last_ip));
+	Sql_GetData(sql_handle, 12, &data, NULL); safestrncpy(acc->birthdate, data, sizeof(acc->birthdate));
 
 	Sql_FreeResult(sql_handle);
 
@@ -595,7 +596,7 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo
 	if( is_new )
 	{// insert into account table
 		if( SQL_SUCCESS != SqlStmt_Prepare(stmt,
-			"INSERT INTO `%s` (`account_id`, `userid`, `user_pass`, `sex`, `email`, `level`, `state`, `unban_time`, `expiration_time`, `logincount`, `lastlogin`, `last_ip`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
+			"INSERT INTO `%s` (`account_id`, `userid`, `user_pass`, `sex`, `email`, `level`, `state`, `unban_time`, `expiration_time`, `logincount`, `lastlogin`, `last_ip`, `birthdate`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
 			db->account_db)
 		||  SQL_SUCCESS != SqlStmt_BindParam(stmt,  0, SQLDT_INT,    (void*)&acc->account_id,      sizeof(acc->account_id))
 		||  SQL_SUCCESS != SqlStmt_BindParam(stmt,  1, SQLDT_STRING, (void*)acc->userid,           strlen(acc->userid))
@@ -609,6 +610,7 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo
 		||  SQL_SUCCESS != SqlStmt_BindParam(stmt,  9, SQLDT_UINT,   (void*)&acc->logincount,      sizeof(acc->logincount))
 		||  SQL_SUCCESS != SqlStmt_BindParam(stmt, 10, SQLDT_STRING, (void*)&acc->lastlogin,       strlen(acc->lastlogin))
 		||  SQL_SUCCESS != SqlStmt_BindParam(stmt, 11, SQLDT_STRING, (void*)&acc->last_ip,         strlen(acc->last_ip))
+		||  SQL_SUCCESS != SqlStmt_BindParam(stmt, 12, SQLDT_STRING, (void*)&acc->birthdate,       strlen(acc->birthdate))
 		||  SQL_SUCCESS != SqlStmt_Execute(stmt)
 		) {
 			SqlStmt_ShowDebug(stmt);
@@ -617,7 +619,7 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo
 	}
 	else
 	{// update account table
-		if( SQL_SUCCESS != SqlStmt_Prepare(stmt, "UPDATE `%s` SET `userid`=?,`user_pass`=?,`sex`=?,`email`=?,`level`=?,`state`=?,`unban_time`=?,`expiration_time`=?,`logincount`=?,`lastlogin`=?,`last_ip`=? WHERE `account_id` = '%d'", db->account_db, acc->account_id)
+		if( SQL_SUCCESS != SqlStmt_Prepare(stmt, "UPDATE `%s` SET `userid`=?,`user_pass`=?,`sex`=?,`email`=?,`level`=?,`state`=?,`unban_time`=?,`expiration_time`=?,`logincount`=?,`lastlogin`=?,`last_ip`=?,`birthdate`=? WHERE `account_id` = '%d'", db->account_db, acc->account_id)
 		||  SQL_SUCCESS != SqlStmt_BindParam(stmt,  0, SQLDT_STRING, (void*)acc->userid,           strlen(acc->userid))
 		||  SQL_SUCCESS != SqlStmt_BindParam(stmt,  1, SQLDT_STRING, (void*)acc->pass,             strlen(acc->pass))
 		||  SQL_SUCCESS != SqlStmt_BindParam(stmt,  2, SQLDT_ENUM,   (void*)&acc->sex,             sizeof(acc->sex))
@@ -629,6 +631,7 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo
 		||  SQL_SUCCESS != SqlStmt_BindParam(stmt,  8, SQLDT_UINT,   (void*)&acc->logincount,      sizeof(acc->logincount))
 		||  SQL_SUCCESS != SqlStmt_BindParam(stmt,  9, SQLDT_STRING, (void*)&acc->lastlogin,       strlen(acc->lastlogin))
 		||  SQL_SUCCESS != SqlStmt_BindParam(stmt, 10, SQLDT_STRING, (void*)&acc->last_ip,         strlen(acc->last_ip))
+		||  SQL_SUCCESS != SqlStmt_BindParam(stmt, 11, SQLDT_STRING, (void*)&acc->birthdate,       strlen(acc->birthdate))
 		||  SQL_SUCCESS != SqlStmt_Execute(stmt)
 		) {
 			SqlStmt_ShowDebug(stmt);

+ 26 - 5
src/login/account_txt.c

@@ -14,7 +14,7 @@
 #include <string.h>
 
 /// global defines
-#define ACCOUNT_TXT_DB_VERSION 20080409
+#define ACCOUNT_TXT_DB_VERSION 20110114
 #define AUTHS_BEFORE_SAVE 10 // flush every 10 saves
 #define AUTH_SAVING_INTERVAL 60000 // flush every 10 minutes
 
@@ -452,10 +452,31 @@ static bool mmo_auth_fromstr(struct mmo_account* a, char* str, unsigned int vers
 	// zero out the destination first
 	memset(a, 0x00, sizeof(struct mmo_account));
 
+	// defaults for older format versions
+	safestrncpy(a->birthdate, "0000-00-00", sizeof(a->birthdate));
+
 	// extract tab-separated columns from line
 	count = sv_split(str, strlen(str), 0, '\t', fields, ARRAYLENGTH(fields), (e_svopt)(SV_TERMINATE_LF|SV_TERMINATE_CRLF));
 
-	if( version == ACCOUNT_TXT_DB_VERSION && count == 13 )
+	if( version == ACCOUNT_TXT_DB_VERSION && count == 14 )
+	{
+		a->account_id = strtol(fields[1], NULL, 10);
+		safestrncpy(a->userid, fields[2], sizeof(a->userid));
+		safestrncpy(a->pass, fields[3], sizeof(a->pass));
+		a->sex = fields[4][0];
+		safestrncpy(a->email, fields[5], sizeof(a->email));
+		a->level = strtoul(fields[6], NULL, 10);
+		a->state = strtoul(fields[7], NULL, 10);
+		a->unban_time = strtol(fields[8], NULL, 10);
+		a->expiration_time = strtol(fields[9], NULL, 10);
+		a->logincount = strtoul(fields[10], NULL, 10);
+		safestrncpy(a->lastlogin, fields[11], sizeof(a->lastlogin));
+		safestrncpy(a->last_ip, fields[12], sizeof(a->last_ip));
+		safestrncpy(a->birthdate, fields[13], sizeof(a->birthdate));
+		regs = fields[14];
+	}
+	else
+	if( version == 20080409 && count == 13 )
 	{
 		a->account_id = strtol(fields[1], NULL, 10);
 		safestrncpy(a->userid, fields[2], sizeof(a->userid));
@@ -558,10 +579,10 @@ static bool mmo_auth_tostr(const struct mmo_account* a, char* str)
 	int i;
 	char* str_p = str;
 
-	str_p += sprintf(str_p, "%d\t%s\t%s\t%c\t%s\t%u\t%u\t%ld\t%ld\t%u\t%s\t%s\t",
+	str_p += sprintf(str_p, "%d\t%s\t%s\t%c\t%s\t%u\t%u\t%ld\t%ld\t%u\t%s\t%s\t%s\t",
 	                 a->account_id, a->userid, a->pass, a->sex, a->email, a->level,
 	                 a->state, (long)a->unban_time, (long)a->expiration_time,
-	                 a->logincount, a->lastlogin, a->last_ip);
+	                 a->logincount, a->lastlogin, a->last_ip, a->birthdate);
 
 	for( i = 0; i < a->account_reg2_num; ++i )
 		if( a->account_reg2[i].str[0] )
@@ -587,7 +608,7 @@ static void mmo_auth_sync(AccountDB_TXT* db)
 	fprintf(fp, "%d\n", ACCOUNT_TXT_DB_VERSION); // savefile version
 
 	fprintf(fp, "// Accounts file: here are saved all information about the accounts.\n");
-	fprintf(fp, "// Structure: account ID, username, password, sex, email, level, state, unban time, expiration time, # of logins, last login time, last (accepted) login ip, repeated(register key, register value)\n");
+	fprintf(fp, "// Structure: account ID, username, password, sex, email, level, state, unban time, expiration time, # of logins, last login time, last (accepted) login ip, birth date, repeated(register key, register value)\n");
 	fprintf(fp, "// where:\n");
 	fprintf(fp, "//   sex             : M or F for normal accounts, S for server accounts\n");
 	fprintf(fp, "//   level           : this account's gm level\n");

+ 1 - 0
src/login/login.c

@@ -912,6 +912,7 @@ int mmo_auth_new(const char* userid, const char* pass, const char sex, const cha
 	acc.expiration_time = ( login_config.start_limited_time != -1 ) ? time(NULL) + login_config.start_limited_time : 0;
 	safestrncpy(acc.lastlogin, "0000-00-00 00:00:00", sizeof(acc.lastlogin));
 	safestrncpy(acc.last_ip, last_ip, sizeof(acc.last_ip));
+	safestrncpy(acc.birthdate, "0000-00-00", sizeof(acc.birthdate));
 
 	if( !accounts->create(accounts, &acc) )
 		return 0;