source_cbl.sp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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.4"
  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. FCVAR_NOTIFY);
  24. // really though, does this actually matter? we're just going to skip the thing anyways
  25. int port = FindConVar("hostport").IntValue;
  26. char portString[6];
  27. IntToString(port, portString, sizeof(portString));
  28. RegAdminCmd("cbl_check_steamid", CheckCBLStatus, ADMFLAG_ROOT);
  29. BuildPath(Path_SM, g_CommunityKickLog, sizeof(g_CommunityKickLog), "logs/sourcecbl.log");
  30. }
  31. /**
  32. * Called once authorized and SourceMod is able to check the client's admin flags.
  33. */
  34. public void OnClientPostAdminCheck(int client) {
  35. if (!IsFakeClient(client) && !SkipCommunityBanListCheck(client)) {
  36. char steamid64[64];
  37. if (GetClientAuthId(client, AuthId_SteamID64, steamid64, sizeof(steamid64))) {
  38. QueryBanList(steamid64, OnSteamAuthBanStatusReceived, GetClientUserId(client));
  39. }
  40. }
  41. }
  42. /**
  43. * Check if we should skip querying the SourceCBL API if the client fulfills certain criteria.
  44. */
  45. bool SkipCommunityBanListCheck(int client) {
  46. // TODO check forward call order to see if cookie cache is available here
  47. // TODO implement cookie cache; save time of last finished query to avoid querying too much
  48. return CheckCommandAccess(client, "cbl_whitelist", ADMFLAG_ROOT);
  49. }
  50. public Action CheckCBLStatus(int client, int argc) {
  51. char steamid64[64];
  52. GetCmdArgString(steamid64, sizeof(steamid64));
  53. StripQuotes(steamid64);
  54. // TODO make sure this is a valid steamid
  55. QueryBanList(steamid64, OnCommandBanStatusReceived,
  56. client? GetClientUserId(client) : REQUESTER_CONSOLE);
  57. return Plugin_Handled;
  58. }
  59. public void OnSteamAuthBanStatusReceived(const char[] steamid64, bool bBanned, int userid) {
  60. // player in banlist, request ban
  61. int client = GetClientOfUserId(userid);
  62. if (bBanned && client) {
  63. KickClient(client,
  64. "You have been banned by SourceCBL for hacking / cheating."
  65. ... "\nVisit www.SourceCBL.com for more information.");
  66. LogToFile(g_CommunityKickLog, "Kicked \"%L\" from server.", client);
  67. }
  68. }
  69. public void OnCommandBanStatusReceived(const char[] steamid64, bool bBanned, int requester) {
  70. int client = requester == REQUESTER_CONSOLE? 0 : GetClientOfUserId(requester);
  71. if (requester == REQUESTER_CONSOLE || client) {
  72. ReplyToCommand(client, "Steam account %s CBL status: %b", steamid64, bBanned);
  73. }
  74. }