[Master] Use RakNet ban system with homebrew bansystem

new-script-api
Koncord 7 years ago
parent 5fcdff843c
commit 73aa83aa03

@ -179,8 +179,13 @@ void MasterServer::Thread()
bool ret = false; bool ret = false;
auto addr = packet->systemAddress.ToString(false); auto addr = packet->systemAddress.ToString(false);
lock_guard<mutex> lock(banMutex);
if (find(banned.begin(), banned.end(), addr) != banned.end()) // check if address is banned if (find(banned.begin(), banned.end(), addr) != banned.end()) // check if address is banned
{
peer->AddToBanList(addr);
return false; return false;
}
luaStuff([&ret, &packet, &sserver, &addr](sol::state &state) { luaStuff([&ret, &packet, &sserver, &addr](sol::state &state) {
sol::protected_function func = state["OnServerAnnounce"]; sol::protected_function func = state["OnServerAnnounce"];
@ -204,15 +209,16 @@ void MasterServer::Thread()
} }
else if (pma.GetFunc() == PacketMasterAnnounce::FUNCTION_ANNOUNCE) else if (pma.GetFunc() == PacketMasterAnnounce::FUNCTION_ANNOUNCE)
{ {
cout << "Updated";
if (isServerValid(server)) if (isServerValid(server))
{ {
cout << "Updated";
iter->second = server; iter->second = server;
keepAliveFunc(); keepAliveFunc();
} }
else else
{ {
cout << "Update rejected";
servers.erase(iter); servers.erase(iter);
pendingACKs[packet->guid] = steady_clock::now(); pendingACKs[packet->guid] = steady_clock::now();
} }
@ -225,12 +231,14 @@ void MasterServer::Thread()
} }
else if (pma.GetFunc() == PacketMasterAnnounce::FUNCTION_ANNOUNCE) else if (pma.GetFunc() == PacketMasterAnnounce::FUNCTION_ANNOUNCE)
{ {
cout << "Added";
if (isServerValid(server)) if (isServerValid(server))
{ {
cout << "Added";
iter = servers.insert({packet->systemAddress, server}).first; iter = servers.insert({packet->systemAddress, server}).first;
keepAliveFunc(); keepAliveFunc();
} }
else
cout << "Adding rejected";
} }
else else
{ {
@ -308,12 +316,18 @@ void MasterServer::luaStuff(std::function<void(sol::state &)> f)
void MasterServer::ban(const std::string &addr) void MasterServer::ban(const std::string &addr)
{ {
lock_guard<mutex> lock(banMutex);
banned.push_back(addr); banned.push_back(addr);
} }
void MasterServer::unban(const std::string &addr) void MasterServer::unban(const std::string &addr)
{ {
lock_guard<mutex> lock(banMutex);
auto it = find(banned.begin(), banned.end(), addr); auto it = find(banned.begin(), banned.end(), addr);
if (it != banned.end()) if (it != banned.end())
{
banned.erase(it); banned.erase(it);
if(peer)
peer->RemoveFromBanList(addr.c_str());
}
} }

@ -49,6 +49,7 @@ private:
std::map<RakNet::RakNetGUID, std::chrono::steady_clock::time_point> pendingACKs; std::map<RakNet::RakNetGUID, std::chrono::steady_clock::time_point> pendingACKs;
sol::state state; sol::state state;
std::mutex luaMutex; std::mutex luaMutex;
std::mutex banMutex;
std::vector<std::string> banned; // does not save on restart std::vector<std::string> banned; // does not save on restart
}; };

Loading…
Cancel
Save