Some node fixes

This commit is contained in:
momo5502 2016-03-14 20:44:51 +01:00
parent 666c488b50
commit 15b26bf4e7
3 changed files with 26 additions and 5 deletions

View File

@ -89,12 +89,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())); protoAddress->set_port(htons(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()))); this->SetPort(ntohs(static_cast<uint16_t>(protoAddress.port() & 0xFFFF)));
this->SetType(Game::netadrtype_t::NA_IP); this->SetType(Game::netadrtype_t::NA_IP);
} }

View File

@ -126,6 +126,7 @@ namespace Components
entry.registered = false; entry.registered = false;
entry.state = Node::STATE_UNKNOWN; entry.state = Node::STATE_UNKNOWN;
entry.address = address; entry.address = address;
entry.challenge.clear();
Node::Nodes.push_back(entry); Node::Nodes.push_back(entry);
@ -398,6 +399,17 @@ namespace Components
std::string signature = Utils::Cryptography::ECDSA::SignMessage(Node::SignatureKey, packet.challenge()); std::string signature = Utils::Cryptography::ECDSA::SignMessage(Node::SignatureKey, packet.challenge());
std::string challenge = Utils::VA("%X", Utils::Cryptography::Rand::GenerateInt()); std::string challenge = Utils::VA("%X", Utils::Cryptography::Rand::GenerateInt());
// The challenge this client sent is exactly the challenge we stored for this client
// That means this is us, so we're going to ignore us :P
if (packet.challenge() == entry->challenge)
{
entry->lastHeard = Game::Com_Milliseconds();
entry->lastTime = Game::Com_Milliseconds();
entry->registered = false;
entry->state = Node::STATE_INVALID;
return;
}
packet.Clear(); packet.Clear();
packet.set_challenge(challenge); packet.set_challenge(challenge);
packet.set_signature(signature); packet.set_signature(signature);
@ -666,7 +678,16 @@ namespace Components
for (int i = 0; i < list.address_size(); ++i) for (int i = 0; i < list.address_size(); ++i)
{ {
Node::AddNode(list.address(i)); Network::Address _addr(list.address(i));
// if (!Node::FindNode(_addr) && _addr.GetPort() >= 1024 && _addr.GetPort() - 20 < 1024)
// {
// std::string a1 = _addr.GetString();
// std::string a2 = address.GetString();
// Logger::Print("Received weird address %s from %s\n", a1.data(), a2.data());
// }
Node::AddNode(_addr);
} }
} }
} }

View File

@ -23,7 +23,7 @@ namespace Components
void QuickPatch::OnFrame(QuickPatch::Callback* callback) void QuickPatch::OnFrame(QuickPatch::Callback* callback)
{ {
if (Dedicated::IsDedicated()) if (Dedicated::IsDedicated() || ZoneBuilder::IsEnabled())
{ {
Dedicated::OnFrame(callback); Dedicated::OnFrame(callback);
} }
@ -35,7 +35,7 @@ namespace Components
void QuickPatch::Once(QuickPatch::Callback* callback) void QuickPatch::Once(QuickPatch::Callback* callback)
{ {
if (Dedicated::IsDedicated()) if (Dedicated::IsDedicated() || ZoneBuilder::IsEnabled())
{ {
Dedicated::Once(callback); Dedicated::Once(callback);
} }