Post by [AMXX PLUGIN HELP] on Feb 18, 2015 20:00:11 GMT
hello guys .. well I have a problem with this plugin amxx "Ingame Config File Editor" of forums.alliedmods.net/showthread.php?p=677802
the problem is that it only displays only the contents of the "cstrike" folder
if someone helps me to display the complete folder on the server ... example:
/ cstrike
/ platforms
/ logs
/dproto.cfg
Here I give the code:
thx!..
the problem is that it only displays only the contents of the "cstrike" folder
if someone helps me to display the complete folder on the server ... example:
/ cstrike
/ platforms
/ logs
/dproto.cfg
Here I give the code:
thx!..
#include <amxmodx>
#include <amxmisc>
#define MAX_FILE_NAME 50
#define MAX_PLAYERS 33
#define FILES_PER_PAGE 8
#define MAX_MENU_CHARS 500
#define MAX_FILE_SIZE 300
#define ACCESS_LEVEL ADMIN_RCON
#define ALL_MENU_KEYS (1<<0 | 1<<1 | 1<<2 | 1<<3 | 1<<4 | 1<<5 | 1<<6 | 1<<7 | 1<<8 | 1<<9)
new my_dir[MAX_PLAYERS][MAX_FILE_SIZE], my_temp_options[MAX_PLAYERS][FILES_PER_PAGE][MAX_FILE_NAME];
new my_selected_file[MAX_PLAYERS][MAX_FILE_SIZE], delete_confirm[MAX_PLAYERS], view_more[MAX_PLAYERS];
new my_page[MAX_PLAYERS], my_file_page[MAX_PLAYERS], my_edit_line[MAX_PLAYERS];
public plugin_init()
{
register_plugin("Configuration File Editor", "1.0", "WhooKid");
register_concmd("amx_con", "start_config", ACCESS_LEVEL, "- Opens config editor");
register_concmd("amx_config", "start_config", ACCESS_LEVEL, "- Opens config editor");
register_menucmd(register_menuid("ConfigeditorDir"), ALL_MENU_KEYS, "pick_dir");
register_menucmd(register_menuid("ConfigeditorEditD"), ALL_MENU_KEYS, "pick_diredit");
register_menucmd(register_menuid("ConfigeditorFoptions"), ALL_MENU_KEYS, "pick_flopt");
register_menucmd(register_menuid("ConfigeditorFile"), ALL_MENU_KEYS, "pick_file");
register_menucmd(register_menuid("ConfigeditorLine"), ALL_MENU_KEYS, "pick_line");
register_clcmd("NewFileName", "user_create_file");
register_clcmd("NewDirectoryName", "user_create_directory");
register_clcmd("RenameFileEnterName", "user_rename_file");
register_clcmd("EnterNewLine", "user_edit_line");
}
public start_config(id)
{
if (get_user_flags(id) & ACCESS_LEVEL)
{
my_page[id] = delete_confirm[id] = 0;
my_dir[id] = "";
list_dir(id);
}
else
client_print(id, print_chat, "[AMXX] You do not have access to this command.");
return PLUGIN_HANDLED;
}
public list_dir(id)
{
new message[MAX_MENU_CHARS], keys = (1 << 8 | 1 << 9), count, found, range = my_page[id] * FILES_PER_PAGE, iLen = formatex(message, 256, "\r== \yConfig Editor \r== \d(Page: %d)^nPath: /%s^n", my_page[id] + 1, my_dir[id]);
new cur_file[MAX_FILE_NAME], cur_directory = open_dir(my_dir[id], cur_file, MAX_FILE_NAME - 1);
while (next_file(cur_directory, cur_file, MAX_FILE_NAME - 1) && found < FILES_PER_PAGE)
if (contain(cur_file, ".") == -1 || containi(cur_file, ".cfg") != -1 || containi(cur_file, ".txt") != -1 || containi(cur_file, ".ini") != -1 || containi(cur_file, ".log") != -1 || containi(cur_file, ".htm") != -1 || containi(cur_file, ".res") != -1 || containi(cur_file, ".sma") != -1)
{
if (contain(cur_file, ".") == -1)
formatex(cur_file[strlen(cur_file)], 2, "/");
if (count >= range)
{
iLen += formatex(message[iLen], 60, "^n\r%d. \w%s", found + 1, cur_file);
my_temp_options[id][found] = cur_file;
keys |= (1 << found);
found++;
}
count++;
}
close_dir(cur_directory);
if (found == FILES_PER_PAGE)
iLen += formatex(message[iLen], 45, "^n^n\r9. \yNext Page");
else
{
iLen += formatex(message[iLen], 45, "^n^n\r9. \yAdd New");
my_temp_options[id][FILES_PER_PAGE - 1] = "AddNew";
}
if (my_page[id] == 0)
iLen += formatex(message[iLen], 60, "^n\r0. \%s", (!equal(my_dir[id], "")) ? "y[Previous Directory]" : "dExit");
else
iLen += formatex(message[iLen], 25, "^n\r0. \wPrevious Page");
show_menu(id, keys, message, -1, "ConfigeditorDir");
}
public list_dir_options(id)
{
new message[MAX_MENU_CHARS], iLen = formatex(message, 256, "\r== \yConfig Editor \r==^n\dPath: /%s^n", my_dir[id]);
if (!delete_confirm[id])
iLen += formatex(message[iLen], 200, "^n\r1. \wAdd new file^n\r2. \wAdd new directory^n\r3. \wDelete directory^n^n\r9. \dExit^n\r0. \yBack to Directory");
else
iLen += formatex(message[iLen], 200, "^n\rAre you sure you want to delete this directory?^n\dNote: (The directory is required to be empty)^n\r4. \wYes^n\r5. \wNo");
show_menu(id, (!delete_confirm[id]) ? (1<<0 | 1<<1 | 1<<2 | 1<<8 | 1<<9) : (1<<3 | 1<<4), message, -1, "ConfigeditorEditD");
}
public list_file_options(id)
{
new message[MAX_MENU_CHARS], iLen = formatex(message, 256, "\r== \yConfig Editor \r==^n\dFile: %s (%dkb)^n", my_selected_file[id], filesize(my_selected_file[id]));
if (!delete_confirm[id])
iLen += formatex(message[iLen], 200, "^n\r1. \wView%s^n\r2. \wEdit^n\r3. \wServer Execute (exec)^n\r4. \wRename^n\r5. \wCopy^n\r6. \wDelete^n^n\r9. \dExit^n\r0. \yBack to Directory", (view_more[id] > 0) ? " More" : "");
else
iLen += formatex(message[iLen], 120, "^n\rAre you sure you want to delete this file?^n4. \wYes^n\r5. \wNo");
show_menu(id, (!delete_confirm[id]) ? (1<<0 | 1<<1 | 1<<2 | 1<<3 | 1<<4 | 1<<5 | 1<<8 | 1<<9) : (1<<3 | 1<<4), message, -1, "ConfigeditorFoptions");
}
public list_file_lines(id)
{
new message[MAX_MENU_CHARS], found, iLen = formatex(message, 256, "\r== \yConfig Editor \r== \d(Page: %d)^nFile: %s^n", my_file_page[id] + 1, my_selected_file[id]), keys = (1 << 9);
new file = fopen(my_selected_file[id], "r"), value[48], line, range = my_file_page[id] * FILES_PER_PAGE;
if (file)
{
while (fgets(file, value, 47) && found < FILES_PER_PAGE)
{
if (line >= range)
{
replace(value, 47, "^n", "");
iLen += formatex(message[iLen], 47, "^n\r%d. \w%s", found + 1, value);
my_temp_options[id][found] = "";
keys |= (1 << found);
found++;
}
line++;
}
fclose(file);
}
else
{
client_print(id, print_chat, "[AMXX] Failed to open the file %s.", my_selected_file[id]);
list_dir(id);
return;
}
if (found == FILES_PER_PAGE)
{
iLen += formatex(message[iLen], 30, "^n^n\r9. \yNext Page");
keys |= (1 << 8);
}
else
{
iLen += formatex(message[iLen], 40, "^n\r%d. \yMake a new line^n", found + 1);
my_temp_options[id][found] = "MakeANewLine";
keys |= (1 << found);
}
if (my_file_page[id] == 0)
iLen += formatex(message[iLen], 30, "^n\r0. \yBack to Options");
else
iLen += formatex(message[iLen], 25, "^n\r0. \wPrevious Page");
show_menu(id, keys, message, -1, "ConfigeditorFile");
}
public list_line_options(id)
{
new message[MAX_MENU_CHARS], null, iLen = formatex(message, 256, "\r== \yConfig Editor \r== \d(Line: %d)^nFile: %s^n", my_edit_line[id] + 1, my_selected_file[id]);
if (read_file(my_selected_file[id], my_edit_line[id], my_temp_options[id][4], 299, null))
{
iLen += formatex(message[iLen], 250, "^n\w%s^n", my_temp_options[id][4]);
if (!equal(my_temp_options[id][1], ""))
{
iLen += formatex(message[iLen], 250, "\rChanged from:^n\w%s^n", my_temp_options[id][1]);
my_temp_options[id][1] = "";
}
}
else
{
client_print(id, print_chat, "[AMXX] Failed to open the file %s.", my_selected_file[id]);
list_dir(id);
return;
}
iLen += formatex(message[iLen], 80, "^n\r1. \wEdit^n\r2. \w%somment^n\r3. \wCopy^n\r4. \wDelete^n^n\r0. \yBack to Lines", (my_temp_options[id][4][0] == '/' && my_temp_options[id][4][1] == '/') ? "Unc" : "C");
show_menu(id, (1 << 0 | 1 << 1 | 1 << 2 | 1 << 3 | 1 << 9) , message, -1, "ConfigeditorLine");
my_temp_options[id][FILES_PER_PAGE - 1] = "";
}
public pick_dir(id, key)
{
switch (key)
{
case 9:{
if (my_page[id] == 0)
{
if (!equal(my_dir[id], ""))
{
new len = strlen(my_dir[id]) - 1;
my_dir[id][len] = ' ';
for (new a = len; a >= 0; a--)
if (my_dir[id][a] != '/')
my_dir[id][a] = ' ';
else
break;
trim(my_dir[id]);
if (equal(my_dir[id], "/"))
my_dir[id] = "";
list_dir(id);
}
}
else
{
my_page[id]--;
list_dir(id);
}
}
case 8: {
if (equal(my_temp_options[id][FILES_PER_PAGE - 1], "AddNew"))
{
list_dir_options(id);
my_temp_options[id][FILES_PER_PAGE - 1] = "";
}
else
{
my_page[id]++;
list_dir(id);
}
}
default: {
new full_file[MAX_FILE_SIZE];
formatex(full_file, MAX_FILE_SIZE, "%s%s", my_dir[id], my_temp_options[id][key]);
if (dir_exists(full_file))
{
my_dir[id] = full_file;
my_page[id] = 0;
list_dir(id);
}
else
{
if (file_exists(full_file))
{
my_selected_file[id] = full_file;
my_file_page[id] = view_more[id] = 0;
list_file_options(id);
}
else
{
client_print(id, print_chat, "[AMXX] The file you have chosen does not exist.");
list_dir(id);
}
}
}
}
return PLUGIN_HANDLED;
}
public pick_diredit(id, key)
{
switch (key)
{
case 9: list_dir(id);
case 4: {
if (delete_confirm[id])
delete_confirm[id] = 0;
list_dir_options(id);
}
case 3: {
delete_confirm[id] = 0;
if (equal(my_dir[id], ""))
{
client_print(id, print_chat, "[AMXX] You are unable to delete your main directory.");
list_dir(id);
}
else if (rmdir(my_dir[id]))
{
client_print(id, print_chat, "[AMXX] Your directory has been successfully deleted.");
my_page[id] = 0;
pick_dir(id, 9);
}
else
{
client_print(id, print_chat, "[AMXX] Unable to delete your directory. Reason unknown, possibly permissions or directory not empty.");
list_dir_options(id);
}
}
case 2: {
delete_confirm[id] = 1;
list_dir_options(id);
}
case 1: {
client_cmd(id, "messagemode ^"NewDirectoryName^"");
list_dir_options(id);
}
case 0: {
client_cmd(id, "messagemode ^"NewFileName^"");
list_dir_options(id);
}
}
return PLUGIN_HANDLED;
}
public pick_flopt(id, key)
{
switch (key)
{
case 9: list_dir(id);
case 5:{
delete_confirm[id] = 1;
list_file_options(id);
}
case 4: {
if (delete_confirm[id])
{
delete_confirm[id] = 0;
list_file_options(id);
return PLUGIN_HANDLED;
}
list_file_options(id);
new new_file[MAX_FILE_SIZE], temp[2000], len = strlen(my_selected_file[id]) - 1, extention[10];
temp = my_selected_file[id];
for (new a = len; a >= 0; a--)
if (temp[a] != '.')
{
extention[len - a] = temp[a];
temp[a] = ' ';
}
else
{
temp[a] = ' ';
break;
}
new_file[0] = extention[0], extention[0] = extention[2], extention[2] = new_file[0];
trim(temp), trim(extention);
formatex(new_file, MAX_FILE_SIZE, "%s_copy.%s", temp, extention);
if (file_exists(new_file))
{
client_print(id, print_chat, "[AMXX] The filename %s already exists. Copy aborted.", new_file);
return PLUGIN_HANDLED;
}
new file1 = fopen(my_selected_file[id], "rt"), file2 = fopen(new_file, "at+");
while (fgets(file1, temp, 1999))
fprintf(file2, temp);
fclose(file1), fclose(file2);
client_print(id, print_chat, "[AMXX] Your file has been successfully copied to %s.", new_file);
}
case 3:{
if (!delete_confirm[id])
{
client_cmd(id, "messagemode ^"RenameFileEnterName^"");
list_file_options(id);
}
else
{
if (delete_file(my_selected_file[id]))
{
client_print(id, print_chat, "[AMXX] Your file has been successfully deleted.");
list_dir(id);
}
else
{
client_print(id, print_chat, "[AMXX] Unable to delete your file. Reason unknown, possibly permissions or file in use.");
list_file_options(id);
}
delete_confirm[id] = 0;
}
}
case 2:{
if (containi(my_selected_file[id], "users.ini") != -1)
{
server_cmd("amx_reloadadmins");
client_print(id, print_chat, "[AMXX] Server administrators have been reloaded.");
}
else
{
server_cmd("exec %s", my_selected_file[id]);
client_print(id, print_chat, "[AMXX] Your file ^"%s^" has been executed by the server.", my_selected_file[id]);
}
list_file_options(id);
}
case 1: list_file_lines(id);
case 0: {
new mssge[1300], temp[1000], iLen = formatex(mssge, 5, "<pre>"), file = fopen(my_selected_file[id], "rt"), view_more_cache = view_more[id];
view_more[id] = 0;
if (view_more_cache)
fseek(file, view_more_cache, SEEK_SET);
while (fgets(file, temp, 999))
if (iLen + strlen(temp) > 1299)
{
view_more[id] = view_more_cache + iLen;
break;
}
else
iLen += formatex(mssge[iLen], 1294 - iLen, "%s", temp);
fclose(file);
mssge[1298] = mssge[1299] = '^n';
show_motd(id, mssge, "View Config");
list_file_options(id);
}
}
return PLUGIN_HANDLED;
}
public pick_file(id, key)
{
switch (key)
{
case 9:{
if (my_file_page[id] != 0)
{
my_file_page[id]--;
list_file_lines(id);
}
else
list_file_options(id);
}
case 8: {
my_file_page[id]++;
list_file_lines(id);
}
default: {
if (equal(my_temp_options[id][key], "MakeANewLine"))
{
if (!write_file(my_selected_file[id], " ", -1))
client_print(id, print_chat, "[AMXX] Unable to edit that file. Reason unknown, possibly permissions or file in use.");
my_temp_options[id][key] = "";
list_file_lines(id);
}
else
{
my_edit_line[id] = (my_file_page[id] * FILES_PER_PAGE) + key;
my_temp_options[id][1] = "";
list_line_options(id);
}
}
}
return PLUGIN_HANDLED;
}
public pick_line(id, key)
{
switch (key)
{
case 9: list_file_lines(id);
case 2, 3: {
new tempfile[20], temp[2000], line = -1, my_line = my_edit_line[id];
formatex(tempfile, 20, "TEMPFILE%d", random_num(100000, 999999));
new file1 = fopen(my_selected_file[id], "rt"), file2 = fopen(tempfile, "at+");
while (fgets(file1, temp, 1999) && line++ != -2)
if (line != my_line)
fprintf(file2, temp);
else if (key == 2)
fprintf(file2, temp), fprintf(file2, temp);
fclose(file1), fclose(file2);
if (delete_file(my_selected_file[id]))
{
rename_file(tempfile, my_selected_file[id], 1);
client_print(id, print_chat, "[AMXX] Line: %d has been %s your file.", my_line + 1, (key == 3) ? "deleted from" : "copied in");
}
else
{
delete_file(tempfile);
client_print(id, print_chat, "[AMXX] The line: %d cannot be %s. File maybe be write protected.", my_line + 1, (key == 3) ? "deleted" : "copied");
}
list_file_lines(id);
}
case 1: {
new temp[500], finished[500], null;
read_file(my_selected_file[id], my_edit_line[id], temp, 500, null);
if (temp[0] == '/' && temp[1] == '/')
{
temp[0] = temp[1] = ' ';
trim(temp);
finished = temp;
}
else
formatex(finished, 500, "//%s", temp);
if (!write_file(my_selected_file[id], finished, my_edit_line[id]))
client_print(id, print_chat, "[AMXX] Unable to edit that file. Reason unknown, possibly permissions or file in use.");
list_line_options(id);
}
case 0:{
client_cmd(id, "messagemode ^"EnterNewLine^"", my_edit_line[id] + 1);
list_line_options(id);
my_temp_options[id][FILES_PER_PAGE - 1] = "EditALine";
}
}
return PLUGIN_HANDLED;
}
public user_create_file(id)
{
if (!(get_user_flags(id) & ACCESS_LEVEL))
{
client_print(id, print_chat, "[AMXX] You do not have access to this command.");
return;
}
new say[MAX_FILE_SIZE];
read_args(say, MAX_FILE_SIZE);
remove_quotes(say), trim(say);
if (equal(say, ""))
{
client_print(id, print_chat, "[AMXX] File aborted.");
return;
}
else if (contain(say, ".") == -1)
{
client_print(id, print_chat, "[AMXX] Your file: %s, does not have a proper extention. File aborted.", say);
return;
}
else if (contain(say, "/") != -1)
{
client_print(id, print_chat, "[AMXX] Your file: %s, cannot contain directories. File aborted.", say);
return;
}
new file[255];
formatex(file, 255, "%s%s", my_dir[id], say);
if (!file_exists(file))
{
if (write_file(file, " ", -1))
client_print(id, print_chat, "[AMXX] Your file: %s, has been successfully created.", say);
else
client_print(id, print_chat, "[AMXX] Unable to create %s. Reason unknown, possibly permissions.", file);
}
else
client_print(id, print_chat, "[AMXX] Unable to create %s. The file already exists.", file);
list_dir(id);
}
public user_create_directory(id)
{
if (!(get_user_flags(id) & ACCESS_LEVEL))
{
client_print(id, print_chat, "[AMXX] You do not have access to this command.");
return;
}
new say[MAX_FILE_SIZE];
read_args(say, MAX_FILE_SIZE);
remove_quotes(say), trim(say);
if (equal(say, ""))
{
client_print(id, print_chat, "[AMXX] Directory aborted.");
return;
}
else if (contain(say, ".") != -1 || contain(say, " ") != -1 || contain(say, "\") != -1 || contain(say, "/") != -1 || contain(say, "'") != -1 || contain(say, "^"") != -1 || contain(say, "`") != -1)
{
client_print(id, print_chat, "[AMXX] Your directory: %s, contains invalid character(s).", say);
return;
}
new newdir[255];
formatex(newdir, 255, "%s%s/", my_dir[id], say);
if (!dir_exists(newdir))
{
if (!mkdir(newdir))
client_print(id, print_chat, "[AMXX] Your directory: %s, has been successfully created.", say);
else
client_print(id, print_chat, "[AMXX] Unable to create %s. Reason unknown, possibly permissions.", newdir);
}
else
client_print(id, print_chat, "[AMXX] Unable to create %s. The directory already exists.", newdir);
list_dir(id);
}
public user_rename_file(id)
{
if (!(get_user_flags(id) & ACCESS_LEVEL))
{
client_print(id, print_chat, "[AMXX] You do not have access to this command.");
return;
}
new say[MAX_FILE_SIZE];
read_args(say, MAX_FILE_SIZE);
remove_quotes(say), trim(say);
if (equal(say, ""))
{
client_print(id, print_chat, "[AMXX] Rename Failed.");
return;
}
else if (contain(say, ".") == -1)
{
client_print(id, print_chat, "[AMXX] The filename %s, does not have a proper extention. Rename aborted.", say);
return;
}
else if (contain(say, "/") != -1)
{
client_print(id, print_chat, "[AMXX] The filename %s, cannot contain directories. Rename aborted.", say);
return;
}
new file[255];
formatex(file, 255, "%s%s", my_dir[id], say);
if (file_exists(file))
{
client_print(id, print_chat, "[AMXX] The filename %s already exists. Rename aborted.", say);
return;
}
if (file_exists(my_selected_file[id]))
{
if (rename_file(my_selected_file[id], file, 1))
client_print(id, print_chat, "[AMXX] Your file has been successfully renamed to %s.", say);
else
client_print(id, print_chat, "[AMXX] Unable to rename %s. Reason unknown, possibly permissions or file in use.", my_selected_file[id]);
}
else
client_print(id, print_chat, "[AMXX] Unable to rename %s. The file doesn't exist.", my_selected_file[id]);
list_dir(id);
}
public user_edit_line(id)
{
if (!(get_user_flags(id) & ACCESS_LEVEL))
{
client_print(id, print_chat, "[AMXX] You do not have access to this command.");
return;
}
new say[MAX_FILE_SIZE], null;
read_args(say, MAX_FILE_SIZE);
remove_quotes(say);
if (equal(say, "") || !equal(my_temp_options[id][FILES_PER_PAGE - 1], "EditALine"))
{
client_print(id, print_chat, "[AMXX] Edit Failed.");
return;
}
if (file_exists(my_selected_file[id]))
{
if (read_file(my_selected_file[id], my_edit_line[id], my_temp_options[id][1], 299, null))
{
if (write_file(my_selected_file[id], say, my_edit_line[id]))
client_print(id, print_chat, "[AMXX] The line has been successfully edited.");
else
client_print(id, print_chat, "[AMXX] Unable to edit that file. Reason unknown, possibly permissions or file in use.");
}
else
client_print(id, print_chat, "[AMXX] The line you are trying to edit does not exist.");
list_line_options(id);
}
else
{
client_print(id, print_chat, "[AMXX] The file your trying to edit no longer exists.");
list_dir(id);
}
}