fucktheschool

Temporary Admins V1.9 *BETA*

Oct 8th, 2016
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 28.16 KB | None | 0 0
  1. /*
  2.  
  3. Temporary Admin by FuckTheSchool ( Eyal282 )
  4.  
  5. Changelog:
  6.  
  7. v1.0: Release of plugin.
  8.  
  9. v1.1: Bug fixes and add of amx_removetempadmin and amx_edittempadmin.
  10.  
  11. v1.2: Fixed amx_removetempadmin and amx_edittempadmin bugs.
  12.       Added /managetemp to show a list of offline temporary admins, for easier access to the commands.
  13.  
  14. v1.3: Added ability to type on flags: Manager, SuperAdmin, Admin, VIP.
  15.  
  16. v1.4: Fixed major bugs that allow use of command only on name. Change of the word "Syntax" to "Usage".
  17.       Changed use of get_time to get_systime to make the plugin more efficient.
  18.  
  19. v1.5: Covered all major bugs related to time after v1.4.
  20.  
  21. v1.6: More major issues to trash. Fixed /adminstatus for permanent rcon admins.
  22.       Fixed amx_removetempadmin and amx_edittempadmin.
  23.  
  24. v1.7: Disconnect the plugin from being dependant on a seperate users.ini to prevent errors.
  25.       This means users.ini is going to get twice as messy.. An idiotic miss spell was corrected.
  26.       Fixed an added player online not able to do /adminstatus. Added a define for the taskid of UpdateTimes.
  27.      
  28. v1.8: /managetemp became 3 times more efficient. Fixed a major bug related to v1.7
  29.       amx_edittempadmin now has access to edit access flags. Added "display name" to make /managetemp more efficient.
  30.       /managetemp has more power than the console commands.
  31.      
  32. v1.9: Fixed annoying bugs related to since v1.7. Plugin became much more stable.
  33.  
  34. */
  35.  
  36. #include <amxmodx>
  37. #include <amxmisc>
  38.  
  39. #pragma semicolon 1
  40.  
  41. #define PLUGIN "Temporary Admin"
  42. #define VERSION "1.9"
  43. #define AUTHOR "FuckTheSchool ( Eyal282 )" // I took something small from the plugin xRedirect but rest is my work.
  44.  
  45. #define Day1 (60 * 60 * 24) // Define is a waste of resources yet it is comfortable.
  46.  
  47. #define ManagerFlags1 "bcdefghijkmnopqrstu"
  48.  
  49. #define SuperAdminFlags1 "cdefghijkmnopqrstu"
  50.  
  51. #define AdminFlags1 "cefgijmnopqrstu"
  52.  
  53. #define VIPFlags1 "ceijp"
  54.  
  55. #define TASKID_UpdateTimes1 349587345
  56.  
  57. new Day = Day1;
  58.  
  59. new const ManagerFlags[] = ManagerFlags1, SuperAdminFlags[] = SuperAdminFlags1;
  60. new const AdminFlags[] = AdminFlags1, VIPFlags[] = VIPFlags1;
  61.  
  62. new AdminsDir[200], aStatus[33], bool:Messaged[33];
  63. new AdminName[33][50], AdminIP[33][50], AdminID[33][50], AdminPassword[33][50], AdminAccess[33][50], AdminTime[33], AdminMethod[33][50], bool:Adding[33], AdminInfo[33][300];
  64.  
  65. new TASKID_UpdateTimes = TASKID_UpdateTimes1;
  66.  
  67. public plugin_init()
  68. {
  69.     register_plugin(PLUGIN, VERSION, AUTHOR);
  70.    
  71.     register_concmd("amx_addtempadmin", "AddAdmin", ADMIN_RCON, "Usage: amx_addtempadmin <name/^"steamid^"/ip> <flags> <days> [password] [display name]"); // Take note that adding to 0 days while player is online will do it until player reconnects.
  72.    
  73.     register_concmd("amx_removetempadmin", "RemoveAdmin", ADMIN_RCON, "Usage: amx_removetempadmin <name/^"steamid^"/ip>");
  74.    
  75.     register_concmd("amx_edittempadmin", "EditAdmin", ADMIN_RCON, "Usage: amx_edittempadmin <name/^"steamid^"/ip> <days> [display name]");
  76.    
  77.     register_clcmd("say", "TimeLeft");
  78.    
  79.     register_clcmd("say /managetemp", "ManageAdmins");
  80.    
  81.     register_clcmd("TempAdmin_Password", "EditPassword");
  82.     register_clcmd("TempAdmin_Flags", "EditFlags");
  83.     register_clcmd("TempAdmin_Time", "EditTime");
  84.     register_clcmd("TempAdmin_Name", "EditName");
  85.    
  86.     register_cvar("amx_prefix_cvar", "PREFIX");
  87. }
  88.  
  89. public plugin_cfg()
  90. {
  91.     new Dir[200];
  92.     get_configsdir(Dir, charsmax(Dir));
  93.  
  94.     formatex(AdminsDir, charsmax(AdminsDir), "%s/users.ini", Dir);
  95.    
  96.     if(!file_exists(AdminsDir))
  97.         write_file(AdminsDir, "; It is unneccessary nor recommended to edit this file other than removing complete lines."), write_file(AdminsDir, "; If you wish to delete a line from here, delete the identical line from users.ini.");
  98.        
  99.     set_task(0.5, "UpdateTimes", TASKID_UpdateTimes);
  100.    
  101.    
  102. }
  103.  
  104. // This updates expiration days in file, for more comfortable access through the file.
  105.  
  106. public UpdateTimes()
  107. {
  108.     new ReadFile[300], Token[7][300], Line, Length, Format[240], Smallest = -1;
  109.    
  110.     while(read_file(AdminsDir, Line++, ReadFile, charsmax(ReadFile), Length))
  111.     {
  112.         if(!read_file(AdminsDir, Line, ReadFile, charsmax(ReadFile), Length))
  113.             break;
  114.        
  115.         parse(ReadFile, Token[0], 231, Token[1], 231, Token[2], 231, Token[3], 231, Token[4], 231, Token[5], 231, Token[6], 231);
  116.        
  117.         if(strfind(Token[4], ";Expiration(") == -1) continue;
  118.        
  119.         new Influence[100], Tok[100], ReadFileView[232];
  120.        
  121.         new DaysLeft = ( ( str_to_num(Token[5]) - get_systime() ) / Day ) + 1;
  122.        
  123.         formatex(ReadFileView, charsmax(ReadFileView), ReadFile);
  124.        
  125.         formatex(Influence, charsmax(Influence), ";Expiration(%i Days):", DaysLeft);
  126.        
  127.         replace(Token[4], 231, Token[4], Influence);
  128.        
  129.         formatex(ReadFile, charsmax(ReadFile), "");
  130.         /*
  131.         new Loop = 6;  
  132.        
  133.         if(strcmp(Token[6], "") == 0)
  134.             Loop = 7;
  135.         */ 
  136.         for(new i;i < 7;i++)
  137.         {
  138.             formatex(Format, charsmax(Format), "^"%s^"%s", Token[i], i == 7 - 1 ? "" : " ");
  139.             add(ReadFile, charsmax(ReadFile), Format);
  140.         }
  141.    
  142.        
  143.         formatex(Tok, charsmax(Tok), Token[0]);
  144.        
  145.         write_file(AdminsDir, DaysLeft > 0 ? ReadFile : "", Line);
  146.        
  147.                
  148.         if( ( Smallest > DaysLeft || Smallest == -1 ) && DaysLeft > 0 ) Smallest = DaysLeft;
  149.     }
  150.    
  151.     new players[32], num;
  152.     get_players(players, num, "ch");
  153.    
  154.     for(new id;id < num;id++) // Refreshing connected
  155.     {
  156.         new i = players[id];
  157.         aStatus[i] = -1;
  158.         set_task(6.0, "CheckTemp", i);
  159.     }
  160.    
  161.     if(Smallest != -1)
  162.     {
  163.         remove_task(TASKID_UpdateTimes);
  164.         set_task(float(Smallest * Day), "UpdateTimes");
  165.     }
  166.    
  167.     server_cmd("amx_reloadadmins");
  168. }
  169.  
  170. // Here we will prohibit the player from /adminstatus'ing himself until we check if he's an admin & temporary admin.
  171.  
  172. public client_putinserver(id)
  173. {
  174.     aStatus[id] = -1;
  175.     AdminMethod[id] = "Name";
  176.     AdminTime[id] = 0;
  177.     AdminPassword[id] = "";
  178.     Messaged[id] = false;
  179.     set_task(1.0, "CheckTemp", id);
  180. }
  181.  
  182. // Here we set the user's amount of expiration days for /adminstatus.
  183.  
  184. public CheckTemp(id)
  185. {
  186.     if(!is_user_admin(id))
  187.         return;
  188.        
  189.     new ReadFile[232], Token[6][232], Line, Length;
  190.    
  191.     while(read_file(AdminsDir, Line++, ReadFile, charsmax(ReadFile), Length))
  192.     {
  193.         if(!read_file(AdminsDir, Line, ReadFile, charsmax(ReadFile), Length)) break;
  194.    
  195.         if(ReadFile[0] == ';' || strcmp(ReadFile, "") == 0) continue;
  196.         parse(ReadFile, Token[0], 231, Token[1], 231, Token[2], 231, Token[3], 231, Token[4], 231, Token[5], 231);
  197.        
  198.         if(strfind(Token[4], ";Expiration(") == -1) continue;
  199.  
  200.         if(strcmp(Token[0], get_user_steamid(id)) == 0 || strcmp(Token[0], get_user_nick(id), 1) == 0 || strcmp(Token[0], get_user_address(id)) == 0)
  201.         {  
  202.             new DaysLeft = ( ( str_to_num(Token[5]) - get_systime() ) / Day ) + 1;
  203.            
  204.             if(DaysLeft <= 0)
  205.             {
  206.                 write_file(AdminsDir, "", Line);
  207.            
  208.             }
  209.        
  210.             if(DaysLeft > 0) aStatus[id] = DaysLeft, set_task(10.0, "DidYouKnow", id);
  211.             break;
  212.         }
  213.     }  
  214. }
  215.  
  216. // This one will inform the temporary admin that he is a temporary admin with a limit of time, if he wasn't messaged already.
  217.  
  218. public DidYouKnow(id)   if(!Messaged[id]) ColorChat(id, "^4You can check when will your admin status expire by typing^3 /adminstatus"), Messaged[id] = true;
  219.  
  220. // This will be called when an admin tries to add a temporary admin.
  221.  
  222. public AddAdmin(id, level, cid)
  223. {
  224.     if(!cmd_access(id, level, cid, 1))
  225.         return PLUGIN_HANDLED;
  226.    
  227.        
  228.     new Message[200], Token[5][200], Type, TempCheck[20], TompChock; // Type 0 = SID, Type 1 = IP, Type 2 = Name.
  229.     read_args(Message, charsmax(Message));
  230.     parse(Message, Token[0], 199, Token[1], 199, Token[2], 199, Token[3], 199, Token[4], 199);
  231.    
  232.     remove_quotes(Message);
  233.     formatex(TempCheck, charsmax(TempCheck), Token[0]); // Maybe IP.
  234.    
  235.     while(containi(TempCheck, ".") != -1)
  236.     {
  237.         replace(TempCheck, charsmax(TempCheck), ".", "");
  238.         TompChock++;
  239.     }
  240.    
  241.     if(!is_str_num(Token[2]))      
  242.         return client_print(id, print_console, "Usage: amx_addtempadmin <name/^"steamid^"/ip> <flags> <days> <password>");
  243.    
  244.     if(equali(Token[1], "Manager")) replace(Token[1], 199, Token[1], ManagerFlags);
  245.     else if(equali(Token[1], "SuperAdmin")) replace(Token[1], 199, Token[1], SuperAdminFlags);
  246.     else if(equali(Token[1], "Admin")) replace(Token[1], 199, Token[1], AdminFlags);
  247.     else if(equali(Token[1], "VIP")) replace(Token[1], 199, Token[1], VIPFlags);
  248.    
  249.     if(containi(Token[1], "l") != -1)
  250.         return client_print(id, print_console, "Admins with rcon access ( l ) are able to set themselves and others as permanent admins.");
  251.    
  252.     new WriteFile[200];
  253.    
  254.     new Combat = get_systime() + ( str_to_num(Token[2]) * Day );
  255.    
  256.     if(contain(Token[0], "STEAM_") != -1 || contain(Token[0], "VALVE_") != -1)
  257.         Type = 0;
  258.        
  259.     else if(is_str_num(TempCheck) && TompChock == 3)
  260.         Type = 1;
  261.        
  262.     else
  263.         Type = 2;
  264.        
  265.     new DisplayName[50];
  266.        
  267.     switch(Type)
  268.     {
  269.         case 0:
  270.         {
  271.             if(equali(Token[1], "") || equali(Token[2], ""))
  272.                 return client_print(id, print_console, "Usage: amx_addtempadmin <^"steamid^"> <flags> <days> [display name]");
  273.                
  274.             formatex(WriteFile, charsmax(WriteFile), "^n^"%s^" ^"^" ^"%s^" ^"ce^" ;^"Expiration(%i Days):^" ^"%i^"", Token[0], Token[1], str_to_num(Token[2]), Combat);
  275.         }
  276.         case 1:
  277.         {
  278.             if(equali(Token[1], "") || equali(Token[2], ""))
  279.                 return client_print(id, print_console, "Usage: amx_addtempadmin <ip> <flags> <days> [display name]");
  280.            
  281.             formatex(WriteFile, charsmax(WriteFile), "^n^"%s^" ^"^" ^"%s^" ^"de^" ;^"Expiration(%i Days):^" ^"%i^"", Token[0], Token[1], str_to_num(Token[2]), Combat);
  282.         }
  283.         case 2:
  284.         {
  285.             if(equali(Token[1], "") || equali(Token[2], "") || equali(Token[3], ""))
  286.                 return client_print(id, print_console, "Usage: amx_addtempadmin <name> <flags> <days> <password>");
  287.            
  288.             if(strcmp(Token[4], "") != 0)
  289.                 formatex(DisplayName, charsmax(DisplayName), " ^"%s^"", Token[4]);
  290.                
  291.             formatex(WriteFile, charsmax(WriteFile), "^n^"%s^" ^"%s^" ^"%s^" ^"a^" ^";Expiration(%i Days):^" ^"%i^"", Token[0], Token[3], Token[1], str_to_num(Token[2]), Combat);
  292.         }
  293.     }
  294.    
  295.     DisplayName = "";
  296.     if(strcmp(Token[4], "") != 0 && Type == 2)
  297.         formatex(DisplayName, charsmax(DisplayName), " ^"%s^"", Token[4]);
  298.        
  299.     else if(strcmp(Token[3], "") != 0 && Type != 2)
  300.         formatex(DisplayName, charsmax(DisplayName), " ^"%s^"", Token[3]);
  301.        
  302.     add(WriteFile, charsmax(WriteFile), DisplayName);
  303.    
  304.     write_file(AdminsDir, WriteFile);
  305.     server_cmd("amx_reloadadmins");
  306.    
  307.     remove_task(TASKID_UpdateTimes);
  308.    
  309.     set_task(1.0, "UpdateTimes", TASKID_UpdateTimes);
  310.    
  311.     return client_print(id, print_console, "%s was added successfully", Token[0]);
  312. }  
  313.  
  314. // This will be called when an admin tries to remove a temporary admin.
  315.  
  316. public RemoveAdmin(id, level, cid)
  317. {
  318.     if(!cmd_access(id, level, cid, 1))
  319.         return PLUGIN_HANDLED;
  320.    
  321.        
  322.     new Message[200], Token[2][200]; // Type 0 = SID, Type 1 = IP, Type 2 = Name.
  323.     read_args(Message, charsmax(Message));
  324.     parse(Message, Token[0], 199, Token[1], 199);
  325.    
  326.     remove_quotes(Token[0]);
  327.    
  328.     new ReadFile[300], Line, Length, Toke[6][300];
  329.    
  330.     while(read_file(AdminsDir, Line++, ReadFile, charsmax(ReadFile), Length))
  331.     {
  332.         if(!read_file(AdminsDir, Line, ReadFile, charsmax(ReadFile), Length)) return client_print(id, print_console, "%s was not found!", Token[0]);
  333.        
  334.         parse(ReadFile, Toke[0], 199, Toke[1], 199, Toke[2], 199, Toke[3], 199, Toke[4], 199, Toke[5], 199);
  335.        
  336.         if(ReadFile[0] == ';' || strcmp(ReadFile, "") == 0 || strfind(Toke[4], ";Expiration(") == -1) continue;
  337.        
  338.         if(strcmp(Token[0], Toke[0]) == 0)
  339.         {
  340.             new Tok[100];
  341.             formatex(Tok, charsmax(Tok), Token[0]);
  342.             write_file(AdminsDir, "", Line);
  343.            
  344.             break;
  345.         }
  346.     }
  347.    
  348.     server_cmd("amx_reloadadmins");
  349.    
  350.     remove_task(TASKID_UpdateTimes);
  351.    
  352.     set_task(1.0, "UpdateTimes", TASKID_UpdateTimes);
  353.    
  354.     return client_print(id, print_console, "%s was removed successfully", Token[0]);
  355. }  
  356.  
  357. // This will be called when an admin tries to edit a temporary admin's time left.
  358.  
  359. public EditAdmin(id, level, cid)
  360. {
  361.     if(!cmd_access(id, level, cid, 1))
  362.         return PLUGIN_HANDLED;
  363.    
  364.        
  365.     new Message[200], Token[3][200]; // Type 0 = SID, Type 1 = IP, Type 2 = Name.
  366.     read_args(Message, charsmax(Message));
  367.     parse(Message, Token[0], 199, Token[1], 199, Token[2], 199);
  368.    
  369.     remove_quotes(Token[0]);
  370.    
  371.     if(!is_str_num(Token[1]))
  372.         return client_print(id, print_console, "Usage: amx_edittempadmin <name/^"steamid^"/ip> <days> [display name]");
  373.    
  374.     new TempToken = str_to_num(Token[1]);
  375.    
  376.     new Combat = get_systime() + ( Day * TempToken );
  377.    
  378.     new players[32], num;
  379.     get_players(players, num, "ch");
  380.    
  381.     new ReadFile[232], Toke[7][232], Line, Format[325], Length;
  382.    
  383.     while(read_file(AdminsDir, Line++, ReadFile, charsmax(ReadFile), Length))
  384.     {
  385.         if(!read_file(AdminsDir, Line, ReadFile, charsmax(ReadFile), Length)) return client_print(id, print_console, "%s was not found!", Token[0]);
  386.    
  387.         parse(ReadFile, Toke[0], 231, Toke[1], 231, Toke[2], 231, Toke[3], 231, Toke[4], 231, Toke[5], 231, Toke[6], 231);
  388.        
  389.         if(ReadFile[0] == ';' || strcmp(ReadFile, "") == 0 || strfind(Toke[4], ";Expiration(") == -1) continue;
  390.        
  391.         if(strcmp(Token[0], Toke[0]) == 0)
  392.         {
  393.             new Tok[100], ReadFileView[232];
  394.            
  395.             formatex(ReadFileView, charsmax(ReadFileView), ReadFile);
  396.            
  397.             formatex(ReadFile, charsmax(ReadFile), "");
  398.            
  399.             formatex(Toke[5], 199, "%i", Combat);
  400.            
  401.             if(strcmp(Token[2], "") != 0)
  402.                 formatex(Toke[2], 199, Token[2]);
  403.             /*
  404.             new Loop = 6;
  405.            
  406.             if(strcmp(Toke[6], "") == 0)
  407.                 Loop = 7;
  408.             */
  409.             for(new i;i < 7;i++)
  410.             {
  411.                 formatex(Format, charsmax(Format), "^"%s^" ", Toke[i]);
  412.                
  413.                 add(ReadFile, charsmax(ReadFile), Format);
  414.             }
  415.    
  416.        
  417.             formatex(Tok, charsmax(Tok), Toke[0]);
  418.        
  419.             write_file(AdminsDir, ReadFile, Line);
  420.            
  421.             break;
  422.         }
  423.     }
  424.    
  425.     server_cmd("amx_reloadadmins");
  426.    
  427.     remove_task(TASKID_UpdateTimes);
  428.    
  429.     set_task(1.0, "UpdateTimes", TASKID_UpdateTimes);
  430.     return client_print(id, print_console, "%s was edited successfully!", Token[0]);
  431. }  
  432.  
  433. public TimeLeft(id)
  434. {
  435.     new Message[100], Command[50], TargetArg[50];
  436.    
  437.     read_argv(1, Message, charsmax(Message));
  438.    
  439.     parse(Message, Command, charsmax(Command), TargetArg, charsmax(TargetArg));
  440.    
  441.     if(equali(Command, "/adminstatus"))
  442.     {
  443.         if(aStatus[id] != -1)
  444.             return ColorChat(id, "^4Your temporary admin will expire in %i Days.", aStatus[id]);
  445.            
  446.         else if(!(get_user_flags(id) & ADMIN_RCON))
  447.             return ColorChat(id, "^4You have no access to this command!");
  448.            
  449.         new Target = cmd_target(id, TargetArg, 0);
  450.                
  451.         if(!Target) return ColorChat(id, "^4Player was not found.");
  452.         else if(!is_user_admin(Target)) return ColorChat(id, "^4This user is not an admin.");          
  453.         else if(aStatus[Target] == -1) return ColorChat(id, "^4This user is a permanent admin.");
  454.                
  455.         return ColorChat(id, "^4%s has %i Days left for his admin.", get_user_nick(Target), aStatus[Target]);
  456.     }
  457.    
  458.     return 0;
  459.  
  460. }
  461.  
  462. // Here the function will create a menu for the player to easily access the admins and add.
  463.  
  464. public ManageAdmins(id)
  465. {
  466.     if(!(get_user_flags(id) & ADMIN_RCON))
  467.         return ColorChat(id, "^4You have no access to this command!");
  468.        
  469.     new ManageMenu = menu_create("Choose an action:", "HandleManageAdmins");
  470.    
  471.     menu_additem(ManageMenu, "Add Online Admin");
  472.     menu_additem(ManageMenu, "Remove Offline Admin");
  473.     menu_additem(ManageMenu, "Edit Offline Admin");
  474.    
  475.     menu_display(id, ManageMenu);
  476.    
  477.     return 0;
  478. }
  479.  
  480. public HandleManageAdmins(id, ManageMenu, item)
  481. {
  482.     if(item == MENU_EXIT)
  483.     {
  484.         menu_destroy(ManageMenu);
  485.         return;
  486.     }
  487.    
  488.     switch(item)
  489.     {
  490.         case 0:
  491.         {
  492.             Adding[id] = true;
  493.             AddAdminMenu(id);
  494.         }
  495.         case 1: RemoveAdminMenu(id);
  496.         case 2:
  497.         {
  498.             Adding[id] = false;
  499.             EditAdminMenu(id);
  500.         }
  501.     }
  502. }
  503.  
  504. public AddAdminMenu(id)
  505. {
  506.     new Format[100];
  507.     new AddMenu = menu_create("Choose Admin Information:", "HandleAddAdminMenu");
  508.    
  509.     formatex(Format, charsmax(Format), "Player:\r %s", AdminName[id]);
  510.     menu_additem(AddMenu, Format);
  511.    
  512.    
  513.     formatex(Format, charsmax(Format), "Method:\r %s", AdminMethod[id]);
  514.     menu_additem(AddMenu, Format);
  515.    
  516.     formatex(Format, charsmax(Format), "Password (\d Name Only\w ):\r %s", AdminPassword[id]);
  517.     menu_additem(AddMenu, Format);
  518.    
  519.     formatex(Format, charsmax(Format), "Flags:\r %s", AdminAccess[id]);
  520.     menu_additem(AddMenu, Format);
  521.    
  522.     formatex(Format, charsmax(Format), "Time:\r %i\w Days", AdminTime[id]);
  523.     menu_additem(AddMenu, Format);
  524.    
  525.     formatex(Format, charsmax(Format), "\rAdd Admin!");
  526.     menu_additem(AddMenu, Format);
  527.    
  528.     menu_display(id, AddMenu);
  529.    
  530. }
  531.  
  532. public HandleAddAdminMenu(id, AddMenu, item)
  533. {
  534.     if(item == MENU_EXIT)
  535.     {
  536.         ManageAdmins(id);
  537.         return PLUGIN_HANDLED;
  538.     }
  539.    
  540.     switch(item)
  541.     {
  542.         case 0:
  543.         {
  544.             AddAdminMenuPlayers(id);
  545.         }
  546.        
  547.         case 1:
  548.         {
  549.             if(equali(AdminMethod[id], "Name"))
  550.                 AdminMethod[id] = "Steam ID";
  551.                
  552.             else if(equali(AdminMethod[id],  "Steam ID"))
  553.                 AdminMethod[id] = "IP Address";
  554.                
  555.             else
  556.                 AdminMethod[id] = "Name";
  557.         }
  558.        
  559.         case 2: client_cmd(id, "messagemode ^"TempAdmin_Password^"");
  560.         case 3: client_cmd(id, "messagemode ^"TempAdmin_Flags^"");
  561.         case 4: client_cmd(id, "messagemode ^"TempAdmin_Time^"");
  562.         case 5:
  563.         {
  564.             if(equali(AdminName[id], "") || equali(AdminID[id], "") || equali(AdminIP[id], "")  // No player selected.
  565.             || ( equali(AdminMethod[id], "Name") && equali(AdminPassword[id], "")) // No password when method is name.
  566.             || AdminTime[id] == 0 // Invalid time.
  567.             || equali(AdminAccess[id], "") // No flags
  568.             )
  569.             {
  570.                 AddAdminMenu(id);
  571.                
  572.                 return ColorChat(id, "You must fill all the required information!");
  573.             }
  574.            
  575.             if(equali(AdminMethod[id], "Name"))
  576.                 server_cmd("amx_addtempadmin ^"%s^" ^"%s^" ^"%i^" ^"%s^" ^"%s^"", AdminName[id], AdminAccess[id], AdminTime[id], AdminPassword[id], AdminName[id]);
  577.                
  578.             else if(equali(AdminMethod[id], "Steam ID"))
  579.                 server_cmd("amx_addtempadmin ^"%s^" ^"%s^" ^"%i^" ^"%s^"", AdminID[id], AdminAccess[id], AdminTime[id], AdminName[id]);
  580.                
  581.             else
  582.                 server_cmd("amx_addtempadmin ^"%s^" ^"%s^" ^"%i^" ^"%s^"", AdminIP[id], AdminAccess[id], AdminTime[id], AdminName[id]);
  583.                
  584.             ColorChat(id, "^4Admin^3 %s^1 was successfully^3 added^1!", AdminName[id]);
  585.         }  
  586.     }
  587.    
  588.     if(item != 0 && item != 5)
  589.         AddAdminMenu(id);
  590.        
  591.     return 0;
  592. }
  593.  
  594. public AddAdminMenuPlayers(id)
  595. {
  596.     new PlayersMenu = menu_create("Choose a player to give admin to:", "HandleAddAdminMenuPlayers");
  597.    
  598.     new players[32], num, InfoID[5];
  599.     get_players(players, num, "ch");
  600.    
  601.     for(new id;id < num;id++)
  602.     {
  603.         new i = players[id];
  604.        
  605.         if(is_user_admin(i))
  606.             continue;
  607.            
  608.         num_to_str(i, InfoID, charsmax(InfoID));
  609.         menu_additem(PlayersMenu, get_user_nick(i), InfoID);
  610.     }
  611.    
  612.     menu_display(id, PlayersMenu);
  613. }
  614.  
  615. public HandleAddAdminMenuPlayers(id, PlayersMenu, item)
  616. {
  617.     if(item == MENU_EXIT)
  618.     {
  619.         AddAdminMenu(id);
  620.         return;
  621.     }
  622.    
  623.     new access, info[5], name[32], callback;
  624.     menu_item_getinfo(PlayersMenu, item, access, info, charsmax(info), name, charsmax(name), callback);
  625.    
  626.     new target = str_to_num(info);
  627.    
  628.     if(!is_user_connected(target))
  629.         return;
  630.        
  631.     AdminName[id] = get_user_nick(target);
  632.     AdminID[id] = get_user_steamid(target);
  633.     AdminIP[id] = get_user_address(target);
  634.    
  635.     AddAdminMenu(id);
  636. }
  637. public RemoveAdminMenu(id)
  638. {
  639.     if(!(get_user_flags(id) & ADMIN_RCON))
  640.         return ColorChat(id, "^4You have no access to this command!");
  641.  
  642.     new RemoveMenu = menu_create("List of admins:", "HandleRemoveAdminMenu");
  643.    
  644.     new ReadFile[300], Token[7][300], Line, Length, Format[240], Num;
  645.    
  646.     while(read_file(AdminsDir, Line++, ReadFile, charsmax(ReadFile), Length))
  647.     {
  648.         if(!read_file(AdminsDir, Line, ReadFile, charsmax(ReadFile), Length)) break;
  649.            
  650.         parse(ReadFile, Token[0], 231, Token[1], 231, Token[2], 231, Token[3], 231, Token[4], 231, Token[5], 231, Token[6], 231);
  651.        
  652.         if(strfind(Token[4], ";Expiration(") == -1) continue;
  653.  
  654.         new DaysLeft = ( ( str_to_num(Token[5]) - get_systime() ) / Day ) + 1;
  655.        
  656.         new DisplayName[50];
  657.        
  658.         if(strcmp(Token[6], "") != 0)
  659.             formatex(DisplayName, charsmax(DisplayName), Token[6]);
  660.         else
  661.             formatex(DisplayName, charsmax(DisplayName), Token[0]);
  662.            
  663.         formatex(Format, charsmax(Format), "%s - %i Days Left", DisplayName, DaysLeft);
  664.        
  665.         menu_additem(RemoveMenu, Format, ReadFile);
  666.    
  667.         Num++;
  668.     }      
  669.        
  670.     if(Num > 0)
  671.         menu_display(id, RemoveMenu);
  672.     else
  673.         return ColorChat(id, "^4There are no temporary admins in the server.");
  674.        
  675.     return 0;
  676. }
  677.  
  678. // The Handler for RemoveAdmins(id). Used for editing the temporary admins.
  679.  
  680. public HandleRemoveAdminMenu(id, RemoveMenu, item)
  681. {
  682.     if(item == MENU_EXIT)
  683.     {
  684.         ManageAdmins(id);
  685.         return;
  686.     }
  687.    
  688.     new access, info[300], name[32], callback;
  689.     menu_item_getinfo(RemoveMenu, item, access, info, charsmax(info), name, charsmax(name), callback);
  690.    
  691.     new ReadFile[300],  Line, Length;
  692.    
  693.     while(read_file(AdminsDir, Line++, ReadFile, charsmax(ReadFile), Length))
  694.     {
  695.         if(!read_file(AdminsDir, Line, ReadFile, charsmax(ReadFile), Length)) break;
  696.        
  697.         if(strcmp(ReadFile, info) == 0)
  698.         {
  699.             write_file(AdminsDir, "", Line);
  700.             break;
  701.         }
  702.     }
  703.    
  704. }  
  705.  
  706. public EditAdminMenu(id)
  707. {
  708.     if(!(get_user_flags(id) & ADMIN_RCON))
  709.         return ColorChat(id, "^4You have no access to this command!");
  710.  
  711.     new EditMenu = menu_create("List of admins:", "HandleEditAdminMenu");
  712.    
  713.     new ReadFile[300], Token[7][40], Line, Length, Format[240], Num;
  714.    
  715.     while(read_file(AdminsDir, Line++, ReadFile, charsmax(ReadFile), Length))
  716.     {
  717.         if(!read_file(AdminsDir, Line, ReadFile, charsmax(ReadFile), Length)) break;
  718.            
  719.         parse(ReadFile, Token[0], 39, Token[1], 39, Token[2], 39, Token[3], 39, Token[4], 39, Token[5], 39, Token[6], 39);
  720.    
  721.         if(strfind(Token[4], ";Expiration(") == -1) continue;
  722.        
  723.        
  724.         new DaysLeft = ( ( str_to_num(Token[5]) - get_systime() ) / Day ) + 1;
  725.        
  726.         new DisplayName[50];
  727.                
  728.         if(strcmp(Token[6], "") != 0)
  729.             formatex(DisplayName, charsmax(DisplayName), Token[6]);
  730.         else
  731.             formatex(DisplayName, charsmax(DisplayName), Token[0]);
  732.        
  733.         formatex(Format, charsmax(Format), "%s - %i Days Left", DisplayName, DaysLeft);
  734.        
  735.         menu_additem(EditMenu, Format, ReadFile);
  736.    
  737.         Num++;
  738.     }      
  739.        
  740.     if(Num > 0)
  741.         menu_display(id, EditMenu);
  742.     else
  743.         return ColorChat(id, "^4There are no temporary admins in the server.");
  744.        
  745.     return 0;
  746. }
  747.  
  748. public HandleEditAdminMenu(id, EditMenu, item)
  749. {
  750.     if(item == MENU_EXIT)
  751.     {
  752.         ManageAdmins(id);
  753.         return;
  754.     }
  755.    
  756.     new access, info[300], name[32], callback;
  757.     menu_item_getinfo(EditMenu, item, access, info, charsmax(info), name, charsmax(name), callback);
  758.    
  759.     EditPlayerAdminMenu(id, info);
  760. }
  761.  
  762. EditPlayerAdminMenu(id, info[300] = "Invalid")
  763. {
  764.     new Format[100], Token[7][40];
  765.    
  766.     if(!equali(info, "Invalid"))
  767.     {
  768.         parse(info, Token[0], 39, Token[1], 39, Token[2], 39, Token[3], 39, Token[4], 39, Token[5], 39, Token[6], 39);
  769.        
  770.            
  771.         new DaysLeft = ( ( str_to_num(Token[5]) - get_systime() ) / Day ) + 1;
  772.    
  773.         AdminID[id] = Token[0];
  774.         AdminPassword[id] = Token[1];
  775.         AdminAccess[id] = Token[2];
  776.         AdminTime[id] = DaysLeft;
  777.         AdminName[id] = Token[6];
  778.         AdminInfo[id] = info;
  779.        
  780.         if(strcmp(Token[6], "") != 0)
  781.             formatex(Format, charsmax(Format), "Editing %s's Admin:", Token[6]);
  782.            
  783.         else
  784.             formatex(Format, charsmax(Format), "Editing %s's Admin:", Token[0]);
  785.     }
  786.     else
  787.     {
  788.         if(strcmp(AdminName[id], "") != 0)
  789.             formatex(Format, charsmax(Format), "Editing %s's Admin:", AdminName[id]);
  790.            
  791.         else
  792.             formatex(Format, charsmax(Format), "Editing %s's Admin:", AdminID[id]);
  793.     }
  794.     new EditPlayerMenu = menu_create(Format, "HandleEditPlayerAdminMenu");
  795.    
  796.     if(strcmp(AdminPassword[id], "") != 0)
  797.     {
  798.         formatex(Format, charsmax(Format), "Password: %s", AdminPassword[id]);
  799.         menu_additem(EditPlayerMenu, Format);
  800.     }
  801.     formatex(Format, charsmax(Format), "Flags: %s", AdminAccess[id]);
  802.     menu_additem(EditPlayerMenu, Format);
  803.    
  804.     formatex(Format, charsmax(Format), "Time: %i Days", AdminTime[id]);
  805.     menu_additem(EditPlayerMenu, Format);
  806.    
  807.     formatex(Format, charsmax(Format), "Display Name ( Optional ): %s", AdminName[id]);
  808.     menu_additem(EditPlayerMenu, Format);
  809.    
  810.     formatex(Format, charsmax(Format), "Complete Editing!");
  811.     menu_additem(EditPlayerMenu, Format);
  812.    
  813.     menu_display(id, EditPlayerMenu);
  814. }
  815.  
  816. public HandleEditPlayerAdminMenu(id, EditPlayerMenu, item)
  817. {
  818.     if(item == MENU_EXIT)
  819.     {
  820.         EditAdminMenu(id);
  821.         return;
  822.     }
  823.     new ReadFile[300], Token[7][300], Line, Length, Influence[100], Format[300];
  824.    
  825.     new Result = item;
  826.     if(strcmp(AdminPassword[id], "") == 0) Result++;
  827.    
  828.     switch(Result)
  829.     {
  830.         case 0: client_cmd(id, "messagemode ^"TempAdmin_Password^"");
  831.         case 1: client_cmd(id, "messagemode ^"TempAdmin_Flags^"");
  832.         case 2: client_cmd(id, "messagemode ^"TempAdmin_Time^"");
  833.         case 3: client_cmd(id, "messagemode ^"TempAdmin_Name^"");
  834.        
  835.     }  
  836.     if(Result != 4)
  837.     {
  838.         EditPlayerAdminMenu(id);
  839.         return;
  840.     }
  841.        
  842.     while(read_file(AdminsDir, Line++, ReadFile, charsmax(ReadFile), Length))
  843.     {
  844.         if(!read_file(AdminsDir, Line, ReadFile, charsmax(ReadFile), Length)) break;
  845.        
  846.         parse(ReadFile, Token[0], 231, Token[1], 231, Token[2], 231, Token[3], 231, Token[4], 231, Token[5], 231, Token[6], 231);
  847.        
  848.         if(strcmp(ReadFile, "") == 0) continue;
  849.        
  850.         if(strcmp(ReadFile, AdminInfo[id]) == 0)
  851.         {
  852.             formatex(Token[1], 231, AdminPassword[id]);
  853.             formatex(Token[2], 231, AdminAccess[id]);
  854.            
  855.             new DaysLeft = ( ( str_to_num(Token[5]) - get_systime() ) / Day ) + 1;
  856.            
  857.             formatex(Influence, charsmax(Influence), ";Expiration(%i Days):", DaysLeft);
  858.        
  859.             replace(Token[4], 231, Token[4], Influence);
  860.            
  861.             formatex(Token[6], 231, AdminName[id]);
  862.            
  863.             new DisplayName[32];
  864.             if(strcmp(Token[6], "") != 0)
  865.                 formatex(DisplayName, charsmax(DisplayName), Token[6]);
  866.                
  867.             else
  868.                 formatex(DisplayName, charsmax(DisplayName), Token[0]);
  869.             /*
  870.             new Loop = 6;
  871.            
  872.             if(strcmp(Token[6], "") != 0)
  873.                 Loop = 7;
  874.             */
  875.             formatex(ReadFile, 0, "");
  876.            
  877.             for(new i;i < 7;i++)
  878.             {
  879.                 formatex(Format, charsmax(Format), "^"%s^" ", Token[i]);
  880.                
  881.                 add(ReadFile, charsmax(ReadFile), Format);
  882.             }
  883.            
  884.             write_file(AdminsDir, "", Line); // Some weird bug, Idunno...
  885.            
  886.             write_file(AdminsDir, ReadFile, Line);
  887.            
  888.             ColorChat(id, "^4Admin^3 %s^1 was successfully^3 edited^1!", DisplayName);
  889.            
  890.             break;
  891.         }
  892.     }
  893.    
  894.    
  895. }
  896.  
  897. public EditPassword(id)
  898. {
  899.     new Arg[30];
  900.     read_args(Arg, charsmax(Arg));
  901.    
  902.     remove_quotes(Arg);
  903.    
  904.    
  905.     AdminPassword[id] = Arg;
  906.    
  907.     if(Adding[id])
  908.         AddAdminMenu(id);
  909.    
  910.     else
  911.         EditPlayerAdminMenu(id);
  912.    
  913.     return 1;
  914. }
  915.  
  916. public EditFlags(id)
  917. {
  918.     new Arg[30];
  919.     read_args(Arg, charsmax(Arg));
  920.    
  921.     remove_quotes(Arg);
  922.    
  923.     if(containi(Arg, "l") != -1)
  924.     {
  925.         replace(Arg, charsmax(Arg), "l", "");
  926.         ColorChat(id, "^3Flags^1 may not have^4 Rcon^1 access. The^4 Rcon^1 flag was removed.");
  927.     }
  928.    
  929.     AdminAccess[id] = Arg;
  930.    
  931.     if(Adding[id])
  932.         AddAdminMenu(id);
  933.    
  934.     else
  935.         EditPlayerAdminMenu(id);
  936.        
  937.     return 1;
  938. }
  939.  
  940. public EditTime(id)
  941. {
  942.     new Arg[30];
  943.     read_args(Arg, charsmax(Arg));
  944.    
  945.     remove_quotes(Arg);
  946.    
  947.     if(!is_str_num(Arg))
  948.     {
  949.        
  950.         if(Adding[id])
  951.             AddAdminMenu(id);
  952.    
  953.         else
  954.             EditPlayerAdminMenu(id);
  955.        
  956.         return ColorChat(id, "^3Time^1 must only contain^4 numbers^1!");
  957.     }
  958.    
  959.     AdminTime[id] = str_to_num(Arg);
  960.    
  961.     if(Adding[id])
  962.         AddAdminMenu(id);
  963.    
  964.     else
  965.         EditPlayerAdminMenu(id);
  966.    
  967.     return 1;
  968. }
  969.  
  970. public EditName(id)
  971. {
  972.     new Arg[30];
  973.     read_args(Arg, charsmax(Arg));
  974.    
  975.     remove_quotes(Arg);
  976.    
  977.    
  978.     AdminName[id] = Arg;
  979.    
  980.     if(Adding[id])
  981.         AddAdminMenu(id);
  982.     else
  983.         EditPlayerAdminMenu(id);
  984.    
  985.     return 1;
  986. }
  987.  
  988.  
  989. stock get_user_steamid(index)
  990. {
  991.     new SteamID[32];
  992.     get_user_authid(index, SteamID, charsmax(SteamID));
  993.    
  994.     return SteamID;
  995. }
  996.  
  997. stock get_user_nick(index)
  998. {
  999.     new Name[32];
  1000.     get_user_name(index, Name, charsmax(Name));
  1001.    
  1002.     return Name;
  1003. }
  1004.  
  1005. stock get_user_address(index)
  1006. {
  1007.     new IP[32];
  1008.     get_user_ip(index, IP, charsmax(IP), 1);
  1009.    
  1010.     return IP;
  1011. }  
  1012.  
  1013. stock ColorChat(const index, const string[], {Float, Sql, Resul,_}:...)
  1014. {
  1015.     new msg[191], players[32], count = 1, PREFIX[32];
  1016.    
  1017.     get_cvar_string("amx_prefix_cvar", PREFIX, charsmax(PREFIX));
  1018.    
  1019.     static len;
  1020.     len = formatex(msg, charsmax(msg), "^3(^4 %s^3 )^1 ", PREFIX);
  1021.     vformat(msg[len], charsmax(msg) - len, string, 3);
  1022.    
  1023.     if(index)    players[0] = index;
  1024.     else    get_players(players,count,"ch");
  1025.    
  1026.     for (new i = 0; i < count; i++)
  1027.     {
  1028.         if(is_user_connected(players[i]))
  1029.         {
  1030.             message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"),_, players[i]);
  1031.             write_byte(players[i]);
  1032.             write_string(msg);
  1033.             message_end();
  1034.         }
  1035.     }
  1036.    
  1037.     return 1;
  1038. }
Add Comment
Please, Sign In to add comment