aliases that start with * break the pfile

Login to reply  Page: « < 1 of 1 > »
30 Jun 2010 - 10:242794
aliases that start with * break the pfile
Found this one last night, so it's not in the code I sent to fizban. Fortunately it only busts the alias section in standard TBA, but if someone inserted something after aliases then it could corrupt that too.

The problem is that get_line treats all lines starting with * as a comment. It's a trivial fix if breaking existing aliases is allowed (not a problem for me). Do you want that version of the fix, or shall I find something that doesn't?



Last edited by Dio (30 Jun 2010 - 10:25)
30 Jun 2010 - 15:322795
Great, thanks. Ideally a non-alias-wiping version would be nice since some people will be upgrading their existing MUDs.


__________________
Rumble
The Builder Academy
tbamud.com 9091
01 Jul 2010 - 08:212796
Righto, this looks to do the job.

 static void write_aliases_ascii(FILE *file, struct char_data *ch)
{
  struct alias_data *temp;
  int count = 0;

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

  for (temp = GET_ALIASES(ch); temp; temp = temp->next)
    count++;

  fprintf(file, "Alis: %d\n", count);

  for (temp = GET_ALIASES(ch); temp; temp = temp->next)
    fprintf(file, " %s\n"   /* Alias: prepend a space in order to avoid issues with aliases beginning
                             * with * (get_line treats lines beginning with * as comments and ignores them */
                  "%s\n"    /* Replacement: always prepended with a space in memory anyway */
                  "%d\n",   /* Type */
                  temp->alias,
                  temp->replacement,
                  temp->type);
}

static void read_aliases_ascii(FILE *file, struct char_data *ch, int count)
{
  int i;

  if (count == 0) {
    GET_ALIASES(ch) = NULL;
    return; /* No aliases in the list. */
  }

  /* This code goes both ways for the old format (where alias and replacement start at the
   * first character on the line) and the new (where they are prepended by a space in order
   * to avoid the possibility of a * at the start of the line */
  for (i = 0; i < count; i++) {
    char abuf[MAX_INPUT_LENGTH+1], rbuf[MAX_INPUT_LENGTH+1], tbuf[MAX_INPUT_LENGTH];

    /* Read the aliased command. */
    get_line(file, abuf);

    /* Read the replacement. This needs to have a space prepended before placing in
     * the in-memory struct. The space may be there already, but we can't be certain! */
    rbuf[0] = ' ';
    get_line(file, rbuf+1);

    /* read the type */
    get_line(file, tbuf);

    if (abuf[0] && rbuf[1] && *tbuf) {
      struct alias_data *temp;
      CREATE(temp, struct alias_data, 1);
      temp->alias       = strdup(abuf[0] == ' ' ? abuf+1 : abuf);
      temp->replacement = strdup(rbuf[1] == ' ' ? rbuf+1 : rbuf);
      temp->type        = atoi(tbuf);
      temp->next        = GET_ALIASES(ch);
      GET_ALIASES(ch)   = temp;
    }
  }
}

Since replacement has a space in front of it in memory anyway, I decided to just stick a space in front of both alias and replacement in the pfile and parse either format of input.


03 Jul 2010 - 01:202797
Thanks, added.


__________________
Rumble
The Builder Academy
tbamud.com 9091
Login to reply  Page: « < 1 of 1 > »