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
|
|
|
|
|
|
|
|
class NetworkConnection;
|
|
|
|
|
2023-11-12 13:27:22 +02:00
|
|
|
class DLL_LINKAGE NetworkServer : boost::noncopyable, public INetworkConnectionListener
|
2023-11-11 16:43:58 +02:00
|
|
|
{
|
|
|
|
std::shared_ptr<NetworkService> io;
|
|
|
|
std::shared_ptr<NetworkAcceptor> acceptor;
|
|
|
|
std::set<std::shared_ptr<NetworkConnection>> connections;
|
|
|
|
|
|
|
|
void connectionAccepted(std::shared_ptr<NetworkSocket>, const boost::system::error_code & ec);
|
|
|
|
void startAsyncAccept();
|
2023-11-12 13:27:22 +02:00
|
|
|
|
|
|
|
void onDisconnected(const std::shared_ptr<NetworkConnection> & connection) override;
|
2023-11-11 16:43:58 +02:00
|
|
|
protected:
|
2023-11-12 13:27:22 +02:00
|
|
|
virtual void onNewConnection(const std::shared_ptr<NetworkConnection> &) = 0;
|
2023-11-12 21:23:42 +02:00
|
|
|
virtual void onConnectionLost(const std::shared_ptr<NetworkConnection> &) = 0;
|
2023-11-11 16:43:58 +02:00
|
|
|
|
|
|
|
void sendPacket(const std::shared_ptr<NetworkConnection> &, const std::vector<uint8_t> & message);
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~NetworkServer() = default;
|
|
|
|
|
|
|
|
void start(uint16_t port);
|
|
|
|
void run();
|
|
|
|
};
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|