source_cbl.sp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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.1"
  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. RequestClientBanStatus(client);
  38. }
  39. }
  40. bool SkipCommunityBanListCheck(int client) {
  41. // TODO check if account is whitelisted (command group / keyvalues / clientprefs cache, etc.)
  42. return CheckCommandAccess(client, "cbl_whitelist", ADMFLAG_ROOT);
  43. }
  44. void RequestClientBanStatus(int client) {
  45. char steamid64[64];
  46. if (GetClientAuthId(client, AuthId_SteamID64, steamid64, sizeof(steamid64))) {
  47. QueryBanList(steamid64, OnSteamAuthBanStatusReceived, GetClientUserId(client));
  48. }
  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. if (bBanned && userid != INVALID_USERID) {
  62. int client = GetClientOfUserId(userid);
  63. if (client) {
  64. KickClient(client,
  65. "You have been banned by SourceCBL for hacking / cheating."
  66. ... "\nVisit www.SourceCBL.com for more information.");
  67. LogToFile(g_CommunityKickLog, "Kicked \"%L\" from server.", client);
  68. }
  69. }
  70. }
  71. public void OnCommandBanStatusReceived(const char[] steamid64, bool bBanned, int requester) {
  72. int client = requester == REQUESTER_CONSOLE? 0 : GetClientOfUserId(requester);
  73. if (requester == REQUESTER_CONSOLE || client) {
  74. ReplyToCommand(client, "Steam account %s CBL status: %b", steamid64, bBanned);
  75. }
  76. }