Switching (#326)

(an instance of generic note made by Dredful)


Go to location of this object, Cluttered Closet.
     Message 1 on *Documentation (#33586):
     Date:    Thu Feb  3 16:37:13 1994 EST
     From:    Blackbriar (#30119)
     To:      *Documentation (#33586) and yduJ (#68)
     Subject: Quota Utilities Porting Documentation
     
     Porting the Byte-Based Quota Utilities from LambdaMOO:
     =====================================================
     
     From LambdaMOO, there are two objects to be ported:
       $quota_utils -- byte-based quota utilities
       $alt_quota_utils -- object-based quota utilities
     You'll also want to make a character named Quota and give Quota ownership of
     those objects (this is optional; you can use Hacker, or whoever).  Also, change
     the ownership of $player.ownership_quota (and its kids) to Quota, and add a
     property on $player called size_quota, with initial value {0,0,0,0}.  Perms ""
     (or, at worst, "r").  Quota must be a programmer, but need not (and should not)
     be a wizard.
     
     You also want a property on $root_class called .object_size, which is owned by
     Quota and has perms "r".  Default value here should be {0,0}.
     
     When you port these, the first things you will want to do is change the names
     so they don't call themselves LambdaMOO Utilities and such.  Call them
     object-based quota utilities and byte-based quota utilities, so you don't get
     confused later.
     
     Also, and this is important, -switch- the pointers on #0.  In other words, make
     $quota_utils point to the object-based utilities and $alt_quota_utils to the
     byte-based utilities (the opposite of LambdaMOO).
     
     Verbs you want to be sure to modify [this list is taken from yduJ's
     documentation on porting the byte-based utilities] follow.  It might be good to
     look at the LambdaMOO versions of these verbs; in many cases, the changes are
     very small.
       $prog:@property
         check $quota_utils:verb_addition_permitted
       $prog:@verb
         check $quota_utils:property_addition_permitted
       $prog:@copy
         LambdaMOO has a modified version which moves verbs while copying;
         this allows for verbs to be copied when a user is out of quota
     
       $wiz:@programmer 
         use $quota_utils to display current quota, instead of having that
         information grabbed directly from the property
       $wiz:@quota
         use $quota_utils:set_quota instead of raw munging on the property
         in addition, LambdaMOO has a 'public' option; this is probably
         unnecessary
     
       $wiz_utils:set_programmer 
         use $quota_utils:adjust_quota_for_programmer to give additional
         quota upon @programmer'ing
       $wiz_utils:set_owner 
         use $quota_utils to handle quota transfer when an object's ownership
         changes
       $wiz_utils:make_player
         use $quota_utils:initialize_quota to set the player's default
         quota.
     
       $builder:@quota 
         use $quota_utils:display_quota
       $builder:_create
         use $quota_utils:bi_create instead of the create() call
     
       [$builder:@measure]
         this is a verb you will likely want to install
     
       $recycler:_recycle 
       $recycler:_create 
       $recycler:setup_toad
         these need to use $quota_utils as well
     
       $login:create
         similar to $wiz_utils:make_player
     
     The next thing you want to do is switch all remaining references to
     .ownership_quota.  Do this:
       @grep ownership_quota
     This will give you all the references to ownership_quota.  You will want to
     modify those references (here, you need to be a bit clever) so that they use
     verbs on $quota_utils.  Specifically, bear in mind
     $quota_utils:creation_permitted and $quota_utils:quota_remaining.  Everywhere
     you use a raw create(), you want to use $quota_utils:bi_create [standing for
     builtin-create(), nothing sexual or political].
     
     Now that these changes are made, and object-based quota is installed, let it
     sit a while.  Try building, creating, recycling, mucking with your quota,
     everything.  Look for places you didn't make changes.  Peek through code all
     over the place.  Once you're comfortable that everything relevant is going
     through $quota_utils, you're ready for the next step.
     
     That next step is deciding on a translation factor.  Sample code from OpalMOO
     was this:
       "Set up the byte-based stuff.  Give every player 20000 bytes for eir own
     character, plus 5000 bytes per original quota point.";
       set_task_perms(player);
       for x in (players())
         x.size_quota = {20000 + 5000 * x.ownership_quota, 0, 0, 0};
       endfor
       x = 0;
       while (x <= tonum(max_object()))
         o = toobj(x);
         if (valid(o))
           o.owner.size_quota = o.owner.size_quota;
           o.owner.size_quota[1] = o.owner.size_quota[1] + 2000;
           $quota_utils:recent_object_bytes(o, 1);
           $alt_quota_utils:charge_quota(o.owner, o);
         endif
         $command_utils:suspend_if_needed(0, tostr("...#", x));
         x = x + 1;
         endwhile
         overs = {};
         for x in (players())
           if (x.size_quota[2] > x.size_quota[1])
             overs = setadd(overs, x);
           endif
           $command_utils:suspend_if_needed(0, tostr("...", x));
         endfor
         player:tell($string_utils:english_number(length(overs)), " players are
     over.");
         player:tell($string_utils:names_of(overs));
     That code is kinda stingy.  You might want to be more generous.
     
     Once everyone is initialized to what you feel to be comfortable, and you want
     to switch to byte-based quota, set everyone's .ownership_quota to -10000:
       ;for x in (players()) x.ownership_quota=-10000; endfor;
     and swap the quota utilities:
       ;;temp=$quota_utils;$quota_utils=$alt_quota_utils;$alt_quota_utils=temp;
     and watch it go.
     
     The last thing you'll want to do is start up $quota_utils:measurement_task,
     which will periodically plod through the database, measuring objects and fixing
     people's quota.  You'll want to modify this code to suit your own DB, however,
     since the timing is based on a -huge- database like LambdaMOO's.
     
     Note: The byte-based implementation does allow anyone to see anyone else's
     quota.  You may want to fix this, in :display_quota.
     
     Note: In the byte-based implementation, characters with "second" characters
     will have quota pooled, if there exists $local.second_character_registry such
     as on LambdaMOO.
     --------------------------
     
     Subject: Additional notes re: quota porting
     
     Also remember to set $no_one and all Guest quotas to 0.
     --------------------------




VERB SOURCE CODE:

init_it:
if (player == this)
    set_task_perms(player);
    for who in (setremove(players(), $hacker))
        who.size_quota = $alt_quota_utils.default_quota;
        if ((g = who.ownership_quota + length(who.owned_objects)) > 8)
            "Gives everyone who has more than 7 quota 5k per unused quota point";
            who.size_quota[1] = who.size_quota[1] + ((g - 8) * 2000);
        elseif ((who.ownership_quota == 0) && (length(who.owned_objects) == 1))
            who.size_quota = {0, 0, 0, 1};
        endif
    endfor
    x = 0;
    while (x <= tonum(max_object()))
        o = toobj(x);
        if (valid(o))
            $alt_quota_utils:recent_object_bytes(o, 1);
            $alt_quota_utils:charge_quota(o.owner, o);
        endif
        $command_utils:suspend_if_needed(0);
        x = x + 1;
    endwhile
    player:tell("Done.");
endif
.


show_init:
if (!(player.wizard || (player == #78)))
    return E_PERM;
endif
player:tell("All players initial quota:");
info = {};
for d in (players())
    info = {@info, {$string_utils:nn(d), d.ownership_quota, (typeof(d.owned_objects) 
== LIST) ? length(d.owned_objects) | d.owned_objects, $string_utils:print(d.size_quota)}};
endfor
for f in (info)
    player:tell_lines($string_utils:columnize(f, 4, 75));
endfor
player:tell("-- Finished");
.



PROPERTY DATA: