Beispiel #1
0
void
boot_social_messages (void)
{
	FILE *fl;
	char *social_command;
	int hide;
	int min_pos;

	if (!(fl = fopen (SOCMESS_FILE, "r")))
	{
		perror ("boot_social_messages");
		abort ();
	}

#define MAX_SOCIALS		200

	social_messages = new SOCIAL_DATA[MAX_SOCIALS];

	for (list_top = 0;; list_top++)
	{

		if (!(social_command = fread_action (fl)))
			break;

		fscanf (fl, " %d ", &hide);
		fscanf (fl, " %d \n", &min_pos);

		if (list_top >= MAX_SOCIALS - 1)
		{
			break;
		}

		social_messages[list_top].social_command = social_command;
		social_messages[list_top].hide = hide;
		social_messages[list_top].min_victim_position = min_pos;
		social_messages[list_top].char_no_arg = fread_action (fl);
		social_messages[list_top].others_no_arg = fread_action (fl);
		social_messages[list_top].char_found = fread_action (fl);

		/* if no char_found, the rest is to be ignored */

		if (!social_messages[list_top].char_found)
			continue;

		social_messages[list_top].others_found = fread_action (fl);
		social_messages[list_top].vict_found = fread_action (fl);
		social_messages[list_top].not_found = fread_action (fl);
		social_messages[list_top].char_auto = fread_action (fl);
		social_messages[list_top].others_auto = fread_action (fl);
	}

	fclose (fl);
}
Beispiel #2
0
void boot_social_messages(void)
{
  FILE *fl;
  int nr, i, hide, min_pos, curr_soc = -1;
  char next_soc[100];
  struct social_messg temp;

  /* open social file */
  if (!(fl = fopen(SOCMESS_FILE, "r"))) {
    log("SYSERR: can't open socials file '%s': %s", SOCMESS_FILE, strerror(errno));
    exit(1);
  }
  /* count socials & allocate space */
  for (nr = 0; *cmd_info[nr].command != '\n'; nr++)
    if (cmd_info[nr].command_pointer == do_action)
      list_top++;

  CREATE(soc_mess_list, struct social_messg, list_top + 1);

  /* now read 'em */
  for (;;) {
    fscanf(fl, " %s ", next_soc);
    if (*next_soc == '$')
      break;
    if (fscanf(fl, " %d %d \n", &hide, &min_pos) != 2) {
      log("SYSERR: format error in social file near social '%s'", next_soc);
      exit(1);
    }
    if (++curr_soc > list_top) {
      log("SYSERR: Ran out of slots in social array. (%d > %d)", curr_soc, list_top);
      break;
    }
 
    /* read the stuff */
    soc_mess_list[curr_soc].act_nr = nr = find_command(next_soc);
    soc_mess_list[curr_soc].hide = hide;
    soc_mess_list[curr_soc].min_victim_position = min_pos;

#ifdef CIRCLE_ACORN
    if (fgetc(fl) != '\n')
      log("SYSERR: Acorn bug workaround failed.");
#endif

    soc_mess_list[curr_soc].char_no_arg = fread_action(fl, nr);
    soc_mess_list[curr_soc].others_no_arg = fread_action(fl, nr);
    soc_mess_list[curr_soc].char_found = fread_action(fl, nr);

    /* if no char_found, the rest is to be ignored */
    if (!soc_mess_list[curr_soc].char_found)
      continue;

    soc_mess_list[curr_soc].others_found = fread_action(fl, nr);
    soc_mess_list[curr_soc].vict_found = fread_action(fl, nr);
    soc_mess_list[curr_soc].not_found = fread_action(fl, nr);
    soc_mess_list[curr_soc].char_auto = fread_action(fl, nr);
    soc_mess_list[curr_soc].others_auto = fread_action(fl, nr);

    /* If social not found, re-use this slot.  'curr_soc' will be reincremented. */
    if (nr < 0) {
      log("SYSERR: Unknown social '%s' in social file.", next_soc);
      memset(&soc_mess_list[curr_soc--], 0, sizeof(struct social_messg));
      continue;
    }

    /* If the command we found isn't do_action, we didn't count it for the CREATE(). */
    if (cmd_info[nr].command_pointer != do_action) {
      log("SYSERR: Social '%s' already assigned to a command.", next_soc);
      memset(&soc_mess_list[curr_soc--], 0, sizeof(struct social_messg));
    }
  }

  /* close file & set top */
  fclose(fl);
  list_top = curr_soc;

  /* now, sort 'em */
  for (curr_soc = 0; curr_soc < list_top; curr_soc++) {
    min_pos = curr_soc;
    for (i = curr_soc + 1; i <= list_top; i++)
      if (soc_mess_list[i].act_nr < soc_mess_list[min_pos].act_nr)
	min_pos = i;
    if (curr_soc != min_pos) {
      temp = soc_mess_list[curr_soc];
      soc_mess_list[curr_soc] = soc_mess_list[min_pos];
      soc_mess_list[min_pos] = temp;
    }
  }
}
Beispiel #3
0
void load_messages(void)
{
  FILE *fl;
  int i, type;
  struct message_type *messages;
  char chk[128], *buf;

  if (!(fl = fopen(MESS_FILE, "r"))) {
    log("SYSERR: Error reading combat message file %s: %s", MESS_FILE, strerror(errno));
    exit(1);
  }

  for (i = 0; i < MAX_MESSAGES; i++) {
    fight_messages[i].a_type = 0;
    fight_messages[i].number_of_attacks = 0;
    fight_messages[i].msg = NULL;
  }

  while (!feof(fl)) {
    buf = fgets(chk, 128, fl);
    while (!feof(fl) && (*chk == '\n' || *chk == '*'))
      buf = fgets(chk, 128, fl);

    while (*chk == 'M') {
      buf = fgets(chk, 128, fl);
      sscanf(chk, " %d\n", &type);
      for (i = 0; (i < MAX_MESSAGES) && (fight_messages[i].a_type != type) &&
         (fight_messages[i].a_type); i++);
      if (i >= MAX_MESSAGES) {
        log("SYSERR: Too many combat messages.  Increase MAX_MESSAGES and recompile.");
        exit(1);
      }
      CREATE(messages, struct message_type, 1);
      fight_messages[i].number_of_attacks++;
      fight_messages[i].a_type = type;
      messages->next = fight_messages[i].msg;
      fight_messages[i].msg = messages;

      messages->die_msg.attacker_msg = fread_action(fl, i);
      messages->die_msg.victim_msg = fread_action(fl, i);
      messages->die_msg.room_msg = fread_action(fl, i);
      messages->miss_msg.attacker_msg = fread_action(fl, i);
      messages->miss_msg.victim_msg = fread_action(fl, i);
      messages->miss_msg.room_msg = fread_action(fl, i);
      messages->hit_msg.attacker_msg = fread_action(fl, i);
      messages->hit_msg.victim_msg = fread_action(fl, i);
      messages->hit_msg.room_msg = fread_action(fl, i);
      messages->god_msg.attacker_msg = fread_action(fl, i);
      messages->god_msg.victim_msg = fread_action(fl, i);
      messages->god_msg.room_msg = fread_action(fl, i);
      buf  = fgets(chk, 128, fl);
      while (!feof(fl) && (*chk == '\n' || *chk == '*'))
        buf  = fgets(chk, 128, fl);
    }
  }
  fclose(fl);
  log("Loaded %d Combat Messages...", i);
}
Beispiel #4
0
void boot_social_messages(void)
{
  FILE *fl;
  int nr, i, hide, min_pos, curr_soc = -1;
  char next_soc[100];
  struct social_messg temp;

  /* open social file */
  if (!(fl = fopen(SOCMESS_FILE, "r"))) {
    log("SYSERR: can't open socials file '%s': %s", SOCMESS_FILE, strerror(errno));
    /*  SYSERR_DESC:
     *  This error, from boot_social_messages(), occurs when the server
     *  fails to open the file containing the social messages.  The error
     *  at the end will indicate the reason why.
     */
    exit(1);
  }
  /* count socials & allocate space */
  for (nr = 0; *cmd_info[nr].command != '\n'; nr++)
    if (cmd_info[nr].command_pointer == do_action)
      list_top++;

  CREATE(soc_mess_list, struct social_messg, list_top + 1);

  /* now read 'em */
  for (;;) {
    fscanf(fl, " %s ", next_soc);
    if (*next_soc == '$')
      break;
    if (fscanf(fl, " %d %d \n", &hide, &min_pos) != 2) {
      log("SYSERR: format error in social file near social '%s'", next_soc);
      /*  SYSERR_DESC:
       *  From boot_social_messages(), this error is output when the
       *  server is expecting to find the remainder of the first line of the
       *  social ('hide' and 'minimum position').  These must follow the
       *  name of the social with a single space such as: 'accuse 0 5\n'.
       *  This error often occurs when one of the numbers is missing or the
       *  social name has a space in it (i.e., 'bend over').
       */
      exit(1);
    }
    if (++curr_soc > list_top) {
      log("SYSERR: Ran out of slots in social array. (%d > %d)", curr_soc, list_top);
      /*  SYSERR_DESC:
       *  The server creates enough space for all of the socials that it finds
       *  in the command structure (cmd_info[] in interpreter.c).  These are
       *  designated with the 'do_action' command call.  If there are more
       *  socials in the file than in the cmd_info structure, the
       *  boot_social_messages() function will fail with this error.
       */
      break;
    }
 
    /* read the stuff */
    soc_mess_list[curr_soc].act_nr = nr = find_command(next_soc);
    soc_mess_list[curr_soc].hide = hide;
    soc_mess_list[curr_soc].min_victim_position = min_pos;

#ifdef CIRCLE_ACORN
    if (fgetc(fl) != '\n')
      log("SYSERR: Acorn bug workaround failed.");
      /*  SYSERR_DESC:
       *  The only time that this error should ever arise is if you are running
       *  your CircleMUD on the Acorn platform.  The error arises when the
       *  server cannot properly read a '\n' out of the file at the end of the
       *  first line of the social (that with 'hide' and 'min position').  This
       *  is in boot_social_messages().
       */
#endif

    soc_mess_list[curr_soc].char_no_arg = fread_action(fl, nr);
    soc_mess_list[curr_soc].others_no_arg = fread_action(fl, nr);
    soc_mess_list[curr_soc].char_found = fread_action(fl, nr);

    /* if no char_found, the rest is to be ignored */
    if (!soc_mess_list[curr_soc].char_found)
      continue;

    soc_mess_list[curr_soc].others_found = fread_action(fl, nr);
    soc_mess_list[curr_soc].vict_found = fread_action(fl, nr);
    soc_mess_list[curr_soc].not_found = fread_action(fl, nr);
    soc_mess_list[curr_soc].char_auto = fread_action(fl, nr);
    soc_mess_list[curr_soc].others_auto = fread_action(fl, nr);

    /* If social not found, re-use this slot.  'curr_soc' will be reincremented. */
    if (nr < 0) {
      log("SYSERR: Unknown social '%s' in social file.", next_soc);
      /*  SYSERR_DESC:
       *  This occurs when the find_command() function in interpreter.c cannot
       *  find the social of the name in the file in the cmd_info[] structure.
       *  This is returned to boot_social_messages(), and the function
       *  reassigns that slot to another social to avoid running out of memory.
       *  The solution is to add this social to the cmd_info[] array in
       *  interpreter.c or to remove the social from the file.
       */
      memset(&soc_mess_list[curr_soc--], 0, sizeof(struct social_messg));
      continue;
    }

    /* If the command we found isn't do_action, we didn't count it for the CREATE(). */
    if (cmd_info[nr].command_pointer != do_action) {
      log("SYSERR: Social '%s' already assigned to a command.", next_soc);
      /*  SYSERR_DESC:
       *  This error occurs when boot_social_messages() reads in a social and
       *  then discovers that it is not assigned 'do_action' as a command in
       *  the cmd_info[] array in interpreter.c
       */
      memset(&soc_mess_list[curr_soc--], 0, sizeof(struct social_messg));
    }
  }

  /* close file & set top */
  fclose(fl);
  list_top = curr_soc;

  /* now, sort 'em */
  for (curr_soc = 0; curr_soc < list_top; curr_soc++) {
    min_pos = curr_soc;
    for (i = curr_soc + 1; i <= list_top; i++)
      if (soc_mess_list[i].act_nr < soc_mess_list[min_pos].act_nr)
	min_pos = i;
    if (curr_soc != min_pos) {
      temp = soc_mess_list[curr_soc];
      soc_mess_list[curr_soc] = soc_mess_list[min_pos];
      soc_mess_list[min_pos] = temp;
    }
  }
}