From 5100a0561f615fd1b94cecaf5ebb41ded17d56ca Mon Sep 17 00:00:00 2001 From: Griatch Date: Tue, 9 Apr 2013 11:14:08 +0200 Subject: [PATCH] Some further bug fixes. --- ev.py | 56 ++++++++++++++++++++++-------- src/commands/default/general.py | 4 +-- src/commands/default/system.py | 3 ++ src/commands/default/unloggedin.py | 2 -- src/players/player.py | 1 + 5 files changed, 48 insertions(+), 18 deletions(-) diff --git a/ev.py b/ev.py index f27419dcff..6be5d7636c 100644 --- a/ev.py +++ b/ev.py @@ -3,10 +3,14 @@ Central API for the Evennia MUD/MUX/MU* creation system. This is basically a set of shortcuts for accessing things in src/ with less boiler plate. -Import this from your code or explore it interactively from a python shell. +Import this from your code, use it with @py from in-game or explore it interactively from +a python shell. Notes: + 0) Use ev.help(), ev.managers.help(), ev.default_cmds.help() and syscmdkeys.help() to + view the API structure and explore which variables/methods are available. + 1) You should import things explicitly from the root of this module - you can not use dot-notation to import deeper. Hence, to access a default command, you can do import ev @@ -133,10 +137,36 @@ from src.utils import gametime from src.utils import ansi ###################################################################### -# API containers +# API containers and helper functions ###################################################################### -class DBmanagers(object): +def help(header=False): + """ + Main Evennia API. + ev.help() views API contents + ev.help(True) or ev.README shows module instructions + + See www.evennia.com for the full documentation. + """ + if header: + return __doc__ + else: + import ev + names = [var for var in ev.__dict__ if not var.startswith('_')] + return ", ".join(names) + +class _EvContainer(object): + """ + Parent for other containers + + """ + def help(self): + "Returns list of contents" + names = [name for name in self.__class__.__dict__ if not name.startswith('_')] + names += [name for name in self.__dict__ if not name.startswith('_')] + return self.__doc__ + "-"*60 + "\n" + ", ".join(names) + +class DBmanagers(_EvContainer): """ Links to instantiated database managers. @@ -149,9 +179,6 @@ class DBmanagers(object): externalconnections - ExternalChannelConnection.objects objects - ObjectDB.objects - Use by doing "from ev import managers", - you can then access the desired manager - on the imported managers object. """ from src.help.models import HelpEntry from src.players.models import PlayerDB @@ -171,13 +198,17 @@ class DBmanagers(object): serverconfigs = ServerConfig.objects del HelpEntry, PlayerDB, ScriptDB, Msg, Channel, PlayerChannelConnection, del ExternalChannelConnection, ObjectDB, ServerConfig + managers = DBmanagers() del DBmanagers -class DefaultCmds(object): +class DefaultCmds(_EvContainer): """ - This container holds direct shortcuts to all default commands in - Evennia. + This container holds direct shortcuts to all default commands in Evennia. + + To access in code, do 'from ev import default_cmds' then + access the properties on the imported default_cmds object. + """ from src.commands.default.cmdset_default import DefaultCmdSet @@ -206,7 +237,7 @@ class DefaultCmds(object): default_cmds = DefaultCmds() del DefaultCmds -class SystemCmds(object): +class SystemCmds(_EvContainer): """ Creating commands with keys set to these constants will make them system commands called as a replacement by the parser when @@ -224,9 +255,6 @@ class SystemCmds(object): To access in code, do 'from ev import syscmdkeys' then access the properties on the imported syscmdkeys object. - For example, try objects.all() to get all - ObjectDB objects in the database. - """ from src.commands import cmdhandler CMD_NOINPUT = cmdhandler.CMD_NOINPUT @@ -237,4 +265,4 @@ class SystemCmds(object): del cmdhandler syscmdkeys = SystemCmds() del SystemCmds - +del _EvContainer diff --git a/src/commands/default/general.py b/src/commands/default/general.py index 69471d615e..defe862841 100644 --- a/src/commands/default/general.py +++ b/src/commands/default/general.py @@ -967,7 +967,7 @@ class CmdIC(MuxCommandOOC): if new_character.sessid == sessid: self.msg("{RYou already act as {c%s{n." % new_character.name) return - elif new_character.player == caller: + elif new_character.sessid and new_character.player == caller: self.msg("{RYou already act as {c%s{n in another session." % new_character.name) return elif not caller.get_character(character=new_character): @@ -990,7 +990,7 @@ class CmdIC(MuxCommandOOC): new_character.location.at_object_receive(new_character, new_character.location) new_character.execute_cmd("look") else: - msg.msg("{rYou cannot become {C%s{n." % new_character.name) + self.msg("{rYou cannot become {C%s{n." % new_character.name) class CmdOOC(MuxCommandOOC): """ diff --git a/src/commands/default/system.py b/src/commands/default/system.py index 323652fb5f..2063cf4a59 100644 --- a/src/commands/default/system.py +++ b/src/commands/default/system.py @@ -130,6 +130,9 @@ class CmdPy(MuxCommand): ev : the evennia API inherits_from(obj, parent) : check object inheritance + You can explore The evennia API from inside the game by calling + ev.help(), ev.managers.help() etc. + {rNote: In the wrong hands this command is a severe security risk. It should only be accessible by trusted server admins/superusers.{n diff --git a/src/commands/default/unloggedin.py b/src/commands/default/unloggedin.py index 98a8351f73..4c8db0696a 100644 --- a/src/commands/default/unloggedin.py +++ b/src/commands/default/unloggedin.py @@ -198,8 +198,6 @@ class CmdUnconnectedCreate(MuxCommand): # If no description is set, set a default description if not new_character.db.desc: new_character.db.desc = "This is a Player." - # set flag for triggering first-time login hook - new_character.db._first_login = True # tell the caller everything went well. string = "A new account '%s' was created. Welcome!" diff --git a/src/players/player.py b/src/players/player.py index 1074b56827..bb96345ba2 100644 --- a/src/players/player.py +++ b/src/players/player.py @@ -292,6 +292,7 @@ class Player(TypeClass): Only called once, the very first time the user logs in. """ + print "player at_first_login", self pass def at_pre_login(self):