ref: b2a2c312907d214aacaa11f97a217e4a42cfe683
parent: edc20cc64e1930bdcc9466063e17f91519492a37
author: Simon Howard <[email protected]>
date: Tue Mar 7 07:57:52 EST 2006
Convert NET_CL_SafePuts to NET_SafePuts, and print rejection messages from the server. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 411
--- 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_ParseConsoleMessage(net_packet_t *packet)
{
char *msg;
- char *p;
msg = NET_ReadString(packet);
@@ -899,17 +898,7 @@
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
--- 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,6 +178,15 @@
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
@@ -183,7 +193,8 @@
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 @@
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');
}
--- 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_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 */