[Node] Get serverlist from dedis

This commit is contained in:
momo5502 2017-05-30 20:31:00 +02:00
parent ed414da81a
commit 15aea4e0bc
7 changed files with 52 additions and 35 deletions

View File

@ -307,7 +307,7 @@ namespace Assets
{ {
std::vector<Game::MaterialTextureDef> textureList; std::vector<Game::MaterialTextureDef> textureList;
for (auto texture : textures.array_items()) for (auto& texture : textures.array_items())
{ {
if (!texture.is_array()) continue; if (!texture.is_array()) continue;
if (textureList.size() >= 0xFF) break; if (textureList.size() >= 0xFF) break;

View File

@ -14,7 +14,7 @@ namespace Components
if (nodes.empty()) return; if (nodes.empty()) return;
auto nodeList = Utils::String::Explode(nodes, '\n'); auto nodeList = Utils::String::Explode(nodes, '\n');
for (auto node : nodeList) for (auto& node : nodeList)
{ {
Utils::String::Replace(node, "\r", ""); Utils::String::Replace(node, "\r", "");
node = Utils::String::Trim(node); node = Utils::String::Trim(node);
@ -71,7 +71,7 @@ namespace Components
//list.set_is_dedi(Dedicated::IsDedicated()); //list.set_is_dedi(Dedicated::IsDedicated());
std::lock_guard<std::recursive_mutex> _(Node::NodeMutex); std::lock_guard<std::recursive_mutex> _(Node::NodeMutex);
for (auto node : Node::Nodes) for (auto& node : Node::Nodes)
{ {
if (node.state == Node::STATE_VALID && node.registered) if (node.state == Node::STATE_VALID && node.registered)
{ {
@ -114,7 +114,7 @@ namespace Components
unsigned int count = 0; unsigned int count = 0;
std::lock_guard<std::recursive_mutex> _(Node::NodeMutex); std::lock_guard<std::recursive_mutex> _(Node::NodeMutex);
for (auto node : Node::Nodes) for (auto& node : Node::Nodes)
{ {
if (node.state == Node::STATE_VALID) if (node.state == Node::STATE_VALID)
{ {
@ -416,7 +416,7 @@ namespace Components
packet.set_signature(Utils::Cryptography::ECC::SignMessage(Node::SignatureKey, challenge)); packet.set_signature(Utils::Cryptography::ECC::SignMessage(Node::SignatureKey, challenge));
std::lock_guard<std::recursive_mutex> _(Node::NodeMutex); std::lock_guard<std::recursive_mutex> _(Node::NodeMutex);
for (auto node : Node::Nodes) for (auto& node : Node::Nodes)
{ {
Network::SendCommand(node.address, "nodeDeregister", packet.SerializeAsString()); Network::SendCommand(node.address, "nodeDeregister", packet.SerializeAsString());
} }
@ -846,7 +846,7 @@ namespace Components
Logger::Print("Nodes: %d (%d)\n", Node::Nodes.size(), Node::GetValidNodeCount()); Logger::Print("Nodes: %d (%d)\n", Node::Nodes.size(), Node::GetValidNodeCount());
std::lock_guard<std::recursive_mutex> _(Node::NodeMutex); std::lock_guard<std::recursive_mutex> _(Node::NodeMutex);
for (auto node : Node::Nodes) for (auto& node : Node::Nodes)
{ {
Logger::Print("%s\t(%s)\n", node.address.getCString(), Node::GetStateName(node.state)); Logger::Print("%s\t(%s)\n", node.address.getCString(), Node::GetStateName(node.state));
} }
@ -894,6 +894,33 @@ namespace Components
Node::LoadNodeRemotePreset(); Node::LoadNodeRemotePreset();
}).detach(); }).detach();
}); });
if (Dedicated::IsEnabled())
{
Network::Handle("getServersRequest", [](Network::Address target, std::string)
{
std::string data;
{
std::lock_guard<std::recursive_mutex> _(Node::NodeMutex);
for (auto& node : Node::Nodes)
{
if (node.state == Node::STATE_VALID && node.isDedi)
{
Game::netIP_t ip = node.address.getIP();
unsigned short port = htons(node.address.getPort());
data.append(reinterpret_cast<char*>(&ip.full), 4);
data.append(reinterpret_cast<char*>(&port), 2);
data.append("\\");
}
}
data.append("EOT");
}
Network::SendCommand(target, "getServersResponse", data);
});
}
} }
Node::~Node() Node::~Node()

View File

@ -184,7 +184,7 @@ namespace Components
ServerList::RefreshContainer.sendCount = 0; ServerList::RefreshContainer.sendCount = 0;
ServerList::RefreshContainer.sentCount = 0; ServerList::RefreshContainer.sentCount = 0;
for (auto server : tempList) for (auto& server : tempList)
{ {
ServerList::InsertRequest(server.addr); ServerList::InsertRequest(server.addr);
} }
@ -255,11 +255,13 @@ namespace Components
if (list) list->clear(); if (list) list->clear();
ServerList::VisibleList.clear(); ServerList::VisibleList.clear();
ServerList::RefreshContainer.mutex.lock();
{
std::lock_guard<std::recursive_mutex> _(ServerList::RefreshContainer.mutex);
ServerList::RefreshContainer.servers.clear(); ServerList::RefreshContainer.servers.clear();
ServerList::RefreshContainer.sendCount = 0; ServerList::RefreshContainer.sendCount = 0;
ServerList::RefreshContainer.sentCount = 0; ServerList::RefreshContainer.sentCount = 0;
ServerList::RefreshContainer.mutex.unlock(); }
if (ServerList::IsOfflineList()) if (ServerList::IsOfflineList())
{ {
@ -417,7 +419,7 @@ namespace Components
auto list = ServerList::GetList(); auto list = ServerList::GetList();
if (list) if (list)
{ {
for (auto server : *list) for (auto& server : *list)
{ {
if (server.addr == container.target) if (server.addr == container.target)
{ {
@ -604,8 +606,7 @@ namespace Components
void ServerList::Frame() void ServerList::Frame()
{ {
// This is bad practice and might even cause undefined behaviour! std::lock_guard<std::recursive_mutex> _(ServerList::RefreshContainer.mutex);
if (!ServerList::RefreshContainer.mutex.try_lock()) return;
if (ServerList::RefreshContainer.awatingList) if (ServerList::RefreshContainer.awatingList)
{ {
@ -644,8 +645,6 @@ namespace Components
} }
ServerList::UpdateVisibleInfo(); ServerList::UpdateVisibleInfo();
ServerList::RefreshContainer.mutex.unlock();
} }
void ServerList::UpdateSource() void ServerList::UpdateSource()
@ -865,9 +864,10 @@ namespace Components
ServerList::FavouriteList.clear(); ServerList::FavouriteList.clear();
ServerList::VisibleList.clear(); ServerList::VisibleList.clear();
ServerList::RefreshContainer.mutex.lock(); {
std::lock_guard<std::recursive_mutex> _(ServerList::RefreshContainer.mutex);
ServerList::RefreshContainer.awatingList = false; ServerList::RefreshContainer.awatingList = false;
ServerList::RefreshContainer.servers.clear(); ServerList::RefreshContainer.servers.clear();
ServerList::RefreshContainer.mutex.unlock(); }
} }
} }

View File

@ -10,16 +10,6 @@ namespace Utils
CSV::~CSV() CSV::~CSV()
{ {
for (auto row : this->dataMap)
{
for (auto entry : row)
{
entry.clear();
}
row.clear();
}
this->dataMap.clear(); this->dataMap.clear();
} }
@ -84,7 +74,7 @@ namespace Utils
{ {
auto rows = Utils::String::Explode(buffer, '\n'); auto rows = Utils::String::Explode(buffer, '\n');
for (auto row : rows) for (auto& row : rows)
{ {
this->parseRow(row, allowComments); this->parseRow(row, allowComments);
} }

View File

@ -34,7 +34,7 @@ namespace Utils
this->refMemory.clear(); this->refMemory.clear();
for (auto data : this->pool) for (auto& data : this->pool)
{ {
Memory::Free(data); Memory::Free(data);
} }

View File

@ -92,7 +92,7 @@ namespace Utils
std::vector<Slot<T>> copiedSlots; std::vector<Slot<T>> copiedSlots;
Utils::Merge(&copiedSlots, this->slots); Utils::Merge(&copiedSlots, this->slots);
for (auto slot : copiedSlots) for (auto& slot : copiedSlots)
{ {
if (slot) if (slot)
{ {

View File

@ -435,7 +435,7 @@ namespace Utils
for (auto file : list) this->deleteFile(file); for (auto file : list) this->deleteFile(file);
this->listDirectories(".", list); this->listDirectories(".", list);
for (auto dir : list) this->deleteDirectory(dir); for (auto& dir : list) this->deleteDirectory(dir);
this->setDirectory(tempDir); this->setDirectory(tempDir);