Skip to content

Commit

Permalink
🐛 Fix cannot record vanilla server
Browse files Browse the repository at this point in the history
  • Loading branch information
unhappychoice committed Jun 8, 2021
1 parent 4855f37 commit 3e2118b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
51 changes: 31 additions & 20 deletions src/main/java/com/replaymod/recording/packet/PacketListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,8 @@ public class PacketListener extends ChannelInboundHandlerAdapter {
private long lastSentPacket;
private long timePassedWhilePaused;
private volatile boolean serverWasPaused;
//#if FABRIC>1
private NetworkState connectionState = NetworkState.LOGIN;
private boolean loginPhase = true;
//#else
//#if MC>=11600
//$$ private ProtocolType connectionState = ProtocolType.LOGIN;
//$$ private boolean loginPhase = true;
//#else
//$$ private EnumConnectionState connectionState = EnumConnectionState.PLAY;
//$$ private boolean loginPhase = false;
//#endif
//#endif

/**
* Used to keep track of the last metadata save job submitted to the save service and
Expand Down Expand Up @@ -232,8 +222,7 @@ public void save(Packet packet) {

//#if MC>=11400
if (packet instanceof LoginSuccessS2CPacket) {
connectionState = NetworkState.PLAY;
loginPhase = false;
moveToPlayState();
}
//#endif
} catch(Exception e) {
Expand Down Expand Up @@ -465,14 +454,7 @@ private PacketData getPacketData(int timestamp, Packet packet) throws Exception
//$$ }
//#endif

//#if MC>=10800
Integer packetId = connectionState.getPacketId(NetworkSide.CLIENTBOUND, packet);
//#else
//$$ Integer packetId = (Integer) connectionState.func_150755_b().inverse().get(packet.getClass());
//#endif
if (packetId == null) {
throw new IOException("Unknown packet type:" + packet.getClass());
}
Integer packetId = getPacketId(packet);
ByteBuf byteBuf = Unpooled.buffer();
try {
packet.write(new PacketByteBuf(byteBuf));
Expand Down Expand Up @@ -534,4 +516,33 @@ public long getCurrentDuration() {
public void setServerWasPaused() {
this.serverWasPaused = true;
}

private Integer getPacketId(Packet packet) throws IOException {
//#if MC>=10800
Integer packetId = connectionState.getPacketId(NetworkSide.CLIENTBOUND, packet);
//#else
//$$ Integer packetId = (Integer) connectionState.func_150755_b().inverse().get(packet.getClass());
//#endif

if (packetId == null) {
/*
Retrying as the state is PLAY
TODO: Investigate packet order and refactor to be more consistent
*/
packetId = NetworkState.PLAY.getPacketId(NetworkSide.CLIENTBOUND, packet);

if (packetId == null) {
throw new IOException("Unknown packet type:" + packet.getClass());
}

moveToPlayState();
}

return packetId;
}

private void moveToPlayState() {
connectionState = NetworkState.PLAY;
loginPhase = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public abstract class MixinNetHandlerLoginClient {
@Final @Shadow
private NetworkManager networkManager;

@Inject(method = "handleLoginSuccess", at=@At("HEAD"))
public void replayModRecording_initiateRecording(CallbackInfo cb) {
initiateRecording(null);
}

/**
* Starts the recording right before switching into PLAY state.
* We cannot use the {@link FMLNetworkEvent.ClientConnectedToServerEvent}
Expand All @@ -35,7 +40,7 @@ private void initiateRecording(SCustomPayloadLoginPacket packet) {
return; // already recording
}
ReplayModRecording.instance.initiateRecording(this.networkManager);
if (eventSender.getRecordingEventHandler() != null) {
if (eventSender.getRecordingEventHandler() != null && packet != null) {
eventSender.getRecordingEventHandler().onPacket(packet);
}
}
Expand Down

0 comments on commit 3e2118b

Please sign in to comment.