Seamless integration of our proto address type
This commit is contained in:
@ -88,7 +88,7 @@ namespace Components
|
||||
}
|
||||
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->SetType(Game::netadrtype_t::NA_IP);
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ namespace Components
|
||||
Address(Game::netadr_t addr) : address(addr) {}
|
||||
Address(Game::netadr_t* addr) : Address(*addr) {}
|
||||
Address(const Address& obj) : address(obj.address) {};
|
||||
Address(const Proto::Network::Address& addr) { this->Deserialize(addr); };
|
||||
bool operator!=(const Address &obj) { return !(*this == obj); };
|
||||
bool operator==(const Address &obj);
|
||||
|
||||
|
@ -8,17 +8,13 @@ namespace Components
|
||||
|
||||
void Node::LoadNodes()
|
||||
{
|
||||
std::string nodes = Utils::ReadFile("players/nodes.dat");
|
||||
if (nodes.empty()) return;
|
||||
|
||||
Proto::Node::List list;
|
||||
list.ParseFromString(nodes);
|
||||
std::string nodes = Utils::ReadFile("players/nodes.dat");
|
||||
if (nodes.empty() || !list.ParseFromString(nodes)) return;
|
||||
|
||||
for (int i = 0; i < list.address_size(); ++i)
|
||||
{
|
||||
Network::Address address;
|
||||
address.Deserialize(list.address(i));
|
||||
Node::AddNode(address);
|
||||
Node::AddNode(list.address(i));
|
||||
}
|
||||
}
|
||||
void Node::StoreNodes(bool force)
|
||||
@ -31,6 +27,10 @@ namespace Components
|
||||
|
||||
Proto::Node::List list;
|
||||
|
||||
// This is obsolete when storing to file.
|
||||
// However, defining another proto message due to this would be redundant.
|
||||
//list.set_is_dedi(Dedicated::IsDedicated());
|
||||
|
||||
for (auto node : Node::Nodes)
|
||||
{
|
||||
if (node.state == Node::STATE_VALID && node.registered)
|
||||
@ -572,9 +572,7 @@ namespace Components
|
||||
|
||||
for (int i = 0; i < list.address_size(); ++i)
|
||||
{
|
||||
Network::Address addr;
|
||||
addr.Deserialize(list.address(i));
|
||||
Node::AddNode(addr);
|
||||
Node::AddNode(list.address(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -589,9 +587,7 @@ namespace Components
|
||||
|
||||
for (int i = 0; i < list.address_size(); ++i)
|
||||
{
|
||||
Network::Address addr;
|
||||
addr.Deserialize(list.address(i));
|
||||
Node::AddNode(addr);
|
||||
Node::AddNode(list.address(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user