From 1816dafbe3849eb03669911369339c18fa68b6fd Mon Sep 17 00:00:00 2001
From: yellowtd <ren_amon@hotmail.com>
Date: Sat, 5 Mar 2016 22:28:33 -0500
Subject: [PATCH] add sub function connect: HOST

Start a server using connect command
---
 src/d_clisrv.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++--
 src/m_menu.c   |  3 +-
 src/m_menu.h   |  2 ++
 3 files changed, 76 insertions(+), 4 deletions(-)

diff --git a/src/d_clisrv.c b/src/d_clisrv.c
index c0179ca1be..d294312268 100644
--- a/src/d_clisrv.c
+++ b/src/d_clisrv.c
@@ -2112,7 +2112,8 @@ static void Command_connect(void)
 		CONS_Printf(M_GetText(
 			"Connect <serveraddress> (port): connect to a server\n"
 			"Connect ANY: connect to the first lan server found\n"
-			"Connect SELF: connect to your own server.\n"));
+			"Connect SELF: connect to your own server.\n"
+			"Connect HOST <map> <gametype>: "));
 		return;
 	}
 
@@ -2127,7 +2128,77 @@ static void Command_connect(void)
 
 	server = false;
 
-	if (!stricmp(COM_Argv(1), "self"))
+    // RedEnchilada: host a game from connect
+    if (!stricmp(COM_Argv(1), "HOST"))
+	{
+	    const char *mapname;
+	    INT32 newmapnum;
+
+	    INT32 j, newgametype = INT32_MAX;
+
+	    if (COM_Argc() != 4)
+        {
+            CONS_Printf("Command must be of form \"Connect"
+                        " HOST <MAPxx> <gametype>\".\n");
+            return;
+        }
+
+	    // Get map number from name
+	    mapname = COM_Argv(2);
+
+	    // internal wad lump always: map command doesn't support external files as in doom legacy
+        if (W_CheckNumForName(mapname) == LUMPERROR)
+        {
+            CONS_Alert(CONS_ERROR, M_GetText("Internal game level '%s' not found\n"), mapname);
+            return;
+        }
+
+        if (strlen(mapname) != 5
+        || (newmapnum = M_MapNumber(mapname[3], mapname[4])) == 0)
+        {
+            CONS_Alert(CONS_ERROR, M_GetText("Invalid level name %s\n"), mapname);
+            return;
+        }
+
+        // Get gametype
+        for (j = 0; gametype_cons_t[j].strvalue; j++)
+			if (!strcasecmp(gametype_cons_t[j].strvalue, COM_Argv(3)))
+			{
+				// Don't do any variable setting here. Wait until you get your
+				// map packet first to avoid sending the same info twice!
+				newgametype = gametype_cons_t[j].value;
+
+				break;
+			}
+
+		if (!gametype_cons_t[j].strvalue) // reached end of the list with no match
+		{
+			// assume they gave us a gametype number, which is okay too
+			for (j = 0; gametype_cons_t[j].strvalue != NULL; j++)
+			{
+				if (atoi(COM_Argv(3)) == gametype_cons_t[j].value)
+				{
+					newgametype = gametype_cons_t[j].value;
+					break;
+				}
+			}
+		}
+
+		if (gametype == INT32_MAX)
+        {
+            CONS_Alert(CONS_ERROR, M_GetText("Invalid gametype %s\n"), COM_Argv(3));
+            return;
+        }
+
+        // Goodbye, we're off to host a server
+        CV_SetValue(&cv_nextmap, newmapnum);
+        CV_SetValue(&cv_newgametype, newgametype);
+        server = true;
+        M_StartServer(0);
+
+        return;
+	}
+	else if (!stricmp(COM_Argv(1), "self"))
 	{
 		servernode = 0;
 		server = true;
diff --git a/src/m_menu.c b/src/m_menu.c
index c7a9fcc162..f3c994c591 100644
--- a/src/m_menu.c
+++ b/src/m_menu.c
@@ -260,7 +260,6 @@ static void M_ConnectMenu(INT32 choice);
 static void M_ConnectIPMenu(INT32 choice);
 #endif
 static void M_StartSplitServerMenu(INT32 choice);
-static void M_StartServer(INT32 choice);
 #ifndef NONET
 static void M_Refresh(INT32 choice);
 static void M_Connect(INT32 choice);
@@ -6123,7 +6122,7 @@ static INT32 M_FindFirstMap(INT32 gtype)
 	return 1;
 }
 
-static void M_StartServer(INT32 choice)
+void M_StartServer(INT32 choice)
 {
 	boolean StartSplitScreenGame = (currentMenu == &MP_SplitServerDef);
 
diff --git a/src/m_menu.h b/src/m_menu.h
index ccb1c11025..05e71d7022 100644
--- a/src/m_menu.h
+++ b/src/m_menu.h
@@ -296,4 +296,6 @@ void Screenshot_option_Onchange(void);
 	NULL\
 }
 
+void M_StartServer(INT32 choice);
+
 #endif //__X_MENU__
-- 
GitLab