Introduce 1.0.1-BETA packet model with 1.0.0-BETA backwards compatibility
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package org.openautonomousconnection.protocol;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.addon.AddonLoader;
|
||||
import dev.unlegitdqrk.unlegitlibrary.file.FileUtils;
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.system.utils.ClientAuthMode;
|
||||
import dev.unlegitdqrk.unlegitlibrary.utils.Logger;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
|
||||
import org.openautonomousconnection.protocol.listeners.ClientListener;
|
||||
import org.openautonomousconnection.protocol.listeners.CustomServerListener;
|
||||
@@ -14,18 +14,28 @@ import org.openautonomousconnection.protocol.packets.v1_0_0.beta.INSQueryPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.INSResponsePacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.WebRequestPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.WebResponsePacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.stream.WebStreamChunkPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.stream.WebStreamEndPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.stream.WebStreamStartPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.stream.WebStreamChunkPacket_v1_0_0_B;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.stream.WebStreamEndPacket_v1_0_0_B;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.stream.WebStreamStartPacket_v1_0_0_B;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.document.WebDocumentApplyRequestPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.document.WebDocumentApplyResponsePacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.document.WebDocumentSnapshotEventPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.navigate.WebNavigateAckPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.navigate.WebNavigateRequestPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.resource.WebResourceRequestPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.resource.WebResourceResponsePacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.stream.WebStreamChunkPacket_v1_0_1_B;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.stream.WebStreamEndPacket_v1_0_1_B;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.stream.WebStreamStartPacket_v1_0_1_B;
|
||||
import org.openautonomousconnection.protocol.side.client.ProtocolClient;
|
||||
import org.openautonomousconnection.protocol.side.ins.ProtocolINSServer;
|
||||
import org.openautonomousconnection.protocol.side.server.ProtocolCustomServer;
|
||||
import org.openautonomousconnection.protocol.side.web.ProtocolWebServer;
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.ProtocolWebServer_1_0_0_B;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.Proxy;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* The main bridge class for the protocol connection.
|
||||
@@ -63,12 +73,8 @@ public final class ProtocolBridge {
|
||||
@Getter
|
||||
private ProtocolCustomServer protocolServer;
|
||||
|
||||
/**
|
||||
* The proxy for client side
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
private Proxy proxy;
|
||||
private AddonLoader addonLoader;
|
||||
|
||||
/**
|
||||
* Initialize the ProtocolBridge instance for the client side
|
||||
@@ -76,24 +82,25 @@ public final class ProtocolBridge {
|
||||
* @param protocolServer The ProtocolCustomServer instance
|
||||
* @param protocolValues The ProtocolSettings instance
|
||||
* @param protocolVersion The ProtocolVersion instance
|
||||
* @param logFolder The folder to store the log files
|
||||
* @param logger The logger
|
||||
* @param addonLoader The Addon loader to load custom extensions
|
||||
* @throws Exception if an error occurs while initializing the ProtocolBridge
|
||||
*/
|
||||
public ProtocolBridge(ProtocolCustomServer protocolServer, ProtocolValues protocolValues, ProtocolVersion protocolVersion, File logFolder) throws Exception {
|
||||
public ProtocolBridge(ProtocolCustomServer protocolServer, ProtocolValues protocolValues, ProtocolVersion protocolVersion,
|
||||
Logger logger, AddonLoader addonLoader) throws Exception {
|
||||
// Assign the parameters to the class fields
|
||||
this.protocolServer = protocolServer;
|
||||
this.protocolValues = protocolValues;
|
||||
this.protocolVersion = protocolVersion;
|
||||
this.logger = logger;
|
||||
this.addonLoader = addonLoader;
|
||||
|
||||
if (protocolServer instanceof ProtocolINSServer) {
|
||||
if (protocolServer instanceof ProtocolINSServer)
|
||||
protocolServer.attachBridge(this, null, false, ClientAuthMode.NONE);
|
||||
} else
|
||||
else
|
||||
protocolServer.attachBridge(this, protocolValues.keyPass, protocolValues.ssl, protocolValues.authMode);
|
||||
|
||||
// Initialize the logger and protocol version
|
||||
initializeLogger(logFolder);
|
||||
initializeProtocolVersion();
|
||||
|
||||
downloadLicenses();
|
||||
|
||||
// Register the appropriate listeners and packets
|
||||
@@ -107,23 +114,24 @@ public final class ProtocolBridge {
|
||||
* @param protocolClient The ProtocolClient instance
|
||||
* @param protocolValues The ProtocolSettings instance
|
||||
* @param protocolVersion The ProtocolVersion instance
|
||||
* @param logFolder The folder to store the log files
|
||||
* @param logger The logger
|
||||
* @param addonLoader The Addon loader to load custom extensions
|
||||
* @throws Exception if an error occurs while initializing the ProtocolBridge
|
||||
*/
|
||||
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.CLIENT)
|
||||
public ProtocolBridge(ProtocolClient protocolClient, ProtocolValues protocolValues, ProtocolVersion protocolVersion, File logFolder) throws Exception {
|
||||
public ProtocolBridge(ProtocolClient protocolClient, ProtocolValues protocolValues, ProtocolVersion protocolVersion,
|
||||
Logger logger, AddonLoader addonLoader) throws Exception {
|
||||
// Assign the parameters to the class fields
|
||||
this.protocolClient = protocolClient;
|
||||
this.protocolValues = protocolValues;
|
||||
this.protocolVersion = protocolVersion;
|
||||
this.logger = logger;
|
||||
this.addonLoader = addonLoader;
|
||||
|
||||
protocolClient.attachBridge(this);
|
||||
|
||||
initializeProtocolVersion();
|
||||
downloadLicenses();
|
||||
|
||||
// Initialize the logger and protocol version
|
||||
initializeLogger(logFolder);
|
||||
initializeProtocolVersion();
|
||||
|
||||
// Register the appropriate listeners and packets
|
||||
registerListeners();
|
||||
@@ -132,8 +140,10 @@ public final class ProtocolBridge {
|
||||
|
||||
private void downloadLicenses() throws IOException {
|
||||
File licensesFolder = new File("licenses");
|
||||
|
||||
if (!licensesFolder.exists() || !licensesFolder.isDirectory()) {
|
||||
if (licensesFolder.exists()) licensesFolder.delete();
|
||||
|
||||
File output = new File("licenses.zip");
|
||||
output.createNewFile();
|
||||
FileUtils.downloadFile("https://open-autonomous-connection.org/assets/licenses.zip", output);
|
||||
@@ -143,27 +153,63 @@ public final class ProtocolBridge {
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the appropriate packets based on the current protocol version
|
||||
* Register the appropriate packets
|
||||
*
|
||||
* <p>Overview of all Packets
|
||||
*
|
||||
* <table border="2">
|
||||
* <tr><th>ID</th><th>Packet</th><th>ProtocolVersion</th></tr>
|
||||
*
|
||||
* <tr><td>8</td><td>{@link org.openautonomousconnection.protocol.packets.v1_0_0.beta.AuthPacket AuthPacket}</td><td>{@link org.openautonomousconnection.protocol.versions.ProtocolVersion#PV_1_0_0_BETA PV_1_0_0_BETA}</td></tr>
|
||||
* <tr><td>7</td><td>{@link org.openautonomousconnection.protocol.packets.v1_0_0.beta.INSQueryPacket INSQueryPacket}</td><td>{@link org.openautonomousconnection.protocol.versions.ProtocolVersion#PV_1_0_0_BETA PV_1_0_0_BETA}</td></tr>
|
||||
* <tr><td>6</td><td>{@link org.openautonomousconnection.protocol.packets.v1_0_0.beta.INSResponsePacket INSResponsePacket}</td><td>{@link org.openautonomousconnection.protocol.versions.ProtocolVersion#PV_1_0_0_BETA PV_1_0_0_BETA}</td></tr>
|
||||
* <tr><td>10</td><td>{@link org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.WebRequestPacket WebRequestPacket}</td><td>{@link org.openautonomousconnection.protocol.versions.ProtocolVersion#PV_1_0_0_BETA PV_1_0_0_BETA}</td></tr>
|
||||
* <tr><td>9</td><td>{@link org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.WebResponsePacket WebResponsePacket}</td><td>{@link org.openautonomousconnection.protocol.versions.ProtocolVersion#PV_1_0_0_BETA PV_1_0_0_BETA}</td></tr>
|
||||
* <tr><td>11</td><td>{@link WebStreamStartPacket_v1_0_0_B v1_0_0.beta.web.stream.WebStreamStartPacket}</td><td>{@link org.openautonomousconnection.protocol.versions.ProtocolVersion#PV_1_0_0_BETA PV_1_0_0_BETA}</td></tr>
|
||||
* <tr><td>13</td><td>{@link WebStreamChunkPacket_v1_0_0_B v1_0_0.beta.web.stream.WebStreamChunkPacket}</td><td>{@link org.openautonomousconnection.protocol.versions.ProtocolVersion#PV_1_0_0_BETA PV_1_0_0_BETA}</td></tr>
|
||||
* <tr><td>12</td><td>{@link WebStreamEndPacket_v1_0_0_B v1_0_0.beta.web.stream.WebStreamEndPacket}</td><td>{@link org.openautonomousconnection.protocol.versions.ProtocolVersion#PV_1_0_0_BETA PV_1_0_0_BETA}</td></tr>
|
||||
*
|
||||
* <tr><td>1</td><td>{@link org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.navigate.WebNavigateRequestPacket WebNavigateRequestPacket}</td><td>{@link org.openautonomousconnection.protocol.versions.ProtocolVersion#PV_1_0_1_BETA PV_1_0_1_BETA}</td></tr>
|
||||
* <tr><td>2</td><td>{@link org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.navigate.WebNavigateAckPacket WebNavigateAckPacket}</td><td>{@link org.openautonomousconnection.protocol.versions.ProtocolVersion#PV_1_0_1_BETA PV_1_0_1_BETA}</td></tr>
|
||||
* <tr><td>3</td><td>{@link org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.resource.WebResourceRequestPacket WebResourceRequestPacket}</td><td>{@link org.openautonomousconnection.protocol.versions.ProtocolVersion#PV_1_0_1_BETA PV_1_0_1_BETA}</td></tr>
|
||||
* <tr><td>4</td><td>{@link org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.resource.WebResourceResponsePacket WebResourceResponsePacket}</td><td>{@link org.openautonomousconnection.protocol.versions.ProtocolVersion#PV_1_0_1_BETA PV_1_0_1_BETA}</td></tr>
|
||||
* <tr><td>14</td><td>{@link WebStreamStartPacket_v1_0_1_B v1_0_1.beta.web.impl.stream.WebStreamStartPacket}</td><td>{@link org.openautonomousconnection.protocol.versions.ProtocolVersion#PV_1_0_1_BETA PV_1_0_1_BETA}</td></tr>
|
||||
* <tr><td>15</td><td>{@link WebStreamChunkPacket_v1_0_1_B v1_0_1.beta.web.impl.stream.WebStreamChunkPacket}</td><td>{@link org.openautonomousconnection.protocol.versions.ProtocolVersion#PV_1_0_1_BETA PV_1_0_1_BETA}</td></tr>
|
||||
* <tr><td>16</td><td>{@link WebStreamEndPacket_v1_0_1_B v1_0_1.beta.web.impl.stream.WebStreamEndPacket}</td><td>{@link org.openautonomousconnection.protocol.versions.ProtocolVersion#PV_1_0_1_BETA PV_1_0_1_BETA}</td></tr>
|
||||
* <tr><td>17</td><td>{@link org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.document.WebDocumentSnapshotEventPacket WebDocumentSnapshotEventPacket}</td><td>{@link org.openautonomousconnection.protocol.versions.ProtocolVersion#PV_1_0_1_BETA PV_1_0_1_BETA}</td></tr>
|
||||
* <tr><td>5</td><td>{@link org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.document.WebDocumentApplyResponsePacket WebDocumentApplyResponsePacket}</td><td>{@link org.openautonomousconnection.protocol.versions.ProtocolVersion#PV_1_0_1_BETA PV_1_0_1_BETA}</td></tr>
|
||||
* <tr><td>18</td><td>{@link org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.document.WebDocumentApplyRequestPacket WebDocumentApplyRequestPacket}</td><td>{@link org.openautonomousconnection.protocol.versions.ProtocolVersion#PV_1_0_1_BETA PV_1_0_1_BETA}</td></tr>
|
||||
* </table>
|
||||
*
|
||||
* @see org.openautonomousconnection.protocol.versions.ProtocolVersion
|
||||
*/
|
||||
private void registerPackets() {
|
||||
// 1.0.0-BETA packets
|
||||
if (isPacketSupported(new AuthPacket(this)))
|
||||
protocolValues.packetHandler.registerPacket(() -> new AuthPacket(this));
|
||||
if (isPacketSupported(new INSQueryPacket())) protocolValues.packetHandler.registerPacket(INSQueryPacket::new);
|
||||
if (isPacketSupported(new INSResponsePacket(this)))
|
||||
protocolValues.packetHandler.registerPacket(() -> new INSResponsePacket(this));
|
||||
if (isPacketSupported(new WebRequestPacket()))
|
||||
protocolValues.packetHandler.registerPacket(WebRequestPacket::new);
|
||||
if (isPacketSupported(new WebResponsePacket()))
|
||||
protocolValues.packetHandler.registerPacket(WebResponsePacket::new);
|
||||
if (isPacketSupported(new WebStreamChunkPacket()))
|
||||
protocolValues.packetHandler.registerPacket(WebStreamChunkPacket::new);
|
||||
if (isPacketSupported(new WebStreamStartPacket()))
|
||||
protocolValues.packetHandler.registerPacket(WebStreamStartPacket::new);
|
||||
if (isPacketSupported(new WebStreamEndPacket()))
|
||||
protocolValues.packetHandler.registerPacket(WebStreamEndPacket::new);
|
||||
registerPacket(AuthPacket::new);
|
||||
registerPacket(INSQueryPacket::new);
|
||||
registerPacket(() -> new INSResponsePacket(this));
|
||||
registerPacket(WebRequestPacket::new);
|
||||
registerPacket(WebResponsePacket::new);
|
||||
registerPacket(WebStreamStartPacket_v1_0_0_B::new);
|
||||
registerPacket(WebStreamChunkPacket_v1_0_0_B::new);
|
||||
registerPacket(WebStreamEndPacket_v1_0_0_B::new);
|
||||
|
||||
// 1.0.1-BETA Packets
|
||||
registerPacket(WebDocumentApplyRequestPacket::new);
|
||||
registerPacket(WebDocumentApplyResponsePacket::new);
|
||||
registerPacket(WebDocumentSnapshotEventPacket::new);
|
||||
registerPacket(WebNavigateRequestPacket::new);
|
||||
registerPacket(WebNavigateAckPacket::new);
|
||||
registerPacket(WebResourceRequestPacket::new);
|
||||
registerPacket(WebResourceResponsePacket::new);
|
||||
registerPacket(WebStreamStartPacket_v1_0_1_B::new);
|
||||
registerPacket(WebStreamChunkPacket_v1_0_1_B::new);
|
||||
registerPacket(WebStreamEndPacket_v1_0_1_B::new);
|
||||
}
|
||||
|
||||
private void registerPacket(Supplier<? extends OACPacket> factory) {
|
||||
if (isPacketSupported(factory.get())) protocolValues.packetHandler.registerPacket(factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the appropriate listeners based on the current side
|
||||
@@ -184,27 +230,6 @@ public final class ProtocolBridge {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the logger instance
|
||||
*
|
||||
* @param logFolder The folder to store the log files
|
||||
*/
|
||||
private void initializeLogger(File logFolder) {
|
||||
// Create a temporary logger instance to avoid final field issues
|
||||
Logger tmpLogger = null;
|
||||
|
||||
try {
|
||||
// Initialize temporary logger
|
||||
tmpLogger = new Logger(logFolder, false, true);
|
||||
} catch (IOException | NoSuchFieldException | IllegalAccessException exception) {
|
||||
exception.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
// Assign the temporary logger to the final field
|
||||
this.logger = tmpLogger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the protocol version
|
||||
* Validate if the protocol version is valid for the current side
|
||||
@@ -244,6 +269,7 @@ public final class ProtocolBridge {
|
||||
*/
|
||||
public boolean isProtocolSupported(ProtocolVersion.Protocol protocol) {
|
||||
boolean yes = false;
|
||||
|
||||
for (ProtocolVersion compatibleVersion : protocolVersion.getCompatibleVersions()) {
|
||||
// Check if the compatible version supports the target protocol
|
||||
yes = compatibleVersion.getSupportedProtocols().contains(protocol);
|
||||
@@ -324,7 +350,7 @@ public final class ProtocolBridge {
|
||||
* @return true if the current instance is running as a web server, false otherwise
|
||||
*/
|
||||
public boolean isRunningAsWebServer() {
|
||||
return isRunningAsServer() && protocolServer instanceof ProtocolWebServer;
|
||||
return isRunningAsServer() && protocolServer instanceof ProtocolWebServer_1_0_0_B;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user