1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00
vcmi/lib/serializer/Connection.h

64 lines
1.7 KiB
C++
Raw Normal View History

/*
* Connection.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
enum class ESerializationVersion : int32_t;
VCMI_LIB_NAMESPACE_BEGIN
class BinaryDeserializer;
class BinarySerializer;
struct CPack;
2024-01-12 01:10:41 +02:00
class INetworkConnection;
class ConnectionPackReader;
class ConnectionPackWriter;
class CGameState;
class IGameCallback;
/// Wrapper class for game connection
/// Handles serialization and deserialization of data received from network
class DLL_LINKAGE CConnection : boost::noncopyable
{
/// Non-owning pointer to underlying connection
2024-01-12 01:10:41 +02:00
std::weak_ptr<INetworkConnection> networkConnection;
std::unique_ptr<ConnectionPackReader> packReader;
std::unique_ptr<ConnectionPackWriter> packWriter;
std::unique_ptr<BinaryDeserializer> deserializer;
std::unique_ptr<BinarySerializer> serializer;
boost::mutex writeMutex;
void disableStackSendingByID();
void enableStackSendingByID();
void disableSmartVectorMemberSerialization();
void enableSmartVectorMemberSerializatoin(CGameState * gs);
2022-12-26 21:28:36 +02:00
public:
2024-01-12 01:10:41 +02:00
bool isMyConnection(const std::shared_ptr<INetworkConnection> & otherConnection) const;
std::shared_ptr<INetworkConnection> getConnection();
std::string uuid;
int connectionID;
2024-02-02 02:36:57 +02:00
explicit CConnection(std::weak_ptr<INetworkConnection> networkConnection);
~CConnection();
void sendPack(const CPack & pack);
std::unique_ptr<CPack> retrievePack(const std::vector<std::byte> & data);
void enterLobbyConnectionMode();
void setCallback(IGameCallback * cb);
void enterGameplayConnectionMode(CGameState * gs);
void setSerializationVersion(ESerializationVersion version);
};
VCMI_LIB_NAMESPACE_END