Ejemplo n.º 1
0
    def setUp(self):
        """
        Sets up testing environment
        """
        self.player = create.create_player("TestPlayer", email="*****@*****.**", password="******", typeclass=self.player_typeclass)
        self.player2 = create.create_player("TestPlayer2", email="*****@*****.**", password="******", typeclass=self.player_typeclass)
        self.room1 = create.create_object(self.room_typeclass, key="Room", nohome=True)
        self.room1.db.desc = "room_desc"
        settings.DEFAULT_HOME = "#%i" % self.room1.id  # we must have a default home
        self.room2 = create.create_object(self.room_typeclass, key="Room2")
        self.exit = create.create_object(self.exit_typeclass, key='out', location=self.room1, destination=self.room2)
        self.obj1 = create.create_object(self.object_typeclass, key="Obj", location=self.room1, home=self.room1)
        self.obj2 = create.create_object(self.object_typeclass, key="Obj2", location=self.room1, home=self.room1)
        self.char1 = create.create_object(self.character_typeclass, key="Char", location=self.room1, home=self.room1)
        self.char1.permissions.add("Immortals")
        self.char2 = create.create_object(self.character_typeclass, key="Char2", location=self.room1, home=self.room1)
        self.char1.player = self.player
        self.player.db._last_puppet = self.char1
        self.char2.player = self.player2
        self.player2.db._last_puppet = self.char2
        self.script = create.create_script(self.script_typeclass, key="Script")
        self.player.permissions.add("Immortals")

        # set up a fake session

        session = ServerSession()
        session.init_session("telnet", ("localhost", "testmode"), SESSIONS)
        session.sessid = 1
        SESSIONS.portal_connect(session.get_sync_data())
        SESSIONS.login(SESSIONS.session_from_sessid(1), self.player, testmode=True)
        self.session = session
Ejemplo n.º 2
0
    def setUp(self):
        """
        Sets up testing environment
        """
        self.player = create.create_player("TestPlayer", email="*****@*****.**", password="******", typeclass=self.player_typeclass)
        self.player2 = create.create_player("TestPlayer2", email="*****@*****.**", password="******", typeclass=self.player_typeclass)
        self.room1 = create.create_object(self.room_typeclass, key="Room", nohome=True)
        self.room1.db.desc = "room_desc"
        settings.DEFAULT_HOME = "#%i" % self.room1.id  # we must have a default home
        self.room2 = create.create_object(self.room_typeclass, key="Room2")
        self.exit = create.create_object(self.exit_typeclass, key='out', location=self.room1, destination=self.room2)
        self.obj1 = create.create_object(self.object_typeclass, key="Obj", location=self.room1, home=self.room1)
        self.obj2 = create.create_object(self.object_typeclass, key="Obj2", location=self.room1, home=self.room1)
        self.char1 = create.create_object(self.character_typeclass, key="Char", location=self.room1, home=self.room1)
        self.char1.permissions.add("Immortals")
        self.char2 = create.create_object(self.character_typeclass, key="Char2", location=self.room1, home=self.room1)
        self.char1.player = self.player
        self.player.db._last_puppet = self.char1
        self.char2.player = self.player2
        self.player2.db._last_puppet = self.char2
        self.script = create.create_script(self.script_typeclass, key="Script")
        self.player.permissions.add("Immortals")

        # set up a fake session

        dummysession = ServerSession()
        dummysession.init_session("telnet", ("localhost", "testmode"), SESSIONS)
        dummysession.sessid = 1
        SESSIONS.portal_connect(dummysession.get_sync_data()) # note that this creates a new Session!
        session = SESSIONS.session_from_sessid(1) # the real session
        SESSIONS.login(session, self.player, testmode=True)
        self.session = session
Ejemplo n.º 3
0
def _create_player(session, playername, password, permissions, typeclass=None):
    """
    Helper function, creates a player of the specified typeclass.
    """
    try:
        new_player = create.create_player(playername,
                                          None,
                                          password,
                                          permissions=permissions,
                                          typeclass=typeclass)

    except Exception as e:
        session.msg(
            "There was an error creating the Player:\n%s\n If this problem persists, contact an admin."
            % e)
        logger.log_trace()
        return False

    # This needs to be set so the engine knows this player is
    # logging in for the first time. (so it knows to call the right
    # hooks during login later)
    new_player.db.FIRST_LOGIN = True

    # join the new player to the public channel
    pchannel = ChannelDB.objects.get_channel(
        settings.DEFAULT_CHANNELS[0]["key"])
    if not pchannel.connect(new_player):
        string = "New player '%s' could not connect to public channel!" % new_player.key
        logger.log_err(string)
    return new_player
Ejemplo n.º 4
0
def create_player(playername, password, permissions=None, typeclass=None):
    """
    Helper function, creates a player of the specified typeclass.
    """
    if not permissions:
        permissions = settings.PERMISSION_PLAYER_DEFAULT

    new_player = create.create_player(playername,
                                      None,
                                      password,
                                      permissions=permissions,
                                      typeclass=typeclass)

    # This needs to be set so the engine knows this player is
    # logging in for the first time. (so it knows to call the right
    # hooks during login later)
    new_player.db.FIRST_LOGIN = True

    # join the new player to the public channel
    pchannel = ChannelDB.objects.get_channel(
        settings.DEFAULT_CHANNELS[0]["key"])
    if not pchannel.connect(new_player):
        string = "New player '%s' could not connect to public channel!" % new_player.key
        logger.log_err(string)

    return new_player
Ejemplo n.º 5
0
 def func(self):
     foobar = create.create_player("TestPlayer4", email="*****@*****.**", password="******",
                                   typeclass=settings.BASE_PLAYER_TYPECLASS)
     foobar.db.FIRST_LOGIN = True
     self.msg("%s" % foobar)
     unloggedin._create_character(self, foobar, settings.BASE_CHARACTER_TYPECLASS, settings.DEFAULT_HOME,
                                  settings.PERMISSION_PLAYER_DEFAULT)
