GlobalLobbyClient.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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::vector<std::string> activeChannels;
  23. std::set<std::string> activeInvites;
  24. std::vector<GlobalLobbyRoom> matchesHistory;
  25. /// Contains known history of each channel
  26. /// Key: concatenated channel type and channel name
  27. /// Value: list of known chat messages
  28. std::map<std::string, std::vector<GlobalLobbyChannelMessage>> chatHistory;
  29. std::shared_ptr<INetworkConnection> networkConnection;
  30. std::string currentGameRoomUUID;
  31. bool accountLoggedIn = false;
  32. std::weak_ptr<GlobalLobbyLoginWindow> loginWindow;
  33. std::weak_ptr<GlobalLobbyWindow> lobbyWindow;
  34. std::shared_ptr<GlobalLobbyWindow> lobbyWindowLock; // helper strong reference to prevent window destruction on closing
  35. void onPacketReceived(const std::shared_ptr<INetworkConnection> &, const std::vector<std::byte> & message) override;
  36. void onConnectionFailed(const std::string & errorMessage) override;
  37. void onConnectionEstablished(const std::shared_ptr<INetworkConnection> &) override;
  38. void onDisconnected(const std::shared_ptr<INetworkConnection> &, const std::string & errorMessage) override;
  39. void receiveAccountCreated(const JsonNode & json);
  40. void receiveOperationFailed(const JsonNode & json);
  41. void receiveClientLoginSuccess(const JsonNode & json);
  42. void receiveChatHistory(const JsonNode & json);
  43. void receiveChatMessage(const JsonNode & json);
  44. void receiveActiveAccounts(const JsonNode & json);
  45. void receiveActiveGameRooms(const JsonNode & json);
  46. void receiveMatchesHistory(const JsonNode & json);
  47. void receiveJoinRoomSuccess(const JsonNode & json);
  48. void receiveInviteReceived(const JsonNode & json);
  49. std::shared_ptr<GlobalLobbyLoginWindow> createLoginWindow();
  50. std::shared_ptr<GlobalLobbyWindow> createLobbyWindow();
  51. void setAccountID(const std::string & accountID);
  52. void setAccountCookie(const std::string & accountCookie);
  53. void setAccountDisplayName(const std::string & accountDisplayName);
  54. public:
  55. explicit GlobalLobbyClient();
  56. ~GlobalLobbyClient();
  57. const std::vector<GlobalLobbyAccount> & getActiveAccounts() const;
  58. const std::vector<GlobalLobbyRoom> & getActiveRooms() const;
  59. const std::vector<std::string> & getActiveChannels() const;
  60. const std::vector<GlobalLobbyRoom> & getMatchesHistory() const;
  61. const std::vector<GlobalLobbyChannelMessage> & getChannelHistory(const std::string & channelType, const std::string & channelName) const;
  62. /// Returns active room by ID. Throws out-of-range on failure
  63. const GlobalLobbyRoom & getActiveRoomByName(const std::string & roomUUID) const;
  64. const std::string & getCurrentGameRoomID() const;
  65. const std::string & getAccountID() const;
  66. const std::string & getAccountCookie() const;
  67. const std::string & getAccountDisplayName() const;
  68. const std::string & getServerHost() const;
  69. uint16_t getServerPort() const;
  70. /// Activate interface and pushes lobby UI as top window
  71. void activateInterface();
  72. void activateRoomInviteInterface();
  73. void sendMatchChatMessage(const std::string & messageText);
  74. void sendMessage(const JsonNode & data);
  75. void sendClientRegister(const std::string & accountName);
  76. void sendClientLogin();
  77. void sendOpenRoom(const std::string & mode, int playerLimit);
  78. void addChannel(const std::string & channel);
  79. void closeChannel(const std::string & channel);
  80. void sendProxyConnectionLogin(const NetworkConnectionPtr & netConnection);
  81. void resetMatchState();
  82. void connect();
  83. bool isConnected() const;
  84. bool isLoggedIn() const;
  85. bool isInvitedToRoom(const std::string & gameRoomID);
  86. };