[Half-Life AMXX] / admin.sma Repository:
ViewVC logotype

Annotation of /admin.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 17 - (view) (download)

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

Contact
ViewVC Help
Powered by ViewVC 1.0.4