Parent Directory
|
Revision Log
Revision 1 - (view) (download)
1 : | ian | 1 | /* AMX Mod X script. |
2 : | * Admin Base Plugin | ||
3 : | * | ||
4 : | * by the AMX Mod X Development Team | ||
5 : | * originally developed by OLO | ||
6 : | * | ||
7 : | * This file is part of AMX Mod X. | ||
8 : | * | ||
9 : | * | ||
10 : | * This program is free software; you can redistribute it and/or modify it | ||
11 : | * under the terms of the GNU General Public License as published by the | ||
12 : | * Free Software Foundation; either version 2 of the License, or (at | ||
13 : | * your option) any later version. | ||
14 : | * | ||
15 : | * This program is distributed in the hope that it will be useful, but | ||
16 : | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 : | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
18 : | * General Public License for more details. | ||
19 : | * | ||
20 : | * You should have received a copy of the GNU General Public License | ||
21 : | * along with this program; if not, write to the Free Software Foundation, | ||
22 : | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 : | * | ||
24 : | * In addition, as a special exception, the author gives permission to | ||
25 : | * link the code of this program with the Half-Life Game Engine ("HL | ||
26 : | * Engine") and Modified Game Libraries ("MODs") developed by Valve, | ||
27 : | * L.L.C ("Valve"). You must obey the GNU General Public License in all | ||
28 : | * respects for all of the code used other than the HL Engine and MODs | ||
29 : | * from Valve. If you modify this file, you may extend this exception | ||
30 : | * to your version of the file, but you are not obligated to do so. If | ||
31 : | * you do not wish to do so, delete this exception statement from your | ||
32 : | * version. | ||
33 : | */ | ||
34 : | |||
35 : | // Uncomment for SQL version | ||
36 : | //#define USING_SQL | ||
37 : | |||
38 : | #include <amxmodx> | ||
39 : | #include <amxmisc> | ||
40 : | #if defined USING_SQL | ||
41 : | #include <sqlx> | ||
42 : | #endif | ||
43 : | |||
44 : | #define MAX_ADMINS 64 | ||
45 : | new PLUGINNAME[] = "AMX Mod X" | ||
46 : | |||
47 : | #define ADMIN_LOOKUP (1<<0) | ||
48 : | #define ADMIN_NORMAL (1<<1) | ||
49 : | #define ADMIN_STEAM (1<<2) | ||
50 : | #define ADMIN_IPADDR (1<<3) | ||
51 : | #define ADMIN_NAME (1<<4) | ||
52 : | |||
53 : | new g_aPassword[MAX_ADMINS][32] | ||
54 : | new g_aName[MAX_ADMINS][32] | ||
55 : | new g_aFlags[MAX_ADMINS] | ||
56 : | new g_aAccess[MAX_ADMINS] | ||
57 : | new g_aNum = 0 | ||
58 : | new g_cmdLoopback[16] | ||
59 : | |||
60 : | public plugin_init() | ||
61 : | { | ||
62 : | #if defined USING_SQL | ||
63 : | register_plugin("Admin Base (SQL)", AMXX_VERSION_STR, "AMXX Dev Team") | ||
64 : | #else | ||
65 : | register_plugin("Admin Base", AMXX_VERSION_STR, "AMXX Dev Team") | ||
66 : | #endif | ||
67 : | register_dictionary("admin.txt") | ||
68 : | register_dictionary("common.txt") | ||
69 : | register_cvar("amx_mode", "1") | ||
70 : | register_cvar("amx_password_field", "_pw") | ||
71 : | register_cvar("amx_default_access", "") | ||
72 : | |||
73 : | register_cvar("amx_vote_ratio", "0.02") | ||
74 : | register_cvar("amx_vote_time", "10") | ||
75 : | register_cvar("amx_vote_answers", "1") | ||
76 : | register_cvar("amx_vote_delay", "60") | ||
77 : | register_cvar("amx_last_voting", "0") | ||
78 : | register_cvar("amx_show_activity", "2") | ||
79 : | register_cvar("amx_votekick_ratio", "0.40") | ||
80 : | register_cvar("amx_voteban_ratio", "0.40") | ||
81 : | register_cvar("amx_votemap_ratio", "0.40") | ||
82 : | |||
83 : | set_cvar_float("amx_last_voting", 0.0) | ||
84 : | |||
85 : | #if defined USING_SQL | ||
86 : | register_srvcmd("amx_sqladmins", "adminSql") | ||
87 : | register_cvar("amx_sql_table", "admins") | ||
88 : | #endif | ||
89 : | register_cvar("amx_sql_host", "127.0.0.1") | ||
90 : | register_cvar("amx_sql_user", "root") | ||
91 : | register_cvar("amx_sql_pass", "") | ||
92 : | register_cvar("amx_sql_db", "amx") | ||
93 : | register_cvar("amx_sql_type", "mysql") | ||
94 : | |||
95 : | register_concmd("amx_reloadadmins", "cmdReload", ADMIN_CFG) | ||
96 : | register_concmd("amx_addadmin", "addadminfn", ADMIN_RCON, "<playername|auth> <accessflags> [password] [authtype] - add specified player as an admin to users.ini") | ||
97 : | |||
98 : | format(g_cmdLoopback, 15, "amxauth%c%c%c%c", random_num('A', 'Z'), random_num('A', 'Z'), random_num('A', 'Z'), random_num('A', 'Z')) | ||
99 : | |||
100 : | register_clcmd(g_cmdLoopback, "ackSignal") | ||
101 : | |||
102 : | remove_user_flags(0, read_flags("z")) // Remove 'user' flag from server rights | ||
103 : | |||
104 : | new configsDir[64] | ||
105 : | get_configsdir(configsDir, 63) | ||
106 : | |||
107 : | server_cmd("exec %s/amxx.cfg", configsDir) // Execute main configuration file | ||
108 : | server_cmd("exec %s/sql.cfg", configsDir) | ||
109 : | #if defined USING_SQL | ||
110 : | server_cmd("amx_sqladmins") | ||
111 : | #else | ||
112 : | format(configsDir, 63, "%s/users.ini", configsDir) | ||
113 : | loadSettings(configsDir) // Load admins accounts | ||
114 : | #endif | ||
115 : | } | ||
116 : | |||
117 : | public addadminfn(id, level, cid) | ||
118 : | { | ||
119 : | if (!cmd_access(id, level, cid, 3)) | ||
120 : | return PLUGIN_HANDLED | ||
121 : | |||
122 : | new idtype = ADMIN_STEAM | ADMIN_LOOKUP | ||
123 : | |||
124 : | if (read_argc() >= 5) | ||
125 : | { | ||
126 : | new t_arg[16] | ||
127 : | read_argv(4, t_arg, 15) | ||
128 : | |||
129 : | if (equali(t_arg, "steam") || equali(t_arg, "steamid") || equali(t_arg, "auth")) | ||
130 : | { | ||
131 : | idtype = ADMIN_STEAM | ||
132 : | } | ||
133 : | else if (equali(t_arg, "ip")) | ||
134 : | { | ||
135 : | idtype = ADMIN_IPADDR | ||
136 : | } | ||
137 : | else if (equali(t_arg, "name") || equali(t_arg, "nick")) | ||
138 : | { | ||
139 : | idtype = ADMIN_NAME | ||
140 : | |||
141 : | if (equali(t_arg, "name")) | ||
142 : | idtype |= ADMIN_LOOKUP | ||
143 : | } else { | ||
144 : | console_print(id, "[%s] Unknown id type ^"%s^", use one of: steamid, ip, name", PLUGINNAME, t_arg) | ||
145 : | return PLUGIN_HANDLED | ||
146 : | } | ||
147 : | } | ||
148 : | |||
149 : | new arg[33] | ||
150 : | read_argv(1, arg, 32) | ||
151 : | new player = -1 | ||
152 : | |||
153 : | if (idtype & ADMIN_STEAM) | ||
154 : | { | ||
155 : | if (containi(arg, "STEAM_0:") == -1) | ||
156 : | { | ||
157 : | idtype |= ADMIN_LOOKUP | ||
158 : | player = cmd_target(id, arg, 10) | ||
159 : | } else { | ||
160 : | new _steamid[24] | ||
161 : | static _players[32], _num, _pv | ||
162 : | get_players(_players, _num) | ||
163 : | for (new _i=0; _i<_num; _i++) | ||
164 : | { | ||
165 : | _pv = _players[_i] | ||
166 : | get_user_authid(_pv, _steamid, 23) | ||
167 : | if (!_steamid[0]) | ||
168 : | continue | ||
169 : | if (equal(_steamid, arg)) | ||
170 : | { | ||
171 : | player = _pv | ||
172 : | break | ||
173 : | } | ||
174 : | } | ||
175 : | if (player < 1) | ||
176 : | { | ||
177 : | idtype &= ~ADMIN_LOOKUP | ||
178 : | } | ||
179 : | } | ||
180 : | } | ||
181 : | else if (idtype & ADMIN_NAME) | ||
182 : | { | ||
183 : | player = cmd_target(id, arg, 10) | ||
184 : | |||
185 : | if (player) | ||
186 : | idtype |= ADMIN_LOOKUP | ||
187 : | else | ||
188 : | idtype &= ~ADMIN_LOOKUP | ||
189 : | } | ||
190 : | else if (idtype & ADMIN_IPADDR) | ||
191 : | { | ||
192 : | new len = strlen(arg) | ||
193 : | new dots, chars | ||
194 : | |||
195 : | for (new i = 0; i < len; i++) | ||
196 : | { | ||
197 : | if (arg[i] == '.') | ||
198 : | { | ||
199 : | if (!chars || chars > 3) | ||
200 : | break | ||
201 : | |||
202 : | if (++dots > 3) | ||
203 : | break | ||
204 : | |||
205 : | chars = 0 | ||
206 : | } else { | ||
207 : | chars++ | ||
208 : | } | ||
209 : | |||
210 : | if (dots != 3 || !chars || chars > 3) | ||
211 : | { | ||
212 : | idtype |= ADMIN_LOOKUP | ||
213 : | player = find_player("dh", arg) | ||
214 : | } | ||
215 : | } | ||
216 : | } | ||
217 : | |||
218 : | if (idtype & ADMIN_LOOKUP && !player) | ||
219 : | { | ||
220 : | console_print(id, "%L", id, "CL_NOT_FOUND") | ||
221 : | return PLUGIN_HANDLED | ||
222 : | } | ||
223 : | |||
224 : | new flags[64] | ||
225 : | read_argv(2, flags, 63) | ||
226 : | |||
227 : | new password[64] | ||
228 : | if (read_argc() >= 4) | ||
229 : | read_argv(3, password, 63) | ||
230 : | |||
231 : | new auth[33] | ||
232 : | if (idtype & ADMIN_LOOKUP) | ||
233 : | { | ||
234 : | if (idtype & ADMIN_STEAM) | ||
235 : | { | ||
236 : | get_user_authid(player, auth, 32) | ||
237 : | } | ||
238 : | else if (idtype & ADMIN_IPADDR) | ||
239 : | { | ||
240 : | get_user_ip(player, auth, 32) | ||
241 : | } | ||
242 : | else if (idtype & ADMIN_NAME) | ||
243 : | { | ||
244 : | get_user_name(player, auth, 32) | ||
245 : | } | ||
246 : | } else { | ||
247 : | copy(auth, 32, arg) | ||
248 : | } | ||
249 : | |||
250 : | new type[16], len | ||
251 : | |||
252 : | if (idtype & ADMIN_STEAM) | ||
253 : | len += format(type[len], 15-len, "c") | ||
254 : | else if (idtype & ADMIN_IPADDR) | ||
255 : | len += format(type[len], 15-len, "d") | ||
256 : | |||
257 : | if (strlen(password) > 0) | ||
258 : | len += format(type[len], 15-len, "a") | ||
259 : | else | ||
260 : | len += format(type[len], 15-len, "e") | ||
261 : | |||
262 : | AddAdmin(id, auth, flags, password, type) | ||
263 : | cmdReload(id, ADMIN_CFG, 0) | ||
264 : | |||
265 : | if (player > 0) | ||
266 : | { | ||
267 : | new name[32] | ||
268 : | get_user_info(player, "name", name, 31) | ||
269 : | accessUser(player, name) | ||
270 : | } | ||
271 : | |||
272 : | return PLUGIN_HANDLED | ||
273 : | } | ||
274 : | |||
275 : | AddAdmin(id, auth[], accessflags[], password[], flags[]) | ||
276 : | { | ||
277 : | #if defined USING_SQL | ||
278 : | new error[128], errno | ||
279 : | |||
280 : | new Handle:info = SQL_MakeStdTuple() | ||
281 : | new Handle:sql = SQL_Connect(info, errno, error, 127) | ||
282 : | |||
283 : | if (sql == Empty_Handle) | ||
284 : | { | ||
285 : | server_print("[AMXX] %L", LANG_SERVER, "SQL_CANT_CON", error) | ||
286 : | //backup to users.ini | ||
287 : | #endif | ||
288 : | // Make sure that the users.ini file exists. | ||
289 : | new configsDir[64] | ||
290 : | get_configsdir(configsDir, 63) | ||
291 : | format(configsDir, 63, "%s/users.ini", configsDir) | ||
292 : | |||
293 : | if (!file_exists(configsDir)) | ||
294 : | { | ||
295 : | console_print(id, "[%s] File ^"%s^" doesn't exist.", PLUGINNAME, configsDir) | ||
296 : | return | ||
297 : | } | ||
298 : | |||
299 : | // Make sure steamid isn't already in file. | ||
300 : | new line = 0, textline[256], len | ||
301 : | const SIZE = 63 | ||
302 : | new line_steamid[SIZE + 1], line_password[SIZE + 1], line_accessflags[SIZE + 1], line_flags[SIZE + 1], parsedParams | ||
303 : | |||
304 : | // <name|ip|steamid> <password> <access flags> <account flags> | ||
305 : | while ((line = read_file(configsDir, line, textline, 255, len))) | ||
306 : | { | ||
307 : | if (len == 0 || equal(textline, ";", 1)) | ||
308 : | continue // comment line | ||
309 : | |||
310 : | parsedParams = parse(textline, line_steamid, SIZE, line_password, SIZE, line_accessflags, SIZE, line_flags, SIZE) | ||
311 : | |||
312 : | if (parsedParams != 4) | ||
313 : | continue // Send warning/error? | ||
314 : | |||
315 : | if (containi(line_flags, flags) != -1 && equal(line_steamid, auth)) | ||
316 : | { | ||
317 : | console_print(id, "[%s] %s already exists!", PLUGINNAME, auth) | ||
318 : | return | ||
319 : | } | ||
320 : | } | ||
321 : | |||
322 : | // If we came here, steamid doesn't exist in users.ini. Add it. | ||
323 : | new linetoadd[512] | ||
324 : | |||
325 : | formatex(linetoadd, 511, "^r^n^"%s^" ^"%s^" ^"%s^" ^"%s^"", auth, password, accessflags, flags) | ||
326 : | console_print(id, "Adding:^n%s", linetoadd) | ||
327 : | |||
328 : | if (!write_file(configsDir, linetoadd)) | ||
329 : | console_print(id, "[%s] Failed writing to %s!", PLUGINNAME, configsDir) | ||
330 : | #if defined USING_SQL | ||
331 : | } | ||
332 : | |||
333 : | new table[32] | ||
334 : | |||
335 : | get_cvar_string("amx_sql_table", table, 31) | ||
336 : | |||
337 : | new Handle:query = SQL_PrepareQuery(sql, "SELECT * FROM `%s` WHERE (`auth` = '%s')", table, auth) | ||
338 : | |||
339 : | if (!SQL_Execute(query)) | ||
340 : | { | ||
341 : | SQL_QueryError(query, error, 127) | ||
342 : | server_print("[AMXX] %L", LANG_SERVER, "SQL_CANT_LOAD_ADMINS", error) | ||
343 : | console_print(id, "[AMXX] %L", LANG_SERVER, "SQL_CANT_LOAD_ADMINS", error) | ||
344 : | } else if (SQL_NumResults(query)) { | ||
345 : | console_print(id, "[%s] %s already exists!", PLUGINNAME, auth) | ||
346 : | } else { | ||
347 : | console_print(id, "Adding to database:^n^"%s^" ^"%s^" ^"%s^" ^"%s^"", auth, password, accessflags, flags) | ||
348 : | |||
349 : | SQL_QueryAndIgnore(sql, "REPLACE INTO `%s` (`auth`, `password`, `access`, `flags`) VALUES ('%s', '%s', '%s', '%s')", table, auth, password, accessflags, flags) | ||
350 : | } | ||
351 : | |||
352 : | SQL_FreeHandle(query) | ||
353 : | SQL_FreeHandle(sql) | ||
354 : | SQL_FreeHandle(info) | ||
355 : | #endif | ||
356 : | |||
357 : | } | ||
358 : | public plugin_cfg() | ||
359 : | { | ||
360 : | new configFile[64], curMap[32] | ||
361 : | |||
362 : | get_configsdir(configFile, 31) | ||
363 : | get_mapname(curMap, 31) | ||
364 : | |||
365 : | new len = format(configFile, 63, "%s/maps/%s.cfg", configFile, curMap) | ||
366 : | |||
367 : | if (file_exists(configFile)) | ||
368 : | set_task(6.1, "delayed_load", 0, configFile, len + 1) | ||
369 : | } | ||
370 : | |||
371 : | public delayed_load(configFile[]) | ||
372 : | { | ||
373 : | server_cmd("exec %s", configFile) | ||
374 : | } | ||
375 : | |||
376 : | loadSettings(szFilename[]) | ||
377 : | { | ||
378 : | if (!file_exists(szFilename)) | ||
379 : | return 0 | ||
380 : | |||
381 : | new szText[256], szFlags[32], szAccess[32] | ||
382 : | new a, pos = 0 | ||
383 : | |||
384 : | while (g_aNum < MAX_ADMINS && read_file(szFilename, pos++, szText, 255, a)) | ||
385 : | { | ||
386 : | if (szText[0] == ';') | ||
387 : | continue | ||
388 : | |||
389 : | if (parse(szText, g_aName[g_aNum], 31, g_aPassword[g_aNum], 31, szAccess, 31, szFlags, 31) < 2) | ||
390 : | continue | ||
391 : | |||
392 : | g_aAccess[g_aNum] = read_flags(szAccess) | ||
393 : | g_aFlags[g_aNum] = read_flags(szFlags) | ||
394 : | ++g_aNum | ||
395 : | } | ||
396 : | |||
397 : | if (g_aNum == 1) | ||
398 : | server_print("[AMXX] %L", LANG_SERVER, "LOADED_ADMIN") | ||
399 : | else | ||
400 : | server_print("[AMXX] %L", LANG_SERVER, "LOADED_ADMINS", g_aNum) | ||
401 : | |||
402 : | return 1 | ||
403 : | } | ||
404 : | |||
405 : | #if defined USING_SQL | ||
406 : | public adminSql() | ||
407 : | { | ||
408 : | new table[32], error[128], type[12], errno | ||
409 : | |||
410 : | new Handle:info = SQL_MakeStdTuple() | ||
411 : | new Handle:sql = SQL_Connect(info, errno, error, 127) | ||
412 : | |||
413 : | get_cvar_string("amx_sql_table", table, 31) | ||
414 : | |||
415 : | SQL_GetAffinity(type, 11) | ||
416 : | |||
417 : | if (sql == Empty_Handle) | ||
418 : | { | ||
419 : | server_print("[AMXX] %L", LANG_SERVER, "SQL_CANT_CON", error) | ||
420 : | |||
421 : | //backup to users.ini | ||
422 : | new configsDir[64] | ||
423 : | |||
424 : | get_configsdir(configsDir, 63) | ||
425 : | format(configsDir, 63, "%s/users.ini", configsDir) | ||
426 : | loadSettings(configsDir) // Load admins accounts | ||
427 : | |||
428 : | return PLUGIN_HANDLED | ||
429 : | } | ||
430 : | |||
431 : | new Handle:query | ||
432 : | |||
433 : | if (equali(type, "sqlite")) | ||
434 : | { | ||
435 : | if (!sqlite_TableExists(sql, table)) | ||
436 : | { | ||
437 : | SQL_QueryAndIgnore(sql, "CREATE TABLE %s ( auth TEXT NOT NULL DEFAULT '', password TEXT NOT NULL DEFAULT '', access TEXT NOT NULL DEFAULT '', flags TEXT NOT NULL DEFAULT '' )", table) | ||
438 : | } | ||
439 : | |||
440 : | query = SQL_PrepareQuery(sql, "SELECT auth, password, access, flags FROM %s", table) | ||
441 : | } else { | ||
442 : | SQL_QueryAndIgnore(sql, "CREATE TABLE IF NOT EXISTS `%s` ( `auth` VARCHAR( 32 ) NOT NULL, `password` VARCHAR( 32 ) NOT NULL, `access` VARCHAR( 32 ) NOT NULL, `flags` VARCHAR( 32 ) NOT NULL ) COMMENT = 'AMX Mod X Admins'", table) | ||
443 : | query = SQL_PrepareQuery(sql,"SELECT `auth`,`password`,`access`,`flags` FROM `%s`", table) | ||
444 : | } | ||
445 : | |||
446 : | if (!SQL_Execute(query)) | ||
447 : | { | ||
448 : | SQL_QueryError(query, error, 127) | ||
449 : | server_print("[AMXX] %L", LANG_SERVER, "SQL_CANT_LOAD_ADMINS", error) | ||
450 : | } else if (!SQL_NumResults(query)) { | ||
451 : | server_print("[AMXX] %L", LANG_SERVER, "NO_ADMINS") | ||
452 : | } else { | ||
453 : | new szFlags[32], szAccess[32] | ||
454 : | |||
455 : | g_aNum = 0 | ||
456 : | |||
457 : | /** do this incase people change the query order and forget to modify below */ | ||
458 : | new qcolAuth = SQL_FieldNameToNum(query, "auth") | ||
459 : | new qcolPass = SQL_FieldNameToNum(query, "password") | ||
460 : | new qcolAccess = SQL_FieldNameToNum(query, "access") | ||
461 : | new qcolFlags = SQL_FieldNameToNum(query, "flags") | ||
462 : | |||
463 : | while ((g_aNum < MAX_ADMINS) && (SQL_MoreResults(query))) | ||
464 : | { | ||
465 : | SQL_ReadResult(query, qcolAuth, g_aName[g_aNum], 31) | ||
466 : | SQL_ReadResult(query, qcolPass, g_aPassword[g_aNum], 31) | ||
467 : | SQL_ReadResult(query, qcolAccess, szAccess, 31) | ||
468 : | SQL_ReadResult(query, qcolFlags, szFlags, 31) | ||
469 : | |||
470 : | g_aAccess[g_aNum] = read_flags(szAccess) | ||
471 : | |||
472 : | g_aFlags[g_aNum] = read_flags(szFlags) | ||
473 : | |||
474 : | ++g_aNum | ||
475 : | SQL_NextRow(query) | ||
476 : | } | ||
477 : | |||
478 : | if (g_aNum == 1) | ||
479 : | server_print("[AMXX] %L", LANG_SERVER, "SQL_LOADED_ADMIN") | ||
480 : | else | ||
481 : | server_print("[AMXX] %L", LANG_SERVER, "SQL_LOADED_ADMINS", g_aNum) | ||
482 : | |||
483 : | SQL_FreeHandle(query) | ||
484 : | SQL_FreeHandle(sql) | ||
485 : | SQL_FreeHandle(info) | ||
486 : | } | ||
487 : | |||
488 : | return PLUGIN_HANDLED | ||
489 : | } | ||
490 : | #endif | ||
491 : | |||
492 : | public cmdReload(id, level, cid) | ||
493 : | { | ||
494 : | if (!cmd_access(id, level, cid, 1)) | ||
495 : | return PLUGIN_HANDLED | ||
496 : | |||
497 : | //strip original flags (patch submitted by mrhunt) | ||
498 : | remove_user_flags(0, read_flags("z")) | ||
499 : | |||
500 : | #if !defined USING_SQL | ||
501 : | new filename[128] | ||
502 : | |||
503 : | get_configsdir(filename, 127) | ||
504 : | format(filename, 63, "%s/users.ini", filename) | ||
505 : | |||
506 : | g_aNum = 0 | ||
507 : | loadSettings(filename) // Re-Load admins accounts | ||
508 : | |||
509 : | if (id != 0) | ||
510 : | { | ||
511 : | if (g_aNum == 1) | ||
512 : | console_print(id, "[AMXX] %L", LANG_SERVER, "LOADED_ADMIN") | ||
513 : | else | ||
514 : | console_print(id, "[AMXX] %L", LANG_SERVER, "LOADED_ADMINS", g_aNum) | ||
515 : | } | ||
516 : | #else | ||
517 : | g_aNum = 0 | ||
518 : | adminSql() | ||
519 : | |||
520 : | if (id != 0) | ||
521 : | { | ||
522 : | if (g_aNum == 1) | ||
523 : | console_print(id, "[AMXX] %L", LANG_SERVER, "SQL_LOADED_ADMIN") | ||
524 : | else | ||
525 : | console_print(id, "[AMXX] %L", LANG_SERVER, "SQL_LOADED_ADMINS", g_aNum) | ||
526 : | } | ||
527 : | #endif | ||
528 : | |||
529 : | new players[32], num, pv | ||
530 : | new name[32] | ||
531 : | get_players(players, num) | ||
532 : | for (new i=0; i<num; i++) | ||
533 : | { | ||
534 : | pv = players[i] | ||
535 : | get_user_name(pv, name, 31) | ||
536 : | accessUser(pv, name) | ||
537 : | } | ||
538 : | |||
539 : | return PLUGIN_HANDLED | ||
540 : | } | ||
541 : | |||
542 : | getAccess(id, name[], authid[], ip[], password[]) | ||
543 : | { | ||
544 : | new index = -1 | ||
545 : | new result = 0 | ||
546 : | |||
547 : | for (new i = 0; i < g_aNum; ++i) | ||
548 : | { | ||
549 : | if (g_aFlags[i] & FLAG_AUTHID) | ||
550 : | { | ||
551 : | if (equal(authid, g_aName[i])) | ||
552 : | { | ||
553 : | index = i | ||
554 : | break | ||
555 : | } | ||
556 : | } | ||
557 : | else if (g_aFlags[i] & FLAG_IP) | ||
558 : | { | ||
559 : | new c = strlen(g_aName[i]) | ||
560 : | |||
561 : | if (g_aName[i][c - 1] == '.') /* check if this is not a xxx.xxx. format */ | ||
562 : | { | ||
563 : | if (equal(g_aName[i], ip, c)) | ||
564 : | { | ||
565 : | index = i | ||
566 : | break | ||
567 : | } | ||
568 : | } /* in other case an IP must just match */ | ||
569 : | else if (equal(ip, g_aName[i])) | ||
570 : | { | ||
571 : | index = i | ||
572 : | break | ||
573 : | } | ||
574 : | } else { | ||
575 : | if (g_aFlags[i] & FLAG_TAG) | ||
576 : | { | ||
577 : | if (containi(name, g_aName[i]) != -1) | ||
578 : | { | ||
579 : | index = i | ||
580 : | break | ||
581 : | } | ||
582 : | } | ||
583 : | else if (equali(name, g_aName[i])) | ||
584 : | { | ||
585 : | index = i | ||
586 : | break | ||
587 : | } | ||
588 : | } | ||
589 : | } | ||
590 : | |||
591 : | if (index != -1) | ||
592 : | { | ||
593 : | if (g_aFlags[index] & FLAG_NOPASS) | ||
594 : | { | ||
595 : | result |= 8 | ||
596 : | new sflags[32] | ||
597 : | |||
598 : | get_flags(g_aAccess[index], sflags, 31) | ||
599 : | set_user_flags(id, g_aAccess[index]) | ||
600 : | |||
601 : | log_amx("Login: ^"%s<%d><%s><>^" became an admin (account ^"%s^") (access ^"%s^") (address ^"%s^")", name, get_user_userid(id), authid, g_aName[index], sflags, ip) | ||
602 : | } | ||
603 : | else if (equal(password, g_aPassword[index])) | ||
604 : | { | ||
605 : | result |= 12 | ||
606 : | set_user_flags(id, g_aAccess[index]) | ||
607 : | |||
608 : | new sflags[32] | ||
609 : | get_flags(g_aAccess[index], sflags, 31) | ||
610 : | |||
611 : | log_amx("Login: ^"%s<%d><%s><>^" became an admin (account ^"%s^") (access ^"%s^") (address ^"%s^")", name, get_user_userid(id), authid, g_aName[index], sflags, ip) | ||
612 : | } else { | ||
613 : | result |= 1 | ||
614 : | |||
615 : | if (g_aFlags[index] & FLAG_KICK) | ||
616 : | { | ||
617 : | result |= 2 | ||
618 : | log_amx("Login: ^"%s<%d><%s><>^" kicked due to invalid password (account ^"%s^") (address ^"%s^")", name, get_user_userid(id), authid, g_aName[index], ip) | ||
619 : | } | ||
620 : | } | ||
621 : | } | ||
622 : | else if (get_cvar_float("amx_mode") == 2.0) | ||
623 : | { | ||
624 : | result |= 2 | ||
625 : | } else { | ||
626 : | new defaccess[32] | ||
627 : | |||
628 : | get_cvar_string("amx_default_access", defaccess, 31) | ||
629 : | |||
630 : | if (!strlen(defaccess)) | ||
631 : | copy(defaccess, 32, "z") | ||
632 : | |||
633 : | new idefaccess = read_flags(defaccess) | ||
634 : | |||
635 : | if (idefaccess) | ||
636 : | { | ||
637 : | result |= 8 | ||
638 : | set_user_flags(id, idefaccess) | ||
639 : | } | ||
640 : | } | ||
641 : | |||
642 : | return result | ||
643 : | } | ||
644 : | |||
645 : | accessUser(id, name[] = "") | ||
646 : | { | ||
647 : | remove_user_flags(id) | ||
648 : | |||
649 : | new userip[32], userauthid[32], password[32], passfield[32], username[32] | ||
650 : | |||
651 : | get_user_ip(id, userip, 31, 1) | ||
652 : | get_user_authid(id, userauthid, 31) | ||
653 : | |||
654 : | if (name[0]) | ||
655 : | { | ||
656 : | copy(username, 31, name) | ||
657 : | } | ||
658 : | else | ||
659 : | { | ||
660 : | get_user_name(id, username, 31) | ||
661 : | } | ||
662 : | |||
663 : | get_cvar_string("amx_password_field", passfield, 31) | ||
664 : | get_user_info(id, passfield, password, 31) | ||
665 : | |||
666 : | new result = getAccess(id, username, userauthid, userip, password) | ||
667 : | |||
668 : | if (result & 1) | ||
669 : | { | ||
670 : | client_cmd(id, "echo ^"* %L^"", id, "INV_PAS") | ||
671 : | } | ||
672 : | |||
673 : | if (result & 2) | ||
674 : | { | ||
675 : | client_cmd(id, "%s", g_cmdLoopback) | ||
676 : | return PLUGIN_HANDLED | ||
677 : | } | ||
678 : | |||
679 : | if (result & 4) | ||
680 : | { | ||
681 : | client_cmd(id, "echo ^"* %L^"", id, "PAS_ACC") | ||
682 : | } | ||
683 : | |||
684 : | if (result & 8) | ||
685 : | { | ||
686 : | client_cmd(id, "echo ^"* %L^"", id, "PRIV_SET") | ||
687 : | } | ||
688 : | |||
689 : | return PLUGIN_CONTINUE | ||
690 : | } | ||
691 : | |||
692 : | public client_infochanged(id) | ||
693 : | { | ||
694 : | if (!is_user_connected(id) || !get_cvar_num("amx_mode")) | ||
695 : | { | ||
696 : | return PLUGIN_CONTINUE | ||
697 : | } | ||
698 : | |||
699 : | new newname[32], oldname[32] | ||
700 : | |||
701 : | get_user_name(id, oldname, 31) | ||
702 : | get_user_info(id, "name", newname, 31) | ||
703 : | |||
704 : | if (!equali(newname, oldname)) | ||
705 : | { | ||
706 : | accessUser(id, newname) | ||
707 : | } | ||
708 : | |||
709 : | return PLUGIN_CONTINUE | ||
710 : | } | ||
711 : | |||
712 : | public ackSignal(id) | ||
713 : | { | ||
714 : | server_cmd("kick #%d ^"%L^"", get_user_userid(id), id, "NO_ENTRY") | ||
715 : | } | ||
716 : | |||
717 : | public client_authorized(id) | ||
718 : | return get_cvar_num("amx_mode") ? accessUser(id) : PLUGIN_CONTINUE | ||
719 : | |||
720 : | public client_putinserver(id) | ||
721 : | { | ||
722 : | if (!is_dedicated_server() && id == 1) | ||
723 : | return get_cvar_num("amx_mode") ? accessUser(id) : PLUGIN_CONTINUE | ||
724 : | |||
725 : | return PLUGIN_CONTINUE | ||
726 : | } |
Contact | ViewVC Help |
Powered by ViewVC 1.0.4 |