+static char *HandleNetworkingPackets()
+{
+ while (1)
+ {
+ /* ---------- check network server for activity ---------- */
+
+ int num_active_sockets = SDLNet_CheckSockets(rfds, 1);
+
+ if (num_active_sockets < 0)
+ return "Error checking network sockets!";
+
+ if (num_active_sockets == 0)
+ break; // no active sockets, stop here
+
+ /* ---------- read packets from network server ---------- */
+
+ int num_bytes = SDLNet_TCP_Recv(sfd, readbuffer + nread, 1);
+
+ if (num_bytes < 0)
+ return "Error reading from network server!";
+
+ if (num_bytes == 0)
+ return "Connection to network server lost!";
+
+ nread += num_bytes;
+
+ HandleNetworkingMessages();
+ }
+
+ return NULL;
+}
+
+static void HandleNetworkingDisconnect()
+{
+ int i;
+
+ SDLNet_TCP_DelSocket(rfds, sfd);
+ SDLNet_TCP_Close(sfd);
+
+ network.enabled = FALSE;
+ network_playing = FALSE;
+
+ for (i = 0; i < MAX_PLAYERS; i++)
+ stored_player[i].connected_network = FALSE;
+}