1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-27 06:47:45 +00:00

Majorly simplified and improved the cmake setup.

Going forward it will be alot easier to maintain.

TODO: simplify path definitions

Conflicts:
	src/servers/Server_Lobby/CMakeLists.txt
	src/servers/Server_REST/CMakeLists.txt
	src/servers/Server_Zone/CMakeLists.txt
This commit is contained in:
Mordred Admin 2017-09-13 11:46:17 +02:00
parent a8d6d8e8fd
commit 924a4b3973
26 changed files with 464 additions and 780 deletions

View file

@ -22,9 +22,9 @@ before_build:
- git submodule update --init - git submodule update --init
- mkdir build - mkdir build
- cd build - cd build
- cmake .. -G "Visual Studio 14 2015" - cmake .. -G "Visual Studio 14 2015"
- cmake --build . --target ALL_BUILD --config Debug - cmake --build . --target ALL_BUILD --config Debug
build_script: build_script:
- cd .. - cd ..
- sh sql_import.sh - sh sql_import.sh

1
.gitignore vendored
View file

@ -54,6 +54,7 @@ cmake_install.cmake
install_manifest.txt install_manifest.txt
compile_commands.json compile_commands.json
CTestTestfile.cmake CTestTestfile.cmake
*.cbp
# Binary Template # Binary Template
*.bt *.bt

View file

@ -8,7 +8,7 @@ before_install:
- sudo apt-get update - sudo apt-get update
- sudo apt-get install gcc-4.9 g++-4.9 gcc-4.9-multilib g++-4.9-multilib cmake3 -y - sudo apt-get install gcc-4.9 g++-4.9 gcc-4.9-multilib g++-4.9-multilib cmake3 -y
- sudo apt-get install libboost-dev libboost-all-dev libmysqlclient-dev -y - sudo apt-get install libboost-dev libboost-all-dev libmysqlclient-dev -y
- sudo apt-get install libmysqlcppconn-dev -y
compiler: compiler:
- gcc - gcc
@ -19,4 +19,4 @@ script:
- cd build - cd build
- cmake .. -DSAPPHIRE_BOOST_VER="1.54.0" -DCMAKE_CXX_COMPILER=g++-4.9 -DCMAKE_C_COMPILER=gcc-4.9 && make -j 3 - cmake .. -DSAPPHIRE_BOOST_VER="1.54.0" -DCMAKE_CXX_COMPILER=g++-4.9 -DCMAKE_C_COMPILER=gcc-4.9 && make -j 3
- cd .. - cd ..
- bash sql_import.sh - bash sql_import.sh

View file

@ -8,8 +8,11 @@ set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}) set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(PROJECT_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include) set(PROJECT_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
##########################################################################
# Boost stuff
# boost stuff
# set(Boost_DEBUG 1) # set(Boost_DEBUG 1)
if(NOT SAPPHIRE_BOOST_VER) if(NOT SAPPHIRE_BOOST_VER)
@ -17,8 +20,31 @@ if(NOT SAPPHIRE_BOOST_VER)
endif() endif()
set(SAPPHIRE_BOOST_FOLDER_NAME boost_1_60_0) set(SAPPHIRE_BOOST_FOLDER_NAME boost_1_60_0)
##########################################################################
# Common and library path
set(SERVER_COMMON_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/servers/Server_Common")
set(LIBRARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/libraries")
##########################################################################
# Dependencies and compiler settings
include( "cmake/boost.cmake" )
include( "cmake/mysql.cmake" )
include( "cmake/compiler.cmake" )
##########################################################################
# Common include folders
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/libraries/external/ChaiScript-6.0.0/include/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/libraries/sapphire/datReader/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src")
include_directories("${PROJECT_INCLUDE_DIR}") include_directories("${PROJECT_INCLUDE_DIR}")
include_directories("${PROJECT_SOURCE_DIR}") include_directories("${PROJECT_SOURCE_DIR}")
##########################################################################
# Common lib folders
link_directories(${MYSQLCONNECTORCPP_LIBRARIES})
link_directories(${SERVER_COMMON_DIR})
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/libraries/sapphire/datReader)
add_subdirectory("src/servers") add_subdirectory("src/servers")
add_subdirectory("src/libraries/sapphire/datReader") add_subdirectory("src/libraries/sapphire/datReader")

39
cmake/boost.cmake Normal file
View file

@ -0,0 +1,39 @@
if(UNIX)
find_package(Boost ${SAPPHIRE_BOOST_VER} COMPONENTS system)
if(Boost_FOUND)
set(BOOST_LIBRARY_DIR ${Boost_LIBRARY_DIR})
else()
if (EXISTS /opt/build_libs/${SAPPHIRE_BOOST_FOLDER_NAME})
set(Boost_INCLUDE_DIR /opt/build_libs/${SAPPHIRE_BOOST_FOLDER_NAME})
set(BOOST_LIBRARYDIR /opt/build_libs/${SAPPHIRE_BOOST_FOLDER_NAME}/stage/lib)
else()
message(FATAL_ERROR "Unable to find boost ${SAPPHIRE_BOOST_VER} package!")
endif()
endif()
else()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../src/libraries/external/${SAPPHIRE_BOOST_FOLDER_NAME})
message(STATUS "Using boost in /libraries/external")
set(Boost_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../src/libraries/external/${SAPPHIRE_BOOST_FOLDER_NAME})
set(BOOST_LIBRARYDIR ${CMAKE_CURRENT_SOURCE_DIR}/../src/libraries/external/${SAPPHIRE_BOOST_FOLDER_NAME}/lib32-msvc-14.0)
else()
find_package(Boost ${SAPPHIRE_BOOST_VER} COMPONENTS system)
if(Boost_FOUND)
set(BOOST_LIBRARY_DIR ${Boost_LIBRARY_DIR})
elseif ((EXISTS $ENV{BOOST_ROOT_DIR}) AND (EXISTS $ENV{BOOST_LIB_DIR}))
set(Boost_INCLUDE_DIR $ENV{BOOST_ROOT_DIR})
set(BOOST_LIBRARYDIR $ENV{BOOST_LIB_DIR})
else()
message(FATAL_ERROR "SapphireError: Unable to find boost ${SAPPHIRE_BOOST_VER} package and environment variables BOOST_ROOT_DIR and BOOST_LIB_DIR not set!")
endif()
endif()
endif()
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost ${SAPPHIRE_BOOST_VER} COMPONENTS log log_setup thread date_time filesystem system)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${BOOST_LIBRARYDIR})

19
cmake/compiler.cmake Normal file
View file

