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) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package org.openautonomousconnection.protocol.packets.v1_0_0.beta;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.file.FileUtils;
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.system.packets.PacketHandler;
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.system.server.ConnectionHandler;
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.system.utils.ClientID;
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.system.server.ConnectedClient;
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.system.server.NetworkServer;
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.utils.NetworkUtils;
|
||||
import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||
import org.openautonomousconnection.protocol.packets.OACPacket;
|
||||
@@ -14,18 +13,16 @@ import org.openautonomousconnection.protocol.side.server.events.S_CustomClientCo
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSResponseStatus;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.*;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Authentication packet used between client and INS/Web servers.
|
||||
* <p>
|
||||
* Responsibilities:
|
||||
*
|
||||
* <p>Responsibilities:
|
||||
* <ul>
|
||||
* <li>Client → Server: Sends client ID and protocol version</li>
|
||||
* <li>Server → Client: Sends CA key, CA certificate and CA serial files</li>
|
||||
* <li>Client → Server: Sends client connection id and protocol version</li>
|
||||
* <li>INS Server → Client: Sends CA key, CA certificate and CA serial files</li>
|
||||
* <li>Performs version compatibility validation</li>
|
||||
* <li>Triggers authentication callbacks on both sides</li>
|
||||
* </ul>
|
||||
@@ -45,95 +42,122 @@ public final class AuthPacket extends OACPacket {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registration constructor
|
||||
* Registration constructor.
|
||||
*/
|
||||
public AuthPacket() {
|
||||
super(4, ProtocolVersion.PV_1_0_0_BETA);
|
||||
super(8, ProtocolVersion.PV_1_0_0_BETA);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes authentication data to the output stream.
|
||||
* <p>
|
||||
* Behavior differs based on the running side:
|
||||
* <ul>
|
||||
* <li>INS Server → sends CA bundle to the client</li>
|
||||
* <li>Client → sends client ID + protocol version</li>
|
||||
* </ul>
|
||||
*/
|
||||
@Override
|
||||
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
||||
if (protocolBridge.isRunningAsWebServer()) objectOutputStream.writeObject(protocolBridge.getProtocolVersion());
|
||||
else if (protocolBridge.isRunningAsINSServer()) {
|
||||
objectOutputStream.writeObject(protocolBridge.getProtocolVersion());
|
||||
public void onWrite(DataOutputStream objectOutputStream) throws IOException {
|
||||
if (protocolBridge.isRunningAsWebServer()) {
|
||||
objectOutputStream.writeUTF(protocolBridge.getProtocolVersion().name());
|
||||
return;
|
||||
}
|
||||
|
||||
if (protocolBridge.isRunningAsINSServer()) {
|
||||
objectOutputStream.writeUTF(protocolBridge.getProtocolVersion().name());
|
||||
|
||||
// Read ca files
|
||||
String caKey = "N/A";
|
||||
String caPem = "N/A";
|
||||
String caSrl = "N/A";
|
||||
|
||||
try {
|
||||
objectOutputStream.writeUTF(protocolBridge.getProtocolServer().getFolderStructure().getCaPrefix() + NetworkUtils.getPublicIPAddress());
|
||||
String caPrefix = protocolBridge.getProtocolServer().getFolderStructure().getCaPrefix()
|
||||
+ NetworkUtils.getPublicIPAddress();
|
||||
|
||||
objectOutputStream.writeUTF(caPrefix);
|
||||
|
||||
caKey = FileUtils.readFileFull(new File(
|
||||
protocolBridge.getProtocolServer().getFolderStructure().privateCAFolder,
|
||||
protocolBridge.getProtocolServer().getFolderStructure().getCaPrefix() + NetworkUtils.getPublicIPAddress() + ".key"));
|
||||
caPrefix + ".key"));
|
||||
|
||||
caPem = FileUtils.readFileFull(new File(
|
||||
protocolBridge.getProtocolServer().getFolderStructure().publicCAFolder,
|
||||
protocolBridge.getProtocolServer().getFolderStructure().getCaPrefix() + NetworkUtils.getPublicIPAddress() + ".pem"));
|
||||
caPrefix + ".pem"));
|
||||
|
||||
caSrl = FileUtils.readFileFull(new File(
|
||||
protocolBridge.getProtocolServer().getFolderStructure().publicCAFolder,
|
||||
protocolBridge.getProtocolServer().getFolderStructure().getCaPrefix() + NetworkUtils.getPublicIPAddress() + ".srl"));
|
||||
caPrefix + ".srl"));
|
||||
} catch (Exception exception) {
|
||||
protocolBridge.getLogger().exception("Failed to read ca-files", exception);
|
||||
setResponseCode(INSResponseStatus.RESPONSE_AUTH_FAILED);
|
||||
}
|
||||
|
||||
// Send ca data
|
||||
objectOutputStream.writeUTF(caKey);
|
||||
objectOutputStream.writeUTF(caPem);
|
||||
objectOutputStream.writeUTF(caSrl);
|
||||
} else if (protocolBridge.isRunningAsClient()) {
|
||||
objectOutputStream.writeObject(protocolBridge.getProtocolClient().getClientINSConnection().getClientId());
|
||||
objectOutputStream.writeObject(protocolBridge.getProtocolVersion());
|
||||
return;
|
||||
}
|
||||
|
||||
if (protocolBridge.isRunningAsClient()) {
|
||||
// FIX: Send the connection id of the connection this auth is meant for.
|
||||
// If we are connecting/authing against INS, use INS connectionId.
|
||||
// Otherwise use Server connectionId.
|
||||
UUID clientConnectionId = null;
|
||||
|
||||
if (protocolBridge.getProtocolClient() != null) {
|
||||
if (protocolBridge.getProtocolClient().getClientINSConnection() != null
|
||||
&& (protocolBridge.getProtocolClient().getClientServerConnection() == null)) {
|
||||
clientConnectionId = protocolBridge.getProtocolClient().getClientINSConnection().getUniqueID();
|
||||
} else if (protocolBridge.getProtocolClient().getClientServerConnection() != null) {
|
||||
clientConnectionId = protocolBridge.getProtocolClient().getClientServerConnection().getUniqueID();
|
||||
} else if (protocolBridge.getProtocolClient().getClientINSConnection() != null) {
|
||||
clientConnectionId = protocolBridge.getProtocolClient().getClientINSConnection().getUniqueID();
|
||||
}
|
||||
}
|
||||
|
||||
objectOutputStream.writeUTF(clientConnectionId.toString());
|
||||
objectOutputStream.writeUTF(protocolBridge.getProtocolVersion().name());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads authentication data and updates protocol state.
|
||||
* <p>
|
||||
* Behavior:
|
||||
* <ul>
|
||||
* <li>Server validates version and registers new connected client</li>
|
||||
* <li>Client saves received CA files and completes TLS initialization</li>
|
||||
* </ul>
|
||||
*/
|
||||
@Override
|
||||
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||
public void onRead(DataInputStream objectInputStream, UUID id) throws IOException {
|
||||
if (protocolBridge.isRunningAsServer()) {
|
||||
ClientID clientID = (ClientID) objectInputStream.readObject();
|
||||
ProtocolVersion clientVersion = (ProtocolVersion) objectInputStream.readObject();
|
||||
ConnectionHandler connectionHandler = protocolBridge.getProtocolServer().getNetwork().getConnectionHandlerByClientId(clientID);
|
||||
UUID clientID = UUID.fromString(objectInputStream.readUTF());
|
||||
ProtocolVersion clientVersion = ProtocolVersion.valueOf(objectInputStream.readUTF());
|
||||
|
||||
ConnectedClient connectionHandler = getConnection(protocolBridge.getProtocolServer().getNetwork(), clientID);
|
||||
if (connectionHandler == null) {
|
||||
setResponseCode(INSResponseStatus.RESPONSE_AUTH_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!protocolBridge.isVersionSupported(clientVersion)) {
|
||||
setResponseCode(INSResponseStatus.RESPONSE_AUTH_FAILED);
|
||||
connectionHandler.disconnect();
|
||||
try {
|
||||
connectionHandler.disconnect();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
return;
|
||||
} else setResponseCode(INSResponseStatus.RESPONSE_AUTH_SUCCESS);
|
||||
}
|
||||
|
||||
setResponseCode(INSResponseStatus.RESPONSE_AUTH_SUCCESS);
|
||||
|
||||
CustomConnectedClient client = protocolBridge.getProtocolServer().getClientByID(clientID);
|
||||
client.setClientVersion(clientVersion);
|
||||
protocolBridge.getProtocolValues().eventManager.executeEvent(new S_CustomClientConnectedEvent(client));
|
||||
} else if (protocolBridge.isRunningAsClient()) {
|
||||
ProtocolVersion serverVersion = (ProtocolVersion) objectInputStream.readObject();
|
||||
if (client != null) {
|
||||
client.setClientVersion(clientVersion);
|
||||
protocolBridge.getProtocolValues().eventManager.executeEvent(new S_CustomClientConnectedEvent(client));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (protocolBridge.isRunningAsClient()) {
|
||||
ProtocolVersion serverVersion = ProtocolVersion.valueOf(objectInputStream.readUTF());
|
||||
|
||||
try {
|
||||
if (!protocolBridge.isVersionSupported(serverVersion)) {
|
||||
setResponseCode(INSResponseStatus.RESPONSE_AUTH_FAILED);
|
||||
protocolBridge.getProtocolClient().getClientINSConnection().disconnect();
|
||||
if (protocolBridge.getProtocolClient() != null
|
||||
&& protocolBridge.getProtocolClient().getClientINSConnection() != null) {
|
||||
protocolBridge.getProtocolClient().getClientINSConnection().disconnect();
|
||||
}
|
||||
return;
|
||||
} else setResponseCode(INSResponseStatus.RESPONSE_AUTH_SUCCESS);
|
||||
}
|
||||
|
||||
setResponseCode(INSResponseStatus.RESPONSE_AUTH_SUCCESS);
|
||||
|
||||
String caPrefix = objectInputStream.readUTF();
|
||||
|
||||
@@ -141,10 +165,9 @@ public final class AuthPacket extends OACPacket {
|
||||
String caPem = objectInputStream.readUTF();
|
||||
String caSrl = objectInputStream.readUTF();
|
||||
|
||||
if (caKey.equalsIgnoreCase("N/A") || caPem.equalsIgnoreCase("N/A") || caSrl.equalsIgnoreCase("N/A"))
|
||||
if (caKey.equalsIgnoreCase("N/A") || caPem.equalsIgnoreCase("N/A") || caSrl.equalsIgnoreCase("N/A")) {
|
||||
setResponseCode(INSResponseStatus.RESPONSE_AUTH_FAILED);
|
||||
else {
|
||||
|
||||
} else {
|
||||
File caPemFile = new File(protocolBridge.getProtocolClient().getFolderStructure().publicCAFolder, caPrefix + ".pem");
|
||||
File caSrlFile = new File(protocolBridge.getProtocolClient().getFolderStructure().publicCAFolder, caPrefix + ".srl");
|
||||
File caKeyFile = new File(protocolBridge.getProtocolClient().getFolderStructure().privateCAFolder, caPrefix + ".key");
|
||||
@@ -154,9 +177,10 @@ public final class AuthPacket extends OACPacket {
|
||||
if (!caSrlFile.exists()) caSrlFile.createNewFile();
|
||||
if (!caKeyFile.exists()) caKeyFile.createNewFile();
|
||||
|
||||
// FIX: Correct file assignments.
|
||||
FileUtils.writeFile(caPemFile, caPem);
|
||||
FileUtils.writeFile(caSrlFile, caKey);
|
||||
FileUtils.writeFile(caKeyFile, caSrl);
|
||||
FileUtils.writeFile(caSrlFile, caSrl);
|
||||
FileUtils.writeFile(caKeyFile, caKey);
|
||||
} catch (Exception exception) {
|
||||
protocolBridge.getLogger().exception("Failed to create/save ca-files", exception);
|
||||
setResponseCode(INSResponseStatus.RESPONSE_AUTH_FAILED);
|
||||
@@ -164,11 +188,27 @@ public final class AuthPacket extends OACPacket {
|
||||
}
|
||||
|
||||
protocolBridge.getProtocolClient().setInsVersion(serverVersion);
|
||||
protocolBridge.getProtocolValues().eventManager.executeEvent(new ConnectedToProtocolINSServerEvent(protocolBridge.getProtocolClient()));
|
||||
protocolBridge.getProtocolValues().eventManager.executeEvent(
|
||||
new ConnectedToProtocolINSServerEvent(protocolBridge.getProtocolClient())
|
||||
);
|
||||
} catch (Exception ignored) {
|
||||
protocolBridge.getProtocolClient().setServerVersion(serverVersion);
|
||||
protocolBridge.getProtocolValues().eventManager.executeEvent(new ConnectedToProtocolServerEvent(protocolBridge.getProtocolClient()));
|
||||
protocolBridge.getProtocolValues().eventManager.executeEvent(
|
||||
new ConnectedToProtocolServerEvent(protocolBridge.getProtocolClient())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ConnectedClient getConnection(NetworkServer server, UUID connectionId) {
|
||||
if (server == null || connectionId == null) return null;
|
||||
|
||||
for (ConnectedClient connection : server.getConnectedClients()) {
|
||||
if (connection != null && connection.getUniqueID().equals(connectionId)) {
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
package org.openautonomousconnection.protocol.packets.v1_0_0.beta;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.system.packets.PacketHandler;
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.system.utils.ClientID;
|
||||
import lombok.Getter;
|
||||
import org.openautonomousconnection.protocol.packets.OACPacket;
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSRecordType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.*;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Packet used by clients to query INS records from an INS server.
|
||||
@@ -34,7 +31,7 @@ public final class INSQueryPacket extends OACPacket {
|
||||
@Getter
|
||||
private INSRecordType type;
|
||||
@Getter
|
||||
private ClientID clientId;
|
||||
private UUID clientId;
|
||||
|
||||
/**
|
||||
* Creates a new INS query packet with all required parameters.
|
||||
@@ -45,8 +42,8 @@ public final class INSQueryPacket extends OACPacket {
|
||||
* @param type Record type requested.
|
||||
* @param clientId Sender client ID for routing.
|
||||
*/
|
||||
public INSQueryPacket(String tln, String name, String sub, INSRecordType type, ClientID clientId) {
|
||||
super(5, ProtocolVersion.PV_1_0_0_BETA);
|
||||
public INSQueryPacket(String tln, String name, String sub, INSRecordType type, UUID clientId) {
|
||||
super(7, ProtocolVersion.PV_1_0_0_BETA);
|
||||
this.TLN = tln;
|
||||
this.name = name;
|
||||
this.sub = sub;
|
||||
@@ -58,36 +55,36 @@ public final class INSQueryPacket extends OACPacket {
|
||||
* Registration constructor
|
||||
*/
|
||||
public INSQueryPacket() {
|
||||
super(5, ProtocolVersion.PV_1_0_0_BETA);
|
||||
super(7, ProtocolVersion.PV_1_0_0_BETA);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the INS query into the stream.
|
||||
*/
|
||||
@Override
|
||||
public void onWrite(PacketHandler handler, ObjectOutputStream out) throws IOException {
|
||||
public void onWrite(DataOutputStream out) throws IOException {
|
||||
out.writeUTF(TLN);
|
||||
out.writeUTF(name);
|
||||
|
||||
out.writeBoolean(sub != null);
|
||||
if (sub != null) out.writeUTF(sub);
|
||||
|
||||
out.writeObject(type);
|
||||
out.writeObject(clientId);
|
||||
out.writeUTF(type.name());
|
||||
out.writeUTF(clientId.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the INS query from the stream.
|
||||
*/
|
||||
@Override
|
||||
public void onRead(PacketHandler handler, ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
public void onRead(DataInputStream in, UUID clientID) throws IOException {
|
||||
TLN = in.readUTF();
|
||||
name = in.readUTF();
|
||||
|
||||
boolean hasSub = in.readBoolean();
|
||||
sub = hasSub ? in.readUTF() : null;
|
||||
|
||||
type = (INSRecordType) in.readObject();
|
||||
clientId = (ClientID) in.readObject();
|
||||
type = INSRecordType.valueOf(in.readUTF());
|
||||
clientId = UUID.fromString(in.readUTF());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.openautonomousconnection.protocol.packets.v1_0_0.beta;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.system.packets.PacketHandler;
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.system.utils.ClientID;
|
||||
import lombok.Getter;
|
||||
import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||
import org.openautonomousconnection.protocol.packets.OACPacket;
|
||||
@@ -9,11 +7,10 @@ import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSRecord;
|
||||
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.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Response packet returned by an INS server after resolving a query.
|
||||
@@ -36,7 +33,7 @@ public final class INSResponsePacket extends OACPacket {
|
||||
@Getter
|
||||
private List<INSRecord> records;
|
||||
@Getter
|
||||
private ClientID clientId;
|
||||
private UUID clientId;
|
||||
|
||||
/**
|
||||
* Creates a populated response packet.
|
||||
@@ -46,7 +43,7 @@ public final class INSResponsePacket extends OACPacket {
|
||||
* @param clientId ID of requesting client.
|
||||
* @param bridge Protocol runtime context.
|
||||
*/
|
||||
public INSResponsePacket(INSResponseStatus status, List<INSRecord> records, ClientID clientId, ProtocolBridge bridge) {
|
||||
public INSResponsePacket(INSResponseStatus status, List<INSRecord> records, UUID clientId, ProtocolBridge bridge) {
|
||||
super(6, ProtocolVersion.PV_1_0_0_BETA);
|
||||
this.status = status;
|
||||
this.records = records;
|
||||
@@ -68,32 +65,32 @@ public final class INSResponsePacket extends OACPacket {
|
||||
* Serializes the response status, records and client ID.
|
||||
*/
|
||||
@Override
|
||||
public void onWrite(PacketHandler handler, ObjectOutputStream out) throws IOException {
|
||||
out.writeObject(status);
|
||||
public void onWrite(DataOutputStream out) throws IOException {
|
||||
out.writeUTF(status.name());
|
||||
out.writeInt(records.size());
|
||||
|
||||
for (INSRecord rec : records) {
|
||||
out.writeObject(rec);
|
||||
writeObject(out, rec);
|
||||
}
|
||||
|
||||
out.writeObject(clientId);
|
||||
out.writeUTF(clientId.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the response, reconstructing the record list.
|
||||
*/
|
||||
@Override
|
||||
public void onRead(PacketHandler handler, ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
status = (INSResponseStatus) in.readObject();
|
||||
public void onRead(DataInputStream in, UUID clientID) throws IOException {
|
||||
status = INSResponseStatus.valueOf(in.readUTF());
|
||||
|
||||
int size = in.readInt();
|
||||
records = new ArrayList<>(size);
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
records.add((INSRecord) in.readObject());
|
||||
records.add((INSRecord) readObject(in));
|
||||
}
|
||||
|
||||
clientId = (ClientID) in.readObject();
|
||||
clientId = UUID.fromString(in.readUTF());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +99,7 @@ public final class INSResponsePacket extends OACPacket {
|
||||
* If running on a client, forwards the result to the client-side API.
|
||||
*/
|
||||
@Override
|
||||
protected void onResponseCodeRead(PacketHandler handler, ObjectInputStream in) {
|
||||
protected void onResponseCodeRead(DataInputStream in, UUID clientID) {
|
||||
if (bridge.isRunningAsClient()) {
|
||||
bridge.getProtocolClient().onResponse(status, records);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
package org.openautonomousconnection.protocol.packets.v1_0_0.beta.web;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.system.packets.PacketHandler;
|
||||
import lombok.Getter;
|
||||
import org.openautonomousconnection.protocol.packets.OACPacket;
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.WebRequestMethod;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.*;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class WebRequestPacket extends OACPacket {
|
||||
|
||||
@@ -26,11 +24,11 @@ public final class WebRequestPacket extends OACPacket {
|
||||
private byte[] body;
|
||||
|
||||
public WebRequestPacket() {
|
||||
super(8, ProtocolVersion.PV_1_0_0_BETA);
|
||||
super(10, ProtocolVersion.PV_1_0_0_BETA);
|
||||
}
|
||||
|
||||
public WebRequestPacket(String path, WebRequestMethod method, Map<String, String> headers, byte[] body) {
|
||||
super(8, ProtocolVersion.PV_1_0_0_BETA);
|
||||
super(10, ProtocolVersion.PV_1_0_0_BETA);
|
||||
this.path = path;
|
||||
this.method = method;
|
||||
this.headers = headers;
|
||||
@@ -38,10 +36,10 @@ public final class WebRequestPacket extends OACPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWrite(PacketHandler handler, ObjectOutputStream out) throws IOException {
|
||||
public void onWrite(DataOutputStream out) throws IOException {
|
||||
out.writeUTF(path != null ? path : "/");
|
||||
out.writeUTF(method != null ? method.name() : WebRequestMethod.GET.name());
|
||||
out.writeObject(headers);
|
||||
writeMap(out, headers);
|
||||
|
||||
if (body == null) body = new byte[0];
|
||||
out.writeInt(body.length);
|
||||
@@ -50,10 +48,10 @@ public final class WebRequestPacket extends OACPacket {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void onRead(PacketHandler handler, ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
public void onRead(DataInputStream in, UUID clientID) throws IOException {
|
||||
this.path = in.readUTF();
|
||||
this.method = WebRequestMethod.valueOf(in.readUTF());
|
||||
this.headers = (Map<String, String>) in.readObject();
|
||||
this.headers = (Map<String, String>) readMap(in);
|
||||
|
||||
int len = in.readInt();
|
||||
if (len < 0) {
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package org.openautonomousconnection.protocol.packets.v1_0_0.beta.web;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.system.packets.PacketHandler;
|
||||
import lombok.Getter;
|
||||
import org.openautonomousconnection.protocol.packets.OACPacket;
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.*;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class WebResponsePacket extends OACPacket {
|
||||
|
||||
@@ -37,10 +35,10 @@ public final class WebResponsePacket extends OACPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWrite(PacketHandler handler, ObjectOutputStream out) throws IOException {
|
||||
public void onWrite(DataOutputStream out) throws IOException {
|
||||
out.writeInt(statusCode);
|
||||
out.writeUTF(contentType != null ? contentType : "text/plain");
|
||||
out.writeObject(headers);
|
||||
writeMap(out, headers);
|
||||
|
||||
if (body == null) body = new byte[0];
|
||||
out.writeInt(body.length);
|
||||
@@ -48,10 +46,10 @@ public final class WebResponsePacket extends OACPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRead(PacketHandler handler, ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
public void onRead(DataInputStream in, UUID clientID) throws IOException {
|
||||
this.statusCode = in.readInt();
|
||||
this.contentType = in.readUTF();
|
||||
this.headers = (Map<String, String>) in.readObject();
|
||||
this.headers = (Map<String, String>) readMap(in);
|
||||
|
||||
int len = in.readInt();
|
||||
if (len < 0) {
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.stream;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.system.packets.PacketHandler;
|
||||
import lombok.Getter;
|
||||
import org.openautonomousconnection.protocol.packets.OACPacket;
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.*;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class WebStreamChunkPacket extends OACPacket {
|
||||
|
||||
@@ -17,24 +15,24 @@ public final class WebStreamChunkPacket extends OACPacket {
|
||||
private byte[] data;
|
||||
|
||||
public WebStreamChunkPacket() {
|
||||
super(11, ProtocolVersion.PV_1_0_0_BETA);
|
||||
super(13, ProtocolVersion.PV_1_0_0_BETA);
|
||||
}
|
||||
|
||||
public WebStreamChunkPacket(int seq, byte[] data) {
|
||||
super(11, ProtocolVersion.PV_1_0_0_BETA);
|
||||
super(13, ProtocolVersion.PV_1_0_0_BETA);
|
||||
this.seq = seq;
|
||||
this.data = (data != null) ? data : new byte[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWrite(PacketHandler handler, ObjectOutputStream out) throws IOException {
|
||||
public void onWrite(DataOutputStream out) throws IOException {
|
||||
out.writeInt(seq);
|
||||
out.writeInt(data.length);
|
||||
out.write(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRead(PacketHandler handler, ObjectInputStream in) throws IOException {
|
||||
public void onRead(DataInputStream in, UUID clientID) throws IOException {
|
||||
seq = in.readInt();
|
||||
int len = in.readInt();
|
||||
if (len < 0) throw new IOException("Negative chunk length");
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.stream;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.system.packets.PacketHandler;
|
||||
import lombok.Getter;
|
||||
import org.openautonomousconnection.protocol.packets.OACPacket;
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.*;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class WebStreamEndPacket extends OACPacket {
|
||||
|
||||
@@ -24,12 +22,12 @@ public final class WebStreamEndPacket extends OACPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWrite(PacketHandler handler, ObjectOutputStream out) throws IOException {
|
||||
public void onWrite(DataOutputStream out) throws IOException {
|
||||
out.writeBoolean(ok);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRead(PacketHandler handler, ObjectInputStream in) throws IOException {
|
||||
public void onRead(DataInputStream in, UUID clientID) throws IOException {
|
||||
ok = in.readBoolean();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.stream;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.system.packets.PacketHandler;
|
||||
import lombok.Getter;
|
||||
import org.openautonomousconnection.protocol.packets.OACPacket;
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.*;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class WebStreamStartPacket extends OACPacket {
|
||||
|
||||
@@ -22,11 +20,11 @@ public final class WebStreamStartPacket extends OACPacket {
|
||||
private long totalLength;
|
||||
|
||||
public WebStreamStartPacket() {
|
||||
super(10, ProtocolVersion.PV_1_0_0_BETA);
|
||||
super(11, ProtocolVersion.PV_1_0_0_BETA);
|
||||
}
|
||||
|
||||
public WebStreamStartPacket(int statusCode, String contentType, Map<String, String> headers, long totalLength) {
|
||||
super(10, ProtocolVersion.PV_1_0_0_BETA);
|
||||
super(11, ProtocolVersion.PV_1_0_0_BETA);
|
||||
this.statusCode = statusCode;
|
||||
this.contentType = contentType;
|
||||
this.headers = headers;
|
||||
@@ -34,19 +32,19 @@ public final class WebStreamStartPacket extends OACPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWrite(PacketHandler handler, ObjectOutputStream out) throws IOException {
|
||||
public void onWrite(DataOutputStream out) throws IOException {
|
||||
out.writeInt(statusCode);
|
||||
out.writeUTF(contentType != null ? contentType : "application/octet-stream");
|
||||
out.writeObject(headers);
|
||||
writeMap(out, headers);
|
||||
out.writeLong(totalLength);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void onRead(PacketHandler handler, ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
public void onRead(DataInputStream in, UUID clientID) throws IOException {
|
||||
statusCode = in.readInt();
|
||||
contentType = in.readUTF();
|
||||
headers = (Map<String, String>) in.readObject();
|
||||
headers = (Map<String, String>) readMap(in);
|
||||
totalLength = in.readLong();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user