Connection.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. boost::mutex writeMutex;
  32. void disableStackSendingByID();
  33. void enableStackSendingByID();
  34. void disableSmartPointerSerialization();
  35. void enableSmartPointerSerialization();
  36. void disableSmartVectorMemberSerialization();
  37. void enableSmartVectorMemberSerializatoin(CGameState * gs);
  38. public:
  39. bool isMyConnection(const std::shared_ptr<INetworkConnection> & otherConnection) const;
  40. std::shared_ptr<INetworkConnection> getConnection();
  41. std::string uuid;
  42. int connectionID;
  43. explicit CConnection(std::weak_ptr<INetworkConnection> networkConnection);
  44. ~CConnection();
  45. void sendPack(const CPack * pack);
  46. CPack * retrievePack(const std::vector<std::byte> & data);
  47. void enterLobbyConnectionMode();
  48. void setCallback(IGameCallback * cb);
  49. void enterGameplayConnectionMode(CGameState * gs);
  50. void setSerializationVersion(ESerializationVersion version);
  51. };
  52. VCMI_LIB_NAMESPACE_END