summaryrefslogtreecommitdiff
path: root/src/login
diff options
context:
space:
mode:
Diffstat (limited to 'src/login')
-rw-r--r--src/login/account.h3
-rw-r--r--src/login/account_sql.c9
-rw-r--r--src/login/account_txt.c31
-rw-r--r--src/login/login.c1
4 files changed, 35 insertions, 9 deletions
diff --git a/src/login/account.h b/src/login/account.h
index 4cc9b353b..650f2c661 100644
--- a/src/login/account.h
+++ b/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)
};
diff --git a/src/login/account_sql.c b/src/login/account_sql.c
index c2f4a9965..e3e725efa 100644
--- a/src/login/account_sql.c
+++ b/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);
diff --git a/src/login/account_txt.c b/src/login/account_txt.c
index ba3388c57..758a2c24e 100644
--- a/src/login/account_txt.c
+++ b/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");
diff --git a/src/login/login.c b/src/login/login.c
index e6bb13f19..6a8525930 100644
--- a/src/login/login.c
+++ b/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;