forked from bklol/Misc-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nekoadmin.sp
78 lines (71 loc) · 2.2 KB
/
nekoadmin.sp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <sourcemod>
char g_szAuth[MAXPLAYERS + 1][32];
Database g_dDatabase = null;
Handle CVAR_ServerTag;
public OnPluginStart()
{
CVAR_ServerTag = CreateConVar("sm_server_tag", "xxxxx", "SERVER TAG");
AutoExecConfig(true, "nekoadmins");
SQL_MakeConnection();
}
void SQL_MakeConnection()
{
char szError[512];
g_dDatabase = SQL_Connect("crossserver", true, szError, sizeof(szError));
if (g_dDatabase == null)
{
SetFailState("Cannot connect to datbase error: %s", szError);
}
}
public void OnClientPostAdminCheck(int client)
{
if (!GetClientAuthId(client, AuthId_Steam2, g_szAuth[client], sizeof(g_szAuth)))
{
KickClient(client, "Verification problem, Please reconnect");
return;
}
SQL_FetchUser(client);
}
void SQL_FetchUser(int client)
{
char szQuery[512];
FormatEx(szQuery, sizeof(szQuery), "SELECT * FROM `admins` WHERE `authid` = '%s'",g_szAuth[client]);
g_dDatabase.Query(SQL_FetchUser_CB, szQuery, GetClientSerial(client));
}
public void SQL_FetchUser_CB(Database db, DBResultSet results, const char[] error, any data)
{
char szFlags[32],szServers[64],serverTag[32],Exptime[32];
int iClient = GetClientFromSerial(data);
GetConVarString(CVAR_ServerTag, serverTag, sizeof(serverTag));
if (results.FetchRow())
{
results.FetchString(1,szFlags,sizeof(szFlags));
results.FetchString(2,szServers,sizeof(szServers));
results.FetchString(3,Exptime,sizeof(Exptime));
int now=GetTime();
int Expt=StringToInt(Exptime)-now;
if(StrContains(szServers,serverTag)!=-1&&!StrEqual(szServers, "")||StrEqual(szServers, "all"))
{
if(Expt>0||StrEqual(Exptime, ""))
{
if (!StrEqual(szFlags, ""))
{
int iFlags = ReadFlagString(szFlags);
int iPlayerFlags = GetUserFlagBits(iClient);
bool bFlags[AdminFlags_TOTAL];
bool bPlayerFlags[AdminFlags_TOTAL];
bool bNewFlags[AdminFlags_TOTAL];
FlagBitsToBitArray(iFlags, bFlags, AdminFlags_TOTAL);
FlagBitsToBitArray(iPlayerFlags, bPlayerFlags, AdminFlags_TOTAL);
for (int i = 0; i < AdminFlags_TOTAL; i++)
{
if (bPlayerFlags[i] || bFlags[i])
bNewFlags[i] = true;
}
int iNewFlags = FlagBitArrayToBits(bNewFlags, AdminFlags_TOTAL)
SetUserFlagBits(iClient, iNewFlags);
}
}
}
}
}