Moved contribs to use the new API. Added the system command keys to a property syscmdkeys, for easy access from ev.py.

This commit is contained in:
Griatch 2012-03-25 18:11:14 +02:00
parent d3ea942ac8
commit 93a1646ea7
5 changed files with 67 additions and 43 deletions

View file

@ -23,15 +23,12 @@ add the following line to the end of OOCCmdSet's at_cmdset_creation():
""" """
from django.conf import settings from django.conf import settings
from src.commands.command import Command from ev import Command, create_object, utils
from src.commands.default.general import CmdLook from ev import default_cmds, db_objects
from src.commands.default.cmdset_ooc import OOCCmdSet
from src.objects.models import ObjectDB
from src.utils import utils, create
CHARACTER_TYPECLASS = settings.BASE_CHARACTER_TYPECLASS CHARACTER_TYPECLASS = settings.BASE_CHARACTER_TYPECLASS
class CmdOOCLook(CmdLook): class CmdOOCLook(default_cmds.CmdLook):
""" """
ooc look ooc look
@ -82,7 +79,7 @@ class CmdOOCLook(CmdLook):
if not avail_chars: if not avail_chars:
self.caller.msg("You have no characters to look at. Why not create one?") self.caller.msg("You have no characters to look at. Why not create one?")
return return
objs = ObjectDB.objects.get_objs_with_key_and_typeclass(self.args.strip(), CHARACTER_TYPECLASS) objs = db_objects.get_objs_with_key_and_typeclass(self.args.strip(), CHARACTER_TYPECLASS)
objs = [obj for obj in objs if obj.id in avail_chars] objs = [obj for obj in objs if obj.id in avail_chars]
if not objs: if not objs:
self.caller.msg("You cannot see this Character.") self.caller.msg("You cannot see this Character.")
@ -95,7 +92,7 @@ class CmdOOCLook(CmdLook):
charnames = [] charnames = []
if self.caller.db._character_dbrefs: if self.caller.db._character_dbrefs:
dbrefs = self.caller.db._character_dbrefs dbrefs = self.caller.db._character_dbrefs
charobjs = [ObjectDB.objects.get_id(dbref) for dbref in dbrefs] charobjs = [db_objects.get_id(dbref) for dbref in dbrefs]
charnames = [charobj.key for charobj in charobjs if charobj] charnames = [charobj.key for charobj in charobjs if charobj]
if charnames: if charnames:
charlist = "The following Character(s) are available:\n\n" charlist = "The following Character(s) are available:\n\n"
@ -152,13 +149,13 @@ class CmdOOCCharacterCreate(Command):
self.caller.msg("Usage: create <character name>") self.caller.msg("Usage: create <character name>")
return return
charname = self.args.strip() charname = self.args.strip()
old_char = ObjectDB.objects.get_objs_with_key_and_typeclass(charname, CHARACTER_TYPECLASS) old_char = db_objects.get_objs_with_key_and_typeclass(charname, CHARACTER_TYPECLASS)
if old_char: if old_char:
self.caller.msg("Character {c%s{n already exists." % charname) self.caller.msg("Character {c%s{n already exists." % charname)
return return
# create the character # create the character
new_character = create.create_object(CHARACTER_TYPECLASS, key=charname) new_character = create_object(CHARACTER_TYPECLASS, key=charname)
if not new_character: if not new_character:
self.caller.msg("{rThe Character couldn't be created. This is a bug. Please contact an admin.") self.caller.msg("{rThe Character couldn't be created. This is a bug. Please contact an admin.")
return return
@ -176,7 +173,7 @@ class CmdOOCCharacterCreate(Command):
self.caller.msg("{gThe Character {c%s{g was successfully created!" % charname) self.caller.msg("{gThe Character {c%s{g was successfully created!" % charname)
class OOCCmdSetCharGen(OOCCmdSet): class OOCCmdSetCharGen(default_cmds.OOCCmdSet):
""" """
Extends the default OOC cmdset. Extends the default OOC cmdset.
""" """

View file

