From 006e8aeee83bf686ba2aa43395c72ea4730e7ecb Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 18 Jul 2020 19:37:49 +0200 Subject: [PATCH] Make CmdGet/Drop/Give give error if obj.move_to returns False. Resolves #2168. --- CHANGELOG.md | 17 +++++++------ evennia/commands/default/general.py | 39 ++++++++++++++++++----------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c41f391940..688cec7892 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,10 +37,10 @@ without arguments starts a full interactive Python console. - EvMore auto-justify now defaults to False since this works better with all types of texts (such as tables). New `justify` bool. Old `justify_kwargs` remains but is now only used to pass extra kwargs into the justify function. -- EvMore `text` argument can now also be a list or a queryset. Querysets will be - sliced to only return the required data per page. EvMore takes a new kwarg - `page_formatter` which will be called for each page. This allows to customize - the display of queryset data, build a new EvTable per page etc. +- EvMore `text` argument can now also be a list or a queryset. Querysets will be + sliced to only return the required data per page. EvMore takes a new kwarg + `page_formatter` which will be called for each page. This allows to customize + the display of queryset data, build a new EvTable per page etc. - Improve performance of `find` and `objects` commands on large data sets (strikaco) - New `CHANNEL_HANDLER_CLASS` setting allows for replacing the ChannelHandler entirely. - Made `py` interactive mode support regular quit() and more verbose. @@ -50,20 +50,21 @@ without arguments starts a full interactive Python console. `.get_command_info()` method for easier overloading and access. (Volund) - Removed unused `CYCLE_LOGFILES` setting. Added `SERVER_LOG_DAY_ROTATION` and `SERVER_LOG_MAX_SIZE` (and equivalent for PORTAL) to control log rotation. -- Addded `inside_rec` lockfunc - if room is locked, the normal `inside()` lockfunc will +- Addded `inside_rec` lockfunc - if room is locked, the normal `inside()` lockfunc will fail e.g. for your inventory objs (since their loc is you), whereas this will pass. - RPSystem contrib's CmdRecog will now list all recogs if no arg is given. Also multiple bugfixes. -- Remove `dummy@example.com` as a default account email when unset, a string is no longer +- Remove `dummy@example.com` as a default account email when unset, a string is no longer required by Django. - Fixes to `spawn`, make updating an existing prototype/object work better. Add `/raw` switch to `spawn` command to extract the raw prototype dict for manual editing. -- `list_to_string` is now `iter_to_string` (but old name still works as legacy alias). It will - now accept any input, including generators and single values. +- `list_to_string` is now `iter_to_string` (but old name still works as legacy alias). It will + now accept any input, including generators and single values. - EvTable should now correctly handle columns with wider asian-characters in them. - Update Twisted requirement to >=2.3.0 to close security vulnerability - Add `$random` inlinefunc, supports minval,maxval arguments that can be ints and floats. - Add `evennia.utils.inlinefuncs.raw()` as a helper to escape inlinefuncs in a string. +- Make CmdGet/Drop/Give give proper error if `obj.move_to` returns `False`. ## Evennia 0.9 (2018-2019) diff --git a/evennia/commands/default/general.py b/evennia/commands/default/general.py index 56dbf94231..cfe7b8e098 100644 --- a/evennia/commands/default/general.py +++ b/evennia/commands/default/general.py @@ -426,11 +426,14 @@ class CmdGet(COMMAND_DEFAULT_CLASS): if not obj.at_before_get(caller): return - obj.move_to(caller, quiet=True) - caller.msg("You pick up %s." % obj.name) - caller.location.msg_contents("%s picks up %s." % (caller.name, obj.name), exclude=caller) - # calling at_get hook method - obj.at_get(caller) + success = obj.move_to(caller, quiet=True) + if not success: + caller.msg("This can't be picked up.") + else: + caller.msg("You pick up %s." % obj.name) + caller.location.msg_contents("%s picks up %s." % (caller.name, obj.name), exclude=caller) + # calling at_get hook method + obj.at_get(caller) class CmdDrop(COMMAND_DEFAULT_CLASS): @@ -471,11 +474,14 @@ class CmdDrop(COMMAND_DEFAULT_CLASS): if not obj.at_before_drop(caller): return - obj.move_to(caller.location, quiet=True) - caller.msg("You drop %s." % (obj.name,)) - caller.location.msg_contents("%s drops %s." % (caller.name, obj.name), exclude=caller) - # Call the object script's at_drop() method. - obj.at_drop(caller) + success = obj.move_to(caller.location, quiet=True) + if not success: + caller.msg("This couldn't be dropped.") + else: + caller.msg("You drop %s." % (obj.name,)) + caller.location.msg_contents("%s drops %s." % (caller.name, obj.name), exclude=caller) + # Call the object script's at_drop() method. + obj.at_drop(caller) class CmdGive(COMMAND_DEFAULT_CLASS): @@ -522,11 +528,14 @@ class CmdGive(COMMAND_DEFAULT_CLASS): return # give object - caller.msg("You give %s to %s." % (to_give.key, target.key)) - to_give.move_to(target, quiet=True) - target.msg("%s gives you %s." % (caller.key, to_give.key)) - # Call the object script's at_give() method. - to_give.at_give(caller, target) + success = to_give.move_to(target, quiet=True) + if not success: + caller.msg("This could not be given.") + else: + caller.msg("You give %s to %s." % (to_give.key, target.key)) + target.msg("%s gives you %s." % (caller.key, to_give.key)) + # Call the object script's at_give() method. + to_give.at_give(caller, target) class CmdSetDesc(COMMAND_DEFAULT_CLASS):