2
0

Connection.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. VCMI_LIB_NAMESPACE_BEGIN
  12. class BinaryDeserializer;
  13. class BinarySerializer;
  14. struct CPack;
  15. class INetworkConnection;
  16. class ConnectionPackReader;
  17. class ConnectionPackWriter;
  18. class CGameState;
  19. class IGameCallback;
  20. /// Wrapper class for game connection
  21. /// Handles serialization and deserialization of data received from network
  22. class DLL_LINKAGE CConnection : boost::noncopyable
  23. {
  24. /// Non-owning pointer to underlying connection
  25. std::weak_ptr<INetworkConnection> networkConnection;
  26. std::unique_ptr<ConnectionPackReader> packReader;
  27. std::unique_ptr<ConnectionPackWriter> packWriter;
  28. std::unique_ptr<BinaryDeserializer> deserializer;
  29. std::unique_ptr<BinarySerializer> serializer;
  30. boost::mutex writeMutex;
  31. void disableStackSendingByID();
  32. void enableStackSendingByID();
  33. void disableSmartPointerSerialization();
  34. void enableSmartPointerSerialization();
  35. void disableSmartVectorMemberSerialization();
  36. void enableSmartVectorMemberSerializatoin(CGameState * gs);
  37. public:
  38. bool isMyConnection(const std::shared_ptr<INetworkConnection> & otherConnection) const;
  39. std::shared_ptr<INetworkConnection> getConnection();
  40. std::string uuid;
  41. int connectionID;
  42. explicit CConnection(std::weak_ptr<INetworkConnection> networkConnection);
  43. ~CConnection();
  44. void sendPack(const CPack * pack);
  45. CPack * retrievePack(const std::vector<std::byte> & data);
  46. void enterLobbyConnectionMode();
  47. void setCallback(IGameCallback * cb);
  48. void enterGameplayConnectionMode(CGameState * gs);
  49. };
  50. VCMI_LIB_NAMESPACE_END