Beispiel #1
0
def quit(player, args, ex):

    mush.message(player.dbref, "Logging out. Goodbye.")
    mush.message(player.location, f"{player.name} disconnected.")
    mush.log(1, f"{player.name} (#{player.dbref}) disconnected.")

    player.flags ^= ObjectFlags.CONNECTED
    player.flags ^= ObjectFlags.DARK

    mush.disconnectUser(player.dbref)
Beispiel #2
0
def loadDb(player, args, ex):

    if (player.flags & ObjectFlags.WIZARD):
        mush.load()
        mush.log(
            0, f"{player.name} (#{player.dbref}) kicked off a database load.")
        mush.message(player.dbref, f"database loaded.")
        mush.msgAll(f"{player.name} kicked off a reload of the database.")
    else:
        mush.message(player.dbref,
                     "It is not wise to meddle in the affairs of wizards.")
Beispiel #3
0
def saveDb(player, args, ex):

    if (player.flags & ObjectFlags.WIZARD):
        mush.save()
        mush.message(player.dbref, f"database saved.")
        mush.log(
            0, f"{player.name} (#{player.dbref}) kicked off a database save.")

    else:
        mush.message(player.dbref,
                     "It is not wise to meddle in the affairs of wizards.")
Beispiel #4
0
def kill(player, args, ex):

    if not player.flags & ObjectFlags.WIZARD:
        mush.log(0,
                 f"{player.name} (#{player.dbref}) tried to kill the server.")
        mush.message(player.dbref,
                     "It is dangerous to meddle in the affairs of wizards.")
        return

    mush.messageAll(f"{player.name} killed the server. Goodbye.")
    mush.log(0, f"{player.name} (#{player.dbref}) killed the server.")
    mush.quit()
Beispiel #5
0
def create(player, args, ex):
    args = evalString(args, player.dbref)
    dbref = mush.db.newObject(player)
    mush.db[dbref]["NAME"] = args
    mush.message(player.dbref,
                 f"Object named {args} created with ref #{dbref}.")
    mush.log(
        2,
        f"{player.name}(#{player.dbref}) created object named {args} (#{dbref})."
    )

    return dbref
Beispiel #6
0
def inspectFunctions():
    mushfun = [
        x[3:] for x in dir(gMushFunctions)
        if x[0:3] == "fn_" and x != "fn_notimplemented"
    ]
    e = EvalEngine("", 1, 1)
    notimp = [
        x for x in mushfun if x != "notimplemented" and x != "create"
        and x != "dig" and getattr(gMushFunctions, f"fn_{x}")
        (e, "(1 5,2,3)") == "#-1 Function Not Implemented"
    ]
    prettylist = [
        x if x not in notimp else f"{x}(NOT IMPLEMENTED)" for x in mushfun
    ]

    mush.log(
        1,
        f"MUSH: {len(mushfun)} known mush functions {len(notimp)} are not implemented."
    )
    mush.log(5, f"MUSH: Known functions list is:\n {' '.join(prettylist)}")
Beispiel #7
0
def doDig(player, name, eout, eback):

    # create room.
    dbref = mush.db.newRoom(player)
    mush.db[dbref]["NAME"] = name
    mush.message(player.dbref, f"Room named {name} created with ref #{dbref}.")
    mush.log(
        2, f"{player.name}(#{player.dbref}) dug room named {name} (#{dbref}).")

    if (eout != None):
        dbrefExit = mush.db.newExit(player)
        mush.db[dbrefExit]["NAME"] = eout
        mush.db[dbrefExit].location = dbref
        mush.db[dbrefExit].home = player.location
        mush.db[player.location].contents.append(dbrefExit)
        mush.message(player.dbref,
                     f"Exit named {eout} created with ref #{dbrefExit}.")
        mush.log(
            2,
            f"{player.name}(#{player.dbref}) dug exit named {eout} (#{dbrefExit})."
        )

    if (eback != None):
        dbrefExit = mush.db.newExit(player)
        mush.db[dbrefExit]["NAME"] = eback
        mush.db[dbrefExit].location = player.location
        mush.db[dbrefExit].home = dbref
        mush.db[dbref].contents.append(dbrefExit)
        mush.message(player.dbref,
                     f"Exit named {eback} created with ref #{dbrefExit}.")
        mush.log(
            2,
            f"{player.name}(#{player.dbref}) dug exit named {eback} (#{dbrefExit})."
        )

    return dbref
