Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
Bug in will_fall( )
Oct 23, 2017, 1:35 am
By GatewaySysop
Bug in do_zap( ), do_brandish( )
Oct 18, 2017, 1:52 pm
By GatewaySysop
Bug in get_exp_worth( )
Oct 10, 2017, 1:26 am
By GatewaySysop
Bug in do_drag( )
Oct 8, 2017, 12:40 am
By GatewaySysop
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Memwatch
Author: Johan Lindh
Submitted by: Vladaar
Beastmaster 6D sound files
Author: Vladaar
Submitted by: Vladaar
Users Online
CommonCrawl, Yandex, Google

Members: 0
Guests: 5
Stats
Files
Topics
Posts
Members
Newest Member
476
3,704
19,231
608
LAntorcha
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » Codebases » SmaugFUSS » mud prograns -rand
Forum Rules | Mark all | Recent Posts

mud prograns -rand
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 Oct 21, 2012, 6:01 pm   Last edited Oct 21, 2012, 6:03 pm by dbna2
Go to the top of the page
Go to the bottom of the page

dbna2
Sorcerer
GroupMembers
Posts600
JoinedDec 2, 2008

So I am having problems with rand mud programs.

#0 0x0097c760 in strcpy () from /lib/libc.so.6
#1 0x08167625 in mprog_driver (com_list=0x0, mob=0x8a77f90, actor=0x0,
obj=0x0, vo=0x0, single_step=0 '\000') at mud_prog.c:2392
#2 0x08169680 in mprog_percent_check (mob=0x8a77f90, actor=0x0, obj=0x0,
vo=0x0, type=2) at mud_prog.c:3035
#3 0x081696d3 in mprog_random_trigger (mob=0x0) at mud_prog.c:3333
#4 0x081b8642 in mobile_update () at update.c:814
#5 0x081ba10f in update_handler () at update.c:2480
#6 0x080e2400 in game_loop () at comm.c:764
#7 0x080e2d7c in main (argc=2138570752, argv=0xbfffea64) at comm.c:367


line 2392
strcpy( tmpcmndlst, com_list );

not sure what to do now

/*  The main focus of the MOBprograms.  This routine is called 
 *  whenever a trigger is successful.  It is responsible for parsing
 *  the command list and figuring out what to do. However, like all
 *  complex procedures, everything is farmed out to the other guys.
 *
 *  This function rewritten by Narn for Realms of Despair, Dec/95.
 *
 */
