Ejemplo n.º 1
0
def com_use(client, arguments=None):
    # No arguments
    if arguments is None:
        t = MenuStr()
        t.add("Possible options are:")
        t.add("  ^cuse <name>^~ - Take control of a character")
        client.send_cc(t.get())
        return

    # Parse arg1: a character name
    engine = ROBEngine()
    arg1list = []
    for x in engine.getchars():
        arg1list.append(x)
    candidates = expand(arguments, arg1list)[0]
    if len(candidates) == 0:
        t = MenuStr()
        t.add("No such character.  Choices are:")
        for x in arg1list:
            t.add("  ^G{}^~".format(x))
        client.send_cc(t.get())
        return
    else:
        arg1 = candidates[0]
        char = engine.getchar(arg1)
        client.robin["char"] = char
        client.send_cc("Now controlling ^G{}^~.\n".format(char.name))
        return
Ejemplo n.º 2
0
def com_char(client, arguments=None):
    engine = ROBEngine()

    # No arguments - show available characters
    if arguments is None:
        t = MenuStr()
        t.add("  Currently Available Characters:")
        t.add("  -------------------------------")
        chars = engine.getchars()
        if len(chars) == 0:
            t.add("    None")
            t.add()
        else:
            for x in chars:
                char = engine.getchar(x)
                if char.updating:
                    updating = "[Updating]"
                else:
                    updating = ""
                t.add("  ^G{:15}^~ ^R[^C{}^R]^~".format(char.name, char.agent))
                t.add(
                    "  ^gC:{:8} S:{:10} R:{:10}^~ ^r{}^~".format(
                        "{}/{}".format(char.cards, char.maxcards),
                        "{}/{}".format(char.stamina, char.maxstamina),
                        char.rupies,
                        updating,
                    )
                )
                t.add("  ^K?session_id={}&viewer_id={}^~".format(char.session, char.viewer))
                currtime = datetime.datetime.now()
                sincelogon = currtime - char.logontime
                slmin, slsec = divmod(sincelogon.seconds, 60)
                slhr, slmin = divmod(slmin, 60)
                slhr += sincelogon.days * 24
                slstr = "Logon: {:02d}:{:02d}:{:02d} ago".format(slhr, slmin, slsec)
                sinceupdate = currtime - char.lastupdatetime
                sumin, susec = divmod(sinceupdate.seconds, 60)
                suhr, sumin = divmod(sumin, 60)
                suhr += sinceupdate.days * 24
                sustr = "Updated: {:02d}:{:02d}:{:02d} ago".format(suhr, sumin, susec)
                t.add("  {:29}{}".format(slstr, sustr))
                numin, nusec = divmod(char.nextupdate.seconds, 60)
                nustr = "Auto-refresh in: {:02d}:{:02d}".format(numin, nusec)
                t.add("  {:29}".format(nustr))
                t.add()
        t.add("  ^cchar add [adb|<sessionstring>] [sensation|desire]^~ to add characters")
        t.add("  ^cchar delete <name>^~ to remove characters")
        t.add("  ^cchar update [all|<name>]^~ to update character stats")
        t.add("  ^cchar use <name>^~ to take control of a character")
        t.add("  ^cchar [save|load]^~ to save or load characters to/from disk")
        client.send_cc(t.get())
        return

    # Arguments passed. Expand
    # e.g. 'char add sensation adb'
    # 'char': command; 'add': arg1; 'sensation': arg2; etc.
    arg1list = ["add", "delete", "update", "use", "save", "load"]
    candidates, rawarg2 = expand(arguments, arg1list)
    if len(candidates) == 0:
        t = MenuStr()
        t.add("Possible options are:")
        t.add()
        t.add("  ^cchar add [adb|<sessionstring>] [sensation|desire]^~ to add characters")
        t.add("  ^cchar delete <name>^~ to remove characters")
        t.add("  ^cchar update [all|<name>]^~ to update character stats")
        t.add("  ^cchar use <name>^~ to take control of a character")
        t.add("  ^cchar [save|load]^~ to save or load characters to/from disk")
        client.send_cc(t.get())
        return
    elif len(candidates) > 1:
        t = MenuStr()
        t.add("The command ^cchar {}^~ was not specific enough. Did you mean:".format(arguments.split(None, 1)[0]))
        for x in candidates:
            t.add("  ^cchar {}^~".format(x))
        client.send_cc(t.get())
        return
    elif len(candidates) == 1:
        arg1 = candidates[0]

    # Got arg1

    # Add
    if arg1 == "add":
        # Need to parse for arg2(method) and arg3(device)
        # arg2 is taken without modification: it either matches 'adb' exactly, or is treated as a session string
        if rawarg2 is None:
            # No arg2 passed
            t = MenuStr()
            t.add("Possible options are:")
            t.add()
            t.add("  ^cchar add adb [sensation|desire]^~")
            t.add("  Look for recent sessions over ADB, use [sensation|desire] headers.")
            t.add()
            t.add("  ^cchar add <sessionstring> [sensation|desire]^~")
            t.add("  Add a character using <sessionstring>, use [sensation|desire] headers.")
            t.add("  (?session_id=<session>&viewer_id=<viewer>)")
            t.add()
            t.add("You must ensure the headers chosen match the device used to start the session.")
            client.send_cc(t.get())
            return

        rawarg2 = rawarg2.split(None, 1)
        arg2 = rawarg2[0]

        # Parse rawarg3
        if len(rawarg2) == 1:
            # No arg3 passed
            t = MenuStr()
            t.add("Possible options are:")
            t.add()
            if arg2 == "adb":
                t.add("  ^cchar add adb [sensation|desire]^~")
                t.add("  Look for recent sessions over ADB, use [sensation|desire] headers.")
            else:
                t.add("  ^cchar add <sessionstring> [sensation|desire]^~")
                t.add("  Add a character using <sessionstring>, use [sensation|desire] headers.")
                t.add("  (^K?session_id=<session>&viewer_id=<viewer>^~)")
            t.add()
            t.add("You must ensure the headers chosen match the device used to start the session.")
            client.send_cc(t.get())
            return

        rawarg3 = rawarg2[1]
        arg3list = ["sensation", "desire"]
        candidates = expand(rawarg3, arg3list)[0]
        if len(candidates) == 0 or len(candidates) > 1:
            t = MenuStr()
            t.add("Possible options are:")
            t.add()
            if arg2 == "adb":
                t.add("  ^cchar add adb [sensation|desire]^~")
                t.add("  Look for recent sessions over ADB, use [sensation|desire] headers.")
            else:
                t.add("  ^cchar add <sessionstring> [sensation|desire]^~")
                t.add("  Add a character using <sessionstring>, use [sensation|desire] headers.")
                t.add("  (^K?session_id=<session>&viewer_id=<viewer>^~)")
            t.add()
            t.add("You must ensure the headers chosen match the device used to start the session.")
            client.send_cc(t.get())
            return
        else:
            arg3 = candidates[0]

        # If we're still here, add a character using the options given
        t = engine.addchar(arg2, arg3)
        if t == "CANCELLED":
            client.send("Character add cancelled by server.\n")
        elif t == "FAILED":
            client.send("No recent sessions found over ADB.\n")
        elif t == "MAINTENANCE":
            client.send("ROB Servers undergoing maintenance.\n")
        else:
            client.send_cc("Successfully added [^G{}^~] with ^R[^C{}^R]^~ headers\n".format(t, arg3))
        return

    # Delete char
    if arg1 == "delete":
        if rawarg2 is None:
            # No arg2
            t = MenuStr()
            t.add("Possible options are:")
            t.add("  ^cchar delete <name>^~    - Remove a character from the character list")
            t.add()
            t.add("Available characters:")
            for x in engine.getchars():
                t.add("  ^G{}^~".format(x))
            client.send_cc(t.get())
            return

        # Parse arg2: a character name
        arg2list = []
        for x in engine.getchars():
            arg2list.append(x)
        candidates = expand(rawarg2, arg2list)[0]
        if len(candidates) == 0:
            t = MenuStr()
            t.add("No such character.  Choices are:")
            for x in arg2list:
                t.add("  ^G{}^~".format(x))
            client.send_cc(t.get())
            return
        else:
            arg2 = candidates[0]
            char = engine.getchar(arg2)
            if client.robin["char"] == char:
                client.robin["char"] = None
            engine.delchar(arg2)
            client.send_cc("Removed ^G{}^~ from character list.\n".format(char.name))
            return

    if arg1 == "update":
        # Parse arg2: either 'all' or a character name
        if rawarg2 is None:
            # No arg2
            t = MenuStr()
            t.add("Possible options are:")
            t.add("  ^cchar update all^~    - Manually update all characters (SLOW)")
            t.add("  ^cchar update <name>^~ - Manually update a character")
            t.add()
            t.add("Available characters:")
            for x in engine.getchars():
                t.add("  ^G{}^~".format(x))
            client.send_cc(t.get())
            return

        arg2list = ["all"]
        for x in engine.getchars():
            arg2list.append(x)
        candidates = expand(rawarg2, arg2list)[0]
        if len(candidates) == 0:
            t = MenuStr()
            """
            t.add("Possible options are:")
            t.add("  ^cchar update all^~    - Manually update all characters (SLOW)")
            t.add("  ^cchar update <name>^~ - Manually update a character")
            """
            t.add("No such character.  Choices are:")
            t.add("  ^call^~")
            for x in engine.getchars():
                t.add("  ^G{}^~".format(x))
            client.send_cc(t.get())
            return
        elif len(candidates) > 1:
            t = MenuStr()
            t.add(
                "The command ^cchar update {}^~ was not specific enough. Did you mean:".format(
                    rawarg2.split(None, 1)[0]
                )
            )
            for x in candidates:
                t.add("  ^cchar update {}^~".format(x))
            client.send_cc(t.get())
            return
        else:
            arg2 = candidates[0]
            if arg2 == "all":
                client.send("Not implemented. Please specify a character name.\n")
                return
            else:
                char = engine.getchar(arg2)
                char.update()
            client.send("Stats updated.\n")
            return

    if arg1 == "use":
        if rawarg2 is None:
            # No arg2
            t = MenuStr()
            t.add("Possible options are:")
            t.add("  ^cchar use <name>^~ - Take control of a character")
            t.add()
            t.add("Available characters:")
            for x in engine.getchars():
                t.add("  ^G{}^~".format(x))
            client.send_cc(t.get())
            return

        # Parse arg2: a character name
        arg2list = []
        for x in engine.getchars():
            arg2list.append(x)
        candidates = expand(rawarg2, arg2list)[0]
        if len(candidates) == 0:
            t = MenuStr()
            t.add("No such character.  Choices are:")
            for x in arg2list:
                t.add("  ^G{}^~".format(x))
            client.send_cc(t.get())
            return
        else:
            arg2 = candidates[0]
            char = engine.getchar(arg2)
            client.robin["char"] = char
            client.send_cc("Now controlling ^G{}^~.\n".format(char.name))
            return

    # Save/Load
    if arg1 == "save":
        engine.savechars()
        client.send("Characters saved.\n")
        return
    if arg1 == "load":
        t = engine.loadchars()
        client.send_cc(t)
        return