Site DB #25

Parent #37Owner #36Flags Source RPG Core/rpgcore-patched.db

Aliases: Site DB, sitedb, site, db

8 verbs · 14 properties · 0 children

Verbs

VerbSpecFlagsDefinerLines
find* _only* _every*this none thisrxd#251
addthis none thisrxd#2540
loadthis none thisrxd#2528
domain_literalthis none thisrxd#2517
init_for_corethis none thisrxd#255
prunethis none thisrxd#2543
report_prune_progressthis none thisrxd#2524
prune_fixupthis none thisrxd#2526

Properties

PropertyDefinerFlagsOwnerValue
domain#25r#36"localdomain"
prune_progress#25rc#36"rei.ee"
prune_stop#25rc#36254
total_pruned_people#25rc#3651021
total_pruned_sites#25rc#3628719
prune_task#25rc#361012403705
node_perms#37rc#36""
data#37r#36<clear>
#37#36{"", "", {}, {}}
key#1c#36<clear>
aliases#1rc#36{"Site DB", "sitedb", "site", "db"}
description#1rc#36{"This object holds a db of places from which players have connected (see `help $site_db').", "The site blacklist and the graylist live as well (see `help blacklist')."}
object_size#1r#36{9080, -1090650497}
html#1rc#36<clear>

Ancestry

Ancestors (nearest first): #37 Generic Database#1 Root Class

Children: none

Call graph

calls n25_1 #25:add n25_3 #25:domain_literal n25_1->n25_3 n37_1 #37:find_exact n25_1->n37_1 n37_6 #37:insert n25_1->n37_6 n25_2 #25:load n25_2->n25_1 n42_0 #42:controls n25_2->n42_0 n37_12 #37:clearall n25_2->n37_12 n52_5 #52:isa n25_2->n52_5 n56_7 #56:running_out_of_time n25_2->n56_7 n6_18 #6:tell n25_2->n6_18 n25_4 #25:init_for_core n25_4->n37_12 n1_28 #1:init_for_core n25_4->n1_28 n25_5 #25:prune n25_5->n37_1 n25_5->n37_6 n25_5->n56_7 n25_5->n6_18 n37_2 #37:find_all n25_5->n37_2 n56_8 #56:suspend_if_needed n25_5->n56_8 n37_7 #37:delete n25_5->n37_7 n24_40 #24:random_wizard n25_5->n24_40 n25_6 #25:report_prune_progress n25_6->n6_18 n59_37 #59:task_valid n25_6->n59_37 n25_7 #25:prune_fixup n25_7->n37_1 n25_7->n37_6 n25_7->n56_8 n25_7->n37_7 n25_7->n25_7

Source

find* _only* _every*

Spec this none thisFlags rxdOwner #36Definer #25

Referenced by

none

Source

1return ((caller == this) || caller_perms().wizard) ? pass(@args) | E_PERM;

add

Spec this none thisFlags rxdOwner #36Definer #25

Referenced by

Source

1":add(player,site)";
2if (!caller_perms().wizard)
3return E_PERM;
4endif
5{who, domain} = args;
6if (this:domain_literal(domain))
7"... just enter it...";
8l = this:find_exact(domain);
9if (l == $failed_match)
10this:insert(domain, {who});
11elseif (!(who in l))
12this:insert(domain, setadd(l, who));
13endif
14else
15"...an actual domain name; add player to list for that domain...";
16"...then add domain itself to list for the next larger domain; repeat...";
17"...  Example:  domain == foo.bar.edu:  ";
18"...            enter #who  on foo.bar.edu list";
19"...            enter `foo' on bar.edu list";
20"...            enter `bar' on edu list";
21if (!(dot = index(domain, ".")))
22dot = length(domain) + 1;
23domain = tostr(domain, ".", this.domain);
24endif
25prev = who;
26while ($failed_match == (l = this:find_exact(domain)))
27this:insert(domain, {prev});
28if (dot)
29prev = domain[1..dot - 1];
30domain = domain[dot + 1..$];
31else
32return;
33endif
34dot = index(domain, ".");
35endwhile
36if (!(prev in l))
37this:insert(domain, {@l, prev});
38endif
39return;
40endif

load

Spec this none thisFlags rxdOwner #2Definer #25

Referenced by

none

Source

1":load([start]) -- reloads site_db with the connection places of all players.";
2"This routine calls suspend() if it runs out of time.";
3"WIZARDLY";
4"...needs to be able to read .all_connect_places";
5if (!$perm_utils:controls(caller_perms(), this))
6return E_PERM;
7endif
8plist = players();
9if (!args)
10this:clearall();
11elseif (i = args[1] in plist)
12plist[1..i - 1] = {};
13else
14return E_INVARG;
15endif
16for p in (plist)
17if (valid(p) && (is_player(p) && (!$object_utils:isa(p, $guest))))
18"... player may be recycled or toaded during the suspend(),...";
19"... guests login from everywhere...";
20for c in (p.all_connect_places)
21this:add(p, c);
22if ($command_utils:running_out_of_time())
23player:tell("...", p);
24suspend(0);
25endif
26endfor
27endif
28endfor