Ejemplo n.º 6
0
 def func(self):
     foobar = create.create_player("TestPlayer4",
                                   email="*****@*****.**",
                                   password="******",
                                   typeclass=settings.BASE_PLAYER_TYPECLASS)
     foobar.db.FIRST_LOGIN = True
     self.msg("%s" % foobar)
     unloggedin._create_character(self, foobar,
                                  settings.BASE_CHARACTER_TYPECLASS,
                                  settings.DEFAULT_HOME,
                                  settings.PERMISSION_PLAYER_DEFAULT)
Ejemplo n.º 7
0
def _create_player(session, playername, password, permissions, typeclass=None):
    """
    Helper function, creates a player of the specified typeclass.
    """
    try:
        new_player = create.create_player(playername, None, password,
                                          permissions=permissions, typeclass=typeclass)

    except Exception, e:
        session.msg("There was an error creating the Player:\n%s\n If this problem persists, contact an admin." % e)
        logger.log_trace()
        return False
Ejemplo n.º 8
0
    def test_cat_db_holder(self):
        player = create.create_player("CatDbPlayer",
                                      email="*****@*****.**",
                                      password="******",
                                      typeclass=CatDbPlayer)

        expected = "What happen!!!"
        player.attributes.add("record", expected, category="Logs")
        self.assertEqual(expected, player.logs.record)

        expected = "Someone set up us the bomb!!!"
        player.attributes.add("result", expected, category="Ledgers")
        self.assertEqual(expected, player.ldb.result)
Ejemplo n.º 9
0
 def switch_accounts(self):
     char_typeclass = settings.BASE_CHARACTER_TYPECLASS
     accounts = cobj(abbr='accounts').children.all()
     for acc_obj in sorted(accounts, key=lambda acc: int(acc.name.split(' ')[1])):
         name = 'MushAcc %s' % acc_obj.name.split(' ')[1]
         password = str(random.randrange(5000000,1000000000))
         email = acc_obj.mushget('email') or None
         new_player = create.create_player(name, email, password)
         new_player.db._import_ready = True
         new_player.db._reset_username = True
         if new_player.email == '*****@*****.**':
             new_player.db._reset_email = True
         objids = acc_obj.mushget('characters').split(' ')
         mush_chars = MushObject.objects.filter(objid__in=objids)
         for char in mush_chars:
             new_char = create.create_object(typeclass=char_typeclass, key=char.name)
             new_char.db.prelogout_location = char.location.obj
             char.obj = new_char
             char.save(update_fields=['obj'])
             new_player.bind_character(new_char)
             new_char.db._import_ready = True
     unbound = MushObject.objects.filter(type=8, obj=None)
     if unbound:
         name = 'Lost and Found'
         password = str(random.randrange(5000000,1000000000))
         email = None
         new_player = create.create_player(name, email, password)
         new_player.db._lost_and_found = True
         for char in unbound:
             new_char = create.create_object(typeclass=char_typeclass, key=char.name)
             new_char.db.prelogout_location = char.location.obj
             char.obj = new_char
             char.save(update_fields=['obj'])
             new_player.bind_character(new_char)
             new_char.db._import_ready = True
     self.sys_msg("Finished importing characters!")
Ejemplo n.º 10
0
def _create_player(session, playername, password, permissions, typeclass=None):
    """
    Helper function, creates a player of the specified typeclass.
    """
    try:
        new_player = create.create_player(playername,
                                          None,
                                          password,
                                          permissions=permissions,
                                          typeclass=typeclass)

    except Exception, e:
        session.msg(
            "There was an error creating the Player:\n%s\n If this problem persists, contact an admin."
            % e)
        logger.log_trace()
        return False
Ejemplo n.º 11
0
def _create_player(session, playername, password, permissions, typeclass=None, email=None):
    """
    Helper function, creates a player of the specified typeclass.
    """
    try:
        new_player = create.create_player(playername, email, password, permissions=permissions, typeclass=typeclass)

    except Exception as e:
        session.msg("There was an error creating the Player:\n%s\n If this problem persists, contact an admin." % e)
        logger.log_trace()
        return False

    # This needs to be set so the engine knows this player is
    # logging in for the first time. (so it knows to call the right
    # hooks during login later)
    new_player.db.FIRST_LOGIN = True

    # join the new player to the public channel
    pchannel = ChannelDB.objects.get_channel(settings.DEFAULT_CHANNELS[0]["key"])
    if not pchannel or not pchannel.connect(new_player):
        string = "New player '%s' could not connect to public channel!" % new_player.key
        logger.log_err(string)
    return new_player
Ejemplo n.º 12
0
    def func(self):
        "Setup the rss-channel mapping"

        # checking we have all we need
        if not settings.RSS_ENABLED:
            string = """RSS is not enabled. You need to activate it in game/settings.py."""
            self.msg(string)
            return
        try:
            import feedparser
            feedparser  # to avoid checker error of not being used
        except ImportError:
            string = (
                "RSS requires python-feedparser (https://pypi.python.org/pypi/feedparser). "
                "Install before continuing.")
            self.msg(string)
            return

        if 'list' in self.switches:
            # show all connections
            rssbots = [
                bot for bot in PlayerDB.objects.filter(
                    db_is_bot=True, username__startswith="rssbot-")
            ]
            if rssbots:
                from evennia.utils.evtable import EvTable
                table = EvTable("{wdbid{n",
                                "{wupdate rate{n",
                                "{wev-channel",
                                "{wRSS feed URL{n",
                                border="cells",
                                maxwidth=_DEFAULT_WIDTH)
                for rssbot in rssbots:
                    table.add_row(rssbot.id, rssbot.db.rss_rate,
                                  rssbot.db.ev_channel, rssbot.db.rss_url)
                self.caller.msg(table)
            else:
                self.msg("No rss bots found.")
            return

        if ('disconnect' in self.switches or 'remove' in self.switches
                or 'delete' in self.switches):
            botname = "rssbot-%s" % self.lhs
            matches = PlayerDB.objects.filter(db_is_bot=True, db_key=botname)
            if not matches:
                # try dbref match
                matches = PlayerDB.objects.filter(db_is_bot=True,
                                                  id=self.args.lstrip("#"))
            if matches:
                matches[0].delete()
                self.msg("RSS connection destroyed.")
            else:
                self.msg(
                    "RSS connection/bot could not be removed, does it exist?")
            return

        if not self.args or not self.rhs:
            string = "Usage: @rss2chan[/switches] <evennia_channel> = <rss url>"
            self.msg(string)
            return
        channel = self.lhs
        url = self.rhs

        botname = "rssbot-%s" % url
        # create a new bot
        bot = PlayerDB.objects.filter(username__iexact=botname)
        if bot:
            # re-use existing bot
            bot = bot[0]
            if not bot.is_bot:
                self.msg("Player '%s' already exists and is not a bot." %
                         botname)
                return
        else:
            bot = create.create_player(botname,
                                       None,
                                       None,
                                       typeclass=bots.RSSBot)
        bot.start(ev_channel=channel, rss_url=url, rss_rate=10)
        self.msg("RSS reporter created. Fetching RSS.")
