#include <amxmodx>
#include <amxmisc>
//#include <engine>
//#include <cstrike>
#include <sqlx>
#define HOST "" //адрес БД форума
#define USER "" //логин к БД форума
#define PASS "" //пароль от БД форума
#define DBASE "" //имя БД
#define USE_CMS 2 // 1 - ips v4.x // 2 - xenforo v2.x
#define GROUP_ID 2 // ID группы форума
new Handle:SQL_Tuple
new Handle:SQL_Connection
new MemberGroupID[33]
new fwdSetPrefix
public plugin_init()
{
register_plugin("Access for forum users", "1.2", "filip / alabamaster1337")
fwdSetPrefix = CreateMultiForward("PutPrefix", ET_IGNORE, FP_CELL)
set_task(1.0, "mysql_connection")
}
public client_putinserver(id)
{
if(is_user_admin(id) || is_user_bot(id) || is_user_hltv(id))
{
//log_amx("Player already has access")
return
}
else
{
set_task(0.3, "CheckUser", id)
}
}
public mysql_connection(id)
{
new err, error[256]
SQL_Tuple = SQL_MakeDbTuple (HOST, USER, PASS, DBASE)
SQL_Connection = SQL_Connect(SQL_Tuple, err, error, charsmax(error))
if(SQL_Connection != Empty_Handle)
{
log_amx("Connect ok")
}
else
{
log_amx("SQLX connect sql error %s ",error)
}
}
public CheckUser(id)
{
new SteamId[35], szTemp[2048]
new Data[1]
Data[0] = id
get_user_authid(id, SteamId, charsmax(SteamId))
// для ips 'field_2' - номер поля steamid // для xenforo 'steamid1337' - ид поля
#if defined USE_CMS
#if USE_CMS == 1
format(szTemp, charsmax(szTemp), "SELECT `member_group_id` FROM `core_members` WHERE `member_id` IN (SELECT `member_id` from `core_pfields_content` WHERE `field_2` = '%s')", SteamId)
#endif
#if USE_CMS == 2
format(szTemp, charsmax(szTemp), "SELECT `user_group_id` FROM `xf_user` WHERE `user_id` IN (SELECT `user_id` from `xf_user_field_value` WHERE `steamid1337` = '%s')", SteamId)
#endif
#endif
SQL_ThreadQuery (SQL_Tuple, "CheckUserHandle", szTemp, Data, 1)
}
public CheckUserHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
switch(FailState)
{
case TQUERY_CONNECT_FAILED, TQUERY_QUERY_FAILED:
{
log_amx("[SQL ERROR #%d] %s", Errcode, Error);
return;
}
}
if(SQL_NumResults(Query) > 0)
{
#if defined USE_CMS
#if USE_CMS == 1
new field = SQL_FieldNameToNum(Query, "member_group_id")
#endif
#if USE_CMS == 2
new field = SQL_FieldNameToNum(Query, "user_group_id")
#endif
#endif
MemberGroupID[Data[0]] = SQL_ReadResult(Query, field)
if(MemberGroupID[Data[0]] == GROUP_ID)
{
set_user_flags(Data[0], read_flags("z")) // флаги доступа
}
new retPr; ExecuteForward(fwdSetPrefix, retPr, Data[0])
}
else
{
MemberGroupID[Data[0]] = 0
}
SQL_FreeHandle(SQL_Tuple)
SQL_FreeHandle(SQL_Connection)
}