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

1
.gitignore vendored
View file

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

View file

@ -8,7 +8,7 @@ before_install:
- 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 libboost-dev libboost-all-dev libmysqlclient-dev -y
- sudo apt-get install libmysqlcppconn-dev -y
compiler:
- gcc

View file

@ -8,8 +8,11 @@ set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
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)
if(NOT SAPPHIRE_BOOST_VER)
@ -17,8 +20,31 @@ if(NOT SAPPHIRE_BOOST_VER)
endif()
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_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/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_SOURCE_DIR}")
add_subdirectory(${PROJECT_SOURCE_DIR}/Server_Common)
add_subdirectory(${PROJECT_SOURCE_DIR}/Server_Lobby)
add_subdirectory(${PROJECT_SOURCE_DIR}/Server_REST)

View file

@ -1,53 +1,6 @@
cmake_minimum_required(VERSION 2.6)
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_SOURCE_FILES
"${CMAKE_CURRENT_SOURCE_DIR}*.cpp"
@ -61,15 +14,9 @@ file(GLOB UTILS_SOURCE_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/Script/*.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})
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
CXX_STANDARD 14

View file

@ -33,10 +33,8 @@ bool QueryResult::nextRow()
MYSQL_ROW row = mysql_fetch_row( m_result );
auto length = mysql_fetch_lengths( m_result );
if( row == NULL )
{
if( row == nullptr )
return false;
}
for( uint32_t i = 0; i < m_fieldCount; ++i )
{
@ -49,10 +47,25 @@ bool QueryResult::nextRow()
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()
{
m_port = 0;
_counter = 0;
m_counter = 0;
m_pConnections = nullptr;
m_connectionCount = -1; // Not connected.
}
@ -62,10 +75,8 @@ Database::~Database()
for( int32_t i = 0; i < m_connectionCount; ++i )
{
if( m_pConnections[i].conn != nullptr )
{
mysql_close( m_pConnections[i].conn );
}
}
delete[] m_pConnections;
}
@ -77,21 +88,18 @@ bool Database::initialize( const DatabaseParams& params )
MYSQL * temp2;
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];
for( i = 0; i < params.connectionCount; ++i )
{
temp = mysql_init( NULL );
temp = mysql_init( nullptr );
if( mysql_options( temp, MYSQL_SET_CHARSET_NAME, "utf8" ) )
{
g_log.Log( Core::LoggingSeverity::error, "Database: Could not set utf8 character set." );
}
g_log.error( "Database: Could not set utf8 character set." );
if( mysql_options( temp, MYSQL_OPT_RECONNECT, &my_true ) )
{
g_log.Log( Core::LoggingSeverity::error, "Database: MYSQL_OPT_RECONNECT could not be set, connection drops may occur but will be counteracted." );
}
g_log.error( "Database: MYSQL_OPT_RECONNECT could not be set, "
"connection drops may occur but will be counteracted." );
temp2 = mysql_real_connect( temp,
params.hostname.c_str(),
@ -99,11 +107,11 @@ bool Database::initialize( const DatabaseParams& params )
params.password.c_str(),
params.databaseName.c_str(),
params.port,
NULL,
nullptr,
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;
}
@ -116,139 +124,54 @@ bool Database::initialize( const DatabaseParams& params )
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();" );
if( !res )
{
return 0;
}
Db::Field *field = res->fetch();
return field[0].getUInt64();
return field[0].get< uint64_t >();
}
DatabaseConnection * Database::getFreeConnection()
{
uint32_t i = 0;
for( ;;)
while( true )
{
DatabaseConnection * con = &m_pConnections[( ( i++ ) % m_connectionCount )];
if( con->lock.try_lock() )
{
return con;
}
// sleep every 20 iterations, otherwise this can cause 100% cpu if the db link goes dead
if( !( i % 20 ) )
{
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 )
{
// Send the query
boost::shared_ptr< QueryResult > qResult( nullptr );
DatabaseConnection * con = getFreeConnection();
if( _SendQuery( con, QueryString.c_str(), false ) )
{
qResult = boost::shared_ptr<QueryResult>( _StoreQueryResult( con ) );
}
if( sendQuery( con, QueryString.c_str(), false ) )
qResult = boost::shared_ptr< QueryResult >( storeQueryResult( con ) );
con->lock.unlock();
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 )
{
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();
bool Result = _SendQuery( con, sql, false );
bool Result = sendQuery( con, QueryString, false );
con->lock.unlock();
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 )
{
delete p;
@ -261,12 +184,9 @@ std::string Database::escapeString( std::string Escape )
DatabaseConnection * con = getFreeConnection();
const char * ret;
if( mysql_real_escape_string( con->conn, a2, Escape.c_str(), ( uint32_t ) Escape.length() ) == 0 )
{
ret = Escape.c_str();
}
else {
else
ret = a2;
}
con->lock.unlock();
return std::string( ret );
@ -288,41 +208,36 @@ std::string Database::escapeString( const char * esc, DatabaseConnection * con )
char a2[16384] = { 0 };
const char * ret;
if( mysql_real_escape_string( con->conn, a2, ( char* ) esc, ( uint32_t ) strlen( esc ) ) == 0 )
{
ret = esc;
}
else
{
ret = a2;
}
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 );
int32_t result = mysql_query( con->conn, sql.c_str() );
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.
// The true on the end will prevent an endless loop here, as it will
// stop after sending the query twice.
result = _SendQuery( con, Sql, true );
result = sendQuery(con, sql, true);
}
else
{
g_log.Log( Core::LoggingSeverity::error, "Database: query failed " + std::string( mysql_error( con->conn ) ) );
g_log.Log( Core::LoggingSeverity::error, "\t" + std::string( Sql ) );
g_log.error( "Database: query failed " + std::string( mysql_error( con->conn ) ) );
g_log.error( "\t" + std::string( sql ) );
}
}
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.
switch( ErrorNumber ) {
@ -332,42 +247,42 @@ bool Database::_HandleError( DatabaseConnection * con, uint32_t ErrorNumber )
case 2055: // Lost connection to sql server - system error
{
// Let's instruct a reconnect to the db when we encounter these errors.
return _Reconnect( con );
}break;
return reconnect( con );
}
}
return false;
}
QueryResult * Database::_StoreQueryResult( DatabaseConnection * con )
QueryResult * Database::storeQueryResult( DatabaseConnection * con )
{
QueryResult* res;
MYSQL_RES* pRes = mysql_store_result( con->conn );
uint32_t uRows = ( uint32_t ) mysql_affected_rows( con->conn );
uint32_t uFields = ( uint32_t ) mysql_field_count( con->conn );
auto uRows = mysql_affected_rows( con->conn );
auto uFields = mysql_field_count( con->conn );
if( uRows == 0 || uFields == 0 || pRes == 0 )
{
if( pRes != NULL )
{
if( pRes != nullptr )
mysql_free_result( pRes );
return nullptr;
}
return NULL;
}
res = new QueryResult( pRes, uFields, uRows );
res = new QueryResult( pRes,
static_cast< uint32_t >( uFields ),
static_cast< uint32_t >( uRows ) );
res->nextRow();
return res;
}
bool Database::_Reconnect( DatabaseConnection * conn )
bool Database::reconnect( DatabaseConnection * conn )
{
MYSQL * temp;
MYSQL * temp2;
temp = mysql_init( NULL );
temp = mysql_init( nullptr );
temp2 = mysql_real_connect( temp,
m_hostname.c_str(),
@ -375,19 +290,17 @@ bool Database::_Reconnect( DatabaseConnection * conn )
m_password.c_str(),
m_databaseName.c_str(),
m_port,
NULL,
nullptr,
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 );
return false;
}
if( conn->conn != NULL )
{
if( conn->conn != nullptr )
mysql_close( conn->conn );
}
conn->conn = temp;
return true;
@ -404,13 +317,63 @@ void Database::shutdown()
{
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 );
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

@ -12,116 +12,30 @@
namespace Core {
namespace Db {
// CField is used to access db-query resultsets
class Field
{
public:
// set value
__inline void setValue( char* value )
{
m_pValue = value;
}
void setValue( char* value );
void setLength( uint32_t value );
// set value
__inline void setLength( uint32_t value )
{
m_size = value;
}
std::string getString() const;
void getBinary( char* dstBuf, uint16_t size ) const;
float getFloat() const;
bool getBool() const;
// return as string
__inline const char *getString()
template< class T >
__inline T get() const
{
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
if( !m_pValue )
return 0;
return static_cast< T >( atol( m_pValue ) );
}
uint32_t getLength() const;
private:
char *m_pValue;
uint32_t m_size;
@ -135,23 +49,10 @@ namespace Core {
~QueryResult();
bool nextRow();
void Delete()
{
delete this;
}
__inline Field* fetch()
{
return m_currentRow;
}
__inline uint32_t getFieldCount() const
{
return m_fieldCount;
}
__inline uint32_t getRowCount() const
{
return m_rowCount;
}
Field* fetch();
uint32_t getFieldCount() const;
uint32_t getRowCount() const;
protected:
uint32_t m_fieldCount;
@ -183,32 +84,18 @@ namespace Core {
Database();
virtual ~Database();
/************************************************************************/
/* Virtual Functions */
/************************************************************************/
bool initialize( const DatabaseParams& params );
void shutdown();
boost::shared_ptr< QueryResult > query( const std::string& QueryString );
QueryResult* queryNA( const char* QueryString );
QueryResult* fQuery( const char * QueryString, DatabaseConnection *con );
void fWaitExecute( const char * QueryString, DatabaseConnection *con );
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()
{
return m_hostname;
}
const std::string& getHostName();
__inline const std::string& getDatabaseName()
{
return m_databaseName;
}
const std::string& getDatabaseName();
std::string escapeString( std::string Escape );
void escapeLongString( const char * str, uint32_t len, std::stringstream& out );
@ -228,14 +115,14 @@ namespace Core {
protected:
// actual query function
bool _SendQuery( DatabaseConnection *con, const char* Sql, bool Self );
QueryResult * _StoreQueryResult( DatabaseConnection * con );
bool _HandleError( DatabaseConnection *conn, uint32_t ErrorNumber );
bool _Reconnect( DatabaseConnection *conn );
bool sendQuery( DatabaseConnection *con, const std::string &sql, bool Self );
QueryResult * storeQueryResult( DatabaseConnection * con );
bool handleError( DatabaseConnection *conn, uint32_t ErrorNumber );
bool reconnect( DatabaseConnection *conn );
DatabaseConnection *m_pConnections;
uint32_t _counter;
uint32_t m_counter;
///////////////////////////////
int32_t m_connectionCount;

View file

@ -2,80 +2,9 @@ cmake_minimum_required(VERSION 2.6)
cmake_policy(SET CMP0015 NEW)
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_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/")
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)
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_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/")
add_executable(server_rest ${SERVER_PUBLIC_INCLUDE_FILES} ${SERVER_SOURCE_FILES})
add_dependencies(server_rest Common xivdat)

View file

@ -56,7 +56,7 @@ namespace Core {
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 );
@ -67,11 +67,11 @@ namespace Core {
m_lookMap[i] = m_look[i];
}
setBirthDay( field[2].getInt8(), field[3].getInt8() );
m_guardianDeity = field[4].getInt8();
m_class = field[5].getInt8();
m_contentId = field[7].getUInt64();
m_zoneId = field[8].getUInt16();
setBirthDay( field[2].get< int8_t >(), field[3].get< int8_t >() );
m_guardianDeity = field[4].get< int8_t >();
m_class = field[5].get< int8_t >();
m_contentId = field[7].get< uint64_t >();
m_zoneId = field[8].get< uint16_t >();
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++ )
{
uint8_t index = i * 2;
m_classMap[i] = field2[index].getUInt8();
m_classMap[i] = field2[index].get< uint8_t >();
//m_expArray[i] =
}
}

