From: cloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Date: Sun, 9 Aug 2020 18:38:04 +0000 (+0000)
Subject: sv_ccmds: Perform actual name change from a single function. Announce in chat.
X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=65a2b532899676194b80a8c340fdc0155365c91e;p=xonotic%2Fdarkplaces.git

sv_ccmds: Perform actual name change from a single function. Announce in chat.

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12887 d7cf8633-e32d-0410-b094-e92efae38249
---

diff --git a/server.h b/server.h
index d8250f65..a8769f6e 100644
--- a/server.h
+++ b/server.h
@@ -610,7 +610,7 @@ void SV_StopThread(void);
 
 void VM_CustomStats_Clear(void);
 void VM_SV_UpdateCustomStats(client_t *client, prvm_edict_t *ent, sizebuf_t *msg, int *stats);
-
+void SV_Name(int clientnum);
 void SV_InitOperatorCommands(void);
 
 void SV_Savegame_to(prvm_prog_t *prog, const char *name);
diff --git a/sv_ccmds.c b/sv_ccmds.c
index ea24d859..51f3eb27 100644
--- a/sv_ccmds.c
+++ b/sv_ccmds.c
@@ -938,6 +938,23 @@ static void SV_Status_f(cmd_state_t *cmd)
 	}
 }
 
+void SV_Name(int clientnum)
+{
+	prvm_prog_t *prog = SVVM_prog;
+	PRVM_serveredictstring(host_client->edict, netname) = PRVM_SetEngineString(prog, host_client->name);
+	if (strcmp(host_client->old_name, host_client->name))
+	{
+		if (host_client->begun)
+			SV_BroadcastPrintf("\003%s ^7changed name to ^3%s\n", host_client->old_name, host_client->name);
+		strlcpy(host_client->old_name, host_client->name, sizeof(host_client->old_name));
+		// send notification to all clients
+		MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
+		MSG_WriteByte (&sv.reliable_datagram, clientnum);
+		MSG_WriteString (&sv.reliable_datagram, host_client->name);
+		SV_WriteNetnameIntoDemo(host_client);
+	}	
+}
+
 /*
 ======================
 SV_Name_f
@@ -945,7 +962,6 @@ SV_Name_f
 */
 static void SV_Name_f(cmd_state_t *cmd)
 {
-	prvm_prog_t *prog = SVVM_prog;
 	int i, j;
 	qboolean valid_colors;
 	const char *newNameSource;
@@ -1040,18 +1056,7 @@ static void SV_Name_f(cmd_state_t *cmd)
 	if (j >= 0 && strlen(host_client->name) < sizeof(host_client->name) - 2)
 		memcpy(host_client->name + strlen(host_client->name), STRING_COLOR_DEFAULT_STR, strlen(STRING_COLOR_DEFAULT_STR) + 1);
 
-	PRVM_serveredictstring(host_client->edict, netname) = PRVM_SetEngineString(prog, host_client->name);
-	if (strcmp(host_client->old_name, host_client->name))
-	{
-		if (host_client->begun)
-			SV_BroadcastPrintf("%s ^7changed name to %s\n", host_client->old_name, host_client->name);
-		strlcpy(host_client->old_name, host_client->name, sizeof(host_client->old_name));
-		// send notification to all clients
-		MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
-		MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
-		MSG_WriteString (&sv.reliable_datagram, host_client->name);
-		SV_WriteNetnameIntoDemo(host_client);
-	}
+	SV_Name(host_client - svs.clients);
 }
 
 static void SV_Rate_f(cmd_state_t *cmd)
diff --git a/sv_main.c b/sv_main.c
index c6a2c3b6..18a2f41c 100644
--- a/sv_main.c
+++ b/sv_main.c
@@ -2648,18 +2648,7 @@ static void SV_UpdateToReliableMessages (void)
 		//strlcpy (host_client->name, name, sizeof (host_client->name));
 		if (name != host_client->name) // prevent buffer overlap SIGABRT on Mac OSX
 			strlcpy (host_client->name, name, sizeof (host_client->name));
-		PRVM_serveredictstring(host_client->edict, netname) = PRVM_SetEngineString(prog, host_client->name);
-		if (strcmp(host_client->old_name, host_client->name))
-		{
-			if (host_client->begun)
-				SV_BroadcastPrintf("%s ^7changed name to %s\n", host_client->old_name, host_client->name);
-			strlcpy(host_client->old_name, host_client->name, sizeof(host_client->old_name));
-			// send notification to all clients
-			MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
-			MSG_WriteByte (&sv.reliable_datagram, i);
-			MSG_WriteString (&sv.reliable_datagram, host_client->name);
-			SV_WriteNetnameIntoDemo(host_client);
-		}
+		SV_Name(i);
 
 		// DP_SV_CLIENTCOLORS
 		host_client->colors = (int)PRVM_serveredictfloat(host_client->edict, clientcolors);