summaryrefslogtreecommitdiff
path: root/src/login
diff options
context:
space:
mode:
Diffstat (limited to 'src/login')
-rw-r--r--src/login/account_sql.c115
-rw-r--r--src/login/ipban_sql.c27
-rw-r--r--src/login/loginlog_sql.c29
3 files changed, 87 insertions, 84 deletions
diff --git a/src/login/account_sql.c b/src/login/account_sql.c
index 1d77f1975..565dd0460 100644
--- a/src/login/account_sql.c
+++ b/src/login/account_sql.c
@@ -1,5 +1,6 @@
-// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
+// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// See the LICENSE file
+// Portions Copyright (c) Athena Dev Teams
#include "../common/malloc.h"
#include "../common/mmo.h"
@@ -125,7 +126,7 @@ static bool account_db_sql_init(AccountDB* self)
const char* database;
const char* codepage;
- db->accounts = Sql_Malloc();
+ db->accounts = SQL->Malloc();
sql_handle = db->accounts;
if( db->db_hostname[0] != '\0' )
@@ -147,15 +148,15 @@ static bool account_db_sql_init(AccountDB* self)
codepage = db->global_codepage;
}
- if( SQL_ERROR == Sql_Connect(sql_handle, username, password, hostname, port, database) )
+ if( SQL_ERROR == SQL->Connect(sql_handle, username, password, hostname, port, database) )
{
Sql_ShowDebug(sql_handle);
- Sql_Free(db->accounts);
+ SQL->Free(db->accounts);
db->accounts = NULL;
return false;
}
- if( codepage[0] != '\0' && SQL_ERROR == Sql_SetEncoding(sql_handle, codepage) )
+ if( codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, codepage) )
Sql_ShowDebug(sql_handle);
return true;
@@ -166,7 +167,7 @@ static void account_db_sql_destroy(AccountDB* self)
{
AccountDB_SQL* db = (AccountDB_SQL*)self;
- Sql_Free(db->accounts);
+ SQL->Free(db->accounts);
db->accounts = NULL;
aFree(db);
}
@@ -348,21 +349,21 @@ static bool account_db_sql_create(AccountDB* self, struct mmo_account* acc)
char* data;
size_t len;
- if( SQL_SUCCESS != Sql_Query(sql_handle, "SELECT MAX(`account_id`)+1 FROM `%s`", db->account_db) )
+ if( SQL_SUCCESS != SQL->Query(sql_handle, "SELECT MAX(`account_id`)+1 FROM `%s`", db->account_db) )
{
Sql_ShowDebug(sql_handle);
return false;
}
- if( SQL_SUCCESS != Sql_NextRow(sql_handle) )
+ if( SQL_SUCCESS != SQL->NextRow(sql_handle) )
{
Sql_ShowDebug(sql_handle);
- Sql_FreeResult(sql_handle);
+ SQL->FreeResult(sql_handle);
return false;
}
- Sql_GetData(sql_handle, 0, &data, &len);
+ SQL->GetData(sql_handle, 0, &data, &len);
account_id = ( data != NULL ) ? atoi(data) : 0;
- Sql_FreeResult(sql_handle);
+ SQL->FreeResult(sql_handle);
if( account_id < START_ACCOUNT_NUM )
account_id = START_ACCOUNT_NUM;
@@ -389,14 +390,14 @@ static bool account_db_sql_remove(AccountDB* self, const int account_id)
Sql* sql_handle = db->accounts;
bool result = false;
- if( SQL_SUCCESS != Sql_QueryStr(sql_handle, "START TRANSACTION")
- || SQL_SUCCESS != Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = %d", db->account_db, account_id)
- || SQL_SUCCESS != Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = %d", db->accreg_db, account_id) )
+ if( SQL_SUCCESS != SQL->QueryStr(sql_handle, "START TRANSACTION")
+ || SQL_SUCCESS != SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = %d", db->account_db, account_id)
+ || SQL_SUCCESS != SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = %d", db->accreg_db, account_id) )
Sql_ShowDebug(sql_handle);
else
result = true;
- result &= ( SQL_SUCCESS == Sql_QueryStr(sql_handle, (result == true) ? "COMMIT" : "ROLLBACK") );
+ result &= ( SQL_SUCCESS == SQL->QueryStr(sql_handle, (result == true) ? "COMMIT" : "ROLLBACK") );
return result;
}
@@ -424,30 +425,30 @@ static bool account_db_sql_load_str(AccountDB* self, struct mmo_account* acc, co
int account_id;
char* data;
- Sql_EscapeString(sql_handle, esc_userid, userid);
+ SQL->EscapeString(sql_handle, esc_userid, userid);
// get the list of account IDs for this user ID
- if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id` FROM `%s` WHERE `userid`= %s '%s'",
+ if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id` FROM `%s` WHERE `userid`= %s '%s'",
db->account_db, (db->case_sensitive ? "BINARY" : ""), esc_userid) )
{
Sql_ShowDebug(sql_handle);
return false;
}
- if( Sql_NumRows(sql_handle) > 1 )
+ if( SQL->NumRows(sql_handle) > 1 )
{// serious problem - duplicit account
ShowError("account_db_sql_load_str: multiple accounts found when retrieving data for account '%s'!\n", userid);
- Sql_FreeResult(sql_handle);
+ SQL->FreeResult(sql_handle);
return false;
}
- if( SQL_SUCCESS != Sql_NextRow(sql_handle) )
+ if( SQL_SUCCESS != SQL->NextRow(sql_handle) )
{// no such entry
- Sql_FreeResult(sql_handle);
+ SQL->FreeResult(sql_handle);
return false;
}
- Sql_GetData(sql_handle, 0, &data, NULL);
+ SQL->GetData(sql_handle, 0, &data, NULL);
account_id = atoi(data);
return account_db_sql_load_num(self, acc, account_id);
@@ -489,15 +490,15 @@ static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account
char* data;
// get next account ID
- if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id` FROM `%s` WHERE `account_id` > '%d' ORDER BY `account_id` ASC LIMIT 1",
+ if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id` FROM `%s` WHERE `account_id` > '%d' ORDER BY `account_id` ASC LIMIT 1",
db->account_db, iter->last_account_id) )
{
Sql_ShowDebug(sql_handle);
return false;
}
- if( SQL_SUCCESS == Sql_NextRow(sql_handle) &&
- SQL_SUCCESS == Sql_GetData(sql_handle, 0, &data, NULL) &&
+ if( SQL_SUCCESS == SQL->NextRow(sql_handle) &&
+ SQL_SUCCESS == SQL->GetData(sql_handle, 0, &data, NULL) &&
data != NULL )
{// get account data
int account_id;
@@ -505,11 +506,11 @@ static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account
if( mmo_auth_fromsql(db, acc, account_id) )
{
iter->last_account_id = account_id;
- Sql_FreeResult(sql_handle);
+ SQL->FreeResult(sql_handle);
return true;
}
}
- Sql_FreeResult(sql_handle);
+ SQL->FreeResult(sql_handle);
return false;
}
@@ -521,7 +522,7 @@ static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int acc
int i = 0;
// retrieve login entry for the specified account
- if( SQL_ERROR == Sql_Query(sql_handle,
+ if( SQL_ERROR == SQL->Query(sql_handle,
"SELECT `account_id`,`userid`,`user_pass`,`sex`,`email`,`group_id`,`state`,`unban_time`,`expiration_time`,`logincount`,`lastlogin`,`last_ip`,`birthdate`,`character_slots`,`pincode`,`pincode_change` FROM `%s` WHERE `account_id` = %d",
db->account_db, account_id )
) {
@@ -529,49 +530,49 @@ static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int acc
return false;
}
- if( SQL_SUCCESS != Sql_NextRow(sql_handle) )
+ if( SQL_SUCCESS != SQL->NextRow(sql_handle) )
{// no such entry
- Sql_FreeResult(sql_handle);
+ SQL->FreeResult(sql_handle);
return false;
}
- Sql_GetData(sql_handle, 0, &data, NULL); acc->account_id = atoi(data);
- Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(acc->userid, data, sizeof(acc->userid));
- Sql_GetData(sql_handle, 2, &data, NULL); safestrncpy(acc->pass, data, sizeof(acc->pass));
- Sql_GetData(sql_handle, 3, &data, NULL); acc->sex = data[0];
- Sql_GetData(sql_handle, 4, &data, NULL); safestrncpy(acc->email, data, sizeof(acc->email));
- Sql_GetData(sql_handle, 5, &data, NULL); acc->group_id = atoi(data);
- Sql_GetData(sql_handle, 6, &data, NULL); acc->state = strtoul(data, NULL, 10);
- Sql_GetData(sql_handle, 7, &data, NULL); acc->unban_time = atol(data);
- Sql_GetData(sql_handle, 8, &data, NULL); acc->expiration_time = atol(data);
- Sql_GetData(sql_handle, 9, &data, NULL); acc->logincount = strtoul(data, NULL, 10);
- Sql_GetData(sql_handle, 10, &data, NULL); safestrncpy(acc->lastlogin, data, sizeof(acc->lastlogin));
- Sql_GetData(sql_handle, 11, &data, NULL); safestrncpy(acc->last_ip, data, sizeof(acc->last_ip));
- Sql_GetData(sql_handle, 12, &data, NULL); safestrncpy(acc->birthdate, data, sizeof(acc->birthdate));
- Sql_GetData(sql_handle, 13, &data, NULL); acc->char_slots = atoi(data);
- Sql_GetData(sql_handle, 14, &data, NULL); safestrncpy(acc->pincode, data, sizeof(acc->pincode));
- Sql_GetData(sql_handle, 15, &data, NULL); acc->pincode_change = atol(data);
+ SQL->GetData(sql_handle, 0, &data, NULL); acc->account_id = atoi(data);
+ SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(acc->userid, data, sizeof(acc->userid));
+ SQL->GetData(sql_handle, 2, &data, NULL); safestrncpy(acc->pass, data, sizeof(acc->pass));
+ SQL->GetData(sql_handle, 3, &data, NULL); acc->sex = data[0];
+ SQL->GetData(sql_handle, 4, &data, NULL); safestrncpy(acc->email, data, sizeof(acc->email));
+ SQL->GetData(sql_handle, 5, &data, NULL); acc->group_id = atoi(data);
+ SQL->GetData(sql_handle, 6, &data, NULL); acc->state = strtoul(data, NULL, 10);
+ SQL->GetData(sql_handle, 7, &data, NULL); acc->unban_time = atol(data);
+ SQL->GetData(sql_handle, 8, &data, NULL); acc->expiration_time = atol(data);
+ SQL->GetData(sql_handle, 9, &data, NULL); acc->logincount = strtoul(data, NULL, 10);
+ SQL->GetData(sql_handle, 10, &data, NULL); safestrncpy(acc->lastlogin, data, sizeof(acc->lastlogin));
+ SQL->GetData(sql_handle, 11, &data, NULL); safestrncpy(acc->last_ip, data, sizeof(acc->last_ip));
+ SQL->GetData(sql_handle, 12, &data, NULL); safestrncpy(acc->birthdate, data, sizeof(acc->birthdate));
+ SQL->GetData(sql_handle, 13, &data, NULL); acc->char_slots = atoi(data);
+ SQL->GetData(sql_handle, 14, &data, NULL); safestrncpy(acc->pincode, data, sizeof(acc->pincode));
+ SQL->GetData(sql_handle, 15, &data, NULL); acc->pincode_change = atol(data);
- Sql_FreeResult(sql_handle);
+ SQL->FreeResult(sql_handle);
// retrieve account regs for the specified user
- if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `str`,`value` FROM `%s` WHERE `type`='1' AND `account_id`='%d'", db->accreg_db, acc->account_id) )
+ if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `str`,`value` FROM `%s` WHERE `type`='1' AND `account_id`='%d'", db->accreg_db, acc->account_id) )
{
Sql_ShowDebug(sql_handle);
return false;
}
- acc->account_reg2_num = (int)Sql_NumRows(sql_handle);
+ acc->account_reg2_num = (int)SQL->NumRows(sql_handle);
- while( SQL_SUCCESS == Sql_NextRow(sql_handle) )
+ while( SQL_SUCCESS == SQL->NextRow(sql_handle) )
{
char* data;
- Sql_GetData(sql_handle, 0, &data, NULL); safestrncpy(acc->account_reg2[i].str, data, sizeof(acc->account_reg2[i].str));
- Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(acc->account_reg2[i].value, data, sizeof(acc->account_reg2[i].value));
+ SQL->GetData(sql_handle, 0, &data, NULL); safestrncpy(acc->account_reg2[i].str, data, sizeof(acc->account_reg2[i].str));
+ SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(acc->account_reg2[i].value, data, sizeof(acc->account_reg2[i].value));
++i;
}
- Sql_FreeResult(sql_handle);
+ SQL->FreeResult(sql_handle);
if( i != acc->account_reg2_num )
return false;
@@ -590,7 +591,7 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo
do
{
- if( SQL_SUCCESS != Sql_QueryStr(sql_handle, "START TRANSACTION") )
+ if( SQL_SUCCESS != SQL->QueryStr(sql_handle, "START TRANSACTION") )
{
Sql_ShowDebug(sql_handle);
break;
@@ -647,7 +648,7 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo
}
// remove old account regs
- if( SQL_SUCCESS != Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `type`='1' AND `account_id`='%d'", db->accreg_db, acc->account_id) )
+ if( SQL_SUCCESS != SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `type`='1' AND `account_id`='%d'", db->accreg_db, acc->account_id) )
{
Sql_ShowDebug(sql_handle);
break;
@@ -680,7 +681,7 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo
} while(0);
// finally
- result &= ( SQL_SUCCESS == Sql_QueryStr(sql_handle, (result == true) ? "COMMIT" : "ROLLBACK") );
+ result &= ( SQL_SUCCESS == SQL->QueryStr(sql_handle, (result == true) ? "COMMIT" : "ROLLBACK") );
SqlStmt_Free(stmt);
return result;
diff --git a/src/login/ipban_sql.c b/src/login/ipban_sql.c
index c75a1f956..701d3bc1d 100644
--- a/src/login/ipban_sql.c
+++ b/src/login/ipban_sql.c
@@ -1,5 +1,6 @@
-// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
+// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// See the LICENSE file
+// Portions Copyright (c) Athena Dev Teams
#include "../common/cbasetypes.h"
#include "../common/db.h"
@@ -73,14 +74,14 @@ void ipban_init(void)
}
// establish connections
- sql_handle = Sql_Malloc();
- if( SQL_ERROR == Sql_Connect(sql_handle, username, password, hostname, port, database) )
+ sql_handle = SQL->Malloc();
+ if( SQL_ERROR == SQL->Connect(sql_handle, username, password, hostname, port, database) )
{
Sql_ShowDebug(sql_handle);
- Sql_Free(sql_handle);
+ SQL->Free(sql_handle);
exit(EXIT_FAILURE);
}
- if( codepage[0] != '\0' && SQL_ERROR == Sql_SetEncoding(sql_handle, codepage) )
+ if( codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, codepage) )
Sql_ShowDebug(sql_handle);
if( login_config.ipban_cleanup_interval > 0 )
@@ -104,7 +105,7 @@ void ipban_final(void)
ipban_cleanup(0,0,0,0); // always clean up on login-server stop
// close connections
- Sql_Free(sql_handle);
+ SQL->Free(sql_handle);
sql_handle = NULL;
}
@@ -207,7 +208,7 @@ 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')",
+ 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]) )
{
Sql_ShowDebug(sql_handle);
@@ -215,12 +216,12 @@ bool ipban_check(uint32 ip)
return true;
}
- if( SQL_ERROR == Sql_NextRow(sql_handle) )
+ if( SQL_ERROR == SQL->NextRow(sql_handle) )
return true;// Shouldn't happen, but just in case...
- Sql_GetData(sql_handle, 0, &data, NULL);
+ SQL->GetData(sql_handle, 0, &data, NULL);
matches = atoi(data);
- Sql_FreeResult(sql_handle);
+ SQL->FreeResult(sql_handle);
return( matches > 0 );
}
@@ -239,7 +240,7 @@ 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 %d MINUTE ,'Password error ban')",
+ 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) )
Sql_ShowDebug(sql_handle);
}
@@ -251,7 +252,7 @@ int ipban_cleanup(int tid, unsigned int tick, int id, intptr_t data)
if( !login_config.ipban )
return 0;// ipban disabled
- if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `ipbanlist` WHERE `rtime` <= NOW()") )
+ if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `ipbanlist` WHERE `rtime` <= NOW()") )
Sql_ShowDebug(sql_handle);
return 0;
diff --git a/src/login/loginlog_sql.c b/src/login/loginlog_sql.c
index d61172697..231ac783b 100644
--- a/src/login/loginlog_sql.c
+++ b/src/login/loginlog_sql.c
@@ -1,5 +1,6 @@
-// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
+// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// See the LICENSE file
+// Portions Copyright (c) Athena Dev Teams
#include "../common/cbasetypes.h"
#include "../common/mmo.h"
@@ -37,16 +38,16 @@ 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 %d MINUTE",
log_login_db, ip2str(ip,NULL), minutes) )// how many times failed account? in one ip.
Sql_ShowDebug(sql_handle);
- if( SQL_SUCCESS == Sql_NextRow(sql_handle) )
+ if( SQL_SUCCESS == SQL->NextRow(sql_handle) )
{
char* data;
- Sql_GetData(sql_handle, 0, &data, NULL);
+ SQL->GetData(sql_handle, 0, &data, NULL);
failures = strtoul(data, NULL, 10);
- Sql_FreeResult(sql_handle);
+ SQL->FreeResult(sql_handle);
}
return failures;
}
@@ -64,10 +65,10 @@ void login_log(uint32 ip, const char* username, int rcode, const char* message)
if( !enabled )
return;
- Sql_EscapeStringLen(sql_handle, esc_username, username, strnlen(username, NAME_LENGTH));
- Sql_EscapeStringLen(sql_handle, esc_message, message, strnlen(message, 255));
+ SQL->EscapeStringLen(sql_handle, esc_username, username, strnlen(username, NAME_LENGTH));
+ SQL->EscapeStringLen(sql_handle, esc_message, message, strnlen(message, 255));
- retcode = Sql_Query(sql_handle,
+ retcode = SQL->Query(sql_handle,
"INSERT INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '%s', '%s', '%d', '%s')",
log_login_db, ip2str(ip,NULL), esc_username, rcode, esc_message);
@@ -103,16 +104,16 @@ bool loginlog_init(void)
codepage = global_codepage;
}
- sql_handle = Sql_Malloc();
+ sql_handle = SQL->Malloc();
- if( SQL_ERROR == Sql_Connect(sql_handle, username, password, hostname, port, database) )
+ if( SQL_ERROR == SQL->Connect(sql_handle, username, password, hostname, port, database) )
{
Sql_ShowDebug(sql_handle);
- Sql_Free(sql_handle);
+ SQL->Free(sql_handle);
exit(EXIT_FAILURE);
}
- if( codepage[0] != '\0' && SQL_ERROR == Sql_SetEncoding(sql_handle, codepage) )
+ if( codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, codepage) )
Sql_ShowDebug(sql_handle);
enabled = true;
@@ -122,7 +123,7 @@ bool loginlog_init(void)
bool loginlog_final(void)
{
- Sql_Free(sql_handle);
+ SQL->Free(sql_handle);
sql_handle = NULL;
return true;
}