shithub: choc

Download patch

ref: 33fe9b40bb366a755a3b1ed6fbe9d2c32a815059
parent: 693828adb286b6c1ec6d0b90f49c6947e6c6dd6e
author: Simon Howard <fraggle@gmail.com>
date: Mon Jan 2 15:13:06 EST 2006

Refer to connected clients by their AddrToString() output rather than just
the pointer to their struct. Listen for IP connections as well as
loopback connections.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 245

--- a/src/net_server.c
+++ b/src/net_server.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: net_server.c 243 2006-01-02 17:24:40Z fraggle $
+// $Id: net_server.c 245 2006-01-02 20:13:06Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -21,6 +21,11 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.8  2006/01/02 20:13:06  fraggle
+// Refer to connected clients by their AddrToString() output rather than just
+// the pointer to their struct.  Listen for IP connections as well as
+// loopback connections.
+//
 // Revision 1.7  2006/01/02 17:24:40  fraggle
 // Remove test code
 //
@@ -58,6 +63,7 @@
 #include "net_loop.h"
 #include "net_packet.h"
 #include "net_server.h"
+#include "net_sdl.h"
 
 typedef enum 
 {
@@ -97,6 +103,15 @@
 static net_client_t clients[MAXNETNODES];
 static net_context_t *server_context;
 
+static char *NET_SV_ClientAddress(net_client_t *client)
+{
+    static char addrbuf[128];
+
+    client->addr->module->AddrToString(client->addr, addrbuf, sizeof(addrbuf)-1);
+    
+    return addrbuf;
+}
+
 static void NET_SV_DisconnectClient(net_client_t *client)
 {
     client->state = CLIENT_STATE_DISCONNECTING;
@@ -288,6 +303,8 @@
     // and cleaned up from the clients list.
 
     client->state = CLIENT_STATE_DISCONNECTED;
+
+    //printf("SV: %s: client disconnected\n", NET_SV_ClientAddress(client));
 }
 
 // Parse a DISCONNECT_ACK packet
@@ -334,7 +351,7 @@
         return;
     }
 
-    //printf("SV: %p: %i\n", client, packet_type);
+    //printf("SV: %s: %i\n", NET_SV_ClientAddress(client), packet_type);
 
     switch (packet_type)
     {
@@ -487,7 +504,7 @@
 
         if (I_GetTimeMS() - client->last_send_time > 5000)
         {
-            //printf("SV: %p: deactivated\n", client);
+            //printf("SV: %s: deactivated\n", NET_SV_ClientAddress(client));
             client->active = false;
             NET_FreeAddress(client->addr);
         }
@@ -505,6 +522,8 @@
     server_context = NET_NewContext();
     NET_AddModule(server_context, &net_loop_server_module);
     net_loop_server_module.InitServer();
+    NET_AddModule(server_context, &net_sdl_module);
+    net_sdl_module.InitServer();
 
     // no clients yet