From 6813c20bb80ccbb390b320539b2d186aeb989f33 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 16 Jan 2018 02:34:27 +0300 Subject: Remove suffix "_sql" from files in login directory. --- src/login/Makefile.in | 2 +- src/login/account.c | 871 +++++++++++++++++++++++++++++++++ src/login/account_sql.c | 871 --------------------------------- src/login/ipban.c | 308 ++++++++++++ src/login/ipban_sql.c | 308 ------------ src/login/loginlog.c | 225 +++++++++ src/login/loginlog_sql.c | 225 --------- vcproj-11/login-server.vcxproj | 6 +- vcproj-11/login-server.vcxproj.filters | 6 +- vcproj-12/login-server.vcxproj | 6 +- vcproj-12/login-server.vcxproj.filters | 6 +- vcproj-14/login-server.vcxproj | 6 +- vcproj-14/login-server.vcxproj.filters | 6 +- 13 files changed, 1423 insertions(+), 1423 deletions(-) create mode 100644 src/login/account.c delete mode 100644 src/login/account_sql.c create mode 100644 src/login/ipban.c delete mode 100644 src/login/ipban_sql.c create mode 100644 src/login/loginlog.c delete mode 100644 src/login/loginlog_sql.c diff --git a/src/login/Makefile.in b/src/login/Makefile.in index 69cc6a897..d0258deb0 100644 --- a/src/login/Makefile.in +++ b/src/login/Makefile.in @@ -40,7 +40,7 @@ MT19937AR_D = $(THIRDPARTY_D)/mt19937ar MT19937AR_OBJ = $(MT19937AR_D)/mt19937ar.o MT19937AR_H = $(MT19937AR_D)/mt19937ar.h -LOGIN_C = account_sql.c HPMlogin.c ipban_sql.c lclif.c login.c loginlog_sql.c +LOGIN_C = account.c HPMlogin.c ipban.c lclif.c login.c loginlog.c LOGIN_OBJ = $(addprefix obj_sql/, $(patsubst %.c,%.o,$(LOGIN_C))) LOGIN_H = login.h account.h HPMlogin.h ipban.h lclif.h loginlog.h LOGIN_PH = lclif.p.h diff --git a/src/login/account.c b/src/login/account.c new file mode 100644 index 000000000..66ede6cfa --- /dev/null +++ b/src/login/account.c @@ -0,0 +1,871 @@ +/** + * This file is part of Hercules. + * http://herc.ws - http://github.com/HerculesWS/Hercules + * + * Copyright (C) 2012-2016 Hercules Dev Team + * Copyright (C) Athena Dev Teams + * + * Hercules is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#define HERCULES_CORE + +#include "config/core.h" // CONSOLE_INPUT +#include "account.h" + +#include "common/cbasetypes.h" +#include "common/conf.h" +#include "common/console.h" +#include "common/memmgr.h" +#include "common/mmo.h" +#include "common/nullpo.h" +#include "common/showmsg.h" +#include "common/socket.h" +#include "common/sql.h" +#include "common/strlib.h" + +#include + +/// 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 mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int account_id); +static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, bool is_new); + +/// public constructor +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; + + // initialize to default values + db->accounts = NULL; + // Sql settings + safestrncpy(db->db_hostname, "127.0.0.1", sizeof(db->db_hostname)); + db->db_port = 3306; + safestrncpy(db->db_username, "ragnarok", sizeof(db->db_username)); + safestrncpy(db->db_password, "ragnarok", sizeof(db->db_password)); + safestrncpy(db->db_database, "ragnarok", sizeof(db->db_database)); + safestrncpy(db->codepage, "", sizeof(db->codepage)); + // other settings + db->case_sensitive = false; + safestrncpy(db->account_db, "login", sizeof(db->account_db)); + safestrncpy(db->global_acc_reg_num_db, "global_acc_reg_num_db", sizeof(db->global_acc_reg_num_db)); + safestrncpy(db->global_acc_reg_str_db, "global_acc_reg_str_db", sizeof(db->global_acc_reg_str_db)); + + return &db->vtable; +} + + +/* ------------------------------------------------------------------------- */ + + +/// establishes database connection +static bool account_db_sql_init(AccountDB* self) +{ + AccountDB_SQL* db = (AccountDB_SQL*)self; + struct Sql *sql_handle = NULL; + + nullpo_ret(db); + + db->accounts = SQL->Malloc(); + sql_handle = db->accounts; + + if (SQL_ERROR == SQL->Connect(sql_handle, db->db_username, db->db_password, + db->db_hostname, db->db_port, db->db_database)) { + Sql_ShowDebug(sql_handle); + SQL->Free(db->accounts); + db->accounts = NULL; + return false; + } + + if (db->codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, db->codepage)) + Sql_ShowDebug(sql_handle); + + Sql_HerculesUpdateCheck(db->accounts); +#ifdef CONSOLE_INPUT + console->input->setSQL(db->accounts); +#endif + return true; +} + +/// disconnects from database +static void account_db_sql_destroy(AccountDB* self) +{ + AccountDB_SQL* db = (AccountDB_SQL*)self; + + nullpo_retv(db); + SQL->Free(db->accounts); + db->accounts = NULL; + aFree(db); +} + +/// Gets a property from this database. +static bool account_db_sql_get_property(AccountDB* self, const char* key, char* buf, size_t buflen) +{ + /* TODO: + * This functionality is not being used as of now, it was removed in + * commit 5479f9631f8579d03fbfd14d8a49c7976226a156, it is meant to get + * engine properties when more than one engine is available. I'll + * re-add it as soon as I can, following the new standards. If anyone + * is interested in this functionality you can contact me in our boards + * and I'll try to add it sooner (Pan) [Panikon] + */ +#if 0 + AccountDB_SQL* db = (AccountDB_SQL*)self; + const char* signature; + + nullpo_ret(db); + nullpo_ret(key); + nullpo_ret(buf); + signature = "engine."; + if( strncmpi(key, signature, strlen(signature)) == 0 ) + { + key += strlen(signature); + if( strcmpi(key, "name") == 0 ) + safesnprintf(buf, buflen, "sql"); + else + if( strcmpi(key, "version") == 0 ) + safesnprintf(buf, buflen, "%d", ACCOUNT_SQL_DB_VERSION); + else + if( strcmpi(key, "comment") == 0 ) + safesnprintf(buf, buflen, "SQL Account Database"); + else + return false;// not found + return true; + } + + signature = "account.sql."; + if( strncmpi(key, signature, strlen(signature)) == 0 ) + { + key += strlen(signature); + if( strcmpi(key, "db_hostname") == 0 ) + safesnprintf(buf, buflen, "%s", db->db_hostname); + else + if( strcmpi(key, "db_port") == 0 ) + safesnprintf(buf, buflen, "%d", db->db_port); + else + if( strcmpi(key, "db_username") == 0 ) + safesnprintf(buf, buflen, "%s", db->db_username); + else + if( strcmpi(key, "db_password") == 0 ) + safesnprintf(buf, buflen, "%s", db->db_password); + else + if( strcmpi(key, "db_database") == 0 ) + safesnprintf(buf, buflen, "%s", db->db_database); + else + if( strcmpi(key, "codepage") == 0 ) + safesnprintf(buf, buflen, "%s", db->codepage); + else + if( strcmpi(key, "case_sensitive") == 0 ) + safesnprintf(buf, buflen, "%d", (db->case_sensitive ? 1 : 0)); + else + if( strcmpi(key, "account_db") == 0 ) + safesnprintf(buf, buflen, "%s", db->account_db); + else + if( strcmpi(key, "global_acc_reg_str_db") == 0 ) + safesnprintf(buf, buflen, "%s", db->global_acc_reg_str_db); + else + if( strcmpi(key, "global_acc_reg_num_db") == 0 ) + safesnprintf(buf, buflen, "%s", db->global_acc_reg_num_db); + else + return false;// not found + return true; + } + + return false;// not found +#endif // 0 + return false; +} + +/** + * Reads the 'inter_configuration' config file and initializes required variables. + * + * @param db Self. + * @param filename Path to configuration file + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool account_db_read_inter(AccountDB_SQL *db, const char *filename, bool imported) +{ + struct config_t config; + struct config_setting_t *setting = NULL; + + nullpo_retr(false, db); + nullpo_retr(false, filename); + + if (!libconfig->load_file(&config, filename)) + return false; // Error message is already shown by libconfig->load_file + + if ((setting = libconfig->lookup(&config, "inter_configuration/database_names")) == NULL) { + libconfig->destroy(&config); + if (imported) + return true; + ShowError("account_db_sql_set_property: inter_configuration/database_names was not found!\n"); + return false; + } + libconfig->setting_lookup_mutable_string(setting, "account_db", db->account_db, sizeof(db->account_db)); + + if ((setting = libconfig->lookup(&config, "inter_configuration/database_names/registry")) == NULL) { + libconfig->destroy(&config); + if (imported) + return true; + ShowError("account_db_sql_set_property: inter_configuration/database_names/registry was not found!\n"); + return false; + } + libconfig->setting_lookup_mutable_string(setting, "global_acc_reg_str_db", db->global_acc_reg_str_db, sizeof(db->global_acc_reg_str_db)); + libconfig->setting_lookup_mutable_string(setting, "global_acc_reg_num_db", db->global_acc_reg_num_db, sizeof(db->global_acc_reg_num_db)); + + // TODO: Proper import mechanism for this file + + libconfig->destroy(&config); + return true; +} + +/** + * Loads the sql configuration. + * + * @param self Self. + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +static bool account_db_sql_set_property(AccountDB* self, struct config_t *config, bool imported) +{ + AccountDB_SQL* db = (AccountDB_SQL*)self; + struct config_setting_t *setting = NULL; + + nullpo_ret(db); + nullpo_ret(config); + + if ((setting = libconfig->lookup(config, "login_configuration/account/sql_connection")) == NULL) { + if (imported) + return true; + ShowError("account_db_sql_set_property: login_configuration/account/sql_connection was not found!\n"); + ShowWarning("account_db_sql_set_property: Defaulting sql_connection...\n"); + return false; + } + + libconfig->setting_lookup_mutable_string(setting, "db_hostname", db->db_hostname, sizeof(db->db_hostname)); + libconfig->setting_lookup_mutable_string(setting, "db_username", db->db_username, sizeof(db->db_username)); + libconfig->setting_lookup_mutable_string(setting, "db_password", db->db_password, sizeof(db->db_password)); + libconfig->setting_lookup_mutable_string(setting, "db_database", db->db_database, sizeof(db->db_database)); + libconfig->setting_lookup_mutable_string(setting, "codepage", db->codepage, sizeof(db->codepage)); // FIXME: Why do we need both codepage and default_codepage? + 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); + + return true; +} + +/// create a new account entry +/// If acc->account_id is -1, the account id will be auto-generated, +/// and its value will be written to acc->account_id if everything succeeds. +static bool account_db_sql_create(AccountDB* self, struct mmo_account* acc) +{ + AccountDB_SQL* db = (AccountDB_SQL*)self; + struct Sql *sql_handle; + + // decide on the account id to assign + int account_id; + nullpo_ret(db); + nullpo_ret(acc); + sql_handle = db->accounts; + if( acc->account_id != -1 ) + {// caller specifies it manually + account_id = acc->account_id; + } + else + {// ask the database + char* data; + size_t len; + + 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) ) + { + Sql_ShowDebug(sql_handle); + SQL->FreeResult(sql_handle); + return false; + } + + SQL->GetData(sql_handle, 0, &data, &len); + account_id = ( data != NULL ) ? atoi(data) : 0; + SQL->FreeResult(sql_handle); + + if( account_id < START_ACCOUNT_NUM ) + account_id = START_ACCOUNT_NUM; + + } + + // zero value is prohibited + if( account_id == 0 ) + return false; + + // absolute maximum + if( account_id > END_ACCOUNT_NUM ) + return false; + + // insert the data into the database + acc->account_id = account_id; + return mmo_auth_tosql(db, acc, true); +} + +/// delete an existing account entry + its regs +static bool account_db_sql_remove(AccountDB* self, const int account_id) +{ + AccountDB_SQL* db = (AccountDB_SQL*)self; + struct Sql *sql_handle; + bool result = false; + + nullpo_ret(db); + sql_handle = db->accounts; + 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->global_acc_reg_num_db, account_id) + || SQL_SUCCESS != SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = %d", db->global_acc_reg_str_db, account_id) + ) + Sql_ShowDebug(sql_handle); + else + result = true; + + result &= ( SQL_SUCCESS == SQL->QueryStr(sql_handle, (result == true) ? "COMMIT" : "ROLLBACK") ); + + return result; +} + +/// update an existing account with the provided new data (both account and regs) +static bool account_db_sql_save(AccountDB* self, const struct mmo_account* acc) +{ + AccountDB_SQL* db = (AccountDB_SQL*)self; + return 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 mmo_auth_fromsql(db, acc, account_id); +} + +/// retrieve data from db and store it in the provided data structure +static bool account_db_sql_load_str(AccountDB* self, struct mmo_account* acc, const char* userid) +{ + AccountDB_SQL* db = (AccountDB_SQL*)self; + struct Sql *sql_handle; + char esc_userid[2*NAME_LENGTH+1]; + int account_id; + char* data; + + nullpo_ret(db); + sql_handle = db->accounts; + 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'", + db->account_db, (db->case_sensitive ? "BINARY" : ""), esc_userid) ) + { + Sql_ShowDebug(sql_handle); + return false; + } + + if( SQL->NumRows(sql_handle) > 1 ) + {// serious problem - duplicate account + ShowError("account_db_sql_load_str: multiple accounts found when retrieving data for account '%s'!\n", userid); + SQL->FreeResult(sql_handle); + return false; + } + + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) + {// no such entry + SQL->FreeResult(sql_handle); + return false; + } + + SQL->GetData(sql_handle, 0, &data, NULL); + account_id = atoi(data); + + return account_db_sql_load_num(self, acc, account_id); +} + + +/// Returns a new forward iterator. +static AccountDBIterator* account_db_sql_iterator(AccountDB* self) +{ + AccountDB_SQL* db = (AccountDB_SQL*)self; + AccountDBIterator_SQL* iter; + + 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; + + // fill data + iter->db = db; + iter->last_account_id = -1; + + return &iter->vtable; +} + + +/// Destroys this iterator, releasing all allocated memory (including itself). +static void account_db_sql_iter_destroy(AccountDBIterator* self) +{ + AccountDBIterator_SQL* iter = (AccountDBIterator_SQL*)self; + aFree(iter); +} + + +/// Fetches the next account in the database. +static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account* acc) +{ + AccountDBIterator_SQL* iter = (AccountDBIterator_SQL*)self; + AccountDB_SQL* db; + struct Sql *sql_handle; + char* data; + + nullpo_ret(iter); + db = (AccountDB_SQL*)iter->db; + nullpo_ret(db); + sql_handle = db->accounts; + // 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", + 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) && + data != NULL ) + {// get account data + int account_id; + account_id = atoi(data); + if( mmo_auth_fromsql(db, acc, account_id) ) + { + iter->last_account_id = account_id; + SQL->FreeResult(sql_handle); + return true; + } + } + SQL->FreeResult(sql_handle); + return false; +} + + +static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int account_id) +{ + struct Sql *sql_handle; + char* data; + + nullpo_ret(db); + nullpo_ret(acc); + sql_handle = db->accounts; + // retrieve login entry for the specified account + 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 ) + ) { + Sql_ShowDebug(sql_handle); + return false; + } + + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) + {// no such entry + 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 = (unsigned int)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 = (unsigned int)strtoul(data, NULL, 10); + SQL->GetData(sql_handle, 10, &data, NULL); safestrncpy(acc->lastlogin, data != NULL ? data : "(never)", 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 != NULL ? data : "0000-00-00", sizeof(acc->birthdate)); + SQL->GetData(sql_handle, 13, &data, NULL); acc->char_slots = (uint8)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 = (unsigned int)atol(data); + + SQL->FreeResult(sql_handle); + + return true; +} + +static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, bool is_new) +{ + struct Sql *sql_handle; + struct SqlStmt *stmt; + bool result = false; + + nullpo_ret(db); + nullpo_ret(acc); + sql_handle = db->accounts; + stmt = SQL->StmtMalloc(sql_handle); + + // try + do + { + + if( SQL_SUCCESS != SQL->QueryStr(sql_handle, "START TRANSACTION") ) + { + Sql_ShowDebug(sql_handle); + break; + } + + if( is_new ) + {// insert into account table + if( SQL_SUCCESS != SQL->StmtPrepare(stmt, + "INSERT INTO `%s` (`account_id`, `userid`, `user_pass`, `sex`, `email`, `group_id`, `state`, `unban_time`, `expiration_time`, `logincount`, `lastlogin`, `last_ip`, `birthdate`, `character_slots`, `pincode`, `pincode_change`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + db->account_db) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_INT, &acc->account_id, sizeof acc->account_id) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, acc->userid, strlen(acc->userid)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 2, SQLDT_STRING, acc->pass, strlen(acc->pass)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 3, SQLDT_ENUM, &acc->sex, sizeof acc->sex) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 4, SQLDT_STRING, &acc->email, strlen(acc->email)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 5, SQLDT_INT, &acc->group_id, sizeof acc->group_id) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 6, SQLDT_UINT, &acc->state, sizeof acc->state) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 7, SQLDT_TIME, &acc->unban_time, sizeof acc->unban_time) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 8, SQLDT_TIME, &acc->expiration_time, sizeof acc->expiration_time) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 9, SQLDT_UINT, &acc->logincount, sizeof acc->logincount) + || SQL_SUCCESS != (acc->lastlogin[0] < '1' || acc->lastlogin[0] > '9' ? + SQL->StmtBindParam(stmt, 10, SQLDT_NULL, NULL, 0) : + SQL->StmtBindParam(stmt, 10, SQLDT_STRING, &acc->lastlogin, strlen(acc->lastlogin)) + ) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 11, SQLDT_STRING, &acc->last_ip, strlen(acc->last_ip)) + || SQL_SUCCESS != (acc->birthdate[0] == '0' ? + SQL->StmtBindParam(stmt, 12, SQLDT_NULL, NULL, 0) : + SQL->StmtBindParam(stmt, 12, SQLDT_STRING, &acc->birthdate, strlen(acc->birthdate)) + ) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 13, SQLDT_UINT8, &acc->char_slots, sizeof acc->char_slots) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 14, SQLDT_STRING, &acc->pincode, strlen(acc->pincode)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 15, SQLDT_UINT, &acc->pincode_change, sizeof acc->pincode_change) + || SQL_SUCCESS != SQL->StmtExecute(stmt) + ) { + SqlStmt_ShowDebug(stmt); + break; + } + } else {// update account table + if( SQL_SUCCESS != SQL->StmtPrepare(stmt, "UPDATE `%s` SET `userid`=?,`user_pass`=?,`sex`=?,`email`=?,`group_id`=?,`state`=?,`unban_time`=?,`expiration_time`=?,`logincount`=?,`lastlogin`=?,`last_ip`=?,`birthdate`=?,`character_slots`=?,`pincode`=?,`pincode_change`=? WHERE `account_id` = '%d'", db->account_db, acc->account_id) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_STRING, acc->userid, strlen(acc->userid)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, acc->pass, strlen(acc->pass)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 2, SQLDT_ENUM, &acc->sex, sizeof acc->sex) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 3, SQLDT_STRING, acc->email, strlen(acc->email)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 4, SQLDT_INT, &acc->group_id, sizeof acc->group_id) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 5, SQLDT_UINT, &acc->state, sizeof acc->state) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 6, SQLDT_TIME, &acc->unban_time, sizeof acc->unban_time) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 7, SQLDT_TIME, &acc->expiration_time, sizeof acc->expiration_time) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 8, SQLDT_UINT, &acc->logincount, sizeof acc->logincount) + || SQL_SUCCESS != (acc->lastlogin[0] < '1' || acc->lastlogin[0] > '9' ? + SQL->StmtBindParam(stmt, 9, SQLDT_NULL, NULL, 0) : + SQL->StmtBindParam(stmt, 9, SQLDT_STRING, &acc->lastlogin, strlen(acc->lastlogin)) + ) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 10, SQLDT_STRING, &acc->last_ip, strlen(acc->last_ip)) + || SQL_SUCCESS != (acc->birthdate[0] == '0' ? + SQL->StmtBindParam(stmt, 11, SQLDT_NULL, NULL, 0) : + SQL->StmtBindParam(stmt, 11, SQLDT_STRING, &acc->birthdate, strlen(acc->birthdate)) + ) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 12, SQLDT_UINT8, &acc->char_slots, sizeof acc->char_slots) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 13, SQLDT_STRING, &acc->pincode, strlen(acc->pincode)) + || SQL_SUCCESS != SQL->StmtBindParam(stmt, 14, SQLDT_UINT, &acc->pincode_change, sizeof acc->pincode_change) + || SQL_SUCCESS != SQL->StmtExecute(stmt) + ) { + SqlStmt_ShowDebug(stmt); + break; + } + } + + // if we got this far, everything was successful + result = true; + + } while(0); + // finally + + result &= ( SQL_SUCCESS == SQL->QueryStr(sql_handle, (result == true) ? "COMMIT" : "ROLLBACK") ); + SQL->StmtFree(stmt); + + return result; +} + +struct Sql *account_db_sql_up(AccountDB* self) +{ + AccountDB_SQL* db = (AccountDB_SQL*)self; + return db ? db->accounts : NULL; +} +void mmo_save_accreg2(AccountDB* self, int fd, int account_id, int char_id) +{ + struct Sql *sql_handle; + AccountDB_SQL* db = (AccountDB_SQL*)self; + int count = RFIFOW(fd, 12); + + nullpo_retv(db); + sql_handle = db->accounts; + if (count) { + int cursor = 14, i; + char key[SCRIPT_VARNAME_LENGTH+1], sval[254]; + + for (i = 0; i < count; i++) { + unsigned int index; + int len = RFIFOB(fd, cursor); + safestrncpy(key, RFIFOP(fd, cursor + 1), min((int)sizeof(key), len)); + cursor += len + 1; + + index = RFIFOL(fd, cursor); + cursor += 4; + + switch (RFIFOB(fd, cursor++)) { + /* int */ + case 0: + if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`account_id`,`key`,`index`,`value`) VALUES ('%d','%s','%u','%u')", db->global_acc_reg_num_db, account_id, key, index, RFIFOL(fd, cursor)) ) + Sql_ShowDebug(sql_handle); + cursor += 4; + break; + case 1: + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `key` = '%s' AND `index` = '%u' LIMIT 1", db->global_acc_reg_num_db, account_id, key, index) ) + Sql_ShowDebug(sql_handle); + break; + /* str */ + case 2: + len = RFIFOB(fd, cursor); + safestrncpy(sval, RFIFOP(fd, cursor + 1), min((int)sizeof(sval), len)); + cursor += len + 1; + if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`account_id`,`key`,`index`,`value`) VALUES ('%d','%s','%u','%s')", db->global_acc_reg_str_db, account_id, key, index, sval) ) + Sql_ShowDebug(sql_handle); + break; + case 3: + if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `key` = '%s' AND `index` = '%u' LIMIT 1", db->global_acc_reg_str_db, account_id, key, index) ) + Sql_ShowDebug(sql_handle); + break; + default: + ShowError("mmo_save_accreg2: DA HOO UNKNOWN TYPE %d\n",RFIFOB(fd, cursor - 1)); + return; + } + } + } +} + +void mmo_send_accreg2(AccountDB* self, int fd, int account_id, int char_id) +{ + struct Sql *sql_handle; + AccountDB_SQL* db = (AccountDB_SQL*)self; + char* data; + int plen = 0; + size_t len; + + nullpo_retv(db); + sql_handle = db->accounts; + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `account_id`='%d'", db->global_acc_reg_str_db, account_id) ) + Sql_ShowDebug(sql_handle); + + WFIFOHEAD(fd, 60000 + 300); + WFIFOW(fd, 0) = 0x3804; + /* 0x2 = length, set prior to being sent */ + WFIFOL(fd, 4) = account_id; + WFIFOL(fd, 8) = char_id; + WFIFOB(fd, 12) = 0;/* var type (only set when all vars have been sent, regardless of type) */ + WFIFOB(fd, 13) = 1;/* is string type */ + WFIFOW(fd, 14) = 0;/* count */ + plen = 16; + + /** + * Vessel! + * + * str type + * { keyLength(B), key(), index(L), valLength(B), val() } + **/ + while ( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { + SQL->GetData(sql_handle, 0, &data, NULL); + len = strlen(data)+1; + + WFIFOB(fd, plen) = (unsigned char)len;/* won't be higher; the column size is 32 */ + plen += 1; + + safestrncpy(WFIFOP(fd,plen), data, len); + plen += len; + + SQL->GetData(sql_handle, 1, &data, NULL); + + WFIFOL(fd, plen) = (unsigned int)atol(data); + plen += 4; + + SQL->GetData(sql_handle, 2, &data, NULL); + len = strlen(data)+1; + + WFIFOB(fd, plen) = (unsigned char)len;/* won't be higher; the column size is 254 */ + plen += 1; + + safestrncpy(WFIFOP(fd,plen), data, len); + plen += len; + + WFIFOW(fd, 14) += 1; + + if( plen > 60000 ) { + WFIFOW(fd, 2) = plen; + WFIFOSET(fd, plen); + + /* prepare follow up */ + WFIFOHEAD(fd, 60000 + 300); + WFIFOW(fd, 0) = 0x3804; + /* 0x2 = length, set prior to being sent */ + WFIFOL(fd, 4) = account_id; + WFIFOL(fd, 8) = char_id; + WFIFOB(fd, 12) = 0;/* var type (only set when all vars have been sent, regardless of type) */ + WFIFOB(fd, 13) = 1;/* is string type */ + WFIFOW(fd, 14) = 0;/* count */ + plen = 16; + } + } + + /* mark & go. */ + WFIFOW(fd, 2) = plen; + WFIFOSET(fd, plen); + + SQL->FreeResult(sql_handle); + + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `account_id`='%d'", db->global_acc_reg_num_db, account_id) ) + Sql_ShowDebug(sql_handle); + + WFIFOHEAD(fd, 60000 + 300); + WFIFOW(fd, 0) = 0x3804; + /* 0x2 = length, set prior to being sent */ + WFIFOL(fd, 4) = account_id; + WFIFOL(fd, 8) = char_id; + WFIFOB(fd, 12) = 0;/* var type (only set when all vars have been sent, regardless of type) */ + WFIFOB(fd, 13) = 0;/* is int type */ + WFIFOW(fd, 14) = 0;/* count */ + plen = 16; + + /** + * Vessel! + * + * int type + * { keyLength(B), key(), index(L), value(L) } + **/ + while ( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { + SQL->GetData(sql_handle, 0, &data, NULL); + len = strlen(data)+1; + + WFIFOB(fd, plen) = (unsigned char)len;/* won't be higher; the column size is 32 */ + plen += 1; + + safestrncpy(WFIFOP(fd,plen), data, len); + plen += len; + + SQL->GetData(sql_handle, 1, &data, NULL); + + WFIFOL(fd, plen) = (unsigned int)atol(data); + plen += 4; + + SQL->GetData(sql_handle, 2, &data, NULL); + + WFIFOL(fd, plen) = atoi(data); + plen += 4; + + WFIFOW(fd, 14) += 1; + + if( plen > 60000 ) { + WFIFOW(fd, 2) = plen; + WFIFOSET(fd, plen); + + /* prepare follow up */ + WFIFOHEAD(fd, 60000 + 300); + WFIFOW(fd, 0) = 0x3804; + /* 0x2 = length, set prior to being sent */ + WFIFOL(fd, 4) = account_id; + WFIFOL(fd, 8) = char_id; + WFIFOB(fd, 12) = 0;/* var type (only set when all vars have been sent, regardless of type) */ + WFIFOB(fd, 13) = 0;/* is int type */ + WFIFOW(fd, 14) = 0;/* count */ + + plen = 16; + } + } + + /* mark as complete & go. */ + WFIFOB(fd, 12) = 1; + WFIFOW(fd, 2) = plen; + WFIFOSET(fd, plen); + + SQL->FreeResult(sql_handle); +} diff --git a/src/login/account_sql.c b/src/login/account_sql.c deleted file mode 100644 index 66ede6cfa..000000000 --- a/src/login/account_sql.c +++ /dev/null @@ -1,871 +0,0 @@ -/** - * This file is part of Hercules. - * http://herc.ws - http://github.com/HerculesWS/Hercules - * - * Copyright (C) 2012-2016 Hercules Dev Team - * Copyright (C) Athena Dev Teams - * - * Hercules is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#define HERCULES_CORE - -#include "config/core.h" // CONSOLE_INPUT -#include "account.h" - -#include "common/cbasetypes.h" -#include "common/conf.h" -#include "common/console.h" -#include "common/memmgr.h" -#include "common/mmo.h" -#include "common/nullpo.h" -#include "common/showmsg.h" -#include "common/socket.h" -#include "common/sql.h" -#include "common/strlib.h" - -#include - -/// 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 mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int account_id); -static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, bool is_new); - -/// public constructor -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; - - // initialize to default values - db->accounts = NULL; - // Sql settings - safestrncpy(db->db_hostname, "127.0.0.1", sizeof(db->db_hostname)); - db->db_port = 3306; - safestrncpy(db->db_username, "ragnarok", sizeof(db->db_username)); - safestrncpy(db->db_password, "ragnarok", sizeof(db->db_password)); - safestrncpy(db->db_database, "ragnarok", sizeof(db->db_database)); - safestrncpy(db->codepage, "", sizeof(db->codepage)); - // other settings - db->case_sensitive = false; - safestrncpy(db->account_db, "login", sizeof(db->account_db)); - safestrncpy(db->global_acc_reg_num_db, "global_acc_reg_num_db", sizeof(db->global_acc_reg_num_db)); - safestrncpy(db->global_acc_reg_str_db, "global_acc_reg_str_db", sizeof(db->global_acc_reg_str_db)); - - return &db->vtable; -} - - -/* ------------------------------------------------------------------------- */ - - -/// establishes database connection -static bool account_db_sql_init(AccountDB* self) -{ - AccountDB_SQL* db = (AccountDB_SQL*)self; - struct Sql *sql_handle = NULL; - - nullpo_ret(db); - - db->accounts = SQL->Malloc(); - sql_handle = db->accounts; - - if (SQL_ERROR == SQL->Connect(sql_handle, db->db_username, db->db_password, - db->db_hostname, db->db_port, db->db_database)) { - Sql_ShowDebug(sql_handle); - SQL->Free(db->accounts); - db->accounts = NULL; - return false; - } - - if (db->codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, db->codepage)) - Sql_ShowDebug(sql_handle); - - Sql_HerculesUpdateCheck(db->accounts); -#ifdef CONSOLE_INPUT - console->input->setSQL(db->accounts); -#endif - return true; -} - -/// disconnects from database -static void account_db_sql_destroy(AccountDB* self) -{ - AccountDB_SQL* db = (AccountDB_SQL*)self; - - nullpo_retv(db); - SQL->Free(db->accounts); - db->accounts = NULL; - aFree(db); -} - -/// Gets a property from this database. -static bool account_db_sql_get_property(AccountDB* self, const char* key, char* buf, size_t buflen) -{ - /* TODO: - * This functionality is not being used as of now, it was removed in - * commit 5479f9631f8579d03fbfd14d8a49c7976226a156, it is meant to get - * engine properties when more than one engine is available. I'll - * re-add it as soon as I can, following the new standards. If anyone - * is interested in this functionality you can contact me in our boards - * and I'll try to add it sooner (Pan) [Panikon] - */ -#if 0 - AccountDB_SQL* db = (AccountDB_SQL*)self; - const char* signature; - - nullpo_ret(db); - nullpo_ret(key); - nullpo_ret(buf); - signature = "engine."; - if( strncmpi(key, signature, strlen(signature)) == 0 ) - { - key += strlen(signature); - if( strcmpi(key, "name") == 0 ) - safesnprintf(buf, buflen, "sql"); - else - if( strcmpi(key, "version") == 0 ) - safesnprintf(buf, buflen, "%d", ACCOUNT_SQL_DB_VERSION); - else - if( strcmpi(key, "comment") == 0 ) - safesnprintf(buf, buflen, "SQL Account Database"); - else - return false;// not found - return true; - } - - signature = "account.sql."; - if( strncmpi(key, signature, strlen(signature)) == 0 ) - { - key += strlen(signature); - if( strcmpi(key, "db_hostname") == 0 ) - safesnprintf(buf, buflen, "%s", db->db_hostname); - else - if( strcmpi(key, "db_port") == 0 ) - safesnprintf(buf, buflen, "%d", db->db_port); - else - if( strcmpi(key, "db_username") == 0 ) - safesnprintf(buf, buflen, "%s", db->db_username); - else - if( strcmpi(key, "db_password") == 0 ) - safesnprintf(buf, buflen, "%s", db->db_password); - else - if( strcmpi(key, "db_database") == 0 ) - safesnprintf(buf, buflen, "%s", db->db_database); - else - if( strcmpi(key, "codepage") == 0 ) - safesnprintf(buf, buflen, "%s", db->codepage); - else - if( strcmpi(key, "case_sensitive") == 0 ) - safesnprintf(buf, buflen, "%d", (db->case_sensitive ? 1 : 0)); - else - if( strcmpi(key, "account_db") == 0 ) - safesnprintf(buf, buflen, "%s", db->account_db); - else - if( strcmpi(key, "global_acc_reg_str_db") == 0 ) - safesnprintf(buf, buflen, "%s", db->global_acc_reg_str_db); - else - if( strcmpi(key, "global_acc_reg_num_db") == 0 ) - safesnprintf(buf, buflen, "%s", db->global_acc_reg_num_db); - else - return false;// not found - return true; - } - - return false;// not found -#endif // 0 - return false; -} - -/** - * Reads the 'inter_configuration' config file and initializes required variables. - * - * @param db Self. - * @param filename Path to configuration file - * @param imported Whether the current config is imported from another file. - * - * @retval false in case of error. - */ -bool account_db_read_inter(AccountDB_SQL *db, const char *filename, bool imported) -{ - struct config_t config; - struct config_setting_t *setting = NULL; - - nullpo_retr(false, db); - nullpo_retr(false, filename); - - if (!libconfig->load_file(&config, filename)) - return false; // Error message is already shown by libconfig->load_file - - if ((setting = libconfig->lookup(&config, "inter_configuration/database_names")) == NULL) { - libconfig->destroy(&config); - if (imported) - return true; - ShowError("account_db_sql_set_property: inter_configuration/database_names was not found!\n"); - return false; - } - libconfig->setting_lookup_mutable_string(setting, "account_db", db->account_db, sizeof(db->account_db)); - - if ((setting = libconfig->lookup(&config, "inter_configuration/database_names/registry")) == NULL) { - libconfig->destroy(&config); - if (imported) - return true; - ShowError("account_db_sql_set_property: inter_configuration/database_names/registry was not found!\n"); - return false; - } - libconfig->setting_lookup_mutable_string(setting, "global_acc_reg_str_db", db->global_acc_reg_str_db, sizeof(db->global_acc_reg_str_db)); - libconfig->setting_lookup_mutable_string(setting, "global_acc_reg_num_db", db->global_acc_reg_num_db, sizeof(db->global_acc_reg_num_db)); - - // TODO: Proper import mechanism for this file - - libconfig->destroy(&config); - return true; -} - -/** - * Loads the sql configuration. - * - * @param self Self. - * @param config The current config being parsed. - * @param imported Whether the current config is imported from another file. - * - * @retval false in case of error. - */ -static bool account_db_sql_set_property(AccountDB* self, struct config_t *config, bool imported) -{ - AccountDB_SQL* db = (AccountDB_SQL*)self; - struct config_setting_t *setting = NULL; - - nullpo_ret(db); - nullpo_ret(config); - - if ((setting = libconfig->lookup(config, "login_configuration/account/sql_connection")) == NULL) { - if (imported) - return true; - ShowError("account_db_sql_set_property: login_configuration/account/sql_connection was not found!\n"); - ShowWarning("account_db_sql_set_property: Defaulting sql_connection...\n"); - return false; - } - - libconfig->setting_lookup_mutable_string(setting, "db_hostname", db->db_hostname, sizeof(db->db_hostname)); - libconfig->setting_lookup_mutable_string(setting, "db_username", db->db_username, sizeof(db->db_username)); - libconfig->setting_lookup_mutable_string(setting, "db_password", db->db_password, sizeof(db->db_password)); - libconfig->setting_lookup_mutable_string(setting, "db_database", db->db_database, sizeof(db->db_database)); - libconfig->setting_lookup_mutable_string(setting, "codepage", db->codepage, sizeof(db->codepage)); // FIXME: Why do we need both codepage and default_codepage? - 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); - - return true; -} - -/// create a new account entry -/// If acc->account_id is -1, the account id will be auto-generated, -/// and its value will be written to acc->account_id if everything succeeds. -static bool account_db_sql_create(AccountDB* self, struct mmo_account* acc) -{ - AccountDB_SQL* db = (AccountDB_SQL*)self; - struct Sql *sql_handle; - - // decide on the account id to assign - int account_id; - nullpo_ret(db); - nullpo_ret(acc); - sql_handle = db->accounts; - if( acc->account_id != -1 ) - {// caller specifies it manually - account_id = acc->account_id; - } - else - {// ask the database - char* data; - size_t len; - - 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) ) - { - Sql_ShowDebug(sql_handle); - SQL->FreeResult(sql_handle); - return false; - } - - SQL->GetData(sql_handle, 0, &data, &len); - account_id = ( data != NULL ) ? atoi(data) : 0; - SQL->FreeResult(sql_handle); - - if( account_id < START_ACCOUNT_NUM ) - account_id = START_ACCOUNT_NUM; - - } - - // zero value is prohibited - if( account_id == 0 ) - return false; - - // absolute maximum - if( account_id > END_ACCOUNT_NUM ) - return false; - - // insert the data into the database - acc->account_id = account_id; - return mmo_auth_tosql(db, acc, true); -} - -/// delete an existing account entry + its regs -static bool account_db_sql_remove(AccountDB* self, const int account_id) -{ - AccountDB_SQL* db = (AccountDB_SQL*)self; - struct Sql *sql_handle; - bool result = false; - - nullpo_ret(db); - sql_handle = db->accounts; - 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->global_acc_reg_num_db, account_id) - || SQL_SUCCESS != SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = %d", db->global_acc_reg_str_db, account_id) - ) - Sql_ShowDebug(sql_handle); - else - result = true; - - result &= ( SQL_SUCCESS == SQL->QueryStr(sql_handle, (result == true) ? "COMMIT" : "ROLLBACK") ); - - return result; -} - -/// update an existing account with the provided new data (both account and regs) -static bool account_db_sql_save(AccountDB* self, const struct mmo_account* acc) -{ - AccountDB_SQL* db = (AccountDB_SQL*)self; - return 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 mmo_auth_fromsql(db, acc, account_id); -} - -/// retrieve data from db and store it in the provided data structure -static bool account_db_sql_load_str(AccountDB* self, struct mmo_account* acc, const char* userid) -{ - AccountDB_SQL* db = (AccountDB_SQL*)self; - struct Sql *sql_handle; - char esc_userid[2*NAME_LENGTH+1]; - int account_id; - char* data; - - nullpo_ret(db); - sql_handle = db->accounts; - 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'", - db->account_db, (db->case_sensitive ? "BINARY" : ""), esc_userid) ) - { - Sql_ShowDebug(sql_handle); - return false; - } - - if( SQL->NumRows(sql_handle) > 1 ) - {// serious problem - duplicate account - ShowError("account_db_sql_load_str: multiple accounts found when retrieving data for account '%s'!\n", userid); - SQL->FreeResult(sql_handle); - return false; - } - - if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) - {// no such entry - SQL->FreeResult(sql_handle); - return false; - } - - SQL->GetData(sql_handle, 0, &data, NULL); - account_id = atoi(data); - - return account_db_sql_load_num(self, acc, account_id); -} - - -/// Returns a new forward iterator. -static AccountDBIterator* account_db_sql_iterator(AccountDB* self) -{ - AccountDB_SQL* db = (AccountDB_SQL*)self; - AccountDBIterator_SQL* iter; - - 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; - - // fill data - iter->db = db; - iter->last_account_id = -1; - - return &iter->vtable; -} - - -/// Destroys this iterator, releasing all allocated memory (including itself). -static void account_db_sql_iter_destroy(AccountDBIterator* self) -{ - AccountDBIterator_SQL* iter = (AccountDBIterator_SQL*)self; - aFree(iter); -} - - -/// Fetches the next account in the database. -static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account* acc) -{ - AccountDBIterator_SQL* iter = (AccountDBIterator_SQL*)self; - AccountDB_SQL* db; - struct Sql *sql_handle; - char* data; - - nullpo_ret(iter); - db = (AccountDB_SQL*)iter->db; - nullpo_ret(db); - sql_handle = db->accounts; - // 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", - 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) && - data != NULL ) - {// get account data - int account_id; - account_id = atoi(data); - if( mmo_auth_fromsql(db, acc, account_id) ) - { - iter->last_account_id = account_id; - SQL->FreeResult(sql_handle); - return true; - } - } - SQL->FreeResult(sql_handle); - return false; -} - - -static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int account_id) -{ - struct Sql *sql_handle; - char* data; - - nullpo_ret(db); - nullpo_ret(acc); - sql_handle = db->accounts; - // retrieve login entry for the specified account - 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 ) - ) { - Sql_ShowDebug(sql_handle); - return false; - } - - if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) - {// no such entry - 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 = (unsigned int)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 = (unsigned int)strtoul(data, NULL, 10); - SQL->GetData(sql_handle, 10, &data, NULL); safestrncpy(acc->lastlogin, data != NULL ? data : "(never)", 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 != NULL ? data : "0000-00-00", sizeof(acc->birthdate)); - SQL->GetData(sql_handle, 13, &data, NULL); acc->char_slots = (uint8)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 = (unsigned int)atol(data); - - SQL->FreeResult(sql_handle); - - return true; -} - -static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, bool is_new) -{ - struct Sql *sql_handle; - struct SqlStmt *stmt; - bool result = false; - - nullpo_ret(db); - nullpo_ret(acc); - sql_handle = db->accounts; - stmt = SQL->StmtMalloc(sql_handle); - - // try - do - { - - if( SQL_SUCCESS != SQL->QueryStr(sql_handle, "START TRANSACTION") ) - { - Sql_ShowDebug(sql_handle); - break; - } - - if( is_new ) - {// insert into account table - if( SQL_SUCCESS != SQL->StmtPrepare(stmt, - "INSERT INTO `%s` (`account_id`, `userid`, `user_pass`, `sex`, `email`, `group_id`, `state`, `unban_time`, `expiration_time`, `logincount`, `lastlogin`, `last_ip`, `birthdate`, `character_slots`, `pincode`, `pincode_change`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - db->account_db) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_INT, &acc->account_id, sizeof acc->account_id) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, acc->userid, strlen(acc->userid)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 2, SQLDT_STRING, acc->pass, strlen(acc->pass)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 3, SQLDT_ENUM, &acc->sex, sizeof acc->sex) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 4, SQLDT_STRING, &acc->email, strlen(acc->email)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 5, SQLDT_INT, &acc->group_id, sizeof acc->group_id) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 6, SQLDT_UINT, &acc->state, sizeof acc->state) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 7, SQLDT_TIME, &acc->unban_time, sizeof acc->unban_time) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 8, SQLDT_TIME, &acc->expiration_time, sizeof acc->expiration_time) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 9, SQLDT_UINT, &acc->logincount, sizeof acc->logincount) - || SQL_SUCCESS != (acc->lastlogin[0] < '1' || acc->lastlogin[0] > '9' ? - SQL->StmtBindParam(stmt, 10, SQLDT_NULL, NULL, 0) : - SQL->StmtBindParam(stmt, 10, SQLDT_STRING, &acc->lastlogin, strlen(acc->lastlogin)) - ) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 11, SQLDT_STRING, &acc->last_ip, strlen(acc->last_ip)) - || SQL_SUCCESS != (acc->birthdate[0] == '0' ? - SQL->StmtBindParam(stmt, 12, SQLDT_NULL, NULL, 0) : - SQL->StmtBindParam(stmt, 12, SQLDT_STRING, &acc->birthdate, strlen(acc->birthdate)) - ) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 13, SQLDT_UINT8, &acc->char_slots, sizeof acc->char_slots) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 14, SQLDT_STRING, &acc->pincode, strlen(acc->pincode)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 15, SQLDT_UINT, &acc->pincode_change, sizeof acc->pincode_change) - || SQL_SUCCESS != SQL->StmtExecute(stmt) - ) { - SqlStmt_ShowDebug(stmt); - break; - } - } else {// update account table - if( SQL_SUCCESS != SQL->StmtPrepare(stmt, "UPDATE `%s` SET `userid`=?,`user_pass`=?,`sex`=?,`email`=?,`group_id`=?,`state`=?,`unban_time`=?,`expiration_time`=?,`logincount`=?,`lastlogin`=?,`last_ip`=?,`birthdate`=?,`character_slots`=?,`pincode`=?,`pincode_change`=? WHERE `account_id` = '%d'", db->account_db, acc->account_id) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_STRING, acc->userid, strlen(acc->userid)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, acc->pass, strlen(acc->pass)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 2, SQLDT_ENUM, &acc->sex, sizeof acc->sex) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 3, SQLDT_STRING, acc->email, strlen(acc->email)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 4, SQLDT_INT, &acc->group_id, sizeof acc->group_id) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 5, SQLDT_UINT, &acc->state, sizeof acc->state) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 6, SQLDT_TIME, &acc->unban_time, sizeof acc->unban_time) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 7, SQLDT_TIME, &acc->expiration_time, sizeof acc->expiration_time) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 8, SQLDT_UINT, &acc->logincount, sizeof acc->logincount) - || SQL_SUCCESS != (acc->lastlogin[0] < '1' || acc->lastlogin[0] > '9' ? - SQL->StmtBindParam(stmt, 9, SQLDT_NULL, NULL, 0) : - SQL->StmtBindParam(stmt, 9, SQLDT_STRING, &acc->lastlogin, strlen(acc->lastlogin)) - ) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 10, SQLDT_STRING, &acc->last_ip, strlen(acc->last_ip)) - || SQL_SUCCESS != (acc->birthdate[0] == '0' ? - SQL->StmtBindParam(stmt, 11, SQLDT_NULL, NULL, 0) : - SQL->StmtBindParam(stmt, 11, SQLDT_STRING, &acc->birthdate, strlen(acc->birthdate)) - ) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 12, SQLDT_UINT8, &acc->char_slots, sizeof acc->char_slots) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 13, SQLDT_STRING, &acc->pincode, strlen(acc->pincode)) - || SQL_SUCCESS != SQL->StmtBindParam(stmt, 14, SQLDT_UINT, &acc->pincode_change, sizeof acc->pincode_change) - || SQL_SUCCESS != SQL->StmtExecute(stmt) - ) { - SqlStmt_ShowDebug(stmt); - break; - } - } - - // if we got this far, everything was successful - result = true; - - } while(0); - // finally - - result &= ( SQL_SUCCESS == SQL->QueryStr(sql_handle, (result == true) ? "COMMIT" : "ROLLBACK") ); - SQL->StmtFree(stmt); - - return result; -} - -struct Sql *account_db_sql_up(AccountDB* self) -{ - AccountDB_SQL* db = (AccountDB_SQL*)self; - return db ? db->accounts : NULL; -} -void mmo_save_accreg2(AccountDB* self, int fd, int account_id, int char_id) -{ - struct Sql *sql_handle; - AccountDB_SQL* db = (AccountDB_SQL*)self; - int count = RFIFOW(fd, 12); - - nullpo_retv(db); - sql_handle = db->accounts; - if (count) { - int cursor = 14, i; - char key[SCRIPT_VARNAME_LENGTH+1], sval[254]; - - for (i = 0; i < count; i++) { - unsigned int index; - int len = RFIFOB(fd, cursor); - safestrncpy(key, RFIFOP(fd, cursor + 1), min((int)sizeof(key), len)); - cursor += len + 1; - - index = RFIFOL(fd, cursor); - cursor += 4; - - switch (RFIFOB(fd, cursor++)) { - /* int */ - case 0: - if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`account_id`,`key`,`index`,`value`) VALUES ('%d','%s','%u','%u')", db->global_acc_reg_num_db, account_id, key, index, RFIFOL(fd, cursor)) ) - Sql_ShowDebug(sql_handle); - cursor += 4; - break; - case 1: - if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `key` = '%s' AND `index` = '%u' LIMIT 1", db->global_acc_reg_num_db, account_id, key, index) ) - Sql_ShowDebug(sql_handle); - break; - /* str */ - case 2: - len = RFIFOB(fd, cursor); - safestrncpy(sval, RFIFOP(fd, cursor + 1), min((int)sizeof(sval), len)); - cursor += len + 1; - if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`account_id`,`key`,`index`,`value`) VALUES ('%d','%s','%u','%s')", db->global_acc_reg_str_db, account_id, key, index, sval) ) - Sql_ShowDebug(sql_handle); - break; - case 3: - if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `key` = '%s' AND `index` = '%u' LIMIT 1", db->global_acc_reg_str_db, account_id, key, index) ) - Sql_ShowDebug(sql_handle); - break; - default: - ShowError("mmo_save_accreg2: DA HOO UNKNOWN TYPE %d\n",RFIFOB(fd, cursor - 1)); - return; - } - } - } -} - -void mmo_send_accreg2(AccountDB* self, int fd, int account_id, int char_id) -{ - struct Sql *sql_handle; - AccountDB_SQL* db = (AccountDB_SQL*)self; - char* data; - int plen = 0; - size_t len; - - nullpo_retv(db); - sql_handle = db->accounts; - if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `account_id`='%d'", db->global_acc_reg_str_db, account_id) ) - Sql_ShowDebug(sql_handle); - - WFIFOHEAD(fd, 60000 + 300); - WFIFOW(fd, 0) = 0x3804; - /* 0x2 = length, set prior to being sent */ - WFIFOL(fd, 4) = account_id; - WFIFOL(fd, 8) = char_id; - WFIFOB(fd, 12) = 0;/* var type (only set when all vars have been sent, regardless of type) */ - WFIFOB(fd, 13) = 1;/* is string type */ - WFIFOW(fd, 14) = 0;/* count */ - plen = 16; - - /** - * Vessel! - * - * str type - * { keyLength(B), key(), index(L), valLength(B), val() } - **/ - while ( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { - SQL->GetData(sql_handle, 0, &data, NULL); - len = strlen(data)+1; - - WFIFOB(fd, plen) = (unsigned char)len;/* won't be higher; the column size is 32 */ - plen += 1; - - safestrncpy(WFIFOP(fd,plen), data, len); - plen += len; - - SQL->GetData(sql_handle, 1, &data, NULL); - - WFIFOL(fd, plen) = (unsigned int)atol(data); - plen += 4; - - SQL->GetData(sql_handle, 2, &data, NULL); - len = strlen(data)+1; - - WFIFOB(fd, plen) = (unsigned char)len;/* won't be higher; the column size is 254 */ - plen += 1; - - safestrncpy(WFIFOP(fd,plen), data, len); - plen += len; - - WFIFOW(fd, 14) += 1; - - if( plen > 60000 ) { - WFIFOW(fd, 2) = plen; - WFIFOSET(fd, plen); - - /* prepare follow up */ - WFIFOHEAD(fd, 60000 + 300); - WFIFOW(fd, 0) = 0x3804; - /* 0x2 = length, set prior to being sent */ - WFIFOL(fd, 4) = account_id; - WFIFOL(fd, 8) = char_id; - WFIFOB(fd, 12) = 0;/* var type (only set when all vars have been sent, regardless of type) */ - WFIFOB(fd, 13) = 1;/* is string type */ - WFIFOW(fd, 14) = 0;/* count */ - plen = 16; - } - } - - /* mark & go. */ - WFIFOW(fd, 2) = plen; - WFIFOSET(fd, plen); - - SQL->FreeResult(sql_handle); - - if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `account_id`='%d'", db->global_acc_reg_num_db, account_id) ) - Sql_ShowDebug(sql_handle); - - WFIFOHEAD(fd, 60000 + 300); - WFIFOW(fd, 0) = 0x3804; - /* 0x2 = length, set prior to being sent */ - WFIFOL(fd, 4) = account_id; - WFIFOL(fd, 8) = char_id; - WFIFOB(fd, 12) = 0;/* var type (only set when all vars have been sent, regardless of type) */ - WFIFOB(fd, 13) = 0;/* is int type */ - WFIFOW(fd, 14) = 0;/* count */ - plen = 16; - - /** - * Vessel! - * - * int type - * { keyLength(B), key(), index(L), value(L) } - **/ - while ( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { - SQL->GetData(sql_handle, 0, &data, NULL); - len = strlen(data)+1; - - WFIFOB(fd, plen) = (unsigned char)len;/* won't be higher; the column size is 32 */ - plen += 1; - - safestrncpy(WFIFOP(fd,plen), data, len); - plen += len; - - SQL->GetData(sql_handle, 1, &data, NULL); - - WFIFOL(fd, plen) = (unsigned int)atol(data); - plen += 4; - - SQL->GetData(sql_handle, 2, &data, NULL); - - WFIFOL(fd, plen) = atoi(data); - plen += 4; - - WFIFOW(fd, 14) += 1; - - if( plen > 60000 ) { - WFIFOW(fd, 2) = plen; - WFIFOSET(fd, plen); - - /* prepare follow up */ - WFIFOHEAD(fd, 60000 + 300); - WFIFOW(fd, 0) = 0x3804; - /* 0x2 = length, set prior to being sent */ - WFIFOL(fd, 4) = account_id; - WFIFOL(fd, 8) = char_id; - WFIFOB(fd, 12) = 0;/* var type (only set when all vars have been sent, regardless of type) */ - WFIFOB(fd, 13) = 0;/* is int type */ - WFIFOW(fd, 14) = 0;/* count */ - - plen = 16; - } - } - - /* mark as complete & go. */ - WFIFOB(fd, 12) = 1; - WFIFOW(fd, 2) = plen; - WFIFOSET(fd, plen); - - SQL->FreeResult(sql_handle); -} diff --git a/src/login/ipban.c b/src/login/ipban.c new file mode 100644 index 000000000..d74e6c4fa --- /dev/null +++ b/src/login/ipban.c @@ -0,0 +1,308 @@ +/** + * This file is part of Hercules. + * http://herc.ws - http://github.com/HerculesWS/Hercules + * + * Copyright (C) 2012-2016 Hercules Dev Team + * Copyright (C) Athena Dev Teams + * + * Hercules is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#define HERCULES_CORE + +#include "ipban.h" + +#include "login/login.h" +#include "login/loginlog.h" +#include "common/cbasetypes.h" +#include "common/conf.h" +#include "common/nullpo.h" +#include "common/showmsg.h" +#include "common/sql.h" +#include "common/strlib.h" +#include "common/timer.h" + +#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); + + +// initialize +void ipban_init(void) +{ + 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); + exit(EXIT_FAILURE); + } + if (ipban_codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, ipban_codepage)) + Sql_ShowDebug(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); + } else { + // make sure it gets cleaned up on login-server start regardless of interval-based cleanups + ipban_cleanup(0,0,0,0); + } +} + +// finalize +void ipban_final(void) +{ + if (!login->config->ipban) + return;// ipban disabled + + if (login->config->ipban_cleanup_interval > 0) + // release data + timer->delete(cleanup_timer_id, ipban_cleanup); + + ipban_cleanup(0,0,0,0); // always clean up on login-server stop + + // close connections + SQL->Free(sql_handle); + sql_handle = NULL; +} + +/** + * Reads 'inter_configuration' and initializes required variables/Sets global + * configuration. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + + */ +bool ipban_config_read_inter(const char *filename, bool imported) +{ + struct config_t config; + struct config_setting_t *setting = NULL; + const char *import = NULL; + bool retval = true; + + nullpo_retr(false, filename); + + if (!libconfig->load_file(&config, filename)) + return false; // Error message is already shown by libconfig->read_file + + if ((setting = libconfig->lookup(&config, "inter_configuration/database_names")) == NULL) { + libconfig->destroy(&config); + if (imported) + return true; + 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)); + + // 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)) + retval = false; + } + } + + libconfig->destroy(&config); + return retval; +} + +/** + * Reads login_configuration/account/ipban/sql_connection and loads configuration options. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool ipban_config_read_connection(const char *filename, struct config_t *config, bool imported) +{ + struct config_setting_t *setting = NULL; + + nullpo_retr(false, filename); + nullpo_retr(false, config); + + if ((setting = libconfig->lookup(config, "login_configuration/account/ipban/sql_connection")) == NULL) { + if (imported) + return true; + ShowError("account_db_sql_set_property: login_configuration/account/ipban/sql_connection was not found in %s!\n", filename); + 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_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); + + return true; +} + +/** + * Reads login_configuration/account/ipban/dynamic_pass_failure and loads configuration options. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool ipban_config_read_dynamic(const char *filename, struct config_t *config, bool imported) +{ + struct config_setting_t *setting = NULL; + + nullpo_retr(false, filename); + nullpo_retr(false, config); + + if ((setting = libconfig->lookup(config, "login_configuration/account/ipban/dynamic_pass_failure")) == NULL) { + if (imported) + return true; + ShowError("account_db_sql_set_property: login_configuration/account/ipban/dynamic_pass_failure was not found in %s!\n", filename); + return false; + } + + libconfig->setting_lookup_bool_real(setting, "enabled", &login->config->dynamic_pass_failure_ban); + libconfig->setting_lookup_uint32(setting, "ban_interval", &login->config->dynamic_pass_failure_ban_interval); + libconfig->setting_lookup_uint32(setting, "ban_limit", &login->config->dynamic_pass_failure_ban_limit); + libconfig->setting_lookup_uint32(setting, "ban_duration", &login->config->dynamic_pass_failure_ban_duration); + + return true; +} + +/** + * Reads login_configuration.account.ipban and loads configuration options. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool ipban_config_read(const char *filename, struct config_t *config, bool imported) +{ + struct config_setting_t *setting = NULL; + bool retval = true; + + nullpo_retr(false, filename); + nullpo_retr(false, config); + + if (ipban_inited) + return false; // settings can only be changed before init + + if ((setting = libconfig->lookup(config, "login_configuration/account/ipban")) == NULL) { + if (!imported) + ShowError("login_config_read: login_configuration/log was not found in %s!\n", filename); + return false; + } + + libconfig->setting_lookup_bool_real(setting, "enabled", &login->config->ipban); + libconfig->setting_lookup_uint32(setting, "cleanup_interval", &login->config->ipban_cleanup_interval); + + if (!ipban_config_read_inter("conf/common/inter-server.conf", imported)) + retval = false; + if (!ipban_config_read_connection(filename, config, imported)) + retval = false; + if (!ipban_config_read_dynamic(filename, config, imported)) + retval = false; + + return retval; +} + +// check ip against active bans list +bool ipban_check(uint32 ip) +{ + uint8* p = (uint8*)&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 `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); + // close connection because we can't verify their connectivity. + return true; + } + + if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) + return false; + + SQL->GetData(sql_handle, 0, &data, NULL); + matches = atoi(data); + SQL->FreeResult(sql_handle); + + return( matches > 0 ); +} + +// log failed attempt +void ipban_log(uint32 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) + { + 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)) + { + Sql_ShowDebug(sql_handle); + } + } +} + +// remove expired bans +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); + + return 0; +} diff --git a/src/login/ipban_sql.c b/src/login/ipban_sql.c deleted file mode 100644 index d74e6c4fa..000000000 --- a/src/login/ipban_sql.c +++ /dev/null @@ -1,308 +0,0 @@ -/** - * This file is part of Hercules. - * http://herc.ws - http://github.com/HerculesWS/Hercules - * - * Copyright (C) 2012-2016 Hercules Dev Team - * Copyright (C) Athena Dev Teams - * - * Hercules is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#define HERCULES_CORE - -#include "ipban.h" - -#include "login/login.h" -#include "login/loginlog.h" -#include "common/cbasetypes.h" -#include "common/conf.h" -#include "common/nullpo.h" -#include "common/showmsg.h" -#include "common/sql.h" -#include "common/strlib.h" -#include "common/timer.h" - -#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); - - -// initialize -void ipban_init(void) -{ - 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); - exit(EXIT_FAILURE); - } - if (ipban_codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, ipban_codepage)) - Sql_ShowDebug(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); - } else { - // make sure it gets cleaned up on login-server start regardless of interval-based cleanups - ipban_cleanup(0,0,0,0); - } -} - -// finalize -void ipban_final(void) -{ - if (!login->config->ipban) - return;// ipban disabled - - if (login->config->ipban_cleanup_interval > 0) - // release data - timer->delete(cleanup_timer_id, ipban_cleanup); - - ipban_cleanup(0,0,0,0); // always clean up on login-server stop - - // close connections - SQL->Free(sql_handle); - sql_handle = NULL; -} - -/** - * Reads 'inter_configuration' and initializes required variables/Sets global - * configuration. - * - * @param filename Path to configuration file (used in error and warning messages). - * @param imported Whether the current config is imported from another file. - * - * @retval false in case of error. - - */ -bool ipban_config_read_inter(const char *filename, bool imported) -{ - struct config_t config; - struct config_setting_t *setting = NULL; - const char *import = NULL; - bool retval = true; - - nullpo_retr(false, filename); - - if (!libconfig->load_file(&config, filename)) - return false; // Error message is already shown by libconfig->read_file - - if ((setting = libconfig->lookup(&config, "inter_configuration/database_names")) == NULL) { - libconfig->destroy(&config); - if (imported) - return true; - 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)); - - // 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)) - retval = false; - } - } - - libconfig->destroy(&config); - return retval; -} - -/** - * Reads login_configuration/account/ipban/sql_connection and loads configuration options. - * - * @param filename Path to configuration file (used in error and warning messages). - * @param config The current config being parsed. - * @param imported Whether the current config is imported from another file. - * - * @retval false in case of error. - */ -bool ipban_config_read_connection(const char *filename, struct config_t *config, bool imported) -{ - struct config_setting_t *setting = NULL; - - nullpo_retr(false, filename); - nullpo_retr(false, config); - - if ((setting = libconfig->lookup(config, "login_configuration/account/ipban/sql_connection")) == NULL) { - if (imported) - return true; - ShowError("account_db_sql_set_property: login_configuration/account/ipban/sql_connection was not found in %s!\n", filename); - 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_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); - - return true; -} - -/** - * Reads login_configuration/account/ipban/dynamic_pass_failure and loads configuration options. - * - * @param filename Path to configuration file (used in error and warning messages). - * @param config The current config being parsed. - * @param imported Whether the current config is imported from another file. - * - * @retval false in case of error. - */ -bool ipban_config_read_dynamic(const char *filename, struct config_t *config, bool imported) -{ - struct config_setting_t *setting = NULL; - - nullpo_retr(false, filename); - nullpo_retr(false, config); - - if ((setting = libconfig->lookup(config, "login_configuration/account/ipban/dynamic_pass_failure")) == NULL) { - if (imported) - return true; - ShowError("account_db_sql_set_property: login_configuration/account/ipban/dynamic_pass_failure was not found in %s!\n", filename); - return false; - } - - libconfig->setting_lookup_bool_real(setting, "enabled", &login->config->dynamic_pass_failure_ban); - libconfig->setting_lookup_uint32(setting, "ban_interval", &login->config->dynamic_pass_failure_ban_interval); - libconfig->setting_lookup_uint32(setting, "ban_limit", &login->config->dynamic_pass_failure_ban_limit); - libconfig->setting_lookup_uint32(setting, "ban_duration", &login->config->dynamic_pass_failure_ban_duration); - - return true; -} - -/** - * Reads login_configuration.account.ipban and loads configuration options. - * - * @param filename Path to configuration file (used in error and warning messages). - * @param config The current config being parsed. - * @param imported Whether the current config is imported from another file. - * - * @retval false in case of error. - */ -bool ipban_config_read(const char *filename, struct config_t *config, bool imported) -{ - struct config_setting_t *setting = NULL; - bool retval = true; - - nullpo_retr(false, filename); - nullpo_retr(false, config); - - if (ipban_inited) - return false; // settings can only be changed before init - - if ((setting = libconfig->lookup(config, "login_configuration/account/ipban")) == NULL) { - if (!imported) - ShowError("login_config_read: login_configuration/log was not found in %s!\n", filename); - return false; - } - - libconfig->setting_lookup_bool_real(setting, "enabled", &login->config->ipban); - libconfig->setting_lookup_uint32(setting, "cleanup_interval", &login->config->ipban_cleanup_interval); - - if (!ipban_config_read_inter("conf/common/inter-server.conf", imported)) - retval = false; - if (!ipban_config_read_connection(filename, config, imported)) - retval = false; - if (!ipban_config_read_dynamic(filename, config, imported)) - retval = false; - - return retval; -} - -// check ip against active bans list -bool ipban_check(uint32 ip) -{ - uint8* p = (uint8*)&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 `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); - // close connection because we can't verify their connectivity. - return true; - } - - if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) - return false; - - SQL->GetData(sql_handle, 0, &data, NULL); - matches = atoi(data); - SQL->FreeResult(sql_handle); - - return( matches > 0 ); -} - -// log failed attempt -void ipban_log(uint32 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) - { - 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)) - { - Sql_ShowDebug(sql_handle); - } - } -} - -// remove expired bans -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); - - return 0; -} diff --git a/src/login/loginlog.c b/src/login/loginlog.c new file mode 100644 index 000000000..7dff14990 --- /dev/null +++ b/src/login/loginlog.c @@ -0,0 +1,225 @@ +/** + * This file is part of Hercules. + * http://herc.ws - http://github.com/HerculesWS/Hercules + * + * Copyright (C) 2012-2016 Hercules Dev Team + * Copyright (C) Athena Dev Teams + * + * Hercules is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#define HERCULES_CORE + +#include "loginlog.h" + +#include "common/cbasetypes.h" +#include "common/conf.h" +#include "common/mmo.h" +#include "common/nullpo.h" +#include "common/showmsg.h" +#include "common/socket.h" +#include "common/sql.h" +#include "common/strlib.h" + +#include // exit + +// Sql settings +static char log_db_hostname[32] = "127.0.0.1"; +static uint16 log_db_port = 3306; +static char log_db_username[32] = "ragnarok"; +static char log_db_password[100] = "ragnarok"; +static char log_db_database[32] = "ragnarok"; +static char log_codepage[32] = ""; +static char log_login_db[256] = "loginlog"; + +static struct Sql *sql_handle = NULL; +static bool enabled = false; + + +// Returns the number of failed login attempts by the ip in the last minutes. +unsigned long loginlog_failedattempts(uint32 ip, unsigned int minutes) +{ + unsigned long failures = 0; + + 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 %u MINUTE", + log_login_db, sockt->ip2str(ip,NULL), minutes) )// how many times failed account? in one ip. + Sql_ShowDebug(sql_handle); + + if( SQL_SUCCESS == SQL->NextRow(sql_handle) ) + { + char* data; + SQL->GetData(sql_handle, 0, &data, NULL); + failures = strtoul(data, NULL, 10); + SQL->FreeResult(sql_handle); + } + return failures; +} + + +/*============================================= + * 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) +{ + char esc_username[NAME_LENGTH*2+1]; + char esc_message[255*2+1]; + int retcode; + + nullpo_retv(username); + nullpo_retv(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)); + + retcode = SQL->Query(sql_handle, + "INSERT INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '%s', '%s', '%d', '%s')", + log_login_db, sockt->ip2str(ip,NULL), esc_username, rcode, esc_message); + + if( retcode != SQL_SUCCESS ) + Sql_ShowDebug(sql_handle); +} + +bool loginlog_init(void) +{ + sql_handle = SQL->Malloc(); + + if (SQL_ERROR == SQL->Connect(sql_handle, log_db_username, log_db_password, + log_db_hostname, log_db_port, log_db_database)) { + Sql_ShowDebug(sql_handle); + SQL->Free(sql_handle); + exit(EXIT_FAILURE); + } + + if (log_codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, log_codepage)) + Sql_ShowDebug(sql_handle); + + enabled = true; + + return true; +} + +bool loginlog_final(void) +{ + SQL->Free(sql_handle); + sql_handle = NULL; + return true; +} + +/** + * Reads 'inter_configuration/database_names' and initializes required + * variables/Sets global configuration. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool loginlog_config_read_names(const char *filename, struct config_t *config, bool imported) +{ + struct config_setting_t *setting = NULL; + + nullpo_retr(false, filename); + nullpo_retr(false, config); + + if ((setting = libconfig->lookup(config, "inter_configuration/database_names")) == NULL) { + if (imported) + return true; + ShowError("loginlog_config_read: inter_configuration/database_names was not found in %s!\n", filename); + return false; + } + + libconfig->setting_lookup_mutable_string(setting, "login_db", log_login_db, sizeof(log_login_db)); + + return true; +} + +/** + * Reads 'inter_configuration.log' and initializes required variables/Sets + * global configuration. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool loginlog_config_read_log(const char *filename, struct config_t *config, bool imported) +{ + struct config_setting_t *setting = NULL; + + nullpo_retr(false, filename); + nullpo_retr(false, config); + + if ((setting = libconfig->lookup(config, "inter_configuration/log/sql_connection")) == NULL) { + if (imported) + return true; + ShowError("loginlog_config_read: inter_configuration/log/sql_connection was not found in %s!\n", filename); + return false; + } + + libconfig->setting_lookup_mutable_string(setting, "db_hostname", log_db_hostname, sizeof(log_db_hostname)); + libconfig->setting_lookup_mutable_string(setting, "db_database", log_db_database, sizeof(log_db_database)); + libconfig->setting_lookup_mutable_string(setting, "db_username", log_db_username, sizeof(log_db_username)); + libconfig->setting_lookup_mutable_string(setting, "db_password", log_db_password, sizeof(log_db_password)); + + libconfig->setting_lookup_uint16(setting, "db_port", &log_db_port); + libconfig->setting_lookup_mutable_string(setting, "codepage", log_codepage, sizeof(log_codepage)); + + return true; +} + +/** + * Reads 'inter_configuration' and initializes required variables/Sets global + * configuration. + * + * @param filename Path to configuration file. + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + **/ +bool loginlog_config_read(const char *filename, bool imported) +{ + struct config_t config; + const char *import = NULL; + bool retval = true; + + nullpo_retr(false, filename); + + 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)) + retval = false; + 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)) + retval = false; + } + } + + libconfig->destroy(&config); + return retval; +} diff --git a/src/login/loginlog_sql.c b/src/login/loginlog_sql.c deleted file mode 100644 index 7dff14990..000000000 --- a/src/login/loginlog_sql.c +++ /dev/null @@ -1,225 +0,0 @@ -/** - * This file is part of Hercules. - * http://herc.ws - http://github.com/HerculesWS/Hercules - * - * Copyright (C) 2012-2016 Hercules Dev Team - * Copyright (C) Athena Dev Teams - * - * Hercules is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#define HERCULES_CORE - -#include "loginlog.h" - -#include "common/cbasetypes.h" -#include "common/conf.h" -#include "common/mmo.h" -#include "common/nullpo.h" -#include "common/showmsg.h" -#include "common/socket.h" -#include "common/sql.h" -#include "common/strlib.h" - -#include // exit - -// Sql settings -static char log_db_hostname[32] = "127.0.0.1"; -static uint16 log_db_port = 3306; -static char log_db_username[32] = "ragnarok"; -static char log_db_password[100] = "ragnarok"; -static char log_db_database[32] = "ragnarok"; -static char log_codepage[32] = ""; -static char log_login_db[256] = "loginlog"; - -static struct Sql *sql_handle = NULL; -static bool enabled = false; - - -// Returns the number of failed login attempts by the ip in the last minutes. -unsigned long loginlog_failedattempts(uint32 ip, unsigned int minutes) -{ - unsigned long failures = 0; - - 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 %u MINUTE", - log_login_db, sockt->ip2str(ip,NULL), minutes) )// how many times failed account? in one ip. - Sql_ShowDebug(sql_handle); - - if( SQL_SUCCESS == SQL->NextRow(sql_handle) ) - { - char* data; - SQL->GetData(sql_handle, 0, &data, NULL); - failures = strtoul(data, NULL, 10); - SQL->FreeResult(sql_handle); - } - return failures; -} - - -/*============================================= - * 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) -{ - char esc_username[NAME_LENGTH*2+1]; - char esc_message[255*2+1]; - int retcode; - - nullpo_retv(username); - nullpo_retv(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)); - - retcode = SQL->Query(sql_handle, - "INSERT INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '%s', '%s', '%d', '%s')", - log_login_db, sockt->ip2str(ip,NULL), esc_username, rcode, esc_message); - - if( retcode != SQL_SUCCESS ) - Sql_ShowDebug(sql_handle); -} - -bool loginlog_init(void) -{ - sql_handle = SQL->Malloc(); - - if (SQL_ERROR == SQL->Connect(sql_handle, log_db_username, log_db_password, - log_db_hostname, log_db_port, log_db_database)) { - Sql_ShowDebug(sql_handle); - SQL->Free(sql_handle); - exit(EXIT_FAILURE); - } - - if (log_codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, log_codepage)) - Sql_ShowDebug(sql_handle); - - enabled = true; - - return true; -} - -bool loginlog_final(void) -{ - SQL->Free(sql_handle); - sql_handle = NULL; - return true; -} - -/** - * Reads 'inter_configuration/database_names' and initializes required - * variables/Sets global configuration. - * - * @param filename Path to configuration file (used in error and warning messages). - * @param config The current config being parsed. - * @param imported Whether the current config is imported from another file. - * - * @retval false in case of error. - */ -bool loginlog_config_read_names(const char *filename, struct config_t *config, bool imported) -{ - struct config_setting_t *setting = NULL; - - nullpo_retr(false, filename); - nullpo_retr(false, config); - - if ((setting = libconfig->lookup(config, "inter_configuration/database_names")) == NULL) { - if (imported) - return true; - ShowError("loginlog_config_read: inter_configuration/database_names was not found in %s!\n", filename); - return false; - } - - libconfig->setting_lookup_mutable_string(setting, "login_db", log_login_db, sizeof(log_login_db)); - - return true; -} - -/** - * Reads 'inter_configuration.log' and initializes required variables/Sets - * global configuration. - * - * @param filename Path to configuration file (used in error and warning messages). - * @param config The current config being parsed. - * @param imported Whether the current config is imported from another file. - * - * @retval false in case of error. - */ -bool loginlog_config_read_log(const char *filename, struct config_t *config, bool imported) -{ - struct config_setting_t *setting = NULL; - - nullpo_retr(false, filename); - nullpo_retr(false, config); - - if ((setting = libconfig->lookup(config, "inter_configuration/log/sql_connection")) == NULL) { - if (imported) - return true; - ShowError("loginlog_config_read: inter_configuration/log/sql_connection was not found in %s!\n", filename); - return false; - } - - libconfig->setting_lookup_mutable_string(setting, "db_hostname", log_db_hostname, sizeof(log_db_hostname)); - libconfig->setting_lookup_mutable_string(setting, "db_database", log_db_database, sizeof(log_db_database)); - libconfig->setting_lookup_mutable_string(setting, "db_username", log_db_username, sizeof(log_db_username)); - libconfig->setting_lookup_mutable_string(setting, "db_password", log_db_password, sizeof(log_db_password)); - - libconfig->setting_lookup_uint16(setting, "db_port", &log_db_port); - libconfig->setting_lookup_mutable_string(setting, "codepage", log_codepage, sizeof(log_codepage)); - - return true; -} - -/** - * Reads 'inter_configuration' and initializes required variables/Sets global - * configuration. - * - * @param filename Path to configuration file. - * @param config The current config being parsed. - * @param imported Whether the current config is imported from another file. - * - * @retval false in case of error. - **/ -bool loginlog_config_read(const char *filename, bool imported) -{ - struct config_t config; - const char *import = NULL; - bool retval = true; - - nullpo_retr(false, filename); - - 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)) - retval = false; - 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)) - retval = false; - } - } - - libconfig->destroy(&config); - return retval; -} diff --git a/vcproj-11/login-server.vcxproj b/vcproj-11/login-server.vcxproj index 6e9088f10..9abd5dc90 100644 --- a/vcproj-11/login-server.vcxproj +++ b/vcproj-11/login-server.vcxproj @@ -196,12 +196,12 @@ - + - + - + diff --git a/vcproj-11/login-server.vcxproj.filters b/vcproj-11/login-server.vcxproj.filters index f41fcdfac..1f3b6ba0f 100644 --- a/vcproj-11/login-server.vcxproj.filters +++ b/vcproj-11/login-server.vcxproj.filters @@ -1,19 +1,19 @@  - + login login - + login login - + login diff --git a/vcproj-12/login-server.vcxproj b/vcproj-12/login-server.vcxproj index 91fa58082..a1cd6fc0e 100644 --- a/vcproj-12/login-server.vcxproj +++ b/vcproj-12/login-server.vcxproj @@ -196,12 +196,12 @@ - + - + - + diff --git a/vcproj-12/login-server.vcxproj.filters b/vcproj-12/login-server.vcxproj.filters index f41fcdfac..1f3b6ba0f 100644 --- a/vcproj-12/login-server.vcxproj.filters +++ b/vcproj-12/login-server.vcxproj.filters @@ -1,19 +1,19 @@  - + login login - + login login - + login diff --git a/vcproj-14/login-server.vcxproj b/vcproj-14/login-server.vcxproj index 445d21ee4..44dee52be 100644 --- a/vcproj-14/login-server.vcxproj +++ b/vcproj-14/login-server.vcxproj @@ -194,12 +194,12 @@ - + - + - + diff --git a/vcproj-14/login-server.vcxproj.filters b/vcproj-14/login-server.vcxproj.filters index f41fcdfac..1f3b6ba0f 100644 --- a/vcproj-14/login-server.vcxproj.filters +++ b/vcproj-14/login-server.vcxproj.filters @@ -1,19 +1,19 @@  - + login login - + login login - + login -- cgit v1.2.3-70-g09d2 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/account.c | 21 +++++++++++---------- src/login/account.h | 4 ++-- src/login/login.c | 4 ++-- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/login/account.c b/src/login/account.c index 66ede6cfa..7e8fa5f30 100644 --- a/src/login/account.c +++ b/src/login/account.c @@ -85,8 +85,8 @@ 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 mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int account_id); -static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, bool is_new); +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); /// public constructor AccountDB* account_db_sql(void) @@ -381,7 +381,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 mmo_auth_tosql(db, acc, true); + return account_mmo_auth_tosql(db, acc, true); } /// delete an existing account entry + its regs @@ -411,14 +411,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 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 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 @@ -516,7 +516,7 @@ static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account {// get account data int account_id; account_id = atoi(data); - if( 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); @@ -528,7 +528,7 @@ static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account } -static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int account_id) +static bool account_mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int account_id) { struct Sql *sql_handle; char* data; @@ -573,7 +573,7 @@ static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int acc return true; } -static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, bool is_new) +static bool account_mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, bool is_new) { struct Sql *sql_handle; struct SqlStmt *stmt; @@ -673,7 +673,8 @@ struct Sql *account_db_sql_up(AccountDB* self) AccountDB_SQL* db = (AccountDB_SQL*)self; return db ? db->accounts : NULL; } -void mmo_save_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) { struct Sql *sql_handle; AccountDB_SQL* db = (AccountDB_SQL*)self; @@ -725,7 +726,7 @@ void mmo_save_accreg2(AccountDB* self, int fd, int account_id, int char_id) } } -void mmo_send_accreg2(AccountDB* self, int fd, int account_id, int char_id) +void account_mmo_send_accreg2(AccountDB* self, int fd, int account_id, int char_id) { struct Sql *sql_handle; AccountDB_SQL* db = (AccountDB_SQL*)self; diff --git a/src/login/account.h b/src/login/account.h index 9bb07fda3..3d47e8c56 100644 --- a/src/login/account.h +++ b/src/login/account.h @@ -164,8 +164,8 @@ struct AccountDB #ifdef HERCULES_CORE struct Sql *account_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); +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); #endif // HERCULES_CORE #endif /* LOGIN_ACCOUNT_H */ 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-70-g09d2 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(-) 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-70-g09d2 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(-) 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-70-g09d2 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(-) 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-70-g09d2 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(-) 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-70-g09d2 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(-) 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-70-g09d2 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(-) 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-70-g09d2 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(-) 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-70-g09d2 From 5c799fd9628efb9d45f32ef1138363bbf814c9a2 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 6 Feb 2018 21:13:29 +0300 Subject: Add global variables into loginlog interface. --- src/login/loginlog.c | 86 +++++++++++++++++++++++++++------------------------- src/login/loginlog.h | 13 ++++++++ 2 files changed, 58 insertions(+), 41 deletions(-) diff --git a/src/login/loginlog.c b/src/login/loginlog.c index 38be53193..0e4cc79f0 100644 --- a/src/login/loginlog.c +++ b/src/login/loginlog.c @@ -33,20 +33,10 @@ #include // exit -// Sql settings -static char log_db_hostname[32] = "127.0.0.1"; -static uint16 log_db_port = 3306; -static char log_db_username[32] = "ragnarok"; -static char log_db_password[100] = "ragnarok"; -static char log_db_database[32] = "ragnarok"; -static char log_codepage[32] = ""; -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; +struct s_loginlog_dbs loginlogdbs; // Returns the number of failed login attempts by the ip in the last minutes. @@ -54,19 +44,19 @@ unsigned long loginlog_failedattempts(uint32 ip, unsigned int minutes) { unsigned long failures = 0; - if( !enabled ) + if( !loginlog->enabled ) return 0; - if( SQL_ERROR == SQL->Query(sql_handle, "SELECT count(*) FROM `%s` WHERE `ip` = '%s' AND `rcode` = '1' AND `time` > NOW() - INTERVAL %u MINUTE", - log_login_db, sockt->ip2str(ip,NULL), minutes) )// how many times failed account? in one ip. - Sql_ShowDebug(sql_handle); + if( SQL_ERROR == SQL->Query(loginlog->sql_handle, "SELECT count(*) FROM `%s` WHERE `ip` = '%s' AND `rcode` = '1' AND `time` > NOW() - INTERVAL %u MINUTE", + loginlog->dbs->log_login_db, sockt->ip2str(ip,NULL), minutes) )// how many times failed account? in one ip. + Sql_ShowDebug(loginlog->sql_handle); - if( SQL_SUCCESS == SQL->NextRow(sql_handle) ) + if( SQL_SUCCESS == SQL->NextRow(loginlog->sql_handle) ) { char* data; - SQL->GetData(sql_handle, 0, &data, NULL); + SQL->GetData(loginlog->sql_handle, 0, &data, NULL); failures = strtoul(data, NULL, 10); - SQL->FreeResult(sql_handle); + SQL->FreeResult(loginlog->sql_handle); } return failures; } @@ -84,43 +74,43 @@ void loginlog_log(uint32 ip, const char* username, int rcode, const char* messag nullpo_retv(username); nullpo_retv(message); - if( !enabled ) + if( !loginlog->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(loginlog->sql_handle, esc_username, username, strnlen(username, NAME_LENGTH)); + SQL->EscapeStringLen(loginlog->sql_handle, esc_message, message, strnlen(message, 255)); - retcode = SQL->Query(sql_handle, + retcode = SQL->Query(loginlog->sql_handle, "INSERT INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '%s', '%s', '%d', '%s')", - log_login_db, sockt->ip2str(ip,NULL), esc_username, rcode, esc_message); + loginlog->dbs->log_login_db, sockt->ip2str(ip,NULL), esc_username, rcode, esc_message); if( retcode != SQL_SUCCESS ) - Sql_ShowDebug(sql_handle); + Sql_ShowDebug(loginlog->sql_handle); } bool loginlog_init(void) { - sql_handle = SQL->Malloc(); + loginlog->sql_handle = SQL->Malloc(); - if (SQL_ERROR == SQL->Connect(sql_handle, log_db_username, log_db_password, - log_db_hostname, log_db_port, log_db_database)) { - Sql_ShowDebug(sql_handle); - SQL->Free(sql_handle); + if (SQL_ERROR == SQL->Connect(loginlog->sql_handle, loginlog->dbs->log_db_username, loginlog->dbs->log_db_password, + loginlog->dbs->log_db_hostname, loginlog->dbs->log_db_port, loginlog->dbs->log_db_database)) { + Sql_ShowDebug(loginlog->sql_handle); + SQL->Free(loginlog->sql_handle); exit(EXIT_FAILURE); } - if (log_codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, log_codepage)) - Sql_ShowDebug(sql_handle); + if (loginlog->dbs->log_codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(loginlog->sql_handle, loginlog->dbs->log_codepage)) + Sql_ShowDebug(loginlog->sql_handle); - enabled = true; + loginlog->enabled = true; return true; } bool loginlog_final(void) { - SQL->Free(sql_handle); - sql_handle = NULL; + SQL->Free(loginlog->sql_handle); + loginlog->sql_handle = NULL; return true; } @@ -148,7 +138,7 @@ bool loginlog_config_read_names(const char *filename, struct config_t *config, b return false; } - libconfig->setting_lookup_mutable_string(setting, "login_db", log_login_db, sizeof(log_login_db)); + libconfig->setting_lookup_mutable_string(setting, "login_db", loginlog->dbs->log_login_db, sizeof(loginlog->dbs->log_login_db)); return true; } @@ -177,13 +167,13 @@ bool loginlog_config_read_log(const char *filename, struct config_t *config, boo return false; } - libconfig->setting_lookup_mutable_string(setting, "db_hostname", log_db_hostname, sizeof(log_db_hostname)); - libconfig->setting_lookup_mutable_string(setting, "db_database", log_db_database, sizeof(log_db_database)); - libconfig->setting_lookup_mutable_string(setting, "db_username", log_db_username, sizeof(log_db_username)); - libconfig->setting_lookup_mutable_string(setting, "db_password", log_db_password, sizeof(log_db_password)); + libconfig->setting_lookup_mutable_string(setting, "db_hostname", loginlog->dbs->log_db_hostname, sizeof(loginlog->dbs->log_db_hostname)); + libconfig->setting_lookup_mutable_string(setting, "db_database", loginlog->dbs->log_db_database, sizeof(loginlog->dbs->log_db_database)); + libconfig->setting_lookup_mutable_string(setting, "db_username", loginlog->dbs->log_db_username, sizeof(loginlog->dbs->log_db_username)); + libconfig->setting_lookup_mutable_string(setting, "db_password", loginlog->dbs->log_db_password, sizeof(loginlog->dbs->log_db_password)); - libconfig->setting_lookup_uint16(setting, "db_port", &log_db_port); - libconfig->setting_lookup_mutable_string(setting, "codepage", log_codepage, sizeof(log_codepage)); + libconfig->setting_lookup_uint16(setting, "db_port", &loginlog->dbs->log_db_port); + libconfig->setting_lookup_mutable_string(setting, "codepage", loginlog->dbs->log_codepage, sizeof(loginlog->dbs->log_codepage)); return true; } @@ -230,6 +220,20 @@ bool loginlog_config_read(const char *filename, bool imported) void loginlog_defaults(void) { loginlog = &loginlog_s; + loginlog->dbs = &loginlogdbs; + + loginlog->sql_handle = NULL; + loginlog->enabled = false; + + // Sql settings + strcpy(loginlog->dbs->log_db_hostname, "127.0.0.1"); + loginlog->dbs->log_db_port = 3306; + strcpy(loginlog->dbs->log_db_username, "ragnarok"); + strcpy(loginlog->dbs->log_db_password, "ragnarok"); + strcpy(loginlog->dbs->log_db_database, "ragnarok"); + *loginlog->dbs->log_codepage = 0; + strcpy(loginlog->dbs->log_login_db, "loginlog"); + loginlog->failedattempts = loginlog_failedattempts; loginlog->log = loginlog_log; loginlog->init = loginlog_init; diff --git a/src/login/loginlog.h b/src/login/loginlog.h index 8edbedbaa..fecb9b364 100644 --- a/src/login/loginlog.h +++ b/src/login/loginlog.h @@ -26,10 +26,23 @@ struct config_t; +struct s_loginlog_dbs { + char log_db_hostname[32]; + uint16 log_db_port; + char log_db_username[32]; + char log_db_password[100]; + char log_db_database[32]; + char log_codepage[32]; + char log_login_db[256]; +}; + /** * Loginlog.c Interface **/ struct loginlog_interface { + struct Sql *sql_handle; + bool enabled; + struct s_loginlog_dbs *dbs; unsigned long (*failedattempts) (uint32 ip, unsigned int minutes); void (*log) (uint32 ip, const char* username, int rcode, const char* message); bool (*init) (void); -- cgit v1.2.3-70-g09d2 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(-) 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-70-g09d2 From 86a06df0f10aa857402a6f7f4afe63d63c05e7da Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 6 Feb 2018 21:54:48 +0300 Subject: Update HPM hooks. --- src/common/HPMDataCheck.h | 17 + src/common/HPMSymbols.inc.h | 28 + src/plugins/HPMHooking/HPMHooking.Defs.inc | 86 + .../HPMHooking/HPMHooking_login.HPMHooksCore.inc | 160 ++ .../HPMHooking/HPMHooking_login.HookingPoints.inc | 43 + src/plugins/HPMHooking/HPMHooking_login.Hooks.inc | 1895 +++++++++++++++----- .../HPMHooking/HPMHooking_login.sources.inc | 4 + 7 files changed, 1808 insertions(+), 425 deletions(-) diff --git a/src/common/HPMDataCheck.h b/src/common/HPMDataCheck.h index f2812a275..fe4745e79 100644 --- a/src/common/HPMDataCheck.h +++ b/src/common/HPMDataCheck.h @@ -309,11 +309,20 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = { #ifdef LOGIN_ACCOUNT_H { "Account_engine", sizeof(struct Account_engine), SERVER_TYPE_LOGIN }, { "AccountDB", sizeof(struct AccountDB), SERVER_TYPE_LOGIN }, + { "AccountDB_SQL", sizeof(struct AccountDB_SQL), SERVER_TYPE_LOGIN }, { "AccountDBIterator", sizeof(struct AccountDBIterator), SERVER_TYPE_LOGIN }, + { "AccountDBIterator_SQL", sizeof(struct AccountDBIterator_SQL), SERVER_TYPE_LOGIN }, + { "account_interface", sizeof(struct account_interface), SERVER_TYPE_LOGIN }, { "mmo_account", sizeof(struct mmo_account), SERVER_TYPE_LOGIN }, #else #define LOGIN_ACCOUNT_H #endif // LOGIN_ACCOUNT_H + #ifdef LOGIN_IPBAN_H + { "ipban_interface", sizeof(struct ipban_interface), SERVER_TYPE_LOGIN }, + { "s_ipban_dbs", sizeof(struct s_ipban_dbs), SERVER_TYPE_LOGIN }, + #else + #define LOGIN_IPBAN_H + #endif // LOGIN_IPBAN_H #ifdef LOGIN_LCLIF_H { "lclif_interface", sizeof(struct lclif_interface), SERVER_TYPE_LOGIN }, { "login_packet_db", sizeof(struct login_packet_db), SERVER_TYPE_LOGIN }, @@ -341,14 +350,22 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = { #else #define LOGIN_LCLIF_P_H #endif // LOGIN_LCLIF_P_H + #ifdef LOGIN_LOGINLOG_H + { "loginlog_interface", sizeof(struct loginlog_interface), SERVER_TYPE_LOGIN }, + { "s_loginlog_dbs", sizeof(struct s_loginlog_dbs), SERVER_TYPE_LOGIN }, + #else + #define LOGIN_LOGINLOG_H + #endif // LOGIN_LOGINLOG_H #ifdef LOGIN_LOGIN_H { "Login_Config", sizeof(struct Login_Config), SERVER_TYPE_LOGIN }, { "client_hash_node", sizeof(struct client_hash_node), SERVER_TYPE_LOGIN }, + { "lchrif_interface", sizeof(struct lchrif_interface), SERVER_TYPE_LOGIN }, { "login_auth_node", sizeof(struct login_auth_node), SERVER_TYPE_LOGIN }, { "login_interface", sizeof(struct login_interface), SERVER_TYPE_LOGIN }, { "login_session_data", sizeof(struct login_session_data), SERVER_TYPE_LOGIN }, { "mmo_char_server", sizeof(struct mmo_char_server), SERVER_TYPE_LOGIN }, { "online_login_data", sizeof(struct online_login_data), SERVER_TYPE_LOGIN }, + { "s_login_dbs", sizeof(struct s_login_dbs), SERVER_TYPE_LOGIN }, #else #define LOGIN_LOGIN_H #endif // LOGIN_LOGIN_H diff --git a/src/common/HPMSymbols.inc.h b/src/common/HPMSymbols.inc.h index 6be9d547c..70de5cdef 100644 --- a/src/common/HPMSymbols.inc.h +++ b/src/common/HPMSymbols.inc.h @@ -29,6 +29,9 @@ #ifdef COMMON_UTILS_H /* HCache */ struct HCache_interface *HCache; #endif // COMMON_UTILS_H +#ifdef LOGIN_ACCOUNT_H /* account */ +struct account_interface *account; +#endif // LOGIN_ACCOUNT_H #ifdef MAP_ATCOMMAND_H /* atcommand */ struct atcommand_interface *atcommand; #endif // MAP_ATCOMMAND_H @@ -140,12 +143,18 @@ struct inter_storage_interface *inter_storage; #ifdef MAP_INTIF_H /* intif */ struct intif_interface *intif; #endif // MAP_INTIF_H +#ifdef LOGIN_IPBAN_H /* ipban */ +struct ipban_interface *ipban; +#endif // LOGIN_IPBAN_H #ifdef MAP_IRC_BOT_H /* ircbot */ struct irc_bot_interface *ircbot; #endif // MAP_IRC_BOT_H #ifdef MAP_ITEMDB_H /* itemdb */ struct itemdb_interface *itemdb; #endif // MAP_ITEMDB_H +#ifdef LOGIN_LOGIN_H /* lchrif */ +struct lchrif_interface *lchrif; +#endif // LOGIN_LOGIN_H #ifdef LOGIN_LCLIF_H /* lclif */ struct lclif_interface *lclif; #endif // LOGIN_LCLIF_H @@ -161,6 +170,9 @@ struct login_interface *login; #ifdef CHAR_LOGINIF_H /* loginif */ struct loginif_interface *loginif; #endif // CHAR_LOGINIF_H +#ifdef LOGIN_LOGINLOG_H /* loginlog */ +struct loginlog_interface *loginlog; +#endif // LOGIN_LOGINLOG_H #ifdef MAP_MAIL_H /* mail */ struct mail_interface *mail; #endif // MAP_MAIL_H @@ -289,6 +301,10 @@ HPExport const char *HPM_shared_symbols(int server_type) if ((server_type&(SERVER_TYPE_ALL)) != 0 && !HPM_SYMBOL("HCache", HCache)) return "HCache"; #endif // COMMON_UTILS_H +#ifdef LOGIN_ACCOUNT_H /* account */ + if ((server_type&(SERVER_TYPE_LOGIN)) != 0 && !HPM_SYMBOL("account", account)) + return "account"; +#endif // LOGIN_ACCOUNT_H #ifdef MAP_ATCOMMAND_H /* atcommand */ if ((server_type&(SERVER_TYPE_MAP)) != 0 && !HPM_SYMBOL("atcommand", atcommand)) return "atcommand"; @@ -437,6 +453,10 @@ HPExport const char *HPM_shared_symbols(int server_type) if ((server_type&(SERVER_TYPE_MAP)) != 0 && !HPM_SYMBOL("intif", intif)) return "intif"; #endif // MAP_INTIF_H +#ifdef LOGIN_IPBAN_H /* ipban */ + if ((server_type&(SERVER_TYPE_LOGIN)) != 0 && !HPM_SYMBOL("ipban", ipban)) + return "ipban"; +#endif // LOGIN_IPBAN_H #ifdef MAP_IRC_BOT_H /* ircbot */ if ((server_type&(SERVER_TYPE_MAP)) != 0 && !HPM_SYMBOL("ircbot", ircbot)) return "ircbot"; @@ -445,6 +465,10 @@ HPExport const char *HPM_shared_symbols(int server_type) if ((server_type&(SERVER_TYPE_MAP)) != 0 && !HPM_SYMBOL("itemdb", itemdb)) return "itemdb"; #endif // MAP_ITEMDB_H +#ifdef LOGIN_LOGIN_H /* lchrif */ + if ((server_type&(SERVER_TYPE_LOGIN)) != 0 && !HPM_SYMBOL("lchrif", lchrif)) + return "lchrif"; +#endif // LOGIN_LOGIN_H #ifdef LOGIN_LCLIF_H /* lclif */ if ((server_type&(SERVER_TYPE_LOGIN)) != 0 && !HPM_SYMBOL("lclif", lclif)) return "lclif"; @@ -465,6 +489,10 @@ HPExport const char *HPM_shared_symbols(int server_type) if ((server_type&(SERVER_TYPE_CHAR)) != 0 && !HPM_SYMBOL("loginif", loginif)) return "loginif"; #endif // CHAR_LOGINIF_H +#ifdef LOGIN_LOGINLOG_H /* loginlog */ + if ((server_type&(SERVER_TYPE_LOGIN)) != 0 && !HPM_SYMBOL("loginlog", loginlog)) + return "loginlog"; +#endif // LOGIN_LOGINLOG_H #ifdef MAP_MAIL_H /* mail */ if ((server_type&(SERVER_TYPE_MAP)) != 0 && !HPM_SYMBOL("mail", mail)) return "mail"; diff --git a/src/plugins/HPMHooking/HPMHooking.Defs.inc b/src/plugins/HPMHooking/HPMHooking.Defs.inc index c293eb1f7..816e1981d 100644 --- a/src/plugins/HPMHooking/HPMHooking.Defs.inc +++ b/src/plugins/HPMHooking/HPMHooking.Defs.inc @@ -33,6 +33,46 @@ typedef bool (*HPMHOOK_post_HCache_check) (bool retVal___, const char *file); typedef FILE* (*HPMHOOK_pre_HCache_open) (const char **file, const char **opt); typedef FILE* (*HPMHOOK_post_HCache_open) (FILE* retVal___, const char *file, const char *opt); #endif // COMMON_UTILS_H +#ifdef LOGIN_ACCOUNT_H /* account */ +typedef struct Sql* (*HPMHOOK_pre_account_db_sql_up) (AccountDB **self); +typedef struct Sql* (*HPMHOOK_post_account_db_sql_up) (struct Sql* retVal___, AccountDB *self); +typedef void (*HPMHOOK_pre_account_mmo_send_accreg2) (AccountDB **self, int *fd, int *account_id, int *char_id); +typedef void (*HPMHOOK_post_account_mmo_send_accreg2) (AccountDB *self, int fd, int account_id, int char_id); +typedef void (*HPMHOOK_pre_account_mmo_save_accreg2) (AccountDB **self, int *fd, int *account_id, int *char_id); +typedef void (*HPMHOOK_post_account_mmo_save_accreg2) (AccountDB *self, int fd, int account_id, int char_id); +typedef bool (*HPMHOOK_pre_account_mmo_auth_fromsql) (AccountDB_SQL **db, struct mmo_account **acc, int *account_id); +typedef bool (*HPMHOOK_post_account_mmo_auth_fromsql) (bool retVal___, AccountDB_SQL *db, struct mmo_account *acc, int account_id); +typedef bool (*HPMHOOK_pre_account_mmo_auth_tosql) (AccountDB_SQL **db, const struct mmo_account **acc, bool *is_new); +typedef bool (*HPMHOOK_post_account_mmo_auth_tosql) (bool retVal___, AccountDB_SQL *db, const struct mmo_account *acc, bool is_new); +typedef AccountDB* (*HPMHOOK_pre_account_db_sql) (void); +typedef AccountDB* (*HPMHOOK_post_account_db_sql) (AccountDB* retVal___); +typedef bool (*HPMHOOK_pre_account_db_sql_init) (AccountDB **self); +typedef bool (*HPMHOOK_post_account_db_sql_init) (bool retVal___, AccountDB *self); +typedef void (*HPMHOOK_pre_account_db_sql_destroy) (AccountDB **self); +typedef void (*HPMHOOK_post_account_db_sql_destroy) (AccountDB *self); +typedef bool (*HPMHOOK_pre_account_db_sql_get_property) (AccountDB **self, const char **key, char **buf, size_t *buflen); +typedef bool (*HPMHOOK_post_account_db_sql_get_property) (bool retVal___, AccountDB *self, const char *key, char *buf, size_t buflen); +typedef bool (*HPMHOOK_pre_account_db_sql_set_property) (AccountDB **self, struct config_t **config, bool *imported); +typedef bool (*HPMHOOK_post_account_db_sql_set_property) (bool retVal___, AccountDB *self, struct config_t *config, bool imported); +typedef bool (*HPMHOOK_pre_account_db_sql_create) (AccountDB **self, struct mmo_account **acc); +typedef bool (*HPMHOOK_post_account_db_sql_create) (bool retVal___, AccountDB *self, struct mmo_account *acc); +typedef bool (*HPMHOOK_pre_account_db_sql_remove) (AccountDB **self, const int *account_id); +typedef bool (*HPMHOOK_post_account_db_sql_remove) (bool retVal___, AccountDB *self, const int account_id); +typedef bool (*HPMHOOK_pre_account_db_sql_save) (AccountDB **self, const struct mmo_account **acc); +typedef bool (*HPMHOOK_post_account_db_sql_save) (bool retVal___, AccountDB *self, const struct mmo_account *acc); +typedef bool (*HPMHOOK_pre_account_db_sql_load_num) (AccountDB **self, struct mmo_account **acc, const int *account_id); +typedef bool (*HPMHOOK_post_account_db_sql_load_num) (bool retVal___, AccountDB *self, struct mmo_account *acc, const int account_id); +typedef bool (*HPMHOOK_pre_account_db_sql_load_str) (AccountDB **self, struct mmo_account **acc, const char **userid); +typedef bool (*HPMHOOK_post_account_db_sql_load_str) (bool retVal___, AccountDB *self, struct mmo_account *acc, const char *userid); +typedef AccountDBIterator* (*HPMHOOK_pre_account_db_sql_iterator) (AccountDB **self); +typedef AccountDBIterator* (*HPMHOOK_post_account_db_sql_iterator) (AccountDBIterator* retVal___, AccountDB *self); +typedef void (*HPMHOOK_pre_account_db_sql_iter_destroy) (AccountDBIterator **self); +typedef void (*HPMHOOK_post_account_db_sql_iter_destroy) (AccountDBIterator *self); +typedef bool (*HPMHOOK_pre_account_db_sql_iter_next) (AccountDBIterator **self, struct mmo_account **acc); +typedef bool (*HPMHOOK_post_account_db_sql_iter_next) (bool retVal___, AccountDBIterator *self, struct mmo_account *acc); +typedef bool (*HPMHOOK_pre_account_db_read_inter) (AccountDB_SQL **db, const char **filename, bool *imported); +typedef bool (*HPMHOOK_post_account_db_read_inter) (bool retVal___, AccountDB_SQL *db, const char *filename, bool imported); +#endif // LOGIN_ACCOUNT_H #ifdef MAP_ATCOMMAND_H /* atcommand */ typedef void (*HPMHOOK_pre_atcommand_init) (bool *minimal); typedef void (*HPMHOOK_post_atcommand_init) (bool minimal); @@ -3429,6 +3469,26 @@ typedef void (*HPMHOOK_post_intif_pRodexCheckName) (int fd); typedef void (*HPMHOOK_pre_intif_pRecvClanMemberAction) (int *fd); typedef void (*HPMHOOK_post_intif_pRecvClanMemberAction) (int fd); #endif // MAP_INTIF_H +#ifdef LOGIN_IPBAN_H /* ipban */ +typedef void (*HPMHOOK_pre_ipban_init) (void); +typedef void (*HPMHOOK_post_ipban_init) (void); +typedef void (*HPMHOOK_pre_ipban_final) (void); +typedef void (*HPMHOOK_post_ipban_final) (void); +typedef int (*HPMHOOK_pre_ipban_cleanup) (int *tid, int64 *tick, int *id, intptr_t *data); +typedef int (*HPMHOOK_post_ipban_cleanup) (int retVal___, int tid, int64 tick, int id, intptr_t data); +typedef bool (*HPMHOOK_pre_ipban_config_read_inter) (const char **filename, bool *imported); +typedef bool (*HPMHOOK_post_ipban_config_read_inter) (bool retVal___, const char *filename, bool imported); +typedef bool (*HPMHOOK_pre_ipban_config_read_connection) (const char **filename, struct config_t **config, bool *imported); +typedef bool (*HPMHOOK_post_ipban_config_read_connection) (bool retVal___, const char *filename, struct config_t *config, bool imported); +typedef bool (*HPMHOOK_pre_ipban_config_read_dynamic) (const char **filename, struct config_t **config, bool *imported); +typedef bool (*HPMHOOK_post_ipban_config_read_dynamic) (bool retVal___, const char *filename, struct config_t *config, bool imported); +typedef bool (*HPMHOOK_pre_ipban_config_read) (const char **filename, struct config_t **config, bool *imported); +typedef bool (*HPMHOOK_post_ipban_config_read) (bool retVal___, const char *filename, struct config_t *config, bool imported); +typedef bool (*HPMHOOK_pre_ipban_check) (uint32 *ip); +typedef bool (*HPMHOOK_post_ipban_check) (bool retVal___, uint32 ip); +typedef void (*HPMHOOK_pre_ipban_log) (uint32 *ip); +typedef void (*HPMHOOK_post_ipban_log) (uint32 ip); +#endif // LOGIN_IPBAN_H #ifdef MAP_IRC_BOT_H /* ircbot */ typedef void (*HPMHOOK_pre_ircbot_init) (bool *minimal); typedef void (*HPMHOOK_post_ircbot_init) (bool minimal); @@ -3599,6 +3659,16 @@ typedef bool (*HPMHOOK_post_itemdb_lookup_const) (bool retVal___, const struct c typedef bool (*HPMHOOK_pre_itemdb_lookup_const_mask) (const struct config_setting_t **it, const char **name, int **value); typedef bool (*HPMHOOK_post_itemdb_lookup_const_mask) (bool retVal___, const struct config_setting_t *it, const char *name, int *value); #endif // MAP_ITEMDB_H +#ifdef LOGIN_LOGIN_H /* lchrif */ +typedef void (*HPMHOOK_pre_lchrif_server_init) (int *id); +typedef void (*HPMHOOK_post_lchrif_server_init) (int id); +typedef void (*HPMHOOK_pre_lchrif_server_destroy) (int *id); +typedef void (*HPMHOOK_post_lchrif_server_destroy) (int id); +typedef void (*HPMHOOK_pre_lchrif_server_reset) (int *id); +typedef void (*HPMHOOK_post_lchrif_server_reset) (int id); +typedef void (*HPMHOOK_pre_lchrif_on_disconnect) (int *id); +typedef void (*HPMHOOK_post_lchrif_on_disconnect) (int id); +#endif // LOGIN_LOGIN_H #ifdef LOGIN_LCLIF_H /* lclif */ typedef void (*HPMHOOK_pre_lclif_init) (void); typedef void (*HPMHOOK_post_lclif_init) (void); @@ -3991,6 +4061,22 @@ typedef void (*HPMHOOK_post_loginif_send_users_count) (int users); typedef void (*HPMHOOK_pre_loginif_connect_to_server) (void); typedef void (*HPMHOOK_post_loginif_connect_to_server) (void); #endif // CHAR_LOGINIF_H +#ifdef LOGIN_LOGINLOG_H /* loginlog */ +typedef unsigned long (*HPMHOOK_pre_loginlog_failedattempts) (uint32 *ip, unsigned int *minutes); +typedef unsigned long (*HPMHOOK_post_loginlog_failedattempts) (unsigned long retVal___, uint32 ip, unsigned int minutes); +typedef void (*HPMHOOK_pre_loginlog_log) (uint32 *ip, const char **username, int *rcode, const char **message); +typedef void (*HPMHOOK_post_loginlog_log) (uint32 ip, const char *username, int rcode, const char *message); +typedef bool (*HPMHOOK_pre_loginlog_init) (void); +typedef bool (*HPMHOOK_post_loginlog_init) (bool retVal___); +typedef bool (*HPMHOOK_pre_loginlog_final) (void); +typedef bool (*HPMHOOK_post_loginlog_final) (bool retVal___); +typedef bool (*HPMHOOK_pre_loginlog_config_read_names) (const char **filename, struct config_t **config, bool *imported); +typedef bool (*HPMHOOK_post_loginlog_config_read_names) (bool retVal___, const char *filename, struct config_t *config, bool imported); +typedef bool (*HPMHOOK_pre_loginlog_config_read_log) (const char **filename, struct config_t **config, bool *imported); +typedef bool (*HPMHOOK_post_loginlog_config_read_log) (bool retVal___, const char *filename, struct config_t *config, bool imported); +typedef bool (*HPMHOOK_pre_loginlog_config_read) (const char **filename, bool *imported); +typedef bool (*HPMHOOK_post_loginlog_config_read) (bool retVal___, const char *filename, bool imported); +#endif // LOGIN_LOGINLOG_H #ifdef MAP_MAIL_H /* mail */ typedef void (*HPMHOOK_pre_mail_clear) (struct map_session_data **sd); typedef void (*HPMHOOK_post_mail_clear) (struct map_session_data *sd); diff --git a/src/plugins/HPMHooking/HPMHooking_login.HPMHooksCore.inc b/src/plugins/HPMHooking/HPMHooking_login.HPMHooksCore.inc index f8c270de3..5300ca3a6 100644 --- a/src/plugins/HPMHooking/HPMHooking_login.HPMHooksCore.inc +++ b/src/plugins/HPMHooking/HPMHooking_login.HPMHooksCore.inc @@ -32,6 +32,44 @@ struct { struct HPMHookPoint *HP_HCache_check_post; struct HPMHookPoint *HP_HCache_open_pre; struct HPMHookPoint *HP_HCache_open_post; + struct HPMHookPoint *HP_account_db_sql_up_pre; + struct HPMHookPoint *HP_account_db_sql_up_post; + struct HPMHookPoint *HP_account_mmo_send_accreg2_pre; + struct HPMHookPoint *HP_account_mmo_send_accreg2_post; + struct HPMHookPoint *HP_account_mmo_save_accreg2_pre; + struct HPMHookPoint *HP_account_mmo_save_accreg2_post; + struct HPMHookPoint *HP_account_mmo_auth_fromsql_pre; + struct HPMHookPoint *HP_account_mmo_auth_fromsql_post; + struct HPMHookPoint *HP_account_mmo_auth_tosql_pre; + struct HPMHookPoint *HP_account_mmo_auth_tosql_post; + struct HPMHookPoint *HP_account_db_sql_pre; + struct HPMHookPoint *HP_account_db_sql_post; + struct HPMHookPoint *HP_account_db_sql_init_pre; + struct HPMHookPoint *HP_account_db_sql_init_post; + struct HPMHookPoint *HP_account_db_sql_destroy_pre; + struct HPMHookPoint *HP_account_db_sql_destroy_post; + struct HPMHookPoint *HP_account_db_sql_get_property_pre; + struct HPMHookPoint *HP_account_db_sql_get_property_post; + struct HPMHookPoint *HP_account_db_sql_set_property_pre; + struct HPMHookPoint *HP_account_db_sql_set_property_post; + struct HPMHookPoint *HP_account_db_sql_create_pre; + struct HPMHookPoint *HP_account_db_sql_create_post; + struct HPMHookPoint *HP_account_db_sql_remove_pre; + struct HPMHookPoint *HP_account_db_sql_remove_post; + struct HPMHookPoint *HP_account_db_sql_save_pre; + struct HPMHookPoint *HP_account_db_sql_save_post; + struct HPMHookPoint *HP_account_db_sql_load_num_pre; + struct HPMHookPoint *HP_account_db_sql_load_num_post; + struct HPMHookPoint *HP_account_db_sql_load_str_pre; + struct HPMHookPoint *HP_account_db_sql_load_str_post; + struct HPMHookPoint *HP_account_db_sql_iterator_pre; + struct HPMHookPoint *HP_account_db_sql_iterator_post; + struct HPMHookPoint *HP_account_db_sql_iter_destroy_pre; + struct HPMHookPoint *HP_account_db_sql_iter_destroy_post; + struct HPMHookPoint *HP_account_db_sql_iter_next_pre; + struct HPMHookPoint *HP_account_db_sql_iter_next_post; + struct HPMHookPoint *HP_account_db_read_inter_pre; + struct HPMHookPoint *HP_account_db_read_inter_post; struct HPMHookPoint *HP_cmdline_init_pre; struct HPMHookPoint *HP_cmdline_init_post; struct HPMHookPoint *HP_cmdline_final_pre; @@ -96,6 +134,32 @@ struct { struct HPMHookPoint *HP_des_decrypt_block_post; struct HPMHookPoint *HP_des_decrypt_pre; struct HPMHookPoint *HP_des_decrypt_post; + struct HPMHookPoint *HP_ipban_init_pre; + struct HPMHookPoint *HP_ipban_init_post; + struct HPMHookPoint *HP_ipban_final_pre; + struct HPMHookPoint *HP_ipban_final_post; + struct HPMHookPoint *HP_ipban_cleanup_pre; + struct HPMHookPoint *HP_ipban_cleanup_post; + struct HPMHookPoint *HP_ipban_config_read_inter_pre; + struct HPMHookPoint *HP_ipban_config_read_inter_post; + struct HPMHookPoint *HP_ipban_config_read_connection_pre; + struct HPMHookPoint *HP_ipban_config_read_connection_post; + struct HPMHookPoint *HP_ipban_config_read_dynamic_pre; + struct HPMHookPoint *HP_ipban_config_read_dynamic_post; + struct HPMHookPoint *HP_ipban_config_read_pre; + struct HPMHookPoint *HP_ipban_config_read_post; + struct HPMHookPoint *HP_ipban_check_pre; + struct HPMHookPoint *HP_ipban_check_post; + struct HPMHookPoint *HP_ipban_log_pre; + struct HPMHookPoint *HP_ipban_log_post; + struct HPMHookPoint *HP_lchrif_server_init_pre; + struct HPMHookPoint *HP_lchrif_server_init_post; + struct HPMHookPoint *HP_lchrif_server_destroy_pre; + struct HPMHookPoint *HP_lchrif_server_destroy_post; + struct HPMHookPoint *HP_lchrif_server_reset_pre; + struct HPMHookPoint *HP_lchrif_server_reset_post; + struct HPMHookPoint *HP_lchrif_on_disconnect_pre; + struct HPMHookPoint *HP_lchrif_on_disconnect_post; struct HPMHookPoint *HP_lclif_init_pre; struct HPMHookPoint *HP_lclif_init_post; struct HPMHookPoint *HP_lclif_final_pre; @@ -406,6 +470,20 @@ struct { struct HPMHookPoint *HP_login_config_set_md5hash_post; struct HPMHookPoint *HP_login_convert_users_to_colors_pre; struct HPMHookPoint *HP_login_convert_users_to_colors_post; + struct HPMHookPoint *HP_loginlog_failedattempts_pre; + struct HPMHookPoint *HP_loginlog_failedattempts_post; + struct HPMHookPoint *HP_loginlog_log_pre; + struct HPMHookPoint *HP_loginlog_log_post; + struct HPMHookPoint *HP_loginlog_init_pre; + struct HPMHookPoint *HP_loginlog_init_post; + struct HPMHookPoint *HP_loginlog_final_pre; + struct HPMHookPoint *HP_loginlog_final_post; + struct HPMHookPoint *HP_loginlog_config_read_names_pre; + struct HPMHookPoint *HP_loginlog_config_read_names_post; + struct HPMHookPoint *HP_loginlog_config_read_log_pre; + struct HPMHookPoint *HP_loginlog_config_read_log_post; + struct HPMHookPoint *HP_loginlog_config_read_pre; + struct HPMHookPoint *HP_loginlog_config_read_post; struct HPMHookPoint *HP_md5_string_pre; struct HPMHookPoint *HP_md5_string_post; struct HPMHookPoint *HP_md5_binary_pre; @@ -735,6 +813,44 @@ struct { int HP_HCache_check_post; int HP_HCache_open_pre; int HP_HCache_open_post; + int HP_account_db_sql_up_pre; + int HP_account_db_sql_up_post; + int HP_account_mmo_send_accreg2_pre; + int HP_account_mmo_send_accreg2_post; + int HP_account_mmo_save_accreg2_pre; + int HP_account_mmo_save_accreg2_post; + int HP_account_mmo_auth_fromsql_pre; + int HP_account_mmo_auth_fromsql_post; + int HP_account_mmo_auth_tosql_pre; + int HP_account_mmo_auth_tosql_post; + int HP_account_db_sql_pre; + int HP_account_db_sql_post; + int HP_account_db_sql_init_pre; + int HP_account_db_sql_init_post; + int HP_account_db_sql_destroy_pre; + int HP_account_db_sql_destroy_post; + int HP_account_db_sql_get_property_pre; + int HP_account_db_sql_get_property_post; + int HP_account_db_sql_set_property_pre; + int HP_account_db_sql_set_property_post; + int HP_account_db_sql_create_pre; + int HP_account_db_sql_create_post; + int HP_account_db_sql_remove_pre; + int HP_account_db_sql_remove_post; + int HP_account_db_sql_save_pre; + int HP_account_db_sql_save_post; + int HP_account_db_sql_load_num_pre; + int HP_account_db_sql_load_num_post; + int HP_account_db_sql_load_str_pre; + int HP_account_db_sql_load_str_post; + int HP_account_db_sql_iterator_pre; + int HP_account_db_sql_iterator_post; + int HP_account_db_sql_iter_destroy_pre; + int HP_account_db_sql_iter_destroy_post; + int HP_account_db_sql_iter_next_pre; + int HP_account_db_sql_iter_next_post; + int HP_account_db_read_inter_pre; + int HP_account_db_read_inter_post; int HP_cmdline_init_pre; int HP_cmdline_init_post; int HP_cmdline_final_pre; @@ -799,6 +915,32 @@ struct { int HP_des_decrypt_block_post; int HP_des_decrypt_pre; int HP_des_decrypt_post; + int HP_ipban_init_pre; + int HP_ipban_init_post; + int HP_ipban_final_pre; + int HP_ipban_final_post; + int HP_ipban_cleanup_pre; + int HP_ipban_cleanup_post; + int HP_ipban_config_read_inter_pre; + int HP_ipban_config_read_inter_post; + int HP_ipban_config_read_connection_pre; + int HP_ipban_config_read_connection_post; + int HP_ipban_config_read_dynamic_pre; + int HP_ipban_config_read_dynamic_post; + int HP_ipban_config_read_pre; + int HP_ipban_config_read_post; + int HP_ipban_check_pre; + int HP_ipban_check_post; + int HP_ipban_log_pre; + int HP_ipban_log_post; + int HP_lchrif_server_init_pre; + int HP_lchrif_server_init_post; + int HP_lchrif_server_destroy_pre; + int HP_lchrif_server_destroy_post; + int HP_lchrif_server_reset_pre; + int HP_lchrif_server_reset_post; + int HP_lchrif_on_disconnect_pre; + int HP_lchrif_on_disconnect_post; int HP_lclif_init_pre; int HP_lclif_init_post; int HP_lclif_final_pre; @@ -1109,6 +1251,20 @@ struct { int HP_login_config_set_md5hash_post; int HP_login_convert_users_to_colors_pre; int HP_login_convert_users_to_colors_post; + int HP_loginlog_failedattempts_pre; + int HP_loginlog_failedattempts_post; + int HP_loginlog_log_pre; + int HP_loginlog_log_post; + int HP_loginlog_init_pre; + int HP_loginlog_init_post; + int HP_loginlog_final_pre; + int HP_loginlog_final_post; + int HP_loginlog_config_read_names_pre; + int HP_loginlog_config_read_names_post; + int HP_loginlog_config_read_log_pre; + int HP_loginlog_config_read_log_post; + int HP_loginlog_config_read_pre; + int HP_loginlog_config_read_post; int HP_md5_string_pre; int HP_md5_string_post; int HP_md5_binary_pre; @@ -1433,15 +1589,19 @@ struct { struct { struct HCache_interface HCache; + struct account_interface account; struct cmdline_interface cmdline; struct console_interface console; struct core_interface core; struct db_interface DB; struct des_interface des; + struct ipban_interface ipban; + struct lchrif_interface lchrif; struct lclif_interface lclif; struct lclif_interface_private PRIV__lclif; struct libconfig_interface libconfig; struct login_interface login; + struct loginlog_interface loginlog; struct md5_interface md5; struct mutex_interface mutex; struct nullpo_interface nullpo; diff --git a/src/plugins/HPMHooking/HPMHooking_login.HookingPoints.inc b/src/plugins/HPMHooking/HPMHooking_login.HookingPoints.inc index 8cec39974..6eb2e8121 100644 --- a/src/plugins/HPMHooking/HPMHooking_login.HookingPoints.inc +++ b/src/plugins/HPMHooking/HPMHooking_login.HookingPoints.inc @@ -30,6 +30,26 @@ struct HookingPointData HookingPoints[] = { { HP_POP(HCache->init, HP_HCache_init) }, { HP_POP(HCache->check, HP_HCache_check) }, { HP_POP(HCache->open, HP_HCache_open) }, +/* account_interface */ + { HP_POP(account->db_sql_up, HP_account_db_sql_up) }, + { HP_POP(account->mmo_send_accreg2, HP_account_mmo_send_accreg2) }, + { HP_POP(account->mmo_save_accreg2, HP_account_mmo_save_accreg2) }, + { HP_POP(account->mmo_auth_fromsql, HP_account_mmo_auth_fromsql) }, + { HP_POP(account->mmo_auth_tosql, HP_account_mmo_auth_tosql) }, + { HP_POP(account->db_sql, HP_account_db_sql) }, + { HP_POP(account->db_sql_init, HP_account_db_sql_init) }, + { HP_POP(account->db_sql_destroy, HP_account_db_sql_destroy) }, + { HP_POP(account->db_sql_get_property, HP_account_db_sql_get_property) }, + { HP_POP(account->db_sql_set_property, HP_account_db_sql_set_property) }, + { HP_POP(account->db_sql_create, HP_account_db_sql_create) }, + { HP_POP(account->db_sql_remove, HP_account_db_sql_remove) }, + { HP_POP(account->db_sql_save, HP_account_db_sql_save) }, + { HP_POP(account->db_sql_load_num, HP_account_db_sql_load_num) }, + { HP_POP(account->db_sql_load_str, HP_account_db_sql_load_str) }, + { HP_POP(account->db_sql_iterator, HP_account_db_sql_iterator) }, + { HP_POP(account->db_sql_iter_destroy, HP_account_db_sql_iter_destroy) }, + { HP_POP(account->db_sql_iter_next, HP_account_db_sql_iter_next) }, + { HP_POP(account->db_read_inter, HP_account_db_read_inter) }, /* cmdline_interface */ { HP_POP(cmdline->init, HP_cmdline_init) }, { HP_POP(cmdline->final, HP_cmdline_final) }, @@ -67,6 +87,21 @@ struct HookingPointData HookingPoints[] = { /* des_interface */ { HP_POP(des->decrypt_block, HP_des_decrypt_block) }, { HP_POP(des->decrypt, HP_des_decrypt) }, +/* ipban_interface */ + { HP_POP(ipban->init, HP_ipban_init) }, + { HP_POP(ipban->final, HP_ipban_final) }, + { HP_POP(ipban->cleanup, HP_ipban_cleanup) }, + { HP_POP(ipban->config_read_inter, HP_ipban_config_read_inter) }, + { HP_POP(ipban->config_read_connection, HP_ipban_config_read_connection) }, + { HP_POP(ipban->config_read_dynamic, HP_ipban_config_read_dynamic) }, + { HP_POP(ipban->config_read, HP_ipban_config_read) }, + { HP_POP(ipban->check, HP_ipban_check) }, + { HP_POP(ipban->log, HP_ipban_log) }, +/* lchrif_interface */ + { HP_POP(lchrif->server_init, HP_lchrif_server_init) }, + { HP_POP(lchrif->server_destroy, HP_lchrif_server_destroy) }, + { HP_POP(lchrif->server_reset, HP_lchrif_server_reset) }, + { HP_POP(lchrif->on_disconnect, HP_lchrif_on_disconnect) }, /* lclif_interface */ { HP_POP(lclif->init, HP_lclif_init) }, { HP_POP(lclif->final, HP_lclif_final) }, @@ -226,6 +261,14 @@ struct HookingPointData HookingPoints[] = { { HP_POP(login->clear_client_hash_nodes, HP_login_clear_client_hash_nodes) }, { HP_POP(login->config_set_md5hash, HP_login_config_set_md5hash) }, { HP_POP(login->convert_users_to_colors, HP_login_convert_users_to_colors) }, +/* loginlog_interface */ + { HP_POP(loginlog->failedattempts, HP_loginlog_failedattempts) }, + { HP_POP(loginlog->log, HP_loginlog_log) }, + { HP_POP(loginlog->init, HP_loginlog_init) }, + { HP_POP(loginlog->final, HP_loginlog_final) }, + { HP_POP(loginlog->config_read_names, HP_loginlog_config_read_names) }, + { HP_POP(loginlog->config_read_log, HP_loginlog_config_read_log) }, + { HP_POP(loginlog->config_read, HP_loginlog_config_read) }, /* md5_interface */ { HP_POP(md5->string, HP_md5_string) }, { HP_POP(md5->binary, HP_md5_binary) }, diff --git a/src/plugins/HPMHooking/HPMHooking_login.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_login.Hooks.inc index 658ee874d..e432da70d 100644 --- a/src/plugins/HPMHooking/HPMHooking_login.Hooks.inc +++ b/src/plugins/HPMHooking/HPMHooking_login.Hooks.inc @@ -106,41 +106,42 @@ FILE* HP_HCache_open(const char *file, const char *opt) { } return retVal___; } -/* cmdline_interface */ -void HP_cmdline_init(void) { +/* account_interface */ +struct Sql* HP_account_db_sql_up(AccountDB *self) { int hIndex = 0; - if (HPMHooks.count.HP_cmdline_init_pre > 0) { - void (*preHookFunc) (void); + struct Sql* retVal___ = NULL; + if (HPMHooks.count.HP_account_db_sql_up_pre > 0) { + struct Sql* (*preHookFunc) (AccountDB **self); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_cmdline_init_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_cmdline_init_pre[hIndex].func; - preHookFunc(); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_up_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_account_db_sql_up_pre[hIndex].func; + retVal___ = preHookFunc(&self); } if (*HPMforce_return) { *HPMforce_return = false; - return; + return retVal___; } } { - HPMHooks.source.cmdline.init(); + retVal___ = HPMHooks.source.account.db_sql_up(self); } - if (HPMHooks.count.HP_cmdline_init_post > 0) { - void (*postHookFunc) (void); - for (hIndex = 0; hIndex < HPMHooks.count.HP_cmdline_init_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_cmdline_init_post[hIndex].func; - postHookFunc(); + if (HPMHooks.count.HP_account_db_sql_up_post > 0) { + struct Sql* (*postHookFunc) (struct Sql* retVal___, AccountDB *self); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_up_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_account_db_sql_up_post[hIndex].func; + retVal___ = postHookFunc(retVal___, self); } } - return; + return retVal___; } -void HP_cmdline_final(void) { +void HP_account_mmo_send_accreg2(AccountDB *self, int fd, int account_id, int char_id) { int hIndex = 0; - if (HPMHooks.count.HP_cmdline_final_pre > 0) { - void (*preHookFunc) (void); + if (HPMHooks.count.HP_account_mmo_send_accreg2_pre > 0) { + void (*preHookFunc) (AccountDB **self, int *fd, int *account_id, int *char_id); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_cmdline_final_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_cmdline_final_pre[hIndex].func; - preHookFunc(); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_mmo_send_accreg2_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_account_mmo_send_accreg2_pre[hIndex].func; + preHookFunc(&self, &fd, &account_id, &char_id); } if (*HPMforce_return) { *HPMforce_return = false; @@ -148,53 +149,52 @@ void HP_cmdline_final(void) { } } { - HPMHooks.source.cmdline.final(); + HPMHooks.source.account.mmo_send_accreg2(self, fd, account_id, char_id); } - if (HPMHooks.count.HP_cmdline_final_post > 0) { - void (*postHookFunc) (void); - for (hIndex = 0; hIndex < HPMHooks.count.HP_cmdline_final_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_cmdline_final_post[hIndex].func; - postHookFunc(); + if (HPMHooks.count.HP_account_mmo_send_accreg2_post > 0) { + void (*postHookFunc) (AccountDB *self, int fd, int account_id, int char_id); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_mmo_send_accreg2_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_account_mmo_send_accreg2_post[hIndex].func; + postHookFunc(self, fd, account_id, char_id); } } return; } -bool HP_cmdline_arg_add(unsigned int pluginID, const char *name, char shortname, CmdlineExecFunc func, const char *help, unsigned int options) { +void HP_account_mmo_save_accreg2(AccountDB *self, int fd, int account_id, int char_id) { int hIndex = 0; - bool retVal___ = false; - if (HPMHooks.count.HP_cmdline_arg_add_pre > 0) { - bool (*preHookFunc) (unsigned int *pluginID, const char **name, char *shortname, CmdlineExecFunc *func, const char **help, unsigned int *options); + if (HPMHooks.count.HP_account_mmo_save_accreg2_pre > 0) { + void (*preHookFunc) (AccountDB **self, int *fd, int *account_id, int *char_id); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_cmdline_arg_add_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_cmdline_arg_add_pre[hIndex].func; - retVal___ = preHookFunc(&pluginID, &name, &shortname, &func, &help, &options); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_mmo_save_accreg2_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_account_mmo_save_accreg2_pre[hIndex].func; + preHookFunc(&self, &fd, &account_id, &char_id); } if (*HPMforce_return) { *HPMforce_return = false; - return retVal___; + return; } } { - retVal___ = HPMHooks.source.cmdline.arg_add(pluginID, name, shortname, func, help, options); + HPMHooks.source.account.mmo_save_accreg2(self, fd, account_id, char_id); } - if (HPMHooks.count.HP_cmdline_arg_add_post > 0) { - bool (*postHookFunc) (bool retVal___, unsigned int pluginID, const char *name, char shortname, CmdlineExecFunc func, const char *help, unsigned int options); - for (hIndex = 0; hIndex < HPMHooks.count.HP_cmdline_arg_add_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_cmdline_arg_add_post[hIndex].func; - retVal___ = postHookFunc(retVal___, pluginID, name, shortname, func, help, options); + if (HPMHooks.count.HP_account_mmo_save_accreg2_post > 0) { + void (*postHookFunc) (AccountDB *self, int fd, int account_id, int char_id); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_mmo_save_accreg2_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_account_mmo_save_accreg2_post[hIndex].func; + postHookFunc(self, fd, account_id, char_id); } } - return retVal___; + return; } -int HP_cmdline_exec(int argc, char **argv, unsigned int options) { +bool HP_account_mmo_auth_fromsql(AccountDB_SQL *db, struct mmo_account *acc, int account_id) { int hIndex = 0; - int retVal___ = 0; - if (HPMHooks.count.HP_cmdline_exec_pre > 0) { - int (*preHookFunc) (int *argc, char ***argv, unsigned int *options); + bool retVal___ = false; + if (HPMHooks.count.HP_account_mmo_auth_fromsql_pre > 0) { + bool (*preHookFunc) (AccountDB_SQL **db, struct mmo_account **acc, int *account_id); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_cmdline_exec_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_cmdline_exec_pre[hIndex].func; - retVal___ = preHookFunc(&argc, &argv, &options); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_mmo_auth_fromsql_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_account_mmo_auth_fromsql_pre[hIndex].func; + retVal___ = preHookFunc(&db, &acc, &account_id); } if (*HPMforce_return) { *HPMforce_return = false; @@ -202,26 +202,26 @@ int HP_cmdline_exec(int argc, char **argv, unsigned int options) { } } { - retVal___ = HPMHooks.source.cmdline.exec(argc, argv, options); + retVal___ = HPMHooks.source.account.mmo_auth_fromsql(db, acc, account_id); } - if (HPMHooks.count.HP_cmdline_exec_post > 0) { - int (*postHookFunc) (int retVal___, int argc, char **argv, unsigned int options); - for (hIndex = 0; hIndex < HPMHooks.count.HP_cmdline_exec_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_cmdline_exec_post[hIndex].func; - retVal___ = postHookFunc(retVal___, argc, argv, options); + if (HPMHooks.count.HP_account_mmo_auth_fromsql_post > 0) { + bool (*postHookFunc) (bool retVal___, AccountDB_SQL *db, struct mmo_account *acc, int account_id); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_mmo_auth_fromsql_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_account_mmo_auth_fromsql_post[hIndex].func; + retVal___ = postHookFunc(retVal___, db, acc, account_id); } } return retVal___; } -bool HP_cmdline_arg_next_value(const char *name, int current_arg, int argc) { +bool HP_account_mmo_auth_tosql(AccountDB_SQL *db, const struct mmo_account *acc, bool is_new) { int hIndex = 0; bool retVal___ = false; - if (HPMHooks.count.HP_cmdline_arg_next_value_pre > 0) { - bool (*preHookFunc) (const char **name, int *current_arg, int *argc); + if (HPMHooks.count.HP_account_mmo_auth_tosql_pre > 0) { + bool (*preHookFunc) (AccountDB_SQL **db, const struct mmo_account **acc, bool *is_new); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_cmdline_arg_next_value_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_cmdline_arg_next_value_pre[hIndex].func; - retVal___ = preHookFunc(&name, ¤t_arg, &argc); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_mmo_auth_tosql_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_account_mmo_auth_tosql_pre[hIndex].func; + retVal___ = preHookFunc(&db, &acc, &is_new); } if (*HPMforce_return) { *HPMforce_return = false; @@ -229,26 +229,26 @@ bool HP_cmdline_arg_next_value(const char *name, int current_arg, int argc) { } } { - retVal___ = HPMHooks.source.cmdline.arg_next_value(name, current_arg, argc); + retVal___ = HPMHooks.source.account.mmo_auth_tosql(db, acc, is_new); } - if (HPMHooks.count.HP_cmdline_arg_next_value_post > 0) { - bool (*postHookFunc) (bool retVal___, const char *name, int current_arg, int argc); - for (hIndex = 0; hIndex < HPMHooks.count.HP_cmdline_arg_next_value_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_cmdline_arg_next_value_post[hIndex].func; - retVal___ = postHookFunc(retVal___, name, current_arg, argc); + if (HPMHooks.count.HP_account_mmo_auth_tosql_post > 0) { + bool (*postHookFunc) (bool retVal___, AccountDB_SQL *db, const struct mmo_account *acc, bool is_new); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_mmo_auth_tosql_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_account_mmo_auth_tosql_post[hIndex].func; + retVal___ = postHookFunc(retVal___, db, acc, is_new); } } return retVal___; } -const char* HP_cmdline_arg_source(struct CmdlineArgData *arg) { +AccountDB* HP_account_db_sql(void) { int hIndex = 0; - const char* retVal___ = NULL; - if (HPMHooks.count.HP_cmdline_arg_source_pre > 0) { - const char* (*preHookFunc) (struct CmdlineArgData **arg); + AccountDB* retVal___ = NULL; + if (HPMHooks.count.HP_account_db_sql_pre > 0) { + AccountDB* (*preHookFunc) (void); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_cmdline_arg_source_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_cmdline_arg_source_pre[hIndex].func; - retVal___ = preHookFunc(&arg); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_account_db_sql_pre[hIndex].func; + retVal___ = preHookFunc(); } if (*HPMforce_return) { *HPMforce_return = false; @@ -256,52 +256,52 @@ const char* HP_cmdline_arg_source(struct CmdlineArgData *arg) { } } { - retVal___ = HPMHooks.source.cmdline.arg_source(arg); + retVal___ = HPMHooks.source.account.db_sql(); } - if (HPMHooks.count.HP_cmdline_arg_source_post > 0) { - const char* (*postHookFunc) (const char* retVal___, struct CmdlineArgData *arg); - for (hIndex = 0; hIndex < HPMHooks.count.HP_cmdline_arg_source_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_cmdline_arg_source_post[hIndex].func; - retVal___ = postHookFunc(retVal___, arg); + if (HPMHooks.count.HP_account_db_sql_post > 0) { + AccountDB* (*postHookFunc) (AccountDB* retVal___); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_account_db_sql_post[hIndex].func; + retVal___ = postHookFunc(retVal___); } } return retVal___; } -/* console_interface */ -void HP_console_init(void) { +bool HP_account_db_sql_init(AccountDB *self) { int hIndex = 0; - if (HPMHooks.count.HP_console_init_pre > 0) { - void (*preHookFunc) (void); + bool retVal___ = false; + if (HPMHooks.count.HP_account_db_sql_init_pre > 0) { + bool (*preHookFunc) (AccountDB **self); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_console_init_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_console_init_pre[hIndex].func; - preHookFunc(); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_init_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_account_db_sql_init_pre[hIndex].func; + retVal___ = preHookFunc(&self); } if (*HPMforce_return) { *HPMforce_return = false; - return; + return retVal___; } } { - HPMHooks.source.console.init(); + retVal___ = HPMHooks.source.account.db_sql_init(self); } - if (HPMHooks.count.HP_console_init_post > 0) { - void (*postHookFunc) (void); - for (hIndex = 0; hIndex < HPMHooks.count.HP_console_init_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_console_init_post[hIndex].func; - postHookFunc(); + if (HPMHooks.count.HP_account_db_sql_init_post > 0) { + bool (*postHookFunc) (bool retVal___, AccountDB *self); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_init_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_account_db_sql_init_post[hIndex].func; + retVal___ = postHookFunc(retVal___, self); } } - return; + return retVal___; } -void HP_console_final(void) { +void HP_account_db_sql_destroy(AccountDB *self) { int hIndex = 0; - if (HPMHooks.count.HP_console_final_pre > 0) { - void (*preHookFunc) (void); + if (HPMHooks.count.HP_account_db_sql_destroy_pre > 0) { + void (*preHookFunc) (AccountDB **self); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_console_final_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_console_final_pre[hIndex].func; - preHookFunc(); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_destroy_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_account_db_sql_destroy_pre[hIndex].func; + preHookFunc(&self); } if (*HPMforce_return) { *HPMforce_return = false; @@ -309,106 +309,107 @@ void HP_console_final(void) { } } { - HPMHooks.source.console.final(); + HPMHooks.source.account.db_sql_destroy(self); } - if (HPMHooks.count.HP_console_final_post > 0) { - void (*postHookFunc) (void); - for (hIndex = 0; hIndex < HPMHooks.count.HP_console_final_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_console_final_post[hIndex].func; - postHookFunc(); + if (HPMHooks.count.HP_account_db_sql_destroy_post > 0) { + void (*postHookFunc) (AccountDB *self); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_destroy_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_account_db_sql_destroy_post[hIndex].func; + postHookFunc(self); } } return; } -void HP_console_display_title(void) { +bool HP_account_db_sql_get_property(AccountDB *self, const char *key, char *buf, size_t buflen) { int hIndex = 0; - if (HPMHooks.count.HP_console_display_title_pre > 0) { - void (*preHookFunc) (void); + bool retVal___ = false; + if (HPMHooks.count.HP_account_db_sql_get_property_pre > 0) { + bool (*preHookFunc) (AccountDB **self, const char **key, char **buf, size_t *buflen); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_console_display_title_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_console_display_title_pre[hIndex].func; - preHookFunc(); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_get_property_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_account_db_sql_get_property_pre[hIndex].func; + retVal___ = preHookFunc(&self, &key, &buf, &buflen); } if (*HPMforce_return) { *HPMforce_return = false; - return; + return retVal___; } } { - HPMHooks.source.console.display_title(); + retVal___ = HPMHooks.source.account.db_sql_get_property(self, key, buf, buflen); } - if (HPMHooks.count.HP_console_display_title_post > 0) { - void (*postHookFunc) (void); - for (hIndex = 0; hIndex < HPMHooks.count.HP_console_display_title_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_console_display_title_post[hIndex].func; - postHookFunc(); + if (HPMHooks.count.HP_account_db_sql_get_property_post > 0) { + bool (*postHookFunc) (bool retVal___, AccountDB *self, const char *key, char *buf, size_t buflen); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_get_property_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_account_db_sql_get_property_post[hIndex].func; + retVal___ = postHookFunc(retVal___, self, key, buf, buflen); } } - return; + return retVal___; } -void HP_console_display_gplnotice(void) { +bool HP_account_db_sql_set_property(AccountDB *self, struct config_t *config, bool imported) { int hIndex = 0; - if (HPMHooks.count.HP_console_display_gplnotice_pre > 0) { - void (*preHookFunc) (void); + bool retVal___ = false; + if (HPMHooks.count.HP_account_db_sql_set_property_pre > 0) { + bool (*preHookFunc) (AccountDB **self, struct config_t **config, bool *imported); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_console_display_gplnotice_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_console_display_gplnotice_pre[hIndex].func; - preHookFunc(); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_set_property_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_account_db_sql_set_property_pre[hIndex].func; + retVal___ = preHookFunc(&self, &config, &imported); } if (*HPMforce_return) { *HPMforce_return = false; - return; + return retVal___; } } { - HPMHooks.source.console.display_gplnotice(); + retVal___ = HPMHooks.source.account.db_sql_set_property(self, config, imported); } - if (HPMHooks.count.HP_console_display_gplnotice_post > 0) { - void (*postHookFunc) (void); - for (hIndex = 0; hIndex < HPMHooks.count.HP_console_display_gplnotice_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_console_display_gplnotice_post[hIndex].func; - postHookFunc(); + if (HPMHooks.count.HP_account_db_sql_set_property_post > 0) { + bool (*postHookFunc) (bool retVal___, AccountDB *self, struct config_t *config, bool imported); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_set_property_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_account_db_sql_set_property_post[hIndex].func; + retVal___ = postHookFunc(retVal___, self, config, imported); } } - return; + return retVal___; } -/* core_interface */ -void HP_core_shutdown_callback(void) { +bool HP_account_db_sql_create(AccountDB *self, struct mmo_account *acc) { int hIndex = 0; - if (HPMHooks.count.HP_core_shutdown_callback_pre > 0) { - void (*preHookFunc) (void); + bool retVal___ = false; + if (HPMHooks.count.HP_account_db_sql_create_pre > 0) { + bool (*preHookFunc) (AccountDB **self, struct mmo_account **acc); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_core_shutdown_callback_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_core_shutdown_callback_pre[hIndex].func; - preHookFunc(); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_create_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_account_db_sql_create_pre[hIndex].func; + retVal___ = preHookFunc(&self, &acc); } if (*HPMforce_return) { *HPMforce_return = false; - return; + return retVal___; } } { - HPMHooks.source.core.shutdown_callback(); + retVal___ = HPMHooks.source.account.db_sql_create(self, acc); } - if (HPMHooks.count.HP_core_shutdown_callback_post > 0) { - void (*postHookFunc) (void); - for (hIndex = 0; hIndex < HPMHooks.count.HP_core_shutdown_callback_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_core_shutdown_callback_post[hIndex].func; - postHookFunc(); + if (HPMHooks.count.HP_account_db_sql_create_post > 0) { + bool (*postHookFunc) (bool retVal___, AccountDB *self, struct mmo_account *acc); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_create_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_account_db_sql_create_post[hIndex].func; + retVal___ = postHookFunc(retVal___, self, acc); } } - return; + return retVal___; } -/* db_interface */ -enum DBOptions HP_DB_fix_options(enum DBType type, enum DBOptions options) { +bool HP_account_db_sql_remove(AccountDB *self, const int account_id) { int hIndex = 0; - enum DBOptions retVal___ = DB_OPT_BASE; - if (HPMHooks.count.HP_DB_fix_options_pre > 0) { - enum DBOptions (*preHookFunc) (enum DBType *type, enum DBOptions *options); + bool retVal___ = false; + if (HPMHooks.count.HP_account_db_sql_remove_pre > 0) { + bool (*preHookFunc) (AccountDB **self, const int *account_id); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_fix_options_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_DB_fix_options_pre[hIndex].func; - retVal___ = preHookFunc(&type, &options); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_remove_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_account_db_sql_remove_pre[hIndex].func; + retVal___ = preHookFunc(&self, &account_id); } if (*HPMforce_return) { *HPMforce_return = false; @@ -416,26 +417,26 @@ enum DBOptions HP_DB_fix_options(enum DBType type, enum DBOptions options) { } } { - retVal___ = HPMHooks.source.DB.fix_options(type, options); + retVal___ = HPMHooks.source.account.db_sql_remove(self, account_id); } - if (HPMHooks.count.HP_DB_fix_options_post > 0) { - enum DBOptions (*postHookFunc) (enum DBOptions retVal___, enum DBType type, enum DBOptions options); - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_fix_options_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_DB_fix_options_post[hIndex].func; - retVal___ = postHookFunc(retVal___, type, options); + if (HPMHooks.count.HP_account_db_sql_remove_post > 0) { + bool (*postHookFunc) (bool retVal___, AccountDB *self, const int account_id); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_remove_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_account_db_sql_remove_post[hIndex].func; + retVal___ = postHookFunc(retVal___, self, account_id); } } return retVal___; } -DBComparator HP_DB_default_cmp(enum DBType type) { +bool HP_account_db_sql_save(AccountDB *self, const struct mmo_account *acc) { int hIndex = 0; - DBComparator retVal___ = NULL; - if (HPMHooks.count.HP_DB_default_cmp_pre > 0) { - DBComparator (*preHookFunc) (enum DBType *type); + bool retVal___ = false; + if (HPMHooks.count.HP_account_db_sql_save_pre > 0) { + bool (*preHookFunc) (AccountDB **self, const struct mmo_account **acc); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_default_cmp_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_DB_default_cmp_pre[hIndex].func; - retVal___ = preHookFunc(&type); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_save_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_account_db_sql_save_pre[hIndex].func; + retVal___ = preHookFunc(&self, &acc); } if (*HPMforce_return) { *HPMforce_return = false; @@ -443,26 +444,26 @@ DBComparator HP_DB_default_cmp(enum DBType type) { } } { - retVal___ = HPMHooks.source.DB.default_cmp(type); + retVal___ = HPMHooks.source.account.db_sql_save(self, acc); } - if (HPMHooks.count.HP_DB_default_cmp_post > 0) { - DBComparator (*postHookFunc) (DBComparator retVal___, enum DBType type); - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_default_cmp_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_DB_default_cmp_post[hIndex].func; - retVal___ = postHookFunc(retVal___, type); + if (HPMHooks.count.HP_account_db_sql_save_post > 0) { + bool (*postHookFunc) (bool retVal___, AccountDB *self, const struct mmo_account *acc); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_save_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_account_db_sql_save_post[hIndex].func; + retVal___ = postHookFunc(retVal___, self, acc); } } return retVal___; } -DBHasher HP_DB_default_hash(enum DBType type) { +bool HP_account_db_sql_load_num(AccountDB *self, struct mmo_account *acc, const int account_id) { int hIndex = 0; - DBHasher retVal___ = NULL; - if (HPMHooks.count.HP_DB_default_hash_pre > 0) { - DBHasher (*preHookFunc) (enum DBType *type); + bool retVal___ = false; + if (HPMHooks.count.HP_account_db_sql_load_num_pre > 0) { + bool (*preHookFunc) (AccountDB **self, struct mmo_account **acc, const int *account_id); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_default_hash_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_DB_default_hash_pre[hIndex].func; - retVal___ = preHookFunc(&type); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_load_num_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_account_db_sql_load_num_pre[hIndex].func; + retVal___ = preHookFunc(&self, &acc, &account_id); } if (*HPMforce_return) { *HPMforce_return = false; @@ -470,26 +471,26 @@ DBHasher HP_DB_default_hash(enum DBType type) { } } { - retVal___ = HPMHooks.source.DB.default_hash(type); + retVal___ = HPMHooks.source.account.db_sql_load_num(self, acc, account_id); } - if (HPMHooks.count.HP_DB_default_hash_post > 0) { - DBHasher (*postHookFunc) (DBHasher retVal___, enum DBType type); - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_default_hash_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_DB_default_hash_post[hIndex].func; - retVal___ = postHookFunc(retVal___, type); + if (HPMHooks.count.HP_account_db_sql_load_num_post > 0) { + bool (*postHookFunc) (bool retVal___, AccountDB *self, struct mmo_account *acc, const int account_id); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_load_num_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_account_db_sql_load_num_post[hIndex].func; + retVal___ = postHookFunc(retVal___, self, acc, account_id); } } return retVal___; } -DBReleaser HP_DB_default_release(enum DBType type, enum DBOptions options) { +bool HP_account_db_sql_load_str(AccountDB *self, struct mmo_account *acc, const char *userid) { int hIndex = 0; - DBReleaser retVal___ = NULL; - if (HPMHooks.count.HP_DB_default_release_pre > 0) { - DBReleaser (*preHookFunc) (enum DBType *type, enum DBOptions *options); + bool retVal___ = false; + if (HPMHooks.count.HP_account_db_sql_load_str_pre > 0) { + bool (*preHookFunc) (AccountDB **self, struct mmo_account **acc, const char **userid); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_default_release_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_DB_default_release_pre[hIndex].func; - retVal___ = preHookFunc(&type, &options); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_load_str_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_account_db_sql_load_str_pre[hIndex].func; + retVal___ = preHookFunc(&self, &acc, &userid); } if (*HPMforce_return) { *HPMforce_return = false; @@ -497,26 +498,26 @@ DBReleaser HP_DB_default_release(enum DBType type, enum DBOptions options) { } } { - retVal___ = HPMHooks.source.DB.default_release(type, options); + retVal___ = HPMHooks.source.account.db_sql_load_str(self, acc, userid); } - if (HPMHooks.count.HP_DB_default_release_post > 0) { - DBReleaser (*postHookFunc) (DBReleaser retVal___, enum DBType type, enum DBOptions options); - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_default_release_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_DB_default_release_post[hIndex].func; - retVal___ = postHookFunc(retVal___, type, options); + if (HPMHooks.count.HP_account_db_sql_load_str_post > 0) { + bool (*postHookFunc) (bool retVal___, AccountDB *self, struct mmo_account *acc, const char *userid); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_load_str_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_account_db_sql_load_str_post[hIndex].func; + retVal___ = postHookFunc(retVal___, self, acc, userid); } } return retVal___; } -DBReleaser HP_DB_custom_release(enum DBReleaseOption which) { +AccountDBIterator* HP_account_db_sql_iterator(AccountDB *self) { int hIndex = 0; - DBReleaser retVal___ = NULL; - if (HPMHooks.count.HP_DB_custom_release_pre > 0) { - DBReleaser (*preHookFunc) (enum DBReleaseOption *which); + AccountDBIterator* retVal___ = NULL; + if (HPMHooks.count.HP_account_db_sql_iterator_pre > 0) { + AccountDBIterator* (*preHookFunc) (AccountDB **self); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_custom_release_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_DB_custom_release_pre[hIndex].func; - retVal___ = preHookFunc(&which); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_iterator_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_account_db_sql_iterator_pre[hIndex].func; + retVal___ = preHookFunc(&self); } if (*HPMforce_return) { *HPMforce_return = false; @@ -524,53 +525,52 @@ DBReleaser HP_DB_custom_release(enum DBReleaseOption which) { } } { - retVal___ = HPMHooks.source.DB.custom_release(which); + retVal___ = HPMHooks.source.account.db_sql_iterator(self); } - if (HPMHooks.count.HP_DB_custom_release_post > 0) { - DBReleaser (*postHookFunc) (DBReleaser retVal___, enum DBReleaseOption which); - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_custom_release_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_DB_custom_release_post[hIndex].func; - retVal___ = postHookFunc(retVal___, which); + if (HPMHooks.count.HP_account_db_sql_iterator_post > 0) { + AccountDBIterator* (*postHookFunc) (AccountDBIterator* retVal___, AccountDB *self); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_iterator_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_account_db_sql_iterator_post[hIndex].func; + retVal___ = postHookFunc(retVal___, self); } } return retVal___; } -struct DBMap* HP_DB_alloc(const char *file, const char *func, int line, enum DBType type, enum DBOptions options, unsigned short maxlen) { +void HP_account_db_sql_iter_destroy(AccountDBIterator *self) { int hIndex = 0; - struct DBMap* retVal___ = NULL; - if (HPMHooks.count.HP_DB_alloc_pre > 0) { - struct DBMap* (*preHookFunc) (const char **file, const char **func, int *line, enum DBType *type, enum DBOptions *options, unsigned short *maxlen); + if (HPMHooks.count.HP_account_db_sql_iter_destroy_pre > 0) { + void (*preHookFunc) (AccountDBIterator **self); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_alloc_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_DB_alloc_pre[hIndex].func; - retVal___ = preHookFunc(&file, &func, &line, &type, &options, &maxlen); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_iter_destroy_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_account_db_sql_iter_destroy_pre[hIndex].func; + preHookFunc(&self); } if (*HPMforce_return) { *HPMforce_return = false; - return retVal___; + return; } } { - retVal___ = HPMHooks.source.DB.alloc(file, func, line, type, options, maxlen); + HPMHooks.source.account.db_sql_iter_destroy(self); } - if (HPMHooks.count.HP_DB_alloc_post > 0) { - struct DBMap* (*postHookFunc) (struct DBMap* retVal___, const char *file, const char *func, int line, enum DBType type, enum DBOptions options, unsigned short maxlen); - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_alloc_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_DB_alloc_post[hIndex].func; - retVal___ = postHookFunc(retVal___, file, func, line, type, options, maxlen); + if (HPMHooks.count.HP_account_db_sql_iter_destroy_post > 0) { + void (*postHookFunc) (AccountDBIterator *self); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_iter_destroy_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_account_db_sql_iter_destroy_post[hIndex].func; + postHookFunc(self); } } - return retVal___; + return; } -union DBKey HP_DB_i2key(int key) { +bool HP_account_db_sql_iter_next(AccountDBIterator *self, struct mmo_account *acc) { int hIndex = 0; - union DBKey retVal___ = { 0 }; - if (HPMHooks.count.HP_DB_i2key_pre > 0) { - union DBKey (*preHookFunc) (int *key); + bool retVal___ = false; + if (HPMHooks.count.HP_account_db_sql_iter_next_pre > 0) { + bool (*preHookFunc) (AccountDBIterator **self, struct mmo_account **acc); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_i2key_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_DB_i2key_pre[hIndex].func; - retVal___ = preHookFunc(&key); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_iter_next_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_account_db_sql_iter_next_pre[hIndex].func; + retVal___ = preHookFunc(&self, &acc); } if (*HPMforce_return) { *HPMforce_return = false; @@ -578,26 +578,26 @@ union DBKey HP_DB_i2key(int key) { } } { - retVal___ = HPMHooks.source.DB.i2key(key); + retVal___ = HPMHooks.source.account.db_sql_iter_next(self, acc); } - if (HPMHooks.count.HP_DB_i2key_post > 0) { - union DBKey (*postHookFunc) (union DBKey retVal___, int key); - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_i2key_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_DB_i2key_post[hIndex].func; - retVal___ = postHookFunc(retVal___, key); + if (HPMHooks.count.HP_account_db_sql_iter_next_post > 0) { + bool (*postHookFunc) (bool retVal___, AccountDBIterator *self, struct mmo_account *acc); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_sql_iter_next_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_account_db_sql_iter_next_post[hIndex].func; + retVal___ = postHookFunc(retVal___, self, acc); } } return retVal___; } -union DBKey HP_DB_ui2key(unsigned int key) { +bool HP_account_db_read_inter(AccountDB_SQL *db, const char *filename, bool imported) { int hIndex = 0; - union DBKey retVal___ = { 0 }; - if (HPMHooks.count.HP_DB_ui2key_pre > 0) { - union DBKey (*preHookFunc) (unsigned int *key); + bool retVal___ = false; + if (HPMHooks.count.HP_account_db_read_inter_pre > 0) { + bool (*preHookFunc) (AccountDB_SQL **db, const char **filename, bool *imported); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_ui2key_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_DB_ui2key_pre[hIndex].func; - retVal___ = preHookFunc(&key); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_read_inter_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_account_db_read_inter_pre[hIndex].func; + retVal___ = preHookFunc(&db, &filename, &imported); } if (*HPMforce_return) { *HPMforce_return = false; @@ -605,26 +605,79 @@ union DBKey HP_DB_ui2key(unsigned int key) { } } { - retVal___ = HPMHooks.source.DB.ui2key(key); + retVal___ = HPMHooks.source.account.db_read_inter(db, filename, imported); } - if (HPMHooks.count.HP_DB_ui2key_post > 0) { - union DBKey (*postHookFunc) (union DBKey retVal___, unsigned int key); - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_ui2key_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_DB_ui2key_post[hIndex].func; - retVal___ = postHookFunc(retVal___, key); + if (HPMHooks.count.HP_account_db_read_inter_post > 0) { + bool (*postHookFunc) (bool retVal___, AccountDB_SQL *db, const char *filename, bool imported); + for (hIndex = 0; hIndex < HPMHooks.count.HP_account_db_read_inter_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_account_db_read_inter_post[hIndex].func; + retVal___ = postHookFunc(retVal___, db, filename, imported); } } return retVal___; } -union DBKey HP_DB_str2key(const char *key) { +/* cmdline_interface */ +void HP_cmdline_init(void) { int hIndex = 0; - union DBKey retVal___ = { 0 }; - if (HPMHooks.count.HP_DB_str2key_pre > 0) { - union DBKey (*preHookFunc) (const char **key); + if (HPMHooks.count.HP_cmdline_init_pre > 0) { + void (*preHookFunc) (void); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_str2key_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_DB_str2key_pre[hIndex].func; - retVal___ = preHookFunc(&key); + for (hIndex = 0; hIndex < HPMHooks.count.HP_cmdline_init_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_cmdline_init_pre[hIndex].func; + preHookFunc(); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.cmdline.init(); + } + if (HPMHooks.count.HP_cmdline_init_post > 0) { + void (*postHookFunc) (void); + for (hIndex = 0; hIndex < HPMHooks.count.HP_cmdline_init_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_cmdline_init_post[hIndex].func; + postHookFunc(); + } + } + return; +} +void HP_cmdline_final(void) { + int hIndex = 0; + if (HPMHooks.count.HP_cmdline_final_pre > 0) { + void (*preHookFunc) (void); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_cmdline_final_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_cmdline_final_pre[hIndex].func; + preHookFunc(); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.cmdline.final(); + } + if (HPMHooks.count.HP_cmdline_final_post > 0) { + void (*postHookFunc) (void); + for (hIndex = 0; hIndex < HPMHooks.count.HP_cmdline_final_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_cmdline_final_post[hIndex].func; + postHookFunc(); + } + } + return; +} +bool HP_cmdline_arg_add(unsigned int pluginID, const char *name, char shortname, CmdlineExecFunc func, const char *help, unsigned int options) { + int hIndex = 0; + bool retVal___ = false; + if (HPMHooks.count.HP_cmdline_arg_add_pre > 0) { + bool (*preHookFunc) (unsigned int *pluginID, const char **name, char *shortname, CmdlineExecFunc *func, const char **help, unsigned int *options); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_cmdline_arg_add_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_cmdline_arg_add_pre[hIndex].func; + retVal___ = preHookFunc(&pluginID, &name, &shortname, &func, &help, &options); } if (*HPMforce_return) { *HPMforce_return = false; @@ -632,26 +685,26 @@ union DBKey HP_DB_str2key(const char *key) { } } { - retVal___ = HPMHooks.source.DB.str2key(key); + retVal___ = HPMHooks.source.cmdline.arg_add(pluginID, name, shortname, func, help, options); } - if (HPMHooks.count.HP_DB_str2key_post > 0) { - union DBKey (*postHookFunc) (union DBKey retVal___, const char *key); - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_str2key_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_DB_str2key_post[hIndex].func; - retVal___ = postHookFunc(retVal___, key); + if (HPMHooks.count.HP_cmdline_arg_add_post > 0) { + bool (*postHookFunc) (bool retVal___, unsigned int pluginID, const char *name, char shortname, CmdlineExecFunc func, const char *help, unsigned int options); + for (hIndex = 0; hIndex < HPMHooks.count.HP_cmdline_arg_add_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_cmdline_arg_add_post[hIndex].func; + retVal___ = postHookFunc(retVal___, pluginID, name, shortname, func, help, options); } } return retVal___; } -union DBKey HP_DB_i642key(int64 key) { +int HP_cmdline_exec(int argc, char **argv, unsigned int options) { int hIndex = 0; - union DBKey retVal___ = { 0 }; - if (HPMHooks.count.HP_DB_i642key_pre > 0) { - union DBKey (*preHookFunc) (int64 *key); + int retVal___ = 0; + if (HPMHooks.count.HP_cmdline_exec_pre > 0) { + int (*preHookFunc) (int *argc, char ***argv, unsigned int *options); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_i642key_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_DB_i642key_pre[hIndex].func; - retVal___ = preHookFunc(&key); + for (hIndex = 0; hIndex < HPMHooks.count.HP_cmdline_exec_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_cmdline_exec_pre[hIndex].func; + retVal___ = preHookFunc(&argc, &argv, &options); } if (*HPMforce_return) { *HPMforce_return = false; @@ -659,26 +712,26 @@ union DBKey HP_DB_i642key(int64 key) { } } { - retVal___ = HPMHooks.source.DB.i642key(key); + retVal___ = HPMHooks.source.cmdline.exec(argc, argv, options); } - if (HPMHooks.count.HP_DB_i642key_post > 0) { - union DBKey (*postHookFunc) (union DBKey retVal___, int64 key); - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_i642key_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_DB_i642key_post[hIndex].func; - retVal___ = postHookFunc(retVal___, key); + if (HPMHooks.count.HP_cmdline_exec_post > 0) { + int (*postHookFunc) (int retVal___, int argc, char **argv, unsigned int options); + for (hIndex = 0; hIndex < HPMHooks.count.HP_cmdline_exec_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_cmdline_exec_post[hIndex].func; + retVal___ = postHookFunc(retVal___, argc, argv, options); } } return retVal___; } -union DBKey HP_DB_ui642key(uint64 key) { +bool HP_cmdline_arg_next_value(const char *name, int current_arg, int argc) { int hIndex = 0; - union DBKey retVal___ = { 0 }; - if (HPMHooks.count.HP_DB_ui642key_pre > 0) { - union DBKey (*preHookFunc) (uint64 *key); + bool retVal___ = false; + if (HPMHooks.count.HP_cmdline_arg_next_value_pre > 0) { + bool (*preHookFunc) (const char **name, int *current_arg, int *argc); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_ui642key_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_DB_ui642key_pre[hIndex].func; - retVal___ = preHookFunc(&key); + for (hIndex = 0; hIndex < HPMHooks.count.HP_cmdline_arg_next_value_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_cmdline_arg_next_value_pre[hIndex].func; + retVal___ = preHookFunc(&name, ¤t_arg, &argc); } if (*HPMforce_return) { *HPMforce_return = false; @@ -686,26 +739,26 @@ union DBKey HP_DB_ui642key(uint64 key) { } } { - retVal___ = HPMHooks.source.DB.ui642key(key); + retVal___ = HPMHooks.source.cmdline.arg_next_value(name, current_arg, argc); } - if (HPMHooks.count.HP_DB_ui642key_post > 0) { - union DBKey (*postHookFunc) (union DBKey retVal___, uint64 key); - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_ui642key_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_DB_ui642key_post[hIndex].func; - retVal___ = postHookFunc(retVal___, key); + if (HPMHooks.count.HP_cmdline_arg_next_value_post > 0) { + bool (*postHookFunc) (bool retVal___, const char *name, int current_arg, int argc); + for (hIndex = 0; hIndex < HPMHooks.count.HP_cmdline_arg_next_value_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_cmdline_arg_next_value_post[hIndex].func; + retVal___ = postHookFunc(retVal___, name, current_arg, argc); } } return retVal___; } -struct DBData HP_DB_i2data(int data) { +const char* HP_cmdline_arg_source(struct CmdlineArgData *arg) { int hIndex = 0; - struct DBData retVal___ = { 0 }; - if (HPMHooks.count.HP_DB_i2data_pre > 0) { - struct DBData (*preHookFunc) (int *data); + const char* retVal___ = NULL; + if (HPMHooks.count.HP_cmdline_arg_source_pre > 0) { + const char* (*preHookFunc) (struct CmdlineArgData **arg); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_i2data_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_DB_i2data_pre[hIndex].func; - retVal___ = preHookFunc(&data); + for (hIndex = 0; hIndex < HPMHooks.count.HP_cmdline_arg_source_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_cmdline_arg_source_pre[hIndex].func; + retVal___ = preHookFunc(&arg); } if (*HPMforce_return) { *HPMforce_return = false; @@ -713,26 +766,830 @@ struct DBData HP_DB_i2data(int data) { } } { - retVal___ = HPMHooks.source.DB.i2data(data); + retVal___ = HPMHooks.source.cmdline.arg_source(arg); } - if (HPMHooks.count.HP_DB_i2data_post > 0) { - struct DBData (*postHookFunc) (struct DBData retVal___, int data); - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_i2data_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_DB_i2data_post[hIndex].func; - retVal___ = postHookFunc(retVal___, data); + if (HPMHooks.count.HP_cmdline_arg_source_post > 0) { + const char* (*postHookFunc) (const char* retVal___, struct CmdlineArgData *arg); + for (hIndex = 0; hIndex < HPMHooks.count.HP_cmdline_arg_source_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_cmdline_arg_source_post[hIndex].func; + retVal___ = postHookFunc(retVal___, arg); } } return retVal___; } -struct DBData HP_DB_ui2data(unsigned int data) { +/* console_interface */ +void HP_console_init(void) { int hIndex = 0; - struct DBData retVal___ = { 0 }; - if (HPMHooks.count.HP_DB_ui2data_pre > 0) { - struct DBData (*preHookFunc) (unsigned int *data); + if (HPMHooks.count.HP_console_init_pre > 0) { + void (*preHookFunc) (void); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_console_init_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_console_init_pre[hIndex].func; + preHookFunc(); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.console.init(); + } + if (HPMHooks.count.HP_console_init_post > 0) { + void (*postHookFunc) (void); + for (hIndex = 0; hIndex < HPMHooks.count.HP_console_init_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_console_init_post[hIndex].func; + postHookFunc(); + } + } + return; +} +void HP_console_final(void) { + int hIndex = 0; + if (HPMHooks.count.HP_console_final_pre > 0) { + void (*preHookFunc) (void); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_console_final_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_console_final_pre[hIndex].func; + preHookFunc(); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.console.final(); + } + if (HPMHooks.count.HP_console_final_post > 0) { + void (*postHookFunc) (void); + for (hIndex = 0; hIndex < HPMHooks.count.HP_console_final_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_console_final_post[hIndex].func; + postHookFunc(); + } + } + return; +} +void HP_console_display_title(void) { + int hIndex = 0; + if (HPMHooks.count.HP_console_display_title_pre > 0) { + void (*preHookFunc) (void); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_console_display_title_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_console_display_title_pre[hIndex].func; + preHookFunc(); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.console.display_title(); + } + if (HPMHooks.count.HP_console_display_title_post > 0) { + void (*postHookFunc) (void); + for (hIndex = 0; hIndex < HPMHooks.count.HP_console_display_title_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_console_display_title_post[hIndex].func; + postHookFunc(); + } + } + return; +} +void HP_console_display_gplnotice(void) { + int hIndex = 0; + if (HPMHooks.count.HP_console_display_gplnotice_pre > 0) { + void (*preHookFunc) (void); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_console_display_gplnotice_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_console_display_gplnotice_pre[hIndex].func; + preHookFunc(); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.console.display_gplnotice(); + } + if (HPMHooks.count.HP_console_display_gplnotice_post > 0) { + void (*postHookFunc) (void); + for (hIndex = 0; hIndex < HPMHooks.count.HP_console_display_gplnotice_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_console_display_gplnotice_post[hIndex].func; + postHookFunc(); + } + } + return; +} +/* core_interface */ +void HP_core_shutdown_callback(void) { + int hIndex = 0; + if (HPMHooks.count.HP_core_shutdown_callback_pre > 0) { + void (*preHookFunc) (void); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_core_shutdown_callback_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_core_shutdown_callback_pre[hIndex].func; + preHookFunc(); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.core.shutdown_callback(); + } + if (HPMHooks.count.HP_core_shutdown_callback_post > 0) { + void (*postHookFunc) (void); + for (hIndex = 0; hIndex < HPMHooks.count.HP_core_shutdown_callback_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_core_shutdown_callback_post[hIndex].func; + postHookFunc(); + } + } + return; +} +/* db_interface */ +enum DBOptions HP_DB_fix_options(enum DBType type, enum DBOptions options) { + int hIndex = 0; + enum DBOptions retVal___ = DB_OPT_BASE; + if (HPMHooks.count.HP_DB_fix_options_pre > 0) { + enum DBOptions (*preHookFunc) (enum DBType *type, enum DBOptions *options); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_fix_options_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_DB_fix_options_pre[hIndex].func; + retVal___ = preHookFunc(&type, &options); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.DB.fix_options(type, options); + } + if (HPMHooks.count.HP_DB_fix_options_post > 0) { + enum DBOptions (*postHookFunc) (enum DBOptions retVal___, enum DBType type, enum DBOptions options); + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_fix_options_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_DB_fix_options_post[hIndex].func; + retVal___ = postHookFunc(retVal___, type, options); + } + } + return retVal___; +} +DBComparator HP_DB_default_cmp(enum DBType type) { + int hIndex = 0; + DBComparator retVal___ = NULL; + if (HPMHooks.count.HP_DB_default_cmp_pre > 0) { + DBComparator (*preHookFunc) (enum DBType *type); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_default_cmp_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_DB_default_cmp_pre[hIndex].func; + retVal___ = preHookFunc(&type); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.DB.default_cmp(type); + } + if (HPMHooks.count.HP_DB_default_cmp_post > 0) { + DBComparator (*postHookFunc) (DBComparator retVal___, enum DBType type); + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_default_cmp_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_DB_default_cmp_post[hIndex].func; + retVal___ = postHookFunc(retVal___, type); + } + } + return retVal___; +} +DBHasher HP_DB_default_hash(enum DBType type) { + int hIndex = 0; + DBHasher retVal___ = NULL; + if (HPMHooks.count.HP_DB_default_hash_pre > 0) { + DBHasher (*preHookFunc) (enum DBType *type); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_default_hash_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_DB_default_hash_pre[hIndex].func; + retVal___ = preHookFunc(&type); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.DB.default_hash(type); + } + if (HPMHooks.count.HP_DB_default_hash_post > 0) { + DBHasher (*postHookFunc) (DBHasher retVal___, enum DBType type); + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_default_hash_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_DB_default_hash_post[hIndex].func; + retVal___ = postHookFunc(retVal___, type); + } + } + return retVal___; +} +DBReleaser HP_DB_default_release(enum DBType type, enum DBOptions options) { + int hIndex = 0; + DBReleaser retVal___ = NULL; + if (HPMHooks.count.HP_DB_default_release_pre > 0) { + DBReleaser (*preHookFunc) (enum DBType *type, enum DBOptions *options); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_default_release_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_DB_default_release_pre[hIndex].func; + retVal___ = preHookFunc(&type, &options); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.DB.default_release(type, options); + } + if (HPMHooks.count.HP_DB_default_release_post > 0) { + DBReleaser (*postHookFunc) (DBReleaser retVal___, enum DBType type, enum DBOptions options); + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_default_release_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_DB_default_release_post[hIndex].func; + retVal___ = postHookFunc(retVal___, type, options); + } + } + return retVal___; +} +DBReleaser HP_DB_custom_release(enum DBReleaseOption which) { + int hIndex = 0; + DBReleaser retVal___ = NULL; + if (HPMHooks.count.HP_DB_custom_release_pre > 0) { + DBReleaser (*preHookFunc) (enum DBReleaseOption *which); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_custom_release_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_DB_custom_release_pre[hIndex].func; + retVal___ = preHookFunc(&which); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.DB.custom_release(which); + } + if (HPMHooks.count.HP_DB_custom_release_post > 0) { + DBReleaser (*postHookFunc) (DBReleaser retVal___, enum DBReleaseOption which); + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_custom_release_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_DB_custom_release_post[hIndex].func; + retVal___ = postHookFunc(retVal___, which); + } + } + return retVal___; +} +struct DBMap* HP_DB_alloc(const char *file, const char *func, int line, enum DBType type, enum DBOptions options, unsigned short maxlen) { + int hIndex = 0; + struct DBMap* retVal___ = NULL; + if (HPMHooks.count.HP_DB_alloc_pre > 0) { + struct DBMap* (*preHookFunc) (const char **file, const char **func, int *line, enum DBType *type, enum DBOptions *options, unsigned short *maxlen); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_alloc_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_DB_alloc_pre[hIndex].func; + retVal___ = preHookFunc(&file, &func, &line, &type, &options, &maxlen); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.DB.alloc(file, func, line, type, options, maxlen); + } + if (HPMHooks.count.HP_DB_alloc_post > 0) { + struct DBMap* (*postHookFunc) (struct DBMap* retVal___, const char *file, const char *func, int line, enum DBType type, enum DBOptions options, unsigned short maxlen); + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_alloc_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_DB_alloc_post[hIndex].func; + retVal___ = postHookFunc(retVal___, file, func, line, type, options, maxlen); + } + } + return retVal___; +} +union DBKey HP_DB_i2key(int key) { + int hIndex = 0; + union DBKey retVal___ = { 0 }; + if (HPMHooks.count.HP_DB_i2key_pre > 0) { + union DBKey (*preHookFunc) (int *key); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_i2key_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_DB_i2key_pre[hIndex].func; + retVal___ = preHookFunc(&key); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.DB.i2key(key); + } + if (HPMHooks.count.HP_DB_i2key_post > 0) { + union DBKey (*postHookFunc) (union DBKey retVal___, int key); + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_i2key_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_DB_i2key_post[hIndex].func; + retVal___ = postHookFunc(retVal___, key); + } + } + return retVal___; +} +union DBKey HP_DB_ui2key(unsigned int key) { + int hIndex = 0; + union DBKey retVal___ = { 0 }; + if (HPMHooks.count.HP_DB_ui2key_pre > 0) { + union DBKey (*preHookFunc) (unsigned int *key); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_ui2key_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_DB_ui2key_pre[hIndex].func; + retVal___ = preHookFunc(&key); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.DB.ui2key(key); + } + if (HPMHooks.count.HP_DB_ui2key_post > 0) { + union DBKey (*postHookFunc) (union DBKey retVal___, unsigned int key); + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_ui2key_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_DB_ui2key_post[hIndex].func; + retVal___ = postHookFunc(retVal___, key); + } + } + return retVal___; +} +union DBKey HP_DB_str2key(const char *key) { + int hIndex = 0; + union DBKey retVal___ = { 0 }; + if (HPMHooks.count.HP_DB_str2key_pre > 0) { + union DBKey (*preHookFunc) (const char **key); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_str2key_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_DB_str2key_pre[hIndex].func; + retVal___ = preHookFunc(&key); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.DB.str2key(key); + } + if (HPMHooks.count.HP_DB_str2key_post > 0) { + union DBKey (*postHookFunc) (union DBKey retVal___, const char *key); + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_str2key_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_DB_str2key_post[hIndex].func; + retVal___ = postHookFunc(retVal___, key); + } + } + return retVal___; +} +union DBKey HP_DB_i642key(int64 key) { + int hIndex = 0; + union DBKey retVal___ = { 0 }; + if (HPMHooks.count.HP_DB_i642key_pre > 0) { + union DBKey (*preHookFunc) (int64 *key); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_i642key_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_DB_i642key_pre[hIndex].func; + retVal___ = preHookFunc(&key); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.DB.i642key(key); + } + if (HPMHooks.count.HP_DB_i642key_post > 0) { + union DBKey (*postHookFunc) (union DBKey retVal___, int64 key); + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_i642key_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_DB_i642key_post[hIndex].func; + retVal___ = postHookFunc(retVal___, key); + } + } + return retVal___; +} +union DBKey HP_DB_ui642key(uint64 key) { + int hIndex = 0; + union DBKey retVal___ = { 0 }; + if (HPMHooks.count.HP_DB_ui642key_pre > 0) { + union DBKey (*preHookFunc) (uint64 *key); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_ui642key_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_DB_ui642key_pre[hIndex].func; + retVal___ = preHookFunc(&key); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.DB.ui642key(key); + } + if (HPMHooks.count.HP_DB_ui642key_post > 0) { + union DBKey (*postHookFunc) (union DBKey retVal___, uint64 key); + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_ui642key_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_DB_ui642key_post[hIndex].func; + retVal___ = postHookFunc(retVal___, key); + } + } + return retVal___; +} +struct DBData HP_DB_i2data(int data) { + int hIndex = 0; + struct DBData retVal___ = { 0 }; + if (HPMHooks.count.HP_DB_i2data_pre > 0) { + struct DBData (*preHookFunc) (int *data); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_i2data_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_DB_i2data_pre[hIndex].func; + retVal___ = preHookFunc(&data); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.DB.i2data(data); + } + if (HPMHooks.count.HP_DB_i2data_post > 0) { + struct DBData (*postHookFunc) (struct DBData retVal___, int data); + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_i2data_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_DB_i2data_post[hIndex].func; + retVal___ = postHookFunc(retVal___, data); + } + } + return retVal___; +} +struct DBData HP_DB_ui2data(unsigned int data) { + int hIndex = 0; + struct DBData retVal___ = { 0 }; + if (HPMHooks.count.HP_DB_ui2data_pre > 0) { + struct DBData (*preHookFunc) (unsigned int *data); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_ui2data_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_DB_ui2data_pre[hIndex].func; + retVal___ = preHookFunc(&data); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.DB.ui2data(data); + } + if (HPMHooks.count.HP_DB_ui2data_post > 0) { + struct DBData (*postHookFunc) (struct DBData retVal___, unsigned int data); + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_ui2data_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_DB_ui2data_post[hIndex].func; + retVal___ = postHookFunc(retVal___, data); + } + } + return retVal___; +} +struct DBData HP_DB_ptr2data(void *data) { + int hIndex = 0; + struct DBData retVal___ = { 0 }; + if (HPMHooks.count.HP_DB_ptr2data_pre > 0) { + struct DBData (*preHookFunc) (void **data); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_ptr2data_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_DB_ptr2data_pre[hIndex].func; + retVal___ = preHookFunc(&data); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.DB.ptr2data(data); + } + if (HPMHooks.count.HP_DB_ptr2data_post > 0) { + struct DBData (*postHookFunc) (struct DBData retVal___, void *data); + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_ptr2data_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_DB_ptr2data_post[hIndex].func; + retVal___ = postHookFunc(retVal___, data); + } + } + return retVal___; +} +int HP_DB_data2i(struct DBData *data) { + int hIndex = 0; + int retVal___ = 0; + if (HPMHooks.count.HP_DB_data2i_pre > 0) { + int (*preHookFunc) (struct DBData **data); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_data2i_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_DB_data2i_pre[hIndex].func; + retVal___ = preHookFunc(&data); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.DB.data2i(data); + } + if (HPMHooks.count.HP_DB_data2i_post > 0) { + int (*postHookFunc) (int retVal___, struct DBData *data); + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_data2i_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_DB_data2i_post[hIndex].func; + retVal___ = postHookFunc(retVal___, data); + } + } + return retVal___; +} +unsigned int HP_DB_data2ui(struct DBData *data) { + int hIndex = 0; + unsigned int retVal___ = 0; + if (HPMHooks.count.HP_DB_data2ui_pre > 0) { + unsigned int (*preHookFunc) (struct DBData **data); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_data2ui_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_DB_data2ui_pre[hIndex].func; + retVal___ = preHookFunc(&data); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.DB.data2ui(data); + } + if (HPMHooks.count.HP_DB_data2ui_post > 0) { + unsigned int (*postHookFunc) (unsigned int retVal___, struct DBData *data); + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_data2ui_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_DB_data2ui_post[hIndex].func; + retVal___ = postHookFunc(retVal___, data); + } + } + return retVal___; +} +void* HP_DB_data2ptr(struct DBData *data) { + int hIndex = 0; + void* retVal___ = NULL; + if (HPMHooks.count.HP_DB_data2ptr_pre > 0) { + void* (*preHookFunc) (struct DBData **data); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_data2ptr_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_DB_data2ptr_pre[hIndex].func; + retVal___ = preHookFunc(&data); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.DB.data2ptr(data); + } + if (HPMHooks.count.HP_DB_data2ptr_post > 0) { + void* (*postHookFunc) (void* retVal___, struct DBData *data); + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_data2ptr_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_DB_data2ptr_post[hIndex].func; + retVal___ = postHookFunc(retVal___, data); + } + } + return retVal___; +} +void HP_DB_init(void) { + int hIndex = 0; + if (HPMHooks.count.HP_DB_init_pre > 0) { + void (*preHookFunc) (void); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_init_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_DB_init_pre[hIndex].func; + preHookFunc(); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.DB.init(); + } + if (HPMHooks.count.HP_DB_init_post > 0) { + void (*postHookFunc) (void); + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_init_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_DB_init_post[hIndex].func; + postHookFunc(); + } + } + return; +} +void HP_DB_final(void) { + int hIndex = 0; + if (HPMHooks.count.HP_DB_final_pre > 0) { + void (*preHookFunc) (void); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_final_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_DB_final_pre[hIndex].func; + preHookFunc(); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.DB.final(); + } + if (HPMHooks.count.HP_DB_final_post > 0) { + void (*postHookFunc) (void); + for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_final_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_DB_final_post[hIndex].func; + postHookFunc(); + } + } + return; +} +/* des_interface */ +void HP_des_decrypt_block(struct des_bit64 *block) { + int hIndex = 0; + if (HPMHooks.count.HP_des_decrypt_block_pre > 0) { + void (*preHookFunc) (struct des_bit64 **block); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_des_decrypt_block_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_des_decrypt_block_pre[hIndex].func; + preHookFunc(&block); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.des.decrypt_block(block); + } + if (HPMHooks.count.HP_des_decrypt_block_post > 0) { + void (*postHookFunc) (struct des_bit64 *block); + for (hIndex = 0; hIndex < HPMHooks.count.HP_des_decrypt_block_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_des_decrypt_block_post[hIndex].func; + postHookFunc(block); + } + } + return; +} +void HP_des_decrypt(unsigned char *data, size_t size) { + int hIndex = 0; + if (HPMHooks.count.HP_des_decrypt_pre > 0) { + void (*preHookFunc) (unsigned char **data, size_t *size); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_des_decrypt_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_des_decrypt_pre[hIndex].func; + preHookFunc(&data, &size); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.des.decrypt(data, size); + } + if (HPMHooks.count.HP_des_decrypt_post > 0) { + void (*postHookFunc) (unsigned char *data, size_t size); + for (hIndex = 0; hIndex < HPMHooks.count.HP_des_decrypt_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_des_decrypt_post[hIndex].func; + postHookFunc(data, size); + } + } + return; +} +/* ipban_interface */ +void HP_ipban_init(void) { + int hIndex = 0; + if (HPMHooks.count.HP_ipban_init_pre > 0) { + void (*preHookFunc) (void); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_ipban_init_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_ipban_init_pre[hIndex].func; + preHookFunc(); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.ipban.init(); + } + if (HPMHooks.count.HP_ipban_init_post > 0) { + void (*postHookFunc) (void); + for (hIndex = 0; hIndex < HPMHooks.count.HP_ipban_init_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_ipban_init_post[hIndex].func; + postHookFunc(); + } + } + return; +} +void HP_ipban_final(void) { + int hIndex = 0; + if (HPMHooks.count.HP_ipban_final_pre > 0) { + void (*preHookFunc) (void); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_ipban_final_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_ipban_final_pre[hIndex].func; + preHookFunc(); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.ipban.final(); + } + if (HPMHooks.count.HP_ipban_final_post > 0) { + void (*postHookFunc) (void); + for (hIndex = 0; hIndex < HPMHooks.count.HP_ipban_final_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_ipban_final_post[hIndex].func; + postHookFunc(); + } + } + return; +} +int HP_ipban_cleanup(int tid, int64 tick, int id, intptr_t data) { + int hIndex = 0; + int retVal___ = 0; + if (HPMHooks.count.HP_ipban_cleanup_pre > 0) { + int (*preHookFunc) (int *tid, int64 *tick, int *id, intptr_t *data); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_ipban_cleanup_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_ipban_cleanup_pre[hIndex].func; + retVal___ = preHookFunc(&tid, &tick, &id, &data); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.ipban.cleanup(tid, tick, id, data); + } + if (HPMHooks.count.HP_ipban_cleanup_post > 0) { + int (*postHookFunc) (int retVal___, int tid, int64 tick, int id, intptr_t data); + for (hIndex = 0; hIndex < HPMHooks.count.HP_ipban_cleanup_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_ipban_cleanup_post[hIndex].func; + retVal___ = postHookFunc(retVal___, tid, tick, id, data); + } + } + return retVal___; +} +bool HP_ipban_config_read_inter(const char *filename, bool imported) { + int hIndex = 0; + bool retVal___ = false; + if (HPMHooks.count.HP_ipban_config_read_inter_pre > 0) { + bool (*preHookFunc) (const char **filename, bool *imported); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_ipban_config_read_inter_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_ipban_config_read_inter_pre[hIndex].func; + retVal___ = preHookFunc(&filename, &imported); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.ipban.config_read_inter(filename, imported); + } + if (HPMHooks.count.HP_ipban_config_read_inter_post > 0) { + bool (*postHookFunc) (bool retVal___, const char *filename, bool imported); + for (hIndex = 0; hIndex < HPMHooks.count.HP_ipban_config_read_inter_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_ipban_config_read_inter_post[hIndex].func; + retVal___ = postHookFunc(retVal___, filename, imported); + } + } + return retVal___; +} +bool HP_ipban_config_read_connection(const char *filename, struct config_t *config, bool imported) { + int hIndex = 0; + bool retVal___ = false; + if (HPMHooks.count.HP_ipban_config_read_connection_pre > 0) { + bool (*preHookFunc) (const char **filename, struct config_t **config, bool *imported); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_ui2data_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_DB_ui2data_pre[hIndex].func; - retVal___ = preHookFunc(&data); + for (hIndex = 0; hIndex < HPMHooks.count.HP_ipban_config_read_connection_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_ipban_config_read_connection_pre[hIndex].func; + retVal___ = preHookFunc(&filename, &config, &imported); } if (*HPMforce_return) { *HPMforce_return = false; @@ -740,26 +1597,26 @@ struct DBData HP_DB_ui2data(unsigned int data) { } } { - retVal___ = HPMHooks.source.DB.ui2data(data); + retVal___ = HPMHooks.source.ipban.config_read_connection(filename, config, imported); } - if (HPMHooks.count.HP_DB_ui2data_post > 0) { - struct DBData (*postHookFunc) (struct DBData retVal___, unsigned int data); - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_ui2data_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_DB_ui2data_post[hIndex].func; - retVal___ = postHookFunc(retVal___, data); + if (HPMHooks.count.HP_ipban_config_read_connection_post > 0) { + bool (*postHookFunc) (bool retVal___, const char *filename, struct config_t *config, bool imported); + for (hIndex = 0; hIndex < HPMHooks.count.HP_ipban_config_read_connection_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_ipban_config_read_connection_post[hIndex].func; + retVal___ = postHookFunc(retVal___, filename, config, imported); } } return retVal___; } -struct DBData HP_DB_ptr2data(void *data) { +bool HP_ipban_config_read_dynamic(const char *filename, struct config_t *config, bool imported) { int hIndex = 0; - struct DBData retVal___ = { 0 }; - if (HPMHooks.count.HP_DB_ptr2data_pre > 0) { - struct DBData (*preHookFunc) (void **data); + bool retVal___ = false; + if (HPMHooks.count.HP_ipban_config_read_dynamic_pre > 0) { + bool (*preHookFunc) (const char **filename, struct config_t **config, bool *imported); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_ptr2data_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_DB_ptr2data_pre[hIndex].func; - retVal___ = preHookFunc(&data); + for (hIndex = 0; hIndex < HPMHooks.count.HP_ipban_config_read_dynamic_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_ipban_config_read_dynamic_pre[hIndex].func; + retVal___ = preHookFunc(&filename, &config, &imported); } if (*HPMforce_return) { *HPMforce_return = false; @@ -767,26 +1624,26 @@ struct DBData HP_DB_ptr2data(void *data) { } } { - retVal___ = HPMHooks.source.DB.ptr2data(data); + retVal___ = HPMHooks.source.ipban.config_read_dynamic(filename, config, imported); } - if (HPMHooks.count.HP_DB_ptr2data_post > 0) { - struct DBData (*postHookFunc) (struct DBData retVal___, void *data); - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_ptr2data_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_DB_ptr2data_post[hIndex].func; - retVal___ = postHookFunc(retVal___, data); + if (HPMHooks.count.HP_ipban_config_read_dynamic_post > 0) { + bool (*postHookFunc) (bool retVal___, const char *filename, struct config_t *config, bool imported); + for (hIndex = 0; hIndex < HPMHooks.count.HP_ipban_config_read_dynamic_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_ipban_config_read_dynamic_post[hIndex].func; + retVal___ = postHookFunc(retVal___, filename, config, imported); } } return retVal___; } -int HP_DB_data2i(struct DBData *data) { +bool HP_ipban_config_read(const char *filename, struct config_t *config, bool imported) { int hIndex = 0; - int retVal___ = 0; - if (HPMHooks.count.HP_DB_data2i_pre > 0) { - int (*preHookFunc) (struct DBData **data); + bool retVal___ = false; + if (HPMHooks.count.HP_ipban_config_read_pre > 0) { + bool (*preHookFunc) (const char **filename, struct config_t **config, bool *imported); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_data2i_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_DB_data2i_pre[hIndex].func; - retVal___ = preHookFunc(&data); + for (hIndex = 0; hIndex < HPMHooks.count.HP_ipban_config_read_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_ipban_config_read_pre[hIndex].func; + retVal___ = preHookFunc(&filename, &config, &imported); } if (*HPMforce_return) { *HPMforce_return = false; @@ -794,26 +1651,26 @@ int HP_DB_data2i(struct DBData *data) { } } { - retVal___ = HPMHooks.source.DB.data2i(data); + retVal___ = HPMHooks.source.ipban.config_read(filename, config, imported); } - if (HPMHooks.count.HP_DB_data2i_post > 0) { - int (*postHookFunc) (int retVal___, struct DBData *data); - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_data2i_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_DB_data2i_post[hIndex].func; - retVal___ = postHookFunc(retVal___, data); + if (HPMHooks.count.HP_ipban_config_read_post > 0) { + bool (*postHookFunc) (bool retVal___, const char *filename, struct config_t *config, bool imported); + for (hIndex = 0; hIndex < HPMHooks.count.HP_ipban_config_read_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_ipban_config_read_post[hIndex].func; + retVal___ = postHookFunc(retVal___, filename, config, imported); } } return retVal___; } -unsigned int HP_DB_data2ui(struct DBData *data) { +bool HP_ipban_check(uint32 ip) { int hIndex = 0; - unsigned int retVal___ = 0; - if (HPMHooks.count.HP_DB_data2ui_pre > 0) { - unsigned int (*preHookFunc) (struct DBData **data); + bool retVal___ = false; + if (HPMHooks.count.HP_ipban_check_pre > 0) { + bool (*preHookFunc) (uint32 *ip); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_data2ui_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_DB_data2ui_pre[hIndex].func; - retVal___ = preHookFunc(&data); + for (hIndex = 0; hIndex < HPMHooks.count.HP_ipban_check_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_ipban_check_pre[hIndex].func; + retVal___ = preHookFunc(&ip); } if (*HPMforce_return) { *HPMforce_return = false; @@ -821,52 +1678,52 @@ unsigned int HP_DB_data2ui(struct DBData *data) { } } { - retVal___ = HPMHooks.source.DB.data2ui(data); + retVal___ = HPMHooks.source.ipban.check(ip); } - if (HPMHooks.count.HP_DB_data2ui_post > 0) { - unsigned int (*postHookFunc) (unsigned int retVal___, struct DBData *data); - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_data2ui_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_DB_data2ui_post[hIndex].func; - retVal___ = postHookFunc(retVal___, data); + if (HPMHooks.count.HP_ipban_check_post > 0) { + bool (*postHookFunc) (bool retVal___, uint32 ip); + for (hIndex = 0; hIndex < HPMHooks.count.HP_ipban_check_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_ipban_check_post[hIndex].func; + retVal___ = postHookFunc(retVal___, ip); } } return retVal___; } -void* HP_DB_data2ptr(struct DBData *data) { +void HP_ipban_log(uint32 ip) { int hIndex = 0; - void* retVal___ = NULL; - if (HPMHooks.count.HP_DB_data2ptr_pre > 0) { - void* (*preHookFunc) (struct DBData **data); + if (HPMHooks.count.HP_ipban_log_pre > 0) { + void (*preHookFunc) (uint32 *ip); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_data2ptr_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_DB_data2ptr_pre[hIndex].func; - retVal___ = preHookFunc(&data); + for (hIndex = 0; hIndex < HPMHooks.count.HP_ipban_log_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_ipban_log_pre[hIndex].func; + preHookFunc(&ip); } if (*HPMforce_return) { *HPMforce_return = false; - return retVal___; + return; } } { - retVal___ = HPMHooks.source.DB.data2ptr(data); + HPMHooks.source.ipban.log(ip); } - if (HPMHooks.count.HP_DB_data2ptr_post > 0) { - void* (*postHookFunc) (void* retVal___, struct DBData *data); - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_data2ptr_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_DB_data2ptr_post[hIndex].func; - retVal___ = postHookFunc(retVal___, data); + if (HPMHooks.count.HP_ipban_log_post > 0) { + void (*postHookFunc) (uint32 ip); + for (hIndex = 0; hIndex < HPMHooks.count.HP_ipban_log_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_ipban_log_post[hIndex].func; + postHookFunc(ip); } } - return retVal___; + return; } -void HP_DB_init(void) { +/* lchrif_interface */ +void HP_lchrif_server_init(int id) { int hIndex = 0; - if (HPMHooks.count.HP_DB_init_pre > 0) { - void (*preHookFunc) (void); + if (HPMHooks.count.HP_lchrif_server_init_pre > 0) { + void (*preHookFunc) (int *id); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_init_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_DB_init_pre[hIndex].func; - preHookFunc(); + for (hIndex = 0; hIndex < HPMHooks.count.HP_lchrif_server_init_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_lchrif_server_init_pre[hIndex].func; + preHookFunc(&id); } if (*HPMforce_return) { *HPMforce_return = false; @@ -874,25 +1731,25 @@ void HP_DB_init(void) { } } { - HPMHooks.source.DB.init(); + HPMHooks.source.lchrif.server_init(id); } - if (HPMHooks.count.HP_DB_init_post > 0) { - void (*postHookFunc) (void); - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_init_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_DB_init_post[hIndex].func; - postHookFunc(); + if (HPMHooks.count.HP_lchrif_server_init_post > 0) { + void (*postHookFunc) (int id); + for (hIndex = 0; hIndex < HPMHooks.count.HP_lchrif_server_init_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_lchrif_server_init_post[hIndex].func; + postHookFunc(id); } } return; } -void HP_DB_final(void) { +void HP_lchrif_server_destroy(int id) { int hIndex = 0; - if (HPMHooks.count.HP_DB_final_pre > 0) { - void (*preHookFunc) (void); + if (HPMHooks.count.HP_lchrif_server_destroy_pre > 0) { + void (*preHookFunc) (int *id); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_final_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_DB_final_pre[hIndex].func; - preHookFunc(); + for (hIndex = 0; hIndex < HPMHooks.count.HP_lchrif_server_destroy_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_lchrif_server_destroy_pre[hIndex].func; + preHookFunc(&id); } if (*HPMforce_return) { *HPMforce_return = false; @@ -900,26 +1757,25 @@ void HP_DB_final(void) { } } { - HPMHooks.source.DB.final(); + HPMHooks.source.lchrif.server_destroy(id); } - if (HPMHooks.count.HP_DB_final_post > 0) { - void (*postHookFunc) (void); - for (hIndex = 0; hIndex < HPMHooks.count.HP_DB_final_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_DB_final_post[hIndex].func; - postHookFunc(); + if (HPMHooks.count.HP_lchrif_server_destroy_post > 0) { + void (*postHookFunc) (int id); + for (hIndex = 0; hIndex < HPMHooks.count.HP_lchrif_server_destroy_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_lchrif_server_destroy_post[hIndex].func; + postHookFunc(id); } } return; } -/* des_interface */ -void HP_des_decrypt_block(struct des_bit64 *block) { +void HP_lchrif_server_reset(int id) { int hIndex = 0; - if (HPMHooks.count.HP_des_decrypt_block_pre > 0) { - void (*preHookFunc) (struct des_bit64 **block); + if (HPMHooks.count.HP_lchrif_server_reset_pre > 0) { + void (*preHookFunc) (int *id); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_des_decrypt_block_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_des_decrypt_block_pre[hIndex].func; - preHookFunc(&block); + for (hIndex = 0; hIndex < HPMHooks.count.HP_lchrif_server_reset_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_lchrif_server_reset_pre[hIndex].func; + preHookFunc(&id); } if (*HPMforce_return) { *HPMforce_return = false; @@ -927,25 +1783,25 @@ void HP_des_decrypt_block(struct des_bit64 *block) { } } { - HPMHooks.source.des.decrypt_block(block); + HPMHooks.source.lchrif.server_reset(id); } - if (HPMHooks.count.HP_des_decrypt_block_post > 0) { - void (*postHookFunc) (struct des_bit64 *block); - for (hIndex = 0; hIndex < HPMHooks.count.HP_des_decrypt_block_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_des_decrypt_block_post[hIndex].func; - postHookFunc(block); + if (HPMHooks.count.HP_lchrif_server_reset_post > 0) { + void (*postHookFunc) (int id); + for (hIndex = 0; hIndex < HPMHooks.count.HP_lchrif_server_reset_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_lchrif_server_reset_post[hIndex].func; + postHookFunc(id); } } return; } -void HP_des_decrypt(unsigned char *data, size_t size) { +void HP_lchrif_on_disconnect(int id) { int hIndex = 0; - if (HPMHooks.count.HP_des_decrypt_pre > 0) { - void (*preHookFunc) (unsigned char **data, size_t *size); + if (HPMHooks.count.HP_lchrif_on_disconnect_pre > 0) { + void (*preHookFunc) (int *id); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_des_decrypt_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_des_decrypt_pre[hIndex].func; - preHookFunc(&data, &size); + for (hIndex = 0; hIndex < HPMHooks.count.HP_lchrif_on_disconnect_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_lchrif_on_disconnect_pre[hIndex].func; + preHookFunc(&id); } if (*HPMforce_return) { *HPMforce_return = false; @@ -953,13 +1809,13 @@ void HP_des_decrypt(unsigned char *data, size_t size) { } } { - HPMHooks.source.des.decrypt(data, size); + HPMHooks.source.lchrif.on_disconnect(id); } - if (HPMHooks.count.HP_des_decrypt_post > 0) { - void (*postHookFunc) (unsigned char *data, size_t size); - for (hIndex = 0; hIndex < HPMHooks.count.HP_des_decrypt_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_des_decrypt_post[hIndex].func; - postHookFunc(data, size); + if (HPMHooks.count.HP_lchrif_on_disconnect_post > 0) { + void (*postHookFunc) (int id); + for (hIndex = 0; hIndex < HPMHooks.count.HP_lchrif_on_disconnect_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_lchrif_on_disconnect_post[hIndex].func; + postHookFunc(id); } } return; @@ -5117,6 +5973,195 @@ uint16 HP_login_convert_users_to_colors(uint16 users) { } return retVal___; } +/* loginlog_interface */ +unsigned long HP_loginlog_failedattempts(uint32 ip, unsigned int minutes) { + int hIndex = 0; + unsigned long retVal___ = 0; + if (HPMHooks.count.HP_loginlog_failedattempts_pre > 0) { + unsigned long (*preHookFunc) (uint32 *ip, unsigned int *minutes); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_loginlog_failedattempts_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_loginlog_failedattempts_pre[hIndex].func; + retVal___ = preHookFunc(&ip, &minutes); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.loginlog.failedattempts(ip, minutes); + } + if (HPMHooks.count.HP_loginlog_failedattempts_post > 0) { + unsigned long (*postHookFunc) (unsigned long retVal___, uint32 ip, unsigned int minutes); + for (hIndex = 0; hIndex < HPMHooks.count.HP_loginlog_failedattempts_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_loginlog_failedattempts_post[hIndex].func; + retVal___ = postHookFunc(retVal___, ip, minutes); + } + } + return retVal___; +} +void HP_loginlog_log(uint32 ip, const char *username, int rcode, const char *message) { + int hIndex = 0; + if (HPMHooks.count.HP_loginlog_log_pre > 0) { + void (*preHookFunc) (uint32 *ip, const char **username, int *rcode, const char **message); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_loginlog_log_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_loginlog_log_pre[hIndex].func; + preHookFunc(&ip, &username, &rcode, &message); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return; + } + } + { + HPMHooks.source.loginlog.log(ip, username, rcode, message); + } + if (HPMHooks.count.HP_loginlog_log_post > 0) { + void (*postHookFunc) (uint32 ip, const char *username, int rcode, const char *message); + for (hIndex = 0; hIndex < HPMHooks.count.HP_loginlog_log_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_loginlog_log_post[hIndex].func; + postHookFunc(ip, username, rcode, message); + } + } + return; +} +bool HP_loginlog_init(void) { + int hIndex = 0; + bool retVal___ = false; + if (HPMHooks.count.HP_loginlog_init_pre > 0) { + bool (*preHookFunc) (void); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_loginlog_init_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_loginlog_init_pre[hIndex].func; + retVal___ = preHookFunc(); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.loginlog.init(); + } + if (HPMHooks.count.HP_loginlog_init_post > 0) { + bool (*postHookFunc) (bool retVal___); + for (hIndex = 0; hIndex < HPMHooks.count.HP_loginlog_init_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_loginlog_init_post[hIndex].func; + retVal___ = postHookFunc(retVal___); + } + } + return retVal___; +} +bool HP_loginlog_final(void) { + int hIndex = 0; + bool retVal___ = false; + if (HPMHooks.count.HP_loginlog_final_pre > 0) { + bool (*preHookFunc) (void); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_loginlog_final_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_loginlog_final_pre[hIndex].func; + retVal___ = preHookFunc(); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.loginlog.final(); + } + if (HPMHooks.count.HP_loginlog_final_post > 0) { + bool (*postHookFunc) (bool retVal___); + for (hIndex = 0; hIndex < HPMHooks.count.HP_loginlog_final_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_loginlog_final_post[hIndex].func; + retVal___ = postHookFunc(retVal___); + } + } + return retVal___; +} +bool HP_loginlog_config_read_names(const char *filename, struct config_t *config, bool imported) { + int hIndex = 0; + bool retVal___ = false; + if (HPMHooks.count.HP_loginlog_config_read_names_pre > 0) { + bool (*preHookFunc) (const char **filename, struct config_t **config, bool *imported); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_loginlog_config_read_names_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_loginlog_config_read_names_pre[hIndex].func; + retVal___ = preHookFunc(&filename, &config, &imported); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.loginlog.config_read_names(filename, config, imported); + } + if (HPMHooks.count.HP_loginlog_config_read_names_post > 0) { + bool (*postHookFunc) (bool retVal___, const char *filename, struct config_t *config, bool imported); + for (hIndex = 0; hIndex < HPMHooks.count.HP_loginlog_config_read_names_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_loginlog_config_read_names_post[hIndex].func; + retVal___ = postHookFunc(retVal___, filename, config, imported); + } + } + return retVal___; +} +bool HP_loginlog_config_read_log(const char *filename, struct config_t *config, bool imported) { + int hIndex = 0; + bool retVal___ = false; + if (HPMHooks.count.HP_loginlog_config_read_log_pre > 0) { + bool (*preHookFunc) (const char **filename, struct config_t **config, bool *imported); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_loginlog_config_read_log_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_loginlog_config_read_log_pre[hIndex].func; + retVal___ = preHookFunc(&filename, &config, &imported); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.loginlog.config_read_log(filename, config, imported); + } + if (HPMHooks.count.HP_loginlog_config_read_log_post > 0) { + bool (*postHookFunc) (bool retVal___, const char *filename, struct config_t *config, bool imported); + for (hIndex = 0; hIndex < HPMHooks.count.HP_loginlog_config_read_log_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_loginlog_config_read_log_post[hIndex].func; + retVal___ = postHookFunc(retVal___, filename, config, imported); + } + } + return retVal___; +} +bool HP_loginlog_config_read(const char *filename, bool imported) { + int hIndex = 0; + bool retVal___ = false; + if (HPMHooks.count.HP_loginlog_config_read_pre > 0) { + bool (*preHookFunc) (const char **filename, bool *imported); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_loginlog_config_read_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_loginlog_config_read_pre[hIndex].func; + retVal___ = preHookFunc(&filename, &imported); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.loginlog.config_read(filename, imported); + } + if (HPMHooks.count.HP_loginlog_config_read_post > 0) { + bool (*postHookFunc) (bool retVal___, const char *filename, bool imported); + for (hIndex = 0; hIndex < HPMHooks.count.HP_loginlog_config_read_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_loginlog_config_read_post[hIndex].func; + retVal___ = postHookFunc(retVal___, filename, imported); + } + } + return retVal___; +} /* md5_interface */ void HP_md5_string(const char *string, char *output) { int hIndex = 0; diff --git a/src/plugins/HPMHooking/HPMHooking_login.sources.inc b/src/plugins/HPMHooking/HPMHooking_login.sources.inc index 55ced3025..78c506043 100644 --- a/src/plugins/HPMHooking/HPMHooking_login.sources.inc +++ b/src/plugins/HPMHooking/HPMHooking_login.sources.inc @@ -26,15 +26,19 @@ /* GENERATED FILE DO NOT EDIT */ HPMHooks.source.HCache = *HCache; +HPMHooks.source.account = *account; HPMHooks.source.cmdline = *cmdline; HPMHooks.source.console = *console; HPMHooks.source.core = *core; HPMHooks.source.DB = *DB; HPMHooks.source.des = *des; +HPMHooks.source.ipban = *ipban; +HPMHooks.source.lchrif = *lchrif; HPMHooks.source.lclif = *lclif; HPMHooks.source.PRIV__lclif = *lclif->p; HPMHooks.source.libconfig = *libconfig; HPMHooks.source.login = *login; +HPMHooks.source.loginlog = *loginlog; HPMHooks.source.md5 = *md5; HPMHooks.source.mutex = *mutex; HPMHooks.source.nullpo = *nullpo; -- cgit v1.2.3-70-g09d2 From 8174c0c1e315533e903d229feb519a71286d4b54 Mon Sep 17 00:00:00 2001 From: Haru Date: Sat, 10 Feb 2018 01:18:28 +0100 Subject: Update Xcode project Signed-off-by: Haru --- Hercules.xcodeproj/project.pbxproj | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Hercules.xcodeproj/project.pbxproj b/Hercules.xcodeproj/project.pbxproj index 4609880aa..2b1363e10 100644 --- a/Hercules.xcodeproj/project.pbxproj +++ b/Hercules.xcodeproj/project.pbxproj @@ -25,10 +25,10 @@ A55AED7C1B8153F100149CF8 /* scanner.c in Sources */ = {isa = PBXBuildFile; fileRef = A56CC72918564C05009EB79C /* scanner.c */; }; A55AED7D1B8153F300149CF8 /* strbuf.c in Sources */ = {isa = PBXBuildFile; fileRef = A56CC72B18564C05009EB79C /* strbuf.c */; }; A567612D185D11D700997C0D /* nullpo.c in Sources */ = {isa = PBXBuildFile; fileRef = A56CC6B2185643BB009EB79C /* nullpo.c */; }; - A56CC68918564387009EB79C /* account_sql.c in Sources */ = {isa = PBXBuildFile; fileRef = A56CC68118564387009EB79C /* account_sql.c */; }; - A56CC68A18564387009EB79C /* ipban_sql.c in Sources */ = {isa = PBXBuildFile; fileRef = A56CC68318564387009EB79C /* ipban_sql.c */; }; + A56CC68918564387009EB79C /* account.c in Sources */ = {isa = PBXBuildFile; fileRef = A56CC68118564387009EB79C /* account.c */; }; + A56CC68A18564387009EB79C /* ipban.c in Sources */ = {isa = PBXBuildFile; fileRef = A56CC68318564387009EB79C /* ipban.c */; }; A56CC68B18564387009EB79C /* login.c in Sources */ = {isa = PBXBuildFile; fileRef = A56CC68518564387009EB79C /* login.c */; }; - A56CC68C18564387009EB79C /* loginlog_sql.c in Sources */ = {isa = PBXBuildFile; fileRef = A56CC68718564387009EB79C /* loginlog_sql.c */; }; + A56CC68C18564387009EB79C /* loginlog.c in Sources */ = {isa = PBXBuildFile; fileRef = A56CC68718564387009EB79C /* loginlog.c */; }; A56CC6C9185643BB009EB79C /* conf.c in Sources */ = {isa = PBXBuildFile; fileRef = A56CC690185643BB009EB79C /* conf.c */; }; A56CC6CA185643BB009EB79C /* conf.c in Sources */ = {isa = PBXBuildFile; fileRef = A56CC690185643BB009EB79C /* conf.c */; }; A56CC6CB185643BB009EB79C /* conf.c in Sources */ = {isa = PBXBuildFile; fileRef = A56CC690185643BB009EB79C /* conf.c */; }; @@ -239,13 +239,13 @@ A56CC66A18564315009EB79C /* login-server */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "login-server"; sourceTree = BUILT_PRODUCTS_DIR; }; A56CC6731856434D009EB79C /* char-server */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "char-server"; sourceTree = BUILT_PRODUCTS_DIR; }; A56CC67C18564356009EB79C /* map-server */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "map-server"; sourceTree = BUILT_PRODUCTS_DIR; }; - A56CC68118564387009EB79C /* account_sql.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = account_sql.c; path = src/login/account_sql.c; sourceTree = SOURCE_ROOT; }; + A56CC68118564387009EB79C /* account.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = account.c; path = src/login/account.c; sourceTree = SOURCE_ROOT; }; A56CC68218564387009EB79C /* account.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = account.h; path = src/login/account.h; sourceTree = SOURCE_ROOT; }; - A56CC68318564387009EB79C /* ipban_sql.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ipban_sql.c; path = src/login/ipban_sql.c; sourceTree = SOURCE_ROOT; }; + A56CC68318564387009EB79C /* ipban.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ipban.c; path = src/login/ipban.c; sourceTree = SOURCE_ROOT; }; A56CC68418564387009EB79C /* ipban.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ipban.h; path = src/login/ipban.h; sourceTree = SOURCE_ROOT; }; A56CC68518564387009EB79C /* login.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = login.c; path = src/login/login.c; sourceTree = SOURCE_ROOT; }; A56CC68618564387009EB79C /* login.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = login.h; path = src/login/login.h; sourceTree = SOURCE_ROOT; }; - A56CC68718564387009EB79C /* loginlog_sql.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = loginlog_sql.c; path = src/login/loginlog_sql.c; sourceTree = SOURCE_ROOT; }; + A56CC68718564387009EB79C /* loginlog.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = loginlog.c; path = src/login/loginlog.c; sourceTree = SOURCE_ROOT; }; A56CC68818564387009EB79C /* loginlog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = loginlog.h; path = src/login/loginlog.h; sourceTree = SOURCE_ROOT; }; A56CC68E185643BB009EB79C /* atomic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = atomic.h; path = src/common/atomic.h; sourceTree = ""; }; A56CC68F185643BB009EB79C /* cbasetypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = cbasetypes.h; path = src/common/cbasetypes.h; sourceTree = ""; }; @@ -565,13 +565,13 @@ A5296FCC1CAC40CF001ABCAC /* lclif.p.h */, A5B894A81A03CDD4005AD22E /* HPMlogin.c */, A5B894A91A03CDD4005AD22E /* HPMlogin.h */, - A56CC68118564387009EB79C /* account_sql.c */, + A56CC68118564387009EB79C /* account.c */, A56CC68218564387009EB79C /* account.h */, - A56CC68318564387009EB79C /* ipban_sql.c */, + A56CC68318564387009EB79C /* ipban.c */, A56CC68418564387009EB79C /* ipban.h */, A56CC68518564387009EB79C /* login.c */, A56CC68618564387009EB79C /* login.h */, - A56CC68718564387009EB79C /* loginlog_sql.c */, + A56CC68718564387009EB79C /* loginlog.c */, A56CC68818564387009EB79C /* loginlog.h */, ); path = "login-server"; @@ -1208,7 +1208,7 @@ A5B894AA1A03CDD4005AD22E /* HPMlogin.c in Sources */, A5296FCD1CAC40CF001ABCAC /* lclif.c in Sources */, A56CC6DE185643BB009EB79C /* grfio.c in Sources */, - A56CC68C18564387009EB79C /* loginlog_sql.c in Sources */, + A56CC68C18564387009EB79C /* loginlog.c in Sources */, A56CC73118564C05009EB79C /* libconfig.c in Sources */, A56CC717185643BB009EB79C /* utils.c in Sources */, A56CC708185643BB009EB79C /* sql.c in Sources */, @@ -1225,13 +1225,13 @@ A56CC6CC185643BB009EB79C /* console.c in Sources */, A56CC72E18564C05009EB79C /* grammar.c in Sources */, A56CC705185643BB009EB79C /* socket.c in Sources */, - A56CC68918564387009EB79C /* account_sql.c in Sources */, + A56CC68918564387009EB79C /* account.c in Sources */, A56CC6E4185643BB009EB79C /* memmgr.c in Sources */, A56CC6E1185643BB009EB79C /* HPM.c in Sources */, A56CC6FF185643BB009EB79C /* random.c in Sources */, A56CC73418564C05009EB79C /* scanctx.c in Sources */, A56CC714185643BB009EB79C /* timer.c in Sources */, - A56CC68A18564387009EB79C /* ipban_sql.c in Sources */, + A56CC68A18564387009EB79C /* ipban.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; -- cgit v1.2.3-70-g09d2