Remove lines in clan.lst

Posted by Zeno on Mon 31 Jan 2005 12:42 AM — 6 posts, 21,948 views.

USA #0
I've got in a clan delete command, works fine etc, but I'm not sure how to delete that clan filename from clan.lst. The actual clan file is deleted, but of course it's still in clan.lst, and I don't think fopen will remove that line.

Manual deletion is out of the question, since this is the last part of my custom player creation clan system.

The file looks like this:
combatant.gui
guardian.gui
tclan.cln
some.cln
another.cln
$
Amended on Mon 31 Jan 2005 12:55 AM by Zeno
USA #1
Why not just save the new list over it? Thats what I do with my asteroids. Since this is used by players, it is obviously online. When you remove the clan from the doubly linked list, just save the new list right afterwards and you should be fine.
USA #2
Well the function is write_clan_list, and it appears to only add a new line, not re-write the whole file. At least from what I see it doing. (After the clan file is removed, I call write_clan_list, and clan.lst has not removed the old file reference) This is the stock function...

void write_clan_list( )
{
    CLAN_DATA *tclan;
    FILE *fpout;
    char filename[256];

    sprintf( filename, "%s%s", CLAN_DIR, CLAN_LIST );
    fpout = fopen( filename, "w" );
    if ( !fpout )
    {
        bug( "FATAL: cannot open clan.lst for writing!\n\r", 0 );
        return;
    }
    for ( tclan = first_clan; tclan; tclan = tclan->next )
        fprintf( fpout, "%s\n", tclan->filename );
    fprintf( fpout, "$\n" );
    fclose( fpout );
}
USA #3
Did you remember to unlink the clan data from the clan list?

Did you even delete the clan data from memory when you deleted the file?

In my case when a clan is deleted, either by the administration or automatically by the system, it removed the clan data from memory, unlinks it from the list, and THEN calls write_clan_list to rebuild the file.
Canada #4
The key line with this stuff is this
fpout = fopen( filename, "w" );
The "w" means to write, if the file exists, it overwrite it and creates an empty file. To add a line to the list would be to use "a".
USA #5
Yeah, forgot to uncomment the lines that would free that clan from the memory. Remember that as I was going to bed.