@ -17,12 +17,13 @@ Features of the editor:
""" """
import re import re
from src.commands.command import Command from ev import Command, CmdSet, utils
from src.commands.cmdset import CmdSet from ev import syscmdkeys
from src.commands.cmdhandler import CMD_NOMATCH, CMD_NOINPUT
from src.utils import utils
from contrib.menusystem import prompt_yesno from contrib.menusystem import prompt_yesno
CMD_NOMATCH = syscmdkeys.CMD_NOMATCH
CMD_NOINPUT = syscmdkeys.CMD_NOINPUT
RE_GROUP = re.compile(r"\".*?\"|\'.*?\'|\S*") RE_GROUP = re.compile(r"\".*?\"|\'.*?\'|\S*")
class CmdEditorBase(Command): class CmdEditorBase(Command):

View file

@ -31,15 +31,16 @@ the initial splash screen.
import re import re
import traceback import traceback
from django.conf import settings from django.conf import settings
from src.players.models import PlayerDB from ev import db_players, db_serverconfs, db_channels
from src.server.models import ServerConfig from ev import utils, logger, create_player
from src.comms.models import Channel from ev import Command, CmdSet
from ev import syscmdkeys
from src.utils import create, logger, utils from contrib.menusystem import MenuNode, MenuTree
from src.commands.command import Command
from src.commands.cmdset import CmdSet CMD_LOGINSTART = syscmdkeys.CMD_LOGINSTART
from src.commands.cmdhandler import CMD_LOGINSTART CMD_NOINPUT = syscmdkeys.CMD_NOINPUT
from contrib.menusystem import MenuNode, MenuTree, CMD_NOINPUT, CMD_NOMATCH CMD_NOMATCH = syscmdkeys.CMD_NOMATCH
CONNECTION_SCREEN_MODULE = settings.CONNECTION_SCREEN_MODULE CONNECTION_SCREEN_MODULE = settings.CONNECTION_SCREEN_MODULE
@ -74,7 +75,7 @@ class CmdUsernameSelect(Command):
locks = "cmd:all()" locks = "cmd:all()"
def func(self): def func(self):
"Execute the command" "Execute the command"
player = PlayerDB.objects.get_player_from_name(self.args) player = db_players.get_player_from_name(self.args)
if not player: if not player:
self.caller.msg("{rThis account name couldn't be found. Did you create it? If you did, make sure you spelled it right (case doesn't matter).{n") self.caller.msg("{rThis account name couldn't be found. Did you create it? If you did, make sure you spelled it right (case doesn't matter).{n")
self.menutree.goto("node1a") self.menutree.goto("node1a")
@ -114,7 +115,7 @@ class CmdPasswordSelect(Command):
return return
# before going on, check eventual bans # before going on, check eventual bans
bans = ServerConfig.objects.conf("server_bans") bans = db_serverconfs.conf("server_bans")
if bans and (any(tup[0]==player.name for tup in bans) if bans and (any(tup[0]==player.name for tup in bans)
or or
any(tup[2].match(player.sessions[0].address[0]) for tup in bans if tup[2])): any(tup[2].match(player.sessions[0].address[0]) for tup in bans if tup[2])):
@ -159,7 +160,7 @@ class CmdUsernameCreate(Command):
its and @/./+/-/_ only.{n") # this echoes the restrictions made by django's auth module. its and @/./+/-/_ only.{n") # this echoes the restrictions made by django's auth module.
self.menutree.goto("node2a") self.menutree.goto("node2a")
return return
if PlayerDB.objects.get_player_from_name(playername): if db_players.get_player_from_name(playername):
self.caller.msg("\n\r {rAccount name %s already exists.{n" % playername) self.caller.msg("\n\r {rAccount name %s already exists.{n" % playername)
self.menutree.goto("node2a") self.menutree.goto("node2a")
return return
@ -202,10 +203,10 @@ class CmdPasswordCreate(Command):
try: try:
permissions = settings.PERMISSION_PLAYER_DEFAULT permissions = settings.PERMISSION_PLAYER_DEFAULT
typeclass = settings.BASE_PLAYER_TYPECLASS typeclass = settings.BASE_PLAYER_TYPECLASS
new_player = create.create_player(playername, None, password, new_player = create_player(playername, None, password,
typeclass=typeclass, typeclass=typeclass,
permissions=permissions, permissions=permissions,
create_character=False) create_character=False)
if not new_player: if not new_player:
self.msg("There was an error creating the Player. This error was logged. Contact an admin.") self.msg("There was an error creating the Player. This error was logged. Contact an admin.")
self.menutree.goto("START") self.menutree.goto("START")
@ -215,7 +216,7 @@ class CmdPasswordCreate(Command):
# join the new player to the public channel # join the new player to the public channel
pchanneldef = settings.CHANNEL_PUBLIC pchanneldef = settings.CHANNEL_PUBLIC
if pchanneldef: if pchanneldef:
pchannel = Channel.objects.get_channel(pchanneldef[0]) pchannel = db_channels.get_channel(pchanneldef[0])
if not pchannel.connect_to(new_player): if not pchannel.connect_to(new_player):
string = "New player '%s' could not connect to public channel!" % new_player.key string = "New player '%s' could not connect to public channel!" % new_player.key
logger.log_errmsg(string) logger.log_errmsg(string)

