Beispiel #1
0
void write_aliases(struct char_data *ch)
{
  FILE *file;
  char fn[MAX_STRING_LENGTH];
  struct alias_data *temp;

  get_filename(GET_NAME(ch), fn, ALIAS_FILE);
  /*remove(fn); do we really need this? fopen w should overwrite*/

  if (GET_ALIASES(ch) == NULL)
    return;

  if ((file = fopen(fn, "w")) == NULL) {
    log("SYSERR: Couldn't save aliases for %s in '%s'.", GET_NAME(ch), fn);
    perror("SYSERR: write_aliases");
    return;
  }

  for (temp = GET_ALIASES(ch); temp; temp = temp->next) {
    int aliaslen = strlen(temp->alias);
    int repllen = strlen(temp->replacement) - 1;

    fprintf(file, "%d\n%s\n"	/* Alias */
		  "%d\n%s\n"	/* Replacement */
		  "%d\n",	/* Type */
		aliaslen, temp->alias,
		repllen, temp->replacement + 1,
		temp->type);
  }
  
  fclose(file);
}
Beispiel #2
0
void read_aliases(CHAR_DATA * ch)
{
	FILE *file;
	char xbuf[MAX_STRING_LENGTH];
	struct alias_data *t2;
	int length;

	log("Read alias %s", GET_NAME(ch));
	get_filename(GET_NAME(ch), xbuf, ALIAS_FILE);

	if ((file = fopen(xbuf, "r")) == NULL)
	{
		if (errno != ENOENT)
		{
			log("SYSERR: Couldn't open alias file '%s' for %s.", xbuf, GET_NAME(ch));
			perror("SYSERR: read_aliases");
		}
		return;
	}

	CREATE(GET_ALIASES(ch), struct alias_data, 1);
	t2 = GET_ALIASES(ch);

	for (;;)  		/* Read the aliased command. */
	{
		fscanf(file, "%d\n", &length);
		fgets(xbuf, length + 1, file);
		t2->alias = str_dup(xbuf);

		/* Build the replacement. */
		fscanf(file, "%d\n", &length);
		*xbuf = ' ';	/* Doesn't need terminated, fgets() will. */
		fgets(xbuf + 1, length + 1, file);
		t2->replacement = str_dup(xbuf);

		/* Figure out the alias type. */
		fscanf(file, "%d\n", &length);
		t2->type = length;

		if (feof(file))
			break;

		CREATE(t2->next, struct alias_data, 1);
		t2 = t2->next;
	};

	fclose(file);
}
Beispiel #3
0
/*
 * Save a character and inventory.
 * Would be cool to save NPC's too for quest purposes,
 *   some of the infrastructure is provided.
 */
