From 917b208edb37bcde0ad9085311bef54fc436b54f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 17 Jan 2018 01:31:35 +0300 Subject: Add account_ prefix to all functions in account.c --- src/login/login.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/login/login.c') diff --git a/src/login/login.c b/src/login/login.c index a78276051..0b540d95a 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -624,7 +624,7 @@ void login_fromchar_parse_account_reg2(int fd, int id, const char *const ip) if( !accounts->load_num(accounts, &acc, account_id) ) ShowStatus("Char-server '%s': receiving (from the char-server) of account_reg2 (account: %d not found, ip: %s).\n", server[id].name, account_id, ip); else { - mmo_save_accreg2(accounts,fd,account_id,RFIFOL(fd, 8)); + account_mmo_save_accreg2(accounts,fd,account_id,RFIFOL(fd, 8)); } RFIFOSKIP(fd,RFIFOW(fd,2)); } @@ -684,7 +684,7 @@ void login_fromchar_parse_request_account_reg2(int fd) int char_id = RFIFOL(fd,6); RFIFOSKIP(fd,10); - mmo_send_accreg2(accounts,fd,account_id,char_id); + account_mmo_send_accreg2(accounts,fd,account_id,char_id); } void login_fromchar_parse_update_wan_ip(int fd, int id) -- cgit v1.2.3-60-g2f50 From 55152d7e642eac14f8ca848a593a17bbf1b57334 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 17 Jan 2018 01:39:37 +0300 Subject: Add loginlog_ prefix to all functions in loginlog.c --- src/login/lclif.c | 2 +- src/login/login.c | 12 ++++++------ src/login/loginlog.c | 2 +- src/login/loginlog.h | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/login/login.c') diff --git a/src/login/lclif.c b/src/login/lclif.c index 1870f9bc9..d03f2fbe7 100644 --- a/src/login/lclif.c +++ b/src/login/lclif.c @@ -375,7 +375,7 @@ int lclif_parse(int fd) // Perform ip-ban check 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"); + loginlog_log(ipl, "unknown", -3, "ip banned"); lclif->login_error(fd, 3); // 3 = Rejected from Server sockt->eof(fd); return 0; diff --git a/src/login/login.c b/src/login/login.c index 0b540d95a..7cbb14db2 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -725,7 +725,7 @@ bool login_fromchar_parse_wrong_pincode(int fd) return true; } - login_log(sockt->host2ip(acc.last_ip), acc.userid, 100, "PIN Code check failed"); // FIXME: Do we really want to log this with the same code as successful logins? + loginlog_log(sockt->host2ip(acc.last_ip), acc.userid, 100, "PIN Code check failed"); // FIXME: Do we really want to log this with the same code as successful logins? } login->remove_online_user(acc.account_id); @@ -1258,7 +1258,7 @@ void login_auth_ok(struct login_session_data* sd) return; } - login_log(ip, sd->userid, 100, "login ok"); + loginlog_log(ip, sd->userid, 100, "login ok"); ShowStatus("Connection of the account '%s' accepted.\n", sd->userid); // create temporary auth entry @@ -1322,7 +1322,7 @@ void login_auth_failed(struct login_session_data *sd, int result) default : error = "Unknown Error."; break; } - login_log(ip, sd->userid, result, error); // FIXME: result can be 100, conflicting with the value 100 we use for successful login... + loginlog_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)) @@ -1430,7 +1430,7 @@ void login_parse_request_connection(int fd, struct login_session_data* sd, const ShowInfo("Connection request of the char-server '%s' @ %u.%u.%u.%u:%u (account: '%s', pass: '%s', ip: '%s')\n", server_name, CONVIP(server_ip), server_port, sd->userid, sd->passwd, ip); sprintf(message, "charserver - %s@%u.%u.%u.%u:%u", server_name, CONVIP(server_ip), server_port); - login_log(sockt->session[fd]->client_addr, sd->userid, 100, message); + loginlog_log(sockt->session[fd]->client_addr, sd->userid, 100, message); result = login->mmo_auth(sd, true); if (core->runflag == LOGINSERVER_ST_RUNNING && @@ -1973,7 +1973,7 @@ int do_final(void) login->clear_client_hash_nodes(); login->clear_dnsbl_servers(); - login_log(0, "login server", 100, "login server shutdown"); + loginlog_log(0, "login server", 100, "login server shutdown"); if (login->config->log_login) loginlog_final(); @@ -2196,7 +2196,7 @@ int do_init(int argc, char** argv) #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); - login_log(0, "login server", 100, "login server started"); + loginlog_log(0, "login server", 100, "login server started"); HPM->event(HPET_READY); diff --git a/src/login/loginlog.c b/src/login/loginlog.c index 7dff14990..90dc3fde8 100644 --- a/src/login/loginlog.c +++ b/src/login/loginlog.c @@ -73,7 +73,7 @@ unsigned long loginlog_failedattempts(uint32 ip, unsigned int minutes) * Records an event in the login log *---------------------------------------------*/ // TODO: add an enum of rcode values -void login_log(uint32 ip, const char* username, int rcode, const char* message) +void loginlog_log(uint32 ip, const char* username, int rcode, const char* message) { char esc_username[NAME_LENGTH*2+1]; char esc_message[255*2+1]; diff --git a/src/login/loginlog.h b/src/login/loginlog.h index 589bc4fa1..8153dd769 100644 --- a/src/login/loginlog.h +++ b/src/login/loginlog.h @@ -26,7 +26,7 @@ #ifdef HERCULES_CORE // TODO: Interface unsigned long loginlog_failedattempts(uint32 ip, unsigned int minutes); -void login_log(uint32 ip, const char* username, int rcode, const char* message); +void loginlog_log(uint32 ip, const char* username, int rcode, const char* message); bool loginlog_init(void); bool loginlog_final(void); bool loginlog_config_read(const char *filename, bool imported); -- cgit v1.2.3-60-g2f50 From 7040d6071e3cbb7eafd9b67108952a1342cac572 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 24 Jan 2018 00:31:58 +0300 Subject: Add server[MAX_SERVERS] into login interface. --- src/login/lclif.c | 22 +++++------ src/login/login.c | 113 +++++++++++++++++++++++++++--------------------------- src/login/login.h | 7 +++- 3 files changed, 73 insertions(+), 69 deletions(-) (limited to 'src/login/login.c') diff --git a/src/login/lclif.c b/src/login/lclif.c index d03f2fbe7..4c0e63173 100644 --- a/src/login/lclif.c +++ b/src/login/lclif.c @@ -257,8 +257,8 @@ bool lclif_send_server_list(struct login_session_data *sd) uint32 ip; struct packet_AC_ACCEPT_LOGIN *packet = NULL; - for (i = 0; i < ARRAYLENGTH(server); ++i) { - if (sockt->session_is_active(server[i].fd)) + for (i = 0; i < ARRAYLENGTH(login->dbs->server); ++i) { + if (sockt->session_is_active(login->dbs->server[i].fd)) server_num++; } if (server_num == 0) @@ -283,24 +283,24 @@ bool lclif_send_server_list(struct login_session_data *sd) packet->last_login_ip = 0; // Not used anymore memset(packet->last_login_time, '\0', sizeof(packet->last_login_time)); // Not used anymore packet->sex = sex_str2num(sd->sex); - for (i = 0, n = 0; i < ARRAYLENGTH(server); ++i) { + for (i = 0, n = 0; i < ARRAYLENGTH(login->dbs->server); ++i) { uint32 subnet_char_ip; - if (!sockt->session_is_valid(server[i].fd)) + if (!sockt->session_is_valid(login->dbs->server[i].fd)) continue; subnet_char_ip = login->lan_subnet_check(ip); - packet->server_list[n].ip = htonl((subnet_char_ip) ? subnet_char_ip : server[i].ip); - packet->server_list[n].port = sockt->ntows(htons(server[i].port)); // [!] LE byte order here [!] - safestrncpy(packet->server_list[n].name, server[i].name, 20); - packet->server_list[n].usercount = login->convert_users_to_colors(server[i].users); + packet->server_list[n].ip = htonl((subnet_char_ip) ? subnet_char_ip : login->dbs->server[i].ip); + packet->server_list[n].port = sockt->ntows(htons(login->dbs->server[i].port)); // [!] LE byte order here [!] + safestrncpy(packet->server_list[n].name, login->dbs->server[i].name, 20); + packet->server_list[n].usercount = login->convert_users_to_colors(login->dbs->server[i].users); - if (server[i].type == CST_PAYING && sd->expiration_time > time(NULL)) + if (login->dbs->server[i].type == CST_PAYING && sd->expiration_time > time(NULL)) packet->server_list[n].property = CST_NORMAL; else - packet->server_list[n].property = server[i].type; + packet->server_list[n].property = login->dbs->server[i].type; - packet->server_list[n].state = server[i].new_; + packet->server_list[n].state = login->dbs->server[i].new_; ++n; } WFIFOSET(sd->fd, length); diff --git a/src/login/login.c b/src/login/login.c index 7cbb14db2..e25c4e8c1 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -52,8 +52,8 @@ struct login_interface login_s; struct login_interface *login; +struct s_login_dbs logindbs; struct Login_Config login_config_; -struct mmo_char_server server[MAX_SERVERS]; // char server data struct Account_engine account_engine[] = { {account_db_sql, NULL} @@ -164,9 +164,9 @@ int charif_sendallwos(int sfd, uint8* buf, size_t len) int i, c; nullpo_ret(buf); - for( i = 0, c = 0; i < ARRAYLENGTH(server); ++i ) + for (i = 0, c = 0; i < ARRAYLENGTH(login->dbs->server); ++i) { - int fd = server[i].fd; + int fd = login->dbs->server[i].fd; if (sockt->session_is_valid(fd) && fd != sfd) { WFIFOHEAD(fd,len); memcpy(WFIFOP(fd,0), buf, len); @@ -183,8 +183,8 @@ int charif_sendallwos(int sfd, uint8* buf, size_t len) void chrif_server_init(int id) { Assert_retv(id >= 0 && id < MAX_SERVERS); - memset(&server[id], 0, sizeof(server[id])); - server[id].fd = -1; + memset(&login->dbs->server[id], 0, sizeof(login->dbs->server[id])); + login->dbs->server[id].fd = -1; } @@ -192,10 +192,10 @@ void chrif_server_init(int id) void chrif_server_destroy(int id) { Assert_retv(id >= 0 && id < MAX_SERVERS); - if (server[id].fd != -1) + if (login->dbs->server[id].fd != -1) { - sockt->close(server[id].fd); - server[id].fd = -1; + sockt->close(login->dbs->server[id].fd); + login->dbs->server[id].fd = -1; } } @@ -213,7 +213,7 @@ void chrif_server_reset(int id) void chrif_on_disconnect(int id) { Assert_retv(id >= 0 && id < MAX_SERVERS); - ShowStatus("Char-server '%s' has disconnected.\n", server[id].name); + ShowStatus("Char-server '%s' has disconnected.\n", login->dbs->server[id].name); chrif_server_reset(id); } @@ -324,7 +324,7 @@ void login_fromchar_parse_auth(int fd, int id, const char *const ip) node->sex == sex_num2str(sex) /*&& node->ip == ip_*/ ) {// found - //ShowStatus("Char-server '%s': authentication of the account %d accepted (ip: %s).\n", server[id].name, account_id, ip); + //ShowStatus("Char-server '%s': authentication of the account %d accepted (ip: %s).\n", login->dbs->server[id].name, account_id, ip); // send ack login->fromchar_auth_ack(fd, account_id, login_id1, login_id2, sex, request_id, node); @@ -334,7 +334,7 @@ void login_fromchar_parse_auth(int fd, int id, const char *const ip) else {// authentication not found nullpo_retv(ip); - ShowStatus("Char-server '%s': authentication of the account %d REFUSED (ip: %s).\n", server[id].name, account_id, ip); + ShowStatus("Char-server '%s': authentication of the account %d REFUSED (ip: %s).\n", login->dbs->server[id].name, account_id, ip); login->fromchar_auth_ack(fd, account_id, login_id1, login_id2, sex, request_id, NULL); } } @@ -345,11 +345,11 @@ void login_fromchar_parse_update_users(int fd, int id) RFIFOSKIP(fd,6); // how many users on world? (update) - if( server[id].users != users ) + if (login->dbs->server[id].users != users) { - ShowStatus("set users %s : %d\n", server[id].name, users); + ShowStatus("set users %s : %d\n", login->dbs->server[id].name, users); - server[id].users = (uint16)users; + login->dbs->server[id].users = (uint16)users; } } @@ -363,13 +363,13 @@ void login_fromchar_parse_request_change_email(int fd, int id, const char *const RFIFOSKIP(fd,46); if( e_mail_check(email) == 0 ) - ShowNotice("Char-server '%s': Attempt to create an e-mail on an account with a default e-mail REFUSED - e-mail is invalid (account: %d, ip: %s)\n", server[id].name, account_id, ip); + ShowNotice("Char-server '%s': Attempt to create an e-mail on an account with a default e-mail REFUSED - e-mail is invalid (account: %d, ip: %s)\n", login->dbs->server[id].name, account_id, ip); else if( !accounts->load_num(accounts, &acc, account_id) || strcmp(acc.email, "a@a.com") == 0 || acc.email[0] == '\0' ) - ShowNotice("Char-server '%s': Attempt to create an e-mail on an account with a default e-mail REFUSED - account doesn't exist or e-mail of account isn't default e-mail (account: %d, ip: %s).\n", server[id].name, account_id, ip); + ShowNotice("Char-server '%s': Attempt to create an e-mail on an account with a default e-mail REFUSED - account doesn't exist or e-mail of account isn't default e-mail (account: %d, ip: %s).\n", login->dbs->server[id].name, account_id, ip); else { memcpy(acc.email, email, sizeof(acc.email)); - ShowNotice("Char-server '%s': Create an e-mail on an account with a default e-mail (account: %d, new e-mail: %s, ip: %s).\n", server[id].name, account_id, email, ip); + ShowNotice("Char-server '%s': Create an e-mail on an account with a default e-mail (account: %d, new e-mail: %s, ip: %s).\n", login->dbs->server[id].name, account_id, email, ip); // Save accounts->save(accounts, &acc); } @@ -428,7 +428,7 @@ void login_fromchar_parse_account_data(int fd, int id, const char *const ip) if( !accounts->load_num(accounts, &acc, account_id) ) { - ShowNotice("Char-server '%s': account %d NOT found (ip: %s).\n", server[id].name, account_id, ip); + ShowNotice("Char-server '%s': account %d NOT found (ip: %s).\n", login->dbs->server[id].name, account_id, ip); login->fromchar_account(fd, account_id, NULL); } else { @@ -461,22 +461,22 @@ void login_fromchar_parse_change_email(int fd, int id, const char *const ip) RFIFOSKIP(fd, 86); if( e_mail_check(actual_email) == 0 ) - ShowNotice("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but actual email is invalid (account: %d, ip: %s)\n", server[id].name, account_id, ip); + ShowNotice("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but actual email is invalid (account: %d, ip: %s)\n", login->dbs->server[id].name, account_id, ip); else if( e_mail_check(new_email) == 0 ) - ShowNotice("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command) with a invalid new e-mail (account: %d, ip: %s)\n", server[id].name, account_id, ip); + ShowNotice("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command) with a invalid new e-mail (account: %d, ip: %s)\n", login->dbs->server[id].name, account_id, ip); else if( strcmpi(new_email, "a@a.com") == 0 ) - ShowNotice("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command) with a default e-mail (account: %d, ip: %s)\n", server[id].name, account_id, ip); + ShowNotice("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command) with a default e-mail (account: %d, ip: %s)\n", login->dbs->server[id].name, account_id, ip); else if( !accounts->load_num(accounts, &acc, account_id) ) - ShowNotice("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but account doesn't exist (account: %d, ip: %s).\n", server[id].name, account_id, ip); + ShowNotice("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but account doesn't exist (account: %d, ip: %s).\n", login->dbs->server[id].name, account_id, ip); else if( strcmpi(acc.email, actual_email) != 0 ) - ShowNotice("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but actual e-mail is incorrect (account: %d (%s), actual e-mail: %s, proposed e-mail: %s, ip: %s).\n", server[id].name, account_id, acc.userid, acc.email, actual_email, ip); + ShowNotice("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but actual e-mail is incorrect (account: %d (%s), actual e-mail: %s, proposed e-mail: %s, ip: %s).\n", login->dbs->server[id].name, account_id, acc.userid, acc.email, actual_email, ip); else { safestrncpy(acc.email, new_email, sizeof(acc.email)); - ShowNotice("Char-server '%s': Modify an e-mail on an account (@email GM command) (account: %d (%s), new e-mail: %s, ip: %s).\n", server[id].name, account_id, acc.userid, new_email, ip); + ShowNotice("Char-server '%s': Modify an e-mail on an account (@email GM command) (account: %d (%s), new e-mail: %s, ip: %s).\n", login->dbs->server[id].name, account_id, acc.userid, new_email, ip); // Save accounts->save(accounts, &acc); } @@ -501,12 +501,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 %u, 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", login->dbs->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 %u, 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", login->dbs->server[id].name, account_id, state, ip); else { - ShowNotice("Char-server '%s': Status change (account: %d, new status %u, ip: %s).\n", server[id].name, account_id, state, ip); + ShowNotice("Char-server '%s': Status change (account: %d, new status %u, ip: %s).\n", login->dbs->server[id].name, account_id, state, ip); acc.state = state; // Save @@ -543,7 +543,7 @@ void login_fromchar_parse_ban(int fd, int id, const char *const ip) RFIFOSKIP(fd,18); if (!accounts->load_num(accounts, &acc, account_id)) { - ShowNotice("Char-server '%s': Error of ban request (account: %d not found, ip: %s).\n", server[id].name, account_id, ip); + ShowNotice("Char-server '%s': Error of ban request (account: %d not found, ip: %s).\n", login->dbs->server[id].name, account_id, ip); } else { time_t timestamp; struct tm *tmtime; @@ -560,14 +560,14 @@ void login_fromchar_parse_ban(int fd, int id, const char *const ip) tmtime->tm_sec += sec; timestamp = mktime(tmtime); if (timestamp == -1) { - ShowNotice("Char-server '%s': Error of ban request (account: %d, invalid date, ip: %s).\n", server[id].name, account_id, ip); + ShowNotice("Char-server '%s': Error of ban request (account: %d, invalid date, ip: %s).\n", login->dbs->server[id].name, account_id, ip); } else if( timestamp <= time(NULL) || timestamp == 0 ) { - ShowNotice("Char-server '%s': Error of ban request (account: %d, new date unbans the account, ip: %s).\n", server[id].name, account_id, ip); + ShowNotice("Char-server '%s': Error of ban request (account: %d, new date unbans the account, ip: %s).\n", login->dbs->server[id].name, account_id, ip); } else { char tmpstr[24]; 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); + login->dbs->server[id].name, account_id, (long)timestamp, tmpstr, ip); acc.unban_time = timestamp; @@ -596,15 +596,15 @@ void login_fromchar_parse_change_sex(int fd, int id, const char *const ip) RFIFOSKIP(fd,6); if( !accounts->load_num(accounts, &acc, account_id) ) - ShowNotice("Char-server '%s': Error of sex change (account: %d not found, ip: %s).\n", server[id].name, account_id, ip); + ShowNotice("Char-server '%s': Error of sex change (account: %d not found, ip: %s).\n", login->dbs->server[id].name, account_id, ip); else if( acc.sex == 'S' ) - ShowNotice("Char-server '%s': Error of sex change - account to change is a Server account (account: %d, ip: %s).\n", server[id].name, account_id, ip); + ShowNotice("Char-server '%s': Error of sex change - account to change is a Server account (account: %d, ip: %s).\n", login->dbs->server[id].name, account_id, ip); else { char sex = ( acc.sex == 'M' ) ? 'F' : 'M'; //Change gender - ShowNotice("Char-server '%s': Sex change (account: %d, new sex %c, ip: %s).\n", server[id].name, account_id, sex, ip); + ShowNotice("Char-server '%s': Sex change (account: %d, new sex %c, ip: %s).\n", login->dbs->server[id].name, account_id, sex, ip); acc.sex = sex; // Save @@ -622,7 +622,7 @@ void login_fromchar_parse_account_reg2(int fd, int id, const char *const ip) int account_id = RFIFOL(fd,4); if( !accounts->load_num(accounts, &acc, account_id) ) - ShowStatus("Char-server '%s': receiving (from the char-server) of account_reg2 (account: %d not found, ip: %s).\n", server[id].name, account_id, ip); + ShowStatus("Char-server '%s': receiving (from the char-server) of account_reg2 (account: %d not found, ip: %s).\n", login->dbs->server[id].name, account_id, ip); else { account_mmo_save_accreg2(accounts,fd,account_id,RFIFOL(fd, 8)); } @@ -637,13 +637,13 @@ void login_fromchar_parse_unban(int fd, int id, const char *const ip) RFIFOSKIP(fd,6); if( !accounts->load_num(accounts, &acc, account_id) ) - ShowNotice("Char-server '%s': Error of Unban request (account: %d not found, ip: %s).\n", server[id].name, account_id, ip); + ShowNotice("Char-server '%s': Error of Unban request (account: %d not found, ip: %s).\n", login->dbs->server[id].name, account_id, ip); else if( acc.unban_time == 0 ) - ShowNotice("Char-server '%s': Error of Unban request (account: %d, no change for unban date, ip: %s).\n", server[id].name, account_id, ip); + ShowNotice("Char-server '%s': Error of Unban request (account: %d, no change for unban date, ip: %s).\n", login->dbs->server[id].name, account_id, ip); else { - ShowNotice("Char-server '%s': Unban request (account: %d, ip: %s).\n", server[id].name, account_id, ip); + ShowNotice("Char-server '%s': Unban request (account: %d, ip: %s).\n", login->dbs->server[id].name, account_id, ip); acc.unban_time = 0; accounts->save(accounts, &acc); } @@ -689,8 +689,8 @@ 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 %u.%u.%u.%u.\n",id, CONVIP(server[id].ip)); + login->dbs->server[id].ip = ntohl(RFIFOL(fd,2)); + ShowInfo("Updated IP of Server #%d to %u.%u.%u.%u.\n",id, CONVIP(login->dbs->server[id].ip)); RFIFOSKIP(fd,6); } @@ -794,8 +794,8 @@ int login_parse_fromchar(int fd) uint32 ipl; char ip[16]; - ARR_FIND( 0, ARRAYLENGTH(server), id, server[id].fd == fd ); - if( id == ARRAYLENGTH(server) ) + ARR_FIND(0, ARRAYLENGTH(login->dbs->server), id, login->dbs->server[id].fd == fd); + if (id == ARRAYLENGTH(login->dbs->server)) {// not a char server ShowDebug("login_parse_fromchar: Disconnecting invalid session #%d (is not a char-server)\n", fd); sockt->eof(fd); @@ -806,12 +806,12 @@ int login_parse_fromchar(int fd) if( sockt->session[fd]->flag.eof ) { sockt->close(fd); - server[id].fd = -1; + login->dbs->server[id].fd = -1; chrif_on_disconnect(id); return 0; } - ipl = server[id].ip; + ipl = login->dbs->server[id].ip; sockt->ip2str(ipl, ip); while (RFIFOREST(fd) >= 2) { @@ -1437,18 +1437,18 @@ void login_parse_request_connection(int fd, struct login_session_data* sd, const result == -1 && sd->sex == 'S' && sd->account_id >= 0 && - sd->account_id < ARRAYLENGTH(server) && - !sockt->session_is_valid(server[sd->account_id].fd) && + sd->account_id < ARRAYLENGTH(login->dbs->server) && + !sockt->session_is_valid(login->dbs->server[sd->account_id].fd) && sockt->allowed_ip_check(ipl)) { ShowStatus("Connection of the char-server '%s' accepted.\n", server_name); - safestrncpy(server[sd->account_id].name, server_name, sizeof(server[sd->account_id].name)); - server[sd->account_id].fd = fd; - server[sd->account_id].ip = server_ip; - server[sd->account_id].port = server_port; - server[sd->account_id].users = 0; - server[sd->account_id].type = type; - server[sd->account_id].new_ = new_; + safestrncpy(login->dbs->server[sd->account_id].name, server_name, sizeof(login->dbs->server[sd->account_id].name)); + login->dbs->server[sd->account_id].fd = fd; + login->dbs->server[sd->account_id].ip = server_ip; + login->dbs->server[sd->account_id].port = server_port; + login->dbs->server[sd->account_id].users = 0; + login->dbs->server[sd->account_id].type = type; + login->dbs->server[sd->account_id].new_ = new_; sockt->session[fd]->func_parse = login->parse_fromchar; sockt->session[fd]->flag.server = 1; @@ -1989,7 +1989,7 @@ int do_final(void) login->online_db->destroy(login->online_db, NULL); login->auth_db->destroy(login->auth_db, NULL); - for( i = 0; i < ARRAYLENGTH(server); ++i ) + for (i = 0; i < ARRAYLENGTH(login->dbs->server); ++i) chrif_server_destroy(i); if( login->fd != -1 ) @@ -2033,7 +2033,7 @@ void do_shutdown_login(void) core->runflag = LOGINSERVER_ST_SHUTDOWN; ShowStatus("Shutting down...\n"); // TODO proper shutdown procedure; kick all characters, wait for acks, ... [FlavioJS] - for( id = 0; id < ARRAYLENGTH(server); ++id ) + for (id = 0; id < ARRAYLENGTH(login->dbs->server); ++id) chrif_server_reset(id); sockt->flush_fifos(); core->runflag = CORE_ST_STOP; @@ -2142,7 +2142,7 @@ int do_init(int argc, char** argv) login->config_read(login->LOGIN_CONF_NAME, false); sockt->net_config_read(login->NET_CONF_NAME); - for( i = 0; i < ARRAYLENGTH(server); ++i ) + for (i = 0; i < ARRAYLENGTH(login->dbs->server); ++i) chrif_server_init(i); // initialize logging @@ -2208,6 +2208,7 @@ void login_defaults(void) { login->config = &login_config_; login->accounts = accounts; + login->dbs = &logindbs; login->mmo_auth = login_mmo_auth; login->mmo_auth_new = login_mmo_auth_new; diff --git a/src/login/login.h b/src/login/login.h index 3af54ef50..b846e2bb7 100644 --- a/src/login/login.h +++ b/src/login/login.h @@ -157,6 +157,10 @@ struct online_login_data { #define MAX_SERVERS 30 +struct s_login_dbs { + struct mmo_char_server server[MAX_SERVERS]; +}; + /** * Login.c Interface **/ @@ -166,6 +170,7 @@ struct login_interface { int fd; struct Login_Config *config; struct AccountDB* accounts; + struct s_login_dbs *dbs; int (*mmo_auth) (struct login_session_data* sd, bool isServer); int (*mmo_auth_new) (const char* userid, const char* pass, const char sex, const char* last_ip); @@ -235,8 +240,6 @@ struct login_interface { }; #ifdef HERCULES_CORE -extern struct mmo_char_server server[MAX_SERVERS]; - void login_defaults(void); #endif // HERCULES_CORE -- cgit v1.2.3-60-g2f50 From a4cbec10932f12f849a942dff29d282975aabd45 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 24 Jan 2018 01:26:39 +0300 Subject: Add interface into account.c. --- src/login/HPMlogin.c | 2 +- src/login/account.c | 114 +++++++++++++++++++---------------------------- src/login/account.h | 70 ++++++++++++++++++++++++----- src/login/login.c | 10 +++-- src/plugins/HPMHooking.c | 1 + 5 files changed, 113 insertions(+), 84 deletions(-) (limited to 'src/login/login.c') diff --git a/src/login/HPMlogin.c b/src/login/HPMlogin.c index b35ac13cb..4bb375edc 100644 --- a/src/login/HPMlogin.c +++ b/src/login/HPMlogin.c @@ -69,7 +69,7 @@ bool HPM_login_data_store_validate(enum HPluginDataTypes type, struct hplugin_da } void HPM_login_plugin_load_sub(struct hplugin *plugin) { - plugin->hpi->sql_handle = account_db_sql_up(login->accounts); + plugin->hpi->sql_handle = account->db_sql_up(login->accounts); } void HPM_login_do_init(void) { diff --git a/src/login/account.c b/src/login/account.c index 7e8fa5f30..cd480def9 100644 --- a/src/login/account.c +++ b/src/login/account.c @@ -39,54 +39,8 @@ /// global defines #define ACCOUNT_SQL_DB_VERSION 20110114 -/// internal structure -typedef struct AccountDB_SQL -{ - AccountDB vtable; // public interface - - struct Sql *accounts; // SQL accounts storage - - // Sql settings - char db_hostname[32]; - uint16 db_port; - char db_username[32]; - char db_password[100]; - char db_database[32]; - char codepage[32]; - // other settings - bool case_sensitive; - char account_db[32]; - char global_acc_reg_num_db[32]; - char global_acc_reg_str_db[32]; - - -} AccountDB_SQL; - -/// internal structure -typedef struct AccountDBIterator_SQL -{ - AccountDBIterator vtable; // public interface - - AccountDB_SQL* db; - int last_account_id; -} AccountDBIterator_SQL; - -/// internal functions -static bool account_db_sql_init(AccountDB* self); -static void account_db_sql_destroy(AccountDB* self); -static bool account_db_sql_get_property(AccountDB* self, const char* key, char* buf, size_t buflen); -static bool account_db_sql_set_property(AccountDB* self, struct config_t *config, bool imported); -static bool account_db_sql_create(AccountDB* self, struct mmo_account* acc); -static bool account_db_sql_remove(AccountDB* self, const int account_id); -static bool account_db_sql_save(AccountDB* self, const struct mmo_account* acc); -static bool account_db_sql_load_num(AccountDB* self, struct mmo_account* acc, const int account_id); -static bool account_db_sql_load_str(AccountDB* self, struct mmo_account* acc, const char* userid); -static AccountDBIterator* account_db_sql_iterator(AccountDB* self); -static void account_db_sql_iter_destroy(AccountDBIterator* self); -static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account* acc); - -static bool account_mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int account_id); -static bool account_mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, bool is_new); +struct account_interface account_s; +struct account_interface *account; /// public constructor AccountDB* account_db_sql(void) @@ -94,16 +48,16 @@ AccountDB* account_db_sql(void) AccountDB_SQL* db = (AccountDB_SQL*)aCalloc(1, sizeof(AccountDB_SQL)); // set up the vtable - db->vtable.init = &account_db_sql_init; - db->vtable.destroy = &account_db_sql_destroy; - db->vtable.get_property = &account_db_sql_get_property; - db->vtable.set_property = &account_db_sql_set_property; - db->vtable.save = &account_db_sql_save; - db->vtable.create = &account_db_sql_create; - db->vtable.remove = &account_db_sql_remove; - db->vtable.load_num = &account_db_sql_load_num; - db->vtable.load_str = &account_db_sql_load_str; - db->vtable.iterator = &account_db_sql_iterator; + db->vtable.init = account->db_sql_init; + db->vtable.destroy = account->db_sql_destroy; + db->vtable.get_property = account->db_sql_get_property; + db->vtable.set_property = account->db_sql_set_property; + db->vtable.save = account->db_sql_save; + db->vtable.create = account->db_sql_create; + db->vtable.remove = account->db_sql_remove; + db->vtable.load_num = account->db_sql_load_num; + db->vtable.load_str = account->db_sql_load_str; + db->vtable.iterator = account->db_sql_iterator; // initialize to default values db->accounts = NULL; @@ -123,10 +77,8 @@ AccountDB* account_db_sql(void) return &db->vtable; } - /* ------------------------------------------------------------------------- */ - /// establishes database connection static bool account_db_sql_init(AccountDB* self) { @@ -323,7 +275,7 @@ static bool account_db_sql_set_property(AccountDB* self, struct config_t *config libconfig->setting_lookup_uint16(setting, "db_port", &db->db_port); libconfig->setting_lookup_bool_real(setting, "case_sensitive", &db->case_sensitive); - account_db_read_inter(db, "conf/common/inter-server.conf", imported); + account->db_read_inter(db, "conf/common/inter-server.conf", imported); return true; } @@ -381,7 +333,7 @@ static bool account_db_sql_create(AccountDB* self, struct mmo_account* acc) // insert the data into the database acc->account_id = account_id; - return account_mmo_auth_tosql(db, acc, true); + return account->mmo_auth_tosql(db, acc, true); } /// delete an existing account entry + its regs @@ -411,14 +363,14 @@ static bool account_db_sql_remove(AccountDB* self, const int account_id) static bool account_db_sql_save(AccountDB* self, const struct mmo_account* acc) { AccountDB_SQL* db = (AccountDB_SQL*)self; - return account_mmo_auth_tosql(db, acc, false); + return account->mmo_auth_tosql(db, acc, false); } /// retrieve data from db and store it in the provided data structure static bool account_db_sql_load_num(AccountDB* self, struct mmo_account* acc, const int account_id) { AccountDB_SQL* db = (AccountDB_SQL*)self; - return account_mmo_auth_fromsql(db, acc, account_id); + return account->mmo_auth_fromsql(db, acc, account_id); } /// retrieve data from db and store it in the provided data structure @@ -458,7 +410,7 @@ static bool account_db_sql_load_str(AccountDB* self, struct mmo_account* acc, co SQL->GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); - return account_db_sql_load_num(self, acc, account_id); + return account->db_sql_load_num(self, acc, account_id); } @@ -471,8 +423,8 @@ static AccountDBIterator* account_db_sql_iterator(AccountDB* self) nullpo_retr(NULL, db); iter = (AccountDBIterator_SQL*)aCalloc(1, sizeof(AccountDBIterator_SQL)); // set up the vtable - iter->vtable.destroy = &account_db_sql_iter_destroy; - iter->vtable.next = &account_db_sql_iter_next; + iter->vtable.destroy = account->db_sql_iter_destroy; + iter->vtable.next = account->db_sql_iter_next; // fill data iter->db = db; @@ -516,8 +468,7 @@ static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account {// get account data int account_id; account_id = atoi(data); - if( account_mmo_auth_fromsql(db, acc, account_id) ) - { + if (account->mmo_auth_fromsql(db, acc, account_id)) { iter->last_account_id = account_id; SQL->FreeResult(sql_handle); return true; @@ -870,3 +821,28 @@ void account_mmo_send_accreg2(AccountDB* self, int fd, int account_id, int char_ SQL->FreeResult(sql_handle); } + +void account_defaults(void) { + account = &account_s; + + account->db_sql_up = account_db_sql_up; + account->mmo_send_accreg2 = account_mmo_send_accreg2; + account->mmo_save_accreg2 = account_mmo_save_accreg2; + account->mmo_auth_fromsql = account_mmo_auth_fromsql; + account->mmo_auth_tosql = account_mmo_auth_tosql; + + account->db_sql = account_db_sql; + account->db_sql_init = account_db_sql_init; + account->db_sql_destroy = account_db_sql_destroy; + account->db_sql_get_property = account_db_sql_get_property; + account->db_sql_set_property = account_db_sql_set_property; + account->db_sql_create = account_db_sql_create; + account->db_sql_remove = account_db_sql_remove; + account->db_sql_save = account_db_sql_save; + account->db_sql_load_num = account_db_sql_load_num; + account->db_sql_load_str = account_db_sql_load_str; + account->db_sql_iterator = account_db_sql_iterator; + account->db_sql_iter_destroy = account_db_sql_iter_destroy; + account->db_sql_iter_next = account_db_sql_iter_next; + account->db_read_inter = account_db_read_inter; +} diff --git a/src/login/account.h b/src/login/account.h index 3d47e8c56..8199ce3ba 100644 --- a/src/login/account.h +++ b/src/login/account.h @@ -33,12 +33,6 @@ struct config_t; // common/conf.h typedef struct AccountDB AccountDB; typedef struct AccountDBIterator AccountDBIterator; - -#ifdef HERCULES_CORE -// standard engines -AccountDB* account_db_sql(void); -#endif // HERCULES_CORE - struct mmo_account { int account_id; @@ -59,7 +53,6 @@ struct mmo_account char birthdate[10+1]; // assigned birth date (format: YYYY-MM-DD, default: 0000-00-00) }; - struct AccountDBIterator { /// Destroys this iterator, releasing all allocated memory (including itself). @@ -161,11 +154,66 @@ struct AccountDB AccountDBIterator* (*iterator)(AccountDB* self); }; -#ifdef HERCULES_CORE -struct Sql *account_db_sql_up(AccountDB* self); +typedef struct AccountDB_SQL +{ + AccountDB vtable; // public interface + + struct Sql *accounts; // SQL accounts storage + + // Sql settings + char db_hostname[32]; + uint16 db_port; + char db_username[32]; + char db_password[100]; + char db_database[32]; + char codepage[32]; + // other settings + bool case_sensitive; + char account_db[32]; + char global_acc_reg_num_db[32]; + char global_acc_reg_str_db[32]; +} AccountDB_SQL; + +/// internal structure +typedef struct AccountDBIterator_SQL +{ + AccountDBIterator vtable; // public interface + + AccountDB_SQL* db; + int last_account_id; +} AccountDBIterator_SQL; -void account_mmo_send_accreg2(AccountDB* self, int fd, int account_id, int char_id); -void account_mmo_save_accreg2(AccountDB* self, int fd, int account_id, int char_id); +/** + * Account.c Interface + **/ +struct account_interface { + struct Sql* (*db_sql_up) (AccountDB* self); + void (*mmo_send_accreg2) (AccountDB* self, int fd, int account_id, int char_id); + void (*mmo_save_accreg2) (AccountDB* self, int fd, int account_id, int char_id); + bool (*mmo_auth_fromsql) (AccountDB_SQL* db, struct mmo_account* acc, int account_id); + bool (*mmo_auth_tosql) (AccountDB_SQL* db, const struct mmo_account* acc, bool is_new); + + AccountDB* (*db_sql) (void); + bool (*db_sql_init) (AccountDB* self); + void (*db_sql_destroy) (AccountDB* self); + bool (*db_sql_get_property) (AccountDB* self, const char* key, char* buf, size_t buflen); + bool (*db_sql_set_property) (AccountDB* self, struct config_t *config, bool imported); + bool (*db_sql_create) (AccountDB* self, struct mmo_account* acc); + bool (*db_sql_remove) (AccountDB* self, const int account_id); + bool (*db_sql_save) (AccountDB* self, const struct mmo_account* acc); + bool (*db_sql_load_num) (AccountDB* self, struct mmo_account* acc, const int account_id); + bool (*db_sql_load_str) (AccountDB* self, struct mmo_account* acc, const char* userid); + AccountDBIterator* (*db_sql_iterator) (AccountDB* self); + void (*db_sql_iter_destroy) (AccountDBIterator* self); + bool (*db_sql_iter_next) (AccountDBIterator* self, struct mmo_account* acc); + + bool (*db_read_inter) (AccountDB_SQL *db, const char *filename, bool imported); +}; + +#ifdef HERCULES_CORE +void account_defaults(void); #endif // HERCULES_CORE +HPShared struct account_interface *account; + #endif /* LOGIN_ACCOUNT_H */ diff --git a/src/login/login.c b/src/login/login.c index e25c4e8c1..86cc93240 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -56,7 +56,7 @@ struct s_login_dbs logindbs; struct Login_Config login_config_; struct Account_engine account_engine[] = { - {account_db_sql, NULL} + {NULL, NULL} }; // account database @@ -624,7 +624,7 @@ void login_fromchar_parse_account_reg2(int fd, int id, const char *const ip) if( !accounts->load_num(accounts, &acc, account_id) ) ShowStatus("Char-server '%s': receiving (from the char-server) of account_reg2 (account: %d not found, ip: %s).\n", login->dbs->server[id].name, account_id, ip); else { - account_mmo_save_accreg2(accounts,fd,account_id,RFIFOL(fd, 8)); + account->mmo_save_accreg2(accounts,fd,account_id,RFIFOL(fd, 8)); } RFIFOSKIP(fd,RFIFOW(fd,2)); } @@ -684,7 +684,7 @@ void login_fromchar_parse_request_account_reg2(int fd) int char_id = RFIFOL(fd,6); RFIFOSKIP(fd,10); - account_mmo_send_accreg2(accounts,fd,account_id,char_id); + account->mmo_send_accreg2(accounts,fd,account_id,char_id); } void login_fromchar_parse_update_wan_ip(int fd, int id) @@ -2094,7 +2094,10 @@ int do_init(int argc, char** argv) { int i; + account_defaults(); + // initialize engine (to accept config settings) + account_engine[0].constructor = account->db_sql; account_engine[0].db = account_engine[0].constructor(); accounts = account_engine[0].db; if( accounts == NULL ) { @@ -2102,6 +2105,7 @@ int do_init(int argc, char** argv) exit(EXIT_FAILURE); } + ipban_defaults(); login_defaults(); lclif_defaults(); diff --git a/src/plugins/HPMHooking.c b/src/plugins/HPMHooking.c index 99b4e63e7..4fedbeae2 100644 --- a/src/plugins/HPMHooking.c +++ b/src/plugins/HPMHooking.c @@ -34,6 +34,7 @@ PRAGMA_GCC5(GCC diagnostic ignored "-Wdiscarded-qualifiers") #define HPM_HOOKS_INCLUDE "HPMHooking/HPMHooking_login.Hooks.inc" #define HPM_POINTS_INCLUDE "HPMHooking/HPMHooking_login.HookingPoints.inc" #define HPM_SOURCES_INCLUDE "HPMHooking/HPMHooking_login.sources.inc" +#include "login/account.h" #include "login/lclif.h" #include "login/lclif.p.h" #include "login/login.h" -- cgit v1.2.3-60-g2f50 From a58b96c5dab055e5563de3ff92482c92ce0bc50c Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 24 Jan 2018 02:55:56 +0300 Subject: Add interface into ipban.c. --- src/login/HPMlogin.c | 1 + src/login/ipban.c | 118 +++++++++++++++++++++++++++-------------------- src/login/ipban.h | 46 ++++++++++++------ src/login/lclif.c | 2 +- src/login/login.c | 8 ++-- src/plugins/HPMHooking.c | 1 + 6 files changed, 106 insertions(+), 70 deletions(-) (limited to 'src/login/login.c') diff --git a/src/login/HPMlogin.c b/src/login/HPMlogin.c index 4bb375edc..65bdb1a71 100644 --- a/src/login/HPMlogin.c +++ b/src/login/HPMlogin.c @@ -25,6 +25,7 @@ #include "common/cbasetypes.h" #include "login/account.h" +#include "login/ipban.h" #include "login/lclif.h" #include "login/lclif.p.h" #include "login/login.h" diff --git a/src/login/ipban.c b/src/login/ipban.c index d74e6c4fa..46798ea45 100644 --- a/src/login/ipban.c +++ b/src/login/ipban.c @@ -34,49 +34,36 @@ #include -// Sql settings -static char ipban_db_hostname[32] = "127.0.0.1"; -static uint16 ipban_db_port = 3306; -static char ipban_db_username[32] = "ragnarok"; -static char ipban_db_password[100] = "ragnarok"; -static char ipban_db_database[32] = "ragnarok"; -static char ipban_codepage[32] = ""; -static char ipban_table[32] = "ipbanlist"; - -// globals -static struct Sql *sql_handle = NULL; -static int cleanup_timer_id = INVALID_TIMER; -static bool ipban_inited = false; - -int ipban_cleanup(int tid, int64 tick, int id, intptr_t data); - +struct ipban_interface ipban_s; +struct ipban_interface *ipban; +struct s_ipban_dbs ipbandbs; // initialize void ipban_init(void) { - ipban_inited = true; + ipban->inited = true; if (!login->config->ipban) return;// ipban disabled // establish connections - sql_handle = SQL->Malloc(); - if (SQL_ERROR == SQL->Connect(sql_handle, ipban_db_username, ipban_db_password, - ipban_db_hostname, ipban_db_port, ipban_db_database)) { - Sql_ShowDebug(sql_handle); - SQL->Free(sql_handle); + ipban->sql_handle = SQL->Malloc(); + if (SQL_ERROR == SQL->Connect(ipban->sql_handle, ipban->dbs->db_username, ipban->dbs->db_password, + ipban->dbs->db_hostname, ipban->dbs->db_port, ipban->dbs->db_database)) { + Sql_ShowDebug(ipban->sql_handle); + SQL->Free(ipban->sql_handle); exit(EXIT_FAILURE); } - if (ipban_codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, ipban_codepage)) - Sql_ShowDebug(sql_handle); + if (ipban->dbs->codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(ipban->sql_handle, ipban->dbs->codepage)) + Sql_ShowDebug(ipban->sql_handle); 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); + timer->add_func_list(ipban->cleanup, "ipban_cleanup"); + ipban->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); + ipban->cleanup(0,0,0,0); } } @@ -88,13 +75,13 @@ void ipban_final(void) if (login->config->ipban_cleanup_interval > 0) // release data - timer->delete(cleanup_timer_id, ipban_cleanup); + timer->delete(ipban->cleanup_timer_id, ipban->cleanup); - ipban_cleanup(0,0,0,0); // always clean up on login-server stop + ipban->cleanup(0,0,0,0); // always clean up on login-server stop // close connections - SQL->Free(sql_handle); - sql_handle = NULL; + SQL->Free(ipban->sql_handle); + ipban->sql_handle = NULL; } /** @@ -126,14 +113,14 @@ bool ipban_config_read_inter(const char *filename, bool imported) ShowError("ipban_config_read: inter_configuration/database_names was not found!\n"); return false; } - libconfig->setting_lookup_mutable_string(setting, "ipban_table", ipban_table, sizeof(ipban_table)); + libconfig->setting_lookup_mutable_string(setting, "ipban_table", ipban->dbs->table, sizeof(ipban->dbs->table)); // import should overwrite any previous configuration, so it should be called last if (libconfig->lookup_string(&config, "import", &import) == CONFIG_TRUE) { if (strcmp(import, filename) == 0 || strcmp(import, "conf/common/inter-server.conf") == 0) { ShowWarning("ipban_config_read_inter: Loop detected! Skipping 'import'...\n"); } else { - if (!ipban_config_read_inter(import, true)) + if (!ipban->config_read_inter(import, true)) retval = false; } } @@ -165,13 +152,13 @@ bool ipban_config_read_connection(const char *filename, struct config_t *config, return false; } - libconfig->setting_lookup_mutable_string(setting, "db_hostname", ipban_db_hostname, sizeof(ipban_db_hostname)); - libconfig->setting_lookup_mutable_string(setting, "db_database", ipban_db_database, sizeof(ipban_db_database)); + libconfig->setting_lookup_mutable_string(setting, "db_hostname", ipban->dbs->db_hostname, sizeof(ipban->dbs->db_hostname)); + libconfig->setting_lookup_mutable_string(setting, "db_database", ipban->dbs->db_database, sizeof(ipban->dbs->db_database)); - libconfig->setting_lookup_mutable_string(setting, "db_username", ipban_db_username, sizeof(ipban_db_username)); - libconfig->setting_lookup_mutable_string(setting, "db_password", ipban_db_password, sizeof(ipban_db_password)); - libconfig->setting_lookup_mutable_string(setting, "codepage", ipban_codepage, sizeof(ipban_codepage)); - libconfig->setting_lookup_uint16(setting, "db_port", &ipban_db_port); + libconfig->setting_lookup_mutable_string(setting, "db_username", ipban->dbs->db_username, sizeof(ipban->dbs->db_username)); + libconfig->setting_lookup_mutable_string(setting, "db_password", ipban->dbs->db_password, sizeof(ipban->dbs->db_password)); + libconfig->setting_lookup_mutable_string(setting, "codepage", ipban->dbs->codepage, sizeof(ipban->dbs->codepage)); + libconfig->setting_lookup_uint16(setting, "db_port", &ipban->dbs->db_port); return true; } @@ -224,7 +211,7 @@ bool ipban_config_read(const char *filename, struct config_t *config, bool impor nullpo_retr(false, filename); nullpo_retr(false, config); - if (ipban_inited) + if (ipban->inited) return false; // settings can only be changed before init if ((setting = libconfig->lookup(config, "login_configuration/account/ipban")) == NULL) { @@ -256,20 +243,20 @@ bool ipban_check(uint32 ip) 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')", - ipban_table, p[3], p[3], p[2], p[3], p[2], p[1], p[3], p[2], p[1], p[0]) ) + if( SQL_ERROR == SQL->Query(ipban->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')", + ipban->dbs->table, p[3], p[3], p[2], p[3], p[2], p[1], p[3], p[2], p[1], p[0]) ) { - Sql_ShowDebug(sql_handle); + Sql_ShowDebug(ipban->sql_handle); // close connection because we can't verify their connectivity. return true; } - if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(ipban->sql_handle) ) return false; - SQL->GetData(sql_handle, 0, &data, NULL); + SQL->GetData(ipban->sql_handle, 0, &data, NULL); matches = atoi(data); - SQL->FreeResult(sql_handle); + SQL->FreeResult(ipban->sql_handle); return( matches > 0 ); } @@ -288,10 +275,10 @@ void ipban_log(uint32 ip) 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 %u MINUTE ,'Password error ban')", - ipban_table, p[3], p[2], p[1], login->config->dynamic_pass_failure_ban_duration)) + if (SQL_ERROR == SQL->Query(ipban->sql_handle, "INSERT INTO `%s`(`list`,`btime`,`rtime`,`reason`) VALUES ('%u.%u.%u.*', NOW() , NOW() + INTERVAL %u MINUTE ,'Password error ban')", + ipban->dbs->table, p[3], p[2], p[1], login->config->dynamic_pass_failure_ban_duration)) { - Sql_ShowDebug(sql_handle); + Sql_ShowDebug(ipban->sql_handle); } } } @@ -301,8 +288,37 @@ int ipban_cleanup(int tid, int64 tick, int id, intptr_t data) { if (!login->config->ipban) return 0;// ipban disabled - if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `rtime` <= NOW()", ipban_table) ) - Sql_ShowDebug(sql_handle); + if( SQL_ERROR == SQL->Query(ipban->sql_handle, "DELETE FROM `%s` WHERE `rtime` <= NOW()", ipban->dbs->table) ) + Sql_ShowDebug(ipban->sql_handle); return 0; } + +void ipban_defaults(void) { + ipban = &ipban_s; + + ipban->dbs = &ipbandbs; + + ipban->sql_handle = NULL; + ipban->cleanup_timer_id = INVALID_TIMER; + ipban->inited = false; + + // Sql settings + strcpy(ipban->dbs->db_hostname, "127.0.0.1"); + ipban->dbs->db_port = 3306; + strcpy(ipban->dbs->db_username, "ragnarok"); + strcpy(ipban->dbs->db_password, "ragnarok"); + strcpy(ipban->dbs->db_database, "ragnarok"); + *ipban->dbs->codepage = 0; + strcpy(ipban->dbs->table, "ipbanlist"); + + ipban->init = ipban_init; + ipban->final = ipban_final; + ipban->cleanup = ipban_cleanup; + ipban->config_read_inter = ipban_config_read_inter; + ipban->config_read_connection = ipban_config_read_connection; + ipban->config_read_dynamic = ipban_config_read_dynamic; + ipban->config_read = ipban_config_read; + ipban->check = ipban_check; + ipban->log = ipban_log; +} diff --git a/src/login/ipban.h b/src/login/ipban.h index 104e3a8a3..29aafba9d 100644 --- a/src/login/ipban.h +++ b/src/login/ipban.h @@ -22,26 +22,44 @@ #define LOGIN_IPBAN_H #include "common/cbasetypes.h" +#include "common/hercules.h" /* Forward Declarations */ struct config_t; // common/conf.h -#ifdef HERCULES_CORE -// TODO: Interface -// initialize -void ipban_init(void); - -// finalize -void ipban_final(void); - -// check ip against ban list -bool ipban_check(uint32 ip); +struct s_ipban_dbs { + char db_hostname[32]; + uint16 db_port; + char db_username[32]; + char db_password[100]; + char db_database[32]; + char codepage[32]; + char table[32]; +}; -// increases failure count for the specified IP -void ipban_log(uint32 ip); +/** + * Ipban.c Interface + **/ +struct ipban_interface { + struct s_ipban_dbs *dbs; + struct Sql *sql_handle; + int cleanup_timer_id; + bool inited; + void (*init) (void); + void (*final) (void); + int (*cleanup) (int tid, int64 tick, int id, intptr_t data); + bool (*config_read_inter) (const char *filename, bool imported); + bool (*config_read_connection) (const char *filename, struct config_t *config, bool imported); + bool (*config_read_dynamic) (const char *filename, struct config_t *config, bool imported); + bool (*config_read) (const char *filename, struct config_t *config, bool imported); + bool (*check) (uint32 ip); + void (*log) (uint32 ip); +}; -// parses configuration options -bool ipban_config_read(const char *filename, struct config_t *config, bool imported); +#ifdef HERCULES_CORE +void ipban_defaults(void); #endif // HERCULES_CORE +HPShared struct ipban_interface *ipban; + #endif /* LOGIN_IPBAN_H */ diff --git a/src/login/lclif.c b/src/login/lclif.c index 4c0e63173..33445f92c 100644 --- a/src/login/lclif.c +++ b/src/login/lclif.c @@ -373,7 +373,7 @@ int lclif_parse(int fd) if ((sd = sockt->session[fd]->session_data) == 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); loginlog_log(ipl, "unknown", -3, "ip banned"); lclif->login_error(fd, 3); // 3 = Rejected from Server diff --git a/src/login/login.c b/src/login/login.c index 86cc93240..44fee5ccd 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -1326,7 +1326,7 @@ void login_auth_failed(struct login_session_data *sd, int result) } if (result == 1 && login->config->dynamic_pass_failure_ban && !sockt->trusted_ip_check(ip)) - ipban_log(ip); // log failed password attempt + ipban->log(ip); // log failed password attempt if (result == 6) { struct mmo_account acc = { 0 }; @@ -1630,7 +1630,7 @@ bool login_config_read_account(const char *filename, struct config_t *config, bo if (!db->set_property(db, config, imported)) retval = false; - if (!ipban_config_read(filename, config, imported)) + if (!ipban->config_read(filename, config, imported)) retval = false; return retval; @@ -1978,7 +1978,7 @@ int do_final(void) if (login->config->log_login) loginlog_final(); - ipban_final(); + ipban->final(); if( account_engine[0].db ) {// destroy account engine @@ -2154,7 +2154,7 @@ int do_init(int argc, char** argv) loginlog_init(); // initialize static and dynamic ipban system - ipban_init(); + ipban->init(); // Online user database init login->online_db = idb_alloc(DB_OPT_RELEASE_DATA); diff --git a/src/plugins/HPMHooking.c b/src/plugins/HPMHooking.c index 4fedbeae2..3e556881e 100644 --- a/src/plugins/HPMHooking.c +++ b/src/plugins/HPMHooking.c @@ -35,6 +35,7 @@ PRAGMA_GCC5(GCC diagnostic ignored "-Wdiscarded-qualifiers") #define HPM_POINTS_INCLUDE "HPMHooking/HPMHooking_login.HookingPoints.inc" #define HPM_SOURCES_INCLUDE "HPMHooking/HPMHooking_login.sources.inc" #include "login/account.h" +#include "login/ipban.h" #include "login/lclif.h" #include "login/lclif.p.h" #include "login/login.h" -- cgit v1.2.3-60-g2f50 From 27f5f420a8afd1603e7882e0e774627e4159a93f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 24 Jan 2018 05:56:04 +0300 Subject: Rename in login.c methods chrif_* into lchrif_*. --- src/login/login.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/login/login.c') diff --git a/src/login/login.c b/src/login/login.c index 44fee5ccd..48fc81113 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -180,7 +180,7 @@ int charif_sendallwos(int sfd, uint8* buf, size_t len) /// Initializes a server structure. -void chrif_server_init(int id) +void lchrif_server_init(int id) { Assert_retv(id >= 0 && id < MAX_SERVERS); memset(&login->dbs->server[id], 0, sizeof(login->dbs->server[id])); @@ -189,7 +189,7 @@ void chrif_server_init(int id) /// Destroys a server structure. -void chrif_server_destroy(int id) +void lchrif_server_destroy(int id) { Assert_retv(id >= 0 && id < MAX_SERVERS); if (login->dbs->server[id].fd != -1) @@ -201,20 +201,20 @@ void chrif_server_destroy(int id) /// Resets all the data related to a server. -void chrif_server_reset(int id) +void lchrif_server_reset(int id) { login->online_db->foreach(login->online_db, login->online_db_setoffline, id); //Set all chars from this char server to offline. - chrif_server_destroy(id); - chrif_server_init(id); + lchrif_server_destroy(id); + lchrif_server_init(id); } /// Called when the connection to Char Server is disconnected. -void chrif_on_disconnect(int id) +void lchrif_on_disconnect(int id) { Assert_retv(id >= 0 && id < MAX_SERVERS); ShowStatus("Char-server '%s' has disconnected.\n", login->dbs->server[id].name); - chrif_server_reset(id); + lchrif_server_reset(id); } @@ -807,7 +807,7 @@ int login_parse_fromchar(int fd) { sockt->close(fd); login->dbs->server[id].fd = -1; - chrif_on_disconnect(id); + lchrif_on_disconnect(id); return 0; } @@ -1990,7 +1990,7 @@ int do_final(void) login->auth_db->destroy(login->auth_db, NULL); for (i = 0; i < ARRAYLENGTH(login->dbs->server); ++i) - chrif_server_destroy(i); + lchrif_server_destroy(i); if( login->fd != -1 ) { @@ -2034,7 +2034,7 @@ void do_shutdown_login(void) ShowStatus("Shutting down...\n"); // TODO proper shutdown procedure; kick all characters, wait for acks, ... [FlavioJS] for (id = 0; id < ARRAYLENGTH(login->dbs->server); ++id) - chrif_server_reset(id); + lchrif_server_reset(id); sockt->flush_fifos(); core->runflag = CORE_ST_STOP; } @@ -2147,7 +2147,7 @@ int do_init(int argc, char** argv) sockt->net_config_read(login->NET_CONF_NAME); for (i = 0; i < ARRAYLENGTH(login->dbs->server); ++i) - chrif_server_init(i); + lchrif_server_init(i); // initialize logging if (login->config->log_login) -- cgit v1.2.3-60-g2f50 From 90e1201d43939e29dc0b0d8807694ff1f710a27f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 24 Jan 2018 17:55:36 +0300 Subject: Create lchrif interface in login.c --- src/login/login.c | 29 +++++++++++++++++++++-------- src/login/login.h | 12 ++++++++++++ 2 files changed, 33 insertions(+), 8 deletions(-) (limited to 'src/login/login.c') diff --git a/src/login/login.c b/src/login/login.c index 48fc81113..26f7d6da3 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -53,6 +53,8 @@ struct login_interface login_s; struct login_interface *login; struct s_login_dbs logindbs; +struct lchrif_interface lchrif_s; +struct lchrif_interface *lchrif; struct Login_Config login_config_; struct Account_engine account_engine[] = { @@ -204,8 +206,8 @@ void lchrif_server_destroy(int id) void lchrif_server_reset(int id) { login->online_db->foreach(login->online_db, login->online_db_setoffline, id); //Set all chars from this char server to offline. - lchrif_server_destroy(id); - lchrif_server_init(id); + lchrif->server_destroy(id); + lchrif->server_init(id); } @@ -214,7 +216,7 @@ void lchrif_on_disconnect(int id) { Assert_retv(id >= 0 && id < MAX_SERVERS); ShowStatus("Char-server '%s' has disconnected.\n", login->dbs->server[id].name); - lchrif_server_reset(id); + lchrif->server_reset(id); } @@ -807,7 +809,7 @@ int login_parse_fromchar(int fd) { sockt->close(fd); login->dbs->server[id].fd = -1; - lchrif_on_disconnect(id); + lchrif->on_disconnect(id); return 0; } @@ -1990,7 +1992,7 @@ int do_final(void) login->auth_db->destroy(login->auth_db, NULL); for (i = 0; i < ARRAYLENGTH(login->dbs->server); ++i) - lchrif_server_destroy(i); + lchrif->server_destroy(i); if( login->fd != -1 ) { @@ -2034,7 +2036,7 @@ void do_shutdown_login(void) ShowStatus("Shutting down...\n"); // TODO proper shutdown procedure; kick all characters, wait for acks, ... [FlavioJS] for (id = 0; id < ARRAYLENGTH(login->dbs->server); ++id) - lchrif_server_reset(id); + lchrif->server_reset(id); sockt->flush_fifos(); core->runflag = CORE_ST_STOP; } @@ -2106,6 +2108,7 @@ int do_init(int argc, char** argv) } ipban_defaults(); + lchrif_defaults(); login_defaults(); lclif_defaults(); @@ -2147,7 +2150,7 @@ int do_init(int argc, char** argv) sockt->net_config_read(login->NET_CONF_NAME); for (i = 0; i < ARRAYLENGTH(login->dbs->server); ++i) - lchrif_server_init(i); + lchrif->server_init(i); // initialize logging if (login->config->log_login) @@ -2207,7 +2210,8 @@ int do_init(int argc, char** argv) return 0; } -void login_defaults(void) { +void login_defaults(void) +{ login = &login_s; login->config = &login_config_; @@ -2284,3 +2288,12 @@ void login_defaults(void) { login->LOGIN_CONF_NAME = NULL; login->NET_CONF_NAME = NULL; } + +void lchrif_defaults(void) +{ + lchrif = &lchrif_s; + lchrif->server_init = lchrif_server_init; + lchrif->server_destroy = lchrif_server_destroy; + lchrif->server_reset = lchrif_server_reset; + lchrif->on_disconnect = lchrif_on_disconnect; +} diff --git a/src/login/login.h b/src/login/login.h index b846e2bb7..7b6d3371c 100644 --- a/src/login/login.h +++ b/src/login/login.h @@ -239,10 +239,22 @@ struct login_interface { char *NET_CONF_NAME; ///< Network configuration filename }; +/** + * Login.c Interface + **/ +struct lchrif_interface { + void (*server_init) (int id); + void (*server_destroy) (int id); + void (*server_reset) (int id); + void (*on_disconnect) (int id); +}; + #ifdef HERCULES_CORE void login_defaults(void); +void lchrif_defaults(void); #endif // HERCULES_CORE HPShared struct login_interface *login; +HPShared struct lchrif_interface *lchrif; #endif /* LOGIN_LOGIN_H */ -- cgit v1.2.3-60-g2f50 From f9c920a728d1a8406fa4a15a395eee23b9bccc7a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 6 Feb 2018 20:49:01 +0300 Subject: Add interface into loginlog.c. --- src/login/HPMlogin.c | 1 + src/login/ipban.c | 2 +- src/login/lclif.c | 2 +- src/login/login.c | 19 ++++++++++--------- src/login/loginlog.c | 21 ++++++++++++++++++--- src/login/loginlog.h | 25 +++++++++++++++++++------ src/plugins/HPMHooking.c | 1 + 7 files changed, 51 insertions(+), 20 deletions(-) (limited to 'src/login/login.c') diff --git a/src/login/HPMlogin.c b/src/login/HPMlogin.c index 65bdb1a71..4f63da6ac 100644 --- a/src/login/HPMlogin.c +++ b/src/login/HPMlogin.c @@ -29,6 +29,7 @@ #include "login/lclif.h" #include "login/lclif.p.h" #include "login/login.h" +#include "login/loginlog.h" #include "common/HPMi.h" #include "common/conf.h" #include "common/console.h" diff --git a/src/login/ipban.c b/src/login/ipban.c index 46798ea45..60a90fec9 100644 --- a/src/login/ipban.c +++ b/src/login/ipban.c @@ -269,7 +269,7 @@ void ipban_log(uint32 ip) 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) diff --git a/src/login/lclif.c b/src/login/lclif.c index 33445f92c..ae9f035e3 100644 --- a/src/login/lclif.c +++ b/src/login/lclif.c @@ -375,7 +375,7 @@ int lclif_parse(int fd) // Perform ip-ban check 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); - loginlog_log(ipl, "unknown", -3, "ip banned"); + loginlog->log(ipl, "unknown", -3, "ip banned"); lclif->login_error(fd, 3); // 3 = Rejected from Server sockt->eof(fd); return 0; diff --git a/src/login/login.c b/src/login/login.c index 26f7d6da3..24d1799df 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -727,7 +727,7 @@ bool login_fromchar_parse_wrong_pincode(int fd) return true; } - loginlog_log(sockt->host2ip(acc.last_ip), acc.userid, 100, "PIN Code check failed"); // FIXME: Do we really want to log this with the same code as successful logins? + loginlog->log(sockt->host2ip(acc.last_ip), acc.userid, 100, "PIN Code check failed"); // FIXME: Do we really want to log this with the same code as successful logins? } login->remove_online_user(acc.account_id); @@ -1260,7 +1260,7 @@ void login_auth_ok(struct login_session_data* sd) return; } - loginlog_log(ip, sd->userid, 100, "login ok"); + loginlog->log(ip, sd->userid, 100, "login ok"); ShowStatus("Connection of the account '%s' accepted.\n", sd->userid); // create temporary auth entry @@ -1324,7 +1324,7 @@ void login_auth_failed(struct login_session_data *sd, int result) default : error = "Unknown Error."; break; } - loginlog_log(ip, sd->userid, result, error); // FIXME: result can be 100, conflicting with the value 100 we use for successful login... + loginlog->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)) @@ -1432,7 +1432,7 @@ void login_parse_request_connection(int fd, struct login_session_data* sd, const ShowInfo("Connection request of the char-server '%s' @ %u.%u.%u.%u:%u (account: '%s', pass: '%s', ip: '%s')\n", server_name, CONVIP(server_ip), server_port, sd->userid, sd->passwd, ip); sprintf(message, "charserver - %s@%u.%u.%u.%u:%u", server_name, CONVIP(server_ip), server_port); - loginlog_log(sockt->session[fd]->client_addr, sd->userid, 100, message); + loginlog->log(sockt->session[fd]->client_addr, sd->userid, 100, message); result = login->mmo_auth(sd, true); if (core->runflag == LOGINSERVER_ST_RUNNING && @@ -1915,7 +1915,7 @@ bool login_config_read(const char *filename, bool imported) if (!login->config_read_users(filename, &config, imported)) retval = false; - if (!loginlog_config_read("conf/common/inter-server.conf", imported)) // Only inter-server + if (!loginlog->config_read("conf/common/inter-server.conf", imported)) // Only inter-server retval = false; if (!HPM->parse_conf(&config, filename, HPCT_LOGIN, imported)) @@ -1975,10 +1975,10 @@ int do_final(void) login->clear_client_hash_nodes(); login->clear_dnsbl_servers(); - loginlog_log(0, "login server", 100, "login server shutdown"); + loginlog->log(0, "login server", 100, "login server shutdown"); if (login->config->log_login) - loginlog_final(); + loginlog->final(); ipban->final(); @@ -2111,6 +2111,7 @@ int do_init(int argc, char** argv) lchrif_defaults(); login_defaults(); lclif_defaults(); + loginlog_defaults(); // read login-server configuration login->config_set_defaults(); @@ -2154,7 +2155,7 @@ int do_init(int argc, char** argv) // initialize logging if (login->config->log_login) - loginlog_init(); + loginlog->init(); // initialize static and dynamic ipban system ipban->init(); @@ -2203,7 +2204,7 @@ int do_init(int argc, char** argv) #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); - loginlog_log(0, "login server", 100, "login server started"); + loginlog->log(0, "login server", 100, "login server started"); HPM->event(HPET_READY); diff --git a/src/login/loginlog.c b/src/login/loginlog.c index 90dc3fde8..38be53193 100644 --- a/src/login/loginlog.c +++ b/src/login/loginlog.c @@ -45,6 +45,9 @@ static char log_login_db[256] = "loginlog"; static struct Sql *sql_handle = NULL; static bool enabled = false; +struct loginlog_interface loginlog_s; +struct loginlog_interface *loginlog; + // Returns the number of failed login attempts by the ip in the last minutes. unsigned long loginlog_failedattempts(uint32 ip, unsigned int minutes) @@ -206,16 +209,16 @@ bool loginlog_config_read(const char *filename, bool imported) if (!libconfig->load_file(&config, filename)) return false; // Error message is already shown by libconfig->load_file - if (!loginlog_config_read_names(filename, &config, imported)) + if (!loginlog->config_read_names(filename, &config, imported)) retval = false; - if (!loginlog_config_read_log(filename, &config, imported)) + if (!loginlog->config_read_log(filename, &config, imported)) retval = false; if (libconfig->lookup_string(&config, "import", &import) == CONFIG_TRUE) { if (strcmp(import, filename) == 0 || strcmp(import, "conf/common/inter-server.conf") == 0) { ShowWarning("inter_config_read: Loop detected! Skipping 'import'...\n"); } else { - if (!loginlog_config_read(import, true)) + if (!loginlog->config_read(import, true)) retval = false; } } @@ -223,3 +226,15 @@ bool loginlog_config_read(const char *filename, bool imported) libconfig->destroy(&config); return retval; } + +void loginlog_defaults(void) +{ + loginlog = &loginlog_s; + loginlog->failedattempts = loginlog_failedattempts; + loginlog->log = loginlog_log; + loginlog->init = loginlog_init; + loginlog->final = loginlog_final; + loginlog->config_read_names = loginlog_config_read_names; + loginlog->config_read_log = loginlog_config_read_log; + loginlog->config_read = loginlog_config_read; +} diff --git a/src/login/loginlog.h b/src/login/loginlog.h index 8153dd769..8edbedbaa 100644 --- a/src/login/loginlog.h +++ b/src/login/loginlog.h @@ -21,15 +21,28 @@ #ifndef LOGIN_LOGINLOG_H #define LOGIN_LOGINLOG_H +#include "common/hercules.h" #include "common/cbasetypes.h" +struct config_t; + +/** + * Loginlog.c Interface + **/ +struct loginlog_interface { + unsigned long (*failedattempts) (uint32 ip, unsigned int minutes); + void (*log) (uint32 ip, const char* username, int rcode, const char* message); + bool (*init) (void); + bool (*final) (void); + bool (*config_read_names) (const char *filename, struct config_t *config, bool imported); + bool (*config_read_log) (const char *filename, struct config_t *config, bool imported); + bool (*config_read) (const char *filename, bool imported); +}; + #ifdef HERCULES_CORE -// TODO: Interface -unsigned long loginlog_failedattempts(uint32 ip, unsigned int minutes); -void loginlog_log(uint32 ip, const char* username, int rcode, const char* message); -bool loginlog_init(void); -bool loginlog_final(void); -bool loginlog_config_read(const char *filename, bool imported); +void loginlog_defaults(void); #endif // HERCULES_CORE +HPShared struct loginlog_interface *loginlog; + #endif /* LOGIN_LOGINLOG_H */ diff --git a/src/plugins/HPMHooking.c b/src/plugins/HPMHooking.c index 3e556881e..8686a07be 100644 --- a/src/plugins/HPMHooking.c +++ b/src/plugins/HPMHooking.c @@ -39,6 +39,7 @@ PRAGMA_GCC5(GCC diagnostic ignored "-Wdiscarded-qualifiers") #include "login/lclif.h" #include "login/lclif.p.h" #include "login/login.h" +#include "login/loginlog.h" #elif defined (HPMHOOKING_CHAR) #define HPM_SERVER_TYPE SERVER_TYPE_CHAR #define HPM_CORE_INCLUDE "HPMHooking/HPMHooking_char.HPMHooksCore.inc" -- cgit v1.2.3-60-g2f50 From 082ceab8e14205d4b9a071bde8b47b5335389ceb Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 7 Feb 2018 01:36:35 +0300 Subject: Add account_engine into login interface. --- src/login/login.c | 23 ++++++++++++----------- src/login/login.h | 1 + 2 files changed, 13 insertions(+), 11 deletions(-) (limited to 'src/login/login.c') diff --git a/src/login/login.c b/src/login/login.c index 24d1799df..5b281c22d 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -57,9 +57,7 @@ struct lchrif_interface lchrif_s; struct lchrif_interface *lchrif; struct Login_Config login_config_; -struct Account_engine account_engine[] = { - {NULL, NULL} -}; +struct Account_engine account_engine; // account database AccountDB* accounts = NULL; @@ -1609,7 +1607,7 @@ bool login_config_read_log(const char *filename, struct config_t *config, bool i bool login_config_read_account(const char *filename, struct config_t *config, bool imported) { struct config_setting_t *setting = NULL; - AccountDB *db = account_engine[0].db; + AccountDB *db = login->dbs->account_engine->db; bool retval = true; nullpo_retr(false, filename); @@ -1982,10 +1980,10 @@ int do_final(void) ipban->final(); - if( account_engine[0].db ) + if (login->dbs->account_engine->db) {// destroy account engine - account_engine[0].db->destroy(account_engine[0].db); - account_engine[0].db = NULL; + login->dbs->account_engine->db->destroy(login->dbs->account_engine->db); + login->dbs->account_engine->db = NULL; } accounts = NULL; // destroyed in account_engine login->online_db->destroy(login->online_db, NULL); @@ -2097,11 +2095,12 @@ int do_init(int argc, char** argv) int i; account_defaults(); + login_defaults(); // initialize engine (to accept config settings) - account_engine[0].constructor = account->db_sql; - account_engine[0].db = account_engine[0].constructor(); - accounts = account_engine[0].db; + login->dbs->account_engine->constructor = account->db_sql; + login->dbs->account_engine->db = login->dbs->account_engine->constructor(); + accounts = login->dbs->account_engine->db; if( accounts == NULL ) { ShowFatalError("do_init: account engine 'sql' not found.\n"); exit(EXIT_FAILURE); @@ -2109,7 +2108,6 @@ int do_init(int argc, char** argv) ipban_defaults(); lchrif_defaults(); - login_defaults(); lclif_defaults(); loginlog_defaults(); @@ -2218,6 +2216,9 @@ void login_defaults(void) login->config = &login_config_; login->accounts = accounts; login->dbs = &logindbs; + login->dbs->account_engine = &account_engine; + login->dbs->account_engine->constructor = NULL; + login->dbs->account_engine->db = NULL; login->mmo_auth = login_mmo_auth; login->mmo_auth_new = login_mmo_auth_new; diff --git a/src/login/login.h b/src/login/login.h index 7b6d3371c..1a4a6d0a3 100644 --- a/src/login/login.h +++ b/src/login/login.h @@ -159,6 +159,7 @@ struct online_login_data { struct s_login_dbs { struct mmo_char_server server[MAX_SERVERS]; + struct Account_engine *account_engine; }; /** -- cgit v1.2.3-60-g2f50