From aa18d5c3ffebab326f21db8a360e8b8f674c48bc Mon Sep 17 00:00:00 2001
From: LJ Sonic <lamr@free.fr>
Date: Sat, 14 Jan 2023 14:53:27 +0100
Subject: [PATCH] Move net command sending to a new function

---
 src/netcode/net_command.c | 22 ++++++++++++++++++++++
 src/netcode/net_command.h |  1 +
 src/netcode/tic_command.c | 22 +---------------------
 3 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/src/netcode/net_command.c b/src/netcode/net_command.c
index 227b78660..9e089a1a2 100644
--- a/src/netcode/net_command.c
+++ b/src/netcode/net_command.c
@@ -324,6 +324,28 @@ void SV_CopyNetCommandsToServerPacket(tic_t tic)
 }
 
 void CL_SendNetCommands(void)
+{
+	// Send extra data if needed
+	if (localtextcmd[0])
+	{
+		netbuffer->packettype = PT_TEXTCMD;
+		M_Memcpy(netbuffer->u.textcmd,localtextcmd, localtextcmd[0]+1);
+		// All extra data have been sent
+		if (HSendPacket(servernode, true, 0, localtextcmd[0]+1)) // Send can fail...
+			localtextcmd[0] = 0;
+	}
+
+	// Send extra data if needed for player 2 (splitscreen)
+	if (localtextcmd2[0])
+	{
+		netbuffer->packettype = PT_TEXTCMD2;
+		M_Memcpy(netbuffer->u.textcmd, localtextcmd2, localtextcmd2[0]+1);
+		// All extra data have been sent
+		if (HSendPacket(servernode, true, 0, localtextcmd2[0]+1)) // Send can fail...
+			localtextcmd2[0] = 0;
+	}
+}
+
 void SendKick(UINT8 playernum, UINT8 msg)
 {
 	UINT8 buf[2];
diff --git a/src/netcode/net_command.h b/src/netcode/net_command.h
index a9447ed7a..3a433ebe4 100644
--- a/src/netcode/net_command.h
+++ b/src/netcode/net_command.h
@@ -58,6 +58,7 @@ size_t TotalTextCmdPerTic(tic_t tic);
 
 void PT_TextCmd(SINT8 node, INT32 netconsole);
 void SV_CopyNetCommandsToServerPacket(tic_t tic);
+void CL_SendNetCommands(void);
 void SendKick(UINT8 playernum, UINT8 msg);
 void SendKicksForNode(SINT8 node, UINT8 msg);
 
diff --git a/src/netcode/tic_command.c b/src/netcode/tic_command.c
index 2eb3b10ac..76d46451f 100644
--- a/src/netcode/tic_command.c
+++ b/src/netcode/tic_command.c
@@ -295,27 +295,7 @@ void CL_SendClientCmd(void)
 	}
 
 	if (cl_mode == CL_CONNECTED || dedicated)
-	{
-		// Send extra data if needed
-		if (localtextcmd[0])
-		{
-			netbuffer->packettype = PT_TEXTCMD;
-			M_Memcpy(netbuffer->u.textcmd,localtextcmd, localtextcmd[0]+1);
-			// All extra data have been sent
-			if (HSendPacket(servernode, true, 0, localtextcmd[0]+1)) // Send can fail...
-				localtextcmd[0] = 0;
-		}
-
-		// Send extra data if needed for player 2 (splitscreen)
-		if (localtextcmd2[0])
-		{
-			netbuffer->packettype = PT_TEXTCMD2;
-			M_Memcpy(netbuffer->u.textcmd, localtextcmd2, localtextcmd2[0]+1);
-			// All extra data have been sent
-			if (HSendPacket(servernode, true, 0, localtextcmd2[0]+1)) // Send can fail...
-				localtextcmd2[0] = 0;
-		}
-	}
+		CL_SendNetCommands();
 }
 
 // send the server packet
-- 
GitLab