Asking the user for input after connection state is CON_PLAYING not working with added function
Hello all, I'm either doing this wrong or something else weird is happening. I've added the CON_INPUT and CON_INPUTPWD connection states to mud.h to act as general input handling states. They set ch->readtxt to the argument descripter_data::nanny () gets whenever a state is set to something else other than CON_PLAYING. (I tried moving this stuff around and this keeps happening.) Then I edited character.h and added the following functions to it ('it' being the character_data class):
// from character.h:
string read (const string &);
string readln (const string &);
string readf( const char *, ... ) __attribute__ ( ( format( printf, 2, 3 ) ) );
string readlnf( const char *, ... ) __attribute__ ( ( format( printf, 2, 3 ) ) );
string readpwd (const string &);
string readpwdln (const string &);
string readpwdf( const char *, ... ) __attribute__ ( ( format( printf, 2, 3 ) ) );
string readpwdlnf( const char *, ... ) __attribute__ ( ( format( printf, 2, 3 ) ) );
// I added the readtxt variable at the end of the class as to not cause class discord:
string readtxt; // Used with ch->readln () and related functions.
// The implementation of the above functions is below, in character.cpp, starting at line 5400 for my copy:
string char_data::read (const string &txt)
{
this->print (txt);
this->desc->connected = CON_INPUT;
return this->readtxt;
}
string char_data::readln (const string &txt)
{
this->printf ("%s\r\n", txt.c_str());
this->desc->connected = CON_INPUT;
return this->readtxt;
}
string char_data::readf ( const char *fmt, ... )
{
char buf[MSL * 2];
va_list args;
va_start( args, fmt );
vsnprintf( buf, MSL * 2, fmt, args );
va_end( args );
this->print( buf);
this->desc->connected = CON_INPUT;
return this->readtxt;
}
string char_data::readlnf( const char *fmt, ... )
{
char buf[MSL * 2];
va_list args;
va_start( args, fmt );
vsnprintf( buf, MSL * 2, fmt, args );
va_end( args );
this->printf ("%s\r\n", buf);
this->desc->connected = CON_INPUT;
return this->readtxt;
}
string char_data::readpwd (const string &txt)
{
this->print (txt);
this->desc->connected = CON_INPUTPWD;
return this->readtxt;
}
string char_data::readpwdln (const string &txt)
{
this->println (txt);
this->desc->connected = CON_INPUTPWD;
return this->readtxt;
}
string char_data::readpwdf ( const char *fmt, ... )
{
char buf[MSL * 2];
va_list args;
va_start( args, fmt );
vsnprintf( buf, MSL * 2, fmt, args );
va_end( args );
this->printf ("%s", buf);
this->desc->connected = CON_INPUTPWD;
return this->readtxt;
}
string char_data::readpwdlnf( const char *fmt, ... )
{
char buf[MSL * 2];
va_list args;
va_start( args, fmt );
vsnprintf( buf, MSL * 2, fmt, args );
va_end( args );
this->printf ("%s\r\n", buf);
this->desc->connected = CON_INPUTPWD;
return this->readtxt;
}
Then I implemented the two connection states like so:
// Ln. 3536 for my copy:
case CON_INPUT:
{
ch->readtxt = argument;
connected = CON_PLAYING;
}
break;
case CON_INPUTPWD:
{
write_to_buffer( (const char*)echo_off_str );
ch->readtxt = argument;
write_to_buffer( (const char*)echo_on_str );
connected = CON_PLAYING;
}
break;
Can any of you tell me what I'm doing wrong? It's hard to determine what's wrong -- the function or the connection state. Even accepting the return value and then doing something like ch->printf ("You entered '%s'\r\n", result.c_str()); doesn't fix it. So right now I'm just confused. The reason I implemented these functions is so that I don't have to implement a hundred thousand connection states for every single form of input I want.
P.s. I used some functions you might not recognize (i.e. println, printlnf, ...); I implemented these and they do work fine.