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/services/channel.c
 *    from the Dead Souls LPC Library
 *    handles intermud channels using the Intermud 3 protocols
 *    created by Descartes of Borg 950625
 *    Version: @(#) channel.c 1.2@(#)
 *    Last modified: 96/12/14
 */

#define SERVICE_CHANNEL

#include <daemons.h>
#include <rooms.h>
#define MSG_SYSTEM   ((1 << 10) | MSG_NOBLOCK)             /* sys messages */
#define MSG_NOBLOCK  (1 << 0)                 /* no blocking */


static private string *local_chans = ({"newbie","cre","gossip","admin","error",
  "priest", "mage", "explorer", "thief", "fighter", "death" });


void eventReceiveChannelWhoReply(mixed *packet) {
    object ob;

    if( file_name(previous_object()) != INTERMUD_D ) return;
    if( !(ob = find_player(packet[5])) ) return;
    packet[6] = (string)DSCHAT_D->GetLocalChannel(packet[6]);
    if( !sizeof(packet[7]) ) {
	ob->eventPrint("No one is listening to " + packet[6] + " at " +
	  packet[2] + ".", MSG_SYSTEM);
	return;
    }
    ob->eventPrint("Listening to " + packet[6] + " at " + packet[2] + ":" +
      implode(packet[7], "   "), MSG_SYSTEM);
}

void eventReceiveChannelWhoRequest(mixed *packet) {
    string *who;
    string ret = "";
    if( file_name(previous_object()) != INTERMUD_D ) return;
    who = DSCHAT_D->GetChannelList(packet[6]);
    INTERMUD_D->eventWrite(({ "chan-who-reply", 5, mud_name(), 0, packet[2],
	packet[3], packet[6], who }));

    foreach(string entry in who){
	ret += entry+", ";
    }
    //ret = truncate(ret,2);
}

void eventReceiveChannelUserRequest(mixed *packet) {
    object ob;
    string visname;
    int gender;
    if( file_name(previous_object()) != INTERMUD_D ) return;
    if( !(ob = find_player(packet[6])) ) {
	INTERMUD_D->eventWrite( ({ "error", 5, mud_name(), 0, packet[2], 0,
	    "unk-user", packet[6] + " is not a valid "
	    "player.", packet }) );
	return;
    }
    visname = (string)ob->GetCapName();
    switch( (string)ob->GetGender() ) {
    case "male": gender = 0; break;
    case "female": gender = 1; break;
    default: gender = 2; break;
    }
    INTERMUD_D->eventWrite( ({ "chan-user-reply", 5, mud_name(), 0, 
	packet[2], 0, packet[6], visname, gender }));
}

void eventReceiveChannelMessage(mixed *packet) {

    if( file_name(previous_object()) != INTERMUD_D ) return;
    if( packet[2] == mud_name() ) return;

    CHAT_D->eventSendChannel(packet[7] + "@" + packet[2], packet[6],
      packet[8]);
    if(packet[2] != mud_name()) CHAT_D->eventAddLast(packet[6],"",packet[6],packet[8],packet[7] + "@" + packet[2]);

}

void eventReceiveChannelEmote(mixed *packet) {

    if( file_name(previous_object()) != INTERMUD_D ) return;
    if( packet[2] == mud_name() ) return;
    if( !packet[7] ) return;
    CHAT_D->eventSendChannel(packet[7] + "@" + packet[2], packet[6],
      packet[8], 1, 0, 0);
    if(packet[2] != mud_name()) CHAT_D->eventAddLast(packet[6],"",packet[6],packet[7] + "@" + packet[2] + replace_string(packet[8],"$N",""));
}

void eventReceiveChannelTargettedEmote(mixed *packet) {
    string target;

    if( file_name(previous_object()) != INTERMUD_D ) return;
    if( packet[2] == mud_name() ) return;
    if( packet[7] != mud_name() ) target = packet[12] + "@" + packet[7];
    else target = packet[12];
    CHAT_D->eventSendChannel(packet[11] + "@" + packet[2], packet[6],
      packet[9], 1, target, packet[10]);
    //if(packet[2] != mud_name()) true();
}

varargs void eventSendChannel(string who, string ch, string msg, int emote,
  string target, string targmsg) {
    mixed *packet;
    mixed *packet_thing = ({ who, ch, msg, emote || "", target || "", targmsg || "" });

    string targpl, where;  // targpl is target keyname


    if( emote ) {
	if( target && targmsg ) {
	    if( sscanf(target, "%s@%s", targpl, where) != 2 ) {
		targpl = convert_name(target);
		where = mud_name();
	    }
	    else {
		//where = trim(where);
		//if(!alphap(last(where,1))) where = truncate(where,1);
		if(member_array(lower_case(where), INTERMUD_D->GetLCMuds()) == -1) {
		    write("No such mud.");
		    return;
		}
		target = SERVICES_D->GetRemoteDisplayName(targpl, where);
		if( !target ) target = capitalize(targpl);
	    }
	    packet = ({ "channel-t", 5, mud_name(), convert_name(who), 0, 0,
	      ch, where, targpl, msg, targmsg, who, target });
	}
	else packet = ({ "channel-e", 5, mud_name(), convert_name(who), 0, 0,
	      ch, who, msg });
    }
    else packet = ({ "channel-m", 5, mud_name(), convert_name(who), 0, 0, ch, 
	  who, msg });
    if(member_array(ch, local_chans) == -1){
	INTERMUD_D->eventWrite(packet);
    }
}

void eventSendChannelWhoRequest(string channel, string mud) {
    string pl;

    pl = (string)this_player(1)->GetKeyName();
    INTERMUD_D->eventWrite(({ "chan-who-req", 5, mud_name(), pl, mud, 0,
	channel }));
}

void eventRegisterChannels(mapping list) {
    mixed *val;
    string channel, ns;

    if( file_name(previous_object()) != INTERMUD_D ) return;
    ns = (string)INTERMUD_D->GetNameserver();
    foreach(channel, val in list) {
	if( !val ) continue;
	if( channel == (string)CHAT_D->GetLocalChannel(channel) && 
	  channel != "dead_test4" && channel != "dead_souls" &&
	  channel != "lpuni" && channel != "german" ) {
	    INTERMUD_D->eventWrite(({ "channel-listen", 5, mud_name(), 0, ns, 
		0, channel, 0 }));
	    log_file("channels", "New channel: " + channel + " recognized " +
	      ctime(time()) + "\nValue: " + identify(val) + "\n\n");
	}
	else INTERMUD_D->eventWrite(({ "channel-listen", 5, mud_name(), 0, ns,
		0, channel, 1 }));
    }

}

int eventAdministerChannel(string channel, string *additions,
  string *subs) {

    if( !((int)master()->valid_apply( ({}) )) ) return 0;
    if( member_array(channel, INTERMUD_D->GetChannels()) == -1 )
	return 0;
    INTERMUD_D->eventWrite(({ "channel-admin", 5, mud_name(),
	(string)this_player(1)->GetKeyName(),
	(string)INTERMUD_D->GetNameserver(),
	0, channel, additions, subs }));

    return 1;
}

int AddChannel(string channel, int privee) {

    if( !((int)master()->valid_apply( ({}) )) ){ 
	return 0;
    }
    if( member_array(channel, INTERMUD_D->GetChannels()) != -1 ){
	return 0;
    }
    INTERMUD_D->eventWrite(({ "channel-add", 5, mud_name(), 
	(string)this_player(1)->GetKeyName(),
	(string)INTERMUD_D->GetNameserver(), 0,
	channel, privee }));
    return 1;
}

int RemoveChannel(string channel) {

    if( member_array(channel, INTERMUD_D->GetChannels()) == -1 ){
	return 0;
    }
    INTERMUD_D->eventWrite(({ "channel-remove", 5, mud_name(),
	(string)this_player(1)->GetKeyName(),
	(string)INTERMUD_D->GetNameserver(), 0,
	channel }));
    return 1;
}