|
@@ -6,12 +6,10 @@
|
|
|
#pragma semicolon 1
|
|
|
#include <sourcemod>
|
|
|
|
|
|
-#include <steamtools>
|
|
|
-
|
|
|
#pragma newdecls required
|
|
|
-#include <newdecl-handles/smjansson>
|
|
|
+#include "source_cbl/webapi.sp"
|
|
|
|
|
|
-#define PLUGIN_VERSION "0.1.0"
|
|
|
+#define PLUGIN_VERSION "0.2.0"
|
|
|
public Plugin myinfo = {
|
|
|
name = "[CSRD] SourceCBL Integration",
|
|
|
author = "nosoop",
|
|
@@ -20,14 +18,8 @@ public Plugin myinfo = {
|
|
|
url = "https://git.csrd.science/"
|
|
|
}
|
|
|
|
|
|
+#define REQUESTER_CONSOLE -1
|
|
|
#define INVALID_USERID -1
|
|
|
-#define SOURCECBL_REQUEST_BAN_ENDPOINT "https://sourcecbl.com/api/steam/"
|
|
|
-#define SOURCECBL_API_TIMEOUT 5
|
|
|
-
|
|
|
-enum APIResponse {
|
|
|
- Response_Success = 0,
|
|
|
- Response_NotAuthorized
|
|
|
-};
|
|
|
|
|
|
char g_CommunityKickLog[PLATFORM_MAX_PATH];
|
|
|
|
|
@@ -62,7 +54,7 @@ void RequestClientBanStatus(int client) {
|
|
|
char steamid64[64];
|
|
|
|
|
|
if (GetClientAuthId(client, AuthId_SteamID64, steamid64, sizeof(steamid64))) {
|
|
|
- QueryBanList(steamid64, GetClientUserId(client));
|
|
|
+ QueryBanList(steamid64, OnSteamAuthBanStatusReceived, GetClientUserId(client));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -72,79 +64,30 @@ public Action CheckCBLStatus(int client, int argc) {
|
|
|
StripQuotes(steamid64);
|
|
|
|
|
|
// TODO make sure this is a valid steamid
|
|
|
- QueryBanList(steamid64);
|
|
|
-}
|
|
|
-
|
|
|
-void QueryBanList(const char[] steamid64, int userid = INVALID_USERID) {
|
|
|
- // we need to use the steamid64 later on down the line to verify the request even if the
|
|
|
- // player disconnects
|
|
|
- DataPack pack = new DataPack();
|
|
|
- pack.WriteCell(userid);
|
|
|
- pack.WriteString(steamid64);
|
|
|
+ QueryBanList(steamid64, OnCommandBanStatusReceived,
|
|
|
+ client? GetClientUserId(client) : REQUESTER_CONSOLE);
|
|
|
|
|
|
- HTTPRequestHandle request = Steam_CreateHTTPRequest(HTTPMethod_GET,
|
|
|
- SOURCECBL_REQUEST_BAN_ENDPOINT);
|
|
|
- Steam_SetHTTPRequestNetworkActivityTimeout(request, SOURCECBL_API_TIMEOUT);
|
|
|
- Steam_SetHTTPRequestGetOrPostParameter(request, "steamid", steamid64);
|
|
|
-
|
|
|
- Steam_SendHTTPRequest(request, OnAccountStatusReceived, pack);
|
|
|
+ return Plugin_Handled;
|
|
|
}
|
|
|
|
|
|
-public int OnAccountStatusReceived(HTTPRequestHandle request, bool bSuccess,
|
|
|
- HTTPStatusCode status, DataPack pack) {
|
|
|
- if (!bSuccess || status != HTTPStatusCode_OK) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- int maxlen = Steam_GetHTTPResponseBodySize(request);
|
|
|
- char[] buffer = new char[maxlen];
|
|
|
-
|
|
|
- Steam_GetHTTPResponseBodyData(request, buffer, maxlen);
|
|
|
- Steam_ReleaseHTTPRequest(request);
|
|
|
-
|
|
|
- // they should've just gone with outputting VDF so I could just slap that shit into a buffer and call it a day
|
|
|
- // also would've preferred SteamID3 so I wouldn't have to use strings
|
|
|
-
|
|
|
- pack.Reset();
|
|
|
- int userid = pack.ReadCell();
|
|
|
- char steamid64[64];
|
|
|
- pack.ReadString(steamid64, sizeof(steamid64));
|
|
|
- delete pack;
|
|
|
-
|
|
|
- /**
|
|
|
- * The API response (currently) has SteamID64 strings as keys for players that are banned.
|
|
|
- * It's going to be a painus in the anus if they change the API again.
|
|
|
- */
|
|
|
- JSONObject accountStatus = view_as<JSONObject>(json_load(buffer));
|
|
|
- if (accountStatus) {
|
|
|
- APIResponse apiStatus = view_as<APIResponse>(
|
|
|
- accountStatus.GetInt("response", view_as<int>(Response_Success)) );
|
|
|
-
|
|
|
- JSONObjectIterator iterator;
|
|
|
- if (apiStatus == Response_Success &&
|
|
|
- (iterator = JSONObjectIterator.From(accountStatus))) {
|
|
|
- char steamid64Key[64];
|
|
|
+public void OnSteamAuthBanStatusReceived(const char[] steamid64, bool bBanned, int userid) {
|
|
|
+ // player in banlist, request ban
|
|
|
+ if (bBanned && userid != INVALID_USERID) {
|
|
|
+ int client = GetClientOfUserId(userid);
|
|
|
+ if (client) {
|
|
|
+ KickClient(client,
|
|
|
+ "You have been banned by SourceCBL for hacking / cheating."
|
|
|
+ ... "\nVisit www.SourceCBL.com for more information.");
|
|
|
|
|
|
- do {
|
|
|
- iterator.GetKey(steamid64Key, sizeof(steamid64Key));
|
|
|
- if (StrEqual(steamid64Key, steamid64)) {
|
|
|
- // player in banlist, request ban
|
|
|
- if (userid != INVALID_USERID) {
|
|
|
- int client = GetClientOfUserId(userid);
|
|
|
- if (client) {
|
|
|
- KickClient(client,
|
|
|
- "You have been banned by SourceCBL for hacking / cheating."
|
|
|
- ... "\nVisit www.SourceCBL.com for more information.");
|
|
|
-
|
|
|
- LogToFile(g_CommunityKickLog, "Kicked \"%L\" from server.", client);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } while ((iterator.Next(accountStatus)));
|
|
|
- // iterator auto-closes
|
|
|
- } else if (apiStatus == Response_NotAuthorized) {
|
|
|
- // TODO shut down everything
|
|
|
+ LogToFile(g_CommunityKickLog, "Kicked \"%L\" from server.", client);
|
|
|
}
|
|
|
- delete accountStatus;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+public void OnCommandBanStatusReceived(const char[] steamid64, bool bBanned, int requester) {
|
|
|
+ int client = requester == REQUESTER_CONSOLE? 0 : GetClientOfUserId(requester);
|
|
|
+
|
|
|
+ if (requester == REQUESTER_CONSOLE || client) {
|
|
|
+ ReplyToCommand(client, "Steam account %s CBL status: %b", steamid64, bBanned);
|
|
|
}
|
|
|
}
|