@ -0,0 +1,19 @@
if(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
else()
add_definitions(-D_WIN32_WINNT=0x601)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHc")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
# edit and continue
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Disabling /SAFESEH")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
endif()
endif()

17
cmake/mysql.cmake Normal file
View file

@ -0,0 +1,17 @@
if(UNIX)
include_directories("/usr/include/mysql/")
else()
include_directories("${LIBRARY_DIR}/external/MySQL/")
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
# 32 bit link
link_directories(${LIBRARY_DIR}/external/MySQL/x86)
link_directories(${LIBRARY_DIR}/external/zlib/x86)
else()
# 64 bit link
link_directories(${LIBRARY_DIR}/external/MySQL/x64)
link_directories(${LIBRARY_DIR}/external/zlib/x64)
endif()
endif()

View file

@ -9,7 +9,6 @@ set(PROJECT_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
include_directories("${PROJECT_INCLUDE_DIR}") include_directories("${PROJECT_INCLUDE_DIR}")
include_directories("${PROJECT_SOURCE_DIR}") include_directories("${PROJECT_SOURCE_DIR}")
add_subdirectory(${PROJECT_SOURCE_DIR}/Server_Common) add_subdirectory(${PROJECT_SOURCE_DIR}/Server_Common)
add_subdirectory(${PROJECT_SOURCE_DIR}/Server_Lobby) add_subdirectory(${PROJECT_SOURCE_DIR}/Server_Lobby)
add_subdirectory(${PROJECT_SOURCE_DIR}/Server_REST) add_subdirectory(${PROJECT_SOURCE_DIR}/Server_REST)

View file

@ -1,53 +1,6 @@
cmake_minimum_required(VERSION 2.6) cmake_minimum_required(VERSION 2.6)
project(Sapphire) project(Sapphire)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/sapphire/datReader/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/ChaiScript-6.0.0/include/")
if(UNIX)
include_directories("/usr/include/mysql/")
message(STATUS "Setting GCC flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
find_package(Boost ${SAPPHIRE_BOOST_VER} COMPONENTS log log_setup thread date_time filesystem system)
if(Boost_FOUND)
set(BOOST_LIBRARY_DIR ${Boost_LIBRARY_DIR})
else()
if (EXISTS /opt/build_libs/${SAPPHIRE_BOOST_FOLDER_NAME})
set(Boost_INCLUDE_DIR /opt/build_libs/${SAPPHIRE_BOOST_FOLDER_NAME})
set(BOOST_LIBRARYDIR /opt/build_libs/${SAPPHIRE_BOOST_FOLDER_NAME}/stage/lib)
else()
message(FATAL_ERROR "Unable to find boost ${SAPPHIRE_BOOST_VER} package!")
endif()
endif()
else()
add_definitions(-D_WIN32_WINNT=0x601)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/MySQL/")
message(STATUS "Setting MSVC flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHc")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/${SAPPHIRE_BOOST_FOLDER_NAME})
message(STATUS "Using boost in /libraries/external")
set(Boost_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/${SAPPHIRE_BOOST_FOLDER_NAME})
set(BOOST_LIBRARYDIR ${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/${SAPPHIRE_BOOST_FOLDER_NAME}/lib32-msvc-14.0)
else()
find_package(Boost ${SAPPHIRE_BOOST_VER} COMPONENTS log log_setup thread date_time filesystem system)
if(Boost_FOUND)
set(BOOST_LIBRARY_DIR ${Boost_LIBRARY_DIR})
elseif ((EXISTS $ENV{BOOST_ROOT_DIR}) AND (EXISTS $ENV{BOOST_LIB_DIR}))
set(Boost_INCLUDE_DIR $ENV{BOOST_ROOT_DIR})
set(BOOST_LIBRARYDIR $ENV{BOOST_LIB_DIR})
else()
message(FATAL_ERROR "SapphireError: Unable to find boost ${SAPPHIRE_BOOST_VER} package and environment variables BOOST_ROOT_DIR and BOOST_LIB_DIR not set!")
endif()
endif()
endif()
set(Boost_USE_STATIC_LIBS ON)
file(GLOB UTILS_PUBLIC_INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*") file(GLOB UTILS_PUBLIC_INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*")
file(GLOB UTILS_SOURCE_FILES file(GLOB UTILS_SOURCE_FILES
"${CMAKE_CURRENT_SOURCE_DIR}*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}*.cpp"
@ -61,15 +14,9 @@ file(GLOB UTILS_SOURCE_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/Script/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/Script/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Util/*.cpp") "${CMAKE_CURRENT_SOURCE_DIR}/Util/*.cpp")
find_package(Boost ${SAPPHIRE_BOOST_VER} COMPONENTS log log_setup thread date_time filesystem system)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${BOOST_LIBRARYDIR})
link_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/sapphire/datReader/")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_library(Common ${UTILS_PUBLIC_INCLUDE_FILES} ${UTILS_SOURCE_FILES} Network/PacketDef/Lobby/ServerLobbyDef.h) add_library(Common ${UTILS_PUBLIC_INCLUDE_FILES} ${UTILS_SOURCE_FILES})
set_target_properties(Common PROPERTIES set_target_properties(Common PROPERTIES
CXX_STANDARD 14 CXX_STANDARD 14
@ -82,7 +29,7 @@ set_target_properties(Common PROPERTIES
) )
if (UNIX) if (UNIX)
target_link_libraries(Common xivdat mysqlclient) target_link_libraries( Common xivdat mysqlclient )
else() else()
target_link_libraries(Common xivdat libmysql) target_link_libraries( Common xivdat libmysql )
endif() endif()

View file

@ -33,10 +33,8 @@ bool QueryResult::nextRow()
MYSQL_ROW row = mysql_fetch_row( m_result ); MYSQL_ROW row = mysql_fetch_row( m_result );
auto length = mysql_fetch_lengths( m_result ); auto length = mysql_fetch_lengths( m_result );
if( row == NULL ) if( row == nullptr )
{
return false; return false;
}
for( uint32_t i = 0; i < m_fieldCount; ++i ) for( uint32_t i = 0; i < m_fieldCount; ++i )
{ {
@ -49,10 +47,25 @@ bool QueryResult::nextRow()
return true; return true;
} }
Field *QueryResult::fetch()
{
return m_currentRow;
}
uint32_t QueryResult::getFieldCount() const
{
return m_fieldCount;
}
uint32_t QueryResult::getRowCount() const
{
return m_rowCount;
}
Database::Database() Database::Database()
{ {
m_port = 0; m_port = 0;
_counter = 0; m_counter = 0;
m_pConnections = nullptr; m_pConnections = nullptr;
m_connectionCount = -1; // Not connected. m_connectionCount = -1; // Not connected.
} }
@ -62,9 +75,7 @@ Database::~Database()
for( int32_t i = 0; i < m_connectionCount; ++i ) for( int32_t i = 0; i < m_connectionCount; ++i )
{ {
if( m_pConnections[i].conn != nullptr ) if( m_pConnections[i].conn != nullptr )
{
mysql_close( m_pConnections[i].conn ); mysql_close( m_pConnections[i].conn );
}
} }
delete[] m_pConnections; delete[] m_pConnections;
@ -77,21 +88,18 @@ bool Database::initialize( const DatabaseParams& params )
MYSQL * temp2; MYSQL * temp2;
my_bool my_true = true; my_bool my_true = true;
g_log.Log( Core::LoggingSeverity::info, "Database: Connecting to " + params.hostname + ", database " + params.databaseName + "..." ); g_log.info( "Database: Connecting to " + params.hostname + ", database " + params.databaseName + "..." );
m_pConnections = new DatabaseConnection[params.connectionCount]; m_pConnections = new DatabaseConnection[params.connectionCount];
for( i = 0; i < params.connectionCount; ++i ) for( i = 0; i < params.connectionCount; ++i )
{ {
temp = mysql_init( NULL ); temp = mysql_init( nullptr );
if( mysql_options( temp, MYSQL_SET_CHARSET_NAME, "utf8" ) ) if( mysql_options( temp, MYSQL_SET_CHARSET_NAME, "utf8" ) )
{ g_log.error( "Database: Could not set utf8 character set." );
g_log.Log( Core::LoggingSeverity::error, "Database: Could not set utf8 character set." );
}
if( mysql_options( temp, MYSQL_OPT_RECONNECT, &my_true ) ) if( mysql_options( temp, MYSQL_OPT_RECONNECT, &my_true ) )
{ g_log.error( "Database: MYSQL_OPT_RECONNECT could not be set, "
g_log.Log( Core::LoggingSeverity::error, "Database: MYSQL_OPT_RECONNECT could not be set, connection drops may occur but will be counteracted." ); "connection drops may occur but will be counteracted." );
}
temp2 = mysql_real_connect( temp, temp2 = mysql_real_connect( temp,
params.hostname.c_str(), params.hostname.c_str(),
@ -99,11 +107,11 @@ bool Database::initialize( const DatabaseParams& params )
params.password.c_str(), params.password.c_str(),
params.databaseName.c_str(), params.databaseName.c_str(),
params.port, params.port,
NULL, nullptr,
0 ); 0 );
if( temp2 == NULL ) if( temp2 == nullptr )
{ {
g_log.Log( Core::LoggingSeverity::fatal, "Database: Connection failed due to: `%s`" + std::string( mysql_error( temp ) ) ); g_log.fatal( "Database: Connection failed due to: `%s`" + std::string( mysql_error( temp ) ) );
return false; return false;
} }
@ -116,139 +124,54 @@ bool Database::initialize( const DatabaseParams& params )
uint64_t Database::getNextUId() uint64_t Database::getNextUId()
{ {
execute( "INSERT INTO uniqueiddata( IdName ) VALUES( 'NOT_SET' );" ); execute( std::string( "INSERT INTO uniqueiddata( IdName ) VALUES( 'NOT_SET' );" ) );
auto res = query( "SELECT LAST_INSERT_ID();" ); auto res = query( "SELECT LAST_INSERT_ID();" );
if( !res ) if( !res )
{
return 0; return 0;
}
Db::Field *field = res->fetch(); Db::Field *field = res->fetch();
return field[0].getUInt64(); return field[0].get< uint64_t >();
} }
DatabaseConnection * Database::getFreeConnection() DatabaseConnection * Database::getFreeConnection()
{ {
uint32_t i = 0; uint32_t i = 0;
for( ;;) while( true )
{ {
DatabaseConnection * con = &m_pConnections[( ( i++ ) % m_connectionCount )]; DatabaseConnection * con = &m_pConnections[( ( i++ ) % m_connectionCount )];
if( con->lock.try_lock() ) if( con->lock.try_lock() )
{
return con; return con;
}
// sleep every 20 iterations, otherwise this can cause 100% cpu if the db link goes dead // sleep every 20 iterations, otherwise this can cause 100% cpu if the db link goes dead
if( !( i % 20 ) ) if( !( i % 20 ) )
{
std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
}
} }
// shouldn't be reached
return NULL;
} }
boost::shared_ptr<QueryResult> Database::query( const std::string& QueryString ) boost::shared_ptr< QueryResult > Database::query( const std::string& QueryString )
{ {
// Send the query // Send the query
boost::shared_ptr<QueryResult> qResult( nullptr ); boost::shared_ptr< QueryResult > qResult( nullptr );
DatabaseConnection * con = getFreeConnection(); DatabaseConnection * con = getFreeConnection();
if( _SendQuery( con, QueryString.c_str(), false ) ) if( sendQuery( con, QueryString.c_str(), false ) )
{ qResult = boost::shared_ptr< QueryResult >( storeQueryResult( con ) );
qResult = boost::shared_ptr<QueryResult>( _StoreQueryResult( con ) );
}
con->lock.unlock(); con->lock.unlock();
return qResult; return qResult;
} }
QueryResult * Database::queryNA( const char* QueryString )
{
// Send the query
QueryResult * qResult = NULL;
DatabaseConnection * con = getFreeConnection();
if( _SendQuery( con, QueryString, false ) )
{
qResult = _StoreQueryResult( con );
}
con->lock.unlock();
return qResult;
}
QueryResult * Database::fQuery( const char * QueryString, DatabaseConnection * con ) {
// Send the query
QueryResult * qResult = NULL;
if( _SendQuery( con, QueryString, false ) )
{
qResult = _StoreQueryResult( con );
}
return qResult;
}
void Database::fWaitExecute( const char * QueryString, DatabaseConnection * con )
{
// Send the query
_SendQuery( con, QueryString, false );
}
bool Database::execute( const char* QueryString, ... ) {
char query[16384];
va_list vlist;
va_start( vlist, QueryString );
vsnprintf( query, 16384, QueryString, vlist );
va_end( vlist );
return waitExecuteNA( query );
}
bool Database::execute( const std::string& QueryString ) bool Database::execute( const std::string& QueryString )
{ {
return waitExecuteNA( QueryString.c_str() );
}
bool Database::executeNA( const char* QueryString )
{
return waitExecuteNA( QueryString );
}
//this will wait for completion
bool Database::waitExecute( const char* QueryString, ... )
{
char sql[16384];
va_list vlist;
va_start( vlist, QueryString );
vsnprintf( sql, 16384, QueryString, vlist );
va_end( vlist );
DatabaseConnection * con = getFreeConnection(); DatabaseConnection * con = getFreeConnection();
bool Result = _SendQuery( con, sql, false ); bool Result = sendQuery( con, QueryString, false );
con->lock.unlock(); con->lock.unlock();
return Result; return Result;
} }
bool Database::waitExecuteNA( const char* QueryString )
{
DatabaseConnection * con = getFreeConnection();
bool Result = _SendQuery( con, QueryString, false );
con->lock.unlock();
return Result;
}
void Database::freeQueryResult( QueryResult * p ) void Database::freeQueryResult( QueryResult * p )
{ {
delete p; delete p;
@ -261,12 +184,9 @@ std::string Database::escapeString( std::string Escape )
DatabaseConnection * con = getFreeConnection(); DatabaseConnection * con = getFreeConnection();
const char * ret; const char * ret;
if( mysql_real_escape_string( con->conn, a2, Escape.c_str(), ( uint32_t ) Escape.length() ) == 0 ) if( mysql_real_escape_string( con->conn, a2, Escape.c_str(), ( uint32_t ) Escape.length() ) == 0 )
{
ret = Escape.c_str(); ret = Escape.c_str();
} else
else {
ret = a2; ret = a2;
}
con->lock.unlock(); con->lock.unlock();
return std::string( ret ); return std::string( ret );
@ -288,41 +208,36 @@ std::string Database::escapeString( const char * esc, DatabaseConnection * con )
char a2[16384] = { 0 }; char a2[16384] = { 0 };
const char * ret; const char * ret;
if( mysql_real_escape_string( con->conn, a2, ( char* ) esc, ( uint32_t ) strlen( esc ) ) == 0 ) if( mysql_real_escape_string( con->conn, a2, ( char* ) esc, ( uint32_t ) strlen( esc ) ) == 0 )
{
ret = esc; ret = esc;
}
else else
{
ret = a2; ret = a2;
}
return std::string( ret ); return std::string( ret );
} }
bool Database::_SendQuery( DatabaseConnection *con, const char* Sql, bool Self ) bool Database::sendQuery( DatabaseConnection *con, const std::string &sql, bool Self )
{ {
//dunno what it does ...leaving untouched int32_t result = mysql_query( con->conn, sql.c_str() );
int32_t result = mysql_query( con->conn, Sql );
if( result > 0 ) if( result > 0 )
{ {
if( Self == false && _HandleError( con, mysql_errno( con->conn ) ) ) if( Self == false && handleError( con, mysql_errno( con->conn ) ) )
{ {
// Re-send the query, the connection was successful. // Re-send the query, the connection was successful.
// The true on the end will prevent an endless loop here, as it will // The true on the end will prevent an endless loop here, as it will
// stop after sending the query twice. // stop after sending the query twice.
result = _SendQuery( con, Sql, true ); result = sendQuery(con, sql, true);
} }
else else
{ {
g_log.Log( Core::LoggingSeverity::error, "Database: query failed " + std::string( mysql_error( con->conn ) ) ); g_log.error( "Database: query failed " + std::string( mysql_error( con->conn ) ) );
g_log.Log( Core::LoggingSeverity::error, "\t" + std::string( Sql ) ); g_log.error( "\t" + std::string( sql ) );
} }
} }
return ( result == 0 ? true : false ); return ( result == 0 ? true : false );
} }
bool Database::_HandleError( DatabaseConnection * con, uint32_t ErrorNumber ) bool Database::handleError( DatabaseConnection *con, uint32_t ErrorNumber )
{ {
// Handle errors that should cause a reconnect to the CDatabase. // Handle errors that should cause a reconnect to the CDatabase.
switch( ErrorNumber ) { switch( ErrorNumber ) {
@ -332,42 +247,42 @@ bool Database::_HandleError( DatabaseConnection * con, uint32_t ErrorNumber )
case 2055: // Lost connection to sql server - system error case 2055: // Lost connection to sql server - system error
{ {
// Let's instruct a reconnect to the db when we encounter these errors. // Let's instruct a reconnect to the db when we encounter these errors.
return _Reconnect( con ); return reconnect( con );
}break; }
} }
return false; return false;
} }
QueryResult * Database::_StoreQueryResult( DatabaseConnection * con ) QueryResult * Database::storeQueryResult( DatabaseConnection * con )
{ {
QueryResult *res; QueryResult* res;
MYSQL_RES * pRes = mysql_store_result( con->conn ); MYSQL_RES* pRes = mysql_store_result( con->conn );
uint32_t uRows = ( uint32_t ) mysql_affected_rows( con->conn ); auto uRows = mysql_affected_rows( con->conn );
uint32_t uFields = ( uint32_t ) mysql_field_count( con->conn ); auto uFields = mysql_field_count( con->conn );
if( uRows == 0 || uFields == 0 || pRes == 0 ) if( uRows == 0 || uFields == 0 || pRes == 0 )
{ {
if( pRes != NULL ) if( pRes != nullptr )
{
mysql_free_result( pRes ); mysql_free_result( pRes );
}
return NULL; return nullptr;
} }
res = new QueryResult( pRes, uFields, uRows ); res = new QueryResult( pRes,
static_cast< uint32_t >( uFields ),
static_cast< uint32_t >( uRows ) );
res->nextRow(); res->nextRow();
return res; return res;
} }
bool Database::_Reconnect( DatabaseConnection * conn ) bool Database::reconnect( DatabaseConnection * conn )
{ {
MYSQL * temp; MYSQL * temp;
MYSQL * temp2; MYSQL * temp2;
temp = mysql_init( NULL ); temp = mysql_init( nullptr );
temp2 = mysql_real_connect( temp, temp2 = mysql_real_connect( temp,
m_hostname.c_str(), m_hostname.c_str(),
@ -375,19 +290,17 @@ bool Database::_Reconnect( DatabaseConnection * conn )
m_password.c_str(), m_password.c_str(),
m_databaseName.c_str(), m_databaseName.c_str(),
m_port, m_port,
NULL, nullptr,
0 ); 0 );
if( temp2 == NULL ) if( temp2 == nullptr )
{ {
g_log.Log( Core::LoggingSeverity::error, "Database: Could not reconnect to database because of " + std::string( mysql_error( temp ) ) ); g_log.error( "Database: Could not reconnect to database -> " + std::string( mysql_error( temp ) ) );
mysql_close( temp ); mysql_close( temp );
return false; return false;
} }
if( conn->conn != NULL ) if( conn->conn != nullptr )
{
mysql_close( conn->conn ); mysql_close( conn->conn );
}
conn->conn = temp; conn->conn = temp;
return true; return true;
@ -404,13 +317,63 @@ void Database::shutdown()
{ {
for( int32_t i = 0; i < m_connectionCount; ++i ) for( int32_t i = 0; i < m_connectionCount; ++i )
{ {
if( m_pConnections[i].conn != NULL ) if( m_pConnections[i].conn != nullptr )
{ {
mysql_close( m_pConnections[i].conn ); mysql_close( m_pConnections[i].conn );
m_pConnections[i].conn = NULL; m_pConnections[i].conn = nullptr;
} }
} }
} }
const std::string &Database::getHostName()
{
return m_hostname;
}
const std::string &Database::getDatabaseName()
{
return m_databaseName;
}
void Field::setValue( char *value )
{
m_pValue = value;
}
void Field::setLength( uint32_t value )
{
m_size = value;
}
std::string Field::getString() const
{
if( !m_pValue )
return "";
return std::string( m_pValue );
}
void Field::getBinary( char *dstBuf, uint16_t size ) const
{
if( m_pValue )
memcpy( dstBuf, m_pValue, size );
else
dstBuf = nullptr;
}
float Field::getFloat() const
{
return m_pValue ? static_cast< float >( atof( m_pValue ) ) : 0;
}
bool Field::getBool() const
{
return m_pValue ? atoi( m_pValue ) > 0 : false;
}
uint32_t Field::getLength() const
{
return m_size;
}
} }
} }

View file

@ -10,245 +10,132 @@
#include <string.h> #include <string.h>
namespace Core { namespace Core {
namespace Db { namespace Db {
// CField is used to access db-query resultsets class Field
class Field {
public:
// set value
void setValue( char* value );
void setLength( uint32_t value );
std::string getString() const;
void getBinary( char* dstBuf, uint16_t size ) const;
float getFloat() const;
bool getBool() const;
template< class T >
__inline T get() const
{ {
public: if( !m_pValue )
return 0;
// set value return static_cast< T >( atol( m_pValue ) );
__inline void setValue( char* value ) }
{
m_pValue = value;
}
// set value uint32_t getLength() const;
__inline void setLength( uint32_t value )
{
m_size = value;
}
// return as string private:
__inline const char *getString() char *m_pValue;
{ uint32_t m_size;
};
return m_pValue ? m_pValue : "";
}
// return as string
__inline void getBinary( char* dstBuf, uint16_t size )
{
if( m_pValue )
{
memcpy( dstBuf, m_pValue, size );
}
else
{
dstBuf = NULL;
}
}
// return as float
__inline float getFloat()
{
return m_pValue ? static_cast< float >( atof( m_pValue ) ) : 0;
}
// return as bool
__inline bool getBool()
{
return m_pValue ? atoi( m_pValue ) > 0 : false;
}
// return as unsigned 8 bit integer
__inline uint8_t getUInt8()
{
return m_pValue ? static_cast< uint8_t >( atol( m_pValue ) ) : 0;
}
// return as signed 8 bit integer
__inline int8_t getInt8()
{
return m_pValue ? static_cast< int8_t >( atol( m_pValue ) ) : 0;
}
// return as unsigned 16 bit integer
__inline uint16_t getUInt16()
{
return m_pValue ? static_cast< uint16_t >( atol( m_pValue ) ) : 0;
}
// return as signed 16 bit integer
__inline int16_t getInt16()
{
return m_pValue ? static_cast< int16_t >( atol( m_pValue ) ) : 0;
}
// return as unsigned 32 bit integer
__inline uint32_t getUInt32()
{
return m_pValue ? static_cast< uint32_t >( atol( m_pValue ) ) : 0;
}
// return as signed 8 bit integer
__inline int32_t getInt32()
{
return m_pValue ? static_cast< int32_t >( atol( m_pValue ) ) : 0;
}
__inline uint32_t getLength()
{
return m_size;
}
// return as unsigned 64 bit integer
uint64_t getUInt64()
{
if( m_pValue )
{
#ifdef _WIN32
uint64_t value;
sscanf( m_pValue, "%I64d", &value );
return value;
#else
uint64_t value;
sscanf( m_pValue, "%Lu", &value );
return value;
#endif
}
else
return 0;
}
private:
char *m_pValue;
uint32_t m_size;
};
class QueryResult class QueryResult
{ {
public: public:
QueryResult( MYSQL_RES *res, uint32_t fields, uint32_t rows ); QueryResult( MYSQL_RES *res, uint32_t fields, uint32_t rows );
~QueryResult(); ~QueryResult();
bool nextRow(); bool nextRow();
void Delete()
{
delete this;
}
__inline Field* fetch() Field* fetch();
{ uint32_t getFieldCount() const;
return m_currentRow; uint32_t getRowCount() const;
}
__inline uint32_t getFieldCount() const
{
return m_fieldCount;
}
__inline uint32_t getRowCount() const
{
return m_rowCount;
}
protected: protected:
uint32_t m_fieldCount; uint32_t m_fieldCount;
uint32_t m_rowCount; uint32_t m_rowCount;
Field *m_currentRow; Field *m_currentRow;
MYSQL_RES *m_result; MYSQL_RES *m_result;
}; };
struct DatabaseConnection struct DatabaseConnection
{ {
std::mutex lock; std::mutex lock;
MYSQL *conn; MYSQL *conn;
}; };
struct DatabaseParams struct DatabaseParams
{ {
std::string hostname; std::string hostname;
std::string username; std::string username;
std::string password; std::string password;
std::string databaseName; std::string databaseName;
uint16_t port; uint16_t port;
uint32_t bufferSize; uint32_t bufferSize;
uint32_t connectionCount; uint32_t connectionCount;
}; };
class Database class Database
{ {
public: public:
Database(); Database();
virtual ~Database(); virtual ~Database();
/************************************************************************/ bool initialize( const DatabaseParams& params );
/* Virtual Functions */
/************************************************************************/
bool initialize( const DatabaseParams& params );
void shutdown(); void shutdown();
boost::shared_ptr<QueryResult> query( const std::string& QueryString ); boost::shared_ptr< QueryResult > query( const std::string& QueryString );
QueryResult* queryNA( const char* QueryString ); bool waitExecuteNA( const char* QueryString );//Wait For Request Completion
QueryResult* fQuery( const char * QueryString, DatabaseConnection *con ); bool execute( const char* QueryString, ... );
void fWaitExecute( const char * QueryString, DatabaseConnection *con ); bool execute( const std::string& QueryString );
bool waitExecute( const char* QueryString, ... );//Wait For Request Completion
bool waitExecuteNA( const char* QueryString );//Wait For Request Completion
bool execute( const char* QueryString, ... );
bool execute( const std::string& QueryString );
bool executeNA( const char* QueryString );
__inline const std::string& getHostName() const std::string& getHostName();
{
return m_hostname;
}
__inline const std::string& getDatabaseName() const std::string& getDatabaseName();
{
return m_databaseName;
}
std::string escapeString( std::string Escape ); std::string escapeString( std::string Escape );
void escapeLongString( const char * str, uint32_t len, std::stringstream& out ); void escapeLongString( const char * str, uint32_t len, std::stringstream& out );
std::string escapeString( const char * esc, DatabaseConnection *con ); std::string escapeString( const char * esc, DatabaseConnection *con );
void freeQueryResult( QueryResult * p ); void freeQueryResult( QueryResult * p );
DatabaseConnection *getFreeConnection(); DatabaseConnection *getFreeConnection();
void cleanupLibs(); void cleanupLibs();
/* database is killed off manually. */ /* database is killed off manually. */
void onShutdown() {} void onShutdown() {}
uint64_t getNextUId(); uint64_t getNextUId();
protected: protected:
// actual query function // actual query function
bool _SendQuery( DatabaseConnection *con, const char* Sql, bool Self ); bool sendQuery( DatabaseConnection *con, const std::string &sql, bool Self );
QueryResult * _StoreQueryResult( DatabaseConnection * con ); QueryResult * storeQueryResult( DatabaseConnection * con );
bool _HandleError( DatabaseConnection *conn, uint32_t ErrorNumber ); bool handleError( DatabaseConnection *conn, uint32_t ErrorNumber );
bool _Reconnect( DatabaseConnection *conn ); bool reconnect( DatabaseConnection *conn );
DatabaseConnection *m_pConnections; DatabaseConnection *m_pConnections;
uint32_t _counter; uint32_t m_counter;
/////////////////////////////// ///////////////////////////////
int32_t m_connectionCount; int32_t m_connectionCount;
// For reconnecting a broken connection // For reconnecting a broken connection
std::string m_hostname; std::string m_hostname;
std::string m_username; std::string m_username;
std::string m_password; std::string m_password;
std::string m_databaseName; std::string m_databaseName;
uint32_t m_port; uint32_t m_port;
}; };
} }
} }
#endif #endif