bool save_char_obj( struct char_data *ch )
{
    FILE *fp;
    char  buf     [ MAX_STRING_LENGTH ];
    char  strsave [ MAX_INPUT_LENGTH  ];
    bool  rval = FALSE;

    if ( IS_NPC( ch ) ) // || GET_LEVEL( ch ) < 2 )
      return rval;

    if ( GET_DESC(ch) && GET_DESC(ch)->original )
      ch = GET_DESC(ch)->original;

    // GET_SAVED(ch) = time( 0 );
    /* close down the reserve descriptor -- don't forget to reopen it */
    fclose( fpReserve );

    sprintf( strsave, "%s/%s/%s", PLAYER_DIR,
             player_dir( GET_NAME( ch ) ),
             capitalize( GET_NAME( ch ) ) );

    if ( !( fp = fopen( strsave, "w" ) ) ) {
      sprintf( buf, "save_char_obj: fopen %s: ", GET_NAME( ch ) );
      log( buf );
      perror( strsave );
      rval = FALSE;
    } else {
      fwrite_char( ch, fp );
      if ( ch->carrying )
        fwrite_obj_char( ch, ch->carrying, fp, 0 );
      if ( GET_ALIASES(ch) )
        fwrite_alias( ch, GET_ALIASES(ch), fp );
      fprintf( fp, "#END\n" );
      fclose( fp );
      rval = TRUE;
    }
    fpReserve = fopen( NULL_FILE, "r" );
    return rval;
}
Beispiel #4
0
void load_text(struct char_data * ch)
{
  FILE *fil = NULL;
  char fname[MAX_INPUT_LENGTH];
  struct alias *al;
  int i, cnt;

  void free_alias(struct alias * a);

  if (IS_NPC(ch))
    return;

  if (!get_filename(GET_NAME(ch), fname, ETEXT_FILE))
    return;

  if (!(fil = fopen(fname, "r"))) {
    if (errno != ENOENT) { /* if it fails, NOT because of no file */
      sprintf(buf1, "SYSERR: READING TEXT FILE %s (5)", fname);
      perror(buf1);
      send_to_char("\r\n***** NOTICE - THERE WAS A PROBLEM READING YOUR ALIAS FILE *****\r\n", ch);
      return;
    }
    return;
  }

  while ((al = GET_ALIASES(ch)) != NULL) { /* get rid of alias multiplying problem */
    GET_ALIASES(ch) = (GET_ALIASES(ch))->next;
    free_alias(al);
  }

  cnt = 200; /* security counter to make memory alloc bombing impossible :) */
  fscanf(fil, "%d\n", &i); /* get first type */
  while (i != -1 && cnt != 0) {
    CREATE(al, struct alias, 1);
    al->type = i;
    fgets(buf, MAX_INPUT_LENGTH, fil);
    buf[strlen(buf) - 1] = '\0';
    al->alias = strdup(buf);
    fgets(buf, MAX_INPUT_LENGTH, fil);
    buf[strlen(buf) - 1] = '\0';
    al->replacement = strdup(buf);
    al->next = ch->player_specials->aliases;
    ch->player_specials->aliases = al;
    fscanf(fil, "%d\n", &i);
    cnt--;
  }
  /* aliases has been loaded */
  if (WHOSPEC(ch)) {
    FREE(WHOSPEC(ch));
  }
  if (POOFIN(ch)) {
    FREE(POOFIN(ch));
  }
  if (POOFOUT(ch)) {
    FREE(POOFOUT(ch));
  }
  if (WHOSTR(ch)) {
    FREE(WHOSTR(ch));
  }
  if (NAMECOLOR(ch)) {
    FREE(NAMECOLOR(ch));
  }

  fgets(buf, MAX_INPUT_LENGTH, fil);
  buf[strlen(buf) - 1] = '\0';
  if (str_cmp("!UNUSED!", buf)) {
    WHOSPEC(ch) = strdup(buf);
  }
  fgets(buf, SMALL_BUFSIZE, fil);
  buf[strlen(buf) - 1] = '\0';
  if (str_cmp("!UNUSED!", buf)) {
    POOFIN(ch) = strdup(buf);
  }
  fgets(buf, SMALL_BUFSIZE, fil);
  buf[strlen(buf) - 1] = '\0';
  if (str_cmp("!UNUSED!", buf)) {
    POOFOUT(ch) = strdup(buf);
  }
  fgets(buf, MAX_INPUT_LENGTH, fil);
  buf[strlen(buf) - 1] = '\0';
  if (str_cmp("!UNUSED!", buf)) {
    WHOSTR(ch) = strdup(buf);
  }
  if (fgets(buf, SMALL_BUFSIZE, fil) > (char*) NULL) {
    buf[strlen(buf) - 1] = '\0';
    if (str_cmp("!UNUSED!", buf)) {
      NAMECOLOR(ch) = strdup(buf);
    }
  }

  if (cnt == 0) {
    send_to_char("Undetermined error when reading your alias file ...\r\n", ch);
    sprintf(buf, "ERROR when reading %s's alias file.", GET_NAME(ch));
    mudlog(buf, 'W', COM_IMMORT, TRUE);
    plog(buf, ch, 0);
  }
  fclose(fil);
  return;
}