Re: Saving poofin/outs...

From: Ron Hensley (ron@peace.dmv.com)
Date: 05/29/96


> Sorry if this is a stupid question, but I'm just curious as to what I need
> to do to get poofins to save.  I realize poofins are similar in respect to
> aliases in that they are not a structure in the pfile.  So, to get them to
> save, I could put a char poofin and char poofout in the pfile, which of
> course would corrupt the pfile and would require a wipe, correct?

Wrong thankfully :) Yeah if you used the pfile it would require a wipe, 
as theres only free bytes and ints etc in there, no room for big long 
string buffers

> Is there an easier way to do the poof saving _without_ needing a pfile
> wipe, maybe incorporate it into alias saving (I have added the alias saving
> code to 3.0 bpl11)??

Ive done this exact thing. Actully I just took the alias.c code and 
hacked my own extras.c based on it. But your right, would be easiest just 
to add a line to read_aliases and write_aliases


Heres what i did though: Note this is done so i can add lots of things to 
this file without affecting the game at all. 

/**********  extras.c     ************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "structs.h"
#include "utils.h"
#include "interpreter.h"

void write_extras(struct char_data *ch)
{
  FILE *file;
  char fn[127];

  get_filename(GET_NAME(ch),fn,EXTRAS_FILE);
  unlink(fn);

  if(POOFIN(ch) == NULL && POOFOUT(ch) == NULL)
    return;

  if ( (file = fopen(fn,"wt")) == NULL)
    return;
  
  if (POOFIN(ch) != NULL) {
    fprintf(file,"|1\n");
    fprintf(file,"%s\n",POOFIN(ch));
  }
  if (POOFOUT(ch) != NULL) {
    fprintf(file,"|2\n");
    fprintf(file,"%s\n",POOFOUT(ch));
  }
  fclose(file);
} 
  
void read_extras(struct char_data *ch)
{
  FILE *file;
  char fn[127], buf[127];   
  char temp_buf[127];

  get_filename(GET_NAME(ch),fn,EXTRAS_FILE);
  
  file = fopen(fn,"r");
  
  if( !file )
    return;
  
  while (fgets(temp_buf,80,file)) {
  
     /* Yeah i was lazy at the time, this could be a strcmp()
    if (temp_buf[0] == '|' && temp_buf[1] == '1') {

      fgets(temp_buf,80,file);
      sprintf(buf,"poofin %s", temp_buf);
      command_interpreter(ch, buf);
    }
    if (temp_buf[0] == '|' && temp_buf[1] == '2') {
      fgets(temp_buf,80,file);
      sprintf(buf, "poofout %s", temp_buf);
      command_interpreter(ch, buf);
    }
  }
  fclose(file);
}

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


in utils.c

to the int get_filename() function, add:
  
  case EXTRAS_FILE:
    prefix = "plrextras";
    suffix = "extras";
    break;

to utils.h, add

  #define EXTRAS_FILE     3


Then is interpreter.c, in the function nanny, in the case '1' where the 
player enters the game, add an 
  read_extras();
right before the 
  break;

and in act.other.c in ACMD(do_save), add an:
  write_extras();
mines right before
  save_char(ch, NOWHERE);

add extras.c to Makefile
create mud/lib/plrextras
 A-E
 F-J
 K-O
 P-T
 U-Z
 ZZZ

Hope thats about it, gives you the generally idea though.
uses line labels 'l1' and 'l2' in the file so when reading back in you 
can tell if theres only an poofoit and no poofin or vice versa

So easy enough to add anything at all in there, with more line labels

Im sure theres better ways to do it, but hey ....... it works

    *******************************************************************
    *   Ron Hensley                     ron@dmv.com                   *
    *   Junior Systems Administrator    http://www.dmv.com/~ron       *
    *   DelMarVa OnLine                 749-1111 Ext. 403             *
    *******************************************************************



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