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