View file

@ -2,80 +2,9 @@ cmake_minimum_required(VERSION 2.6)
cmake_policy(SET CMP0015 NEW) cmake_policy(SET CMP0015 NEW)
project(Sapphire) project(Sapphire)
include_directories("../../libraries/external/ChaiScript-6.0.0/include/")
include_directories("../../libraries/sapphire/datReader/")
include_directories("../")
file(GLOB SERVER_PUBLIC_INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*") file(GLOB SERVER_PUBLIC_INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*")
file(GLOB SERVER_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}*.c*") file(GLOB SERVER_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}*.c*")
set(SERVER_COMMON_DIR ../Server_Common)
set(Boost_USE_STATIC_LIBS ON)
if(UNIX)
include_directories("/usr/include/mysql/")
message(STATUS "Setting GCC flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
find_package(Boost ${SAPPHIRE_BOOST_VER} COMPONENTS log log_setup thread date_time filesystem system)
if(Boost_FOUND)
set(BOOST_LIBRARY_DIR ${Boost_LIBRARY_DIR})
else()
if (EXISTS /opt/build_libs/${SAPPHIRE_BOOST_FOLDER_NAME})
set(Boost_INCLUDE_DIR /opt/build_libs/${SAPPHIRE_BOOST_FOLDER_NAME})
set(BOOST_LIBRARYDIR /opt/build_libs/${SAPPHIRE_BOOST_FOLDER_NAME}/stage/lib)
find_package(Boost ${SAPPHIRE_BOOST_VER} COMPONENTS log log_setup thread date_time filesystem system)
else()
message(FATAL_ERROR "Unable to find boost ${SAPPHIRE_BOOST_VER} package!")
endif()
endif()
else()
add_definitions(-D_WIN32_WINNT=0x601)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/MySQL/")
message(STATUS "Setting MSVC flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHc")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
# edit and continue
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Disabling /SAFESEH")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
endif()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/${SAPPHIRE_BOOST_FOLDER_NAME})
message(STATUS "Using boost in /libraries/external")
set(Boost_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/${SAPPHIRE_BOOST_FOLDER_NAME})
set(BOOST_LIBRARYDIR ${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/${SAPPHIRE_BOOST_FOLDER_NAME}/lib32-msvc-14.0)
else()
find_package(Boost ${SAPPHIRE_BOOST_VER} COMPONENTS log log_setup thread date_time filesystem system)
if(Boost_FOUND)
set(BOOST_LIBRARY_DIR ${Boost_LIBRARY_DIR})
elseif ((EXISTS $ENV{BOOST_ROOT_DIR}) AND (EXISTS $ENV{BOOST_LIB_DIR}))
set(Boost_INCLUDE_DIR $ENV{BOOST_ROOT_DIR})
set(BOOST_LIBRARYDIR $ENV{BOOST_LIB_DIR})
else()
message(FATAL_ERROR "SapphireError: Unable to find boost ${SAPPHIRE_BOOST_VER} package and environment variables BOOST_ROOT_DIR and BOOST_LIB_DIR not set!")
endif()
endif()
endif()
include_directories(${Boost_INCLUDE_DIR})
link_directories(${BOOST_LIBRARYDIR})
link_directories(${SERVER_COMMON_DIR})
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/sapphire/datReader)
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
# 32 bit link
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/MySQL/x86)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/zlib/x86)
else()
# 64 bit link
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/MySQL/x64)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/zlib/x64)
endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../../../bin/") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../../../bin/")
add_executable(server_lobby ${SERVER_PUBLIC_INCLUDE_FILES} ${SERVER_SOURCE_FILES}) add_executable(server_lobby ${SERVER_PUBLIC_INCLUDE_FILES} ${SERVER_SOURCE_FILES})

