summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2018-02-06 20:49:01 +0300
committerAndrei Karas <akaras@inbox.ru>2018-02-09 18:34:44 +0300
commitf9c920a728d1a8406fa4a15a395eee23b9bccc7a (patch)
tree7e5f4108f63259f8ddea30285137ee0fdd201529
parent90e1201d43939e29dc0b0d8807694ff1f710a27f (diff)
downloadhercules-f9c920a728d1a8406fa4a15a395eee23b9bccc7a.tar.gz
hercules-f9c920a728d1a8406fa4a15a395eee23b9bccc7a.tar.bz2
hercules-f9c920a728d1a8406fa4a15a395eee23b9bccc7a.tar.xz
hercules-f9c920a728d1a8406fa4a15a395eee23b9bccc7a.zip
Add interface into loginlog.c.
-rw-r--r--src/login/HPMlogin.c1
-rw-r--r--src/login/ipban.c2
-rw-r--r--src/login/lclif.c2
-rw-r--r--src/login/login.c19
-rw-r--r--src/login/loginlog.c21
-rw-r--r--src/login/loginlog.h25
-rw-r--r--src/plugins/HPMHooking.c1
7 files changed, 51 insertions, 20 deletions
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"