Converting player files from BIF @ StrangeMUD

CAVNESS@orange.cc.utexas.edu
Date: 03/29/94


From:	IN%"ec938236@ebar.dth.dk"  "Poul Rxste Hansen" 28-MAR-1994 22:18:49.92
To:	IN%"CAVNESS@utxvms.cc.utexas.edu"
CC:	
Subj:	no subject (file transmission)

Return-path: <ec938236@ebar.dth.dk>
Received: from dese01.ebar.dth.dk by utxvms.cc.utexas.edu (PMDF V4.3-6 #4544)
 id <01HAIRYCVS4G8WWEMD@utxvms.cc.utexas.edu>; Mon, 28 Mar 1994 22:12:13 CST
Received: by dese01.ebar.dth.dk (5.57/1.34) id AA10193; Tue,
 29 Mar 94 05:12:08 +0200
Date: Tue, 29 Mar 1994 05:12:07 +0100 (MET)
From: Poul Rxste Hansen <ec938236@ebar.dth.dk>
Subject: no subject (file transmission)
To: CAVNESS@utxvms.cc.utexas.edu
Message-id: <9403290312.AA10193@dese01.ebar.dth.dk>
X-Mailer: ELM [version 2.3 PL11]
Content-transfer-encoding: 7BIT

in file comm.c :

int	main(int argc, char **argv)
{
   int	port, i;
   char	buf[512];
   int	pos = 1;
   char	*dir;

   port = DFLT_PORT;
   dir = DFLT_DIR;

   while ((pos < argc) && (*(argv[pos]) == '-')) {
      switch (*(argv[pos] + 1)) {
      case 'd':
	 if (*(argv[pos] + 2))


.......


	 no_specials = 1;
	 log("Suppressing assignment of special routines.");
	 break;
      case 'c':
	 if (chdir(dir) < 0) {
	    perror("Fatal error changing to data directory");
	    exit(0);
	 }
	 log("Converting player files to new format...");
         i=convert_to_new();
	 if (i) sprintf(buf, "Conversion succeeded... :)");
		else sprintf(buf, "Conversion failed... :("); 
	 log(buf);
	 return(i); 
	 break;
     default:
	 sprintf(buf, "SYSERR: Unknown option -%c in argument string.", *(argv[pos] + 1));
	 log(buf);
	 break;
      }

...........

------------------------------

in file structs.h

/* this file will be in the format that the converted file will be in.....
	after conversion, copy this struct into char_file_u ..... */ 

struct conv_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];
};

-------------------------------------------------------------------

file db.h


#define POLICIES_FILE	"text/policies"	/* player policies/rules	*/
#define HANDBOOK_FILE	"text/handbook"	/* handbook for new immorts	*/

#define CONV_FILE	"misc/players.converted"
#define PLAYER_FILE	"misc/players"	/* the player database		*/
#define MESS_FILE	"misc/messages"	/* damage message		*/

.....

/* public procedures in db.c */

int	convert_to_new(void);
void	boot_db(void);
.....

-----------------------------------

file db.c

struct player_index_element *player_table = 0; /* index to player file	*/
FILE *player_fl = 0;			/* file desc of player file	*/
FILE *conv_player_fl = 0;
int	top_of_p_table = 0;		/* ref to top of table		*/
int	top_of_p_file = 0;		/* ref of size of p file	*/

.............




int	convert_to_new(void)
{
   struct char_file_u cfrom;
   struct conv_char_file_u cto;
   long	size, recs;
   int i;

   if (!(player_fl = fopen(PLAYER_FILE, "r+b"))) {
      perror("Error opening playerfile");
      return(0);
   }

   if (!(conv_player_fl = fopen(CONV_FILE, "w+b"))) {
      perror("Error opening convert_playerfile");
      return(0);
   }

   fseek(player_fl, 0L, SEEK_END);
   size = ftell(player_fl);
   rewind(player_fl);
   if (size % sizeof(struct char_file_u))
      fprintf(stderr, "WARNING:  PLAYERFILE IS PROBABLY CORRUPT!\n");
   recs = size / sizeof(struct char_file_u);
   if (recs) {
      sprintf(buf, " %ld players in db ready for conversion.", recs);
      log(buf);
   } else {
      log("Why the fuck should you convert, when there's nothing to convert???");
	return(0);
   }
   
   for (; !feof(player_fl); ) {
      fread(&cfrom, sizeof(struct char_file_u), 1, player_fl);
	cto.sex=cfrom.sex;
	cto.class=cfrom.class;
	cto.level=cfrom.level;
	cto.birth=cfrom.birth;
	cto.played=cfrom.played;

 	cto.weight=cfrom.weight;
	cto.height=cfrom.height;

	strcpy(cto.title, cfrom.title);
	cto.hometown=cfrom.hometown;
	strcpy(cto.description, cfrom.description);
	strcpy(cto.talks, cfrom.talks);
	
	cto.abilities=cfrom.abilities;

	cto.points=cfrom.points;

	for (i=0;i<=MAX_SKILLS;i++) cto.skills[i]=cfrom.skills[i];

	for (i=0;i<=MAX_AFFECT;i++) cto.affected[i]=cfrom.affected[i];

	cto.specials2=cfrom.specials2;

	cto.last_logon=cfrom.last_logon;
	strcpy(cto.host, cfrom.host);

	strcpy(cto.name, cfrom.name);
	strcpy(cto.pwd, cfrom.pwd);
	
	if (!feof(player_fl)) {
	   fwrite(&cto, sizeof(struct conv_char_file_u), 1, conv_player_fl);
	   sprintf (buf, "Conversion of %s is now done.", cto.name);
	   log(buf);
	}

   }
   log("Conversion finished....");
   fclose(player_fl);
   fclose(conv_player_fl);
   system("cp misc/players misc/players.safety");
   return(1);
}




.... :)

remember...after having used it with a conv_char_file_u different than the
char_file_u.....change the current char_file_u to match the conv_char_file_u,
so that it uses the new additions as standard...
:)


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cavness@utxvms.cc.utexas.edu        |       The Great Holy Star Goat
Kenneth G. Cavness                  |          is with all of us,
"Supreme Diva"                      |         braised be Its name.
"I'm pro-choice--please don't       |
shoot me in the back."              |     Braise the name of Our Lard!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                    



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