mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Added timer functionality to NetworkServer
Might not be related to networking strictly speaking, but useful to have functionality for network thread
This commit is contained in:
parent
d6869160c5
commit
a50cdbda0c
@ -90,6 +90,11 @@ void LobbyClient::onDisconnected(const std::shared_ptr<NetworkConnection> &)
|
||||
CInfoWindow::showInfoDialog("Connection to game lobby was lost!", {});
|
||||
}
|
||||
|
||||
void LobbyClient::onTimer()
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
|
||||
void LobbyClient::sendMessage(const JsonNode & data)
|
||||
{
|
||||
std::string payloadString = data.toJson(true);
|
||||
|
@ -36,6 +36,7 @@ class LobbyClient : public INetworkClientListener
|
||||
void onConnectionFailed(const std::string & errorMessage) override;
|
||||
void onConnectionEstablished(const std::shared_ptr<NetworkConnection> &) override;
|
||||
void onDisconnected(const std::shared_ptr<NetworkConnection> &) override;
|
||||
void onTimer() override;
|
||||
|
||||
public:
|
||||
explicit LobbyClient(LobbyWindow * window);
|
||||
|
@ -75,6 +75,15 @@ void NetworkClient::stop()
|
||||
io->stop();
|
||||
}
|
||||
|
||||
void NetworkClient::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();
|
||||
});
|
||||
}
|
||||
|
||||
void NetworkClient::sendPacket(const std::vector<uint8_t> & message)
|
||||
{
|
||||
connection->sendPacket(message);
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
NetworkClient(INetworkClientListener & listener);
|
||||
virtual ~NetworkClient() = default;
|
||||
|
||||
void setTimer(std::chrono::milliseconds duration);
|
||||
void sendPacket(const std::vector<uint8_t> & message);
|
||||
|
||||
void start(const std::string & host, uint16_t port);
|
||||
|
@ -14,8 +14,9 @@
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
using NetworkService = boost::asio::io_service;
|
||||
using NetworkSocket = boost::asio::basic_stream_socket<boost::asio::ip::tcp>;
|
||||
using NetworkAcceptor = boost::asio::basic_socket_acceptor<boost::asio::ip::tcp>;
|
||||
using NetworkSocket = boost::asio::ip::tcp::socket;
|
||||
using NetworkAcceptor = boost::asio::ip::tcp::acceptor;
|
||||
using NetworkBuffer = boost::asio::streambuf;
|
||||
using NetworkTimer = boost::asio::steady_timer;
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
@ -38,6 +38,7 @@ 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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user