Ejemplo n.º 13
0
    def func(self):
        "Setup the irc-channel mapping"

        if not settings.IRC_ENABLED:
            string = """IRC is not enabled. You need to activate it in game/settings.py."""
            self.msg(string)
            return

        if 'list' in self.switches:
            # show all connections
            ircbots = [
                bot for bot in PlayerDB.objects.filter(
                    db_is_bot=True, username__startswith="ircbot-")
            ]
            if ircbots:
                from evennia.utils.evtable import EvTable
                table = EvTable("{wdbid{n",
                                "{wbotname{n",
                                "{wev-channel{n",
                                "{wirc-channel{n",
                                "{wSSL{n",
                                maxwidth=_DEFAULT_WIDTH)
                for ircbot in ircbots:
                    ircinfo = "%s (%s:%s)" % (ircbot.db.irc_channel,
                                              ircbot.db.irc_network,
                                              ircbot.db.irc_port)
                    table.add_row(ircbot.id, ircbot.db.irc_botname,
                                  ircbot.db.ev_channel, ircinfo,
                                  ircbot.db.irc_ssl)
                self.caller.msg(table)
            else:
                self.msg("No irc bots found.")
            return

        if ('disconnect' in self.switches or 'remove' in self.switches
                or 'delete' in self.switches):
            botname = "ircbot-%s" % self.lhs
            matches = PlayerDB.objects.filter(db_is_bot=True, username=botname)
            dbref = utils.dbref(self.lhs)
            if not matches and dbref:
                # try dbref match
                matches = PlayerDB.objects.filter(db_is_bot=True, id=dbref)
            if matches:
                matches[0].delete()
                self.msg("IRC connection destroyed.")
            else:
                self.msg(
                    "IRC connection/bot could not be removed, does it exist?")
            return

        if not self.args or not self.rhs:
            string = "Usage: @irc2chan[/switches] <evennia_channel> = <ircnetwork> <port> <#irchannel> <botname>"
            self.msg(string)
            return

        channel = self.lhs
        self.rhs = self.rhs.replace('#', ' ')  # to avoid Python comment issues
        try:
            irc_network, irc_port, irc_channel, irc_botname = \
                       [part.strip() for part in self.rhs.split(None, 3)]
            irc_channel = "#%s" % irc_channel
        except Exception:
            string = "IRC bot definition '%s' is not valid." % self.rhs
            self.msg(string)
            return

        botname = "ircbot-%s" % irc_botname
        irc_ssl = "ssl" in self.switches

        # create a new bot
        bot = PlayerDB.objects.filter(username__iexact=botname)
        if bot:
            # re-use an existing bot
            bot = bot[0]
            if not bot.is_bot:
                self.msg("Player '%s' already exists and is not a bot." %
                         botname)
                return
        else:
            bot = create.create_player(botname,
                                       None,
                                       None,
                                       typeclass=bots.IRCBot)
        bot.start(ev_channel=channel,
                  irc_botname=irc_botname,
                  irc_channel=irc_channel,
                  irc_network=irc_network,
                  irc_port=irc_port,
                  irc_ssl=irc_ssl)
        self.msg("Connection created. Starting IRC bot.")
Ejemplo n.º 14
0
    def func(self):
        session = self.caller

        # check for too many login errors too quick.
        if _throttle(session, maxlim=5, timeout=5*60, storage=_LATEST_FAILED_LOGINS):
            # timeout is 5 minutes.
            session.msg("{RYou made too many connection attempts. Try again in a few minutes.{n")
            return

        args = self.args
        # extract quoted parts
        parts = [part.strip() for part in re.split(r"\"|\'", args) if part.strip()]
        if len(parts) == 1:
            # this was (hopefully) due to no quotes being found, or a guest login
            parts = parts[0].split(None, 1)
            # Guest login
            if len(parts) == 1 and parts[0].lower() == "guest" and settings.GUEST_ENABLED:
                session.msg("Guest logins through old import are not allowed.")
                return

        if len(parts) != 2:
            session.msg("\n\r Usage (without <>): connect <name> <password>")
            return
        playername, password = parts

        # Match old character name and check password
        char = Character.objects.filter_family(db_key__iexact=playername).first()
        if not char:
            session.msg("Character not found.")
            return
        old_char = char.mush
        if not old_char:
            session.msg("Character has no old data!")
            return
        player = char.db._owner
        if not player:
            session.msg("Character is not bound to a valid account.")
            return
        if not old_char.check_password(password):
            session.msg("Invalid password.")
            _throttle(session, storage=_LATEST_FAILED_LOGINS)
            return
        if not char.db._import_ready:
            session.msg("Character has already been imported or was not originally from PennMUSH. Contact an admin\nif this is in error.")
            return
        if player.db._lost_and_found:
            session.msg("Credentials accepted. Character is in the Lost and Found.\nCreating a new account for them.")
            create_name = unicode(float(time.time())).replace('.', '-')
            new_player = create_player(create_name, email=None, password=password)
            new_player.db._was_lost = True
            new_player.db._reset_email = True
            new_player.db._reset_username = True
            new_player.bind_character(char)
            session.msg("Your temporary account name is: %s" % create_name)
            session.msg("Account created, using your PennMUSH password.")
        else:
            session.msg("Credentials accepted. You can now login to this account with the given password.\nPlease set your username and email with the listed commands.")
            new_player = player
            new_player.set_password(password)
        session.msg("Import process complete!")
        for character in new_player.get_all_characters():
            del character.db._import_ready
        session.sessionhandler.login(session, new_player)
