Merge branch 'reload-bans' into 'next'

Fix reloadbans clearing ban.txt and clearbans not actually saving the changes

See merge request STJr/SRB2!1215
This commit is contained in:
James R 2020-12-10 14:28:13 -05:00
commit a5d228773d
1 changed files with 21 additions and 13 deletions

View File

@ -2260,11 +2260,15 @@ void D_SaveBan(void)
size_t i; size_t i;
banreason_t *reasonlist = reasonhead; banreason_t *reasonlist = reasonhead;
const char *address, *mask; const char *address, *mask;
const char *path = va("%s"PATHSEP"%s", srb2home, "ban.txt");
if (!reasonhead) if (!reasonhead)
{
remove(path);
return; return;
}
f = fopen(va("%s"PATHSEP"%s", srb2home, "ban.txt"), "w"); f = fopen(path, "w");
if (!f) if (!f)
{ {
@ -2308,16 +2312,14 @@ static void Ban_Add(const char *reason)
reasontail = reasonlist; reasontail = reasonlist;
} }
static void Command_ClearBans(void) static void Ban_Clear(void)
{ {
banreason_t *temp; banreason_t *temp;
if (!I_ClearBans)
return;
I_ClearBans(); I_ClearBans();
D_SaveBan();
reasontail = NULL; reasontail = NULL;
while (reasonhead) while (reasonhead)
{ {
temp = reasonhead->next; temp = reasonhead->next;
@ -2327,6 +2329,15 @@ static void Command_ClearBans(void)
} }
} }
static void Command_ClearBans(void)
{
if (!I_ClearBans)
return;
Ban_Clear();
D_SaveBan();
}
static void Ban_Load_File(boolean warning) static void Ban_Load_File(boolean warning)
{ {
FILE *f; FILE *f;
@ -2334,6 +2345,9 @@ static void Ban_Load_File(boolean warning)
const char *address, *mask; const char *address, *mask;
char buffer[MAX_WADPATH]; char buffer[MAX_WADPATH];
if (!I_ClearBans)
return;
f = fopen(va("%s"PATHSEP"%s", srb2home, "ban.txt"), "r"); f = fopen(va("%s"PATHSEP"%s", srb2home, "ban.txt"), "r");
if (!f) if (!f)
@ -2343,13 +2357,7 @@ static void Ban_Load_File(boolean warning)
return; return;
} }
if (I_ClearBans) Ban_Clear();
Command_ClearBans();
else
{
fclose(f);
return;
}
for (i=0; fgets(buffer, (int)sizeof(buffer), f); i++) for (i=0; fgets(buffer, (int)sizeof(buffer), f); i++)
{ {