Ascii Pfile Index Problem

From: Stephen Squires (gicker42@hotmail.com)
Date: 02/03/02


  Hello, I recently patched in ascii pfiles, file ascii.201.1.patch
on the ftp site.

  It seems to work more or less ok, but it only reads the first
record from the plr_index.  The files save fine, and records
are added to the index fine as well, it just isn't loading them.
So only the first character created an actually log in after
they've created.

  I've seen a question like this in the archives but it wasn't answered.

  Here are some code snippets that might help:

void build_player_index(void)
{
  int rec_count = 0, i;
  FILE *plr_index;
  char index_name[40], line[256], bits[64];
  char arg2[80];

  sprintf(index_name, "%s", PLR_INDEX_FILE);
  if(!(plr_index = fopen(index_name, "r"))) {
    top_of_p_table = -1;
    log("No player index file!  First new char will be IMP!");
    return;
   }

  /* count the number of players in the index */
  while(get_line(plr_index, line))
    if(*line != '~')
      rec_count++;
  rewind(plr_index);

  if(rec_count == 0) {
     player_table = NULL;
     top_of_p_file = top_of_p_table = -1;
     return;
   }

  CREATE(player_table, struct player_index_element, rec_count);
  for(i = 0; i < rec_count; i++) {
    get_line(plr_index, line);
    sscanf(line, "%ld %s %d %s %d", &player_table[i].id, arg2,
        &player_table[i].level, bits, (int *)&player_table[i].last);
    CREATE(player_table[i].name, char, strlen(arg2) + 1);
    strcpy(player_table[i].name, arg2);
    player_table[i].flags = asciiflag_conv(bits);
    top_idnum = MAX(top_idnum, player_table[i].id);
  }
  fclose(plr_index);
  top_of_p_file = top_of_p_table = i - 1;
}

int load_char(char *name, struct char_data * ch)
{
  int rec_count = 0, i, idnum;
  FILE *plr_index;
  char line[256];
  char arg2[80];

  if(!(plr_index = fopen(PLR_INDEX_FILE, "r"))) {
        return -1;
  }
  if(!(plr_index = fopen(PLR_INDEX_FILE, "r"))) {
        return -1;
  }

  while(get_line(plr_index, line))
    if(*line != '~')
      rec_count++;
  rewind(plr_index);

  if(rec_count == 0) {
    return -1;
   }

  for(i = 0; i < rec_count; i++) {
    get_line(plr_index, line);
    sscanf(line, "%d %s", &idnum, arg2);
        for (i = 0;(*(name + i) = LOWER(*(name + i))); i++);

  if(rec_count == 0) {
    return -1;
   }
     if (!strcmp(arg2, name)) {
          fclose(plr_index);
          store_to_char(name, ch);
          return idnum; }
  }

  return -1;
  fclose(plr_index);
}

And a copy of my index file:

1 paladine 34 0 1012659022
2 test 0 dfjkoqtuE 1012659120
3 reorx 0 gjkoqtuE 1012679119
4 sirrion 33 0 1012676405
~


Hope someone can help.

Steve Squires




_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT