I'm not sure if this is the right place for this, but it seems as good a place as any.
My Goal: I'm working on a function that parses a prompt much like SMAUG does, so if a player has a prompt of "[$h/$Hhp]" it will send "[100/100hp]" -- or whatever the player's health and max health are.
My Problem: It appears that sprintf is not working in the function. The function properly detects flags, but it does not add the information I would like.
My Code:
As you can see, there is quite a lot of error checking in there. This is what I get as output:
Via telnet:
In the terminal:
I don't think I'm doing anything wrong, yet I continue to get the wrong results... so can someone more learned than I tell my where I'm f'ed up?
Thank you,
Will
My Goal: I'm working on a function that parses a prompt much like SMAUG does, so if a player has a prompt of "[$h/$Hhp]" it will send "[100/100hp]" -- or whatever the player's health and max health are.
My Problem: It appears that sprintf is not working in the function. The function properly detects flags, but it does not add the information I would like.
My Code:
void send_prompt( D_MOBILE *player )
{
char *buf = (char*) malloc( sizeof( char ) * MAX_BUFFER );
char *pbuf = player->prompt;
char *start = buf;
/*
*Possible Prompt Flags:
*$h - Current Health
*$H - Maximum Health
*$l - Current Level
*/
if( !player->prompt )
{
cmd_prompt( player, "default" );
}
for( ;*pbuf; pbuf++ )
{
if( *pbuf != '$' )
{
*buf = *pbuf;
buf++;
}
else
{
pbuf++;
switch( *pbuf )
{
case 'h':
sprintf( buf, "%i", player->curHealth );
fprintf( stderr, "Current Health Flag\n" );
break;
case 'H':
sprintf( buf, "%i", player->maxHealth );
fprintf( stderr, "Maximum Health Flag\n" );
break;
case 'l':
sprintf( buf, "%i", player->level );
fprintf( stderr, "Current Level Flag\n" );
break;
default:
fprintf( stderr, "Default\n" );
sprintf( buf, "%c", *pbuf );
break;
}
}
}
*buf = '\0';
text_to_mobile( player, start );
fprintf( stderr, "Prompt set as: %s\nPrompt being displayed: %s\n", player->prompt, start );
return;
}
As you can see, there is quite a lot of error checking in there. This is what I get as output:
Via telnet:
What is your name? Will
What is your password?
[LOG: Will has entered the game.]
Welcome to SocketMUD(tm)
We hope your stay here will be a pleasant one,
and are looking forward to serving you a rich
and colorful mud experience.
The staff.
[/hp Level: ]
[/hp Level: ]
[/hp Level: ]
In the terminal:
(06:51 PM Mon May 24)
(w@w.domain1)-(~/dev/C/Projects/SocketMUD/socketmud/src)>./SocketMud
Current Health Flag
Maximum Health Flag
Current Level Flag
Prompt set as: [$h/$Hhp Level: $l]
Prompt being displayed: [/hp Level: ]
Current Health Flag
Maximum Health Flag
Current Level Flag
Prompt set as: [$h/$Hhp Level: $l]
Prompt being displayed: [/hp Level: ]
Current Health Flag
Maximum Health Flag
Current Level Flag
Prompt set as: [$h/$Hhp Level: $l]
Prompt being displayed: [/hp Level: ]
Current Health Flag
Maximum Health Flag
Current Level Flag
Prompt set as: [$h/$Hhp Level: $l]
Prompt being displayed: [/hp Level: ]
(06:52 PM Mon May 24)
(w@w.domain1)-(~/dev/C/Projects/SocketMUD/socketmud/src)>
I don't think I'm doing anything wrong, yet I continue to get the wrong results... so can someone more learned than I tell my where I'm f'ed up?
Thank you,
Will