Advertisement
Guest User

adasdada

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