mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
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:
parent
d3ea942ac8
commit
93a1646ea7
5 changed files with 67 additions and 43 deletions
|
|
@ -23,15 +23,12 @@ add the following line to the end of OOCCmdSet's at_cmdset_creation():
|
|||
"""
|
||||
|
||||
from django.conf import settings
|
||||
from src.commands.command import Command
|
||||
from src.commands.default.general import CmdLook
|
||||
from src.commands.default.cmdset_ooc import OOCCmdSet
|
||||
from src.objects.models import ObjectDB
|
||||
from src.utils import utils, create
|
||||
from ev import Command, create_object, utils
|
||||
from ev import default_cmds, db_objects
|
||||
|
||||
CHARACTER_TYPECLASS = settings.BASE_CHARACTER_TYPECLASS
|
||||
|
||||
class CmdOOCLook(CmdLook):
|
||||
class CmdOOCLook(default_cmds.CmdLook):
|
||||
"""
|
||||
ooc look
|
||||
|
||||
|
|
@ -82,7 +79,7 @@ class CmdOOCLook(CmdLook):
|
|||
if not avail_chars:
|
||||
self.caller.msg("You have no characters to look at. Why not create one?")
|
||||
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]
|
||||
if not objs:
|
||||
self.caller.msg("You cannot see this Character.")
|
||||
|
|
@ -95,7 +92,7 @@ class CmdOOCLook(CmdLook):
|
|||
charnames = []
|
||||
if 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]
|
||||
if charnames:
|
||||
charlist = "The following Character(s) are available:\n\n"
|
||||
|
|
@ -152,13 +149,13 @@ class CmdOOCCharacterCreate(Command):
|
|||
self.caller.msg("Usage: create <character name>")
|
||||
return
|
||||
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:
|
||||
self.caller.msg("Character {c%s{n already exists." % charname)
|
||||
return
|
||||
# create the character
|
||||
|
||||
new_character = create.create_object(CHARACTER_TYPECLASS, key=charname)
|
||||
new_character = create_object(CHARACTER_TYPECLASS, key=charname)
|
||||
if not new_character:
|
||||
self.caller.msg("{rThe Character couldn't be created. This is a bug. Please contact an admin.")
|
||||
return
|
||||
|
|
@ -176,7 +173,7 @@ class CmdOOCCharacterCreate(Command):
|
|||
|
||||
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.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -17,12 +17,13 @@ Features of the editor:
|
|||
"""
|
||||
|
||||
import re
|
||||
from src.commands.command import Command
|
||||
from src.commands.cmdset import CmdSet
|
||||
from src.commands.cmdhandler import CMD_NOMATCH, CMD_NOINPUT
|
||||
from src.utils import utils
|
||||
from ev import Command, CmdSet, utils
|
||||
from ev import syscmdkeys
|
||||
from contrib.menusystem import prompt_yesno
|
||||
|
||||
CMD_NOMATCH = syscmdkeys.CMD_NOMATCH
|
||||
CMD_NOINPUT = syscmdkeys.CMD_NOINPUT
|
||||
|
||||
RE_GROUP = re.compile(r"\".*?\"|\'.*?\'|\S*")
|
||||
|
||||
class CmdEditorBase(Command):
|
||||
|
|
|
|||
|
|
@ -31,15 +31,16 @@ the initial splash screen.
|
|||
import re
|
||||
import traceback
|
||||
from django.conf import settings
|
||||
from src.players.models import PlayerDB
|
||||
from src.server.models import ServerConfig
|
||||
from src.comms.models import Channel
|
||||
from ev import db_players, db_serverconfs, db_channels
|
||||
from ev import utils, logger, create_player
|
||||
from ev import Command, CmdSet
|
||||
from ev import syscmdkeys
|
||||
|
||||
from src.utils import create, logger, utils
|
||||
from src.commands.command import Command
|
||||
from src.commands.cmdset import CmdSet
|
||||
from src.commands.cmdhandler import CMD_LOGINSTART
|
||||
from contrib.menusystem import MenuNode, MenuTree, CMD_NOINPUT, CMD_NOMATCH
|
||||
from contrib.menusystem import MenuNode, MenuTree
|
||||
|
||||
CMD_LOGINSTART = syscmdkeys.CMD_LOGINSTART
|
||||
CMD_NOINPUT = syscmdkeys.CMD_NOINPUT
|
||||
CMD_NOMATCH = syscmdkeys.CMD_NOMATCH
|
||||
|
||||
CONNECTION_SCREEN_MODULE = settings.CONNECTION_SCREEN_MODULE
|
||||
|
||||
|
|
@ -74,7 +75,7 @@ class CmdUsernameSelect(Command):
|
|||
locks = "cmd:all()"
|
||||
def func(self):
|
||||
"Execute the command"
|
||||
player = PlayerDB.objects.get_player_from_name(self.args)
|
||||
player = db_players.get_player_from_name(self.args)
|
||||
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.menutree.goto("node1a")
|
||||
|
|
@ -114,7 +115,7 @@ class CmdPasswordSelect(Command):
|
|||
return
|
||||
|
||||
# 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)
|
||||
or
|
||||
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.
|
||||
self.menutree.goto("node2a")
|
||||
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.menutree.goto("node2a")
|
||||
return
|
||||
|
|
@ -202,10 +203,10 @@ class CmdPasswordCreate(Command):
|
|||
try:
|
||||
permissions = settings.PERMISSION_PLAYER_DEFAULT
|
||||
typeclass = settings.BASE_PLAYER_TYPECLASS
|
||||
new_player = create.create_player(playername, None, password,
|
||||
typeclass=typeclass,
|
||||
permissions=permissions,
|
||||
create_character=False)
|
||||
new_player = create_player(playername, None, password,
|
||||
typeclass=typeclass,
|
||||
permissions=permissions,
|
||||
create_character=False)
|
||||
if not new_player:
|
||||
self.msg("There was an error creating the Player. This error was logged. Contact an admin.")
|
||||
self.menutree.goto("START")
|
||||
|
|
@ -215,7 +216,7 @@ class CmdPasswordCreate(Command):
|
|||
# join the new player to the public channel
|
||||
pchanneldef = settings.CHANNEL_PUBLIC
|
||||
if pchanneldef:
|
||||
pchannel = Channel.objects.get_channel(pchanneldef[0])
|
||||
pchannel = db_channels.get_channel(pchanneldef[0])
|
||||
if not pchannel.connect_to(new_player):
|
||||
string = "New player '%s' could not connect to public channel!" % new_player.key
|
||||
logger.log_errmsg(string)
|
||||
|
|
|
|||
|
|
@ -23,16 +23,16 @@ game.gamesrc.commands.basecmdset. The test command is also a good
|
|||
example of how to use this module in code.
|
||||
|
||||
"""
|
||||
from src.commands.cmdhandler import CMD_NOMATCH, CMD_NOINPUT
|
||||
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
|
||||
from ev import syscmdkeys
|
||||
|
||||
# imported only to make them available during execution of code blocks
|
||||
from src.objects.models import ObjectDB
|
||||
from src.players.models import PlayerDB
|
||||
from ev import Command, CmdSet, utils
|
||||
from ev import default_cmds
|
||||
|
||||
# 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:
|
||||
self.caller.msg("{rThis option is not available.{n")
|
||||
|
||||
class CmdMenuLook(CmdLook):
|
||||
class CmdMenuLook(default_cmds.CmdLook):
|
||||
"""
|
||||
ooc look
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ class CmdMenuLook(CmdLook):
|
|||
# otherwise we use normal look
|
||||
super(CmdMenuLook, self).func()
|
||||
|
||||
class CmdMenuHelp(CmdHelp):
|
||||
class CmdMenuHelp(default_cmds.CmdHelp):
|
||||
"""
|
||||
help
|
||||
|
||||
|
|
@ -241,7 +241,7 @@ class MenuNode(object):
|
|||
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.
|
||||
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
|
||||
separator - this string will be put on the line between menu nodes5B.
|
||||
"""
|
||||
|
|
|
|||
25
ev.py
25
ev.py
|
|
@ -78,6 +78,31 @@ from src.commands.command import Command
|
|||
from src.commands.cmdset import CmdSet
|
||||
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
|
||||
from src.locks import lockfuncs
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue