From a73380db16c8c346f3b7eeb4a5f1d9026dc4c67a Mon Sep 17 00:00:00 2001 From: momo5502 Date: Tue, 16 Aug 2016 01:54:52 +0200 Subject: [PATCH] Some fixes --- deps/mongoose | 2 +- deps/protobuf | 2 +- src/Components/Modules/Auth.cpp | 9 ++++ src/Components/Modules/Bans.cpp | 96 ++++++++++++++++++++++++++++++++- src/Components/Modules/Bans.hpp | 17 ++++++ src/Game/Functions.cpp | 10 ++++ src/Game/Functions.hpp | 3 ++ 7 files changed, 135 insertions(+), 4 deletions(-) diff --git a/deps/mongoose b/deps/mongoose index d4a83514..2efc8598 160000 --- a/deps/mongoose +++ b/deps/mongoose @@ -1 +1 @@ -Subproject commit d4a8351464e9737b8108435ffb51382f21a55230 +Subproject commit 2efc8598297de21d54ab52e383ed8adbb3325d3d diff --git a/deps/protobuf b/deps/protobuf index a2484208..d9ccf4d0 160000 --- a/deps/protobuf +++ b/deps/protobuf @@ -1 +1 @@ -Subproject commit a2484208c3291ea522a891114d2821829bd09083 +Subproject commit d9ccf4d0b1fdfb55bdc41f49d42f37a6c4b5302a diff --git a/src/Components/Modules/Auth.cpp b/src/Components/Modules/Auth.cpp index 3bdfa0bc..853ab54e 100644 --- a/src/Components/Modules/Auth.cpp +++ b/src/Components/Modules/Auth.cpp @@ -167,6 +167,15 @@ namespace Components unsigned __int64 xuid = strtoull(steamId.data(), nullptr, 16); unsigned int id = static_cast(~0x110000100000000 & xuid); + SteamID guid; + guid.Bits = xuid; + + if (Bans::IsBanned({ guid, address.GetIP() })) + { + Network::Send(address, "error\nEXE_ERR_BANNED_PERM"); + return; + } + if ((xuid & 0xFFFFFFFF00000000) != 0x110000100000000 || id != (Utils::Cryptography::JenkinsOneAtATime::Compute(connectData.publickey()) & ~0x80000000)) { Network::Send(address, "error\nXUID doesn't match the certificate!"); diff --git a/src/Components/Modules/Bans.cpp b/src/Components/Modules/Bans.cpp index 71706fab..a0b755f5 100644 --- a/src/Components/Modules/Bans.cpp +++ b/src/Components/Modules/Bans.cpp @@ -2,6 +2,95 @@ namespace Components { + std::mutex Bans::AccessMutex; + + bool Bans::IsBanned(Bans::Entry entry) + { + auto list = Bans::LoadBans(); + + if (entry.first.Bits) + { + for (auto& idEntry : list.IDList) + { + if (idEntry.Bits == entry.first.Bits) + { + return true; + } + } + } + + if (entry.second.full) + { + for (auto& ipEntry : list.IPList) + { + if (ipEntry.full == entry.second.full) + { + return true; + } + } + } + + return false; + } + + void Bans::InsertBan(Bans::Entry entry) + { + auto list = Bans::LoadBans(); + + Bans::AccessMutex.lock(); + + if (entry.first.Bits) + { + bool found = false; + for (auto& idEntry : list.IDList) + { + if (idEntry.Bits == entry.first.Bits) + { + found = true; + break; + } + } + + if (!found) + { + list.IDList.push_back(entry.first); + } + } + + if (entry.second.full) + { + bool found = false; + for (auto& ipEntry : list.IPList) + { + if (ipEntry.full == entry.second.full) + { + found = true; + break; + } + } + + if (!found) + { + list.IPList.push_back(entry.second); + } + } + + // TODO: Write bans + + Bans::AccessMutex.unlock(); + } + + Bans::BanList Bans::LoadBans() + { + Bans::BanList list; + Bans::AccessMutex.lock(); + + // TODO: Read bans + + Bans::AccessMutex.unlock(); + return list; + } + void Bans::BanClientNum(int num, std::string reason) { if (!Dvar::Var("sv_running").Get()) @@ -18,9 +107,12 @@ namespace Components Game::client_t* client = &Game::svs_clients[num]; - // TODO: Write player info into a ban database + SteamID guid; + guid.Bits = client->steamid; - SV_KickClientError(client, reason); + Bans::InsertBan({ guid, client->addr.ip }); + + Game::SV_KickClientError(client, reason); } Bans::Bans() diff --git a/src/Components/Modules/Bans.hpp b/src/Components/Modules/Bans.hpp index a9ce51d5..737ebfa2 100644 --- a/src/Components/Modules/Bans.hpp +++ b/src/Components/Modules/Bans.hpp @@ -3,6 +3,8 @@ namespace Components class Bans : public Component { public: + typedef std::pair Entry; + Bans(); ~Bans(); @@ -11,5 +13,20 @@ namespace Components #endif static void BanClientNum(int num, std::string reason); + + static bool IsBanned(Entry entry); + static void InsertBan(Entry entry); + + private: + class BanList + { + public: + std::vector IDList; + std::vector IPList; + }; + + static std::mutex AccessMutex; + + static BanList LoadBans(); }; } diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index f8a16926..dedaf011 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -420,4 +420,14 @@ namespace Game SV_KickClient(client, reason.data()); } + + void Scr_iPrintLn(int clientNum, std::string message) + { + Game::SV_GameSendServerCommand(clientNum, 0, Utils::String::VA("%c \"%s\"", 0x66, message.data())); + } + + void Scr_iPrintLnBold(int clientNum, std::string message) + { + Game::SV_GameSendServerCommand(clientNum, 0, Utils::String::VA("%c \"%s\"", 0x67, message.data())); + } } diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 05b0b543..ef8ed7a3 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -509,4 +509,7 @@ namespace Game void SV_KickClient(client_t* client, const char* reason); void SV_KickClientError(client_t* client, std::string reason); + + void Scr_iPrintLn(int clientNum, std::string message); + void Scr_iPrintLnBold(int clientNum, std::string message); }