nightmare3_fluffos_v2/
nightmare3_fluffos_v2/bin/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/ChangeLog.old/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/Win32/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/compat/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/compat/simuls/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/include/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/clone/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/command/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/data/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/etc/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/include/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/inherit/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/inherit/master/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/log/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/single/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/single/tests/compiler/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/single/tests/efuns/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/single/tests/operators/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/u/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/tmp/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/windows/
nightmare3_fluffos_v2/lib/cmds/ambassador/
nightmare3_fluffos_v2/lib/cmds/database/
nightmare3_fluffos_v2/lib/cmds/hm/
nightmare3_fluffos_v2/lib/cmds/soul/
nightmare3_fluffos_v2/lib/daemon/cfg/
nightmare3_fluffos_v2/lib/daemon/cfg/mon_races/
nightmare3_fluffos_v2/lib/daemon/cfg/races/
nightmare3_fluffos_v2/lib/daemon/include/
nightmare3_fluffos_v2/lib/daemon/save/
nightmare3_fluffos_v2/lib/daemon/services/
nightmare3_fluffos_v2/lib/daemon/soul/
nightmare3_fluffos_v2/lib/doc/
nightmare3_fluffos_v2/lib/doc/TestPlans/
nightmare3_fluffos_v2/lib/doc/approval/
nightmare3_fluffos_v2/lib/doc/approval/QC/
nightmare3_fluffos_v2/lib/doc/approval/balance/
nightmare3_fluffos_v2/lib/doc/build/
nightmare3_fluffos_v2/lib/doc/build/armours/
nightmare3_fluffos_v2/lib/doc/build/economy/
nightmare3_fluffos_v2/lib/doc/build/etc/
nightmare3_fluffos_v2/lib/doc/build/monster/
nightmare3_fluffos_v2/lib/doc/build/room/
nightmare3_fluffos_v2/lib/doc/build/virtual/
nightmare3_fluffos_v2/lib/doc/build/weapon/
nightmare3_fluffos_v2/lib/doc/classes/
nightmare3_fluffos_v2/lib/doc/efun/
nightmare3_fluffos_v2/lib/doc/etc/
nightmare3_fluffos_v2/lib/doc/help/creator/
nightmare3_fluffos_v2/lib/doc/help/hm/
nightmare3_fluffos_v2/lib/doc/law/
nightmare3_fluffos_v2/lib/doc/lpc/basic/
nightmare3_fluffos_v2/lib/doc/lpc/data_types/
nightmare3_fluffos_v2/lib/doc/lpc/etc/
nightmare3_fluffos_v2/lib/doc/lpc/intermediate/
nightmare3_fluffos_v2/lib/doc/lpc/types/
nightmare3_fluffos_v2/lib/doc/mudlib/
nightmare3_fluffos_v2/lib/doc/mudlib/features/
nightmare3_fluffos_v2/lib/domains/Examples/etc/
nightmare3_fluffos_v2/lib/domains/Examples/room/
nightmare3_fluffos_v2/lib/domains/Examples/virtual/
nightmare3_fluffos_v2/lib/domains/Examples/virtual/exaA/
nightmare3_fluffos_v2/lib/domains/Examples/virtual/exaB/
nightmare3_fluffos_v2/lib/domains/Examples/weapon/
nightmare3_fluffos_v2/lib/domains/Praxis/
nightmare3_fluffos_v2/lib/domains/Praxis/adm/
nightmare3_fluffos_v2/lib/domains/Praxis/attic/
nightmare3_fluffos_v2/lib/domains/Praxis/cemetary/
nightmare3_fluffos_v2/lib/domains/Praxis/cemetary/mon/
nightmare3_fluffos_v2/lib/domains/Praxis/data/
nightmare3_fluffos_v2/lib/domains/Praxis/death/
nightmare3_fluffos_v2/lib/domains/Praxis/mountains/
nightmare3_fluffos_v2/lib/domains/Praxis/obj/armour/
nightmare3_fluffos_v2/lib/domains/Praxis/obj/magic/
nightmare3_fluffos_v2/lib/domains/Praxis/obj/weapon/
nightmare3_fluffos_v2/lib/domains/Praxis/orc_valley/
nightmare3_fluffos_v2/lib/domains/Praxis/quests/
nightmare3_fluffos_v2/lib/domains/Praxis/standardOld/
nightmare3_fluffos_v2/lib/include/
nightmare3_fluffos_v2/lib/log/
nightmare3_fluffos_v2/lib/log/errors/
nightmare3_fluffos_v2/lib/log/reports/
nightmare3_fluffos_v2/lib/log/watch/
nightmare3_fluffos_v2/lib/news/
nightmare3_fluffos_v2/lib/secure/cfg/
nightmare3_fluffos_v2/lib/secure/cmds/ambassador/
nightmare3_fluffos_v2/lib/secure/cmds/mortal/
nightmare3_fluffos_v2/lib/secure/save/users/d/
nightmare3_fluffos_v2/lib/secure/std/
nightmare3_fluffos_v2/lib/std/hm/
nightmare3_fluffos_v2/lib/std/living/
nightmare3_fluffos_v2/lib/std/room/
nightmare3_fluffos_v2/lib/std/user/
nightmare3_fluffos_v2/lib/std/virtual/
nightmare3_fluffos_v2/lib/www/
nightmare3_fluffos_v2/lib/www/errors/
nightmare3_fluffos_v2/lib/www/gateways/
nightmare3_fluffos_v2/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;
}