foundationI_fluffos_v1/
foundationI_fluffos_v1/bin/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/ChangeLog.old/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/Win32/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/compat/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/compat/simuls/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/include/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/clone/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/command/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/data/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/etc/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/include/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/inherit/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/inherit/master/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/log/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/single/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/single/tests/compiler/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/single/tests/efuns/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/single/tests/operators/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/u/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/tmp/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/windows/
foundationI_fluffos_v1/lib/
foundationI_fluffos_v1/lib/cmds/ambassador/
foundationI_fluffos_v1/lib/cmds/database/
foundationI_fluffos_v1/lib/cmds/soul/
foundationI_fluffos_v1/lib/daemon/include/
foundationI_fluffos_v1/lib/daemon/save/
foundationI_fluffos_v1/lib/daemon/services/
foundationI_fluffos_v1/lib/daemon/soul/
foundationI_fluffos_v1/lib/doc/build/
foundationI_fluffos_v1/lib/doc/build/room/
foundationI_fluffos_v1/lib/doc/build/virtual/
foundationI_fluffos_v1/lib/doc/driver/
foundationI_fluffos_v1/lib/doc/efun/
foundationI_fluffos_v1/lib/doc/etc/
foundationI_fluffos_v1/lib/doc/help/creator/
foundationI_fluffos_v1/lib/doc/help/hm/
foundationI_fluffos_v1/lib/doc/help/user/
foundationI_fluffos_v1/lib/doc/lpc/basic/
foundationI_fluffos_v1/lib/doc/lpc/data_types/
foundationI_fluffos_v1/lib/doc/lpc/etc/
foundationI_fluffos_v1/lib/doc/lpc/intermediate/
foundationI_fluffos_v1/lib/doc/lpc/types/
foundationI_fluffos_v1/lib/doc/mudlib/
foundationI_fluffos_v1/lib/doc/mudlib/features/
foundationI_fluffos_v1/lib/domains/Examples/etc/
foundationI_fluffos_v1/lib/domains/Examples/room/
foundationI_fluffos_v1/lib/domains/Examples/virtual/
foundationI_fluffos_v1/lib/domains/Examples/virtual/exaA/
foundationI_fluffos_v1/lib/domains/Examples/virtual/exaB/
foundationI_fluffos_v1/lib/domains/Examples/weapon/
foundationI_fluffos_v1/lib/domains/Standard/
foundationI_fluffos_v1/lib/domains/Standard/pools/
foundationI_fluffos_v1/lib/domains/Standard/std/
foundationI_fluffos_v1/lib/domains/Standard/xtra/
foundationI_fluffos_v1/lib/include/
foundationI_fluffos_v1/lib/news/
foundationI_fluffos_v1/lib/secure/cfg/
foundationI_fluffos_v1/lib/secure/cmds/adm/
foundationI_fluffos_v1/lib/secure/cmds/ambassador/
foundationI_fluffos_v1/lib/secure/cmds/mortal/
foundationI_fluffos_v1/lib/secure/etc/
foundationI_fluffos_v1/lib/secure/etc/approval/
foundationI_fluffos_v1/lib/secure/etc/elections/
foundationI_fluffos_v1/lib/secure/etc/mudlib/
foundationI_fluffos_v1/lib/secure/etc/quests/
foundationI_fluffos_v1/lib/secure/save/daemon/
foundationI_fluffos_v1/lib/secure/save/postal/d/descartes/
foundationI_fluffos_v1/lib/secure/save/users/d/
foundationI_fluffos_v1/lib/secure/std/
foundationI_fluffos_v1/lib/std/obj/
foundationI_fluffos_v1/lib/std/room/
foundationI_fluffos_v1/lib/std/user/
foundationI_fluffos_v1/lib/std/virtual/
foundationI_fluffos_v1/old/
foundationI_fluffos_v1/win32/
/*    /daemon/chat.c
 *    from the Nightmare 3.2 Mudlib
 *    daemon to handle all mud chat channels
 *    created by Descartes of Borg 931220
 */
