Re: Circle: The CircleMUD player file format

From: DoDGeR (dodger@WPI.EDU)
Date: 04/23/95


though each file is unique, here is an example that I wrote to give you an
idea....
/* ************************************************************************
*  file: purgeplay.c                                    Part of CircleMUD * 
*  Usage: purge useless chars from playerfile                             *
*  All Rights Reserved                                                    *
*  Copyright (C) 1992, 1993 The Trustees of The Johns Hopkins University  *
************************************************************************* */

#include <stdio.h>
#include <ctype.h>
#include <time.h>
#include <strings.h>
#include <sys/types.h>

typedef signed char     sbyte;
typedef unsigned char   ubyte;
typedef signed short int        sh_int;
typedef unsigned short int      ush_int;
typedef char    bool;
typedef char    byte;

#define LEVEL_IMPL      60
#define LEVEL_CIMP      59
#define LEVEL_GRGOD     58
#define LEVEL_GOD       57
#define LEVEL_DEMIGOD   56
#define LEVEL_AVATAR    55
#define LEVEL_WBUILD    54
#define LEVEL_QUESTOR   53
#define LEVEL_AMBASADOR 52
#define LEVEL_IMMORT    51

#define PLR_KILLER      (1 << 0)
#define PLR_THIEF       (1 << 1)
#define PLR_FROZEN      (1 << 2)
#define PLR_DONTSET     (1 << 3)   /* Dont EVER set (ISNPC bit) */
#define PLR_WRITING     (1 << 4)
#define PLR_MAILING     (1 << 5)
#define PLR_CRASH       (1 << 6)
#define PLR_SITEOK      (1 << 7)
#define PLR_NOSHOUT     (1 << 8)
#define PLR_NOTITLE     (1 << 9)
#define PLR_DELETED     (1 << 10)
#define PLR_LOADROOM    (1 << 11)
#define PLR_NOWIZLIST   (1 << 12)
#define PLR_NODELETE    (1 << 13)
#define PLR_INVSTART    (1 << 14)
#define PLR_CRYO        (1 << 15)
#define SECS_PER_REAL_MIN  60
#define SECS_PER_REAL_HOUR (60*SECS_PER_REAL_MIN)
#define SECS_PER_REAL_DAY  (24*SECS_PER_REAL_HOUR)
#define SECS_PER_REAL_YEAR (365*SECS_PER_REAL_DAY)

#define MAX_PWD_LENGTH 10
#define HOST_LEN       30
#define MAX_SKILLS     128
#define MAX_TOUNGE     3
#define MAX_AFFECT    32

#define MAX_PWD_LENGTH_NEW 10
#define HOST_LEN_NEW 30
#define MAX_SKILLS_NEW 250
#define MAX_TOUNGE_NEW 3
#define MAX_TITLE_LEN_NEW 80
#define MAX_XDESC_LEN_NEW 240
#define MAX_NAME_LEN_SAVE_NEW  20
#define MAX_AFFECT_NEW    32
#define MAX_POOF_NEW  250

struct char_ability_data_new 
{
  sbyte str;
  sbyte str_add;
  sbyte intel;
  sbyte wis;
  sbyte dex;
  sbyte con;
};

struct char_point_data_new 
{
  sh_int mana;
  sh_int max_mana;
  sh_int hit;
  sh_int max_hit;
  sh_int move;
  sh_int max_move;
  sh_int armor;
  int  gold;
  int  bank_gold;
  int  exp;
  sbyte hitroll;
  sbyte damroll;
};

struct char_special2_data_new 
{
  long idnum;
  sh_int load_room;
  byte spells_to_learn;
  int  alignment;
  long act;
  long pref;
  int  wimp_level;
  byte freeze_level;
  ubyte bad_pws;
  sh_int apply_saving_throw[5];
  sbyte conditions[3];
  char poofIn[MAX_POOF_NEW];
  char poofOut[MAX_POOF_NEW];
  ubyte spare0;
  ubyte spare1;
  ubyte spare2;
  ubyte spare3;
  ubyte spare4;
  ubyte spare5;
  ubyte spare6;
  ubyte spare7;
  ubyte spare8;
  ubyte spare9;
  ubyte spare10;
  ubyte spare11;
  long spare12;
  long spare13;
  long spare14;
  long spare15;
  long spare16;
  long spare17;
  long spare18;
  long spare19;
  long spare20;
  long spare21;
};


