Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Temporary Admin by FuckTheSchool ( Eyal282 )
- Changelog:
- v1.0: Release of plugin.
- v1.1: Bug fixes and add of amx_removetempadmin and amx_edittempadmin.
- v1.2: Fixed amx_removetempadmin and amx_edittempadmin bugs.
- Added /managetemp to show a list of offline temporary admins, for easier access to the commands.
- v1.3: Added ability to type on flags: Manager, SuperAdmin, Admin, VIP.
- v1.4: Fixed major bugs that allow use of command only on name. Change of the word "Syntax" to "Usage".
- Changed use of get_time to get_systime to make the plugin more efficient.
- v1.5: Covered all major bugs related to time after v1.4.
- v1.6: More major issues to trash. Fixed /adminstatus for permanent rcon admins.
- Fixed amx_removetempadmin and amx_edittempadmin.
- v1.7: Disconnect the plugin from being dependant on a seperate users.ini to prevent errors.
- This means users.ini is going to get twice as messy.. An idiotic miss spell was corrected.
- Fixed an added player online not able to do /adminstatus. Added a define for the taskid of UpdateTimes.
- v1.8: /managetemp became 3 times more efficient. Fixed a major bug related to v1.7
- amx_edittempadmin now has access to edit access flags. Added "display name" to make /managetemp more efficient.
- /managetemp has more power than the console commands.
- v1.9: Fixed annoying bugs related to since v1.7. Plugin became much more stable.
- */
- #include <amxmodx>
- #include <amxmisc>
- #pragma semicolon 1
- #define PLUGIN "Temporary Admin"
- #define VERSION "1.9"
- #define AUTHOR "FuckTheSchool ( Eyal282 )" // I took something small from the plugin xRedirect but rest is my work.
- #define Day1 (60 * 60 * 24) // Define is a waste of resources yet it is comfortable.
- #define ManagerFlags1 "bcdefghijkmnopqrstu"
- #define SuperAdminFlags1 "cdefghijkmnopqrstu"
- #define AdminFlags1 "cefgijmnopqrstu"
- #define VIPFlags1 "ceijp"
- #define TASKID_UpdateTimes1 349587345
- new Day = Day1;
- new const ManagerFlags[] = ManagerFlags1, SuperAdminFlags[] = SuperAdminFlags1;
- new const AdminFlags[] = AdminFlags1, VIPFlags[] = VIPFlags1;
- new AdminsDir[200], aStatus[33], bool:Messaged[33];
- 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];
- new TASKID_UpdateTimes = TASKID_UpdateTimes1;
- public plugin_init()
- {
- register_plugin(PLUGIN, VERSION, AUTHOR);
- 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.
- register_concmd("amx_removetempadmin", "RemoveAdmin", ADMIN_RCON, "Usage: amx_removetempadmin <name/^"steamid^"/ip>");
- register_concmd("amx_edittempadmin", "EditAdmin", ADMIN_RCON, "Usage: amx_edittempadmin <name/^"steamid^"/ip> <days> [display name]");
- register_clcmd("say", "TimeLeft");
- register_clcmd("say /managetemp", "ManageAdmins");
- register_clcmd("TempAdmin_Password", "EditPassword");
- register_clcmd("TempAdmin_Flags", "EditFlags");
- register_clcmd("TempAdmin_Time", "EditTime");
- register_clcmd("TempAdmin_Name", "EditName");
- register_cvar("amx_prefix_cvar", "PREFIX");
- }
- public plugin_cfg()
- {
- new Dir[200];
- get_configsdir(Dir, charsmax(Dir));
- formatex(AdminsDir, charsmax(AdminsDir), "%s/users.ini", Dir);
- if(!file_exists(AdminsDir))
- 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.");
- set_task(0.5, "UpdateTimes", TASKID_UpdateTimes);
- }
- // This updates expiration days in file, for more comfortable access through the file.
- public UpdateTimes()
- {
- new ReadFile[300], Token[7][300], Line, Length, Format[240], Smallest = -1;
- while(read_file(AdminsDir, Line++, ReadFile, charsmax(ReadFile), Length))
- {
- if(!read_file(AdminsDir, Line, ReadFile, charsmax(ReadFile), Length))
- break;
- parse(ReadFile, Token[0], 231, Token[1], 231, Token[2], 231, Token[3], 231, Token[4], 231, Token[5], 231, Token[6], 231);
- if(strfind(Token[4], ";Expiration(") == -1) continue;
- new Influence[100], Tok[100], ReadFileView[232];
- new DaysLeft = ( ( str_to_num(Token[5]) - get_systime() ) / Day ) + 1;
- formatex(ReadFileView, charsmax(ReadFileView), ReadFile);
- formatex(Influence, charsmax(Influence), ";Expiration(%i Days):", DaysLeft);
- replace(Token[4], 231, Token[4], Influence);
- formatex(ReadFile, charsmax(ReadFile), "");
- /*
- new Loop = 6;
- if(strcmp(Token[6], "") == 0)
- Loop = 7;
- */
- for(new i;i < 7;i++)
- {
- formatex(Format, charsmax(Format), "^"%s^"%s", Token[i], i == 7 - 1 ? "" : " ");
- add(ReadFile, charsmax(ReadFile), Format);
- }
- formatex(Tok, charsmax(Tok), Token[0]);
- write_file(AdminsDir, DaysLeft > 0 ? ReadFile : "", Line);
- if( ( Smallest > DaysLeft || Smallest == -1 ) && DaysLeft > 0 ) Smallest = DaysLeft;
- }
- new players[32], num;
- get_players(players, num, "ch");
- for(new id;id < num;id++) // Refreshing connected
- {
- new i = players[id];
- aStatus[i] = -1;
- set_task(6.0, "CheckTemp", i);
- }
- if(Smallest != -1)
- {
- remove_task(TASKID_UpdateTimes);
- set_task(float(Smallest * Day), "UpdateTimes");
- }
- server_cmd("amx_reloadadmins");
- }
- // Here we will prohibit the player from /adminstatus'ing himself until we check if he's an admin & temporary admin.
- public client_putinserver(id)
- {
- aStatus[id] = -1;
- AdminMethod[id] = "Name";
- AdminTime[id] = 0;
- AdminPassword[id] = "";
- Messaged[id] = false;
- set_task(1.0, "CheckTemp", id);
- }
- // Here we set the user's amount of expiration days for /adminstatus.
- public CheckTemp(id)
- {
- if(!is_user_admin(id))
- return;
- new ReadFile[232], Token[6][232], Line, Length;
- while(read_file(AdminsDir, Line++, ReadFile, charsmax(ReadFile), Length))
- {
- if(!read_file(AdminsDir, Line, ReadFile, charsmax(ReadFile), Length)) break;
- if(ReadFile[0] == ';' || strcmp(ReadFile, "") == 0) continue;
- parse(ReadFile, Token[0], 231, Token[1], 231, Token[2], 231, Token[3], 231, Token[4], 231, Token[5], 231);
- if(strfind(Token[4], ";Expiration(") == -1) continue;
- 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)
- {
- new DaysLeft = ( ( str_to_num(Token[5]) - get_systime() ) / Day ) + 1;
- if(DaysLeft <= 0)
- {
- write_file(AdminsDir, "", Line);
- }
- if(DaysLeft > 0) aStatus[id] = DaysLeft, set_task(10.0, "DidYouKnow", id);
- break;
- }
- }
- }
- // This one will inform the temporary admin that he is a temporary admin with a limit of time, if he wasn't messaged already.
- public DidYouKnow(id) if(!Messaged[id]) ColorChat(id, "^4You can check when will your admin status expire by typing^3 /adminstatus"), Messaged[id] = true;
- // This will be called when an admin tries to add a temporary admin.
- public AddAdmin(id, level, cid)
- {
- if(!cmd_access(id, level, cid, 1))
- return PLUGIN_HANDLED;
- new Message[200], Token[5][200], Type, TempCheck[20], TompChock; // Type 0 = SID, Type 1 = IP, Type 2 = Name.
- read_args(Message, charsmax(Message));
- parse(Message, Token[0], 199, Token[1], 199, Token[2], 199, Token[3], 199, Token[4], 199);
- remove_quotes(Message);
- formatex(TempCheck, charsmax(TempCheck), Token[0]); // Maybe IP.
- while(containi(TempCheck, ".") != -1)
- {
- replace(TempCheck, charsmax(TempCheck), ".", "");
- TompChock++;
- }
- if(!is_str_num(Token[2]))
- return client_print(id, print_console, "Usage: amx_addtempadmin <name/^"steamid^"/ip> <flags> <days> <password>");
- if(equali(Token[1], "Manager")) replace(Token[1], 199, Token[1], ManagerFlags);
- else if(equali(Token[1], "SuperAdmin")) replace(Token[1], 199, Token[1], SuperAdminFlags);
- else if(equali(Token[1], "Admin")) replace(Token[1], 199, Token[1], AdminFlags);
- else if(equali(Token[1], "VIP")) replace(Token[1], 199, Token[1], VIPFlags);
- if(containi(Token[1], "l") != -1)
- return client_print(id, print_console, "Admins with rcon access ( l ) are able to set themselves and others as permanent admins.");
- new WriteFile[200];
- new Combat = get_systime() + ( str_to_num(Token[2]) * Day );
- if(contain(Token[0], "STEAM_") != -1 || contain(Token[0], "VALVE_") != -1)
- Type = 0;
- else if(is_str_num(TempCheck) && TompChock == 3)
- Type = 1;
- else
- Type = 2;
- new DisplayName[50];
- switch(Type)
- {
- case 0:
- {
- if(equali(Token[1], "") || equali(Token[2], ""))
- return client_print(id, print_console, "Usage: amx_addtempadmin <^"steamid^"> <flags> <days> [display name]");
- formatex(WriteFile, charsmax(WriteFile), "^n^"%s^" ^"^" ^"%s^" ^"ce^" ;^"Expiration(%i Days):^" ^"%i^"", Token[0], Token[1], str_to_num(Token[2]), Combat);
- }
- case 1:
- {
- if(equali(Token[1], "") || equali(Token[2], ""))
- return client_print(id, print_console, "Usage: amx_addtempadmin <ip> <flags> <days> [display name]");
- formatex(WriteFile, charsmax(WriteFile), "^n^"%s^" ^"^" ^"%s^" ^"de^" ;^"Expiration(%i Days):^" ^"%i^"", Token[0], Token[1], str_to_num(Token[2]), Combat);
- }
- case 2:
- {
- if(equali(Token[1], "") || equali(Token[2], "") || equali(Token[3], ""))
- return client_print(id, print_console, "Usage: amx_addtempadmin <name> <flags> <days> <password>");
- if(strcmp(Token[4], "") != 0)
- formatex(DisplayName, charsmax(DisplayName), " ^"%s^"", Token[4]);
- 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);
- }
- }
- DisplayName = "";
- if(strcmp(Token[4], "") != 0 && Type == 2)
- formatex(DisplayName, charsmax(DisplayName), " ^"%s^"", Token[4]);
- else if(strcmp(Token[3], "") != 0 && Type != 2)
- formatex(DisplayName, charsmax(DisplayName), " ^"%s^"", Token[3]);
- add(WriteFile, charsmax(WriteFile), DisplayName);
- write_file(AdminsDir, WriteFile);
- server_cmd("amx_reloadadmins");
- remove_task(TASKID_UpdateTimes);
- set_task(1.0, "UpdateTimes", TASKID_UpdateTimes);
- return client_print(id, print_console, "%s was added successfully", Token[0]);
- }
- // This will be called when an admin tries to remove a temporary admin.
- public RemoveAdmin(id, level, cid)
- {
- if(!cmd_access(id, level, cid, 1))
- return PLUGIN_HANDLED;
- new Message[200], Token[2][200]; // Type 0 = SID, Type 1 = IP, Type 2 = Name.
- read_args(Message, charsmax(Message));
- parse(Message, Token[0], 199, Token[1], 199);
- remove_quotes(Token[0]);
- new ReadFile[300], Line, Length, Toke[6][300];
- while(read_file(AdminsDir, Line++, ReadFile, charsmax(ReadFile), Length))
- {
- if(!read_file(AdminsDir, Line, ReadFile, charsmax(ReadFile), Length)) return client_print(id, print_console, "%s was not found!", Token[0]);
- parse(ReadFile, Toke[0], 199, Toke[1], 199, Toke[2], 199, Toke[3], 199, Toke[4], 199, Toke[5], 199);
- if(ReadFile[0] == ';' || strcmp(ReadFile, "") == 0 || strfind(Toke[4], ";Expiration(") == -1) continue;
- if(strcmp(Token[0], Toke[0]) == 0)
- {
- new Tok[100];
- formatex(Tok, charsmax(Tok), Token[0]);
- write_file(AdminsDir, "", Line);
- break;
- }
- }
- server_cmd("amx_reloadadmins");
- remove_task(TASKID_UpdateTimes);
- set_task(1.0, "UpdateTimes", TASKID_UpdateTimes);
- return client_print(id, print_console, "%s was removed successfully", Token[0]);
- }
- // This will be called when an admin tries to edit a temporary admin's time left.
- public EditAdmin(id, level, cid)
- {
- if(!cmd_access(id, level, cid, 1))
- return PLUGIN_HANDLED;
- new Message[200], Token[3][200]; // Type 0 = SID, Type 1 = IP, Type 2 = Name.
- read_args(Message, charsmax(Message));
- parse(Message, Token[0], 199, Token[1], 199, Token[2], 199);
- remove_quotes(Token[0]);
- if(!is_str_num(Token[1]))
- return client_print(id, print_console, "Usage: amx_edittempadmin <name/^"steamid^"/ip> <days> [display name]");
- new TempToken = str_to_num(Token[1]);
- new Combat = get_systime() + ( Day * TempToken );
- new players[32], num;
- get_players(players, num, "ch");
- new ReadFile[232], Toke[7][232], Line, Format[325], Length;
- while(read_file(AdminsDir, Line++, ReadFile, charsmax(ReadFile), Length))
- {
- if(!read_file(AdminsDir, Line, ReadFile, charsmax(ReadFile), Length)) return client_print(id, print_console, "%s was not found!", Token[0]);
- parse(ReadFile, Toke[0], 231, Toke[1], 231, Toke[2], 231, Toke[3], 231, Toke[4], 231, Toke[5], 231, Toke[6], 231);
- if(ReadFile[0] == ';' || strcmp(ReadFile, "") == 0 || strfind(Toke[4], ";Expiration(") == -1) continue;
- if(strcmp(Token[0], Toke[0]) == 0)
- {
- new Tok[100], ReadFileView[232];
- formatex(ReadFileView, charsmax(ReadFileView), ReadFile);
- formatex(ReadFile, charsmax(ReadFile), "");
- formatex(Toke[5], 199, "%i", Combat);
- if(strcmp(Token[2], "") != 0)
- formatex(Toke[2], 199, Token[2]);
- /*
- new Loop = 6;
- if(strcmp(Toke[6], "") == 0)
- Loop = 7;
- */
- for(new i;i < 7;i++)
- {
- formatex(Format, charsmax(Format), "^"%s^" ", Toke[i]);
- add(ReadFile, charsmax(ReadFile), Format);
- }
- formatex(Tok, charsmax(Tok), Toke[0]);
- write_file(AdminsDir, ReadFile, Line);
- break;
- }
- }
- server_cmd("amx_reloadadmins");
- remove_task(TASKID_UpdateTimes);
- set_task(1.0, "UpdateTimes", TASKID_UpdateTimes);
- return client_print(id, print_console, "%s was edited successfully!", Token[0]);
- }
- public TimeLeft(id)
- {
- new Message[100], Command[50], TargetArg[50];
- read_argv(1, Message, charsmax(Message));
- parse(Message, Command, charsmax(Command), TargetArg, charsmax(TargetArg));
- if(equali(Command, "/adminstatus"))
- {
- if(aStatus[id] != -1)
- return ColorChat(id, "^4Your temporary admin will expire in %i Days.", aStatus[id]);
- else if(!(get_user_flags(id) & ADMIN_RCON))
- return ColorChat(id, "^4You have no access to this command!");
- new Target = cmd_target(id, TargetArg, 0);
- if(!Target) return ColorChat(id, "^4Player was not found.");
- else if(!is_user_admin(Target)) return ColorChat(id, "^4This user is not an admin.");
- else if(aStatus[Target] == -1) return ColorChat(id, "^4This user is a permanent admin.");
- return ColorChat(id, "^4%s has %i Days left for his admin.", get_user_nick(Target), aStatus[Target]);
- }
- return 0;
- }
- // Here the function will create a menu for the player to easily access the admins and add.
- public ManageAdmins(id)
- {
- if(!(get_user_flags(id) & ADMIN_RCON))
- return ColorChat(id, "^4You have no access to this command!");
- new ManageMenu = menu_create("Choose an action:", "HandleManageAdmins");
- menu_additem(ManageMenu, "Add Online Admin");
- menu_additem(ManageMenu, "Remove Offline Admin");
- menu_additem(ManageMenu, "Edit Offline Admin");
- menu_display(id, ManageMenu);
- return 0;
- }
- public HandleManageAdmins(id, ManageMenu, item)
- {
- if(item == MENU_EXIT)
- {
- menu_destroy(ManageMenu);
- return;
- }
- switch(item)
- {
- case 0:
- {
- Adding[id] = true;
- AddAdminMenu(id);
- }
- case 1: RemoveAdminMenu(id);
- case 2:
- {
- Adding[id] = false;
- EditAdminMenu(id);
- }
- }
- }
- public AddAdminMenu(id)
- {
- new Format[100];
- new AddMenu = menu_create("Choose Admin Information:", "HandleAddAdminMenu");
- formatex(Format, charsmax(Format), "Player:\r %s", AdminName[id]);
- menu_additem(AddMenu, Format);
- formatex(Format, charsmax(Format), "Method:\r %s", AdminMethod[id]);
- menu_additem(AddMenu, Format);
- formatex(Format, charsmax(Format), "Password (\d Name Only\w ):\r %s", AdminPassword[id]);
- menu_additem(AddMenu, Format);
- formatex(Format, charsmax(Format), "Flags:\r %s", AdminAccess[id]);
- menu_additem(AddMenu, Format);
- formatex(Format, charsmax(Format), "Time:\r %i\w Days", AdminTime[id]);
- menu_additem(AddMenu, Format);
- formatex(Format, charsmax(Format), "\rAdd Admin!");
- menu_additem(AddMenu, Format);
- menu_display(id, AddMenu);
- }
- public HandleAddAdminMenu(id, AddMenu, item)
- {
- if(item == MENU_EXIT)
- {
- ManageAdmins(id);
- return PLUGIN_HANDLED;
- }
- switch(item)
- {
- case 0:
- {
- AddAdminMenuPlayers(id);
- }
- case 1:
- {
- if(equali(AdminMethod[id], "Name"))
- AdminMethod[id] = "Steam ID";
- else if(equali(AdminMethod[id], "Steam ID"))
- AdminMethod[id] = "IP Address";
- else
- AdminMethod[id] = "Name";
- }
- case 2: client_cmd(id, "messagemode ^"TempAdmin_Password^"");
- case 3: client_cmd(id, "messagemode ^"TempAdmin_Flags^"");
- case 4: client_cmd(id, "messagemode ^"TempAdmin_Time^"");
- case 5:
- {
- if(equali(AdminName[id], "") || equali(AdminID[id], "") || equali(AdminIP[id], "") // No player selected.
- || ( equali(AdminMethod[id], "Name") && equali(AdminPassword[id], "")) // No password when method is name.
- || AdminTime[id] == 0 // Invalid time.
- || equali(AdminAccess[id], "") // No flags
- )
- {
- AddAdminMenu(id);
- return ColorChat(id, "You must fill all the required information!");
- }
- if(equali(AdminMethod[id], "Name"))
- server_cmd("amx_addtempadmin ^"%s^" ^"%s^" ^"%i^" ^"%s^" ^"%s^"", AdminName[id], AdminAccess[id], AdminTime[id], AdminPassword[id], AdminName[id]);
- else if(equali(AdminMethod[id], "Steam ID"))
- server_cmd("amx_addtempadmin ^"%s^" ^"%s^" ^"%i^" ^"%s^"", AdminID[id], AdminAccess[id], AdminTime[id], AdminName[id]);
- else
- server_cmd("amx_addtempadmin ^"%s^" ^"%s^" ^"%i^" ^"%s^"", AdminIP[id], AdminAccess[id], AdminTime[id], AdminName[id]);
- ColorChat(id, "^4Admin^3 %s^1 was successfully^3 added^1!", AdminName[id]);
- }
- }
- if(item != 0 && item != 5)
- AddAdminMenu(id);
- return 0;
- }
- public AddAdminMenuPlayers(id)
- {
- new PlayersMenu = menu_create("Choose a player to give admin to:", "HandleAddAdminMenuPlayers");
- new players[32], num, InfoID[5];
- get_players(players, num, "ch");
- for(new id;id < num;id++)
- {
- new i = players[id];
- if(is_user_admin(i))
- continue;
- num_to_str(i, InfoID, charsmax(InfoID));
- menu_additem(PlayersMenu, get_user_nick(i), InfoID);
- }
- menu_display(id, PlayersMenu);
- }
- public HandleAddAdminMenuPlayers(id, PlayersMenu, item)
- {
- if(item == MENU_EXIT)
- {
- AddAdminMenu(id);
- return;
- }
- new access, info[5], name[32], callback;
- menu_item_getinfo(PlayersMenu, item, access, info, charsmax(info), name, charsmax(name), callback);
- new target = str_to_num(info);
- if(!is_user_connected(target))
- return;
- AdminName[id] = get_user_nick(target);
- AdminID[id] = get_user_steamid(target);
- AdminIP[id] = get_user_address(target);
- AddAdminMenu(id);
- }
- public RemoveAdminMenu(id)
- {
- if(!(get_user_flags(id) & ADMIN_RCON))
- return ColorChat(id, "^4You have no access to this command!");
- new RemoveMenu = menu_create("List of admins:", "HandleRemoveAdminMenu");
- new ReadFile[300], Token[7][300], Line, Length, Format[240], Num;
- while(read_file(AdminsDir, Line++, ReadFile, charsmax(ReadFile), Length))
- {
- if(!read_file(AdminsDir, Line, ReadFile, charsmax(ReadFile), Length)) break;
- parse(ReadFile, Token[0], 231, Token[1], 231, Token[2], 231, Token[3], 231, Token[4], 231, Token[5], 231, Token[6], 231);
- if(strfind(Token[4], ";Expiration(") == -1) continue;
- new DaysLeft = ( ( str_to_num(Token[5]) - get_systime() ) / Day ) + 1;
- new DisplayName[50];
- if(strcmp(Token[6], "") != 0)
- formatex(DisplayName, charsmax(DisplayName), Token[6]);
- else
- formatex(DisplayName, charsmax(DisplayName), Token[0]);
- formatex(Format, charsmax(Format), "%s - %i Days Left", DisplayName, DaysLeft);
- menu_additem(RemoveMenu, Format, ReadFile);
- Num++;
- }
- if(Num > 0)
- menu_display(id, RemoveMenu);
- else
- return ColorChat(id, "^4There are no temporary admins in the server.");
- return 0;
- }
- // The Handler for RemoveAdmins(id). Used for editing the temporary admins.
- public HandleRemoveAdminMenu(id, RemoveMenu, item)
- {
- if(item == MENU_EXIT)
- {
- ManageAdmins(id);
- return;
- }
- new access, info[300], name[32], callback;
- menu_item_getinfo(RemoveMenu, item, access, info, charsmax(info), name, charsmax(name), callback);
- new ReadFile[300], Line, Length;
- while(read_file(AdminsDir, Line++, ReadFile, charsmax(ReadFile), Length))
- {
- if(!read_file(AdminsDir, Line, ReadFile, charsmax(ReadFile), Length)) break;
- if(strcmp(ReadFile, info) == 0)
- {
- write_file(AdminsDir, "", Line);
- break;
- }
- }
- }
- public EditAdminMenu(id)
- {
- if(!(get_user_flags(id) & ADMIN_RCON))
- return ColorChat(id, "^4You have no access to this command!");
- new EditMenu = menu_create("List of admins:", "HandleEditAdminMenu");
- new ReadFile[300], Token[7][40], Line, Length, Format[240], Num;
- while(read_file(AdminsDir, Line++, ReadFile, charsmax(ReadFile), Length))
- {
- if(!read_file(AdminsDir, Line, ReadFile, charsmax(ReadFile), Length)) break;
- parse(ReadFile, Token[0], 39, Token[1], 39, Token[2], 39, Token[3], 39, Token[4], 39, Token[5], 39, Token[6], 39);
- if(strfind(Token[4], ";Expiration(") == -1) continue;
- new DaysLeft = ( ( str_to_num(Token[5]) - get_systime() ) / Day ) + 1;
- new DisplayName[50];
- if(strcmp(Token[6], "") != 0)
- formatex(DisplayName, charsmax(DisplayName), Token[6]);
- else
- formatex(DisplayName, charsmax(DisplayName), Token[0]);
- formatex(Format, charsmax(Format), "%s - %i Days Left", DisplayName, DaysLeft);
- menu_additem(EditMenu, Format, ReadFile);
- Num++;
- }
- if(Num > 0)
- menu_display(id, EditMenu);
- else
- return ColorChat(id, "^4There are no temporary admins in the server.");
- return 0;
- }
- public HandleEditAdminMenu(id, EditMenu, item)
- {
- if(item == MENU_EXIT)
- {
- ManageAdmins(id);
- return;
- }
- new access, info[300], name[32], callback;
- menu_item_getinfo(EditMenu, item, access, info, charsmax(info), name, charsmax(name), callback);
- EditPlayerAdminMenu(id, info);
- }
- EditPlayerAdminMenu(id, info[300] = "Invalid")
- {
- new Format[100], Token[7][40];
- if(!equali(info, "Invalid"))
- {
- parse(info, Token[0], 39, Token[1], 39, Token[2], 39, Token[3], 39, Token[4], 39, Token[5], 39, Token[6], 39);
- new DaysLeft = ( ( str_to_num(Token[5]) - get_systime() ) / Day ) + 1;
- AdminID[id] = Token[0];
- AdminPassword[id] = Token[1];
- AdminAccess[id] = Token[2];
- AdminTime[id] = DaysLeft;
- AdminName[id] = Token[6];
- AdminInfo[id] = info;
- if(strcmp(Token[6], "") != 0)
- formatex(Format, charsmax(Format), "Editing %s's Admin:", Token[6]);
- else
- formatex(Format, charsmax(Format), "Editing %s's Admin:", Token[0]);
- }
- else
- {
- if(strcmp(AdminName[id], "") != 0)
- formatex(Format, charsmax(Format), "Editing %s's Admin:", AdminName[id]);
- else
- formatex(Format, charsmax(Format), "Editing %s's Admin:", AdminID[id]);
- }
- new EditPlayerMenu = menu_create(Format, "HandleEditPlayerAdminMenu");
- if(strcmp(AdminPassword[id], "") != 0)
- {
- formatex(Format, charsmax(Format), "Password: %s", AdminPassword[id]);
- menu_additem(EditPlayerMenu, Format);
- }
- formatex(Format, charsmax(Format), "Flags: %s", AdminAccess[id]);
- menu_additem(EditPlayerMenu, Format);
- formatex(Format, charsmax(Format), "Time: %i Days", AdminTime[id]);
- menu_additem(EditPlayerMenu, Format);
- formatex(Format, charsmax(Format), "Display Name ( Optional ): %s", AdminName[id]);
- menu_additem(EditPlayerMenu, Format);
- formatex(Format, charsmax(Format), "Complete Editing!");
- menu_additem(EditPlayerMenu, Format);
- menu_display(id, EditPlayerMenu);
- }
- public HandleEditPlayerAdminMenu(id, EditPlayerMenu, item)
- {
- if(item == MENU_EXIT)
- {
- EditAdminMenu(id);
- return;
- }
- new ReadFile[300], Token[7][300], Line, Length, Influence[100], Format[300];
- new Result = item;
- if(strcmp(AdminPassword[id], "") == 0) Result++;
- switch(Result)
- {
- case 0: client_cmd(id, "messagemode ^"TempAdmin_Password^"");
- case 1: client_cmd(id, "messagemode ^"TempAdmin_Flags^"");
- case 2: client_cmd(id, "messagemode ^"TempAdmin_Time^"");
- case 3: client_cmd(id, "messagemode ^"TempAdmin_Name^"");
- }
- if(Result != 4)
- {
- EditPlayerAdminMenu(id);
- return;
- }
- while(read_file(AdminsDir, Line++, ReadFile, charsmax(ReadFile), Length))
- {
- if(!read_file(AdminsDir, Line, ReadFile, charsmax(ReadFile), Length)) break;
- parse(ReadFile, Token[0], 231, Token[1], 231, Token[2], 231, Token[3], 231, Token[4], 231, Token[5], 231, Token[6], 231);
- if(strcmp(ReadFile, "") == 0) continue;
- if(strcmp(ReadFile, AdminInfo[id]) == 0)
- {
- formatex(Token[1], 231, AdminPassword[id]);
- formatex(Token[2], 231, AdminAccess[id]);
- new DaysLeft = ( ( str_to_num(Token[5]) - get_systime() ) / Day ) + 1;
- formatex(Influence, charsmax(Influence), ";Expiration(%i Days):", DaysLeft);
- replace(Token[4], 231, Token[4], Influence);
- formatex(Token[6], 231, AdminName[id]);
- new DisplayName[32];
- if(strcmp(Token[6], "") != 0)
- formatex(DisplayName, charsmax(DisplayName), Token[6]);
- else
- formatex(DisplayName, charsmax(DisplayName), Token[0]);
- /*
- new Loop = 6;
- if(strcmp(Token[6], "") != 0)
- Loop = 7;
- */
- formatex(ReadFile, 0, "");
- for(new i;i < 7;i++)
- {
- formatex(Format, charsmax(Format), "^"%s^" ", Token[i]);
- add(ReadFile, charsmax(ReadFile), Format);
- }
- write_file(AdminsDir, "", Line); // Some weird bug, Idunno...
- write_file(AdminsDir, ReadFile, Line);
- ColorChat(id, "^4Admin^3 %s^1 was successfully^3 edited^1!", DisplayName);
- break;
- }
- }
- }
- public EditPassword(id)
- {
- new Arg[30];
- read_args(Arg, charsmax(Arg));
- remove_quotes(Arg);
- AdminPassword[id] = Arg;
- if(Adding[id])
- AddAdminMenu(id);
- else
- EditPlayerAdminMenu(id);
- return 1;
- }
- public EditFlags(id)
- {
- new Arg[30];
- read_args(Arg, charsmax(Arg));
- remove_quotes(Arg);
- if(containi(Arg, "l") != -1)
- {
- replace(Arg, charsmax(Arg), "l", "");
- ColorChat(id, "^3Flags^1 may not have^4 Rcon^1 access. The^4 Rcon^1 flag was removed.");
- }
- AdminAccess[id] = Arg;
- if(Adding[id])
- AddAdminMenu(id);
- else
- EditPlayerAdminMenu(id);
- return 1;
- }
- public EditTime(id)
- {
- new Arg[30];
- read_args(Arg, charsmax(Arg));
- remove_quotes(Arg);
- if(!is_str_num(Arg))
- {
- if(Adding[id])
- AddAdminMenu(id);
- else
- EditPlayerAdminMenu(id);
- return ColorChat(id, "^3Time^1 must only contain^4 numbers^1!");
- }
- AdminTime[id] = str_to_num(Arg);
- if(Adding[id])
- AddAdminMenu(id);
- else
- EditPlayerAdminMenu(id);
- return 1;
- }
- public EditName(id)
- {
- new Arg[30];
- read_args(Arg, charsmax(Arg));
- remove_quotes(Arg);
- AdminName[id] = Arg;
- if(Adding[id])
- AddAdminMenu(id);
- else
- EditPlayerAdminMenu(id);
- return 1;
- }
- stock get_user_steamid(index)
- {
- new SteamID[32];
- get_user_authid(index, SteamID, charsmax(SteamID));
- return SteamID;
- }
- stock get_user_nick(index)
- {
- new Name[32];
- get_user_name(index, Name, charsmax(Name));
- return Name;
- }
- stock get_user_address(index)
- {
- new IP[32];
- get_user_ip(index, IP, charsmax(IP), 1);
- return IP;
- }
- stock ColorChat(const index, const string[], {Float, Sql, Resul,_}:...)
- {
- new msg[191], players[32], count = 1, PREFIX[32];
- get_cvar_string("amx_prefix_cvar", PREFIX, charsmax(PREFIX));
- static len;
- len = formatex(msg, charsmax(msg), "^3(^4 %s^3 )^1 ", PREFIX);
- vformat(msg[len], charsmax(msg) - len, string, 3);
- if(index) players[0] = index;
- else get_players(players,count,"ch");
- for (new i = 0; i < count; i++)
- {
- if(is_user_connected(players[i]))
- {
- message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"),_, players[i]);
- write_byte(players[i]);
- write_string(msg);
- message_end();
- }
- }
- return 1;
- }
Add Comment
Please, Sign In to add comment