Example #1
0
 def call(self, cmdobj, args, msg=None, cmdset=None, noansi=True):
     """
     Test a command by assigning all the needed
     properties to cmdobj and  running
         cmdobj.at_pre_cmd()
         cmdobj.parse()
         cmdobj.func()
         cmdobj.at_post_cmd()
     The msgreturn value is compared to eventual
     output sent to caller.msg in the game
     """
     cmdobj.caller = self.char1
     cmdobj.cmdstring = cmdobj.key
     cmdobj.args = args
     cmdobj.cmdset = cmdset
     cmdobj.raw_string = cmdobj.key + " " + args
     cmdobj.obj = self.char1
     cmdobj.sessid = 1
     # test
     self.char1.player.ndb.stored_msg = []
     cmdobj.at_pre_cmd()
     cmdobj.parse()
     cmdobj.func()
     cmdobj.at_post_cmd()
     # clean out prettytable sugar
     returned_msg = "|".join(_RE.sub("", mess) for mess in self.char1.player.ndb.stored_msg)
     #returned_msg = "|".join(self.char1.player.ndb.stored_msg)
     returned_msg = ansi.parse_ansi(returned_msg, strip_ansi=noansi).strip()
     if msg != None:
         if msg == "" and returned_msg or not returned_msg.startswith(msg.strip()):
             sep1 = "\n" + "="*30 + "Wanted message" + "="*34 + "\n"
             sep2 = "\n" + "="*30 + "Returned message" + "="*32 + "\n"
             sep3 = "\n" + "="*78
             retval = sep1 + msg.strip() + sep2 + returned_msg + sep3
             raise AssertionError(retval)
Example #2
0
from src.players.models import PlayerDB
from src.objects.models import ObjectDB
from src.server.models import ServerConfig
from src.comms.models import Channel

from src.utils import create, logger, utils, ansi
from src.commands.default.muxcommand import MuxCommand
from src.commands.cmdhandler import CMD_LOGINSTART

# limit symbol import for API
__all__ = ("CmdUnconnectedConnect", "CmdUnconnectedCreate", "CmdUnconnectedQuit", "CmdUnconnectedLook", "CmdUnconnectedHelp", "Magic")

CONNECTION_SCREEN_MODULE = settings.CONNECTION_SCREEN_MODULE
CONNECTION_SCREEN = ""
try:
    CONNECTION_SCREEN = ansi.parse_ansi(utils.string_from_module(CONNECTION_SCREEN_MODULE))
except Exception:
    pass
if not CONNECTION_SCREEN:
    CONNECTION_SCREEN = "\nEvennia: Error in CONNECTION_SCREEN MODULE (randomly picked connection screen variable is not a string). \nEnter 'help' for aid."

class Magic(MuxCommand):
    """
    Hidden command for the web client's magic cookie authenticator.
    """
    key = "magic"
    def func(self):
        session = self.caller
        player = PlayerDB.objects.player_search(self.lhs)
        if len(player) != 1:
            player = None
Example #3
0
def parse_ansi(*args, **kwargs):
    """
    Shortcut to use the IMC2 ANSI parser.
    """
    return ansi.parse_ansi(parser=IMCANSIParser(), *args, **kwargs)
Example #4
0
                    #print "cmdname, args, kwargs:", cmdname, args, kwargs
                    msdp_string = self.msdp.evennia_to_msdp(cmdname, *args, **kwargs)
                    #print "msdp_string:", msdp_string
                    self.msdp.data_out(msdp_string)

        # parse **kwargs, falling back to ttype if nothing is given explicitly
        ttype = self.protocol_flags.get('TTYPE', {})
        xterm256 = kwargs.get("xterm256", ttype.get('256 COLORS', False) if ttype.get("init_done") else True)
        useansi = kwargs.get("ansi", ttype and ttype.get('ANSI', False) if ttype.get("init_done") else True)
        raw = kwargs.get("raw", False)
        nomarkup = kwargs.get("nomarkup", not (xterm256 or useansi))
        prompt = kwargs.get("prompt")

        if prompt:
            # Send prompt separately
            prompt = ansi.parse_ansi(_RE_N.sub("", text) + "{n", strip_ansi=nomarkup, xterm256=xterm256)
            prompt = prompt.replace(IAC, IAC + IAC).replace('\n', '\r\n')
            prompt += IAC + GA
            self.transport.write(mccp_compress(self, prompt))

        #print "telnet kwargs=%s, message=%s" % (kwargs, text)
        #print "xterm256=%s, useansi=%s, raw=%s, nomarkup=%s, init_done=%s" % (xterm256, useansi, raw, nomarkup, ttype.get("init_done"))
        if raw:
            # no processing whatsoever
            self.sendLine(text)
        else:
            # we need to make sure to kill the color at the end in order
            # to match the webclient output.
            #print "telnet data out:", self.protocol_flags, id(self.protocol_flags), id(self), "nomarkup: %s, xterm256: %s" % (nomarkup, xterm256)
            self.sendLine(ansi.parse_ansi(_RE_N.sub("", text) + "{n", strip_ansi=nomarkup, xterm256=xterm256))
Example #5
0
        raw = kwargs.get("raw", False)
        nomarkup = kwargs.get("nomarkup", not (xterm256 or useansi))
        prompt = kwargs.get("prompt")
        echo = kwargs.get("echo", None)
        mxp = kwargs.get("mxp", self.protocol_flags.get("MXP", False))

        #print "telnet kwargs=%s, message=%s" % (kwargs, text)
        #print "xterm256=%s, useansi=%s, raw=%s, nomarkup=%s, init_done=%s" % (xterm256, useansi, raw, nomarkup, ttype.get("init_done"))
        if raw:
            # no processing whatsoever
            self.sendLine(text)
        elif text:
            # we need to make sure to kill the color at the end in order
            # to match the webclient output.
            #print "telnet data out:", self.protocol_flags, id(self.protocol_flags), id(self), "nomarkup: %s, xterm256: %s" % (nomarkup, xterm256)
            linetosend = ansi.parse_ansi(_RE_N.sub("", text) + "{n", strip_ansi=nomarkup, xterm256=xterm256, mxp=mxp)
            if mxp:
                linetosend = mxp_parse(linetosend)
            self.sendLine(linetosend)

        if prompt:
            # Send prompt separately
            prompt = ansi.parse_ansi(_RE_N.sub("", prompt) + "{n", strip_ansi=nomarkup, xterm256=xterm256)
            prompt = prompt.replace(IAC, IAC + IAC).replace('\n', '\r\n')
            prompt += IAC + GA
            self.transport.write(mccp_compress(self, prompt))
        if echo:
            self.transport.write(mccp_compress(self, IAC+WONT+ECHO))
        elif echo == False:
            self.transport.write(mccp_compress(self, IAC+WILL+ECHO))