Small changes to formatting, and to input handling

This commit is contained in:
Vatiken 2012-03-21 04:44:23 +00:00
parent 8852c83abf
commit 61f538c112
3 changed files with 36 additions and 38 deletions

View file

@ -819,9 +819,9 @@ void game_loop(socket_t local_mother_desc)
for (d = descriptor_list; d; d = next_d) { for (d = descriptor_list; d; d = next_d) {
next_d = d->next; next_d = d->next;
if (FD_ISSET(d->descriptor, &exc_set)) { if (FD_ISSET(d->descriptor, &exc_set)) {
FD_CLR(d->descriptor, &input_set); FD_CLR(d->descriptor, &input_set);
FD_CLR(d->descriptor, &output_set); FD_CLR(d->descriptor, &output_set);
close_socket(d); close_socket(d);
} }
} }
@ -831,9 +831,9 @@ void game_loop(socket_t local_mother_desc)
if (FD_ISSET(d->descriptor, &input_set)) if (FD_ISSET(d->descriptor, &input_set))
{ {
if ( d->pProtocol != NULL ) /* KaVir's plugin */ if ( d->pProtocol != NULL ) /* KaVir's plugin */
d->pProtocol->WriteOOB = 0; /* KaVir's plugin */ d->pProtocol->WriteOOB = 0; /* KaVir's plugin */
if (process_input(d) < 0) if (process_input(d) < 0)
close_socket(d); close_socket(d);
} }
} }
@ -899,8 +899,8 @@ void game_loop(socket_t local_mother_desc)
/* Print prompts for other descriptors who had no other output */ /* Print prompts for other descriptors who had no other output */
for (d = descriptor_list; d; d = d->next) { for (d = descriptor_list; d; d = d->next) {
if (!d->has_prompt) { if (!d->has_prompt) {
write_to_descriptor(d->descriptor, make_prompt(d)); write_to_descriptor(d->descriptor, make_prompt(d));
d->has_prompt = TRUE; d->has_prompt = TRUE;
} }
} }
@ -1556,11 +1556,8 @@ static int process_output(struct descriptor_data *t)
if (STATE(t) == CON_PLAYING && t->character && !IS_NPC(t->character) && !PRF_FLAGGED(t->character, PRF_COMPACT)) if (STATE(t) == CON_PLAYING && t->character && !IS_NPC(t->character) && !PRF_FLAGGED(t->character, PRF_COMPACT))
strcat(osb, "\r\n"); /* strcpy: OK (osb:MAX_SOCK_BUF-2 reserves space) */ strcat(osb, "\r\n"); /* strcpy: OK (osb:MAX_SOCK_BUF-2 reserves space) */
if (!t->pProtocol->WriteOOB) if (!t->pProtocol->WriteOOB) /* add a prompt */
{ strcat(i, make_prompt(t)); /* strcpy: OK (i:MAX_SOCK_BUF reserves space) */
/* add a prompt */
strcat(i, make_prompt(t)); /* strcpy: OK (i:MAX_SOCK_BUF reserves space) */
}
/* now, send the output. If this is an 'interruption', use the prepended /* now, send the output. If this is an 'interruption', use the prepended
* CRLF, otherwise send the straight output sans CRLF. */ * CRLF, otherwise send the straight output sans CRLF. */
@ -1740,13 +1737,13 @@ static ssize_t perform_socket_read(socket_t desc, char *read_point, size_t space
{ {
ssize_t ret; ssize_t ret;
#if defined(CIRCLE_ACORN) #if defined(CIRCLE_ACORN)
ret = recv(desc, read_point, space_left, MSG_DONTWAIT); ret = recv(desc, read_point, space_left, MSG_DONTWAIT);
#elif defined(CIRCLE_WINDOWS) #elif defined(CIRCLE_WINDOWS)
ret = recv(desc, read_point, space_left, 0); ret = recv(desc, read_point, space_left, 0);
#else #else
ret = read(desc, read_point, space_left); ret = read(desc, read_point, space_left);
#endif #endif
/* Read was successful. */ /* Read was successful. */
if (ret > 0) if (ret > 0)
@ -1814,9 +1811,7 @@ static int process_input(struct descriptor_data *t)
size_t space_left; size_t space_left;
char *ptr, *read_point, *write_point, *nl_pos = NULL; char *ptr, *read_point, *write_point, *nl_pos = NULL;
char tmp[MAX_INPUT_LENGTH]; char tmp[MAX_INPUT_LENGTH];
static char read_buf[MAX_PROTOCOL_BUFFER] = { '\0' }; /* KaVir's plugin */
static char read_buf[MAX_PROTOCOL_BUFFER]; /* KaVir's plugin */
read_buf[0] = '\0'; /* KaVir's plugin */
/* first, find the point where we left off reading data */ /* first, find the point where we left off reading data */
buf_length = strlen(t->inbuf); buf_length = strlen(t->inbuf);
@ -1829,14 +1824,15 @@ static int process_input(struct descriptor_data *t)
return (-1); return (-1);
} }
bytes_read = perform_socket_read(t->descriptor, read_buf, space_left); /* Read # of "bytes_read" from socket, and if we have something, mark the sizeof data
* in the read_buf array as NULL */
if ( bytes_read >= 0 ) if ((bytes_read = perform_socket_read(t->descriptor, read_buf, space_left)) > 0)
{
read_buf[bytes_read] = '\0'; read_buf[bytes_read] = '\0';
ProtocolInput( t, read_buf, bytes_read, t->inbuf );
bytes_read = strlen(t->inbuf); /* Since we have recieved atleast 1 byte of data from the socket, lets run it through
} * ProtocolInput() and rip out anything that is Out Of Band */
if ( bytes_read > 0 )
bytes_read = ProtocolInput( t, read_buf, bytes_read, t->inbuf );
if (bytes_read < 0) /* Error, disconnect them. */ if (bytes_read < 0) /* Error, disconnect them. */
return (-1); return (-1);
@ -1849,7 +1845,7 @@ static int process_input(struct descriptor_data *t)
/* search for a newline in the data we just read */ /* search for a newline in the data we just read */
for (ptr = read_point; *ptr && !nl_pos; ptr++) for (ptr = read_point; *ptr && !nl_pos; ptr++)
if (ISNEWL(*ptr)) if (ISNEWL(*ptr))
nl_pos = ptr; nl_pos = ptr;
read_point += bytes_read; read_point += bytes_read;
space_left -= bytes_read; space_left -= bytes_read;

View file

@ -11,6 +11,7 @@
******************************************************************************/ ******************************************************************************/
#include <arpa/telnet.h> #include <arpa/telnet.h>
#include <sys/types.h>
#include "protocol.h" #include "protocol.h"
/****************************************************************************** /******************************************************************************
@ -349,13 +350,13 @@ void ProtocolDestroy( protocol_t *apProtocol )
free(apProtocol); free(apProtocol);
} }
void ProtocolInput( descriptor_t *apDescriptor, char *apData, int aSize, char *apOut ) ssize_t ProtocolInput( descriptor_t *apDescriptor, char *apData, int aSize, char *apOut )
{ {
static char CmdBuf[MAX_PROTOCOL_BUFFER+1]; static char CmdBuf[MAX_PROTOCOL_BUFFER+1];
static char IacBuf[MAX_PROTOCOL_BUFFER+1]; static char IacBuf[MAX_PROTOCOL_BUFFER+1];
int CmdIndex = 0; ssize_t CmdIndex = 0;
int IacIndex = 0; ssize_t IacIndex = 0;
int Index; ssize_t Index;
protocol_t *pProtocol = apDescriptor ? apDescriptor->pProtocol : NULL; protocol_t *pProtocol = apDescriptor ? apDescriptor->pProtocol : NULL;
@ -365,7 +366,7 @@ void ProtocolInput( descriptor_t *apDescriptor, char *apData, int aSize, char *a
if ( CmdIndex >= MAX_PROTOCOL_BUFFER || IacIndex >= MAX_PROTOCOL_BUFFER ) if ( CmdIndex >= MAX_PROTOCOL_BUFFER || IacIndex >= MAX_PROTOCOL_BUFFER )
{ {
ReportBug("ProtocolInput: Too much incoming data to store in the buffer.\n"); ReportBug("ProtocolInput: Too much incoming data to store in the buffer.\n");
return; return (-1);
} }
/* IAC IAC is treated as a single value of 255 */ /* IAC IAC is treated as a single value of 255 */
@ -419,7 +420,7 @@ void ProtocolInput( descriptor_t *apDescriptor, char *apData, int aSize, char *a
{ {
const char *pClientName = pProtocol->pVariables[eMSDP_CLIENT_ID]->pValueString; const char *pClientName = pProtocol->pVariables[eMSDP_CLIENT_ID]->pValueString;
InfoMessage(apDescriptor, "Receiving MXP Version From Client.\r\n"); InfoMessage(apDescriptor, "Receiving MXP Version From Client.\r\n");
free(pProtocol->pVariables[eMSDP_CLIENT_VERSION]->pValueString); free(pProtocol->pVariables[eMSDP_CLIENT_VERSION]->pValueString);
pProtocol->pVariables[eMSDP_CLIENT_VERSION]->pValueString = AllocString(pMXPTag); pProtocol->pVariables[eMSDP_CLIENT_VERSION]->pValueString = AllocString(pMXPTag);
@ -513,6 +514,7 @@ void ProtocolInput( descriptor_t *apDescriptor, char *apData, int aSize, char *a
/* Copy the input buffer back to the player. */ /* Copy the input buffer back to the player. */
strcat( apOut, CmdBuf ); strcat( apOut, CmdBuf );
return (CmdIndex);
} }
const char *ProtocolOutput( descriptor_t *apDescriptor, const char *apData, int *apLength ) const char *ProtocolOutput( descriptor_t *apDescriptor, const char *apData, int *apLength )

View file

@ -250,7 +250,7 @@ void ProtocolNegotiate( descriptor_t *apDescriptor );
* whatever is left for the mud to parse normally. Call this after data has * whatever is left for the mud to parse normally. Call this after data has
* been read into the input buffer, before it is used for anything else. * been read into the input buffer, before it is used for anything else.
*/ */
void ProtocolInput( descriptor_t *apDescriptor, char *apData, int aSize, char *apOut ); ssize_t ProtocolInput( descriptor_t *apDescriptor, char *apData, int aSize, char *apOut );
/* Function: ProtocolOutput /* Function: ProtocolOutput
* *