mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-24 21:57:44 +00:00
Refactoring and modernizing
This commit is contained in:
parent
5182439403
commit
13dc04ebb5
425 changed files with 6922 additions and 6542 deletions
1389
src/common/Common.h
1389
src/common/Common.h
File diff suppressed because it is too large
Load diff
|
@ -7,63 +7,64 @@
|
|||
#include <string>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace Core {
|
||||
class ConfigMgr
|
||||
namespace Core
|
||||
{
|
||||
public:
|
||||
ConfigMgr() = default;
|
||||
class ConfigMgr
|
||||
{
|
||||
public:
|
||||
ConfigMgr() = default;
|
||||
|
||||
~ConfigMgr() = default;
|
||||
~ConfigMgr() = default;
|
||||
|
||||
bool loadConfig( const std::string& configName );
|
||||
|
||||
template<class T> struct always_false : std::false_type {};
|
||||
bool loadConfig( const std::string& configName );
|
||||
|
||||
template< class T >
|
||||
T getValue( const std::string& section, const std::string& name, T defaultValue = T() )
|
||||
{
|
||||
if constexpr (std::is_same_v<T, uint32_t>)
|
||||
return m_pInih->GetInteger( section, name, defaultValue );
|
||||
else if constexpr (std::is_same_v<T, int32_t>)
|
||||
return m_pInih->GetInteger( section, name, defaultValue );
|
||||
else if constexpr (std::is_same_v<T, uint16_t>)
|
||||
return m_pInih->GetInteger( section, name, defaultValue );
|
||||
else if constexpr (std::is_same_v<T, int16_t>)
|
||||
return m_pInih->GetInteger( section, name, defaultValue );
|
||||
else if constexpr (std::is_same_v<T, uint8_t>)
|
||||
return m_pInih->GetInteger( section, name, defaultValue );
|
||||
else if constexpr (std::is_same_v<T, int8_t>)
|
||||
return m_pInih->GetInteger( section, name, defaultValue );
|
||||
else if constexpr (std::is_same_v<T, long>)
|
||||
return m_pInih->GetInteger( section, name, defaultValue );
|
||||
else if constexpr (std::is_same_v<T, double>)
|
||||
return m_pInih->GetReal( section, name, defaultValue );
|
||||
else if constexpr (std::is_same_v<T, float>)
|
||||
return m_pInih->GetReal( section, name, defaultValue );
|
||||
else if constexpr (std::is_same_v<T, std::string>)
|
||||
return m_pInih->Get( section, name, defaultValue );
|
||||
else if constexpr (std::is_same_v<T, bool>)
|
||||
return m_pInih->GetBoolean( section, name, defaultValue );
|
||||
else
|
||||
static_assert(always_false<T>::value, "non-exhaustive getter!");
|
||||
}
|
||||
template<class T> struct always_false : std::false_type {};
|
||||
|
||||
template< class T >
|
||||
void setValue( const std::string& name, T defaultValue = T() )
|
||||
{
|
||||
// TODO: reimplement this...
|
||||
//m_propTree.put( name, defaultValue );
|
||||
}
|
||||
template< class T >
|
||||
T getValue( const std::string& section, const std::string& name, T defaultValue = T() )
|
||||
{
|
||||
if constexpr (std::is_same_v<T, uint32_t>)
|
||||
return m_pInih->GetInteger( section, name, defaultValue );
|
||||
else if constexpr (std::is_same_v<T, int32_t>)
|
||||
return m_pInih->GetInteger( section, name, defaultValue );
|
||||
else if constexpr (std::is_same_v<T, uint16_t>)
|
||||
return m_pInih->GetInteger( section, name, defaultValue );
|
||||
else if constexpr (std::is_same_v<T, int16_t>)
|
||||
return m_pInih->GetInteger( section, name, defaultValue );
|
||||
else if constexpr (std::is_same_v<T, uint8_t>)
|
||||
return m_pInih->GetInteger( section, name, defaultValue );
|
||||
else if constexpr (std::is_same_v<T, int8_t>)
|
||||
return m_pInih->GetInteger( section, name, defaultValue );
|
||||
else if constexpr (std::is_same_v<T, long>)
|
||||
return m_pInih->GetInteger( section, name, defaultValue );
|
||||
else if constexpr (std::is_same_v<T, double>)
|
||||
return m_pInih->GetReal( section, name, defaultValue );
|
||||
else if constexpr (std::is_same_v<T, float>)
|
||||
return m_pInih->GetReal( section, name, defaultValue );
|
||||
else if constexpr (std::is_same_v<T, std::string>)
|
||||
return m_pInih->Get( section, name, defaultValue );
|
||||
else if constexpr (std::is_same_v<T, bool>)
|
||||
return m_pInih->GetBoolean( section, name, defaultValue );
|
||||
else
|
||||
static_assert(always_false<T>::value, "non-exhaustive getter!");
|
||||
}
|
||||
|
||||
private:
|
||||
bool copyDefaultConfig( const std::string& configName );
|
||||
template< class T >
|
||||
void setValue( const std::string& name, T defaultValue = T() )
|
||||
{
|
||||
// TODO: reimplement this...
|
||||
//m_propTree.put( name, defaultValue );
|
||||
}
|
||||
|
||||
std::unique_ptr< INIReader > m_pInih;
|
||||
private:
|
||||
bool copyDefaultConfig( const std::string& configName );
|
||||
|
||||
const std::string m_globalConfigFile = "global.ini";
|
||||
const std::string m_configFolderRoot = "./config/";
|
||||
const std::string m_configDefaultSuffix = ".default";
|
||||
};
|
||||
std::unique_ptr< INIReader > m_pInih;
|
||||
|
||||
const std::string m_globalConfigFile = "global.ini";
|
||||
const std::string m_configFolderRoot = "./config/";
|
||||
const std::string m_configDefaultSuffix = ".default";
|
||||
};
|
||||
}
|
||||
|
||||
#endif //SAPPHIRE_CONFIGMGR_H
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#include <string>
|
||||
|
||||
namespace Core {
|
||||
namespace Util {
|
||||
std::string base64_encode( uint8_t const*, uint32_t len );
|
||||
namespace Core::Util
|
||||
{
|
||||
std::string base64_encode( uint8_t const*, uint32_t len );
|
||||
|
||||
std::string base64_decode( std::string const& s );
|
||||
}
|
||||
std::string base64_decode( const std::string& s );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,25 +3,25 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace Core {
|
||||
namespace Util {
|
||||
using md5_context = struct
|
||||
namespace Core::Util
|
||||
{
|
||||
uint32_t total[2];
|
||||
uint32_t state[4];
|
||||
uint8_t buffer[64];
|
||||
};
|
||||
using md5_context = struct
|
||||
{
|
||||
uint32_t total[2];
|
||||
uint32_t state[4];
|
||||
uint8_t buffer[64];
|
||||
};
|
||||
|
||||
|
||||
void md5( uint8_t* text, uint8_t* hash, int32_t size );
|
||||
void md5( uint8_t* text, uint8_t* hash, int32_t size );
|
||||
|
||||
void md5_starts( md5_context* ctx );
|
||||
void md5_starts( md5_context* ctx );
|
||||
|
||||
void md5_update( md5_context* ctx, uint8_t* input, uint32_t length );
|
||||
void md5_update( md5_context* ctx, uint8_t* input, uint32_t length );
|
||||
|
||||
void md5_finish( md5_context* ctx, uint8_t digest[16] );
|
||||
void md5_finish( md5_context* ctx, uint8_t digest[16] );
|
||||
|
||||
static const char* msg[] =
|
||||
static const char* msg[] =
|
||||
{
|
||||
"",
|
||||
"a",
|
||||
|
@ -33,7 +33,7 @@ static const char* msg[] =
|
|||
"345678901234567890"
|
||||
};
|
||||
|
||||
static const char* val[] =
|
||||
static const char* val[] =
|
||||
{
|
||||
"d41d8cd98f00b204e9800998ecf8427e",
|
||||
"0cc175b9c0f1b6a831c399e269772661",
|
||||
|
@ -45,7 +45,7 @@ static const char* val[] =
|
|||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* md5.h */
|
||||
|
|
|
@ -8,120 +8,112 @@
|
|||
#include <vector>
|
||||
#include "Util/LockedWaitQueue.h"
|
||||
|
||||
namespace Mysql {
|
||||
class Connection;
|
||||
|
||||
class ResultSet;
|
||||
|
||||
class PreparedResultSet;
|
||||
|
||||
class PreparedStatement;
|
||||
namespace Mysql
|
||||
{
|
||||
class Connection;
|
||||
class ResultSet;
|
||||
class PreparedResultSet;
|
||||
class PreparedStatement;
|
||||
}
|
||||
|
||||
namespace Core {
|
||||
namespace Db {
|
||||
class DatabaseWorker;
|
||||
|
||||
class PreparedStatement;
|
||||
|
||||
class Operation;
|
||||
|
||||
class DbWorker;
|
||||
|
||||
using PreparedStmtScopedPtr = std::unique_ptr< PreparedStatement >;
|
||||
|
||||
enum ConnectionFlags
|
||||
namespace Core::Db
|
||||
{
|
||||
CONNECTION_ASYNC = 0x1,
|
||||
CONNECTION_SYNC = 0x2,
|
||||
CONNECTION_BOTH = CONNECTION_ASYNC | CONNECTION_SYNC
|
||||
};
|
||||
class DatabaseWorker;
|
||||
class PreparedStatement;
|
||||
class Operation;
|
||||
class DbWorker;
|
||||
using PreparedStmtScopedPtr = std::unique_ptr< PreparedStatement >;
|
||||
|
||||
struct ConnectionInfo
|
||||
{
|
||||
std::string user;
|
||||
std::string password;
|
||||
std::string database;
|
||||
std::string host;
|
||||
uint16_t port;
|
||||
uint8_t syncThreads;
|
||||
uint8_t asyncThreads;
|
||||
};
|
||||
|
||||
using PreparedStatementMap = std::map< uint32_t, std::pair< std::string, ConnectionFlags > >;
|
||||
|
||||
class DbConnection :
|
||||
public std::enable_shared_from_this< DbConnection >
|
||||
{
|
||||
public:
|
||||
// Constructor for synchronous connections.
|
||||
DbConnection( ConnectionInfo& connInfo );
|
||||
|
||||
// Constructor for asynchronous connections.
|
||||
DbConnection( Core::LockedWaitQueue< std::shared_ptr< Operation > >* queue, ConnectionInfo& connInfo );
|
||||
|
||||
virtual ~DbConnection();
|
||||
|
||||
virtual uint32_t open();
|
||||
|
||||
void close();
|
||||
|
||||
bool prepareStatements();
|
||||
|
||||
bool execute( const std::string& sql );
|
||||
|
||||
bool execute( std::shared_ptr< PreparedStatement > stmt );
|
||||
|
||||
std::shared_ptr< Mysql::ResultSet > query( const std::string& sql );
|
||||
|
||||
std::shared_ptr< Mysql::ResultSet > query( std::shared_ptr< PreparedStatement > stmt );
|
||||
|
||||
void beginTransaction();
|
||||
|
||||
void rollbackTransaction();
|
||||
|
||||
void commitTransaction();
|
||||
|
||||
bool ping();
|
||||
|
||||
uint32_t getLastError();
|
||||
|
||||
bool lockIfReady();
|
||||
|
||||
void unlock();
|
||||
|
||||
std::shared_ptr< Mysql::Connection > getConnection()
|
||||
enum ConnectionFlags
|
||||
{
|
||||
return m_pConnection;
|
||||
}
|
||||
CONNECTION_ASYNC = 0x1,
|
||||
CONNECTION_SYNC = 0x2,
|
||||
CONNECTION_BOTH = CONNECTION_ASYNC | CONNECTION_SYNC
|
||||
};
|
||||
|
||||
std::shared_ptr< Mysql::PreparedStatement > getPreparedStatement( uint32_t index );
|
||||
struct ConnectionInfo
|
||||
{
|
||||
std::string user;
|
||||
std::string password;
|
||||
std::string database;
|
||||
std::string host;
|
||||
uint16_t port;
|
||||
uint8_t syncThreads;
|
||||
uint8_t asyncThreads;
|
||||
};
|
||||
|
||||
void prepareStatement( uint32_t index, const std::string& sql, ConnectionFlags flags );
|
||||
using PreparedStatementMap = std::map< uint32_t, std::pair< std::string, ConnectionFlags > >;
|
||||
|
||||
virtual void doPrepareStatements() = 0;
|
||||
class DbConnection :
|
||||
public std::enable_shared_from_this< DbConnection >
|
||||
{
|
||||
public:
|
||||
// Constructor for synchronous connections.
|
||||
DbConnection( ConnectionInfo& connInfo );
|
||||
|
||||
protected:
|
||||
std::vector< std::shared_ptr< Mysql::PreparedStatement > > m_stmts;
|
||||
PreparedStatementMap m_queries;
|
||||
bool m_reconnecting;
|
||||
bool m_prepareError;
|
||||
// Constructor for asynchronous connections.
|
||||
DbConnection( Core::LockedWaitQueue< std::shared_ptr< Operation > >* queue, ConnectionInfo& connInfo );
|
||||
|
||||
private:
|
||||
LockedWaitQueue< std::shared_ptr< Operation > >* m_queue;
|
||||
std::shared_ptr< DbWorker > m_worker;
|
||||
std::shared_ptr< Mysql::Connection > m_pConnection;
|
||||
ConnectionInfo& m_connectionInfo;
|
||||
ConnectionFlags m_connectionFlags;
|
||||
std::mutex m_mutex;
|
||||
virtual ~DbConnection();
|
||||
|
||||
DbConnection( DbConnection const& right ) = delete;
|
||||
virtual uint32_t open();
|
||||
|
||||
DbConnection& operator=( DbConnection const& right ) = delete;
|
||||
};
|
||||
void close();
|
||||
|
||||
bool prepareStatements();
|
||||
|
||||
bool execute( const std::string& sql );
|
||||
|
||||
bool execute( std::shared_ptr< PreparedStatement > stmt );
|
||||
|
||||
std::shared_ptr< Mysql::ResultSet > query( const std::string& sql );
|
||||
|
||||
std::shared_ptr< Mysql::ResultSet > query( std::shared_ptr< PreparedStatement > stmt );
|
||||
|
||||
void beginTransaction();
|
||||
|
||||
void rollbackTransaction();
|
||||
|
||||
void commitTransaction();
|
||||
|
||||
bool ping();
|
||||
|
||||
uint32_t getLastError();
|
||||
|
||||
bool lockIfReady();
|
||||
|
||||
void unlock();
|
||||
|
||||
std::shared_ptr< Mysql::Connection > getConnection()
|
||||
{
|
||||
return m_pConnection;
|
||||
}
|
||||
|
||||
std::shared_ptr< Mysql::PreparedStatement > getPreparedStatement( uint32_t index );
|
||||
|
||||
void prepareStatement( uint32_t index, const std::string& sql, ConnectionFlags flags );
|
||||
|
||||
virtual void doPrepareStatements() = 0;
|
||||
|
||||
protected:
|
||||
std::vector< std::shared_ptr< Mysql::PreparedStatement > > m_stmts;
|
||||
PreparedStatementMap m_queries;
|
||||
bool m_reconnecting;
|
||||
bool m_prepareError;
|
||||
|
||||
private:
|
||||
LockedWaitQueue< std::shared_ptr< Operation > >* m_queue;
|
||||
std::shared_ptr< DbWorker > m_worker;
|
||||
std::shared_ptr< Mysql::Connection > m_pConnection;
|
||||
ConnectionInfo& m_connectionInfo;
|
||||
ConnectionFlags m_connectionFlags;
|
||||
std::mutex m_mutex;
|
||||
|
||||
DbConnection( DbConnection const& right ) = delete;
|
||||
|
||||
DbConnection& operator=( DbConnection const& right ) = delete;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -8,44 +8,43 @@
|
|||
#include <string>
|
||||
#include "DbConnection.h"
|
||||
|
||||
namespace Core {
|
||||
namespace Db {
|
||||
|
||||
template< class T >
|
||||
class DbWorkerPool;
|
||||
|
||||
class DbLoader
|
||||
namespace Core::Db
|
||||
{
|
||||
public:
|
||||
DbLoader();
|
||||
|
||||
template< class T >
|
||||
DbLoader& addDb( DbWorkerPool< T >& pool, const ConnectionInfo& info );
|
||||
class DbWorkerPool;
|
||||
|
||||
bool initDbs();
|
||||
|
||||
enum DbTypeFlags
|
||||
class DbLoader
|
||||
{
|
||||
DATABASE_NONE = 0,
|
||||
DATABASE_CHARACTER = 1,
|
||||
DATABASE_MASK_ALL = DATABASE_CHARACTER
|
||||
public:
|
||||
DbLoader();
|
||||
|
||||
template< class T >
|
||||
DbLoader& addDb( DbWorkerPool< T >& pool, const ConnectionInfo& info );
|
||||
|
||||
bool initDbs();
|
||||
|
||||
enum DbTypeFlags
|
||||
{
|
||||
DATABASE_NONE = 0,
|
||||
DATABASE_CHARACTER = 1,
|
||||
DATABASE_MASK_ALL = DATABASE_CHARACTER
|
||||
};
|
||||
|
||||
private:
|
||||
bool openDatabases();
|
||||
|
||||
bool prepareStatements();
|
||||
|
||||
using Predicate = std::function< bool() >;
|
||||
using Closer = std::function< void() >;
|
||||
|
||||
bool process( std::queue< Predicate >& queue );
|
||||
|
||||
std::queue< Predicate > m_open;
|
||||
std::queue< Predicate > m_prepare;
|
||||
std::stack< Closer > m_close;
|
||||
};
|
||||
|
||||
private:
|
||||
bool openDatabases();
|
||||
|
||||
bool prepareStatements();
|
||||
|
||||
using Predicate = std::function< bool() >;
|
||||
using Closer = std::function< void() >;
|
||||
|
||||
bool process( std::queue< Predicate >& queue );
|
||||
|
||||
std::queue< Predicate > m_open;
|
||||
std::queue< Predicate > m_prepare;
|
||||
std::stack< Closer > m_close;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif //SAPPHIRE_DBLOADER_H
|
||||
|
|
|
@ -6,35 +6,32 @@
|
|||
#include "Util/LockedWaitQueue.h"
|
||||
#include <memory>
|
||||
|
||||
namespace Core {
|
||||
namespace Db {
|
||||
class DbConnection;
|
||||
|
||||
class Operation;
|
||||
|
||||
class DbWorker
|
||||
namespace Core::Db
|
||||
{
|
||||
public:
|
||||
DbWorker( LockedWaitQueue< std::shared_ptr< Operation > >* newQueue, DbConnection* connection );
|
||||
class DbConnection;
|
||||
class Operation;
|
||||
|
||||
~DbWorker();
|
||||
class DbWorker
|
||||
{
|
||||
public:
|
||||
DbWorker( LockedWaitQueue< std::shared_ptr< Operation > >* newQueue, DbConnection* connection );
|
||||
|
||||
private:
|
||||
LockedWaitQueue< std::shared_ptr< Operation > >* m_queue;
|
||||
DbConnection* m_pConn;
|
||||
~DbWorker();
|
||||
|
||||
void workerThread();
|
||||
private:
|
||||
LockedWaitQueue< std::shared_ptr< Operation > >* m_queue;
|
||||
DbConnection* m_pConn;
|
||||
|
||||
std::thread m_workerThread;
|
||||
void workerThread();
|
||||
|
||||
std::atomic< bool > m_cancelationToken;
|
||||
std::thread m_workerThread;
|
||||
|
||||
DbWorker( DbWorker const& right ) = delete;
|
||||
std::atomic< bool > m_cancelationToken;
|
||||
|
||||
DbWorker& operator=( DbWorker const& right ) = delete;
|
||||
};
|
||||
DbWorker( DbWorker const& right ) = delete;
|
||||
|
||||
DbWorker& operator=( DbWorker const& right ) = delete;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif //SAPPHIRE_DBWORKER_H
|
||||
|
|
|
@ -8,89 +8,88 @@
|
|||
#include "Util/LockedWaitQueue.h"
|
||||
#include "DbConnection.h"
|
||||
|
||||
namespace Core {
|
||||
namespace Db {
|
||||
|
||||
template< typename T >
|
||||
class LockedWaitQueue;
|
||||
|
||||
class Operation;
|
||||
|
||||
class PreparedStatement;
|
||||
|
||||
struct ConnectionInfo;
|
||||
|
||||
template< class T >
|
||||
class DbWorkerPool
|
||||
namespace Core::Db
|
||||
{
|
||||
private:
|
||||
enum InternalIndex
|
||||
|
||||
template< typename T >
|
||||
class LockedWaitQueue;
|
||||
|
||||
class Operation;
|
||||
|
||||
class PreparedStatement;
|
||||
|
||||
struct ConnectionInfo;
|
||||
|
||||
template< class T >
|
||||
class DbWorkerPool
|
||||
{
|
||||
IDX_ASYNC,
|
||||
IDX_SYNCH,
|
||||
IDX_SIZE
|
||||
private:
|
||||
enum InternalIndex
|
||||
{
|
||||
IDX_ASYNC,
|
||||
IDX_SYNCH,
|
||||
IDX_SIZE
|
||||
};
|
||||
|
||||
public:
|
||||
DbWorkerPool();
|
||||
|
||||
~DbWorkerPool();
|
||||
|
||||
void setConnectionInfo( const ConnectionInfo& info, uint8_t asyncThreads, uint8_t synchThreads );
|
||||
|
||||
uint32_t open();
|
||||
|
||||
void close();
|
||||
|
||||
bool prepareStatements();
|
||||
|
||||
inline ConnectionInfo getConnectionInfo() const
|
||||
{
|
||||
return m_connectionInfo;
|
||||
}
|
||||
|
||||
// Async execution
|
||||
void execute( const std::string& sql );
|
||||
|
||||
void execute( std::shared_ptr< PreparedStatement > stmt );
|
||||
|
||||
// Sync execution
|
||||
void directExecute( const std::string& sql );
|
||||
|
||||
void directExecute( std::shared_ptr< PreparedStatement > stmt );
|
||||
|
||||
std::shared_ptr< Mysql::ResultSet >
|
||||
query( const std::string& sql, std::shared_ptr< T > connection = nullptr );
|
||||
|
||||
std::shared_ptr< Mysql::PreparedResultSet > query( std::shared_ptr< PreparedStatement > stmt );
|
||||
|
||||
using PreparedStatementIndex = typename T::Statements;
|
||||
|
||||
std::shared_ptr< PreparedStatement > getPreparedStatement( PreparedStatementIndex index );
|
||||
|
||||
void escapeString( std::string& str );
|
||||
|
||||
void keepAlive();
|
||||
|
||||
private:
|
||||
uint32_t openConnections( InternalIndex type, uint8_t numConnections );
|
||||
|
||||
unsigned long escapeString( char* to, const char* from, unsigned long length );
|
||||
|
||||
void enqueue( std::shared_ptr< Operation > op );
|
||||
|
||||
std::shared_ptr< T > getFreeConnection();
|
||||
|
||||
const std::string& getDatabaseName() const;
|
||||
|
||||
std::unique_ptr< Core::LockedWaitQueue< std::shared_ptr< Operation > > > m_queue;
|
||||
std::array< std::vector< std::shared_ptr< T > >, IDX_SIZE > m_connections;
|
||||
ConnectionInfo m_connectionInfo;
|
||||
uint8_t m_asyncThreads;
|
||||
uint8_t m_synchThreads;
|
||||
};
|
||||
|
||||
public:
|
||||
DbWorkerPool();
|
||||
|
||||
~DbWorkerPool();
|
||||
|
||||
void setConnectionInfo( const ConnectionInfo& info, uint8_t asyncThreads, uint8_t synchThreads );
|
||||
|
||||
uint32_t open();
|
||||
|
||||
void close();
|
||||
|
||||
bool prepareStatements();
|
||||
|
||||
inline ConnectionInfo getConnectionInfo() const
|
||||
{
|
||||
return m_connectionInfo;
|
||||
}
|
||||
|
||||
// Async execution
|
||||
void execute( const std::string& sql );
|
||||
|
||||
void execute( std::shared_ptr< PreparedStatement > stmt );
|
||||
|
||||
// Sync execution
|
||||
void directExecute( const std::string& sql );
|
||||
|
||||
void directExecute( std::shared_ptr< PreparedStatement > stmt );
|
||||
|
||||
std::shared_ptr< Mysql::ResultSet >
|
||||
query( const std::string& sql, std::shared_ptr< T > connection = nullptr );
|
||||
|
||||
std::shared_ptr< Mysql::PreparedResultSet > query( std::shared_ptr< PreparedStatement > stmt );
|
||||
|
||||
using PreparedStatementIndex = typename T::Statements;
|
||||
|
||||
std::shared_ptr< PreparedStatement > getPreparedStatement( PreparedStatementIndex index );
|
||||
|
||||
void escapeString( std::string& str );
|
||||
|
||||
void keepAlive();
|
||||
|
||||
private:
|
||||
uint32_t openConnections( InternalIndex type, uint8_t numConnections );
|
||||
|
||||
unsigned long escapeString( char* to, const char* from, unsigned long length );
|
||||
|
||||
void enqueue( std::shared_ptr< Operation > op );
|
||||
|
||||
std::shared_ptr< T > getFreeConnection();
|
||||
|
||||
const std::string& getDatabaseName() const;
|
||||
|
||||
std::unique_ptr< Core::LockedWaitQueue< std::shared_ptr< Operation > > > m_queue;
|
||||
std::array< std::vector< std::shared_ptr< T > >, IDX_SIZE > m_connections;
|
||||
ConnectionInfo m_connectionInfo;
|
||||
uint8_t m_asyncThreads;
|
||||
uint8_t m_synchThreads;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif //SAPPHIRE_DBWORKERPOOL_H
|
||||
|
|
|
@ -1,51 +1,49 @@
|
|||
#ifndef SAPPHIRE_OPERATION_H
|
||||
#define SAPPHIRE_OPERATION_H
|
||||
|
||||
namespace Mysql {
|
||||
class Connection;
|
||||
}
|
||||
|
||||
namespace Core {
|
||||
namespace Db {
|
||||
class DbConnection;
|
||||
|
||||
class PreparedStatement;
|
||||
|
||||
class Operation
|
||||
namespace Mysql
|
||||
{
|
||||
public:
|
||||
Operation() :
|
||||
m_pConn( nullptr )
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~Operation()
|
||||
{
|
||||
}
|
||||
|
||||
virtual int call()
|
||||
{
|
||||
execute();
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual bool execute() = 0;
|
||||
|
||||
virtual void setConnection( DbConnection* pCon )
|
||||
{
|
||||
m_pConn = pCon;
|
||||
}
|
||||
|
||||
DbConnection* m_pConn;
|
||||
|
||||
private:
|
||||
Operation( Operation const& right ) = delete;
|
||||
|
||||
Operation& operator=( Operation const& right ) = delete;
|
||||
};
|
||||
|
||||
|
||||
class Connection;
|
||||
}
|
||||
|
||||
namespace Core::Db
|
||||
{
|
||||
class DbConnection;
|
||||
|
||||
class PreparedStatement;
|
||||
|
||||
class Operation
|
||||
{
|
||||
public:
|
||||
Operation() :
|
||||
m_pConn( nullptr )
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~Operation()
|
||||
{
|
||||
}
|
||||
|
||||
virtual int call()
|
||||
{
|
||||
execute();
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual bool execute() = 0;
|
||||
|
||||
virtual void setConnection( DbConnection* pCon )
|
||||
{
|
||||
m_pConn = pCon;
|
||||
}
|
||||
|
||||
DbConnection* m_pConn;
|
||||
|
||||
private:
|
||||
Operation( Operation const& right ) = delete;
|
||||
|
||||
Operation& operator=( Operation const& right ) = delete;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //SAPPHIRE_OPERATION_H
|
||||
|
|
|
@ -7,85 +7,83 @@
|
|||
#include <memory>
|
||||
#include "Operation.h"
|
||||
|
||||
namespace Mysql {
|
||||
class PreparedStatement;
|
||||
namespace Mysql
|
||||
{
|
||||
class PreparedStatement;
|
||||
}
|
||||
|
||||
namespace Core {
|
||||
namespace Db {
|
||||
union PreparedStatementDataUnion
|
||||
namespace Core::Db
|
||||
{
|
||||
bool boolean;
|
||||
uint32_t ui32;
|
||||
int32_t i32;
|
||||
uint64_t ui64;
|
||||
int64_t i64;
|
||||
double d;
|
||||
};
|
||||
union PreparedStatementDataUnion
|
||||
{
|
||||
bool boolean;
|
||||
uint32_t ui32;
|
||||
int32_t i32;
|
||||
uint64_t ui64;
|
||||
int64_t i64;
|
||||
double d;
|
||||
};
|
||||
|
||||
enum PreparedStatementValueType
|
||||
{
|
||||
TYPE_BOOL,
|
||||
TYPE_UI,
|
||||
TYPE_UI64,
|
||||
TYPE_I,
|
||||
TYPE_I64,
|
||||
TYPE_DOUBLE,
|
||||
TYPE_STRING,
|
||||
TYPE_BINARY,
|
||||
TYPE_NULL
|
||||
};
|
||||
enum PreparedStatementValueType
|
||||
{
|
||||
TYPE_BOOL,
|
||||
TYPE_UI,
|
||||
TYPE_UI64,
|
||||
TYPE_I,
|
||||
TYPE_I64,
|
||||
TYPE_DOUBLE,
|
||||
TYPE_STRING,
|
||||
TYPE_BINARY,
|
||||
TYPE_NULL
|
||||
};
|
||||
|
||||
struct PreparedStatementData
|
||||
{
|
||||
PreparedStatementDataUnion data;
|
||||
PreparedStatementValueType type;
|
||||
std::vector< uint8_t > binary;
|
||||
};
|
||||
struct PreparedStatementData
|
||||
{
|
||||
PreparedStatementDataUnion data;
|
||||
PreparedStatementValueType type;
|
||||
std::vector< uint8_t > binary;
|
||||
};
|
||||
|
||||
class PreparedStatement
|
||||
{
|
||||
public:
|
||||
explicit PreparedStatement( uint32_t index );
|
||||
class PreparedStatement
|
||||
{
|
||||
public:
|
||||
explicit PreparedStatement( uint32_t index );
|
||||
|
||||
~PreparedStatement();
|
||||
~PreparedStatement();
|
||||
|
||||
void setBool( uint8_t index, bool value );
|
||||
void setBool( uint8_t index, bool value );
|
||||
|
||||
void setUInt( uint8_t index, uint32_t value );
|
||||
void setUInt( uint8_t index, uint32_t value );
|
||||
|
||||
void setUInt64( uint8_t index, uint64_t value );
|
||||
void setUInt64( uint8_t index, uint64_t value );
|
||||
|
||||
void setInt( uint8_t index, int32_t value );
|
||||
void setInt( uint8_t index, int32_t value );
|
||||
|
||||
void setInt64( uint8_t index, int64_t value );
|
||||
void setInt64( uint8_t index, int64_t value );
|
||||
|
||||
void setDouble( uint8_t index, double value );
|
||||
void setDouble( uint8_t index, double value );
|
||||
|
||||
void setString( uint8_t index, const std::string& value );
|
||||
void setString( uint8_t index, const std::string& value );
|
||||
|
||||
void setBinary( uint8_t index, const std::vector< uint8_t >& value );
|
||||
void setBinary( uint8_t index, const std::vector< uint8_t >& value );
|
||||
|
||||
void setNull( uint8_t index );
|
||||
void setNull( uint8_t index );
|
||||
|
||||
uint32_t getIndex() const;
|
||||
uint32_t getIndex() const;
|
||||
|
||||
void setMysqlPS( std::shared_ptr< Mysql::PreparedStatement > pStmt );
|
||||
void setMysqlPS( std::shared_ptr< Mysql::PreparedStatement > pStmt );
|
||||
|
||||
void bindParameters();
|
||||
void bindParameters();
|
||||
|
||||
protected:
|
||||
std::shared_ptr< Mysql::PreparedStatement > m_stmt;
|
||||
uint32_t m_index;
|
||||
std::vector< PreparedStatementData > m_statementData;
|
||||
protected:
|
||||
std::shared_ptr< Mysql::PreparedStatement > m_stmt;
|
||||
uint32_t m_index;
|
||||
std::vector< PreparedStatementData > m_statementData;
|
||||
|
||||
PreparedStatement( PreparedStatement const& right ) = delete;
|
||||
PreparedStatement( PreparedStatement const& right ) = delete;
|
||||
|
||||
PreparedStatement& operator=( PreparedStatement const& right ) = delete;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
PreparedStatement& operator=( PreparedStatement const& right ) = delete;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,50 +5,49 @@
|
|||
#include "Operation.h"
|
||||
#include <memory>
|
||||
|
||||
namespace Core {
|
||||
namespace Db {
|
||||
class PreparedStatement;
|
||||
|
||||
class StatementTask :
|
||||
public Operation
|
||||
namespace Core::Db
|
||||
{
|
||||
public:
|
||||
class PreparedStatement;
|
||||
|
||||
StatementTask( const std::string& sql, bool async = false );
|
||||
class StatementTask :
|
||||
public Operation
|
||||
{
|
||||
public:
|
||||
|
||||
~StatementTask();
|
||||
StatementTask( const std::string& sql, bool async = false );
|
||||
|
||||
bool execute() override;
|
||||
~StatementTask();
|
||||
|
||||
// QueryResultFuture getFuture() const
|
||||
// {
|
||||
// return m_result->get_future();
|
||||
// }
|
||||
bool execute() override;
|
||||
|
||||
private:
|
||||
std::string m_sql;
|
||||
bool m_hasResult;
|
||||
// QueryResultPromise *m_result;
|
||||
};
|
||||
// QueryResultFuture getFuture() const
|
||||
// {
|
||||
// return m_result->get_future();
|
||||
// }
|
||||
|
||||
class PreparedStatementTask :
|
||||
public Operation
|
||||
{
|
||||
public:
|
||||
PreparedStatementTask( std::shared_ptr< PreparedStatement > stmt, bool async = false );
|
||||
private:
|
||||
std::string m_sql;
|
||||
bool m_hasResult;
|
||||
// QueryResultPromise *m_result;
|
||||
};
|
||||
|
||||
~PreparedStatementTask();
|
||||
class PreparedStatementTask :
|
||||
public Operation
|
||||
{
|
||||
public:
|
||||
PreparedStatementTask( std::shared_ptr< PreparedStatement > stmt, bool async = false );
|
||||
|
||||
bool execute() override;
|
||||
//PreparedQueryResultFuture getFuture() { return m_result->get_future(); }
|
||||
~PreparedStatementTask();
|
||||
|
||||
protected:
|
||||
std::shared_ptr< PreparedStatement > m_stmt;
|
||||
bool m_hasResult;
|
||||
//PreparedQueryResultPromise* m_result;
|
||||
};
|
||||
bool execute() override;
|
||||
//PreparedQueryResultFuture getFuture() { return m_result->get_future(); }
|
||||
|
||||
protected:
|
||||
std::shared_ptr< PreparedStatement > m_stmt;
|
||||
bool m_hasResult;
|
||||
//PreparedQueryResultPromise* m_result;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,100 +3,99 @@
|
|||
|
||||
#include "DbConnection.h"
|
||||
|
||||
namespace Core {
|
||||
namespace Db {
|
||||
class DbConnectionInfo;
|
||||
|
||||
enum ZoneDbStatements : uint32_t
|
||||
namespace Core::Db
|
||||
{
|
||||
CHARA_SEL,
|
||||
CHARA_SEL_MINIMAL,
|
||||
CHARA_SEL_SEARCHINFO,
|
||||
CHARA_SEL_QUEST,
|
||||
CHARA_INS,
|
||||
CHARA_UP,
|
||||
CHARA_UP_NAME,
|
||||
CHARA_UP_HPMP,
|
||||
CHARA_UP_MODE,
|
||||
CHARA_UP_MOUNT,
|
||||
CHARA_UP_INVINCIBLE,
|
||||
CHARA_UP_CUSTOMIZE,
|
||||
CHARA_UP_MODELMAINWEAP,
|
||||
CHARA_UP_MODELSUBWEAP,
|
||||
CHARA_UP_MODELSYSWEAP,
|
||||
CHARA_UP_MODELEQUIP,
|
||||
CHARA_UP_EMOTEMODETYPE,
|
||||
CHARA_UP_FIRSTLOGINTIME,
|
||||
CHARA_UP_LANGUAGE,
|
||||
CHARA_UP_ISNEWGAME,
|
||||
CHARA_UP_ISNEWADV,
|
||||
CHARA_UP_TERRITORY,
|
||||
CHARA_UP_POS,
|
||||
CHARA_UP_CLASS,
|
||||
CHARA_UP_STATUS,
|
||||
CHARA_UP_TOTALPLAYTIME,
|
||||
CHARA_UP_HOMEPOINT,
|
||||
CHARA_UP_FAVOPOINT,
|
||||
CHARA_UP_TITLE,
|
||||
CHARA_UP_TITLELIST,
|
||||
CHARA_UP_ACHIEVEMENTS,
|
||||
CHARA_UP_AETHERYTE,
|
||||
CHARA_UP_HOWTO,
|
||||
CHARA_UP_MINIONS,
|
||||
CHARA_UP_MOUNTS,
|
||||
CHARA_UP_GEARSET,
|
||||
CHARA_UP_CONFIGFLAGS,
|
||||
CHARA_UP_QUESTCOMPLETE,
|
||||
CHARA_UP_OPENINGSEQ,
|
||||
CHARA_UP_QUESTTRACKING,
|
||||
CHARA_UP_GRANDCOMPANY,
|
||||
CHARA_UP_GRANDCOMPANYRANKS,
|
||||
CHARA_UP_DISCOVERY,
|
||||
CHARA_UP_GMRANK,
|
||||
CHARA_UP_EQUIPDISPLAYFLAGS,
|
||||
CHARA_UP_UNLOCKS,
|
||||
CHARA_UP_CFPENATLY,
|
||||
CHARA_SEARCHINFO_INS,
|
||||
CHARA_SEARCHINFO_UP_SELECTCLASS,
|
||||
CHARA_SEARCHINFO_UP_SELECTREGION,
|
||||
CHARA_SEARCHINFO_UP_SEARCHCOMMENT,
|
||||
class DbConnectionInfo;
|
||||
|
||||
CHARA_QUEST_INS,
|
||||
CHARA_QUEST_UP,
|
||||
CHARA_QUEST_DEL,
|
||||
enum ZoneDbStatements : uint32_t
|
||||
{
|
||||
CHARA_SEL,
|
||||
CHARA_SEL_MINIMAL,
|
||||
CHARA_SEL_SEARCHINFO,
|
||||
CHARA_SEL_QUEST,
|
||||
CHARA_INS,
|
||||
CHARA_UP,
|
||||
CHARA_UP_NAME,
|
||||
CHARA_UP_HPMP,
|
||||
CHARA_UP_MODE,
|
||||
CHARA_UP_MOUNT,
|
||||
CHARA_UP_INVINCIBLE,
|
||||
CHARA_UP_CUSTOMIZE,
|
||||
CHARA_UP_MODELMAINWEAP,
|
||||
CHARA_UP_MODELSUBWEAP,
|
||||
CHARA_UP_MODELSYSWEAP,
|
||||
CHARA_UP_MODELEQUIP,
|
||||
CHARA_UP_EMOTEMODETYPE,
|
||||
CHARA_UP_FIRSTLOGINTIME,
|
||||
CHARA_UP_LANGUAGE,
|
||||
CHARA_UP_ISNEWGAME,
|
||||
CHARA_UP_ISNEWADV,
|
||||
CHARA_UP_TERRITORY,
|
||||
CHARA_UP_POS,
|
||||
CHARA_UP_CLASS,
|
||||
CHARA_UP_STATUS,
|
||||
CHARA_UP_TOTALPLAYTIME,
|
||||
CHARA_UP_HOMEPOINT,
|
||||
CHARA_UP_FAVOPOINT,
|
||||
CHARA_UP_TITLE,
|
||||
CHARA_UP_TITLELIST,
|
||||
CHARA_UP_ACHIEVEMENTS,
|
||||
CHARA_UP_AETHERYTE,
|
||||
CHARA_UP_HOWTO,
|
||||
CHARA_UP_MINIONS,
|
||||
CHARA_UP_MOUNTS,
|
||||
CHARA_UP_GEARSET,
|
||||
CHARA_UP_CONFIGFLAGS,
|
||||
CHARA_UP_QUESTCOMPLETE,
|
||||
CHARA_UP_OPENINGSEQ,
|
||||
CHARA_UP_QUESTTRACKING,
|
||||
CHARA_UP_GRANDCOMPANY,
|
||||
CHARA_UP_GRANDCOMPANYRANKS,
|
||||
CHARA_UP_DISCOVERY,
|
||||
CHARA_UP_GMRANK,
|
||||
CHARA_UP_EQUIPDISPLAYFLAGS,
|
||||
CHARA_UP_UNLOCKS,
|
||||
CHARA_UP_CFPENATLY,
|
||||
CHARA_SEARCHINFO_INS,
|
||||
CHARA_SEARCHINFO_UP_SELECTCLASS,
|
||||
CHARA_SEARCHINFO_UP_SELECTREGION,
|
||||
CHARA_SEARCHINFO_UP_SEARCHCOMMENT,
|
||||
|
||||
CHARA_CLASS_SEL,
|
||||
CHARA_CLASS_INS,
|
||||
CHARA_CLASS_UP,
|
||||
CHARA_CLASS_DEL,
|
||||
CHARA_QUEST_INS,
|
||||
CHARA_QUEST_UP,
|
||||
CHARA_QUEST_DEL,
|
||||
|
||||
CHARA_ITEMINV_INS,
|
||||
CHARA_CLASS_SEL,
|
||||
CHARA_CLASS_INS,
|
||||
CHARA_CLASS_UP,
|
||||
CHARA_CLASS_DEL,
|
||||
|
||||
CHARA_ITEMGLOBAL_INS,
|
||||
CHARA_ITEMGLOBAL_UP,
|
||||
CHARA_ITEMGLOBAL_DELETE,
|
||||
CHARA_ITEMINV_INS,
|
||||
|
||||
ZONE_SEL_BNPCTEMPLATES,
|
||||
CHARA_ITEMGLOBAL_INS,
|
||||
CHARA_ITEMGLOBAL_UP,
|
||||
CHARA_ITEMGLOBAL_DELETE,
|
||||
|
||||
MAX_STATEMENTS
|
||||
};
|
||||
ZONE_SEL_BNPCTEMPLATES,
|
||||
|
||||
class ZoneDbConnection : public DbConnection
|
||||
{
|
||||
public:
|
||||
using Statements = ZoneDbStatements;
|
||||
MAX_STATEMENTS
|
||||
};
|
||||
|
||||
ZoneDbConnection( ConnectionInfo& connInfo );
|
||||
class ZoneDbConnection : public DbConnection
|
||||
{
|
||||
public:
|
||||
using Statements = ZoneDbStatements;
|
||||
|
||||
ZoneDbConnection( Core::LockedWaitQueue< std::shared_ptr< Operation > >* q, ConnectionInfo& connInfo );
|
||||
ZoneDbConnection( ConnectionInfo& connInfo );
|
||||
|
||||
~ZoneDbConnection();
|
||||
ZoneDbConnection( Core::LockedWaitQueue< std::shared_ptr< Operation > >* q, ConnectionInfo& connInfo );
|
||||
|
||||
void doPrepareStatements() override;
|
||||
~ZoneDbConnection();
|
||||
|
||||
};
|
||||
void doPrepareStatements() override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif //SAPPHIRE_CHARACONNECTION_H
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
#include <set>
|
||||
#include <variant>
|
||||
|
||||
namespace Core {
|
||||
namespace Data {
|
||||
namespace Core::Data
|
||||
{
|
||||
|
||||
class ExdDataGenerated;
|
||||
|
||||
|
@ -8694,7 +8694,6 @@ const std::set< uint32_t >& getZoneSharedGroupIdList()
|
|||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -3,34 +3,30 @@
|
|||
|
||||
#include <memory>
|
||||
|
||||
namespace Core {
|
||||
namespace Core
|
||||
{
|
||||
|
||||
class ConfigMgr;
|
||||
class ConfigMgr;
|
||||
using ConfigMgrPtr = std::shared_ptr< ConfigMgr >;
|
||||
|
||||
typedef std::shared_ptr< ConfigMgr > ConfigMgrPtr;
|
||||
namespace Network
|
||||
{
|
||||
class Hive;
|
||||
class Acceptor;
|
||||
class Connection;
|
||||
using HivePtr = std::shared_ptr< Hive >;
|
||||
using AcceptorPtr = std::shared_ptr< Acceptor >;
|
||||
using ConnectionPtr = std::shared_ptr< Connection >;
|
||||
|
||||
namespace Packets
|
||||
{
|
||||
class GamePacket;
|
||||
class FFXIVPacketBase;
|
||||
using GamePacketPtr = std::shared_ptr< GamePacket >;
|
||||
using FFXIVPacketBasePtr = std::shared_ptr< FFXIVPacketBase >;
|
||||
}
|
||||
|
||||
namespace Network {
|
||||
class Hive;
|
||||
|
||||
class Acceptor;
|
||||
|
||||
class Connection;
|
||||
|
||||
typedef std::shared_ptr< Hive > HivePtr;
|
||||
typedef std::shared_ptr< Acceptor > AcceptorPtr;
|
||||
typedef std::shared_ptr< Connection > ConnectionPtr;
|
||||
|
||||
namespace Packets {
|
||||
class GamePacket;
|
||||
|
||||
class FFXIVPacketBase;
|
||||
|
||||
typedef std::shared_ptr< GamePacket > GamePacketPtr;
|
||||
typedef std::shared_ptr< FFXIVPacketBase > FFXIVPacketBasePtr;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -7,29 +7,30 @@
|
|||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
namespace Core {
|
||||
|
||||
class Framework
|
||||
namespace Core
|
||||
{
|
||||
using TypenameToObject = std::map< std::type_index, std::shared_ptr< void > >;
|
||||
TypenameToObject ObjectMap;
|
||||
|
||||
public:
|
||||
template< typename T >
|
||||
std::shared_ptr< T > get()
|
||||
class Framework
|
||||
{
|
||||
auto iType = ObjectMap.find( typeid( T ) );
|
||||
assert( !( iType == ObjectMap.end() ) );
|
||||
return std::static_pointer_cast< T >( iType->second );
|
||||
}
|
||||
using TypenameToObject = std::map< std::type_index, std::shared_ptr< void > >;
|
||||
TypenameToObject ObjectMap;
|
||||
|
||||
template< typename T >
|
||||
void set( std::shared_ptr< T > value )
|
||||
{
|
||||
assert( value ); // why would anyone store nullptrs....
|
||||
ObjectMap[ typeid( T ) ] = value;
|
||||
}
|
||||
};
|
||||
public:
|
||||
template< typename T >
|
||||
std::shared_ptr< T > get()
|
||||
{
|
||||
auto iType = ObjectMap.find( typeid( T ) );
|
||||
assert( !( iType == ObjectMap.end() ) );
|
||||
return std::static_pointer_cast< T >( iType->second );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
void set( std::shared_ptr< T > value )
|
||||
{
|
||||
assert( value ); // why would anyone store nullptrs....
|
||||
ObjectMap[ typeid( T ) ] = value;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -48,11 +48,6 @@ void Logger::init()
|
|||
spdlog::flush_on( spdlog::level::critical );
|
||||
}
|
||||
|
||||
|
||||
void Logger::Log( LoggingSeverity logSev, const std::string& text )
|
||||
{
|
||||
}
|
||||
|
||||
void Logger::error( const std::string& text )
|
||||
{
|
||||
spdlog::get( "logger" )->error( text );
|
||||
|
|
|
@ -3,45 +3,33 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
namespace Core {
|
||||
|
||||
enum struct LoggingSeverity : uint8_t
|
||||
{
|
||||
trace = 0,
|
||||
debug = 1,
|
||||
info = 2,
|
||||
warning = 3,
|
||||
error = 4,
|
||||
fatal = 5
|
||||
};
|
||||
|
||||
class Logger
|
||||
namespace Core
|
||||
{
|
||||
|
||||
private:
|
||||
std::string m_logFile;
|
||||
class Logger
|
||||
{
|
||||
|
||||
public:
|
||||
Logger();
|
||||
private:
|
||||
std::string m_logFile;
|
||||
|
||||
~Logger();
|
||||
public:
|
||||
Logger();
|
||||
|
||||
void init();
|
||||
~Logger();
|
||||
|
||||
void Log( LoggingSeverity logSev, const std::string& text );
|
||||
void init();
|
||||
|
||||
void error( const std::string& text );
|
||||
void error( const std::string& text );
|
||||
|
||||
void info( const std::string& text );
|
||||
void info( const std::string& text );
|
||||
|
||||
void debug( const std::string& text );
|
||||
void debug( const std::string& text );
|
||||
|
||||
void fatal( const std::string& text );
|
||||
void fatal( const std::string& text );
|
||||
|
||||
void setLogPath( const std::string& logPath );
|
||||
|
||||
};
|
||||
void setLogPath( const std::string& logPath );
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -13,75 +13,74 @@
|
|||
#include <vector>
|
||||
|
||||
|
||||
namespace Core {
|
||||
namespace Network {
|
||||
|
||||
class Connection;
|
||||
|
||||
class Acceptor : public std::enable_shared_from_this< Acceptor >
|
||||
namespace Core::Network
|
||||
{
|
||||
friend class Hive;
|
||||
|
||||
private:
|
||||
HivePtr m_hive;
|
||||
asio::ip::tcp::acceptor m_acceptor;
|
||||
asio::strand m_io_strand;
|
||||
std::atomic< uint32_t > m_error_state;
|
||||
class Connection;
|
||||
|
||||
private:
|
||||
Acceptor( const Acceptor& rhs );
|
||||
class Acceptor : public std::enable_shared_from_this< Acceptor >
|
||||
{
|
||||
friend class Hive;
|
||||
|
||||
Acceptor& operator=( const Acceptor& rhs );
|
||||
private:
|
||||
HivePtr m_hive;
|
||||
asio::ip::tcp::acceptor m_acceptor;
|
||||
asio::strand m_io_strand;
|
||||
std::atomic< uint32_t > m_error_state;
|
||||
|
||||
void StartError( const asio::error_code& error );
|
||||
private:
|
||||
Acceptor( const Acceptor& rhs );
|
||||
|
||||
void DispatchAccept( ConnectionPtr connection );
|
||||
Acceptor& operator=( const Acceptor& rhs );
|
||||
|
||||
void HandleAccept( const asio::error_code& error, ConnectionPtr connection );
|
||||
void StartError( const asio::error_code& error );
|
||||
|
||||
private:
|
||||
// Called when a connection has connected to the server. This function
|
||||
// should return true to invoke the connection's OnAccept function if the
|
||||
// connection will be kept. If the connection will not be kept, the
|
||||
// connection's Disconnect function should be called and the function
|
||||
// should return false.
|
||||
virtual bool OnAccept( ConnectionPtr connection, const std::string& host, uint16_t port );
|
||||
void DispatchAccept( ConnectionPtr connection );
|
||||
|
||||
// Called when an error is encountered. Most typically, this is when the
|
||||
// acceptor is being closed via the Stop function or if the Listen is
|
||||
// called on an address that is not available.
|
||||
virtual void OnError( const asio::error_code& error );
|
||||
void HandleAccept( const asio::error_code& error, ConnectionPtr connection );
|
||||
|
||||
public:
|
||||
Acceptor( HivePtr hive );
|
||||
private:
|
||||
// Called when a connection has connected to the server. This function
|
||||
// should return true to invoke the connection's OnAccept function if the
|
||||
// connection will be kept. If the connection will not be kept, the
|
||||
// connection's Disconnect function should be called and the function
|
||||
// should return false.
|
||||
virtual bool OnAccept( ConnectionPtr connection, const std::string& host, uint16_t port );
|
||||
|
||||
virtual ~Acceptor();
|
||||
// Called when an error is encountered. Most typically, this is when the
|
||||
// acceptor is being closed via the Stop function or if the Listen is
|
||||
// called on an address that is not available.
|
||||
virtual void OnError( const asio::error_code& error );
|
||||
|
||||
// Returns the Hive object.
|
||||
HivePtr GetHive();
|
||||
public:
|
||||
Acceptor( HivePtr hive );
|
||||
|
||||
// Returns the acceptor object.
|
||||
asio::ip::tcp::acceptor& GetAcceptor();
|
||||
virtual ~Acceptor();
|
||||
|
||||
// Returns the strand object.
|
||||
asio::strand& GetStrand();
|
||||
// Returns the Hive object.
|
||||
HivePtr GetHive();
|
||||
|
||||
// Returns true if this object has an error associated with it.
|
||||
bool HasError();
|
||||
// Returns the acceptor object.
|
||||
asio::ip::tcp::acceptor& GetAcceptor();
|
||||
|
||||
public:
|
||||
// Begin listening on the specific network interface.
|
||||
void Listen( const std::string& host, const uint16_t& port );
|
||||
// Returns the strand object.
|
||||
asio::strand& GetStrand();
|
||||
|
||||
// Posts the connection to the listening interface. The next client that
|
||||
// connections will be given this connection. If multiple calls to Accept
|
||||
// are called at a time, then they are accepted in a FIFO order.
|
||||
void Accept( ConnectionPtr connection );
|
||||
// Returns true if this object has an error associated with it.
|
||||
bool HasError();
|
||||
|
||||
// Stop the Acceptor from listening.
|
||||
void Stop();
|
||||
};
|
||||
public:
|
||||
// Begin listening on the specific network interface.
|
||||
void Listen( const std::string& host, const uint16_t& port );
|
||||
|
||||
// Posts the connection to the listening interface. The next client that
|
||||
// connections will be given this connection. If multiple calls to Accept
|
||||
// are called at a time, then they are accepted in a FIFO order.
|
||||
void Accept( ConnectionPtr connection );
|
||||
|
||||
// Stop the Acceptor from listening.
|
||||
void Stop();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -5,182 +5,179 @@
|
|||
#include <vector>
|
||||
#include "PacketDef/Ipcs.h"
|
||||
|
||||
namespace Core {
|
||||
namespace Network {
|
||||
namespace Packets {
|
||||
|
||||
/**
|
||||
* Anticipated usage:
|
||||
* ==================
|
||||
* Set up a stream buffer to collect the bytes to be transmitted as a packet.
|
||||
* Now, you can do the following (given you have the structs filled out already).
|
||||
*
|
||||
* FFXIVARR_PACKET_HEADER pkt_hdr = { . . . };
|
||||
* FFXIVARR_PACKET_SEGMENT_HEADER pkt_seg_hdr[n] = { . . . };
|
||||
*
|
||||
* std::stringstream buf;
|
||||
* buf << pkt_hdr;
|
||||
* for( int i = 0; i < n; i++ )
|
||||
* {
|
||||
* buf << pkt_seg_hdr[i];
|
||||
* buf << {pkt_seg_data[i]};
|
||||
* }
|
||||
*
|
||||
* The reverse can be done parsing a packet. Remember to validate the packet
|
||||
* type before parsing the headers.
|
||||
*
|
||||
* Compression and Encryption:
|
||||
* ===========================
|
||||
* By using std::iostream's, you can support stream filters. Simply create a
|
||||
* stream that performs the compression or encryption, and use that stream to
|
||||
* read and write.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Structure representing the common header for all FFXIVARR packets.
|
||||
*
|
||||
* 0 4 8 12 14 16
|
||||
* +-------------------------------+---------------+-------+-------+
|
||||
* | unknown_0 | unknown_8 |
|
||||
* +-------------------------------+---------------+-------+-------+
|
||||
* | timestamp | size | cType | count |
|
||||
* +---+---+-------+---------------+---------------+-------+-------+
|
||||
* | ? |CMP| ? | ? |
|
||||
* +---+---+-------+---------------+
|
||||
* (followed by /count/ FFXIVARR_PACKET_SEGMENTs)
|
||||
*/
|
||||
struct FFXIVARR_PACKET_HEADER
|
||||
namespace Core::Network::Packets
|
||||
{
|
||||
/** Unknown data, no actual use has been determined */
|
||||
uint64_t unknown_0;
|
||||
uint64_t unknown_8;
|
||||
/** Represents the number of milliseconds since epoch that the packet was sent. */
|
||||
uint64_t timestamp;
|
||||
/** The size of the packet header and its payload */
|
||||
uint32_t size;
|
||||
/** The type of this connection - 1 zone, 2 chat*/
|
||||
uint16_t connectionType;
|
||||
/** The number of packet segments that follow. */
|
||||
uint16_t count;
|
||||
uint8_t unknown_20;
|
||||
/** Indicates if the data segments of this packet are compressed. */
|
||||
uint8_t isCompressed;
|
||||
uint32_t unknown_24;
|
||||
};
|
||||
|
||||
inline std::ostream& operator<<( std::ostream& os, const FFXIVARR_PACKET_HEADER& hdr )
|
||||
{
|
||||
return os.write( reinterpret_cast< const char* >( &hdr ), sizeof hdr );
|
||||
}
|
||||
/**
|
||||
* Anticipated usage:
|
||||
* ==================
|
||||
* Set up a stream buffer to collect the bytes to be transmitted as a packet.
|
||||
* Now, you can do the following (given you have the structs filled out already).
|
||||
*
|
||||
* FFXIVARR_PACKET_HEADER pkt_hdr = { . . . };
|
||||
* FFXIVARR_PACKET_SEGMENT_HEADER pkt_seg_hdr[n] = { . . . };
|
||||
*
|
||||
* std::stringstream buf;
|
||||
* buf << pkt_hdr;
|
||||
* for( int i = 0; i < n; i++ )
|
||||
* {
|
||||
* buf << pkt_seg_hdr[i];
|
||||
* buf << {pkt_seg_data[i]};
|
||||
* }
|
||||
*
|
||||
* The reverse can be done parsing a packet. Remember to validate the packet
|
||||
* type before parsing the headers.
|
||||
*
|
||||
* Compression and Encryption:
|
||||
* ===========================
|
||||
* By using std::iostream's, you can support stream filters. Simply create a
|
||||
* stream that performs the compression or encryption, and use that stream to
|
||||
* read and write.
|
||||
*/
|
||||
|
||||
inline std::istream& operator>>( std::istream& is, FFXIVARR_PACKET_HEADER& hdr )
|
||||
{
|
||||
return is.read( reinterpret_cast< char* >( &hdr ), sizeof hdr );
|
||||
}
|
||||
|
||||
/**
|
||||
* Structure representing the header portion of a packet segment.
|
||||
*
|
||||
* NOTE: If the main packet header indicated the packet is compressed, this
|
||||
* header will be compressed as well! The header will NOT ever be encrypted.
|
||||
*
|
||||
* 0 4 8 12 16
|
||||
* +---------------+---------------+---------------+-------+-------+
|
||||
* | size | source_actor | target_actor | type | pad |
|
||||
* +---------------+---------------+---------------+-------+-------+
|
||||
* | |
|
||||
* : type-specific data of length, size, follows :
|
||||
* | (NOTE: Some segments MAY be encrypted) |
|
||||
* +---------------------------------------------------------------+
|
||||
*/
|
||||
struct FFXIVARR_PACKET_SEGMENT_HEADER
|
||||
{
|
||||
/** The size of the segment header and its data. */
|
||||
uint32_t size;
|
||||
/** The session ID this segment describes. */
|
||||
uint32_t source_actor;
|
||||
/** The session ID this packet is being delivered to. */
|
||||
uint32_t target_actor;
|
||||
/** The segment type. (1, 2, 3, 7, 8, 9, 10) */
|
||||
uint16_t type;
|
||||
uint16_t padding;
|
||||
};
|
||||
|
||||
inline std::ostream& operator<<( std::ostream& os, const FFXIVARR_PACKET_SEGMENT_HEADER& hdr )
|
||||
{
|
||||
return os.write( reinterpret_cast< const char* >( &hdr ), sizeof hdr );
|
||||
}
|
||||
|
||||
inline std::istream& operator>>( std::istream& is, FFXIVARR_PACKET_SEGMENT_HEADER& hdr )
|
||||
{
|
||||
return is.read( reinterpret_cast< char* >( &hdr ), sizeof hdr );
|
||||
}
|
||||
|
||||
template< int T >
|
||||
struct FFXIVIpcBasePacket
|
||||
{
|
||||
/** Creates a constant representing the IPC type */
|
||||
enum
|
||||
/**
|
||||
* Structure representing the common header for all FFXIVARR packets.
|
||||
*
|
||||
* 0 4 8 12 14 16
|
||||
* +-------------------------------+---------------+-------+-------+
|
||||
* | unknown_0 | unknown_8 |
|
||||
* +-------------------------------+---------------+-------+-------+
|
||||
* | timestamp | size | cType | count |
|
||||
* +---+---+-------+---------------+---------------+-------+-------+
|
||||
* | ? |CMP| ? | ? |
|
||||
* +---+---+-------+---------------+
|
||||
* (followed by /count/ FFXIVARR_PACKET_SEGMENTs)
|
||||
*/
|
||||
struct FFXIVARR_PACKET_HEADER
|
||||
{
|
||||
_ServerIpcType = T
|
||||
/** Unknown data, no actual use has been determined */
|
||||
uint64_t unknown_0;
|
||||
uint64_t unknown_8;
|
||||
/** Represents the number of milliseconds since epoch that the packet was sent. */
|
||||
uint64_t timestamp;
|
||||
/** The size of the packet header and its payload */
|
||||
uint32_t size;
|
||||
/** The type of this connection - 1 zone, 2 chat*/
|
||||
uint16_t connectionType;
|
||||
/** The number of packet segments that follow. */
|
||||
uint16_t count;
|
||||
uint8_t unknown_20;
|
||||
/** Indicates if the data segments of this packet are compressed. */
|
||||
uint8_t isCompressed;
|
||||
uint32_t unknown_24;
|
||||
};
|
||||
};
|
||||
|
||||
struct FFXIVARR_PACKET_RAW
|
||||
{
|
||||
FFXIVARR_PACKET_SEGMENT_HEADER segHdr;
|
||||
std::vector< uint8_t > data;
|
||||
};
|
||||
inline std::ostream& operator<<( std::ostream& os, const FFXIVARR_PACKET_HEADER& hdr )
|
||||
{
|
||||
return os.write( reinterpret_cast< const char* >( &hdr ), sizeof hdr );
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates the type of the segment
|
||||
* IPC type will contain an additional header: FFXIVARR_PACKET_SEGMENT_HEADER + FFXIVARR_IPC_HEADER + data
|
||||
* The remaining types don't contain an additonal header, FFXIVARR_PACKET_SEGMENT_HEADER + data
|
||||
*/
|
||||
enum FFXIVARR_SEGMENT_TYPE
|
||||
{
|
||||
SEGMENTTYPE_SESSIONINIT = 1,
|
||||
SEGMENTTYPE_IPC = 3,
|
||||
SEGMENTTYPE_KEEPALIVE = 7,
|
||||
//SEGMENTTYPE_RESPONSE = 8,
|
||||
SEGMENTTYPE_ENCRYPTIONINIT = 9,
|
||||
};
|
||||
inline std::istream& operator>>( std::istream& is, FFXIVARR_PACKET_HEADER& hdr )
|
||||
{
|
||||
return is.read( reinterpret_cast< char* >( &hdr ), sizeof hdr );
|
||||
}
|
||||
|
||||
/**
|
||||
* Structural representation of the common header for IPC packet segments.
|
||||
* NOTE: This is packet segment type 3.
|
||||
*
|
||||
* 0 4 6 8 12 16
|
||||
* +-------+-------+------+----------+---------------+---------------+
|
||||
* | 14 00 | type | pad | serverId | timestamp | pad1 |
|
||||
* +-------+-------+------+----------+---------------+---------------+
|
||||
* | |
|
||||
* : data :
|
||||
* | |
|
||||
* +-----------------------------------------------------------------+
|
||||
*/
|
||||
struct FFXIVARR_IPC_HEADER
|
||||
{
|
||||
uint16_t reserved;
|
||||
uint16_t type;
|
||||
uint16_t padding;
|
||||
uint16_t serverId;
|
||||
uint32_t timestamp;
|
||||
uint32_t padding1;
|
||||
};
|
||||
/**
|
||||
* Structure representing the header portion of a packet segment.
|
||||
*
|
||||
* NOTE: If the main packet header indicated the packet is compressed, this
|
||||
* header will be compressed as well! The header will NOT ever be encrypted.
|
||||
*
|
||||
* 0 4 8 12 16
|
||||
* +---------------+---------------+---------------+-------+-------+
|
||||
* | size | source_actor | target_actor | type | pad |
|
||||
* +---------------+---------------+---------------+-------+-------+
|
||||
* | |
|
||||
* : type-specific data of length, size, follows :
|
||||
* | (NOTE: Some segments MAY be encrypted) |
|
||||
* +---------------------------------------------------------------+
|
||||
*/
|
||||
struct FFXIVARR_PACKET_SEGMENT_HEADER
|
||||
{
|
||||
/** The size of the segment header and its data. */
|
||||
uint32_t size;
|
||||
/** The session ID this segment describes. */
|
||||
uint32_t source_actor;
|
||||
/** The session ID this packet is being delivered to. */
|
||||
uint32_t target_actor;
|
||||
/** The segment type. (1, 2, 3, 7, 8, 9, 10) */
|
||||
uint16_t type;
|
||||
uint16_t padding;
|
||||
};
|
||||
|
||||
inline std::ostream& operator<<( std::ostream& os, const FFXIVARR_PACKET_SEGMENT_HEADER& hdr )
|
||||
{
|
||||
return os.write( reinterpret_cast< const char* >( &hdr ), sizeof hdr );
|
||||
}
|
||||
|
||||
inline std::istream& operator>>( std::istream& is, FFXIVARR_PACKET_SEGMENT_HEADER& hdr )
|
||||
{
|
||||
return is.read( reinterpret_cast< char* >( &hdr ), sizeof hdr );
|
||||
}
|
||||
|
||||
template< int T >
|
||||
struct FFXIVIpcBasePacket
|
||||
{
|
||||
/** Creates a constant representing the IPC type */
|
||||
enum
|
||||
{
|
||||
_ServerIpcType = T
|
||||
};
|
||||
};
|
||||
|
||||
struct FFXIVARR_PACKET_RAW
|
||||
{
|
||||
FFXIVARR_PACKET_SEGMENT_HEADER segHdr;
|
||||
std::vector< uint8_t > data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Indicates the type of the segment
|
||||
* IPC type will contain an additional header: FFXIVARR_PACKET_SEGMENT_HEADER + FFXIVARR_IPC_HEADER + data
|
||||
* The remaining types don't contain an additonal header, FFXIVARR_PACKET_SEGMENT_HEADER + data
|
||||
*/
|
||||
enum FFXIVARR_SEGMENT_TYPE
|
||||
{
|
||||
SEGMENTTYPE_SESSIONINIT = 1,
|
||||
SEGMENTTYPE_IPC = 3,
|
||||
SEGMENTTYPE_KEEPALIVE = 7,
|
||||
//SEGMENTTYPE_RESPONSE = 8,
|
||||
SEGMENTTYPE_ENCRYPTIONINIT = 9,
|
||||
};
|
||||
|
||||
/**
|
||||
* Structural representation of the common header for IPC packet segments.
|
||||
* NOTE: This is packet segment type 3.
|
||||
*
|
||||
* 0 4 6 8 12 16
|
||||
* +-------+-------+------+----------+---------------+---------------+
|
||||
* | 14 00 | type | pad | serverId | timestamp | pad1 |
|
||||
* +-------+-------+------+----------+---------------+---------------+
|
||||
* | |
|
||||
* : data :
|
||||
* | |
|
||||
* +-----------------------------------------------------------------+
|
||||
*/
|
||||
struct FFXIVARR_IPC_HEADER
|
||||
{
|
||||
uint16_t reserved;
|
||||
uint16_t type;
|
||||
uint16_t padding;
|
||||
uint16_t serverId;
|
||||
uint32_t timestamp;
|
||||
uint32_t padding1;
|
||||
};
|
||||
|
||||
inline std::ostream& operator<<( std::ostream& os, const FFXIVARR_IPC_HEADER& hdr )
|
||||
{
|
||||
return os.write( reinterpret_cast< const char* >( &hdr ), sizeof hdr );
|
||||
}
|
||||
|
||||
inline std::istream& operator>>( std::istream& is, FFXIVARR_IPC_HEADER& hdr )
|
||||
{
|
||||
return is.read( reinterpret_cast< char* >( &hdr ), sizeof hdr );
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<( std::ostream& os, const FFXIVARR_IPC_HEADER& hdr )
|
||||
{
|
||||
return os.write( reinterpret_cast< const char* >( &hdr ), sizeof hdr );
|
||||
}
|
||||
|
||||
inline std::istream& operator>>( std::istream& is, FFXIVARR_IPC_HEADER& hdr )
|
||||
{
|
||||
return is.read( reinterpret_cast< char* >( &hdr ), sizeof hdr );
|
||||
}
|
||||
|
||||
} /* Packets */
|
||||
} /* Network */
|
||||
} /* Core */
|
||||
|
||||
#endif /*_CORE_NETWORK_PACKETS_COMMON_H*/
|
||||
|
|
|
@ -12,157 +12,153 @@
|
|||
#include "Acceptor.h"
|
||||
#include <memory>
|
||||
|
||||
namespace Core {
|
||||
namespace Network {
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class Hive;
|
||||
|
||||
class Acceptor;
|
||||
|
||||
class Connection;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class Connection : public std::enable_shared_from_this< Connection >
|
||||
namespace Core::Network
|
||||
{
|
||||
friend class Acceptor;
|
||||
|
||||
friend class Hive;
|
||||
class Hive;
|
||||
|
||||
protected:
|
||||
HivePtr m_hive;
|
||||
asio::ip::tcp::socket m_socket;
|
||||
asio::strand m_io_strand;
|
||||
std::vector< uint8_t > m_recv_buffer;
|
||||
std::list< int32_t > m_pending_recvs;
|
||||
std::list< std::vector< uint8_t > > m_pending_sends;
|
||||
int32_t m_receive_buffer_size;
|
||||
std::atomic< uint32_t > m_error_state;
|
||||
class Acceptor;
|
||||
|
||||
class Connection;
|
||||
|
||||
Connection( HivePtr hive );
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
virtual ~Connection();
|
||||
|
||||
private:
|
||||
Connection( const Connection& rhs );
|
||||
|
||||
Connection& operator=( const Connection& rhs );
|
||||
|
||||
void StartSend();
|
||||
|
||||
void StartRecv( int32_t total_bytes );
|
||||
|
||||
void StartError( const asio::error_code& error );
|
||||
|
||||
void DispatchSend( std::vector< uint8_t > buffer );
|
||||
|
||||
void DispatchRecv( int32_t total_bytes );
|
||||
|
||||
void HandleConnect( const asio::error_code& error );
|
||||
|
||||
void HandleSend( const asio::error_code& error, std::list< std::vector< uint8_t > >::iterator itr );
|
||||
|
||||
void HandleRecv( const asio::error_code& error, int32_t actual_bytes );
|
||||
|
||||
|
||||
private:
|
||||
// Called when the connection has successfully connected to the local host.
|
||||
virtual void OnAccept( const std::string& host, uint16_t port )
|
||||
class Connection : public std::enable_shared_from_this< Connection >
|
||||
{
|
||||
friend class Acceptor;
|
||||
|
||||
friend class Hive;
|
||||
|
||||
protected:
|
||||
HivePtr m_hive;
|
||||
asio::ip::tcp::socket m_socket;
|
||||
asio::strand m_io_strand;
|
||||
std::vector< uint8_t > m_recv_buffer;
|
||||
std::list< int32_t > m_pending_recvs;
|
||||
std::list< std::vector< uint8_t > > m_pending_sends;
|
||||
int32_t m_receive_buffer_size;
|
||||
std::atomic< uint32_t > m_error_state;
|
||||
|
||||
|
||||
Connection( HivePtr hive );
|
||||
|
||||
virtual ~Connection();
|
||||
|
||||
private:
|
||||
Connection( const Connection& rhs );
|
||||
|
||||
Connection& operator=( const Connection& rhs );
|
||||
|
||||
void StartSend();
|
||||
|
||||
void StartRecv( int32_t total_bytes );
|
||||
|
||||
void StartError( const asio::error_code& error );
|
||||
|
||||
void DispatchSend( std::vector< uint8_t > buffer );
|
||||
|
||||
void DispatchRecv( int32_t total_bytes );
|
||||
|
||||
void HandleConnect( const asio::error_code& error );
|
||||
|
||||
void HandleSend( const asio::error_code& error, std::list< std::vector< uint8_t > >::iterator itr );
|
||||
|
||||
void HandleRecv( const asio::error_code& error, int32_t actual_bytes );
|
||||
|
||||
|
||||
private:
|
||||
// Called when the connection has successfully connected to the local host.
|
||||
virtual void OnAccept( const std::string& host, uint16_t port )
|
||||
{
|
||||
};
|
||||
|
||||
// Called when the connection has successfully connected to the remote host.
|
||||
virtual void OnConnect( const std::string& host, uint16_t port )
|
||||
{
|
||||
};
|
||||
|
||||
// Called when data has been sent by the connection.
|
||||
virtual void OnSend( const std::vector< uint8_t >& buffer )
|
||||
{
|
||||
};
|
||||
|
||||
// Called when data has been received by the connection.
|
||||
virtual void OnRecv( std::vector< uint8_t >& buffer )
|
||||
{
|
||||
};
|
||||
|
||||
// Called when an error is encountered.
|
||||
virtual void OnError( const asio::error_code& error )
|
||||
{
|
||||
};
|
||||
|
||||
// Called when the connection has been disconnected
|
||||
virtual void OnDisconnect()
|
||||
{
|
||||
};
|
||||
|
||||
public:
|
||||
// Returns the Hive object.
|
||||
HivePtr GetHive();
|
||||
|
||||
// Returns the socket object.
|
||||
asio::ip::tcp::socket& GetSocket();
|
||||
|
||||
// Returns the strand object.
|
||||
asio::strand& GetStrand();
|
||||
|
||||
// Sets the application specific receive buffer size used. For stream
|
||||
// based protocols such as HTTP, you want this to be pretty large, like
|
||||
// 64kb. For packet based protocols, then it will be much smaller,
|
||||
// usually 512b - 8kb depending on the protocol. The default value is
|
||||
// 4kb.
|
||||
void SetReceiveBufferSize( int32_t size );
|
||||
|
||||
// Returns the size of the receive buffer size of the current object.
|
||||
int32_t GetReceiveBufferSize() const;
|
||||
|
||||
// Returns true if this object has an error associated with it.
|
||||
bool HasError();
|
||||
|
||||
// Binds the socket to the specified interface.
|
||||
void Bind( const std::string& ip, uint16_t port );
|
||||
|
||||
// Starts an a/synchronous connect.
|
||||
void Connect( const std::string& host, uint16_t port );
|
||||
|
||||
// Posts data to be sent to the connection.
|
||||
void Send( const std::vector< uint8_t >& buffer );
|
||||
|
||||
// Posts a recv for the connection to process. If total_bytes is 0, then
|
||||
// as many bytes as possible up to GetReceiveBufferSize() will be
|
||||
// waited for. If Recv is not 0, then the connection will wait for exactly
|
||||
// total_bytes before invoking OnRecv.
|
||||
void Recv( int32_t total_bytes = 0 );
|
||||
|
||||
// Posts an asynchronous disconnect event for the object to process.
|
||||
void Disconnect();
|
||||
};
|
||||
|
||||
// Called when the connection has successfully connected to the remote host.
|
||||
virtual void OnConnect( const std::string& host, uint16_t port )
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< class T >
|
||||
std::shared_ptr< T > addServerToHive( const std::string& listenIp, uint32_t port, HivePtr pHive )
|
||||
{
|
||||
};
|
||||
|
||||
// Called when data has been sent by the connection.
|
||||
virtual void OnSend( const std::vector< uint8_t >& buffer )
|
||||
{
|
||||
};
|
||||
|
||||
// Called when data has been received by the connection.
|
||||
virtual void OnRecv( std::vector< uint8_t >& buffer )
|
||||
{
|
||||
};
|
||||
|
||||
// Called when an error is encountered.
|
||||
virtual void OnError( const asio::error_code& error )
|
||||
{
|
||||
};
|
||||
|
||||
// Called when the connection has been disconnected
|
||||
virtual void OnDisconnect()
|
||||
{
|
||||
};
|
||||
|
||||
public:
|
||||
// Returns the Hive object.
|
||||
HivePtr GetHive();
|
||||
|
||||
// Returns the socket object.
|
||||
asio::ip::tcp::socket& GetSocket();
|
||||
|
||||
// Returns the strand object.
|
||||
asio::strand& GetStrand();
|
||||
|
||||
// Sets the application specific receive buffer size used. For stream
|
||||
// based protocols such as HTTP, you want this to be pretty large, like
|
||||
// 64kb. For packet based protocols, then it will be much smaller,
|
||||
// usually 512b - 8kb depending on the protocol. The default value is
|
||||
// 4kb.
|
||||
void SetReceiveBufferSize( int32_t size );
|
||||
|
||||
// Returns the size of the receive buffer size of the current object.
|
||||
int32_t GetReceiveBufferSize() const;
|
||||
|
||||
// Returns true if this object has an error associated with it.
|
||||
bool HasError();
|
||||
|
||||
// Binds the socket to the specified interface.
|
||||
void Bind( const std::string& ip, uint16_t port );
|
||||
|
||||
// Starts an a/synchronous connect.
|
||||
void Connect( const std::string& host, uint16_t port );
|
||||
|
||||
// Posts data to be sent to the connection.
|
||||
void Send( const std::vector< uint8_t >& buffer );
|
||||
|
||||
// Posts a recv for the connection to process. If total_bytes is 0, then
|
||||
// as many bytes as possible up to GetReceiveBufferSize() will be
|
||||
// waited for. If Recv is not 0, then the connection will wait for exactly
|
||||
// total_bytes before invoking OnRecv.
|
||||
void Recv( int32_t total_bytes = 0 );
|
||||
|
||||
// Posts an asynchronous disconnect event for the object to process.
|
||||
void Disconnect();
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< class T >
|
||||
std::shared_ptr< T > addServerToHive( const std::string& listenIp, uint32_t port, HivePtr pHive )
|
||||
{
|
||||
try
|
||||
{
|
||||
AcceptorPtr acceptor( new Acceptor( pHive ) );
|
||||
acceptor->Listen( listenIp, port );
|
||||
std::shared_ptr< T > connection( new T( pHive, acceptor ) );
|
||||
acceptor->Accept( connection );
|
||||
return connection;
|
||||
try
|
||||
{
|
||||
AcceptorPtr acceptor( new Acceptor( pHive ) );
|
||||
acceptor->Listen( listenIp, port );
|
||||
std::shared_ptr< T > connection( new T( pHive, acceptor ) );
|
||||
acceptor->Accept( connection );
|
||||
return connection;
|
||||
}
|
||||
catch( std::runtime_error e )
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
catch( std::runtime_error e )
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -14,326 +14,323 @@
|
|||
#include "CommonNetwork.h"
|
||||
#include "PacketDef/Ipcs.h"
|
||||
|
||||
namespace Core {
|
||||
namespace Network {
|
||||
namespace Packets {
|
||||
|
||||
// Must forward define these in order to enable the compiler to produce the
|
||||
// correct template functions.
|
||||
|
||||
template< typename T, typename T1 >
|
||||
class FFXIVIpcPacket;
|
||||
|
||||
template< class T >
|
||||
using ZoneChannelPacket = FFXIVIpcPacket< T, ServerZoneIpcType >;
|
||||
|
||||
template< class T >
|
||||
using ChatChannelPacket = FFXIVIpcPacket< T, ServerChatIpcType >;
|
||||
|
||||
template< class T >
|
||||
using LobbyChannelPacket = FFXIVIpcPacket< T, ServerLobbyIpcType >;
|
||||
|
||||
|
||||
template< class T, typename... Args >
|
||||
std::shared_ptr< ZoneChannelPacket< T > > makeZonePacket( Args... args )
|
||||
namespace Core::Network::Packets
|
||||
{
|
||||
return std::make_shared< ZoneChannelPacket< T > >( args... );
|
||||
|
||||
// Must forward define these in order to enable the compiler to produce the
|
||||
// correct template functions.
|
||||
|
||||
template< typename T, typename T1 >
|
||||
class FFXIVIpcPacket;
|
||||
|
||||
template< class T >
|
||||
using ZoneChannelPacket = FFXIVIpcPacket< T, ServerZoneIpcType >;
|
||||
|
||||
template< class T >
|
||||
using ChatChannelPacket = FFXIVIpcPacket< T, ServerChatIpcType >;
|
||||
|
||||
template< class T >
|
||||
using LobbyChannelPacket = FFXIVIpcPacket< T, ServerLobbyIpcType >;
|
||||
|
||||
|
||||
template< class T, typename... Args >
|
||||
std::shared_ptr< ZoneChannelPacket< T > > makeZonePacket( Args... args )
|
||||
{
|
||||
return std::make_shared< ZoneChannelPacket< T > >( args... );
|
||||
}
|
||||
|
||||
template< class T, typename... Args >
|
||||
std::shared_ptr< T > makeWrappedPacket( Args... args )
|
||||
{
|
||||
return std::make_shared< T >( args... );
|
||||
}
|
||||
|
||||
template< class T, typename... Args >
|
||||
std::shared_ptr< ChatChannelPacket< T > > makeChatPacket( Args... args )
|
||||
{
|
||||
return std::make_shared< ChatChannelPacket< T > >( args... );
|
||||
}
|
||||
|
||||
template< class T, typename... Args >
|
||||
std::shared_ptr< LobbyChannelPacket< T > > makeLobbyPacket( Args... args )
|
||||
{
|
||||
return std::make_shared< LobbyChannelPacket< T > >( args... );
|
||||
}
|
||||
|
||||
/**
|
||||
* The base implementation of a game packet. Needed for parsing packets.
|
||||
*/
|
||||
template< typename T1 >
|
||||
class FFXIVIpcPacketBase
|
||||
{
|
||||
public:
|
||||
virtual ~FFXIVIpcPacketBase() = default;
|
||||
|
||||
/**
|
||||
* @brief Gets the IPC type of this packet. (Useful for determining the
|
||||
* type of a parsed packet.)
|
||||
*/
|
||||
virtual T1 ipcType() = 0;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////7
|
||||
|
||||
class FFXIVPacketBase
|
||||
{
|
||||
public:
|
||||
FFXIVPacketBase() :
|
||||
m_segmentType( 0 )
|
||||
{
|
||||
initializeSegmentHeader();
|
||||
}
|
||||
|
||||
FFXIVPacketBase( uint16_t segmentType, uint32_t sourceActorId, uint32_t targetActorId ) :
|
||||
m_segmentType( segmentType )
|
||||
{
|
||||
initializeSegmentHeader();
|
||||
setSourceActor( sourceActorId );
|
||||
setTargetActor( targetActorId );
|
||||
}
|
||||
|
||||
std::size_t getSize() const
|
||||
{
|
||||
return m_segHdr.size;
|
||||
}
|
||||
|
||||
virtual std::vector< uint8_t > getData() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
protected:
|
||||
/** The segment header */
|
||||
FFXIVARR_PACKET_SEGMENT_HEADER m_segHdr;
|
||||
uint16_t m_segmentType;
|
||||
|
||||
public:
|
||||
virtual uint32_t getContentSize()
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
|
||||
virtual std::vector< uint8_t > getContent()
|
||||
{
|
||||
return {};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Gets the segment type of this packet.
|
||||
*/
|
||||
uint16_t getSegmentType() const
|
||||
{
|
||||
return m_segmentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the source actor id for this packet.
|
||||
* @param actorId The source actor id.
|
||||
*/
|
||||
void setSourceActor( uint32_t actorId )
|
||||
{
|
||||
m_segHdr.source_actor = actorId;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Gets the source actor id for this packet.
|
||||
* @return The source actor id.
|
||||
*/
|
||||
uint32_t getSourceActor() const
|
||||
{
|
||||
return m_segHdr.source_actor;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Sets the target actor id for this packet.
|
||||
* @param actorId The target actor id.
|
||||
*/
|
||||
void setTargetActor( uint32_t actorId )
|
||||
{
|
||||
m_segHdr.target_actor = actorId;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Gets the target actor id for this packet.
|
||||
*/
|
||||
uint32_t getTargetActor( void ) const
|
||||
{
|
||||
return m_segHdr.target_actor;
|
||||
};
|
||||
|
||||
/** Initializes the fields of the segment header structure */
|
||||
virtual void initializeSegmentHeader( void )
|
||||
{
|
||||
// Zero out the structure.
|
||||
memset( &m_segHdr, 0, sizeof( FFXIVARR_PACKET_SEGMENT_HEADER ) );
|
||||
|
||||
// Set the values of static fields.
|
||||
// The size must be the sum of the segment header and the content
|
||||
m_segHdr.size = sizeof( FFXIVARR_PACKET_SEGMENT_HEADER ) + getContentSize();
|
||||
m_segHdr.type = getSegmentType();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template< typename T, typename T1 >
|
||||
class FFXIVIpcPacket :
|
||||
public FFXIVIpcPacketBase< T1 >, public FFXIVPacketBase
|
||||
{
|
||||
public:
|
||||
FFXIVIpcPacket< T, T1 >( uint32_t sourceActorId, uint32_t targetActorId ) :
|
||||
FFXIVPacketBase( 3, sourceActorId, targetActorId )
|
||||
{
|
||||
initialize();
|
||||
};
|
||||
|
||||
FFXIVIpcPacket< T, T1 >( uint32_t sourceActorId ) :
|
||||
FFXIVPacketBase( 3, sourceActorId, sourceActorId )
|
||||
{
|
||||
initialize();
|
||||
};
|
||||
|
||||
FFXIVIpcPacket< T, T1 >( const FFXIVARR_PACKET_RAW& rawPacket )
|
||||
{
|
||||
auto ipcHdrSize = sizeof( FFXIVARR_IPC_HEADER );
|
||||
auto copySize = std::min< uint32_t >( sizeof( T ), rawPacket.segHdr.size - ipcHdrSize );
|
||||
|
||||
memcpy( &m_segHdr, &rawPacket.segHdr, sizeof( FFXIVARR_PACKET_SEGMENT_HEADER ) );
|
||||
memcpy( &m_data, &rawPacket.data[ 0 ] + ipcHdrSize, copySize );
|
||||
|
||||
memset( &m_ipcHdr, 0, ipcHdrSize );
|
||||
m_ipcHdr.type = static_cast< ServerZoneIpcType >( m_data._ServerIpcType );
|
||||
}
|
||||
|
||||
uint32_t getContentSize() override
|
||||
{
|
||||
return sizeof( FFXIVARR_IPC_HEADER ) + sizeof( T );
|
||||
}
|
||||
|
||||
std::vector< uint8_t > getContent() override
|
||||
{
|
||||
std::vector< uint8_t > content( getContentSize() );
|
||||
memcpy( content.data(), &m_ipcHdr, sizeof( FFXIVARR_IPC_HEADER ) );
|
||||
memcpy( content.data() + sizeof( FFXIVARR_IPC_HEADER ), &m_data, sizeof( T ) );
|
||||
return content;
|
||||
}
|
||||
|
||||
std::vector< uint8_t > getData() const override
|
||||
{
|
||||
auto segmentHeaderSize = sizeof( FFXIVARR_PACKET_SEGMENT_HEADER );
|
||||
auto ipcHeaderSize = sizeof( FFXIVARR_IPC_HEADER );
|
||||
auto dataSize = sizeof( m_data );
|
||||
|
||||
std::vector< uint8_t > data( segmentHeaderSize + ipcHeaderSize + dataSize );
|
||||
|
||||
memcpy( &data[ 0 ], &m_segHdr, segmentHeaderSize );
|
||||
memcpy( &data[ segmentHeaderSize ], &m_ipcHdr, ipcHeaderSize );
|
||||
memcpy( &data[ segmentHeaderSize + ipcHeaderSize ], &m_data, dataSize );
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
T1 ipcType() override
|
||||
{
|
||||
return static_cast< T1 >( m_data._ServerIpcType );
|
||||
};
|
||||
|
||||
/** Gets a reference to the underlying IPC data structure. */
|
||||
T& data()
|
||||
{
|
||||
return m_data;
|
||||
};
|
||||
|
||||
const T& data() const
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
protected:
|
||||
/** Initializes the fields of the header structures */
|
||||
virtual void initialize()
|
||||
{
|
||||
// Zero out the structures.
|
||||
memset( &m_ipcHdr, 0, sizeof( FFXIVARR_IPC_HEADER ) );
|
||||
memset( &m_data, 0, sizeof( T ) );
|
||||
|
||||
// The IPC type itself.
|
||||
m_ipcHdr.type = static_cast< ServerZoneIpcType >( m_data._ServerIpcType );
|
||||
m_ipcHdr.timestamp = static_cast< uint32_t >( Util::getTimeSeconds() );
|
||||
m_segHdr.size = sizeof( T ) + sizeof( FFXIVARR_IPC_HEADER ) + sizeof( FFXIVARR_PACKET_SEGMENT_HEADER );
|
||||
};
|
||||
|
||||
protected:
|
||||
/** The IPC packet header */
|
||||
FFXIVARR_IPC_HEADER m_ipcHdr;
|
||||
/** The underlying data portion of the packet as a structure */
|
||||
T m_data;
|
||||
};
|
||||
|
||||
|
||||
class FFXIVRawPacket :
|
||||
public FFXIVPacketBase
|
||||
{
|
||||
public:
|
||||
FFXIVRawPacket( uint16_t type, uint32_t size, uint32_t sourceActorId, uint32_t targetActorId ) :
|
||||
m_data( std::vector< uint8_t >( size - sizeof( FFXIVARR_PACKET_SEGMENT_HEADER ) ) ),
|
||||
FFXIVPacketBase( type, sourceActorId, targetActorId )
|
||||
{
|
||||
initialize();
|
||||
m_segHdr.size = size;
|
||||
};
|
||||
|
||||
FFXIVRawPacket( char* data, uint16_t size ) :
|
||||
m_data( std::vector< uint8_t >( size ) )
|
||||
{
|
||||
auto segmentHdrSize = sizeof( FFXIVARR_PACKET_SEGMENT_HEADER );
|
||||
|
||||
memcpy( &m_data[ 0 ], data + segmentHdrSize, size - segmentHdrSize );
|
||||
memcpy( &m_segHdr, data, segmentHdrSize );
|
||||
}
|
||||
|
||||
uint32_t getContentSize() override
|
||||
{
|
||||
return m_data.size();
|
||||
}
|
||||
|
||||
std::vector< uint8_t > getContent() override
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
virtual std::vector< uint8_t > getData() const override
|
||||
{
|
||||
std::vector< uint8_t > data( sizeof( FFXIVARR_PACKET_SEGMENT_HEADER ) + m_data.size() );
|
||||
|
||||
memcpy( &data[ 0 ], &m_segHdr, sizeof( FFXIVARR_PACKET_SEGMENT_HEADER ) );
|
||||
memcpy( &data[ sizeof( FFXIVARR_PACKET_SEGMENT_HEADER ) ], &m_data[ 0 ], m_data.size() );
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/** Gets a reference to the underlying IPC data structure. */
|
||||
std::vector< uint8_t >& data()
|
||||
{
|
||||
return m_data;
|
||||
};
|
||||
|
||||
protected:
|
||||
/** Initializes the fields of the header structures */
|
||||
virtual void initialize()
|
||||
{
|
||||
// Zero out the structures.
|
||||
memset( &m_data[ 0 ], 0, m_data.size() );
|
||||
};
|
||||
|
||||
protected:
|
||||
/** The underlying data portion of the packet as a structure */
|
||||
std::vector< uint8_t > m_data;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
template< class T, typename... Args >
|
||||
std::shared_ptr< T > makeWrappedPacket( Args... args )
|
||||
{
|
||||
return std::make_shared< T >( args... );
|
||||
}
|
||||
|
||||
template< class T, typename... Args >
|
||||
std::shared_ptr< ChatChannelPacket< T > > makeChatPacket( Args... args )
|
||||
{
|
||||
return std::make_shared< ChatChannelPacket< T > >( args... );
|
||||
}
|
||||
|
||||
template< class T, typename... Args >
|
||||
std::shared_ptr< LobbyChannelPacket< T > > makeLobbyPacket( Args... args )
|
||||
{
|
||||
return std::make_shared< LobbyChannelPacket< T > >( args... );
|
||||
}
|
||||
|
||||
/**
|
||||
* The base implementation of a game packet. Needed for parsing packets.
|
||||
*/
|
||||
template< typename T1 >
|
||||
class FFXIVIpcPacketBase
|
||||
{
|
||||
public:
|
||||
virtual ~FFXIVIpcPacketBase() = default;
|
||||
|
||||
/**
|
||||
* @brief Gets the IPC type of this packet. (Useful for determining the
|
||||
* type of a parsed packet.)
|
||||
*/
|
||||
virtual T1 ipcType() = 0;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////7
|
||||
|
||||
class FFXIVPacketBase
|
||||
{
|
||||
public:
|
||||
FFXIVPacketBase() :
|
||||
m_segmentType( 0 )
|
||||
{
|
||||
initializeSegmentHeader();
|
||||
}
|
||||
|
||||
FFXIVPacketBase( uint16_t segmentType, uint32_t sourceActorId, uint32_t targetActorId ) :
|
||||
m_segmentType( segmentType )
|
||||
{
|
||||
initializeSegmentHeader();
|
||||
setSourceActor( sourceActorId );
|
||||
setTargetActor( targetActorId );
|
||||
}
|
||||
|
||||
std::size_t getSize() const
|
||||
{
|
||||
return m_segHdr.size;
|
||||
}
|
||||
|
||||
virtual std::vector< uint8_t > getData() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
protected:
|
||||
/** The segment header */
|
||||
FFXIVARR_PACKET_SEGMENT_HEADER m_segHdr;
|
||||
uint16_t m_segmentType;
|
||||
|
||||
public:
|
||||
virtual uint32_t getContentSize()
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
|
||||
virtual std::vector< uint8_t > getContent()
|
||||
{
|
||||
return {};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Gets the segment type of this packet.
|
||||
*/
|
||||
uint16_t getSegmentType() const
|
||||
{
|
||||
return m_segmentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the source actor id for this packet.
|
||||
* @param actorId The source actor id.
|
||||
*/
|
||||
void setSourceActor( uint32_t actorId )
|
||||
{
|
||||
m_segHdr.source_actor = actorId;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Gets the source actor id for this packet.
|
||||
* @return The source actor id.
|
||||
*/
|
||||
uint32_t getSourceActor() const
|
||||
{
|
||||
return m_segHdr.source_actor;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Sets the target actor id for this packet.
|
||||
* @param actorId The target actor id.
|
||||
*/
|
||||
void setTargetActor( uint32_t actorId )
|
||||
{
|
||||
m_segHdr.target_actor = actorId;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Gets the target actor id for this packet.
|
||||
*/
|
||||
uint32_t getTargetActor( void ) const
|
||||
{
|
||||
return m_segHdr.target_actor;
|
||||
};
|
||||
|
||||
/** Initializes the fields of the segment header structure */
|
||||
virtual void initializeSegmentHeader( void )
|
||||
{
|
||||
// Zero out the structure.
|
||||
memset( &m_segHdr, 0, sizeof( FFXIVARR_PACKET_SEGMENT_HEADER ) );
|
||||
|
||||
// Set the values of static fields.
|
||||
// The size must be the sum of the segment header and the content
|
||||
m_segHdr.size = sizeof( FFXIVARR_PACKET_SEGMENT_HEADER ) + getContentSize();
|
||||
m_segHdr.type = getSegmentType();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template< typename T, typename T1 >
|
||||
class FFXIVIpcPacket :
|
||||
public FFXIVIpcPacketBase< T1 >, public FFXIVPacketBase
|
||||
{
|
||||
public:
|
||||
FFXIVIpcPacket< T, T1 >( uint32_t sourceActorId, uint32_t targetActorId ) :
|
||||
FFXIVPacketBase( 3, sourceActorId, targetActorId )
|
||||
{
|
||||
initialize();
|
||||
};
|
||||
|
||||
FFXIVIpcPacket< T, T1 >( uint32_t sourceActorId ) :
|
||||
FFXIVPacketBase( 3, sourceActorId, sourceActorId )
|
||||
{
|
||||
initialize();
|
||||
};
|
||||
|
||||
FFXIVIpcPacket< T, T1 >( const FFXIVARR_PACKET_RAW& rawPacket )
|
||||
{
|
||||
auto ipcHdrSize = sizeof( FFXIVARR_IPC_HEADER );
|
||||
auto copySize = std::min< uint32_t >( sizeof( T ), rawPacket.segHdr.size - ipcHdrSize );
|
||||
|
||||
memcpy( &m_segHdr, &rawPacket.segHdr, sizeof( FFXIVARR_PACKET_SEGMENT_HEADER ) );
|
||||
memcpy( &m_data, &rawPacket.data[ 0 ] + ipcHdrSize, copySize );
|
||||
|
||||
memset( &m_ipcHdr, 0, ipcHdrSize );
|
||||
m_ipcHdr.type = static_cast< ServerZoneIpcType >( m_data._ServerIpcType );
|
||||
}
|
||||
|
||||
uint32_t getContentSize() override
|
||||
{
|
||||
return sizeof( FFXIVARR_IPC_HEADER ) + sizeof( T );
|
||||
}
|
||||
|
||||
std::vector< uint8_t > getContent() override
|
||||
{
|
||||
std::vector< uint8_t > content( getContentSize() );
|
||||
memcpy( content.data(), &m_ipcHdr, sizeof( FFXIVARR_IPC_HEADER ) );
|
||||
memcpy( content.data() + sizeof( FFXIVARR_IPC_HEADER ), &m_data, sizeof( T ) );
|
||||
return content;
|
||||
}
|
||||
|
||||
std::vector< uint8_t > getData() const override
|
||||
{
|
||||
auto segmentHeaderSize = sizeof( FFXIVARR_PACKET_SEGMENT_HEADER );
|
||||
auto ipcHeaderSize = sizeof( FFXIVARR_IPC_HEADER );
|
||||
auto dataSize = sizeof( m_data );
|
||||
|
||||
std::vector< uint8_t > data( segmentHeaderSize + ipcHeaderSize + dataSize );
|
||||
|
||||
memcpy( &data[ 0 ], &m_segHdr, segmentHeaderSize );
|
||||
memcpy( &data[ segmentHeaderSize ], &m_ipcHdr, ipcHeaderSize );
|
||||
memcpy( &data[ segmentHeaderSize + ipcHeaderSize ], &m_data, dataSize );
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
T1 ipcType() override
|
||||
{
|
||||
return static_cast< T1 >( m_data._ServerIpcType );
|
||||
};
|
||||
|
||||
/** Gets a reference to the underlying IPC data structure. */
|
||||
T& data()
|
||||
{
|
||||
return m_data;
|
||||
};
|
||||
|
||||
const T& data() const
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
protected:
|
||||
/** Initializes the fields of the header structures */
|
||||
virtual void initialize()
|
||||
{
|
||||
// Zero out the structures.
|
||||
memset( &m_ipcHdr, 0, sizeof( FFXIVARR_IPC_HEADER ) );
|
||||
memset( &m_data, 0, sizeof( T ) );
|
||||
|
||||
// The IPC type itself.
|
||||
m_ipcHdr.type = static_cast< ServerZoneIpcType >( m_data._ServerIpcType );
|
||||
m_ipcHdr.timestamp = static_cast< uint32_t >( Util::getTimeSeconds() );
|
||||
m_segHdr.size = sizeof( T ) + sizeof( FFXIVARR_IPC_HEADER ) + sizeof( FFXIVARR_PACKET_SEGMENT_HEADER );
|
||||
};
|
||||
|
||||
protected:
|
||||
/** The IPC packet header */
|
||||
FFXIVARR_IPC_HEADER m_ipcHdr;
|
||||
/** The underlying data portion of the packet as a structure */
|
||||
T m_data;
|
||||
};
|
||||
|
||||
|
||||
class FFXIVRawPacket :
|
||||
public FFXIVPacketBase
|
||||
{
|
||||
public:
|
||||
FFXIVRawPacket( uint16_t type, uint32_t size, uint32_t sourceActorId, uint32_t targetActorId ) :
|
||||
m_data( std::vector< uint8_t >( size - sizeof( FFXIVARR_PACKET_SEGMENT_HEADER ) ) ),
|
||||
FFXIVPacketBase( type, sourceActorId, targetActorId )
|
||||
{
|
||||
initialize();
|
||||
m_segHdr.size = size;
|
||||
};
|
||||
|
||||
FFXIVRawPacket( char* data, uint16_t size ) :
|
||||
m_data( std::vector< uint8_t >( size ) )
|
||||
{
|
||||
auto segmentHdrSize = sizeof( FFXIVARR_PACKET_SEGMENT_HEADER );
|
||||
|
||||
memcpy( &m_data[ 0 ], data + segmentHdrSize, size - segmentHdrSize );
|
||||
memcpy( &m_segHdr, data, segmentHdrSize );
|
||||
}
|
||||
|
||||
uint32_t getContentSize() override
|
||||
{
|
||||
return m_data.size();
|
||||
}
|
||||
|
||||
std::vector< uint8_t > getContent() override
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
virtual std::vector< uint8_t > getData() const override
|
||||
{
|
||||
std::vector< uint8_t > data( sizeof( FFXIVARR_PACKET_SEGMENT_HEADER ) + m_data.size() );
|
||||
|
||||
memcpy( &data[ 0 ], &m_segHdr, sizeof( FFXIVARR_PACKET_SEGMENT_HEADER ) );
|
||||
memcpy( &data[ sizeof( FFXIVARR_PACKET_SEGMENT_HEADER ) ], &m_data[ 0 ], m_data.size() );
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/** Gets a reference to the underlying IPC data structure. */
|
||||
std::vector< uint8_t >& data()
|
||||
{
|
||||
return m_data;
|
||||
};
|
||||
|
||||
protected:
|
||||
/** Initializes the fields of the header structures */
|
||||
virtual void initialize()
|
||||
{
|
||||
// Zero out the structures.
|
||||
memset( &m_data[ 0 ], 0, m_data.size() );
|
||||
};
|
||||
|
||||
protected:
|
||||
/** The underlying data portion of the packet as a structure */
|
||||
std::vector< uint8_t > m_data;
|
||||
};
|
||||
|
||||
|
||||
} /* Packets */
|
||||
} /* Network */
|
||||
} /* Core */
|
||||
|
||||
#endif /*_CORE_NETWORK_PACKETS_CGAMEPACKETNEW_H*/
|
||||
|
|
|
@ -3,51 +3,47 @@
|
|||
|
||||
#include "CommonNetwork.h"
|
||||
|
||||
namespace Core {
|
||||
namespace Network {
|
||||
namespace Packets {
|
||||
|
||||
enum PacketParseResult
|
||||
namespace Core::Network::Packets
|
||||
{
|
||||
/// Dissected game packet successfully
|
||||
Success,
|
||||
|
||||
/// Buffer is too short to dissect a message.
|
||||
Incomplete,
|
||||
enum PacketParseResult
|
||||
{
|
||||
/// Dissected game packet successfully
|
||||
Success,
|
||||
|
||||
/// Invalid data detected.
|
||||
Malformed
|
||||
};
|
||||
/// Buffer is too short to dissect a message.
|
||||
Incomplete,
|
||||
|
||||
/// Read packet header from buffer with given offset.
|
||||
/// Buffer with given offset must be pointing to start of the new FFXIV packet.
|
||||
PacketParseResult getHeader( const std::vector< uint8_t >& buffer, const uint32_t offset,
|
||||
FFXIVARR_PACKET_HEADER& header );
|
||||
/// Invalid data detected.
|
||||
Malformed
|
||||
};
|
||||
|
||||
/// Read packet header from buffer with given offset.
|
||||
/// Buffer with given offset must be pointing to start of FFXIVARR_PACKET_SEGMENT_HEADER data.
|
||||
/// Keep in mind that this function does check for data validity. Call checkSegmentHeader() if that's needed.
|
||||
PacketParseResult getSegmentHeader( const std::vector< uint8_t >& buffer, const uint32_t offset,
|
||||
FFXIVARR_PACKET_SEGMENT_HEADER& header );
|
||||
/// Read packet header from buffer with given offset.
|
||||
/// Buffer with given offset must be pointing to start of the new FFXIV packet.
|
||||
PacketParseResult getHeader( const std::vector< uint8_t >& buffer, const uint32_t offset,
|
||||
FFXIVARR_PACKET_HEADER& header );
|
||||
|
||||
/// Read packets from the buffer with given offset.
|
||||
/// Buffer with given offset must be pointing to end of FFXIVARR_PACKET_HEADER data.
|
||||
PacketParseResult getPackets( const std::vector< uint8_t >& buffer, const uint32_t offset,
|
||||
const FFXIVARR_PACKET_HEADER& header,
|
||||
std::vector< Packets::FFXIVARR_PACKET_RAW >& packets );
|
||||
/// Read packet header from buffer with given offset.
|
||||
/// Buffer with given offset must be pointing to start of FFXIVARR_PACKET_SEGMENT_HEADER data.
|
||||
/// Keep in mind that this function does check for data validity. Call checkSegmentHeader() if that's needed.
|
||||
PacketParseResult getSegmentHeader( const std::vector< uint8_t >& buffer, const uint32_t offset,
|
||||
FFXIVARR_PACKET_SEGMENT_HEADER& header );
|
||||
|
||||
/// Read single packet from the buffer with given offset.
|
||||
/// Buffer with an offset must be pointing to start of FFXIVARR_PACKET_SEGMENT_HEADER data.
|
||||
PacketParseResult getPacket( const std::vector< uint8_t >& buffer, const uint32_t offset,
|
||||
FFXIVARR_PACKET_RAW& packet );
|
||||
/// Read packets from the buffer with given offset.
|
||||
/// Buffer with given offset must be pointing to end of FFXIVARR_PACKET_HEADER data.
|
||||
PacketParseResult getPackets( const std::vector< uint8_t >& buffer, const uint32_t offset,
|
||||
const FFXIVARR_PACKET_HEADER& header,
|
||||
std::vector< Packets::FFXIVARR_PACKET_RAW >& packets );
|
||||
|
||||
bool checkHeader( const FFXIVARR_PACKET_HEADER& header );
|
||||
/// Read single packet from the buffer with given offset.
|
||||
/// Buffer with an offset must be pointing to start of FFXIVARR_PACKET_SEGMENT_HEADER data.
|
||||
PacketParseResult getPacket( const std::vector< uint8_t >& buffer, const uint32_t offset,
|
||||
FFXIVARR_PACKET_RAW& packet );
|
||||
|
||||
bool checkSegmentHeader( const FFXIVARR_PACKET_SEGMENT_HEADER& header );
|
||||
bool checkHeader( const FFXIVARR_PACKET_HEADER& header );
|
||||
|
||||
bool checkSegmentHeader( const FFXIVARR_PACKET_SEGMENT_HEADER& header );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
|
@ -5,52 +5,50 @@
|
|||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
namespace Core {
|
||||
namespace Network {
|
||||
|
||||
class Hive : public std::enable_shared_from_this< Hive >
|
||||
namespace Core:: Network
|
||||
{
|
||||
private:
|
||||
asio::io_service m_io_service;
|
||||
std::shared_ptr< asio::io_service::work > m_work_ptr;
|
||||
std::atomic< uint32_t > m_shutdown;
|
||||
|
||||
private:
|
||||
Hive( const Hive& rhs );
|
||||
class Hive : public std::enable_shared_from_this< Hive >
|
||||
{
|
||||
private:
|
||||
asio::io_service m_io_service;
|
||||
std::shared_ptr< asio::io_service::work > m_work_ptr;
|
||||
std::atomic< uint32_t > m_shutdown;
|
||||
|
||||
Hive& operator=( const Hive& rhs );
|
||||
private:
|
||||
Hive( const Hive& rhs );
|
||||
|
||||
public:
|
||||
Hive();
|
||||
Hive& operator=( const Hive& rhs );
|
||||
|
||||
virtual ~Hive();
|
||||
public:
|
||||
Hive();
|
||||
|
||||
// Returns the io_service of this object.
|
||||
asio::io_service& GetService();
|
||||
virtual ~Hive();
|
||||
|
||||
// Returns true if the Stop function has been called.
|
||||
bool HasStopped();
|
||||
// Returns the io_service of this object.
|
||||
asio::io_service& GetService();
|
||||
|
||||
// Polls the networking subsystem once from the current thread and
|
||||
// returns.
|
||||
void Poll();
|
||||
// Returns true if the Stop function has been called.
|
||||
bool HasStopped();
|
||||
|
||||
// Runs the networking system on the current thread. This function blocks
|
||||
// until the networking system is stopped, so do not call on a single
|
||||
// threaded application with no other means of being able to call Stop
|
||||
// unless you code in such logic.
|
||||
void Run();
|
||||
// Polls the networking subsystem once from the current thread and
|
||||
// returns.
|
||||
void Poll();
|
||||
|
||||
// Stops the networking system. All work is finished and no more
|
||||
// networking interactions will be possible afterwards until Reset is called.
|
||||
void Stop();
|
||||
// Runs the networking system on the current thread. This function blocks
|
||||
// until the networking system is stopped, so do not call on a single
|
||||
// threaded application with no other means of being able to call Stop
|
||||
// unless you code in such logic.
|
||||
void Run();
|
||||
|
||||
// Restarts the networking system after Stop as been called. A new work
|
||||
// object is created ad the shutdown flag is cleared.
|
||||
void Reset();
|
||||
};
|
||||
// Stops the networking system. All work is finished and no more
|
||||
// networking interactions will be possible afterwards until Reset is called.
|
||||
void Stop();
|
||||
|
||||
// Restarts the networking system after Stop as been called. A new work
|
||||
// object is created ad the shutdown flag is cleared.
|
||||
void Reset();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
#endif
|
||||
|
|
|
@ -8,36 +8,33 @@
|
|||
#include "GamePacketNew.h"
|
||||
#include "Forwards.h"
|
||||
|
||||
namespace Core {
|
||||
namespace Network {
|
||||
namespace Packets {
|
||||
|
||||
typedef std::shared_ptr< FFXIVPacketBase > FFXIVPacketBasePtr;
|
||||
|
||||
class PacketContainer
|
||||
namespace Core::Network::Packets
|
||||
{
|
||||
public:
|
||||
PacketContainer( uint32_t segmentTargetOverride = 0 );
|
||||
|
||||
~PacketContainer();
|
||||
using FFXIVPacketBasePtr = std::shared_ptr< FFXIVPacketBase >;
|
||||
|
||||
void addPacket( FFXIVPacketBasePtr entry );
|
||||
class PacketContainer
|
||||
{
|
||||
public:
|
||||
PacketContainer( uint32_t segmentTargetOverride = 0 );
|
||||
|
||||
FFXIVARR_PACKET_HEADER m_ipcHdr;
|
||||
~PacketContainer();
|
||||
|
||||
std::vector< FFXIVPacketBasePtr > m_entryList;
|
||||
void addPacket( FFXIVPacketBasePtr entry );
|
||||
|
||||
std::string toString();
|
||||
FFXIVARR_PACKET_HEADER m_ipcHdr;
|
||||
|
||||
void fillSendBuffer( std::vector< uint8_t >& sendBuffer );
|
||||
std::vector< FFXIVPacketBasePtr > m_entryList;
|
||||
|
||||
private:
|
||||
uint32_t m_segmentTargetOverride;
|
||||
std::string toString();
|
||||
|
||||
};
|
||||
void fillSendBuffer( std::vector< uint8_t >& sendBuffer );
|
||||
|
||||
private:
|
||||
uint32_t m_segmentTargetOverride;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -7,122 +7,123 @@
|
|||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
namespace Core {
|
||||
|
||||
template< class T >
|
||||
class LockedQueue
|
||||
{
|
||||
public:
|
||||
LockedQueue();
|
||||
|
||||
~LockedQueue();
|
||||
|
||||
T pop();
|
||||
|
||||
//we can pass this in by reference, instead of copying
|
||||
void push( const T object );
|
||||
|
||||
//we can pass this in by reference
|
||||
//this will push it onto the queue, and swap the object
|
||||
// with a default-constructed T at the same time.
|
||||
void push_swap( T& object );
|
||||
|
||||
void push_reset( T& object );
|
||||
|
||||
|
||||
std::size_t size();
|
||||
|
||||
|
||||
protected:
|
||||
std::queue< T > m_queue;
|
||||
std::mutex m_mutex;
|
||||
|
||||
};
|
||||
|
||||
template< class T >
|
||||
LockedQueue< T >::LockedQueue()
|
||||
namespace Core
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
template< class T >
|
||||
std::size_t LockedQueue< T >::size()
|
||||
{
|
||||
std::lock_guard< std::mutex > lock( m_mutex );
|
||||
return m_queue.size();
|
||||
}
|
||||
|
||||
|
||||
template< class T >
|
||||
LockedQueue< T >::~LockedQueue()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
template< class T >
|
||||
T LockedQueue< T >::pop()
|
||||
{
|
||||
std::lock_guard< std::mutex > lock( m_mutex );
|
||||
|
||||
if( m_queue.empty() )
|
||||
template< class T >
|
||||
class LockedQueue
|
||||
{
|
||||
return T();
|
||||
public:
|
||||
LockedQueue();
|
||||
|
||||
~LockedQueue();
|
||||
|
||||
T pop();
|
||||
|
||||
//we can pass this in by reference, instead of copying
|
||||
void push( const T object );
|
||||
|
||||
//we can pass this in by reference
|
||||
//this will push it onto the queue, and swap the object
|
||||
// with a default-constructed T at the same time.
|
||||
void push_swap( T& object );
|
||||
|
||||
void push_reset( T& object );
|
||||
|
||||
|
||||
std::size_t size();
|
||||
|
||||
|
||||
protected:
|
||||
std::queue< T > m_queue;
|
||||
std::mutex m_mutex;
|
||||
|
||||
};
|
||||
|
||||
template< class T >
|
||||
LockedQueue< T >::LockedQueue()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
T result = m_queue.front();
|
||||
template< class T >
|
||||
std::size_t LockedQueue< T >::size()
|
||||
{
|
||||
std::lock_guard< std::mutex > lock( m_mutex );
|
||||
return m_queue.size();
|
||||
}
|
||||
|
||||
m_queue.pop();
|
||||
|
||||
return result;
|
||||
}
|
||||
template< class T >
|
||||
LockedQueue< T >::~LockedQueue()
|
||||
{
|
||||
|
||||
template< class T >
|
||||
void LockedQueue< T >::push( const T object )
|
||||
{
|
||||
std::lock_guard< std::mutex > lock( m_mutex );
|
||||
m_queue.push( object );
|
||||
}
|
||||
|
||||
template< class T >
|
||||
void LockedQueue< T >::push_swap( T& object )
|
||||
{
|
||||
std::lock_guard< std::mutex > lock( m_mutex );
|
||||
}
|
||||
|
||||
m_queue.push( object );
|
||||
|
||||
T default_ctored_object = T();
|
||||
//this is a special swap that will do a legit naive swap normally,
|
||||
// except if there exists a function called T::swap(), which is
|
||||
// specialized and possibly faster.
|
||||
std::swap( object, default_ctored_object );
|
||||
template< class T >
|
||||
T LockedQueue< T >::pop()
|
||||
{
|
||||
std::lock_guard< std::mutex > lock( m_mutex );
|
||||
|
||||
if( m_queue.empty() )
|
||||
{
|
||||
return T();
|
||||
}
|
||||
|
||||
T result = m_queue.front();
|
||||
|
||||
m_queue.pop();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template< class T >
|
||||
void LockedQueue< T >::push( const T object )
|
||||
{
|
||||
std::lock_guard< std::mutex > lock( m_mutex );
|
||||
m_queue.push( object );
|
||||
}
|
||||
|
||||
template< class T >
|
||||
void LockedQueue< T >::push_swap( T& object )
|
||||
{
|
||||
std::lock_guard< std::mutex > lock( m_mutex );
|
||||
|
||||
m_queue.push( object );
|
||||
|
||||
T default_ctored_object = T();
|
||||
//this is a special swap that will do a legit naive swap normally,
|
||||
// except if there exists a function called T::swap(), which is
|
||||
// specialized and possibly faster.
|
||||
std::swap( object, default_ctored_object );
|
||||
|
||||
|
||||
|
||||
//default_ctored_object is now the value of object, and it will go out
|
||||
// of scope here. In the case that T is a shared_ptr of some kind,
|
||||
// this will allow that the object on the queue is the *last* shared_ptr
|
||||
// in existance by the time this function returns.
|
||||
|
||||
}
|
||||
|
||||
template< class T >
|
||||
void LockedQueue< T >::push_reset( T& object )
|
||||
{
|
||||
std::lock_guard< std::mutex > lock( m_mutex );
|
||||
|
||||
m_queue.push( object );
|
||||
|
||||
T default_ctored_object = T();
|
||||
|
||||
object.reset();
|
||||
|
||||
//default_ctored_object is now the value of object, and it will go out
|
||||
// of scope here. In the case that T is a shared_ptr of some kind,
|
||||
// this will allow that the object on the queue is the *last* shared_ptr
|
||||
// in existance by the time this function returns.
|
||||
|
||||
}
|
||||
//default_ctored_object is now the value of object, and it will go out
|
||||
// of scope here. In the case that T is a shared_ptr of some kind,
|
||||
// this will allow that the object on the queue is the *last* shared_ptr
|
||||
// in existance by the time this function returns.
|
||||
|
||||
}
|
||||
|
||||
template< class T >
|
||||
void LockedQueue< T >::push_reset( T& object )
|
||||
{
|
||||
std::lock_guard< std::mutex > lock( m_mutex );
|
||||
|
||||
m_queue.push( object );
|
||||
|
||||
T default_ctored_object = T();
|
||||
|
||||
object.reset();
|
||||
|
||||
//default_ctored_object is now the value of object, and it will go out
|
||||
// of scope here. In the case that T is a shared_ptr of some kind,
|
||||
// this will allow that the object on the queue is the *last* shared_ptr
|
||||
// in existance by the time this function returns.
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,98 +8,99 @@
|
|||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace Core {
|
||||
|
||||
template< typename T >
|
||||
class LockedWaitQueue
|
||||
namespace Core
|
||||
{
|
||||
private:
|
||||
std::mutex m_queueLock;
|
||||
std::queue< T > m_queue;
|
||||
std::condition_variable m_condition;
|
||||
std::atomic< bool > m_shutdown;
|
||||
|
||||
public:
|
||||
|
||||
LockedWaitQueue< T >() :
|
||||
m_shutdown( false )
|
||||
template< typename T >
|
||||
class LockedWaitQueue
|
||||
{
|
||||
}
|
||||
private:
|
||||
std::mutex m_queueLock;
|
||||
std::queue< T > m_queue;
|
||||
std::condition_variable m_condition;
|
||||
std::atomic< bool > m_shutdown;
|
||||
|
||||
void push( const T& value )
|
||||
{
|
||||
std::lock_guard< std::mutex > lock( m_queueLock );
|
||||
m_queue.push( std::move( value ) );
|
||||
public:
|
||||
|
||||
m_condition.notify_one();
|
||||
}
|
||||
|
||||
bool empty()
|
||||
{
|
||||
std::lock_guard< std::mutex > lock( m_queueLock );
|
||||
|
||||
return m_queue.empty();
|
||||
}
|
||||
|
||||
bool pop( T& value )
|
||||
{
|
||||
std::lock_guard< std::mutex > lock( m_queueLock );
|
||||
|
||||
if( m_queue.empty() || m_shutdown )
|
||||
return false;
|
||||
|
||||
value = m_queue.front();
|
||||
|
||||
m_queue.pop();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void waitAndPop( T& value )
|
||||
{
|
||||
std::unique_lock< std::mutex > lock( m_queueLock );
|
||||
|
||||
while( m_queue.empty() && !m_shutdown )
|
||||
m_condition.wait( lock );
|
||||
|
||||
if( m_queue.empty() || m_shutdown )
|
||||
return;
|
||||
|
||||
value = m_queue.front();
|
||||
|
||||
m_queue.pop();
|
||||
}
|
||||
|
||||
void cancel()
|
||||
{
|
||||
std::unique_lock< std::mutex > lock( m_queueLock );
|
||||
|
||||
while( !m_queue.empty() )
|
||||
LockedWaitQueue< T >() :
|
||||
m_shutdown( false )
|
||||
{
|
||||
T& value = m_queue.front();
|
||||
}
|
||||
|
||||
deleteQueuedObject( value );
|
||||
void push( const T& value )
|
||||
{
|
||||
std::lock_guard< std::mutex > lock( m_queueLock );
|
||||
m_queue.push( std::move( value ) );
|
||||
|
||||
m_condition.notify_one();
|
||||
}
|
||||
|
||||
bool empty()
|
||||
{
|
||||
std::lock_guard< std::mutex > lock( m_queueLock );
|
||||
|
||||
return m_queue.empty();
|
||||
}
|
||||
|
||||
bool pop( T& value )
|
||||
{
|
||||
std::lock_guard< std::mutex > lock( m_queueLock );
|
||||
|
||||
if( m_queue.empty() || m_shutdown )
|
||||
return false;
|
||||
|
||||
value = m_queue.front();
|
||||
|
||||
m_queue.pop();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void waitAndPop( T& value )
|
||||
{
|
||||
std::unique_lock< std::mutex > lock( m_queueLock );
|
||||
|
||||
while( m_queue.empty() && !m_shutdown )
|
||||
m_condition.wait( lock );
|
||||
|
||||
if( m_queue.empty() || m_shutdown )
|
||||
return;
|
||||
|
||||
value = m_queue.front();
|
||||
|
||||
m_queue.pop();
|
||||
}
|
||||
|
||||
m_shutdown = true;
|
||||
void cancel()
|
||||
{
|
||||
std::unique_lock< std::mutex > lock( m_queueLock );
|
||||
|
||||
m_condition.notify_all();
|
||||
}
|
||||
while( !m_queue.empty() )
|
||||
{
|
||||
T& value = m_queue.front();
|
||||
|
||||
private:
|
||||
template< typename E = T >
|
||||
typename std::enable_if< std::is_pointer< E >::value >::type deleteQueuedObject( E& obj )
|
||||
{
|
||||
delete obj;
|
||||
}
|
||||
deleteQueuedObject( value );
|
||||
|
||||
template< typename E = T >
|
||||
typename std::enable_if< !std::is_pointer< E >::value >::type deleteQueuedObject( E const& )
|
||||
{
|
||||
}
|
||||
};
|
||||
m_queue.pop();
|
||||
}
|
||||
|
||||
m_shutdown = true;
|
||||
|
||||
m_condition.notify_all();
|
||||
}
|
||||
|
||||
private:
|
||||
template< typename E = T >
|
||||
typename std::enable_if< std::is_pointer< E >::value >::type deleteQueuedObject( E& obj )
|
||||
{
|
||||
delete obj;
|
||||
}
|
||||
|
||||
template< typename E = T >
|
||||
typename std::enable_if< !std::is_pointer< E >::value >::type deleteQueuedObject( E const& )
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -5,104 +5,104 @@
|
|||
#include <unordered_map>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Core {
|
||||
namespace Util {
|
||||
template< typename T, typename ActorIdType = uint32_t >
|
||||
class SpawnIndexAllocator
|
||||
namespace Core::Util
|
||||
{
|
||||
public:
|
||||
static_assert( std::is_same< T, uint8_t >::value || std::is_same< T, uint16_t >::value ||
|
||||
std::is_same< T, uint32_t >::value || std::is_same< T, uint64_t >::value,
|
||||
"T must be uint8_t, uint16_t, uint32_t, uint64_t" );
|
||||
|
||||
SpawnIndexAllocator() :
|
||||
m_maxSlotId( 0 ),
|
||||
m_reserveFirstSlot( false )
|
||||
template< typename T, typename ActorIdType = uint32_t >
|
||||
|
||||
class SpawnIndexAllocator
|
||||
{
|
||||
}
|
||||
public:
|
||||
static_assert( std::is_same< T, uint8_t >::value || std::is_same< T, uint16_t >::value ||
|
||||
std::is_same< T, uint32_t >::value || std::is_same< T, uint64_t >::value,
|
||||
"T must be uint8_t, uint16_t, uint32_t, uint64_t" );
|
||||
|
||||
void init( T maxSlotId, bool reserveFirstSlot = false )
|
||||
{
|
||||
m_maxSlotId = maxSlotId;
|
||||
m_reserveFirstSlot = reserveFirstSlot;
|
||||
SpawnIndexAllocator() :
|
||||
m_maxSlotId( 0 ),
|
||||
m_reserveFirstSlot( false )
|
||||
{
|
||||
}
|
||||
|
||||
setupQueue();
|
||||
void init( T maxSlotId, bool reserveFirstSlot = false )
|
||||
{
|
||||
m_maxSlotId = maxSlotId;
|
||||
m_reserveFirstSlot = reserveFirstSlot;
|
||||
|
||||
// todo: reserve max slot id in map to prevent any runtime reshashing
|
||||
}
|
||||
setupQueue();
|
||||
|
||||
T freeUsedSpawnIndex( ActorIdType actorId )
|
||||
{
|
||||
auto it = m_actorIdToAllocatedMap.find( actorId );
|
||||
if( it == m_actorIdToAllocatedMap.end() )
|
||||
return 0;
|
||||
// todo: reserve max slot id in map to prevent any runtime reshashing
|
||||
}
|
||||
|
||||
auto index = it->second;
|
||||
m_availableIds.push( index );
|
||||
m_actorIdToAllocatedMap.erase( it );
|
||||
T freeUsedSpawnIndex( ActorIdType actorId )
|
||||
{
|
||||
auto it = m_actorIdToAllocatedMap.find( actorId );
|
||||
if( it == m_actorIdToAllocatedMap.end() )
|
||||
return 0;
|
||||
|
||||
return index;
|
||||
}
|
||||
auto index = it->second;
|
||||
m_availableIds.push( index );
|
||||
m_actorIdToAllocatedMap.erase( it );
|
||||
|
||||
T getNextFreeSpawnIndex( ActorIdType actorId )
|
||||
{
|
||||
assert( m_maxSlotId != 0 );
|
||||
return index;
|
||||
}
|
||||
|
||||
if( m_availableIds.empty() )
|
||||
return getAllocFailId();
|
||||
T getNextFreeSpawnIndex( ActorIdType actorId )
|
||||
{
|
||||
assert( m_maxSlotId != 0 );
|
||||
|
||||
auto nextId = m_availableIds.front();
|
||||
m_availableIds.pop();
|
||||
if( m_availableIds.empty() )
|
||||
return getAllocFailId();
|
||||
|
||||
m_actorIdToAllocatedMap[ actorId ] = nextId;
|
||||
|
||||
return nextId;
|
||||
}
|
||||
|
||||
void freeAllSpawnIndexes()
|
||||
{
|
||||
setupQueue();
|
||||
|
||||
m_actorIdToAllocatedMap.clear();
|
||||
}
|
||||
|
||||
bool isSpawnIndexValid( T spawnIndex )
|
||||
{
|
||||
return spawnIndex != getAllocFailId();
|
||||
}
|
||||
|
||||
constexpr T getAllocFailId() const
|
||||
{
|
||||
return static_cast< T >( -1 );
|
||||
}
|
||||
|
||||
protected:
|
||||
void setupQueue()
|
||||
{
|
||||
assert( m_maxSlotId != 0 );
|
||||
|
||||
while( !m_availableIds.empty() )
|
||||
auto nextId = m_availableIds.front();
|
||||
m_availableIds.pop();
|
||||
|
||||
uint32_t start = 0;
|
||||
m_actorIdToAllocatedMap[ actorId ] = nextId;
|
||||
|
||||
// slot 0 is reserved when used for spawning actors/players otherwise the local player actor spawnIndex
|
||||
// will be used by another actor and despawn the local player
|
||||
if( m_reserveFirstSlot )
|
||||
start = 1;
|
||||
return nextId;
|
||||
}
|
||||
|
||||
for( uint32_t i = start; i < m_maxSlotId; i++ )
|
||||
m_availableIds.push( i );
|
||||
}
|
||||
void freeAllSpawnIndexes()
|
||||
{
|
||||
setupQueue();
|
||||
|
||||
std::queue< T > m_availableIds;
|
||||
std::unordered_map< ActorIdType, T > m_actorIdToAllocatedMap;
|
||||
m_actorIdToAllocatedMap.clear();
|
||||
}
|
||||
|
||||
T m_maxSlotId;
|
||||
bool m_reserveFirstSlot;
|
||||
};
|
||||
bool isSpawnIndexValid( T spawnIndex )
|
||||
{
|
||||
return spawnIndex != getAllocFailId();
|
||||
}
|
||||
|
||||
constexpr T getAllocFailId() const
|
||||
{
|
||||
return static_cast< T >( -1 );
|
||||
}
|
||||
|
||||
protected:
|
||||
void setupQueue()
|
||||
{
|
||||
assert( m_maxSlotId != 0 );
|
||||
|
||||
while( !m_availableIds.empty() )
|
||||
m_availableIds.pop();
|
||||
|
||||
uint32_t start = 0;
|
||||
|
||||
// slot 0 is reserved when used for spawning actors/players otherwise the local player actor spawnIndex
|
||||
// will be used by another actor and despawn the local player
|
||||
if( m_reserveFirstSlot )
|
||||
start = 1;
|
||||
|
||||
for( uint32_t i = start; i < m_maxSlotId; i++ )
|
||||
m_availableIds.push( i );
|
||||
}
|
||||
|
||||
std::queue< T > m_availableIds;
|
||||
std::unordered_map< ActorIdType, T > m_actorIdToAllocatedMap;
|
||||
|
||||
T m_maxSlotId;
|
||||
bool m_reserveFirstSlot;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif //SAPPHIRE_SPAWNINDEXALLOCATOR_H
|
||||
|
|
|
@ -5,33 +5,34 @@
|
|||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
namespace Core::Util {
|
||||
|
||||
std::string binaryToHexString( uint8_t* pBinData, uint16_t size );
|
||||
|
||||
std::string binaryToHexDump( uint8_t* pBinData, uint16_t size );
|
||||
|
||||
std::string intToHexString( uint64_t intValue, uint8_t width = 2 );
|
||||
|
||||
void eraseAll( std::string& inOutStr, char remove );
|
||||
void eraseAllIn( std::string& inOutStr, std::string& remove );
|
||||
|
||||
std::string toLowerCopy( const std::string& inStr );
|
||||
|
||||
uint64_t getTimeMs();
|
||||
|
||||
int64_t getTimeSeconds();
|
||||
|
||||
uint64_t getEorzeanTimeStamp();
|
||||
|
||||
void valueToFlagByteIndexValue( uint32_t inVal, uint8_t& outVal, uint16_t& outIndex );
|
||||
|
||||
template <class T>
|
||||
inline void hashCombine( std::size_t& seed, const T& v )
|
||||
namespace Core::Util
|
||||
{
|
||||
std::hash<T> hasher;
|
||||
seed ^= hasher( v ) + 0x9e3779b9 + ( seed << 6 ) + ( seed >> 2 );
|
||||
}
|
||||
|
||||
std::string binaryToHexString( uint8_t* pBinData, uint16_t size );
|
||||
|
||||
std::string binaryToHexDump( uint8_t* pBinData, uint16_t size );
|
||||
|
||||
std::string intToHexString( uint64_t intValue, uint8_t width = 2 );
|
||||
|
||||
void eraseAll( std::string& inOutStr, char remove );
|
||||
void eraseAllIn( std::string& inOutStr, std::string& remove );
|
||||
|
||||
std::string toLowerCopy( const std::string& inStr );
|
||||
|
||||
uint64_t getTimeMs();
|
||||
|
||||
int64_t getTimeSeconds();
|
||||
|
||||
uint64_t getEorzeanTimeStamp();
|
||||
|
||||
void valueToFlagByteIndexValue( uint32_t inVal, uint8_t& outVal, uint16_t& outIndex );
|
||||
|
||||
template <class T>
|
||||
inline void hashCombine( std::size_t& seed, const T& v )
|
||||
{
|
||||
std::hash< T > hasher;
|
||||
seed ^= hasher( v ) + 0x9e3779b9 + ( seed << 6 ) + ( seed >> 2 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -5,42 +5,39 @@
|
|||
|
||||
#define PI 3.14159265358979323846f
|
||||
|
||||
namespace Core {
|
||||
namespace Math {
|
||||
namespace Util {
|
||||
|
||||
float distanceSq( float x, float y, float z, float x1, float y1, float z1 );
|
||||
|
||||
float distance( float x, float y, float z, float x1, float y1, float z1 );
|
||||
|
||||
float distance2DSq( float x, float y, float x1, float y1 );
|
||||
|
||||
float distance2D( float x, float y, float x1, float y1 );
|
||||
|
||||
float calcAngTo( float x, float y, float x1, float y1 );
|
||||
|
||||
float calcAngFrom( float x, float y, float x1, float y1 );
|
||||
|
||||
uint16_t floatToUInt16( float val );
|
||||
|
||||
uint16_t floatToUInt16Rot( float val );
|
||||
|
||||
uint8_t floatToUInt8Rot( float val );
|
||||
|
||||
template < typename T >
|
||||
T clamp( T val, T minimum, T maximum )
|
||||
namespace Core::Math::Util
|
||||
{
|
||||
if( val > maximum )
|
||||
return maximum;
|
||||
|
||||
if( val < minimum )
|
||||
return minimum;
|
||||
float distanceSq( float x, float y, float z, float x1, float y1, float z1 );
|
||||
|
||||
return val;
|
||||
}
|
||||
float distance( float x, float y, float z, float x1, float y1, float z1 );
|
||||
|
||||
float distance2DSq( float x, float y, float x1, float y1 );
|
||||
|
||||
float distance2D( float x, float y, float x1, float y1 );
|
||||
|
||||
float calcAngTo( float x, float y, float x1, float y1 );
|
||||
|
||||
float calcAngFrom( float x, float y, float x1, float y1 );
|
||||
|
||||
uint16_t floatToUInt16( float val );
|
||||
|
||||
uint16_t floatToUInt16Rot( float val );
|
||||
|
||||
uint8_t floatToUInt8Rot( float val );
|
||||
|
||||
template < typename T >
|
||||
T clamp( T val, T minimum, T maximum )
|
||||
{
|
||||
if( val > maximum )
|
||||
return maximum;
|
||||
|
||||
if( val < minimum )
|
||||
return minimum;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,13 +3,10 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
namespace Core {
|
||||
namespace Version {
|
||||
|
||||
extern const std::string GIT_HASH;
|
||||
extern const std::string VERSION;
|
||||
|
||||
} /* Version */
|
||||
} /* Core */
|
||||
namespace Core::Version
|
||||
{
|
||||
extern const std::string GIT_HASH;
|
||||
extern const std::string VERSION;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -56,7 +56,7 @@ foreach(_scriptDir ${children})
|
|||
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/ScriptLoader.cpp.in" "${_scriptDir}/ScriptLoader.cpp")
|
||||
|
||||
cotire("script_${_name}")
|
||||
#cotire("script_${_name}")
|
||||
|
||||
if(MSVC)
|
||||
add_custom_command(TARGET "script_${_name}" POST_BUILD
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#define AETHERYTE_MENU_FAVORITE_POINT 4
|
||||
#define AETHERYTE_MENU_FAVORITE_POINT_SECURITY_TOKEN 5
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class Aethernet :
|
||||
public EventScript
|
||||
{
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
#define AETHERYTE_MENU_FAVORITE_POINT 4
|
||||
#define AETHERYTE_MENU_FAVORITE_POINT_SECURITY_TOKEN 5
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class Aetheryte :
|
||||
public EventScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Actor/Player.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class CmnDefCutSceneReplay :
|
||||
public EventScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Actor/Player.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class CmnDefHousingSignboard :
|
||||
public EventScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Actor/Player.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class CmnDefInnBed :
|
||||
public EventScript
|
||||
{
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#define ACTION_RENAME 3
|
||||
#define ACTION_REMOVE 4
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class CmnDefLinkShell :
|
||||
public EventScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Actor/Player.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class CmnDefMarketBoardGridania :
|
||||
public EventScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Actor/Player.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class CmnDefMogLetter :
|
||||
public EventScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Actor/Player.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class CmnDefNpcRepair :
|
||||
public EventScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Actor/Player.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class CmnDefWeatherForeCast :
|
||||
public EventScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Actor/Player.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ComDefMobHuntBoard :
|
||||
public EventScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Actor/Player.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class GilShop :
|
||||
public EventScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Actor/Player.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class HouFurOrchestrion :
|
||||
public EventScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ThePalaceoftheDeadFloors101110 :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ThePalaceoftheDeadFloors110 :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ThePalaceoftheDeadFloors111120 :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ThePalaceoftheDeadFloors1120 :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ThePalaceoftheDeadFloors121130 :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ThePalaceoftheDeadFloors131140 :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ThePalaceoftheDeadFloors141150 :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ThePalaceoftheDeadFloors151160 :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ThePalaceoftheDeadFloors161170 :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ThePalaceoftheDeadFloors171180 :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ThePalaceoftheDeadFloors181190 :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ThePalaceoftheDeadFloors191200 :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ThePalaceoftheDeadFloors2130 :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ThePalaceoftheDeadFloors3140 :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ThePalaceoftheDeadFloors4150 :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ThePalaceoftheDeadFloors5160 :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ThePalaceoftheDeadFloors6170 :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ThePalaceoftheDeadFloors7180 :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ThePalaceoftheDeadFloors8190 :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ThePalaceoftheDeadFloors91100 :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class AlaMhigo :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class AmdaporKeep :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class AmdaporKeepHard :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class BaelsarsWall :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class BardamsMettle :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class BrayfloxsLongstop :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class BrayfloxsLongstopHard :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class CastrumAbania :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class CastrumMeridianum :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class CopperbellMines :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class CopperbellMinesHard :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class CuttersCry :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class DomaCastle :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class DzemaelDarkhold :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class Halatali :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class HalataliHard :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class HaukkeManor :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class HaukkeManorHard :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class HellsLid :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class HullbreakerIsle :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class HullbreakerIsleHard :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class KuganeCastle :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class Neverreap :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class PharosSirius :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class PharosSiriusHard :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class SaintMociannesArboretum :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
#include <Zone/InstanceContent.h>
|
||||
#include <Actor/Player.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class Sastasha :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class SastashaHard :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ShisuioftheVioletTides :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class Snowcloak :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class SohmAl :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class SohmAlHard :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class SohrKhai :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class TheAery :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class TheAetherochemicalResearchFacility :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Zone/InstanceContent.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class TheAntitower :
|
||||
public InstanceContentScript
|
||||
{
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue