From 562d6c66f2f0b7a576145741b4cc4bd5b4d9fc65 Mon Sep 17 00:00:00 2001 From: Nils Brederlow <62596379+dingodoppelt@users.noreply.github.com> Date: Wed, 17 Jun 2026 16:56:39 +0200 Subject: [PATCH 1/4] Refactor server chat handling by extracting methods. Added range check method to MathUtils --- src/server.cpp | 21 ++++++++++++++++----- src/server.h | 3 +++ src/util.h | 7 +++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/server.cpp b/src/server.cpp index 67274965bc..6647c2cef5 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1297,14 +1297,25 @@ void CServer::CreateAndSendChatTextForAllConChannels ( const int iCurChanID, con const QString strActualMessageText = "(" + QTime::currentTime().toString ( "hh:mm:ss AP" ) + ") " + ChanName.toHtmlEscaped() + " " + strChatText.toHtmlEscaped(); + // Send chat text to all connected clients --------------------------------- + SendChatTextToAllConChannels ( strActualMessageText ); +} + +void CServer::SendChatTextToAllConChannels ( const QString& strChatText ) +{ // Send chat text to all connected clients --------------------------------- for ( int i = 0; i < iMaxNumChannels; i++ ) { - if ( vecChannels[i].IsConnected() ) - { - // send message - vecChannels[i].CreateChatTextMes ( strActualMessageText ); - } + SendChatTextToConChannel ( i, strChatText ); + } +} + +void CServer::SendChatTextToConChannel ( const int iCurChanID, const QString& strChatText ) +{ + if ( MathUtils::InRange ( iCurChanID, 0, iMaxNumChannels - 1 ) && vecChannels[iCurChanID].IsConnected() ) + { + // send message + vecChannels[iCurChanID].CreateChatTextMes ( strChatText ); } } diff --git a/src/server.h b/src/server.h index 2e6b13e835..4f1c4a3805 100644 --- a/src/server.h +++ b/src/server.h @@ -191,6 +191,9 @@ class CServer : public QObject, public CServerSlots void SetEnableDelayPanning ( bool bDelayPanningOn ) { bDelayPan = bDelayPanningOn; } bool IsDelayPanningEnabled() { return bDelayPan; } + void SendChatTextToAllConChannels ( const QString& strChatText ); + void SendChatTextToConChannel ( const int iCurChanID, const QString& strChatText ); + protected: // access functions for actual channels bool IsConnected ( const int iChanNum ) { return vecChannels[iChanNum].IsConnected(); } diff --git a/src/util.h b/src/util.h index 563fbb58ef..d62c3a0c38 100644 --- a/src/util.h +++ b/src/util.h @@ -1223,6 +1223,13 @@ class MathUtils return powf ( 10.0f, ( fInValueRange0_1 - 1.0f ) * AUD_MIX_FADER_RANGE_DB / 20.0f ); } } + + // return true if a value is inside a given range, otherwise false + template + static inline bool InRange ( T value, T lower, T upper ) + { + return !( value < lower || value > upper ); + } }; /******************************************************************************\ From 16b1ade00b40af81338d91d7d7284b594e4c3687 Mon Sep 17 00:00:00 2001 From: Nils Brederlow <62596379+dingodoppelt@users.noreply.github.com> Date: Thu, 18 Jun 2026 19:54:38 +0200 Subject: [PATCH 2/4] Remove overhead Co-authored-by: Peter L Jones --- src/server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server.cpp b/src/server.cpp index 6647c2cef5..1ebcc65999 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1306,7 +1306,7 @@ void CServer::SendChatTextToAllConChannels ( const QString& strChatText ) // Send chat text to all connected clients --------------------------------- for ( int i = 0; i < iMaxNumChannels; i++ ) { - SendChatTextToConChannel ( i, strChatText ); + if ( vecChannels[i].IsConnected() ) vecChannels[i].CreateChatTextMes ( strChatText ); } } From 4f9a532a07923fd52c1b3451d20d06c8fad6fa15 Mon Sep 17 00:00:00 2001 From: Nils Brederlow <62596379+dingodoppelt@users.noreply.github.com> Date: Thu, 18 Jun 2026 19:59:49 +0200 Subject: [PATCH 3/4] Clarify comment Co-authored-by: Peter L Jones --- src/util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.h b/src/util.h index d62c3a0c38..0b9169f265 100644 --- a/src/util.h +++ b/src/util.h @@ -1224,7 +1224,7 @@ class MathUtils } } - // return true if a value is inside a given range, otherwise false + // return true if a value is within the lower and upper bounds (inclusively), otherwise false template static inline bool InRange ( T value, T lower, T upper ) { From 1e1f54ab90c566dbda461cf40c4915e5680d7da1 Mon Sep 17 00:00:00 2001 From: Nils Brederlow <62596379+dingodoppelt@users.noreply.github.com> Date: Thu, 18 Jun 2026 20:01:35 +0200 Subject: [PATCH 4/4] fix style --- src/server.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/server.cpp b/src/server.cpp index 1ebcc65999..c32f737a75 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1306,7 +1306,10 @@ void CServer::SendChatTextToAllConChannels ( const QString& strChatText ) // Send chat text to all connected clients --------------------------------- for ( int i = 0; i < iMaxNumChannels; i++ ) { - if ( vecChannels[i].IsConnected() ) vecChannels[i].CreateChatTextMes ( strChatText ); + if ( vecChannels[i].IsConnected() ) + { + vecChannels[i].CreateChatTextMes ( strChatText ); + } } }