Connection.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Connection.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. enum class ESerializationVersion : int32_t;
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class BinaryDeserializer;
  14. class BinarySerializer;
  15. struct CPack;
  16. class INetworkConnection;
  17. class ConnectionPackReader;
  18. class ConnectionPackWriter;
  19. class CGameState;
  20. class IGameCallback;
  21. /// Wrapper class for game connection
  22. /// Handles serialization and deserialization of data received from network
  23. class DLL_LINKAGE CConnection : boost::noncopyable
  24. {
  25. /// Non-owning pointer to underlying connection
  26. std::weak_ptr<INetworkConnection> networkConnection;
  27. std::unique_ptr<ConnectionPackReader> packReader;
  28. std::unique_ptr<ConnectionPackWriter> packWriter;
  29. std::unique_ptr<BinaryDeserializer> deserializer;
  30. std::unique_ptr<BinarySerializer> serializer;
  31. std::mutex writeMutex;
  32. void disableSmartVectorMemberSerialization();
  33. void enableSmartVectorMemberSerializatoin(CGameState * gs);
  34. public:
  35. bool isMyConnection(const std::shared_ptr<INetworkConnection> & otherConnection) const;
  36. std::shared_ptr<INetworkConnection> getConnection();
  37. std::string uuid;
  38. int connectionID;
  39. explicit CConnection(std::weak_ptr<INetworkConnection> networkConnection);
  40. ~CConnection();
  41. void sendPack(const CPack & pack);
  42. std::unique_ptr<CPack> retrievePack(const std::vector<std::byte> & data);
  43. void enterLobbyConnectionMode();
  44. void setCallback(IGameCallback * cb);
  45. void enterGameplayConnectionMode(CGameState * gs);
  46. void setSerializationVersion(ESerializationVersion version);
  47. };
  48. VCMI_LIB_NAMESPACE_END