[Code] [Newbie] A player list command

From: Melissa Jadwinski (jadwin@tiac.net)
Date: 01/18/99


Hi all, I have whipped up a player list command which is based on mostly on
do_who and Brian Helms' show immortals snippet.  It takes an argument
similar to do_users or do_who.  I am pretty new to Circle coding in general
and while the code works fine, it includes deleted players.  Any ideas on
how to screen for deleted players?  I get compile errors when I do a simple
if "(PLR_FLAGGED(player, PLR_DELETED)) continue;".  The command is pretty
useful other than that....  (I have races on my mud, if you don't you
should remove those portions before using this.)

Thanks a ton!
Melissa Jadwinski
meer@meersan.net



/* Player Search command shamelessly twisted from do_who, idea
   inspired by Brian Helms <bhelms1@gl.umbc.edu>'s show immortals
   snippet, and by Primacy <jmrobins@wired.uvm.edu>'s do_players.
   meer@meersan.net, 18 Jan 99
*/

#define PLAYER_FORMAT \
"format: players [minlev[-maxlev]] [-s] [-c classlist] [-r racelist]\r\n"

ACMD(do_players)
{
  FILE *fl;
  struct char_file_u player;
  size_t i;
  char mode;
  int low = 0, high = LVL_IMPL;
  int showclass = 0, short_list = 0, showrace = 0, num_found = 0, done = 0;
  char tmp[64];

  skip_spaces(&argument);
  strcpy(buf, argument);

    if (!(fl = fopen(PLAYER_FILE, "r+"))) {
      send_to_char("Can't open player file.", ch);
      return;
    }

  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 's':
        short_list = 1;
        strcpy(buf, buf1);
        break;
      case 'l':
        half_chop(buf1, arg, buf);
        sscanf(arg, "%d-%d", &low, &high);
        break;
      case 'r':
        half_chop(buf1, arg, buf);
        for (i = 0; i < strlen(arg); i++)
          showrace |= find_race_bitvector(arg[i]);
        break;

      case 'c':
        half_chop(buf1, arg, buf);
        for (i = 0; i < strlen(arg); i++)
          showclass |= find_class_bitvector(arg[i]);
        break;
      default:
        send_to_char(PLAYER_FORMAT, ch);
        return;
      }                         /* end of switch */

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

  send_to_char("\r\nPlayer Search:  ", ch);

  while (!done) {             /* begin while statement */
    fread(&player, sizeof(struct char_file_u), 1, fl);
    if (feof(fl)) {
      fclose(fl);
      done=TRUE;
    }
/*      if (PLR_FLAGGED(?player, PLR_DELETED))   <-----  Arrggh
        continue;
 */
      if (player.level < low || player.level > high)
        continue;
      if (showclass && !(showclass & (1 << player.chclass)))
        continue;
      if (showrace && !(showrace & (1 << player.race)))
        continue;
      if (short_list) {
        sprintf(tmp, "%-12.12s%s",
               player.name,
               ((!(++num_found % 4)) ? "\r\n" : ""));
        strcat(buf, tmp);

      } else {
        num_found++;
        sprintf(tmp, "%s", player.name);
        strcat(buf, tmp);
        strcat(buf, "\r\n");
      }                           /* endif shortlist */
    }
  }                             /* end of while */

  strcat(buf, "\r\n");

  if (num_found == 0)
    sprintf(tmp, "No players found.\r\n");
  else if (num_found == 1)
    sprintf(tmp, "One player found.\r\n");
  else
    sprintf(tmp, "%d players found.\r\n", num_found);
  send_to_char(tmp, ch);

  page_string(ch->desc, buf, 1);

}


     +------------------------------------------------------------+
     | 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