#define DEBUG(x) tell_object(find_player("descartes"), x)

#include <std.h>
#include <network.h>
#include <daemons.h>
#include <objects.h>

inherit DAEMON;

#define MAGENTA "%^MAGENTA%^"
#define RESET "%^RESET%^"

static private mapping channels;

int list_channel(string str);

void create() {
    string *chans;
    object *who;
    int i, j;

    daemon::create();
    set_no_clean(1);
    channels = ([]);
    i = sizeof(who = users());
    while(i--) {
        j = sizeof(chans = (string *)who[i]->query_channels());
        while(j--) {
            if(!channels[chans[j]]) channels[chans[j]] = ({});
            channels[chans[j]] = distinct_array(channels[chans[j]]+({who[i]}));
        }
    }
}

void add_user(string *chans) {
    object ob;
    int i;

    if(!userp(ob = previous_object())) return;
    i = sizeof(chans);
    while(i--) { 
        if(!channels[chans[i]]) channels[chans[i]] = ({});
         channels[chans[i]] = distinct_array(channels[chans[i]]+({ob}));
    }
}

void remove_user(string *chans) {
    object ob;
    int i;

    if(!userp(ob = previous_object())) return;
    i = sizeof(chans);
    while(i--) {
        if(!channels[chans[i]]) continue;
        else channels[chans[i]] -= ({ ob });
        if(!sizeof(channels[chans[i]])) map_delete(channels, chans[i]);
    }
}

int do_chat(string verb, string str) {
    string msg;
    int emote;
    string name;

    if(verb == "list") return list_channel(str);
    if(!channels[verb]) {
        if(sscanf(verb, "%semote", verb)) emote = 1;
        else return 0;
        if(!channels[verb]) return 0;
    }
    if(member_array(this_player(), channels[verb]) == -1) return 0;
    if(!str) {
        this_player()->set_blocked(verb);
        return 1;
    }
    if((int)this_player()->query_blocked(verb)) {
        if((int)this_player()->query_blocked("all")) {
            message(verb, "You cannot chat while totally blocked.", this_player());
            return 1;
        }
        this_player()->set_blocked(verb);
    }
    if(verb == "admin" || verb=="cre") {
        if(!(name = (string)this_player()->query_CapName()))
          name = capitalize((string)this_player()->query_name());
    }
    else name=this_player()->query_cap_name();
    if(emote) msg = sprintf("%s<%s>%s %s %s", MAGENTA, verb, RESET,
      name, str);
    else msg = sprintf("%s %s<%s>%s %s", name, MAGENTA, verb, RESET, str);
    message(verb, msg, channels[verb]);
    if(member_array(verb, INTERMUD_CHANNELS) != -1){
      //SERVICES_D->send_gwizmsg(str, emote);
      SERVICES_D-> eventSendChannel(name, "imud_code", str, 0);
    }
    return 1;
}

void inter_channels(string who, string verb, string str, int emote) {
    string msg;

    if(!channels[verb] || base_name(previous_object()) != SERVICES_D) return;
    if(emote)
    msg = sprintf("%s<%s>%s %s %s", MAGENTA, verb, RESET, who, str);
    else msg = sprintf("%s %s<%s>%s %s", who, MAGENTA, verb, RESET, str);
    message(verb, msg, channels[verb]);
}

int list_channel(string str) {
    string list;
    int i;

    if(!channels[str]) return 0;
    if(member_array(this_player(), channels[str]) == -1) return 0;
    list = "";
    list = "Online: ";
    i =sizeof(channels[str]);
    while(i--) {
        if(!channels[str][i]) continue;
        if(hiddenp(channels[str][i]) || (int)channels[str][i]->query_invis() ||
          (int)channels[str][i]->query_blocked(str)) continue;
        list += "    "+(string)channels[str][i]->query_cap_name();
    }
    message("info", list, this_player());
    return 1;
}