Ejemplo n.º 15
0
    def func(self):
        "Setup the rss-channel mapping"

        # checking we have all we need
        if not settings.RSS_ENABLED:
            string = """RSS is not enabled. You need to activate it in game/settings.py."""
            self.msg(string)
            return
        try:
            import feedparser
            feedparser   # to avoid checker error of not being used
        except ImportError:
            string = ("RSS requires python-feedparser (https://pypi.python.org/pypi/feedparser). "
                      "Install before continuing.")
            self.msg(string)
            return

        if 'list' in self.switches:
            # show all connections
            rssbots = [bot for bot in PlayerDB.objects.filter(db_is_bot=True, username__startswith="rssbot-")]
            if rssbots:
                from evennia.utils.evtable import EvTable
                table = EvTable("{wdbid{n", "{wupdate rate{n", "{wev-channel",
                                "{wRSS feed URL{n", border="cells", maxwidth=_DEFAULT_WIDTH)
                for rssbot in rssbots:
                    table.add_row(rssbot.id, rssbot.db.rss_rate, rssbot.db.ev_channel, rssbot.db.rss_url)
                self.caller.msg(table)
            else:
                self.msg("No rss bots found.")
            return

        if('disconnect' in self.switches or 'remove' in self.switches or
                                                    'delete' in self.switches):
            botname = "rssbot-%s" % self.lhs
            matches = PlayerDB.objects.filter(db_is_bot=True, db_key=botname)
            if not matches:
                # try dbref match
                matches = PlayerDB.objects.filter(db_is_bot=True, id=self.args.lstrip("#"))
            if matches:
                matches[0].delete()
                self.msg("RSS connection destroyed.")
            else:
                self.msg("RSS connection/bot could not be removed, does it exist?")
            return

        if not self.args or not self.rhs:
            string = "Usage: @rss2chan[/switches] <evennia_channel> = <rss url>"
            self.msg(string)
            return
        channel = self.lhs
        url = self.rhs

        botname = "rssbot-%s" % url
        # create a new bot
        bot = PlayerDB.objects.filter(username__iexact=botname)
        if bot:
            # re-use existing bot
            bot = bot[0]
            if not bot.is_bot:
                self.msg("Player '%s' already exists and is not a bot." % botname)
                return
        else:
            bot = create.create_player(botname, None, None, typeclass=bots.RSSBot)
        bot.start(ev_channel=channel, rss_url=url, rss_rate=10)
        self.msg("RSS reporter created. Fetching RSS.")
Ejemplo n.º 16
0
def player(key, password, email=None):
    return create_player(key, email, password)
Ejemplo n.º 17
0
    def func(self):
        """Setup the irc-channel mapping"""

        if not settings.IRC_ENABLED:
            string = """IRC is not enabled. You need to activate it in game/settings.py."""
            self.msg(string)
            return

        if 'list' in self.switches:
            # show all connections
            self.msg(_list_bots())
            return

        if 'disconnect' in self.switches or 'remove' in self.switches or 'delete' in self.switches:
            botname = "ircbot-%s" % self.lhs
            matches = PlayerDB.objects.filter(db_is_bot=True, username=botname)
            dbref = utils.dbref(self.lhs)
            if not matches and dbref:
                # try dbref match
                matches = PlayerDB.objects.filter(db_is_bot=True, id=dbref)
            if matches:
                matches[0].delete()
                self.msg("IRC connection destroyed.")
            else:
                self.msg("IRC connection/bot could not be removed, does it exist?")
            return

        if not self.args or not self.rhs:
            string = "Usage: @irc2chan[/switches] <evennia_channel> =" \
                     " <ircnetwork> <port> <#irchannel> <botname>[:typeclass]"
            self.msg(string)
            return

        channel = self.lhs
        self.rhs = self.rhs.replace('#', ' ')  # to avoid Python comment issues
        try:
            irc_network, irc_port, irc_channel, irc_botname = \
                       [part.strip() for part in self.rhs.split(None, 4)]
            irc_channel = "#%s" % irc_channel
        except Exception:
            string = "IRC bot definition '%s' is not valid." % self.rhs
            self.msg(string)
            return

        botclass = None
        if ":" in irc_botname:
            irc_botname, botclass = [part.strip() for part in irc_botname.split(":", 2)]
        botname = "ircbot-%s" % irc_botname
        # If path given, use custom bot otherwise use default.
        botclass = botclass if botclass else bots.IRCBot
        irc_ssl = "ssl" in self.switches

        # create a new bot
        bot = PlayerDB.objects.filter(username__iexact=botname)
        if bot:
            # re-use an existing bot
            bot = bot[0]
            if not bot.is_bot:
                self.msg("Player '%s' already exists and is not a bot." % botname)
                return
        else:
            try:
                bot = create.create_player(botname, None, None, typeclass=botclass)
            except Exception as err:
                self.msg("|rError, could not create the bot:|n '%s'." % err)
                return
        bot.start(ev_channel=channel, irc_botname=irc_botname, irc_channel=irc_channel,
                  irc_network=irc_network, irc_port=irc_port, irc_ssl=irc_ssl)
        self.msg("Connection created. Starting IRC bot.")
