So this is what I have so far. It works, but there are some problems with it.
Basically, it puts a lot of \n\r's into the buffer and I can't seem to get them
out. Also, at times it crashes the game, and at times it does not display the
prompt and the buffer just gets destroyed. Finally, this is a good one: what is
occuring in the game to said player displays in the shell. I literally laughed
at that one. So, this is what I have:
bool read_from_descriptor( DESCRIPTOR_DATA *d )
{
int iStart;
/* 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 )
{
sprintf( log_buf, "%s input overflow!", d->host );
log_string( log_buf );
write_to_descriptor( d->descriptor,
"\n\r*** PUT A LID ON IT!!! ***\n\r", 0 );
return FALSE;
}
/* Snarf input. */
#if defined(macintosh)
for ( ; ; )
{
int c;
c = getc( stdin );
if ( c == '\0' || c == EOF )
break;
putc( c, stdout );
if ( c == '\r' )
putc( '\n', stdout );
d->inbuf[iStart++] = c;
if ( iStart > sizeof(d->inbuf) - 10 )
break;
}
#endif
#if defined(MSDOS) || defined(unix)
for ( ; ; )
{
int nRead;
nRead = read( d->descriptor, d->inbuf + iStart,
sizeof(d->inbuf) - 10 - iStart );
if ( nRead > 0 )
{
iStart += nRead;
if ( d->inbuf[iStart-1] == '\n' || d->inbuf[iStart-1] == '\r' )
break;
}
else if ( nRead == 0 )
{
log_string( "EOF encountered on read." );
return FALSE;
}
else if ( errno == EWOULDBLOCK )
break;
else
{
perror( "Read_from_descriptor" );
return FALSE;
}
}
#endif
d->inbuf[iStart] = '\0';
//return TRUE;
if(d)
{
char command[MSL];
int x, i, y,temp, z = 0;
int csize;
bool character = FALSE;
csize = strlen(d->inbuf);
command[0] = '\0';
if(d->character)
character = TRUE; //we have a character
if(character)
{
if(d->character->wait < 1) //don't do this if there is
no wait.
return TRUE;
}
for(x = 0, i = 0;x <= csize;x++)
{
if(d->character)
character = TRUE; //we have a character
if(d->inbuf[x] == '\n' || d->inbuf[x] == '\r' ||
d->inbuf[x]
=='\0')
//dont copy this.
{
if(command[0] != '\0')
found = TRUE; //we have a command.
}
else
{
command[i] = d->inbuf[x]; //lets copy the next
element.
i++; //increment the command
by 1
continue; //lets get the rest of
the command.
}
if(found && character) //we have the command. let's see
if we can execute it.
{
//execute it.
interpret(d->character, command);
//lets check to see if we executed it. if we
did, let's remove it.
if(d->character->remove_command)
{
//shift contents of the array.
temp = x - strlen(command);
//move previous items over the item
that you're trying to delete
for(z = 0; z < csize;z++, temp++)
{
d->inbuf[temp] =
d->inbuf[temp+strlen(command)];
}
//lets set the remove command to false.
if(d->character)
d->character->remove_command =
FALSE;
//set found to false
found = FALSE;
//set i to 0 in the command.
i = 0;
//set the new csize
csize = strlen(d->inbuf);
/*We executed the command during a wait
state. We also
removed the command. So let's check the
next one.*/
}
//clear out the command.
for(y = 0;command[y] != '\0';y++)
command[y] = '\0';
//set i to be 0 in the command.
i = 0;
//set found to false
found = FALSE;
}
}
}
return TRUE;
}
Maybe someone can lend me a hand. THANKS!