diff --git a/src/Components/Modules/Network.cpp b/src/Components/Modules/Network.cpp index 3777fdd5..3d30eb43 100644 --- a/src/Components/Modules/Network.cpp +++ b/src/Components/Modules/Network.cpp @@ -114,12 +114,12 @@ namespace Components void Network::Address::Serialize(Proto::Network::Address* protoAddress) { protoAddress->set_ip(this->GetIP().full); - protoAddress->set_port(htons(this->GetPort()) & 0xFFFF); + protoAddress->set_port(this->GetPort() & 0xFFFF); } void Network::Address::Deserialize(const Proto::Network::Address& protoAddress) { this->SetIP(protoAddress.ip()); - this->SetPort(ntohs(static_cast(protoAddress.port() & 0xFFFF))); + this->SetPort(static_cast(protoAddress.port())); this->SetType(Game::netadrtype_t::NA_IP); } diff --git a/src/Components/Modules/Node.cpp b/src/Components/Modules/Node.cpp index f1caf99f..5eb5ef5b 100644 --- a/src/Components/Modules/Node.cpp +++ b/src/Components/Modules/Node.cpp @@ -143,6 +143,7 @@ namespace Components Proto::Node::List list; list.set_is_dedi(Dedicated::IsDedicated()); list.set_protocol(PROTOCOL); + list.set_version(NODE_VERSION); for (auto node : Node::Nodes) { @@ -165,22 +166,13 @@ namespace Components void Node::DeleteInvalidSessions() { - std::vector cleanSessions; - - for (auto session : Node::Sessions) + for (auto i = Node::Sessions.begin(); i != Node::Sessions.end(); ++i) { - if (session.lastTime > 0 && (Game::Com_Milliseconds() - session.lastTime) <= SESSION_TIMEOUT) + if (i->lastTime <= 0 || (Game::Com_Milliseconds() - i->lastTime) > SESSION_TIMEOUT) { - cleanSessions.push_back(session); + i = Node::Sessions.erase(i); } } - - if (cleanSessions.size() != Node::Sessions.size()) - { - //Node::Sessions.clear(); - //Utils::Merge(&Node::Sessions, cleanSessions); - Node::Sessions = cleanSessions; - } } void Node::DeleteInvalidNodes() @@ -692,6 +684,7 @@ namespace Components entry->isDedi = list.is_dedi(); entry->protocol = list.protocol(); + entry->version = list.version(); entry->state = Node::STATE_VALID; entry->lastTime = Game::Com_Milliseconds(); @@ -704,6 +697,12 @@ namespace Components { Network::Address _addr(list.address(i)); + // Version 0 sends port in the wrong byte order! + if (entry->version <= 0) + { + _addr.SetPort(ntohs(_addr.GetPort())); + } + // if (!Node::FindNode(_addr) && _addr.GetPort() >= 1024 && _addr.GetPort() - 20 < 1024) // { // std::string a1 = _addr.GetString(); diff --git a/src/Components/Modules/Node.hpp b/src/Components/Modules/Node.hpp index 3f80206f..71e85ff7 100644 --- a/src/Components/Modules/Node.hpp +++ b/src/Components/Modules/Node.hpp @@ -7,6 +7,8 @@ #define NODE_STORE_INTERVAL 1000 * 60* 1 // Store nodes every minute #define SESSION_TIMEOUT 1000 * 10 // 10 seconds session timeout +#define NODE_VERSION 1 + namespace Components { class Node : public Component @@ -47,6 +49,7 @@ namespace Components // This is only relevant for clients bool isDedi; uint32_t protocol; + uint32_t version; }; struct ClientSession diff --git a/src/Proto/node.proto b/src/Proto/node.proto index 9aec1395..103f616d 100644 --- a/src/Proto/node.proto +++ b/src/Proto/node.proto @@ -15,4 +15,5 @@ message List bool is_dedi = 1; repeated Network.Address address = 2; uint32 protocol = 3; + uint32 version = 4; }