if( strlen(buf) > 256)the 256, being the magic number, this is bad. You will want to define a constant. Most of the merc tree have something called MAX_INPUT_LENGTH(or MIL). This constant should be the limiter to how much input a person can send. It should always be less than MAX_STRING_LENGTH (or MSL). To increase the string acceptance on your MUD you should just need to increase MAX_INPUT_LENGTH and be done with it.
bool read_from_descriptor( DESCRIPTOR_DATA * d )
{
unsigned int iStart, iErr;
/*
* Hold horses if pending command already.
*/
if( d->incomm[0] != '\0' )
return TRUE;
/*
* Check for overflow.
*/
iStart = strlen( d->inbuf );
if( iStart >= sizeof( d->inbuf ) - 10 )
{
log_printf( "%s input overflow!", d->host );
write_to_descriptor( d->descriptor, "\n\r*** PUT A LID ON IT!!! ***\n\r", 0 );
return FALSE;
}
for( ;; )
{
int nRead;
nRead = recv( d->descriptor, d->inbuf + iStart, sizeof( d->inbuf ) - 10 - iStart, 0 );
iErr = errno;
if( nRead > 0 )
{
iStart += nRead;
if( d->inbuf[iStart - 1] == '\n' || d->inbuf[iStart - 1] == '\r' )
break;
}
else if( nRead == 0 && d->connected >= CON_PLAYING )
{
log_string_plus( "EOF encountered on read.", LOG_COMM, LEVEL_IMMORTAL );
return FALSE;
}
else if( iErr == EWOULDBLOCK )
break;
else
{
perror( "Read_from_descriptor" );
return FALSE;
}
}
d->inbuf[iStart] = '\0';
return TRUE;
}
void read_from_buffer( DESCRIPTOR_DATA * d )
{
int i, j, k, iac = 0;
/*
* Hold horses if pending command already.
*/
if( d->incomm[0] != '\0' )
return;
/*
* Look for at least one new line.
*/
for( i = 0; d->inbuf[i] != '\n' && d->inbuf[i] != '\r' && i < MAX_INBUF_SIZE; i++ ) /* <<< HERE */
{
if( d->inbuf[i] == '\0' )
return;
}
/*
* Canonical input processing.
*/
for( i = 0, k = 0; d->inbuf[i] != '\n' && d->inbuf[i] != '\r'; i++ )
{
if( k >= MAX_INBUF_SIZE - 2 ) /* <<< and HERE */
{
write_to_descriptor( d, "Line too long.\r\n", 0 );
…
Thanks, Davenge.