Skip to content

refactor(network): Clean up utility functions for network commands#2725

Open
Caball009 wants to merge 5 commits into
TheSuperHackers:mainfrom
Caball009:refactor_network_if_else_chains
Open

refactor(network): Clean up utility functions for network commands#2725
Caball009 wants to merge 5 commits into
TheSuperHackers:mainfrom
Caball009:refactor_network_if_else_chains

Conversation

@Caball009
Copy link
Copy Markdown

@Caball009 Caball009 commented May 17, 2026

This PR cleans up some utility functions in the network code, mainly by refactoring them from if/else chains to switch statements. No change should have a functional difference (with the exception of a removed debug assertion).

See commits for cleaner (per function) diffs.

@Caball009 Caball009 added Minor Severity: Minor < Major < Critical < Blocker Network Anything related to network, servers Refactor Edits the code with insignificant behavior changes, is never user facing labels May 17, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 17, 2026

Greptile Summary

This PR refactors four utility functions in NetworkUtil.cpp from verbose if/else chains to switch statements, and adds const-correctness to two function signatures in the header. The logic is preserved across all functions except for one deliberate-but-unacknowledged behavioral change.

  • DoesCommandRequireACommandID, IsCommandSynchronized, and CommandRequiresDirectSend are correctly rewritten as switch statements with no semantic change.
  • CommandRequiresAck is simplified to delegate to DoesCommandRequireACommandID; the original had a duplicate NETCOMMANDTYPE_DISCONNECTPLAYER entry so the unique type sets are identical.
  • GetNetCommandTypeAsString uses a local CASE_LABEL macro for brevity, but the DEBUG_CRASH call on the default branch has been replaced with a silent string return, removing a debug-build guard that would catch newly added enum values not yet registered in this function.

Confidence Score: 3/5

Safe to merge for release builds; the missing DEBUG_CRASH in GetNetCommandTypeAsString means unknown enum values are now silently swallowed in debug builds, which could hide future integration bugs when new command types are added.

All four switch refactors are functionally equivalent in release builds, and the const-correctness improvements in the header are clean. The one concrete change from the stated intent is in GetNetCommandTypeAsString: the original deliberately crashed in debug builds when an unrecognized NetCommandType was passed, catching callers that forget to update the function after adding a new type. The replacement silently returns NETCOMMANDTYPE_UNKNOWN, removing that safety net.

Core/GameEngine/Source/GameNetwork/NetworkUtil.cpp — specifically the default branch of GetNetCommandTypeAsString.

Important Files Changed

Filename Overview
Core/GameEngine/Source/GameNetwork/NetworkUtil.cpp Refactors four if/else chains to switch statements and deduplicates CommandRequiresAck by delegating to DoesCommandRequireACommandID; all functionally equivalent except GetNetCommandTypeAsString loses its DEBUG_CRASH guard on unknown types.
Core/GameEngine/Include/GameNetwork/networkutil.h Adds const-correctness to CommandRequiresAck and CommandRequiresDirectSend parameter declarations — straightforward improvement with no issues.
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
Core/GameEngine/Source/GameNetwork/NetworkUtil.cpp:200
**Silent regression: `DEBUG_CRASH` removed without acknowledgement**

The original `default:` branch called `DEBUG_CRASH(("Unknown NetCommandType in GetNetCommandTypeAsString"))`, which would assert/abort in debug builds when an unrecognized enum value was passed — a deliberate guard to catch callers that forget to update this function when new command types are added. The new `default: return "NETCOMMANDTYPE_UNKNOWN"` silently swallows the unknown type in both debug and release builds. The PR description says "No change should have a functional difference," but this is a clear debug-build behavior change that removes active error detection.

Reviews (1): Last reviewed commit: "Refactored 'GetNetCommandTypeAsString'." | Re-trigger Greptile

#define CASE_LABEL(x) case x: return #x;

switch (type) {
default: return "NETCOMMANDTYPE_UNKNOWN";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Silent regression: DEBUG_CRASH removed without acknowledgement

The original default: branch called DEBUG_CRASH(("Unknown NetCommandType in GetNetCommandTypeAsString")), which would assert/abort in debug builds when an unrecognized enum value was passed — a deliberate guard to catch callers that forget to update this function when new command types are added. The new default: return "NETCOMMANDTYPE_UNKNOWN" silently swallows the unknown type in both debug and release builds. The PR description says "No change should have a functional difference," but this is a clear debug-build behavior change that removes active error detection.

Prompt To Fix With AI
This is a comment left during a code review.
Path: Core/GameEngine/Source/GameNetwork/NetworkUtil.cpp
Line: 200

Comment:
**Silent regression: `DEBUG_CRASH` removed without acknowledgement**

The original `default:` branch called `DEBUG_CRASH(("Unknown NetCommandType in GetNetCommandTypeAsString"))`, which would assert/abort in debug builds when an unrecognized enum value was passed — a deliberate guard to catch callers that forget to update this function when new command types are added. The new `default: return "NETCOMMANDTYPE_UNKNOWN"` silently swallows the unknown type in both debug and release builds. The PR description says "No change should have a functional difference," but this is a clear debug-build behavior change that removes active error detection.

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I made a note of it in the first post.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Minor Severity: Minor < Major < Critical < Blocker Network Anything related to network, servers Refactor Edits the code with insignificant behavior changes, is never user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant