Skip to content

Commit

Permalink
Add a check during network negotiation that ensures that both sides h…
Browse files Browse the repository at this point in the history
…ave the same enforced packetflow.
  • Loading branch information
marchermans committed Nov 13, 2023
1 parent 3ccaaea commit 85cd3e0
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class NetworkComponentNegotiator {
* <li>If the server has none optional components that are not present on the client, then negotiation fails</li>
* <li>For each of the matching channels the following is executed:</li>
* <ul>
* <li>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.</li>
* <li>If one side has no version range provided, but has a preferred version, then it is checked against the other sides range. If the check fails then it fail.</li>
* <li>If one side has a range, but the other has no version, then negotiation fails.</li>
* <li>If one side has a preferred version, but no range, then the preferred version is interpreted as the sole acceptable range.</li>
Expand Down Expand Up @@ -152,6 +153,7 @@ public static NegotiationResult negotiate(List<NegotiableNetworkComponent> serve
* <p>
* The following rules are followed:
* <ul>
* <li>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.</li>
* <li>If one side has no version range provided, but has a preferred version, then it is checked against the other sides range.</li>
* <li>If one side has a range, but the other has no version, then negotiation fails.</li>
* <li>If one side has a preferred version, but no range, then the preferred version is interpreted as the sole acceptable range.</li>
Expand All @@ -173,6 +175,14 @@ public static NegotiationResult negotiate(List<NegotiableNetworkComponent> serve
*/
@VisibleForTesting
public static Optional<ComponentNegotiationResult> validateComponent(NegotiableNetworkComponent left, NegotiableNetworkComponent right, String requestingSide) {
if (left.flow().isPresent()) {
if (right.flow().isEmpty()) {
return Optional.of(new ComponentNegotiationResult(false, Component.translatable("neoforge.network.negotiation.failure.flow.%s.missing".formatted(requestingSide), left.id())));
} else if (left.flow().get() != right.flow().get()) {
return Optional.of(new ComponentNegotiationResult(false, Component.translatable("neoforge.network.negotiation.failure.flow.%s.mismatch".formatted(requestingSide), left.id(), left.flow().get(), right.flow().get())));
}
}

Optional<Range<Integer>> leftRange = left.buildVersionRange();
Optional<Range<Integer>> rightRange = right.buildVersionRange();

Expand Down

0 comments on commit 85cd3e0

Please sign in to comment.