Skip to content

Commit

Permalink
Added a Custom Banlist Snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
DJPlaya committed Sep 28, 2017
1 parent 692a3e1 commit 0b67a5e
Show file tree
Hide file tree
Showing 4 changed files with 326 additions and 0 deletions.
4 changes: 4 additions & 0 deletions GRAB/Custom Banlist/banlist.txt.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
STEAM_0:0:57999292
STEAM_1:1:84082797
STEAM_0:1:102745531
//end
3 changes: 3 additions & 0 deletions GRAB/Custom Banlist/banned_user.cfg.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
banid 0 STEAM_0:0:57999292
banid 0 STEAM_1:1:84082797
banid 0 STEAM_0:1:102745531
162 changes: 162 additions & 0 deletions GRAB/Custom Banlist/check.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<?php
/*
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
*/

/* Version 1430123388 */


//File containing banned id's (read AND write permissions required unless $allowremote is true)
//ex. './bannedIDs.txt', './banned_user.cfg', 'http://example.com/banlist.txt'
$idlist = './banned_user.cfg';

//Allow remote list locations (disable the need for write permissions)
//Note: If you enable this you MUST end the file in atleast a newline
//character or preferrably something like //end otherwise the last
//Steam ID on the list will be ignored!
$allowremote = false; //true or false

//Ban STEAM_ID_PENDING, STEAM_ID_LAN, VALVE_ID_PENDING, VALVE_ID_LAN?
$banpending = false; //true or false

//Disable Steam ID validity checking (NOT RECOMMENDED)
//Only do this if you are getting _INVALID on ID's you're 100% sure are valid
//Note: Disabling validity checking will also force $banpending to false. If
//you want to keep STEAM_ID_PENDING for example banned with validity cheking
//disabled you will have to add it to your banlist.
$noval = false; //true or false

//Enable PHP error messages for debugging reasons, otherwise just print _ERROR on errors
$enabledebug = false; //true or false


//Don't edit below unless you know what you're doing!
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
if (!(error_reporting() & $errno)) {
return;
}

switch ($errno) {
default:
echo '_ERROR';
exit(1);
break;
}

return true;
}

if ($enabledebug == false) {
set_error_handler("myErrorHandler");
}

if (isset($_GET['id'])) {
$id = $_GET['id'];
} else {
$id = '';
}
if ($id == '') {
$id = 'empty';
}

if ($noval == false) {
if (strpos($id, '_ID_PENDING') !== false && strlen($id) < 17 || strpos($id, '_ID_LAN') !== false && strlen($id) < 13) {
if ($banpending == true) {
echo '_BAN';
exit;
} else {
echo '_OK';
exit;
}
}
if (strpos($id, 'STEAM_') === false || is_numeric(substr($id, 10)) == false || strpos(substr($id, 10), '.') !== false || strlen($id) > 24) {
echo '_INVALID';
exit;
}
}

$id = preg_replace('/^STEAM_[0-9]:/i', '', $id);

$banned = false;
if ($allowremote == false) {
$handle = @fopen($idlist, 'r+t');
if ($handle) {
fseek($handle, 0);
if (strpos(fgets($handle), "\r\n") !== false) {
$linebreak = "\r\n";
fseek($handle, -2, SEEK_END);
} else {
$linebreak = "\n";
fseek($handle, -1, SEEK_END);
}
if (strpos(fgets($handle), $linebreak) === false) {
fwrite($handle, $linebreak);
}
fseek($handle, 0);
while (($line = fgets($handle)) !== false) {
if (strpos($line, $id . $linebreak) !== false) {
$banned = true;
break;
}
}
} else {
trigger_error("Unable to open file ($idlist) for reading and writing", E_USER_ERROR);
}
fclose($handle);
} else {
$handle = @fopen($idlist, 'rt');
if ($handle) {
if (strpos(fgets($handle), "\r\n") !== false) {
$linebreak = "\r\n";
} else {
$linebreak = "\n";
}
} else {
trigger_error("Unable to open file ($idlist) for reading", E_USER_ERROR);
}
fclose($handle);
$handle = @fopen($idlist, 'rt');
if ($handle) {
while (($line = fgets($handle)) !== false) {
if (strpos($line, $id . $linebreak) !== false) {
$banned = true;
break;
}
}
} else {
trigger_error("Unable to open file ($idlist) for reading", E_USER_ERROR);
}
fclose($handle);
}

if ($banned == true) {
echo _BAN;
} else {
echo _OK;
}
exit;
?>
157 changes: 157 additions & 0 deletions GRAB/Custom Banlist/smac_custom_banlist.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#pragma semicolon 1

/* SM Includes */
#include <sourcemod>
#include <socket>
#include <smac>

