comm.c

MudOSa4DGD/mudlib/dgd/lib/sys/efun/comm.c · 3.0 KB

From the archive MudOSa4DGD-30.06.98.tar.gz

Download the archive   « Back to the archive contents

/*
 * comm.c
 *
 * Communication funcs
 *
 * (C) Frank Schmidt, Jesus@NorseMUD
 *
 */


/* actually show <message> to the connected user */
static int __RECEIVE_DEF(string msg) {
  object user;
  if (user=__query_user()) {
    /* pass tell over to user object */
    user->send_message(msg);
    return 1;
  }
  /* object not interactive */
  return 0;
}


#ifdef MUDOS_COMMUNICATION

/* tell <str> to object <ob> */
static void tell_object(object ob, string str) {
  ob->__CATCH_TELL_DEF(str);
}


/* tell <str> to this_player() */
static void write(string str) {
  object ob;
  if (ob=this_player())
    ob->__CATCH_TELL_DEF(str);
}


#ifdef MUDOS_INVENTORY

/* tell something to a room */
static varargs void tell_room(object room, string message, mixed exclude) {
  room->__CATCH_TELL_DEF(message, exclude);
}


/* say <str> to environment of this_player() */
static varargs void say(string str, mixed exclude) {
  object env, tp;
  if ((tp=this_player())) {
    if (arrayp(exclude))
      exclude += ({ tp });
    else
      exclude = ({ tp });
  }
  if (env=environment(tp)) {
    env->__CATCH_TELL_DEF(str, exclude);
  }
}
#endif


/* shout <str> to all users except this_player() */
static void shout(string str) {
  int i;
  object *livs;
  livs = users();
  livs -= ({ this_player() });
  for (i=::sizeof(livs); --i >= 0; )
    livs[i]->__CATCH_TELL_DEF(str);
}

#endif /* MUDOS_COMMUNICATION */



#ifdef MUDOS_MESSAGE

/* send a message with a class to several objects */
static varargs int message(string class, string message, mixed target, mixed exclude) {
  /* turn target & exclude into an array */
  int i, n;
  switch (typeof(target)) {
  case T_OBJECT:
    target = ({ target });
    break;
  case T_STRING:
    target = ({ find_object(target) });
    break;
  case T_ARRAY:
    break;
  default:
    error("Bad type of argument 3 to message().");
    return 0;
  }

  /* exclude some folks? */
  if (exclude) {
    if (!arrayp(exclude)) exclude = ({ exclude });
    target -= exclude;
  }

  /* let them receive the message */
  for (i=::sizeof(target); --i >= 0; )
    n += target[i]->receive_message(class, message, exclude);

  /* return number of objects received the message */
  return n;
}

#endif


/* catch a tell from someone/something in current object */
varargs int __CATCH_TELL_DEF(string str, mixed exclude) {
#ifdef MUDOS_ROOM_ECHO
  /* I really believe echoing messages through inv is Mudlib's responsiblity */
  int i, n;
  object *inv;
  if (inv=all_inventory(this_object())) {
    /* pass tell to objects in inventory */
    if (exclude) {
      if (!arrayp(exclude)) exclude = ({ exclude });
      inv -= exclude;
    }
    for (i=::sizeof(inv); --i >= 0; )
      n += inv[i]->__CATCH_TELL_DEF(str, exclude);
  }

  /* redirect to receive() efun */
  return n + __RECEIVE_DEF(str);
#else
  return __RECEIVE_DEF(str);
#endif
}


#ifdef MUDOS_RECEIVE_MESSAGE

/* we've received a message with a class */
varargs int receive_message(string class, string messy, mixed exclude) {
  /* redirect to catch_tell() */
  return __CATCH_TELL_DEF(messy, exclude);
}

#endif

Site Stats

Snippets: 1791
Codebases: 571