added disconnecting from network server from setup menu
authorHolger Schemel <info@artsoft.org>
Tue, 26 Jun 2018 22:02:22 +0000 (00:02 +0200)
committerHolger Schemel <info@artsoft.org>
Tue, 26 Jun 2018 22:02:22 +0000 (00:02 +0200)
src/netserv.c
src/network.c
src/network.h
src/screens.c

index 4fd8461076fa0c3a5332ca500f9b0c9d2ed916f4..963a862b229b345067ca0e64b2ec3a5e3f4d475c 100644 (file)
@@ -129,6 +129,7 @@ static void RemovePlayer(struct NetworkServerPlayerInfo *player)
   free(player);
   clients--;
 
+#if 0  /* do not terminate network server if last player disconnected */
   if (onceonly && clients == 0)
   {
     if (options.verbose)
@@ -138,6 +139,7 @@ static void RemovePlayer(struct NetworkServerPlayerInfo *player)
     }
     exit(0);
   }
+#endif
 }
 
 static void AddPlayer(TCPsocket fd)
index 5f35825a6aed79117107402e095ed98cb8064cf1..e21de8c5859c47b1f5e1dcae2cda6678f8704715 100644 (file)
@@ -809,3 +809,16 @@ void HandleNetworking()
     }
   }
 }
+
+void DisconnectFromNetworkServer()
+{
+  DrawNetworkText_Title("Terminating Network");
+  DrawNetworkText("Disconnecting from network server ...");
+
+  HandleNetworkingDisconnect();
+
+  DrawNetworkText_Success("Successfully disconnected!");
+
+  /* short time to recognize result of network initialization */
+  Delay(1000);
+}
index 23b33077f8659c4a11207cd2839cb0d01ae93e0d..fbbea6dbb1495ee9bc9300e76a01acdb4cf1582e 100644 (file)
@@ -27,5 +27,6 @@ void SendToServer_ContinuePlaying(void);
 void SendToServer_StopPlaying(int);
 void SendToServer_MovePlayer(byte);
 void HandleNetworking(void);
+void DisconnectFromNetworkServer(void);
 
 #endif
index 54e27e311f8c4d0f086cb4a1e7207f2eaf291207..3ffcb48493dcb0b11ae1bd0b2196b08d2b2fc8c2 100644 (file)
@@ -6445,10 +6445,9 @@ static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
     ToggleFullscreenOrChangeWindowScalingIfNeeded();
 
   if (si->value == &setup.network_mode &&
-      setup.network_mode &&
-      !network.enabled)
+      setup.network_mode != network.enabled)
   {
-    network.enabled = TRUE;
+    network.enabled = setup.network_mode;
 
     SetGameStatus(GAME_MODE_LOADING);
     SetDrawBackgroundMask(REDRAW_NONE);
@@ -6459,7 +6458,10 @@ static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
 
     FadeIn(REDRAW_ALL);
 
-    InitNetworkServer();
+    if (network.enabled)
+      InitNetworkServer();
+    else
+      DisconnectFromNetworkServer();
 
     SetGameStatus(GAME_MODE_SETUP);
     SetDrawBackgroundMask(REDRAW_FIELD);