Ejemplo n.º 18
0
 def func(self):
     """
     Guest is a child of Player typeclass.
     """
     session = self.caller
     num_guests = 1
     playerlist = AccountDB.objects.typeclass_search(GUEST)
     guest = None
     bans = ServerConfig.objects.conf("server_bans")
     addr = session.address
     if bans and (any(tup[2].match(session.address)
                      for tup in bans if tup[2])):
         # this is a banned IP or name!
         string = "{rYou have been banned and cannot continue from here." \
                  "\nIf you feel this ban is in error, please email an admin.{x"
         self.dc_session(string)
         return
     try:
         check_vpn = settings.CHECK_VPN
     except AttributeError:
         check_vpn = False
     if check_vpn:
         # check if IP is in our whitelist
         white_list = ServerConfig.objects.conf("white_list") or []
         if addr not in white_list:
             qname = addr[::-1] + "." + str(
                 settings.TELNET_PORTS[0]
             ) + "." + settings.TELNET_INTERFACES[0][::-1]
             try:
                 query(qname)
                 msg = "Guest connections from TOR are not permitted, sorry."
                 self.dc_session(msg)
                 return
             except NXDOMAIN:
                 # not inside TOR
                 pass
             import json
             from urllib2 import urlopen
             api_key = getattr(settings, 'HOST_BLOCKER_API_KEY', "")
             request = "http://tools.xioax.com/networking/v2/json/%s/%s" % (
                 addr, api_key)
             try:
                 data = json.load(urlopen(request))
                 print "Returned from xiaox: %s" % str(data)
                 if data['host-ip']:
                     self.dc_session(
                         "Guest connections from VPNs are not permitted, sorry."
                     )
                     return
                 # the address was safe, add it to our white_list
                 white_list.append(addr)
                 ServerConfig.objects.conf('white_list', white_list)
             except Exception as err:
                 import traceback
                 traceback.print_exc()
                 print 'Error code on trying to check VPN:', err
     for pc in playerlist:
         if pc.is_guest():
             # add session check just to be absolutely sure we don't connect to a guest in-use
             if pc.is_connected or pc.sessions.all():
                 num_guests += 1
             else:
                 guest = pc
                 break
     # create a new guest account
     if not guest:
         session.msg("All guests in use, creating a new one.")
         key = "Guest" + str(num_guests)
         playerlist = [ob.key for ob in playerlist]
         while key in playerlist:
             num_guests += 1
             key = "Guest" + str(num_guests)
             # maximum loop check just in case
             if num_guests > 5000:
                 break
         guest = create.create_player(key,
                                      "*****@*****.**",
                                      "DefaultGuestPassword",
                                      typeclass=GUEST,
                                      is_superuser=False,
                                      locks=None,
                                      permissions="Guests",
                                      report_to=session)
     # now connect the player to the guest account
     session.msg("Logging in as %s" % guest.key)
     session.sessionhandler.login(session, guest)
Ejemplo n.º 19
0
def creating(request):
    user = request.user
    #foobar = create.create_player("TestPlayer42", email="*****@*****.**", password="******", typeclass=settings.BASE_PLAYER_TYPECLASS)
    #foobar.db.FIRST_LOGIN = True
    #unloggedin._create_character(self, foobar, settings.BASE_CHARACTER_TYPECLASS, settings.DEFAULT_HOME, settings.PERMISSION_PLAYER_DEFAULT)
    if request.method == 'POST':
        myform = request.POST
        test = myform['validation']
        if test.lower() != "june":
            return HttpResponseRedirect('/chargen')
        fields = myform['name']
        pwd = myform['password']
        circuit = create.create_player(fields, email="*****@*****.**", password=pwd, typeclass=settings.BASE_PLAYER_TYPECLASS)
        unloggedin._create_character(user, circuit, settings.BASE_CHARACTER_TYPECLASS, settings.DEFAULT_HOME, settings.PERMISSION_PLAYER_DEFAULT)
        newchar = circuit.db._last_puppet
        newchar.db.tradition = myform['tradition']
        newchar.db.desc =  myform['description']
        newchar.db.image = myform['image']
        newchar.db.essence = myform['testinput']
        newchar.db.concept = myform['concept']
        newchar.db.strength = trans(myform['Strength'])
        newchar.db.dexterity = trans(myform['Dexterity'])
        newchar.db.stamina = trans(myform['Stamina'])
        newchar.db.charisma = trans(myform['Charisma'])
        newchar.db.manipulation = trans(myform['Manipulation'])
        newchar.db.appearance = trans(myform['Appearance'])
        newchar.db.perception = trans(myform['Perception'])
        newchar.db.intelligence = trans(myform['Intelligence'])
        newchar.db.wits = trans(myform['Wits'])
        newchar.db.alertness = trans(myform['testA'])-1
        newchar.db.athletics = trans(myform['testA1'])-1
        newchar.db.awareness = trans(myform['testA2'])-1
        newchar.db.brawl = trans(myform['testA3'])-1
        newchar.db.intimidation = trans(myform['testA4'])-1
        newchar.db.firearms = trans(myform['testB1'])-1
        newchar.db.martialarts = trans(myform['testB2'])-1
        newchar.db.melee = trans(myform['testB3'])-1
        newchar.db.meditation = trans(myform['testB4'])-1
        newchar.db.stealth = trans(myform['testB5'])-1
        newchar.db.computer = trans(myform['testC1'])-1
        newchar.db.medicine = trans(myform['testC3'])-1
        newchar.db.occult = trans(myform['testC4'])-1
        newchar.db.rituals = trans(myform['testC5'])-1

        newchar.db.melee = trans(myform['testB3'])-1
        newchar.db.meditation = trans(myform['testB4'])-1
        newchar.db.stealth = trans(myform['testB5'])-1
        newchar.db.astrology = trans(myform['testC'])-1
        newchar.db.computer = trans(myform['testC1'])-1
        newchar.db.medicine = trans(myform['testC3'])-1
        newchar.db.occult = trans(myform['testC4'])-1
        newchar.db.rituals = trans(myform['testC5'])-1
        newchar.db.correspondence = trans(myform["Correspondence"])-1
        newchar.db.entropy = trans(myform["Entropy"])-1
        newchar.db.life = trans(myform["Life"])-1
        newchar.db.forces = trans(myform["Forces"])-1
        newchar.db.matter = trans(myform["Matter"])-1
        newchar.db.mind = trans(myform["Mind"])-1
        newchar.db.prime = trans(myform["Prime"])-1
        newchar.db.spirit = trans(myform["Spirit"])-1
        newchar.db.time = trans(myform["Time"])-1

        newchar.db.quintessence = trans(myform["Quintessence"])-1
        newchar.db.arete = trans(myform["Arete"])-1
        newchar.db.willpower = trans(myform["Willpower"])-1
        newchar.db.arcane = trans(myform["Arcane"])-1
        newchar.db.belief = trans(myform["Belief"])-1
        newchar.db.luck = trans(myform["Luck"])-1
        newchar.db.avatar = trans(myform["Avatar"])-1
        newchar.db.familiar = trans(myform["Familiar"])-1
        newchar.db.resources = trans(myform["Resources"])-1
        urlz = '/character/sheet/'
        nchr = str(newchar.id);
        urlz = urlz + nchr + '/'
        return redirect(urlz)
