MudOSa4DGD/
MudOSa4DGD/bin/
MudOSa4DGD/data/
MudOSa4DGD/doc/
MudOSa4DGD/doc/driver/
MudOSa4DGD/doc/efun/bitstrings/
MudOSa4DGD/doc/efun/command/
MudOSa4DGD/doc/efun/communication/
MudOSa4DGD/doc/efun/heart_beat/
MudOSa4DGD/doc/efun/interactive/
MudOSa4DGD/doc/efun/inventory/
MudOSa4DGD/doc/efun/living/
MudOSa4DGD/doc/efun/mappings/
MudOSa4DGD/doc/efun/strings/
MudOSa4DGD/doc/efun/uid/
MudOSa4DGD/doc/funs/
MudOSa4DGD/doc/language/
MudOSa4DGD/mudlib/dgd/doc/
MudOSa4DGD/mudlib/dgd/lib/include/dgd/
MudOSa4DGD/mudlib/dgd/lib/std/
MudOSa4DGD/mudlib/dgd/lib/sys/
MudOSa4DGD/mudlib/dgd/log/
MudOSa4DGD/mudlib/log/
MudOSa4DGD/mudlib/std/include/
MudOSa4DGD/mudlib/std/obj/
/*
 * 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