diff options
Diffstat (limited to 'src/login')
-rw-r--r-- | src/login/CMakeLists.txt | 12 | ||||
-rw-r--r-- | src/login/Makefile.in | 13 | ||||
-rw-r--r-- | src/login/account.h | 9 | ||||
-rw-r--r-- | src/login/account_sql.c | 19 | ||||
-rw-r--r-- | src/login/ipban.h | 6 | ||||
-rw-r--r-- | src/login/ipban_sql.c | 14 | ||||
-rw-r--r-- | src/login/login.c | 60 | ||||
-rw-r--r-- | src/login/login.h | 10 | ||||
-rw-r--r-- | src/login/loginlog.h | 8 | ||||
-rw-r--r-- | src/login/loginlog_sql.c | 11 | ||||
-rw-r--r-- | src/login/sql/CMakeLists.txt | 39 |
11 files changed, 90 insertions, 111 deletions
diff --git a/src/login/CMakeLists.txt b/src/login/CMakeLists.txt deleted file mode 100644 index fa657f8fd..000000000 --- a/src/login/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ - -# -# setup -# -set( LOGIN_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "" ) -set( SQL_LOGIN_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "" ) - - -# -# targets -# -add_subdirectory( sql ) diff --git a/src/login/Makefile.in b/src/login/Makefile.in index fa5f92105..7551eed5f 100644 --- a/src/login/Makefile.in +++ b/src/login/Makefile.in @@ -1,9 +1,14 @@ +# Copyright (c) Hercules Dev Team, licensed under GNU GPL. +# See the LICENSE file + +# @configure_input@ CONFIG_D = ../config CONFIG_H = $(wildcard $(CONFIG_D)/*.h) $(wildcard $(CONFIG_D)/*/*.h) COMMON_D = ../common COMMON_H = $(wildcard $(COMMON_D)/*.h) +SYSINFO_INC = $(COMMON_D)/sysinfo.inc LIBCONFIG_D = ../../3rdparty/libconfig LIBCONFIG_OBJ = $(addprefix $(LIBCONFIG_D)/, libconfig.o grammar.o scanctx.o \ @@ -23,7 +28,7 @@ LOGIN_H = login.h account.h ipban.h loginlog.h HAVE_MYSQL=@HAVE_MYSQL@ ifeq ($(HAVE_MYSQL),yes) - LOGIN_SERVER_SQL_DEPENDS=$(LOGIN_OBJ) $(COMMON_D)/obj_sql/common_sql.a $(COMMON_D)/obj_all/common.a $(MT19937AR_OBJ) $(LIBCONFIG_OBJ) + LOGIN_SERVER_SQL_DEPENDS=$(LOGIN_OBJ) $(COMMON_D)/obj_sql/common_sql.a $(COMMON_D)/obj_all/common.a $(MT19937AR_OBJ) $(LIBCONFIG_OBJ $(SYSINFO_INC)) else LOGIN_SERVER_SQL_DEPENDS=needs_mysql endif @@ -62,6 +67,10 @@ help: Makefile: Makefile.in @$(MAKE) -C ../.. src/login/Makefile +$(SYSINFO_INC): $(LOGIN_C) $(LOGIN_H) $(COMMON_H) $(CONFIG_H) $(MT19937AR_H) $(LIBCONFIG_H) + @echo " MAKE $@" + @$(MAKE) -C ../.. sysinfo + needs_mysql: @echo "MySQL not found or disabled by the configure script" @exit 1 @@ -85,7 +94,7 @@ login-server: ../../login-server@EXEEXT@ obj_sql/%.o: %.c $(LOGIN_H) $(COMMON_H) $(CONFIG_H) $(MT19937AR_H) $(LIBCONFIG_H) | obj_sql @echo " CC $<" - @$(CC) @CFLAGS@ $(MT19937AR_INCLUDE) $(LIBCONFIG_INCLUDE) @MYSQL_CFLAGS@ @CPPFLAGS@ -c $(OUTPUT_OPTION) $< + @$(CC) @CFLAGS@ @DEFS@ $(MT19937AR_INCLUDE) $(LIBCONFIG_INCLUDE) @MYSQL_CFLAGS@ @CPPFLAGS@ -c $(OUTPUT_OPTION) $< # missing object files $(COMMON_D)/obj_all/common.a: diff --git a/src/login/account.h b/src/login/account.h index 234e7c0c1..e15143ce9 100644 --- a/src/login/account.h +++ b/src/login/account.h @@ -2,11 +2,12 @@ // See the LICENSE file // Portions Copyright (c) Athena Dev Teams -#ifndef _LOGIN_ACCOUNT_H_ -#define _LOGIN_ACCOUNT_H_ +#ifndef LOGIN_ACCOUNT_H +#define LOGIN_ACCOUNT_H #include "../common/cbasetypes.h" #include "../common/mmo.h" // ACCOUNT_REG2_NUM +#include "../common/sql.h" // Sql typedef struct AccountDB AccountDB; typedef struct AccountDBIterator AccountDBIterator; @@ -24,7 +25,7 @@ struct mmo_account char email[40]; // e-mail (by default: a@a.com) int group_id; // player group id uint8 char_slots; // this accounts maximum character slots (maximum is limited to MAX_CHARS define in char server) - unsigned int state; // packet 0x006a value + 1 (0: compte OK) + unsigned int state; // packet 0x006a value + 1 (0: complete OK) time_t unban_time; // (timestamp): ban time limit of the account (0 = no ban) time_t expiration_time; // (timestamp): validity limit of the account (0 = unlimited) unsigned int logincount; // number of successful auth attempts @@ -139,4 +140,4 @@ 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); -#endif /* _LOGIN_ACCOUNT_H_ */ +#endif /* LOGIN_ACCOUNT_H */ diff --git a/src/login/account_sql.c b/src/login/account_sql.c index 1483196ab..51e499369 100644 --- a/src/login/account_sql.c +++ b/src/login/account_sql.c @@ -2,17 +2,22 @@ // See the LICENSE file // Portions Copyright (c) Athena Dev Teams +#define HERCULES_CORE + +#include "../config/core.h" // CONSOLE_INPUT +#include "account.h" + +#include <stdlib.h> +#include <string.h> + +#include "../common/console.h" #include "../common/malloc.h" #include "../common/mmo.h" #include "../common/showmsg.h" +#include "../common/socket.h" #include "../common/sql.h" #include "../common/strlib.h" #include "../common/timer.h" -#include "../common/console.h" -#include "../common/socket.h" -#include "account.h" -#include <stdlib.h> -#include <string.h> /// global defines #define ACCOUNT_SQL_DB_VERSION 20110114 @@ -449,7 +454,7 @@ static bool account_db_sql_load_str(AccountDB* self, struct mmo_account* acc, co } if( SQL->NumRows(sql_handle) > 1 ) - {// serious problem - duplicit account + {// 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; @@ -652,7 +657,7 @@ Sql* account_db_sql_up(AccountDB* self) { AccountDB_SQL* db = (AccountDB_SQL*)self; Sql_HerculesUpdateCheck(db->accounts); #ifdef CONSOLE_INPUT - console->setSQL(db->accounts); + console->input->setSQL(db->accounts); #endif return db->accounts; } diff --git a/src/login/ipban.h b/src/login/ipban.h index e6851d8dd..b4f3ac51b 100644 --- a/src/login/ipban.h +++ b/src/login/ipban.h @@ -1,8 +1,8 @@ // Copyright (c) Athena Dev Teams - Licensed under GNU GPL // For more information, see LICENCE in the main folder -#ifndef _LOGIN_IPBAN_H_ -#define _LOGIN_IPBAN_H_ +#ifndef LOGIN_IPBAN_H +#define LOGIN_IPBAN_H #include "../common/cbasetypes.h" @@ -22,4 +22,4 @@ void ipban_log(uint32 ip); bool ipban_config_read(const char* key, const char* value); -#endif /* _LOGIN_IPBAN_H_ */ +#endif /* LOGIN_IPBAN_H */ diff --git a/src/login/ipban_sql.c b/src/login/ipban_sql.c index 74f45e418..081f28d84 100644 --- a/src/login/ipban_sql.c +++ b/src/login/ipban_sql.c @@ -2,6 +2,15 @@ // See the LICENSE file // Portions Copyright (c) Athena Dev Teams +#define HERCULES_CORE + +#include "ipban.h" + +#include <stdlib.h> +#include <string.h> + +#include "login.h" +#include "loginlog.h" #include "../common/cbasetypes.h" #include "../common/db.h" #include "../common/malloc.h" @@ -9,11 +18,6 @@ #include "../common/socket.h" #include "../common/strlib.h" #include "../common/timer.h" -#include "login.h" -#include "ipban.h" -#include "loginlog.h" -#include <stdlib.h> -#include <string.h> // global sql settings static char global_db_hostname[32] = "127.0.0.1"; diff --git a/src/login/login.c b/src/login/login.c index c12c9bde9..0488ae4ed 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -2,6 +2,18 @@ // See the LICENSE file // Portions Copyright (c) Athena Dev Teams +#define HERCULES_CORE + +#include "login.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "account.h" +#include "ipban.h" +#include "loginlog.h" +#include "../common/HPM.h" #include "../common/core.h" #include "../common/db.h" #include "../common/malloc.h" @@ -12,15 +24,6 @@ #include "../common/strlib.h" #include "../common/timer.h" #include "../common/utils.h" -#include "../common/HPM.h" -#include "account.h" -#include "ipban.h" -#include "login.h" -#include "loginlog.h" - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> struct Login_Config login_config; @@ -170,7 +173,7 @@ static int online_data_cleanup_sub(DBKey key, DBData *data, va_list ap) static int online_data_cleanup(int tid, int64 tick, int id, intptr_t data) { online_db->foreach(online_db, online_data_cleanup_sub); return 0; -} +} //-------------------------------------------------------------------- @@ -284,7 +287,7 @@ int lan_subnetcheck(uint32 ip) } //---------------------------------- -// Reading Lan Support configuration +// Reading LAN Support configuration //---------------------------------- int login_lan_config_read(const char *lancfgName) { @@ -721,13 +724,13 @@ int parse_fromchar(int fd) 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", 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", 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", server[id].name, account_id, ip); acc.unban_time = 0; accounts->save(accounts, &acc); } @@ -842,18 +845,20 @@ int parse_fromchar(int fd) WFIFOHEAD(fd,183); WFIFOW(fd,0) = 0x2737; safestrncpy((char*)WFIFOP(fd,2), acc.userid, NAME_LENGTH); - if (u_group >= acc.group_id) { + if (u_group >= acc.group_id) safestrncpy((char*)WFIFOP(fd,26), acc.pass, 33); - } + else + memset(WFIFOP(fd,26), '\0', 33); safestrncpy((char*)WFIFOP(fd,59), acc.email, 40); safestrncpy((char*)WFIFOP(fd,99), acc.last_ip, 16); WFIFOL(fd,115) = acc.group_id; safestrncpy((char*)WFIFOP(fd,119), acc.lastlogin, 24); WFIFOL(fd,143) = acc.logincount; WFIFOL(fd,147) = acc.state; - if (u_group >= acc.group_id) { + if (u_group >= acc.group_id) safestrncpy((char*)WFIFOP(fd,151), acc.pincode, 5); - } + else + memset(WFIFOP(fd,151), '\0', 5); safestrncpy((char*)WFIFOP(fd,156), acc.birthdate, 11); WFIFOL(fd,167) = map_fd; WFIFOL(fd,171) = u_fd; @@ -909,7 +914,7 @@ int mmo_auth_new(const char* userid, const char* pass, const char sex, const cha // check if the account doesn't exist already if( accounts->load_str(accounts, &acc, userid) ) { - ShowNotice("Attempt of creation of an already existant account (account: %s_%c, pass: %s, received pass: %s)\n", userid, sex, acc.pass, pass); + ShowNotice("Attempt of creation of an already existing account (account: %s_%c, pass: %s, received pass: %s)\n", userid, sex, acc.pass, pass); return 1; // 1 = Incorrect Password } @@ -1042,8 +1047,9 @@ int mmo_auth(struct login_session_data* sd, bool isServer) { for( i = 0; i < 16; i++ ) sprintf(&smd5[i * 2], "%02x", sd->client_hash[i]); + smd5[32] = '\0'; - ShowNotice("Invalid client hash (account: %s, pass: %s, sent md5: %d, ip: %s)\n", sd->userid, sd->passwd, smd5, ip); + ShowNotice("Invalid client hash (account: %s, pass: %s, sent md5: %s, ip: %s)\n", sd->userid, sd->passwd, smd5, ip); return 5; } } @@ -1101,12 +1107,12 @@ void login_auth_ok(struct login_session_data* sd) WFIFOSET(fd,3); return; } else if( login_config.min_group_id_to_connect >= 0 && login_config.group_id_to_connect == -1 && sd->group_id < login_config.min_group_id_to_connect ) { - ShowStatus("Connection refused: the minium group id required for connection is %d (account: %s, group: %d).\n", login_config.min_group_id_to_connect, sd->userid, sd->group_id); + ShowStatus("Connection refused: the minimum group id required for connection is %d (account: %s, group: %d).\n", login_config.min_group_id_to_connect, sd->userid, sd->group_id); WFIFOHEAD(fd,3); WFIFOW(fd,0) = 0x81; WFIFOB(fd,2) = 1; // 01 = Server closed WFIFOSET(fd,3); - return; + return; } server_num = 0; @@ -1306,7 +1312,7 @@ int parse_login(int fd) // Perform ip-ban check if( login_config.ipban && ipban_check(ipl) ) { - ShowStatus("Connection refused: IP isn't authorised (deny/allow, ip: %s).\n", ip); + ShowStatus("Connection refused: IP isn't authorized (deny/allow, ip: %s).\n", ip); login_log(ipl, "unknown", -3, "ip banned"); WFIFOHEAD(fd,23); WFIFOW(fd,0) = 0x6a; @@ -1689,8 +1695,7 @@ int login_config_read(const char* cfgName) //-------------------------------------- // Function called at exit of the server //-------------------------------------- -void do_final(void) -{ +int do_final(void) { int i; struct client_hash_node *hn = login_config.client_hash_nodes; @@ -1730,6 +1735,7 @@ void do_final(void) } ShowStatus("Finished.\n"); + return EXIT_SUCCESS; } //------------------------------ @@ -1769,7 +1775,7 @@ int do_init(int argc, char** argv) { int i; - // intialize engine (to accept config settings) + // initialize engine (to accept config settings) account_engine[0].db = account_engine[0].constructor(); // read login-server configuration @@ -1824,7 +1830,7 @@ int do_init(int argc, char** argv) HPM->config_read(NULL, 0); HPM->event(HPET_INIT); - // server port open & binding + // server port open & binding if( (login_fd = make_listen_bind(login_config.login_ip,login_config.login_port)) == -1 ) { ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",login_config.login_port); exit(EXIT_FAILURE); diff --git a/src/login/login.h b/src/login/login.h index 14c361a15..9b9d1e82c 100644 --- a/src/login/login.h +++ b/src/login/login.h @@ -2,11 +2,11 @@ // See the LICENSE file // Portions Copyright (c) Athena Dev Teams -#ifndef _LOGIN_LOGIN_H_ -#define _LOGIN_LOGIN_H_ +#ifndef LOGIN_LOGIN_H +#define LOGIN_LOGIN_H -#include "../common/mmo.h" // NAME_LENGTH,SEX_* #include "../common/core.h" // CORE_ST_LAST +#include "../common/mmo.h" // NAME_LENGTH,SEX_* enum E_LOGINSERVER_ST { @@ -72,7 +72,7 @@ struct Login_Config { unsigned int ip_sync_interval; // interval (in minutes) to execute a DNS/IP update (for dynamic IPs) bool log_login; // whether to log login server actions or not char date_format[32]; // date format used in messages - bool new_account_flag,new_acc_length_limit; // autoregistration via _M/_F ? / if yes minimum length is 4? + bool new_account_flag,new_acc_length_limit; // auto-registration via _M/_F ? / if yes minimum length is 4? int start_limited_time; // new account expiration time (-1: unlimited) bool use_md5_passwds; // work with password hashes instead of plaintext passwords? int group_id_to_connect; // required group id to connect @@ -100,4 +100,4 @@ extern struct mmo_char_server server[MAX_SERVERS]; extern struct Login_Config login_config; -#endif /* _LOGIN_LOGIN_H_ */ +#endif /* LOGIN_LOGIN_H */ diff --git a/src/login/loginlog.h b/src/login/loginlog.h index 730fb6e62..52e18f3d1 100644 --- a/src/login/loginlog.h +++ b/src/login/loginlog.h @@ -1,9 +1,10 @@ // Copyright (c) Athena Dev Teams - Licensed under GNU GPL // For more information, see LICENCE in the main folder -#ifndef _LOGIN_LOGINLOG_H_ -#define _LOGIN_LOGINLOG_H_ +#ifndef LOGIN_LOGINLOG_H +#define LOGIN_LOGINLOG_H +#include "../common/cbasetypes.h" unsigned long loginlog_failedattempts(uint32 ip, unsigned int minutes); void login_log(uint32 ip, const char* username, int rcode, const char* message); @@ -11,5 +12,4 @@ bool loginlog_init(void); bool loginlog_final(void); bool loginlog_config_read(const char* w1, const char* w2); - -#endif /* _LOGIN_LOGINLOG_H_ */ +#endif /* LOGIN_LOGINLOG_H */ diff --git a/src/login/loginlog_sql.c b/src/login/loginlog_sql.c index 231ac783b..2c0b1cc03 100644 --- a/src/login/loginlog_sql.c +++ b/src/login/loginlog_sql.c @@ -2,13 +2,18 @@ // See the LICENSE file // Portions Copyright (c) Athena Dev Teams +#define HERCULES_CORE + +#include "loginlog.h" + +#include <string.h> +#include <stdlib.h> // exit + #include "../common/cbasetypes.h" #include "../common/mmo.h" #include "../common/socket.h" #include "../common/sql.h" #include "../common/strlib.h" -#include <string.h> -#include <stdlib.h> // exit // global sql settings (in ipban_sql.c) static char global_db_hostname[32] = "127.0.0.1"; @@ -30,7 +35,7 @@ static Sql* sql_handle = NULL; static bool enabled = false; -// Returns the number of failed login attemps by the ip in the last minutes. +// 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; diff --git a/src/login/sql/CMakeLists.txt b/src/login/sql/CMakeLists.txt deleted file mode 100644 index 46cf4db02..000000000 --- a/src/login/sql/CMakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ - -# -# login sql -# -if( BUILD_SQL_SERVERS ) -message( STATUS "Creating target login-server" ) -set( SQL_LOGIN_HEADERS - "${SQL_LOGIN_SOURCE_DIR}/account.h" - "${SQL_LOGIN_SOURCE_DIR}/ipban.h" - "${SQL_LOGIN_SOURCE_DIR}/login.h" - "${SQL_LOGIN_SOURCE_DIR}/loginlog.h" - ) -set( SQL_LOGIN_SOURCES - "${SQL_LOGIN_SOURCE_DIR}/account_sql.c" - "${SQL_LOGIN_SOURCE_DIR}/ipban_sql.c" - "${SQL_LOGIN_SOURCE_DIR}/login.c" - "${SQL_LOGIN_SOURCE_DIR}/loginlog_sql.c" - ) -set( DEPENDENCIES common_sql ) -set( LIBRARIES ${GLOBAL_LIBRARIES} ) -set( INCLUDE_DIRS ${GLOBAL_INCLUDE_DIRS} ${COMMON_BASE_INCLUDE_DIRS} ) -set( DEFINITIONS "${GLOBAL_DEFINITIONS} ${COMMON_BASE_DEFINITIONS} -DWITH_SQL" ) -set( SOURCE_FILES ${COMMON_BASE_HEADERS} ${COMMON_SQL_HEADERS} ${SQL_LOGIN_HEADERS} ${SQL_LOGIN_SOURCES} ) -source_group( common FILES ${COMMON_BASE_HEADERS} ${COMMON_SQL_HEADERS} ) -source_group( login FILES ${SQL_LOGIN_HEADERS} ${SQL_LOGIN_SOURCES} ) -include_directories( ${INCLUDE_DIRS} ) -add_executable( login-server ${SOURCE_FILES} ) -add_dependencies( login-server ${DEPENDENCIES} ) -target_link_libraries( login-server ${LIBRARIES} ${DEPENDENCIES} ) -set_target_properties( login-server PROPERTIES COMPILE_FLAGS "${DEFINITIONS}" ) -if( INSTALL_COMPONENT_RUNTIME ) - cpack_add_component( Runtime_loginserver_sql DESCRIPTION "login-server (sql version)" DISPLAY_NAME "login-server" GROUP Runtime ) - install( TARGETS login-server - DESTINATION "." - COMPONENT Runtime_loginserver_sql ) -endif( INSTALL_COMPONENT_RUNTIME ) -set( TARGET_LIST ${TARGET_LIST} login-server CACHE INTERNAL "" ) -message( STATUS "Creating target login-server - done" ) -endif( BUILD_SQL_SERVERS ) |