- Added comments
This commit is contained in:
@@ -10,45 +10,101 @@ import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
/**
|
||||
* Abstract class representing a packet in the Open Autonomous Connection (OAC) protocol.
|
||||
* This class extends the base Packet class and includes additional functionality specific to OAC.
|
||||
*/
|
||||
public abstract class OACPacket extends Packet {
|
||||
|
||||
/**
|
||||
* The protocol version associated with this packet.
|
||||
*/
|
||||
@Getter
|
||||
private final ProtocolVersion protocolVersion;
|
||||
|
||||
/**
|
||||
* The response code for the packet, defaulting to RESPONSE_NOT_REQUIRED.
|
||||
*/
|
||||
private DNSResponseCode responseCode = DNSResponseCode.RESPONSE_NOT_REQUIRED;
|
||||
|
||||
/**
|
||||
* Constructor for OACPacket.
|
||||
* @param id The unique identifier for the packet.
|
||||
* @param protocolVersion The protocol version associated with this packet.
|
||||
*/
|
||||
public OACPacket(int id, ProtocolVersion protocolVersion) {
|
||||
super(id);
|
||||
this.protocolVersion = protocolVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the response code for the packet.
|
||||
* @return The DNSResponseCode associated with the packet.
|
||||
*/
|
||||
protected final DNSResponseCode getResponseCode() {
|
||||
return responseCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the response code for the packet.
|
||||
* @param responseCode The DNSResponseCode to set for the packet.
|
||||
*/
|
||||
protected final void setResponseCode(DNSResponseCode responseCode) {
|
||||
this.responseCode = responseCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the packet data to the output stream.
|
||||
* @param packetHandler The packet handler managing the packet.
|
||||
* @param objectOutputStream The output stream to write the packet data to.
|
||||
* @throws IOException If an I/O error occurs.
|
||||
* @throws ClassNotFoundException If a class cannot be found during serialization.
|
||||
*/
|
||||
@Override
|
||||
public final void write(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
||||
// Write the specific packet data
|
||||
onWrite(packetHandler, objectOutputStream);
|
||||
|
||||
// Write the response code if the protocol version is not classic
|
||||
if (protocolVersion != ProtocolVersion.PV_1_0_0_CLASSIC) objectOutputStream.writeObject(responseCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void read(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||
// Read the specific packet data
|
||||
onRead(packetHandler, objectInputStream);
|
||||
if (protocolVersion != ProtocolVersion.PV_1_0_0_CLASSIC) {
|
||||
responseCode = (DNSResponseCode) objectInputStream.readObject();
|
||||
onResponseCodeRead(packetHandler, objectInputStream);
|
||||
}
|
||||
|
||||
// Read the response code if the protocol version is not classic
|
||||
if (protocolVersion != ProtocolVersion.PV_1_0_0_CLASSIC) responseCode = (DNSResponseCode) objectInputStream.readObject();
|
||||
else responseCode = DNSResponseCode.RESPONSE_NOT_REQUIRED;
|
||||
|
||||
// Call the response code read handler
|
||||
onResponseCodeRead(packetHandler, objectInputStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract method to be implemented by subclasses for writing specific packet data.
|
||||
* @param packetHandler The packet handler managing the packet.
|
||||
* @param objectOutputStream The output stream to write the packet data to.
|
||||
* @throws IOException If an I/O error occurs.
|
||||
* @throws ClassNotFoundException If a class cannot be found during serialization.
|
||||
*/
|
||||
public abstract void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException;
|
||||
|
||||
/**
|
||||
* Abstract method to be implemented by subclasses for reading specific packet data.
|
||||
* @param packetHandler The packet handler managing the packet.
|
||||
* @param objectInputStream The input stream to read the packet data from.
|
||||
* @throws IOException If an I/O error occurs.
|
||||
* @throws ClassNotFoundException If a class cannot be found during deserialization.
|
||||
*/
|
||||
public abstract void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException;
|
||||
|
||||
protected void onResponseCodeRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) {
|
||||
}
|
||||
/**
|
||||
* Method called after the response code has been read from the input stream.
|
||||
* Subclasses can override this method to handle any additional logic based on the response code.
|
||||
* @param packetHandler The packet handler managing the packet.
|
||||
* @param objectInputStream The input stream from which the response code was read.
|
||||
*/
|
||||
protected void onResponseCodeRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) {}
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ import dev.unlegitdqrk.unlegitlibrary.network.system.server.ConnectionHandler;
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.utils.NetworkUtils;
|
||||
import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||
import org.openautonomousconnection.protocol.packets.OACPacket;
|
||||
import org.openautonomousconnection.protocol.side.client.events.ConnectedToProtocolServer;
|
||||
import org.openautonomousconnection.protocol.side.client.events.ConnectedToProtocolDNSServerEvent;
|
||||
import org.openautonomousconnection.protocol.side.dns.ConnectedProtocolClient;
|
||||
import org.openautonomousconnection.protocol.side.dns.events.ConnectedProtocolClientEvent;
|
||||
import org.openautonomousconnection.protocol.side.web.ConnectedWebClient;
|
||||
@@ -130,7 +130,7 @@ public class AuthPacket extends OACPacket {
|
||||
}
|
||||
|
||||
ProtocolBridge.getInstance().getProtocolClient().setServerVersion(serverVersion);
|
||||
ProtocolBridge.getInstance().getProtocolSettings().eventManager.executeEvent(new ConnectedToProtocolServer());
|
||||
ProtocolBridge.getInstance().getProtocolSettings().eventManager.executeEvent(new ConnectedToProtocolDNSServerEvent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -5,10 +5,10 @@ import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||
import org.openautonomousconnection.protocol.packets.OACPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.UnsupportedClassicPacket;
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.Classic_Domain;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.Classic_DomainPacketReceivedEvent;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.Classic_ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.Classic_RequestDomain;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.events.Classic_DomainPacketReceivedEvent;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_RequestDomain;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
|
@@ -4,7 +4,7 @@ import dev.unlegitdqrk.unlegitlibrary.network.system.packets.PacketHandler;
|
||||
import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||
import org.openautonomousconnection.protocol.packets.OACPacket;
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.Classic_ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
|
@@ -6,10 +6,10 @@ import org.openautonomousconnection.protocol.packets.OACPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.UnsupportedClassicPacket;
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.DNSResponseCode;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.Classic_Domain;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.Classic_PingPacketReceivedEvent;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.Classic_ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.Classic_RequestDomain;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.events.Classic_PingPacketReceivedEvent;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_RequestDomain;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
|
Reference in New Issue
Block a user