1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-02 16:57:47 +00:00

Plenty more cleanup and code quality adjustments.

This commit is contained in:
Mordred 2019-03-11 22:48:33 +01:00
parent 35a8461dbb
commit 8a35c4e370
25 changed files with 459 additions and 533 deletions

View file

@ -1,15 +1,14 @@
#include "LoginSession.h" #include "LoginSession.h"
namespace Sapphire { namespace Sapphire {
LoginSession::LoginSession( void ) LoginSession::LoginSession( void )
{ {
//setSocket(NULL); //setSocket(NULL);
}
} LoginSession::~LoginSession( void )
{
LoginSession::~LoginSession( void )
{ }
}
} }

View file

@ -14,8 +14,8 @@ namespace Sapphire
{ {
private: private:
uint32_t m_IP; uint32_t m_ip;
uint32_t m_accountID; uint32_t m_accountId;
uint8_t m_sessionId[56]; uint8_t m_sessionId[56];
public: public:
@ -25,9 +25,9 @@ namespace Sapphire
~LoginSession( void ); ~LoginSession( void );
uint32_t getIP() uint32_t getIp()
{ {
return m_IP; return m_ip;
} }
void setSessionId( uint8_t* sessionId ) void setSessionId( uint8_t* sessionId )
@ -35,29 +35,21 @@ namespace Sapphire
memcpy( m_sessionId, sessionId, 56 ); memcpy( m_sessionId, sessionId, 56 );
} }
void setIP( uint32_t iP ) void setIp( uint32_t ip )
{ {
m_IP = iP; m_ip = ip;
} }
uint32_t getAccountID() uint32_t getAccountId()
{ {
return m_accountID; return m_accountId;
} }
void setAccountID( uint32_t iD ) void setAccountId( uint32_t id )
{ {
m_accountID = iD; m_accountId = id;
} }
/*INLINE CLobbySocket* getSocket() {
return m_pGS;
}
INLINE void setSocket(CLobbySocket * pS) {
m_pGS = pS;
}*/
}; };
} }

View file

@ -33,7 +33,6 @@ namespace Sapphire::Common::Config
} network; } network;
}; };
struct WorldConfig struct WorldConfig
{ {
GlobalConfig global; GlobalConfig global;

View file

@ -29,8 +29,7 @@ namespace Sapphire::Util
"message digest", "message digest",
"abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
"12345678901234567890123456789012345678901234567890123456789012" \ "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
"345678901234567890"
}; };
static const char* val[] = static const char* val[] =

View file