Ejemplo n.º 20
0
    def func(self):
        "Do checks and create account"

        session = self.caller

        try:
            playername, email, password = self.playerinfo
        except ValueError:
            string = "\n\r Usage (without <>): create \"<playername>\" <email> <password>"
            session.msg(string)
            return
        if not re.findall('^[\w. @+-]+$', playername) or not (0 < len(playername) <= 30):
            session.msg("\n\r Playername can be max 30 characters, or less. Letters, spaces, dig\
its and @/./+/-/_ only.") # this echoes the restrictions made by django's auth module.
            return
        if not email or not password:
            session.msg("\n\r You have to supply an e-mail address followed by a password." )
            return

        if not utils.validate_email_address(email):
            # check so the email at least looks ok.
            session.msg("'%s' is not a valid e-mail address." % email)
            return

        # Run sanity and security checks

        if PlayerDB.objects.filter(username=playername):
            # player already exists
            session.msg("Sorry, there is already a player with the name '%s'." % playername)
            return
        if PlayerDB.objects.get_player_from_email(email):
            # email already set on a player
            session.msg("Sorry, there is already a player with that email address.")
            return
        if len(password) < 3:
            # too short password
            string = "Your password must be at least 3 characters or longer."
            string += "\n\rFor best security, make it at least 8 characters long, "
            string += "avoid making it a real word and mix numbers into it."
            session.msg(string)
            return

        # everything's ok. Create the new player account.
        try:
            default_home = ObjectDB.objects.get_id(settings.DEFAULT_HOME)

            typeclass = settings.BASE_CHARACTER_TYPECLASS
            permissions = settings.PERMISSION_PLAYER_DEFAULT

            try:
                new_player = create.create_player(playername, email, password,
                                                     permissions=permissions)

            except Exception, e:
                session.msg("There was an error creating the default Player/Character:\n%s\n If this problem persists, contact an admin." % e)
                logger.log_trace()
                return

            # This needs to be called so the engine knows this player is
            # logging in for the first time. (so it knows to call the right
            # hooks during login later)
            utils.init_new_player(new_player)

            # join the new player to the public channel
            pchanneldef = settings.CHANNEL_PUBLIC
            if pchanneldef:
                pchannel = ChannelDB.objects.get_channel(pchanneldef[0])
                if not pchannel.connect(new_player):
                    string = "New player '%s' could not connect to public channel!" % new_player.key
                    logger.log_errmsg(string)

            if MULTISESSION_MODE < 2:
                # if we only allow one character, create one with the same name as Player
                # (in mode 2, the character must be created manually once logging in)
                new_character = create.create_object(typeclass, key=playername,
                                          location=default_home, home=default_home,
                                          permissions=permissions)
                # set playable character list
                new_player.db._playable_characters.append(new_character)

                # allow only the character itself and the player to puppet this character (and Immortals).
                new_character.locks.add("puppet:id(%i) or pid(%i) or perm(Immortals) or pperm(Immortals)" %
                                        (new_character.id, new_player.id))

                # If no description is set, set a default description
                if not new_character.db.desc:
                    new_character.db.desc = "This is a Player."
                # We need to set this to have @ic auto-connect to this character
                new_player.db._last_puppet = new_character

            # tell the caller everything went well.
            string = "A new account '%s' was created. Welcome!"
            if " " in playername:
                string += "\n\nYou can now log in with the command 'connect %s <your password>'."
            else:
                string += "\n\nYou can now log with the command 'connect %s <your password>'."
            session.msg(string % (playername, email))
Ejemplo n.º 21
0
    def func(self):
        """Setup the irc-channel mapping"""

        if not settings.IRC_ENABLED:
            string = """IRC is not enabled. You need to activate it in game/settings.py."""
            self.msg(string)
            return

        if 'list' in self.switches:
            # show all connections
            self.msg(_list_bots())
            return

        if 'disconnect' in self.switches or 'remove' in self.switches or 'delete' in self.switches:
            botname = "ircbot-%s" % self.lhs
            matches = PlayerDB.objects.filter(db_is_bot=True, username=botname)
            dbref = utils.dbref(self.lhs)
            if not matches and dbref:
                # try dbref match
                matches = PlayerDB.objects.filter(db_is_bot=True, id=dbref)
            if matches:
                matches[0].delete()
                self.msg("IRC connection destroyed.")
            else:
                self.msg(
                    "IRC connection/bot could not be removed, does it exist?")
            return

        if not self.args or not self.rhs:
            string = "Usage: @irc2chan[/switches] <evennia_channel> =" \
                     " <ircnetwork> <port> <#irchannel> <botname>[:typeclass]"
            self.msg(string)
            return

        channel = self.lhs
        self.rhs = self.rhs.replace('#', ' ')  # to avoid Python comment issues
        try:
            irc_network, irc_port, irc_channel, irc_botname = \
                       [part.strip() for part in self.rhs.split(None, 4)]
            irc_channel = "#%s" % irc_channel
        except Exception:
            string = "IRC bot definition '%s' is not valid." % self.rhs
            self.msg(string)
            return

        botclass = None
        if ":" in irc_botname:
            irc_botname, botclass = [
                part.strip() for part in irc_botname.split(":", 2)
            ]
        botname = "ircbot-%s" % irc_botname
        # If path given, use custom bot otherwise use default.
        botclass = botclass if botclass else bots.IRCBot
        irc_ssl = "ssl" in self.switches

        # create a new bot
        bot = PlayerDB.objects.filter(username__iexact=botname)
        if bot:
            # re-use an existing bot
            bot = bot[0]
            if not bot.is_bot:
                self.msg("Player '%s' already exists and is not a bot." %
                         botname)
                return
        else:
            try:
                bot = create.create_player(botname,
                                           None,
                                           None,
                                           typeclass=botclass)
            except Exception as err:
                self.msg("|rError, could not create the bot:|n '%s'." % err)
                return
        bot.start(ev_channel=channel,
                  irc_botname=irc_botname,
                  irc_channel=irc_channel,
                  irc_network=irc_network,
                  irc_port=irc_port,
                  irc_ssl=irc_ssl)
        self.msg("Connection created. Starting IRC bot.")
