Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
auth_update crash
Dec 23, 2017, 10:15 pm
By Remcon
check_tumble
Dec 18, 2017, 7:21 pm
By Remcon
parse description bug
Dec 15, 2017, 10:08 pm
By Remcon
Couple bugs
Dec 12, 2017, 5:42 pm
By Remcon
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
LoP 1.46
Author: Remcon
Submitted by: Remcon
LOP 1.45
Author: Remcon
Submitted by: Remcon
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Users Online
CommonCrawl, Yahoo!

Members: 0
Guests: 12
Stats
Files
Topics
Posts
Members
Newest Member
478
3,708
19,242
612
Jacki72H
Today's Birthdays
Evoru (32)
Related Links
» SmaugMuds.org » General » General Discussions » Generic question/problem with...
Forum Rules | Mark all | Recent Posts

Generic question/problem with mob/obj/room progs
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 Mar 17, 2006, 7:18 pm   Last edited Mar 17, 2006, 7:19 pm by Keberus
Go to the top of the page
Go to the bottom of the page

Keberus
Conjurer
GroupFUSS Project Team
Posts341
JoinedJun 4, 2005

Okay, the other day on the fote website someone posted a message about not being able to use certain keywords together in a program and it working properly. I decided to check into and found that he was indeed correct. For example: if you did "rpedit add speech dos kudos" it will make a program that has both the keywords dos and kudos. The problem is that in all 3 there is a function called strstr that finds the first reference to the argument sent and changes the pointers posion in the string and will never validate the second one if it is the larger of the two. For example if i would switch it and do "rpedit add speech kudos dos" both would work just fine. I was able to change up the rprog one and got good results so i wanted to post the code and ask if there would be any complications and/or if this problem existed in smaug (and maybe earlier)..anyways to the code.

Old code:
void rprog_wordlist_check( char *arg, CHAR_DATA *mob, CHAR_DATA *actor,
			  OBJ_DATA *obj, void *vo, int type, ROOM_INDEX_DATA *room )
{

  char        temp1[ MAX_STRING_LENGTH ];
  char        temp2[ MAX_INPUT_LENGTH ];
  char        word[ MAX_INPUT_LENGTH ];
  MPROG_DATA *mprg;
  char       *list;
  char       *start;
  char       *dupl;
  char       *end;
  int         i;

  if ( actor && !char_died(actor) && actor->in_room )
    room = actor->in_room;

  for ( mprg = room->mudprogs; mprg; mprg = mprg->next )
    if ( mprg->type & type )
      {
	strcpy( temp1, mprg->arglist );
	list = temp1;
	for ( i = 0; i < strlen( list ); i++ )
	  list[i] = LOWER( list[i] );
	strcpy( temp2, arg );
	dupl = temp2;
	for ( i = 0; i < strlen( dupl ); i++ )
	  dupl[i] = LOWER( dupl[i] );
	if ( ( list[0] == 'p' ) && ( list[1] == ' ' ) )
	  {
	    list += 2;
	    while ( ( start = strstr( dupl, list ) ) )
	      if ( (start == dupl || *(start-1) == ' ' )
		  && ( *(end = start + strlen( list ) ) == ' '
		      || *end == '\n'
		      || *end == '\r'
		      || *end == '\0' ) )
		{
		  rset_supermob( room );
		  mprog_driver( mprg->comlist, mob, actor, obj, vo, FALSE );
		  release_supermob() ;
		  break;
		}
	      else
		dupl = start+1;
	  }
	else
	  {
	    list = one_argument( list, word );
	    for( ; word[0] != '\0'; list = one_argument( list, word ) )
	      while ( ( start = strstr( dupl, word ) ) )
		if ( ( start == dupl || *(start-1) == ' ' )
		    && ( *(end = start + strlen( word ) ) == ' '
			|| *end == '\n'
			|| *end == '\r'
			|| *end == '\0' ) )
		  {
		    rset_supermob( room );
		    mprog_driver( mprg->comlist, mob, actor, obj, vo, FALSE );
		    release_supermob();
		    break;
		  }
		else
		  dupl = start+1;
	  }
      }
      return;
}


new code...*NOTE only modified the part that doesnt deal with the exact phrase*
*ALSO NOTE* This is a fote codebase so if the problem isnt in any other code I would kind of like to know.

void rprog_wordlist_check( char *arg, CHAR_DATA *mob, CHAR_DATA *actor,
			  OBJ_DATA *obj, void *vo, int type, ROOM_INDEX_DATA *room )
{

  char        temp1[ MAX_STRING_LENGTH ];
  char        temp2[ MAX_INPUT_LENGTH ];
  char        word[ MAX_INPUT_LENGTH ];
  MPROG_DATA *mprg;
  char       *list;
  char       *start;
  char       *dupl;
  char       *end;
  int         i;

  if ( actor && !char_died(actor) && actor->in_room )
    room = actor->in_room;

  for ( mprg = room->mudprogs; mprg; mprg = mprg->next )
    if ( mprg->type & type )
      {
	strcpy( temp1, mprg->arglist );
	list = temp1;
	for ( i = 0; i < strlen( list ); i++ )
	  list[i] = LOWER( list[i] );
	strcpy( temp2, arg );
	dupl = temp2;
	for ( i = 0; i < strlen( dupl ); i++ )
	  dupl[i] = LOWER( dupl[i] );
	if ( ( list[0] == 'p' ) && ( list[1] == ' ' ) )
	  {
	    list += 2;
	    while ( ( start = strstr( dupl, list ) ) )
	      if ( (start == dupl || *(start-1) == ' ' )
		  && ( *(end = start + strlen( list ) ) == ' '
		      || *end == '\n'
		      || *end == '\r'
		      || *end == '\0' ) )
		{
		  rset_supermob( room );
		  mprog_driver( mprg->comlist, mob, actor, obj, vo, FALSE );
		  release_supermob() ;
		  break;
		}
	      else
		dupl = start+1;
	  }
	else
	  {
	    list = one_argument( list, word );
	    for( ; word[0] != '\0'; list = one_argument( list, word ) )
                    {
                           if( !str_cmp(dupl, word) )
                           {
		    rset_supermob( room );
		    mprog_driver( mprg->comlist, mob, actor, obj, vo, FALSE );
		    release_supermob();
		    break;
                           }
	  }
      }
      return;
}


The nice thing is that it is considerably simplified. So I guess the reason I want your guys' opinons is because I have no idea why they wouldn't have done it that way in the first place.

Thanks,
KeB
       
Post is unread #2 Mar 17, 2006, 8:20 pm   Last edited Nov 25, 2007, 7:14 pm by Samson
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,639
JoinedJan 1, 2002

Just to add to this, it was also picked up by someone else using AFKMud who discovered a similar problem and posted his solution here: http://www.smaugmuds.org/index.php?a=topic&t=1102

I haven't had time to mess with it yet but figured I'd link it here.
       
Post is unread #3 Mar 17, 2006, 8:44 pm
Go to the top of the page
Go to the bottom of the page

Keberus
Conjurer
GroupFUSS Project Team
Posts341
JoinedJun 4, 2005

After checking over mine again i realized that mateo's version is much better because I forgot to try the whole or a partial statement instead of just individual words. Btw: his code does seem to fix the problem

KeB
       
Pages:<< prev 1 next >>