GameConnection.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * GameConnection.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. #include "GameConnectionID.h"
  12. enum class ESerializationVersion : int32_t;
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class BinaryDeserializer;
  15. class BinarySerializer;
  16. struct CPack;
  17. class INetworkConnection;
  18. class GameConnectionPackReader;
  19. class GameConnectionPackWriter;
  20. class CGameState;
  21. class IGameInfoCallback;
  22. /// Wrapper class for game connection
  23. /// Handles serialization and deserialization of data received from network
  24. class DLL_LINKAGE GameConnection final : boost::noncopyable
  25. {
  26. /// Non-owning pointer to underlying connection
  27. std::weak_ptr<INetworkConnection> networkConnection;
  28. std::unique_ptr<GameConnectionPackReader> packReader;
  29. std::unique_ptr<GameConnectionPackWriter> packWriter;
  30. std::unique_ptr<BinaryDeserializer> deserializer;
  31. std::unique_ptr<BinarySerializer> serializer;
  32. std::mutex writeMutex;
  33. public:
  34. bool isMyConnection(const std::shared_ptr<INetworkConnection> & otherConnection) const;
  35. std::shared_ptr<INetworkConnection> getConnection();
  36. std::string uuid;
  37. GameConnectionID connectionID = GameConnectionID::INVALID;
  38. explicit GameConnection(std::weak_ptr<INetworkConnection> networkConnection);
  39. ~GameConnection();
  40. void sendPack(const CPack & pack);
  41. std::unique_ptr<CPack> retrievePack(const std::vector<std::byte> & data);
  42. void enterLobbyConnectionMode();
  43. void setCallback(IGameInfoCallback & cb);
  44. void setSerializationVersion(ESerializationVersion version);
  45. };
  46. VCMI_LIB_NAMESPACE_END