View file

@ -36,7 +36,7 @@ bool Core::Network::SapphireAPI::login( const std::string& username, const std::
return false;
// user found, proceed
int32_t accountId = pQR->fetch()[0].getUInt32();
int32_t accountId = pQR->fetch()[0].get< uint32_t >();
// session id string generation
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
// get the next free account id
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
g_database.execute( "INSERT INTO accounts (account_Id, account_name, account_pass, account_created) VALUE(%i, '%s', '%s', %i);",
accountId,
username.c_str(),
pass.c_str(),
time( NULL ) );
g_database.execute( "INSERT INTO accounts (account_Id, account_name, account_pass, account_created) VALUE( " +
std::to_string( accountId ) + ", '" +
username + "', '" +
pass + "', " +
std::to_string( time( nullptr ) ) + ");");
if( !login( username, pass, sId ) )
@ -223,7 +223,7 @@ std::vector<Core::PlayerMinimal> Core::Network::SapphireAPI::getCharList( uint32
Core::Db::Field *field = pQR->fetch();
uint32_t charId = field[0].getInt32();
uint32_t charId = field[0].get< uint32_t >();
player.load( charId );
@ -257,7 +257,7 @@ uint32_t Core::Network::SapphireAPI::getNextCharId()
return 0x00200001;
}
charId = pQR->fetch()[0].getUInt32() + 1;
charId = pQR->fetch()[0].get< uint32_t >() + 1;
if( charId < 0x00200001 )
{
return 0x00200001;
@ -277,7 +277,7 @@ uint64_t Core::Network::SapphireAPI::getNextContentId()
return 0x0040000001000001;
}
contentId = pQR->fetch()[0].getUInt64() + 1;
contentId = pQR->fetch()[0].get< uint64_t >() + 1;
if( contentId < 0x0040000001000001 )
{
return 0x0040000001000001;

View file

@ -292,8 +292,10 @@ void Core::Entity::Player::teleport( uint16_t aetheryteId, uint8_t type )
{
auto data = g_exdData.getAetheryteInfo( aetheryteId );
if( data != nullptr )
if( data == nullptr )
{
return;
}
setStateFlag( PlayerStateFlag::BetweenAreas );
sendStateFlags();
@ -312,7 +314,6 @@ void Core::Entity::Player::teleport( uint16_t aetheryteId, uint8_t type )
rot = z_pos->getTargetRotation();
}
sendDebug( "Teleport: " + data->placename + " " + data->placename_aethernet +
"(" + std::to_string( data->levelId ) + ")" );
@ -338,7 +339,7 @@ void Core::Entity::Player::teleport( uint16_t aetheryteId, uint8_t type )
m_queuedZoneing = boost::make_shared< QueuedZoning >( data->target_zone, pos, Util::getTimeMs(), rot );
}
}
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 ) );
if( field[index].getInt16() != 0 )
if( field[index].get< int16_t >() != 0 )
{
boost::shared_ptr<QuestActive> pActiveQuest( new QuestActive() );
pActiveQuest->c.questId = field[index].getInt16();
pActiveQuest->c.sequence = field[index + 1].getUInt8();
pActiveQuest->c.flags = field[index + 2].getUInt8();
pActiveQuest->c.UI8A = field[index + 3].getUInt8();
pActiveQuest->c.UI8B = field[index + 4].getUInt8();
pActiveQuest->c.UI8C = field[index + 5].getUInt8();
pActiveQuest->c.UI8D = field[index + 6].getUInt8();
pActiveQuest->c.UI8E = field[index + 7].getUInt8();
pActiveQuest->c.UI8F = field[index + 8].getUInt8();
pActiveQuest->c.padding1 = field[index + 9].getUInt8();
pActiveQuest->c.questId = field[index].get< int16_t >();
pActiveQuest->c.sequence = field[index + 1].get< uint8_t >();
pActiveQuest->c.flags = field[index + 2].get< uint8_t >();
pActiveQuest->c.UI8A = field[index + 3].get< uint8_t >();
pActiveQuest->c.UI8B = field[index + 4].get< uint8_t >();
pActiveQuest->c.UI8C = field[index + 5].get< uint8_t >();
pActiveQuest->c.UI8D = field[index + 6].get< uint8_t >();
pActiveQuest->c.UI8E = field[index + 7].get< uint8_t >();
pActiveQuest->c.UI8F = field[index + 8].get< uint8_t >();
pActiveQuest->c.padding1 = field[index + 9].get< uint8_t >();
m_activeQuests[i] = pActiveQuest;
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();
strcpy( m_name, field[0].getString() );
strcpy( m_name, field[0].getString().c_str() );
ZonePtr pCurrZone = g_zoneMgr.getZone( field[1].getInt32() );
m_zoneId = field[1].getInt32();
ZonePtr pCurrZone = g_zoneMgr.getZone( field[1].get< int32_t >() );
m_zoneId = field[1].get< int32_t >();
// see if a valid zone could be found for the character
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" );
// default to new gridania
@ -119,9 +119,9 @@ bool Core::Entity::Player::load( uint32_t charId, Core::SessionPtr pSession )
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_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 ) );
m_modelMainWeapon = field[12].getUInt64();
m_modelMainWeapon = field[12].get< uint64_t >();
field[14].getBinary( reinterpret_cast< char* >( m_modelEquip ), sizeof( m_modelEquip ) );
m_guardianDeity = field[15].getUInt8();
m_birthDay = field[16].getUInt8();
m_birthMonth = field[17].getUInt8();
m_status = static_cast< ActorStatus >( field[18].getUInt8() );
m_class = static_cast< ClassJob >( field[19].getUInt8() );
m_homePoint = field[20].getUInt8();
m_guardianDeity = field[15].get< uint8_t >();
m_birthDay = field[16].get< uint8_t >();
m_birthMonth = field[17].get< uint8_t >();
m_status = static_cast< ActorStatus >( field[18].get< uint8_t >() );
m_class = static_cast< ClassJob >( field[19].get< uint8_t >() );
m_homePoint = field[20].get< uint8_t >();
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 ) );
@ -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 ) );
m_startTown = field[30].getInt8();
m_playTime = field[31].getUInt32();
m_startTown = field[30].get< int8_t >();
m_playTime = field[31].get< uint32_t >();
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 ) );
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;
@ -241,8 +241,8 @@ bool Core::Entity::Player::loadClassData()
for( uint8_t i = 0; i < 25; i++ )
{
uint8_t index = i * 2;
m_classArray[i] = field[index].getUInt8();
m_expArray[i] = field[index + 1].getUInt32();
m_classArray[i] = field[index].get< uint8_t >();
m_expArray[i] = field[index + 1].get< uint32_t >();
}
return true;
@ -257,9 +257,9 @@ bool Core::Entity::Player::loadSearchInfo()
Db::Field* field = pQR->fetch();
m_searchSelectClass = field[1].getUInt8();
m_searchSelectRegion = field[2].getUInt8();
sprintf( m_searchMessage, field[3].getString() );
m_searchSelectClass = field[1].get< uint8_t >();
m_searchSelectRegion = field[2].get< uint8_t >();
sprintf( m_searchMessage, field[3].getString().c_str() );
return true;
}
@ -405,7 +405,7 @@ void Core::Entity::Player::createUpdateSql()
updateCharaInfoSearch += entry + ", ";
updateCharaInfoSearch += condition;
g_database.execute( updateCharaInfoSearch.c_str() );
g_database.execute( updateCharaInfoSearch );
}
if( !charaBaseSet.empty() )
@ -414,7 +414,7 @@ void Core::Entity::Player::createUpdateSql()
updateCharaBase += entry + ", ";
updateCharaBase += condition;
g_database.execute( updateCharaBase.c_str() );
g_database.execute( updateCharaBase );
}
if( !charaDetailSet.empty() )
@ -423,7 +423,7 @@ void Core::Entity::Player::createUpdateSql()
updateCharaDetail += entry + ", ";
updateCharaDetail += condition;
g_database.execute( updateCharaDetail.c_str() );
g_database.execute( updateCharaDetail );
}
if( !charaClassSet.empty() )
@ -432,7 +432,7 @@ void Core::Entity::Player::createUpdateSql()
updateCharaClass += entry + ", ";
updateCharaClass += condition;
g_database.execute( updateCharaClass.c_str() );
g_database.execute( updateCharaClass );
}
if( !charaQuestSet.empty() )
@ -441,7 +441,7 @@ void Core::Entity::Player::createUpdateSql()
updateCharaQuest += entry + ", ";
updateCharaQuest += condition;
g_database.execute( updateCharaQuest.c_str() );
g_database.execute( updateCharaQuest );
}
m_updateFlags = PlayerSyncFlags::None;

