#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <sockets>
#include <nvault>
#define PLUGIN "VACBanned.com Checker"
#define AUTHOR "_or_75"
#define VERSION "0.2"
#define VAC_HOST "vacbanned.com"
#define VAC_GET "GET /view/detail/id/%s HTTP/1.1^r^nHost: %s^r^n^r^n"
#define VAULT "vacbanstatus"
#define VAC_MESSAGE "Vac banned from secure server."
// Квары
new g_pAutoCheck; // Включить\Выключить авто проверку
new g_pCheckType; // Когда проверять игрока [0 - при коннекте на сервер, 1 - при заходе игрока за команду]
new g_pPunishType; // Тип наказания [0 - в лог файл, 1 - кик, 2 - кик и бан по steamid, 3 - кик и бан по ip]
new g_pBanTime; // Время бана если VAC статус - забанен [0 - на всегда, 1+ - время в минутах]
new g_pSleepPunish; // Задержка перед наказанием после появления сообщения
new g_pExpireDays; // Через сколько дней удаляться VAC баны
// Глобальные переменные
new g_Socket[33]; // Хендл сокета
new g_Vault; // Хендл nvault
new g_PlayerBot[33]; // 1 если игрок бот
new g_JoinedTeam[33]; // 1 если игрок зашел за команду (T или CT)
new g_SteamID[33][35]; // Стим ИД
new g_FriendID[33][65]; // Steam community ID#
enum // Наказания
{
LOG_ONLY,
KICK_ONLY,
KICK_BAN_ID,
KICK_BAN_IP
}
enum // Значения в базе данных
{
NO_DB_ENTRY,
NOT_BANNED,
BANNED
}
// Константы для функций set_task
#define TASKID_GETANSWER 0
#define TASKID_CLOSECONNECTION 1
#define TASKID_PUNISHPLAYER 2
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
g_pAutoCheck = register_cvar( "vac_autocheck" , "1" );
g_pCheckType = register_cvar( "vac_checktype" , "1" );
g_pPunishType = register_cvar( "vac_punishtype" , "1" );
g_pBanTime = register_cvar( "vac_bantime" , "60" );
g_pSleepPunish = register_cvar( "vac_sleepban" , "10" );
g_pExpireDays = register_cvar( "vac_expiredays" , "7" );
register_event( "TeamInfo" , "PlayerJoinedTeam" , "a" , "2=TERRORIST" , "2=CT" );
}
public plugin_cfg()
{
new ConfigDir[64];
get_configsdir(ConfigDir , 63 );
server_cmd( "exec %s/vacban.cfg" , ConfigDir );
server_exec();
g_Vault = nvault_open( VAULT );
if ( g_Vault == INVALID_HANDLE )
set_fail_state( "Error opening nvault" );
else
nvault_prune(g_Vault , 0 , get_systime() - ( get_pcvar_num( g_pExpireDays ) * 86400 ));
}
public plugin_end()
{
nvault_close(g_Vault);
}
public client_putinserver(id)
{
g_PlayerBot[id] = is_user_bot( id );
if ( g_PlayerBot[id] )
return PLUGIN_CONTINUE;
g_JoinedTeam[id] = 0;
g_SteamID[id][0] = 0;
g_FriendID[id][0] = 0;
get_user_authid( id , g_SteamID[id], 34 );
GetFriendID( g_SteamID[id] , g_FriendID[id] , 64 );
if ( get_pcvar_num( g_pAutoCheck ) && !get_pcvar_num( g_pCheckType ) && is_user_steam(id) )
CheckPlayerVAC(id)
return PLUGIN_CONTINUE;
}
public PlayerJoinedTeam()
{
new id = read_data(1);
if ( g_JoinedTeam[id] || g_PlayerBot[id] )
return PLUGIN_CONTINUE;
g_JoinedTeam[id] = 1;
if ( get_pcvar_num( g_pAutoCheck ) && get_pcvar_num( g_pCheckType ) && is_user_steam(id) )
CheckPlayerVAC(id)
if ( !is_user_steam(id) )
client_print(id, print_chat , "[VAC] Ошибка, для проверки нужен steam аккаунт.")
return PLUGIN_CONTINUE;
}
public client_disconnect(id)
{
if( g_PlayerBot[id] )
return PLUGIN_CONTINUE;
if ( g_Socket[id] )
socket_close(g_Socket[id]);
g_JoinedTeam[id] = 0;
return PLUGIN_CONTINUE;
}
public CheckPlayerVAC(id)
{
new BanVal = nvault_get( g_Vault , g_SteamID[id] );
if ( BanVal == NO_DB_ENTRY )
{
SendRequest( id );
client_print(id, print_chat , "[VAC] Отправка запроса на сервер.")
}
else if ( BanVal == BANNED )
{
new param_punish[2];
param_punish[0] = id;
param_punish[1] = get_pcvar_num( g_pPunishType );
client_print(id, print_chat , "[VAC] Ваш аккаунт заблокирован.")
if(get_pcvar_num( g_pCheckType ))
set_task(float( get_pcvar_num( g_pSleepPunish ) ), "PunishPlayer", TASKID_PUNISHPLAYER, param_punish, 2, "a", 1)
else
set_task(0.0, "PunishPlayer", TASKID_PUNISHPLAYER, param_punish, 2, "a", 1)
}
else if ( BanVal == NOT_BANNED )
{
client_print(id, print_chat , "[VAC] Ваш аккаунт не заблокирован.")
}
}
public SendRequest(id)
{
new error
new SendBuffer[512]
g_Socket[id] = socket_open(VAC_HOST, 80, SOCKET_TCP, error)
format(SendBuffer, 511, VAC_GET, g_FriendID[id], VAC_HOST)
socket_send(g_Socket[id], SendBuffer, 511)
new param[1];
param[0] = id;
set_task(1.0, "TaskWaitAnswer", TASKID_GETANSWER, param, 1, "a", 15)
set_task(16.0, "TaskCloseConnection", TASKID_CLOSECONNECTION, param, 1, "", 0)
}
public TaskWaitAnswer(param[1])
{
new id = param[0];
new BanVal[2];
static g_Data[1024]
if (socket_change(g_Socket[id] , 1))
{
socket_recv(g_Socket[id], g_Data, 1023)
new BanedStatus = containi(g_Data, "<strong>BANNED</strong></span>")
new NotBanedStatus = containi(g_Data, "NOT BANNED^n")
if (BanedStatus >= 0)
{
new param_punish[2];
param_punish[0] = id;
param_punish[1] = get_pcvar_num( g_pPunishType );
BanVal[0] = '0' + BANNED;
nvault_pset( g_Vault , g_SteamID[id] , BanVal );
client_print(id, print_chat , "[VAC] Ваш аккаунт заблокирован.")
if(get_pcvar_num( g_pCheckType ))
set_task(float( get_pcvar_num( g_pSleepPunish ) ), "PunishPlayer", TASKID_PUNISHPLAYER, param_punish, 2, "a", 1)
else
set_task(0.0, "PunishPlayer", TASKID_PUNISHPLAYER, param_punish, 2, "a", 1)
socket_close(g_Socket[id])
remove_task(TASKID_GETANSWER)
remove_task(TASKID_CLOSECONNECTION)
}
else if (NotBanedStatus >= 0)
{
BanVal[0] = '0' + NOT_BANNED;
nvault_pset( g_Vault , g_SteamID[id] , BanVal );
client_print(id, print_chat , "[VAC] Ваш аккаунт не заблокирован.")
socket_close(g_Socket[id])
remove_task(TASKID_GETANSWER)
remove_task(TASKID_CLOSECONNECTION)
}
}
}
public TaskCloseConnection(param[1])
{
new id = param[0];
socket_close(g_Socket[id])
}
public PunishPlayer( param[2] )
{
new id = param[0]
new PunishType = param[1]
new PlayerName[32]
switch ( PunishType )
{
case LOG_ONLY:
{
get_user_name(id, PlayerName, 31)
log_to_file("vacstatus.log", "Player %s is VAC banned. [SteamID: %s]", PlayerName, g_SteamID[id])
return PLUGIN_HANDLED;
}
case KICK_ONLY:
{
server_cmd("amx_kick ^"#%d^" ^"%s^"", get_user_userid(id), VAC_MESSAGE);
}
case KICK_BAN_ID:
{
server_cmd("amx_ban ^"#%d^" ^"%d^" ^"%s^"" , get_user_userid(id) , get_pcvar_num( g_pBanTime ), VAC_MESSAGE );
}
case KICK_BAN_IP:
{
server_cmd( "amx_banip ^"#%d^" ^"%d^" ^"%s^"" , get_user_userid(id) , get_pcvar_num( g_pBanTime ), VAC_MESSAGE );
}
}
remove_task(TASKID_PUNISHPLAYER)
return PLUGIN_HANDLED;
}
public GetFriendID(const szAuthID[],szReturn[],iRetLen)
{
static const szFriendsBaseNum[] = "76561197960265728";
new szServer[2], szSteamID[64];
new iServerPos = containi(szAuthID,":");
if(iServerPos < 0)
return 0;
strtok(szAuthID[iServerPos+1],szServer,charsmax(szServer),szSteamID,charsmax(szSteamID),':',1);
if(!is_str_num(szServer) || !is_str_num(szSteamID))
return 0;
// AuthID * 2
NumString_Add(szSteamID,szSteamID,szSteamID,charsmax(szSteamID));
// AuthID + Base Number + Server Number
NumString_Add(szSteamID,szFriendsBaseNum,szSteamID,charsmax(szSteamID));
NumString_Add(szSteamID,szServer,szSteamID,charsmax(szSteamID));
return (copy(szReturn,iRetLen,szSteamID) > 0);
}
NumString_Add(const szString1[],const szString2[],szReturn[], iRetLen)
{
new iLen1 = strlen(szString1), iLen2=strlen(szString2);
if(!iLen1 || !iLen2)
return;
static szTemp1[64];
copy(szTemp1,iLen1,szString1);
static szTemp2[64];
copy(szTemp2,iLen2,szString2);
static szTemp3[64];
new iTempNum,iCarry;
new iCharPos=0;
do
{
iTempNum = 0;
if(--iLen1 >= 0 && isdigit(szTemp1[iLen1]))
iTempNum += char_to_num(szTemp1[iLen1]);
if(--iLen2 >= 0 && isdigit(szTemp2[iLen2]))
iTempNum += char_to_num(szTemp2[iLen2]);
iTempNum += iCarry;
iTempNum -= ((iCarry = iTempNum / 10) * 10);
szTemp3[iCharPos++] = num_to_char(iTempNum);
}
while(iLen1 >= 0 || iLen2 >= 0);
new bool:iNumStarted = false;
new iLastChar = min(iRetLen, iCharPos);
new i
if(iLastChar)
{
while(--iCharPos >= 0 && i < iLastChar)
{
if(szTemp3[iCharPos] == '0' && !iNumStarted)
continue;
else
{
iNumStarted = true;
szReturn[i++] = szTemp3[iCharPos];
}
}
}
}
num_to_char(num)
{
return ( (num < 0) || (num > 9) ) ? '^0' : '0' + num;
}
char_to_num(chr)
{
return ( (chr < '0') || (chr > '9') ) ? 0 : (chr - '0');
}
stock bool:is_user_steam(id)
{
static dp_pointer
if(dp_pointer || (dp_pointer = get_cvar_pointer("dp_r_id_provider")))
{
server_cmd("dp_clientinfo %d", id)
server_exec()
return (get_pcvar_num(dp_pointer) == 2) ? true : false
}
return false
}