Fix bad addresses.
This commit is contained in:
parent
e6158199f5
commit
8b932677f5
@ -82,6 +82,10 @@ namespace Components
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
bool Network::Address::IsValid()
|
||||||
|
{
|
||||||
|
return (this->GetType() != Game::netadrtype_t::NA_BAD);
|
||||||
|
}
|
||||||
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);
|
||||||
|
@ -6,7 +6,7 @@ namespace Components
|
|||||||
class Address
|
class Address
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Address() {};
|
Address() { this->SetType(Game::netadrtype_t::NA_BAD); };
|
||||||
Address(std::string addrString);
|
Address(std::string addrString);
|
||||||
Address(Game::netadr_t addr) : address(addr) {}
|
Address(Game::netadr_t addr) : address(addr) {}
|
||||||
Address(Game::netadr_t* addr) : Address(*addr) {}
|
Address(Game::netadr_t* addr) : Address(*addr) {}
|
||||||
@ -30,6 +30,7 @@ namespace Components
|
|||||||
|
|
||||||
bool IsLocal();
|
bool IsLocal();
|
||||||
bool IsSelf();
|
bool IsSelf();
|
||||||
|
bool IsValid();
|
||||||
|
|
||||||
void Serialize(Proto::Network::Address* protoAddress);
|
void Serialize(Proto::Network::Address* protoAddress);
|
||||||
void Deserialize(const Proto::Network::Address& protoAddress);
|
void Deserialize(const Proto::Network::Address& protoAddress);
|
||||||
|
@ -13,7 +13,10 @@ namespace Components
|
|||||||
FileSystem::File defaultNodes("default_nodes.dat");
|
FileSystem::File defaultNodes("default_nodes.dat");
|
||||||
if (!defaultNodes.Exists()) return;
|
if (!defaultNodes.Exists()) return;
|
||||||
|
|
||||||
auto nodes = Utils::Explode(defaultNodes.GetBuffer(), '\n');
|
auto buffer = defaultNodes.GetBuffer();
|
||||||
|
Utils::Replace(buffer, "\r", "");
|
||||||
|
|
||||||
|
auto nodes = Utils::Explode(buffer, '\n');
|
||||||
for (auto node : nodes)
|
for (auto node : nodes)
|
||||||
{
|
{
|
||||||
if (!node.empty())
|
if (!node.empty())
|
||||||
@ -90,9 +93,9 @@ namespace Components
|
|||||||
void Node::AddNode(Network::Address address)
|
void Node::AddNode(Network::Address address)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (address.IsSelf()) return;
|
if (!address.IsValid() || address.IsSelf()) return;
|
||||||
#else
|
#else
|
||||||
if (address.IsLocal() || address.IsSelf()) return;
|
if (!address.IsValid() || address.IsLocal() || address.IsSelf()) return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Node::NodeEntry* existingEntry = Node::FindNode(address);
|
Node::NodeEntry* existingEntry = Node::FindNode(address);
|
||||||
@ -112,6 +115,8 @@ namespace Components
|
|||||||
entry.address = address;
|
entry.address = address;
|
||||||
|
|
||||||
Node::Nodes.push_back(entry);
|
Node::Nodes.push_back(entry);
|
||||||
|
|
||||||
|
Logger::Print("Adding node %s...\n", address.GetString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user