· 8 years ago · May 20, 2018, 04:48 AM
1#include <amxmodx>
2#include <amxmisc>
3#include <sqlx>
4
5#define PLUGIN "SQL Ban"
6#define VERSION "1.0"
7#define AUTHOR "[R]ak"
8
9#define SQL_HOST "104.153.108.19"
10#define SQL_USER "comunida_bans"
11#define SQL_PASS "3181cq61."
12#define SQL_DATEBASE "comunida_bans"
13
14
15enum {
16
17 SQL_CHECK,
18 SQL_ADD,
19 SQL_REMOVE,
20 SQL_CREATETABLE,
21 SQL_DELETE
22
23}
24
25const SQL_DATA_LENG = 2
26
27new const TABLE[] = "SQL_BAN"
28
29new Handle:g_hTuple
30
31new Pointer
32
33enum _:BanType {
34
35 LocalBan,
36 GlobalBan
37
38}
39
40new Cmd_cid[BanType]
41
42new g_ServerIp[22]
43
44new szQuery[264]
45
46const TASK_HID = 2707
47
48public plugin_init() {
49
50 register_plugin(PLUGIN, VERSION, AUTHOR)
51
52 Cmd_cid[LocalBan] = register_concmd("amx_banm", "cmdamxBan", ADMIN_KICK, "<target|#userid> <time> <reason>")
53
54 Cmd_cid[GlobalBan] = register_concmd("amx_global", "cmdamxBan", ADMIN_KICK, "<target|#userid> <time> <reason>")
55
56
57 get_user_ip(0, g_ServerIp, charsmax(g_ServerIp))
58
59 Pointer = get_cvar_pointer("__sxei_output")
60
61 MySQLx_Init()
62
63}
64
65public cmdamxBan(id, level, cid) {
66
67 if (!cmd_access(id, level, cid, 3))
68 return PLUGIN_HANDLED
69
70 new Name[32]
71
72 read_argv(1, Name, charsmax(Name))
73
74 new pId = cmd_target(id, Name)
75
76 if (!pId)
77 return PLUGIN_HANDLED
78
79 new szTime[7] ,Reason[32], Time
80
81 read_argv(2, szTime, charsmax(szTime))
82
83 read_argv(3, Reason, charsmax(Reason))
84
85 remove_quotes(Reason)
86
87 Time = str_to_num(szTime)
88
89 get_user_name(pId, Name, charsmax(Name))
90
91 ban_user(id, pId, Name, Time, Reason, Cmd_cid[LocalBan] == cid ? LocalBan : GlobalBan)
92
93 return PLUGIN_HANDLED
94
95}
96
97
98public client_putinserver(id)
99set_task(2.0, "task_getHid", id+TASK_HID, .flags="a", .repeat=5)
100
101
102public task_getHid(taskid) {
103
104 taskid -= TASK_HID
105
106 new Hid[32]
107
108 get_user_hid(taskid, Hid, charsmax(Hid))
109
110 if(strlen(Hid) >= 27) {
111
112 remove_task(taskid+TASK_HID)
113
114 new Data[SQL_DATA_LENG]
115
116 formatex(szQuery, charsmax(szQuery), "SELECT * FROM %s WHERE Hid = ^"%s^";", TABLE, Hid)
117
118 Data[0] = SQL_CHECK
119
120 Data[1] = taskid
121
122 SQL_ThreadQuery(g_hTuple, "dbHandler", szQuery, Data, SQL_DATA_LENG)
123
124 }
125}
126
127ban_user(id, pId, Name[], Time, Reason[], Type) {
128
129 new Data[SQL_DATA_LENG], Hid[32], aName[32], Systime
130
131 get_user_name(id, aName, charsmax(aName))
132
133 get_user_hid(pId, Hid, charsmax(Hid))
134
135 Systime = get_systime()
136
137 formatex(szQuery, charsmax(szQuery), "INSERT INTO %s ( Admin, UserName, HID, Time, Reason, Server, BanType ) VALUES ( ^"%s^", ^"%s^", ^"%s^", ^"%d^", ^"%s^", ^"%s^", ^"%d^" );", TABLE, aName, Name, Hid, !Time ? Time : (Systime + ( Time * 60 )), Reason, g_ServerIp, Type)
138
139 Data[0] = SQL_ADD
140
141 SQL_ThreadQuery(g_hTuple, "dbHandler", szQuery, Data, SQL_DATA_LENG)
142
143 client_print(0, print_chat, "[Infinity-Gamers] El Admin %s baneo a %s por %d minutos; Motivo: %s; Hid: %s", aName, Name, Time, Reason, Hid)
144
145 console_print(0, "[Infinity-Gamers] - El Admin %s baneo a %s por %d minutos; Motivo: %s; Hid: %s", aName, Name, Time, Reason, Hid)
146
147 server_cmd("kick #%d BANNED | Tiempo: %d Min | Motivo: %s | Ingresa Comunidad-Infinity.com", get_user_userid(pId), Time, Reason)
148
149 return PLUGIN_HANDLED
150
151}
152
153public dbHandler(failstate, Handle:Query, error[], error2, data[]) {
154
155 if(failstate != TQUERY_SUCCESS && failstate != TQUERY_QUERY_FAILED)
156 log_amx("FAILSTATE=%d | ERROR=^"%s^" | ERROR2=%d", failstate, error, error2)
157
158 static sql_Do, id;
159
160 sql_Do = data[0]
161
162 switch(sql_Do) {
163
164 case SQL_CHECK: {
165
166 if(!SQL_NumResults(Query))
167 return
168
169 new Time, Systime, Reason[32], Global, Ip[22]
170
171 id = data[1]
172
173 Systime = get_systime()
174
175 while(SQL_MoreResults(Query)) {
176
177 Time = SQL_ReadResult(Query, 4)
178
179 if(Systime < Time || !Time) {
180
181 Global = SQL_ReadResult(Query, 7)
182
183 SQL_ReadResult(Query, 6, Ip, charsmax(Ip))
184
185 if(Global || equal(Ip, g_ServerIp)) {
186
187 SQL_ReadResult(Query, 5, Reason, charsmax(Reason))
188
189 new Buffer[32]
190
191 if(!Time)
192 copy(Buffer, charsmax(Buffer), "Permanente")
193 else {
194
195 if(Time - Systime <= 60)
196 formatex(Buffer, charsmax(Buffer), "1 Minuto aprox")
197 else
198 formatex(Buffer, charsmax(Buffer), "%d Minutos aprox", (Time - Systime ) / 60)
199
200
201 }
202
203
204
205 server_cmd("kick #%d BANNED | Tiempo: %s | Motivo: %s", get_user_userid(id), Buffer, Reason)
206
207 break
208
209 }
210 }
211
212 SQL_NextRow(Query)
213
214 }
215 }
216 }
217}
218
219get_user_hid(id, hid[], size) {
220
221 server_cmd("sxe_userhid #%d", get_user_userid(id))
222
223 server_exec()
224
225 get_pcvar_string(Pointer, hid, size)
226
227}
228
229CreateTable_Sql() {
230
231 new Data[SQL_DATA_LENG]
232
233 formatex(szQuery, charsmax(szQuery), "CREATE TABLE IF NOT EXISTS %s ( Admin varchar(32) NOT NULL, UserName varchar(32) NOT NULL, HID varchar(32) NOT NULL, CurTime TIMESTAMP DEFAULT NOW(), Time int(11) NOT NULL, Reason varchar(32) NOT NULL, Server varchar(32) NOT NULL, BanType int(2) NOT NULL);", TABLE)
234
235 Data[0] = SQL_CREATETABLE
236
237 SQL_ThreadQuery(g_hTuple, "dbHandler", szQuery, Data, SQL_DATA_LENG)
238
239}
240
241MySQLx_Init() {
242
243 g_hTuple = SQL_MakeDbTuple(SQL_HOST, SQL_USER, SQL_PASS, SQL_DATEBASE)
244
245 if(!g_hTuple)
246 return pause("a")
247
248 CreateTable_Sql()
249
250 return 1
251}
252
253public plugin_end()
254SQL_FreeHandle(g_hTuple)