/* File: Whois.c By: SSJ_Vegeta_Jr@hotmail.com *
* Comment: Whois into a HTML file, made specifically *
* for the Realms of Vio-X (vio-x.idlegames.net port: *
* 6660). If you use this, try to mention me sometime. */
#include "conf.h"
#include "sysdep.h"
#include "structs.h"
#include "utils.h"
#include "comm.h"
#include "interpreter.h"
#include "handler.h"
#include "db.h"
#include "screen.h"
extern char *class_abbrevs[];
bitvector_t find_class_bitvector(const char *arg);
void whois_html(void);
ACMD(do_who);
int show_on_who_list(struct descriptor_data *d);
/* *
* This hardly deserves it's own function, but I see future *
* expansion capabilities... *
* TR 8-18-98 *
* Fixed: 8-25-98 */
int show_on_who_list(struct descriptor_data *d)
{
if ((STATE(d) != CON_PLAYING) && (STATE(d) != CON_MEDIT) &&
(STATE(d) != CON_OEDIT) && (STATE(d) != CON_REDIT) &&
(STATE(d) != CON_SEDIT) && (STATE(d) != CON_ZEDIT) &&
(STATE(d) != CON_AEDIT) && (STATE(d) != CON_TEDIT) &&
(STATE(d) != CON_TRIGEDIT))
return 0;
else
return 1;
}
#define WHO_FORMAT \
"format: who [minlev[-maxlev]] [-n name] [-c classlist] [-s] [-o] [-q] [-r] [-z]\r\n"
void whois_html(void)
{
struct descriptor_data *d;
struct char_data *tch;
char name_search[MAX_INPUT_LENGTH], buf[MAX_INPUT_LENGTH];
int low = 0, high = LVL_IMPL, localwho = 0, questwho = 0;
int showclass = 0, short_list = 0, outlaws = 0, num_can_see = 0;
int who_room = 0;
FILE *fp;
if (!(fp = fopen(WHO_FILE, "wt"))) {
sprintf(buf, "Can't open who file '%s'", WHO_FILE);
perror(buf);
exit(1);
}
name_search[0] = buf[0] = '\0';
fprintf(fp, "\n
\nPlayers
\n
");
for (d = descriptor_list; d; d = d->next) {
/*if (STATE(d) != CON_PLAYING)
continue;
if (STATE(d) == CON_PLAYING)
continue;*/
if (d->original)
tch = d->original;
else if (!(tch = d->character))
continue;
if (!show_on_who_list(d))
continue;
if (*name_search && str_cmp(GET_NAME(tch), name_search) &&
!strstr(GET_TITLE(tch), name_search))
continue;
if (GET_LEVEL(tch) < low || GET_LEVEL(tch) > high)
continue;
if (outlaws && !PLR_FLAGGED(tch, PLR_KILLER) &&
!PLR_FLAGGED(tch, PLR_THIEF))
continue;
if (questwho && !PRF_FLAGGED(tch, PRF_QUEST))
continue;
if (localwho)
continue;
if (who_room)
continue;
if (showclass && !(showclass & (1 << GET_CLASS(tch))))
continue;
if (GET_INVIS_LEV(tch) < 2) {
num_can_see++;
if (GET_LEVEL(tch) >= LVL_IMMORT)
fprintf(fp, "");
else
fprintf(fp, "");
fprintf(fp, "[%3d %s] %s", GET_LEVEL(tch), CLASS_ABBR(tch), GET_NAME(tch));
if (GET_INVIS_LEV(tch))
fprintf(fp, " (i%d)", GET_INVIS_LEV(tch));
else if (AFF_FLAGGED(tch, AFF_INVISIBLE))
fprintf(fp, " (invis)");
if (PLR_FLAGGED(tch, PLR_MAILING))
fprintf(fp, " (mailing)");
else if ((STATE(d) >= CON_OEDIT) && (STATE(d) <= CON_AEDIT))
fprintf(fp, " (OLC)");
else if (PLR_FLAGGED(tch, PLR_WRITING))
fprintf(fp, " (writing)");
if (PRF_FLAGGED(tch, PRF_DEAF))
fprintf(fp, " (deaf)");
if (PRF_FLAGGED(tch, PRF_NOTELL))
fprintf(fp, " (notell)");
if (PRF_FLAGGED(tch, PRF_QUEST))
fprintf(fp, " (quest)");
if (PLR_FLAGGED(tch, PLR_THIEF))
fprintf(fp, " (THIEF)");
if (PLR_FLAGGED(tch, PLR_KILLER))
fprintf(fp, " (KILLER)");
fprintf(fp, "
\n");
}
} /* endif shortlist */
fprintf(fp, "\n");
if (num_can_see == 0)
fprintf(fp, "
Nobody at all!
\n");
else if (num_can_see == 1)
fprintf(fp, "
One lonely character displayed.
\n");
else
fprintf(fp, "
%d characters displayed.
\n", num_can_see);
fprintf(fp, "");
fclose(fp);
}
/* FIXME: This whole thing just needs rewritten. */
ACMD(do_who)
{
struct descriptor_data *d;
struct char_data *tch;
char name_search[MAX_INPUT_LENGTH], buf[MAX_INPUT_LENGTH];
char mode;
int low = 0, high = LVL_IMPL, localwho = 0, questwho = 0;
int showclass = 0, short_list = 0, outlaws = 0, num_can_see = 0;
int who_room = 0;
skip_spaces(&argument);
strcpy(buf, argument); /* strcpy: OK (sizeof: argument == buf) */
name_search[0] = '\0';
while (*buf) {
char arg[MAX_INPUT_LENGTH], buf1[MAX_INPUT_LENGTH];
half_chop(buf, arg, buf1);
if (isdigit(*arg)) {
sscanf(arg, "%d-%d", &low, &high);
strcpy(buf, buf1); /* strcpy: OK (sizeof: buf1 == buf) */
} else if (*arg == '-') {
mode = *(arg + 1); /* just in case; we destroy arg in the switch */
switch (mode) {
case 'o':
case 'k':
outlaws = 1;
strcpy(buf, buf1); /* strcpy: OK (sizeof: buf1 == buf) */
break;
case 'z':
localwho = 1;
strcpy(buf, buf1); /* strcpy: OK (sizeof: buf1 == buf) */
break;
case 's':
short_list = 1;
strcpy(buf, buf1); /* strcpy: OK (sizeof: buf1 == buf) */
break;
case 'q':
questwho = 1;
strcpy(buf, buf1); /* strcpy: OK (sizeof: buf1 == buf) */
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 = 1;
strcpy(buf, buf1); /* strcpy: OK (sizeof: buf1 == buf) */
break;
case 'c':
half_chop(buf1, arg, buf);
showclass = find_class_bitvector(arg);
break;
default:
send_to_char(ch, "%s", WHO_FORMAT);
return;
} /* end of switch */
} else { /* endif */
send_to_char(ch, "%s", WHO_FORMAT);
return;
}
} /* end while (parser) */
send_to_char(ch, "Players\r\n-------\r\n");
for (d = descriptor_list; d; d = d->next) {
/*if (STATE(d) != CON_PLAYING)
continue;
if (STATE(d) == CON_PLAYING)
continue;*/
if (d->original)
tch = d->original;
else if (!(tch = d->character))
continue;
if (!show_on_who_list(d))
continue;
if (*name_search && str_cmp(GET_NAME(tch), name_search) &&
!strstr(GET_TITLE(tch), name_search))
continue;
if (!CAN_SEE(ch, tch) || GET_LEVEL(tch) < low || GET_LEVEL(tch) > high)
continue;
if (outlaws && !PLR_FLAGGED(tch, PLR_KILLER) &&
!PLR_FLAGGED(tch, PLR_THIEF))
continue;
if (questwho && !PRF_FLAGGED(tch, PRF_QUEST))
continue;
if (localwho && world[IN_ROOM(ch)].zone != world[IN_ROOM(tch)].zone)
continue;
if (who_room && (IN_ROOM(tch) != IN_ROOM(ch)))
continue;
if (showclass && !(showclass & (1 << GET_CLASS(tch))))
continue;
if (short_list) {
send_to_char(ch, "%s[%3d %s] %-12.12s%s%s%s",
(GET_LEVEL(tch) >= LVL_IMMORT ? CCYEL(ch, C_SPR) : ""),
GET_LEVEL(tch), CLASS_ABBR(tch), GET_NAME(tch), CCNRM(ch, C_SPR),
(GET_LEVEL(tch) >= LVL_IMMORT ? CCNRM(ch, C_SPR) : ""),
((!(++num_can_see % 4)) ? "\r\n" : ""));
} else {
num_can_see++;
if (!IS_NPC(tch) && (tch)->player.pretitle && strlen(GET_PRETITLE(tch)) > 1)
send_to_char(ch, "%s[%3d %s] %s %s %s%s",
(GET_LEVEL(tch) >= LVL_IMMORT ? CCYEL(ch, C_SPR) : ""),
GET_LEVEL(tch), CLASS_ABBR(tch),
GET_PRETITLE(tch), GET_NAME(tch),
GET_TITLE(tch), CCNRM(ch, C_SPR));
else
send_to_char(ch, "%s[%3d %s] %s %s%s",
(GET_LEVEL(tch) >= LVL_IMMORT ? CCYEL(ch, C_SPR) : ""),
GET_LEVEL(tch), CLASS_ABBR(tch),
GET_NAME(tch), GET_TITLE(tch), CCNRM(ch, C_SPR));
if (GET_LEVEL(tch) > LVL_IMMORT - 1) { /* Remove bolding colors */
send_to_char(ch, CCNRM(ch, C_SPR));
send_to_char(ch, CCYEL(ch, C_SPR));
}
if (GET_INVIS_LEV(tch))
send_to_char(ch, " (i%d)", GET_INVIS_LEV(tch));
else if (AFF_FLAGGED(tch, AFF_INVISIBLE))
send_to_char(ch, " (invis)");
if (PLR_FLAGGED(tch, PLR_MAILING))
send_to_char(ch, " (mailing)");
else if ((STATE(d) >= CON_OEDIT) && (STATE(d) <= CON_AEDIT))
send_to_char(ch, " (OLC)");
else if (PLR_FLAGGED(tch, PLR_WRITING))
send_to_char(ch, " (writing)");
if (PRF_FLAGGED(tch, PRF_DEAF))
send_to_char(ch, " (deaf)");
if (PRF_FLAGGED(tch, PRF_NOTELL))
send_to_char(ch, " (notell)");
if (PRF_FLAGGED(tch, PRF_QUEST))
send_to_char(ch, " (quest)");
if (PLR_FLAGGED(tch, PLR_THIEF))
send_to_char(ch, " (THIEF)");
if (PLR_FLAGGED(tch, PLR_KILLER))
send_to_char(ch, " %s(KILLER)%s",
CCRED(ch, C_SPR), CCNRM(ch, C_SPR));
if (GET_LEVEL(tch) >= LVL_IMMORT)
send_to_char(ch, CCNRM(ch, C_SPR));
send_to_char(ch, "\r\n");
} /* endif shortlist */
} /* end of for */
if (short_list && (num_can_see % 4))
send_to_char(ch, "\r\n");
if (num_can_see == 0)
send_to_char(ch, "\r\nNobody at all!\r\n");
else if (num_can_see == 1)
send_to_char(ch, "\r\nOne lonely character displayed.\r\n");
else
send_to_char(ch, "\r\n%d characters displayed.\r\n", num_can_see);
}