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