Ignore Code [by Josh B.]
Snippet Posted Wednesday, August 12th @ 11:28:55 PM, by George Greer in the Commands dept.
Added May 6, 1997. Click the link below to read it or download it.

From: "Josh B." <ruiner@mail.org>
Subject: Ignore Code...

Hiya,

I just finished the code I've been working on for ignoring players,
and just thought I'd send it to the list if anybody wants to use it.
Keep in mind that I haven't done much testing on it.  With the
testing that I have done, I've noticed one problem. (if you can
figure it out, e-mail me so i can change it.)  Anyway, it saves fine,
but when the person quits, and comes back in, it reads the file fine,
but for some reason it reads it twice, and you have to type ignore
<player> two times in order to stop ignoring the player.  Anyway,
that's the only problem I've found.  Good Luck:

Put the ignore.c file included in this message into your src
directory, and add ignore.o to the makefile and put

ignore.o: ignore.c structs.h utils.h interpreter.h

$(CC) -c $(CFLAGS) ignore.c

edit act.comm.c:

Towards top put
extern int is_ignoring(struct char_data *ch, struct char_data *vict);

in the ACMD(do_tell) function, add somewhere with all the others
else if (is_ignoring(ch, vict));
  act("$E's ignoring you.", FALSE, ch, 0, vict, TO_ROOM | TO_SLEEP);

in act.offensive.c:
ACMD(do_ignore)
{
  struct char_data *victim;
  struct ignore *a, *temp;

  one_argument(argument, arg);

  if (!*arg)
    send_to_char("Ignore who?\r\n", ch);
  else if (!(victim = get_char_vis(ch, arg)))
    send_to_char(NOPERSON, ch);
  else if (victim == ch)
    send_to_char("Ignore yourself?  Go seek help!\r\n", ch);
  else if (IS_NPC(victim))
    send_to_char("No ignoring monsters.  That isn't nice.\r\n", ch);
  else if ((a = find_ignore(GET_IGNORELIST(ch), arg)) != NULL) {
    REMOVE_FROM_LIST(a, GET_IGNORELIST(ch), next);
    send_to_char("You no longer ignore them.\r\n", ch);
    free(a->ignore);
    free(a);
  } else {
    CREATE(a, struct ignore, 1);
    a->ignore = str_dup(arg);
    a->next = GET_IGNORELIST(ch);
    GET_IGNORELIST(ch) = a;
    send_to_char(OK, ch);
  }
}

utils.c
find all the other declarations of _FILE and add
case IGNORE_FILE:
  prefix="plrignore"
  suffix="ignore"
  break;

utils.h
again, find the #define's of the other _FILE, and add
#define IGNORE_FILE 2
also, add somewhere
GET_IGNORELIST(ch) ((ch->player_specials->ignorelist)

interpreter.h
add
struct ignore {
  char *ignore;
  struct ignore *next
}

structs.h
in struct player_special_data { add
  struct ignore *ignorelist;

I think that about does it.  I made this message pretty fast because
I have to leave soon, but if you have any problems, just e-mail me.

Hope this helps :)

Josh

/* ************************************************************************
*   File: ignore.c






  *

*  Usage: Ignoring Players



                  *
*








  *
*  Written by Josh Brittenham





  *
*                                                                         *
*  Copyright (C) 1993, 94 by the Trustees of the Johns Hopkins University *
*  CircleMUD is based on DikuMUD, Copyright (C) 1990, 1991.               *
************************************************************************ */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "conf.h"
#include "sysdep.h"
#include "structs.h"
#include "utils.h"
#include "interpreter.h"

struct ignore *find_ignore(struct ignore *ignore_list, char *str)
{
  while (ignore_list != NULL) {
    if (*str == *ignore_list->ignore)
      if (!strcmp(str, ignore_list->ignore))
    return ignore_list;
    ignore_list = ignore_list->next;
  }
  return NULL;
}

int is_ignoring(struct char_data *ch, struct char_data *vict)
{
  struct ignore *temp;
  char buf[127];

  sprintf(buf, "%s", GET_NAME(ch));
  temp = GET_IGNORELIST(vict);
  while (temp != NULL) {
    if (!str_cmp(buf, temp->ignore))
      return 1;
  temp = temp->next;
  }
  return 0;
}

void write_ignorelist(struct char_data *ch)
{
  FILE *file;
  char ignoref[127];
  struct ignore *ignoretemp;
  int ignorelength;

  get_filename(GET_NAME(ch), ignoref, IGNORE_FILE);
  unlink(ignoref);
  if (!GET_IGNORELIST(ch))
    return;
  file = fopen(ignoref, "wt");
  ignoretemp = GET_IGNORELIST(ch);
  while(ignoretemp) {
    ignorelength = strlen(ignoretemp->ignore);
    fprintf(file, "%d\n", ignorelength);
    fprintf(file, "%s\n", ignoretemp->ignore);
    ignoretemp = ignoretemp->next;
  }
  fclose(file);
}

void read_ignorelist(struct char_data *ch)
{
  FILE *file;
  char ignoref[127];
  struct ignore *ignoretemp2;
  char buf[127];
  int ignorelength;

  get_filename(GET_NAME(ch), ignoref, IGNORE_FILE);
  file = fopen(ignoref, "r");
  if(!file)
    return;
  CREATE(GET_IGNORELIST(ch), struct ignore, 1);
  ignoretemp2 = GET_IGNORELIST(ch);
  do {
    fscanf(file, "%d\n", &ignorelength);
    fgets(buf, ignorelength + 1, file);
    ignoretemp2->ignore = strdup(buf);
    if(!feof(file)) {
      CREATE(ignoretemp2->next, struct ignore, 1);
      ignoretemp2 = ignoretemp2->next;
    }
  } while(!feof(file));
  fclose(file);
}



<< Identify (Minor) Spell [by Soren P. Skou] | Reply | View as text | Flattened | Immlist Command [by Brian Helms] >>

 


Related Links
  CircleMUD
download
Related Articles
More by greerga
 
 

CircleMUD Snippets
 
Note: Not all of these snippets will work perfectly with your version of code, so be prepared to fix one or two bugs that may arise, and please let me know what you needed to do to fix it. Sending a corrected version is always welcome.
Finally, if you wish to use any of the snippets from this page, you are more than welcome, just mention the authors in your credits. If you wish to release any of these snippets to the public on another site, contact me FIRST.