1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-26 14:37:44 +00:00

Merge remote-tracking branch 'SapphireServer/develop' into develop

This commit is contained in:
JeidoUran 2019-01-13 16:04:26 +01:00
commit 8f1a7dd368
5 changed files with 46 additions and 52 deletions

View file

@ -15,7 +15,6 @@
#include "RestConnector.h" #include "RestConnector.h"
#include "LobbySession.h" #include "LobbySession.h"
extern Sapphire::Logger g_log;
extern Sapphire::ServerLobby g_serverLobby; extern Sapphire::ServerLobby g_serverLobby;
extern Sapphire::Network::RestConnector g_restConnector; extern Sapphire::Network::RestConnector g_restConnector;
@ -44,13 +43,13 @@ void Sapphire::Network::GameConnection::OnAccept( const std::string& host, uint1
auto connection = make_GameConnection( m_hive, m_pAcceptor, m_pFw ); auto connection = make_GameConnection( m_hive, m_pAcceptor, m_pFw );
m_pAcceptor->Accept( connection ); m_pAcceptor->Accept( connection );
g_log.info( "Connect from " + m_socket.remote_endpoint().address().to_string() ); Logger::info( "Connect from {0}", m_socket.remote_endpoint().address().to_string() );
} }
void Sapphire::Network::GameConnection::OnDisconnect() void Sapphire::Network::GameConnection::OnDisconnect()
{ {
g_log.debug( "DISCONNECT" ); Logger::debug( "DISCONNECT" );
} }
void Sapphire::Network::GameConnection::OnRecv( std::vector< uint8_t >& buffer ) void Sapphire::Network::GameConnection::OnRecv( std::vector< uint8_t >& buffer )
@ -60,15 +59,15 @@ void Sapphire::Network::GameConnection::OnRecv( std::vector< uint8_t >& buffer )
if( headerResult == Incomplete ) if( headerResult == Incomplete )
{ {
g_log.info( "Dropping connection due to incomplete packet header." ); Logger::info( "Dropping connection due to incomplete packet header." );
g_log.info( "FIXME: Packet message bounary is not implemented." ); Logger::info( "FIXME: Packet message bounary is not implemented." );
Disconnect(); Disconnect();
return; return;
} }
if( headerResult == Malformed ) if( headerResult == Malformed )
{ {
g_log.info( "Dropping connection due to malformed packet header." ); Logger::info( "Dropping connection due to malformed packet header." );
Disconnect(); Disconnect();
return; return;
} }
@ -80,15 +79,15 @@ void Sapphire::Network::GameConnection::OnRecv( std::vector< uint8_t >& buffer )
if( packetResult == Incomplete ) if( packetResult == Incomplete )
{ {
g_log.info( "Dropping connection due to incomplete packets." ); Logger::info( "Dropping connection due to incomplete packets." );
g_log.info( "FIXME: Packet message bounary is not implemented." ); Logger::info( "FIXME: Packet message bounary is not implemented." );
Disconnect(); Disconnect();
return; return;
} }
if( packetResult == Malformed ) if( packetResult == Malformed )
{ {
g_log.info( "Dropping connection due to malformed packets." ); Logger::info( "Dropping connection due to malformed packets." );
Disconnect(); Disconnect();
return; return;
} }
@ -100,7 +99,7 @@ void Sapphire::Network::GameConnection::OnRecv( std::vector< uint8_t >& buffer )
void Sapphire::Network::GameConnection::OnError( const asio::error_code& error ) void Sapphire::Network::GameConnection::OnError( const asio::error_code& error )
{ {
g_log.info( "GameConnection closed: " + error.message() ); Logger::info( "GameConnection closed: {0}", error.message() );
} }
void void
@ -119,9 +118,9 @@ Sapphire::Network::GameConnection::sendError( uint64_t sequence, uint32_t errorc
void Sapphire::Network::GameConnection::getCharList( FFXIVARR_PACKET_RAW& packet, uint32_t tmpId ) void Sapphire::Network::GameConnection::getCharList( FFXIVARR_PACKET_RAW& packet, uint32_t tmpId )
{ {
uint64_t sequence = *reinterpret_cast< uint64_t* >( &packet.data[ 0 ] + 0x10 ); uint64_t sequence = *reinterpret_cast< uint64_t* >( &packet.data[ 0 ] + 0x10 );
g_log.info( "Sequence [" + std::to_string( sequence ) + "]" ); Logger::info( "Sequence [{0}]", sequence );
g_log.info( "[" + std::to_string( m_pSession->getAccountID() ) + "] ReqCharList" ); Logger::info( "[{0}] ReqCharList", m_pSession->getAccountID() );
Packets::LobbyPacketContainer pRP( m_encKey ); Packets::LobbyPacketContainer pRP( m_encKey );
auto serverListPacket = makeLobbyPacket< FFXIVIpcServerList >( tmpId ); auto serverListPacket = makeLobbyPacket< FFXIVIpcServerList >( tmpId );
@ -171,11 +170,13 @@ void Sapphire::Network::GameConnection::getCharList( FFXIVARR_PACKET_RAW& packet
charListPacket->data().charaDetails[ j ] = details; charListPacket->data().charaDetails[ j ] = details;
g_log.debug( "[" + std::to_string( charIndex ) + "] " + std::to_string( details.index ) + " - " Logger::debug( "[{0}] {1} - {2} - {3} - {4} - {5}",
+ std::get< 0 >( charEntry ) + " - " + charIndex,
std::to_string( std::get< 1 >( charEntry ) ) + " - " + details.index,
std::to_string( std::get< 2 >( charEntry ) ) + " - " + std::get< 0 >( charEntry ),
std::get< 3 >( charEntry ) ); std::get< 1 >( charEntry ),
std::get< 2 >( charEntry ),
std::get< 3 >( charEntry ) );
} }
charIndex++; charIndex++;
} }
@ -201,9 +202,9 @@ void Sapphire::Network::GameConnection::getCharList( FFXIVARR_PACKET_RAW& packet
void Sapphire::Network::GameConnection::enterWorld( FFXIVARR_PACKET_RAW& packet, uint32_t tmpId ) void Sapphire::Network::GameConnection::enterWorld( FFXIVARR_PACKET_RAW& packet, uint32_t tmpId )
{ {
uint64_t sequence = *reinterpret_cast< uint64_t* >( &packet.data[ 0 ] + 0x10 ); uint64_t sequence = *reinterpret_cast< uint64_t* >( &packet.data[ 0 ] + 0x10 );
g_log.info( "Sequence [" + std::to_string( sequence ) + "]" ); Logger::info( "Sequence [{0}]", sequence );
g_log.info( "[" + std::to_string( m_pSession->getAccountID() ) + "] ReqEnterWorld" ); Logger::info( "[{0}] ReqEnterWorld", m_pSession->getAccountID() );
uint64_t lookupId = *reinterpret_cast< uint64_t* >( &packet.data[ 0 ] + 0x18 ); uint64_t lookupId = *reinterpret_cast< uint64_t* >( &packet.data[ 0 ] + 0x18 );
@ -225,8 +226,7 @@ void Sapphire::Network::GameConnection::enterWorld( FFXIVARR_PACKET_RAW& packet,
if( logInCharId == -1 ) if( logInCharId == -1 )
return; return;
g_log.info( "[" + std::to_string( m_pSession->getAccountID() ) + "] Logging in as " + logInCharName + "(" + Logger::info( "[{0}] Logging in as {1} ({2})", m_pSession->getAccountID(), logInCharName, logInCharId );
std::to_string( logInCharId ) + ")" );
Packets::LobbyPacketContainer pRP( m_encKey ); Packets::LobbyPacketContainer pRP( m_encKey );
@ -251,12 +251,12 @@ bool Sapphire::Network::GameConnection::sendServiceAccountList( FFXIVARR_PACKET_
session->setAccountID( 0 ); session->setAccountID( 0 );
session->setSessionId( ( uint8_t* ) &packet.data[ 0 ] + 0x20 ); session->setSessionId( ( uint8_t* ) &packet.data[ 0 ] + 0x20 );
pSession = session; pSession = session;
g_log.info( "Allowed connection with no session: " + std::string( ( char* ) &packet.data[ 0 ] + 0x20 ) ); Logger::info( "Allowed connection with no session: {0}", std::string( ( char* ) &packet.data[ 0 ] + 0x20 ) );
} }
if( pSession != nullptr ) if( pSession != nullptr )
{ {
g_log.info( "Found session linked to accountId: " + std::to_string( pSession->getAccountID() ) ); Logger::info( "Found session linked to accountId: {0}", pSession->getAccountID() );
m_pSession = pSession; m_pSession = pSession;
auto serviceIdInfoPacket = makeLobbyPacket< FFXIVIpcServiceIdInfo >( tmpId ); auto serviceIdInfoPacket = makeLobbyPacket< FFXIVIpcServiceIdInfo >( tmpId );
@ -272,7 +272,7 @@ bool Sapphire::Network::GameConnection::sendServiceAccountList( FFXIVARR_PACKET_
} }
else else
{ {
g_log.info( "Could not retrieve session: " + std::string( ( char* ) &packet.data[ 0 ] + 0x20 ) ); Logger::info( "Could not retrieve session: {0}", std::string( ( char* ) &packet.data[ 0 ] + 0x20 ) );
sendError( 1, 5006, 13001, tmpId ); sendError( 1, 5006, 13001, tmpId );
return true; return true;
@ -284,10 +284,10 @@ bool Sapphire::Network::GameConnection::createOrModifyChar( FFXIVARR_PACKET_RAW&
{ {
uint64_t sequence = *reinterpret_cast< uint64_t* >( &packet.data[ 0 ] + 0x10 ); uint64_t sequence = *reinterpret_cast< uint64_t* >( &packet.data[ 0 ] + 0x10 );
uint8_t type = *reinterpret_cast< uint8_t* >( &packet.data[ 0 ] + 0x29 ); uint8_t type = *reinterpret_cast< uint8_t* >( &packet.data[ 0 ] + 0x29 );
g_log.info( "Sequence [" + std::to_string( sequence ) + "]" ); Logger::info( "Sequence [{0}]", sequence );
g_log.info( "Type [" + std::to_string( type ) + "]" ); Logger::info( "Type [{0}]", type );
g_log.info( "[" + std::to_string( m_pSession->getAccountID() ) + "] ReqCharCreate" ); Logger::info( "[{0}] ReqCharCreate", m_pSession->getAccountID() );
std::string name; std::string name;
uint32_t newId = g_restConnector.getNextCharId(); uint32_t newId = g_restConnector.getNextCharId();
@ -297,7 +297,7 @@ bool Sapphire::Network::GameConnection::createOrModifyChar( FFXIVARR_PACKET_RAW&
{ {
name = std::string( ( char* ) &packet.data[ 0 ] + 0x2C ); name = std::string( ( char* ) &packet.data[ 0 ] + 0x2C );
g_log.info( "[" + std::to_string( m_pSession->getAccountID() ) + "] Type 1: " + name ); Logger::info( "[{0}] Type 1: {1}", m_pSession->getAccountID(), name );
Packets::LobbyPacketContainer pRP( m_encKey ); Packets::LobbyPacketContainer pRP( m_encKey );
@ -325,7 +325,7 @@ bool Sapphire::Network::GameConnection::createOrModifyChar( FFXIVARR_PACKET_RAW&
else if( type == 2 ) //Character creation finalize else if( type == 2 ) //Character creation finalize
{ {
std::string charDetails( ( char* ) &packet.data[ 0 ] + 0x4C ); std::string charDetails( ( char* ) &packet.data[ 0 ] + 0x4C );
g_log.info( "[" + std::to_string( m_pSession->getAccountID() ) + "] Type 2: " + charDetails ); Logger::info( "[{0}] Type 2: {1}", m_pSession->getAccountID(), charDetails );
if( g_restConnector.createCharacter( ( char* ) m_pSession->getSessionId(), m_pSession->newCharName, charDetails ) != if( g_restConnector.createCharacter( ( char* ) m_pSession->getSessionId(), m_pSession->newCharName, charDetails ) !=
-1 ) -1 )
@ -354,7 +354,7 @@ bool Sapphire::Network::GameConnection::createOrModifyChar( FFXIVARR_PACKET_RAW&
else if( type == 4 ) //Character delete else if( type == 4 ) //Character delete
{ {
name = std::string( ( char* ) &packet.data[ 0 ] + 0x2C ); name = std::string( ( char* ) &packet.data[ 0 ] + 0x2C );
g_log.info( "[" + std::to_string( m_pSession->getAccountID() ) + "] Type 4: " + name ); Logger::info( "[{0}] Type 4: {1}", m_pSession->getAccountID(), name );
if( g_restConnector.deleteCharacter( ( char* ) m_pSession->getSessionId(), name ) ) if( g_restConnector.deleteCharacter( ( char* ) m_pSession->getSessionId(), name ) )
@ -383,8 +383,7 @@ bool Sapphire::Network::GameConnection::createOrModifyChar( FFXIVARR_PACKET_RAW&
} }
else else
{ {
g_log.error( "[" + std::to_string( m_pSession->getAccountID() ) + "] Unknown Character Creation Type: " + Logger::error( "[{0}] Unknown Character Creation Type: {1}", m_pSession->getAccountID(), type );
std::to_string( type ) );
} }
return false; return false;
} }
@ -394,7 +393,7 @@ void Sapphire::Network::GameConnection::handleGamePacket( Packets::FFXIVARR_PACK
uint32_t tmpId = packet.segHdr.target_actor; uint32_t tmpId = packet.segHdr.target_actor;
g_log.info( "OpCode [" + std::to_string( *reinterpret_cast< uint16_t* >( &packet.data[ 2 ] ) ) + "]" ); Logger::info( "OpCode [{0}]", *reinterpret_cast< uint16_t* >( &packet.data[ 2 ] ) );
switch( *reinterpret_cast< uint16_t* >( &packet.data[ 2 ] ) ) switch( *reinterpret_cast< uint16_t* >( &packet.data[ 2 ] ) )
{ {
@ -438,7 +437,6 @@ void Sapphire::Network::GameConnection::sendPacket( Packets::LobbyPacketContaine
void Sapphire::Network::GameConnection::sendPackets( Packets::PacketContainer* pPacket ) void Sapphire::Network::GameConnection::sendPackets( Packets::PacketContainer* pPacket )
{ {
//g_log.Log(LoggingSeverity::info, pPacket->toString());
std::vector< uint8_t > sendBuffer; std::vector< uint8_t > sendBuffer;
pPacket->fillSendBuffer( sendBuffer ); pPacket->fillSendBuffer( sendBuffer );
@ -503,7 +501,7 @@ void Sapphire::Network::GameConnection::handlePackets( const Sapphire::Network::
case SEGMENTTYPE_IPC: // game packet case SEGMENTTYPE_IPC: // game packet
{ {
g_log.info( "GamePacket [" + std::to_string( inPacket.segHdr.type ) + "]" ); Logger::info( "GamePacket [{0}]", inPacket.segHdr.type );
handleGamePacket( inPacket ); handleGamePacket( inPacket );
break; break;
} }

View file

@ -8,8 +8,6 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
extern Sapphire::Logger g_log;
typedef std::vector< std::tuple< std::string, uint32_t, uint64_t, std::string > > CharList; typedef std::vector< std::tuple< std::string, uint32_t, uint64_t, std::string > > CharList;
Sapphire::Network::RestConnector::RestConnector() Sapphire::Network::RestConnector::RestConnector()
@ -35,7 +33,7 @@ HttpResponse Sapphire::Network::RestConnector::requestApi( std::string endpoint,
} }
catch( std::exception& e ) catch( std::exception& e )
{ {
g_log.error( endpoint + " failed, REST is not reachable: " + std::string( e.what() ) ); Logger::error( "{0} failed, Api is not reachable: {1}", endpoint, e.what() );
return nullptr; return nullptr;
} }
return r; return r;
@ -61,7 +59,7 @@ Sapphire::LobbySessionPtr Sapphire::Network::RestConnector::getSession( char* sI
} }
catch( std::exception& e ) catch( std::exception& e )
{ {
g_log.debug( "Could not parse REST response: " + std::string( e.what() ) ); Logger::debug( "Could not parse Api response: {0}", e.what() );
return nullptr; return nullptr;
} }
@ -103,7 +101,7 @@ bool Sapphire::Network::RestConnector::checkNameTaken( std::string name )
} }
catch( std::exception& e ) catch( std::exception& e )
{ {
g_log.debug( "Could not parse REST response: " + std::string( e.what() ) ); Logger::debug( "Could not parse Api response: {0}", e.what() );
return true; return true;
} }
@ -137,7 +135,7 @@ uint32_t Sapphire::Network::RestConnector::getNextCharId()
} }
catch( std::exception& e ) catch( std::exception& e )
{ {
g_log.debug( "Could not parse REST response: " + std::string( e.what() ) ); Logger::debug( "Could not parse Api response: {0}", e.what() );
return -1; return -1;
} }
@ -176,7 +174,7 @@ uint64_t Sapphire::Network::RestConnector::getNextContentId()
} }
catch( std::exception& e ) catch( std::exception& e )
{ {
g_log.debug( "Could not parse REST response: " + std::string( e.what() ) ); Logger::debug( "Could not parse Api response: {0}", e.what() );
return -1; return -1;
} }
@ -206,7 +204,7 @@ CharList Sapphire::Network::RestConnector::getCharList( char* sId )
return list; return list;
std::string content = std::string( std::istreambuf_iterator< char >( r->content ), {} ); std::string content = std::string( std::istreambuf_iterator< char >( r->content ), {} );
g_log.debug( content ); Logger::debug( content );
if( r->status_code.find( "200" ) != std::string::npos ) if( r->status_code.find( "200" ) != std::string::npos )
{ {
auto json = nlohmann::json(); auto json = nlohmann::json();
@ -217,18 +215,18 @@ CharList Sapphire::Network::RestConnector::getCharList( char* sId )
} }
catch( std::exception& e ) catch( std::exception& e )
{ {
g_log.debug( "Could not parse REST response: " + std::string( e.what() ) ); Logger::debug( "Could not parse Api response: {0}", e.what() );
return list; return list;
} }
if( json["result"].get< std::string >().find( "invalid" ) == std::string::npos ) if( json["result"].get< std::string >().find( "invalid" ) == std::string::npos )
{ {
g_log.debug( json["result"] ); Logger::debug( json["result"] );
for( auto& child : json["charArray"] ) for( auto& child : json["charArray"] )
{ {
g_log.info( child["contentId"] ); Logger::info( child["contentId"] );
//std::string, uint32_t, uint64_t, std::string //std::string, uint32_t, uint64_t, std::string
list.push_back( { child["name"], list.push_back( { child["name"],
std::stoi( std::string( child["charId"] ) ), std::stoi( std::string( child["charId"] ) ),
@ -271,7 +269,7 @@ bool Sapphire::Network::RestConnector::deleteCharacter( char* sId, std::string n
} }
catch( std::exception& e ) catch( std::exception& e )
{ {
g_log.debug( "Could not parse REST response: " + std::string( e.what() ) ); Logger::debug( "Could not parse Api response: {0}", e.what() );
return false; return false;
} }
@ -297,7 +295,7 @@ int Sapphire::Network::RestConnector::createCharacter( char* sId, std::string na
return -1; return -1;
std::string content = std::string( std::istreambuf_iterator< char >( r->content ), {} ); std::string content = std::string( std::istreambuf_iterator< char >( r->content ), {} );
g_log.debug( content ); Logger::debug( content );
if( r->status_code.find( "200" ) != std::string::npos ) if( r->status_code.find( "200" ) != std::string::npos )
{ {
auto json = nlohmann::json(); auto json = nlohmann::json();
@ -308,7 +306,7 @@ int Sapphire::Network::RestConnector::createCharacter( char* sId, std::string na
} }
catch( std::exception& e ) catch( std::exception& e )
{ {
g_log.debug( "Could not parse REST response: " + std::string( e.what() ) ); Logger::debug( "Could not parse Api response: {0}", e.what() );
return -1; return -1;
} }

View file

@ -276,7 +276,6 @@ void Sapphire::Network::GameConnection::handlePacket( Sapphire::Network::Packets
void Sapphire::Network::GameConnection::sendPackets( Packets::PacketContainer* pPacket ) void Sapphire::Network::GameConnection::sendPackets( Packets::PacketContainer* pPacket )
{ {
//g_log.Log(LoggingSeverity::info, pPacket->toString());
std::vector< uint8_t > sendBuffer; std::vector< uint8_t > sendBuffer;
pPacket->fillSendBuffer( sendBuffer ); pPacket->fillSendBuffer( sendBuffer );

View file

@ -82,7 +82,7 @@ void Sapphire::Network::GameConnection::clientTriggerHandler( FrameworkPtr pFw,
Logger::debug( "[{0}] Incoming action: {1:04X}\nparam1: {2:016X}\nparam2: {3:08X}\nparam3: {4:016x}", Logger::debug( "[{0}] Incoming action: {1:04X}\nparam1: {2:016X}\nparam2: {3:08X}\nparam3: {4:016x}",
m_pSession->getId(), commandId, param1, param2, param3 ); m_pSession->getId(), commandId, param1, param2, param3 );
//g_log.Log(LoggingSeverity::debug, "[" + std::to_string(m_pSession->getId()) + "] " + pInPacket->toString()); //Logger::Log(LoggingSeverity::debug, "[" + std::to_string(m_pSession->getId()) + "] " + pInPacket->toString());
switch( commandId ) switch( commandId )
{ {

View file

@ -155,7 +155,6 @@ void Sapphire::Scripting::ScriptMgr::onPlayerFirstEnterWorld( Entity::Player& pl
// catch( const std::exception &e ) // catch( const std::exception &e )
// { // {
// std::string what = e.what(); // std::string what = e.what();
// g_log.Log( LoggingSeverity::error, what );
// } // }
} }