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
|
|
|
|
|
2023-11-18 16:34:18 +02:00
|
|
|
#include "../../lib/network/NetworkListener.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
|
|
|
|
2023-12-28 21:27:21 +02:00
|
|
|
class GlobalLobbyClient : public INetworkClientListener, boost::noncopyable
|
2023-11-11 16:43:58 +02:00
|
|
|
{
|
2023-12-28 21:27:21 +02:00
|
|
|
std::unique_ptr<boost::thread> networkThread;
|
2023-11-18 16:34:18 +02:00
|
|
|
std::unique_ptr<NetworkClient> networkClient;
|
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
|
|
|
|
2023-12-25 21:23:27 +02:00
|
|
|
void onPacketReceived(const std::shared_ptr<NetworkConnection> &, const std::vector<uint8_t> & message) override;
|
2023-11-12 13:27:22 +02:00
|
|
|
void onConnectionFailed(const std::string & errorMessage) override;
|
2023-12-25 21:23:27 +02:00
|
|
|
void onConnectionEstablished(const std::shared_ptr<NetworkConnection> &) override;
|
|
|
|
void onDisconnected(const std::shared_ptr<NetworkConnection> &) override;
|
2023-12-26 18:30:37 +02:00
|
|
|
void onTimer() override;
|
2023-11-12 15:32:54 +02:00
|
|
|
|
2023-11-11 16:43:58 +02:00
|
|
|
public:
|
2023-12-28 21:27:21 +02:00
|
|
|
explicit GlobalLobbyClient();
|
2023-12-27 19:07:49 +02:00
|
|
|
~GlobalLobbyClient();
|
2023-11-12 15:32:54 +02:00
|
|
|
|
|
|
|
void sendMessage(const JsonNode & data);
|
2023-12-28 21:27:21 +02:00
|
|
|
void connect();
|
|
|
|
bool isConnected();
|
|
|
|
std::shared_ptr<GlobalLobbyLoginWindow> createLoginWindow();
|
|
|
|
std::shared_ptr<GlobalLobbyWindow> createLobbyWindow();
|
2023-11-11 16:43:58 +02:00
|
|
|
};
|