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

int count, state, blocked, short, logged, forwarding;
int lastchecked, lastmessage;
string message, announce, name, final, tempy, cratty, f_global, forwardee;
object owner;

int read_it(string str);

int validate(){
    object prev = previous_object();
    if(prev && prev->GetForced()) return 0;
    if(this_player() && this_player()->GetForced()) return 0;
    if(!name || (owner && this_player() == owner)) return 1;
    return 0;
}

void create(){
    ::create();
    AddSave(({"state","forwarding","name","forwardee","announce","message",
                "lastchecked","lastmessage"}));
    SetKeyName("answering machine");
    SetId( ({"machine","voicemail"}) );
    SetShort("an answering machine");
    SetLong("This is a portable answering machine. There is a label on "
            "it you can read.");
    SetItems(([
                "label" : "A label you can read.",
                ]));
    SetRead(([
                "label" : (: read_it :),
                ]));
    SetDefaultRead("Try: read label on machine");
    SetProperties(([
                "no steal" : 1,
                ]));
    SetMass(1);
    SetVendorType(VT_TREASURE);
    state=0;
    count = 0;
    set_heart_beat(10);
}

void init(){
    ::init();
    add_action("toggle_answer","answer");
    add_action("check_it","check");
    add_action("set_ann","announce");
    add_action("check_mess","tells");
    add_action("erase","erase");
    //add_action("tellforward","tellforward");
    add_action("arch_it","archive");
    if(owner){
        this_object()->get_ann();
    }
    else {
        if(name && owner) return;
        if(environment() && interactive(environment())){
            unguarded( (: owner = environment() :) );
            unguarded( (: name =  owner->GetKeyName() :) );
        }
    }
}

void heart_beat(){
    count++;
    if(!clonep(this_object())) return;
    if(name && !owner){
        if(!(owner = unguarded( (: find_player(name) :) ))){
            this_object()->eventDestruct();
        }
    }
    if(count > 36){
        count = 0;
        if(lastchecked < lastmessage){
            if(environment()){
                environment()->eventPrint("The answering machine %^GREEN%^"+
                        "BEEPS%^RESET%^.");
            }
        }
    }
}

int tellforward(string str){
    object env = environment();
    //This functionality is incomplete
    return 0;
    if(!validate()) return 0;
    if(!env || !this_player() || env != this_player() ){
        return 0;
    }
    if(!str){
        if(forwardee && forwarding){
            write("You are forwarding tells to "+forwardee+".");
        }
        else {
            write("There is no current forwarding recipient.");
        }
        return 1;
    }
    if(str == "off"){
        write("Disabling tell forwarding.");
        forwarding = 0;
        forwardee = 0;
        return 1;
    }
    write("You are now forwarding tells to: "+str);
    forwardee = str;
    forwarding = 1;
    return 1;
}

int toggle_answer(string str){
    if(str=="on"){
        if(state==1){
            write("The answering machine is already on.\n");
            return 1;
        }
        state=1;
        blocked=1;
        short=1;
        logged=1;
        unguarded( (: owner = this_player() :) );
        unguarded( (: name = this_player()->GetKeyName() :) );
        this_object()->log_it("*** Answering machine activated on "+
                local_ctime(time())+".\n");
        write("The answering machine is on.\n");
        return 1;
    }
    if(str=="off"){
        if(state==0){
            write("The machine is already turned off.\n");
            return 1;
        }
        state=0;
        blocked=0;
        short=0;
        logged=0;
        name=0;
        owner=0;
        cratty=0;
        tempy=0;
        forwardee=0;
        forwarding=0;
        write("The answering machine is off.\n");
        return 1;
    }
}

int query_answer(){
    return state;
}

int do_tell(string wut){
    owner->eventForce(wut);
    return 1;
}

int get_message(string str){
    object prev = previous_object();
    if(!prev || 
            (base_name(prev) != CMD_TELL && base_name(prev) != SERVICES_D)){ 
        return 0;
    }
    cratty="";
    if(forwarding && forwardee){
        string localtemp;
        cratty += "(forwarded to "+forwardee+") ";
        localtemp = "tell "+forwardee+" "+str;
        tempy = replace_string(localtemp,"tells you","");
        unguarded( (: do_tell, tempy :) );
    }
    tempy = 0;
    cratty += str;
    this_object()->final();
    lastmessage = time();
    return 1;
}

string send_message(){
    if(!sizeof(announce)) this_object()->get_ann(); 
    return announce;
}

static int log_it(string str){
    f_global=str;
    name=lower_case(owner->GetKeyName());
    unguarded((: write_file(homedir(owner)+"/log/messages", f_global+"\n") :));
    return 1;
}

static int final(){
    tempy = local_ctime(time())+":\n"+cratty+"\n\n";
    if(!blocked){
        message("info",final+"\n", environment(this_object()));
    }
    if(logged){
        unguarded( (: this_object()->log_it(tempy) :) );
    }
    cratty = 0;
    tempy = 0;
    return 1;
}

int set_ann(string str){
    if(!validate()) return 0;
    if(!state){
        write("The machine is not turned on.\n");
        return 1;
    }
    announce=str;
    rm(homedir(owner)+"/log/annc");
    write_file(homedir(this_player())+"/log/annc", announce);
    return 1;
}

int get_ann(){
    if(file_size(homedir(owner)+"/log/annc") > 0){
        unguarded( (: announce=read_file(homedir(owner)+"/log/annc") :) );
    }
    if(!sizeof(announce)){
        announce=capitalize(name)+" cannot "+
            "answer your tell right now. Your message has been recorded "+
            "and "+nominative(owner)+" will get back to you as soon as possible.";
    }
    return 1;
}

int check_mess(string str){
    if(!validate()) return 0;
    if(!str){
        lastchecked = time();
        owner->more(homedir(owner)+"/log/messages");
        return 1;
    }
}

string read_it(string str){
    string ret = "\n"+
        "answer on/off   - on activates the machine. off doesn't.\n"+
        "announce <msg>  - '<msg>' is whatever you want the sender to see.\n"+
        "tells           - lists messages by date, time and sender.\n"+
        "erase tape      - erases all messages on the machine.\n"+
        "archive tape    - copies tape onto backup archive file.\n"+
        //"tellforward <name>  - Forwards any tells you receive to the "+
        //"person specifed. Use with GREAT caution.\n"+
        "\n"+
        "\n";
    return ret;
}

int erase(string str){
    if(!validate()) return 1;
    if(str=="tape"){
        write("You erase the answering machine tape.\n");
        rm(homedir(owner)+"/log/messages");
        return 1;
    }
}

int arch_it(string str){
    string temp;
    if(!validate()) return 0;
    if(str=="tape"){
        write("You save the contents of the answering machine tape "
                "into "+homedir(owner)+"/log/archive.\n");
        temp=read_file(homedir(owner)+"/log/messages");
        write_file(homedir(owner)+"/log/archive", temp);
        return 1;
    }
}

int clean_tape(string str){
    if(!validate()) return 0;
    if(str=="tape"){
        this_object()->arch_it("tape");
        this_object()->erase("tape");
        return 1;
    }
}