View file

@ -4,10 +4,6 @@ cmake_policy(SET CMP0014 OLD)
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_SOURCE_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
*.c*
@ -24,77 +20,9 @@ file(GLOB SERVER_SOURCE_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
StatusEffect/*.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/")
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)
set_target_properties(server_zone PROPERTIES

View file

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

View file

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

View file

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

View file

@ -29,8 +29,8 @@ bool Core::LinkshellMgr::loadLinkshells()
do
{
uint32_t linkshellId = field[0].getUInt32();
uint32_t masterId = field[1].getUInt32();
uint32_t linkshellId = field[0].get< uint32_t >();
uint32_t masterId = field[1].get< uint32_t >();
std::string name = field[3].getString();
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();
GamePacketNew< FFXIVIpcDiscovery, ServerZoneIpcType > discoveryPacket( pPlayer->getId() );
discoveryPacket.data().map_id = field[1].getInt16();
discoveryPacket.data().map_part_id = field[2].getInt16();
discoveryPacket.data().map_id = field[1].get< int16_t >();
discoveryPacket.data().map_part_id = field[2].get< int16_t >();
pPlayer->queuePacket( discoveryPacket );
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
{
Db::Field *field = pQR->fetch();
uint32_t id = field[0].getUInt32();
uint32_t targetZoneId = field[1].getUInt32();
uint32_t nameId = field[2].getUInt32();
uint32_t sizeId = field[3].getUInt32();
uint32_t classJob = field[4].getUInt32();
uint32_t displayFlags1 = field[5].getUInt32();
uint32_t displayFlags2 = field[6].getUInt32();
uint32_t level = field[7].getUInt32();
uint32_t id = field[0].get< uint32_t >();
uint32_t targetZoneId = field[1].get< uint32_t >();
uint32_t nameId = field[2].get< uint32_t >();
uint32_t sizeId = field[3].get< uint32_t >();
uint32_t classJob = field[4].get< uint32_t >();
uint32_t displayFlags1 = field[5].get< uint32_t >();
uint32_t displayFlags2 = field[6].get< uint32_t >();
uint32_t level = field[7].get< uint32_t >();
float posX = field[8].getFloat();
float posY = field[9].getFloat();
float posZ = field[10].getFloat();
uint32_t rotation = field[11].getUInt32();
uint32_t mobType = field[12].getUInt32();
uint32_t behaviour = field[13].getUInt32();
uint64_t modelMainWeapon = field[14].getUInt32();
uint64_t modelSubWeapon = field[15].getUInt32();
uint32_t modelId = field[16].getUInt32();
uint32_t type = field[17].getUInt32();
uint32_t rotation = field[11].get< uint32_t >();
uint32_t mobType = field[12].get< uint32_t >();
uint32_t behaviour = field[13].get< uint32_t >();
uint64_t modelMainWeapon = field[14].get< uint32_t >();
uint64_t modelSubWeapon = field[15].get< uint32_t >();
uint32_t modelId = field[16].get< uint32_t >();
uint32_t type = field[17].get< uint32_t >();
Common::FFXIVARR_POSITION3 pos;

View file

@ -34,14 +34,14 @@ namespace Core {
do
{
Db::Field *field = pQR->fetch();
uint32_t id = field[0].getUInt32();
uint32_t targetZoneId = field[1].getUInt32();
uint32_t id = field[0].get< uint32_t >();
uint32_t targetZoneId = field[1].get< uint32_t >();
Common::FFXIVARR_POSITION3 pos;
pos.x = field[2].getFloat();
pos.y = field[3].getFloat();
pos.z = field[4].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 ) );