Some fixes

This commit is contained in:
momo5502 2016-08-16 01:54:52 +02:00
parent 2530457eb6
commit a73380db16
7 changed files with 135 additions and 4 deletions

2
deps/mongoose vendored

@ -1 +1 @@
Subproject commit d4a8351464e9737b8108435ffb51382f21a55230 Subproject commit 2efc8598297de21d54ab52e383ed8adbb3325d3d

2
deps/protobuf vendored

@ -1 +1 @@
Subproject commit a2484208c3291ea522a891114d2821829bd09083 Subproject commit d9ccf4d0b1fdfb55bdc41f49d42f37a6c4b5302a

View File

@ -167,6 +167,15 @@ namespace Components
unsigned __int64 xuid = strtoull(steamId.data(), nullptr, 16); unsigned __int64 xuid = strtoull(steamId.data(), nullptr, 16);
unsigned int id = static_cast<unsigned int>(~0x110000100000000 & xuid); unsigned int id = static_cast<unsigned int>(~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)) if ((xuid & 0xFFFFFFFF00000000) != 0x110000100000000 || id != (Utils::Cryptography::JenkinsOneAtATime::Compute(connectData.publickey()) & ~0x80000000))
{ {
Network::Send(address, "error\nXUID doesn't match the certificate!"); Network::Send(address, "error\nXUID doesn't match the certificate!");

View File

@ -2,6 +2,95 @@
namespace Components 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) void Bans::BanClientNum(int num, std::string reason)
{ {
if (!Dvar::Var("sv_running").Get<bool>()) if (!Dvar::Var("sv_running").Get<bool>())
@ -18,9 +107,12 @@ namespace Components
Game::client_t* client = &Game::svs_clients[num]; 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() Bans::Bans()

View File

@ -3,6 +3,8 @@ namespace Components
class Bans : public Component class Bans : public Component
{ {
public: public:
typedef std::pair<SteamID, Game::netIP_t> Entry;
Bans(); Bans();
~Bans(); ~Bans();
@ -11,5 +13,20 @@ namespace Components
#endif #endif
static void BanClientNum(int num, std::string reason); static void BanClientNum(int num, std::string reason);
static bool IsBanned(Entry entry);
static void InsertBan(Entry entry);
private:
class BanList
{
public:
std::vector<SteamID> IDList;
std::vector<Game::netIP_t> IPList;
};
static std::mutex AccessMutex;
static BanList LoadBans();
}; };
} }

View File

@ -420,4 +420,14 @@ namespace Game
SV_KickClient(client, reason.data()); 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()));
}
} }

View File

@ -509,4 +509,7 @@ namespace Game
void SV_KickClient(client_t* client, const char* reason); void SV_KickClient(client_t* client, const char* reason);
void SV_KickClientError(client_t* client, std::string 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);
} }