ds2.10/bin/
ds2.10/extra/
ds2.10/extra/crat/
ds2.10/extra/creremote/
ds2.10/extra/mingw/
ds2.10/extra/wolfpaw/
ds2.10/fluffos-2.16-ds05/
ds2.10/fluffos-2.16-ds05/Win32/
ds2.10/fluffos-2.16-ds05/compat/
ds2.10/fluffos-2.16-ds05/compat/simuls/
ds2.10/fluffos-2.16-ds05/include/
ds2.10/fluffos-2.16-ds05/testsuite/
ds2.10/fluffos-2.16-ds05/testsuite/clone/
ds2.10/fluffos-2.16-ds05/testsuite/command/
ds2.10/fluffos-2.16-ds05/testsuite/data/
ds2.10/fluffos-2.16-ds05/testsuite/etc/
ds2.10/fluffos-2.16-ds05/testsuite/include/
ds2.10/fluffos-2.16-ds05/testsuite/inherit/
ds2.10/fluffos-2.16-ds05/testsuite/inherit/master/
ds2.10/fluffos-2.16-ds05/testsuite/log/
ds2.10/fluffos-2.16-ds05/testsuite/single/
ds2.10/fluffos-2.16-ds05/testsuite/single/tests/compiler/
ds2.10/fluffos-2.16-ds05/testsuite/single/tests/efuns/
ds2.10/fluffos-2.16-ds05/testsuite/single/tests/operators/
ds2.10/fluffos-2.16-ds05/testsuite/u/
ds2.10/lib/cmds/admins/
ds2.10/lib/cmds/common/
ds2.10/lib/cmds/creators/include/
ds2.10/lib/daemon/services/
ds2.10/lib/daemon/tmp/
ds2.10/lib/doc/
ds2.10/lib/doc/bguide/
ds2.10/lib/doc/efun/all/
ds2.10/lib/doc/efun/arrays/
ds2.10/lib/doc/efun/buffers/
ds2.10/lib/doc/efun/compile/
ds2.10/lib/doc/efun/floats/
ds2.10/lib/doc/efun/functions/
ds2.10/lib/doc/efun/general/
ds2.10/lib/doc/efun/mixed/
ds2.10/lib/doc/efun/numbers/
ds2.10/lib/doc/efun/parsing/
ds2.10/lib/doc/help/classes/
ds2.10/lib/doc/help/races/
ds2.10/lib/doc/lfun/
ds2.10/lib/doc/lfun/all/
ds2.10/lib/doc/lfun/lib/abilities/
ds2.10/lib/doc/lfun/lib/armor/
ds2.10/lib/doc/lfun/lib/bank/
ds2.10/lib/doc/lfun/lib/bot/
ds2.10/lib/doc/lfun/lib/clay/
ds2.10/lib/doc/lfun/lib/clean/
ds2.10/lib/doc/lfun/lib/clerk/
ds2.10/lib/doc/lfun/lib/client/
ds2.10/lib/doc/lfun/lib/combat/
ds2.10/lib/doc/lfun/lib/connect/
ds2.10/lib/doc/lfun/lib/container/
ds2.10/lib/doc/lfun/lib/corpse/
ds2.10/lib/doc/lfun/lib/creator/
ds2.10/lib/doc/lfun/lib/daemon/
ds2.10/lib/doc/lfun/lib/damage/
ds2.10/lib/doc/lfun/lib/deterioration/
ds2.10/lib/doc/lfun/lib/donate/
ds2.10/lib/doc/lfun/lib/door/
ds2.10/lib/doc/lfun/lib/equip/
ds2.10/lib/doc/lfun/lib/file/
ds2.10/lib/doc/lfun/lib/fish/
ds2.10/lib/doc/lfun/lib/fishing/
ds2.10/lib/doc/lfun/lib/flashlight/
ds2.10/lib/doc/lfun/lib/follow/
ds2.10/lib/doc/lfun/lib/ftp_client/
ds2.10/lib/doc/lfun/lib/ftp_data_connection/
ds2.10/lib/doc/lfun/lib/fuel/
ds2.10/lib/doc/lfun/lib/furnace/
ds2.10/lib/doc/lfun/lib/genetics/
ds2.10/lib/doc/lfun/lib/holder/
ds2.10/lib/doc/lfun/lib/id/
ds2.10/lib/doc/lfun/lib/interactive/
ds2.10/lib/doc/lfun/lib/lamp/
ds2.10/lib/doc/lfun/lib/leader/
ds2.10/lib/doc/lfun/lib/light/
ds2.10/lib/doc/lfun/lib/limb/
ds2.10/lib/doc/lfun/lib/living/
ds2.10/lib/doc/lfun/lib/load/
ds2.10/lib/doc/lfun/lib/look/
ds2.10/lib/doc/lfun/lib/manipulate/
ds2.10/lib/doc/lfun/lib/meal/
ds2.10/lib/doc/lfun/lib/messages/
ds2.10/lib/doc/lfun/lib/player/
ds2.10/lib/doc/lfun/lib/poison/
ds2.10/lib/doc/lfun/lib/position/
ds2.10/lib/doc/lfun/lib/post_office/
ds2.10/lib/doc/lfun/lib/potion/
ds2.10/lib/doc/lfun/lib/room/
ds2.10/lib/doc/lfun/lib/server/
ds2.10/lib/doc/lfun/lib/spell/
ds2.10/lib/doc/lfun/lib/torch/
ds2.10/lib/doc/lfun/lib/vendor/
ds2.10/lib/doc/lfun/lib/virt_sky/
ds2.10/lib/doc/lfun/lib/weapon/
ds2.10/lib/doc/lfun/lib/worn_storage/
ds2.10/lib/doc/lpc/constructs/
ds2.10/lib/doc/lpc/etc/
ds2.10/lib/doc/lpc/intermediate/
ds2.10/lib/doc/lpc/types/
ds2.10/lib/doc/misc/
ds2.10/lib/doc/old/
ds2.10/lib/doc/phints/
ds2.10/lib/domains/
ds2.10/lib/domains/Praxis/adm/
ds2.10/lib/domains/Praxis/attic/
ds2.10/lib/domains/Praxis/cemetery/mon/
ds2.10/lib/domains/Praxis/data/
ds2.10/lib/domains/Praxis/death/
ds2.10/lib/domains/Praxis/mountains/
ds2.10/lib/domains/Praxis/obj/armour/
ds2.10/lib/domains/Praxis/obj/magic/
ds2.10/lib/domains/Praxis/obj/weapon/
ds2.10/lib/domains/Praxis/orc_valley/
ds2.10/lib/domains/Ylsrim/
ds2.10/lib/domains/Ylsrim/adm/
ds2.10/lib/domains/Ylsrim/armor/
ds2.10/lib/domains/Ylsrim/broken/
ds2.10/lib/domains/Ylsrim/fish/
ds2.10/lib/domains/Ylsrim/meal/
ds2.10/lib/domains/Ylsrim/npc/
ds2.10/lib/domains/Ylsrim/obj/
ds2.10/lib/domains/Ylsrim/virtual/
ds2.10/lib/domains/Ylsrim/weapon/
ds2.10/lib/domains/alpha/room/
ds2.10/lib/domains/alpha/virtual/
ds2.10/lib/domains/campus/adm/
ds2.10/lib/domains/campus/etc/
ds2.10/lib/domains/campus/meals/
ds2.10/lib/domains/campus/txt/ai/charles/
ds2.10/lib/domains/campus/txt/ai/charles/bak2/
ds2.10/lib/domains/campus/txt/ai/charles/bak2/bak1/
ds2.10/lib/domains/campus/txt/ai/charly/
ds2.10/lib/domains/campus/txt/ai/charly/bak/
ds2.10/lib/domains/campus/txt/jenny/
ds2.10/lib/domains/cave/doors/
ds2.10/lib/domains/cave/etc/
ds2.10/lib/domains/cave/meals/
ds2.10/lib/domains/cave/weap/
ds2.10/lib/domains/default/chamber/
ds2.10/lib/domains/default/creator/
ds2.10/lib/domains/default/doors/
ds2.10/lib/domains/default/etc/
ds2.10/lib/domains/default/vehicle/
ds2.10/lib/domains/default/virtual/
ds2.10/lib/domains/town/save/
ds2.10/lib/domains/town/txt/shame/
ds2.10/lib/domains/town/virtual/
ds2.10/lib/domains/town/virtual/bottom/
ds2.10/lib/domains/town/virtual/space/
ds2.10/lib/estates/
ds2.10/lib/ftp/
ds2.10/lib/lib/comp/
ds2.10/lib/lib/daemons/
ds2.10/lib/lib/daemons/include/
ds2.10/lib/lib/lvs/
ds2.10/lib/lib/user/
ds2.10/lib/lib/virtual/
ds2.10/lib/log/
ds2.10/lib/log/adm/
ds2.10/lib/log/archive/
ds2.10/lib/log/chan/
ds2.10/lib/log/errors/
ds2.10/lib/log/law/adm/
ds2.10/lib/log/law/email/
ds2.10/lib/log/law/names/
ds2.10/lib/log/law/sites-misc/
ds2.10/lib/log/law/sites-register/
ds2.10/lib/log/law/sites-tempban/
ds2.10/lib/log/law/sites-watch/
ds2.10/lib/log/open/
ds2.10/lib/log/reports/
ds2.10/lib/log/router/
ds2.10/lib/log/secure/
ds2.10/lib/log/watch/
ds2.10/lib/obj/book_source/
ds2.10/lib/obj/include/
ds2.10/lib/powers/prayers/
ds2.10/lib/powers/spells/
ds2.10/lib/realms/template/
ds2.10/lib/realms/template/adm/
ds2.10/lib/realms/template/area/
ds2.10/lib/realms/template/area/armor/
ds2.10/lib/realms/template/area/npc/
ds2.10/lib/realms/template/area/obj/
ds2.10/lib/realms/template/area/room/
ds2.10/lib/realms/template/area/weap/
ds2.10/lib/realms/template/bak/
ds2.10/lib/realms/template/cmds/
ds2.10/lib/save/kills/o/
ds2.10/lib/secure/cfg/classes/
ds2.10/lib/secure/cmds/builders/
ds2.10/lib/secure/cmds/creators/include/
ds2.10/lib/secure/cmds/players/include/
ds2.10/lib/secure/daemon/imc2server/
ds2.10/lib/secure/daemon/include/
ds2.10/lib/secure/lib/
ds2.10/lib/secure/lib/include/
ds2.10/lib/secure/lib/net/include/
ds2.10/lib/secure/lib/std/
ds2.10/lib/secure/log/adm/
ds2.10/lib/secure/log/bak/
ds2.10/lib/secure/log/intermud/
ds2.10/lib/secure/log/network/
ds2.10/lib/secure/modules/
ds2.10/lib/secure/npc/
ds2.10/lib/secure/obj/include/
ds2.10/lib/secure/room/
ds2.10/lib/secure/save/
ds2.10/lib/secure/save/backup/
ds2.10/lib/secure/save/boards/
ds2.10/lib/secure/save/players/g/
ds2.10/lib/secure/tmp/
ds2.10/lib/secure/upgrades/files/
ds2.10/lib/secure/verbs/creators/
ds2.10/lib/std/board/
ds2.10/lib/std/lib/
ds2.10/lib/verbs/admins/include/
ds2.10/lib/verbs/builders/
ds2.10/lib/verbs/common/
ds2.10/lib/verbs/common/include/
ds2.10/lib/verbs/creators/
ds2.10/lib/verbs/creators/include/
ds2.10/lib/verbs/rooms/
ds2.10/lib/verbs/rooms/include/
ds2.10/lib/www/client/
ds2.10/lib/www/errors/
ds2.10/lib/www/images/
ds2.10/win32/
/*    /lib/interface.c
 *    from the Dead Souls Object Library
 *    handles user interface issues
 *    created by Descartes of Borg 950428
 *    Version: @(#) interface.c 1.4@(#)
 *    Last Modified: 96/10/15
 */