View file

@ -2,80 +2,9 @@ cmake_minimum_required(VERSION 2.6)
cmake_policy(SET CMP0015 NEW) cmake_policy(SET CMP0015 NEW)
project(Sapphire) project(Sapphire)
include_directories("../../libraries/external/ChaiScript-6.0.0/include/")
include_directories("../../libraries/sapphire/datReader/")
include_directories("../")
file(GLOB SERVER_PUBLIC_INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*") file(GLOB SERVER_PUBLIC_INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*")
file(GLOB SERVER_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}*.c*") file(GLOB SERVER_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}*.c*")
set(SERVER_COMMON_DIR ../Server_Common)
set(Boost_USE_STATIC_LIBS ON)
if(UNIX)
include_directories("/usr/include/mysql/")
message(STATUS "Setting GCC flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
find_package(Boost ${SAPPHIRE_BOOST_VER} COMPONENTS log log_setup thread date_time filesystem system)
if(Boost_FOUND)
set(BOOST_LIBRARY_DIR ${Boost_LIBRARY_DIR})
else()
if (EXISTS /opt/build_libs/${SAPPHIRE_BOOST_FOLDER_NAME})
set(Boost_INCLUDE_DIR /opt/build_libs/${SAPPHIRE_BOOST_FOLDER_NAME})
set(BOOST_LIBRARYDIR /opt/build_libs/${SAPPHIRE_BOOST_FOLDER_NAME}/stage/lib)
find_package(Boost ${SAPPHIRE_BOOST_VER} COMPONENTS log log_setup thread date_time filesystem system)
else()
message(FATAL_ERROR "Unable to find boost ${SAPPHIRE_BOOST_VER} package!")
endif()
endif()
else()
add_definitions(-D_WIN32_WINNT=0x601)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/MySQL/")
message(STATUS "Setting MSVC flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHc")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
# edit and continue
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Disabling /SAFESEH")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
endif()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/${SAPPHIRE_BOOST_FOLDER_NAME})
message(STATUS "Using boost in /src/lib")
set(Boost_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/${SAPPHIRE_BOOST_FOLDER_NAME})
set(BOOST_LIBRARYDIR ${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/${SAPPHIRE_BOOST_FOLDER_NAME}/lib32-msvc-14.0)
else()
find_package(Boost ${SAPPHIRE_BOOST_VER} COMPONENTS log log_setup thread date_time filesystem system)
if(Boost_FOUND)
set(BOOST_LIBRARY_DIR ${Boost_LIBRARY_DIR})
elseif ((EXISTS $ENV{BOOST_ROOT_DIR}) AND (EXISTS $ENV{BOOST_LIB_DIR}))
set(Boost_INCLUDE_DIR $ENV{BOOST_ROOT_DIR})
set(BOOST_LIBRARYDIR $ENV{BOOST_LIB_DIR})
else()
message(FATAL_ERROR "SapphireError: Unable to find boost ${SAPPHIRE_BOOST_VER} package and environment variables BOOST_ROOT_DIR and BOOST_LIB_DIR not set!")
endif()
endif()
endif()
include_directories(${Boost_INCLUDE_DIR})
link_directories(${BOOST_LIBRARYDIR})
link_directories(${SERVER_COMMON_DIR})
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/sapphire/datReader)
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
# 32 bit link
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/MySQL/x86)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/zlib/x86)
else()
# 64 bit link
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/MySQL/x64)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/zlib/x64)
endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../../../bin/") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../../../bin/")
add_executable(server_rest ${SERVER_PUBLIC_INCLUDE_FILES} ${SERVER_SOURCE_FILES}) add_executable(server_rest ${SERVER_PUBLIC_INCLUDE_FILES} ${SERVER_SOURCE_FILES})
add_dependencies(server_rest Common xivdat) add_dependencies(server_rest Common xivdat)