struct affected_type_new 
{
  sbyte type;
  sh_int duration;
  sbyte modifier;
  byte location;
  long bitvector;
  struct affected_type_new *next;
};
struct char_file_u_new 
{
  byte sex;
  byte class;
  byte level;
  time_t birth;
  /* Time of birth of character     */
  int  played;
  /* Number of secs played in total */
  ubyte weight;
  ubyte height;
  char title[MAX_TITLE_LEN_NEW];
  sh_int hometown;
  char description[MAX_XDESC_LEN_NEW];
  bool talks[MAX_TOUNGE_NEW];
  struct char_ability_data_new abilities;
  struct char_point_data_new points;
  byte skills[MAX_SKILLS_NEW];
  struct affected_type_new affected[MAX_AFFECT_NEW];
  struct char_special2_data_new specials2;
  time_t last_logon;
  /* Time (in secs) of last logon */
  char host[HOST_LEN_NEW+1];
  /* host of last logon */
  /* char data */
  char name[MAX_NAME_LEN_SAVE_NEW];
  char pwd[MAX_PWD_LENGTH_NEW+1];
};


/********************
 ********************
 ********************
 ********************/


struct char_ability_data 
{
  sbyte str;
  sbyte str_add;
  sbyte intel;
  sbyte wis;
  sbyte dex;
  sbyte con;
};

struct char_point_data 
{
  sh_int mana;
  sh_int max_mana;
  sh_int hit;
  sh_int max_hit;
  sh_int move;
  sh_int max_move;
  sh_int armor;
  int  gold;
  int  bank_gold;
  int  exp;
  sbyte hitroll;
  sbyte damroll;
};

struct char_special2_data 
{
  long idnum;
  sh_int load_room;
  byte spells_to_learn;
  int  alignment;
  long act;
  long pref;
  int  wimp_level;
  byte freeze_level;
  ubyte bad_pws;
  sh_int apply_saving_throw[5];
  sbyte conditions[3];
  ubyte spare0;
  ubyte spare1;
  ubyte spare2;
  ubyte spare3;
  ubyte spare4;
  ubyte spare5;
  ubyte spare6;
  ubyte spare7;
  ubyte spare8;
  ubyte spare9;
  ubyte spare10;
  ubyte spare11;
  long spare12;
  long spare13;
  long spare14;
  long spare15;
  long spare16;
  long spare17;
  long spare18;
  long spare19;
  long spare20;
  long spare21;
};


struct affected_type 
{
  sbyte type;
  sh_int duration;
  sbyte modifier;
  byte location;
  long bitvector;
  struct affected_type *next;
};
struct char_file_u 
{
  byte sex;
  byte class;
  byte level;
  time_t birth;
  /* Time of birth of character     */
  int  played;
  /* Number of secs played in total */
  ubyte weight;
  ubyte height;
  char title[80];
  sh_int hometown;
  char description[240];
  bool talks[MAX_TOUNGE];
  struct char_ability_data abilities;
  struct char_point_data points;
  byte skills[MAX_SKILLS];
  struct affected_type affected[MAX_AFFECT];
  struct char_special2_data specials2;
  time_t last_logon;
  /* Time (in secs) of last logon */
  char host[HOST_LEN+1];
  /* host of last logon */
  /* char data */
  char name[20];
  char pwd[MAX_PWD_LENGTH+1];
};