/* Plugin Info */
public Plugin:myinfo =
{
name = "SMAC Custom Global Banlist",
author = SMAC_AUTHOR,
description = "Kicks players on the custom global banlist",
version = SMAC_VERSION,
url = ""
};

/* Globals */
#define CUSTOM_HOSTNAME "custom.com"
#define CUSTOM_QUERY "api/check.php?id="

enum BanType {
Ban_None = 0,
Ban_CUSTOM,
};

new Handle:g_hCvarKick = INVALID_HANDLE;
new Handle:g_hBanlist = INVALID_HANDLE;
new bool:g_bLateLoad = false;

/* Plugin Functions */
public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
{
g_bLateLoad = late;
return APLRes_Success;
}

public OnPluginStart()
{
LoadTranslations("smac.phrases");

// Convars.
g_hCvarKick = SMAC_CreateConVar("smac_custom_kick", "1", "Automatically kick players on the Custom banlist.", FCVAR_PLUGIN, true, 0.0, true, 1.0);

// Initialize.
g_hBanlist = CreateTrie();

if (g_bLateLoad)
{
decl String:sAuthID[MAX_AUTHID_LENGTH];

for (new i = 1; i <= MaxClients; i++)
{
if (IsClientAuthorized(i) && GetClientAuthId(i, AuthId_Steam2, sAuthID, sizeof(sAuthID), false))
{
OnClientAuthorized(i, sAuthID);
}
}
}

}

public OnClientAuthorized(client, const String:auth[])
{
if (IsFakeClient(client))
return;

// Workaround for universe digit change on L4D+ engines.
decl String:sAuthID[MAX_AUTHID_LENGTH];
FormatEx(sAuthID, sizeof(sAuthID), "STEAM_0:%s", auth[8]);

// Check the cache first.
new BanType:banValue = Ban_None;

if (GetTrieValue(g_hBanlist, sAuthID, banValue))
{
if (banValue == Ban_CUSTOM && GetConVarBool(g_hCvarKick) && SMAC_CheatDetected(client, Detection_Unknown, INVALID_HANDLE) == Plugin_Continue)
{
KickClient(client, "%t", "SMAC_GlobalBanned", "Custom", "www.custom.com");
}

return;
}

// Clear a large cache to prevent slowdowns. Shouldn't reach this size anyway.
if (GetTrieSize(g_hBanlist) > 50000)
ClearTrie(g_hBanlist);

// Check the banlist.
new Handle:hPack = CreateDataPack();
WritePackCell(hPack, GetClientUserId(client));
WritePackString(hPack, sAuthID);

new Handle:socket = SocketCreate(SOCKET_TCP, OnSocketError);
SocketSetArg(socket, hPack);
SocketSetOption(socket, ConcatenateCallbacks, 4096);
SocketConnect(socket, OnSocketConnected, OnSocketReceive, OnSocketDisconnected, CUSTOM_HOSTNAME, 80);
}

public OnSocketConnected(Handle:socket, any:hPack)
{
decl String:sAuthID[MAX_AUTHID_LENGTH], String:sRequest[256];
ResetPack(hPack);
ReadPackCell(hPack);
ReadPackString(hPack, sAuthID, sizeof(sAuthID));
FormatEx(sRequest, sizeof(sRequest), "GET /%s%s HTTP/1.0\r\nHost: %s\r\nConnection: close\r\n\r\n", CUSTOM_QUERY, sAuthID, CUSTOM_HOSTNAME);
SocketSend(socket, sRequest);
}

public OnSocketReceive(Handle:socket, String:data[], const size, any:hPack)
{
ResetPack(hPack);

new client = GetClientOfUserId(ReadPackCell(hPack));

if (IS_CLIENT(client))
{
decl String:sAuthID[MAX_AUTHID_LENGTH];
ReadPackString(hPack, sAuthID, sizeof(sAuthID));

if (StrContains(data, "_BAN") != -1)
{
SetTrieValue(g_hBanlist, sAuthID, Ban_CUSTOM);

if (SMAC_CheatDetected(client, Detection_Unknown, INVALID_HANDLE) == Plugin_Continue)
{
SMAC_PrintAdminNotice("%N | %s | Custom Ban", client, sAuthID);

if (GetConVarBool(g_hCvarKick))
{
SMAC_LogAction(client, "was kicked.");
KickClient(client, "%t", "SMAC_GlobalBanned", "Custom", "www.custom.com");
}
else
{
SMAC_LogAction(client, "is on the banlist.");
}
}
}
else
{
SetTrieValue(g_hBanlist, sAuthID, Ban_None);
}
}
}

public OnSocketDisconnected(Handle:socket, any:hPack)
{
CloseHandle(hPack);
CloseHandle(socket);
}

public OnSocketError(Handle:socket, const errorType, const errorNum, any:hPack)
{
CloseHandle(hPack);
CloseHandle(socket);
}

0 comments on commit 0b67a5e

Please sign in to comment.