03 May, 2009, Banner wrote in the 1st comment:
Votes: 0
I was thinking of writing a function to check and remove inactive pfiles, but I had a few questions.

1) How would you search a pfile that is not logged in, so I'd need to scan the file, what would I use?

2) What value would I check? Last logout time, I'd think.

3) How would I convert that big number into something like 3 days or 30 days or whatever?
03 May, 2009, Kline wrote in the 2nd comment:
Votes: 0
Here's a block of code in used on a GodWars-based game I maintain; written by a friend. It works fine for us, but could probably be cleaned/add logging/"move" deletions instead of "delete" them, etc. Hope it's a good basis to start from!

void pwipe()
{
DESCRIPTOR_DATA *d;
struct dirent *Dir;
struct stat Stat;
DIR *Directory;
DIR *Backup;
DIR *Store;
char FName[80];
char F2Name[80];
char F3Name[80];
time_t real_time = current_time;
time_t Ptime;

d = new_ghost_descriptor();

Directory=opendir(PLAYER_DIR);
Backup = opendir(BACKUP_DIR);
Store = opendir( BACK2_DIR);
Dir=readdir(Directory);
log_string("Begining Scan/deletion of old pfiles.\n\r");
while(Dir!=NULL)
{
xprintf(FName, PLAYER_DIR"%s", Dir->d_name);
xprintf(F2Name, BACKUP_DIR"%s", Dir->d_name);
xprintf(F3Name, BACK2_DIR"%s", Dir->d_name);
stat( FName, &Stat);
if(S_ISREG(Stat.st_mode)) {
if (Dir->d_name[0] >= 'A' && Dir->d_name[0] <= 'Z') {
load_char_obj( d, Dir->d_name);
// wipe files older than 90 days
Ptime = (int) d->character->lasttime;
if ( (real_time - Ptime) > (86400 * 90))
{
log_string(Dir->d_name);
unlink(FName);
unlink(F2Name);
unlink(F3Name);
}
}
}
Dir=readdir(Directory);
}
log_string("Done with player scan.\n\r");
closedir(Directory);
closedir(Backup);
closedir(Store);
}
03 May, 2009, Sharmair wrote in the 3rd comment:
Votes: 0
I assume by you even asking this, that you don't have the stock SMAUG grux.c file (it was omitted
from the last couple versions - I think 1.4 was the last one to have it). Grux deleted pfiles based on
number of days inactive (it used the file time as the last activity) and the level of the player, it also
built the player database that the grub command uses. Grux was a stand alone program that was
meant to be ran daily (probably from the startup script on the daily reboot).

Basically you would use opendir/readdir/closedir to scan the directories for pfiles, then open each
file and scan for the data you need (grux just scans for level and uses the stat function to get the
file time, but you could also scan for a last log on data point in the pfile if that is your last activity
data).

The time you have would probably be a time_t, and that is in seconds, so you would just subtract
the last activity time from the current time to get the number of seconds, then you could divide
by 86400 to get the number of days (rounded down - well, assuming int math).

On my SMAUG derived MUD, I made two in MUD commands, one to clean players and another to
build the player database using some of the code from grux.c. It has worked out quite well and
this sounds a lot like what you are doing, so it might work for you too.
03 May, 2009, Guest wrote in the 4th comment:
Votes: 0
You should also go poke around the snippets section for Smaug. You should see the pfile cleanup code sitting there, calling to you, disappointed you haven't noticed it yet… :)
03 May, 2009, Banner wrote in the 5th comment:
Votes: 0
Samson said:
You should also go poke around the snippets section for Smaug. You should see the pfile cleanup code sitting there, calling to you, disappointed you haven't noticed it yet… :)

I had that once, but it has some kind of bug in it. It corrupted pfiles and randomly deleted ones that were just on the other day, leaving me restoring backups every so often so I eventually had to remove it.
03 May, 2009, Guest wrote in the 6th comment:
Votes: 0
You'll forgive me if I question the claims that it has "some kind of bug in it" when it's been used in numerous games and hasn't had anything more than a minor memory leak due to string allocation reported in the whole time it's been around. And it was used on Alsherok as well so I'm pretty sure it doesn't do the things you say.

