Re: [CODE][NEWBIE][HELP]

From: Acido (acido@dvmud.net)
Date: 02/18/99


At 01:43 PM 2/18/99 -0500, you wrote:
>I know the aliases I have used to test this are less than 127 and it still
>crashes.  Plain and simple, if you have an alias and you type save, the mud
>dies.  I can't figure it out.   :(
>Does anyone out there have some alias code that patches cleanly with
>circle30bpl14???? Or maybe a fix for this situation?
>
Here is my alias.c file it may contain errors since im writing this in my
mailer and not pasting actual code :)
May not even work for you but it should give you some basic ideas of
how to write your own.

#include "conf.h"
#include "sysdep.h"

#include "structs.h"
#include "utils.h"
#include "db.h"
#include "comm.h"
#include "interpreter.h"
#include "constants.h"

/* Externs */
extern struct player_index_element *player_table;
extern int find_name(char *name);

void write_aliases(struct char_data *ch)
{
  FILE *outfile;
  struct alias *temp;
  char outname[40], bits[127], *buf;
  int length, i;

  if (IS_NPC(ch) || GET_PFILEPOS(ch) < 0)
    return;

  memset(bits, 0, sizeof(bits));
  memset(outname, 0, sizeof(outname));

  for (i = 0; (*(bits + i) = LOWER(*(ch->player.name + i))); i++);
    sprintf(outname, "%s%c/%s%s", PLR_PREFIX, *bits, bits, ALIAS_SUFFIX);

  if (!(outfile = fopen(outname, "w"))) {
    sprintf(buf2, "SYSERR: Error opening output file: %s", outname);
    mudlog(buf2, NRM, MAX(LVL_PRIEST, GET_INVIS_LEV(ch)), TRUE);
    send_to_char("ERROR: There was an error opening your alias file, please
report.\r\n", ch);
    return;
  }

  if (!GET_ALIASES(ch)) {
    remove(outname);
    return;
  }

  temp = GET_ALIASES(ch);

  while (temp) {
    length = strlen(temp->alias);
    if (length > MAX_RAW_INPUT_LENGTH) {
      temp = temp->next;
      continue;
    }
    fprintf(outfile, "%d\n", length);
    fprintf(outfile, "%s\n", temp->alias);
    buf = temp->replacement;
    while (*++buf == ' ');
      length = strlen(buf);
    fprintf(outfile, "%d\n, length);
    fprintf(outfile, "%s\n", buf);
    fprintf(outfile, "%d\n", temp->type);
    temp = temp->next;
  }
  fclose(outfile);
}

void read_aliases(struct char_data *ch)
{
  FILE *file;
  struct alias *t2;
  char filename[40];
  char temp_buf[MAX_RAW_INPUT_LENGTH + 5], buf[MAX_RAW_INPUT_LENGTH + 5];
  long id;
  int length;

  if (IS_NPC(ch) || GET_PFILEPOS(ch) < 0)
    return;

  if ((id = find_name(GET_NAME(ch))) < 0) {
    sprintf(buf2, "SYSERR: Invalid idnum in (read_aliases) for player
(%s)", GET_NAME(ch));
    mudlog(buf2, NRM, MAX(LVL_PRIEST, GET_INVIS_LEV(ch)), TRUE);
    return;
  } else {
    sprintf(filename, "%s%c/%s%s", PLR_PREFIX, *player_table[id].name,
              player_table[id].name, ALIAS_SUFFIX);
    if (!(file = fopen(filename, "r")))
      return;

    CREATE(GET_ALIASES(ch), struct alias, 1);
    t2 = GET_ALIASES(ch);
    do {
      fscanf(file, "%d\n", &length);
      fgets(buf, length + 1, file);
      t2->alias = strdup(buf);
      fscanf(file, "%d\n", &length);
      fgets(buf, length + 1, file);
      strcpy(temp_buf, " ");
      strcat(temp_buf, buf);
      t2->replacement = strdup(temp_buf);
      fscanf(file, "%d\n", &length);
      t2->type = length;
      if (!feof(file)) {
        CREATE(t2->next, struct alias, 1);
        t2 = t2->next;
      }
    } while (!feof(file));
  }
  fclose(file);
}


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



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