net.MagicHeader
net.MagicHeader
#Overview
name: net.MagicHeader
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
String representing binary bits which are prepended to every packet sent by the game. Max length: 32 bits.
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of net.MagicHeader is to define a string representing binary bits that are prepended to every packet sent by the game. This setting is primarily used in the networking system of Unreal Engine 5, specifically in the packet handling subsystem.
The Unreal Engine subsystem that relies on this setting variable is the networking module, particularly the StatelessConnectHandlerComponent. This component is part of the packet handling system, which manages network connections and packet processing.
The value of this variable is set through the console variable system (CVarNetMagicHeader). It can be modified at runtime or set in configuration files.
The associated variable CVarNetMagicHeader interacts directly with net.MagicHeader. They share the same value, and CVarNetMagicHeader is used to access and manipulate the net.MagicHeader setting within the code.
Developers must be aware of the following when using this variable:
- The maximum length of the magic header is 32 bits.
- The header is prepended to every packet sent by the game, which can affect network performance and packet structure.
- Changing this value will impact all network communications in the game.
Best practices when using this variable include:
- Use it sparingly and only when necessary for specific networking requirements.
- Keep the header as short as possible to minimize overhead.
- Ensure that all connected clients and servers are using the same magic header to maintain compatibility.
- Document any changes to this variable, as it can significantly impact network behavior.
Regarding the associated variable CVarNetMagicHeader:
The purpose of CVarNetMagicHeader is to provide a console-accessible interface for the net.MagicHeader setting. It allows for runtime modification and access to the magic header value.
This variable is used within the StatelessConnectHandlerComponent to retrieve the current magic header value and apply it to the packet handling system. It’s part of the networking subsystem and is crucial for maintaining consistent packet structures across the network.
The value of CVarNetMagicHeader is set through the console variable system, which can be modified at runtime or through configuration files.
CVarNetMagicHeader directly interacts with net.MagicHeader, serving as the primary means of accessing and modifying the magic header value within the code.
Developers should be aware that changes to CVarNetMagicHeader will immediately affect the network packet structure. They should also ensure that the value adheres to the 32-bit length limitation.
Best practices for using CVarNetMagicHeader include:
- Use it for debugging and testing network configurations.
- Implement proper error checking when retrieving the value to handle empty or invalid strings.
- Consider the performance implications of frequently accessing this console variable in performance-critical code paths.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PacketHandlers/StatelessConnectHandlerComponent.cpp:233
Scope: file
Source code excerpt:
TAutoConsoleVariable<FString> CVarNetMagicHeader(
TEXT("net.MagicHeader"),
TEXT(""),
TEXT("String representing binary bits which are prepended to every packet sent by the game. Max length: 32 bits."));
namespace UE::Net
{
#Associated Variable and Callsites
This variable is associated with another variable named CVarNetMagicHeader
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PacketHandlers/StatelessConnectHandlerComponent.cpp:232
Scope: file
Source code excerpt:
*/
TAutoConsoleVariable<FString> CVarNetMagicHeader(
TEXT("net.MagicHeader"),
TEXT(""),
TEXT("String representing binary bits which are prepended to every packet sent by the game. Max length: 32 bits."));
namespace UE::Net
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PacketHandlers/StatelessConnectHandlerComponent.cpp:406
Scope (from outer to inner):
file
function StatelessConnectHandlerComponent::StatelessConnectHandlerComponent
Source code excerpt:
bRequiresHandshake = true;
FString MagicHeaderStr = CVarNetMagicHeader.GetValueOnAnyThread();
if (!MagicHeaderStr.IsEmpty())
{
int32 HeaderStrLen = MagicHeaderStr.Len();
if (HeaderStrLen <= 32)