nightmare4_fluffos_v1/
nightmare4_fluffos_v1/bin/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/ChangeLog.old/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/Win32/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/compat/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/compat/simuls/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/include/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/clone/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/command/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/data/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/etc/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/include/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/inherit/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/inherit/master/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/log/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/single/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/single/tests/compiler/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/single/tests/efuns/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/single/tests/operators/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/u/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/tmp/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/windows/
nightmare4_fluffos_v1/lib/cfg/
nightmare4_fluffos_v1/lib/cmds/admins/
nightmare4_fluffos_v1/lib/cmds/common/
nightmare4_fluffos_v1/lib/cmds/creators/include/
nightmare4_fluffos_v1/lib/cmds/creators/include/SCCS/
nightmare4_fluffos_v1/lib/cmds/hm/
nightmare4_fluffos_v1/lib/daemon/services/
nightmare4_fluffos_v1/lib/doc/
nightmare4_fluffos_v1/lib/doc/faq/
nightmare4_fluffos_v1/lib/doc/help/classes/
nightmare4_fluffos_v1/lib/doc/help/creators/
nightmare4_fluffos_v1/lib/doc/help/hm/
nightmare4_fluffos_v1/lib/doc/help/players/
nightmare4_fluffos_v1/lib/doc/help/races/
nightmare4_fluffos_v1/lib/doc/help/religion/
nightmare4_fluffos_v1/lib/doc/mudlib/
nightmare4_fluffos_v1/lib/doc/mudlib/cfg/
nightmare4_fluffos_v1/lib/domains/Ylsrim/
nightmare4_fluffos_v1/lib/domains/Ylsrim/adm/
nightmare4_fluffos_v1/lib/domains/Ylsrim/armour/
nightmare4_fluffos_v1/lib/domains/Ylsrim/fish/
nightmare4_fluffos_v1/lib/domains/Ylsrim/meal/
nightmare4_fluffos_v1/lib/domains/Ylsrim/npc/
nightmare4_fluffos_v1/lib/domains/Ylsrim/virtual/
nightmare4_fluffos_v1/lib/domains/Ylsrim/weapon/
nightmare4_fluffos_v1/lib/domains/Ylsrim/xtra/
nightmare4_fluffos_v1/lib/lib/comp/
nightmare4_fluffos_v1/lib/lib/lvs/
nightmare4_fluffos_v1/lib/lib/std/
nightmare4_fluffos_v1/lib/lib/user/
nightmare4_fluffos_v1/lib/news/
nightmare4_fluffos_v1/lib/obj/
nightmare4_fluffos_v1/lib/obj/include/
nightmare4_fluffos_v1/lib/save/
nightmare4_fluffos_v1/lib/save/kills/a/
nightmare4_fluffos_v1/lib/save/kills/b/
nightmare4_fluffos_v1/lib/save/kills/f/
nightmare4_fluffos_v1/lib/save/kills/m/
nightmare4_fluffos_v1/lib/save/kills/q/
nightmare4_fluffos_v1/lib/save/kills/r/
nightmare4_fluffos_v1/lib/secure/cfg/
nightmare4_fluffos_v1/lib/secure/cfg/classes/
nightmare4_fluffos_v1/lib/secure/cfg/races/SCCS/
nightmare4_fluffos_v1/lib/secure/cmds/creators/include/
nightmare4_fluffos_v1/lib/secure/cmds/players/
nightmare4_fluffos_v1/lib/secure/cmds/players/include/
nightmare4_fluffos_v1/lib/secure/daemon/include/
nightmare4_fluffos_v1/lib/secure/lib/
nightmare4_fluffos_v1/lib/secure/lib/include/
nightmare4_fluffos_v1/lib/secure/lib/net/
nightmare4_fluffos_v1/lib/secure/lib/std/
nightmare4_fluffos_v1/lib/secure/obj/
nightmare4_fluffos_v1/lib/secure/obj/include/
nightmare4_fluffos_v1/lib/secure/save/
nightmare4_fluffos_v1/lib/secure/save/boards/
nightmare4_fluffos_v1/lib/secure/save/votes/
nightmare4_fluffos_v1/lib/spells/
nightmare4_fluffos_v1/lib/verbs/admins/include/
nightmare4_fluffos_v1/lib/verbs/common/
nightmare4_fluffos_v1/lib/verbs/common/include/
nightmare4_fluffos_v1/lib/verbs/creators/
nightmare4_fluffos_v1/lib/verbs/creators/include/
nightmare4_fluffos_v1/lib/verbs/players/include/SCCS/
nightmare4_fluffos_v1/lib/verbs/rooms/
nightmare4_fluffos_v1/lib/verbs/rooms/include/
nightmare4_fluffos_v1/lib/www/
nightmare4_fluffos_v1/old/
nightmare4_fluffos_v1/old/tools/
nightmare4_fluffos_v1/win32/
/*    /daemon/postal/options.c
 *    from Nightmare IV
 *    IIPS options management system
 *    created by Descartes of Borg 940502
 */

