Connection.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 IGameInfoCallback;
  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. public:
  33. bool isMyConnection(const std::shared_ptr<INetworkConnection> & otherConnection) const;
  34. std::shared_ptr<INetworkConnection> getConnection();
  35. std::string uuid;
  36. int connectionID;
  37. explicit CConnection(std::weak_ptr<INetworkConnection> networkConnection);
  38. ~CConnection();
  39. void sendPack(const CPack & pack);
  40. std::unique_ptr<CPack> retrievePack(const std::vector<std::byte> & data);
  41. void enterLobbyConnectionMode();
  42. void setCallback(IGameInfoCallback * cb);
  43. void setSerializationVersion(ESerializationVersion version);
  44. };
  45. VCMI_LIB_NAMESPACE_END