GlobalLobbyClient.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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::vector<GlobalLobbyRoom> matchesHistory;
  24. /// Contains known history of each channel
  25. /// Key: concatenated channel type and channel name
  26. /// Value: list of known chat messages
  27. std::map<std::string, std::vector<GlobalLobbyChannelMessage>> chatHistory;
  28. std::shared_ptr<INetworkConnection> networkConnection;
  29. std::string currentGameRoomUUID;
  30. std::weak_ptr<GlobalLobbyLoginWindow> loginWindow;
  31. std::weak_ptr<GlobalLobbyWindow> lobbyWindow;
  32. std::shared_ptr<GlobalLobbyWindow> lobbyWindowLock; // helper strong reference to prevent window destruction on closing
  33. void onPacketReceived(const std::shared_ptr<INetworkConnection> &, const std::vector<std::byte> & message) override;
  34. void onConnectionFailed(const std::string & errorMessage) override;
  35. void onConnectionEstablished(const std::shared_ptr<INetworkConnection> &) override;
  36. void onDisconnected(const std::shared_ptr<INetworkConnection> &, const std::string & errorMessage) override;
  37. void receiveAccountCreated(const JsonNode & json);
  38. void receiveOperationFailed(const JsonNode & json);
  39. void receiveClientLoginSuccess(const JsonNode & json);
  40. void receiveChatHistory(const JsonNode & json);
  41. void receiveChatMessage(const JsonNode & json);
  42. void receiveActiveAccounts(const JsonNode & json);
  43. void receiveActiveGameRooms(const JsonNode & json);
  44. void receiveMatchesHistory(const JsonNode & json);
  45. void receiveJoinRoomSuccess(const JsonNode & json);
  46. void receiveInviteReceived(const JsonNode & json);
  47. std::shared_ptr<GlobalLobbyLoginWindow> createLoginWindow();
  48. std::shared_ptr<GlobalLobbyWindow> createLobbyWindow();
  49. public:
  50. explicit GlobalLobbyClient();
  51. ~GlobalLobbyClient();
  52. const std::vector<GlobalLobbyAccount> & getActiveAccounts() const;
  53. const std::vector<GlobalLobbyRoom> & getActiveRooms() const;
  54. const std::vector<std::string> & getActiveChannels() const;
  55. const std::vector<GlobalLobbyRoom> & getMatchesHistory() const;
  56. const std::vector<GlobalLobbyChannelMessage> & getChannelHistory(const std::string & channelType, const std::string & channelName) const;
  57. /// Activate interface and pushes lobby UI as top window
  58. void activateInterface();
  59. void sendMatchChatMessage(const std::string & messageText);
  60. void sendMessage(const JsonNode & data);
  61. void sendClientRegister(const std::string & accountName);
  62. void sendClientLogin();
  63. void sendOpenRoom(const std::string & mode, int playerLimit);
  64. void sendProxyConnectionLogin(const NetworkConnectionPtr & netConnection);
  65. void resetMatchState();
  66. void connect();
  67. bool isConnected() const;
  68. };