On Tue, 18 Nov 1997, Chris Jacobson wrote:
> I use a Perl script by Patrick Dughi for cleaning out ASCII pfiles... all
> it does right now is check for the Deleted flag. However, I was
> wondering if it was possible to add in a check for Levl: # being less
> than a certain number, and the file being older than, say, 30 days.
>
> Is this possible? If so, anyone care to give me a small snippet of code?
> I know no Perl :-)
The best way to keep your pfiles clean is probably to add it to your mud's
bootup code. I added player level and last-on to the player index and
added a clean_pfiles() function using the old purgeplay.c code as a model.
Here's some of the code that was involved:
/* db.h */
/* revised index struct...race, class, clan aren't needed */
struct player_index_element {
char *name;
long id;
int level;
int race;
int class;
int clan;
long last;
};
/* db.c */
/* replacement that skips deleted players */
void save_player_index(void)
{
int i;
FILE *index_file;
if(!(index_file = fopen(PLR_INDEX_FILE, "w"))) {
log("SYSERR: Could not write player index file");
return;
}
for(i = 0; i <= top_of_p_table; i++)
if(*player_table[i].name) {
fprintf(index_file, "%s %d %d %d %d %d %d\n", player_table[i].name,
(int)player_table[i].id, player_table[i].level,
player_table[i].race, player_table[i].class,
player_table[i].clan, (int) player_table[i].last);
}
fclose(index_file);
}
/* a "thing" command (call it what you want) to generate a new index file */
ACMD(do_thing)
{
int i, j;
FILE *fl;
struct char_file_u player;
struct char_data *p;
char arg[256];
long timeout = 1000;
CREATE(p, struct char_data, 1);
for(i = 0; i <= top_of_p_table; i++) {
memset((char *) &player, 0, sizeof(struct char_file_u));
load_char(player_table[i].name, &player, NULL);
clear_char(p);
store_to_char(&player, p);
sprintf(buf, "%s %d %d %d %d %d %d\n", player_table[i].name,
(int) GET_IDNUM(p), GET_LEVEL(p),
GET_RACE(p), GET_CLASS(p),
GET_CLAN(p), (int) player.last_logon);
fprintf(fl, buf);
}
fclose(fl);
}
/* new function that removes associated files...you'll have to edit this
to make it work with your mud
*/
void remove_player(long id, byte stomp)
{
long i;
for(i = 0; i < top_of_p_table; i++)
if(player_table[i].id > 0 && player_table[i].id == id)
break;
if(player_table[i].id != id || !*player_table[i].name)
return;
sprintf(buf, "%s/%c/%s", PLR_PREFIX, *player_table[i].name,
player_table[i].name);
chmod(buf, S_IREAD | S_IWRITE);
unlink(buf);
sprintf(buf, "%s/%c/%s", RENT_PREFIX, *player_table[i].name,
player_table[i].name);
chmod(buf, S_IREAD | S_IWRITE);
unlink(buf);
get_filename(player_table[i].name, buf, SAVES_FILE);
unlink(buf);
sprintf(buf, "%s/%c/%s", MAIL_PREFIX, *player_table[i].name,
player_table[i].name);
chmod(buf, S_IREAD | S_IWRITE);
unlink(buf);
if(stomp)
*player_table[i].name = '\0';
}
/* the actual cleanup code...modify to suit your needs and add to the
boot code
*/
void clean_pfiles(void)
{
int i, timeout;
struct char_file_u plr;
for(i = 0; i < top_of_p_table; i++) {
if(player_table[i].level < 1)
timeout = 0;
/*else if(player_table[i].level == 1)
timeout = 4;
else if(player_table[i].level <= 10)
timeout = 21;
else if(player_table[i].level <= 20)
timeout = 31;*/
else
timeout = 90;
timeout *= SECS_PER_REAL_DAY;
if((time(0) - player_table[i].last) > timeout) {
memset((char *) &plr, 0, sizeof(struct char_file_u));
if((load_char(player_table[i].name, &plr, NULL)) >= 0)
/*if(IS_SET(plr.char_specials_saved.act, PLR_NODELETE)) {
sprintf(buf, "PCLEAN: (PLR_NODEL) %s skipped",
player_table[i].name);
log(buf);
continue;
}*/
remove_player(plr.char_specials_saved.idnum, TRUE);
if(player_table[i].id > 0) {
sprintf(buf, "PCLEAN: %s Lev:%d Last:%s",
plr.name ? plr.name : "(null)", plr.level,
asctime(localtime(&plr.last_logon)));
log(buf);
}
}
}
save_player_index();
}
Keep in mind that this code probably wouldn't compile in anyone's mud
without modificaiton. It's just a base to get you started so if you want
to use it please read the code carefully and understand what it does
before using it.
Sam
+------------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
| http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
+------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/08/00 PST