Player Database (#41)

(an instance of Generic Database made by Hacker)

     A database containing all player names and aliases.
     See `help $player_db' for more information.



VERB SOURCE CODE:

load:
":load() -- reloads the player_db with the names of all existing players.";
"This routine calls suspend() if it runs out of time.";
".frozen is set to 1 while the load is in progress so that other routines are warned 
and don't try to do any updates.  Sometimes, an update is unavoidable (e.g., player 
gets recycled) in which case the offending routine should set .frozen to 2, causing 
the load to start over at the beginning.";
if ((caller != this) && (!$perm_utils:controls(caller_perms(), this)))
    return E_PERM;
endif
this:clearall();
this.frozen = 1;
for p in (players())
    this:suspend_restart(p);
    "... note that if a player is recycled or toaded during the suspension,...";
    "... it won't be removed from the for loop iteration; thus this test:     ";
    if (valid(p) && is_player(p))
        if (typeof(po = this:find_exact(p.name)) == ERR)
            player:tell(p.name, ":  ", po);
            return;
        elseif (po != p)
            if (valid(po) && is_player(po))
                player:tell("name `", p.name, "' for ", p, " subsumes alias for ", 
po.name, "(", po, ").");
            endif
            this:insert(p.name, p);
        endif
        for a in (p.aliases)
            this:suspend_restart(p);
            if (index(a, " ") || index(a, "	"))
                "don't bother";
            elseif (typeof(ao = this:find_exact(a)) == ERR)
                player:tell(a, ":  ", ao);
                return;
            elseif (!(valid(ao) && is_player(ao)))
                this:insert(a, p);
            elseif (ao != p)
                player:tell("alias `", a, "' for ", p.name, "(", p, ") used by ", 
ao.name, "(", ao, ").");
            endif
        endfor
    endif
endfor
this.frozen = 0;
.


check:
":check() -- checks for recycled and toaded players that managed not to get expunged 
from the db.";
for p in (properties($player_db))
    if ((ticks_left() < 500) || (seconds_left() < 2))
        player:tell("...", p);
        suspend(0);
    endif
    if (p[1] == " ")
        nlist = this.(p)[3];
        olist = this.(p)[4];
        for i in [1..length(nlist)]
            if (valid(olist[i]) && (is_player(olist[i]) && (nlist[i] in olist[i].aliases)))
            else
                player:tell(".", p[2..length(p)], " <- ", nlist[i], " ", olist[i]);
            endif
        endfor
    endif
endfor
player:tell("done.");
.


init_for_core:
if (caller_perms().wizard)
    pass();
    this.reserved = {};
    this:load();
endif
.


available:
":available(name) => 1 if a name is available for use, or the object id of whoever 
is currently using it, or 0 if the name is otherwise forbidden.";
"If $player_db is not .frozen and :available returns 1, then $player:set_name will 
succeed.";
name = args[1];
if ((name in this.stupid_names) || (name in this.reserved))
    return 0;
elseif (((((!name) || index(name, " ")) || index(name, "\\")) || index(name, "\"")) 
|| index(name, "	"))
    return 0;
elseif (index("*#()", name[1]))
    return 0;
elseif (valid(who = this:find_exact(name)) && is_player(who))
    return who;
else
    return 1;
endif
.


suspend_restart:
"used during :load to do the usual out-of-time check.";
"if someone makes a modification during the suspension (indicated by this.frozen 
being set to 2), we have to restart the entire load.";
if (caller != this)
    return E_PERM;
elseif ($command_utils:running_out_of_time())
    player:tell("...", args[1]);
    suspend(0);
    if (this.frozen != 1)
        player:tell("...argh... restarting $player_db:load...");
        fork (0)
            this:load();
        endfork
        kill_task(task_id());
    endif
endif
.


why_bad_name:
":why_bad_name(player, namespec) => Returns a message explaining why a player name 
change is invalid.  Stolen from APHiD's #15411:name_okay.";
who = args[1];
name = $building_utils:parse_names(args[2])[1];
si = index(name, " ");
qi = index(name, "\"");
bi = index(name, "\\");
ti = index(name, "	");
if ((si || qi) || bi)
    return tostr("You may not use a name containing ", $string_utils:english_list({@si 
? {"spaces"} | {}, @qi ? {"quotation marks"} | {}, @bi ? {"backslashes"} | {}, @ti 
? {"tabs"} | {}}, "ERROR", " or "), ".  Try \"", strsub(strsub(strsub(name, " ", 
"_"), "\"", "'"), "\\", "/"), "\" instead.");
elseif (name == "")
    return tostr("You may not use a blank name.");