#include <lib.h>
#include <daemons.h>
#include <message_class.h>
#include "include/interface.h"

inherit LIB_CHAT;
inherit LIB_COMMAND;
inherit LIB_EDITOR;
inherit LIB_CHARIO;
inherit LIB_NMSH;
inherit LIB_CEDIT;

private string Terminal;
private mapping Blocked;
private int *Screen;
private static int LogHarass, Client;
private static mapping TermInfo;
string MessageQueue;
int PauseMessages, annoyblock;
int MessageExceptions, BlockAnnoying;

static void create(){
    chat::create();
    command::create();
    editor::create();
    nmsh::create();
    Terminal = "ansi";
    Screen = ({ 80, 20 });
    Blocked = ([]);
}

static string process_input(string str){
    command::SetCommandFail(0);
    command::process_input(str);
    if( Client ){
        int cl;
        sscanf(str, "%d %s", cl, str);
    }
    if( (str = editor::process_input(str)) == "" ) return "";
    else {
        str = nmsh::process_input(str);
        if( str != "" ){
            return chat_command(str);
        }
        else {
            return "";
        }
    }
}

static void terminal_type(string str){
    if( !stringp(str) ) return;
    else SetTerminal(lower_case(str));
}

static void window_size(int width, int height){ SetScreen(width, height); }

