diff options
Diffstat (limited to 'src/login_sql')
-rw-r--r-- | src/login_sql/login.c | 56 | ||||
-rw-r--r-- | src/login_sql/login.h | 43 |
2 files changed, 48 insertions, 51 deletions
diff --git a/src/login_sql/login.c b/src/login_sql/login.c index e104d0367..281d2a09b 100644 --- a/src/login_sql/login.c +++ b/src/login_sql/login.c @@ -35,15 +35,16 @@ struct s_subnet { int subnet_count = 0; +// GM account management struct gm_account* gm_account_db = NULL; unsigned int GM_num = 0; // number of gm accounts //Account registration flood protection [Kevin] int allowed_regs = 1; int time_allowed = 10; //in seconds -unsigned int new_reg_tick = 0; -int num_regs = 0; + +// data handling (SQL) Sql* sql_handle; // database parameters @@ -66,6 +67,9 @@ char login_db_user_pass[256] = "user_pass"; char login_db_level[256] = "level"; +//----------------------------------------------------- +// Session data structure +//----------------------------------------------------- struct login_session_data { uint16 md5keylen; char md5key[20]; @@ -386,8 +390,12 @@ bool check_password(struct login_session_data* ld, int passwdenc, const char* pa //----------------------------------------------------- int mmo_auth_new(struct mmo_account* account, char sex) { + static int num_regs = 0; // registration counter + static unsigned int new_reg_tick = gettick(); + unsigned int tick = gettick(); char md5buf[32+1]; + time_t connect_until = 0; SqlStmt* stmt; int result = 0; @@ -413,10 +421,13 @@ int mmo_auth_new(struct mmo_account* account, char sex) if( result ) return result;// error or incorrect user/pass + if( login_config.start_limited_time != -1 ) + connect_until = time(NULL) + login_config.start_limited_time; + // insert new entry into db //TODO: error checking stmt = SqlStmt_Malloc(sql_handle); - SqlStmt_Prepare(stmt, "INSERT INTO `%s` (`%s`, `%s`, `sex`, `email`) VALUES (?, ?, '%c', 'a@a.com')", login_db, login_db_userid, login_db_user_pass, TOUPPER(sex)); + SqlStmt_Prepare(stmt, "INSERT INTO `%s` (`%s`, `%s`, `sex`, `email`, `connect_until`) VALUES (?, ?, '%c', 'a@a.com', '%d')", login_db, login_db_userid, login_db_user_pass, TOUPPER(sex), connect_until); SqlStmt_BindParam(stmt, 0, SQLDT_STRING, account->userid, strnlen(account->userid, NAME_LENGTH)); if( login_config.use_md5_passwds ) { @@ -426,9 +437,9 @@ int mmo_auth_new(struct mmo_account* account, char sex) else SqlStmt_BindParam(stmt, 1, SQLDT_STRING, account->passwd, strnlen(account->passwd, NAME_LENGTH)); SqlStmt_Execute(stmt); - SqlStmt_Free(stmt); - ShowInfo("New account: userid='%s' passwd='%s' sex='%c'\n", account->userid, account->passwd, TOUPPER(sex)); + ShowNotice("Account creation (account %s, id: %d, pass: %s, sex: %c, connection with _M/_F)\n", account->userid, SqlStmt_LastInsertId(stmt), account->passwd, TOUPPER(sex)); + SqlStmt_Free(stmt); if( DIFF_TICK(tick, new_reg_tick) > 0 ) {// Update the registration check. @@ -600,7 +611,8 @@ static int online_db_setoffline(DBKey key, void* data, va_list ap) //-------------------------------- int parse_fromchar(int fd) { - int i, id; + unsigned int i; + int id; uint32 ipl; char ip[16]; @@ -786,25 +798,6 @@ int parse_fromchar(int fd) WFIFOSET(fd,2); break; - case 0x2720: // Request to become a GM - if( RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2) ) - return 0; - { - int acc = RFIFOL(fd,4); - RFIFOSKIP(fd, RFIFOW(fd,2)); - - ShowWarning("change GM isn't supported in this login server version.\n"); - ShowError("change GM error 0 %s\n", RFIFOP(fd,8)); - - // announce gm level update result - WFIFOHEAD(fd,10); - WFIFOW(fd,0) = 0x2721; - WFIFOL(fd,2) = acc; - WFIFOL(fd,6) = 0; // level - WFIFOSET(fd,10); - } - break; - // Map server send information to change an email of an account via char-server case 0x2722: // 0x2722 <account_id>.L <actual_e-mail>.40B <new_e-mail>.40B if (RFIFOREST(fd) < 86) @@ -1404,7 +1397,7 @@ void login_auth_failed(struct mmo_account* account, int fd, int result) int parse_login(int fd) { struct mmo_account account; - int result, i; + int result; uint32 ipl; char ip[16]; @@ -1471,14 +1464,16 @@ int parse_login(int fd) account.version = RFIFOL(fd,2); safestrncpy(account.userid, (char*)RFIFOP(fd,6), NAME_LENGTH);//## does it have to be nul-terminated? if (command != 0x01dd) { + ShowStatus("Request for connection of %s (ip: %s).\n", account.userid, ip); safestrncpy(account.passwd, (char*)RFIFOP(fd,30), NAME_LENGTH);//## does it have to be nul-terminated? + account.passwdenc = 0; } else { + ShowStatus("Request for connection (encryption mode) of %s (ip: %s).\n", account.userid, ip); memcpy(account.passwd, RFIFOP(fd,30), 16); account.passwd[16] = '\0'; // raw binary data here! + account.passwdenc = PASSWORDENC; } RFIFOSKIP(fd,packet_len); - account.passwdenc = (command == 0x01dd) ? PASSWORDENC : 0; - result = mmo_auth(&account, fd); if( result == -1 ) @@ -1492,6 +1487,7 @@ int parse_login(int fd) RFIFOSKIP(fd,2); { struct login_session_data* ld; + unsigned int i; if( session[fd]->session_data ) { ShowWarning("login: abnormal request of MD5 key (already opened session).\n"); @@ -1777,6 +1773,8 @@ int login_config_read(const char* cfgName) else if(!strcmpi(w1, "new_account")) login_config.new_account_flag = (bool)config_switch(w2); + else if(!strcmpi(w1, "start_limited_time")) + login_config.start_limited_time = atoi(w2); else if(!strcmpi(w1, "check_client_version")) login_config.check_client_version = (bool)config_switch(w2); else if(!strcmpi(w1, "client_version_to_connect")) @@ -1980,8 +1978,6 @@ int do_init(int argc, char** argv) //##TODO invoke a CONSOLE_START plugin event } - new_reg_tick = gettick(); - // server port open & binding login_fd = make_listen_bind(login_config.login_ip, login_config.login_port); diff --git a/src/login_sql/login.h b/src/login_sql/login.h index 02de3c0e8..babe47b82 100644 --- a/src/login_sql/login.h +++ b/src/login_sql/login.h @@ -39,28 +39,29 @@ struct mmo_char_server { extern struct Login_Config { - uint32 login_ip; // the address to bind to - uint16 login_port; // the port to bind to - unsigned int ip_sync_interval; // interval (in minutes) to execute a DNS/IP update (for dynamic IPs) - bool log_login; // whether to log login server actions or not - char date_format[32]; // date format used in messages - bool console; // console input system enabled? - bool new_account_flag; // autoregistration via _M/_F ? - bool case_sensitive; // are logins case sensitive ? - bool use_md5_passwds; // work with password hashes instead of plaintext passwords? - bool login_gm_read; // should the login server handle info about gm accounts? - int min_level_to_connect; // minimum level of player/GM (0: player, 1-99: GM) to connect - bool online_check; // reject incoming players that are already registered as online ? - bool check_client_version; // check the clientversion set in the clientinfo ? - int client_version_to_connect; // the client version needed to connect (if checking is enabled) + uint32 login_ip; // the address to bind to + uint16 login_port; // the port to bind to + unsigned int ip_sync_interval; // interval (in minutes) to execute a DNS/IP update (for dynamic IPs) + bool log_login; // whether to log login server actions or not + char date_format[32]; // date format used in messages + bool console; // console input system enabled? + bool new_account_flag; // autoregistration via _M/_F ? + int start_limited_time; // new account expiration time (-1: unlimited) + bool case_sensitive; // are logins case sensitive ? + bool use_md5_passwds; // work with password hashes instead of plaintext passwords? + bool login_gm_read; // should the login server handle info about gm accounts? + int min_level_to_connect; // minimum level of player/GM (0: player, 1-99: GM) to connect + bool online_check; // reject incoming players that are already registered as online ? + bool check_client_version; // check the clientversion set in the clientinfo ? + int client_version_to_connect; // the client version needed to connect (if checking is enabled) - bool ipban; // perform IP blocking (via contents of `ipbanlist`) ? - bool dynamic_pass_failure_ban; // automatic IP blocking due to failed login attemps ? - unsigned int dynamic_pass_failure_ban_interval; // how far to scan the loginlog for password failures - unsigned int dynamic_pass_failure_ban_limit; // number of failures needed to trigger the ipban - unsigned int dynamic_pass_failure_ban_duration; // duration of the ipban - bool use_dnsbl; // dns blacklist blocking ? - char dnsbl_servs[1024]; // comma-separated list of dnsbl servers + bool ipban; // perform IP blocking (via contents of `ipbanlist`) ? + bool dynamic_pass_failure_ban; // automatic IP blocking due to failed login attemps ? + unsigned int dynamic_pass_failure_ban_interval; // how far to scan the loginlog for password failures + unsigned int dynamic_pass_failure_ban_limit; // number of failures needed to trigger the ipban + unsigned int dynamic_pass_failure_ban_duration; // duration of the ipban + bool use_dnsbl; // dns blacklist blocking ? + char dnsbl_servs[1024]; // comma-separated list of dnsbl servers } login_config; |