From d18235cae43500d68210b09514b76506fc831014 Mon Sep 17 00:00:00 2001 From: Haru Date: Tue, 28 Oct 2014 15:52:53 +0100 Subject: Added preliminary support for login and char server in the HPMDataCheck - Special thanks to Ind Signed-off-by: Haru --- src/login/HPMlogin.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ src/login/HPMlogin.h | 20 +++++++++++++++++++ src/login/Makefile.in | 4 ++-- src/login/account_sql.c | 10 +++++----- src/login/login.c | 50 ++++++++++++++++++++++++++++++++++++---------- 5 files changed, 119 insertions(+), 18 deletions(-) create mode 100644 src/login/HPMlogin.c create mode 100644 src/login/HPMlogin.h (limited to 'src/login') diff --git a/src/login/HPMlogin.c b/src/login/HPMlogin.c new file mode 100644 index 000000000..6b223d249 --- /dev/null +++ b/src/login/HPMlogin.c @@ -0,0 +1,53 @@ +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file + +#define HERCULES_CORE + +#include "HPMlogin.h" + +#include +#include +#include +#include + +#include "../common/HPM.h" +#include "../common/cbasetypes.h" +#include "../common/conf.h" +#include "../common/db.h" +#include "../common/des.h" +#include "../common/ers.h" +#include "../common/malloc.h" +#include "../common/mapindex.h" +#include "../common/mmo.h" +#include "../common/showmsg.h" +#include "../common/socket.h" +#include "../common/strlib.h" +#include "../common/sysinfo.h" + +#include "../common/HPMDataCheck.h" + +bool HPM_login_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr) { + /* record address */ + switch( type ) { + default: + return false; + } + return true; +} + +void HPM_login_plugin_load_sub(struct hplugin *plugin) { +} + +void HPM_login_do_init(void) { +#if 0 // TODO (HPMDataCheck is disabled for the time being) + HPM->datacheck_init(HPMDataCheck, HPMDataCheckLen, HPMDataCheckVer); +#else + HPM->DataCheck = NULL; +#endif +} + +void HPM_login_do_final(void) { +#if 0 // TODO (HPMDataCheck is disabled for the time being) + HPM->datacheck_final(); +#endif +} diff --git a/src/login/HPMlogin.h b/src/login/HPMlogin.h new file mode 100644 index 000000000..6bdc0fb7b --- /dev/null +++ b/src/login/HPMlogin.h @@ -0,0 +1,20 @@ +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file + +#ifndef LOGIN_HPMLOGIN_H +#define LOGIN_HPMLOGIN_H + +#include "../common/cbasetypes.h" +#include "../common/HPM.h" + +struct hplugin; + +bool HPM_login_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr); + +void HPM_login_plugin_load_sub(struct hplugin *plugin); + +void HPM_login_do_final(void); + +void HPM_login_do_init(void); + +#endif /* LOGIN_HPMLOGIN_H */ diff --git a/src/login/Makefile.in b/src/login/Makefile.in index a4aec59cf..9b1db69c2 100644 --- a/src/login/Makefile.in +++ b/src/login/Makefile.in @@ -22,9 +22,9 @@ MT19937AR_OBJ = $(MT19937AR_D)/mt19937ar.o MT19937AR_H = $(MT19937AR_D)/mt19937ar.h MT19937AR_INCLUDE = -I$(MT19937AR_D) -LOGIN_C = account_sql.c ipban_sql.c login.c loginlog_sql.c +LOGIN_C = account_sql.c HPMlogin.c ipban_sql.c login.c loginlog_sql.c LOGIN_OBJ = $(addprefix obj_sql/, $(patsubst %.c,%.o,$(LOGIN_C))) -LOGIN_H = login.h account.h ipban.h loginlog.h +LOGIN_H = login.h account.h HPMlogin.h ipban.h loginlog.h HAVE_MYSQL=@HAVE_MYSQL@ ifeq ($(HAVE_MYSQL),yes) diff --git a/src/login/account_sql.c b/src/login/account_sql.c index 51e499369..996bfcf44 100644 --- a/src/login/account_sql.c +++ b/src/login/account_sql.c @@ -169,6 +169,10 @@ static bool account_db_sql_init(AccountDB* self) if( codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, codepage) ) Sql_ShowDebug(sql_handle); + Sql_HerculesUpdateCheck(db->accounts); +#ifdef CONSOLE_INPUT + console->input->setSQL(db->accounts); +#endif return true; } @@ -655,11 +659,7 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo Sql* account_db_sql_up(AccountDB* self) { AccountDB_SQL* db = (AccountDB_SQL*)self; - Sql_HerculesUpdateCheck(db->accounts); -#ifdef CONSOLE_INPUT - console->input->setSQL(db->accounts); -#endif - return db->accounts; + return db ? db->accounts : NULL; } void mmo_save_accreg2(AccountDB* self, int fd, int account_id, int char_id) { Sql* sql_handle = ((AccountDB_SQL*)self)->accounts; diff --git a/src/login/login.c b/src/login/login.c index 129049627..9aa2e778b 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -10,6 +10,7 @@ #include #include +#include "HPMlogin.h" #include "account.h" #include "ipban.h" #include "loginlog.h" @@ -1737,6 +1738,10 @@ int do_final(void) { login_fd = -1; } + HPM_login_do_final(); + + HPM->event(HPET_POST_FINAL); + ShowStatus("Finished.\n"); return EXIT_SUCCESS; } @@ -1770,6 +1775,9 @@ void do_shutdown(void) } } +void login_hp_symbols(void) { + HPM->share(account_db_sql_up(accounts),"sql_handle"); +} //------------------------------ // Login server initialization @@ -1780,9 +1788,38 @@ int do_init(int argc, char** argv) // initialize engine (to accept config settings) account_engine[0].db = account_engine[0].constructor(); + accounts = account_engine[0].db; + if( accounts == NULL ) { + ShowFatalError("do_init: account engine 'sql' not found.\n"); + exit(EXIT_FAILURE); + } // read login-server configuration login_set_defaults(); + + HPM_login_do_init(); + HPM->symbol_defaults_sub = login_hp_symbols; + HPM->config_read(NULL, 0); +#if 0 + /* TODO: Move to common code */ + for( i = 1; i < argc; i++ ) { + const char* arg = argv[i]; + if( strcmp(arg, "--load-plugin") == 0 ) { + if( map->arg_next_value(arg, i, argc, true) ) { + RECREATE(load_extras, char *, ++load_extras_count); + load_extras[load_extras_count-1] = argv[++i]; + } + } + } + HPM->config_read((const char * const *)load_extras, load_extras_count); + if (load_extras) { + aFree(load_extras); + load_extras = NULL; + load_extras_count = 0; + } +#endif + HPM->event(HPET_PRE_INIT); + login_config_read((argc > 1) ? argv[1] : LOGIN_CONF_NAME); login_lan_config_read((argc > 2) ? argv[2] : LAN_CONF_NAME); @@ -1817,20 +1854,11 @@ int do_init(int argc, char** argv) } // Account database init - accounts = account_engine[0].db; - if( accounts == NULL ) { - ShowFatalError("do_init: account engine 'sql' not found.\n"); + if(!accounts->init(accounts)) { + ShowFatalError("do_init: Failed to initialize account engine 'sql'.\n"); exit(EXIT_FAILURE); - } else { - - if(!accounts->init(accounts)) { - ShowFatalError("do_init: Failed to initialize account engine 'sql'.\n"); - exit(EXIT_FAILURE); - } } - HPM->share(account_db_sql_up(accounts),"sql_handle"); - HPM->config_read(NULL, 0); HPM->event(HPET_INIT); // server port open & binding -- cgit v1.2.3-70-g09d2