varargs int eventReceive(string message, int noprompt, int noerase){
    int max_length = __LARGEST_PRINTABLE_STRING__ - 192;
    string prompt = this_object()->GetPrompt(1);
    string *stack = call_stack(2);
    if(stack[1] == "write2" && message != "\n"){
        noerase = 1;
    }
    if(in_edit(this_object())) prompt = this_object()->GetPrompt();
    if(sizeof(message) > max_length){
        while(sizeof(message)){
            string tmp = message[0..max_length];
            receive(tmp+(noprompt ? "" : prompt));
            message = replace_string(message, tmp, "");
        }
    }
    else {
        if(!noerase && this_object()->GetProperty("reprompt")){
            this_object()->erase_prompt();
        }
        receive(message);
        this_object()->CheckCharmode();
    }
}

void receive_message(mixed msg_class, string msg){
    int cl = 0;
    if(intp(msg_class)){
        cl = msg_class;
        eventPrint(msg, cl);
        return;
    }

    else if( msg_class[0] == 'N' ){
        msg_class = msg_class[1..];
        cl |= MSG_NOWRAP;
    }
    else if( msg_class == "prompt" && msg_class == "editor" ) cl |= MSG_NOWRAP;

    switch(msg_class){
        case "smell": case "sound": case "touch": 
            cl |= MSG_ENV;
        break;

        case "receive":
            cl |= MSG_RECEIVE;
        break;

        case "snoop":
            cl |= MSG_SYSTEM | MSG_NOCOLOUR;

        case "broadcast":
            cl |= MSG_SYSTEM;
        break;

        case "editor":
            cl |= MSG_EDIT;
        break;

        case "tell": case "shout":
            cl |= MSG_CONV;
        break;

        case "come": case "leave": case "telout": case "telin":
            cl |= MSG_ENV;
        break;

        case "living_item": case "inanimate_item":
            cl |= MSG_ROOMDESC;
        break;

        case "system": case "more":
            cl |= MSG_SYSTEM;
        break;

        case "prompt":
            cl = MSG_PROMPT;
        break;

        case "error":
            cl |= MSG_ERROR;
        break;

        case "help":
            cl |= MSG_HELP;

        default:
        cl |= MSG_ENV;

    }
    eventPrint(msg, cl);
}

