Swr 1.0 - A question on a bug with the login (a.k.a. nanny) function.

Posted by Odis on Wed 11 Dec 2002 01:57 AM — 6 posts, 20,542 views.

#0
Well, I have a very important question. I run a MUD derived off of SWR and I've fixed almost every bug I've found, except for this one. When a person logs in and it says "Please choose a main ability from the following classes" and then if they type ee or something like that it crashes. So I guess I'll just try and post the code here (only the section I know the bug is in) and hope you can find what I'm looking for. I'm not really an experienced coder, but I know enough for what I need. Only this one bug has slipped my mind, I'm not good at working with arguments really. So please post a reply if you can help. Sorry if the format is screwed up a bit, I copy and pasted it.

------ From void nanny in comm.c ------



write_to_buffer( d, "\n\rPlease choose a main ability from the folowing classes:\n\r[", 0 );
buf[0] = '\0';
for ( iClass = 0; iClass < MAX_ABILITY; iClass++ )
{
if (ability_name[iClass] && ability_name[iClass][0] != '\0')
{
if ( iClass > 0 )
{
if ( strlen(buf)+strlen(ability_name[iClass]) > 77 )
{
strcat( buf, "\n\r" );
write_to_buffer( d, buf, 0 );
buf[0] = '\0';
}
else
strcat( buf, " " );
}
strcat( buf, ability_name[iClass] );
}
}
strcat( buf, "]\n\r: " );
write_to_buffer( d, buf, 0 );
d->connected = CON_GET_NEW_CLASS;
break;

case CON_GET_NEW_CLASS:
argument = one_argument(argument, arg);
if (!str_cmp( arg, "help") )
{
do_help(ch, argument);
write_to_buffer( d, "Please choose an ability class: ", 0);
return;
}


for ( iClass = 0; iClass < MAX_ABILITY; iClass++ )
{
if ( toupper(arg[0]) == toupper(ability_name[iClass][0])
&& !str_prefix( arg, ability_name[iClass] ) )
{
ch->main_ability = iClass;
break;
}
}

if ( iClass == MAX_ABILITY
|| !ability_name[iClass] || ability_name[iClass][0] == '\0')
{
write_to_buffer( d,
"That's not a skill class.\n\rWhat IS it going to be? ", 0 );
return;
}
USA #1
Actually I did this on my SWR Mud also. What is MAX_ABILITY defined to in mud.h and how many abilitys are going to be displayed? Tell me that and I think I can tell you how to fix it.
#2
MAX_ABILITY is defined as 8 but I only want to display 7. Should I change MAX_ABILITY to 7?
USA #3
Make sure you have 7 and only 7 defined in const.c . Then change it so the code looks like this:

write_to_buffer( d, "\n\rPlease choose a main ability from the folowing classes:\n\r[", 0 );
buf[0] = '\0';
for ( iClass = 0; iClass < 7; iClass++ )
{
if (ability_name[iClass] && ability_name[iClass][0] != '\0')
{
if ( iClass > 0 )
{
if ( strlen(buf)+strlen(ability_name[iClass]) > 77 )
{
strcat( buf, "\n\r" );
write_to_buffer( d, buf, 0 );
buf[0] = '\0';
}
else
strcat( buf, " " );
}
strcat( buf, ability_name[iClass] );
}
}
strcat( buf, "]\n\r: " );
write_to_buffer( d, buf, 0 );
d->connected = CON_GET_NEW_CLASS;
break;

case CON_GET_NEW_CLASS:
argument = one_argument(argument, arg);
if (!str_cmp( arg, "help") )
{
do_help(ch, argument);
write_to_buffer( d, "Please choose an ability class: ", 0);
return;
}


for ( iClass = 0; iClass < 7; iClass++ )
{
if ( toupper(arg[0]) == toupper(ability_name[iClass][0])
&& !str_prefix( arg, ability_name[iClass] ) )
{
ch->main_ability = iClass;
break;
}
}

if ( iClass == MAX_ABILITY
|| !ability_name[iClass] || ability_name[iClass][0] == '\0')
{
write_to_buffer( d,
"That's not a skill class.\n\rWhat IS it going to be? ", 0 );
return;
}

It should fix the bug that you were getting. If it doesn't then just let me know.
#4
Thanks! That fixed it. I guess it was crashing becuase it would loop up 1 more than was defined. So yeah, thanks agian.


~Odis
USA #5
Glad I could help. :)