void mprog_driver ( char *com_list, CHAR_DATA *mob, CHAR_DATA *actor,
		   OBJ_DATA *obj, void *vo, bool single_step)
{
  char tmpcmndlst[ MAX_STRING_LENGTH ];
  char *command_list; 
  CHAR_DATA *rndm = NULL;
  char *cmnd = NULL;
  CHAR_DATA *vch   = NULL;
  int count        = 0;
  int count2       = 0;
  int ignorelevel  = 0;
  int iflevel, result;
  bool ifstate[MAX_IFS][ DO_ELSE + 1 ];
  static int prog_nest;
  MPSLEEP_DATA *mpsleep = NULL; 
  char arg[MAX_INPUT_LENGTH]; 
  static int serial;
  int curr_serial;
  ROOM_INDEX_DATA *supermob_room;
  OBJ_DATA *true_supermob_obj;
  bool rprog_oprog = ( mob == supermob );

   if( rprog_oprog )
   {
      serial++;
      supermob_room = mob->in_room;
      true_supermob_obj = supermob_obj;
   }
   else
      true_supermob_obj = NULL, supermob_room = NULL;
   curr_serial = serial;

  
  if IS_AFFECTED( mob, AFF_CHARM )
    return;
    
  /* Next couple of checks stop program looping. -- Altrag */
  if ( mob == actor )
  {
    progbug( "triggering oneself.", mob );
    return;
  }
  
  if ( ++prog_nest > MAX_PROG_NEST )
  {
    progbug( "max_prog_nest exceeded.", mob );
    --prog_nest;
    return;
  }

  /* Make sure all ifstate bools are set to FALSE */
  for ( iflevel = 0; iflevel < MAX_IFS; iflevel++ )
  {
    for ( count = 0; count < DO_ELSE; count++ )
    {
      ifstate[iflevel][count] = FALSE;
    }
  }

   iflevel = 0;
   mprog_online = 0;

  /*
   * get a random visible player who is in the room with the mob.
   *
   *  If there isn't a random player in the room, rndm stays NULL.
   *  If you do a $r, $R, $j, or $k with rndm = NULL, you'll crash
   *  in mprog_translate.
   *
   *  Adding appropriate error checking in mprog_translate.
   *    -Haus
   *
   * This used to ignore players MAX_LEVEL - 3 and higher (standard
   * Merc has 4 immlevels).  Thought about changing it to ignore all
   * imms, but decided to just take it out.  If the mob can see you, 
   * you may be chosen as the random player. -Narn
   *
   */

  count = 0;
  for ( vch = mob->in_room->first_person; vch; vch = vch->next_in_room )
    if ( !IS_NPC( vch )
       &&  can_see( mob, vch ) )
      {
        if ( number_range( 0, count ) == 0 )
	  rndm = vch;
        count++;
      }
  
  strcpy( tmpcmndlst, com_list );
  command_list = tmpcmndlst;
 
 /* mpsleep - Restore the environment -rkb */
 if (current_mpsleep)
 {
 ignorelevel = current_mpsleep->ignorelevel;
 iflevel = current_mpsleep->iflevel;

 if (single_step)
 mob->mpscriptpos = 0;

      for( count = 0; count < MAX_IFS; ++count )
      {
         for( count2 = 0; count2 <= DO_ELSE; ++count2 )
            ifstate[count][count2] = current_mpsleep->ifstate[count][count2];
      }

 current_mpsleep = NULL;
 }
 
 if ( single_step )
  {
    if ( mob->mpscriptpos > strlen( tmpcmndlst ) )
       mob->mpscriptpos = 0;
    else
       command_list += mob->mpscriptpos;
    if ( *command_list == '\0' )
    {
	command_list = tmpcmndlst;
	mob->mpscriptpos = 0;
    }
  }

  /* From here on down, the function is all mine.  The original code
     did not support nested ifs, so it had to be redone.  The max 
     logiclevel (MAX_IFS) is defined at the beginning of this file, 
     use it to increase/decrease max allowed nesting.  -Narn 
  */

  while ( TRUE )
  {
    /* With these two lines, cmnd becomes the current line from the prog,
       and command_list becomes everything after that line. */


//      command_list = mprog_one_command( command_list, cmnd );
    cmnd = command_list;
    command_list = mprog_next_command( command_list );


      mprog_online++;

      /* Are we at the end? */
      if( cmnd[0] == '\0' )
      {
         if( ifstate[iflevel][IN_IF] || ifstate[iflevel][IN_ELSE] )
         {
            progbug( "Missing endif", mob );
         }
         --prog_nest;
         return;
      }


      /*
       * mpsleep - Check if we should sleep -rkb 
       */
      one_argument( cmnd, arg );
      if( !str_cmp( arg, "mpsleep" ) )
      {
         if( ( ifstate[iflevel][IN_IF] == TRUE && ifstate[iflevel][DO_IF] == FALSE ) ||  // if we are in an if/else and we
           ( ifstate[iflevel][IN_ELSE] == TRUE && ifstate[iflevel][DO_ELSE] == FALSE ) ) // dont want to execute, dont..
         {
         }
         else
         {
            CREATE( mpsleep, MPSLEEP_DATA, 1 );

            /*
             * State variables 
             */
            mpsleep->ignorelevel = ignorelevel;
            mpsleep->iflevel = iflevel;

            for( count = 0; count < MAX_IFS; ++count )
            {
               for( count2 = 0; count2 <= DO_ELSE; ++count2 )
                  mpsleep->ifstate[count][count2] = ifstate[count][count2];
            }

            /*
             * Driver arguments 
             */
            mpsleep->com_list = STRALLOC( command_list );
            mpsleep->mob = mob;
            mpsleep->actor = actor;
            mpsleep->obj = obj;
            mpsleep->vo = vo;
            mpsleep->single_step = single_step;

            /*
             * Time to sleep 
             */
            cmnd = one_argument( cmnd, arg );
            if( cmnd[0] == '\0' )
               mpsleep->timer = 4;
            else
               mpsleep->timer = atoi( cmnd );

            if( mpsleep->timer < 1 )
            {
               progbug( "mpsleep - bad arg, using default", mob );
               mpsleep->timer = 4;
            }

            /*
             * Save type of prog, room, object or mob 
             */
            if( mpsleep->mob->pIndexData->vnum == MOB_VNUM_SUPERMOB )
            {
               if( !str_prefix( "Room", mpsleep->mob->description ) )
               {
                  mpsleep->type = MP_ROOM;
                  mpsleep->room = mpsleep->mob->in_room;
               }
               else if( !str_prefix( "Object", mpsleep->mob->description ) )
                  mpsleep->type = MP_OBJ;
            }
            else
               mpsleep->type = MP_MOB;

            LINK( mpsleep, first_mpsleep, last_mpsleep, next, prev );
            --prog_nest;
            return;
         }
      }
    /* Evaluate/execute the command, check what happened. */
    result = mprog_do_command( cmnd, mob, actor, obj, vo, rndm, 
            ( ifstate[iflevel][IN_IF] && !ifstate[iflevel][DO_IF] )
            || ( ifstate[iflevel][IN_ELSE] && !ifstate[iflevel][DO_ELSE] ),
            ( ignorelevel > 0 ) );
if( rprog_oprog )
         uphold_supermob( &curr_serial, serial, &supermob_room, true_supermob_obj );

    /* Script prog support  -Thoric */
    if ( single_step )
    {
      mob->mpscriptpos = command_list - tmpcmndlst;
      --prog_nest;
      return;
    }

    /* This is the complicated part.  Act on the returned value from
       mprog_do_command according to the current logic state. */
    switch ( result )
    {
    case COMMANDOK:
#ifdef DEBUG
log_string( "COMMANDOK" );
#endif
      /* Ok, this one's a no-brainer. */
      continue;
      break;

    case IFTRUE:
#ifdef DEBUG
log_string( "IFTRUE" );
#endif
      /* An if was evaluated and found true.  Note that we are in an
         if section and that we want to execute it. */
      iflevel++;
      if ( iflevel == MAX_IFS )
      {
        progbug( "Maximum nested ifs exceeded", mob );
        --prog_nest;
        return;
      }

      ifstate[iflevel][IN_IF] = TRUE; 
      ifstate[iflevel][DO_IF] = TRUE;
      break;

    case IFFALSE:
#ifdef DEBUG
log_string( "IFFALSE" );
#endif
      /* An if was evaluated and found false.  Note that we are in an
         if section and that we don't want to execute it unless we find
         an or that evaluates to true. */
      iflevel++;
      if ( iflevel == MAX_IFS )
      {
        progbug( "Maximum nested ifs exceeded", mob );
        --prog_nest;
        return;
      }
      ifstate[iflevel][IN_IF] = TRUE; 
      ifstate[iflevel][DO_IF] = FALSE;
      break;

    case ORTRUE:
#ifdef DEBUG
log_string( "ORTRUE" );
#endif
      /* An or was evaluated and found true.  We should already be in an
         if section, so note that we want to execute it. */
      if ( !ifstate[iflevel][IN_IF] )
      {
        progbug( "Unmatched or", mob );
        --prog_nest;
        return;
      }
      ifstate[iflevel][DO_IF] = TRUE;
      break;

    case ORFALSE:
#ifdef DEBUG
log_string( "ORFALSE" );
#endif
      /* An or was evaluated and found false.  We should already be in an
         if section, and we don't need to do much.  If the if was true or
         there were/will be other ors that evaluate(d) to true, they'll set
         do_if to true. */
      if ( !ifstate[iflevel][IN_IF] )
      {
        progbug( "Unmatched or", mob );
        --prog_nest;
        return;
      }
      continue;
      break;

    case FOUNDELSE:
#ifdef DEBUG
log_string( "FOUNDELSE" );
#endif
      /* Found an else.  Make sure we're in an if section, bug out if not.
         If this else is not one that we wish to ignore, note that we're now 
         in an else section, and look at whether or not we executed the if 
         section to decide whether to execute the else section.  Ca marche 
         bien. */
      if ( ignorelevel > 0 )
        continue;

      if ( ifstate[iflevel][IN_ELSE] )
      {
        progbug( "Found else in an else section", mob );
        --prog_nest;
        return;
      }
      if ( !ifstate[iflevel][IN_IF] )
      {
        progbug( "Unmatched else", mob );
        --prog_nest;
        return;
      }

      ifstate[iflevel][IN_ELSE] = TRUE;
      ifstate[iflevel][DO_ELSE] = !ifstate[iflevel][DO_IF];
      ifstate[iflevel][IN_IF]   = FALSE;
      ifstate[iflevel][DO_IF]   = FALSE;
   
      break;

    case FOUNDENDIF:
#ifdef DEBUG
log_string( "FOUNDENDIF" );
#endif
      /* Hmm, let's see... FOUNDENDIF must mean that we found an endif.
         So let's make sure we were expecting one, return if not.  If this
         endif matches the if or else that we're executing, note that we are 
         now no longer executing an if.  If not, keep track of what we're 
         ignoring. */
      if ( !( ifstate[iflevel][IN_IF] || ifstate[iflevel][IN_ELSE] ) )
      {
        progbug( "Unmatched endif", mob );
        --prog_nest;
        return;
      }

      if ( ignorelevel > 0 )      
      {
        ignorelevel--;
        continue;
      }

      ifstate[iflevel][IN_IF]   = FALSE;
      ifstate[iflevel][DO_IF]   = FALSE;
      ifstate[iflevel][IN_ELSE] = FALSE;
      ifstate[iflevel][DO_ELSE] = FALSE;

      iflevel--;
      break;

    case IFIGNORED:
#ifdef DEBUG
log_string( "IFIGNORED" );
#endif
      if ( !( ifstate[iflevel][IN_IF] || ifstate[iflevel][IN_ELSE] ) )
      {
        progbug( "Parse error, ignoring if while not in if or else", mob );
        --prog_nest;
        return;
      }
      ignorelevel++;
      break;

    case ORIGNORED:
#ifdef DEBUG
log_string( "ORIGNORED" );
#endif
      if ( !( ifstate[iflevel][IN_IF] || ifstate[iflevel][IN_ELSE] ) )
      {
        progbug( "Unmatched or", mob );
        --prog_nest;
        return;
      }
      if ( ignorelevel == 0 )
      {
        progbug( "Parse error, mistakenly ignoring or", mob );
        --prog_nest;
        return;
      }

      break;

    case BERR:
#ifdef DEBUG
log_string( "BERR" );
#endif
      --prog_nest;
      return;
      break;
    }
  }
  --prog_nest;
  return;
}

       
Post is unread #2 Oct 21, 2012, 8:35 pm
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,857
JoinedJul 26, 2005

Looks like it isn't liking trying to strcpy NULL and com_list is NULL when it gets there. Try something like this
if( com_list )
   strcpy( tmpcmndlst, com_list );
else
   snprintf( tmpcmnlst, sizeof( tmpcmndlst ), "%s", "" );

Sorry if it gives an error haven't tested it out.
       
Post is unread #3 Oct 22, 2012, 1:26 am
Go to the top of the page
Go to the bottom of the page

Aurin
Magician
GroupMembers
Posts189
JoinedSep 5, 2010

Also, since you're looking into it, take a look at this http://www.smaugmuds.org/index.php?a=topic&t=4574. I came across a problem with the random thing a while ago, as well as fixing that NULL crash at the same time--that was supposedly handled elsewhere in the code.

:)
       
Pages:<< prev 1 next >>