View file

@ -56,7 +56,7 @@ namespace Core {
memset( m_name, 0, 32 ); memset( m_name, 0, 32 );
strcpy( m_name, field[0].getString() ); strcpy( m_name, field[0].getString().c_str() );
field[1].getBinary( (char*)m_look, 26 ); field[1].getBinary( (char*)m_look, 26 );
@ -67,11 +67,11 @@ namespace Core {
m_lookMap[i] = m_look[i]; m_lookMap[i] = m_look[i];
} }
setBirthDay( field[2].getInt8(), field[3].getInt8() ); setBirthDay( field[2].get< int8_t >(), field[3].get< int8_t >() );
m_guardianDeity = field[4].getInt8(); m_guardianDeity = field[4].get< int8_t >();
m_class = field[5].getInt8(); m_class = field[5].get< int8_t >();
m_contentId = field[7].getUInt64(); m_contentId = field[7].get< uint64_t >();
m_zoneId = field[8].getUInt16(); m_zoneId = field[8].get< uint16_t >();
auto pQR2 = g_database.query( "SELECT * FROM characlass WHERE CharacterId = " + std::to_string( charId ) + ";" ); auto pQR2 = g_database.query( "SELECT * FROM characlass WHERE CharacterId = " + std::to_string( charId ) + ";" );
@ -80,7 +80,7 @@ namespace Core {
for( uint8_t i = 0; i < 25; i++ ) for( uint8_t i = 0; i < 25; i++ )
{ {
uint8_t index = i * 2; uint8_t index = i * 2;
m_classMap[i] = field2[index].getUInt8(); m_classMap[i] = field2[index].get< uint8_t >();
//m_expArray[i] = //m_expArray[i] =
} }
} }

View file