#include <lib.h>
#include <dirs.h>
#include <daemons.h>
#include <objects.h>
#include "options.h"

inherit LIB_DAEMON;

private mapping __MyGroups;
private mapping __Options;
static private string __Owner;

void create() {
    daemon::create();
    SetNoClean(1);
    __MyGroups = ([]);
    __Options = ([]);
    __Owner = 0;
}

static private int valid_access() {
    switch(base_name(previous_object(0))) {
        case OBJ_POST: case FOLDERS_D: case LETTERS_D:
        case LOCALPOST_D: case REMOTEPOST_D: case OPTIONS_D:
          return 1;
        default: return 0;
    }
}

void assure_box_exists(string who) {
    string tmp, file;

    if(!valid_access()) return;
    if(__Owner == who) return;
    file = DIR_POSTAL+"/"+who[0..0]+"/"+who+"/postalrc"+__SAVE_EXTENSION__;
    if(unguarded((: file_exists, file :))) return;
    file = DIR_POSTAL+"/"+who[0..0];
    if(unguarded((: file_size, file :)) != -2) unguarded((: mkdir, file :));
    file = DIR_POSTAL+"/"+who[0..0]+"/"+who;
    if(unguarded((: file_size, file :)) != -2) unguarded((: mkdir, file :));
    __MyGroups = ([]);
    __Options = ([]);
    __Owner = who;
    unguarded((: save_object, file+"/postalrc" :));
}

static private void load_options(string who) {
    string file;

    if(who == __Owner) return;
    this_object()->assure_box_exists(who);
    if(__Owner == who) {
        return;
      }
    __Owner = who;
    file = DIR_POSTAL+"/"+who[0..0]+"/"+who+"/postalrc";
    unguarded((: restore_object, file :));
  }

static private void save_options() {
    string file;

    file = DIR_POSTAL+"/"+__Owner[0..0]+"/"+__Owner+"/postalrc";
    unguarded((: save_object, file :));
}

void set_option(string who, string option, mixed value) {
    if(base_name(previous_object()) != OBJ_POST) return;
    load_options(who);
    __Options[option] = value;
    save_options();
}
                                                                             
mixed query_option(string who, string option) {
    string tmp;

    tmp = base_name(previous_object());
    if(tmp != OBJ_POST && tmp != LOCALPOST_D && tmp != FOLDERS_D) return 0;
    load_options(who);
    return __Options[option];
}

mapping query_options(string who) {
    string tmp;

    tmp = base_name(previous_object());
    if(tmp != OBJ_POST && tmp != LOCALPOST_D && tmp != FOLDERS_D) return ([]);
    load_options(who);
    return copy(__Options);
}

void set_group(string who, string group, string *members) {
    if(!valid_access()) return;
    load_options(who);
    if(!members) map_delete(__MyGroups, group);
    else __MyGroups[group] = members;
    save_options();
  }

string *query_group(string who, string group) {
    if(!valid_access()) return ({});
    load_options(who);
    return copy(__MyGroups[group]);
  }

mapping query_groups(string who) {
    if(!valid_access()) return ([]);
    load_options(who);
    return copy(__MyGroups);
  }