void	purge(char *filename)
{
   FILE * fl;
   FILE * outfile;
   struct char_file_u player;
   struct char_file_u_new player2;
   int	okay, num = 0;
   int i;
   long	timeout;
   char	*ptr, reason[80];
   struct affected_type *af;
   
   if (!(fl = fopen(filename, "r+"))) {
      printf("Can't open %s.", filename);
      exit();
   }

   outfile = fopen("players.fixed", "w");
   printf("editting: \n");

   for (; ; ) {
      fread(&player, sizeof(struct char_file_u ), 1, fl);
      if (feof(fl)) {
	 fclose(fl);
	 fclose(outfile);
	 puts("Done.");
	 exit();
      }

      okay = 1;
      *reason = '\0';

      for (ptr = player.name; *ptr; ptr++)
	 if (!isalpha(*ptr) || *ptr == ' ') {
	    okay = 0;
	    strcpy(reason, "Invalid name");
	 }

      if (player.level == 0) {
	 okay = 0;
	 strcpy(reason, "Never entered game");
      }

      if (player.level < 0 || player.level > LEVEL_IMPL) {
	 okay = 0;
	 strcpy(reason, "Invalid level");
      }

      /* now, check for timeouts.  They only apply if the char is not
       cryo-rented.   Lev 32-34 do not time out.  */

      if (okay && player.level <= LEVEL_IMMORT) {

	 if (!(player.specials2.act & PLR_CRYO)) {
	    if (player.level == 1)
	       timeout = 15;	/* Lev   1 : 4 days */
	    else if (player.level <= 4)	
	       timeout = 20;	/* Lev 2-4 : 7 days */
	    else if (player.level <= 10)	
	       timeout = 25;	/* Lev 5-10: 30 days */
	    else if (player.level <= LEVEL_IMMORT - 1) 
	       timeout = 35;	/* Lev 11-30: 60 days */
	    else if (player.level <= LEVEL_IMMORT)   
	       timeout = 90;	/* Lev 31: 90 days */
	 } else
	       timeout = 90;

	 timeout *= SECS_PER_REAL_DAY;

	 if ((time(0) - player.last_logon) > timeout) {
	    okay = 0;
	    sprintf(reason, "Level %2d idle for %3d days", player.level,
	        ((time(0) - player.last_logon) / SECS_PER_REAL_DAY));
	 }
      }

      if (player.specials2.act & PLR_DELETED) {
	 okay = 0;
	 sprintf(reason, "Deleted flag set");
      }

      if (!okay && (player.specials2.act & PLR_NODELETE)) {
	 okay = 2;
	 strcat(reason, "; NOT deleted.");
      }
      
      player2.sex=player.sex;
      player2.class=player.class-1;
      player2.level=player.level;
      player2.birth=player.birth;
      player2.played=player.played;
      player2.weight=player.weight;
      player2.height=player.height;
      strcpy(player2.title,player.title);
      player2.hometown=player.hometown;
      strcpy(player2.description,player.description);
      player2.last_logon=player.last_logon;
      for(i=0;i<MAX_TOUNGE;i++)
	player2.talks[i]=player.talks[i];
      for(;i<MAX_TOUNGE_NEW;i++)
	player2.talks[i]=0;
      for(i=0;i<MAX_SKILLS;i++)
	if(player.skills[i])
	  player2.skills[i]=player.skills[i];
	else
	  player2.skills[i]=0;
      for(;i<MAX_SKILLS_NEW;i++)
	player2.skills[i]=0;
      player2.skills[45]=0;
      player2.skills[46]=0;
      player2.skills[47]=0;
      player2.skills[48]=0;
      player2.skills[49]=0;
      player2.skills[50]=player.skills[61];
      player2.skills[51]=0;
      player2.skills[52]=player.skills[54];
      player2.skills[53]=player.skills[53];
      player2.skills[54]=player.skills[55];
      player2.skills[55]=player.skills[66];
      player2.skills[56]=player.skills[56];
      player2.skills[57]=player.skills[57];
      player2.skills[58]=player.skills[58];
      player2.skills[59]=player.skills[59];
      player2.skills[60]=player.skills[60];
      player2.skills[61]=player.skills[62];
      player2.skills[62]=player.skills[63];
      player2.skills[63]=player.skills[64];
      player2.skills[64]=player.skills[65];
      player2.skills[65]=0;
      player2.skills[66]=0;
      player2.skills[67]=0;
      player2.skills[161]=player.skills[48];
      player2.skills[162]=player.skills[51];
      player2.skills[163]=player.skills[46];
      player2.skills[164]=player.skills[50];
      player2.skills[165]=player.skills[49];
      player2.skills[166]=0;
      player2.skills[167]=player.skills[52];
      player2.skills[168]=player.skills[45];
      player2.skills[169]=player.skills[47];
      player2.skills[170]=0;
      player2.skills[171]=player.skills[67];
      for (af=&player.affected,i = 0; i < MAX_AFFECT; i++) 
       {
	 if (af) 
	  {
	    player2.affected[i].type = player.affected[i].type;
	    player2.affected[i].duration=player.affected[i].duration;
	    player2.affected[i].modifier=player.affected[i].modifier;
	    player2.affected[i].location=player.affected[i].location;
	    player2.affected[i].bitvector=player.affected[i].bitvector;
	    player2.affected[i].next = 0;
	    af = af->next;
	  }
	 else 
	  {
	    player2.affected[i].type = 0;
	      /* Zero signifies not used */
	    player2.affected[i].duration = 0;
	    player2.affected[i].modifier = 0;
	    player2.affected[i].location = 0;
	    player2.affected[i].bitvector = 0;
	    player2.affected[i].next = 0;
	  }
       }
      for(;MAX_AFFECT_NEW>i;i++)
       {	   
	 player2.affected[i].type = 0;
	 /* Zero signifies not used */
	 player2.affected[i].duration = 0;
	 player2.affected[i].modifier = 0;
	 player2.affected[i].location = 0;
	 player2.affected[i].bitvector = 0;
	 player2.affected[i].next = 0;
       }
      strcpy(player2.host,player.host);
      strcpy(player2.name,player.name);
      strcpy(player2.pwd,player.pwd);
      player2.abilities.str=player.abilities.str;
      player2.abilities.str_add=player.abilities.str_add;
      player2.abilities.dex=player.abilities.dex;
      player2.abilities.wis=player.abilities.wis;
      player2.abilities.intel=player.abilities.intel;
      player2.abilities.con=player.abilities.con;

      player2.points.mana=player.points.mana;
      player2.points.max_mana=player.points.max_mana;
      player2.points.hit=player.points.hit;
      player2.points.max_hit=player.points.max_hit;
      player2.points.move=player.points.move;
      player2.points.max_move=player.points.max_move;
      player2.points.armor=player.points.armor;
      player2.points.gold=player.points.gold;
      player2.points.bank_gold=player.points.bank_gold;
      player2.points.exp=player.points.exp;
      player2.points.hitroll=player.points.hitroll;
      player2.points.damroll=player.points.damroll;
      
      player2.specials2.idnum=player.specials2.idnum;
      player2.specials2.load_room=player.specials2.load_room;
      player2.specials2.spells_to_learn=player.specials2.spells_to_learn;
      player2.specials2.alignment=player.specials2.alignment;
      player2.specials2.act=player.specials2.act;
      player2.specials2.pref=player.specials2.pref;
      player2.specials2.wimp_level=player.specials2.wimp_level;
      player2.specials2.freeze_level=player.specials2.freeze_level;
      player2.specials2.bad_pws=player.specials2.bad_pws;
      for (i=0;i<5;i++)
	player2.specials2.apply_saving_throw[i]=player.specials2.apply_saving_throw[i];
      for(i=0;i<3;i++)
	player2.specials2.conditions[i]=player.specials2.conditions[i];
      strcpy(player2.specials2.poofIn,"\0");
      strcpy(player2.specials2.poofOut,"\0");
      
      










	 if (okay)
	 fwrite(&player2, sizeof(struct char_file_u_new ), 1, outfile);
      else
	 printf("%4d. %-20s %s\n", ++num, player2.name, reason);

      if (okay == 2)
	 fprintf(stderr, "%-20s %s\n", player2.name, reason);
   }
}



void main(int argc, char *argv[])
{
   if (argc != 2)
      printf("Usage: %s playerfile-name\n", argv[0]);
   else
      purge(argv[1]);
}


-------------------------------------------------------------------------------
Harvard Law:
        Under the most rigorously controlled conditions of pressure,
        temperature, volume, humidity, and other variables, the
        organism will do as it damn well pleases.
DoDGeR@wpi.wpi.edu



This archive was generated by hypermail 2b30 : 12/07/00 PST