Ejemplo n.º 22
0
def creating(request):
    user = request.user
    #foobar = create.create_player("TestPlayer42", email="*****@*****.**", password="******", typeclass=settings.BASE_PLAYER_TYPECLASS)
    #foobar.db.FIRST_LOGIN = True
    #unloggedin._create_character(self, foobar, settings.BASE_CHARACTER_TYPECLASS, settings.DEFAULT_HOME, settings.PERMISSION_PLAYER_DEFAULT)
    if request.method == 'POST':
        myform = request.POST
        print(request.POST)
        print(myform)
        fields = myform['name']
        pwd = myform['password']
        circuit = create.create_player(
            fields,
            email="*****@*****.**",
            password=pwd,
            typeclass=settings.BASE_PLAYER_TYPECLASS)
        unloggedin._create_character(user, circuit,
                                     settings.BASE_CHARACTER_TYPECLASS,
                                     settings.DEFAULT_HOME,
                                     settings.PERMISSION_PLAYER_DEFAULT)
        newchar = circuit.db._last_puppet
        newchar.db.tradition = myform['tradition']
        newchar.db.desc = myform['description']
        newchar.db.image = myform['image']
        newchar.db.essence = myform['testinput']
        newchar.db.concept = myform['concept']
        newchar.db.strength = trans(myform['Strength'])
        newchar.db.dexterity = trans(myform['Dexterity'])
        newchar.db.stamina = trans(myform['Stamina'])
        newchar.db.charisma = trans(myform['Charisma'])
        newchar.db.manipulation = trans(myform['Manipulation'])
        newchar.db.appearance = trans(myform['Appearance'])
        newchar.db.perception = trans(myform['Perception'])
        newchar.db.intelligence = trans(myform['Intelligence'])
        newchar.db.wits = trans(myform['Wits'])
        newchar.db.alertness = trans(myform['testA']) - 1
        newchar.db.athletics = trans(myform['testA1']) - 1
        newchar.db.awareness = trans(myform['testA2']) - 1
        newchar.db.brawl = trans(myform['testA3']) - 1
        newchar.db.intimidation = trans(myform['testA4']) - 1
        newchar.db.streetwise = trans(myform['testA5']) - 1
        newchar.db.drive = trans(myform['testB']) - 1
        newchar.db.firearms = trans(myform['testB1']) - 1
        newchar.db.martialarts = trans(myform['testB2']) - 1
        newchar.db.melee = trans(myform['testB3']) - 1
        newchar.db.meditation = trans(myform['testB4']) - 1
        newchar.db.stealth = trans(myform['testB5']) - 1
        newchar.db.astrology = trans(myform['testC']) - 1
        newchar.db.computer = trans(myform['testC1']) - 1
        newchar.db.language = trans(myform['testC2']) - 1
        newchar.db.medicine = trans(myform['testC3']) - 1
        newchar.db.occult = trans(myform['testC4']) - 1
        newchar.db.rituals = trans(myform['testC5']) - 1

        newchar.db.melee = trans(myform['testB3']) - 1
        newchar.db.meditation = trans(myform['testB4']) - 1
        newchar.db.stealth = trans(myform['testB5']) - 1
        newchar.db.astrology = trans(myform['testC']) - 1
        newchar.db.computer = trans(myform['testC1']) - 1
        newchar.db.language = trans(myform['testC2']) - 1
        newchar.db.medicine = trans(myform['testC3']) - 1
        newchar.db.occult = trans(myform['testC4']) - 1
        newchar.db.rituals = trans(myform['testC5']) - 1
        newchar.db.correspondence = trans(myform["Correspondence"]) - 1
        newchar.db.entropy = trans(myform["Entropy"]) - 1
        newchar.db.life = trans(myform["Life"]) - 1
        newchar.db.forces = trans(myform["Forces"]) - 1
        newchar.db.matter = trans(myform["Matter"]) - 1
        newchar.db.mind = trans(myform["Mind"]) - 1
        newchar.db.prime = trans(myform["Prime"]) - 1
        newchar.db.spirit = trans(myform["Spirit"]) - 1
        newchar.db.time = trans(myform["Time"]) - 1

        newchar.db.quintessence = trans(myform["Quintessence"]) - 1
        newchar.db.arete = trans(myform["Arete"]) - 1
        newchar.db.willpower = trans(myform["Willpower"]) - 1
        newchar.db.arcane = trans(myform["Arcane"]) - 1
        newchar.db.belief = trans(myform["Belief"]) - 1
        newchar.db.luck = trans(myform["Luck"]) - 1
        newchar.db.avatar = trans(myform["Avatar"]) - 1
        newchar.db.familiar = trans(myform["Familiar"]) - 1
        newchar.db.resources = trans(myform["Resources"]) - 1
        urlz = '/character/sheet/'
        nchr = str(newchar.id)
        urlz = urlz + nchr + '/'
        return redirect(urlz)
