Skip to content

Commit

Permalink
1.19 -> 1.20-pre6
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed May 27, 2023
1 parent d4ba442 commit 2270873
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 23 deletions.
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ org.gradle.daemon=false

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.19.3
yarn_mappings=1.19.3+build.2
loader_version=0.14.11
fabric_version=0.68.1+1.19.3
minecraft_version=1.20-pre6
yarn_mappings=1.20-pre6+build.2
loader_version=0.14.21
fabric_version=0.82.1+1.20

# Mod Properties
group=com.sollace
Expand All @@ -20,4 +20,4 @@ org.gradle.daemon=false
modrinth_project_id=coknAH3s

# Dependencies
modmenu_version=5.0.0-alpha.3
modmenu_version=7.0.0-beta.2
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.function.Function;

import com.google.common.base.Preconditions;
import com.sollace.fabwork.impl.ClientConnectionAccessor;
import com.sollace.fabwork.impl.packets.ClientSimpleNetworkingImpl;
import com.sollace.fabwork.impl.packets.ServerSimpleNetworkingImpl;

Expand Down Expand Up @@ -50,13 +51,13 @@ public void sendToServer(T packet) {
*/
public Future<T> awaitResponseFrom(ServerPlayerEntity client) {
Objects.requireNonNull(client, "Client player cannot be null");
return ServerSimpleNetworkingImpl.waitForReponse(this, client.networkHandler.getConnection());
return ServerSimpleNetworkingImpl.waitForReponse(this, ClientConnectionAccessor.get(client.networkHandler));
}

/**
* Repackages a Fabwork packet into a normal Minecraft protocol packet suitable for sending to the connected server.
*/
public net.minecraft.network.Packet<ServerPlayPacketListener> toPacket(T packet) {
public net.minecraft.network.packet.Packet<ServerPlayPacketListener> toPacket(T packet) {
Objects.requireNonNull(packet, "Packet cannot be null");
return ClientSimpleNetworkingImpl.createC2SPacket(id(), packet.toBuffer());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void sendToSurroundingPlayers(T packet, Entity entity) {
/**
* Repackages a fabwork packet into a normal Minecraft protocol packet suitable for sending to a connected client.
*/
public net.minecraft.network.Packet<ClientPlayPacketListener> toPacket(T packet) {
public net.minecraft.network.packet.Packet<ClientPlayPacketListener> toPacket(T packet) {
Objects.requireNonNull(packet, "Packet cannot be null");
return ServerPlayNetworking.createS2CPacket(id(), packet.toBuffer());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.sollace.fabwork.impl;

import net.minecraft.network.ClientConnection;
import net.minecraft.server.network.ServerPlayNetworkHandler;

public interface ClientConnectionAccessor {
ClientConnection getConnection();

static ClientConnection get(ServerPlayNetworkHandler handler) {
return ((ClientConnectionAccessor)handler).getConnection();
}
}
24 changes: 13 additions & 11 deletions src/main/java/com/sollace/fabwork/impl/FabworkServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ public void onInitialize() {
ServerPlayNetworking.registerGlobalReceiver(CONSENT_ID, (server, player, handler, buffer, response) -> {
LoaderUtil.invokeUntrusted(() -> {
SynchronisationState state = new SynchronisationState(ModEntryImpl.read(buffer), emptyState.installedOnServer().stream());
LOGGER.info("Got mod list from {}[{}]: {}", player.getName().getString(), handler.getConnection().getAddress(), ModEntriesUtil.stringify(state.installedOnClient()));
clientLoginStates.put(handler.getConnection(), state);
ClientConnection connection = ClientConnectionAccessor.get(handler);
LOGGER.info("Got mod list from {}[{}]: {}", player.getName().getString(), connection.getAddress(), ModEntriesUtil.stringify(state.installedOnClient()));
clientLoginStates.put(connection, state);
}, "Received synchronize response from client");
});

ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
LoaderUtil.invokeUntrusted(() -> {
LOGGER.info("Sending mod list to {}[{}]", handler.getPlayer().getName().getString(), handler.getConnection().getAddress());
LOGGER.info("Sending mod list to {}[{}]", handler.getPlayer().getName().getString(), handler.getConnectionAddress());
sender.sendPacket(CONSENT_ID, ModEntryImpl.write(
emptyState.installedOnServer().stream(),
PacketByteBufs.create())
Expand All @@ -54,23 +55,24 @@ public void onInitialize() {

ServerConnectionEvents.CONNECT.register((handler, sender, server) -> {
LoaderUtil.invokeUntrusted(() -> {
PlayPingSynchroniser.waitForClientResponse(handler.getConnection(), responseType -> {
PlayPingSynchroniser.waitForClientResponse(ClientConnectionAccessor.get(handler), responseType -> {
ClientConnection connection = ClientConnectionAccessor.get(handler);
if (responseType == ResponseType.COMPLETED) {
if (clientLoginStates.containsKey(handler.getConnection())) {
clientLoginStates.remove(handler.getConnection()).verify(handler.getConnection(), LOGGER, true);
if (clientLoginStates.containsKey(connection)) {
clientLoginStates.remove(connection).verify(connection, LOGGER, true);
} else {
LOGGER.warn("{}[{}] did not send a mod list. They may not have fabwork installed", handler.getPlayer().getName().getString(), handler.getConnection().getAddress());
LOGGER.warn("{}[{}] did not send a mod list. They may not have fabwork installed", handler.getPlayer().getName().getString(), handler.getConnectionAddress());
if (config.allowUnmoddedClients) {
LOGGER.warn("Connection to {}[{}] has been force permitted by server configuration. They are allowed to join checking installed mods! Their game may be broken upon joining!", handler.getPlayer().getName().getString(), handler.getConnection().getAddress());
LOGGER.warn("Connection to {}[{}] has been force permitted by server configuration. They are allowed to join checking installed mods! Their game may be broken upon joining!", handler.getPlayer().getName().getString(), handler.getConnectionAddress());
} else {
emptyState.verify(handler.getConnection(), LOGGER, false);
emptyState.verify(connection, LOGGER, false);
}
}
} else {
LOGGER.warn("Failed to receive response from client. {}[{}] ConnectionState: {}",
handler.getPlayer().getName().getString(),
handler.getConnection().getAddress(),
handler.getConnection().isOpen() ? " OPEN" : " CLOSED"
handler.getConnectionAddress(),
handler.isConnectionOpen() ? " OPEN" : " CLOSED"
);
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
package com.sollace.fabwork.impl.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.sollace.fabwork.impl.ClientConnectionAccessor;
import com.sollace.fabwork.impl.PlayPingSynchroniser;

import net.minecraft.network.ClientConnection;
import net.minecraft.network.NetworkThreadUtils;
import net.minecraft.network.listener.ServerPlayPacketListener;
import net.minecraft.network.packet.c2s.play.PlayPongC2SPacket;
import net.minecraft.server.network.ServerPlayNetworkHandler;

@Mixin(ServerPlayNetworkHandler.class)
abstract class ServerPlayNetworkHandlerMixin implements ServerPlayPacketListener {
abstract class ServerPlayNetworkHandlerMixin implements ServerPlayPacketListener, ClientConnectionAccessor {
@Inject(method = "onPong(Lnet/minecraft/network/packet/c2s/play/PlayPongC2SPacket;)V", at = @At("HEAD"))
private void onOnPong(PlayPongC2SPacket packet, CallbackInfo info) {
NetworkThreadUtils.forceMainThread(packet, this, ((ServerPlayNetworkHandler)(Object)this).player.getWorld());
NetworkThreadUtils.forceMainThread(packet, this, ((ServerPlayNetworkHandler)(Object)this).player.getServerWorld());
PlayPingSynchroniser.onClientResponse(packet, ((ServerPlayNetworkHandler)(Object)this).player.getWorld().getServer());
}

@Override
@Accessor("connection")
public abstract ClientConnection getConnection();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static void send(Identifier id, PacketByteBuf buffer) {
ClientPlayNetworking.send(id, buffer);
}

public static net.minecraft.network.Packet<ServerPlayPacketListener> createC2SPacket(Identifier id, PacketByteBuf buffer) {
public static net.minecraft.network.packet.Packet<ServerPlayPacketListener> createC2SPacket(Identifier id, PacketByteBuf buffer) {
return ClientPlayNetworking.createC2SPacket(id, buffer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.function.Function;

import com.sollace.fabwork.api.packets.*;
import com.sollace.fabwork.impl.ClientConnectionAccessor;
import com.sollace.fabwork.impl.PlayPingSynchroniser;

import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
Expand Down Expand Up @@ -39,7 +40,7 @@ public static <T extends Packet<ServerPlayerEntity>> Future<T> waitForReponse(C2
final CompletableFuture<T> future = new CompletableFuture<>();

packetType.receiver().addTemporaryListener((sender, packet) -> {
if (sender.networkHandler.getConnection() == connection) {
if (ClientConnectionAccessor.get(sender.networkHandler) == connection) {
receivedPacket[0] = packet;
return true;
}
Expand Down

0 comments on commit 2270873

Please sign in to comment.