Skip to content

Refactor server chat handling by extracting methods#3741

Open
dingodoppelt wants to merge 4 commits into
jamulussoftware:mainfrom
dingodoppelt:refactor_chat
Open

Refactor server chat handling by extracting methods#3741
dingodoppelt wants to merge 4 commits into
jamulussoftware:mainfrom
dingodoppelt:refactor_chat

Conversation

@dingodoppelt

@dingodoppelt dingodoppelt commented Jun 17, 2026

Copy link
Copy Markdown
Member

Short description of changes

This refactors CServer::CreateAndSendChatTextForAllConChannels into three functions for sending messages.
The extracted methods

  1. create the full chat message including timestamp and name of the sending client,
  2. iterate over all possible channel numbers to
  3. send the message text to a channel

As it is now possible to call the function to send a message to a channel directly, the channel number needs to be boundary checked.
A function InRange() was introduced into util.h for that purpose.

CHANGELOG: Refactor server chat handling by extracting methods

Context: Fixes an issue?

Not yet ;)

Does this change need documentation? What needs to be documented and how?
No

Status of this Pull Request

Ready for review
What is missing until this pull request can be merged?

Review, Approval

Checklist

  • I've verified that this Pull Request follows the general code principles
  • I tested my code and it does what I want
  • My code follows the style guide
  • I waited some time after this Pull Request was opened and all GitHub checks completed without errors.
  • I've filled all the content above

Comment thread src/util.h
Comment thread src/util.h

// return true if a value is inside a given range, otherwise false
template<typename T>
static inline bool InRange ( T value, T lower, T upper )

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Java/C# programmer in me wants this as an extension to Comparable<T>, so that

(<Comparable<Int>>32).inRange(0, 100)

returns true. Don't know if C++ can do better than what you've got here, though. (What you should do is constraint T somehow, really.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know if C++ can do better than what you've got here, though. (What you should do is constraint T somehow, really.)

This function cannot be called from the outside so I think we should be safe here.
The first placed I searched for range validating functions was the Jamulus source code, then Qt docs because I thought there must be something there. Then I wrote this :) If we don't need it and it might cause issues I'm happy to remove it and do the sanity checks locally.

Comment thread src/util.h Outdated
Comment thread src/server.cpp Outdated
dingodoppelt and others added 3 commits June 18, 2026 19:54
Co-authored-by: Peter L Jones <pljones@users.noreply.github.com>
Co-authored-by: Peter L Jones <pljones@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring Non-behavioural changes, Code cleanup

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants