Re: [CODE] Verify function

From: James Turner (turnerjh@XTN.NET)
Date: 06/26/98

George <greerga@CIRCLEMUD.ORG> writes:

> On Thu, 25 Jun 1998, James Turner wrote:
> >  static char retbuf[MAX_STRING_LENGTH];
> Ouch.  Wouldn't it be better to act like strcpy() than an 8k static buffer?

Yah, it was a quick piece of code.  Using a returned strdup now.
Same effect as acting like a strcpy.  I would make it act like strcat
by default, but I want to add some buffer overflow checking.  I don't
much like having a function that returnes heap malloc'd data though.
Another alternative is a static char * that keeps track of a malloc'd
string in the function itself and frees every call if it is previously
allocated.  Basically the same as a static buffer except it shrinks to
the size of the actual string.

(Note: I wrote the above about an hour ago.  I changed it to use a
static pointer now.  Makes the functions more self-contained and
easier to use IMO, since if you wanted to call them from elsewhere
there wouldn't be any need to worry about freeing the string and

> >  if (rnum == NOWHERE) return NULL;
>   Perhaps this should be in the do_verify function since we know beforehand.

Problem with this (and with how I did it) -- verify will eventually
work on mobs and objects as well.  The real_room should be moved to
inside the called fucntions so that they can decide if they're using
mobs or objs or rooms or whatnot.  It would be possible to add flags
to the list of functions for if it is for a mob or whatnot, but
really, even if looping over the entire mud, the function call
overhead is miniscule compared to the other calculations going on.

> >        sprintf(retbuf + strlen(retbuf), "Room %d: going %s then %s doesn't return to starting room\r\n",
> >                world[rnum].number, dirs[i], dirs[rev_dir[i]]);
> counter += sprintf(retbuf + counter, ....);
> Works better than strlen() if you're in a loop.

*nod* What would really be nice is a snprintfcat() function.  Maybe
I'll make one real quick-like.. not terribly hard.  The n would be for
the max allowed length of the buffer.  Tiny impact hit (strlen'ing the
buffer each call to the function) but it would really simplify some of
the redundant details.

> >      if (TOROOM(rnum, i) == NOWHERE) {
> >        sprintf(retbuf + strlen(retbuf), "Room %d: door to the %s leads nowhere\r\n",
> >                world[rnum].number, dirs[i]);
> >      }
> Might also want to check for '< 0 or > top_of_world', just in case.


> >  if (a < 0 || b < 0 || a == b) {
> >    send_to_char("Usage: verify <first room> <last room>\r\n", ch);
> >    return;
> >  }
> What if you only want to verify one room?
> >  for (vfn = 0; vfs[vfn]; vfn++) {
> >    for (i = a; i <= b; i++) {
>       if ((x = real_room(i)) != NOWHERE)        (Prevent unnecessary call.)

Can't do that since this will eventually loop over mobs.  Maybe
separate verifiers for each category... but that adds a lot of extra
checks and if's.  The function call overhead is miniscule, and
besides, this is more likely to be used on a builder port where a two
second lag isn't as bad as when it causes a player to die from a mob

I've done a good bit more work, added object and mob name verification
(ie makes sure there's no garbage in the text fields) as well as
checking for color bleed.

I'll post the updated version sometime soon when it calms down a bit.
It seems to be working quite well; the only problem is it doesn't do
any zone checking (coming soon!) and that I want it to verify even
more information.  Ideas are very welcomed!

James Turner                   UIN: 1102038

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | |

This archive was generated by hypermail 2b30 : 12/15/00 PST