Ejemplo n.º 23
0
    def func(self):
        "Do checks and create account"

        session = self.caller

        try:
            playername, email, password = self.playerinfo
        except ValueError:
            string = "\n\r Usage (without <>): create \"<playername>\" <email> <password>"
            session.msg(string)
            return
        if not re.findall('^[\w. @+-]+$',
                          playername) or not (0 < len(playername) <= 30):
            session.msg(
                "\n\r Playername can be max 30 characters, or less. Letters, spaces, dig\
its and @/./+/-/_ only."
            )  # this echoes the restrictions made by django's auth module.
            return
        if not email or not password:
            session.msg(
                "\n\r You have to supply an e-mail address followed by a password."
            )
            return

        if not utils.validate_email_address(email):
            # check so the email at least looks ok.
            session.msg("'%s' is not a valid e-mail address." % email)
            return

        # Run sanity and security checks

        if PlayerDB.objects.filter(username=playername):
            # player already exists
            session.msg(
                "Sorry, there is already a player with the name '%s'." %
                playername)
            return
        if PlayerDB.objects.get_player_from_email(email):
            # email already set on a player
            session.msg(
                "Sorry, there is already a player with that email address.")
            return
        if len(password) < 3:
            # too short password
            string = "Your password must be at least 3 characters or longer."
            string += "\n\rFor best security, make it at least 8 characters long, "
            string += "avoid making it a real word and mix numbers into it."
            session.msg(string)
            return

        # everything's ok. Create the new player account.
        try:
            default_home = ObjectDB.objects.get_id(settings.DEFAULT_HOME)

            typeclass = settings.BASE_CHARACTER_TYPECLASS
            permissions = settings.PERMISSION_PLAYER_DEFAULT

            try:
                new_player = create.create_player(playername,
                                                  email,
                                                  password,
                                                  permissions=permissions)

            except Exception, e:
                session.msg(
                    "There was an error creating the default Player/Character:\n%s\n If this problem persists, contact an admin."
                    % e)
                logger.log_trace()
                return

            # This needs to be called so the engine knows this player is
            # logging in for the first time. (so it knows to call the right
            # hooks during login later)
            utils.init_new_player(new_player)

            # join the new player to the public channel
            pchanneldef = settings.CHANNEL_PUBLIC
            if pchanneldef:
                pchannel = ChannelDB.objects.get_channel(pchanneldef[0])
                if not pchannel.connect(new_player):
                    string = "New player '%s' could not connect to public channel!" % new_player.key
                    logger.log_errmsg(string)

            if MULTISESSION_MODE < 2:
                # if we only allow one character, create one with the same name as Player
                # (in mode 2, the character must be created manually once logging in)
                new_character = create.create_object(typeclass,
                                                     key=playername,
                                                     location=default_home,
                                                     home=default_home,
                                                     permissions=permissions)
                # set playable character list
                new_player.db._playable_characters.append(new_character)

                # allow only the character itself and the player to puppet this character (and Immortals).
                new_character.locks.add(
                    "puppet:id(%i) or pid(%i) or perm(Immortals) or pperm(Immortals)"
                    % (new_character.id, new_player.id))

                # If no description is set, set a default description
                if not new_character.db.desc:
                    new_character.db.desc = "This is a Player."
                # We need to set this to have @ic auto-connect to this character
                new_player.db._last_puppet = new_character

            # tell the caller everything went well.
            string = "A new account '%s' was created. Welcome!"
            if " " in playername:
                string += "\n\nYou can now log in with the command 'connect %s <your password>'."
            else:
                string += "\n\nYou can now log with the command 'connect %s <your password>'."
            session.msg(string % (playername, email))
Ejemplo n.º 24
0
    def func(self):
        "Setup the irc-channel mapping"

        if not settings.IRC_ENABLED:
            string = """IRC is not enabled. You need to activate it in game/settings.py."""
            self.msg(string)
            return

        if 'list' in self.switches:
            # show all connections
            ircbots = [bot for bot in PlayerDB.objects.filter(db_is_bot=True, username__startswith="ircbot-")]
            if ircbots:
                from evennia.utils.evtable import EvTable
                table = EvTable("{wdbid{n", "{wbotname{n", "{wev-channel{n", "{wirc-channel{n", "{wSSL{n", maxwidth=_DEFAULT_WIDTH)
                for ircbot in ircbots:
                    ircinfo = "%s (%s:%s)" % (ircbot.db.irc_channel, ircbot.db.irc_network, ircbot.db.irc_port)
                    table.add_row(ircbot.id, ircbot.db.irc_botname, ircbot.db.ev_channel, ircinfo, ircbot.db.irc_ssl)
                self.caller.msg(table)
            else:
                self.msg("No irc bots found.")
            return


        if('disconnect' in self.switches or 'remove' in self.switches or
                                                    'delete' in self.switches):
            botname = "ircbot-%s" % self.lhs
            matches = PlayerDB.objects.filter(db_is_bot=True, username=botname)
            dbref = utils.dbref(self.lhs)
            if not matches and dbref:
                # try dbref match
                matches = PlayerDB.objects.filter(db_is_bot=True, id=dbref)
            if matches:
                matches[0].delete()
                self.msg("IRC connection destroyed.")
            else:
                self.msg("IRC connection/bot could not be removed, does it exist?")
            return

        if not self.args or not self.rhs:
            string = "Usage: @irc2chan[/switches] <evennia_channel> = <ircnetwork> <port> <#irchannel> <botname>"
            self.msg(string)
            return

        channel = self.lhs
        self.rhs = self.rhs.replace('#', ' ') # to avoid Python comment issues
        try:
            irc_network, irc_port, irc_channel, irc_botname = \
                       [part.strip() for part in self.rhs.split(None, 3)]
            irc_channel = "#%s" % irc_channel
        except Exception:
            string = "IRC bot definition '%s' is not valid." % self.rhs
            self.msg(string)
            return

        botname = "ircbot-%s" % irc_botname
        irc_ssl = "ssl" in self.switches

        # create a new bot
        bot = PlayerDB.objects.filter(username__iexact=botname)
        if bot:
            # re-use an existing bot
            bot = bot[0]
            if not bot.is_bot:
                self.msg("Player '%s' already exists and is not a bot." % botname)
                return
        else:
            bot = create.create_player(botname, None, None, typeclass=bots.IRCBot)
        bot.start(ev_channel=channel, irc_botname=irc_botname, irc_channel=irc_channel,
                  irc_network=irc_network, irc_port=irc_port, irc_ssl=irc_ssl)
        self.msg("Connection created. Starting IRC bot.")