View file

@ -23,16 +23,16 @@ game.gamesrc.commands.basecmdset. The test command is also a good
example of how to use this module in code. example of how to use this module in code.
""" """
from src.commands.cmdhandler import CMD_NOMATCH, CMD_NOINPUT from ev import syscmdkeys
from src.commands.command import Command
from src.commands.cmdset import CmdSet
from src.commands.default.general import CmdLook
from src.commands.default.help import CmdHelp
from src.utils import utils
# imported only to make them available during execution of code blocks from ev import Command, CmdSet, utils
from src.objects.models import ObjectDB from ev import default_cmds
from src.players.models import PlayerDB
# imported only to make it available during execution of code blocks
import ev
CMD_NOMATCH = syscmdkeys.CMD_NOMATCH
CMD_NOINPUT = syscmdkeys.CMD_NOINPUT
# #
@ -61,7 +61,7 @@ class CmdMenuNode(Command):
else: else:
self.caller.msg("{rThis option is not available.{n") self.caller.msg("{rThis option is not available.{n")
class CmdMenuLook(CmdLook): class CmdMenuLook(default_cmds.CmdLook):
""" """
ooc look ooc look
@ -88,7 +88,7 @@ class CmdMenuLook(CmdLook):
# otherwise we use normal look # otherwise we use normal look
super(CmdMenuLook, self).func() super(CmdMenuLook, self).func()
class CmdMenuHelp(CmdHelp): class CmdMenuHelp(default_cmds.CmdHelp):
""" """
help help
@ -241,7 +241,7 @@ class MenuNode(object):
commands have access to self.menutree and so can be used to select nodes. commands have access to self.menutree and so can be used to select nodes.
code - functional code. This will be executed just before this node is loaded (i.e. code - functional code. This will be executed just before this node is loaded (i.e.
as soon after it's been selected from another node). self.caller is available as soon after it's been selected from another node). self.caller is available
to call from this code block, as well as ObjectDB and PlayerDB. to call from this code block, as well as ev.
nodefaultcmds - if true, don't offer the default help and look commands in the node nodefaultcmds - if true, don't offer the default help and look commands in the node
separator - this string will be put on the line between menu nodes5B. separator - this string will be put on the line between menu nodes5B.
""" """

25
ev.py
View file

@ -78,6 +78,31 @@ from src.commands.command import Command
from src.commands.cmdset import CmdSet from src.commands.cmdset import CmdSet
from src.commands import default as default_cmds from src.commands import default as default_cmds
class SystemCmds(object):
"""
Creating commands with keys set to these constants will make
them system commands called as a replacement by the parser when
special situations occur. If not defined, the hard-coded
responses in the server are used.
CMD_NOINPUT - no input was given on command line
CMD_NOMATCH - no valid command key was found
CMD_MULTIMATCH - multiple command matches were found
CMD_CHANNEL - the command name is a channel name
CMD_LOGINSTART - this command will be called as the very
first command when a player connects to
the server.
"""
from src.commands import cmdhandler
CMD_NOINPUT = cmdhandler.CMD_NOINPUT
CMD_NOMATCH = cmdhandler.CMD_NOMATCH
CMD_MULTIMATCH = cmdhandler.CMD_MULTIMATCH
CMD_CHANNEL = cmdhandler.CMD_CHANNEL
CMD_LOGINSTART = cmdhandler.CMD_LOGINSTART
del cmdhandler
syscmdkeys = SystemCmds()
# locks # locks
from src.locks import lockfuncs from src.locks import lockfuncs