Beispiel #8
0
def testParse():

    tests = {
        "     abc def ghi": "abc def ghi",
        "add(1,2,3)dog house": "6dog house",
        "abs(add(-1,-5,-6))candy": "12candy",
        "add(-1,-5,-6))candy": "-12)candy",
        "dog was here[add(1,2)]": "dog was here3",
        "[dog was here[add(1,2)]]": "dog was here3",
        "add(dog,1,2,3,4": "10",
        "add(1,2": "3",
        "after(as the world turns,world)": " turns",
        "hello world! [alphamin(zoo,black,orangutang,yes)]":
        "hello world! black",
        "alphamax(dog,zoo,abacus,cat)": "zoo",
        "1": "1",
        "and(0,1)": "0",
        "and(dog,-12,3,#12)": "1",
        "and(dog,-13,3,#-12)": "0",
        "aposs(me)dog": "itsdog",
        "aposs(#1)": "its",
        "art(aardvark) aardvark": "an aardvark",
        "art(doghouse) doghouse": "a doghouse",
        "avg(1 2 3 4 5,6 4 3,2,1 0 0 0 3 4 5 6 7 8)": "3.368421",
        "before(as the world turns,world)": "as the ",
        "can_see(me,here)": "#-1 Function Not Implemented",
        "capstr(hello, world!)": "Hello, world!",
        "cat(hello,world,you,crazy,place!)": "hello world you crazy place!",
        "ceil(64.78)": "65",
        "ceil(64.23)": "65",
        "center(Hello World,40,-)": "--------------Hello World---------------",
        "comp(abc,abc)": "0",
        "comp(Abc,abc)": "-1",
        "comp(abc,Abc)": "1",
        "convsecs(123456)": "Fri Jan  2 02:17:36 1970",
        "create(dog,30)": "#3",  # This is a problem.
        "dec(312)": "311",
        "dec(dog12)": "dog11",
        "dec(dog-1)": "dog-2",
        "default(me/description,so weird)": "The Alpha and Omega.",
        "default(me/yoyo,Not a yoyo here.": "Not a yoyo here.",
        "[delete(abcdefgh, 3, 2)]": "abcfgh",
        "dig(house)": "#4",
        "dig(house,out,in)": "#5",
        "dist2D(1,1,3,3)": "2.828427",
        "dist3D(1,1,1,3,3,3)": "3.464102",
        "div(5,2)": "2",
        "e()": "2.718281",
        "edefault(me/yoyo,so w[e()]ird)": "so w2.718281ird",
        "edit(dog house,dog,cat)": "cat house",
        "edit(dog house,$,cat)": "dog housecat",
        "edit(dog house,^,cat)": "catdog house",
        "elem(this is a test,is, )": "2",
        "element(this|is|a|test,is,|)": "2",
        "elem(this is a test,t?st, )": "4",
        "elements(Foof|Ack|Beep|Moo,3 1,|)": "Beep|Foof",
        "elements(Foo Ack Beep Moo Zot,2 4)": "Ack Moo",
        "emit(foo)": "",
        "enumerate(foo bar)": "foo and bar",
        "enumerate(foo bar baz)": "foo, bar, and baz",
        "enumerate(foo|bar|baz,|,doggie)": "foo, bar, doggie baz",
        "eq(a,b)": "#-1 Arguments must be numbers",
        "eq(1,2,3)": "#-1 Function expects two arguments",
        "eq(2,2)": "1",
        "eq(2,1)": "0",
        "escape(hello world[ dog % ; ] { } hah!)":
        "\\hello world\\[ dog \\% \\; \\] \\{ \\} hah!",
        "eval(me,description)": "The Alpha and Omega.",
        "exp()": "1.0",
        "exp(0)": "1.0",
        "exp(1)": "2.718282",
        "exp(2)": "7.389056",
        "extract(a|b|c|d,2,2,|)": "b|c",
        "extract(a dog in the house went bark,2,4)": "dog in the house",
        "extract(a dog,4,5)": "",
        "first()": "",
        "first(dog house)": "dog",
        "first(dog^house^was,^)": "dog",
        "flip(foo bar baz)": "zab rab oof",
        "floor(23.12)": "23",
        "add(1,1)": "2",
        "foreach(me/addone,123456)": "234567",
        "freeattr(me,test,foo)": "2",
        "fullname(me)": "God",
        "get(me/nothing)": "",
        "get(me/test1foo)": "FOOBAR",
        "grab(dog|cat|horse|mouse|house|help,h*,|)": "horse",
        "graball(dog|cat|horse|mouse|house|help,h*,|)": "horse|house|help",
        "hasattr(dog,cat)": "0",
        "hasattr(me,cat)": "0",
        "hasattr(me,test1foo)": "1",
        "hasflag(me,god)": "1",
        "hasflag(me,eXit)": "0",
        "hastype(me,DOG)": "#-1 Unsupported type.",
        "hastype(me,EXIT)": "0",
        "hastype(me,PLAYER)": "1",
        "home(me)": "#-1",
        "if(dog,true,false)": "true",
        "if(#-12,true,false)": "false",
        "if(-12,true,false)": "true",
        "inc(dog2)": "dog3",
        "inc(dog-1": "dog0",
        "index(a|b|c|d,|,2,2)": "b|c",
        "index(a dog in the house went bark, ,2,4)": "dog in the house",
        "index(a dog, ,4,5)": "",
        "inlist()": "1",
        "inlist(dog)": "0",
        "inlist(a dog was here,not": "0",
        "[inlist(a|dog|was,was,|)]": "1",
        "[insert(This is a string,4,test)]": "This is a test string",
        "[insert(one|three|four|five,2,two,|)]": "one|two|three|four|five",
        "isdbref(#-12)": "0",
        "isdbref(#1)": "1",
        "isnum(dog)": "0",
        "isnum(1)": "1",
        "isnum(-1)": "1",
        "isword(dog)": "1",
        "isword(dog3)": "0",
        "words(a b c d e f)": "6",
        "words(a|b|c|d|e|f,|)": "6",
        "words()": "0",
        "iter(a b c d e f,##)": "a b c d e f",
        "iter(a b c d e f,###@)": "a1 b2 c3 d4 e5 f6",
        "[iter(1|2|3|4|5,add(##,add(##,1)),|)]Hello World!":
        "3 5 7 9 11Hello World!",
        "last(this is the last word)": "word",
        "last(this|is|the|last|word,|": "word",
        "lattr(me)":
        "NAME DESCRIPTION ADDONE ADDBOTH NAMESORT TEST1FOO TEST0FOO",
        "lattr(me/test*)": "TEST1FOO TEST0FOO",
        "lcon(me)": "#3",
        "lcon(here)": "#1 #6",
        "lcstr(Foo BAR bAz)": "foo bar baz",
        "lcstr()": "",
        "loc(me)": "#0",
        "loc()": "#-1",
        "log(12)": "2.484907",
        "lt(12,-1)": "0",
        "lte(3,3)": "1",
        "lwho()": "",
        "map(addone,10 11 12 13 14 15 16)": "11 12 13 14 15 16 17",
        "map(me/addone,1;2;3,;)": "2;3;4",
        "map(me/doesntexist,a b c)": "",
        "match(dog cat bear,cb?)": "0",
        "match(dog cat bear,c?t)": "2",
        "match(dog|cat|bear,b*,|)": "3",
        "matchall(dog|cat|bear|boar|cow|boa,b*,|)": "3 4 6",
        "matchall(dog cat,c?z)": "",
        "max(dog,cat,2,zoo,3)": "3",
        "max(dog,cat)": "0",
        "max()": "0",
        "max(1,1.2)": "1.2",
        "member(dog cat,cat)": "2",
        "member(a|b|c|d,c,|)": "3",
        "mid(dog,dog,dog)": "#-1 Arguments two and three must be integers.",
        "mid(the dog was here,3,10": " dog was h",
        "mid(a,3,4)": "",
        "min(dog,1,-1)": "-1",
        "mix(addboth,1|2|3|4|5,10|9|8|7|6,|)": "11|11|11|11|11",
        "mix(me/addboth,1 2 3,4)": "#-1 Lists must be of equal length",
        "[mod(6,2)]": "0",
        "[mod(5,2)]": "1",
        "[mod(5,add(1,1))]": "1",
        "mudname()": "PynnMush",
        "mul(1,dog,2)": "0",
        "[mul(2,2,2,2,2)]": "32",
        "[mul(1,3,2)]": "6",
        "[mul()]": "0",  # Note: in Pennmush empty returns 1. We change here.
        "name(me)": "God",
        "name(herE)": "Master Room",
        "nearby(me,here)": "1",
        "nearby(9,50)": "0",
        "neq(1,1)": "0",
        "neq(0,1)": "1",
        "not(1)": "0",
        "not(0)": "1",
        "not(dog)": "0",
        "not(#-1)": "1",
        "nwho()": "0",
        "num(me)": "#1",
        "obj(me)": "it",
        "objmem(me)": "28",
        "oemit(here,hello)": "",
        "oemit(me,hello)": "",
        "or(add(0,0))": "0",
        "or(bool(dog))": "1",
        "or()": "0",
        "open(door,#5)": "#8",
        "open(door,#1)": "#-1 Target must be a room.",
        "owner(blag)": "#-1",
        "owner(door)": "#1",
        "pemit(bl,hello)": "I don't see that player here.",
        "pemit(me,hello)": "",
        "playermem(me)": "224",
        "pos(a dog,I saw A DOG and a cat and a dog.)": "26",
        "pos(a dog,a cat)": "#-1",
        "power(2,3)": "8",
        "power(1.2,3.34)": "1.838507",
        "setr(0,hello)[r(0)]": "hellohello",
        "remove(dog dog cat dog dog,dog)": "dog cat dog dog",
        "repeat(hello,3)": "hellohellohello",
        "replace(go south good boy!,2,north)": "go north good boy!",
        "rest(this is the rest)": "is the rest",
        "revwords(this is the test)": "test the is this",
        "revwords(this|is|the|test,|)": "test|the|is|this",
        "right(this is a test,4)": "test",
        "rjust(test,10,#)": "######test",
        "room(me)": "#0",
        "round(1.234,0)": "1",
        "round(1.234,1)": "1.2",
        "savetime()": "Wed Dec 31 16:00:00 1969",
        "setdiff(a f g z c d,z c a)": "d f g",
        "setinter(a b c g h,a b h z)": "a b h",
        "setunion(a|b|c|d,d|e|a|f,|)": "a|b|c|d|e|f",
        "shl(10,1)": "20",
        "shr(10,2)": "2",
        "sign(-5)": "-1",
        "sign(0)": "0",
        "sign(10)": "1",
        "sort(z b a)": "a b z",
        "sort(12 -2 5 7)": "-2 5 7 12",
        "sort(#12 #-2 #5 #7)": "#-2 #5 #7 #12",
        "[sortby(me/namesort,#5 #6 #7 #8)]": "#8 #5 #7 #6",
        "iter(sortby(me/namesort,#5 #6 #7 #8),[name(##)])":
        "door house in out",
        "space(4)": "    ",
        "splice(foo bar baz,eek moof gleep,bar)": "foo moof baz",
        "sqr()": "0",
        "sqr(2)": "4",
        "sqrt(sqr(2))": "2",
        "sqrt(-1)": "#-1 Number cannot be negative.",
        "squish(     dog    was here    )": "dog was here",
        "strcat(foo bar,baz bah)": "foo barbaz bah",
        "strlen(foo)": "3",
        "strmatch(Foo bar baz,*Baz)": "1",
        "strmatch(Foo bar baz,*Foo)": "0",
        "strmatch(Foo bar baz,*o*a*)": "1",
        "sub(1,2)": "-1",
        "sub(2,1)": "1",
        "subj(me)": "it",
        "switch(this is test,*txs*,a b c,*izs*,d e f,No match for #$.)":
        "No match for this is test.",
        "table(a*b*c*d*e*f,8,30,*,|)":
        "       a|       b|       c|\n       d|       e|       f|",
        "timestring(5600)": "0d 1h 33m 20s",
        "[trim(   foo bar baz   eek  )]": "foo bar baz   eek",
        "[trim(***BLAM***,*)]": "BLAM",
        "[trim(-----> WOW---,-,r)]": "-----> WOW",
        "trunc(101Dalmations)": "101",
        "trunc(Dalmations101": "",
        "trunc(10.78)": "10",
        "type(me)": "PLAYER",
        "type(here)": "ROOM",
        "u(me/addboth,u(addone,20),13,14,15)": "34",
        "v(N)": "God",
        "ucstr(this is a test)": "THIS IS A TEST",
        "udefault(me/addcoth,add(%0,%1),u(addone,20),13,14,15)": "34",
        "urlencode(http://this is a test.com":
        "http%3A%2F%2Fthis+is+a+test.com",
        "urldecode(http%3A%2F%2Fthis+is+a+test.com":
        "http://this is a test.com",
        "vadd(1|2|3,4|5|6,|)": "5|7|9",
        "vdim(1|2|3,|)": "3",
        "vdot(1 2 3,2 3 4)": "20",
        "vmul(2,1 2 3)": "2 4 6",
        "vmul(1 2 3,2 3 4)": "2 6 12",
        "version(dog)": "PynnMush 1.02",
        "vmag(3 4)": "5.0",
        "vsub(3 4 5,3 2 1)": "0 2 4",
        "vunit(2 0 0)": "1.0 0.0 0.0",
        "words(this is a test)": "4",
        "xget(me,test1foo)": "FOOBAR",
    }

    mush.db[1]["ADDONE"] = "add(%0,1)"
    mush.db[1]["ADDBOTH"] = "add(%0,%1)"
    mush.db[1]["NAMESORT"] = "[comp(name(%0),name(%1))]"
    mush.db[1]["TEST1FOO"] = "FOOBAR"
    mush.db[1]["TEST0FOO"] = "FOOBAR"

    inspectFunctions()
    mush.log(
        1,
        f"MUSH: running {len(tests.keys())} functional tests on mush functions"
    )

    failed = 0
    succeeded = 0
    for s in tests:
        e = EvalEngine(s, 1, 1)
        val = e.eval("")

        if val != tests[s]:
            failed += 1
            mush.log(
                0,
                f"Test failed! \'{s}\'\n\texpected: \'{tests[s]}\'\n\tactual: \'{val}\'"
            )
        else:
            succeeded += 1
            mush.log(
                5,
                f"Test passed! \'{s}\'\n\texpected: \'{tests[s]}\'\n\tactual: \'{val}\'"
            )

    mush.log(
        1,
        f"MUSH: {succeeded} tests passed and {failed} tests failed on mush functions."
    )