Some further bug fixes.

This commit is contained in:
Griatch 2013-04-09 11:14:08 +02:00
parent 20a57d4167
commit 5100a0561f
5 changed files with 48 additions and 18 deletions

56
ev.py
View file

@ -3,10 +3,14 @@
Central API for the Evennia MUD/MUX/MU* creation system. 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. 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: 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 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 dot-notation to import deeper. Hence, to access a default command, you can do
import ev import ev
@ -133,10 +137,36 @@ from src.utils import gametime
from src.utils import ansi 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. Links to instantiated database managers.
@ -149,9 +179,6 @@ class DBmanagers(object):
externalconnections - ExternalChannelConnection.objects externalconnections - ExternalChannelConnection.objects
objects - ObjectDB.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.help.models import HelpEntry
from src.players.models import PlayerDB from src.players.models import PlayerDB
@ -171,13 +198,17 @@ class DBmanagers(object):
serverconfigs = ServerConfig.objects serverconfigs = ServerConfig.objects
del HelpEntry, PlayerDB, ScriptDB, Msg, Channel, PlayerChannelConnection, del HelpEntry, PlayerDB, ScriptDB, Msg, Channel, PlayerChannelConnection,
del ExternalChannelConnection, ObjectDB, ServerConfig del ExternalChannelConnection, ObjectDB, ServerConfig
managers = DBmanagers() managers = DBmanagers()
del DBmanagers del DBmanagers
class DefaultCmds(object): class DefaultCmds(_EvContainer):
""" """
This container holds direct shortcuts to all default commands in This container holds direct shortcuts to all default commands in Evennia.
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 from src.commands.default.cmdset_default import DefaultCmdSet
@ -206,7 +237,7 @@ class DefaultCmds(object):
default_cmds = DefaultCmds() default_cmds = DefaultCmds()
del DefaultCmds del DefaultCmds
class SystemCmds(object): class SystemCmds(_EvContainer):
""" """
Creating commands with keys set to these constants will make Creating commands with keys set to these constants will make
them system commands called as a replacement by the parser when 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 To access in code, do 'from ev import syscmdkeys' then
access the properties on the imported syscmdkeys object. 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 from src.commands import cmdhandler
CMD_NOINPUT = cmdhandler.CMD_NOINPUT CMD_NOINPUT = cmdhandler.CMD_NOINPUT
@ -237,4 +265,4 @@ class SystemCmds(object):
del cmdhandler del cmdhandler
syscmdkeys = SystemCmds() syscmdkeys = SystemCmds()
del SystemCmds del SystemCmds
del _EvContainer

View file

@ -967,7 +967,7 @@ class CmdIC(MuxCommandOOC):
if new_character.sessid == sessid: if new_character.sessid == sessid:
self.msg("{RYou already act as {c%s{n." % new_character.name) self.msg("{RYou already act as {c%s{n." % new_character.name)
return 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) self.msg("{RYou already act as {c%s{n in another session." % new_character.name)
return return
elif not caller.get_character(character=new_character): 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.location.at_object_receive(new_character, new_character.location)
new_character.execute_cmd("look") new_character.execute_cmd("look")
else: 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): class CmdOOC(MuxCommandOOC):
""" """

View file

@ -130,6 +130,9 @@ class CmdPy(MuxCommand):
ev : the evennia API ev : the evennia API
inherits_from(obj, parent) : check object inheritance 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. {rNote: In the wrong hands this command is a severe security risk.
It should only be accessible by trusted server admins/superusers.{n It should only be accessible by trusted server admins/superusers.{n

View file

@ -198,8 +198,6 @@ class CmdUnconnectedCreate(MuxCommand):
# 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."
# set flag for triggering first-time login hook
new_character.db._first_login = True
# 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!"

View file

@ -292,6 +292,7 @@ class Player(TypeClass):
Only called once, the very first Only called once, the very first
time the user logs in. time the user logs in.
""" """
print "player at_first_login", self
pass pass
def at_pre_login(self): def at_pre_login(self):