GlobalLobbyClient.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * GlobalLobbyClient.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 "GlobalLobbyDefines.h"
  12. #include "../../lib/network/NetworkInterface.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class JsonNode;
  15. VCMI_LIB_NAMESPACE_END
  16. class GlobalLobbyLoginWindow;
  17. class GlobalLobbyWindow;
  18. class GlobalLobbyClient final : public INetworkClientListener, boost::noncopyable
  19. {
  20. std::vector<GlobalLobbyAccount> activeAccounts;
  21. std::vector<GlobalLobbyRoom> activeRooms;
  22. std::shared_ptr<INetworkConnection> networkConnection;
  23. std::weak_ptr<GlobalLobbyLoginWindow> loginWindow;
  24. std::weak_ptr<GlobalLobbyWindow> lobbyWindow;
  25. std::shared_ptr<GlobalLobbyWindow> lobbyWindowLock; // helper strong reference to prevent window destruction on closing
  26. void onPacketReceived(const std::shared_ptr<INetworkConnection> &, const std::vector<uint8_t> & message) override;
  27. void onConnectionFailed(const std::string & errorMessage) override;
  28. void onConnectionEstablished(const std::shared_ptr<INetworkConnection> &) override;
  29. void onDisconnected(const std::shared_ptr<INetworkConnection> &) override;
  30. void sendClientRegister();
  31. void sendClientLogin();
  32. void receiveAccountCreated(const JsonNode & json);
  33. void receiveOperationFailed(const JsonNode & json);
  34. void receiveLoginSuccess(const JsonNode & json);
  35. void receiveChatHistory(const JsonNode & json);
  36. void receiveChatMessage(const JsonNode & json);
  37. void receiveActiveAccounts(const JsonNode & json);
  38. void receiveActiveGameRooms(const JsonNode & json);
  39. void receiveJoinRoomSuccess(const JsonNode & json);
  40. std::shared_ptr<GlobalLobbyLoginWindow> createLoginWindow();
  41. std::shared_ptr<GlobalLobbyWindow> createLobbyWindow();
  42. public:
  43. explicit GlobalLobbyClient();
  44. ~GlobalLobbyClient();
  45. const std::vector<GlobalLobbyAccount> & getActiveAccounts() const;
  46. const std::vector<GlobalLobbyRoom> & getActiveRooms() const;
  47. /// Activate interface and pushes lobby UI as top window
  48. void activateInterface();
  49. void sendMessage(const JsonNode & data);
  50. void sendOpenPublicRoom();
  51. void sendOpenPrivateRoom();
  52. void sendProxyConnectionLogin(const NetworkConnectionPtr & netConnection);
  53. void connect();
  54. bool isConnected();
  55. };