mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Fixing a bug in @ic if trying to puppet while already puppeting. Added sessid keyword to at_post_login hook in order to correctly relay login text only to the correct session. Removed the src.utils.debug module as well as the CmdDebug command which has not been supported for a good while.
This commit is contained in:
parent
a3f12a289d
commit
416d6e14bc
10 changed files with 22 additions and 316 deletions
|
|
@ -61,7 +61,7 @@ class ExamplePlayer(Player):
|
|||
|
||||
msg(outgoing_string, from_obj=None, data=None)
|
||||
swap_character(new_character, delete_old_character=False)
|
||||
execute_cmd(raw_string)
|
||||
execute_cmd(raw_string, sessid=None)
|
||||
search(ostring, global_search=False, attribute_name=None, use_nicks=False, location=None, ignore_errors=False, player=False)
|
||||
is_typeclass(typeclass, exact=False)
|
||||
swap_typeclass(new_typeclass, clean_attributes=False, no_default=True)
|
||||
|
|
@ -79,7 +79,7 @@ class ExamplePlayer(Player):
|
|||
at_init()
|
||||
at_cmdset_get()
|
||||
at_first_login()
|
||||
at_post_login()
|
||||
at_post_login(sessid=None)
|
||||
at_disconnect()
|
||||
at_message_receive()
|
||||
at_message_send()
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@ Building and world design commands
|
|||
from django.conf import settings
|
||||
from src.objects.models import ObjectDB, ObjAttribute
|
||||
from src.players.models import PlayerAttribute
|
||||
from src.utils import create, utils, debug
|
||||
from src.utils import create, utils
|
||||
from src.utils.ansi import raw
|
||||
from src.commands.default.muxcommand import MuxCommand
|
||||
from src.commands.cmdhandler import get_and_merge_cmdsets
|
||||
|
||||
# limit symbol import for API
|
||||
__all__ = ("ObjManipCommand", "CmdSetObjAlias", "CmdCopy",
|
||||
"CmdCpAttr", "CmdMvAttr", "CmdCreate", "CmdDebug",
|
||||
"CmdCpAttr", "CmdMvAttr", "CmdCreate",
|
||||
"CmdDesc", "CmdDestroy", "CmdDig", "CmdTunnel", "CmdLink",
|
||||
"CmdUnLink", "CmdSetHome", "CmdListCmdSets", "CmdName",
|
||||
"CmdOpen", "CmdSetAttribute", "CmdTypeclass", "CmdWipe",
|
||||
|
|
@ -426,49 +426,6 @@ class CmdCreate(ObjManipCommand):
|
|||
if string:
|
||||
caller.msg(string)
|
||||
|
||||
|
||||
class CmdDebug(MuxCommand):
|
||||
"""
|
||||
Debug game entities
|
||||
|
||||
Usage:
|
||||
@debug[/switch] <path to code>
|
||||
|
||||
Switches:
|
||||
obj - debug an object
|
||||
script - debug a script
|
||||
|
||||
Examples:
|
||||
@debug/script game.gamesrc.scripts.myscript.MyScript
|
||||
@debug/script myscript.MyScript
|
||||
@debug/obj examples.red_button.RedButton
|
||||
|
||||
This command helps when debugging the codes of objects and scripts.
|
||||
It creates the given object and runs tests on its hooks.
|
||||
"""
|
||||
|
||||
key = "@debug"
|
||||
locks = "cmd:perm(debug) or perm(Builders)"
|
||||
help_category = "Building"
|
||||
|
||||
def func(self):
|
||||
"Running the debug"
|
||||
|
||||
if not self.args or not self.switches:
|
||||
self.caller.msg("Usage: @debug[/obj][/script] <path>")
|
||||
return
|
||||
|
||||
path = self.args
|
||||
|
||||
if 'obj' in self.switches or 'object' in self.switches:
|
||||
# create and debug the object
|
||||
self.caller.msg(debug.debug_object(path, self.caller))
|
||||
self.caller.msg(debug.debug_object_scripts(path, self.caller))
|
||||
|
||||
elif 'script' in self.switches:
|
||||
self.caller.msg(debug.debug_syntax_script(path))
|
||||
|
||||
|
||||
class CmdDesc(MuxCommand):
|
||||
"""
|
||||
@desc - describe an object or room
|
||||
|
|
|
|||
|
|
@ -58,7 +58,6 @@ class CharacterCmdSet(CmdSet):
|
|||
self.add(building.CmdTeleport())
|
||||
self.add(building.CmdSetObjAlias())
|
||||
self.add(building.CmdListCmdSets())
|
||||
self.add(building.CmdDebug())
|
||||
self.add(building.CmdWipe())
|
||||
self.add(building.CmdSetAttribute())
|
||||
self.add(building.CmdName())
|
||||
|
|
|
|||
|
|
@ -237,7 +237,6 @@ class CmdIC(MuxPlayerCommand):
|
|||
self.msg("{rYou may not become %s.{n" % new_character.name)
|
||||
return
|
||||
if player.puppet_object(sessid, new_character):
|
||||
self.msg("\n{gYou become {c%s{n.\n" % new_character.name)
|
||||
player.db._last_puppet = new_character
|
||||
if not new_character.location:
|
||||
# this might be due to being hidden away at logout; check
|
||||
|
|
@ -245,10 +244,7 @@ class CmdIC(MuxPlayerCommand):
|
|||
if not loc: # still no location; use home
|
||||
loc = new_character.home
|
||||
new_character.location = loc
|
||||
if new_character.location:
|
||||
new_character.location.msg_contents("%s has entered the game." % new_character.key, exclude=[new_character])
|
||||
new_character.location.at_object_receive(new_character, new_character.location)
|
||||
new_character.execute_cmd("look")
|
||||
new_character.location.at_object_receive(new_character, new_character.location)
|
||||
else:
|
||||
self.msg("{rYou cannot become {C%s{n." % new_character.name)
|
||||
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ class CmdUnconnectedConnect(MuxCommand):
|
|||
# player.at_init() # always called when object is loaded from disk
|
||||
# player.at_pre_login()
|
||||
# player.at_first_login() # only once
|
||||
# player.at_post_login()
|
||||
# player.at_post_login(sessid=sessid)
|
||||
session.sessionhandler.login(session, player)
|
||||
|
||||
class CmdUnconnectedCreate(MuxCommand):
|
||||
|
|
|
|||
|
|
@ -803,6 +803,15 @@ class Character(Object):
|
|||
self.location.msg_contents("%s has entered the game." % self.name, exclude=[self])
|
||||
self.location.at_object_receive(self, self.location)
|
||||
|
||||
def at_post_puppet(self):
|
||||
"""
|
||||
Called just after puppeting has completed.
|
||||
"""
|
||||
self.msg("\nYou become {c%s{n.\n" % self.name)
|
||||
self.execute_cmd("look")
|
||||
if self.location:
|
||||
self.location.msg_contents("%s has entered the game." % self.name, exclude=[self])
|
||||
|
||||
def at_post_unpuppet(self, player):
|
||||
"""
|
||||
We stove away the character when the player goes ooc/logs off, otherwise the character object will
|
||||
|
|
|
|||
|
|
@ -407,7 +407,7 @@ class PlayerDB(TypedObject):
|
|||
return False
|
||||
if normal_mode and session.puppet:
|
||||
# cleanly unpuppet eventual previous object puppeted by this session
|
||||
self.unpuppet_object(self, sessid)
|
||||
self.unpuppet_object(sessid)
|
||||
if obj.player and obj.player.is_connected and obj.player != self:
|
||||
# we don't allow to puppet an object already controlled by an active
|
||||
# player. To kick a player, call unpuppet_object on them explicitly.
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ class Player(TypeClass):
|
|||
at_init()
|
||||
at_cmdset_get()
|
||||
at_first_login()
|
||||
at_post_login()
|
||||
at_post_login(sessid=None)
|
||||
at_disconnect()
|
||||
at_message_receive()
|
||||
at_message_send()
|
||||
|
|
@ -313,7 +313,7 @@ class Player(TypeClass):
|
|||
else:
|
||||
logger.log_infomsg("[%s]: %s" % (now, message))
|
||||
|
||||
def at_post_login(self):
|
||||
def at_post_login(self, sessid=None):
|
||||
"""
|
||||
Called at the end of the login process, just before letting
|
||||
them loose. This is called before an eventual Character's
|
||||
|
|
@ -324,17 +324,17 @@ class Player(TypeClass):
|
|||
# in this mode we should have only one character available. We
|
||||
# try to auto-connect to it by calling the @ic command
|
||||
# (this relies on player.db._last_puppet being set)
|
||||
self.execute_cmd("@ic")
|
||||
self.execute_cmd("@ic", sessid=sessid)
|
||||
elif _MULTISESSION_MODE == 1:
|
||||
# in this mode the first session to connect acts like mode 0,
|
||||
# the following sessions "share" the same view and should
|
||||
# not perform any actions
|
||||
if not self.get_all_puppets():
|
||||
self.execute_cmd("@ic")
|
||||
self.execute_cmd("@ic", sessid=sessid)
|
||||
elif _MULTISESSION_MODE == 2:
|
||||
# In this mode we by default end up at a character selection
|
||||
# screen. We execute look on the player.
|
||||
self.execute_cmd("look")
|
||||
self.execute_cmd("look", sessid=sessid)
|
||||
|
||||
def at_disconnect(self, reason=None):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -231,7 +231,7 @@ class ServerSessionHandler(SessionHandler):
|
|||
self.server.amp_protocol.call_remote_PortalAdmin(session.sessid,
|
||||
operation=SLOGIN,
|
||||
data=sessdata)
|
||||
player.at_post_login()
|
||||
player.at_post_login(sessid=session.sessid)
|
||||
|
||||
def disconnect(self, session, reason=""):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,255 +0,0 @@
|
|||
"""
|
||||
Debug mechanisms for easier developing advanced game objects
|
||||
|
||||
|
||||
The functions in this module are intended to stress-test various
|
||||
aspects of an in-game entity, notably objects and scripts, during
|
||||
development. This allows to run several automated tests on the
|
||||
entity without having to do the testing by creating/deleting etc
|
||||
in-game.
|
||||
|
||||
The default Evennia accesses the methods of this module through
|
||||
a special state and cmdset, using the @debug command.
|
||||
|
||||
"""
|
||||
|
||||
from traceback import format_exc
|
||||
from src.utils import create
|
||||
|
||||
|
||||
def trace():
|
||||
"Format the traceback."
|
||||
errlist = format_exc().split('\n')
|
||||
if len(errlist) > 4:
|
||||
errlist = errlist[4:]
|
||||
ret = "\n" + "\n".join("<<< {r%s{n" % line for line in errlist if line)
|
||||
return ret
|
||||
|
||||
#
|
||||
# Testing scripts
|
||||
#
|
||||
|
||||
def debug_script(script_path, obj=None, auto_delete=True):
|
||||
"""
|
||||
This function takes a script database object (ScriptDB) and tests
|
||||
all its hooks for syntax errors. Note that no run-time errors
|
||||
will be caught, only weird python syntax.
|
||||
|
||||
script_path - the full path to the script typeclass module and class.
|
||||
|
||||
"""
|
||||
try:
|
||||
string = "Test-creating a new script of this type ... "
|
||||
scriptobj = create.create_script(script_path, autostart=False)
|
||||
scriptobj.obj = obj
|
||||
scriptobj.save()
|
||||
string += "{gOk{n."
|
||||
except Exception:
|
||||
string += trace()
|
||||
try: scriptobj.delete()
|
||||
except: pass
|
||||
return string
|
||||
|
||||
string += "\nRunning syntax check ..."
|
||||
try:
|
||||
string += "\nTesting syntax of at_script_creation(self) ... "
|
||||
ret = scriptobj.at_script_creation()
|
||||
string += "{gOk{n."
|
||||
except Exception:
|
||||
string += trace()
|
||||
try:
|
||||
string += "\nTesting syntax of is_valid(self) ... "
|
||||
ret = scriptobj.is_valid()
|
||||
string += "{gOk{n."
|
||||
except Exception:
|
||||
string += trace()
|
||||
try:
|
||||
string += "\nTesting syntax of at_start(self) ... "
|
||||
ret = scriptobj.at_start()
|
||||
string += "{gOk{n."
|
||||
except Exception:
|
||||
string += trace()
|
||||
try:
|
||||
string += "\nTesting syntax of at_repeat(self) ... "
|
||||
ret = scriptobj.at_repeat()
|
||||
string += "{gOk{n."
|
||||
except Exception:
|
||||
string += trace()
|
||||
try:
|
||||
string += "\nTesting syntax of at_stop(self) ... "
|
||||
ret = scriptobj.at_script_creation()
|
||||
string += "{gOk{n."
|
||||
except Exception:
|
||||
string += trace()
|
||||
|
||||
if auto_delete:
|
||||
try:
|
||||
scriptobj.delete()
|
||||
except:
|
||||
string += trace()
|
||||
|
||||
return string
|
||||
|
||||
#
|
||||
# Testing objects
|
||||
#
|
||||
|
||||
def debug_object(obj_path, caller):
|
||||
"""
|
||||
Auto-test an object's hooks and methods.
|
||||
"""
|
||||
try:
|
||||
string = "\n Test-creating a new object of path {w%s{n ... " % obj_path
|
||||
obj = create.create_object(obj_path)
|
||||
obj.location = caller.location
|
||||
string += "{gOk{n."
|
||||
except Exception:
|
||||
string += trace()
|
||||
try: obj.delete()
|
||||
except: pass
|
||||
return string
|
||||
string += "\nRunning syntax checks ..."
|
||||
try:
|
||||
string += "\nCalling at_first_login(self) ... "
|
||||
ret = obj.at_first_login()
|
||||
string += "{gOk{n."
|
||||
except Exception:
|
||||
string += trace()
|
||||
try:
|
||||
string += "\nCalling at_pre_login(self) ... "
|
||||
ret = obj.at_pre_login()
|
||||
string += "{gOk{n."
|
||||
except Exception:
|
||||
string += trace()
|
||||
try:
|
||||
string += "\nCalling at_post_login(self) ... "
|
||||
ret = obj.at_post_login()
|
||||
string += "{gOk{n."
|
||||
except Exception:
|
||||
string += trace()
|
||||
try:
|
||||
string += "\nCalling at_disconnect(self) ... "
|
||||
ret = obj.at_disconnect()
|
||||
string += "{gOk{n."
|
||||
except Exception:
|
||||
string += trace()
|
||||
try:
|
||||
string += "\nCalling at_before_move(self, dest) ... "
|
||||
ret = obj.at_before_move(caller.location)
|
||||
string += "{gOk{n: returns %s" % ret
|
||||
except Exception:
|
||||
string += trace()
|
||||
try:
|
||||
string += "\nCalling announce_move_from(self, dest) ... "
|
||||
ret = obj.announce_move_from(caller.location)
|
||||
string += "{gOk{n"
|
||||
except Exception:
|
||||
string += trace()
|
||||
try:
|
||||
string += "\nCalling announce_move_to(self, source_loc) ... "
|
||||
ret = obj.announce_move_from(caller.location)
|
||||
string += "{gOk{n."
|
||||
except Exception:
|
||||
string += trace()
|
||||
try:
|
||||
string += "\nCalling at_after_move(self, source_loc) ... "
|
||||
ret = obj.at_after_move(caller.location)
|
||||
string += "{gOk{n."
|
||||
except Exception:
|
||||
string += trace()
|
||||
try:
|
||||
string += "\nCalling at_object_receive(self, caller, source_loc) ... "
|
||||
ret = obj.at_object_receive(caller, caller.location)
|
||||
string += "{gOk{n."
|
||||
except Exception:
|
||||
string += trace()
|
||||
try:
|
||||
string += "\nCalling return_appearance(self, caller) ... "
|
||||
ret = obj.return_appearance(caller)
|
||||
string += "{gOk{n."
|
||||
except Exception:
|
||||
string += trace()
|
||||
try:
|
||||
string += "\nCalling at_msg_receive(self, msg, from_obj) ... "
|
||||
ret = obj.at_msg_receive("test_message_receive", caller)
|
||||
string += "{gOk{n."
|
||||
except Exception:
|
||||
string += trace()
|
||||
try:
|
||||
string += "\nCalling at_msg_send(self, msg, to_obj) ... "
|
||||
ret = obj.at_msg_send("test_message_send", caller)
|
||||
string += "{gOk{n."
|
||||
except Exception:
|
||||
string += trace()
|
||||
try:
|
||||
string += "\nCalling at_desc(self, looker) ... "
|
||||
ret = obj.at_desc(caller)
|
||||
string += "{gOk{n."
|
||||
except Exception:
|
||||
string += trace()
|
||||
try:
|
||||
string += "\nCalling at_object_delete(self) ... "
|
||||
ret = obj.at_object_delete()
|
||||
string += "{gOk{n."
|
||||
except Exception:
|
||||
string += trace()
|
||||
try:
|
||||
string += "\nCalling at_get(self, getter) ... "
|
||||
ret = obj.at_get(caller)
|
||||
string += "{gOk{n."
|
||||
except Exception:
|
||||
string += trace()
|
||||
try:
|
||||
string += "\nCalling at_drop(self, dropper) ... "
|
||||
ret = obj.at_drop(caller)
|
||||
string += "{gOk{n."
|
||||
except Exception:
|
||||
string += trace()
|
||||
try:
|
||||
string += "\nCalling at_say(self, speaker, message) ... "
|
||||
ret = obj.at_say(caller, "test_message_say")
|
||||
string += "{gOk{n."
|
||||
except Exception:
|
||||
string += trace()
|
||||
|
||||
try:
|
||||
obj.delete()
|
||||
except:
|
||||
string += trace()
|
||||
return string
|
||||
|
||||
def debug_object_scripts(obj_path, caller):
|
||||
"""
|
||||
Create an object and test all its associated scripts
|
||||
independently.
|
||||
"""
|
||||
|
||||
try:
|
||||
string = "\n Testing scripts on {w%s{n ... " % obj_path
|
||||
obj = create.create_object(obj_path)
|
||||
obj.location = caller.location
|
||||
obj = obj.dbobj
|
||||
string += "{gOk{n."
|
||||
except Exception:
|
||||
string += trace()
|
||||
try: obj.delete()
|
||||
except: pass
|
||||
return string
|
||||
scripts = obj.scripts.all()
|
||||
if scripts:
|
||||
string += "\n Running tests on %i object scripts ... " % (len(scripts))
|
||||
for script in scripts:
|
||||
string += "\n {wTesting %s{n ..." % script.key
|
||||
path = script.typeclass_path
|
||||
string += debug_script(path, obj=obj)
|
||||
#string += debug_run_script(path, obj=obj)
|
||||
else:
|
||||
string += "\n No scripts defined on object."
|
||||
|
||||
try:
|
||||
obj.delete()
|
||||
except:
|
||||
string += trace()
|
||||
return string
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue