summaryrefslogtreecommitdiff
path: root/src/login/ipban_sql.c
diff options
context:
space:
mode:
authorFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2008-10-15 12:12:14 +0000
committerFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2008-10-15 12:12:14 +0000
commit07bde8db7bd90940be387e9337088d4640b9cb91 (patch)
treeb2e97b5dd01f7889056f9a5f31fc448d77b36d21 /src/login/ipban_sql.c
parent5217b4d9e852347f5ad95360b74b0efe4febec1b (diff)
downloadhercules-07bde8db7bd90940be387e9337088d4640b9cb91.tar.gz
hercules-07bde8db7bd90940be387e9337088d4640b9cb91.tar.bz2
hercules-07bde8db7bd90940be387e9337088d4640b9cb91.tar.xz
hercules-07bde8db7bd90940be387e9337088d4640b9cb91.zip
* Fixed ipban sql connecting to the sql server when disabled
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@13292 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/login/ipban_sql.c')
-rw-r--r--src/login/ipban_sql.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/login/ipban_sql.c b/src/login/ipban_sql.c
index aec74e06b..db383b908 100644
--- a/src/login/ipban_sql.c
+++ b/src/login/ipban_sql.c
@@ -33,6 +33,7 @@ static char ipban_table[32] = "ipbanlist";
// globals
static Sql* sql_handle = NULL;
static int cleanup_timer_id = INVALID_TIMER;
+static bool ipban_inited = false;
int ipban_cleanup(int tid, unsigned int tick, int id, intptr data);
@@ -47,6 +48,11 @@ void ipban_init(void)
const char* database;
const char* codepage;
+ ipban_inited = true;
+
+ if( !login_config.ipban )
+ return;// ipban disabled
+
if( ipban_db_hostname[0] != '\0' )
{// local settings
username = ipban_db_username;
@@ -85,6 +91,9 @@ void ipban_init(void)
// finalize
void ipban_final(void)
{
+ if( !login_config.ipban )
+ return;// ipban disabled
+
// release data
delete_timer(cleanup_timer_id, ipban_cleanup);
@@ -98,6 +107,9 @@ bool ipban_config_read(const char* key, const char* value)
{
const char* signature;
+ if( ipban_inited )
+ return false;// settings can only be changed before init
+
signature = "sql.";
if( strncmpi(key, signature, strlen(signature)) == 0 )
{
@@ -186,6 +198,9 @@ bool ipban_check(uint32 ip)
char* data = NULL;
int matches;
+ if( !login_config.ipban )
+ return false;// ipban disabled
+
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT count(*) FROM `%s` WHERE `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]) )
{
@@ -207,7 +222,12 @@ bool ipban_check(uint32 ip)
// log failed attempt
void ipban_log(uint32 ip)
{
- unsigned long failures = loginlog_failedattempts(ip, login_config.dynamic_pass_failure_ban_interval);// how many times failed account? in one ip.
+ unsigned long failures;
+
+ 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.
// if over the limit, add a temporary ban entry
if( failures >= login_config.dynamic_pass_failure_ban_limit )
@@ -222,6 +242,9 @@ void ipban_log(uint32 ip)
// remove expired bans
int ipban_cleanup(int tid, unsigned int tick, int id, intptr data)
{
+ if( !login_config.ipban )
+ return 0;// ipban disabled
+
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `ipbanlist` WHERE `rtime` <= NOW()") )
Sql_ShowDebug(sql_handle);