Fix bad addresses.

This commit is contained in:
momo5502 2016-02-15 20:28:01 +01:00
parent e6158199f5
commit 8b932677f5
3 changed files with 14 additions and 4 deletions

View File

@ -82,6 +82,10 @@ namespace Components
return false;
}
bool Network::Address::IsValid()
{
return (this->GetType() != Game::netadrtype_t::NA_BAD);
}
void Network::Address::Serialize(Proto::Network::Address* protoAddress)
{
protoAddress->set_ip(this->GetIP().full);

View File

@ -6,7 +6,7 @@ namespace Components
class Address
{
public:
Address() {};
Address() { this->SetType(Game::netadrtype_t::NA_BAD); };
Address(std::string addrString);
Address(Game::netadr_t addr) : address(addr) {}
Address(Game::netadr_t* addr) : Address(*addr) {}
@ -30,6 +30,7 @@ namespace Components
bool IsLocal();
bool IsSelf();
bool IsValid();
void Serialize(Proto::Network::Address* protoAddress);
void Deserialize(const Proto::Network::Address& protoAddress);

View File

@ -13,7 +13,10 @@ namespace Components
FileSystem::File defaultNodes("default_nodes.dat");
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)
{
if (!node.empty())
@ -90,9 +93,9 @@ namespace Components
void Node::AddNode(Network::Address address)
{
#ifdef DEBUG
if (address.IsSelf()) return;
if (!address.IsValid() || address.IsSelf()) return;
#else
if (address.IsLocal() || address.IsSelf()) return;
if (!address.IsValid() || address.IsLocal() || address.IsSelf()) return;
#endif
Node::NodeEntry* existingEntry = Node::FindNode(address);
@ -112,6 +115,8 @@ namespace Components
entry.address = address;
Node::Nodes.push_back(entry);
Logger::Print("Adding node %s...\n", address.GetString());
}
}