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