Advertisement
Guest User

asdada

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