2023-11-11 16:43:58 +02:00
|
|
|
/*
|
|
|
|
* NetworkServer.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
|
|
|
#include "NetworkDefines.h"
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2024-01-12 01:10:41 +02:00
|
|
|
class NetworkServer : public INetworkConnectionListener, public INetworkServer
|
2023-11-11 16:43:58 +02:00
|
|
|
{
|
2024-01-12 01:10:41 +02:00
|
|
|
std::shared_ptr<NetworkContext> io;
|
2023-11-11 16:43:58 +02:00
|
|
|
std::shared_ptr<NetworkAcceptor> acceptor;
|
2024-01-12 01:10:41 +02:00
|
|
|
std::set<std::shared_ptr<INetworkConnection>> connections;
|
2023-11-11 16:43:58 +02:00
|
|
|
|
2023-11-18 16:34:18 +02:00
|
|
|
INetworkServerListener & listener;
|
|
|
|
|
2023-11-11 16:43:58 +02:00
|
|
|
void connectionAccepted(std::shared_ptr<NetworkSocket>, const boost::system::error_code & ec);
|
2024-07-11 23:39:36 +02:00
|
|
|
uint16_t startAsyncAccept();
|
2023-11-12 13:27:22 +02:00
|
|
|
|
2024-02-02 01:27:19 +02:00
|
|
|
void onDisconnected(const std::shared_ptr<INetworkConnection> & connection, const std::string & errorMessage) override;
|
|
|
|
void onPacketReceived(const std::shared_ptr<INetworkConnection> & connection, const std::vector<std::byte> & message) override;
|
2023-11-18 16:34:18 +02:00
|
|
|
public:
|
2024-01-12 01:10:41 +02:00
|
|
|
NetworkServer(INetworkServerListener & listener, const std::shared_ptr<NetworkContext> & context);
|
2023-11-11 16:43:58 +02:00
|
|
|
|
2024-07-11 23:39:36 +02:00
|
|
|
uint16_t start(uint16_t port) override;
|
2023-11-11 16:43:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|