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