Login
User Name:

Password:



Register

Forgot your password?
void nanny_get_new_race -- comm.c
Feb 16, 2025 1:25 am
By Elwood
IPv6
Jan 25, 2025 10:45 pm
By Samson
mudstrlcpy and mudstrlcat
Jan 18, 2025 5:23 pm
By Samson
I3 and IMC
Jan 17, 2025 9:35 pm
By Samson
AFKMud 2.5.1
Jan 17, 2025 2:22 pm
By Samson
SmaugFUSS 1.9.7
Author: Various
Submitted by: Samson
AFKMud 2.5.1
Author: AFKMud Team
Submitted by: Samson
Kayle's Weather Code for AFKMud
Author: Kayle
Submitted by: Samson
AFKMud 2.5.0
Author: AFKMud Team
Submitted by: Samson
SWFotEFUSS 1.5.2
Author: Various
Submitted by: Samson
Users Online
Anthropic, Bing

Members: 0
Guests: 19
Stats
Files
Topics
Posts
Members
Newest Member
503
3,812
19,715
599
AlbertinaV

» SmaugMuds » Codebases » SWFOTE FUSS » void nanny_get_new_race -- co...
Forum Rules | Mark all | Recent Posts

void nanny_get_new_race -- comm.c
< Newer Topic :: Older Topic > void nanny_get_new_race -- comm.c

Pages:<< prev 1 next >>
Post is unread #1 Feb 16, 2025 1:25 am   
Go to the top of the page
Go to the bottom of the page

Elwood
Fledgling
GroupMembers
Posts12
JoinedMar 29, 2024

 
Original:
void nanny_get_new_race( DESCRIPTOR_DATA * d, const char *argument )
{
   char buf[MAX_STRING_LENGTH], arg[MAX_STRING_LENGTH], buf2[MAX_STRING_LENGTH];
   CHAR_DATA *ch = d->character;
   int iRace, iClass, col = 0;

   argument = one_argument( argument, arg );
   
   if( !str_cmp( arg, "help" ) )
   {
      do_help( ch, argument );
      send_to_desc_color( "&zPlease choose a race:&w ", d );
      return;
   }

   for( iRace = 0; iRace < MAX_RACE; iRace++ )
   {
      if( toupper( arg[0] ) == toupper( race_table[iRace].race_name[0] )
         && !str_prefix( arg, race_table[iRace].race_name ) )
      {
         ch->race = iRace;
         break;
      }
   }

   if( iRace == MAX_RACE || !race_table[iRace].race_name || race_table[iRace].race_name[0] == '\0' )
   {
      send_to_desc_color( "&zThat's not a race.\r\nWhat is your race?&w ", d );
      return;
   }

   send_to_desc_color( "\r\n&zPlease choose a main ability from the following classes:&w\r\n", d );
   
   buf[0] = '\0';
   col = 0;
   
   for( iClass = 0; iClass < MAX_ABILITY; iClass++ )
   {
      if( ability_name[iClass] && ability_name[iClass][0] != '\0' && str_cmp( ability_name[iClass], "force" ) )
      {
         snprintf( buf2, MAX_STRING_LENGTH, "&R[&z%-15.15s&R]&w  ", ability_name[iClass] );
         mudstrlcat( buf, buf2, MAX_STRING_LENGTH );
         if( ++col % 4 == 0 )
         {
            mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH );
            send_to_desc_color( buf, d );
            buf[0] = '\0';
         }
      }
   }
   
   if( col % 4 != 0 )
      mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH );
   mudstrlcat( buf, "&z:&w ", MAX_STRING_LENGTH );

   send_to_desc_color( buf, d );
   d->connected = CON_GET_NEW_CLASS;
}


Fix:
void nanny_get_new_race( DESCRIPTOR_DATA * d, const char *argument )
{
   char buf[MAX_STRING_LENGTH], arg[MAX_STRING_LENGTH], buf2[MAX_STRING_LENGTH];
   CHAR_DATA *ch = d->character;
   int iRace, iClass, col = 0;

   argument = one_argument( argument, arg );
   
   if( !str_cmp( arg, "help" ) )
   {
      do_help( ch, argument );
      send_to_desc_color( "&zPlease choose a race:&w ", d );
      return;
   }

    if( arg == NULL || arg[0] == '\0' )
    {
    send_to_desc_color("&zYou must enter a valid race name.\r\nWhat is your race?&w ", d);
    return;
    }

   for( iRace = 0; iRace < MAX_RACE; iRace++ )
   {
	   if( race_table[iRace].race_name == NULL || race_table[iRace].race_name[0] == '\0' )
    continue;

      if( toupper( arg[0] ) == toupper( race_table[iRace].race_name[0] )
         && !str_prefix( arg, race_table[iRace].race_name ) )
      {
         ch->race = iRace;
         break;
      }
   }

    if( iRace == MAX_RACE || !race_table[iRace].race_name || race_table[iRace].race_name[0] == '\0' )
   {
      send_to_desc_color( "&zThat's not a race.\r\nWhat is your race?&w ", d );
      return;
   }

   send_to_desc_color( "\r\n&zPlease choose a main ability from the following classes:&w\r\n", d );
   
   buf[0] = '\0';
   col = 0;
   
   for( iClass = 0; iClass < MAX_ABILITY; iClass++ )
   {
      if( ability_name[iClass] && ability_name[iClass][0] != '\0' && str_cmp( ability_name[iClass], "force" ) )
      {
         snprintf( buf2, MAX_STRING_LENGTH, "&R[&z%-15.15s&R]&w  ", ability_name[iClass] );
         mudstrlcat( buf, buf2, MAX_STRING_LENGTH );
         if( ++col % 4 == 0 )
         {
            mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH );
            send_to_desc_color( buf, d );
            buf[0] = '\0';
         }
      }
   }
   
   if( col % 4 != 0 )
      mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH );
   mudstrlcat( buf, "&z:&w ", MAX_STRING_LENGTH );

   send_to_desc_color( buf, d );
   d->connected = CON_GET_NEW_CLASS;
}


Why this should be done.... If someone put in random race, or non existant... it never checked, therefor it would crash mud. Wtih this fix it will ensure this does not happen

Pages:<< prev 1 next >>