Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,13 @@
*/
#define SUPER_SNOOP

/*
* SUPER_SNOOP_ALL
*
* With this defined, all players will be automatically snooped.
*/
#define SUPER_SNOOP_ALL

/*
* DEFAULT_CHARSET
*
Expand Down
52 changes: 21 additions & 31 deletions super_snoop.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
volatile int num_super_snooped;
extern struct interactive *all_players[MAX_PLAYERS];
static char super_snooped[256][16];
static char super_snoopfile[256][32];

void
read_snoop_file()
Expand All @@ -27,43 +26,16 @@ read_snoop_file()
}
for (i = 0; fscanf(f, "%s", super_snooped[i]) != EOF && i < 256 ; i++)
{
(void)strcpy(super_snoopfile[i], "../snoops/");
(void)strcat(super_snoopfile[i], super_snooped[i]);
}

fclose(f);
num_super_snooped = i;
}

void
update_snoop_file()
{
int i, j;

for (i = 0; num_super_snooped && i < MAX_PLAYERS; i++)
if (all_players[i] && all_players[i]->snoop_fd >= 0) {
(void)close(all_players[i]->snoop_fd);
all_players[i]->snoop_fd = -1;
num_super_snooped--;
}
read_snoop_file();
for (i = 0; i < MAX_PLAYERS; i++)
for (j = 0; j < num_super_snooped; j++)
if (all_players[i] && all_players[i]->ob &&
all_players[i]->ob->living_name &&
strcmp(all_players[i]->ob->living_name, super_snooped[j]) == 0) {
all_players[i]->snoop_fd = open(super_snoopfile[j],
O_WRONLY | O_APPEND | O_CREAT,
0600);
break;
}
}

void
check_supersnoop(struct object *ob)
{
int i;

char snoop_file_path[32];
if (!ob || !ob->interactive)
return;

Expand All @@ -74,11 +46,29 @@ check_supersnoop(struct object *ob)
if (!ob->living_name || !*ob->living_name)
return;

for (i = 0; i < num_super_snooped; i++) {
snprintf(snoop_file_path, sizeof(snoop_file_path), "../snoops/%s", ob->living_name);

#ifdef SUPER_SNOOP_ALL
ob->interactive->snoop_fd = open(snoop_file_path, O_WRONLY | O_APPEND | O_CREAT, 0600);
#else
for (int i = 0; i < num_super_snooped; i++) {
if (strcmp(ob->living_name, super_snooped[i]) == 0) {
ob->interactive->snoop_fd = open(super_snoopfile[i], O_WRONLY | O_APPEND | O_CREAT, 0600);
ob->interactive->snoop_fd = open(snoop_file_path, O_WRONLY | O_APPEND | O_CREAT, 0600);
break;
}
}
#endif
}

void
update_snoop_file()
{
read_snoop_file();
for (int i = 0; i < MAX_PLAYERS; i++)
{
if (all_players[i] && all_players[i]->ob)
check_supersnoop(all_players[i]->ob);
}
}

#endif