Christian's Edit

From Gwen Morse's Wiki
Jump to: navigation, search
; +-----------------------------------------------------------------+
; |                     - -  TinyFuge Edit  - -                     |
; |     Written and Copyright Jun 3, 1997 Christian J. Robinson     |
; |                     (infynity at onewest dot net)                      |
; |     Distributed under the terms of the GNU Public License.      |
; |                No warranty, express or implied!                 |
; +-----------------------------------------------------------------+

; This code was designed to completely get away from having any server side
; code for the /ed command, because that makes it all inherently insecure.
; However, this code does send the client some code to grab the info you are
; editing, but this is considered acceptable and reasonably safe. Especially
; since it chooses a random number to include as part of the trigger.

; If the number it gets back is -not- what it chose when you invoked /ed, it
; complains of a possible spoof, and ignores the trigger string. On top of
; that, it will complain and ignore -any- edit trigger if you haven't invoked
; /ed since the last time it got a matching trigger.

; This /ed code calls a handler (a command /def) called ed_<world_type>, for
; your current world, or a world specified with -w<world>, sending it any
; arguments it received. That is, if the world type is 'tiny.mux' when you
; invoked /ed, it would run /ed_tiny.mux, plus whatever you typed after /ed as
; arguments. If there is no handler for the world type, it will complain and
; stop.

; A handler should /return the necessary text to somehow get the world to send
; you the string: TinyFugueEdit (randnum) > (whatever is needed to set the new
; attribute) Without the ()'s, of course. (See the handlers I have defined
; below.)

; So far I only have a handler for all MUSH/MUX types (ed_tiny.mux just calls
; ed_tiny.mush), plus a somewhat workable MUCK handler that requires
; server-side code (ick).
; 

; If all else fails, read the code. :)
; -----------------------------------------------------------------------------
; RCS:
; $Id: tf-edit.tf,v 1.6 2001/10/08 14:31:22 infynity Exp $
; $Log: tf-edit.tf,v $
; Revision 1.6  2001/10/08 14:31:22  infynity
; Changed @pemit to @pemit/silent for MUX/MUSH.
;
; Revision 1.5  2000/11/13 03:46:55  infynity
; Email address change, again.
;
; Revision 1.4  2000/11/03 06:03:56  infynity
; Email address change.
;
; Revision 1.3  2000/04/22 10:21:20  infynity
; Code cleanup.  /ed now more "cleanly" calls the handlers,
; which no longer need to /echo -e, and are expected to /return...
;
; Commentary cleanup.
;
; Revision 1.2  1999/07/12 10:38:50  infynity
; Added a handler for MUCK, but it requires a server-side program. Ah well.
;
; Revision 1.1  1999/07/12 08:18:20  infynity
; Initial revision
;
; -----------------------------------------------------------------------------

/loaded __OWNLIB__/tf-edit.tf

; Set up:
/set tf_edit_randnum=0

; The trigger:
/def -i -ag -p100 -mglob -t"TinyFugueEdit * > *" -q tf_edit_trig = \
 /if ({2} = {tf_edit_randnum} & {tf_edit_randnum} != 0) %;\
  /grab %-3 %;\
  /set tf_edit_randnum=0 %;\
 /else \
  /echo %% Possible TinyFugueEdit spoof-> %* %;\
 /endif

; The tf command:
/def -i ed = \
 /test getopts("w:") %;\
 /if ({opt_w} !~ "" & $(/listsockets -s %{opt_w}) =~ "") \
  /echo -e %% No connected worlds match '%{opt_w}'. %;\
  /return %;\
 /endif %; \
 /let wtype=$[world_info((({opt_w} !~ "") ? {opt_w} : ${world_name}), 'type')] %;\
 /if ($(/listdef -s -i ed_%{wtype}) !/ "") \
  /set tf_edit_randnum=$[rand(99,9999999)] %;\
  /ed_%{wtype} $[escape('%[]{}\'', {*})] %;\
  /let _text=%? %;\
  /if ({_text} !~ "") \
    /test send(_text, {opt_w}) %;\
  /endif %;\
 /else \
  /echo -e %% An /ed macro handler does not exist for world type: '%{wtype}' %;\
 /endif

; Uncomment this to make it so sending 'ed *' actually calls '/ed *'.
;/def -i -mglob -h'SEND ed *' tf_edit_send_hook = /ed %-1

; A handler for tiny.mush:
/def -i ed_tiny.mush = \
 /if (regmatch('(.+)/([^ ]+)$', {*})) \
  /echo %% TF Edit -    Object: %P1 %;\
  /echo %%         - Attribute: %P2 %;\
  /let _text=@pemit/silent me=TinyFugueEdit %tf_edit_randnum > &%P2 %P1=[get(%P1/%P2)] %;\
  /return _text %;\
 /else \
  /echo -e %% /ED Usage for world type '%{wtype}': /ed <object>/<attribute> %;\
  /return '' %;\
 /endif

; tiny.mux is close enough to tiny.mush:
/def -i ed_tiny.mux = /ed_tiny.mush %*

; A handler for tiny.muck:  (This requires a program on the MUCK.)
/def -i ed_tiny.muck = \
 /if (regmatch('(.+)=([^ ]+)$', {*})) \
  /echo %% TF Edit -   Object: %P1 %;\
  /echo %%         - Property: %P2 %;\
  /let _text=edit %tf_edit_randnum %P1=%P2 %;\
  /return _text %;\
 /else \
  /echo -e %% /ED Usage for world type '%{wtype}': /ed <object>=<property> %;\
  /return '' %;\
 /endif

; vim: set et: