Some cleanup and changing to conform to PEP8 standard.

This commit is contained in:
Griatch 2014-07-10 20:29:16 +02:00
parent 364b156456
commit 3819c97b06
3 changed files with 32 additions and 32 deletions

View file

@ -73,21 +73,21 @@ class CmdUnconnectedConnect(MuxCommand):
if playername == None: if playername == None:
session.msg("All guest accounts are in use. Please try again later.") session.msg("All guest accounts are in use. Please try again later.")
return return
password = "%016x" % getrandbits(64) password = "%016x" % getrandbits(64)
home = ObjectDB.objects.get_id(settings.GUEST_HOME) home = ObjectDB.objects.get_id(settings.GUEST_HOME)
permissions = settings.PERMISSION_GUEST_DEFAULT permissions = settings.PERMISSION_GUEST_DEFAULT
typeclass = settings.BASE_CHARACTER_TYPECLASS typeclass = settings.BASE_CHARACTER_TYPECLASS
ptypeclass = settings.BASE_GUEST_TYPECLASS ptypeclass = settings.BASE_GUEST_TYPECLASS
start_location = ObjectDB.objects.get_id(settings.GUEST_START_LOCATION) start_location = ObjectDB.objects.get_id(settings.GUEST_START_LOCATION)
new_player = CreatePlayer(session, playername, password, new_player = _create_player(session, playername, password,
home, permissions, ptypeclass) home, permissions, ptypeclass)
if new_player: if new_player:
CreateCharacter(session, new_player, typeclass, start_location, _create_character(session, new_player, typeclass, start_location,
home, permissions) home, permissions)
session.sessionhandler.login(session, new_player) session.sessionhandler.login(session, new_player)
except Exception: except Exception:
# We are in the middle between logged in and -not, so we have # We are in the middle between logged in and -not, so we have
# to handle tracebacks ourselves at this point. If we don't, # to handle tracebacks ourselves at this point. If we don't,
@ -97,7 +97,7 @@ class CmdUnconnectedConnect(MuxCommand):
logger.log_errmsg(traceback.format_exc()) logger.log_errmsg(traceback.format_exc())
finally: finally:
return return
if len(parts) != 2: if len(parts) != 2:
session.msg("\n\r Usage (without <>): connect <name> <password>") session.msg("\n\r Usage (without <>): connect <name> <password>")
return return
@ -217,11 +217,11 @@ class CmdUnconnectedCreate(MuxCommand):
default_home = ObjectDB.objects.get_id(settings.DEFAULT_HOME) default_home = ObjectDB.objects.get_id(settings.DEFAULT_HOME)
permissions = settings.PERMISSION_PLAYER_DEFAULT permissions = settings.PERMISSION_PLAYER_DEFAULT
typeclass = settings.BASE_CHARACTER_TYPECLASS typeclass = settings.BASE_CHARACTER_TYPECLASS
new_player = CreatePlayer(session, playername, password, default_home, permissions) new_player = _create_player(session, playername, password, default_home, permissions)
start_location = ObjectDB.objects.get_id(settings.START_LOCATION) start_location = ObjectDB.objects.get_id(settings.START_LOCATION)
if new_player: if new_player:
if MULTISESSION_MODE < 2: if MULTISESSION_MODE < 2:
CreateCharacter(session, new_player, typeclass, start_location, _create_character(session, new_player, typeclass, start_location,
default_home, permissions) default_home, permissions)
# tell the caller everything went well. # tell the caller everything went well.
string = "A new account '%s' was created. Welcome!" string = "A new account '%s' was created. Welcome!"
@ -230,7 +230,7 @@ class CmdUnconnectedCreate(MuxCommand):
else: else:
string += "\n\nYou can now log with the command 'connect %s <your password>'." string += "\n\nYou can now log with the command 'connect %s <your password>'."
session.msg(string % (playername, playername)) session.msg(string % (playername, playername))
except Exception: except Exception:
# We are in the middle between logged in and -not, so we have # We are in the middle between logged in and -not, so we have
# to handle tracebacks ourselves at this point. If we don't, # to handle tracebacks ourselves at this point. If we don't,
@ -334,10 +334,10 @@ You can use the {wlook{n command if you want to see the connect screen again.
self.caller.msg(string) self.caller.msg(string)
def CreatePlayer(session, playername, password, def _create_player(session, playername, password,
default_home, permissions, typeclass=None): default_home, permissions, typeclass=None):
""" """
Creates a player of the specified typeclass. Helper function, creates a player of the specified typeclass.
""" """
try: try:
new_player = create.create_player(playername, None, password, new_player = create.create_player(playername, None, password,
@ -363,10 +363,10 @@ def CreatePlayer(session, playername, password,
return new_player return new_player
def CreateCharacter(session, new_player, typeclass, start_location, home, permissions): def _create_character(session, new_player, typeclass, start_location, home, permissions):
""" """
Creates a character based on a player's name. This is meant for Guest and Helper function, creates a character based on a player's name.
MULTISESSION_MODE <2 situations. This is meant for Guest and MULTISESSION_MODE < 2 situations.
""" """
try: try:
if not start_location: if not start_location:
@ -376,11 +376,11 @@ def CreateCharacter(session, new_player, typeclass, start_location, home, permis
permissions=permissions) permissions=permissions)
# set playable character list # set playable character list
new_player.db._playable_characters.append(new_character) new_player.db._playable_characters.append(new_character)
# allow only the character itself and the player to puppet this character (and Immortals). # 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.locks.add("puppet:id(%i) or pid(%i) or perm(Immortals) or pperm(Immortals)" %
(new_character.id, new_player.id)) (new_character.id, new_player.id))
# If no description is set, set a default description # If no description is set, set a default description
if not new_character.db.desc: if not new_character.db.desc:
new_character.db.desc = "This is a Player." new_character.db.desc = "This is a Player."
@ -390,4 +390,4 @@ def CreateCharacter(session, new_player, typeclass, start_location, home, permis
session.msg("There was an error creating the Character:\n%s\n If this problem persists, contact an admin." % e) session.msg("There was an error creating the Character:\n%s\n If this problem persists, contact an admin." % e)
logger.log_trace() logger.log_trace()
return False return False

View file

@ -356,9 +356,9 @@ class Evennia(object):
# flag to avoid loops. # flag to avoid loops.
self.shutdown_complete = True self.shutdown_complete = True
reactor.callLater(0, reactor.stop) reactor.callLater(0, reactor.stop)
# server start/stop hooks # server start/stop hooks
def at_server_start(self): def at_server_start(self):
""" """
This is called every time the server starts up, regardless of This is called every time the server starts up, regardless of
@ -366,8 +366,8 @@ class Evennia(object):
""" """
if SERVER_STARTSTOP_MODULE: if SERVER_STARTSTOP_MODULE:
SERVER_STARTSTOP_MODULE.at_server_start() SERVER_STARTSTOP_MODULE.at_server_start()
def at_server_stop(self): def at_server_stop(self):
""" """
This is called just before a server is shut down, regardless This is called just before a server is shut down, regardless
@ -375,24 +375,24 @@ class Evennia(object):
""" """
if SERVER_STARTSTOP_MODULE: if SERVER_STARTSTOP_MODULE:
SERVER_STARTSTOP_MODULE.at_server_stop() SERVER_STARTSTOP_MODULE.at_server_stop()
def at_server_reload_start(self): def at_server_reload_start(self):
""" """
This is called only when server starts back up after a reload. This is called only when server starts back up after a reload.
""" """
if SERVER_STARTSTOP_MODULE: if SERVER_STARTSTOP_MODULE:
SERVER_STARTSTOP_MODULE.at_server_reload_start() SERVER_STARTSTOP_MODULE.at_server_reload_start()
def at_server_reload_stop(self): def at_server_reload_stop(self):
""" """
This is called only time the server stops before a reload. This is called only time the server stops before a reload.
""" """
if SERVER_STARTSTOP_MODULE: if SERVER_STARTSTOP_MODULE:
SERVER_STARTSTOP_MODULE.at_server_reload_stop() SERVER_STARTSTOP_MODULE.at_server_reload_stop()
def at_server_cold_start(self): def at_server_cold_start(self):
""" """
This is called only when the server starts "cold", i.e. after a This is called only when the server starts "cold", i.e. after a
@ -405,7 +405,7 @@ class Evennia(object):
guest.delete() guest.delete()
if SERVER_STARTSTOP_MODULE: if SERVER_STARTSTOP_MODULE:
SERVER_STARTSTOP_MODULE.at_server_cold_start() SERVER_STARTSTOP_MODULE.at_server_cold_start()
def at_server_cold_stop(self): def at_server_cold_stop(self):
""" """
This is called only when the server goes down due to a shutdown or reset. This is called only when the server goes down due to a shutdown or reset.

View file

@ -306,14 +306,14 @@ BASE_SCRIPT_TYPECLASS = "src.scripts.scripts.DoNothing"
# fallback if an object's normal home location is deleted. Default # fallback if an object's normal home location is deleted. Default
# is Limbo (#2). # is Limbo (#2).
DEFAULT_HOME = "#2" DEFAULT_HOME = "#2"
# This enables guest logins.
GUEST_ENABLED = True
# The default home location used for guests.
GUEST_HOME = "#2"
# The start position for new characters. Default is Limbo (#2). # The start position for new characters. Default is Limbo (#2).
# MULTISESSION_MODE = 0, 1 - used by default unloggedin create command # MULTISESSION_MODE = 0, 1 - used by default unloggedin create command
# MULTISESSION_MODE = 2 - used by default character_create command # MULTISESSION_MODE = 2 - used by default character_create command
START_LOCATION = "#2" START_LOCATION = "#2"
# This enables guest logins.
GUEST_ENABLED = True
# The default home location used for guests.
GUEST_HOME = "#2"
# The start position used for guest characters. # The start position used for guest characters.
GUEST_START_LOCATION = "#2" GUEST_START_LOCATION = "#2"
# The naming convention for guest players/characters. The size of this list # The naming convention for guest players/characters. The size of this list