summaryrefslogtreecommitdiff
path: root/src/login
diff options
context:
space:
mode:
Diffstat (limited to 'src/login')
-rw-r--r--src/login/Makefile.in2
-rw-r--r--src/login/account_sql.c12
-rw-r--r--src/login/ipban_sql.c34
-rw-r--r--src/login/login.c261
-rw-r--r--src/login/login.h5
-rw-r--r--src/login/loginlog_sql.c2
6 files changed, 158 insertions, 158 deletions
diff --git a/src/login/Makefile.in b/src/login/Makefile.in
index 022831fb5..6560e6497 100644
--- a/src/login/Makefile.in
+++ b/src/login/Makefile.in
@@ -106,7 +106,7 @@ login-server: ../../login-server@EXEEXT@
../../login-server@EXEEXT@: $(LOGIN_SERVER_SQL_DEPENDS) Makefile
@echo " LD $(notdir $@)"
@$(CC) @STATIC@ @LDFLAGS@ -o ../../login-server@EXEEXT@ $(LOGIN_OBJ) $(COMMON_D)/obj_sql/common_sql.a \
- $(COMMON_D)/obj_all/common.a $(MT19937AR_OBJ) $(LIBCONFIG_OBJ) @LIBS@ @PCRE_LIBS@ @MYSQL_LIBS@
+ $(COMMON_D)/obj_all/common.a $(MT19937AR_OBJ) $(LIBCONFIG_OBJ) @LIBS@ @MYSQL_LIBS@
# login object files
diff --git a/src/login/account_sql.c b/src/login/account_sql.c
index 1de0fb5e9..2a7401f1b 100644
--- a/src/login/account_sql.c
+++ b/src/login/account_sql.c
@@ -719,7 +719,7 @@ void mmo_save_accreg2(AccountDB* self, int fd, int account_id, int char_id) {
for (i = 0; i < count; i++) {
unsigned int index;
int len = RFIFOB(fd, cursor);
- safestrncpy(key, (char*)RFIFOP(fd, cursor + 1), min((int)sizeof(key), len));
+ safestrncpy(key, RFIFOP(fd, cursor + 1), min((int)sizeof(key), len));
cursor += len + 1;
index = RFIFOL(fd, cursor);
@@ -728,7 +728,7 @@ void mmo_save_accreg2(AccountDB* self, int fd, int account_id, int char_id) {
switch (RFIFOB(fd, cursor++)) {
/* int */
case 0:
- if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`account_id`,`key`,`index`,`value`) VALUES ('%d','%s','%u','%d')", db->global_acc_reg_num_db, account_id, key, index, RFIFOL(fd, cursor)) )
+ if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`account_id`,`key`,`index`,`value`) VALUES ('%d','%s','%u','%u')", db->global_acc_reg_num_db, account_id, key, index, RFIFOL(fd, cursor)) )
Sql_ShowDebug(sql_handle);
cursor += 4;
break;
@@ -739,7 +739,7 @@ void mmo_save_accreg2(AccountDB* self, int fd, int account_id, int char_id) {
/* str */
case 2:
len = RFIFOB(fd, cursor);
- safestrncpy(sval, (char*)RFIFOP(fd, cursor + 1), min((int)sizeof(sval), len));
+ safestrncpy(sval, RFIFOP(fd, cursor + 1), min((int)sizeof(sval), len));
cursor += len + 1;
if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`account_id`,`key`,`index`,`value`) VALUES ('%d','%s','%u','%s')", db->global_acc_reg_str_db, account_id, key, index, sval) )
Sql_ShowDebug(sql_handle);
@@ -791,7 +791,7 @@ void mmo_send_accreg2(AccountDB* self, int fd, int account_id, int char_id) {
WFIFOB(fd, plen) = (unsigned char)len;/* won't be higher; the column size is 32 */
plen += 1;
- safestrncpy((char*)WFIFOP(fd,plen), data, len);
+ safestrncpy(WFIFOP(fd,plen), data, len);
plen += len;
SQL->GetData(sql_handle, 1, &data, NULL);
@@ -805,7 +805,7 @@ void mmo_send_accreg2(AccountDB* self, int fd, int account_id, int char_id) {
WFIFOB(fd, plen) = (unsigned char)len;/* won't be higher; the column size is 254 */
plen += 1;
- safestrncpy((char*)WFIFOP(fd,plen), data, len);
+ safestrncpy(WFIFOP(fd,plen), data, len);
plen += len;
WFIFOW(fd, 14) += 1;
@@ -859,7 +859,7 @@ void mmo_send_accreg2(AccountDB* self, int fd, int account_id, int char_id) {
WFIFOB(fd, plen) = (unsigned char)len;/* won't be higher; the column size is 32 */
plen += 1;
- safestrncpy((char*)WFIFOP(fd,plen), data, len);
+ safestrncpy(WFIFOP(fd,plen), data, len);
plen += len;
SQL->GetData(sql_handle, 1, &data, NULL);
diff --git a/src/login/ipban_sql.c b/src/login/ipban_sql.c
index 090886e93..301d22c18 100644
--- a/src/login/ipban_sql.c
+++ b/src/login/ipban_sql.c
@@ -68,7 +68,7 @@ void ipban_init(void)
ipban_inited = true;
- if( !login_config.ipban )
+ if (!login->config->ipban)
return;// ipban disabled
if( ipban_db_hostname[0] != '\0' )
@@ -101,10 +101,10 @@ void ipban_init(void)
if( codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, codepage) )
Sql_ShowDebug(sql_handle);
- if( login_config.ipban_cleanup_interval > 0 )
+ if (login->config->ipban_cleanup_interval > 0)
{ // set up periodic cleanup of connection history and active bans
timer->add_func_list(ipban_cleanup, "ipban_cleanup");
- cleanup_timer_id = timer->add_interval(timer->gettick()+10, ipban_cleanup, 0, 0, login_config.ipban_cleanup_interval*1000);
+ cleanup_timer_id = timer->add_interval(timer->gettick()+10, ipban_cleanup, 0, 0, login->config->ipban_cleanup_interval*1000);
} else // make sure it gets cleaned up on login-server start regardless of interval-based cleanups
ipban_cleanup(0,0,0,0);
}
@@ -112,10 +112,10 @@ void ipban_init(void)
// finalize
void ipban_final(void)
{
- if( !login_config.ipban )
+ if (!login->config->ipban)
return;// ipban disabled
- if( login_config.ipban_cleanup_interval > 0 )
+ if (login->config->ipban_cleanup_interval > 0)
// release data
timer->delete(cleanup_timer_id, ipban_cleanup);
@@ -196,19 +196,19 @@ bool ipban_config_read(const char* key, const char* value)
{
key += strlen(signature);
if( strcmpi(key, "enable") == 0 )
- login_config.ipban = (bool)config_switch(value);
+ login->config->ipban = (bool)config_switch(value);
else
if( strcmpi(key, "dynamic_pass_failure_ban") == 0 )
- login_config.dynamic_pass_failure_ban = (bool)config_switch(value);
+ login->config->dynamic_pass_failure_ban = (bool)config_switch(value);
else
if( strcmpi(key, "dynamic_pass_failure_ban_interval") == 0 )
- login_config.dynamic_pass_failure_ban_interval = atoi(value);
+ login->config->dynamic_pass_failure_ban_interval = atoi(value);
else
if( strcmpi(key, "dynamic_pass_failure_ban_limit") == 0 )
- login_config.dynamic_pass_failure_ban_limit = atoi(value);
+ login->config->dynamic_pass_failure_ban_limit = atoi(value);
else
if( strcmpi(key, "dynamic_pass_failure_ban_duration") == 0 )
- login_config.dynamic_pass_failure_ban_duration = atoi(value);
+ login->config->dynamic_pass_failure_ban_duration = atoi(value);
else
return false;// not found
return true;
@@ -224,7 +224,7 @@ bool ipban_check(uint32 ip)
char* data = NULL;
int matches;
- if( !login_config.ipban )
+ if (!login->config->ipban)
return false;// ipban disabled
if( SQL_ERROR == SQL->Query(sql_handle, "SELECT count(*) FROM `%s` WHERE `rtime` > NOW() AND (`list` = '%u.*.*.*' OR `list` = '%u.%u.*.*' OR `list` = '%u.%u.%u.*' OR `list` = '%u.%u.%u.%u')",
@@ -250,17 +250,17 @@ void ipban_log(uint32 ip)
{
unsigned long failures;
- if( !login_config.ipban )
+ if (!login->config->ipban)
return;// ipban disabled
- failures = loginlog_failedattempts(ip, login_config.dynamic_pass_failure_ban_interval);// how many times failed account? in one ip.
+ failures = loginlog_failedattempts(ip, login->config->dynamic_pass_failure_ban_interval);// how many times failed account? in one ip.
// if over the limit, add a temporary ban entry
- if( failures >= login_config.dynamic_pass_failure_ban_limit )
+ if (failures >= login->config->dynamic_pass_failure_ban_limit)
{
uint8* p = (uint8*)&ip;
- if (SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s`(`list`,`btime`,`rtime`,`reason`) VALUES ('%u.%u.%u.*', NOW() , NOW() + INTERVAL %d MINUTE ,'Password error ban')",
- ipban_table, p[3], p[2], p[1], login_config.dynamic_pass_failure_ban_duration))
+ if (SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s`(`list`,`btime`,`rtime`,`reason`) VALUES ('%u.%u.%u.*', NOW() , NOW() + INTERVAL %u MINUTE ,'Password error ban')",
+ ipban_table, p[3], p[2], p[1], login->config->dynamic_pass_failure_ban_duration))
{
Sql_ShowDebug(sql_handle);
}
@@ -269,7 +269,7 @@ void ipban_log(uint32 ip)
// remove expired bans
int ipban_cleanup(int tid, int64 tick, int id, intptr_t data) {
- if( !login_config.ipban )
+ if (!login->config->ipban)
return 0;// ipban disabled
if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `rtime` <= NOW()", ipban_table) )
diff --git a/src/login/login.c b/src/login/login.c
index e478d0252..bd826b300 100644
--- a/src/login/login.c
+++ b/src/login/login.c
@@ -28,7 +28,6 @@
#include "login/loginlog.h"
#include "common/HPM.h"
#include "common/cbasetypes.h"
-#include "common/conf.h"
#include "common/core.h"
#include "common/db.h"
#include "common/memmgr.h"
@@ -46,7 +45,7 @@
struct login_interface login_s;
struct login_interface *login;
-struct Login_Config login_config;
+struct Login_Config login_config_;
struct mmo_char_server server[MAX_SERVERS]; // char server data
struct Account_engine account_engine[] = {
@@ -353,7 +352,7 @@ void login_fromchar_parse_request_change_email(int fd, int id, const char *const
char email[40];
int account_id = RFIFOL(fd,2);
- safestrncpy(email, (char*)RFIFOP(fd,6), 40); remove_control_chars(email);
+ safestrncpy(email, RFIFOP(fd,6), 40); remove_control_chars(email);
RFIFOSKIP(fd,46);
if( e_mail_check(email) == 0 )
@@ -392,22 +391,22 @@ void login_fromchar_account(int fd, int account_id, struct mmo_account *acc)
if (pincode[0] == '\0')
memset(pincode,'\0',sizeof(pincode));
- safestrncpy((char*)WFIFOP(fd,6), email, 40);
+ safestrncpy(WFIFOP(fd,6), email, 40);
WFIFOL(fd,46) = (uint32)expiration_time;
WFIFOB(fd,50) = (unsigned char)group_id;
WFIFOB(fd,51) = char_slots;
- safestrncpy((char*)WFIFOP(fd,52), birthdate, 10+1);
- safestrncpy((char*)WFIFOP(fd,63), pincode, 4+1 );
+ safestrncpy(WFIFOP(fd,52), birthdate, 10+1);
+ safestrncpy(WFIFOP(fd,63), pincode, 4+1 );
WFIFOL(fd,68) = acc->pincode_change;
}
else
{
- safestrncpy((char*)WFIFOP(fd,6), "", 40);
+ safestrncpy(WFIFOP(fd,6), "", 40);
WFIFOL(fd,46) = 0;
WFIFOB(fd,50) = 0;
WFIFOB(fd,51) = 0;
- safestrncpy((char*)WFIFOP(fd,52), "", 10+1);
- safestrncpy((char*)WFIFOP(fd,63), "\0\0\0\0", 4+1 );
+ safestrncpy(WFIFOP(fd,52), "", 10+1);
+ safestrncpy(WFIFOP(fd,63), "\0\0\0\0", 4+1 );
WFIFOL(fd,68) = 0;
}
WFIFOSET(fd,72);
@@ -450,8 +449,8 @@ void login_fromchar_parse_change_email(int fd, int id, const char *const ip)
char new_email[40];
int account_id = RFIFOL(fd,2);
- safestrncpy(actual_email, (char*)RFIFOP(fd,6), 40);
- safestrncpy(new_email, (char*)RFIFOP(fd,46), 40);
+ safestrncpy(actual_email, RFIFOP(fd,6), 40);
+ safestrncpy(new_email, RFIFOP(fd,46), 40);
RFIFOSKIP(fd, 86);
if( e_mail_check(actual_email) == 0 )
@@ -495,12 +494,12 @@ void login_fromchar_parse_account_update(int fd, int id, const char *const ip)
RFIFOSKIP(fd,10);
if( !accounts->load_num(accounts, &acc, account_id) )
- ShowNotice("Char-server '%s': Error of Status change (account: %d not found, suggested status %d, ip: %s).\n", server[id].name, account_id, state, ip);
+ ShowNotice("Char-server '%s': Error of Status change (account: %d not found, suggested status %u, ip: %s).\n", server[id].name, account_id, state, ip);
else
if( acc.state == state )
- ShowNotice("Char-server '%s': Error of Status change - actual status is already the good status (account: %d, status %d, ip: %s).\n", server[id].name, account_id, state, ip);
+ ShowNotice("Char-server '%s': Error of Status change - actual status is already the good status (account: %d, status %u, ip: %s).\n", server[id].name, account_id, state, ip);
else {
- ShowNotice("Char-server '%s': Status change (account: %d, new status %d, ip: %s).\n", server[id].name, account_id, state, ip);
+ ShowNotice("Char-server '%s': Status change (account: %d, new status %u, ip: %s).\n", server[id].name, account_id, state, ip);
acc.state = state;
// Save
@@ -528,12 +527,12 @@ void login_fromchar_parse_ban(int fd, int id, const char *const ip)
struct mmo_account acc;
int account_id = RFIFOL(fd,2);
- int year = (short)RFIFOW(fd,6);
- int month = (short)RFIFOW(fd,8);
- int mday = (short)RFIFOW(fd,10);
- int hour = (short)RFIFOW(fd,12);
- int min = (short)RFIFOW(fd,14);
- int sec = (short)RFIFOW(fd,16);
+ int year = RFIFOW(fd,6);
+ int month = RFIFOW(fd,8);
+ int mday = RFIFOW(fd,10);
+ int hour = RFIFOW(fd,12);
+ int min = RFIFOW(fd,14);
+ int sec = RFIFOW(fd,16);
RFIFOSKIP(fd,18);
if (!accounts->load_num(accounts, &acc, account_id)) {
@@ -559,7 +558,7 @@ void login_fromchar_parse_ban(int fd, int id, const char *const ip)
ShowNotice("Char-server '%s': Error of ban request (account: %d, new date unbans the account, ip: %s).\n", server[id].name, account_id, ip);
} else {
char tmpstr[24];
- timestamp2string(tmpstr, sizeof(tmpstr), timestamp, login_config.date_format);
+ timestamp2string(tmpstr, sizeof(tmpstr), timestamp, login->config->date_format);
ShowNotice("Char-server '%s': Ban request (account: %d, new final date of banishment: %ld (%s), ip: %s).\n",
server[id].name, account_id, (long)timestamp, tmpstr, ip);
@@ -684,7 +683,7 @@ void login_fromchar_parse_request_account_reg2(int fd)
void login_fromchar_parse_update_wan_ip(int fd, int id)
{
server[id].ip = ntohl(RFIFOL(fd,2));
- ShowInfo("Updated IP of Server #%d to %d.%d.%d.%d.\n",id, CONVIP(server[id].ip));
+ ShowInfo("Updated IP of Server #%d to %u.%u.%u.%u.\n",id, CONVIP(server[id].ip));
RFIFOSKIP(fd,6);
}
@@ -700,7 +699,7 @@ void login_fromchar_parse_change_pincode(int fd)
struct mmo_account acc;
if (accounts->load_num(accounts, &acc, RFIFOL(fd,2))) {
- safestrncpy(acc.pincode, (char*)RFIFOP(fd,6), sizeof(acc.pincode));
+ safestrncpy(acc.pincode, RFIFOP(fd,6), sizeof(acc.pincode));
acc.pincode_change = ((unsigned int)time(NULL));
accounts->save(accounts, &acc);
}
@@ -733,22 +732,22 @@ void login_fromchar_accinfo(int fd, int account_id, int u_fd, int u_aid, int u_g
{
WFIFOHEAD(fd,183);
WFIFOW(fd,0) = 0x2737;
- safestrncpy((char*)WFIFOP(fd,2), acc->userid, NAME_LENGTH);
+ safestrncpy(WFIFOP(fd,2), acc->userid, NAME_LENGTH);
if (u_group >= acc->group_id)
- safestrncpy((char*)WFIFOP(fd,26), acc->pass, 33);
+ safestrncpy(WFIFOP(fd,26), acc->pass, 33);
else
memset(WFIFOP(fd,26), '\0', 33);
- safestrncpy((char*)WFIFOP(fd,59), acc->email, 40);
- safestrncpy((char*)WFIFOP(fd,99), acc->last_ip, 16);
+ safestrncpy(WFIFOP(fd,59), acc->email, 40);
+ safestrncpy(WFIFOP(fd,99), acc->last_ip, 16);
WFIFOL(fd,115) = acc->group_id;
- safestrncpy((char*)WFIFOP(fd,119), acc->lastlogin, 24);
+ safestrncpy(WFIFOP(fd,119), acc->lastlogin, 24);
WFIFOL(fd,143) = acc->logincount;
WFIFOL(fd,147) = acc->state;
if (u_group >= acc->group_id)
- safestrncpy((char*)WFIFOP(fd,151), acc->pincode, 5);
+ safestrncpy(WFIFOP(fd,151), acc->pincode, 5);
else
memset(WFIFOP(fd,151), '\0', 5);
- safestrncpy((char*)WFIFOP(fd,156), acc->birthdate, 11);
+ safestrncpy(WFIFOP(fd,156), acc->birthdate, 11);
WFIFOL(fd,167) = map_fd;
WFIFOL(fd,171) = u_fd;
WFIFOL(fd,175) = u_aid;
@@ -808,18 +807,18 @@ int login_parse_fromchar(int fd)
ipl = server[id].ip;
sockt->ip2str(ipl, ip);
- while( RFIFOREST(fd) >= 2 ) {
+ while (RFIFOREST(fd) >= 2) {
uint16 command = RFIFOW(fd,0);
if (VECTOR_LENGTH(HPM->packets[hpParse_FromChar]) > 0) {
- int result = HPM->parse_packets(fd,hpParse_FromChar);
+ int result = HPM->parse_packets(fd,command,hpParse_FromChar);
if (result == 1)
continue;
if (result == 2)
return 0;
}
- switch( command ) {
+ switch (command) {
case 0x2712: // request from char-server to authenticate an account
if( RFIFOREST(fd) < 23 )
@@ -995,12 +994,12 @@ int login_mmo_auth_new(const char* userid, const char* pass, const char sex, con
//Account Registration Flood Protection by [Kevin]
if( new_reg_tick == 0 )
new_reg_tick = timer->gettick();
- if( DIFF_TICK(tick, new_reg_tick) < 0 && num_regs >= login_config.allowed_regs ) {
+ if (DIFF_TICK(tick, new_reg_tick) < 0 && num_regs >= login->config->allowed_regs) {
ShowNotice("Account registration denied (registration limit exceeded)\n");
return 3;
}
- if( login_config.new_acc_length_limit && ( strlen(userid) < 4 || strlen(pass) < 4 ) )
+ if (login->config->new_acc_length_limit && (strlen(userid) < 4 || strlen(pass) < 4))
return 1;
// check for invalid inputs
@@ -1019,7 +1018,7 @@ int login_mmo_auth_new(const char* userid, const char* pass, const char sex, con
safestrncpy(acc.pass, pass, sizeof(acc.pass));
acc.sex = sex;
safestrncpy(acc.email, "a@a.com", sizeof(acc.email));
- acc.expiration_time = ( login_config.start_limited_time != -1 ) ? time(NULL) + login_config.start_limited_time : 0;
+ 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));
@@ -1034,7 +1033,7 @@ int login_mmo_auth_new(const char* userid, const char* pass, const char sex, con
if( DIFF_TICK(tick, new_reg_tick) > 0 ) {// Update the registration check.
num_regs = 0;
- new_reg_tick = tick + login_config.time_allowed*1000;
+ new_reg_tick = tick + login->config->time_allowed*1000;
}
++num_regs;
@@ -1054,7 +1053,7 @@ int login_mmo_auth(struct login_session_data* sd, bool isServer) {
sockt->ip2str(sockt->session[sd->fd]->client_addr, ip);
// DNS Blacklist check
- if( login_config.use_dnsbl ) {
+ if (login->config->use_dnsbl) {
char r_ip[16];
char ip_dnsbl[256];
char* dnsbl_serv;
@@ -1062,7 +1061,7 @@ int login_mmo_auth(struct login_session_data* sd, bool isServer) {
sprintf(r_ip, "%u.%u.%u.%u", sin_addr[0], sin_addr[1], sin_addr[2], sin_addr[3]);
- for( dnsbl_serv = strtok(login_config.dnsbl_servs,","); dnsbl_serv != NULL; dnsbl_serv = strtok(NULL,",") ) {
+ for (dnsbl_serv = strtok(login->config->dnsbl_servs,","); dnsbl_serv != NULL; dnsbl_serv = strtok(NULL,",")) {
sprintf(ip_dnsbl, "%s.%s", r_ip, trim(dnsbl_serv));
if (sockt->host2ip(ip_dnsbl)) {
ShowInfo("DNSBL: (%s) Blacklisted. User Kicked.\n", r_ip);
@@ -1073,13 +1072,13 @@ int login_mmo_auth(struct login_session_data* sd, bool isServer) {
}
//Client Version check
- if( login_config.check_client_version && sd->version != login_config.client_version_to_connect )
+ if (login->config->check_client_version && sd->version != login->config->client_version_to_connect)
return 5;
len = strnlen(sd->userid, NAME_LENGTH);
// Account creation with _M/_F
- if( login_config.new_account_flag ) {
+ if (login->config->new_account_flag) {
if (len > 2 && sd->passwd[0] != '\0' && // valid user and password lengths
sd->passwdenc == PWENC_NONE && // unencoded password
sd->userid[len-2] == '_' && memchr("FfMm", sd->userid[len-1], 4)) // _M/_F suffix
@@ -1113,21 +1112,21 @@ int login_mmo_auth(struct login_session_data* sd, bool isServer) {
if( acc.unban_time != 0 && acc.unban_time > time(NULL) ) {
char tmpstr[24];
- timestamp2string(tmpstr, sizeof(tmpstr), acc.unban_time, login_config.date_format);
+ timestamp2string(tmpstr, sizeof(tmpstr), acc.unban_time, login->config->date_format);
ShowNotice("Connection refused (account: %s, pass: %s, banned until %s, ip: %s)\n", sd->userid, sd->passwd, tmpstr, ip);
return 6; // 6 = Your are Prohibited to log in until %s
}
if( acc.state != 0 ) {
- ShowNotice("Connection refused (account: %s, pass: %s, state: %d, ip: %s)\n", sd->userid, sd->passwd, acc.state, ip);
+ ShowNotice("Connection refused (account: %s, pass: %s, state: %u, ip: %s)\n", sd->userid, sd->passwd, acc.state, ip);
return acc.state - 1;
}
- if( login_config.client_hash_check && !isServer ) {
+ if (login->config->client_hash_check && !isServer) {
struct client_hash_node *node = NULL;
bool match = false;
- for( node = login_config.client_hash_nodes; node; node = node->next ) {
+ for (node = login->config->client_hash_nodes; node; node = node->next) {
if( acc.group_id < node->group_id )
continue;
if( *node->hash == '\0' // Allowed to login without hash
@@ -1216,12 +1215,12 @@ void login_auth_ok(struct login_session_data* sd)
return;
}
- if( login_config.group_id_to_connect >= 0 && sd->group_id != login_config.group_id_to_connect ) {
- ShowStatus("Connection refused: the required group id for connection is %d (account: %s, group: %d).\n", login_config.group_id_to_connect, sd->userid, sd->group_id);
+ if (login->config->group_id_to_connect >= 0 && sd->group_id != login->config->group_id_to_connect) {
+ ShowStatus("Connection refused: the required group id for connection is %d (account: %s, group: %d).\n", login->config->group_id_to_connect, sd->userid, sd->group_id);
login->connection_problem(fd, 1); // 01 = server closed
return;
- } else if( login_config.min_group_id_to_connect >= 0 && login_config.group_id_to_connect == -1 && sd->group_id < login_config.min_group_id_to_connect ) {
- ShowStatus("Connection refused: the minimum group id required for connection is %d (account: %s, group: %d).\n", login_config.min_group_id_to_connect, sd->userid, sd->group_id);
+ } else if (login->config->min_group_id_to_connect >= 0 && login->config->group_id_to_connect == -1 && sd->group_id < login->config->min_group_id_to_connect) {
+ ShowStatus("Connection refused: the minimum group id required for connection is %d (account: %s, group: %d).\n", login->config->min_group_id_to_connect, sd->userid, sd->group_id);
login->connection_problem(fd, 1); // 01 = server closed
return;
}
@@ -1331,8 +1330,7 @@ void login_auth_failed(struct login_session_data* sd, int result)
fd = sd->fd;
ip = sockt->session[fd]->client_addr;
- if (login_config.log_login)
- {
+ if (login->config->log_login) {
const char* error;
switch( result ) {
case 0: error = "Unregistered ID."; break; // 0 = Unregistered ID
@@ -1363,7 +1361,7 @@ void login_auth_failed(struct login_session_data* sd, int result)
login_log(ip, sd->userid, result, error); // FIXME: result can be 100, conflicting with the value 100 we use for successful login...
}
- if (result == 1 && login_config.dynamic_pass_failure_ban && !sockt->trusted_ip_check(ip))
+ if (result == 1 && login->config->dynamic_pass_failure_ban && !sockt->trusted_ip_check(ip))
ipban_log(ip); // log failed password attempt
#if PACKETVER >= 20120000 /* not sure when this started */
@@ -1375,7 +1373,7 @@ void login_auth_failed(struct login_session_data* sd, int result)
else { // 6 = Your are Prohibited to log in until %s
struct mmo_account acc;
time_t unban_time = ( accounts->load_str(accounts, &acc, sd->userid) ) ? acc.unban_time : 0;
- timestamp2string((char*)WFIFOP(fd,6), 20, unban_time, login_config.date_format);
+ timestamp2string(WFIFOP(fd,6), 20, unban_time, login->config->date_format);
}
WFIFOSET(fd,26);
#else
@@ -1387,7 +1385,7 @@ void login_auth_failed(struct login_session_data* sd, int result)
else { // 6 = Your are Prohibited to log in until %s
struct mmo_account acc;
time_t unban_time = ( accounts->load_str(accounts, &acc, sd->userid) ) ? acc.unban_time : 0;
- timestamp2string((char*)WFIFOP(fd,3), 20, unban_time, login_config.date_format);
+ timestamp2string(WFIFOP(fd,3), 20, unban_time, login->config->date_format);
}
WFIFOSET(fd,23);
#endif
@@ -1431,8 +1429,8 @@ bool login_parse_client_login(int fd, struct login_session_data* sd, const char
// Shinryo: For the time being, just use token as password.
if(command == 0x0825)
{
- char *accname = (char *)RFIFOP(fd, 9);
- char *token = (char *)RFIFOP(fd, 0x5C);
+ const char *accname = RFIFOP(fd, 9);
+ const char *token = RFIFOP(fd, 0x5C);
size_t uAccLen = strlen(accname);
size_t uTokenLen = RFIFOREST(fd) - 0x5C;
@@ -1450,10 +1448,10 @@ bool login_parse_client_login(int fd, struct login_session_data* sd, const char
else
{
version = RFIFOL(fd,2);
- safestrncpy(username, (const char*)RFIFOP(fd,6), NAME_LENGTH);
+ safestrncpy(username, RFIFOP(fd,6), NAME_LENGTH);
if( israwpass )
{
- safestrncpy(password, (const char*)RFIFOP(fd,30), NAME_LENGTH);
+ safestrncpy(password, RFIFOP(fd,30), NAME_LENGTH);
clienttype = RFIFOB(fd,54);
}
else
@@ -1471,7 +1469,7 @@ bool login_parse_client_login(int fd, struct login_session_data* sd, const char
{
ShowStatus("Request for connection of %s (ip: %s).\n", sd->userid, ip);
safestrncpy(sd->passwd, password, PASSWD_LEN);
- if( login_config.use_md5_passwds )
+ if (login->config->use_md5_passwds)
MD5_String(sd->passwd, sd->passwd);
sd->passwdenc = PWENC_NONE;
}
@@ -1482,7 +1480,7 @@ bool login_parse_client_login(int fd, struct login_session_data* sd, const char
sd->passwdenc = PASSWORDENC;
}
- if (sd->passwdenc != PWENC_NONE && login_config.use_md5_passwds) {
+ if (sd->passwdenc != PWENC_NONE && login->config->use_md5_passwds) {
login->auth_failed(sd, 3); // send "rejected from server"
return true;
}
@@ -1536,15 +1534,15 @@ void login_parse_request_connection(int fd, struct login_session_data* sd, const
uint16 new_;
int result;
- safestrncpy(sd->userid, (char*)RFIFOP(fd,2), NAME_LENGTH);
- safestrncpy(sd->passwd, (char*)RFIFOP(fd,26), NAME_LENGTH);
- if( login_config.use_md5_passwds )
+ safestrncpy(sd->userid, RFIFOP(fd,2), NAME_LENGTH);
+ safestrncpy(sd->passwd, RFIFOP(fd,26), NAME_LENGTH);
+ if (login->config->use_md5_passwds)
MD5_String(sd->passwd, sd->passwd);
sd->passwdenc = PWENC_NONE;
- sd->version = login_config.client_version_to_connect; // hack to skip version check
+ sd->version = login->config->client_version_to_connect; // hack to skip version check
server_ip = ntohl(RFIFOL(fd,54));
server_port = ntohs(RFIFOW(fd,58));
- safestrncpy(server_name, (char*)RFIFOP(fd,60), 20);
+ safestrncpy(server_name, RFIFOP(fd,60), 20);
type = RFIFOW(fd,82);
new_ = RFIFOW(fd,84);
RFIFOSKIP(fd,86);
@@ -1606,8 +1604,7 @@ int login_parse_login(int fd)
if( sd == NULL )
{
// Perform ip-ban check
- if (login_config.ipban && !sockt->trusted_ip_check(ipl) && ipban_check(ipl))
- {
+ if (login->config->ipban && !sockt->trusted_ip_check(ipl) && ipban_check(ipl)) {
ShowStatus("Connection refused: IP isn't authorized (deny/allow, ip: %s).\n", ip);
login_log(ipl, "unknown", -3, "ip banned");
login->login_error(fd, 3); // 3 = Rejected from Server
@@ -1621,18 +1618,18 @@ int login_parse_login(int fd)
sd->fd = fd;
}
- while( RFIFOREST(fd) >= 2 ) {
+ while (RFIFOREST(fd) >= 2) {
uint16 command = RFIFOW(fd,0);
if (VECTOR_LENGTH(HPM->packets[hpParse_Login]) > 0) {
- int result = HPM->parse_packets(fd,hpParse_Login);
+ int result = HPM->parse_packets(fd,command,hpParse_Login);
if (result == 1)
continue;
if (result == 2)
return 0;
}
- switch( command ) {
+ switch (command) {
case 0x0200: // New alive packet: structure: 0x200 <account.userid>.24B. used to verify if client is always alive.
if (RFIFOREST(fd) < 26)
@@ -1701,40 +1698,40 @@ int login_parse_login(int fd)
}
-void login_set_defaults()
+void login_config_set_defaults(void)
{
- login_config.login_ip = INADDR_ANY;
- login_config.login_port = 6900;
- login_config.ipban_cleanup_interval = 60;
- login_config.ip_sync_interval = 0;
- login_config.log_login = true;
- safestrncpy(login_config.date_format, "%Y-%m-%d %H:%M:%S", sizeof(login_config.date_format));
- login_config.new_account_flag = true;
- login_config.new_acc_length_limit = true;
- login_config.use_md5_passwds = false;
- login_config.group_id_to_connect = -1;
- login_config.min_group_id_to_connect = -1;
- login_config.check_client_version = false;
- login_config.client_version_to_connect = 20;
- login_config.allowed_regs = 1;
- login_config.time_allowed = 10;
-
- login_config.ipban = true;
- login_config.dynamic_pass_failure_ban = true;
- login_config.dynamic_pass_failure_ban_interval = 5;
- login_config.dynamic_pass_failure_ban_limit = 7;
- login_config.dynamic_pass_failure_ban_duration = 5;
- login_config.use_dnsbl = false;
- safestrncpy(login_config.dnsbl_servs, "", sizeof(login_config.dnsbl_servs));
-
- login_config.client_hash_check = 0;
- login_config.client_hash_nodes = NULL;
+ login->config->login_ip = INADDR_ANY;
+ login->config->login_port = 6900;
+ login->config->ipban_cleanup_interval = 60;
+ login->config->ip_sync_interval = 0;
+ login->config->log_login = true;
+ safestrncpy(login->config->date_format, "%Y-%m-%d %H:%M:%S", sizeof(login->config->date_format));
+ login->config->new_account_flag = true;
+ login->config->new_acc_length_limit = true;
+ login->config->use_md5_passwds = false;
+ login->config->group_id_to_connect = -1;
+ login->config->min_group_id_to_connect = -1;
+ login->config->check_client_version = false;
+ login->config->client_version_to_connect = 20;
+ login->config->allowed_regs = 1;
+ login->config->time_allowed = 10;
+
+ login->config->ipban = true;
+ login->config->dynamic_pass_failure_ban = true;
+ login->config->dynamic_pass_failure_ban_interval = 5;
+ login->config->dynamic_pass_failure_ban_limit = 7;
+ login->config->dynamic_pass_failure_ban_duration = 5;
+ login->config->use_dnsbl = false;
+ safestrncpy(login->config->dnsbl_servs, "", sizeof(login->config->dnsbl_servs));
+
+ login->config->client_hash_check = 0;
+ login->config->client_hash_nodes = NULL;
}
//-----------------------------------
// 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;
@@ -1761,50 +1758,50 @@ int login_config_read(const char* cfgName)
ShowInfo("Console Silent Setting: %d\n", atoi(w2));
}
else if( !strcmpi(w1, "bind_ip") ) {
- login_config.login_ip = sockt->host2ip(w2);
- if( login_config.login_ip ) {
+ login->config->login_ip = sockt->host2ip(w2);
+ if (login->config->login_ip) {
char ip_str[16];
- ShowStatus("Login server binding IP address : %s -> %s\n", w2, sockt->ip2str(login_config.login_ip, ip_str));
+ ShowStatus("Login server binding IP address : %s -> %s\n", w2, sockt->ip2str(login->config->login_ip, ip_str));
}
}
else if( !strcmpi(w1, "login_port") ) {
- login_config.login_port = (uint16)atoi(w2);
+ login->config->login_port = (uint16)atoi(w2);
}
else if(!strcmpi(w1, "log_login"))
- login_config.log_login = (bool)config_switch(w2);
+ login->config->log_login = (bool)config_switch(w2);
else if(!strcmpi(w1, "new_account"))
- login_config.new_account_flag = (bool)config_switch(w2);
+ login->config->new_account_flag = (bool)config_switch(w2);
else if(!strcmpi(w1, "new_acc_length_limit"))
- login_config.new_acc_length_limit = (bool)config_switch(w2);
+ login->config->new_acc_length_limit = (bool)config_switch(w2);
else if(!strcmpi(w1, "start_limited_time"))
- login_config.start_limited_time = atoi(w2);
+ login->config->start_limited_time = atoi(w2);
else if(!strcmpi(w1, "check_client_version"))
- login_config.check_client_version = (bool)config_switch(w2);
+ login->config->check_client_version = (bool)config_switch(w2);
else if(!strcmpi(w1, "client_version_to_connect"))
- login_config.client_version_to_connect = (unsigned int)strtoul(w2, NULL, 10);
+ login->config->client_version_to_connect = (unsigned int)strtoul(w2, NULL, 10);
else if(!strcmpi(w1, "use_MD5_passwords"))
- login_config.use_md5_passwds = (bool)config_switch(w2);
+ login->config->use_md5_passwds = (bool)config_switch(w2);
else if(!strcmpi(w1, "group_id_to_connect"))
- login_config.group_id_to_connect = atoi(w2);
+ login->config->group_id_to_connect = atoi(w2);
else if(!strcmpi(w1, "min_group_id_to_connect"))
- login_config.min_group_id_to_connect = atoi(w2);
+ login->config->min_group_id_to_connect = atoi(w2);
else if(!strcmpi(w1, "date_format"))
- safestrncpy(login_config.date_format, w2, sizeof(login_config.date_format));
+ safestrncpy(login->config->date_format, w2, sizeof(login->config->date_format));
else if(!strcmpi(w1, "allowed_regs")) //account flood protection system
- login_config.allowed_regs = atoi(w2);
+ login->config->allowed_regs = atoi(w2);
else if(!strcmpi(w1, "time_allowed"))
- login_config.time_allowed = atoi(w2);
+ login->config->time_allowed = atoi(w2);
else if(!strcmpi(w1, "use_dnsbl"))
- login_config.use_dnsbl = (bool)config_switch(w2);
+ login->config->use_dnsbl = (bool)config_switch(w2);
else if(!strcmpi(w1, "dnsbl_servers"))
- safestrncpy(login_config.dnsbl_servs, w2, sizeof(login_config.dnsbl_servs));
+ safestrncpy(login->config->dnsbl_servs, w2, sizeof(login->config->dnsbl_servs));
else if(!strcmpi(w1, "ipban_cleanup_interval"))
- login_config.ipban_cleanup_interval = (unsigned int)atoi(w2);
+ login->config->ipban_cleanup_interval = (unsigned int)atoi(w2);
else if(!strcmpi(w1, "ip_sync_interval"))
- login_config.ip_sync_interval = (unsigned int)1000*60*atoi(w2); //w2 comes in minutes.
+ login->config->ip_sync_interval = (unsigned int)1000*60*atoi(w2); //w2 comes in minutes.
else if(!strcmpi(w1, "client_hash_check"))
- login_config.client_hash_check = config_switch(w2);
+ login->config->client_hash_check = config_switch(w2);
else if(!strcmpi(w1, "client_hash")) {
int group = 0;
char md5[33];
@@ -1831,9 +1828,9 @@ int login_config_read(const char* cfgName)
}
nnode->group_id = group;
- nnode->next = login_config.client_hash_nodes;
+ nnode->next = login->config->client_hash_nodes;
- login_config.client_hash_nodes = nnode;
+ login->config->client_hash_nodes = nnode;
}
}
else if(!strcmpi(w1, "import"))
@@ -1858,7 +1855,7 @@ int login_config_read(const char* cfgName)
//--------------------------------------
int do_final(void) {
int i;
- struct client_hash_node *hn = login_config.client_hash_nodes;
+ struct client_hash_node *hn = login->config->client_hash_nodes;
ShowStatus("Terminating...\n");
@@ -1872,7 +1869,7 @@ int do_final(void) {
login_log(0, "login server", 100, "login server shutdown");
- if( login_config.log_login )
+ if (login->config->log_login)
loginlog_final();
ipban_final();
@@ -1986,7 +1983,7 @@ int do_init(int argc, char** argv)
login_defaults();
// read login-server configuration
- login_set_defaults();
+ login->config_set_defaults();
login->LOGIN_CONF_NAME = aStrdup("conf/login-server.conf");
login->NET_CONF_NAME = aStrdup("conf/network.conf");
@@ -2004,7 +2001,7 @@ int do_init(int argc, char** argv)
chrif_server_init(i);
// initialize logging
- if( login_config.log_login )
+ if (login->config->log_login)
loginlog_init();
// initialize static and dynamic ipban system
@@ -2025,9 +2022,9 @@ int do_init(int argc, char** argv)
timer->add_interval(timer->gettick() + 600*1000, login->online_data_cleanup, 0, 0, 600*1000);
// add timer to detect ip address change and perform update
- if (login_config.ip_sync_interval) {
+ if (login->config->ip_sync_interval) {
timer->add_func_list(login->sync_ip_addresses, "login->sync_ip_addresses");
- timer->add_interval(timer->gettick() + login_config.ip_sync_interval, login->sync_ip_addresses, 0, 0, login_config.ip_sync_interval);
+ timer->add_interval(timer->gettick() + login->config->ip_sync_interval, login->sync_ip_addresses, 0, 0, login->config->ip_sync_interval);
}
// Account database init
@@ -2039,8 +2036,8 @@ int do_init(int argc, char** argv)
HPM->event(HPET_INIT);
// server port open & binding
- if ((login->fd = sockt->make_listen_bind(login_config.login_ip,login_config.login_port)) == -1) {
- ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",login_config.login_port);
+ if ((login->fd = sockt->make_listen_bind(login->config->login_ip,login->config->login_port)) == -1) {
+ ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",login->config->login_port);
exit(EXIT_FAILURE);
}
@@ -2053,7 +2050,7 @@ int do_init(int argc, char** argv)
console->display_gplnotice();
#endif // CONSOLE_INPUT
- ShowStatus("The login-server is "CL_GREEN"ready"CL_RESET" (Server is listening on the port %u).\n\n", login_config.login_port);
+ ShowStatus("The login-server is "CL_GREEN"ready"CL_RESET" (Server is listening on the port %u).\n\n", login->config->login_port);
login_log(0, "login server", 100, "login server started");
HPM->event(HPET_READY);
@@ -2064,7 +2061,7 @@ int do_init(int argc, char** argv)
void login_defaults(void) {
login = &login_s;
- login->lc = &login_config;
+ login->config = &login_config_;
login->accounts = accounts;
login->mmo_auth = login_mmo_auth;
@@ -2124,6 +2121,8 @@ void login_defaults(void) {
login->login_error = login_login_error;
login->send_coding_key = login_send_coding_key;
+ login->config_set_defaults = login_config_set_defaults;
+ login->config_read = login_config_read;
login->LOGIN_CONF_NAME = NULL;
login->NET_CONF_NAME = NULL;
}
diff --git a/src/login/login.h b/src/login/login.h
index 8036d04ad..f79f75cb3 100644
--- a/src/login/login.h
+++ b/src/login/login.h
@@ -152,7 +152,7 @@ struct login_interface {
DBMap* auth_db;
DBMap* online_db;
int fd;
- struct Login_Config *lc;
+ struct Login_Config *config;
struct AccountDB* accounts;
int (*mmo_auth) (struct login_session_data* sd, bool isServer);
@@ -209,13 +209,14 @@ struct login_interface {
void (*char_server_connection_status) (int fd, struct login_session_data* sd, uint8 status);
void (*parse_request_connection) (int fd, struct login_session_data* sd, const char *ip, uint32 ipl);
int (*parse_login) (int fd);
+ void (*config_set_defaults) (void);
+ int (*config_read) (const char *cfgName);
char *LOGIN_CONF_NAME;
char *NET_CONF_NAME; ///< Network configuration filename
};
#ifdef HERCULES_CORE
extern struct mmo_char_server server[MAX_SERVERS];
-extern struct Login_Config login_config;
void login_defaults(void);
#endif // HERCULES_CORE
diff --git a/src/login/loginlog_sql.c b/src/login/loginlog_sql.c
index f26d9890f..356bba3b4 100644
--- a/src/login/loginlog_sql.c
+++ b/src/login/loginlog_sql.c
@@ -59,7 +59,7 @@ unsigned long loginlog_failedattempts(uint32 ip, unsigned int minutes)
if( !enabled )
return 0;
- if( SQL_ERROR == SQL->Query(sql_handle, "SELECT count(*) FROM `%s` WHERE `ip` = '%s' AND `rcode` = '1' AND `time` > NOW() - INTERVAL %d MINUTE",
+ if( SQL_ERROR == SQL->Query(sql_handle, "SELECT count(*) FROM `%s` WHERE `ip` = '%s' AND `rcode` = '1' AND `time` > NOW() - INTERVAL %u MINUTE",
log_login_db, sockt->ip2str(ip,NULL), minutes) )// how many times failed account? in one ip.
Sql_ShowDebug(sql_handle);