mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
Switch turn timers handling to boost asio timer
This commit is contained in:
@@ -30,6 +30,7 @@ class DLL_LINKAGE INetworkServerListener : public INetworkConnectionListener
|
||||
friend class NetworkServer;
|
||||
protected:
|
||||
virtual void onNewConnection(const std::shared_ptr<NetworkConnection> &) = 0;
|
||||
virtual void onTimer() = 0;
|
||||
|
||||
~INetworkServerListener() = default;
|
||||
};
|
||||
@@ -38,9 +39,9 @@ class DLL_LINKAGE INetworkClientListener : public INetworkConnectionListener
|
||||
{
|
||||
friend class NetworkClient;
|
||||
protected:
|
||||
virtual void onTimer() = 0;
|
||||
virtual void onConnectionFailed(const std::string & errorMessage) = 0;
|
||||
virtual void onConnectionEstablished(const std::shared_ptr<NetworkConnection> &) = 0;
|
||||
virtual void onTimer() = 0;
|
||||
|
||||
~INetworkClientListener() = default;
|
||||
};
|
||||
|
||||
@@ -80,4 +80,14 @@ void NetworkServer::onPacketReceived(const std::shared_ptr<NetworkConnection> &
|
||||
listener.onPacketReceived(connection, message);
|
||||
}
|
||||
|
||||
void NetworkServer::setTimer(std::chrono::milliseconds duration)
|
||||
{
|
||||
auto timer = std::make_shared<NetworkTimer>(*io, duration);
|
||||
timer->async_wait([this, timer](const boost::system::error_code& error){
|
||||
if (!error)
|
||||
listener.onTimer();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
||||
@@ -34,6 +34,7 @@ public:
|
||||
|
||||
void sendPacket(const std::shared_ptr<NetworkConnection> &, const std::vector<uint8_t> & message);
|
||||
void closeConnection(const std::shared_ptr<NetworkConnection> &);
|
||||
void setTimer(std::chrono::milliseconds duration);
|
||||
|
||||
void start(uint16_t port);
|
||||
void run(std::chrono::milliseconds duration);
|
||||
|
||||
Reference in New Issue
Block a user