|
|
@ -47,6 +47,11 @@ MasterServer::MasterServer(const std::string &luaScript)
|
|
|
|
state.set_function("BanAddress", [this](const string &address) {
|
|
|
|
state.set_function("BanAddress", [this](const string &address) {
|
|
|
|
this->ban(address);
|
|
|
|
this->ban(address);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
state.new_usertype<MasterServer::SServer>("Server",
|
|
|
|
|
|
|
|
"name", sol::property(&MasterServer::SServer::GetName),
|
|
|
|
|
|
|
|
"gamemode", sol::property(&MasterServer::SServer::GetGameMode),
|
|
|
|
|
|
|
|
"version", sol::property(&MasterServer::SServer::GetVersion)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
state.set_function("UnbanAddress", [this](const string &address) {
|
|
|
|
state.set_function("UnbanAddress", [this](const string &address) {
|
|
|
|
this->unban(address);
|
|
|
|
this->unban(address);
|
|
|
@ -173,6 +178,24 @@ void MasterServer::Thread()
|
|
|
|
pendingACKs[packet->guid] = steady_clock::now();
|
|
|
|
pendingACKs[packet->guid] = steady_clock::now();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto isServerValid = [&](const SServer &sserver) {
|
|
|
|
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
auto addr = packet->systemAddress.ToString(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (find(banned.begin(), banned.end(), addr) != banned.end()) // check if address is banned
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
luaStuff([&ret, &packet, &sserver, &addr](sol::state &state) {
|
|
|
|
|
|
|
|
sol::protected_function func = state["OnServerAnnounce"];
|
|
|
|
|
|
|
|
sol::protected_function_result result = func.call(addr, sserver);
|
|
|
|
|
|
|
|
if (result.valid())
|
|
|
|
|
|
|
|
ret = result.get<bool>();
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
cerr << "Error: " << result.get<string>() << endl;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (iter != servers.end())
|
|
|
|
if (iter != servers.end())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (pma.GetFunc() == PacketMasterAnnounce::FUNCTION_DELETE)
|
|
|
|
if (pma.GetFunc() == PacketMasterAnnounce::FUNCTION_DELETE)
|
|
|
@ -185,10 +208,19 @@ void MasterServer::Thread()
|
|
|
|
else if (pma.GetFunc() == PacketMasterAnnounce::FUNCTION_ANNOUNCE)
|
|
|
|
else if (pma.GetFunc() == PacketMasterAnnounce::FUNCTION_ANNOUNCE)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cout << "Updated";
|
|
|
|
cout << "Updated";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isServerValid(server))
|
|
|
|
|
|
|
|
{
|
|
|
|
iter->second = server;
|
|
|
|
iter->second = server;
|
|
|
|
keepAliveFunc();
|
|
|
|
keepAliveFunc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
servers.erase(iter);
|
|
|
|
|
|
|
|
pendingACKs[packet->guid] = steady_clock::now();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cout << "Keeping alive";
|
|
|
|
cout << "Keeping alive";
|
|
|
|
keepAliveFunc();
|
|
|
|
keepAliveFunc();
|
|
|
@ -197,9 +229,12 @@ void MasterServer::Thread()
|
|
|
|
else if (pma.GetFunc() == PacketMasterAnnounce::FUNCTION_ANNOUNCE)
|
|
|
|
else if (pma.GetFunc() == PacketMasterAnnounce::FUNCTION_ANNOUNCE)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cout << "Added";
|
|
|
|
cout << "Added";
|
|
|
|
|
|
|
|
if (isServerValid(server))
|
|
|
|
|
|
|
|
{
|
|
|
|
iter = servers.insert({packet->systemAddress, server}).first;
|
|
|
|
iter = servers.insert({packet->systemAddress, server}).first;
|
|
|
|
keepAliveFunc();
|
|
|
|
keepAliveFunc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cout << "Unknown";
|
|
|
|
cout << "Unknown";
|
|
|
|