Skip to content
This repository has been archived by the owner on Jan 15, 2025. It is now read-only.

Commit

Permalink
fix packets and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
xspanger3770 committed Oct 24, 2023
1 parent ecbb698 commit ba34442
Showing 5 changed files with 7 additions and 31 deletions.
2 changes: 1 addition & 1 deletion GlobalQuakeAPI/src/main/java/gqserver/api/Packet.java
Original file line number Diff line number Diff line change
@@ -5,6 +5,6 @@

public interface Packet extends Serializable {

default void onServerReceive(ServerClient serverClient) throws IOException {};
default void onServerReceive(ServerClient serverClient) throws IOException {}

}
Original file line number Diff line number Diff line change
@@ -3,21 +3,6 @@
import gqserver.api.Packet;
import gqserver.api.data.system.ServerClientConfig;

public class HandshakePacket extends Packet {
public record HandshakePacket(int compatVersion, ServerClientConfig clientConfig) implements Packet {

private final int compatVersion;
private final ServerClientConfig clientConfig;

public HandshakePacket(int compatVersion, ServerClientConfig clientConfig){
this.compatVersion = compatVersion;
this.clientConfig = clientConfig;
}

public int getCompatVersion() {
return compatVersion;
}

public ServerClientConfig getClientConfig() {
return clientConfig;
}
}
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@

import java.io.IOException;

public class HeartbeatPacket extends Packet {
public record HeartbeatPacket() implements Packet {

@Override
public void onServerReceive(ServerClient serverClient) throws IOException {
Original file line number Diff line number Diff line change
@@ -2,14 +2,5 @@

import gqserver.api.Packet;

public class TerminationPacket extends Packet {
private final String cause;

public TerminationPacket(String cause) {
this.cause = cause;
}

public String getCause() {
return cause;
}
public record TerminationPacket(String cause) implements Packet {
}
Original file line number Diff line number Diff line change
@@ -90,13 +90,13 @@ private void handshake(ServerClient client) throws IOException {
try {
Packet packet = client.readPacket();
if (packet instanceof HandshakePacket handshakePacket) {
if (handshakePacket.getCompatVersion() != COMPATIBILITY_VERSION) {
if (handshakePacket.compatVersion() != COMPATIBILITY_VERSION) {
client.sendPacket(new TerminationPacket("Your client version is not compatible with the server!"));
throw new InvalidPacketException("Client's version is not compatible %d != %d"
.formatted(handshakePacket.getCompatVersion(), COMPATIBILITY_VERSION));
.formatted(handshakePacket.compatVersion(), COMPATIBILITY_VERSION));
}

client.setClientConfig(handshakePacket.getClientConfig());
client.setClientConfig(handshakePacket.clientConfig());
} else {
throw new InvalidPacketException("Received packet is not handshake!");
}

0 comments on commit ba34442

Please sign in to comment.