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