mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-26 09:38:08 -05:00
fix local login query response handler not working (#3495)
(cherry picked from commit b7e14635cf
)
This commit is contained in:
parent
51ad78441b
commit
21518609e3
3 changed files with 30 additions and 8 deletions
|
@ -147,7 +147,7 @@ public final class ServerLoginNetworkAddon extends AbstractNetworkAddon<ServerLo
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean understood = originalBuf != null;
|
boolean understood = originalBuf != null;
|
||||||
@Nullable ServerLoginNetworking.LoginQueryResponseHandler handler = ServerNetworkingImpl.LOGIN.getHandler(channel);
|
@Nullable ServerLoginNetworking.LoginQueryResponseHandler handler = this.getHandler(channel);
|
||||||
|
|
||||||
if (handler == null) {
|
if (handler == null) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.util.concurrent.FutureTask;
|
||||||
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.network.ServerLoginNetworkHandler;
|
import net.minecraft.server.network.ServerLoginNetworkHandler;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.util.Util;
|
||||||
|
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
@ -29,20 +30,22 @@ import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
||||||
import net.fabricmc.fabric.api.networking.v1.ServerLoginConnectionEvents;
|
import net.fabricmc.fabric.api.networking.v1.ServerLoginConnectionEvents;
|
||||||
import net.fabricmc.fabric.api.networking.v1.ServerLoginNetworking;
|
import net.fabricmc.fabric.api.networking.v1.ServerLoginNetworking;
|
||||||
import net.fabricmc.fabric.test.networking.NetworkingTestmods;
|
import net.fabricmc.fabric.test.networking.NetworkingTestmods;
|
||||||
import net.fabricmc.fabric.test.networking.play.NetworkingPlayPacketTest;
|
|
||||||
|
|
||||||
public final class NetworkingLoginQueryTest implements ModInitializer {
|
public final class NetworkingLoginQueryTest implements ModInitializer {
|
||||||
private static final boolean useLoginDelayTest = System.getProperty("fabric-networking-api-v1.loginDelayTest") != null;
|
private static final boolean useLoginDelayTest = System.getProperty("fabric-networking-api-v1.loginDelayTest") != null;
|
||||||
|
|
||||||
|
public static final Identifier GLOBAL_TEST_CHANNEL = NetworkingTestmods.id("global_test_channel");
|
||||||
|
public static final Identifier LOCAL_TEST_CHANNEL = NetworkingTestmods.id("local_test_channel");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
ServerLoginConnectionEvents.QUERY_START.register(this::onLoginStart);
|
ServerLoginConnectionEvents.QUERY_START.register(this::onLoginStart);
|
||||||
ServerLoginConnectionEvents.QUERY_START.register(this::delaySimply);
|
ServerLoginConnectionEvents.QUERY_START.register(this::delaySimply);
|
||||||
|
|
||||||
// login delaying example
|
// login delaying example
|
||||||
ServerLoginNetworking.registerGlobalReceiver(NetworkingPlayPacketTest.TEST_CHANNEL, (server, handler, understood, buf, synchronizer, sender) -> {
|
ServerLoginNetworking.registerGlobalReceiver(GLOBAL_TEST_CHANNEL, (server, handler, understood, buf, synchronizer, sender) -> {
|
||||||
if (understood) {
|
if (understood) {
|
||||||
NetworkingTestmods.LOGGER.info("Understood response from client in {}", NetworkingPlayPacketTest.TEST_CHANNEL);
|
NetworkingTestmods.LOGGER.info("Understood response from client in {}", GLOBAL_TEST_CHANNEL);
|
||||||
|
|
||||||
if (useLoginDelayTest) {
|
if (useLoginDelayTest) {
|
||||||
FutureTask<?> future = new FutureTask<>(() -> {
|
FutureTask<?> future = new FutureTask<>(() -> {
|
||||||
|
@ -59,9 +62,21 @@ public final class NetworkingLoginQueryTest implements ModInitializer {
|
||||||
synchronizer.waitFor(future);
|
synchronizer.waitFor(future);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
NetworkingTestmods.LOGGER.info("Client did not understand response query message with channel name {}", NetworkingPlayPacketTest.TEST_CHANNEL);
|
NetworkingTestmods.LOGGER.info("Client did not understand response query message with channel name {}", GLOBAL_TEST_CHANNEL);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ServerLoginConnectionEvents.QUERY_START.register((handler, server, sender, synchronizer) -> {
|
||||||
|
ServerLoginNetworking.registerReceiver(handler, LOCAL_TEST_CHANNEL, (server1, handler1, understood, buf, synchronizer1, responseSender) -> {
|
||||||
|
if (understood) {
|
||||||
|
NetworkingTestmods.LOGGER.info("Understood response from client in {}", LOCAL_TEST_CHANNEL);
|
||||||
|
} else {
|
||||||
|
NetworkingTestmods.LOGGER.info("Client did not understand response query message with channel name {}", LOCAL_TEST_CHANNEL);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
sender.sendPacket(LOCAL_TEST_CHANNEL, PacketByteBufs.create());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void delaySimply(ServerLoginNetworkHandler handler, MinecraftServer server, PacketSender sender, ServerLoginNetworking.LoginSynchronizer synchronizer) {
|
private void delaySimply(ServerLoginNetworkHandler handler, MinecraftServer server, PacketSender sender, ServerLoginNetworking.LoginSynchronizer synchronizer) {
|
||||||
|
@ -81,6 +96,6 @@ public final class NetworkingLoginQueryTest implements ModInitializer {
|
||||||
|
|
||||||
private void onLoginStart(ServerLoginNetworkHandler networkHandler, MinecraftServer server, PacketSender sender, ServerLoginNetworking.LoginSynchronizer synchronizer) {
|
private void onLoginStart(ServerLoginNetworkHandler networkHandler, MinecraftServer server, PacketSender sender, ServerLoginNetworking.LoginSynchronizer synchronizer) {
|
||||||
// Send a dummy query when the client starts accepting queries.
|
// Send a dummy query when the client starts accepting queries.
|
||||||
sender.sendPacket(NetworkingPlayPacketTest.TEST_CHANNEL, PacketByteBufs.empty()); // dummy packet
|
sender.sendPacket(GLOBAL_TEST_CHANNEL, PacketByteBufs.empty()); // dummy packet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,16 +19,23 @@ package net.fabricmc.fabric.test.networking.client.login;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import net.fabricmc.api.ClientModInitializer;
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
|
import net.fabricmc.fabric.api.client.networking.v1.ClientLoginConnectionEvents;
|
||||||
import net.fabricmc.fabric.api.client.networking.v1.ClientLoginNetworking;
|
import net.fabricmc.fabric.api.client.networking.v1.ClientLoginNetworking;
|
||||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
||||||
import net.fabricmc.fabric.test.networking.play.NetworkingPlayPacketTest;
|
import net.fabricmc.fabric.test.networking.login.NetworkingLoginQueryTest;
|
||||||
|
|
||||||
public final class NetworkingLoginQueryClientTest implements ClientModInitializer {
|
public final class NetworkingLoginQueryClientTest implements ClientModInitializer {
|
||||||
@Override
|
@Override
|
||||||
public void onInitializeClient() {
|
public void onInitializeClient() {
|
||||||
// Send a dummy response to the server in return, by registering here we essentially say we understood the server's query
|
// Send a dummy response to the server in return, by registering here we essentially say we understood the server's query
|
||||||
ClientLoginNetworking.registerGlobalReceiver(NetworkingPlayPacketTest.TEST_CHANNEL, (client, handler, buf, listenerAdder) -> {
|
ClientLoginNetworking.registerGlobalReceiver(NetworkingLoginQueryTest.GLOBAL_TEST_CHANNEL, (client, handler, buf, listenerAdder) -> {
|
||||||
return CompletableFuture.completedFuture(PacketByteBufs.empty());
|
return CompletableFuture.completedFuture(PacketByteBufs.empty());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ClientLoginConnectionEvents.QUERY_START.register((handler, client) -> {
|
||||||
|
ClientLoginNetworking.registerReceiver(NetworkingLoginQueryTest.LOCAL_TEST_CHANNEL, (client1, handler1, buf, listenerAdder) -> {
|
||||||
|
return CompletableFuture.completedFuture(PacketByteBufs.empty());
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue