From 052e67c541a2a68451a7a8007bb022593f80f23c Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Wed, 7 Mar 2018 17:22:41 +0100 Subject: [PATCH 1/5] Add broadcast importance (fixes #669) --- src/game/server/entities/character.cpp | 2 +- src/game/server/gamecontext.cpp | 26 +++++++++++++++++++++++++- src/game/server/gamecontext.h | 2 +- src/game/server/player.h | 2 ++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 8a9a928db..bbeb0562f 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -1221,7 +1221,7 @@ void CCharacter::HandleBroadcast() char aBuftime[64]; int IntTime = (int)((float)(Server()->Tick() - m_StartTime) / ((float)Server()->TickSpeed())); str_format(aBuftime, sizeof(aBuftime), "%s%d:%s%d", ((IntTime/60) > 9)?"":"0", IntTime/60, ((IntTime%60) > 9)?"":"0", IntTime%60); - GameServer()->SendBroadcast(aBuftime, m_pPlayer->GetCID()); + GameServer()->SendBroadcast(aBuftime, m_pPlayer->GetCID(), false); m_CpLastBroadcast = m_CpActive; m_LastBroadcast = Server()->Tick(); } diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index d3a8d3efb..52108488c 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -398,11 +398,35 @@ void CGameContext::SendWeaponPickup(int ClientID, int Weapon) } -void CGameContext::SendBroadcast(const char *pText, int ClientID) +void CGameContext::SendBroadcast(const char *pText, int ClientID, bool IsImportant) { CNetMsg_Sv_Broadcast Msg; Msg.m_pMessage = pText; + + if (ClientID == -1) + { + Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientID); + + for (int i = 0; i < MAX_CLIENTS; i++) + { + if (m_apPlayers[i]) + { + m_apPlayers[i]->m_LastBroadcastImportance = true; + m_apPlayers[i]->m_LastBroadcast = Server()->Tick(); + } + } + return; + } + + if (!m_apPlayers[ClientID]) + return; + + if (!IsImportant && m_apPlayers[ClientID]->m_LastBroadcastImportance && m_apPlayers[ClientID]->m_LastBroadcast > Server()->Tick() - Server()->TickSpeed() * 6) + return; + Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientID); + m_apPlayers[ClientID]->m_LastBroadcast = Server()->Tick(); + m_apPlayers[ClientID]->m_LastBroadcastImportance = IsImportant; } void CGameContext::StartVote(const char *pDesc, const char *pCommand, const char *pReason) diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index 724d94f98..54269fe1e 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -191,7 +191,7 @@ public: void SendChat(int ClientID, int Team, const char *pText, int SpamProtectionClientID = -1); void SendEmoticon(int ClientID, int Emoticon); void SendWeaponPickup(int ClientID, int Weapon); - void SendBroadcast(const char *pText, int ClientID); + void SendBroadcast(const char *pText, int ClientID, bool IsImportant = true); void List(int ClientID, const char* filter); diff --git a/src/game/server/player.h b/src/game/server/player.h index b36e91da4..e3b453370 100644 --- a/src/game/server/player.h +++ b/src/game/server/player.h @@ -181,6 +181,8 @@ public: void AfkVoteTimer(CNetObj_PlayerInput *NewTarget); int64 m_LastPlaytime; int64 m_LastEyeEmote; + int64 m_LastBroadcast; + bool m_LastBroadcastImportance; int m_LastTarget_x; int m_LastTarget_y; CNetObj_PlayerInput m_LastTarget; From ab2876743afa93b7de3a06029ea8e3d9e888fe86 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Wed, 7 Mar 2018 18:06:39 +0100 Subject: [PATCH 2/5] Make broadcast importance delay configurable --- src/engine/shared/config_variables.h | 1 + src/game/server/gamecontext.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index d9b862ef0..659e1f944 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -187,6 +187,7 @@ MACRO_CONFIG_INT(SvHit, sv_hit, 1, 0, 1, CFGFLAG_SERVER|CFGFLAG_GAME, "Whether p MACRO_CONFIG_INT(SvEndlessDrag, sv_endless_drag, 0, 0, 1, CFGFLAG_SERVER|CFGFLAG_GAME, "Turns endless hooking on/off") MACRO_CONFIG_INT(SvTestingCommands, sv_test_cmds, 0, 0, 1, CFGFLAG_SERVER, "Turns testing commands aka cheats on/off") MACRO_CONFIG_INT(SvFreezeDelay, sv_freeze_delay, 3, 1, 30, CFGFLAG_SERVER|CFGFLAG_GAME, "How many seconds the players will remain frozen (applies to all except delayed freeze in switch layer & deepfreeze)") +MACRO_CONFIG_INT(SvBroadcastDelay, sv_broadcast_delay, 6, 1, 180, CFGFLAG_SERVER, "How many seconds unimportant broadcasts won't overwrite important ones") MACRO_CONFIG_INT(ClDDRaceBinds, cl_race_binds, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Enable Default DDRace builds when pressing the reset binds button") MACRO_CONFIG_INT(ClDDRaceBindsSet, cl_race_binds_set, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Whether the DDRace binds set or not (this is automated you don't need to use this)") MACRO_CONFIG_INT(SvEndlessSuperHook, sv_endless_super_hook, 0, 0, 1, CFGFLAG_SERVER, "Endless hook for super players on/off") diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 52108488c..c411dda59 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -421,7 +421,7 @@ void CGameContext::SendBroadcast(const char *pText, int ClientID, bool IsImporta if (!m_apPlayers[ClientID]) return; - if (!IsImportant && m_apPlayers[ClientID]->m_LastBroadcastImportance && m_apPlayers[ClientID]->m_LastBroadcast > Server()->Tick() - Server()->TickSpeed() * 6) + if (!IsImportant && m_apPlayers[ClientID]->m_LastBroadcastImportance && m_apPlayers[ClientID]->m_LastBroadcast > Server()->Tick() - Server()->TickSpeed() * g_Config.m_SvBroadcastDelay) return; Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientID); From 8d1e60d5a659b94ccf35d913e571c6299f9277ca Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Wed, 7 Mar 2018 18:10:57 +0100 Subject: [PATCH 3/5] Fix code style --- src/game/server/gamecontext.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index c411dda59..574c58651 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -403,13 +403,13 @@ void CGameContext::SendBroadcast(const char *pText, int ClientID, bool IsImporta CNetMsg_Sv_Broadcast Msg; Msg.m_pMessage = pText; - if (ClientID == -1) + if(ClientID == -1) { Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientID); - for (int i = 0; i < MAX_CLIENTS; i++) + for(int i = 0; i < MAX_CLIENTS; i++) { - if (m_apPlayers[i]) + if(m_apPlayers[i]) { m_apPlayers[i]->m_LastBroadcastImportance = true; m_apPlayers[i]->m_LastBroadcast = Server()->Tick(); @@ -418,10 +418,10 @@ void CGameContext::SendBroadcast(const char *pText, int ClientID, bool IsImporta return; } - if (!m_apPlayers[ClientID]) + if(!m_apPlayers[ClientID]) return; - if (!IsImportant && m_apPlayers[ClientID]->m_LastBroadcastImportance && m_apPlayers[ClientID]->m_LastBroadcast > Server()->Tick() - Server()->TickSpeed() * g_Config.m_SvBroadcastDelay) + if(!IsImportant && m_apPlayers[ClientID]->m_LastBroadcastImportance && m_apPlayers[ClientID]->m_LastBroadcast > Server()->Tick() - Server()->TickSpeed() * g_Config.m_SvBroadcastDelay) return; Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientID); From cc70628a49c6878871202570a5240c5d59d72b78 Mon Sep 17 00:00:00 2001 From: Chiller Dragon Date: Thu, 15 Mar 2018 22:35:25 +0100 Subject: [PATCH 4/5] Static broadcast delay (10 sec) --- src/engine/shared/config_variables.h | 1 - src/game/server/gamecontext.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index 659e1f944..d9b862ef0 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -187,7 +187,6 @@ MACRO_CONFIG_INT(SvHit, sv_hit, 1, 0, 1, CFGFLAG_SERVER|CFGFLAG_GAME, "Whether p MACRO_CONFIG_INT(SvEndlessDrag, sv_endless_drag, 0, 0, 1, CFGFLAG_SERVER|CFGFLAG_GAME, "Turns endless hooking on/off") MACRO_CONFIG_INT(SvTestingCommands, sv_test_cmds, 0, 0, 1, CFGFLAG_SERVER, "Turns testing commands aka cheats on/off") MACRO_CONFIG_INT(SvFreezeDelay, sv_freeze_delay, 3, 1, 30, CFGFLAG_SERVER|CFGFLAG_GAME, "How many seconds the players will remain frozen (applies to all except delayed freeze in switch layer & deepfreeze)") -MACRO_CONFIG_INT(SvBroadcastDelay, sv_broadcast_delay, 6, 1, 180, CFGFLAG_SERVER, "How many seconds unimportant broadcasts won't overwrite important ones") MACRO_CONFIG_INT(ClDDRaceBinds, cl_race_binds, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Enable Default DDRace builds when pressing the reset binds button") MACRO_CONFIG_INT(ClDDRaceBindsSet, cl_race_binds_set, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Whether the DDRace binds set or not (this is automated you don't need to use this)") MACRO_CONFIG_INT(SvEndlessSuperHook, sv_endless_super_hook, 0, 0, 1, CFGFLAG_SERVER, "Endless hook for super players on/off") diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 574c58651..e8cb465b9 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -421,7 +421,7 @@ void CGameContext::SendBroadcast(const char *pText, int ClientID, bool IsImporta if(!m_apPlayers[ClientID]) return; - if(!IsImportant && m_apPlayers[ClientID]->m_LastBroadcastImportance && m_apPlayers[ClientID]->m_LastBroadcast > Server()->Tick() - Server()->TickSpeed() * g_Config.m_SvBroadcastDelay) + if(!IsImportant && m_apPlayers[ClientID]->m_LastBroadcastImportance && m_apPlayers[ClientID]->m_LastBroadcast > Server()->Tick() - Server()->TickSpeed() * 10) return; Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientID); From 74ecdea3ab760e40a343c3f9f213ebe8e7861bd8 Mon Sep 17 00:00:00 2001 From: Chiller Dragon Date: Fri, 16 Mar 2018 13:30:47 +0100 Subject: [PATCH 5/5] Add assert on unimportant broadcasts to all players --- src/game/server/gamecontext.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index e8cb465b9..649292157 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -405,6 +405,7 @@ void CGameContext::SendBroadcast(const char *pText, int ClientID, bool IsImporta if(ClientID == -1) { + dbg_assert(IsImportant, "broadcast messages to all players must be important"); Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientID); for(int i = 0; i < MAX_CLIENTS; i++)