· 8 years ago · Mar 14, 2018, 10:42 AM
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//new Vector:AdminList;
45
46new AdminCount;
47
48new PLUGINNAME[] = "AMX Mod X"
49
50#define ADMIN_LOOKUP (1<<0)
51#define ADMIN_NORMAL (1<<1)
52#define ADMIN_STEAM (1<<2)
53#define ADMIN_IPADDR (1<<3)
54#define ADMIN_NAME (1<<4)
55
56new g_cmdLoopback[16]
57new bool:g_CaseSensitiveName[33];
58
59// pcvars
60new amx_mode;
61new amx_password_field;
62new amx_default_access;
63
64// Dynamic array to hold names.
65new Array:g_aAdminNames
66new Trie:g_tAdminNames
67
68public plugin_init()
69{
70#if defined USING_SQL
71 register_plugin("Admin Base (SQL)", AMXX_VERSION_STR, "AMXX Dev Team")
72#else
73 register_plugin("Admin Base", "Custom 1.8.1", "AMXX Dev Team")
74#endif
75 register_dictionary("admin.txt")
76 register_dictionary("common.txt")
77 amx_mode=register_cvar("amx_mode", "1")
78 amx_password_field=register_cvar("amx_password_field", "_pw")
79 amx_default_access=register_cvar("amx_default_access", "")
80
81 register_cvar("amx_vote_ratio", "0.02")
82 register_cvar("amx_vote_time", "10")
83 register_cvar("amx_vote_answers", "1")
84 register_cvar("amx_vote_delay", "60")
85 register_cvar("amx_last_voting", "0")
86 register_cvar("amx_show_activity", "2")
87 register_cvar("amx_votekick_ratio", "0.40")
88 register_cvar("amx_voteban_ratio", "0.40")
89 register_cvar("amx_votemap_ratio", "0.40")
90
91 set_cvar_float("amx_last_voting", 0.0)
92
93#if defined USING_SQL
94 register_srvcmd("amx_sqladmins", "adminSql")
95 register_cvar("amx_sql_table", "admins")
96#endif
97 register_cvar("amx_sql_host", "127.0.0.1")
98 register_cvar("amx_sql_user", "root")
99 register_cvar("amx_sql_pass", "")
100 register_cvar("amx_sql_db", "amx")
101 register_cvar("amx_sql_type", "mysql")
102
103 register_concmd("amx_reloadadmins", "cmdReload", ADMIN_CFG)
104 register_concmd("amx_addadmin", "addadminfn", ADMIN_RCON, "<playername|auth> <accessflags> [password] [authtype] - add specified player as an admin to users.ini")
105
106 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'))
107
108 register_clcmd(g_cmdLoopback, "ackSignal")
109
110 remove_user_flags(0, read_flags("z")) // Remove 'user' flag from server rights
111
112 new configsDir[64]
113 get_configsdir(configsDir, 63)
114
115 server_cmd("exec %s/amxx.cfg", configsDir) // Execute main configuration file
116 server_cmd("exec %s/sql.cfg", configsDir)
117
118 // Create a vector of 5 cells to store the info.
119 //AdminList=vector_create(5);
120
121 g_aAdminNames = ArrayCreate(32)
122 g_tAdminNames = TrieCreate()
123
124#if defined USING_SQL
125 server_cmd("amx_sqladmins")
126#else
127 format(configsDir, 63, "%s/users.ini", configsDir)
128 loadSettings(configsDir) // Load admins accounts
129#endif
130}
131public client_connect(id)
132{
133 g_CaseSensitiveName[id] = false;
134}
135public addadminfn(id, level, cid)
136{
137 if (!cmd_access(id, level, cid, 3))
138 return PLUGIN_HANDLED
139
140 new idtype = ADMIN_STEAM | ADMIN_LOOKUP
141
142 if (read_argc() >= 5)
143 {
144 new t_arg[16]
145 read_argv(4, t_arg, 15)
146
147 if (equali(t_arg, "steam") || equali(t_arg, "steamid") || equali(t_arg, "auth"))
148 {
149 idtype = ADMIN_STEAM
150 }
151 else if (equali(t_arg, "ip"))
152 {
153 idtype = ADMIN_IPADDR
154 }
155 else if (equali(t_arg, "name") || equali(t_arg, "nick"))
156 {
157 idtype = ADMIN_NAME
158
159 if (equali(t_arg, "name"))
160 idtype |= ADMIN_LOOKUP
161 } else {
162 console_print(id, "[%s] Unknown id type ^"%s^", use one of: steamid, ip, name", PLUGINNAME, t_arg)
163 return PLUGIN_HANDLED
164 }
165 }
166
167 new arg[33]
168 read_argv(1, arg, 32)
169 new player = -1
170
171 if (idtype & ADMIN_STEAM)
172 {
173 if (containi(arg, "STEAM_0:") == -1)
174 {
175 idtype |= ADMIN_LOOKUP
176 player = cmd_target(id, arg, CMDTARGET_ALLOW_SELF | CMDTARGET_NO_BOTS)
177 } else {
178 new _steamid[44]
179 static _players[32], _num, _pv
180 get_players(_players, _num)
181 for (new _i=0; _i<_num; _i++)
182 {
183 _pv = _players[_i]
184 get_user_authid(_pv, _steamid, sizeof(_steamid)-1)
185 if (!_steamid[0])
186 continue
187 if (equal(_steamid, arg))
188 {
189 player = _pv
190 break
191 }
192 }
193 if (player < 1)
194 {
195 idtype &= ~ADMIN_LOOKUP
196 }
197 }
198 }
199 else if (idtype & ADMIN_NAME)
200 {
201 player = cmd_target(id, arg, CMDTARGET_ALLOW_SELF | CMDTARGET_NO_BOTS)
202
203 if (player)
204 idtype |= ADMIN_LOOKUP
205 else
206 idtype &= ~ADMIN_LOOKUP
207 }
208 else if (idtype & ADMIN_IPADDR)
209 {
210 new len = strlen(arg)
211 new dots, chars
212
213 for (new i = 0; i < len; i++)
214 {
215 if (arg[i] == '.')
216 {
217 if (!chars || chars > 3)
218 break
219
220 if (++dots > 3)
221 break
222
223 chars = 0
224 } else {
225 chars++
226 }
227
228 if (dots != 3 || !chars || chars > 3)
229 {
230 idtype |= ADMIN_LOOKUP
231 player = find_player("dh", arg)
232 }
233 }
234 }
235
236 if (idtype & ADMIN_LOOKUP && !player)
237 {
238 console_print(id, "%L", id, "CL_NOT_FOUND")
239 return PLUGIN_HANDLED
240 }
241
242 new flags[64]
243 read_argv(2, flags, 63)
244
245 new password[64]
246 if (read_argc() >= 4)
247 read_argv(3, password, 63)
248
249 new auth[33]
250 new Comment[33]; // name of player to pass to comment field
251 if (idtype & ADMIN_LOOKUP)
252 {
253 get_user_name(player, Comment, sizeof(Comment)-1)
254 if (idtype & ADMIN_STEAM)
255 {
256 get_user_authid(player, auth, 32)
257 }
258 else if (idtype & ADMIN_IPADDR)
259 {
260 get_user_ip(player, auth, 32)
261 }
262 else if (idtype & ADMIN_NAME)
263 {
264 get_user_name(player, auth, 32)
265 }
266 } else {
267 copy(auth, 32, arg)
268 }
269
270 new type[16], len
271
272 if (idtype & ADMIN_STEAM)
273 len += format(type[len], 15-len, "c")
274 else if (idtype & ADMIN_IPADDR)
275 len += format(type[len], 15-len, "d")
276
277 if (strlen(password) > 0)
278 len += format(type[len], 15-len, "a")
279 else
280 len += format(type[len], 15-len, "e")
281
282 AddAdmin(id, auth, flags, password, type, Comment)
283 cmdReload(id, ADMIN_CFG, 0)
284
285 if (player > 0)
286 {
287 new name[32]
288 get_user_info(player, "name", name, 31)
289 accessUser(player, name)
290 }
291
292 return PLUGIN_HANDLED
293}
294
295AddAdmin(id, auth[], accessflags[], password[], flags[], comment[]="")
296{
297#if defined USING_SQL
298 new error[128], errno
299
300 new Handle:info = SQL_MakeStdTuple()
301 new Handle:sql = SQL_Connect(info, errno, error, 127)
302
303 if (sql == Empty_Handle)
304 {
305 server_print("[AMXX] %L", LANG_SERVER, "SQL_CANT_CON", error)
306 //backup to users.ini
307#endif
308 // Make sure that the users.ini file exists.
309 new configsDir[64]
310 get_configsdir(configsDir, 63)
311 format(configsDir, 63, "%s/users.ini", configsDir)
312
313 if (!file_exists(configsDir))
314 {
315 console_print(id, "[%s] File ^"%s^" doesn't exist.", PLUGINNAME, configsDir)
316 return
317 }
318
319 // Make sure steamid isn't already in file.
320 new line = 0, textline[256], len
321 const SIZE = 63
322 new line_steamid[SIZE + 1], line_password[SIZE + 1], line_accessflags[SIZE + 1], line_flags[SIZE + 1], parsedParams
323
324 // <name|ip|steamid> <password> <access flags> <account flags>
325 while ((line = read_file(configsDir, line, textline, 255, len)))
326 {
327 if (len == 0 || equal(textline, "", 1))
328 continue // comment line
329
330 parsedParams = parse(textline, line_steamid, SIZE, line_password, SIZE, line_accessflags, SIZE, line_flags, SIZE)
331
332 if (parsedParams != 4)
333 continue // Send warning/error?
334
335 if (containi(line_flags, flags) != -1 && equal(line_steamid, auth))
336 {
337 console_print(id, "[%s] %s already exists!", PLUGINNAME, auth)
338 return
339 }
340 }
341
342 // If we came here, steamid doesn't exist in users.ini. Add it.
343 new linetoadd[512]
344
345 if (comment[0]==0)
346 {
347 formatex(linetoadd, 511, "^r^n^"%s^" ^"%s^" ^"%s^" ^"%s^"", auth, password, accessflags, flags)
348 }
349 else
350 {
351 formatex(linetoadd, 511, "^r^n^"%s^" ^"%s^" ^"%s^" ^"%s^" ^"%s^"", auth, password, accessflags, flags, comment)
352 }
353 console_print(id, "Adding:^n%s", linetoadd)
354
355 if (!write_file(configsDir, linetoadd))
356 console_print(id, "[%s] Failed writing to %s!", PLUGINNAME, configsDir)
357#if defined USING_SQL
358 }
359
360 new table[32]
361
362 get_cvar_string("amx_sql_table", table, 31)
363
364 new Handle:query = SQL_PrepareQuery(sql, "SELECT * FROM `%s` WHERE (`auth` = '%s')", table, auth)
365
366 if (!SQL_Execute(query))
367 {
368 SQL_QueryError(query, error, 127)
369 server_print("[AMXX] %L", LANG_SERVER, "SQL_CANT_LOAD_ADMINS", error)
370 console_print(id, "[AMXX] %L", LANG_SERVER, "SQL_CANT_LOAD_ADMINS", error)
371 } else if (SQL_NumResults(query)) {
372 console_print(id, "[%s] %s already exists!", PLUGINNAME, auth)
373 } else {
374 console_print(id, "Adding to database:^n^"%s^" ^"%s^" ^"%s^" ^"%s^"", auth, password, accessflags, flags)
375
376 SQL_QueryAndIgnore(sql, "REPLACE INTO `%s` (`auth`, `password`, `access`, `flags`) VALUES ('%s', '%s', '%s', '%s')", table, auth, password, accessflags, flags)
377 }
378
379 SQL_FreeHandle(query)
380 SQL_FreeHandle(sql)
381 SQL_FreeHandle(info)
382#endif
383
384}
385public plugin_cfg()
386{
387 set_task(6.1, "delayed_load")
388}
389
390public delayed_load()
391{
392 new configFile[128], curMap[64], configDir[128]
393
394 get_configsdir(configDir, sizeof(configDir)-1)
395 get_mapname(curMap, sizeof(curMap)-1)
396
397 new i=0;
398
399 while (curMap[i] != '_' && curMap[i++] != '^0') {/*do nothing*/}
400
401 if (curMap[i]=='_')
402 {
403 // this map has a prefix
404 curMap[i]='^0';
405 formatex(configFile, sizeof(configFile)-1, "%s/maps/prefix_%s.cfg", configDir, curMap);
406
407 if (file_exists(configFile))
408 {
409 server_cmd("exec %s", configFile);
410 }
411 }
412
413 get_mapname(curMap, sizeof(curMap)-1)
414
415
416 formatex(configFile, sizeof(configFile)-1, "%s/maps/%s.cfg", configDir, curMap)
417
418 if (file_exists(configFile))
419 {
420 server_cmd("exec %s", configFile)
421 }
422
423}
424
425loadSettings(szFilename[])
426{
427 new File=fopen(szFilename,"r");
428
429 if (File)
430 {
431 new Text[512];
432 new Flags[32];
433 new Access[32]
434 new AuthData[44];
435 new Password[32];
436 new Name[32];
437
438 ArrayClear(g_aAdminNames);
439
440 while (!feof(File))
441 {
442 fgets(File,Text,sizeof(Text)-1);
443
444 trim(Text);
445
446 // comment
447 if (Text[0]==';')
448 {
449 continue;
450 }
451
452 Flags[0]=0;
453 Access[0]=0;
454 AuthData[0]=0;
455 Password[0]=0;
456 Name[0]=0;
457
458 // not enough parameters
459 if (parse(Text,AuthData,sizeof(AuthData)-1,Password,sizeof(Password)-1,Access,sizeof(Access)-1,Flags,sizeof(Flags)-1, Name, charsmax(Name)) < 2)
460 {
461 continue;
462 }
463
464 admins_push(AuthData,Password,read_flags(Access),read_flags(Flags));
465 ArrayPushString(g_aAdminNames, Name)
466 strtolower(Name)
467 TrieSetCell(g_tAdminNames, Name, 1)
468
469 AdminCount++;
470 }
471
472 fclose(File);
473 }
474
475 if (AdminCount == 1)
476 {
477 server_print("[AMXX] %L", LANG_SERVER, "LOADED_ADMIN");
478 }
479 else
480 {
481 server_print("[AMXX] %L", LANG_SERVER, "LOADED_ADMINS", AdminCount);
482 }
483
484 return 1;
485}
486
487#if defined USING_SQL
488public adminSql()
489{
490 new table[32], error[128], type[12], errno
491
492 new Handle:info = SQL_MakeStdTuple()
493 new Handle:sql = SQL_Connect(info, errno, error, 127)
494
495 get_cvar_string("amx_sql_table", table, 31)
496
497 SQL_GetAffinity(type, 11)
498
499 if (sql == Empty_Handle)
500 {
501 server_print("[AMXX] %L", LANG_SERVER, "SQL_CANT_CON", error)
502
503 //backup to users.ini
504 new configsDir[64]
505
506 get_configsdir(configsDir, 63)
507 format(configsDir, 63, "%s/users.ini", configsDir)
508 loadSettings(configsDir) // Load admins accounts
509
510 return PLUGIN_HANDLED
511 }
512
513 new Handle:query
514
515 if (equali(type, "sqlite"))
516 {
517 if (!sqlite_TableExists(sql, table))
518 {
519 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)
520 }
521
522 query = SQL_PrepareQuery(sql, "SELECT auth, password, access, flags FROM %s", table)
523 } else {
524 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)
525 query = SQL_PrepareQuery(sql,"SELECT `auth`,`password`,`access`,`flags` FROM `%s`", table)
526 }
527
528 if (!SQL_Execute(query))
529 {
530 SQL_QueryError(query, error, 127)
531 server_print("[AMXX] %L", LANG_SERVER, "SQL_CANT_LOAD_ADMINS", error)
532 } else if (!SQL_NumResults(query)) {
533 server_print("[AMXX] %L", LANG_SERVER, "NO_ADMINS")
534 } else {
535
536 AdminCount = 0
537
538 /** do this incase people change the query order and forget to modify below */
539 new qcolAuth = SQL_FieldNameToNum(query, "auth")
540 new qcolPass = SQL_FieldNameToNum(query, "password")
541 new qcolAccess = SQL_FieldNameToNum(query, "access")
542 new qcolFlags = SQL_FieldNameToNum(query, "flags")
543
544 new AuthData[44];
545 new Password[44];
546 new Access[32];
547 new Flags[32];
548
549 while (SQL_MoreResults(query))
550 {
551 SQL_ReadResult(query, qcolAuth, AuthData, sizeof(AuthData)-1);
552 SQL_ReadResult(query, qcolPass, Password, sizeof(Password)-1);
553 SQL_ReadResult(query, qcolAccess, Access, sizeof(Access)-1);
554 SQL_ReadResult(query, qcolFlags, Flags, sizeof(Flags)-1);
555
556 admins_push(AuthData,Password,read_flags(Access),read_flags(Flags));
557
558 ++AdminCount;
559 SQL_NextRow(query)
560 }
561
562 if (AdminCount == 1)
563 {
564 server_print("[AMXX] %L", LANG_SERVER, "SQL_LOADED_ADMIN")
565 }
566 else
567 {
568 server_print("[AMXX] %L", LANG_SERVER, "SQL_LOADED_ADMINS", AdminCount)
569 }
570
571 SQL_FreeHandle(query)
572 SQL_FreeHandle(sql)
573 SQL_FreeHandle(info)
574 }
575
576 return PLUGIN_HANDLED
577}
578#endif
579
580public cmdReload(id, level, cid)
581{
582 if (!cmd_access(id, level, cid, 1))
583 return PLUGIN_HANDLED
584
585 //strip original flags (patch submitted by mrhunt)
586 remove_user_flags(0, read_flags("z"))
587
588 admins_flush();
589
590#if !defined USING_SQL
591 new filename[128]
592
593 get_configsdir(filename, 127)
594 format(filename, 63, "%s/users.ini", filename)
595
596 AdminCount = 0;
597 loadSettings(filename); // Re-Load admins accounts
598
599 if (id != 0)
600 {
601 if (AdminCount == 1)
602 {
603 console_print(id, "[AMXX] %L", LANG_SERVER, "LOADED_ADMIN");
604 }
605 else
606 {
607 console_print(id, "[AMXX] %L", LANG_SERVER, "LOADED_ADMINS", AdminCount);
608 }
609 }
610#else
611 AdminCount = 0
612 adminSql()
613
614 if (id != 0)
615 {
616 if (AdminCount == 1)
617 console_print(id, "[AMXX] %L", LANG_SERVER, "SQL_LOADED_ADMIN")
618 else
619 console_print(id, "[AMXX] %L", LANG_SERVER, "SQL_LOADED_ADMINS", AdminCount)
620 }
621#endif
622
623 new players[32], num, pv
624 new name[32]
625 get_players(players, num)
626 for (new i=0; i<num; i++)
627 {
628 pv = players[i]
629 get_user_name(pv, name, 31)
630 accessUser(pv, name)
631 }
632
633 return PLUGIN_HANDLED
634}
635
636getAccess(id, name[], authid[], ip[], password[])
637{
638 new index = -1
639 new result = 0
640
641 static Count;
642 static Flags;
643 static Access;
644 static AuthData[44];
645 static Password[32];
646
647 g_CaseSensitiveName[id] = false;
648
649 Count=admins_num();
650 for (new i = 0; i < Count; ++i)
651 {
652 Flags=admins_lookup(i,AdminProp_Flags);
653 admins_lookup(i,AdminProp_Auth,AuthData,sizeof(AuthData)-1);
654
655 if (Flags & FLAG_AUTHID)
656 {
657 if (equal(authid, AuthData))
658 {
659 index = i
660 break
661 }
662 }
663 else if (Flags & FLAG_IP)
664 {
665 new c = strlen(AuthData)
666
667 if (AuthData[c - 1] == '.') /* check if this is not a xxx.xxx. format */
668 {
669 if (equal(AuthData, ip, c))
670 {
671 index = i
672 break
673 }
674 } /* in other case an IP must just match */
675 else if (equal(ip, AuthData))
676 {
677 index = i
678 break
679 }
680 }
681 else
682 {
683 if (Flags & FLAG_CASE_SENSITIVE)
684 {
685 if (Flags & FLAG_TAG)
686 {
687 if (contain(name, AuthData) != -1)
688 {
689 index = i
690 g_CaseSensitiveName[id] = true
691 break
692 }
693 }
694 else if (equal(name, AuthData))
695 {
696 index = i
697 g_CaseSensitiveName[id] = true
698 break
699 }
700 }
701 else
702 {
703 if (Flags & FLAG_TAG)
704 {
705 if (containi(name, AuthData) != -1)
706 {
707 index = i
708 break
709 }
710 }
711 else if (equali(name, AuthData))
712 {
713 index = i
714 break
715 }
716 }
717 }
718 }
719// check name here? If no match, Do index = -1
720 if( index == -1 )
721 {
722 strtolower(name)
723 if( TrieKeyExists(g_tAdminNames, name) )
724 result |= 16
725 }
726 else
727 {
728 new szNameOnFile[32]
729 ArrayGetString(g_aAdminNames, index, szNameOnFile, charsmax(szNameOnFile))
730 if( szNameOnFile[0] )
731 {
732 if( !equali(name, szNameOnFile) )
733 {
734 index = -1
735 }
736 }
737 }
738 if (index != -1)
739 {
740 Access=admins_lookup(index,AdminProp_Access);
741
742 if (Flags & FLAG_NOPASS)
743 {
744 result |= 8
745 new sflags[32]
746
747 get_flags(Access, sflags, 31)
748 set_user_flags(id, Access)
749
750 log_amx("Login: ^"%s<%d><%s><>^" became an admin (account ^"%s^") (access ^"%s^") (address ^"%s^")", name, get_user_userid(id), authid, AuthData, sflags, ip)
751 }
752 else
753 {
754
755 admins_lookup(index,AdminProp_Password,Password,sizeof(Password)-1);
756
757 if (equal(password, Password))
758 {
759 result |= 12
760 set_user_flags(id, Access)
761
762 new sflags[32]
763 get_flags(Access, sflags, 31)
764
765 log_amx("Login: ^"%s<%d><%s><>^" became an admin (account ^"%s^") (access ^"%s^") (address ^"%s^")", name, get_user_userid(id), authid, AuthData, sflags, ip)
766 }
767 else
768 {
769 result |= 1
770
771 if (Flags & FLAG_KICK)
772 {
773 result |= 2
774 log_amx("Login: ^"%s<%d><%s><>^" kicked due to invalid password (account ^"%s^") (address ^"%s^")", name, get_user_userid(id), authid, AuthData, ip)
775 }
776 }
777 }
778 }
779 else if (get_pcvar_float(amx_mode) == 2.0)
780 {
781 result |= 2
782 }
783 else
784 {
785 new defaccess[32]
786
787 get_pcvar_string(amx_default_access, defaccess, 31)
788
789 if (!strlen(defaccess))
790 {
791 copy(defaccess, 32, "z")
792 }
793
794 new idefaccess = read_flags(defaccess)
795
796 if (idefaccess)
797 {
798 result |= 8
799 set_user_flags(id, idefaccess)
800 }
801 }
802
803 return result
804}
805
806accessUser(id, name[] = "")
807{
808 remove_user_flags(id)
809
810 new userip[32], userauthid[32], password[32], passfield[32], username[32]
811
812 get_user_ip(id, userip, 31, 1)
813 get_user_authid(id, userauthid, 31)
814
815 if (name[0])
816 {
817 copy(username, 31, name)
818 }
819 else
820 {
821 get_user_name(id, username, 31)
822 }
823
824 get_pcvar_string(amx_password_field, passfield, 31)
825 get_user_info(id, passfield, password, 31)
826
827 new result = getAccess(id, username, userauthid, userip, password)
828
829 if (result & 1)
830 {
831 client_cmd(id, "echo ^"* %L^"", id, "INV_PAS")
832 }
833
834 if (result & 2)
835 {
836 client_cmd(id, "%s", g_cmdLoopback)
837 return PLUGIN_HANDLED
838 }
839
840 if (result & 4)
841 {
842 client_cmd(id, "echo ^"* %L^"", id, "PAS_ACC")
843 }
844
845 if (result & 8)
846 {
847 client_cmd(id, "echo ^"* %L^"", id, "PRIV_SET")
848 }
849
850 if (result & 16)
851 {
852 server_cmd("kick #%d ^"You are not allowed to use that name.^"", get_user_userid(id))
853 }
854
855 return PLUGIN_CONTINUE
856}
857
858public client_infochanged(id)
859{
860 if (!is_user_connected(id) || !get_pcvar_num(amx_mode))
861 {
862 return PLUGIN_CONTINUE
863 }
864
865 new newname[32], oldname[32]
866
867 get_user_name(id, oldname, 31)
868 get_user_info(id, "name", newname, 31)
869
870 if (g_CaseSensitiveName[id])
871 {
872 if (!equal(newname, oldname))
873 {
874 accessUser(id, newname)
875 }
876 }
877 else
878 {
879 if (!equali(newname, oldname))
880 {
881 accessUser(id, newname)
882 }
883 }
884 return PLUGIN_CONTINUE
885}
886
887public ackSignal(id)
888{
889 server_cmd("kick #%d ^"%L^"", get_user_userid(id), id, "NO_ENTRY")
890 return PLUGIN_HANDLED
891}
892
893public client_authorized(id)
894 return get_pcvar_num(amx_mode) ? accessUser(id) : PLUGIN_CONTINUE
895
896public client_putinserver(id)
897{
898 if (!is_dedicated_server() && id == 1)
899 return get_pcvar_num(amx_mode) ? accessUser(id) : PLUGIN_CONTINUE
900
901 return PLUGIN_CONTINUE
902}
903
904public plugin_end()
905{
906 ArrayDestroy(g_aAdminNames)
907}