shithub: choc

Download patch

ref: 67fae2be49cb9203de5b952ab8b17a37db800c15
parent: df5be3d8c12bda4f22a8500240765fefe5ccf21c
author: Simon Howard <[email protected]>
date: Sat Apr 12 13:02:20 EDT 2014

net: Add -nodes command line argument.

This matches the -nodes parameter that ipxsetup has; interpret it as
an "auto-start" parameter that launches the game when the intended
number of clients have joined the server.

--- a/src/net_gui.c
+++ b/src/net_gui.c
@@ -34,6 +34,7 @@
 #include "i_system.h"
 #include "i_timer.h"
 #include "i_video.h"
+#include "m_argv.h"
 #include "m_misc.h"
 
 #include "net_client.h"
@@ -51,6 +52,11 @@
 static txt_label_t *master_msg_label;
 static boolean had_warning;
 
+// Number of players we expect to be in the game. When the number is
+// reached, we auto-start the game (if we're the controller). If
+// zero, do not autostart.
+static int expected_nodes;
+
 static void EscapePressed(TXT_UNCAST_ARG(widget), void *unused)
 {
     TXT_Shutdown();
@@ -343,6 +349,43 @@
     had_warning = true;
 }
 
+static void ParseCommandLineArgs(void)
+{
+    int i;
+
+    //!
+    // @arg <n>
+    // @category net
+    //
+    // Autostart the netgame when n nodes (clients) have joined the server.
+    //
+
+    i = M_CheckParmWithArgs("-nodes", 1);
+    if (i > 0)
+    {
+        expected_nodes = atoi(myargv[i + 1]);
+    }
+}
+
+static void CheckAutoLaunch(void)
+{
+    int nodes;
+
+    if (net_client_received_wait_data
+     && net_client_wait_data.is_controller
+     && expected_nodes > 0)
+    {
+        nodes = net_client_wait_data.num_players
+              + net_client_wait_data.num_drones;
+
+        if (nodes >= expected_nodes)
+        {
+            StartGame(NULL, NULL);
+            expected_nodes = 0;
+        }
+    }
+}
+
 void NET_WaitForLaunch(void)
 {
     if (!TXT_Init())
@@ -353,6 +396,7 @@
 
     I_InitWindowIcon();
 
+    ParseCommandLineArgs();
     OpenWaitDialog();
     had_warning = false;
 
@@ -359,6 +403,7 @@
     while (net_waiting_for_launch)
     {
         UpdateGUI();
+        CheckAutoLaunch();
         CheckSHA1Sums();
         CheckMasterStatus();