Skip to content

Commit

Permalink
First rough pass at 23w31a (doesn't compile)
Browse files Browse the repository at this point in the history
  • Loading branch information
basaigh committed Aug 9, 2023
1 parent bfb6430 commit b29b1d0
Show file tree
Hide file tree
Showing 38 changed files with 531 additions and 296 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.github.steveice10</groupId>
<artifactId>mcprotocollib</artifactId>
<version>1.20-1</version>
<version>1.20.2-SNAPSHOT</version>
<packaging>jar</packaging>

<name>MCProtocolLib</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
import com.github.steveice10.mc.protocol.data.status.handler.ServerInfoHandler;
import com.github.steveice10.mc.protocol.data.status.handler.ServerPingTimeHandler;
import com.github.steveice10.mc.protocol.packet.configuration.clientbound.ClientboundFinishConfigurationPacket;
import com.github.steveice10.mc.protocol.packet.handshake.serverbound.ClientIntentionPacket;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundDisconnectPacket;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundKeepAlivePacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundKeepAlivePacket;
import com.github.steveice10.mc.protocol.packet.common.clientbound.ClientboundDisconnectPacket;
import com.github.steveice10.mc.protocol.packet.common.clientbound.ClientboundKeepAlivePacket;
import com.github.steveice10.mc.protocol.packet.common.serverbound.ServerboundKeepAlivePacket;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundStartConfigurationPacket;
import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundGameProfilePacket;
import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundHelloPacket;
import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundLoginCompressionPacket;
Expand All @@ -35,7 +37,6 @@
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;

/**
* Handles making initial login and status requests for clients.
Expand Down Expand Up @@ -84,7 +85,7 @@ public void packetReceived(Session session, Packet packet) {
session.send(new ServerboundKeyPacket(helloPacket.getPublicKey(), key, helloPacket.getChallenge()));
session.enableEncryption(protocol.enableEncryption(key));
} else if (packet instanceof ClientboundGameProfilePacket) {
protocol.setState(ProtocolState.GAME);
protocol.setState(ProtocolState.CONFIGURATION);
} else if (packet instanceof ClientboundLoginDisconnectPacket) {
session.disconnect(((ClientboundLoginDisconnectPacket) packet).getReason());
} else if (packet instanceof ClientboundLoginCompressionPacket) {
Expand Down Expand Up @@ -113,6 +114,12 @@ public void packetReceived(Session session, Packet packet) {
session.send(new ServerboundKeepAlivePacket(((ClientboundKeepAlivePacket) packet).getPingId()));
} else if (packet instanceof ClientboundDisconnectPacket) {
session.disconnect(((ClientboundDisconnectPacket) packet).getReason());
} else if (packet instanceof ClientboundStartConfigurationPacket) {
protocol.setState(ProtocolState.CONFIGURATION);
}
} else if (protocol.getState() == ProtocolState.CONFIGURATION) {
if (packet instanceof ClientboundFinishConfigurationPacket) {
protocol.setState(ProtocolState.GAME);
}
}
}
Expand Down
27 changes: 15 additions & 12 deletions src/main/java/com/github/steveice10/mc/protocol/ServerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
import com.github.steveice10.mc.protocol.data.status.VersionInfo;
import com.github.steveice10.mc.protocol.data.status.handler.ServerInfoBuilder;
import com.github.steveice10.mc.protocol.packet.configuration.clientbound.ClientboundFinishConfigurationPacket;
import com.github.steveice10.mc.protocol.packet.configuration.serverbound.ServerboundFinishConfigurationPacket;
import com.github.steveice10.mc.protocol.packet.handshake.serverbound.ClientIntentionPacket;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundDisconnectPacket;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundKeepAlivePacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundKeepAlivePacket;
import com.github.steveice10.mc.protocol.packet.common.clientbound.ClientboundDisconnectPacket;
import com.github.steveice10.mc.protocol.packet.common.clientbound.ClientboundKeepAlivePacket;
import com.github.steveice10.mc.protocol.packet.common.serverbound.ServerboundKeepAlivePacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundConfigurationAcknowledgedPacket;
import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundGameProfilePacket;
import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundHelloPacket;
import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundLoginCompressionPacket;
Expand Down Expand Up @@ -97,9 +100,7 @@ public void packetReceived(Session session, Packet packet) {
throw new UnsupportedOperationException("Invalid client intent: " + intentionPacket.getIntent());
}
}
}

if (protocol.getState() == ProtocolState.LOGIN) {
} else if (protocol.getState() == ProtocolState.LOGIN) {
if (packet instanceof ServerboundHelloPacket) {
this.username = ((ServerboundHelloPacket) packet).getUsername();

Expand All @@ -121,9 +122,7 @@ public void packetReceived(Session session, Packet packet) {
session.enableEncryption(protocol.enableEncryption(key));
new Thread(new UserAuthTask(session, key)).start();
}
}

if (protocol.getState() == ProtocolState.STATUS) {
} else if (protocol.getState() == ProtocolState.STATUS) {
if (packet instanceof ServerboundStatusRequestPacket) {
ServerInfoBuilder builder = session.getFlag(MinecraftConstants.SERVER_INFO_BUILDER_KEY);
if (builder == null) {
Expand All @@ -141,14 +140,18 @@ public void packetReceived(Session session, Packet packet) {
} else if (packet instanceof ServerboundPingRequestPacket) {
session.send(new ClientboundPongResponsePacket(((ServerboundPingRequestPacket) packet).getPingTime()));
}
}

if (protocol.getState() == ProtocolState.GAME) {
} else if (protocol.getState() == ProtocolState.GAME) {
if (packet instanceof ServerboundKeepAlivePacket) {
if (((ServerboundKeepAlivePacket) packet).getPingId() == this.lastPingId) {
long time = System.currentTimeMillis() - this.lastPingTime;
session.setFlag(MinecraftConstants.PING_KEY, time);
}
} else if (packet instanceof ServerboundConfigurationAcknowledgedPacket) {
protocol.setState(ProtocolState.CONFIGURATION);
}
} else if (protocol.getState() == ProtocolState.CONFIGURATION) {
if (packet instanceof ServerboundFinishConfigurationPacket) {
protocol.setState(ProtocolState.GAME);
}
}
}
Expand Down
Loading

0 comments on commit b29b1d0

Please sign in to comment.