#include amxmodx
new g_File[32] = "addons/rechecker/resources.ini";
new g_Path[24] = "addons/rechecker/bases";
new g_PrecFile[32];
new Array:g_Files;
public plugin_precache()
{
register_plugin("RC BaseChanger", "freesrv", "custom");
new glfile[32], glfile_path[64], prec_buff[34], glfile_buff[34];
new gldir = open_dir(g_Path, glfile, charsmax(glfile)), maxarr = 0;
md5_file(g_File, prec_buff);
g_Files = ArrayCreate(32);
do
{
if(strlen(glfile) > 3)
{
formatex(glfile_path, charsmax(glfile_path), "%s/%s", g_Path,glfile);
md5_file(glfile_path, glfile_buff);
if(equal(prec_buff, glfile_buff))
copy(g_PrecFile, charsmax(g_PrecFile), glfile);
ArrayPushString(g_Files, glfile); maxarr += 1;
}
}
while(next_file(gldir, glfile, charsmax(glfile)));
close_dir(gldir);
new listfile[128];
format(listfile, charsmax(listfile), "addons/rechecker/baselist.txt");
if(!file_exists(listfile))
{
write_file(listfile, g_PrecFile, 0);
write_file(listfile, "0", 1);
}
new i, chk, lstfile[36], chkfile[36], arrfile[32], maxlst, len;
for(i = 0 ; i < maxarr ; i++)
{
ArrayGetString(g_Files, i, arrfile, charsmax(arrfile));
formatex(chkfile, charsmax(chkfile), "@%s", arrfile);
chk = 0;
new j; maxlst = file_size(listfile, 1);
for(j = 2; j < maxlst - 1; j++)
{
read_file(listfile, j, lstfile, charsmax(lstfile), len);
if (strfind(lstfile, chkfile) != -1) chk += 1;
}
if(chk == 0)
{
format(chkfile, charsmax(chkfile), "0%s", chkfile);
write_file(listfile, chkfile, -1);
}
}
new nextfile[32], setfile[32], pos;
read_file(listfile, 0, nextfile, charsmax(nextfile), len);
read_file(listfile, 1, setfile, charsmax(setfile), len);
if(strlen(setfile) < 2)
{
if(maxlst > 3)
{
i = 0;
for(i = 0; i < maxarr; i++)
{
ArrayGetString(g_Files, i, chkfile, charsmax(chkfile));
if(strfind(nextfile, chkfile) != -1)
{
if (i == maxarr-1) pos = 0;
else pos = i + 1;
}
}
ArrayGetString(g_Files, pos, nextfile, charsmax(nextfile));
log_amx("^tПроверка ведется по базе ^"%s^"", nextfile);
}
else copy(nextfile, charsmax(nextfile), g_PrecFile);
formatex(glfile_path, charsmax(glfile_path), "%s/%s", g_Path,nextfile);
write_file(listfile, nextfile, 0);
}
else formatex(glfile_path, charsmax(glfile_path), "%s/%s", g_Path,setfile);
ArrayDestroy(g_Files);
file_copy(glfile_path, g_File);
pause("ad");
}
stock bool:file_copy(SOURCE[], TARGET[])
{
new source = fopen(SOURCE, "rb");
new target = fopen(TARGET, "wb");
for(new buffer, eof = feof(source); !eof; !eof && fputc(target, buffer))
{
buffer = fgetc(source);
eof = feof(source);
}
fclose(source);
fclose(target);
return true;
}