diff options
-rw-r--r-- | src/net_client.c | 15 | ||||
-rw-r--r-- | src/net_common.c | 37 | ||||
-rw-r--r-- | src/net_common.h | 5 |
3 files changed, 40 insertions, 17 deletions
diff --git a/src/net_client.c b/src/net_client.c index 379a5a78..fecae5be 100644 --- a/src/net_client.c +++ b/src/net_client.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: net_client.c 410 2006-03-07 12:46:52Z fraggle $ +// $Id: net_client.c 411 2006-03-07 12:57:52Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -890,7 +890,6 @@ static void NET_CL_ParseResendRequest(net_packet_t *packet) static void NET_CL_ParseConsoleMessage(net_packet_t *packet) { char *msg; - char *p; msg = NET_ReadString(packet); @@ -899,17 +898,7 @@ static void NET_CL_ParseConsoleMessage(net_packet_t *packet) return; } - // Do not do a straight "puts" of the string, as this could be - // dangerous (sending control codes to terminals can do all - // kinds of things) - - for (p=msg; *p; ++p) - { - if (isprint(*p)) - putchar(*p); - } - - putchar('\n'); + NET_SafePuts(msg); } // parse a received packet diff --git a/src/net_common.c b/src/net_common.c index d79d30ec..0318df7a 100644 --- a/src/net_common.c +++ b/src/net_common.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: net_common.c 374 2006-02-19 13:42:27Z fraggle $ +// $Id: net_common.c 411 2006-03-07 12:57:52Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -47,6 +47,7 @@ // Common code shared between the client and server // +#include <ctype.h> #include <stdlib.h> #include "doomdef.h" @@ -177,13 +178,23 @@ static void NET_Conn_ParseDisconnectACK(net_connection_t *conn, static void NET_Conn_ParseReject(net_connection_t *conn, net_packet_t *packet) { + char *msg; + + msg = NET_ReadString(packet); + + if (msg == NULL) + { + return; + } + if (conn->state == NET_CONN_STATE_CONNECTING) { // rejected by server conn->state = NET_CONN_STATE_DISCONNECTED; - // there is a rejection message here, but it is unused at the moment. + printf("Rejected by server: "); + NET_SafePuts(msg); } } @@ -514,8 +525,28 @@ unsigned int NET_ExpandTicNum(unsigned int relative, unsigned int b) result -= 0x100; if (l > 0xb0 && b < 0x40) result += 0x100; - + return result; } +// "Safe" version of puts, for displaying messages received from the +// network. + +void NET_SafePuts(char *s) +{ + char *p; + + // Do not do a straight "puts" of the string, as this could be + // dangerous (sending control codes to terminals can do all + // kinds of things) + + for (p=s; *p; ++p) + { + if (isprint(*p)) + putchar(*p); + } + + putchar('\n'); +} + diff --git a/src/net_common.h b/src/net_common.h index 657804fb..af68157c 100644 --- a/src/net_common.h +++ b/src/net_common.h @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: net_common.h 374 2006-02-19 13:42:27Z fraggle $ +// $Id: net_common.h 411 2006-03-07 12:57:52Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -111,6 +111,9 @@ void NET_Conn_Disconnect(net_connection_t *conn); void NET_Conn_Run(net_connection_t *conn); net_packet_t *NET_Conn_NewReliable(net_connection_t *conn, int packet_type); +// Other miscellaneous common functions + +void NET_SafePuts(char *msg); unsigned int NET_ExpandTicNum(unsigned int relative, unsigned int b); #endif /* #ifndef NET_COMMON_H */ |