GlobalLobbyClient.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. std::weak_ptr<GlobalLobbyLoginWindow> loginWindow;
  32. std::weak_ptr<GlobalLobbyWindow> lobbyWindow;
  33. std::shared_ptr<GlobalLobbyWindow> lobbyWindowLock; // helper strong reference to prevent window destruction on closing
  34. void onPacketReceived(const std::shared_ptr<INetworkConnection> &, const std::vector<std::byte> & message) override;
  35. void onConnectionFailed(const std::string & errorMessage) override;
  36. void onConnectionEstablished(const std::shared_ptr<INetworkConnection> &) override;
  37. void onDisconnected(const std::shared_ptr<INetworkConnection> &, const std::string & errorMessage) override;
  38. void receiveAccountCreated(const JsonNode & json);
  39. void receiveOperationFailed(const JsonNode & json);
  40. void receiveClientLoginSuccess(const JsonNode & json);
  41. void receiveChatHistory(const JsonNode & json);
  42. void receiveChatMessage(const JsonNode & json);
  43. void receiveActiveAccounts(const JsonNode & json);
  44. void receiveActiveGameRooms(const JsonNode & json);
  45. void receiveMatchesHistory(const JsonNode & json);
  46. void receiveJoinRoomSuccess(const JsonNode & json);
  47. void receiveInviteReceived(const JsonNode & json);
  48. std::shared_ptr<GlobalLobbyLoginWindow> createLoginWindow();
  49. std::shared_ptr<GlobalLobbyWindow> createLobbyWindow();
  50. public:
  51. explicit GlobalLobbyClient();
  52. ~GlobalLobbyClient();
  53. const std::vector<GlobalLobbyAccount> & getActiveAccounts() const;
  54. const std::vector<GlobalLobbyRoom> & getActiveRooms() const;
  55. const std::vector<std::string> & getActiveChannels() const;
  56. const std::vector<GlobalLobbyRoom> & getMatchesHistory() const;
  57. const std::vector<GlobalLobbyChannelMessage> & getChannelHistory(const std::string & channelType, const std::string & channelName) const;
  58. /// Activate interface and pushes lobby UI as top window
  59. void activateInterface();
  60. void activateRoomInviteInterface();
  61. void sendMatchChatMessage(const std::string & messageText);
  62. void sendMessage(const JsonNode & data);
  63. void sendClientRegister(const std::string & accountName);
  64. void sendClientLogin();
  65. void sendOpenRoom(const std::string & mode, int playerLimit);
  66. void sendProxyConnectionLogin(const NetworkConnectionPtr & netConnection);
  67. void resetMatchState();
  68. void connect();
  69. bool isConnected() const;
  70. bool isInvitedToRoom(const std::string & gameRoomID);
  71. };