diff --git a/src/stationapi/Node.hpp b/src/stationapi/Node.hpp index 6ce98a3..1ab4703 100644 --- a/src/stationapi/Node.hpp +++ b/src/stationapi/Node.hpp @@ -10,17 +10,21 @@ #include template -class Node : public UdpManagerHandler { +class Node : public UdpManagerHandler +{ public: - explicit Node(NodeT* node, const std::string& listenAddress, uint16_t listenPort, bool bindToIp = false) - : node_{node} { + explicit Node(NodeT *node, const std::string &listenAddress, uint16_t listenPort, bool bindToIp = false) + : node_{node} + { UdpManager::Params params; params.handler = this; params.port = listenPort; - if (bindToIp) { - if (listenAddress.length() > sizeof(params.bindIpAddress)) { + if (bindToIp) + { + if (listenAddress.length() > sizeof(params.bindIpAddress)) + { throw std::runtime_error{"Invalid bind ip specified: " + listenAddress}; } @@ -32,16 +36,15 @@ public: virtual ~Node() { udpManager_->Release(); } - void Tick() { + void Tick() + { udpManager_->GiveTime(); - auto remove_iter - = std::remove_if(std::begin(clients_), std::end(clients_), [](auto& client) { - return client->GetConnection()->GetStatus() == UdpConnection::cStatusDisconnected; - }); + auto remove_iter = std::remove_if(std::begin(clients_), std::end(clients_), [](auto &client) + { return client->GetConnection()->GetStatus() == UdpConnection::cStatusDisconnected; }); if (remove_iter != std::end(clients_)) - clients_.erase(remove_iter); + clients_.erase(remove_iter, clients_.end()); OnTick(); } @@ -49,13 +52,14 @@ public: private: virtual void OnTick() = 0; - void OnConnectRequest(UdpConnection* connection) override { + void OnConnectRequest(UdpConnection *connection) override + { AddClient(std::make_unique(connection, node_)); } void AddClient(std::unique_ptr client) { clients_.push_back(std::move(client)); } std::vector> clients_; - NodeT* node_; - UdpManager* udpManager_; + NodeT *node_; + UdpManager *udpManager_; };