static void receive_snoop(string str){ receive_message("snoop", "%"+str); } 

int Setup(){
    command::Setup();
    nmsh::Setup();
    TermInfo = (mapping)TERMINAL_D->query_term_info(Terminal);
}

int eventFlushQueuedMessages(){
    print_long_string(this_object(),MessageQueue);
    MessageQueue = "";
    return 1;
}

varargs int eventPauseMessages(int x, int exceptions){
    if(exceptions) MessageExceptions = exceptions;
    else MessageExceptions = 0;
    if(x) PauseMessages = 1;
    else {
        if(PauseMessages){
            eventFlushQueuedMessages();
        }
        PauseMessages = 0;
    }
    return PauseMessages;
}

static varargs int PassengerPrint(string msg, mixed arg2, 
        mixed arg3, object *riders){
    object *targs = ({});
    if(riders && sizeof(riders)){
        int i1, rider_source;
        if(!arg2) arg2 = 0;
        if(!arg3) arg3 = 0;
        if(sizeof(riders)){
            if(arg2 && intp(arg2)){
                object *tmp_riders = riders;
                if(arg2 & MSG_CONV || arg2 & MSG_ENV){
                    foreach(object ob in previous_object(-1)){
                        if(member_array(ob,riders) != -1){
                            tmp_riders -= ({ ob });
                            rider_source = 1;
                        }
                    }
                }
                if((arg2 & MSG_CONV))  true();
                else {
                    if(objectp(arg2)) targs = tmp_riders - ({ arg2 });
                    else if(arrayp(arg2)) targs =  tmp_riders - arg2;
                    else targs = tmp_riders;
                    targs->eventPrint(msg, arg3);
                }
            }
            i1 = sizeof(previous_object(-1)) -1;
            if(i1 < 0) i1 = 0;
            if(sizeof(previous_object(-1)) &&
                    (member_array(previous_object(),riders) != -1 ||
                     member_array(previous_object(-1)[i1],riders) != -1) &&
                    (!intp(arg2) || (!(arg2 & MSG_CONV) && !(arg2 & MSG_ENV))) && 
                    member_array(this_object(),previous_object(-1)) == -1){ 
                if(objectp(arg2)) targs = riders - ({ arg2 });
                else if(arrayp(arg2)) targs = riders - arg2;
                else targs = riders;
                environment()->eventPrint(msg, arg2, arg3);
            }
        }
    }  
    return 1;
}

