You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
This PR refactors four network utility functions in NetworkUtil.cpp from verbose if/else chains to cleaner switch statements, and adds const-correctness to two function signatures. No functional changes were intended, and verification confirms the enum value sets are identical before and after for each function.
CommandRequiresAck is now a one-liner that delegates to DoesCommandRequireACommandID, eliminating a near-duplicate list that had a copy-paste duplicate (NETCOMMANDTYPE_DISCONNECTPLAYER) in the original.
GetNetCommandTypeAsString gains a CASE_LABEL macro for DRY string expansion, adds three previously missing enum values (NETCOMMANDTYPE_UNKNOWN, NETCOMMANDTYPE_DISCONNECTSTART, NETCOMMANDTYPE_DISCONNECTEND), and restores the DEBUG_CRASH guard on the default branch per the discussion on the previous thread.
Confidence Score: 5/5
Safe to merge — all refactored switch statements cover exactly the same enum values as the original if/else chains, and the previous thread concerns have been resolved.
The diff is a pure structural refactor: every function's return-true set was manually cross-checked and is identical to the original. CommandRequiresAck now correctly delegates rather than maintaining a separate (previously duplicate-containing) list. The DEBUG_CRASH on the unhandled default in GetNetCommandTypeAsString has been restored. The three newly added enum literals in the string function are additions, not removals. No logic paths changed.
Refactored four if/else chain functions to switch statements; CommandRequiresAck simplified to delegate to DoesCommandRequireACommandID; GetNetCommandTypeAsString updated with CASE_LABEL macro, three new enum values, and DEBUG_CRASH restored on default. All functional sets verified equivalent.
Core/GameEngine/Include/GameNetwork/networkutil.h
CommandRequiresAck and CommandRequiresDirectSend signatures updated to take const NetCommandMsg* — a straightforward const-correctness improvement matching the implementation.
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[CommandRequiresAck\nconst NetCommandMsg*] -->|delegates to| B[DoesCommandRequireACommandID\nNetCommandType]
C[CommandRequiresDirectSend\nconst NetCommandMsg*] -->|switch on getNetCommandType| D{DirectSend\nenum set}
B -->|switch on type| E{CommandID\nenum set}
F[IsCommandSynchronized\nNetCommandType] -->|switch on type| G{Sync\nenum set}
H[GetNetCommandTypeAsString\nNetCommandType] -->|CASE_LABEL macro| I{All enum values\n+ UNKNOWN/START/END}
E -->|match| J[TRUE]
E -->|default| K[FALSE]
D -->|match| J
D -->|default| K
G -->|match| J
G -->|default| K
I -->|match| L[return name string]
I -->|default| M[DEBUG_CRASH +\nreturn NETCOMMANDTYPE_INVALID]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MinorSeverity: Minor < Major < Critical < BlockerNetworkAnything related to network, serversRefactorEdits the code with insignificant behavior changes, is never user facing
3 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
See commits for cleaner (per function) diffs.