source_cbl.sp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * [CSRD] SourceCBL Integration
  3. *
  4. * An optimized version of the SourceCBL plugin.
  5. */
  6. #pragma semicolon 1
  7. #include <sourcemod>
  8. #pragma newdecls required
  9. #include "source_cbl/webapi.sp"
  10. #define PLUGIN_VERSION "0.2.0"
  11. public Plugin myinfo = {
  12. name = "[CSRD] SourceCBL Integration",
  13. author = "nosoop",
  14. description = "Personal integartion of the SourceCBL API.",
  15. version = PLUGIN_VERSION,
  16. url = "https://git.csrd.science/"
  17. }
  18. #define REQUESTER_CONSOLE -1
  19. #define INVALID_USERID -1
  20. char g_CommunityKickLog[PLATFORM_MAX_PATH];
  21. public void OnPluginStart() {
  22. CreateConVar("sm_scbl_enabled", "1",
  23. "Teamwork.TF convar for A2S_RULES's sake. Does absolutely nothing else.",
  24. FCVAR_NOTIFY);
  25. // really though, does this actually matter? we're just going to skip the thing anyways
  26. int port = FindConVar("hostport").IntValue;
  27. char portString[6];
  28. IntToString(port, portString, sizeof(portString));
  29. RegAdminCmd("cbl_check_steamid", CheckCBLStatus, ADMFLAG_ROOT);
  30. BuildPath(Path_SM, g_CommunityKickLog, sizeof(g_CommunityKickLog), "logs/sourcecbl.log");
  31. }
  32. public void OnClientAuthorized(int client) {
  33. if (!IsFakeClient(client) && !SkipCommunityBanListCheck(client)) {
  34. RequestClientBanStatus(client);
  35. }
  36. }
  37. bool SkipCommunityBanListCheck(int client) {
  38. // TODO check if account is whitelisted (command group / keyvalues / clientprefs cache, etc.)
  39. return CheckCommandAccess(client, "cbl_whitelist", 0);
  40. }
  41. void RequestClientBanStatus(int client) {
  42. char steamid64[64];
  43. if (GetClientAuthId(client, AuthId_SteamID64, steamid64, sizeof(steamid64))) {
  44. QueryBanList(steamid64, OnSteamAuthBanStatusReceived, GetClientUserId(client));
  45. }
  46. }
  47. public Action CheckCBLStatus(int client, int argc) {
  48. char steamid64[64];
  49. GetCmdArgString(steamid64, sizeof(steamid64));
  50. StripQuotes(steamid64);
  51. // TODO make sure this is a valid steamid
  52. QueryBanList(steamid64, OnCommandBanStatusReceived,
  53. client? GetClientUserId(client) : REQUESTER_CONSOLE);
  54. return Plugin_Handled;
  55. }
  56. public void OnSteamAuthBanStatusReceived(const char[] steamid64, bool bBanned, int userid) {
  57. // player in banlist, request ban
  58. if (bBanned && userid != INVALID_USERID) {
  59. int client = GetClientOfUserId(userid);
  60. if (client) {
  61. KickClient(client,
  62. "You have been banned by SourceCBL for hacking / cheating."
  63. ... "\nVisit www.SourceCBL.com for more information.");
  64. LogToFile(g_CommunityKickLog, "Kicked \"%L\" from server.", client);
  65. }
  66. }
  67. }
  68. public void OnCommandBanStatusReceived(const char[] steamid64, bool bBanned, int requester) {
  69. int client = requester == REQUESTER_CONSOLE? 0 : GetClientOfUserId(requester);
  70. if (requester == REQUESTER_CONSOLE || client) {
  71. ReplyToCommand(client, "Steam account %s CBL status: %b", steamid64, bBanned);
  72. }
  73. }