2016-09-10 02:28:11 +02:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2024-05-29 22:08:32 +02:00
|
|
|
enum class ESerializationVersion : int32_t;
|
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2023-11-18 16:34:18 +02:00
|
|
|
class BinaryDeserializer;
|
|
|
|
class BinarySerializer;
|
2022-07-26 15:07:42 +02:00
|
|
|
struct CPack;
|
2024-01-12 01:10:41 +02:00
|
|
|
class INetworkConnection;
|
2023-12-25 21:23:27 +02:00
|
|
|
class ConnectionPackReader;
|
|
|
|
class ConnectionPackWriter;
|
|
|
|
class CGameState;
|
2024-01-20 23:01:49 +02:00
|
|
|
class IGameCallback;
|
2022-07-26 15:07:42 +02:00
|
|
|
|
2023-12-25 21:23:27 +02:00
|
|
|
/// Wrapper class for game connection
|
|
|
|
/// Handles serialization and deserialization of data received from network
|
|
|
|
class DLL_LINKAGE CConnection : boost::noncopyable
|
2016-09-10 02:28:11 +02:00
|
|
|
{
|
2023-11-18 16:34:18 +02:00
|
|
|
/// Non-owning pointer to underlying connection
|
2024-01-12 01:10:41 +02:00
|
|
|
std::weak_ptr<INetworkConnection> networkConnection;
|
2016-10-29 18:52:19 +02:00
|
|
|
|
2023-12-25 21:23:27 +02:00
|
|
|
std::unique_ptr<ConnectionPackReader> packReader;
|
|
|
|
std::unique_ptr<ConnectionPackWriter> packWriter;
|
|
|
|
std::unique_ptr<BinaryDeserializer> deserializer;
|
|
|
|
std::unique_ptr<BinarySerializer> serializer;
|
|
|
|
|
2024-02-25 20:05:28 +02:00
|
|
|
boost::mutex writeMutex;
|
|
|
|
|
2023-12-25 21:23:27 +02:00
|
|
|
void disableStackSendingByID();
|
|
|
|
void enableStackSendingByID();
|
|
|
|
void disableSmartVectorMemberSerialization();
|
2024-02-03 19:57:23 +02:00
|
|
|
void enableSmartVectorMemberSerializatoin(CGameState * gs);
|
2022-12-26 21:28:36 +02:00
|
|
|
|
2016-09-10 02:28:11 +02:00
|
|
|
public:
|
2024-01-12 01:10:41 +02:00
|
|
|
bool isMyConnection(const std::shared_ptr<INetworkConnection> & otherConnection) const;
|
2024-01-21 16:48:36 +02:00
|
|
|
std::shared_ptr<INetworkConnection> getConnection();
|
2023-12-25 21:23:27 +02:00
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
std::string uuid;
|
2016-09-10 02:28:11 +02:00
|
|
|
int connectionID;
|
|
|
|
|
2024-02-02 02:36:57 +02:00
|
|
|
explicit CConnection(std::weak_ptr<INetworkConnection> networkConnection);
|
2023-12-25 21:23:27 +02:00
|
|
|
~CConnection();
|
2016-09-10 02:28:11 +02:00
|
|
|
|
2024-10-04 15:35:31 +02:00
|
|
|
void sendPack(const CPack & pack);
|
|
|
|
std::unique_ptr<CPack> retrievePack(const std::vector<std::byte> & data);
|
2023-12-25 21:23:27 +02:00
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
void enterLobbyConnectionMode();
|
2024-01-20 23:01:49 +02:00
|
|
|
void setCallback(IGameCallback * cb);
|
2018-01-05 19:21:07 +02:00
|
|
|
void enterGameplayConnectionMode(CGameState * gs);
|
2024-05-29 22:08:32 +02:00
|
|
|
void setSerializationVersion(ESerializationVersion version);
|
2016-09-10 02:28:11 +02:00
|
|
|
};
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|