@ -209,7 +209,9 @@ std::shared_ptr< Mysql::PreparedStatement > Sapphire::Db::DbConnection::getPrepa
return ret; return ret;
} }
void Sapphire::Db::DbConnection::prepareStatement( uint32_t index, const std::string& sql, Sapphire::Db::ConnectionFlags flags ) void Sapphire::Db::DbConnection::prepareStatement( uint32_t index,
const std::string& sql,
Sapphire::Db::ConnectionFlags flags )
{ {
m_queries.insert( PreparedStatementMap::value_type( index, std::make_pair( sql, flags ) ) ); m_queries.insert( PreparedStatementMap::value_type( index, std::make_pair( sql, flags ) ) );

View file

@ -2,7 +2,8 @@
#include "Operation.h" #include "Operation.h"
#include "Util/LockedWaitQueue.h" #include "Util/LockedWaitQueue.h"
Sapphire::Db::DbWorker::DbWorker( Sapphire::LockedWaitQueue< std::shared_ptr< Operation > >* newQueue, DbConnection* pConn ) Sapphire::Db::DbWorker::DbWorker( Sapphire::LockedWaitQueue< std::shared_ptr< Operation > >* newQueue,
DbConnection* pConn )
{ {
m_pConn = pConn; m_pConn = pConn;
m_queue = newQueue; m_queue = newQueue;

View file

@ -10,8 +10,7 @@
#include "Logging/Logger.h" #include "Logging/Logger.h"
#include <mysql.h> #include <mysql.h>
class PingOperation : class PingOperation : public Sapphire::Db::Operation
public Sapphire::Db::Operation
{ {
bool execute() override bool execute() override
{ {
@ -256,25 +255,5 @@ void Sapphire::Db::DbWorkerPool< T >::directExecute( std::shared_ptr< PreparedSt
connection->unlock(); connection->unlock();
} }
/*
template <class T>
void DatabaseWorkerPool<T>::ExecuteOrAppend(SQLTransaction& trans, const char* sql)
{
if (!trans)
Execute(sql);
else
trans->Append(sql);
}
template <class T>
void DatabaseWorkerPool<T>::ExecuteOrAppend(SQLTransaction& trans, PreparedStatement* stmt)
{
if (!trans)
Execute(stmt);
else
trans->Append(stmt);
}
*/
template template
class Sapphire::Db::DbWorkerPool< Sapphire::Db::ZoneDbConnection >; class Sapphire::Db::DbWorkerPool< Sapphire::Db::ZoneDbConnection >;

View file

@ -44,7 +44,7 @@ namespace Sapphire::Db
bool prepareStatements(); bool prepareStatements();
inline ConnectionInfo getConnectionInfo() const const ConnectionInfo& getConnectionInfo() const
{ {
return m_connectionInfo; return m_connectionInfo;
} }

View file

@ -41,7 +41,6 @@ bool Sapphire::Db::StatementTask::execute()
Sapphire::Db::PreparedStatementTask::PreparedStatementTask( std::shared_ptr< Sapphire::Db::PreparedStatement > stmt, Sapphire::Db::PreparedStatementTask::PreparedStatementTask( std::shared_ptr< Sapphire::Db::PreparedStatement > stmt,
bool async ) : bool async ) :
m_stmt( stmt ) m_stmt( stmt )
//, m_result(nullptr)
{ {
m_hasResult = async; // If the operation is async, then there's a result m_hasResult = async; // If the operation is async, then there's a result
} }

View file

@ -9,8 +9,7 @@ namespace Sapphire::Db
{ {
class PreparedStatement; class PreparedStatement;
class StatementTask : class StatementTask : public Operation
public Operation
{ {
public: public:
@ -20,15 +19,9 @@ namespace Sapphire::Db
bool execute() override; bool execute() override;
// QueryResultFuture getFuture() const
// {
// return m_result->get_future();
// }
private: private:
std::string m_sql; std::string m_sql;
bool m_hasResult; bool m_hasResult;
// QueryResultPromise *m_result;
}; };
class PreparedStatementTask : class PreparedStatementTask :
@ -40,12 +33,10 @@ namespace Sapphire::Db
~PreparedStatementTask(); ~PreparedStatementTask();
bool execute() override; bool execute() override;
//PreparedQueryResultFuture getFuture() { return m_result->get_future(); }
protected: protected:
std::shared_ptr< PreparedStatement > m_stmt; std::shared_ptr< PreparedStatement > m_stmt;
bool m_hasResult; bool m_hasResult;
//PreparedQueryResultPromise* m_result;
}; };
} }

View file

@ -5,33 +5,28 @@
namespace Sapphire namespace Sapphire
{ {
class ConfigMgr; class ConfigMgr;
using ConfigMgrPtr = std::shared_ptr< ConfigMgr >;
class Framework; class Framework;
using ConfigMgrPtr = std::shared_ptr< ConfigMgr >;
using FrameworkPtr = std::shared_ptr< Framework >; using FrameworkPtr = std::shared_ptr< Framework >;
}
namespace Network namespace Sapphire::Network
{ {
class Hive; class Hive;
class Acceptor; class Acceptor;
class Connection; class Connection;
using HivePtr = std::shared_ptr< Hive >; using HivePtr = std::shared_ptr< Hive >;
using AcceptorPtr = std::shared_ptr< Acceptor >; using AcceptorPtr = std::shared_ptr< Acceptor >;
using ConnectionPtr = std::shared_ptr< Connection >; using ConnectionPtr = std::shared_ptr< Connection >;
}
namespace Packets namespace Sapphire::Network::Packets
{ {
class GamePacket; class GamePacket;
class FFXIVPacketBase; class FFXIVPacketBase;
using GamePacketPtr = std::shared_ptr< GamePacket >; using GamePacketPtr = std::shared_ptr< GamePacket >;
using FFXIVPacketBasePtr = std::shared_ptr< FFXIVPacketBase >; using FFXIVPacketBasePtr = std::shared_ptr< FFXIVPacketBase >;
}
}
} }
#endif #endif

View file

@ -10,21 +10,18 @@
namespace fs = std::experimental::filesystem; namespace fs = std::experimental::filesystem;
namespace Sapphire Sapphire::Logger::Logger()
{ {
Logger::Logger() }
{
} Sapphire::Logger::~Logger()
{
Logger::~Logger() }
{
} void Sapphire::Logger::init( const std::string& logPath )
{
void Logger::init( const std::string& logPath )
{
auto pos = logPath.find_last_of( fs::path::preferred_separator ); auto pos = logPath.find_last_of( fs::path::preferred_separator );
if( pos != std::string::npos ) if( pos != std::string::npos )
@ -51,41 +48,40 @@ namespace Sapphire
// see: https://github.com/gabime/spdlog/wiki/7.-Flush-policy // see: https://github.com/gabime/spdlog/wiki/7.-Flush-policy
// nb: if the server crashes, log data can be missing from the file unless something logs critical just before it does // nb: if the server crashes, log data can be missing from the file unless something logs critical just before it does
spdlog::flush_on( spdlog::level::critical ); spdlog::flush_on( spdlog::level::critical );
}
void Logger::setLogLevel( uint8_t logLevel )
{
spdlog::set_level( static_cast< spdlog::level::level_enum >( logLevel ) );
}
void Logger::error( const std::string& text )
{
spdlog::get( "logger" )->error( text );
}
void Logger::warn( const std::string& text )
{
spdlog::get( "logger" )->warn( text );
}
void Logger::info( const std::string& text )
{
spdlog::get( "logger" )->info( text );
}
void Logger::debug( const std::string& text )
{
spdlog::get( "logger" )->debug( text );
}
void Logger::fatal( const std::string& text )
{
spdlog::get( "logger" )->critical( text );
}
void Logger::trace( const std::string& text )
{
spdlog::get( "logger" )->trace( text );
}
} }
void Sapphire::Logger::setLogLevel( uint8_t logLevel )
{
spdlog::set_level( static_cast< spdlog::level::level_enum >( logLevel ) );
}
void Sapphire::Logger::error( const std::string& text )
{
spdlog::get( "logger" )->error( text );
}
void Sapphire::Logger::warn( const std::string& text )
{
spdlog::get( "logger" )->warn( text );
}
void Sapphire::Logger::info( const std::string& text )
{
spdlog::get( "logger" )->info( text );
}
void Sapphire::Logger::debug( const std::string& text )
{
spdlog::get( "logger" )->debug( text );
}
void Sapphire::Logger::fatal( const std::string& text )
{
spdlog::get( "logger" )->critical( text );
}
void Sapphire::Logger::trace( const std::string& text )
{
spdlog::get( "logger" )->trace( text );
}

View file

@ -2,12 +2,7 @@
#include "Acceptor.h" #include "Acceptor.h"
#include "Connection.h" #include "Connection.h"
namespace Sapphire::Network Sapphire::Network::Acceptor::Acceptor( HivePtr hive ) :
{
//-----------------------------------------------------------------------------
Acceptor::Acceptor( HivePtr hive ) :
m_hive( hive ), m_hive( hive ),
m_acceptor( hive->getService() ), m_acceptor( hive->getService() ),
m_io_strand( hive->getService() ), m_io_strand( hive->getService() ),
@ -15,22 +10,21 @@ Acceptor::Acceptor( HivePtr hive ) :
{ {
} }
Acceptor::~Acceptor() Sapphire::Network::Acceptor::~Acceptor()
{ {
} }
bool Sapphire::Network::Acceptor::onAccept( ConnectionPtr connection, const std::string& host, uint16_t port )
bool Acceptor::onAccept( ConnectionPtr connection, const std::string& host, uint16_t port )
{ {
return true; return true;
} }
void Acceptor::onError( const asio::error_code& error ) void Sapphire::Network::Acceptor::onError( const asio::error_code& error )
{ {
} }
void Acceptor::startError( const asio::error_code& error ) void Sapphire::Network::Acceptor::startError( const asio::error_code& error )
{ {
uint32_t v1 = 1; uint32_t v1 = 1;
uint32_t v2 = 0; uint32_t v2 = 0;
@ -43,7 +37,7 @@ void Acceptor::startError( const asio::error_code& error )
} }
} }
void Acceptor::dispatchAccept( ConnectionPtr connection ) void Sapphire::Network::Acceptor::dispatchAccept( ConnectionPtr connection )
{ {
m_acceptor.async_accept( connection->getSocket(), m_acceptor.async_accept( connection->getSocket(),
connection->getStrand().wrap( std::bind( &Acceptor::handleAccept, connection->getStrand().wrap( std::bind( &Acceptor::handleAccept,
@ -52,7 +46,7 @@ void Acceptor::dispatchAccept( ConnectionPtr connection )
connection ) ) ); connection ) ) );
} }
void Acceptor::handleAccept( const asio::error_code& error, ConnectionPtr connection ) void Sapphire::Network::Acceptor::handleAccept( const asio::error_code& error, ConnectionPtr connection )
{ {
if( error || hasError() || m_hive->hasStopped() ) if( error || hasError() || m_hive->hasStopped() )
{ {
@ -78,17 +72,17 @@ void Acceptor::handleAccept( const asio::error_code& error, ConnectionPtr connec
} }
} }
void Acceptor::stop() void Sapphire::Network::Acceptor::stop()
{ {
} }
void Acceptor::accept( ConnectionPtr connection ) void Sapphire::Network::Acceptor::accept( ConnectionPtr connection )
{ {
m_io_strand.post( std::bind( &Acceptor::dispatchAccept, shared_from_this(), connection ) ); m_io_strand.post( std::bind( &Acceptor::dispatchAccept, shared_from_this(), connection ) );
} }
void Acceptor::listen( const std::string& host, const uint16_t& port ) void Sapphire::Network::Acceptor::listen( const std::string& host, const uint16_t& port )
{ {
try try
{ {
@ -109,21 +103,19 @@ void Acceptor::listen( const std::string& host, const uint16_t& port )
} }
HivePtr Acceptor::getHive() Sapphire::Network::HivePtr Sapphire::Network::Acceptor::getHive()
{ {
return m_hive; return m_hive;
} }
asio::ip::tcp::acceptor& Acceptor::getAcceptor() asio::ip::tcp::acceptor& Sapphire::Network::Acceptor::getAcceptor()
{ {
return m_acceptor; return m_acceptor;
} }
bool Acceptor::hasError() bool Sapphire::Network::Acceptor::hasError()
{ {
uint32_t v1 = 1; uint32_t v1 = 1;
uint32_t v2 = 1; uint32_t v2 = 1;
return ( m_error_state.compare_exchange_strong( v1, v2 ) ); return ( m_error_state.compare_exchange_strong( v1, v2 ) );
} }
}

View file

@ -3,11 +3,7 @@
#include <functional> #include <functional>
#include "Framework.h" #include "Framework.h"
namespace Sapphire::Network Sapphire::Network::Connection::Connection( HivePtr hive, FrameworkPtr pFw ) :
{
//-----------------------------------------------------------------------------
Connection::Connection( HivePtr hive, FrameworkPtr pFw ) :
m_hive( hive ), m_hive( hive ),
m_socket( hive->getService() ), m_socket( hive->getService() ),
m_io_strand( hive->getService() ), m_io_strand( hive->getService() ),
@ -17,11 +13,11 @@ Connection::Connection( HivePtr hive, FrameworkPtr pFw ) :
{ {
} }
Connection::~Connection() Sapphire::Network::Connection::~Connection()
{ {
} }
void Connection::bind( const std::string& ip, uint16_t port ) void Sapphire::Network::Connection::bind( const std::string& ip, uint16_t port )
{ {
asio::ip::tcp::endpoint endpoint( asio::ip::address::from_string( ip ), port ); asio::ip::tcp::endpoint endpoint( asio::ip::address::from_string( ip ), port );
m_socket.open( endpoint.protocol() ); m_socket.open( endpoint.protocol() );
@ -29,7 +25,7 @@ void Connection::bind( const std::string& ip, uint16_t port )
m_socket.bind( endpoint ); m_socket.bind( endpoint );
} }
void Connection::startSend() void Sapphire::Network::Connection::startSend()
{ {
if( !m_pending_sends.empty() ) if( !m_pending_sends.empty() )
{ {
@ -42,7 +38,7 @@ void Connection::startSend()
} }
} }
void Connection::startRecv( int32_t total_bytes ) void Sapphire::Network::Connection::startRecv( int32_t total_bytes )
{ {
if( total_bytes > 0 ) if( total_bytes > 0 )
{ {
@ -65,7 +61,7 @@ void Connection::startRecv( int32_t total_bytes )
} }
} }
void Connection::startError( const asio::error_code& error ) void Sapphire::Network::Connection::startError( const asio::error_code& error )
{ {
uint32_t v1 = 1; uint32_t v1 = 1;
uint32_t v2 = 0; uint32_t v2 = 0;
@ -78,7 +74,7 @@ void Connection::startError( const asio::error_code& error )
} }
} }
void Connection::handleConnect( const asio::error_code& error ) void Sapphire::Network::Connection::handleConnect( const asio::error_code& error )
{ {
if( error || hasError() || m_hive->hasStopped() ) if( error || hasError() || m_hive->hasStopped() )
{ {
@ -98,8 +94,8 @@ void Connection::handleConnect( const asio::error_code& error )
} }
} }
void void Sapphire::Network::Connection::handleSend( const asio::error_code& error,
Connection::handleSend( const asio::error_code& error, std::list< std::vector< uint8_t > >::iterator itr ) std::list< std::vector< uint8_t > >::iterator itr )
{ {
if( error || hasError() || m_hive->hasStopped() ) if( error || hasError() || m_hive->hasStopped() )
{ {
@ -113,7 +109,7 @@ Connection::handleSend( const asio::error_code& error, std::list< std::vector< u
} }
} }
void Connection::handleRecv( const asio::error_code& error, int32_t actual_bytes ) void Sapphire::Network::Connection::handleRecv( const asio::error_code& error, int32_t actual_bytes )
{ {
if( error || hasError() || m_hive->hasStopped() ) if( error || hasError() || m_hive->hasStopped() )
{ {
@ -132,7 +128,7 @@ void Connection::handleRecv( const asio::error_code& error, int32_t actual_bytes
} }
} }
void Connection::dispatchSend( std::vector< uint8_t > buffer ) void Sapphire::Network::Connection::dispatchSend( std::vector< uint8_t > buffer )
{ {
bool should_start_send = m_pending_sends.empty(); bool should_start_send = m_pending_sends.empty();
m_pending_sends.push_back( buffer ); m_pending_sends.push_back( buffer );
@ -142,7 +138,7 @@ void Connection::dispatchSend( std::vector< uint8_t > buffer )
} }
} }
void Connection::dispatchRecv( int32_t total_bytes ) void Sapphire::Network::Connection::dispatchRecv( int32_t total_bytes )
{ {
bool should_start_receive = m_pending_recvs.empty(); bool should_start_receive = m_pending_recvs.empty();
m_pending_recvs.push_back( total_bytes ); m_pending_recvs.push_back( total_bytes );
@ -153,61 +149,61 @@ void Connection::dispatchRecv( int32_t total_bytes )
} }
void Connection::connect( const std::string& host, uint16_t port ) void Sapphire::Network::Connection::connect( const std::string& host, uint16_t port )
{ {
asio::ip::tcp::resolver resolver( m_hive->getService() ); asio::ip::tcp::resolver resolver( m_hive->getService() );
asio::ip::tcp::resolver::query query( host, std::to_string( port ) ); asio::ip::tcp::resolver::query query( host, std::to_string( port ) );
asio::ip::tcp::resolver::iterator iterator = resolver.resolve( query ); asio::ip::tcp::resolver::iterator iterator = resolver.resolve( query );
m_socket.async_connect( *iterator, m_socket.async_connect( *iterator,
m_io_strand.wrap( std::bind( &Connection::handleConnect, shared_from_this(), std::placeholders::_1 ) ) ); m_io_strand.wrap( std::bind( &Connection::handleConnect,
shared_from_this(), std::placeholders::_1 ) ) );
} }
void Connection::disconnect() void Sapphire::Network::Connection::disconnect()
{ {
onDisconnect(); onDisconnect();
m_socket.close(); m_socket.close();
} }
void Connection::recv( int32_t total_bytes ) void Sapphire::Network::Connection::recv( int32_t total_bytes )
{ {
m_io_strand.post( std::bind( &Connection::dispatchRecv, shared_from_this(), total_bytes ) ); m_io_strand.post( std::bind( &Connection::dispatchRecv, shared_from_this(), total_bytes ) );
} }
void Connection::send( const std::vector< uint8_t >& buffer ) void Sapphire::Network::Connection::send( const std::vector< uint8_t >& buffer )
{ {
m_io_strand.post( std::bind( &Connection::dispatchSend, shared_from_this(), buffer ) ); m_io_strand.post( std::bind( &Connection::dispatchSend, shared_from_this(), buffer ) );
} }
asio::ip::tcp::socket& Connection::getSocket() asio::ip::tcp::socket& Sapphire::Network::Connection::getSocket()
{ {
return m_socket; return m_socket;
} }
asio::strand& Connection::getStrand() asio::strand& Sapphire::Network::Connection::getStrand()
{ {
return m_io_strand; return m_io_strand;
} }
HivePtr Connection::getHive() Sapphire::Network::HivePtr Sapphire::Network::Connection::getHive()
{ {
return m_hive; return m_hive;
} }
void Connection::setReceiveBufferSize( int32_t size ) void Sapphire::Network::Connection::setReceiveBufferSize( int32_t size )
{ {
m_receive_buffer_size = size; m_receive_buffer_size = size;
} }
int32_t Connection::getReceiveBufferSize() const int32_t Sapphire::Network::Connection::getReceiveBufferSize() const
{ {
return m_receive_buffer_size; return m_receive_buffer_size;
} }
bool Connection::hasError() bool Sapphire::Network::Connection::hasError()
{ {
uint32_t v1 = 1; uint32_t v1 = 1;
uint32_t v2 = 1; uint32_t v2 = 1;
return ( m_error_state.compare_exchange_strong( v1, v2 ) ); return ( m_error_state.compare_exchange_strong( v1, v2 ) );
} }
}

View file

@ -22,9 +22,7 @@ namespace Sapphire::Network
{ {
class Hive; class Hive;
class Acceptor; class Acceptor;
class Connection; class Connection;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -32,7 +30,6 @@ namespace Sapphire::Network
class Connection : public std::enable_shared_from_this< Connection > class Connection : public std::enable_shared_from_this< Connection >
{ {
friend class Acceptor; friend class Acceptor;
friend class Hive; friend class Hive;
protected: protected:

View file

@ -1,5 +1,5 @@
#ifndef _GAMEPACKET_NEW_H #ifndef _GAMEPACKET_H
#define _GAMEPACKET_NEW_H #define _GAMEPACKET_H
#include <stdint.h> #include <stdint.h>
#include <iostream> #include <iostream>
@ -17,53 +17,52 @@
namespace Sapphire::Network::Packets namespace Sapphire::Network::Packets
{ {
// Must forward define these in order to enable the compiler to produce the // Must forward define these in order to enable the compiler to produce the
// correct template functions. // correct template functions.
template< typename T, typename T1 >
class FFXIVIpcPacket;
template< typename T, typename T1 > template< class T >
class FFXIVIpcPacket; using ZoneChannelPacket = FFXIVIpcPacket< T, ServerZoneIpcType >;
template< class T > template< class T >
using ZoneChannelPacket = FFXIVIpcPacket< T, ServerZoneIpcType >; using ChatChannelPacket = FFXIVIpcPacket< T, ServerChatIpcType >;
template< class T > template< class T >
using ChatChannelPacket = FFXIVIpcPacket< T, ServerChatIpcType >; using LobbyChannelPacket = FFXIVIpcPacket< T, ServerLobbyIpcType >;
template< class T >
using LobbyChannelPacket = FFXIVIpcPacket< T, ServerLobbyIpcType >;
template< class T, typename... Args > template< class T, typename... Args >
std::shared_ptr< ZoneChannelPacket< T > > makeZonePacket( Args... args ) std::shared_ptr< ZoneChannelPacket< T > > makeZonePacket( Args... args )
{ {
return std::make_shared< ZoneChannelPacket< T > >( args... ); return std::make_shared< ZoneChannelPacket< T > >( args... );
} }
template< class T, typename... Args > template< class T, typename... Args >
std::shared_ptr< T > makeWrappedPacket( Args... args ) std::shared_ptr< T > makeWrappedPacket( Args... args )
{ {
return std::make_shared< T >( args... ); return std::make_shared< T >( args... );
} }
template< class T, typename... Args > template< class T, typename... Args >
std::shared_ptr< ChatChannelPacket< T > > makeChatPacket( Args... args ) std::shared_ptr< ChatChannelPacket< T > > makeChatPacket( Args... args )
{ {
return std::make_shared< ChatChannelPacket< T > >( args... ); return std::make_shared< ChatChannelPacket< T > >( args... );
} }
template< class T, typename... Args > template< class T, typename... Args >
std::shared_ptr< LobbyChannelPacket< T > > makeLobbyPacket( Args... args ) std::shared_ptr< LobbyChannelPacket< T > > makeLobbyPacket( Args... args )
{ {
return std::make_shared< LobbyChannelPacket< T > >( args... ); return std::make_shared< LobbyChannelPacket< T > >( args... );
} }
/** /**
* The base implementation of a game packet. Needed for parsing packets. * The base implementation of a game packet. Needed for parsing packets.
*/ */
template< typename T1 > template< typename T1 >
class FFXIVIpcPacketBase class FFXIVIpcPacketBase
{ {
public: public:
virtual ~FFXIVIpcPacketBase() = default; virtual ~FFXIVIpcPacketBase() = default;
/** /**
@ -71,13 +70,13 @@ public:
* type of a parsed packet.) * type of a parsed packet.)
*/ */
virtual T1 ipcType() = 0; virtual T1 ipcType() = 0;
}; };
////////////////////////////////////////////////7 ////////////////////////////////////////////////7
class FFXIVPacketBase class FFXIVPacketBase
{ {
public: public:
FFXIVPacketBase() : FFXIVPacketBase() :
m_segmentType( 0 ) m_segmentType( 0 )
{ {
@ -102,12 +101,12 @@ public:
return {}; return {};
} }
protected: protected:
/** The segment header */ /** The segment header */
FFXIVARR_PACKET_SEGMENT_HEADER m_segHdr; FFXIVARR_PACKET_SEGMENT_HEADER m_segHdr;
uint16_t m_segmentType; uint16_t m_segmentType;
public: public:
virtual size_t getContentSize() virtual size_t getContentSize()
{ {
return 0; return 0;
@ -173,13 +172,13 @@ public:
m_segHdr.type = getSegmentType(); m_segHdr.type = getSegmentType();
} }
}; };
template< typename T, typename T1 > template< typename T, typename T1 >
class FFXIVIpcPacket : class FFXIVIpcPacket :
public FFXIVIpcPacketBase< T1 >, public FFXIVPacketBase public FFXIVIpcPacketBase< T1 >, public FFXIVPacketBase
{ {
public: public:
FFXIVIpcPacket< T, T1 >( uint32_t sourceActorId, uint32_t targetActorId ) : FFXIVIpcPacket< T, T1 >( uint32_t sourceActorId, uint32_t targetActorId ) :
FFXIVPacketBase( 3, sourceActorId, targetActorId ) FFXIVPacketBase( 3, sourceActorId, targetActorId )
{ {
@ -248,7 +247,7 @@ public:
return m_data; return m_data;
} }
protected: protected:
/** Initializes the fields of the header structures */ /** Initializes the fields of the header structures */
virtual void initialize() virtual void initialize()
{ {
@ -262,18 +261,18 @@ protected:
m_segHdr.size = sizeof( T ) + sizeof( FFXIVARR_IPC_HEADER ) + sizeof( FFXIVARR_PACKET_SEGMENT_HEADER ); m_segHdr.size = sizeof( T ) + sizeof( FFXIVARR_IPC_HEADER ) + sizeof( FFXIVARR_PACKET_SEGMENT_HEADER );
}; };
protected: protected:
/** The IPC packet header */ /** The IPC packet header */
FFXIVARR_IPC_HEADER m_ipcHdr; FFXIVARR_IPC_HEADER m_ipcHdr;
/** The underlying data portion of the packet as a structure */ /** The underlying data portion of the packet as a structure */
T m_data; T m_data;
}; };
class FFXIVRawPacket : class FFXIVRawPacket :
public FFXIVPacketBase public FFXIVPacketBase
{ {
public: public:
FFXIVRawPacket( uint16_t type, uint32_t size, uint32_t sourceActorId, uint32_t targetActorId ) : 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 ) ) ), m_data( std::vector< uint8_t >( size - sizeof( FFXIVARR_PACKET_SEGMENT_HEADER ) ) ),
FFXIVPacketBase( type, sourceActorId, targetActorId ) FFXIVPacketBase( type, sourceActorId, targetActorId )
@ -317,7 +316,7 @@ public:
return m_data; return m_data;
}; };
protected: protected:
/** Initializes the fields of the header structures */ /** Initializes the fields of the header structures */
virtual void initialize() virtual void initialize()
{ {
@ -325,12 +324,11 @@ protected:
memset( &m_data[ 0 ], 0, m_data.size() ); memset( &m_data[ 0 ], 0, m_data.size() );
}; };
protected: protected:
/** The underlying data portion of the packet as a structure */ /** The underlying data portion of the packet as a structure */
std::vector< uint8_t > m_data; std::vector< uint8_t > m_data;
}; };
} }
#endif /*_CORE_NETWORK_PACKETS_CGAMEPACKETNEW_H*/ #endif

View file

@ -2,44 +2,41 @@
#include <functional> #include <functional>
#include "Hive.h" #include "Hive.h"
namespace Sapphire::Network
{
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
Hive::Hive() : Sapphire::Network::Hive::Hive() :
m_work_ptr( new asio::io_service::work( m_io_service ) ), m_work_ptr( new asio::io_service::work( m_io_service ) ),
m_shutdown( 0 ) m_shutdown( 0 )
{ {
} }
Hive::~Hive() Sapphire::Network::Hive::~Hive()
{ {
} }
asio::io_service& Hive::getService() asio::io_service& Sapphire::Network::Hive::getService()
{ {
return m_io_service; return m_io_service;
} }
bool Hive::hasStopped() bool Sapphire::Network::Hive::hasStopped()
{ {
uint32_t v1 = 1; uint32_t v1 = 1;
uint32_t v2 = 1; uint32_t v2 = 1;
return m_shutdown.compare_exchange_strong( v1, v2 ); return m_shutdown.compare_exchange_strong( v1, v2 );
} }
void Hive::poll() void Sapphire::Network::Hive::poll()
{ {
m_io_service.poll(); m_io_service.poll();
} }
void Hive::run() void Sapphire::Network::Hive::run()
{ {
m_io_service.run(); m_io_service.run();
} }
void Hive::stop() void Sapphire::Network::Hive::stop()
{ {
uint32_t v1 = 1; uint32_t v1 = 1;
uint32_t v2 = 0; uint32_t v2 = 0;
@ -51,7 +48,7 @@ void Hive::stop()
} }
} }
void Hive::reset() void Sapphire::Network::Hive::reset()
{ {
uint32_t v1 = 0; uint32_t v1 = 0;
uint32_t v2 = 1; uint32_t v2 = 1;
@ -61,5 +58,3 @@ void Hive::reset()
m_work_ptr.reset( new asio::io_service::work( m_io_service ) ); m_work_ptr.reset( new asio::io_service::work( m_io_service ) );
} }
} }
}

