Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
 Couple bugs
Yesterday, 5:42 pm
By Remcon
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
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
Memwatch
Author: Johan Lindh
Submitted by: Vladaar
Users Online
CommonCrawl, Yahoo!, DotBot

Members: 0
Guests: 14
Stats
Files
Topics
Posts
Members
Newest Member
477
3,705
19,232
608
LAntorcha
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » Bugfix Lists » SWFOTE FUSS Bugfix List » [Bug] Numerous problems with ...
Forum Rules | Mark all | Recent Posts

[Bug] Numerous problems with droptroops command
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 Oct 29, 2006, 1:50 pm
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,639
JoinedJan 1, 2002

Bug: Numerous problems with droptroops command
Danger: Medium - Some crashers and other security problems
Found by: Phoneix Dracul
Fixed by: Keberus

---

misc.c, do_droptroops

Replace the function with:
#define MAX_DROP_TROOPS 20

//do_droptroops fixed by KeB 10/24/06
void do_droptroops( CHAR_DATA *ch, char *argument )
{
   int num, vnum, i;
   SHIP_DATA *ship;
   CHAR_DATA *mob;
   MOB_INDEX_DATA  * pMobIndex;
   OBJ_DATA        * blaster;
   OBJ_INDEX_DATA  * pObjIndex;
   ROOM_INDEX_DATA *room, *rtest;
   char tmpbuf[MAX_STRING_LENGTH];

   if( ch->pcdata->clan == NULL )
   {
      send_to_char( "You must be in a clan to drop troops.\r\n", ch );
      return;
   }

   if( ch->pcdata->clan->troops < 1 )
   {
      send_to_char( "Your clan has no ground assault troops.\r\n", ch );
      return;
   }

   num = atoi(argument);
   if( num > ch->pcdata->clan->troops )
   {
      send_to_char( "Your clan doesn't have that many ground assault troops.\r\n", ch );
      return;
   }

   if( ( ship = ship_from_cockpit(ch->in_room->vnum) ) == NULL )
   {
      send_to_char( "You must be in the cockpit of the dropship to do this.\r\n", ch );
      return;
   }

   vnum = ship->location;
   if( ( room = get_room_index(vnum) ) == NULL )
   {
      send_to_char( "This ship is not in a room.\r\n", ch );
      return;
   }

   if( num > MAX_DROP_TROOPS )
   {
      ch_printf( ch, "You can only drop %d troops at once!\r\n", MAX_DROP_TROOPS );
      return;
   }
   if( num > ch->pcdata->clan->troops )
      num = ch->pcdata->clan->troops;

   if( ( pMobIndex = get_mob_index( 82 ) ) == NULL )
      return;

   if( room->area == NULL )
      return;

   for( i = 1; i <= num; i++ )
   {
      /* Can be any room but the hi_room and low_room */
      vnum = number_range( room->area->low_r_vnum + 1, room->area->hi_r_vnum - 1 );

      if( ( rtest = get_room_index(vnum) ) == NULL )
         continue;

      /* Now lets make sure the room isn't safe and isn't a player home */
      if( IS_SET( rtest->room_flags, ROOM_SAFE ) || IS_SET( rtest->room_flags, ROOM_PLR_HOME ) )
      {
         --i;
         continue;
      }
      mob = create_mobile( pMobIndex );
      char_to_room( mob, rtest );
      if( ch->pcdata && ch->pcdata->clan )
         sprintf( tmpbuf , "(%s) %s" , ch->pcdata->clan->name  , mob->long_descr );
      STRFREE( mob->long_descr );
      mob->mob_clan = QUICKLINK( ch->pcdata->clan->name );
      mob->long_descr = STRALLOC( tmpbuf );
      if( ( pObjIndex = get_obj_index( OBJ_VNUM_BLASTECH_E11 ) ) != NULL )
      {
         blaster = create_object( pObjIndex, mob->top_level );
         obj_to_char( blaster, mob );
         equip_char( mob, blaster, WEAR_WIELD );
      }
   }
   sprintf( tmpbuf, "&RYelling and the thunder of feet is heard from the troop hold as %d troops exit the ship and fan out.\r\n", num );
   ch->pcdata->clan->troops -= num;
   echo_to_cockpit( AT_RED, ship, tmpbuf );
}


Keberus said:


Basically, it would be easiest if you replace your do_droptroops with this one. The problem with the old code is that it used room for everthing even after it got set to NULL, then continued in the loop it would try accessing room->area->low_r_vnum ...which crashed the mud. Also I put in a global variable for max # of droptroops, and put in checks to make sure the room wasn't a player home, safe, or floating in a void.


Also of note, in this fix, I also corrected the line:
mob->mob_clan = ch->pcdata->clan->name;

The result of this, while unlikely, could lead to string memory corruption down the road.
       
Pages:<< prev 1 next >>