@ -36,7 +36,7 @@ bool Core::Network::SapphireAPI::login( const std::string& username, const std::
return false; return false;
// user found, proceed // user found, proceed
int32_t accountId = pQR->fetch()[0].getUInt32(); int32_t accountId = pQR->fetch()[0].get< uint32_t >();
// session id string generation // session id string generation
srand( ( uint32_t )time( NULL ) + 42 ); srand( ( uint32_t )time( NULL ) + 42 );
@ -96,14 +96,14 @@ bool Core::Network::SapphireAPI::createAccount( const std::string& username, con
// we are clear and can create a new account // we are clear and can create a new account
// get the next free account id // get the next free account id
pQR = g_database.query( "SELECT MAX(account_id) FROM accounts;" ); pQR = g_database.query( "SELECT MAX(account_id) FROM accounts;" );
int32_t accountId = pQR->fetch()[0].getUInt32() + 1; int32_t accountId = pQR->fetch()[0].get< uint32_t >() + 1;
// store the account to the db // store the account to the db
g_database.execute( "INSERT INTO accounts (account_Id, account_name, account_pass, account_created) VALUE(%i, '%s', '%s', %i);", g_database.execute( "INSERT INTO accounts (account_Id, account_name, account_pass, account_created) VALUE( " +
accountId, std::to_string( accountId ) + ", '" +
username.c_str(), username + "', '" +
pass.c_str(), pass + "', " +
time( NULL ) ); std::to_string( time( nullptr ) ) + ");");
if( !login( username, pass, sId ) ) if( !login( username, pass, sId ) )
@ -223,7 +223,7 @@ std::vector<Core::PlayerMinimal> Core::Network::SapphireAPI::getCharList( uint32
Core::Db::Field *field = pQR->fetch(); Core::Db::Field *field = pQR->fetch();
uint32_t charId = field[0].getInt32(); uint32_t charId = field[0].get< uint32_t >();
player.load( charId ); player.load( charId );
@ -257,7 +257,7 @@ uint32_t Core::Network::SapphireAPI::getNextCharId()
return 0x00200001; return 0x00200001;
} }
charId = pQR->fetch()[0].getUInt32() + 1; charId = pQR->fetch()[0].get< uint32_t >() + 1;
if( charId < 0x00200001 ) if( charId < 0x00200001 )
{ {
return 0x00200001; return 0x00200001;
@ -277,7 +277,7 @@ uint64_t Core::Network::SapphireAPI::getNextContentId()
return 0x0040000001000001; return 0x0040000001000001;
} }
contentId = pQR->fetch()[0].getUInt64() + 1; contentId = pQR->fetch()[0].get< uint64_t >() + 1;
if( contentId < 0x0040000001000001 ) if( contentId < 0x0040000001000001 )
{ {
return 0x0040000001000001; return 0x0040000001000001;
@ -306,4 +306,4 @@ bool Core::Network::SapphireAPI::removeSession( const std::string& sId )
m_sessionMap.erase( sId ); m_sessionMap.erase( sId );
return true; return true;
} }

View file

@ -292,53 +292,54 @@ void Core::Entity::Player::teleport( uint16_t aetheryteId, uint8_t type )
{ {
auto data = g_exdData.getAetheryteInfo( aetheryteId ); auto data = g_exdData.getAetheryteInfo( aetheryteId );
if( data != nullptr ) if( data == nullptr )
{ {
return;
setStateFlag( PlayerStateFlag::BetweenAreas );
sendStateFlags();
auto z_pos = g_zoneMgr.getZonePosition( data->levelId );
Common::FFXIVARR_POSITION3 pos;
pos.x = 0;
pos.y = 0;
pos.z = 0;
float rot = 0;
if( z_pos != nullptr )
{
pos = z_pos->getTargetPosition();
rot = z_pos->getTargetRotation();
}
sendDebug( "Teleport: " + data->placename + " " + data->placename_aethernet +
"(" + std::to_string( data->levelId ) + ")" );
// TODO: this should be simplified and a type created in server_common/common.h.
if( type == 1 ) // teleport
{
prepareZoning( data->target_zone, true, 1, 112 );
sendToInRangeSet( ActorControlPacket142( getId(), ActorDespawnEffect, 0x04 ) );
setZoningType( Common::ZoneingType::Teleport );
}
else if( type == 2 ) // aethernet
{
prepareZoning( data->target_zone, true, 1, 112 );
sendToInRangeSet( ActorControlPacket142( getId(), ActorDespawnEffect, 0x04 ) );
setZoningType( Common::ZoneingType::Teleport );
}
else if( type == 3 ) // return
{
prepareZoning( data->target_zone, true, 1, 111 );
sendToInRangeSet( ActorControlPacket142( getId(), ActorDespawnEffect, 0x03 ) );
setZoningType( Common::ZoneingType::Return );
}
m_queuedZoneing = boost::make_shared< QueuedZoning >( data->target_zone, pos, Util::getTimeMs(), rot );
} }
setStateFlag( PlayerStateFlag::BetweenAreas );
sendStateFlags();
auto z_pos = g_zoneMgr.getZonePosition( data->levelId );
Common::FFXIVARR_POSITION3 pos;
pos.x = 0;
pos.y = 0;
pos.z = 0;
float rot = 0;
if( z_pos != nullptr )
{
pos = z_pos->getTargetPosition();
rot = z_pos->getTargetRotation();
}
sendDebug( "Teleport: " + data->placename + " " + data->placename_aethernet +
"(" + std::to_string( data->levelId ) + ")" );
// TODO: this should be simplified and a type created in server_common/common.h.
if( type == 1 ) // teleport
{
prepareZoning( data->target_zone, true, 1, 112 );
sendToInRangeSet( ActorControlPacket142( getId(), ActorDespawnEffect, 0x04 ) );
setZoningType( Common::ZoneingType::Teleport );
}
else if( type == 2 ) // aethernet
{
prepareZoning( data->target_zone, true, 1, 112 );
sendToInRangeSet( ActorControlPacket142( getId(), ActorDespawnEffect, 0x04 ) );
setZoningType( Common::ZoneingType::Teleport );
}
else if( type == 3 ) // return
{
prepareZoning( data->target_zone, true, 1, 111 );
sendToInRangeSet( ActorControlPacket142( getId(), ActorDespawnEffect, 0x03 ) );
setZoningType( Common::ZoneingType::Return );
}
m_queuedZoneing = boost::make_shared< QueuedZoning >( data->target_zone, pos, Util::getTimeMs(), rot );
} }
void Core::Entity::Player::forceZoneing( uint32_t zoneId ) void Core::Entity::Player::forceZoneing( uint32_t zoneId )

View file

@ -39,20 +39,20 @@ bool Core::Entity::Player::loadActiveQuests()
//g_log.debug( " QUEST_ID: " + std::to_string( field[index].getInt16() ) + " INDEX: " + std::to_string( index ) ); //g_log.debug( " QUEST_ID: " + std::to_string( field[index].getInt16() ) + " INDEX: " + std::to_string( index ) );
if( field[index].getInt16() != 0 ) if( field[index].get< int16_t >() != 0 )
{ {
boost::shared_ptr<QuestActive> pActiveQuest( new QuestActive() ); boost::shared_ptr<QuestActive> pActiveQuest( new QuestActive() );
pActiveQuest->c.questId = field[index].getInt16(); pActiveQuest->c.questId = field[index].get< int16_t >();
pActiveQuest->c.sequence = field[index + 1].getUInt8(); pActiveQuest->c.sequence = field[index + 1].get< uint8_t >();
pActiveQuest->c.flags = field[index + 2].getUInt8(); pActiveQuest->c.flags = field[index + 2].get< uint8_t >();
pActiveQuest->c.UI8A = field[index + 3].getUInt8(); pActiveQuest->c.UI8A = field[index + 3].get< uint8_t >();
pActiveQuest->c.UI8B = field[index + 4].getUInt8(); pActiveQuest->c.UI8B = field[index + 4].get< uint8_t >();
pActiveQuest->c.UI8C = field[index + 5].getUInt8(); pActiveQuest->c.UI8C = field[index + 5].get< uint8_t >();
pActiveQuest->c.UI8D = field[index + 6].getUInt8(); pActiveQuest->c.UI8D = field[index + 6].get< uint8_t >();
pActiveQuest->c.UI8E = field[index + 7].getUInt8(); pActiveQuest->c.UI8E = field[index + 7].get< uint8_t >();
pActiveQuest->c.UI8F = field[index + 8].getUInt8(); pActiveQuest->c.UI8F = field[index + 8].get< uint8_t >();
pActiveQuest->c.padding1 = field[index + 9].getUInt8(); pActiveQuest->c.padding1 = field[index + 9].get< uint8_t >();
m_activeQuests[i] = pActiveQuest; m_activeQuests[i] = pActiveQuest;
m_questIdToQuestIdx[pActiveQuest->c.questId] = i; m_questIdToQuestIdx[pActiveQuest->c.questId] = i;

View file

@ -98,15 +98,15 @@ bool Core::Entity::Player::load( uint32_t charId, Core::SessionPtr pSession )
Db::Field *field = pQR->fetch(); Db::Field *field = pQR->fetch();
strcpy( m_name, field[0].getString() ); strcpy( m_name, field[0].getString().c_str() );
ZonePtr pCurrZone = g_zoneMgr.getZone( field[1].getInt32() ); ZonePtr pCurrZone = g_zoneMgr.getZone( field[1].get< int32_t >() );
m_zoneId = field[1].getInt32(); m_zoneId = field[1].get< int32_t >();
// see if a valid zone could be found for the character // see if a valid zone could be found for the character
if( !pCurrZone ) if( !pCurrZone )
{ {
g_log.error( "[" + char_id_str + "] Zone " + std::to_string( field[1].getInt32() ) + "not found!" ); g_log.error( "[" + char_id_str + "] Zone " + std::to_string( field[1].get< int32_t >() ) + "not found!" );
g_log.error( "[" + char_id_str + "] Setting default zone instead" ); g_log.error( "[" + char_id_str + "] Setting default zone instead" );
// default to new gridania // default to new gridania
@ -119,9 +119,9 @@ bool Core::Entity::Player::load( uint32_t charId, Core::SessionPtr pSession )
setRotation( 0.0f ); setRotation( 0.0f );
} }
m_hp = field[2].getUInt32(); m_hp = field[2].get< uint16_t >();
m_mp = field[3].getUInt32(); m_mp = field[3].get< uint16_t >();
m_tp = 0; m_tp = 0;
m_pos.x = field[6].getFloat(); m_pos.x = field[6].getFloat();
@ -131,22 +131,22 @@ bool Core::Entity::Player::load( uint32_t charId, Core::SessionPtr pSession )
field[11].getBinary( reinterpret_cast< char* >( m_customize ), sizeof( m_customize ) ); field[11].getBinary( reinterpret_cast< char* >( m_customize ), sizeof( m_customize ) );
m_modelMainWeapon = field[12].getUInt64(); m_modelMainWeapon = field[12].get< uint64_t >();
field[14].getBinary( reinterpret_cast< char* >( m_modelEquip ), sizeof( m_modelEquip ) ); field[14].getBinary( reinterpret_cast< char* >( m_modelEquip ), sizeof( m_modelEquip ) );
m_guardianDeity = field[15].getUInt8(); m_guardianDeity = field[15].get< uint8_t >();
m_birthDay = field[16].getUInt8(); m_birthDay = field[16].get< uint8_t >();
m_birthMonth = field[17].getUInt8(); m_birthMonth = field[17].get< uint8_t >();
m_status = static_cast< ActorStatus >( field[18].getUInt8() ); m_status = static_cast< ActorStatus >( field[18].get< uint8_t >() );
m_class = static_cast< ClassJob >( field[19].getUInt8() ); m_class = static_cast< ClassJob >( field[19].get< uint8_t >() );
m_homePoint = field[20].getUInt8(); m_homePoint = field[20].get< uint8_t >();
field[21].getBinary( reinterpret_cast< char* >( m_howTo ), sizeof( m_howTo ) ); field[21].getBinary( reinterpret_cast< char* >( m_howTo ), sizeof( m_howTo ) );
m_contentId = field[22].getUInt64(); m_contentId = field[22].get< uint64_t >();
m_voice = field[23].getUInt32(); m_voice = field[23].get< uint32_t >();
field[24].getBinary( reinterpret_cast< char* >( m_questCompleteFlags ), sizeof( m_questCompleteFlags ) ); field[24].getBinary( reinterpret_cast< char* >( m_questCompleteFlags ), sizeof( m_questCompleteFlags ) );
@ -160,19 +160,19 @@ bool Core::Entity::Player::load( uint32_t charId, Core::SessionPtr pSession )
field[29].getBinary( reinterpret_cast< char* >( m_discovery ), sizeof( m_discovery ) ); field[29].getBinary( reinterpret_cast< char* >( m_discovery ), sizeof( m_discovery ) );
m_startTown = field[30].getInt8(); m_startTown = field[30].get< int8_t >();
m_playTime = field[31].getUInt32(); m_playTime = field[31].get< uint32_t >();
m_bNewAdventurer = field[32].getBool(); m_bNewAdventurer = field[32].getBool();
m_gc = field[33].getUInt8(); m_gc = field[33].get< uint8_t >();
field[34].getBinary( reinterpret_cast< char* >( m_gcRank ), sizeof( m_gcRank ) ); field[34].getBinary( reinterpret_cast< char* >( m_gcRank ), sizeof( m_gcRank ) );
m_cfPenaltyUntil = field[35].getUInt32(); m_cfPenaltyUntil = field[35].get< uint32_t >();
m_openingSequence = field[36].getUInt32(); m_openingSequence = field[36].get< uint32_t >();
m_gmRank = field[37].getUInt8(); m_gmRank = field[37].get< uint8_t >();
m_pCell = nullptr; m_pCell = nullptr;
@ -241,8 +241,8 @@ bool Core::Entity::Player::loadClassData()
for( uint8_t i = 0; i < 25; i++ ) for( uint8_t i = 0; i < 25; i++ )
{ {
uint8_t index = i * 2; uint8_t index = i * 2;
m_classArray[i] = field[index].getUInt8(); m_classArray[i] = field[index].get< uint8_t >();
m_expArray[i] = field[index + 1].getUInt32(); m_expArray[i] = field[index + 1].get< uint32_t >();
} }
return true; return true;
@ -257,9 +257,9 @@ bool Core::Entity::Player::loadSearchInfo()
Db::Field* field = pQR->fetch(); Db::Field* field = pQR->fetch();
m_searchSelectClass = field[1].getUInt8(); m_searchSelectClass = field[1].get< uint8_t >();
m_searchSelectRegion = field[2].getUInt8(); m_searchSelectRegion = field[2].get< uint8_t >();
sprintf( m_searchMessage, field[3].getString() ); sprintf( m_searchMessage, field[3].getString().c_str() );
return true; return true;
} }
@ -405,7 +405,7 @@ void Core::Entity::Player::createUpdateSql()
updateCharaInfoSearch += entry + ", "; updateCharaInfoSearch += entry + ", ";
updateCharaInfoSearch += condition; updateCharaInfoSearch += condition;
g_database.execute( updateCharaInfoSearch.c_str() ); g_database.execute( updateCharaInfoSearch );
} }
if( !charaBaseSet.empty() ) if( !charaBaseSet.empty() )
@ -414,7 +414,7 @@ void Core::Entity::Player::createUpdateSql()
updateCharaBase += entry + ", "; updateCharaBase += entry + ", ";
updateCharaBase += condition; updateCharaBase += condition;
g_database.execute( updateCharaBase.c_str() ); g_database.execute( updateCharaBase );
} }
if( !charaDetailSet.empty() ) if( !charaDetailSet.empty() )
@ -423,7 +423,7 @@ void Core::Entity::Player::createUpdateSql()
updateCharaDetail += entry + ", "; updateCharaDetail += entry + ", ";
updateCharaDetail += condition; updateCharaDetail += condition;
g_database.execute( updateCharaDetail.c_str() ); g_database.execute( updateCharaDetail );
} }
if( !charaClassSet.empty() ) if( !charaClassSet.empty() )
@ -432,7 +432,7 @@ void Core::Entity::Player::createUpdateSql()
updateCharaClass += entry + ", "; updateCharaClass += entry + ", ";
updateCharaClass += condition; updateCharaClass += condition;
g_database.execute( updateCharaClass.c_str() ); g_database.execute( updateCharaClass );
} }
if( !charaQuestSet.empty() ) if( !charaQuestSet.empty() )
@ -441,7 +441,7 @@ void Core::Entity::Player::createUpdateSql()
updateCharaQuest += entry + ", "; updateCharaQuest += entry + ", ";
updateCharaQuest += condition; updateCharaQuest += condition;
g_database.execute( updateCharaQuest.c_str() ); g_database.execute( updateCharaQuest );
} }
m_updateFlags = PlayerSyncFlags::None; m_updateFlags = PlayerSyncFlags::None;

