Class NetworkComponentNegotiator
java.lang.Object
net.neoforged.neoforge.network.negotiation.NetworkComponentNegotiator
Negotiates the network components between the server and client.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
The result of a negotiation. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static List
<NegotiableNetworkComponent> buildDisabledOptionalComponents
(List<NegotiableNetworkComponent> currentSide, List<NegotiableNetworkComponent> otherSide) Builds a list of disabled optional components.static NegotiationResult
negotiate
(List<NegotiableNetworkComponent> server, List<NegotiableNetworkComponent> client) Negotiates the network components between the server and client.validateComponent
(NegotiableNetworkComponent left, NegotiableNetworkComponent right, String requestingSide) Checks if two components are compatible.
-
Constructor Details
-
NetworkComponentNegotiator
public NetworkComponentNegotiator()
-
-
Method Details
-
negotiate
public static NegotiationResult negotiate(List<NegotiableNetworkComponent> server, List<NegotiableNetworkComponent> client) Negotiates the network components between the server and client.The following rules are followed:
- Any component that is optional on the client but is not present on the server is removed from the client's list.
- Any component that is optional on the server but is not present on the client is removed from the server's list.
- If the client has none optional components that are not present on the server, then negotiation fails
- If the server has none optional components that are not present on the client, then negotiation fails
- For each of the matching channels the following is executed:
- Check if packet flow directions are set, and if at least one is set match it to the other, by missing or wrong value fail the negotiation.
- Check if both sides have the same version, or none set.
- At this point the channels are considered compatible, pick the servers version. It does not matter what side is picked since either both have the same version, or no version at all.
If negotiation succeeds then a list of agreed upon channels and their versions is returned.
If negotiation fails then a
Component
is returned with the reason for failure.- Parameters:
server
- The list of server components that the server wishes to use for communication.client
- The list of client components that the client wishes to use for communication.- Returns:
- A
NegotiationResult
that contains the agreed upon channels and their versions if negotiation succeeded, or aComponent
with the reason for failure if negotiation failed.
-
buildDisabledOptionalComponents
private static List<NegotiableNetworkComponent> buildDisabledOptionalComponents(List<NegotiableNetworkComponent> currentSide, List<NegotiableNetworkComponent> otherSide) Builds a list of disabled optional components.- Parameters:
currentSide
- The current side to check for disabled optional components.otherSide
- The other side to check for missing components.- Returns:
- The list of disabled optional components.
-
validateComponent
@VisibleForTesting public static Optional<NetworkComponentNegotiator.ComponentNegotiationResult> validateComponent(NegotiableNetworkComponent left, NegotiableNetworkComponent right, String requestingSide) Checks if two components are compatible.The following rules are followed:
- Check if packet flow directions are set, and if at least one is set match it to the other, by missing or wrong value fail the negotiation.
- Check if both sides have the same version, or none set.
If negotiation succeeds then an empty
Optional
is returned.If negotiation fails then a
NegotiationResult
is returned with the reason for failure.- Parameters:
left
- The verification component to compare.right
- The requesting component to compare.requestingSide
- The side of the requesting component.- Returns:
- An empty
Optional
if negotiation succeeded, or aNegotiationResult
with the reason for failure if negotiation failed.
-