source_cbl.sp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.2"
  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. /**
  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. if (bBanned && userid != INVALID_USERID) {
  63. int client = GetClientOfUserId(userid);
  64. if (client) {
  65. KickClient(client,
  66. "You have been banned by SourceCBL for hacking / cheating."
  67. ... "\nVisit www.SourceCBL.com for more information.");
  68. LogToFile(g_CommunityKickLog, "Kicked \"%L\" from server.", client);
  69. }
  70. }
  71. }
  72. public void OnCommandBanStatusReceived(const char[] steamid64, bool bBanned, int requester) {
  73. int client = requester == REQUESTER_CONSOLE? 0 : GetClientOfUserId(requester);
  74. if (requester == REQUESTER_CONSOLE || client) {
  75. ReplyToCommand(client, "Steam account %s CBL status: %b", steamid64, bBanned);
  76. }
  77. }