-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGiveRoles.sp
146 lines (125 loc) · 3.83 KB
/
GiveRoles.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <sourcemod>
#include <smlib>
#include <discord_utilities>
#include <multicolors>
#pragma newdecls required
#pragma semicolon 1
public Plugin myinfo =
{
name = "Give Roles",
author = "Nano",
description = "Automatically give roles on discord when players join, or link their accounts, or claim their roles",
version = "1.2",
url = "https://steamcommunity.com/id/nano2k06/"
};
char g_sPath[PLATFORM_MAX_PATH];
/*-------------------------
-----Purpose: Forwards-----
-------------------------*/
public void OnPluginStart()
{
HookEvent("player_connect_full", Event_PlayerConnect);
BuildPath(Path_SM, g_sPath, sizeof(g_sPath), "configs/GiveRoles.cfg");
if(!FileExists(g_sPath))
{
SetFailState("Could not find config: \"%s\"", g_sPath);
return;
}
}
public void Event_PlayerConnect(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
if (!client || !IsValidClient(client))
{
return;
}
HandleRoles(client);
}
/*-------------------------
------Purpose: Voids-------
--------------------------*/
void HandleRoles(int client)
{
char sFlags[30], sTempFlag[32], sRolesGroupID[256], sRoleID[32];
int iFlagCount;
KeyValues g_sKeyValues = CreateKeyValues("GiveRoles");
g_sKeyValues.ImportFromFile(g_sPath);
if (!g_sKeyValues.GotoFirstSubKey())
return;
do
{
g_sKeyValues.GetSectionName(sRoleID, sizeof(sRoleID));
g_sKeyValues.GetString("name", sRolesGroupID, sizeof(sRolesGroupID));
g_sKeyValues.GetString("flags", sFlags, sizeof(sFlags));
iFlagCount = strlen(sFlags);
for (int x = 0; x < iFlagCount; x++)
{
Format(sTempFlag, 2, sFlags[x]);
if(StrContains("abcdefghijklmnopqrst", sTempFlag) != -1)
{
GetFlagInt(sTempFlag);
int iFlag = StringToInt(sTempFlag);
if(IsClientInGame(client) && GetUserAdmin(client).HasFlag(Admin_Root))
{
return;
}
if(IsValidClient(client))
{
if(Client_HasAdminFlags(client, iFlag))
{
DU_AddRole(client, sRoleID);
}
else
{
DU_DeleteRole(client, sRoleID);
}
}
}
}
}
while (g_sKeyValues.GotoNextKey());
delete g_sKeyValues;
}
/*-------------------------
------Purpose: Stocks------
-------------------------*/
stock void GetFlagInt(char sBuffer[30])
{
FlagStringToInt(sBuffer, "a", ADMFLAG_RESERVATION);
FlagStringToInt(sBuffer, "b", ADMFLAG_GENERIC);
FlagStringToInt(sBuffer, "c", ADMFLAG_KICK);
FlagStringToInt(sBuffer, "d", ADMFLAG_BAN);
FlagStringToInt(sBuffer, "e", ADMFLAG_UNBAN);
FlagStringToInt(sBuffer, "f", ADMFLAG_SLAY);
FlagStringToInt(sBuffer, "g", ADMFLAG_CHANGEMAP);
FlagStringToInt(sBuffer, "h", 128);
FlagStringToInt(sBuffer, "i", ADMFLAG_CONFIG);
FlagStringToInt(sBuffer, "j", ADMFLAG_CHAT);
FlagStringToInt(sBuffer, "k", ADMFLAG_VOTE);
FlagStringToInt(sBuffer, "l", ADMFLAG_PASSWORD);
FlagStringToInt(sBuffer, "m", ADMFLAG_RCON);
FlagStringToInt(sBuffer, "n", ADMFLAG_CHEATS);
FlagStringToInt(sBuffer, "o", ADMFLAG_CUSTOM1);
FlagStringToInt(sBuffer, "p", ADMFLAG_CUSTOM2);
FlagStringToInt(sBuffer, "q", ADMFLAG_CUSTOM3);
FlagStringToInt(sBuffer, "r", ADMFLAG_CUSTOM4);
FlagStringToInt(sBuffer, "s", ADMFLAG_CUSTOM5);
FlagStringToInt(sBuffer, "t", ADMFLAG_CUSTOM6);
}
stock void FlagStringToInt(char sStrToReplace[30], char sFlag[10], int iReplaceWith)
{
char sNewFlagValue[10];
IntToString(iReplaceWith, sNewFlagValue, sizeof(sNewFlagValue));
ReplaceString(sStrToReplace, sizeof(sStrToReplace), sFlag, sNewFlagValue, false);
}
stock bool IsValidClient(int client)
{
if((1 <= client <= MaxClients)
&& IsClientInGame(client)
&& !IsFakeClient(client)
&& DU_IsChecked(client)
&& DU_IsMember(client)
&& IsClientConnected(client))
return true;
return false;
}