elseif (i = index("*#()", name[1]))
    return tostr("You may not begin a name with the \"", "*#()"[i], "\" character.");
elseif (name in $player_db.stupid_names)
    return tostr("The name \"", name, "\" would probably cause problems in command 
parsing or similar usage.");
elseif (name in $player_db.reserved)
    return tostr("The name \"", name, "\" is reserved.");
elseif (length(name) > $login.max_player_name)
    return tostr("The name \"", name, "\" is too long.  Maximum name length is ", 
$login.max_player_name, " characters.");
elseif ((valid(match = $player_db:find_exact(name)) && is_player(match)) && (who 
!= match))
    return tostr("The name \"", name, "\" is already being used by ", match.name, 
"(", match, ").");
elseif ($player_db.frozen)
    return tostr("$player_db is not accepting new changes at the moment.");
endif
.



PROPERTY DATA:
      stupid_names
      frozen
      reserved
      T
      e
      n
      M
      h
      D
      Dr
      B
      c
      r
      Z
      Ma
      rat
      K
      Ca
      P
      L
      Th
      Ba
      Q
      Dre
      drb
      A
      Am
      Ki
      V
      S
      ci
      No
      bl
      G
      J
      Ch
      Y
      Ho
      Je
      Ev
      Ne
      Bu
      De
      An
      Man
      Sc
      Dra
      Gr
      F
      fi
      ge
      Gri
      Qu
      va
      cal
      cin
      Ta
      tar
      Sa
      sal
      Br
      mal
      Hor
      He
      Anr
      jo
      Pr
      The_
      St
      ka
      be
      ras
      Lo
      lor
      lore
      Mar
      O
      Saf
      Saff
      ob
      BenD
      Cha
      Ec
      Ecl
      Ecli
      Eclip
      Eclips
      cl
      Se
      Si
      Sic
      So
      Ar
      W
      Jea
      Ja
      Pa
      Ste
      Lu
      To
      Toc
      ra
      Jan
      Co
      marc
      mr
      ph
      Sy
      pi
      al
      i
      Pir
      Me
      Sai
      com
      ze
      po
      pol
      mel
      car
      Mo
      kat
      cat
      Bur
      mi
      Bo
      But
      ro
      Mant
      Ran
      Su
      Wi
      U
      Mae
      Def
      ton
      eve
      eva
      Ben
      fa
      go
      Wil
      Rod
      Fl
      Joh
      Sh
      Jac
      As
      Kar
      Cy
      Gu
      Gun
      Nes
      ant
      Tr
      trism
      Ga
      Gi
      La
      Sp
      Re
      Tri
      tre
      qui
      Kal
      Blac
      Fig
      Rob
      El
      Gue
      Fr
      pe
      Ha
      Sn
      faa
      Min
      !
      bou
      boud
      sho
      Vi
      Sw
      marg
      bec
      Ip
      Ips
      Sna
      Lar
      Sil
      Pu
      Tree
      Blacka
      Amb
      Jay
      Wo
      ari
      aria
      2
      3
      9
      na
      bea
      griff
      Cas
      Bud
      Vai
      X
      df
      Defa
      Yo
      wh
      whi
      los
      py
      Ur
      Wol
      Bri
      Bria
      Ber
      god
      Mac
      mack
      Dea
      Vis
      Phl
      Fir
      ke
      Son
      Sonn
      beck
      Le
      Lum
      ald
      I'
      sub
      Pat
      Fe
      sta
      fel
      cyb
      We
      kr
      li
      Sha
      leg
      Kl
      tris
      fla
      tw
      Rot
      stet
      Ken
      Ic
      Per
      Que
      Sj
      Deat
      shal
      Sco
      te
      Bert
      Mag
      di
      Er
      Bla
      Ni
      In
      nat
      Ju
      Sam
      Jen
      Gol
      Tal
      Pro
      quix
      do
      mis
      8
      Pri
      yj
      yja
      jaz
      The_M
      stev
      Lin
      Lio
      Cir
      may
      fu
      fas
      ART
      Bow
      sun
      Val
      Da
      clip
      aj
      cae
      pus
      pussy
      kid
      Sir
      um
      v.
      Cor
      hy
      The
      Moo
      Ama
      ab
      amaz
      bi
      ir
      sk
      sky
      Hi
      arc
      Her
      Circ
      rb
      rai
      Rainb
      Zo
      Led
      Os
      gro
      G-
      sl
      Quen
      Cli
      Whir
      ww
      wolf
      whit
      Ti
      Mos