2023-11-11 16:43:58 +02:00
|
|
|
/*
|
2023-12-27 19:07:49 +02:00
|
|
|
* GlobalLobbyClient.h, part of VCMI engine
|
2023-11-11 16:43:58 +02:00
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2024-01-21 16:48:36 +02:00
|
|
|
#include "GlobalLobbyDefines.h"
|
2024-01-12 01:10:41 +02:00
|
|
|
#include "../../lib/network/NetworkInterface.h"
|
2023-11-11 16:43:58 +02:00
|
|
|
|
2023-12-27 19:07:49 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
class JsonNode;
|
|
|
|
VCMI_LIB_NAMESPACE_END
|
2023-11-12 15:32:54 +02:00
|
|
|
|
2023-12-28 21:27:21 +02:00
|
|
|
class GlobalLobbyLoginWindow;
|
2023-12-27 19:07:49 +02:00
|
|
|
class GlobalLobbyWindow;
|
2023-11-11 16:43:58 +02:00
|
|
|
|
2024-01-21 16:48:36 +02:00
|
|
|
class GlobalLobbyClient final : public INetworkClientListener, boost::noncopyable
|
2023-11-11 16:43:58 +02:00
|
|
|
{
|
2024-01-21 16:48:36 +02:00
|
|
|
std::vector<GlobalLobbyAccount> activeAccounts;
|
|
|
|
std::vector<GlobalLobbyRoom> activeRooms;
|
2024-03-13 23:02:53 +02:00
|
|
|
std::vector<std::string> activeChannels;
|
2024-03-25 20:23:57 +02:00
|
|
|
std::set<std::string> activeInvites;
|
2024-03-20 18:40:37 +02:00
|
|
|
std::vector<GlobalLobbyRoom> matchesHistory;
|
2024-03-13 23:02:53 +02:00
|
|
|
|
|
|
|
/// Contains known history of each channel
|
|
|
|
/// Key: concatenated channel type and channel name
|
|
|
|
/// Value: list of known chat messages
|
|
|
|
std::map<std::string, std::vector<GlobalLobbyChannelMessage>> chatHistory;
|
2024-01-21 16:48:36 +02:00
|
|
|
|
2024-01-12 16:55:36 +02:00
|
|
|
std::shared_ptr<INetworkConnection> networkConnection;
|
2024-03-18 19:52:53 +02:00
|
|
|
std::string currentGameRoomUUID;
|
2023-12-28 21:27:21 +02:00
|
|
|
|
|
|
|
std::weak_ptr<GlobalLobbyLoginWindow> loginWindow;
|
|
|
|
std::weak_ptr<GlobalLobbyWindow> lobbyWindow;
|
|
|
|
std::shared_ptr<GlobalLobbyWindow> lobbyWindowLock; // helper strong reference to prevent window destruction on closing
|
2023-11-12 15:32:54 +02:00
|
|
|
|
2024-02-02 01:27:19 +02:00
|
|
|
void onPacketReceived(const std::shared_ptr<INetworkConnection> &, const std::vector<std::byte> & message) override;
|
2023-11-12 13:27:22 +02:00
|
|
|
void onConnectionFailed(const std::string & errorMessage) override;
|
2024-01-12 01:10:41 +02:00
|
|
|
void onConnectionEstablished(const std::shared_ptr<INetworkConnection> &) override;
|
2024-02-02 01:27:19 +02:00
|
|
|
void onDisconnected(const std::shared_ptr<INetworkConnection> &, const std::string & errorMessage) override;
|
2023-11-12 15:32:54 +02:00
|
|
|
|
2024-01-08 20:50:43 +02:00
|
|
|
void receiveAccountCreated(const JsonNode & json);
|
2024-02-02 00:12:30 +02:00
|
|
|
void receiveOperationFailed(const JsonNode & json);
|
2024-03-11 17:48:56 +02:00
|
|
|
void receiveClientLoginSuccess(const JsonNode & json);
|
2024-01-08 20:50:43 +02:00
|
|
|
void receiveChatHistory(const JsonNode & json);
|
|
|
|
void receiveChatMessage(const JsonNode & json);
|
|
|
|
void receiveActiveAccounts(const JsonNode & json);
|
2024-01-21 16:48:36 +02:00
|
|
|
void receiveActiveGameRooms(const JsonNode & json);
|
2024-03-20 18:40:37 +02:00
|
|
|
void receiveMatchesHistory(const JsonNode & json);
|
2024-01-21 16:48:36 +02:00
|
|
|
void receiveJoinRoomSuccess(const JsonNode & json);
|
2024-02-10 19:02:25 +02:00
|
|
|
void receiveInviteReceived(const JsonNode & json);
|
2024-01-21 16:48:36 +02:00
|
|
|
|
|
|
|
std::shared_ptr<GlobalLobbyLoginWindow> createLoginWindow();
|
|
|
|
std::shared_ptr<GlobalLobbyWindow> createLobbyWindow();
|
2024-01-11 22:51:36 +02:00
|
|
|
|
2023-11-11 16:43:58 +02:00
|
|
|
public:
|
2024-01-12 16:55:36 +02:00
|
|
|
explicit GlobalLobbyClient();
|
2023-12-27 19:07:49 +02:00
|
|
|
~GlobalLobbyClient();
|
2023-11-12 15:32:54 +02:00
|
|
|
|
2024-01-21 16:48:36 +02:00
|
|
|
const std::vector<GlobalLobbyAccount> & getActiveAccounts() const;
|
|
|
|
const std::vector<GlobalLobbyRoom> & getActiveRooms() const;
|
2024-03-13 23:02:53 +02:00
|
|
|
const std::vector<std::string> & getActiveChannels() const;
|
2024-03-20 18:40:37 +02:00
|
|
|
const std::vector<GlobalLobbyRoom> & getMatchesHistory() const;
|
2024-03-13 23:02:53 +02:00
|
|
|
const std::vector<GlobalLobbyChannelMessage> & getChannelHistory(const std::string & channelType, const std::string & channelName) const;
|
2024-01-21 16:48:36 +02:00
|
|
|
|
|
|
|
/// Activate interface and pushes lobby UI as top window
|
|
|
|
void activateInterface();
|
2024-03-23 21:12:10 +02:00
|
|
|
void activateRoomInviteInterface();
|
2024-03-18 19:52:53 +02:00
|
|
|
|
2024-03-20 18:40:37 +02:00
|
|
|
void sendMatchChatMessage(const std::string & messageText);
|
2023-11-12 15:32:54 +02:00
|
|
|
void sendMessage(const JsonNode & data);
|
2024-02-09 23:02:41 +02:00
|
|
|
void sendClientRegister(const std::string & accountName);
|
|
|
|
void sendClientLogin();
|
2024-03-11 20:03:33 +02:00
|
|
|
void sendOpenRoom(const std::string & mode, int playerLimit);
|
2024-01-21 16:48:36 +02:00
|
|
|
|
2024-01-29 22:05:11 +02:00
|
|
|
void sendProxyConnectionLogin(const NetworkConnectionPtr & netConnection);
|
2024-03-18 19:52:53 +02:00
|
|
|
void resetMatchState();
|
2024-01-29 22:05:11 +02:00
|
|
|
|
2023-12-28 21:27:21 +02:00
|
|
|
void connect();
|
2024-02-10 19:02:25 +02:00
|
|
|
bool isConnected() const;
|
2024-03-25 20:23:57 +02:00
|
|
|
bool isInvitedToRoom(const std::string & gameRoomID);
|
2023-11-11 16:43:58 +02:00
|
|
|
};
|