varargs int eventPrint(string msg, mixed arg2, mixed arg3){
    int msg_class;
    string prompt = "";
    object *passengers = filter(all_inventory(this_object()), (: living :) );
    if(this_object()->GetProperty("reprompt")){
        prompt = this_object()->GetPrompt(1);
    } 
    if( !msg ) return 0;
    if( !arg2 && !arg3 ) msg_class = MSG_ENV;
    else if( !arg2 ){
        if( !intp(arg3) ) msg_class = MSG_ENV;
        else msg_class = arg3;
    }
    else if( !intp(arg2) ) msg_class = MSG_ENV;
    else msg_class = arg2;
    if(sizeof(passengers) && (msg_class & MSG_ENV || msg_class & MSG_CONV)){
    } 
    if( !(msg_class & MSG_NOBLOCK) && GetBlocked("all") ) return 0;

    if((msg_class & MSG_ANNOYING) && annoyblock) return 0;

    /* This is no longer necessary, since the commands
     * "mute" and "gag" can now keep things quiet on
     * on channels for individuals if they so wish.
     * if((msg_class & MSG_CHAN) && environment() &&
     *  environment()->GetProperty("meeting room")) return 0;
     */
    if( GetLogHarass() )
        log_file("harass/" + GetKeyName(), strip_colours(msg) + "\n");
    if( !TermInfo )
        TermInfo = (mapping)TERMINAL_D->query_term_info(GetTerminal());
    if( !(msg_class & MSG_NOCOLOUR) ){
        int indent;

        if( msg_class & MSG_CONV ) indent = 4;
        else indent = 0;
        if( msg_class & MSG_NOWRAP )
            msg = terminal_colour(msg + "%^RESET%^", TermInfo);
        else
            msg = terminal_colour(msg + "%^RESET%^\n"+prompt, TermInfo,
                    GetScreen()[0], indent);
    }
    else if( !(msg_class & MSG_NOWRAP) ) msg = wrap(msg, GetScreen()[0]-1);
    if(PauseMessages && !(msg_class & MessageExceptions)){
        MessageQueue += msg;
    }
    else {
        if(msg_class & MSG_RECEIVE){
            receive(msg);
            return 1;
        }
        if( Client ) eventReceive("<" + msg_class + " " + msg + " " + msg_class +">\n");
        else eventReceive(msg);
    }
    return 1;
}

varargs int SetBlocked(string type, int flag){
    if( !type ) return 0;
    if( undefinedp(flag) ) flag = !Blocked[type];
    if( Blocked[type] == 2 && !archp(this_player()) ){
        this_player()->eventPrint("Unable to unblock " + type + ".");
        return -1;
    }
    Blocked[type] = flag;
    message("system", "You are "+(Blocked[type] ? "now blocking" :
                "no longer blocking")+" "+type+".", this_object());
    return Blocked[type];
}

int GetBlocked(string type){ return (Blocked["all"] || Blocked[type]); }

int SetClient(int x){
    return 0;
    if( x ) SetTerminal("unknown");
    return (Client = x);
}