domain_literal

Spec this none thisFlags rxdOwner #36Definer #25

Referenced by

Source

1":domain_literal(string)";
2" => true iff string is a domain literal (i.e., numeric IP address).";
3if (10 <= (len = length(hnum = strsub(args[1], ".", ""))))
4return toint(hnum[1..9]) && toint(hnum[6..len]);
5else
6return toint(hnum);
7endif
8"SLEAZY CODE ALERT";
9"... what I wanted to do was return toint(strsub(args[1],\".\",\"\"))";
10"... but on a 32-bit machine, this has a 1 in 4294967296 chance of failing";
11"... (e.g., on \"42.94.967.296\", though I'll grant this particular example";
12"...  entails some very strange subnetting on net 42, to say the least).";
13"... So we do something that is guaranteed to work so long as internet";
14"... addresses stay under 32 bits --- a while yet...";
15"";
16"... As soon as we're sure match() is working, this will become a one-liner:";
17return match(args[1], "[0-9]+%.[0-9]+%.[0-9]+%.[0-9]+");

init_for_core

Spec this none thisFlags rxdOwner #2Definer #25

Referenced by

none

Source

1if (caller_perms().wizard)
2pass();
3this:clearall();
4this.domain = "localdomain";
5endif

prune

Spec this none thisFlags rxdOwner #2Definer #25

Referenced by

none

Source

1"Carefully loop through the db and delete items associated with !valid and !is_player objects.  If that results in no objects remaining for a site, delete that site.";
2"Attempt to keep memory usage down by only asking for a small number of items at a time.  Should probably have some arguments to control this.";
3"Another thing it should do is be clever about string typed items.";
4"Rewriting this to do numerics now.";
5if (!caller_perms().wizard)
6raise(E_PERM);
7endif
8this.prune_task = task_id();
9probe = this.prune_progress;
10while (probe[1] <= this.prune_stop)
11probestring = tostr(probe[1], ".", probe[2], ".");
12for sitename in (z = this:find_all_keys(probestring))
13items = this:find_exact(sitename);
14orig = items;
15for y in (items)
16if ((typeof(y) == OBJ) && ((!valid(y)) || (!is_player(y))))
17items = setremove(items, y);
18endif
19$command_utils:suspend_if_needed(0);
20endfor
21if (!items)
22this:delete(sitename);
23this.total_pruned_sites = this.total_pruned_sites + 1;
24elseif (items == orig)
25else
26this:insert(sitename, items);
27this.total_pruned_people = (this.total_pruned_people + length(orig)) - length(items);
28endif
29$command_utils:suspend_if_needed(0);
30endfor
31if (probe[2] == 255)
32probe[1] = probe[1] + 1;
33probe[2] = 0;
34else
35probe[2] = probe[2] + 1;
36endif
37this.prune_progress = probe;
38if ($command_utils:running_out_of_time())
39set_task_perms($wiz_utils:random_wizard());
40suspend(0);
41endif
42endwhile
43player:tell("Prune stopped at ", toliteral(this.prune_progress));

report_prune_progress

Spec this none thisFlags rxdOwner #2Definer #25

Referenced by

none

Source

1player:tell("Prune is up to ", toliteral(this.prune_progress), ".");
2mine = 0;
3if (typeof(this.prune_progress) == STR)
4total = (26 * 26) * 26;
5for x in [1..3]
6mine = ((mine * 26) + index($string_utils.alphabet, this.prune_progress[x])) - 1;
7endfor
8else
9total = 256 * 256;
10mine = (this.prune_progress[1] * 256) + this.prune_progress[2];
11endif
12percent = (100.0 * tofloat(mine)) / tofloat(total);
13player:tell("We have processed ", mine, " entries out of ", total, ", or ", toint(percent), ".", toint(10.0 * percent) % 10, "%.");
14player:tell("There were ", this.total_pruned_people, " individual list entries removed, and ", this.total_pruned_sites, " whole sites removed.");
15if ($code_utils:task_valid(this.prune_task))
16player:tell("Prune task is ", this.prune_task, ".  Stacktrace:");
17for x in (task_stack(this.prune_task, 1))
18if (valid(x[4]))
19player:tell(x[4], ":", x[2], " [", x[1], "]  ", x[3].name, "  (", x[6], ")");
20endif
21endfor
22else
23player:tell("The recorded task_id is no longer valid.");
24endif

prune_fixup

Spec this none thisFlags rxdOwner #2Definer #25

Referenced by

Source

1if (!caller_perms().wizard)
2raise(E_PERM);
3endif
4root = args[1];
5items = this:find_exact(root);
6orig = items;
7if (items == #-3)
8return 1;
9endif
10$site_db.prune_progress = root;
11for item in (items)
12if (typeof(item) == STR)
13if (this:prune_fixup((item + ".") + root))
14items = setremove(items, item);
15endif
16endif
17$command_utils:suspend_if_needed(0);
18endfor
19if (!items)
20this:delete(root);
21this.total_pruned_sites = this.total_pruned_sites + 1;
22return 1;
23elseif (orig == items)
24else
25this:insert(root, items);
26endif