Synopsis: Command flags to lower target checking code duplication. May 98 From erwin@andreasen.com Sat May 30 10:26:18 1998 Date: Sat, 30 May 1998 10:26:14 +0200 (MET DST) From: "Erwin S. Andreasen" X-Sender: erwin@shire.shire.dk To: rom@rom.org Subject: Re: ROM 2.4b6 now available In-Reply-To: <199805300233.TAA27392@mailhost.cmc.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Status: O X-Status: On Fri, 29 May 1998, Russ Taylor wrote: > All do_foo() functions that are called from within the source are now > called through a wrapper function, do_function(). This ensures that a > static string cannot be modified unintentionally (a potential crash bug). > The do_function() command dups the string and passes it on to the > specified function, then frees the string after execution of the command > is complete. Any file using do_function() must include interp.h Personally I solved that problem by making the second argument to any do_function a 'const char *' rather than 'char *'. It gave a great deal of warnings in the beginning :) BTW, something which may also be useful to people: I also pass a 3rd argument to do functions, Character (previously known as CHAR_DATA) * target. This target is determined by interpret() in certain functions: there is a number of flags that determine how the target is searched for: #define WORLD CMD_WORLD Target can be anywhere in the world #define ROOM CMD_ROOM Target can be in the room #define TRUST CMD_TRUST Target must have lower trust than the executor #define NPC CMD_NPC Taret must be an NPC #define FULL CMD_FULL Target's name must be typed in fully rather than abbreviated #define PLR CMD_PLAYER Target must be a player #define SWI CMD_NOSWITCH NPCs (including switched people) cannot use this command and get a proper error message #define OFFLINE CMD_OFFLINE The command, if it does not find a player online, tries to load a player then proceed, and when finished, unloads them (saving their new updated status) and resets the last-modified time on the pfile. All those options move the common code into interpret() and make the do_functions much smaller. One thing I STILL need to add is flags for offensive commands: e.g. take a look at kick and kill and circle etc. Most of them have things in common like: defaulting to a target if none is specified, checking for is_safe, calling check_killer etc. ============================================================================== Herlev, Denmark UNIX System Programmer <*> (not speaking for) DDE ==============================================================================