int GetClient(){ return Client; }

int SetLogHarass(int x){
    string txt;

    if( GetForced() || (this_player(1) != this_object()) ) return LogHarass;
    if( LogHarass == x ) return LogHarass;
    if( x ){
        txt = "**************** Start of Log *****************\n"+
            "Time: " + ctime( time() ) + "\n";
        if( environment( this_object() ) ) txt += "Place: " +
            file_name( environment( this_object() ) ) + "\n";
    } else {
        txt = "**************** End of Log *****************\n"+
            "Time: " + ctime( time() ) + "\n";
    }
    log_file("harass/" + GetKeyName(), txt);
    return (LogHarass = x);
}

int GetLogHarass(){ return LogHarass; }

int *SetScreen(int width, int height){ 
    if( !width || !height ) return Screen;
    width--;
    if( width * height > __LARGEST_PRINTABLE_STRING__ ){
        if( width > height ) width = __LARGEST_PRINTABLE_STRING__/height;
        else if( height > width ) height = __LARGEST_PRINTABLE_STRING__/width;
        else width = height = (__LARGEST_PRINTABLE_STRING__-1)/2;
    }
    return (Screen = ({ width, height })); 
}

int *GetScreen(){ return Screen; }

string SetTerminal(string terminal){ 
    switch( terminal ){
        case "iris-ansi-net": case "vt100": case "vt220": case "vt102":
            case "vt300": case "dec-vt100":
            terminal = "ansi";
        break;
        case "unknown": case "ansi": case "freedom": case "ansi-status":
            case "xterm": 
            break;
        case "console": case "ibm-3278-2":
            terminal = "unknown";
        break;
        case "html" : terminal = "html"; break;
        default:
        log_file("terminals", "Unknown terminal type: " + terminal + "\n");
        terminal = Terminal;
        break;
    }
    if( terminal != Terminal ) 
        TermInfo = (mapping)TERMINAL_D->query_term_info(terminal);
    return Terminal = terminal;
}

string GetTerminal(){ return Terminal; }

string GetKeyName(){ return 0; }

int SetAnnoyblock(int i){
    if(!this_player()) return 0;
    if(archp(this_object()) && !archp(this_player())) return 0;
    if(!archp(this_object()) && this_player() != this_object()) return 0;
    if(i) annoyblock = 1;
    else annoyblock = 0;
    return annoyblock;
}

int GetAnnoyblock(){
    return annoyblock;
}

static int rArrow(string str){
    int ret, cedmode = this_object()->GetCedmode();
    switch(cedmode){
        case 0 : ret = nmsh::rArrow(str); break;
        case 1 : ret = cedit::rArrow(str); break;
    }
    return ret;
}

static int rCtrl(string str){
    int ret, cedmode = this_object()->GetCedmode();
    switch(cedmode){
        case 0 : ret = nmsh::rCtrl(str); break;
        case 1 : ret = cedit::rCtrl(str); break;
    }
    return ret;
}

static int rBackspace(){
    int ret, cedmode = this_object()->GetCedmode();
    switch(cedmode){
        case 0 : ret = nmsh::rBackspace(); break;
        case 1 : ret = cedit::rBackspace(); break;
    }
    return ret;
}

static int rEnter(){
    int ret, cedmode = this_object()->GetCedmode();
    switch(cedmode){
        case 0 : ret = nmsh::rEnter(); break;
        case 1 : ret = cedit::rEnter(); break;
    }
    return ret;
}

static int rAscii(string str){
    int ret, cedmode = this_object()->GetCedmode();
    switch(cedmode){
        case 0 : ret = nmsh::rAscii(str); break;
        case 1 : ret = cedit::rAscii(str); break;
    }
    return ret;
}

static int rDel(){
    int ret, cedmode = this_object()->GetCedmode();
    switch(cedmode){
        case 0 : ret = nmsh::rDel(); break;
        case 1 : ret = cedit::rDel(); break;
    }
    return ret;
}

static int rAnsi(string str){
    int ret, cedmode = this_object()->GetCedmode();
    switch(cedmode){
        case 0 : ret = nmsh::rAnsi(str); break;
        case 1 : ret = cedit::rAnsi(str); break;
    }
    return ret;
}