1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-01 16:37:45 +00:00
sapphire/src/lobby/GameConnection.h

103 lines
2.8 KiB
C
Raw Normal View History

2017-08-08 13:53:47 +02:00
#ifndef GAMECONNECTION_H
#define GAMECONNECTION_H
2018-03-06 22:22:19 +01:00
#include <Network/Connection.h>
#include <Network/Acceptor.h>
#include <Network/CommonNetwork.h>
2017-08-08 13:53:47 +02:00
2018-03-06 22:22:19 +01:00
#include <Network/PacketContainer.h>
#include <Util/LockedQueue.h>
2017-08-08 13:53:47 +02:00
#include <asio.hpp>
2018-10-26 13:46:28 +02:00
#include <map>
#include "LobbyPacketContainer.h"
2017-08-08 13:53:47 +02:00
#include "Forwards.h"
#define DECLARE_HANDLER( x ) void x( Packets::GamePacketPtr pInPacket, Entity::PlayerPtr pPlayer )
namespace Sapphire::Lobby
2017-08-08 13:53:47 +02:00
{
class GameConnection : public Network::Connection
2018-10-28 21:53:21 +01:00
{
2017-08-08 13:53:47 +02:00
2018-10-28 21:53:21 +01:00
private:
// TODO move the next three params to the session, makes more sense there
// encryption key
uint8_t m_encKey[0x10];
2017-08-08 13:53:47 +02:00
2018-10-28 21:53:21 +01:00
// base key, the encryption key is generated from this
union
{
struct {
uint32_t magic;
uint32_t key;
uint32_t version;
char keyPhrase[ 0x20 ];
};
uint8_t rawKey[ 0x2C ];
} m_baseKey;
2017-08-08 13:53:47 +02:00
2018-10-28 21:53:21 +01:00
bool m_bEncryptionInitialized;
2017-08-08 13:53:47 +02:00
Network::AcceptorPtr m_pAcceptor;
2017-08-08 13:53:47 +02:00
2018-10-28 21:53:21 +01:00
LobbySessionPtr m_pSession;
2017-08-08 13:53:47 +02:00
Common::Util::LockedQueue< Network::Packets::GamePacketPtr > m_inQueue;
Common::Util::LockedQueue< Network::Packets::GamePacketPtr > m_outQueue;
std::vector< uint8_t > m_packets;
2017-08-08 13:53:47 +02:00
2018-10-28 21:53:21 +01:00
public:
2020-03-01 01:09:33 +11:00
GameConnection( Network::HivePtr pHive, Network::AcceptorPtr pAcceptor );
2017-08-08 13:53:47 +02:00
2018-10-28 21:53:21 +01:00
~GameConnection();
2017-08-08 13:53:47 +02:00
2018-10-28 21:53:21 +01:00
void generateEncryptionKey( uint32_t key, const std::string& keyPhrase );
2017-08-08 13:53:47 +02:00
2018-10-28 21:53:21 +01:00
// overwrite the parents onConnect for our game socket needs
void onAccept( const std::string& host, uint16_t port ) override;
2017-08-08 13:53:47 +02:00
void onDisconnect() override;
2017-08-08 13:53:47 +02:00
void onRecv( std::vector< uint8_t >& buffer ) override;
2017-08-08 13:53:47 +02:00
void onError( const asio::error_code& error ) override;
2017-08-08 13:53:47 +02:00
void sendError( uint32_t requestNumber, uint32_t clientTimeValue, uint32_t errorCode, uint16_t messageId, uint32_t tmpId );
void serviceLogin( Network::Packets::FFXIVARR_PACKET_RAW& packet, uint32_t tmpId );
void gameLogin( Network::Packets::FFXIVARR_PACKET_RAW& packet, uint32_t tmpId );
2017-08-08 13:53:47 +02:00
bool login( Network::Packets::FFXIVARR_PACKET_RAW& packet, uint32_t tmpId );
2017-08-08 13:53:47 +02:00
bool charaMake( Network::Packets::FFXIVARR_PACKET_RAW& packet, uint32_t tmpId );
2017-08-08 13:53:47 +02:00
void debugLogin( Network::Packets::FFXIVARR_PACKET_RAW &packet, uint32_t tmpId );
2017-08-08 13:53:47 +02:00
void debugLogin2( Network::Packets::FFXIVARR_PACKET_RAW & packet, uint32_t tmpId );
2017-08-08 13:53:47 +02:00
void handlePackets( const Network::Packets::FFXIVARR_PACKET_HEADER& ipcHeader,
const std::vector< Network::Packets::FFXIVARR_PACKET_RAW >& packetData );
void handleGamePacket( Network::Packets::FFXIVARR_PACKET_RAW& pPacket );
2017-08-08 13:53:47 +02:00
void handlePacket( Network::Packets::FFXIVPacketBasePtr pPacket );
void sendPackets( Network::Packets::PacketContainer* pPacket );
void sendPacket( Network::Packets::LobbyPacketContainer& pLpc );
2017-08-08 13:53:47 +02:00
void sendSinglePacket( Network::Packets::FFXIVPacketBasePtr pPacket );
2017-08-08 13:53:47 +02:00
2018-10-28 21:53:21 +01:00
};
2017-08-08 13:53:47 +02:00
}
#endif