Pages:<< prev 1 next >>



Fledgling

GroupMembers
Posts14
JoinedMar 29, 2024
Original:
Fix:
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
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


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



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



Fledgling

GroupMembers
Posts14
JoinedMar 29, 2024
Yea guess thats what makes it work correctly

Pages:<< prev 1 next >>