Correct byte order for node ports
This commit is contained in:
parent
b83d85b651
commit
3746bceec4
@ -114,12 +114,12 @@ namespace Components
|
|||||||
void Network::Address::Serialize(Proto::Network::Address* protoAddress)
|
void Network::Address::Serialize(Proto::Network::Address* protoAddress)
|
||||||
{
|
{
|
||||||
protoAddress->set_ip(this->GetIP().full);
|
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)
|
void Network::Address::Deserialize(const Proto::Network::Address& protoAddress)
|
||||||
{
|
{
|
||||||
this->SetIP(protoAddress.ip());
|
this->SetIP(protoAddress.ip());
|
||||||
this->SetPort(ntohs(static_cast<uint16_t>(protoAddress.port() & 0xFFFF)));
|
this->SetPort(static_cast<uint16_t>(protoAddress.port()));
|
||||||
this->SetType(Game::netadrtype_t::NA_IP);
|
this->SetType(Game::netadrtype_t::NA_IP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,6 +143,7 @@ namespace Components
|
|||||||
Proto::Node::List list;
|
Proto::Node::List list;
|
||||||
list.set_is_dedi(Dedicated::IsDedicated());
|
list.set_is_dedi(Dedicated::IsDedicated());
|
||||||
list.set_protocol(PROTOCOL);
|
list.set_protocol(PROTOCOL);
|
||||||
|
list.set_version(NODE_VERSION);
|
||||||
|
|
||||||
for (auto node : Node::Nodes)
|
for (auto node : Node::Nodes)
|
||||||
{
|
{
|
||||||
@ -165,22 +166,13 @@ namespace Components
|
|||||||
|
|
||||||
void Node::DeleteInvalidSessions()
|
void Node::DeleteInvalidSessions()
|
||||||
{
|
{
|
||||||
std::vector<Node::ClientSession> cleanSessions;
|
for (auto i = Node::Sessions.begin(); i != Node::Sessions.end(); ++i)
|
||||||
|
|
||||||
for (auto session : Node::Sessions)
|
|
||||||
{
|
{
|
||||||
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()
|
void Node::DeleteInvalidNodes()
|
||||||
@ -692,6 +684,7 @@ namespace Components
|
|||||||
|
|
||||||
entry->isDedi = list.is_dedi();
|
entry->isDedi = list.is_dedi();
|
||||||
entry->protocol = list.protocol();
|
entry->protocol = list.protocol();
|
||||||
|
entry->version = list.version();
|
||||||
entry->state = Node::STATE_VALID;
|
entry->state = Node::STATE_VALID;
|
||||||
entry->lastTime = Game::Com_Milliseconds();
|
entry->lastTime = Game::Com_Milliseconds();
|
||||||
|
|
||||||
@ -704,6 +697,12 @@ namespace Components
|
|||||||
{
|
{
|
||||||
Network::Address _addr(list.address(i));
|
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)
|
// if (!Node::FindNode(_addr) && _addr.GetPort() >= 1024 && _addr.GetPort() - 20 < 1024)
|
||||||
// {
|
// {
|
||||||
// std::string a1 = _addr.GetString();
|
// std::string a1 = _addr.GetString();
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
#define NODE_STORE_INTERVAL 1000 * 60* 1 // Store nodes every minute
|
#define NODE_STORE_INTERVAL 1000 * 60* 1 // Store nodes every minute
|
||||||
#define SESSION_TIMEOUT 1000 * 10 // 10 seconds session timeout
|
#define SESSION_TIMEOUT 1000 * 10 // 10 seconds session timeout
|
||||||
|
|
||||||
|
#define NODE_VERSION 1
|
||||||
|
|
||||||
namespace Components
|
namespace Components
|
||||||
{
|
{
|
||||||
class Node : public Component
|
class Node : public Component
|
||||||
@ -47,6 +49,7 @@ namespace Components
|
|||||||
// This is only relevant for clients
|
// This is only relevant for clients
|
||||||
bool isDedi;
|
bool isDedi;
|
||||||
uint32_t protocol;
|
uint32_t protocol;
|
||||||
|
uint32_t version;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ClientSession
|
struct ClientSession
|
||||||
|
@ -15,4 +15,5 @@ message List
|
|||||||
bool is_dedi = 1;
|
bool is_dedi = 1;
|
||||||
repeated Network.Address address = 2;
|
repeated Network.Address address = 2;
|
||||||
uint32 protocol = 3;
|
uint32 protocol = 3;
|
||||||
|
uint32 version = 4;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user