· 8 years ago · Jul 25, 2018, 03:54 PM
1#pragma semicolon 1
2
3#define DEBUG
4
5#define PLUGIN_AUTHOR "xFlane"
6#define PLUGIN_VERSION "1.00"
7#define PREFIX " \x04[SourceMod]\x01"
8
9#include <sourcemod>
10#include <sdktools>
11#include <cstrike>
12#include <multicolors>
13//#include <sdkhooks>
14
15#define SECONDS_IN_MINUTE 60
16
17#pragma newdecls required
18
19int g_iBanCTUnix[MAXPLAYERS + 1];
20bool g_bBanCTBool[MAXPLAYERS + 1];
21
22Database db;
23
24EngineVersion g_Game;
25
26public Plugin myinfo =
27{
28 name = "",
29 author = PLUGIN_AUTHOR,
30 description = "",
31 version = PLUGIN_VERSION,
32 url = ""
33};
34
35public void OnPluginStart()
36{
37 g_Game = GetEngineVersion();
38 if(g_Game != Engine_CSGO && g_Game != Engine_CSS)
39 {
40 SetFailState("This plugin is for CSGO/CSS only.");
41 }
42
43 /* Translations */
44 LoadTranslations("common.phrases");
45
46 /* SQL */
47 if (db == INVALID_HANDLE)
48 {
49 char error[255];
50 db = SQL_Connect("ban_ct", true, error, sizeof(error));
51
52 if (db == null)
53 {
54 PrintToServer("Could not connect [SQL]: %s", error);
55 }
56
57 SQL_TQuery(db, SQL_NoAction, "CREATE TABLE IF NOT EXISTS `ban_ct` ( `auth` varchar(32) NOT NULL, `banctunix` int(15) NOT NULL )");
58 }
59
60
61 /* ConVars */
62 RegAdminCmd("sm_banct", Command_BanCT, ADMFLAG_BAN, "Ban player from the counter-terrorist team.");
63 RegAdminCmd("sm_unbanct", Command_UnbanCT, ADMFLAG_BAN, "Unban player from the counter-terrorist team.");
64}
65
66/* Hooks, etc.. */
67
68public void OnClientPostAdminCheck(int client)
69{
70 g_bBanCTBool[client] = false;
71 g_iBanCTUnix[client] = 0;
72
73 char SteamID[32];
74 GetClientAuthId(client, AuthId_SteamID64, SteamID, sizeof(SteamID));
75
76 char aQuery[255];
77 FormatEx(aQuery, sizeof(aQuery), "SELECT banctunix from ban_ct where auth='%s'", SteamID);
78 SQL_TQuery(db, SQL_LoadPlayer, aQuery, GetClientSerial(client));
79}
80
81/* */
82
83/* Natives */
84
85public APLRes AskPluginLoad2(Handle plugin, bool late, char[] error, int err_max)
86{
87 RegPluginLibrary("Ban_CT");
88 CreateNative("IsPlayerBannedFromGuardsTeam", Native_IsPlayerBanned);
89}
90
91public int Native_IsPlayerBanned(Handle plugin, int numParams) {
92
93 int client = GetNativeCell(1);
94
95 if (client < 1 || client > MaxClients)
96 {
97 return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index (%d)", client);
98 }
99 if (!IsClientConnected(client))
100 {
101 return ThrowNativeError(SP_ERROR_NATIVE, "Client %d is not connected", client);
102 }
103
104 int currentTime = GetTime();
105 if (currentTime > g_iBanCTUnix[client])
106 {
107 g_iBanCTUnix[client] = 0;
108 g_bBanCTBool[client] = false;
109
110 char SteamID[32];
111 GetClientAuthId(client, AuthId_SteamID64, SteamID, sizeof(SteamID));
112
113 char aQuery[255];
114 FormatEx(aQuery, sizeof(aQuery), "DELETE from ban_ct where auth='%s'", SteamID);
115 SQL_TQuery(db, SQL_NoAction, aQuery);
116 }
117
118 return g_bBanCTBool[client] ? 1:0;
119}
120
121/* */
122
123/* SQL CALLBACKS */
124
125public void SQL_NoAction(Handle owner, Handle hndl, const char[] error, any data)
126{
127 if (hndl == INVALID_HANDLE)
128 {
129 PrintToServer("[BANCT] SQL ERROR: %s", error);
130 }
131}
132
133public void SQL_LoadPlayer(Handle owner, Handle hndl, const char[] error, any data)
134{
135 int client = GetClientFromSerial(data);
136
137 if(client == 0)
138 return;
139
140 if (hndl == INVALID_HANDLE)
141 {
142 PrintToServer("[BANCT DATABASE] %s", error);
143 }
144
145 else if (SQL_GetRowCount(hndl))
146 {
147 int currentTime = GetTime();
148 while (SQL_FetchRow(hndl))
149 {
150 g_iBanCTUnix[client] = SQL_FetchInt(hndl, 0);
151 if (currentTime < g_iBanCTUnix[client])
152 {
153 g_bBanCTBool[client] = true;
154 }
155 else
156 {
157 char SteamID[32];
158 GetClientAuthId(client, AuthId_SteamID64, SteamID, sizeof(SteamID));
159
160 char aQuery[255];
161 FormatEx(aQuery, sizeof(aQuery), "DELETE from ban_ct where auth='%s'", SteamID);
162 SQL_TQuery(db, SQL_NoAction, aQuery);
163 }
164 }
165 }
166
167 return;
168}
169
170/* */
171
172/* Commands */
173
174public Action Command_BanCT(int client, int args)
175{
176 if(args < 2)
177 {
178 PrintToChat(client, "%s Syntax error: /banct <target> <time (in minutes)>", PREFIX);
179 return Plugin_Handled;
180 }
181
182 char Arg1[MAX_NAME_LENGTH];
183 GetCmdArg(1, Arg1, sizeof(Arg1));
184
185 int target = FindTarget(client, Arg1, true);
186
187 if(target == -1)
188 {
189 return Plugin_Handled;
190 }
191
192 if(g_bBanCTBool[target])
193 {
194 PrintToChat(client, "%s \x02%N\x01 is already banned from the \x0Ccounter-terrorist team.", PREFIX, target);
195 return Plugin_Handled;
196 }
197
198 char Arg2[11];
199 GetCmdArg(2, Arg2, sizeof(Arg2));
200
201 int time = StringToInt(Arg2);
202
203 if(time <= 0)
204 {
205 PrintToChat(client, "%s You cant ban player for less than \x021\x01 minute.", PREFIX);
206 return Plugin_Handled;
207 }
208
209 time *= SECONDS_IN_MINUTE;
210
211 g_iBanCTUnix[target] = GetTime() + time;
212 g_bBanCTBool[target] = true;
213
214 char TimeFormat[64];
215 FormatTime(TimeFormat, sizeof(TimeFormat), "%d/%m/%y %H:%M:%S", g_iBanCTUnix[target]);
216
217 PrintToChatAll("%s \x02%N\x01 has banned \x02%N\x01 from the \x0Ccounter-terrorist team.", PREFIX, client, target);
218 PrintToChatAll("%s The ban will expire at: \x02%s\x01.", PREFIX, TimeFormat);
219
220 char SteamID[32];
221 GetClientAuthId(client, AuthId_SteamID64, SteamID, sizeof(SteamID));
222
223 char aQuery[255];
224 FormatEx(aQuery, sizeof(aQuery), "INSERT INTO ban_ct (auth,banctunix) VALUES ('%s','%i')", SteamID, g_iBanCTUnix[target]);
225 SQL_TQuery(db, SQL_NoAction, aQuery);
226
227 return Plugin_Handled;
228}
229
230public Action Command_UnbanCT(int client, int args)
231{
232 if(args < 1)
233 {
234 PrintToChat(client, "%s Syntax error: /unbanct <target>", PREFIX);
235 return Plugin_Handled;
236 }
237
238 char Arg1[MAX_NAME_LENGTH];
239 GetCmdArg(1, Arg1, sizeof(Arg1));
240
241 int target = FindTarget(client, Arg1, true);
242
243 if(target == -1)
244 {
245 return Plugin_Handled;
246 }
247
248 if(!g_bBanCTBool[target])
249 {
250 PrintToChat(client, "%s \x02%\x01 is not banned from the \x0Ccounter-terrorist team.", PREFIX, target);
251 return Plugin_Handled;
252 }
253
254 g_bBanCTBool[target] = false;
255 g_iBanCTUnix[target] = 0;
256
257 PrintToChatAll("%s \x02%N\x01 has unbanned \x02%N\x01 from the \x0Ccounter-terrorist team.", PREFIX, client, target);
258
259 char SteamID[32];
260 GetClientAuthId(client, AuthId_SteamID64, SteamID, sizeof(SteamID));
261
262 char aQuery[255];
263 FormatEx(aQuery, sizeof(aQuery), "DELETE from ban_ct where auth='%s'", SteamID);
264 SQL_TQuery(db, SQL_NoAction, aQuery);
265
266 return Plugin_Handled;
267}
268
269
270/* */