From 7068a70da24de358985f0101233b6701345ef022 Mon Sep 17 00:00:00 2001
From: z411 <z411@omaera.org>
Date: Fri, 16 Oct 2020 17:08:55 -0300
Subject: [PATCH] Fixed sound disabling and medal screening

---
 qcsrc/client/hud/panel/centerprint.qc |  2 +-
 qcsrc/client/main.qc                  | 11 +++++++++++
 qcsrc/common/net_linked.qh            |  1 +
 qcsrc/server/client.qc                | 24 ++++++------------------
 qcsrc/server/command/common.qc        |  2 +-
 5 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/qcsrc/client/hud/panel/centerprint.qc b/qcsrc/client/hud/panel/centerprint.qc
index a5c557a708..971391c685 100644
--- a/qcsrc/client/hud/panel/centerprint.qc
+++ b/qcsrc/client/hud/panel/centerprint.qc
@@ -288,7 +288,7 @@ void HUD_CenterPrint()
 		
 		tmp_in.x += (panel_size.x - newsize.x) / 2; // center medal icon
 		
-		if(centerprint_medal_times <= MSG_MEDAL_SCREEN) {
+		if(centerprint_medal_times < MSG_MEDAL_SCREEN) {
 			tmp_in.x -= ((newsize.x * 1.1) * (centerprint_medal_times - 1) / 2);
 			for(int t = 0; t < centerprint_medal_times; t++) {
 				drawpic(tmp_in, centerprint_medal_icon, newsize, '1 1 1', a, DRAWFLAG_NORMAL);
diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc
index f81bfc1a4e..947ae18b02 100644
--- a/qcsrc/client/main.qc
+++ b/qcsrc/client/main.qc
@@ -957,6 +957,17 @@ NET_HANDLE(TE_CSQC_TEAMNAMES, bool isNew)
 	return = true;
 }
 
+NET_HANDLE(TE_CSQC_CHATSOUND, bool isNew)
+{
+	string snd = ReadString();
+	snd = strcat("chat/", snd, ".ogg");
+	
+	precache_sound(snd);
+	_sound(NULL, CH_INFO, snd, VOL_BASE, ATTN_NONE);
+
+	return = true;
+}
+
 float GetSpeedUnitFactor(int speed_unit)
 {
 	switch(speed_unit)
diff --git a/qcsrc/common/net_linked.qh b/qcsrc/common/net_linked.qh
index 125c01f961..c431c601d8 100644
--- a/qcsrc/common/net_linked.qh
+++ b/qcsrc/common/net_linked.qh
@@ -8,6 +8,7 @@ REGISTER_NET_TEMP(TE_CSQC_WEAPONCOMPLAIN)
 REGISTER_NET_TEMP(TE_CSQC_VEHICLESETUP)
 
 REGISTER_NET_TEMP(TE_CSQC_TEAMNAMES)
+REGISTER_NET_TEMP(TE_CSQC_CHATSOUND)
 
 const int RACE_NET_CHECKPOINT_HIT_QUALIFYING = 0; // byte checkpoint, short time, short recordtime, string recordholder
 const int RACE_NET_CHECKPOINT_CLEAR = 1;
diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc
index 2aaab0fb75..70ff57e3f7 100644
--- a/qcsrc/server/client.qc
+++ b/qcsrc/server/client.qc
@@ -3219,9 +3219,7 @@ int Say(entity source, int teamsay, entity privatesay, string msgin, bool floodc
 
 bool play_chatsound(entity source, string msgin)
 {
-	//bprintf("Source (%s) has cl_chat_sounds = %d\n", source.netname, CS(source).cvar_cl_chat_sounds);
-	//if(autocvar_sv_chat_sounds && CS(source).cvar_cl_chat_sounds) {
-	if(autocvar_sv_chat_sounds) {
+	if(autocvar_sv_chat_sounds && CS(source).cvar_cl_chat_sounds) {
 		var .float flood_sound = floodcontrol_chatsound;
 		
 		if (source.(flood_sound) < time - autocvar_sv_chat_sounds_flood) {
@@ -3229,21 +3227,11 @@ bool play_chatsound(entity source, string msgin)
 			rawmsg = strreplace("\n", " ", msgin);
 			
 			if (findinlist_abbrev(rawmsg, autocvar_sv_chat_sounds_list)) {
-				string sndname = strcat("sound/chat/", rawmsg, ".ogg");
-				
-				/*FOREACH_CLIENT(true, {
-					if(IS_REAL_CLIENT(it)) {
-						bprintf("Destination (%s) has cl_chat_sounds = %d\n", it.netname, CS(it).cvar_cl_chat_sounds);
-						if(CS(it).cvar_cl_chat_sounds) {
-							precache_sound(sndname);
-							play2(it, sndname);
-						}
-					} else {
-						bprintf("Destination (%s) has cl_chat_sounds = %d but it's not a real client\n", it.netname, CS(it).cvar_cl_chat_sounds);
-					}
-				});*/
-				play2all(sndname);
-				
+				FOREACH_CLIENT(IS_REAL_CLIENT(it) && CS(it).cvar_cl_chat_sounds, {
+					msg_entity = it;
+					WriteHeader(MSG_ONE, TE_CSQC_CHATSOUND);
+					WriteString(MSG_ONE, rawmsg);
+				});
 				source.(flood_sound) = time;
 				return true;
 			}
diff --git a/qcsrc/server/command/common.qc b/qcsrc/server/command/common.qc
index 94ea014e9f..981e792062 100644
--- a/qcsrc/server/command/common.qc
+++ b/qcsrc/server/command/common.qc
@@ -238,7 +238,7 @@ void timeout_handler_think(entity this)
 				if(round_handler && round_handler_GetEndTime() > 0)
 					round_handler.round_endtime += total_time;
 					
-				LOG_INFOF("timeout lasted %d secs", total_time);
+				LOG_INFOF("Timeout lasted %d secs", total_time);
 
 				// unlock the view for players so they can move around again
 				FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
-- 
2.39.5