[Long] Problem...

From: Josh Brittenham (beavis@MidIowa1.pcpartner.net)
Date: 02/21/97


Hello,

I'm writing this as a last resort, I've spent a day trying to figure it 
out, and also let some other people see my code to try and figure it 
out.  Nobody can find a thing.  Heres the scenario:

I've made changes to the who screen similar to the patch that is at the 
circle ftp site.  I just found this problem yesterday.  It seems that 
whenever there are more than 2 gods on, like 3, and somebody types who, 
the mud just crashes with a segmentation fault.  I can't imagine what 
would be causing the problem.  I am including my do_who function although 
i do not thing the problem lies here.  If anybody thinks they have an 
idea of what could be causing the crash, I'd really appreciate it.

Here is code...

#define WHO_FORMAT \
"format: who [minlev[-maxlev]] [-n name] [-c classes] [-rzqimo]\r\n"

ACMD(do_who)
{
  struct descriptor_data *d;
  struct char_data *wch;
  char wiz_buf[MAX_INPUT_LENGTH];
  char player_buf[MAX_INPUT_LENGTH];
  char name_search[MAX_INPUT_LENGTH+1];
  char mode;
  
  size_t i;
  int low = 0, high = LVL_IMPL, showclass = 0;
  bool who_room = FALSE, who_zone = FALSE, who_quest = 0;
  int num_wiz = 0, num_players = 0;
  bool outlaws = FALSE, noimm = FALSE, nomort = FALSE;

  const char *WizAbbr[LVL_IMPL - (LVL_IMMORT-2)] = {
    "\\c02QuESToR\\c00",
    "\\c02BuILDeR\\c00",
    "\\c02 CoDeR \\c00",
    "\\c02HeaDImP\\c00",
    "\null"
};

  skip_spaces(&argument);
  strcpy(buf, argument);
  name_search[0] = '\0';

  while (*buf) {
    half_chop(buf, arg, buf1);
    if (isdigit(*arg)) {
      sscanf(arg, "%d-%d", &low, &high);
      strcpy(buf, buf1);
    } else if (*arg == '-') {
      mode = *(arg + 1);	/* just in case; we destroy arg in the switch */
      switch (mode) {
      case 'o':
      case 'k':
	outlaws = TRUE;
	strcpy(buf, buf1);
	break;
      case 'z':
	who_zone = TRUE;
	strcpy(buf, buf1);
	break;
      case 'q':
	who_quest = TRUE;
	strcpy(buf, buf1);
	break;
      case 'l':
	half_chop(buf1, arg, buf);
	sscanf(arg, "%d-%d", &low, &high);
	break;
      case 'n':
	half_chop(buf1, name_search, buf);
	break;
      case 'r':
	who_room = TRUE;
	strcpy(buf, buf1);
	break;
      case 'c':
	half_chop(buf1, arg, buf);
	for (i = 0; i < strlen(arg); i++)
	  showclass |= find_class_bitvector(arg[i]);
	break;
      case 'i':
	nomort = TRUE;
	strcpy(buf, buf1);
	break;
      case 'm':
	noimm = TRUE;
	strcpy(buf, buf1);
	break;
      default: 
	send_to_char(WHO_FORMAT, ch);
	return;
	break;
      }				/* end of switch */

    } else {			/* endif */
      send_to_char(WHO_FORMAT, ch);
      return;
    }
  }				/* end while (parser) */

  strcpy(wiz_buf, "\\c04W\\c06i\\c04z\\c06a\\c04r\\c06d\\c04s\\c00\r\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\r\n");
  strcpy(player_buf, "\\c04P\\c06l\\c04a\\c06y\\c04e\\c06r\\c04s\\c00\r\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\r\n");

  for (d = descriptor_list; d; d = d->next) {
    if (d->connected)
      continue;

    if (d->original)
      wch = d->original;
    else if (!(wch = d->character))
      continue;

    
    if (!CAN_SEE(ch, wch))
      continue;
    if (GET_LEVEL(wch) < low || GET_LEVEL(wch) > high)
      continue;
    if ((noimm && GET_LEVEL(wch) >= LVL_IMMORT) || (nomort && GET_LEVEL(wch) < LVL_IMMORT))
      continue;
    if (*name_search && str_cmp(GET_NAME(wch), name_search) && !strstr(GET_TITLE(wch), name_search))
      continue;
    if (outlaws && !PLR_FLAGGED(wch, PLR_KILLER) && !PLR_FLAGGED(wch, PLR_THIEF))
      continue;    
    if (who_quest && !PRF_FLAGGED(wch, PRF_QUEST))
      continue;
    if (who_zone && world[ch->in_room].zone != world[wch->in_room].zone)
      continue;
    if (who_room && (wch->in_room != ch->in_room))
      continue;
    if (showclass && !(showclass & (1 << GET_CLASS(wch))))
      continue;

      if (GET_LEVEL(wch) >= LVL_IMMORT) {
        sprintf(wiz_buf, "%s%s[%s] \\c11%s\\c14 %s\\c00",
	        wiz_buf, CCWHT(ch, C_SPR), 
	        WizAbbr[GET_LEVEL(wch) - LVL_IMMORT],GET_NAME(wch),
         	GET_TITLE(wch));
                num_wiz++;
		
	   } else {
	
        sprintf(player_buf, "%s%s[%d %s %s] \\c11%s\\c14 %s\\c00",
	      player_buf, CCWHT(ch, C_SPR),
	      GET_LEVEL(wch), CLASS_ABBR(wch), RACE_ABBR(wch), GET_NAME(wch),
	      GET_TITLE(wch));
	      num_players++;
	
	  }


      *buf = '\0';
      if (GET_INVIS_LEV(wch))
	sprintf(buf, "%s (i%d)", buf, GET_INVIS_LEV(wch));
      else if (IS_AFFECTED(wch, AFF_INVISIBLE))
	strcat(buf, " (invis)");
      if (PLR_FLAGGED(wch, PLR_MAILING))
	strcat(buf, " (mailing)");
      else if (PLR_FLAGGED(wch, PLR_WRITING))
	strcat(buf, " (writing)");
      if (PRF_FLAGGED(wch, PRF_DEAF))
	strcat(buf, " (deaf)");
      if (PRF_FLAGGED(wch, PRF_NOTELL))
	strcat(buf, " (notell)");
      if (PRF_FLAGGED(wch, PRF_QUEST))
	strcat(buf, " (quest)");
      if (PLR_FLAGGED(wch, PLR_THIEF))
	strcat(buf, " (THIEF)");
      if (PLR_FLAGGED(wch, PLR_KILLER))
	strcat(buf, " (KILLER)");
      if (GET_LEVEL(wch) >= LVL_IMMORT)
	strcat(buf, CCNRM(ch, C_SPR));
      strcat(buf, "\r\n");

      if (GET_LEVEL(wch) >= LVL_IMMORT)
      strcat(wiz_buf, buf);
	else
      strcat(player_buf, buf);
  }				/* end of for */
  
  if (num_wiz) { 
    page_string(ch->desc, wiz_buf, 0);
    send_to_char("\r\n", ch);
 }
  if (num_players) {
    page_string(ch->desc, player_buf, 0);
    send_to_char("\r\n", ch);
 }

  if ((num_wiz+num_players) == 0)
    strcpy(buf, "There are currently no Wizards, or Players visible to you.\r\n");
  if (num_wiz)
    sprintf(buf, "There %s %d Wizard%s%s", (num_wiz == 1 ? "is" : "are"),
    num_wiz, (num_wiz == 1 ? "" : "s"), (num_players ? " and there" : "."));
  if (num_players)
    sprintf(buf, "%s %s %d visible player%s.", (num_wiz ? buf : "There"),
    (num_players == 1 ? "is" : "are"), num_players, (num_players == 1 ? "" : "s"));
  strcat(buf, "\r\n");

  send_to_char(buf, ch);  
}

+-----------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
|   http://cspo.queensu.ca/~fletcher/Circle/list_faq.html   |
|    Or send 'info circle' to majordomo@cspo.queensu.ca     |
+-----------------------------------------------------------+



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