Seamless integration of our proto address type
This commit is contained in:
parent
348b876e5e
commit
a5cca963e0
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -168,8 +168,9 @@ namespace Utils
|
||||
|
||||
if (FileExists(file))
|
||||
{
|
||||
std::ifstream stream(file, std::ios::binary);
|
||||
std::streamsize size = 0;
|
||||
std::ifstream stream(file, std::ios::binary);
|
||||
if (!stream.is_open()) return buffer;
|
||||
|
||||
stream.seekg(0, std::ios::end);
|
||||
size = stream.tellg();
|
||||
@ -180,7 +181,7 @@ namespace Utils
|
||||
buffer.clear();
|
||||
buffer.resize((uint32_t)size);
|
||||
|
||||
stream.read((char *)buffer.data(), size);
|
||||
stream.read(const_cast<char*>(buffer.data()), size);
|
||||
}
|
||||
|
||||
stream.close();
|
||||
|
Loading…
Reference in New Issue
Block a user