Initial work for login server to C++ (#2583)

* Initial progression of moving the map-server to C++ format.
* Converted all core files to .cpp and header files to .hpp.
Thanks to @lighta!
This commit is contained in:
lighta 2017-11-08 13:56:41 -04:00 committed by Aleos
parent 728a29d435
commit a587b913fa
19 changed files with 134 additions and 149 deletions

1
.gitignore vendored
View File

@ -152,6 +152,7 @@ Thumbs.db
/.idea/vcs.xml
/.idea/workspace.xml
/build/
/cbuild/
# bat tools
/charserv.bat

View File

@ -7,8 +7,7 @@ set( LOGIN_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "" )
#
if( BUILD_SERVERS )
message( STATUS "Creating target login-server" )
file(GLOB LOGIN_HEADERS ${LOGIN_SOURCE_DIR}/*.h)
file(GLOB LOGIN_SOURCES_C ${LOGIN_SOURCE_DIR}/*.c)
file(GLOB LOGIN_HEADERS ${LOGIN_SOURCE_DIR}/*.hpp)
file(GLOB LOGIN_SOURCES_CXX ${LOGIN_SOURCE_DIR}/*.cpp)
set(LOGIN_SOURCES ${LOGIN_SOURCES_C} ${LOGIN_SOURCES_CXX})
#message( STATUS "LOGIN_SOURCES="${LOGIN_SOURCES})

View File

@ -11,9 +11,9 @@ LIBCONFIG_H = $(shell ls ../../3rdparty/libconfig/*.h)
LIBCONFIG_AR = ../../3rdparty/libconfig/obj/libconfig.a
LIBCONFIG_INCLUDE = -I../../3rdparty/libconfig
LOGIN_OBJ = $(shell ls *.c | sed -e "s/\.c/\.o/g") $(shell ls *.cpp | sed -e "s/\.cpp/\.o/g")
LOGIN_OBJ = $(shell ls *.cpp | sed -e "s/\.cpp/\.o/g")
LOGIN_DIR_OBJ = $(LOGIN_OBJ:%=obj/%)
LOGIN_H = $(shell ls *.h)
LOGIN_H = $(shell ls *.hpp)
HAVE_MYSQL=@HAVE_MYSQL@
ifeq ($(HAVE_MYSQL),yes)

View File

@ -7,14 +7,18 @@
* @author rAthena Dev Team
*/
#include "account.hpp"
#include <stdlib.h>
#include <string.h>
#include <algorithm> //min / max
#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 "account.h"
#include <stdlib.h>
/// global defines
@ -309,10 +313,7 @@ static bool account_db_sql_create(AccountDB* self, struct mmo_account* acc) {
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;
account_id = max((uint32_t) START_ACCOUNT_NUM, account_id);
}
// zero value is prohibited

View File

@ -7,12 +7,9 @@
* @author rAthena Dev Team
*/
#ifndef __ACCOUNT_H_INCLUDED__
#define __ACCOUNT_H_INCLUDED__
#ifdef __cplusplus
extern "C" {
#endif
#pragma once
#ifndef _ACCOUNT_HPP_
#define _ACCOUNT_HPP_
#include "../common/cbasetypes.h"
#include "../common/mmo.h" // ACCOUNT_REG2_NUM
@ -145,8 +142,5 @@ struct AccountDB {
void mmo_send_global_accreg(AccountDB* self, int fd, int account_id, int char_id);
void mmo_save_global_accreg(AccountDB* self, int fd, int account_id, int char_id);
#ifdef __cplusplus
}
#endif
#endif // __ACCOUNT_H_INCLUDED__
#endif /* _ACCOUNT_HPP_ */

View File

@ -8,15 +8,18 @@
* @author rAthena Dev Team
*/
#include "ipban.hpp"
#include <stdlib.h>
#include <string.h>
#include "../common/cbasetypes.h"
#include "../common/showmsg.h"
#include "../common/sql.h"
#include "../common/strlib.h"
#include "../common/timer.h"
#include "login.h"
#include "ipban.h"
#include "loginlog.h"
#include <stdlib.h>
#include "login.hpp"
#include "loginlog.hpp"
// login sql settings
static char ipban_db_hostname[32] = "127.0.0.1";
@ -155,10 +158,10 @@ bool ipban_config_read(const char* key, const char* value) {
safestrncpy(ipban_table, value, sizeof(ipban_table));
else
if( strcmpi(key, "enable") == 0 )
login_config.ipban = (bool)config_switch(value);
login_config.ipban = (config_switch(value) != 0);
else
if( strcmpi(key, "dynamic_pass_failure_ban") == 0 )
login_config.dynamic_pass_failure_ban = (bool)config_switch(value);
login_config.dynamic_pass_failure_ban = (config_switch(value) != 0);
else
if( strcmpi(key, "dynamic_pass_failure_ban_interval") == 0 )
login_config.dynamic_pass_failure_ban_interval = atoi(value);

View File

@ -8,12 +8,9 @@
* @author rAthena Dev Team
*/
#ifndef __IPBAN_H_INCLUDED__
#define __IPBAN_H_INCLUDED__
#ifdef __cplusplus
extern "C" {
#endif
#pragma once
#ifndef _IPBAN_HPP_
#define _IPBAN_HPP_
#include "../common/cbasetypes.h"
@ -51,8 +48,4 @@ void ipban_init(void);
*/
void ipban_final(void);
#ifdef __cplusplus
}
#endif
#endif // __IPBAN_H_INCLUDED__
#endif /* _IPBAN_HPP_ */

View File

@ -155,24 +155,22 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="account.h" />
<ClInclude Include="ipban.h" />
<ClInclude Include="login.h" />
<ClInclude Include="loginchrif.h" />
<ClInclude Include="loginclif.h" />
<ClInclude Include="logincnslif.h" />
<ClInclude Include="loginlog.h" />
<ClInclude Include="account.hpp" />
<ClInclude Include="ipban.hpp" />
<ClInclude Include="login.hpp" />
<ClInclude Include="loginchrif.hpp" />
<ClInclude Include="loginclif.hpp" />
<ClInclude Include="logincnslif.hpp" />
<ClInclude Include="loginlog.hpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="account.c" />
<ClCompile Include="ipban.c" />
<ClCompile Include="login.cpp">
<CompileAs>CompileAsCpp</CompileAs>
</ClCompile>
<ClCompile Include="loginchrif.c" />
<ClCompile Include="loginclif.c" />
<ClCompile Include="logincnslif.c" />
<ClCompile Include="loginlog.c" />
<ClCompile Include="account.cpp" />
<ClCompile Include="ipban.cpp" />
<ClCompile Include="login.cpp"/>
<ClCompile Include="loginchrif.cpp" />
<ClCompile Include="loginclif.cpp" />
<ClCompile Include="logincnslif.cpp" />
<ClCompile Include="loginlog.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -11,45 +11,45 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="account.h">
<ClInclude Include="account.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ipban.h">
<ClInclude Include="ipban.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="login.h">
<ClInclude Include="login.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="loginchrif.h">
<ClInclude Include="loginchrif.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="loginclif.h">
<ClInclude Include="loginclif.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="logincnslif.h">
<ClInclude Include="logincnslif.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="loginlog.h">
<ClInclude Include="loginlog.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="account.c">
<ClCompile Include="account.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ipban.c">
<ClCompile Include="ipban.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="loginchrif.c">
<ClCompile Include="loginchrif.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="loginclif.c">
<ClCompile Include="loginclif.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="logincnslif.c">
<ClCompile Include="logincnslif.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="loginlog.c">
<ClCompile Include="loginlog.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="login.cpp">

View File

@ -9,6 +9,11 @@
*/
#pragma warning(disable:4800)
#include "login.hpp"
#include <stdlib.h>
#include <string.h>
#include <string>
#include "../common/core.h"
#include "../common/db.h"
@ -24,15 +29,12 @@
#include "../common/utils.h"
#include "../common/mmo.h"
#include "../config/core.h"
#include "account.h"
#include "ipban.h"
#include "login.h"
#include "loginlog.h"
#include "loginclif.h"
#include "loginchrif.h"
#include "logincnslif.h"
#include <stdlib.h>
#include "account.hpp"
#include "ipban.hpp"
#include "loginlog.hpp"
#include "loginclif.hpp"
#include "loginchrif.hpp"
#include "logincnslif.hpp"
#define LOGIN_MAX_MSG 30 /// Max number predefined in msg_conf
static char* msg_table[LOGIN_MAX_MSG]; /// Login Server messages_conf

View File

@ -8,17 +8,18 @@
* @author rAthena Dev Team
*/
#ifndef _LOGIN_H_
#define _LOGIN_H_
#pragma once
#ifndef _LOGIN_HPP_
#define _LOGIN_HPP_
#ifdef __cplusplus
extern "C" {
#endif
#include <memory>
#include "../config/core.h"
#include "../common/cbasetypes.h"
#include "../common/mmo.h" // NAME_LENGTH,SEX_*
#include "../common/core.h" // CORE_ST_LAST
#include "account.h"
#include "../config/core.h"
#include "account.hpp"
enum E_LOGINSERVER_ST {
LOGINSERVER_ST_RUNNING = CORE_ST_LAST,
@ -234,8 +235,5 @@ int login_mmo_auth_new(const char* userid, const char* pass, const char sex, con
*/
int login_mmo_auth(struct login_session_data* sd, bool isServer);
#ifdef __cplusplus
}
#endif
#endif /* _LOGIN_H_ */
#endif /* _LOGIN_HPP_ */

View File

@ -7,16 +7,19 @@
* @author rAthena Dev Team
*/
#include "loginchrif.hpp"
#include <stdlib.h>
#include <string.h>
#include "../common/timer.h" //difftick
#include "../common/strlib.h" //safeprint
#include "../common/showmsg.h" //show notice
#include "../common/socket.h" //wfifo session
#include "account.h"
#include "login.h"
#include "loginlog.h"
#include "loginchrif.h"
#include <stdlib.h>
#include "account.hpp"
#include "login.hpp"
#include "loginlog.hpp"
//early declaration
void logchrif_on_disconnect(int id);
@ -52,7 +55,7 @@ int logchrif_sendallwos(int sfd, uint8* buf, size_t len) {
* @param data: unused
* @return 0
*/
static int logchrif_sync_ip_addresses(int tid, unsigned int tick, int id, intptr_t data) {
int logchrif_sync_ip_addresses(int tid, unsigned int tick, int id, intptr_t data) {
uint8 buf[2];
ShowInfo("IP Sync in progress...\n");
WBUFW(buf,0) = 0x2735;

View File

@ -7,12 +7,11 @@
* @author rAthena Dev Team
*/
#ifndef LOGINCHRIF_H
#define LOGINCHRIF_H
#pragma once
#ifndef _LOGINCHRIF_HPP_
#define _LOGINCHRIF_HPP_
#ifdef __cplusplus
extern "C" {
#endif
#include "../common/cbasetypes.h"
/**
* Entry point from char-server to log-server.
@ -48,9 +47,6 @@ void do_shutdown_loginchrif(void);
*/
void do_final_loginchrif(void);
#ifdef __cplusplus
}
#endif
#endif /* LOGINCHRIF_H */
#endif /* _LOGINCHRIF_HPP_ */

View File

@ -7,6 +7,11 @@
* @author rAthena Dev Team
*/
#include "loginclif.hpp"
#include <stdlib.h>
#include <string.h>
#include "../common/timer.h" //difftick
#include "../common/strlib.h" //safeprint
#include "../common/showmsg.h" //show notice
@ -15,14 +20,12 @@
#include "../common/utils.h"
#include "../common/md5calc.h"
#include "../common/random.h"
#include "account.h"
#include "ipban.h" //ipban_check
#include "login.h"
#include "loginlog.h"
#include "loginclif.h"
#include "loginchrif.h"
#include <stdlib.h>
#include "account.hpp"
#include "ipban.hpp" //ipban_check
#include "login.hpp"
#include "loginlog.hpp"
#include "loginchrif.hpp"
/**
* Transmit auth result to client.
@ -484,7 +487,7 @@ int logclif_parse(int fd) {
if( session[fd]->flag.eof )
{
ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip);
ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip);
do_close(fd);
return 0;
}

View File

@ -7,12 +7,9 @@
* @author rAthena Dev Team
*/
#ifndef _LOGINCLIF_H
#define _LOGINCLIF_H
#ifdef __cplusplus
extern "C" {
#endif
#pragma once
#ifndef _LOGINCLIF_HPP_
#define _LOGINCLIF_HPP_
/**
* Entry point from client to log-server.
@ -34,9 +31,5 @@ void do_init_loginclif(void);
*/
void do_final_loginclif(void);
#ifdef __cplusplus
}
#endif
#endif /* _LOGINCLIF_H */
#endif /* _LOGINCLIF_HPP_ */

View File

@ -7,6 +7,11 @@
* @author rAthena Dev Team
*/
#include "logincnslif.hpp"
#include <stdlib.h>
#include <string.h>
#include "../common/mmo.h" //cbasetype + NAME_LENGTH
#include "../common/showmsg.h" //show notice
#include "../common/md5calc.h"
@ -14,10 +19,8 @@
#include "../common/cli.h"
#include "../common/timer.h"
#include "../common/strlib.h"
#include "login.h"
#include "logincnslif.h"
#include <stdlib.h>
#include "login.hpp"
/**
* Login-server console help: starting option info.
@ -121,7 +124,7 @@ int cnslif_parse(const char* buf){
runflag = 0;
}
else if( strcmpi("alive", command) == 0 || strcmpi("status", command) == 0 )
ShowInfo(CL_CYAN"Console: "CL_BOLD"I'm Alive."CL_RESET"\n");
ShowInfo(CL_CYAN "Console: " CL_BOLD "I'm Alive." CL_RESET"\n");
else if( strcmpi("reloadconf", command) == 0 ) {
ShowInfo("Reloading config file \"%s\"\n", login_config.loginconf_name);
login_config_read(login_config.loginconf_name, false);

View File

@ -7,12 +7,18 @@
* @author rAthena Dev Team
*/
#ifndef CONSOLEIF_H
#define CONSOLEIF_H
#pragma once
#ifndef _LOGINCNSLIF_HPP_
#define _LOGINCNSLIF_HPP_
#ifdef __cplusplus
extern "C" {
#endif
/**
* Login-server console help: starting option info.
* Do not rename function used as extern.
* @param do_exit: terminate program execution ?
*/
void display_helpscreen(bool do_exit);
}
/**
* Console Command Parser
@ -33,13 +39,6 @@ int cnslif_parse(const char* buf);
*/
int logcnslif_get_options(int argc, char ** argv);
/**
* Login-server console help: starting option info.
* Do not rename function used as extern.
* @param do_exit: terminate program execution ?
*/
void display_helpscreen(bool do_exit);
/**
* Initialize the module.
* Launched at login-serv start, create db or other long scope variable here.
@ -50,9 +49,6 @@ void do_init_logincnslif(void);
*/
void do_final_logincnslif(void);
#ifdef __cplusplus
}
#endif
#endif /* CONSOLEIF_H */
#endif /* _LOGINCNSLIF_HPP_ */

View File

@ -7,13 +7,17 @@
* @author rAthena Dev Team
*/
#include "loginlog.hpp"
#include <stdlib.h> // exit
#include <string.h>
#include "../common/cbasetypes.h"
#include "../common/mmo.h"
#include "../common/socket.h"
#include "../common/sql.h"
#include "../common/strlib.h"
#include "../common/showmsg.h"
#include <stdlib.h> // exit
// global sql settings (in ipban_sql.c)
static char global_db_hostname[64] = "127.0.0.1"; // Doubled to reflect the change on commit #0f2dd7f

View File

@ -7,12 +7,13 @@
* @author rAthena Dev Team
*/
#ifndef __LOGINLOG_H_INCLUDED__
#define __LOGINLOG_H_INCLUDED__
#pragma once
#ifndef _LOGINLOG_HPP_
#define _LOGINLOG_HPP_
#ifdef __cplusplus
extern "C" {
#endif
#include <memory>
#include "../common/cbasetypes.h"
/**
* Get the number of failed login attempts by the ip in the last minutes.
@ -54,8 +55,5 @@ bool loginlog_init(void);
*/
bool loginlog_final(void);
#ifdef __cplusplus
}
#endif
#endif // __LOGINLOG_H_INCLUDED__
#endif /* _LOGINLOG_HPP_ */