source_cbl.sp 2.9 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.5"
  11. public Plugin myinfo = {
  12. name = "[CSRD] SourceCBL Integration",
  13. author = "nosoop",
  14. description = "Personal integration of the SourceCBL API.",
  15. version = PLUGIN_VERSION,
  16. url = "https://git.csrd.science/"
  17. }
  18. #define REQUESTER_CONSOLE -1
  19. char g_CommunityKickLog[PLATFORM_MAX_PATH];
  20. public void OnPluginStart() {
  21. CreateConVar("sm_scbl_enabled", "1",
  22. "Teamwork.TF convar for A2S_RULES's sake. Does absolutely nothing else, "
  23. ... "since it's always going to be enabled anyways.",
  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. /**
  33. * Called once authorized and SourceMod is able to check the client's admin flags.
  34. */
  35. public void OnClientPostAdminCheck(int client) {
  36. if (!IsFakeClient(client) && !SkipCommunityBanListCheck(client)) {
  37. char steamid64[64];
  38. if (GetClientAuthId(client, AuthId_SteamID64, steamid64, sizeof(steamid64))) {
  39. QueryBanList(steamid64, OnSteamAuthBanStatusReceived, GetClientUserId(client));
  40. }
  41. }
  42. }
  43. /**
  44. * Check if we should skip querying the SourceCBL API if the client fulfills certain criteria.
  45. */
  46. bool SkipCommunityBanListCheck(int client) {
  47. // TODO check forward call order to see if cookie cache is available here
  48. // TODO implement cookie cache; save time of last finished query to avoid querying too much
  49. return CheckCommandAccess(client, "cbl_whitelist", ADMFLAG_ROOT);
  50. }
  51. public Action CheckCBLStatus(int client, int argc) {
  52. char steamid64[64];
  53. GetCmdArgString(steamid64, sizeof(steamid64));
  54. StripQuotes(steamid64);
  55. // TODO make sure this is a valid steamid
  56. QueryBanList(steamid64, OnCommandBanStatusReceived,
  57. client? GetClientUserId(client) : REQUESTER_CONSOLE);
  58. return Plugin_Handled;
  59. }
  60. public void OnSteamAuthBanStatusReceived(const char[] steamid64, bool bBanned, int userid) {
  61. // player in banlist, request ban
  62. int client = GetClientOfUserId(userid);
  63. if (bBanned && client) {
  64. KickClient(client,
  65. "You have been banned by SourceCBL for hacking / cheating.\n"
  66. ... "Visit www.SourceCBL.com for more information.");
  67. LogToFile(g_CommunityKickLog, "Kicked \"%L\" from server.", client);
  68. }
  69. }
  70. public void OnCommandBanStatusReceived(const char[] steamid64, bool bBanned, int requester) {
  71. int client = requester == REQUESTER_CONSOLE? 0 : GetClientOfUserId(requester);
  72. if (requester == REQUESTER_CONSOLE || client) {
  73. ReplyToCommand(client, "Account %s SourceCBL status: %s", steamid64,
  74. bBanned? "banned" : "not banned");
  75. }
  76. }