added handling SIGINT (Ctrl-C) to exit standalone network server
authorHolger Schemel <info@artsoft.org>
Thu, 31 May 2018 11:04:13 +0000 (13:04 +0200)
committerHolger Schemel <info@artsoft.org>
Mon, 18 Jun 2018 17:47:31 +0000 (19:47 +0200)
src/netserv.c

index 6555e0497922502843b7ef909c34cfc69be28bf1..71b23c959b0587ce5ce4231cfd8259d1165c3134 100644 (file)
@@ -433,6 +433,13 @@ static void Handle_OP_MOVE_PLAYER(struct NetworkServerPlayerInfo *player)
   ServerFrameCounter++;
 }
 
+void ExitNetworkServer(int exit_value)
+{
+  Error(ERR_NETWORK_SERVER, "exiting network server");
+
+  exit(exit_value);
+}
+
 /* the following is not used for a standalone server;
    the pointer points to an integer containing the port-number */
 int NetworkServerThread(void *ptr)
@@ -458,6 +465,10 @@ void NetworkServer(int port, int serveronly)
   if (port == 0)
     port = DEFAULT_SERVER_PORT;
 
+  // if only running the network server, exit on Ctrl-C
+  if (serveronly)
+    signal(SIGINT, ExitNetworkServer);
+
   if (!serveronly)
     onceonly = 1;