/** * [CSRD] SourceCBL Integration * * An optimized version of the SourceCBL plugin. */ #pragma semicolon 1 #include #pragma newdecls required #include "source_cbl/webapi.sp" #define PLUGIN_VERSION "0.2.5" public Plugin myinfo = { name = "[CSRD] SourceCBL Integration", author = "nosoop", description = "Personal integration of the SourceCBL API.", version = PLUGIN_VERSION, url = "https://git.csrd.science/" } #define REQUESTER_CONSOLE -1 char g_CommunityKickLog[PLATFORM_MAX_PATH]; public void OnPluginStart() { CreateConVar("sm_scbl_enabled", "1", "Teamwork.TF convar for A2S_RULES's sake. Does absolutely nothing else, " ... "since it's always going to be enabled anyways.", FCVAR_NOTIFY); // really though, does this actually matter? we're just going to skip the thing anyways int port = FindConVar("hostport").IntValue; char portString[6]; IntToString(port, portString, sizeof(portString)); RegAdminCmd("cbl_check_steamid", CheckCBLStatus, ADMFLAG_ROOT); BuildPath(Path_SM, g_CommunityKickLog, sizeof(g_CommunityKickLog), "logs/sourcecbl.log"); } /** * Called once authorized and SourceMod is able to check the client's admin flags. */ public void OnClientPostAdminCheck(int client) { if (!IsFakeClient(client) && !SkipCommunityBanListCheck(client)) { char steamid64[64]; if (GetClientAuthId(client, AuthId_SteamID64, steamid64, sizeof(steamid64))) { QueryBanList(steamid64, OnSteamAuthBanStatusReceived, GetClientUserId(client)); } } } /** * Check if we should skip querying the SourceCBL API if the client fulfills certain criteria. */ bool SkipCommunityBanListCheck(int client) { // TODO check forward call order to see if cookie cache is available here // TODO implement cookie cache; save time of last finished query to avoid querying too much return CheckCommandAccess(client, "cbl_whitelist", ADMFLAG_ROOT); } public Action CheckCBLStatus(int client, int argc) { char steamid64[64]; GetCmdArgString(steamid64, sizeof(steamid64)); StripQuotes(steamid64); // TODO make sure this is a valid steamid QueryBanList(steamid64, OnCommandBanStatusReceived, client? GetClientUserId(client) : REQUESTER_CONSOLE); return Plugin_Handled; } public void OnSteamAuthBanStatusReceived(const char[] steamid64, bool bBanned, int userid) { // player in banlist, request ban int client = GetClientOfUserId(userid); if (bBanned && client) { KickClient(client, "You have been banned by SourceCBL for hacking / cheating.\n" ... "Visit www.SourceCBL.com for more information."); LogToFile(g_CommunityKickLog, "Kicked \"%L\" from server.", client); } } public void OnCommandBanStatusReceived(const char[] steamid64, bool bBanned, int requester) { int client = requester == REQUESTER_CONSOLE? 0 : GetClientOfUserId(requester); if (requester == REQUESTER_CONSOLE || client) { ReplyToCommand(client, "Account %s SourceCBL status: %s", steamid64, bBanned? "banned" : "not banned"); } }