diff --git a/evennia/commands/default/unloggedin.py b/evennia/commands/default/unloggedin.py index ae8f3b0c0f..9affc8fa46 100644 --- a/evennia/commands/default/unloggedin.py +++ b/evennia/commands/default/unloggedin.py @@ -30,6 +30,8 @@ CONNECTION_SCREEN_MODULE = settings.CONNECTION_SCREEN_MODULE # would also block dummyrunner, so it's not added as default. _LATEST_FAILED_LOGINS = defaultdict(list) + + def _throttle(session, maxlim=None, timeout=None, storage=_LATEST_FAILED_LOGINS): """ This will check the session's address against the @@ -95,8 +97,8 @@ def create_guest_player(session): bans = ServerConfig.objects.conf("server_bans") if bans and any(tup[2].match(session.address) for tup in bans if tup[2]): # this is a banned IP! - string = "{rYou have been banned and cannot continue from here." \ - "\nIf you feel this ban is in error, please email an admin.{x" + string = "|rYou have been banned and cannot continue from here." \ + "\nIf you feel this ban is in error, please email an admin.|x" session.msg(string) session.sessionhandler.disconnect(session, "Good bye! Disconnecting.") return True, None @@ -118,14 +120,11 @@ def create_guest_player(session): permissions = settings.PERMISSION_GUEST_DEFAULT typeclass = settings.BASE_CHARACTER_TYPECLASS ptypeclass = settings.BASE_GUEST_TYPECLASS - new_player = _create_player(session, playername, password, - permissions, ptypeclass) + new_player = _create_player(session, playername, password, permissions, ptypeclass) if new_player: - _create_character(session, new_player, typeclass, - home, permissions) + _create_character(session, new_player, typeclass, home, permissions) return True, new_player - except Exception: # We are in the middle between logged in and -not, so we have # to handle tracebacks ourselves at this point. If we don't, @@ -150,7 +149,7 @@ def create_normal_player(session, name, password): # check for too many login errors too quick. if _throttle(session, maxlim=5, timeout=5*60): # timeout is 5 minutes. - session.msg("{RYou made too many connection attempts. Try again in a few minutes.{n") + session.msg("|RYou made too many connection attempts. Try again in a few minutes.|n") return None # Match account name and check password @@ -167,15 +166,14 @@ def create_normal_player(session, name, password): player.at_failed_login(session) return None - # Check IP and/or name bans bans = ServerConfig.objects.conf("server_bans") - if bans and (any(tup[0]==player.name.lower() for tup in bans) + if bans and (any(tup[0] == player.name.lower() for tup in bans) or 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" + string = "|rYou have been banned and cannot continue from here." \ + "\nIf you feel this ban is in error, please email an admin.|x" session.msg(string) session.sessionhandler.disconnect(session, "Good bye! Disconnecting.") return None @@ -213,7 +211,7 @@ class CmdUnconnectedConnect(COMMAND_DEFAULT_CLASS): # 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") + session.msg("|RYou made too many connection attempts. Try again in a few minutes.|n") return args = self.args @@ -237,12 +235,6 @@ class CmdUnconnectedConnect(COMMAND_DEFAULT_CLASS): name, password = parts player = create_normal_player(session, name, password) if player: - # actually do the login. This will call all other hooks: - # session.at_login() - # player.at_init() # always called when object is loaded from disk - # player.at_first_login() # only once, for player-centric setup - # player.at_pre_login() - # player.at_post_login(session=session) session.sessionhandler.login(session, player) @@ -264,7 +256,7 @@ class CmdUnconnectedCreate(COMMAND_DEFAULT_CLASS): arg_regex = r"\s.*?|$" def func(self): - "Do checks and create account" + """Do checks and create account""" session = self.caller args = self.args.strip() @@ -309,12 +301,12 @@ class CmdUnconnectedCreate(COMMAND_DEFAULT_CLASS): # Check IP and/or name bans bans = ServerConfig.objects.conf("server_bans") - if bans and (any(tup[0]==playername.lower() for tup in bans) + if bans and (any(tup[0] == playername.lower() for tup in bans) or 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" + string = "|rYou have been banned and cannot continue from here." \ + "\nIf you feel this ban is in error, please email an admin.|x" session.msg(string) session.sessionhandler.disconnect(session, "Good bye! Disconnecting.") return @@ -327,8 +319,7 @@ class CmdUnconnectedCreate(COMMAND_DEFAULT_CLASS): if new_player: if MULTISESSION_MODE < 2: default_home = ObjectDB.objects.get_id(settings.DEFAULT_HOME) - _create_character(session, new_player, typeclass, - default_home, permissions) + _create_character(session, new_player, typeclass, default_home, permissions) # tell the caller everything went well. string = "A new account '%s' was created. Welcome!" if " " in playername: @@ -361,7 +352,7 @@ class CmdUnconnectedQuit(COMMAND_DEFAULT_CLASS): locks = "cmd:all()" def func(self): - "Simply close the connection." + """Simply close the connection.""" session = self.caller session.sessionhandler.disconnect(session, "Good bye! Disconnecting.") @@ -383,7 +374,7 @@ class CmdUnconnectedLook(COMMAND_DEFAULT_CLASS): locks = "cmd:all()" def func(self): - "Show the connect screen." + """Show the connect screen.""" connection_screen = utils.random_string_from_module(CONNECTION_SCREEN_MODULE) if not connection_screen: connection_screen = "No connection screen found. Please contact an admin." @@ -405,25 +396,25 @@ class CmdUnconnectedHelp(COMMAND_DEFAULT_CLASS): locks = "cmd:all()" def func(self): - "Shows help" + """Shows help""" string = \ """ You are not yet logged into the game. Commands available at this point: - {wcreate{n - create a new account - {wconnect{n - connect with an existing account - {wlook{n - re-show the connection screen - {whelp{n - show this help - {wencoding{n - change the text encoding to match your client - {wscreenreader{n - make the server more suitable for use with screen readers - {wquit{n - abort the connection + |wcreate|n - create a new account + |wconnect|n - connect with an existing account + |wlook|n - re-show the connection screen + |whelp|n - show this help + |wencoding|n - change the text encoding to match your client + |wscreenreader|n - make the server more suitable for use with screen readers + |wquit|n - abort the connection -First create an account e.g. with {wcreate Anna c67jHL8p{n -(If you have spaces in your name, use double quotes: {wcreate "Anna the Barbarian" c67jHL8p{n -Next you can connect to the game: {wconnect Anna c67jHL8p{n +First create an account e.g. with |wcreate Anna c67jHL8p|n +(If you have spaces in your name, use double quotes: |wcreate "Anna the Barbarian" c67jHL8p|n +Next you can connect to the game: |wconnect Anna c67jHL8p|n -You can use the {wlook{n command if you want to see the connect screen again. +You can use the |wlook|n command if you want to see the connect screen again. """ self.caller.msg(string) @@ -479,10 +470,10 @@ class CmdUnconnectedEncoding(COMMAND_DEFAULT_CLASS): pencoding = self.session.protocol_flags.get("ENCODING", None) string = "" if pencoding: - string += "Default encoding: {g%s{n (change with {w@encoding {n)" % pencoding + string += "Default encoding: |g%s|n (change with |w@encoding |n)" % pencoding encodings = settings.ENCODINGS if encodings: - string += "\nServer's alternative encodings (tested in this order):\n {g%s{n" % ", ".join(encodings) + string += "\nServer's alternative encodings (tested in this order):\n |g%s|n" % ", ".join(encodings) if not string: string = "No encodings found." else: @@ -492,7 +483,8 @@ class CmdUnconnectedEncoding(COMMAND_DEFAULT_CLASS): try: utils.to_str(utils.to_unicode("test-string"), encoding=encoding) except LookupError: - string = "|rThe encoding '|w%s|r' is invalid. Keeping the previous encoding '|w%s|r'.|n" % (encoding, old_encoding) + string = "|rThe encoding '|w%s|r' is invalid. Keeping the previous encoding '|w%s|r'.|n"\ + % (encoding, old_encoding) else: self.session.protocol_flags["ENCODING"] = encoding string = "Your custom text encoding was changed from '|w%s|n' to '|w%s|n'." % (old_encoding, encoding) @@ -501,6 +493,7 @@ class CmdUnconnectedEncoding(COMMAND_DEFAULT_CLASS): self.session.sessionhandler.session_portal_sync(self.session) self.caller.msg(string.strip()) + class CmdUnconnectedScreenreader(COMMAND_DEFAULT_CLASS): """ Activate screenreader mode. @@ -515,10 +508,10 @@ class CmdUnconnectedScreenreader(COMMAND_DEFAULT_CLASS): aliases = "@screenreader" def func(self): - "Flips screenreader setting." + """Flips screenreader setting.""" new_setting = not self.session.protocol_flags.get("SCREENREADER", False) - self.session.protocol_flags["SCREENREADER"] = new_setting - string = "Screenreader mode turned {w%s{n." % ("on" if new_setting else "off") + self.session.protocol_flags["SCREENREADER"] = new_setting + string = "Screenreader mode turned |w%s|n." % ("on" if new_setting else "off") self.caller.msg(string) self.session.sessionhandler.session_portal_sync(self.session) @@ -528,8 +521,7 @@ 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) + 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) @@ -555,8 +547,7 @@ def _create_character(session, new_player, typeclass, home, permissions): This is meant for Guest and MULTISESSION_MODE < 2 situations. """ try: - new_character = create.create_object(typeclass, key=new_player.key, - home=home, permissions=permissions) + new_character = create.create_object(typeclass, key=new_player.key, home=home, permissions=permissions) # set playable character list new_player.db._playable_characters.append(new_character)