Updated to latest UnlegitLibrary Version
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
package org.openautonomousconnection.protocol.packets;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.system.packets.Packet;
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.system.packets.PacketHandler;
|
||||
import lombok.Getter;
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSResponseStatus;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.*;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Abstract class representing a packet in the Open Autonomous Connection (OAC) protocol.
|
||||
@@ -27,6 +25,13 @@ public abstract class OACPacket extends Packet {
|
||||
*/
|
||||
private INSResponseStatus responseCode = INSResponseStatus.RESPONSE_NOT_REQUIRED;
|
||||
|
||||
private final int id;
|
||||
|
||||
@Override
|
||||
public int getPacketID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for OACPacket.
|
||||
*
|
||||
@@ -34,7 +39,7 @@ public abstract class OACPacket extends Packet {
|
||||
* @param protocolVersion The protocol version associated with this packet.
|
||||
*/
|
||||
public OACPacket(int id, ProtocolVersion protocolVersion) {
|
||||
super(id);
|
||||
this.id = id;
|
||||
this.protocolVersion = protocolVersion;
|
||||
}
|
||||
|
||||
@@ -59,61 +64,54 @@ public abstract class OACPacket extends Packet {
|
||||
/**
|
||||
* 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.
|
||||
* @param outputStream 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 {
|
||||
public final void write(DataOutputStream outputStream) throws IOException {
|
||||
// Write the specific packet data
|
||||
onWrite(packetHandler, objectOutputStream);
|
||||
onWrite(outputStream);
|
||||
|
||||
// Write the response code if the protocol version is not classic
|
||||
if (protocolVersion != ProtocolVersion.PV_1_0_0_CLASSIC) objectOutputStream.writeObject(responseCode);
|
||||
if (protocolVersion != ProtocolVersion.PV_1_0_0_CLASSIC) outputStream.writeUTF(responseCode.name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void read(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||
public final void read(DataInputStream inputStream, UUID clientID) throws IOException {
|
||||
// Read the specific packet data
|
||||
onRead(packetHandler, objectInputStream);
|
||||
onRead(inputStream, clientID);
|
||||
|
||||
// Read the response code if the protocol version is not classic
|
||||
if (protocolVersion != ProtocolVersion.PV_1_0_0_CLASSIC)
|
||||
responseCode = (INSResponseStatus) objectInputStream.readObject();
|
||||
responseCode = INSResponseStatus.valueOf(inputStream.readUTF());
|
||||
else responseCode = INSResponseStatus.RESPONSE_NOT_REQUIRED;
|
||||
|
||||
// Call the response code read handler
|
||||
onResponseCodeRead(packetHandler, objectInputStream);
|
||||
onResponseCodeRead(inputStream, clientID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param outputStream 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;
|
||||
public abstract void onWrite(DataOutputStream outputStream) throws IOException;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param inputStream 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;
|
||||
public abstract void onRead(DataInputStream inputStream, UUID clientID) throws IOException;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param inputStream The input stream from which the response code was read.
|
||||
*/
|
||||
protected void onResponseCodeRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) {
|
||||
protected void onResponseCodeRead(DataInputStream inputStream, UUID clientID) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user