Connection.h 1.6 KB

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