textdump
./ColdCore-3.0a6/textdump · 1.5 MB
From the archive ColdCore3.0a6.tar.gz
Download the archive « Back to the archive contents
object $root;
var $root manager = $root;
var $root trusted = [];
var $root child_index = 15;
var $root fertile = 1;
var $root inited = 0;
var $root quota = 75000;
var $root managed = 0;
var $root writers = [$root];
var $root created_on = 0;
var $root flags = ['methods, 'code, 'fertile, 'core, 'variables];
var $root quota_exempt = 0;
var $root writes = 0;
var $root trusted_by = 0;
var $root help_node = 0;
root method .init_root(): nooverride {
.change_manager(this());
flags = ['variables, 'methods, 'code];
created_on = time();
};
root method .uninit_root(): nooverride {
var obj;
(| manager.del_managed_obj() |);
catch any {
for obj in (.managed())
obj.change_manager($reaper);
}
catch any {
for obj in (.writers('literal))
.del_writer(obj);
}
catch any {
for obj in (.writes())
obj.del_writer(this());
}
catch any {
for obj in (.trusted('literal))
.del_trusted(obj);
}
catch any {
for obj in (.trusted_by())
obj.del_trusted(this());
}
// tell $sys we are going away
$sys.sender_going_away();
};
public method .initialize(): nooverride {
var ancestors, ancestor, pos, len;
if ((caller() != $sys) && (sender() != this()))
throw(~perm, "Caller is not $sys and sender is not this.");
if (inited)
throw(~perm, "Already initialized.");
ancestors = ancestors();
len = ancestors.length();
for pos in [0 .. len - 1] {
(> ._initialize_ancestor(ancestors[len - pos]) <);
// pause();
}
inited = 1;
};
public method .uninitialize(): nooverride {
var ancestor, errors, p;
(> .perms(caller(), $root, $sys) <);
errors = [];
for ancestor in (ancestors()) {
catch any
._uninitialize_ancestor(ancestor);
with
errors += [traceback()];
}
for p in (.variables())
.del_var(p);
return errors;
};
public method .perms(): nooverride {
arg what, [args];
var flag;
if (!args)
args = ['writer];
if (type(args[1]) == 'symbol) {
switch (args[1]) {
case 'system:
if (!($sys.is_system(what)))
throw(~perm, ("Permission Denied: " + what) + " is not of the system.", what);
case 'manager:
if (((.manager()) != what) && (!($sys.is_system(what))))
throw(~perm, ("Permission Denied: " + what) + " is not the manager.", what);
case 'trusts:
if (!(.trusts(what)))
throw(~perm, ("Permission Denied: " + what) + " is not a trustee.", what);
default:
if (!(.is_writable_by(what)))
throw(~perm, ("Permission Denied: " + what) + " is not a writer.", what);
}
} else if (type(what) == 'objnum) {
if (!(what in args))
throw(~perm, (what + " is not one of: ") + ((args.mmap('namef, 'ref)).to_english()), what);
}
};
root method ._change_parents(): nooverride {
arg parents;
var old_a, old_p, p, o, a, new_a;
if (!parents)
throw(~noparents, "Objects must have at least 1 parent");
// remember the old ancestors and parents
old_a = ancestors();
old_p = .parents();
// build the new ancestors list by hand, so we can uninit befor changing
new_a = [this(), @parents];
for p in (parents)
new_a = new_a.union(p.ancestors());
// uninit it
for a in (old_a.set_difference(new_a))
(| ._uninitialize_ancestor(a) |);
// do the change
(> chparents(parents) <);
// init new
for a in (ancestors().set_difference(old_a))
(| ._initialize_ancestor(a) |);
};
public method .chparents() {
arg [parents];
var parent, cur;
if (!(| .perms(sender(), 'manager) |))
(> .perms(caller(), $root, $sys) <);
if (!parents)
throw(~noparents, "There must be at least 1 parent for each object.");
// Notify new parents of impending change.
cur = parents();
for parent in (parents) {
if (!(parent in cur))
(> parent.will_inherit(sender()) <);
}
// Everything's okay, go ahead and try it.
._change_parents(parents);
};
public method .will_inherit(): nooverride {
arg who;
if (this() in (sender().parents()))
throw(~perm, ((sender() + " already has ") + this()) + " as a parent.");
if ((!(.has_flag('fertile, sender()))) && (!(.trusts(who))))
throw(~perm, ((this() + " refuses to be parent of ") + sender()) + ".");
};
public method .manager(): nooverride {
return manager || $reaper;
};
public method .writers(): nooverride {
arg [literal];
if (literal)
return writers || [];
// for speed, just add rather than setadd, use .compress() later if necessary
return (writers || []) + [.manager(), this()];
};
public method .trusted(): nooverride {
arg [literal];
if (literal)
return trusted || [];
return (trusted || []) + (.writers());
};
public method .is_writable_by(): nooverride {
arg obj;
return (| obj in (.writers()) |) || ($sys.is_system(obj));
};
public method .trusts(): nooverride {
arg obj;
return (| obj in (.trusted()) |) || ((obj == $scheduler) || ($sys.is_system(obj)));
};
public method .change_manager(): nooverride {
arg new;
var old;
if ((caller() != definer()) && (!($sys.is_system(sender()))))
throw(~perm, "You must have system priveleges to change the manager.");
if (type(new) != 'objnum)
throw(~invarg, "Managers must be given as a single dbref.");
old = .manager();
manager = new;
old.del_managed_obj();
new.add_managed_obj();
};
public method .add_writer(): nooverride {
arg obj;
(> .perms(sender(), 'manager) <);
writers = (writers || []).setadd(obj);
obj.add_writable_obj();
};
public method .del_writer(): nooverride {
arg obj;
(caller() == definer()) || (> .perms(sender(), 'manager) <);
writers = (writers || []).setremove(obj);
if (!writers)
(| clear_var('writers) |);
obj.del_writable_obj();
};
public method .add_trusted(): nooverride {
arg obj;
(caller() == definer()) || (> .perms(sender(), 'manager) <);
trusted = (trusted || []).setadd(obj);
obj.add_trusted_obj();
};
public method .del_trusted(): nooverride {
arg obj;
(> .perms(sender(), 'manager) <);
trusted = (trusted || []).setremove(obj);
if (!trusted)
clear_var('trusted);
obj.del_trusted_obj();
};
public method .as_this_run() {
arg obj, method, args;
if (caller() != $scheduler)
throw(~perm, "Sender not allowed to gain access to object perms.");
return (> obj.(method)(@args) <);
};
public method .add_parent() {
arg parent;
(> .perms(sender(), 'manager) <);
(> parent.will_inherit(sender()) <);
if (.has_ancestor(parent))
throw(~perm, ((sender() + " already has ") + this()) + " as an ancestor.");
._change_parents(parents() + [parent]);
};
public method .del_parent() {
arg parent;
var parents;
(> .perms(sender(), 'manager) <);
if (!valid(parent))
throw(~type, "Not a valid parent, must send a valid object.");
parents = .parents();
if (!(parent in parents))
throw(~parentnf, ((parent + " is not a parent of ") + this()) + ".");
parents = parents.setremove(parent);
(> ._change_parents(parents) <);
};
public method .spawn(): nooverride {
arg [suffix];
var obj, tmp, objname, mngr, na;
(> .will_spawn(sender()) <);
suffix = (> .get_obj_suffix(@suffix) <);
return $sys.spawn_sender(suffix, sender());
};
public method .destroy(): nooverride {
// This doesn't actually destroy us immediately, but we will go away when
// nothing is holding onto us any more.
(> .perms(sender(), 'manager) <);
if (.has_flag('core))
throw(~perm, "This object is a core object, and cannot be destroyed!");
(> .uninitialize() <);
destroy();
};
public method .add_var() {
arg name, [args];
var tmp, kid;
(> .perms(sender()) <);
if (!(tostr(name).valid_ident()))
throw(~invident, name + " is not a valid ident.");
(> add_var(name) <);
// The following code is a kludge as we can't send a default value to the
// primitive.
if (args) {
tmp = tosym((("__set_" + tostr(name)) + "_") + time());
catch any {
add_method([((tostr(name) + " = ") + toliteral(args[1])) + ";"], tmp);
.(tmp)();
if (((args.length()) > 1) && ((args[2]) == 'inherit)) {
for kid in (.descendants())
kid.(tmp)();
}
del_method(tmp);
} with {
del_method(tmp);
rethrow(error());
}
}
};
public method .variables(): nooverride {
return variables();
};
public method .del_var(): nooverride {
arg name;
var n, obj;
(caller() == definer()) || (> .perms(sender()) <);
// try and clear the variable on all of the descendants, before deleting
// the variable...
(> .clear_variable(name) <);
// now delete the variable
(> del_var(name) <);
};
public method .del_method() {
arg name;
(> .perms(sender()) <);
(> del_method(name) <);
};
public method .methods(): nooverride {
if (!(.has_flag('methods, sender())))
throw(~perm, (sender() + " doesn't have permission to find methods on ") + this());
return methods();
};
public method .parents(): nooverride {
return parents();
};
public method .children(): nooverride {
return children();
};
public method .ancestors(): nooverride {
return ancestors();
};
public method .find_method(): nooverride {
arg name;
if (!(.has_flag('methods, sender())))
throw(~perm, (sender() + " doesn't have permission to find methods on ") + this());
return (> find_method(name) <);
};
public method .find_next_method(): nooverride {
arg name, after;
if (!(.has_flag('methods, sender())))
throw(~perm, (sender() + " doesn't have permission to find methods on ") + this());
return (> find_next_method(name, after) <);
};
private method .corify_descendants_of(): nooverride {
arg obj;
var d, name, l;
name = (| tosym("core_" + (obj.objname())) |);
catch ~methodnf {
if ((> obj.find_method(name) <) != obj) {
dblog(((("** Coremethod for " + obj) + " in wrong place (on ") + (obj.find_method(name))) + ") **");
return;
}
} with {
return;
}
(| obj.(name)() |);
for d in (obj.descendants()) {
catch any {
(> d.(name)() <);
} with {
dblog(((("ERROR encountered in " + d) + ".") + name) + "():");
for l in ($parse_lib.traceback())
dblog(l);
}
refresh();
}
};
public method .add_method() {
arg code, name;
var l, m, line;
(> .perms(sender()) <);
(| $sys.touch() |);
// check for a few things only admins can do
if (!(sender().is($admin))) {
for l in [1 .. listlen(code)] {
line = code[l];
if ((m = line.match_regexp("[^a-z0-9_.]anticipate_assignment\("))) {
(> sender().tell($code_lib.point_to_line("ERROR: call to anticipate_assignment()", ((m[1])[1]) + 2, ((m[1])[2]) - 2, l, line)) <);
throw(~perm, "anticipate_assignment() may only be used by an administrator.");
}
}
}
return (> add_method(code, name) <);
};
public method .has_ancestor(): nooverride {
arg obj;
return (> has_ancestor(obj) <);
};
public method .eval(): nooverride {
arg code, [dest];
var errors, result, method;
dest = dest ? dest[1] : this();
if (!(sender() in [$scheduler, $root]))
(> .perms(sender()) <);
// Compile the code.
method = tosym("tmp_eval_" + tostr(time()));
errors = .add_method(code, method);
if (errors)
return ['errors, errors, 0, 0];
// Evaluate the expression. Be sure to remove it afterwards, so that no
// one else can call it.
catch any {
result = (> dest.(method)() <);
} with {
(| del_method(method) |);
rethrow(error());
}
(| del_method(method) |);
return ['result, result];
};
public method .method_info(): nooverride {
arg [args];
return (> method_info(@args) <);
};
public method .data(): nooverride {
arg [parent];
var par, data, out;
if (!(.has_flag('variables, sender())))
throw(~perm, ((sender().namef('ref)) + " is not allowed to read variables on ") + (.namef('ref)));
if (parent) {
if (type(parent[1]) != 'objnum)
throw(~type, (parent[1]) + " is not an object.");
return (> data(parent[1]) <);
} else {
data = (> data() <);
out = #[];
for par in (data) {
// if the parent doesn't exist anymore, just let them see the data.
if ((!valid(par[1])) || ((par[1]).has_flag('variables, sender())))
out = out.add(par[1], par[2]);
else
out = out.add(par[1], ["*** Permission Denied ***"]);
}
return out;
}
};
public method .size(): nooverride {
arg [args];
[(args ?= 'int)] = args;
switch (args) {
case 'string:
return tostr(size());
case 'english:
return size().to_english();
default:
return size();
}
};
public method .descendants(): nooverride {
var kids, i, c, child, d;
d = #[];
for child in (children())
d = dict_add(d, child, 1);
while ((| (c = dict_keys(d)[++i]) |)) {
for child in (c.children())
d = dict_add(d, child, 1);
pause();
}
return dict_keys(d);
};
public method .get_quota(): nooverride {
return quota;
};
public method .quota_valid(): nooverride {
if (quota_exempt)
return 1;
if (!(.is($user)))
return 0;
return (.quota_byte_usage()) < (.quota());
};
public method .match_children() {
arg string;
var children, child_names, c;
children = .children();
child_names = children.mmap('name);
// direct matches first.
for c in (child_names) {
if (c == string)
return children[c in child_names];
}
// ok, try partial matches
for c in (child_names) {
if ($string.match_begin(c, string))
return children[c in child_names];
}
return 0;
};
public method .del_flag(): nooverride {
arg flag;
(> .perms(sender(), 'manager) <);
// let them add any flag they want
flags = (flags || []).setremove(flag);
};
public method ._display_descendants() {
arg space, checked, levels, maxlev;
var c, anc, list, id, perms;
id = ((space + this()) + " ") + ($object_lib.see_perms(this()));
for anc in (dict_keys(checked)) {
if (.has_ancestor(anc))
return [];
// [id + " (above)"];
}
if (((.parents()).length()) > 1)
id += " (MI)";
list = [id];
space += " ";
levels++;
// check children
if ((!maxlev) || (maxlev != levels)) {
for c in (.children()) {
list += c._display_descendants(space, checked, levels, maxlev);
checked = dict_add(checked, c, 1);
pause();
}
}
return list;
};
public method ._get_method_info(): nooverride {
arg anc, method;
var code, lines, dis_flag, meth_args, flags, first_comment;
code = anc.list_method(method);
lines = code.length();
if (lines > 5)
code = code.subrange(1, 5);
flags = anc.method_flags(method);
if (code) {
meth_args = regexp(code[1], "arg ([^;]);");
if (meth_args) {
meth_args = meth_args[1];
code = code.delete(1);
} else {
meth_args = "";
}
if (code && ((!(code[1])) || (((code[1])[1]) == "v")))
code = code.delete(1);
if (code && ((!(code[1])) || (((code[1])[1]) == "v")))
code = code.delete(1);
first_comment = code ? (code[1]) + " " : " ";
first_comment = (((first_comment[1]) == "/") || ((first_comment[1]) == "r")) ? first_comment : "";
} else {
meth_args = "";
first_comment = "";
}
return [anc, method, meth_args, flags, lines, first_comment];
};
public method .namef() {
arg type;
return tostr(this());
// $# Edited 28 Oct 1995 21:06 Lynx ($lynx)
};
public method .match_descendants() {
arg string;
var match, child;
match = .match_children(string);
if (match)
return match;
for child in (.children()) {
match = child.match_descendants(string);
if (match)
return match;
}
return 0;
};
public method .debug() {
arg [stuff];
var x, line, mngr, meth;
meth = (| (stack()[2])[3] |);
if (meth)
line = ((("DEBUG " + sender()) + ".") + meth) + "(): ";
else
line = ("DEBUG " + sender()) + ": ";
for x in (stuff)
line = (line + " ") + toliteral(x);
(| (.manager()).tell(line) |);
};
public method .set_quota(): nooverride {
arg value;
(> .perms(caller(), $user, @$sys.system(), $root) <);
quota = value;
};
public method .name() {
arg [args];
return tostr(this());
};
public method .quota(): nooverride {
return quota;
};
public method .quota_byte_usage(): nooverride {
var total, obj;
for obj in (.managed()) {
if (!valid(obj))
continue;
total += obj.size();
}
return total;
};
public method .corify(): nooverride {
var d;
if (sender() != $sys)
throw(~sysonly, "This should only be called by $sys.make_core().");
// reverse engineer it--if coreify_<object> exists,
// call it on this object and all of its descendants.
for d in (.descendants()) {
.corify_descendants_of(d);
refresh();
}
};
root method ._initialize_ancestor(): nooverride {
arg ancestor;
var method;
if (!(method = (| tosym("init_" + tostr(ancestor.objname())) |)))
return;
catch ~methodnf {
if (find_method(method) != ancestor)
throw(~perm, ((("Initialization method for " + ancestor) + " in wrong place (") + find_method(method)) + ")");
.(method)();
}
};
root method ._uninitialize_ancestor(): nooverride {
arg ancestor;
var method, found;
if (!(method = tosym("uninit_" + tostr(ancestor.objname()))))
return;
catch ~methodnf {
if ((.find_method(method)) == ancestor) {
found = 1;
.(method)();
}
(| $root.clear_def_vars(ancestor) |);
if (!found)
throw(~perm, ((("UnInitialization method for " + ancestor) + " in wrong place (") + (.find_method(method))) + ")");
}
};
public method .objname(): nooverride {
return (> objname() <);
};
public method .set_objname() {
arg objname;
(> .perms(sender()) <);
// Make sure first argument is a symbol.
if (type(objname) != 'symbol)
throw(~type, "New objname is not a symbol.");
// Make sure everything is lowercase.
objname = tosym(tostr(objname).lowercase());
// Do nothing if objname isn't different.
if (objname == (| objname() |))
return;
return (> set_objname(objname) <);
};
public method .created_on(): nooverride {
return created_on;
};
public method .is_of(): nooverride {
arg obj;
return obj in ancestors();
};
public method .is(): nooverride {
arg [args];
if (!args)
throw(~invarg, "Must have one argument.");
if (type(args[1]) == 'dictionary)
return has_ancestor(args[2]);
return has_ancestor(args[1]);
};
public method .hname() {
arg [args];
return ((("<a href=\"/bin/display?" + this()) + "\">") + this()) + "</a>";
};
public method .add_flag(): nooverride {
arg flag;
(> .perms(sender(), 'manager) <);
if ((flag == 'core) && (!($sys.is_system(sender()))))
throw(~perm, "Only system objects can set the 'core flag.");
(flag == 'fertile) && (> .perms(sender(), 'manager) <);
// let them add any flag they want
flags = (flags || []).setadd(flag);
};
public method .build_name() {
arg [args];
var output, type, part, rval;
output = "";
for part in (args) {
type = type(part);
if (type == 'list)
output += (| .(part[1])(@part.subrange(2)) |) || "";
else if (type == 'string)
output += part;
}
return output;
};
public method .clear_variable(): nooverride {
arg name;
var n, obj;
(> .perms(sender()) <);
n = tosym("_clear_var_" + tostr(time()));
catch any {
.add_method([("clear_var(" + toliteral(name)) + ");"], n);
for obj in (.descendants()) {
(| obj.(n)() |);
pause();
}
(| del_method(n) |);
} with {
(| del_method(n) |);
}
};
public method .ancestors_to(): nooverride {
arg obj;
var a, out;
out = [this()];
for a in (.ancestors()) {
if (a.has_ancestor(obj))
out = out.setadd(a);
}
return out;
};
public method .descendants_to(): nooverride {
arg checked, levels, maxlev;
var c, list;
list = [this()];
levels++;
// check parents
if ((!maxlev) || (maxlev != levels)) {
for c in (.children()) {
list += [c.descendants_to(checked, levels, maxlev)];
checked = checked.setadd(c);
}
}
return list;
};
public method .ancestry(): nooverride {
arg gen;
var i, out;
out = [];
if (type(gen) == 'objnum) {
for i in (.ancestors()) {
if (i.has_ancestor(gen))
out += [i];
}
return out;
}
if (gen != 0) {
for i in (.parents())
out = out.union(i.ancestry(gen - 1));
}
return out;
};
public method .generations(): nooverride {
arg gen;
var p, out;
out = [this()];
if (gen != 0) {
for p in (.parents())
out = out.union(p.generations(gen - 1));
}
return out;
};
public method .variable_info() {
arg gen, def, fltr, match;
var ancs, data, pp, p;
if (!(.has_flag('variables, sender())))
throw(~perm, (sender() + " cannot read variables on ") + this());
if (def)
ancs = [def];
else
ancs = .(gen[1])(gen[2]) || [this()];
data = [];
for pp in ((data().to_list()).reverse()) {
if (valid(pp[1]) && ((pp[1]) in ancs)) {
for p in (pp[2]) {
if (tostr(p[1]).(match)(fltr) != 0)
data += [[pp[1], @p]];
}
}
}
return data;
};
public method .method_flags(): nooverride {
arg method;
if (!(.has_flag('methods, sender())))
throw(~perm, (sender() + " doesn't have permission to find methods on ") + this());
return (> method_flags(method) <);
};
public method .method_access(): nooverride {
arg method;
if (!(.has_flag('methods, sender())))
throw(~perm, (sender() + " doesn't have permission to find methods on ") + this());
return (> method_access(method) <);
};
public method .set_method_flags(): nooverride {
arg method, flags;
if (!(.is_writable_by(sender())))
throw(~perm, (sender() + " cannot write to ") + this());
if (('locked in flags) && (!($sys.is_system(sender()))))
throw(~perm, "Only administrators can set the locked method flag.");
return (> set_method_flags(method, flags) <);
};
public method .set_method_access(): nooverride {
arg method, state;
if (!(.is_writable_by(sender())))
throw(~perm, (sender() + " cannot write to ") + this());
return (> set_method_access(method, state) <);
};
public method .set_flags(): nooverride {
arg new_flags;
(> .perms(sender(), 'manager) <);
if (type(new_flags) != 'list)
throw(~invflags, "Flags must be submitted as a list of symbols.");
if ((!new_flags) && flags)
return clear_var('flags);
if (('core in new_flags) && (!($sys.is_system(sender()))))
throw(~perm, "Only system objects can set the 'core flag.");
('fertile in new_flags) && (> .perms(sender(), 'manager) <);
flags = new_flags;
};
public method .managed(): nooverride {
return managed || [];
};
root method .add_managed_obj(): nooverride {
managed = (managed || []).setadd(sender());
};
root method .del_managed_obj(): nooverride {
managed = (managed || []).setremove(sender());
if (!managed)
clear_var('managed);
};
public method .writes(): nooverride {
(> .perms(sender(), 'trusts) <);
return writes || [];
};
root method .add_writable_obj(): nooverride {
writes = (writes || []).setadd(sender());
};
root method .del_writable_obj(): nooverride {
writes = (writes || []).setremove(sender());
if (!writes)
clear_var('writes);
};
public method .trusted_by(): nooverride {
return trusted_by || [];
};
root method .add_trusted_obj(): nooverride {
trusted_by = (trusted_by || []).setadd(sender());
};
root method .del_trusted_obj(): nooverride {
trusted_by = (trusted_by || []).setremove(sender());
if (!trusted_by)
clear_var('trusted_by);
};
public method .has_flag(): nooverride {
arg flag, [sender];
[(sender ?= sender())] = sender;
if (flag == 'core)
return flag in (.flags());
return (flag in (.flags())) || (.trusts(sender));
};
public method .flags(): nooverride {
return flags || [];
};
public method .quota_exempt(): nooverride {
return quota_exempt;
};
public method .clean_root() {
var obj;
// Called by $sys.clean_database()
(> .perms(caller(), $sys) <);
(| ._clean_root('trusted, 'trusted_by) |);
(| ._clean_root('trusted_by, 'trusted) |);
(| ._clean_root('writers, 'writes) |);
(| ._clean_root('writes, 'writers) |);
if (!manager) {
manager = this();
.change_manager($reaper);
}
if (managed) {
managed = managed.valid_objects();
for obj in (managed) {
refresh();
if ((obj.manager()) != this())
managed = setremove(managed, obj);
}
if (!managed)
clear_var('managed);
}
};
public method .objnum(): nooverride {
return objnum();
};
root method .clear_def_vars(): nooverride {
arg definer;
var code, v, a, meth, errs;
code = [];
for v in (definer.variables())
code += [("clear_var(" + v) + ");"];
meth = tosym("_root_tmp_" + time());
if (!(definer.add_method(code, meth))) {
(| sender().(meth)() |);
(| definer.del_method(meth) |);
}
};
public method .list_methods() {
arg gen, def, fltr, match;
var ancs, a, m, i, methods;
if (!(.has_flag('methods, sender())))
throw(~perm, (sender() + " cannot view methods on ") + this());
if (def)
ancs = [def];
else
ancs = .(gen[1])(gen[2]) || [this()];
methods = #[];
for a in (ancs) {
for m in (a.methods()) {
if (tostr(m).(match)(fltr) != 0) {
i = a.method_info(m);
methods = methods.add_elem(i[5], [a, m, @i]);
}
}
}
return methods;
};
public method .method_bytecode() {
arg method;
return (> method_bytecode(method) <);
};
public method .rename_method() {
arg now, new;
(> .perms(sender()) <);
(| $sys.touch() |);
return (> rename_method(now, new) <);
};
public method .examine() {
return [];
};
public method .new_descendants() {
var kid, kids;
kids = #[];
for kid in (children()) {
kids = kids.add(kid, 1);
kids = kids.union(kid.new_descendants());
pause();
}
return kids.keys();
};
private method ._clean_root() {
arg v, m;
var obj, value;
if ((value = get_var(v))) {
value = value.valid_objects();
for obj in (value) {
if (!(this() in obj.(m)()))
value = value.setremove(obj);
refresh();
}
if (value)
set_var(v, value);
else
clear_var(v);
}
};
private method .set_quota_exempt(): nooverride {
arg bool;
if (bool)
quota_exempt = 1;
else
(| clear_var('quota_exempt) |);
};
public method .help_node() {
return help_node;
};
public method .set_hnode() {
arg node;
(> .perms(sender(), 'manager) <);
help_node = node;
};
public method .list_method() {
arg [args];
if (!(.has_flag('code, sender())))
throw(~perm, (("Method code on " + (.namef('ref))) + " is not readable by ") + (sender().namef('ref)));
return (> list_method(@args) <);
};
public method .new() {
arg [suffix];
var obj, tmp, objname, mngr, na;
// this difference between this and .spawn() is that you
// can override this method to return a frob instead.
(> .will_spawn(sender()) <);
suffix = (> .get_obj_suffix(@suffix) <);
return $sys.spawn_sender(suffix, sender());
};
public method .will_spawn(): nooverride {
arg who;
if (!(.has_flag('fertile, who)))
throw(~perm, "Not fertile or readable.");
// available quota?
if (!(who.quota_valid()))
throw(~quota, "Sender does not have the available quota");
};
public method .get_obj_suffix() {
arg [suffix];
var objname, tmp;
// Figure out the suffix from the arguments and child index.
[(suffix ?= 0)] = suffix;
if (suffix) {
// so they dont confuse child_index:
if (suffix.is_numeric())
throw(~perm, "You cannot specify a numeric suffix.");
// so we get correct symbols & it is always lowercase:
suffix = lowercase(strsed(suffix, "[^a-z0-9_]+", "", "g"));
} else {
// get the next valid objname
objname = tostr((| .objname() |) || "unknown");
tmp = tosym(objname);
while ((| lookup(tmp) |)) {
child_index++;
tmp = tosym((objname + "_") + tostr(child_index));
}
suffix = tostr(child_index);
}
return suffix;
};
object $sys: $root;
var $sys admins = [];
var $sys agents = [$root, $daemon];
var $sys startup = #[['time, 851214747], ['objects, [$login_daemon, $lag_watcher, $http_daemon, $smtp_daemon, $world]], ['heartbeat_interval, 5]];
var $sys starting = #[['quota, 75000], ['new_user_class, $admin], ['anonymous_user_class, $guest]];
var $sys server_address = ["129.123.4.76", "ice.cold.org"];
var $sys system_email_addresses = #[['default, "nobody@need.to.set.this.address"]];
var $sys core_version = "3.0a6";
var $sys validate_email_addresses = 1;
var $sys backup = #[['interval, 3600], ['last, 851213220], ['next, 851218347], ['started, 851213221]];
var $sys system = [$sys, $root];
var $sys touched = 851214764;
var $sys loggers = [$http_interface, $daemon, $user, $connection];
var $root created_on = 796268969;
var $root inited = 1;
var $root flags = ['methods, 'code, 'core, 'variables];
var $root quota_exempt = 1;
var $root manager = $sys;
var $sys bindings = #[['atomic, $sys], ['create, $sys], ['backup, $sys], ['shutdown, $sys], ['set_heartbeat, $sys], ['cancel, $scheduler], ['task_info, $scheduler], ['execute, $sys], ['bind_function, $sys], ['unbind_function, $sys], ['bind_port, $daemon], ['unbind_port, $daemon], ['open_connection, $connection], ['reassign_connection, $daemon], ['fopen, $file], ['fstat, $file], ['fchmod, $file], ['fmkdir, $file], ['frmdir, $file], ['files, $file], ['fremove, $file], ['frename, $file], ['fclose, $file], ['fseek, $file], ['feof, $file], ['fwrite, $file], ['fread, $file], ['fflush, $file], ['chparents, $root], ['destroy, $root], ['dblog, $sys], ['add_var, $root], ['del_var, $root], ['variables, $root], ['list_method, $root], ['add_method, $root], ['del_method, $root], ['method_bytecode, $root], ['methods, $root], ['rename_method, $root], ['set_method_access, $root], ['set_method_flags, $root], ['data, $root], ['del_objname, $root], ['set_objname, $root], ['suspend, $scheduler], ['resume, $scheduler], ['set_user, $user], ['config, $sys]];
var $sys blacklist = [];
var $root managed = [$sys];
var $root owned = [$sys];
public method .next_objnum(): native;
public method .version(): native;
driver method .startup() {
arg args;
var opt, str, obj, f;
if (args && ("-clean" in args)) {
catch any
(> .clean_database() <);
with
.log($parse_lib.traceback(traceback()));
shutdown();
return;
}
catch any {
// Bind functions for security
for f in (bindings) {
catch any
bind_function(@f);
with
dblog((("** Unable to bind function " + (f[1])) + "() to ") + (f[2]));
}
// Set up five-second heartbeat.
set_heartbeat(startup['heartbeat_interval]);
// set the startup time, reset backup time.
startup = startup.add('time, time());
backup = backup.add('next, time() + (backup['interval]));
// tell objects who should know, that we are up.
if (type(args) != 'list)
args = [];
for obj in (startup['objects]) {
.log(("Calling " + obj) + ".startup()");
catch any
(> obj.startup(@args) <);
with
.log($parse_lib.traceback(traceback()));
}
} with {
.log(("Startup ERROR at " + ctime()) + ":");
.log(toliteral(traceback()));
.log($parse_lib.traceback(traceback(), -1, ""));
}
};
public method .server_info() {
arg what, [long];
var tmp;
switch (what) {
case 'up_time:
return time() - (startup['time]);
case 'startup_time:
return startup['time];
case 'server_hostname:
return $network.hostname();
case 'server_ip:
return $network.ip();
case 'last_backup:
return backup['last];
case 'driver_version:
tmp = .version();
return (((((long ? "Cold Genesis " : "") + (tmp[1])) + ".") + (tmp[2])) + "p") + (tmp[3]);
case 'core_version:
return (long ? "ColdCore " : "") + core_version;
default:
throw(~unknown, "Unknown flag.");
}
};
public method .create_user() {
arg name, password, email, [type];
var user;
if ((!(| .perms(caller(), $login_interface) |)) && (!(| .perms(sender(), 'system) |)))
throw(~perm, "Caller and Sender are not allowed to call this method.");
[(type ?= 'new_user_class)] = type;
catch any {
user = (starting[type]).spawn(name);
user.set_name(name);
if (type == 'new_user_class)
user.set_password(password);
user.change_manager(user);
user.set_user_info($user_info, "email", email);
} with {
// Failed to initialize the child; destroy it.
if (!(| user.destroy() |)) {
(| user.uninitialize() |);
(| user.destroy() |);
}
rethrow(error());
}
return user;
};
public method .admins() {
return admins;
};
public method .is_admin() {
arg obj;
return (obj == $sys) || (obj in admins);
};
public method .shutdown() {
var opt, str, obj;
(> .perms(sender(), $sys) <);
// tell startup objects that we are closing shop
for obj in (startup['objects]) {
.log(("Calling " + obj) + ".shutdown()");
catch any
(> obj.shutdown() <);
with
.log($parse_lib.traceback(traceback()));
}
return shutdown();
};
public method .spawn_sender() {
arg suffix, manager;
var namestr;
(> .perms(caller(), $root, $sys) <);
namestr = (tostr(sender().objname()) + "_") + suffix;
return .create([sender()], tosym(namestr), manager);
};
public method .is_system() {
arg obj;
return obj in system;
};
public method .log() {
arg text;
var l;
if ((!sender()) in loggers) {
if ((!(| .perms(sender(), 'system) |)) && (!(| .perms(caller(), 'system) |)))
throw(~perm, "Only system objects can log.");
}
if (type(text) == 'list) {
for l in (text)
.log(l);
} else {
dblog((("[" + ($time.format("%d %h %y %H:%M"))) + "] ") + text);
}
};
driver method .heartbeat() {
if (sender() != 0)
throw(~perm, "Sender is not the server.");
(| $scheduler.pulse() |);
if (time() > (backup['next]))
.do_backup(this(), 'interval);
};
public method .do_backup() {
arg [args];
var line, who, how, name, dirty;
(> .perms(sender(), 'system) <);
dirty = .dirty();
[(who ?= sender()), (how ?= 'request)] = args;
if (!valid(who))
who = sender();
backup = backup.add('next, time() + (backup['interval]));
backup = backup.add('last, time());
if ((how == 'interval) && (!dirty))
return;
catch any {
name = who.namef('ref);
.log(("BACKUP (" + name) + ") ");
line = (("Backup started at " + ($time.format("%r"))) + " by ") + name;
$channel_ui._broadcast('System, line);
}
// double pause will hopefully let people know about it before it happens
pause();
pause();
backup = backup.add('started, time());
(> backup() <);
};
public method .set_startup() {
arg what, value;
var valid;
(> .perms(sender(), 'system) <);
valid = startup.keys();
if ((!what) in valid)
throw(~type, "Key must be one of " + toliteral(valid));
startup = startup.add(what, value);
};
public method .get_system_email() {
arg what;
var email;
// email directory for system services, such as arch admins.
email = (| system_email_addresses[what] |) || ((| system_email_addresses['default] |) || "<no email set>");
return email;
};
public method .new_admin() {
if (caller() != $admin)
throw(~perm, "Caller is not $admin.");
admins = setadd(admins, sender());
};
public method .agents() {
return agents;
};
public method .get_startup() {
arg what;
return startup[what];
};
public method .set_starting() {
arg what, value;
var valid;
(> .perms(sender(), 'system) <);
valid = starting.keys();
if ((!what) in valid)
throw(~type, "Key must be one of " + toliteral(valid));
starting = starting.add(what, value);
};
public method .execute() {
arg script, args, [background];
(> .perms(sender(), 'system) <);
(> execute(script, args, @background) <);
};
public method .get_starting() {
arg what;
return starting[what];
};
private method .create() {
arg parents, name, manager;
var new;
new = create(parents);
catch any {
new.set_objname(name);
new.initialize();
new.change_manager(manager);
} with {
// Failed to initialize the child; destroy it.
if (!(| new.destroy() |)) {
(| new.uninitialize() |);
(| new.destroy() |);
}
rethrow(error());
}
return new;
};
public method .system() {
return system;
};
public method .del_system_email() {
arg key;
(> .perms(sender(), 'manager) <);
system_email_addresses = system_email_addresses.del(key);
};
public method .add_system_email() {
arg key, email;
(> .perms(sender(), 'manager) <);
if (type(key) != 'symbol)
throw(~type, "Key is not a symbol.");
if (type(email) != 'string)
throw(~type, "Email address is not a string.");
system_email_addresses = system_email_addresses.add(key, email);
};
public method .add_method() {
arg code, name;
var line;
(> .perms(sender()) <);
line = ("SYSTEM: ." + tostr(name)) + "() MODIFIED";
line = (line + " by ") + (sender().namef('ref));
.log(line);
return (> pass(code, name) <);
};
public method .atomic() {
arg [args];
(> .perms(sender(), 'system) <);
return (> atomic(@args) <);
};
public method .add_to_blacklist() {
arg domain, duration;
(> .perms(sender(), 'system) <);
blacklist = blacklist.setadd(domain);
if (duration > 0)
$scheduler.add_task(duration, 'del_from_blacklist, domain);
};
public method .del_from_blacklist() {
arg domain;
(> .perms(sender(), 'system) <);
blacklist = blacklist.setremove(domain);
};
public method .validate_email_addresses() {
return validate_email_addresses;
};
public method .blacklist() {
return blacklist;
};
driver method .signal() {
arg signal;
var line;
// the driver will send the following signals:
// HUP -- driver will drop out of atomic mode and will flush i/o
// USR2 -- driver does nothing
// USR1 -- driver aborts all currently executing tasks, not suggested
// QUIT -- For both of these the driver will shutdown after current
// INT tasks finish their current execution frame. Note: do not
// preempt tasks at this point as they will not resume.
line = ("** Received Signal: " + signal) + " **";
(| $channel_ui._broadcast('System, line) |);
if (sig in ['QUIT, 'INT]) {
(| $channel_ui._broadcast('all, "******************************") |);
(| $channel_ui._broadcast('all, "** IMMINENT SERVER SHUTDOWN **") |);
(| $channel_ui._broadcast('all, "******************************") |);
}
};
root method .sender_going_away() {
admins = admins.setremove(sender());
agents = agents.setremove(sender());
system = system.setremove(sender());
};
public method ._status(): native;
bind_native .status() ._status();
public method .status() {
return (> ._status() <) + [backup['interval], backup['last], backup['next]];
};
private method ._loop_for_core() {
arg code;
var obj;
$root.add_method(code, '___coretmp);
for obj in ($root.descendants()) {
obj.___coretmp();
pause();
}
$root.del_method('___coretmp);
};
private method .initialize_core() {
var obj;
(| .clean_database() |);
// reset child indices
._loop_for_core(["child_index = 0;"]);
};
public method .clean_database() {
var obj, p, c, cmd;
(> .perms(caller()) <);
// cleanup some of $root's messiness
for obj in ($root.descendants()) {
(| obj.clean_root() |);
refresh();
}
// rehash all command caches
for obj in ($has_commands.descendants()) {
if ((| obj.is_command_cache() |))
(| obj.purge_caches() |);
refresh();
}
// incase people are logged in, give back their caches :)
// this does not update their local caches, that is only
// done when they login.
for obj in ((| $user_db.connected() |) || []) {
for p in ((| obj.parents() |) || [])
(| p.cache_init() |);
refresh();
}
// check user info (move'em home etc)
for obj in ($user.descendants()) {
if ((| (obj.home()) != (obj.location()) |))
(| obj.move_to(obj.home()) |);
refresh();
}
// validate all locations and location content's
for obj in ($physical.descendants()) {
(| obj.validate_contents() |);
if (obj.has_ancestor($located)) {
if ((!valid(obj.location())) || (!(obj in ((obj.location()).contents()))))
obj.move_to((| obj.home() |) || $lost_and_found);
}
refresh();
}
};
public method .blacklisted() {
arg remote;
var t;
for t in (blacklist) {
if (match_pattern(remote, t))
return 1;
}
return 0;
};
public method .add_to_system() {
arg obj;
if (!(.is_admin(sender())))
throw(~perm, "Sender is not an admin.");
if (!((obj in admins) || (obj in agents)))
throw(~perm, "Object is not an agent or admin.");
system = system.union([obj]);
};
public method .del_from_system() {
arg obj;
if (!(.is_admin(sender())))
throw(~perm, "Sender is not an admin.");
if (!((obj in admins) || (obj in agents)))
throw(~perm, "Object is not an agent or admin.");
system = system.setremove(obj);
};
public method .touch() {
touched = time();
};
public method .touched() {
return touched;
};
public method .backup() {
return backup;
};
public method .dirty() {
return touched > (backup['last]);
};
public method .do_shutdown() {
arg [args];
var why, time, increments, line, name, mins;
if ((!($sys.is_admin(sender()))) || (definer() != this()))
throw(~perm, "Sender is not an admin.");
[(time ?= 0), (why ?= "")] = args;
increments = [600, 300, 180, 60];
while (increments && (time < (increments[1])))
increments = increments.delete(1);
name = sender().namef('xref);
.log(("*** SHUTDOWN called by " + name) + " ***");
if (why) {
why = ("*** " + why) + " ***";
.log(why);
}
while (1) {
if (!increments) {
$channel_ui._broadcast('all, "*** SYSTEM SHUTDOWN ***");
break;
}
line = "*** SYSTEM SHUTDOWN IN ";
mins = (increments[1]) / 60;
line = ((line + tostr(mins)) + " MINUTE") + ((mins == 1) ? "" : "S");
line = ((line + " CALLED BY ") + name) + " ***";
$channel_ui._broadcast('all, line);
if (why)
$channel_ui._broadcast('all, why);
$scheduler.sleep(increments[1]);
increments = increments.delete(1);
}
return .shutdown();
};
public method .loggers() {
return loggers;
};
root method .core_sys(): nooverride {
starting = dict_add(starting, 'new_user_class, $admin);
system_email_addresses = #[['default, "nobody@need.to.set.this.address"]];
};
driver method .backup_done() {
catch any {
$channel_ui._broadcast('System, "Backup completed, executing filesystem cleanup...");
pause();
pause();
.execute("backup", []);
}
catch any
$channel_ui._broadcast('System, "Backup completed, elapsed time " + ($time.elapsed(time() - (backup['started]), 'long)));
backup = backup.del('started);
};
private method .make_core() {
arg ver;
var obj, d, o, top, x, admin, tmp, name;
// core rooms should be +core, and cant be destroyed
// traverse the list inverseley, less unseen heirarchial shuffling
d = $root.descendants();
top = listlen(d);
core_version = ver;
dblog(("** " + top) + " objects, destroying all non-core objects...");
catch any {
for x in [1 .. top] {
obj = d[(top - x) + 1];
(| obj.destroy() |);
if (valid(obj)) {
obj.change_manager(obj);
for o in (obj.writers('literal)) {
obj.del_writer(o);
refresh();
}
}
refresh();
}
// shutdown this task so that references can have
// a chance to clear out, on destroyed objects.
dblog("** done, suspending for new task **");
// do this the hard way, to be secure
.add_var('TMP_HEARTBEAT_CODE, .list_method('heartbeat));
.add_method([".finish_core();"], 'heartbeat);
} with {
dblog("traceback: " + traceback());
}
};
public method .task_info() {
arg [args];
(> .perms(sender(), 'system) <);
return (> task_info(@args) <);
};
public method .destroy_sender() {
// potential problem spot, but sometimes its needed
// add core definer items to the list, if you want them to call it
(> .perms(caller(), $exit, $connection, $connection_interface) <);
(> sender().destroy() <);
};
private method .finish_core() {
// cleanup heartbeat
.add_method(TMP_HEARTBEAT_CODE, 'heartbeat);
.del_var('TMP_HEARTBEAT_CODE);
// ok, finish up
catch any {
dblog("** corifying remaining objects");
$root.corify();
dblog("** cleaning database..");
.clean_database();
dblog("** shutting down..");
shutdown();
} with {
dblog("traceback: " + traceback());
}
};
public method .old_admin() {
if (caller() != $admin)
throw(~perm, "Caller is not $admin.");
admins = setremove(admins, sender());
system = setremove(system, sender());
};
new object $foundation: $root;
var $root child_index = 7;
var $root fertile = 1;
var $root trusted = [];
var $root inited = 1;
var $root created_on = 796268969;
var $root flags = ['methods, 'code, 'fertile, 'core, 'variables];
var $root manager = $foundation;
var $root managed = [$foundation];
var $root owned = [$foundation];
var $foundation edit_types = 0;
public method .configure() {
arg set;
// This is for post-creation configuration of a VR object. It is used
// to interactively configure the VR aspects and behaviour of an object.
// It should be optional, any command hooking into confingure should check
// for a -conf?igure option first (which would imply skipping configuration).
//
// Overriding methods should pass() first, giving priority to their
// ancestors. The argument 'set' is a dictionary with symbol keys
// defining what has been set. Use the definer's name + "_" + setting
// as the name of the key ("name" on $has_name would be 'has_name_name).
// If something is already in the set dictionary, do not re-set it
// again (for instance, if the command hooking into configure accepted
// the name of the object on it's command line it would put
// 'has_name_name in the dictionary and $has_name.configure() would not
// prompt for the name).
//
// "@skip" should always skip the setting, and not alter it.
// if .prompt() returns 'aborted, throw ~abort.
//
(> .perms(sender()) <);
return set;
};
public method .environment() {
return [];
};
public method .match_environment() {
arg str;
var obj, env, found, match, target;
if (!str)
throw(~objnf, "No object specified.", str);
str = str.strip_article();
// Handle special cases.
if (str in ["me", "my"])
return this();
else if (((str[1]) == "$") || ((str[1]) == "#"))
return (> $object_lib.to_dbref(str) <);
else if (str in ["it", "him", "her"])
return (| .match_context(str) |) || throw(~context, ("I don't see " + str) + " here, do you?");
// Start matching
found = [];
env = .environment();
// special case ordinal references
if ((match = $parse_lib.ordinal_reference(str)))
return env.match_nth(@match);
if ((match = $parse_lib.possessive_reference(str))) {
if ((match[1]) == "me")
obj = this();
else
obj = (> env.match_object(match[1]) <);
catch ~objnf, ~ambig {
env = (| obj.contents() |) || [];
if ((found = $parse_lib.ordinal_reference(match[2])))
return (> env.match_nth(@found) <);
else
return (> env.match_object(match[2]) <);
} with {
if (error() == ~objnf)
throw(~objnf, (((obj.name()) + " does not have ") + ((match[2]).add_indefinite())) + ".");
throw(~ambig, ((("\"" + str) + "\" can match ") + ((((traceback()[1])[3]).mmap('namef, 'ref)).to_english("", " or "))) + ".");
}
} else {
catch ~objnf, ~ambig {
return (> env.match_object(str) <);
} with {
if (error() == ~objnf)
throw(~objnf, ("You do not see " + (str.add_indefinite())) + " anywhere.");
throw(~ambig, ((("\"" + str) + "\" can match ") + ((((traceback()[1])[3]).mmap('namef, 'ref)).to_english("", " or "))) + ".");
}
}
};
public method .local_to_environment() {
arg obj;
return obj in (.environment());
};
public method .get_edit_types() {
return edit_types || [];
};
public method .set_edit_types(): nooverride {
arg t;
(> .perms(sender()) <);
if (t)
edit_types = t;
};
public method .all_edit_types(): nooverride {
var i, l, t;
l = [];
for i in (.ancestors()) {
if (type((| (t = i.get_edit_types()) |)) == 'list)
l = l.union(i.get_edit_types());
}
return l;
};
new object $has_settings: $foundation;
var $root child_index = 2;
var $root fertile = 1;
var $root manager = $has_settings;
var $root inited = 1;
var $root flags = ['methods, 'code, 'fertile, 'core, 'variables];
var $root created_on = 796268969;
var $has_settings settings = #[];
var $has_settings defined_settings = #[];
var $has_settings local_settings = [];
var $root managed = [$has_settings];
var $root owned = [$has_settings];
root method .uninit_has_settings() {
settings = 0;
defined_settings = 0;
local_settings = 0;
};
public method ._find_definers() {
arg name, count, [begin];
var a, matches;
// Find a definer for <name>
// <count> is a number
// 1 finds the first possible definer
// 0 finds all
// If <begin> is given cound a match_begin as a match
matches = [];
for a in (ancestors()) {
if (a.has_ancestor($has_settings)) {
if (a.defines_setting(name, begin)) {
switch (count) {
case 0:
matches += [a];
case 1:
return matches + [a];
default:
matches += [a];
count = count - 1;
}
}
}
}
return matches;
};
public method .set_setting() {
arg definer, name, value;
var options;
(> .perms(sender(), 'writers) <);
if (type(name) != 'string)
throw(~type, "name must be a string");
if (!definer)
definer = ._find_setting_definer(name);
options = definer.configure_setting(name);
value = (> .((| options['check] |) || 'is_any)(definer, value, @(| options['check_args] |) || []) <);
(> .((| options['set] |) || 'set_local_setting)(definer, name, value, sender(), @(| options['set_args] |) || []) <);
if (!local_settings)
local_settings = [];
local_settings = local_settings.union([name]);
};
public method .add_setting() {
arg name, [options];
(> .perms(sender(), 'writers) <);
if (type(name) != 'string)
throw(~type, "name must be a string");
[(options ?= #[])] = options;
if (!defined_settings)
defined_settings = #[];
if (defined_settings.contains(name))
throw(~error, (this() + " already has a setting named ") + name);
defined_settings = defined_settings.add(name, ._default_options());
.configure_setting(name, options);
};
public method .defines_setting() {
arg name;
if (name in (defined_settings.keys()))
return 1;
return 0;
};
public method .del_setting() {
arg name;
var k, m;
(> .perms(sender(), 'writers) <);
if (!(name in (defined_settings.keys())))
throw(~namenf, (name + " not defined on ") + this());
m = (defined_settings[name])['del];
defined_settings = defined_settings.del(name);
for k in (.children())
(| k.m(this(), name) |);
};
public method .is_boolean() {
arg definer, value, [args];
if ((!value) || (value in ["y", "yes", "true", "t", "1", "on"]))
return 1;
return 0;
};
public method .get_inherited_setting() {
arg name, definer, [args];
var sets, a;
for a in (.ancestors()) {
if ((a.has_ancestor(definer)) && (a.local_settings(definer)))
return a.get_local_setting(definer, name);
}
return 0;
};
public method .get_indirect_setting() {
arg name, definer, args;
var fname, val;
fname = ._to_fullname(name, definer);
if (fname in (setting_data.keys())) {
val = setting_data[fname];
if (type(val) == 'objnum)
return (> (setting_data[fname]).get_setting(spec, definer, args) <);
else
return setting_data[fname];
} else {
return (definer.setting_data())[fname];
}
};
public method .setting() {
arg name, [definer];
var sets, options;
[(definer ?= 0)] = definer;
if (type(name) != 'string)
throw(~type, "name must be a string");
if ((type(definer) != 'objnum) && (definer != 0))
throw(~type, "definer must be zero or a dbref");
if ((!name) && (!definer))
throw(~huh, "definer must be non-zero or name must be given");
if (!definer) {
definer = ._find_setting_definer(name);
if (!definer)
throw(~definernf, "No definer could be found for " + name);
} else if (!name) {
sets = #[];
for name in (definer.defined_settings()) {
options = definer.configure_setting(name);
sets = sets.add(name, .((| options['get] |) || 'get_local_method)(name, definer, @(| options['get_args] |) || []));
}
return sets;
}
options = definer.configure_setting(name);
catch ~keynf
(> .(options['access_check])(name, sender()) <);
return (> .((| options['get] |) || 'get_local_setting)(name, definer, @(| options['get_args] |) || []) <);
};
public method .default_setting_info() {
return #[['type, "string"], ['check, 'is_anything], ['get, 'get_direct_setting], ['set, 'set_direct_setting], ['del, 'del_direct_setting], ['set_args, ['name, 'definer, 'value, 'style]], ['get_args, ['name, 'definer]]];
};
public method ._find_setting_definer() {
arg name;
var a;
for a in (.ancestors()) {
if ((a.has_ancestor(definer())) && (name in (a.defined_settings())))
return a;
}
throw(~definernf, ((("Unable to find setting " + toliteral(name)) + " on ") + (.name())) + ".");
};
public method ._default_options() {
return #[['get, 'get_local_setting], ['set, 'set_local_setting], ['check, 'is_any], ['del, 'delete_local_setting], ['check_args, []], ['get_args, []], ['set_args, []]];
};
public method .configure_setting() {
arg name, [options];
var o, new;
if (type(name) != 'string)
throw(~type, "name must be a string.");
if (options) {
options = options[1];
if (type(options) != 'dictionary)
throw(~type, "options must be a dictionary.");
} else {
options = #[];
}
if (!dict_contains(defined_settings, name))
throw(~namenf, (("Setting " + name) + " is not defined on ") + this());
if (!options)
return defined_settings[name];
// Iterate through the options and make changes.
(> .perms(sender(), 'writers) <);
new = defined_settings[name];
for o in (options.keys())
new = new.add(o, options[o]);
defined_settings = defined_settings.add(name, new);
};
public method .defined_settings() {
return (| defined_settings.keys() |) || [];
};
public method .delete_local_setting() {
arg definer, name;
var sets;
(> .perms(sender(), this()) <);
sets = (| defined_settings[definer] |) || #[];
sets = (| sets.del(name) |) || sets;
defined_settings = sets;
};
public method .is_any() {
arg definer, value, [args];
return value;
};
protected method .set_local_setting() {
arg definer, name, value, [args];
var sets;
if (!settings)
settings = #[];
sets = (| settings[definer] |) || #[];
sets = sets.add(name, value);
settings = settings.add(definer, sets);
};
public method .get_local_setting(): nooverride {
arg name, definer, [args];
return (| (settings[definer])[name] |) || throw(~setting, ("Setting \"" + name) + "\" has not been defined.");
};
root method .init_has_settings() {
defined_settings = #[];
local_settings = #[];
settings = #[];
};
public method .settings() {
var a, out, s;
//returns all settings available on this object
out = #[];
for a in (.ancestors()) {
if (a == definer())
break;
s = (| a.defined_settings() |) || [];
if (s)
out = out.add(a, s);
}
return out;
};
public method .is_list_of() {
arg definer, value, type;
var out, element;
switch (type(value)) {
case 'string:
if (((value[1]) != "[") || ((value.last()) != "]"))
throw(~type, "value is not parsable as a list.");
value = (value.subrange(2, (value.length()) - 2)).explode(",");
.debug(value);
out = [];
for element in (value)
out += [.is_type(definer, element.strip(" "), type)];
return out;
case 'list:
out = [];
for element in (value)
out += [.is_type(definer, element, type)];
return out;
default:
throw(~type, "value is not parsable as list.");
}
};
public method .is_type() {
arg definer, value, type;
if (type(value) == type)
return value;
switch (type) {
case 'string:
return toliteral(value);
case 'integer:
if (value.is_numeric())
return toint(value);
else
throw(~type, "Value is unparseable as integer.");
case 'objnum:
return $object_lib.to_dbref(value);
default:
return value;
}
};
public method .local_setting() {
arg [definer];
[(definer ?= 0)] = definer;
if (definer)
return (| local_settings[definer] |) || [];
return local_settings;
};
public method .local_settings() {
arg [definer];
[(definer ?= 0)] = definer;
if (definer)
return (| local_settings[definer] |) || [];
return local_settings;
};
public method .display_setting() {
arg name, [definer];
var sets, options, s;
(> .perms(sender(), 'trusts) <);
[(definer ?= 0)] = definer;
if (type(name) != 'string)
throw(~type, "name must be a string");
if ((type(definer) != 'objnum) && (definer != 0))
throw(~type, "definer must be zero or a dbref");
if ((!name) && (!definer))
throw(~huh, "definer must be non-zero or name must be given");
if (!definer) {
definer = ._find_setting_definer(name);
if (!definer)
throw(~definernf, "No definer could be found for " + name);
} else if (!name) {
sets = #[];
for name in (definer.defined_settings()) {
options = definer.configure_setting(name);
catch ~keynf
.(options['access_check])(sender());
s = .((| options['get] |) || 'get_local_method)(name, definer, @(| options['get_args] |) || []);
sets = sets.add(name, (| .(options['display])(s) |) || s);
}
return sets;
}
options = definer.configure_setting(name);
s = (> .((| options['get] |) || 'get_local_setting)(name, definer, @(| options['get_args] |) || []) <);
catch any {
return (> .(options['display])(s) <);
} with {
if (type(s) == 'objnum)
return s.namef('ref);
else
return toliteral(s);
}
};
public method .display_boolean_yes_no() {
arg value;
if (value)
return "yes";
else
return "no";
};
public method .display_boolean_on_off() {
arg value;
if (value)
return "on";
else
return "off";
};
public method .get_local_setting_boolean() {
arg name, definer, [args];
return (| (settings[definer])[name] |) || 0;
};
public method .get_defined_settings() {
return defined_settings;
};
new object $has_name: $has_settings;
var $root child_index = 11;
var $root fertile = 1;
var $root inited = 1;
var $root created_on = 796268969;
var $root flags = ['methods, 'code, 'fertile, 'core, 'variables];
var $has_name name = ['normal, "named object", "a named object"];
var $has_settings defined_settings = #[];
var $has_settings local_settings = #[];
var $has_settings settings = #[];
var $root manager = $has_name;
var $has_name templates = 0;
var $root owned = [$has_name];
var $root managed = [$has_name];
public method .set_name() {
arg new_name, [args];
var type;
(> .perms(sender()) <);
if (new_name && ((new_name[1]) in ["$", "#"]))
throw(~invname, "Names cannot begin with \"$\" or \"#\".");
if (type(new_name) != 'string)
throw(~type, "New name must be given as a string.");
// this will not catch them all, but we can try.
if (new_name.match_regexp("^(a|an|the) +"))
throw(~bad_name, "Do not include articles in name, use +u +n or +pinstead.");
[(type ?= 'normal)] = args;
if (!(type in ['prop, 'normal, 'uniq]))
throw(~invarg, "Type must be one of: 'prop, 'normal or 'uniq");
switch (type) {
case 'prop:
new_name = [new_name, new_name];
case 'uniq:
new_name = [new_name, "the " + new_name];
case 'normal:
new_name = [new_name, new_name.add_indefinite()];
}
name = [type, @new_name];
};
public method .match_name() {
arg str;
var m, t;
if ((m = match_begin(name[2], str)))
return m;
for t in (templates || []) {
if ((m = match_template(str, t)))
return m;
}
return 0;
};
public method .name() {
arg [args];
if (!name)
return tostr(this());
if (!args)
return name[3];
switch (args[1]) {
case 'type:
return name[1];
case 'noarticle:
return name[2];
default:
return name;
}
};
public method .name_templates() {
return templates || [];
};
public method .namef() {
arg type;
switch (type) {
case 'ref:
return (((.name()) + " (") + this()) + ")";
case 'xref:
return ((this() + " (") + (.name())) + ")";
case 'name:
return .name();
default:
return (> pass(type) <);
}
// $# Edited 28 Oct 1995 21:06 Lynx ($lynx)
};
public method .hname() {
arg [args];
return ((("<a href=\"/bin/describe?target=" + (.objname())) + "\">") + (.name())) + "</a>";
};
public method .add_name_template() {
arg template;
(> .perms(sender()) <);
templates = setadd(templates || [], template);
};
public method .del_name_template() {
arg template;
(> .perms(sender()) <);
templates = setremove(templates || [], template);
if (!templates)
(| clear_var('templates) |);
};
public method .init_has_name() {
var objname;
objname = tostr(.objname());
name = ['prop, tostr(objname), tostr(objname)];
};
new object $has_commands: $foundation;
var $root fertile = 1;
var $root inited = 1;
var $root created_on = 796268969;
var $root flags = ['methods, 'code, 'fertile, 'core, 'variables];
var $root child_index = 4;
var $has_commands shortcuts = #[];
var $has_commands local = 0;
var $has_commands remote = 0;
var $root manager = $has_commands;
var $root managed = [$has_commands];
var $root owned = [$has_commands];
public method .add_command() {
arg template, method, [type];
var cmd, types, count, x;
(> .perms(sender()) <);
[(type ?= 'local)] = type;
if ("*" in template)
throw(~invcmd, "Invalid command, command templates cannot contain \"*\"!.");
cmd = (> $command_lib.validate_command_template(template) <);
if (!(type in ['local, 'remote]))
throw(~type, "Command types can be either 'local or 'remote");
if ('this in (((cmd[2]).values()).slice(1)))
type = 'remote;
if (type == 'remote) {
for x in (((cmd[2]).values()).slice(1)) {
if (x == 'this)
count++;
}
if (!count)
throw(~add_command, "Command type defined as remote with no <this> argument.");
else if (count > 1)
throw(~add_command, "More than one <this> argument specified in template.");
}
if (!get_var(type))
set_var(type, #[]);
set_var(type, get_var(type).setadd_elem((cmd[1])[1], [@cmd[1], template, method, cmd[2]]));
};
public method .all_local_commands() {
var cmds, a, acmds;
cmds = #[];
for a in (ancestors()) {
if (a == definer())
break;
if ((acmds = (| a.local_commands() |)))
cmds = cmds.add(a, acmds);
}
return cmds;
};
public method .local_commands() {
return local || #[];
};
public method .get_command_info() {
arg type, cmd;
var info, a, ainfo;
info = [];
for a in (ancestors()) {
if (a == definer())
break;
if ((ainfo = (| a.command_info(type, cmd) |)))
info = info.union(ainfo);
}
return info;
};
public method .del_command() {
arg template, method;
var cmd, c, d, info, type;
(> .perms(sender()) <);
cmd = template.explode();
if (!cmd)
throw(~type, "Invalid template.");
cmd = cmd[1];
info = #[['local, .get_command_info('local, cmd)]];
info = info.add('remote, .get_command_info('remote, cmd));
for type in (info) {
for c in (type[2]) {
if (((c[3]) == template) && ((c[4]) == method)) {
set_var(type[1], get_var(type[1]).del_elem(cmd, c));
d++;
}
}
}
return d;
};
public method .remote_commands() {
return remote || #[];
};
root method .init_has_commands() {
local = (remote = (shortcuts = #[]));
};
root method .uninit_has_commands() {
.clear_variables(@.variables());
};
public method .add_shortcut() {
arg shortcut, template, method;
var relation;
(> .perms(sender()) <);
if ((type(shortcut) != 'string) || (type(template) != 'string))
throw(~type, "Both shortcut and template must be strings.");
if (type(method) != 'symbol)
throw(~type, "Method must be submitted as a symbol.");
relation = (> $command_lib.parse_relation(shortcut, template) <);
shortcut = (relation[1])[1];
relation = (relation[2])[2];
if (!shortcuts)
shortcuts = #[];
shortcuts = shortcuts.add(shortcut, [method, relation]);
};
public method .del_shortcut() {
arg shortcut;
var value;
(> .perms(sender()) <);
value = (| shortcuts.del(shortcut) |);
if (type(value) != 'dictionary)
throw(~shortcutnf, ("Shortcut \"" + shortcut) + "\" is not defined on this object.");
shortcuts = value;
};
public method .all_shortcuts() {
var s, a, as;
s = [];
for a in (ancestors()) {
if (a == definer())
break;
if ((as = (| a.shortcuts() |)))
s += as.to_list();
}
return s;
};
public method .get_shortcut_info() {
arg shortcut;
return (| shortcuts[shortcut] |) || throw(~shortcutnf, ("Shortcut \"" + shortcut) + "\" is not defined on this object.", shortcut);
};
public method .shortcuts() {
return shortcuts || #[];
};
public method .command_info() {
arg type, cmd;
return (| get_var(type)[cmd] |) || throw(~cmdnf, ("Command \"" + cmd) + "\" is not defined on this object.", cmd);
};
public method .all_remote_commands() {
var cmds, a, acmds;
cmds = #[];
for a in (ancestors()) {
if (a == definer())
break;
if ((acmds = (| a.remote_commands() |)))
cmds = cmds.add(a, acmds);
}
return cmds;
};
new object $described: $has_name, $has_commands;
var $described prose = [];
var $root inited = 1;
var $root created_on = 796268969;
var $root flags = ['methods, 'code, 'variables, 'core];
var $has_name name = ['uniq, "Generic Described Object", "the Generic Described Object"];
var $has_commands shortcuts = #[];
var $has_commands remote = #[];
var $root manager = $described;
var $root owned = [$described];
var $foundation edit_types = ["prose"];
var $root managed = [$described];
root method .init_described() {
prose = [];
};
protected method .description() {
arg flags;
var out, name;
out = (<$ctext_frob, [[(<$format, ["subj", [], [.name()], 'do_subj]>)], #[]]>);
if ((| flags['prose] |))
return [out, .prose()];
return [out];
};
public method .prose() {
arg [no_default];
return prose || (no_default ? 0 : "You see nothing special");
};
public method .set_prose() {
arg new;
(> .perms(sender()) <);
switch (type(new)) {
case 'string, 'list:
new = (> $compiler.compile_cml(new) <);
case 'frob:
// we'll let this pass by unharmed
default:
throw(~invalid, "Prose can be submitted as CML or Ctext");
}
prose = new;
};
root method .uninit_described() {
prose = 0;
};
public method .get_description(): nooverride {
arg [dflags];
var flags, f;
flags = #[['prose, 1], ['actor, sender()]];
if (dflags && (type(dflags[1]) == 'dictionary)) {
dflags = dflags[1];
for f in (dflags.keys())
flags = dict_add(flags, f, dflags[f]);
}
return .description(flags);
};
public method .edit_prose() {
var p;
(> .perms(sender()) <);
p = .prose();
if (type(p) == 'frob)
p = p.uncompile();
(> sender().invoke_editor(this(), '_edit_prose_callback, p, []) <);
};
public method ._edit_prose_callback() {
arg text, client_data;
(> .perms(sender()) <);
.set_prose(text);
return "Description set.";
};
public method .configure() {
arg set;
var p, end, ctext, s, still, type;
set = (> pass(set) <);
s = sender();
still = ("Do you still want to describe " + (.name())) + "? [no] ";
if (!(set.contains('described_prose))) {
while (!end) {
if (.is($exit))
type = "exit ";
else if (.is($place))
type = "place ";
else
type = "";
p = s.read((("Describe " + type) + (.name())) + ", Enter \".\" to finish or \"@abort\" to abort description.");
if (p == 'aborted) {
end = !(s.prompt_yesno(still, 0));
} else {
catch any {
ctext = (> $compiler.compile_cml(p) <);
s.tell(["You submitted the following description:", ""]);
s.tell(ctext);
s.tell("");
if (!(end = s.prompt_yesno("Keep this description? [yes] ")))
ctext = 0;
} with {
s.tell(["The following CML compiler error occurred:", " ", (traceback()[1])[2]]);
end = !(s.prompt_yesno(still, 0));
}
}
}
if (ctext)
.set_prose(ctext);
set = set.add('described_prose, 1);
}
return set;
};
public method .get_detail() {
arg name;
var details, d, matches;
details = (| (.prose()).get_var('details) |);
if (!details)
throw(~nodetail, ("No \"" + name) + "\" in your environment.");
matches = [];
for d in (details.keys()) {
if (match_begin(d, name))
matches += [d];
}
if (!matches)
throw(~nodetail, ("No \"" + name) + "\" in your environment.");
if (listlen(matches) != 1)
throw(~ambig, (("\"" + name) + "\" can match ") + (matches.to_english()));
return (<$ctext_frob, [details[matches[1]], #[['this, this()]]]>);
};
new object $has_gender: $has_name;
var $root inited = 1;
var $root created_on = 796268969;
var $root flags = ['methods, 'code, 'variables, 'core];
var $has_gender gender = 0;
var $has_name name = ['uniq, "The Generic Gendered Object", "the The Generic Gendered Object"];
var $has_settings defined_settings = #[["gender", #[['get, 'gender], ['set, 'set_gender], ['check, 'check_gender], ['del, 'delete_local_setting], ['check_args, []], ['get_args, []], ['set_args, []]]]];
var $root manager = $has_gender;
var $root managed = [$has_gender];
var $root owned = [$has_gender];
public method .gender_context() {
return gender.pronoun('po);
};
root method .init_has_gender() {
gender = $gender_neuter;
};
public method .set_gender() {
arg definer, name, value, [args];
(sender() != this()) && (> .perms(sender(), 'manager) <);
gender = value;
};
public method .gender() {
arg [args];
return gender;
};
new object $has_messages: $foundation;
var $root fertile = 1;
var $root manager = $has_messages;
var $root inited = 1;
var $root created_on = 796268969;
var $root flags = ['methods, 'code, 'fertile, 'core, 'variables];
var $has_messages messages = 0;
var $has_messages message_info = 0;
var $root managed = [$has_messages];
var $root owned = [$has_messages];
var $foundation edit_types = ["messages"];
public method .add_message() {
arg name;
(> .perms(sender(), 'writer) <);
if (type(name) != 'string)
throw(~type, "Name must be a string");
if (!messages)
messages = #[];
if (!message_info)
message_info = #[];
message_info = message_info.add(name, #[]);
};
public method .message_info() {
arg name, field;
var m;
((| (m = message_info[name]) |) != ~keynf) || throw(~messagenf, ("Message " + name) + " is not defined here.");
switch (field) {
case 'evaluator:
return (| m['evaluator] |) || $bs_eval;
case 'compiler:
return (| m['compiler] |) || $compiler;
case 'uncompiler:
return (| m['uncompiler] |) || $uncompiler;
default:
throw(~fieldnf, "Invalid field.");
}
};
public method .set_message_info() {
arg name, field, value;
var m;
((| (m = message_info[name]) |) != ~keynf) || throw(~messagenf, ("Message " + name) + " is not defined here.");
m = m.add(field, value);
message_info = message_info.add(name, m);
};
public method .message_parts() {
arg name;
return (| (message_info[name])[4] |) || [];
};
public method .evalutor() {
arg name;
return (defined_messages[name])[1];
};
public method .set_evaluator() {
arg name, evaluator;
var current;
.perms(sender(), 'writer);
current = defined_messages[name];
current = current.replace(1, evaluator);
.set_message_info(name, current);
};
public method .defines_message() {
arg name;
var n;
// returns 1 if the message <name> is defined here.
if (message_info)
return ((| message_info[name] |) != ~keynf) ? 1 : 0;
return 0;
};
public method .del_message() {
arg name;
var mess, kids;
(> .perms(sender(), 'writer) <);
message_info = message_info.del(name);
};
public method .local_messages() {
return messages || #[];
};
public method .messages() {
var all_messages, a, a_messages, d_messages, d, m, my_d;
// return all messages set on this() or parents
// a : on eancestor
// all_messages: the sum total of message
// a_messages: messages from ancestor a
// d: the definer of a message
// d_messages: messages from ancestor a, defined on d
// m: a specific message
// my_d: messags from definer d that have already been found.
all_messages = #[];
for a in (.ancestors()) {
if (a == definer())
break;
if (a.has_ancestor(definer())) {
a_messages = a.local_messages();
for d in (a_messages.keys()) {
d_messages = a_messages[d];
my_d = (| all_messages[d] |) || #[];
for m in (d_messages.keys()) {
if ((| my_d[m] |) == ~keynf)
my_d = my_d.add(m, d_messages[m]);
}
all_messages = all_messages.add(d, my_d);
}
}
}
return all_messages;
};
public method .local_message() {
arg name, [definer];
var d;
if (messages) {
if (!definer) {
for d in (messages.keys()) {
catch ~keynf
return (messages[d])[name];
}
} else {
catch ~keynf
return (messages[definer[1]])[name];
}
}
throw(~messagenf, "Message was not found.");
};
public method .prep_evaluator() {
arg name;
.perms(sender(), 'writers);
return (.messaage_info(name))[2];
// 9-26-95/19:57 Jeff ($jeff), moved from $has_messages.prep_evalutor
};
public method .message() {
arg name, [definer];
var a, message, mes, m;
//retrieve the specified message as ctext
if (definer)
definer = definer[1];
else
definer = (._find_message_definer(name))[2];
message = $message_frob.new();
for a in (.ancestors()) {
catch ~methodnf, ~messagenf
return a.local_message(name, definer);
}
throw(~messagenf, "No matching message.");
};
public method .set_message() {
arg name, message, [definer];
var mes, partial, compiler;
(> .perms(sender(), 'writer) <);
[(definer ?= ._find_message_definer(name))] = definer;
[partial, definer] = definer;
if (!messages)
messages = #[];
mes = (| messages[definer] |) || #[];
compiler = definer.message_info(partial, 'compiler);
message = compiler.compile_cml(message);
messages = messages.add(definer, mes.add(name, message));
};
public method .local_matching_messages() {
arg name, [definer];
var n, matches, d;
matches = [];
if (definer) {
for n in ((messages[definer]).keys()) {
if ($string.match_begin(n, name))
matches += [n];
}
} else {
for d in (messages.keys()) {
for n in ((messages[d]).keys()) {
if ($string.match_begin(n, name))
matches += [n];
}
}
}
return matches;
};
public method .matching_messages() {
arg name, definer;
var mes, a, m, len, messages, found, anc, mname;
mes = $message_frob.new();
found = #[];
//if (messages)
// return mes;
mname = name + ".";
len = mname.length();
anc = .ancestors();
a = $has_messages in anc;
anc = anc.subrange(1, a - 1);
for a in (anc) {
messages = (| (a.local_messages())[definer] |) || #[];
for m in (messages.keys()) {
if ((m == name) && ((| found[m] |) == ~keynf))
mes = mes.add_entry("general", messages[m]);
else if (($string.match_begin(m, mname)) && ((| found[m] |) == ~keynf))
mes = mes.add_entry(m.subrange(len + 1), messages[m]);
found = found.add(m, 1);
}
}
return mes;
};
public method ._del_message() {
arg name;
var mess;
mess = messages[sender()];
mess = mess.del(name);
messages = messages.add(sender(), mess);
};
public method ._find_message_definer() {
arg name;
var a, pos, name2;
pos = name.rindex(".");
if (pos)
name2 = name.subrange(1, pos - 1);
for a in (.ancestors()) {
catch ~methodnf {
if (a.defines_message(name))
return [name, a];
else if (a.defines_message(name2))
return [name2, a];
}
}
throw(~definernf, ("Could not find definer for " + name) + ".");
};
public method .eval_message() {
arg name, vars, [definer];
var message, partial;
if (!definer) {
[partial, definer] = ._find_message_definer(name);
} else {
partial = name;
definer = definer[1];
}
vars = vars.add('evaluator, definer.message_info(partial, 'evaluator));
message = .matching_messages(partial, definer);
if (message == (<$message_frob, #[]>))
message = $message_frob.new_with(#[["general", .message(partial, definer)]]);
message = message.set_vars(vars);
return message.eval_ctext(vars.add('time, 'pre));
};
root method .uninit_has_messages() {
messages = 0;
defined_messages = 0;
};
public method ._del_message_part() {
arg name, part;
var m, mess;
.debug(sender(), name, part);
if (messages && (sender() in (messages.keys()))) {
mess = messages[sender()];
.debug(mess);
if (name in (mess.keys())) {
m = mess[name];
.debug(m);
m = m.del_entry(part);
.debug(m);
mess = mess.add(name, m);
messages = messages.add(sender(), mess);
}
}
};
public method .unset_message() {
arg message, definer;
var mes;
mes = (| messages[definer] |) || #[];
(> (mes = mes.del(message)) <);
messages = messages.add(definer, mes);
};
public method .set_var() {
arg this, name, value;
var vars;
vars = this[2];
vars = vars.add(name, value);
return (<this(), [this[1], vars]>);
};
public method .set_vars() {
arg this, new;
var vars, key;
vars = this[2];
for key in (new)
vars = vars.add(key, new[key]);
return (<this(), [this[1], vars]>);
};
public method .edit_messages() {
var msg, s;
(> .perms((s = sender())) <);
msg = (s.display_messages("", this())).flatten();
(> s.invoke_editor(this(), '_edit_messages_callback, msg, []) <);
};
public method ._edit_messages_callback() {
arg text, client_data;
var errors, i, m, def;
(> .perms(sender()) <);
for i in (text) {
if (i.trim()) {
if ((m = i.match_pattern("$* (*):"))) {
sender().tell("Compiling messages defined for $%s (%s).".format(m[1], m[2]));
def = $object_lib.to_dbref(m[1]);
} else if ((m = i.match_pattern("$*:"))) {
sender().tell("Compiling messages defined for $%s.".format(m[1]));
def = $object_lib.to_dbref(m[1]);
} else if ((m = i.match_pattern("*=*"))) {
sender().set_message((m[1]).trim(), (m[2]).trim(), def);
} else {
sender().tell("Could not parse `%s`.".format(i));
}
}
}
};
new object $event_handler: $foundation;
var $root manager = $event_handler;
var $root managed = [$event_handler];
var $root flags = ['variables, 'methods, 'code, 'core];
var $root created_on = 850790316;
var $root inited = 1;
var $event_handler hooks = 0;
var $event_handler hooked = 0;
var $event_handler events = 0;
root method .uninit_event_handler() {
var e, o;
for e in ((hooks || #[]).keys())
(| o.event_hook_removed(e) |);
(| (.location()).unhook_from_all() |);
};
public method .clear_event_hook() {
arg event;
var o;
(> .perms(sender(), 'writer) <);
if ((!hooks) || (!(hooks.contains(event))))
return;
for o in (hooks[event])
(| o.event_hook_removed(event) |);
hooks = dict_del(hooks, event);
if (!hooks) {
(| clear_var('hooks) |);
(| clear_var('hooked) |);
}
};
public method .event_hooks() {
if (hooks)
return dict_keys(hooks);
return [];
};
public method .hook_into_event() {
arg event;
if (!hooks)
hooks = #[];
(> .will_hook(event, sender()) <);
hooks = dict_add(hooks, event, setadd((| hooks[event] |) || [], sender()));
hooked = (hooked || #[]).setadd_elem(sender(), event);
(| .did_hook(event, sender()) |);
};
public method .unhook_from_event() {
arg event;
if (!hooks)
return;
hooks = dict_add(hooks, event, setremove(hooks[event], sender()));
hooked = hooked.del_elem(sender(), event);
};
public method .unhook_from_all() {
var e;
if ((!hooked) || (!(hooked.contains(sender()))))
return;
for e in (hooked[sender()])
hooks = dict_add(hooks, e, setremove(hooks[e], sender()));
hooked = dict_del(hooked, sender());
};
protected method .will_hook() {
arg event, obj;
};
protected method .did_hook() {
arg event, obj;
};
public method .send_event() {
arg event, [args];
var o;
// some sort of perms checking..
if ((!hooks) || (!(hooks.contains(event))))
return;
for o in (hooks[event]) {
if (!valid(o)) {
hooks = dict_add(hooks, event, setremove(hooks[event], o));
hooked = hooked.del_elem(o, event);
}
(| o.event_notify(event, sender(), @args) |);
}
};
public method .event_notify() {
arg event, origin, [args];
if (caller() != $event_handler)
throw(~perm, caller() + " is not $event_handler.");
};
public method .event_hook_removed() {
arg event;
(> .perms(caller(), $event_handler) <);
};
public method .deregister_event() {
arg event, update_on;
var value;
(> .perms(sender()) <);
if ((events.contains(update_on)) && ((events[update_on]).contains(event))) {
value = (events[update_on]).del(event);
if (value)
events = events.add(update_on, value);
else
events = events.del(update_on);
if (!events)
clear_var('events);
}
};
public method .hook_events() {
arg type;
var status, source, event, l, all;
if (events && (events.contains(type))) {
all = events[type];
events = events.del(type);
l = .location();
for event in (all) {
[event, [status, source]] = event;
switch (source) {
case 'location:
l.hook_into_event(event);
case 'this:
.hook_into_event(event);
default:
source.hook_into_event(event);
}
all = all.add(event, [1, source]);
}
events = events.add(type, all);
}
};
public method .register_event() {
arg event, update_on, src;
var value, all;
(> .perms(sender()) <);
if (!events)
events = #[];
if ((update_on != 'move) && (update_on != 'startup))
throw(~type, "Update on must be either 'move or 'startup");
if (type(src) == 'symbol) {
if ((src != 'location) && (src != 'this))
throw(~type, "Source types must be either 'location or 'this.");
} else if (type(src) != 'object) {
throw(~type, "Source type must be either a symbol or object.");
} else if (!(src.is($event_handler))) {
throw(~type, ("Source " + (src.namef('ref))) + " is not an event handler.");
}
if (events.contains(update_on)) {
all = events[update_on];
if ((events[update_on]).contains(event)) {
value = replace(all[event], 2, src);
events = events.add(update_on, all.add(event, value));
} else {
events = events.add(update_on, all.add(event, [0, src]));
}
} else {
events = events.add(update_on, #[[event, [0, src]]]);
}
};
public method .unhook_events() {
arg type, [loc];
var all, event, status, source;
if (events && (events.contains(type))) {
all = events[type];
events = events.del(type);
loc ? loc[1] : (.location());
for event in (all) {
[event, [status, source]] = event;
switch (source) {
case 'location:
loc.unhook_from_event(event);
case 'this:
.unhook_from_event(event);
default:
source.hook_into_event(event);
}
all = all.add(event, [0, source]);
}
events = events.add(type, all);
}
};
new object $physical: $described, $has_gender, $has_messages, $event_handler;
var $root trusted = [];
var $root inited = 1;
var $root created_on = 796268969;
var $root flags = ['methods, 'code, 'variables, 'core];
var $described prose = [];
var $has_gender gender = $gender_neuter;
var $physical visibility = 0;
var $has_name name = ['uniq, "Generic Physical Object", "the Generic Physical Object"];
var $has_settings defined_settings = #[["visibility", #[['get, 'visibility], ['set, 'set_visibility], ['check, 'is_type], ['del, 'delete_local_setting], ['check_args, ['integer]], ['get_args, []], ['set_args, []]]]];
var $has_settings local_settings = #[];
var $has_settings settings = #[];
var $root manager = $physical;
var $root owned = [$physical];
var $root managed = [$physical];
public method .set_visibility() {
arg definer, name, value, [args];
(> .perms(sender()) <);
visibility = value;
};
public method .visibility() {
arg [args];
return visibility;
};
public method .is_visible_to() {
arg whom;
return (.visibility()) >= ((whom.location()).darkness());
};
public method .set_darkness() {
arg definer, name, value, [args];
(> .perms(sender()) <);
darkness = value;
};
public method .vr_examine();
new object $located: $physical;
var $located inited = 0;
var $located location = $lost_and_found;
var $located obvious = 1;
var $root created_on = 796268969;
var $root flags = ['methods, 'code, 'variables, 'core];
var $has_gender gender = $gender_neuter;
var $described prose = [];
var $has_name name = ['uniq, "Generic Located Object", "the Generic Located Object"];
var $root manager = $located;
var $root child_index = 1;
var $root managed = [$located];
var $root owned = [$located];
root method .init_located() {
location = $void;
location.add_sender_to_contents();
obvious = 1;
};
public method .uninit() {
if (caller() != $root)
throw(~perm, "Caller is not root.");
location.del_sender_from_contents();
location = 0;
};
public method .environment() {
return [this()] + ((location.environment()).setremove(this()));
};
public method .match_environment() {
arg str;
var thing, matches;
if (str == "here")
return location;
return (> pass(str) <);
};
public method .location() {
return location || $void;
};
public method .will_move() {
arg mover, place;
};
protected method .did_move() {
arg mover, old_place;
// cleanup events
.unhook_events('move, old_place);
location.send_event('movement, 'arrive);
.hook_events('move);
};
public method .realm() {
return realm;
};
root method .uninit_located() {
(.location()).del_sender_from_contents();
};
public method .move_to() {
arg place;
var old;
// Don't do anything if we're already here.
if (place == location)
return;
if (!(place.has_ancestor($location)))
throw(~type, "Argument is not a location.");
// Notify involved parties of impending move, allowing them to throw
// errors.
if (!valid(location))
location = $nowhere;
(> .will_move(sender(), place) <);
(> location.will_leave(place) <);
(> place.will_arrive(location) <);
// Set location.
old = location;
location = place;
old.del_sender_from_contents();
place.add_sender_to_contents();
// Notify involved parties of completed move, in reverse order.
place.did_arrive(old);
old.did_leave(place);
.did_move(sender(), old);
};
public method .match_environment_all() {
arg s;
if (s == "here")
return [location, @(> pass(@args) <)];
else
return (> pass(s) <);
};
public method .obvious() {
return obvious;
};
public method .set_obvious() {
arg obv;
.perms(sender());
obvious = obv;
};
public method .realm_name() {
arg [args];
return (.location()).realm_name(@args);
};
public method .is_obvious_to() {
arg whom;
// will later do something creative here
return 1;
};
new object $thing: $located;
var $root child_index = 169;
var $root fertile = 1;
var $root inited = 1;
var $root created_on = 796268969;
var $root flags = ['methods, 'code, 'fertile, 'variables, 'core];
var $located location = $void;
var $located obvious = 1;
var $has_gender gender = $gender_neuter;
var $described prose = [];
var $has_name name = ['normal, "thing", "a thing"];
var $has_commands shortcuts = #[];
var $has_commands remote = #[["@lock", [["@lock", "* with|to *", "@lock <this> with|to <any>", 'lock_with_cmd, #[[1, ['this, []]], [3, ['any, []]]]], ["@lock", "*", "@lock <this>", 'lock_cmd, #[[1, ['this, []]]]]]], ["@unlock", [["@unlock", "*", "@unlock <this>", 'unlock_cmd, #[[1, ['this, []]]]]]], ["@boot", [["@boot", "*", "@boot <this>", 'boot_cmd, #[[1, ['this, []]]]]]]];
var $has_commands local = #[];
var $thing lock = <$true_lock_frob, []>;
var $has_settings defined_settings = #[["home", #[['get, 'home], ['set, 'set_local_setting], ['check, 'check_home], ['del, 'delete_local_setting], ['check_args, []], ['get_args, []], ['set_args, []]]]];
var $has_settings local_settings = #[];
var $has_settings settings = #[];
var $root manager = $thing;
var $root owned = [$thing];
var $root managed = [$thing];
public method .boot_cmd() {
arg cmdstr, cmd, this;
var loc, dest, exit;
loc = .location();
if (!(| .perms(sender(), 'manager) |)) {
.tell((((sender().name()) + " tried to boot you from ") + (loc.name())) + "!");
loc.announce((((((sender().name()) + " tried to boot ") + (.name())) + " from ") + (loc.name())) + "!", sender(), this());
return ((("Only " + ((loc.manager()).name())) + " can boot people from ") + (loc.name())) + "!";
}
dest = .home();
catch any {
sender().tell(("You boot " + (.name())) + ".");
loc.announce((((((sender().name()) + " boots ") + (.name())) + " from ") + ((.location()).name())) + ".", this(), sender());
if ((sender().location()) != loc)
(sender().location()).announce((((((sender().name()) + " boots ") + (.name())) + " from ") + ((.location()).name())) + ".", this(), sender());
(> .move_to(dest) <);
} with {
return (traceback()[1])[2];
}
// $# Edited 05 Nov 1995 14:10 Lynx ($lynx)
};
public method .lock() {
return lock;
};
public method .lock_cmd() {
arg cmdstr, cmd, this;
if (!(| .perms(sender()) |))
return ((("Only " + ((.manager()).name())) + " can lock ") + (.name())) + "!";
lock = $false_lock_frob.new();
return "You lock " + (.name());
};
public method .lock_with_cmd() {
arg cmdstr, cmd, this, prep, str;
if (!(| .perms(sender()) |))
return ((("Only " + ((.manager()).name())) + " can lock ") + (.name())) + "!";
catch ~objnf, ~parse {
lock = $lock_parser.parse(str, sender());
return ((((("You lock " + (.name())) + " ") + prep) + " ") + (lock.lock_name('thing))) + ".";
} with {
switch (error()) {
case ~objnf:
return "Object not found in lock string.";
case ~parse:
return "Invalid lock string.";
}
}
};
public method .unlock_cmd() {
arg cmdstr, cmd, this;
if (!(| .perms(sender()) |))
return ((("Only " + ((.manager()).name())) + " can lock ") + (.name())) + "!";
lock = $true_lock_frob.new();
return "You unlock " + (.name());
};
public method .will_move() {
arg mover, place;
(> pass(mover, place) <);
if (mover.is($housekeeper))
return;
if (lock && ((mover != $exit) && (!(lock.try(mover)))))
throw(~locked, ((((.name()).capitalize()) + " is locked to ") + (lock.lock_name('thing))) + ".");
else if (!(.is_writable_by(sender())))
throw(~move, "You cannot move " + this());
};
public method .home() {
arg [args];
var home;
home = (| .get_local_setting("home", $thing) |);
if (home)
return home;
if ((.manager()).is($user))
return .manager();
return $lost_and_found;
};
public method .check_home() {
arg definer, value, [args];
var home;
home = (> .match_environment(value) <);
if ((!(| home.trusts(sender()) |)) && (!(| home.setting("public-home") |)))
throw(~perm, ("You do not have permission to make " + (home.name())) + " your home.");
return home;
// $# Edited 16 Oct 1995 18:04 Lynx ($lynx)
};
public method .check_gender() {
arg definer, value, [args];
var g, gs;
gs = [$gender_female, $gender_male, $gender_neuter];
g = value in (gs.mmap('name));
if (!g)
throw(~set, "Gender must be one of: " + ((gs.mmap('name)).to_english("", " or ")));
return gs[g];
};
public method .check_match_with() {
arg definer, value, [args];
var matching;
if (value in ["regexp", "pattern", "begin"])
return tosym("match_" + (value.lowercase()));
throw(~perm, "You can match with: regexp, pattern, begin.");
};
new object $command_cache: $has_commands;
var $root child_index = 3;
var $root fertile = 1;
var $root manager = $command_cache;
var $root created_on = 796605573;
var $root inited = 1;
var $root flags = ['methods, 'code, 'fertile, 'variables, 'core];
var $command_cache shortcut_cache = 0;
var $command_cache remote_cache = 0;
var $command_cache local_cache = 0;
var $has_commands shortcuts = #[];
var $root managed = [$command_cache];
var $root owned = [$command_cache];
var $command_cache interfaces = 0;
root method .uninit_command_cache() {
var i;
(| .purge_caches() |);
for i in (interfaces || [])
i.interface_unlink();
};
public method .rehash_caches() {
Showing the first 100 KB of 1.5 MB. Download the archive for the full file.