View file

@ -12,7 +12,6 @@ namespace Sapphire::Network::Packets
{ {
using FFXIVPacketBasePtr = std::shared_ptr< FFXIVPacketBase >; using FFXIVPacketBasePtr = std::shared_ptr< FFXIVPacketBase >;
class PacketContainer class PacketContainer
{ {
public: public:

View file

@ -9,7 +9,6 @@ namespace Sapphire::Util
{ {
template< typename T, typename ActorIdType = uint32_t > template< typename T, typename ActorIdType = uint32_t >
class SpawnIndexAllocator class SpawnIndexAllocator
{ {
public: public:

View file

@ -32,7 +32,7 @@ namespace Sapphire::Util
void valueToFlagByteIndexValue( uint32_t inVal, uint8_t& outVal, uint16_t& outIndex ); void valueToFlagByteIndexValue( uint32_t inVal, uint8_t& outVal, uint16_t& outIndex );
template <class T> template< class T >
inline void hashCombine( std::size_t& seed, const T& v ) inline void hashCombine( std::size_t& seed, const T& v )
{ {
std::hash< T > hasher; std::hash< T > hasher;

View file

@ -13,11 +13,11 @@
namespace Sapphire::Entity namespace Sapphire::Entity
{ {
typedef struct using HateListEntry = struct
{ {
uint32_t m_hateAmount; uint32_t m_hateAmount;
CharaPtr m_pChara; CharaPtr m_pChara;
} HateListEntry; };
enum class BNpcState enum class BNpcState
{ {

View file

@ -25,7 +25,7 @@ namespace Sapphire::Entity
uint8_t m_customize[26]; uint8_t m_customize[26];
public: public:
BNpcTemplate() {}; BNpcTemplate() = default;
BNpcTemplate( uint32_t id, uint32_t baseId, uint32_t nameId, uint64_t weaponMain, uint64_t weaponSub, uint8_t aggressionMode, BNpcTemplate( uint32_t id, uint32_t baseId, uint32_t nameId, uint64_t weaponMain, uint64_t weaponSub, uint8_t aggressionMode,
uint8_t enemyType, uint8_t onlineStatus, uint8_t pose, uint16_t modelChara, uint8_t enemyType, uint8_t onlineStatus, uint8_t pose, uint16_t modelChara,

View file

@ -60,8 +60,7 @@ namespace Sapphire::Entity
Action::ActionCallback interruptCallback, uint64_t additional ); Action::ActionCallback interruptCallback, uint64_t additional );
/*! start/register a normal event */ /*! start/register a normal event */
void void eventStart( uint64_t actorId, uint32_t eventId, Event::EventHandler::EventType eventParam, uint8_t eventParam1,
eventStart( uint64_t actorId, uint32_t eventId, Event::EventHandler::EventType eventParam, uint8_t eventParam1,
uint32_t eventParam2, Event::EventHandler::EventFinishCallback callback = nullptr ); uint32_t eventParam2, Event::EventHandler::EventFinishCallback callback = nullptr );
/*! play a subevent */ /*! play a subevent */
@ -70,9 +69,8 @@ namespace Sapphire::Entity
void playGilShop( uint32_t eventId, uint32_t flags, void playGilShop( uint32_t eventId, uint32_t flags,
Event::EventHandler::SceneReturnCallback eventCallback ); Event::EventHandler::SceneReturnCallback eventCallback );
void void directorPlayScene( uint32_t eventId, uint32_t scene, uint32_t flags, uint32_t eventParam3,
directorPlayScene( uint32_t eventId, uint32_t scene, uint32_t flags, uint32_t eventParam3, uint32_t eventParam4, uint32_t eventParam4, uint32_t eventParam5 = 0 );
uint32_t eventParam5 = 0 );
/*! play a subevent */ /*! play a subevent */
void playScene( uint32_t eventId, uint32_t scene, uint32_t flags, void playScene( uint32_t eventId, uint32_t scene, uint32_t flags,