Login
User Name:

Password:



Register

Forgot your password?
void nanny_get_new_race -- comm.c
Mar 13, 2025 7:08 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, AhrefsBot, Meta, Bing

Members: 0
Guests: 8
Stats
Files
Topics
Posts
Members
Newest Member
503
3,812
19,720
594
BiancaLowr

» 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
Posts14
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

Post is unread #2 Feb 27, 2025 8:11 pm   Last edited Feb 27, 2025 8:12 pm by Elwood
Go to the top of the page
Go to the bottom of the page

Elwood
Fledgling
GroupMembers
Posts14
JoinedMar 29, 2024

 
RE: Fix: Took the null section out since it really did nothing...
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( 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, sizeof(buf2), "&R[&z%-15.15s&R]&w  ", ability_name[iClass] );
         mudstrlcat( buf, buf2, sizeof(buf) );
         if( ++col % 4 == 0 )
         {
            mudstrlcat( buf, "\r\n", sizeof(buf) );
            send_to_desc_color( buf, d );
            buf[0] = '\0';
         }
      }
   }
   
   if( col % 4 != 0 )
      mudstrlcat( buf, "\r\n", sizeof(buf) );
   mudstrlcat( buf, "&z:&w ", sizeof(buf) );

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

Post is unread #3 Feb 28, 2025 9:20 pm   
Go to the top of the page
Go to the bottom of the page

GatewaySysop
Conjurer
GroupMembers
Posts429
JoinedMar 7, 2005

 
Forgive me, but am I wrong or is the only change this addition you're talking about making?

   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;
      }
   }

Post is unread #4 Mar 13, 2025 7:08 am   
Go to the top of the page
Go to the bottom of the page

Elwood
Fledgling
GroupMembers
Posts14
JoinedMar 29, 2024

 
Yea guess thats what makes it work correctly :P

Pages:<< prev 1 next >>