You could of course have tried reporting the issues, so if they do exist they can be investigated. It's highly unlikely there ARE any issues though or it would have been widely reported by now.
04 May, 2009, Banner wrote in the 7th comment:
Votes: 0
Samson said:
You'll forgive me if I question the claims that it has "some kind of bug in it" when it's been used in numerous games and hasn't had anything more than a minor memory leak due to string allocation reported in the whole time it's been around. And it was used on Alsherok as well so I'm pretty sure it doesn't do the things you say.

You could of course have tried reporting the issues, so if they do exist they can be investigated. It's highly unlikely there ARE any issues though or it would have been widely reported by now.

No it's more likely that I'm making it up. At any rate, once it was removed, the problems stopped. Although that code was added in by another coder, so perhaps it was modified or added incorrectly, but either way, it deleted pfiles errornously and removing it solved the problems. I never report bugs back to snippet authors, my mistake. If this isn't a widely known error, then I'll try that code again to see if it causes any more problems.
04 May, 2009, quixadhal wrote in the 8th comment:
Votes: 0
Banner said:
I was thinking of writing a function to check and remove inactive pfiles, but I had a few questions.

1) How would you search a pfile that is not logged in, so I'd need to scan the file, what would I use?

2) What value would I check? Last logout time, I'd think.

3) How would I convert that big number into something like 3 days or 30 days or whatever?


One thing you could do IF you're on a system that preserves access times for files (not all do, and many admins turn that off for performance reasons), is start by filtering your player file list by access time. Files accessed within N days don't need to be looked at. If you were writing a script to do this, "man find" and look down at the "atime" entry.

If your player files have a last logout time, it's probably stored as a simple unix timestamp. Subtract that from now to get how many seconds since they logged out. I typed this at 1241452187, which I got via the command date "+%s". So, if you don't have or don't trust access time, you can do that comparison on each file and remove any where the difference is larger than you want.

That said… I don't. Disk space is dirt-cheap, I'd rather have some level 1 player who visited 3 years ago go "Wow! My character still exists?", rather than someone who played all the time, got bored and wandered off, and then came back a year later to find their level 50 character they spent half a year of their life building is gone.
04 May, 2009, Banner wrote in the 9th comment:
Votes: 0
quixadhal said:
That said… I don't. Disk space is dirt-cheap, I'd rather have some level 1 player who visited 3 years ago go "Wow! My character still exists?", rather than someone who played all the time, got bored and wandered off, and then came back a year later to find their level 50 character they spent half a year of their life building is gone.

I have the space, but its about other things. Finger information, clan membership data and number counts, hiscore tables, login history, account accuracy/character counts, ect. that I'd like to be up to date with information that isn't cluttered by people that haven't been on in months. Also, I'm only using it on the active player directory. The backup directory will retain all characters that were ever deleted or killed, which can be used to revert a deleted pfile should the need arise.
04 May, 2009, Zenn wrote in the 10th comment:
Votes: 0
If it's a question of information, why not have the systems only show people that have been online within x amount of days, rather than deleting the characters?
05 May, 2009, Banner wrote in the 11th comment:
Votes: 0
Because it's easier to rid the information in one fell swoop than to travel throughout my entire code and write an ifcheck to hide information if someone isn't on. Work with me here.
05 May, 2009, quixadhal wrote in the 12th comment:
Votes: 0
Rename the files as whatever.inactive, or move them to an inactive directory… that way your login code can check for their existence if the normal version isn't present, and rename them if they actually log back in. All the rest of your code can ignore them.
11 Jun, 2009, Metsuro wrote in the 13th comment:
Votes: 0
quixadhal said:
Rename the files as whatever.inactive, or move them to an inactive directory… that way your login code can check for their existence if the normal version isn't present, and rename them if they actually log back in. All the rest of your code can ignore them.


Then how would you handle names, all inactive players still tie up avaible names? or do you move them and offer a free name change when they get back? do you force the new guy with that name to change name?
11 Jun, 2009, quixadhal wrote in the 14th comment:
Votes: 0
That's up to you. I don't like the idea of deleting player files… ever. I guess I'd make an exception for level 1 characters, since they have no real investment anyways, but anyone who's played more than a dozen hours deserves the chance to return without losing any progress. Since the OP is insisting on it, I suggested renaming them rather than deleting them, so you can restore an old player if they come back. If there isn't a name conflict, the system could do this itself. If there is, it's up to you to decide whom to rename, and how to go about it.
0.0/14