View file

@ -4,10 +4,6 @@ cmake_policy(SET CMP0014 OLD)
project(Sapphire_Zone) project(Sapphire_Zone)
include_directories("../../libraries/external/ChaiScript-6.0.0/include/")
include_directories("../../libraries/sapphire/datReader/")
include_directories("../")
file(GLOB SERVER_PUBLIC_INCLUDE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/* ${CMAKE_CURRENT_SOURCE_DIR}/Script/*) file(GLOB SERVER_PUBLIC_INCLUDE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/* ${CMAKE_CURRENT_SOURCE_DIR}/Script/*)
file(GLOB SERVER_SOURCE_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} file(GLOB SERVER_SOURCE_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
*.c* *.c*
@ -24,77 +20,9 @@ file(GLOB SERVER_SOURCE_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
StatusEffect/*.c* StatusEffect/*.c*
Zone/*.c*) Zone/*.c*)
set(SERVER_COMMON_DIR ../Server_Common)
set(Boost_USE_STATIC_LIBS ON)
if(UNIX)
include_directories("/usr/include/mysql/")
message(STATUS "Setting GCC flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
find_package(Boost ${SAPPHIRE_BOOST_VER} COMPONENTS log log_setup thread date_time filesystem system)
if(Boost_FOUND)
set(BOOST_LIBRARY_DIR ${Boost_LIBRARY_DIR})
else()
if (EXISTS /opt/build_libs/${SAPPHIRE_BOOST_FOLDER_NAME})
set(Boost_INCLUDE_DIR /opt/build_libs/${SAPPHIRE_BOOST_FOLDER_NAME})
set(BOOST_LIBRARYDIR /opt/build_libs/${SAPPHIRE_BOOST_FOLDER_NAME}/stage/lib)
find_package(Boost ${SAPPHIRE_BOOST_VER} COMPONENTS log log_setup thread date_time filesystem system)
else()
message(FATAL_ERROR "Unable to find boost ${SAPPHIRE_BOOST_VER} package!")
endif()
endif()
else()
add_definitions(-D_WIN32_WINNT=0x601)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/MySQL/")
message(STATUS "Setting MSVC flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHc")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
# edit and continue
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Disabling /SAFESEH")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
endif()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/${SAPPHIRE_BOOST_FOLDER_NAME})
message(STATUS "Using boost in /libraries/external")
set(Boost_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/${SAPPHIRE_BOOST_FOLDER_NAME})
set(BOOST_LIBRARYDIR ${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/${SAPPHIRE_BOOST_FOLDER_NAME}/lib32-msvc-14.0)
else()
find_package(Boost ${SAPPHIRE_BOOST_VER} COMPONENTS log log_setup thread date_time filesystem system)
if(Boost_FOUND)
set(BOOST_LIBRARY_DIR ${Boost_LIBRARY_DIR})
elseif ((EXISTS $ENV{BOOST_ROOT_DIR}) AND (EXISTS $ENV{BOOST_LIB_DIR}))
set(Boost_INCLUDE_DIR $ENV{BOOST_ROOT_DIR})
set(BOOST_LIBRARYDIR $ENV{BOOST_LIB_DIR})
else()
message(FATAL_ERROR "SapphireError: Unable to find boost ${SAPPHIRE_BOOST_VER} package and environment variables BOOST_ROOT_DIR and BOOST_LIB_DIR not set!")
endif()
endif()
endif()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Script)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${BOOST_LIBRARYDIR})
link_directories(${SERVER_COMMON_DIR})
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/sapphire/datReader)
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
# 32 bit link
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/MySQL/x86)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/zlib/x86)
else()
# 64 bit link
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/MySQL/x64)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/external/zlib/x64)
endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../../../bin/") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../../../bin/")
add_executable(server_zone ${SERVER_PUBLIC_INCLUDE_FILES} ${SERVER_SOURCE_FILES} Linkshell/Linkshell.cpp Linkshell/Linkshell.h) add_executable(server_zone ${SERVER_PUBLIC_INCLUDE_FILES} ${SERVER_SOURCE_FILES} )
add_dependencies(server_zone Common xivdat) add_dependencies(server_zone Common xivdat)
set_target_properties(server_zone PROPERTIES set_target_properties(server_zone PROPERTIES
@ -113,9 +41,9 @@ if(MSVC)
endif() endif()
if (UNIX) if (UNIX)
target_link_libraries (server_zone Common xivdat pthread mysqlclient dl z) target_link_libraries ( server_zone Common xivdat pthread mysqlclient dl z )
else() else()
target_link_libraries (server_zone Common xivdat libmysql zlib1) target_link_libraries ( server_zone Common xivdat libmysql zlib1 )
endif() endif()
target_link_libraries(server_zone ${Boost_LIBRARIES} ${Boost_LIBRARIES}) target_link_libraries(server_zone ${Boost_LIBRARIES} ${Boost_LIBRARIES} )

View file

@ -243,8 +243,8 @@ void Core::DebugCommandHandler::set( char * data, Core::Entity::PlayerPtr pPlaye
"', '" + std::to_string( map_id ) + "', '" + std::to_string( map_id ) +
"', '" + std::to_string( discover_id ) + "')"; "', '" + std::to_string( discover_id ) + "')";
g_database.execute( query1.c_str() ); g_database.execute( query1 );
g_database.execute( query2.c_str() ); g_database.execute( query2 );
} }

View file

@ -633,15 +633,15 @@ Core::ItemPtr Core::Inventory::loadItem( uint64_t uId )
try try
{ {
Db::Field *itemField = itemRes->fetch(); Db::Field *itemField = itemRes->fetch();
auto itemInfo = g_exdData.getItemInfo( itemField[0].getUInt32() ); auto itemInfo = g_exdData.getItemInfo( itemField[0].get< uint32_t >() );
bool isHq = itemField[2].getUInt8() == 1 ? true : false; bool isHq = itemField[2].get< uint8_t >() == 1 ? true : false;
ItemPtr pItem( new Item( uId, ItemPtr pItem( new Item( uId,
itemInfo->id, itemInfo->id,
itemInfo->model_primary, itemInfo->model_primary,
itemInfo->model_secondary, itemInfo->model_secondary,
static_cast< ItemCategory >( itemInfo->ui_category ), static_cast< ItemCategory >( itemInfo->ui_category ),
isHq ) ); isHq ) );
pItem->setStackSize( itemField[1].getUInt32() ); pItem->setStackSize( itemField[1].get< uint32_t >() );
return pItem; return pItem;
} }
@ -669,11 +669,11 @@ bool Core::Inventory::load()
do do
{ {
uint16_t storageId = field[0].getUInt16(); uint16_t storageId = field[0].get< uint16_t >();
for( int32_t i = 1; i <= 14; i++ ) for( int32_t i = 1; i <= 14; i++ )
{ {
uint64_t uItemId = field[i].getUInt64(); uint64_t uItemId = field[i].get< uint64_t >();
if( uItemId == 0 ) if( uItemId == 0 )
continue; continue;
@ -707,10 +707,10 @@ bool Core::Inventory::load()
do do
{ {
uint16_t storageId = bagField[0].getUInt16(); uint16_t storageId = bagField[0].get< uint16_t >();
for( int32_t i = 1; i <= 25; i++ ) for( int32_t i = 1; i <= 25; i++ )
{ {
uint64_t uItemId = bagField[i].getUInt64(); uint64_t uItemId = bagField[i].get< uint64_t >();
if( uItemId == 0 ) if( uItemId == 0 )
continue; continue;
@ -740,10 +740,10 @@ bool Core::Inventory::load()
do do
{ {
uint16_t storageId = curField[0].getUInt16(); uint16_t storageId = curField[0].get< uint16_t >();
for( int32_t i = 1; i <= 12; i++ ) for( int32_t i = 1; i <= 12; i++ )
{ {
uint64_t uItemId = curField[i].getUInt64(); uint64_t uItemId = curField[i].get< uint64_t >();
if( uItemId == 0 ) if( uItemId == 0 )
continue; continue;
@ -774,10 +774,10 @@ bool Core::Inventory::load()
do do
{ {
uint16_t storageId = crystalField[0].getUInt16(); uint16_t storageId = crystalField[0].get< uint16_t >();
for( int32_t i = 1; i <= 17; i++ ) for( int32_t i = 1; i <= 17; i++ )
{ {
uint64_t uItemId = crystalField[i].getUInt64(); uint64_t uItemId = crystalField[i].get< uint64_t >();
if( uItemId == 0 ) if( uItemId == 0 )
continue; continue;

View file

@ -42,9 +42,8 @@ void Core::ItemContainer::removeItem( uint8_t slotId )
{ {
g_database.execute( "DELETE FROM charaglobalitem " \ g_database.execute( "DELETE FROM charaglobalitem WHERE itemId = " +
"WHERE itemId = %i ", std::to_string( it->second->getUId() ) );
it->second->getUId() );
m_itemMap.erase( it ); m_itemMap.erase( it );

View file

@ -29,8 +29,8 @@ bool Core::LinkshellMgr::loadLinkshells()
do do
{ {
uint32_t linkshellId = field[0].getUInt32(); uint32_t linkshellId = field[0].get< uint32_t >();
uint32_t masterId = field[1].getUInt32(); uint32_t masterId = field[1].get< uint32_t >();
std::string name = field[3].getString(); std::string name = field[3].getString();
auto func = []( std::set< uint64_t >& outList, Db::Field * pField ) auto func = []( std::set< uint64_t >& outList, Db::Field * pField )

View file

@ -350,13 +350,13 @@ void Core::Network::GameConnection::discoveryHandler( const Packets::GamePacket&
Db::Field *field = pQR->fetch(); Db::Field *field = pQR->fetch();
GamePacketNew< FFXIVIpcDiscovery, ServerZoneIpcType > discoveryPacket( pPlayer->getId() ); GamePacketNew< FFXIVIpcDiscovery, ServerZoneIpcType > discoveryPacket( pPlayer->getId() );
discoveryPacket.data().map_id = field[1].getInt16(); discoveryPacket.data().map_id = field[1].get< int16_t >();
discoveryPacket.data().map_part_id = field[2].getInt16(); discoveryPacket.data().map_part_id = field[2].get< int16_t >();
pPlayer->queuePacket( discoveryPacket ); pPlayer->queuePacket( discoveryPacket );
pPlayer->sendNotice( "Discovery ref pos ID: " + std::to_string( ref_position_id ) ); pPlayer->sendNotice( "Discovery ref pos ID: " + std::to_string( ref_position_id ) );
pPlayer->discover( field[1].getInt16(), field[2].getInt16() ); pPlayer->discover( field[1].get< int16_t >(), field[2].get< int16_t >() );
} }

View file

@ -162,24 +162,24 @@ void Zone::loadCellCache()
do do
{ {
Db::Field *field = pQR->fetch(); Db::Field *field = pQR->fetch();
uint32_t id = field[0].getUInt32(); uint32_t id = field[0].get< uint32_t >();
uint32_t targetZoneId = field[1].getUInt32(); uint32_t targetZoneId = field[1].get< uint32_t >();
uint32_t nameId = field[2].getUInt32(); uint32_t nameId = field[2].get< uint32_t >();
uint32_t sizeId = field[3].getUInt32(); uint32_t sizeId = field[3].get< uint32_t >();
uint32_t classJob = field[4].getUInt32(); uint32_t classJob = field[4].get< uint32_t >();
uint32_t displayFlags1 = field[5].getUInt32(); uint32_t displayFlags1 = field[5].get< uint32_t >();
uint32_t displayFlags2 = field[6].getUInt32(); uint32_t displayFlags2 = field[6].get< uint32_t >();
uint32_t level = field[7].getUInt32(); uint32_t level = field[7].get< uint32_t >();
float posX = field[8].getFloat(); float posX = field[8].getFloat();
float posY = field[9].getFloat(); float posY = field[9].getFloat();
float posZ = field[10].getFloat(); float posZ = field[10].getFloat();
uint32_t rotation = field[11].getUInt32(); uint32_t rotation = field[11].get< uint32_t >();
uint32_t mobType = field[12].getUInt32(); uint32_t mobType = field[12].get< uint32_t >();
uint32_t behaviour = field[13].getUInt32(); uint32_t behaviour = field[13].get< uint32_t >();
uint64_t modelMainWeapon = field[14].getUInt32(); uint64_t modelMainWeapon = field[14].get< uint32_t >();
uint64_t modelSubWeapon = field[15].getUInt32(); uint64_t modelSubWeapon = field[15].get< uint32_t >();
uint32_t modelId = field[16].getUInt32(); uint32_t modelId = field[16].get< uint32_t >();
uint32_t type = field[17].getUInt32(); uint32_t type = field[17].get< uint32_t >();
Common::FFXIVARR_POSITION3 pos; Common::FFXIVARR_POSITION3 pos;

View file

@ -34,14 +34,14 @@ namespace Core {
do do
{ {
Db::Field *field = pQR->fetch(); Db::Field *field = pQR->fetch();
uint32_t id = field[0].getUInt32(); uint32_t id = field[0].get< uint32_t >();
uint32_t targetZoneId = field[1].getUInt32(); uint32_t targetZoneId = field[1].get< uint32_t >();
Common::FFXIVARR_POSITION3 pos; Common::FFXIVARR_POSITION3 pos;
pos.x = field[2].getFloat(); pos.x = field[2].getFloat();
pos.y = field[3].getFloat(); pos.y = field[3].getFloat();
pos.z = field[4].getFloat(); pos.z = field[4].getFloat();
float posO = field[5].getFloat(); float posO = field[5].getFloat();
uint32_t radius = field[6].getUInt32(); uint32_t radius = field[6].get< uint32_t >();
m_zonePositionMap[id] = ZonePositionPtr( new ZonePosition( id, targetZoneId, pos, radius, posO ) ); m_zonePositionMap[id] = ZonePositionPtr( new ZonePosition( id, targetZoneId, pos, radius, posO ) );