"host:port" format representing the TLN's info endpoint,
- * or null if the TLN has no registered info site.
+ * or null if the TLN has no registered info site.
*/
public abstract String resolveTLNInfoSite(String tln);
@@ -271,46 +156,4 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
public final String getINSFrontendSite() {
return configurationManager.getString("server.site.frontend");
}
-
- /**
- * Class representing the folder structure for server certificates.
- */
- public final class ServerCertificateFolderStructure {
- public final File certificatesFolder;
-
- public final File publicFolder;
- public final File privateFolder;
-
- public final File privateCAFolder;
- public final File privateServerFolder;
-
- public final File publicCAFolder;
- public final File publicServerFolder;
- public final String caPrefix = "ca_ins_";
- public final String certPrefix = "cert_ins_";
-
- public ServerCertificateFolderStructure() {
- certificatesFolder = new File("certificates");
-
- publicFolder = new File(certificatesFolder, "public");
- privateFolder = new File(certificatesFolder, "private");
-
- privateCAFolder = new File(privateFolder, "ca");
- privateServerFolder = new File(privateFolder, "server");
-
- publicCAFolder = new File(publicFolder, "ca");
- publicServerFolder = new File(publicFolder, "server");
-
- if (!certificatesFolder.exists()) certificatesFolder.mkdirs();
-
- if (!publicFolder.exists()) publicFolder.mkdirs();
- if (!privateFolder.exists()) privateFolder.mkdirs();
-
- if (!privateCAFolder.exists()) privateCAFolder.mkdirs();
- if (!privateServerFolder.exists()) privateServerFolder.mkdirs();
-
- if (!publicCAFolder.exists()) publicCAFolder.mkdirs();
- if (!publicServerFolder.exists()) publicServerFolder.mkdirs();
- }
- }
}
diff --git a/src/main/java/org/openautonomousconnection/protocol/side/ins/events/ConnectedProtocolClientEvent.java b/src/main/java/org/openautonomousconnection/protocol/side/ins/events/ConnectedProtocolClientEvent.java
deleted file mode 100644
index 6891621..0000000
--- a/src/main/java/org/openautonomousconnection/protocol/side/ins/events/ConnectedProtocolClientEvent.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package org.openautonomousconnection.protocol.side.ins.events;
-
-import dev.unlegitdqrk.unlegitlibrary.event.impl.Event;
-import lombok.Getter;
-import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
-import org.openautonomousconnection.protocol.side.ins.ConnectedProtocolClient;
-import org.openautonomousconnection.protocol.versions.ProtocolVersion;
-
-/**
- * Event triggered when a protocol client connects to the INS server.
- */
-@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS)
-public final class ConnectedProtocolClientEvent extends Event {
-
- @Getter
- private final ConnectedProtocolClient protocolClient;
-
- public ConnectedProtocolClientEvent(ConnectedProtocolClient protocolClient) {
- this.protocolClient = protocolClient;
- }
-}
diff --git a/src/main/java/org/openautonomousconnection/protocol/side/server/CustomConnectedClient.java b/src/main/java/org/openautonomousconnection/protocol/side/server/CustomConnectedClient.java
new file mode 100644
index 0000000..862b71b
--- /dev/null
+++ b/src/main/java/org/openautonomousconnection/protocol/side/server/CustomConnectedClient.java
@@ -0,0 +1,178 @@
+package org.openautonomousconnection.protocol.side.server;
+
+import dev.unlegitdqrk.unlegitlibrary.network.system.server.ConnectionHandler;
+import lombok.Getter;
+import org.openautonomousconnection.protocol.packets.OACPacket;
+import org.openautonomousconnection.protocol.versions.ProtocolVersion;
+
+public abstract class CustomConnectedClient {
+
+ @Getter
+ private final ConnectionHandler pipelineConnection;
+
+ @Getter
+ private final ProtocolCustomServer server;
+
+ private ProtocolVersion clientVersion = null;
+
+ @Getter
+ private boolean clientVersionLoaded = false;
+
+ public CustomConnectedClient(ConnectionHandler pipelineConnection, ProtocolCustomServer protocolServer) {
+ this.pipelineConnection = pipelineConnection;
+ this.server = protocolServer;
+ }
+
+ public synchronized void disconnect() {
+ try {
+ server.clientDisconnected(this);
+ } catch (Exception ignored) {
+ }
+ try {
+ pipelineConnection.disconnect();
+ } catch (Exception ignored) {
+ }
+ }
+
+
+ /**
+ * Gets the protocol version of the connected client.
+ *
+ * @return The protocol version of the client, defaults to PV_1_0_0_CLASSIC if not set.
+ */
+ public ProtocolVersion getClientVersion() {
+ return clientVersion == null ? ProtocolVersion.PV_1_0_0_CLASSIC : clientVersion;
+ }
+
+ /**
+ * Sets the protocol version of the connected client.
+ *
+ * @param clientVersion The protocol version to set.
+ */
+ public void setClientVersion(ProtocolVersion clientVersion) {
+ if (clientVersionLoaded) return;
+ if (clientVersion == null) return;
+
+ this.clientVersion = clientVersion;
+ this.clientVersionLoaded = true;
+ }
+
+ /**
+ * Checks if the connected client is a stable client.
+ *
+ * @return True if the client is stable, false otherwise.
+ */
+ public boolean isStableClient() {
+ // Check if the server version is stable
+ return !isBetaClient() && !isClassicClient();
+ }
+
+ /**
+ * Checks if the connected client supports stable protocol versions.
+ *
+ * @return True if the client supports stable versions, false otherwise.
+ */
+ public boolean supportClientStable() {
+ boolean yes = false;
+ for (ProtocolVersion compatibleVersion : getClientVersion().getCompatibleVersions()) {
+ // Check if compatible version is stable
+ yes = compatibleVersion.getProtocolType() == ProtocolVersion.ProtocolType.STABLE;
+ if (yes) break;
+ }
+
+ // Check if the client version is stable
+ return isStableClient() || yes;
+ }
+
+ /**
+ * Checks if the connected client is a beta client.
+ *
+ * @return True if the client is beta, false otherwise.
+ */
+ public boolean isBetaClient() {
+ // Check if the server version is beta
+ return getClientVersion().getProtocolType() == ProtocolVersion.ProtocolType.BETA;
+ }
+
+ /**
+ * Checks if the connected client supports beta protocol versions.
+ *
+ * @return True if the client supports beta versions, false otherwise.
+ */
+ public boolean supportClientBeta() {
+ boolean yes = false;
+ for (ProtocolVersion compatibleVersion : getClientVersion().getCompatibleVersions()) {
+ // Check if compatible version is beta
+ yes = compatibleVersion.getProtocolType() == ProtocolVersion.ProtocolType.BETA;
+ if (yes) break;
+ }
+
+ // Check if the client version is beta
+ return isBetaClient() || yes;
+ }
+
+ /**
+ * Checks if the connected client is a classic client.
+ *
+ * @return True if the client is classic, false otherwise.
+ */
+ public boolean isClassicClient() {
+ return getClientVersion().getProtocolType() == ProtocolVersion.ProtocolType.CLASSIC;
+ }
+
+ /**
+ * Checks if the connected client supports classic protocol versions.
+ *
+ * @return True if the client supports classic versions, false otherwise.
+ */
+ public boolean supportClientClassic() {
+ boolean yes = false;
+ for (ProtocolVersion compatibleVersion : getClientVersion().getCompatibleVersions()) {
+ // Check if compatible version is classic
+ yes = compatibleVersion.getProtocolType() == ProtocolVersion.ProtocolType.CLASSIC;
+ if (yes) break;
+ }
+
+ // Check if the client version is classic
+ return isClassicClient() || yes;
+ }
+
+ /**
+ * Checks if the connected client supports the protocol version of the given packet.
+ *
+ * @param packet The packet to check support for.
+ * @return True if the client supports the packet's protocol version, false otherwise.
+ */
+ public boolean supportClientPacket(OACPacket packet) {
+ return supportClientVersion(packet.getProtocolVersion());
+ }
+
+ /**
+ * Checks if the connected client supports the given protocol version.
+ *
+ * @param targetVersion The protocol version to check support for.
+ * @return True if the client supports the target version, false otherwise.
+ */
+ public boolean supportClientVersion(ProtocolVersion targetVersion) {
+ // Check if the client version matches the target version or is compatible
+ return getClientVersion() == targetVersion || getClientVersion().getCompatibleVersions().contains(targetVersion);
+ }
+
+ /**
+ * Checks if the connected client supports the given protocol.
+ *
+ * @param protocol The protocol to check support for.
+ * @return True if the client supports the protocol, false otherwise.
+ */
+ public boolean supportClientProtocol(ProtocolVersion.Protocol protocol) {
+ boolean yes = false;
+ for (ProtocolVersion compatibleVersion : getClientVersion().getCompatibleVersions()) {
+ // Check if compatible version supports the protocol
+ yes = compatibleVersion.getSupportedProtocols().contains(protocol);
+ if (yes) break;
+ }
+
+ // Check if the client version supports the protocol
+ return getClientVersion().getSupportedProtocols().contains(protocol) || yes;
+ }
+}
diff --git a/src/main/java/org/openautonomousconnection/protocol/side/server/ProtocolCustomServer.java b/src/main/java/org/openautonomousconnection/protocol/side/server/ProtocolCustomServer.java
new file mode 100644
index 0000000..14d36e4
--- /dev/null
+++ b/src/main/java/org/openautonomousconnection/protocol/side/server/ProtocolCustomServer.java
@@ -0,0 +1,206 @@
+package org.openautonomousconnection.protocol.side.server;
+
+import dev.unlegitdqrk.unlegitlibrary.network.system.server.NetworkServer;
+import dev.unlegitdqrk.unlegitlibrary.network.utils.NetworkUtils;
+import lombok.Getter;
+import lombok.Setter;
+import org.openautonomousconnection.protocol.ProtocolBridge;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.security.cert.CertificateException;
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class ProtocolCustomServer {
+
+ /**
+ * Structure for server.
+ */
+ @Getter
+ private final ServerCertificateFolderStructure folderStructure;
+
+ /**
+ * Certificate files for SSL.
+ */
+ private final File certFile;
+ /**
+ * Certificate files for SSL.
+ */
+ private final File keyFile;
+
+ /**
+ * The reference to the ProtocolBridge Object
+ */
+ @Getter
+ private ProtocolBridge protocolBridge;
+
+ /**
+ * List of connected web clients.
+ */
+ @Getter
+ private List
@@ -148,7 +138,6 @@ public final class INSRecordTools {
*
*
* @param record The record to validate.
- *
* @return {@code true} if the record passes all checks, {@code false} otherwise.
*/
public static boolean isValidRecord(INSRecord record) {
@@ -157,17 +146,18 @@ public final class INSRecordTools {
if (record.value == null || record.value.isEmpty()) return false;
if (record.port < 0 || record.port > 65535) return false;
- if (record.ttl < 0) return false;
-
- return true;
+ return record.ttl >= 0;
}
+ // -------------------------------------------------------------------------
+ // Validation helpers
+ // -------------------------------------------------------------------------
+
/**
* Validates a collection of records by applying {@link #isValidRecord(INSRecord)}
* to each element.
*
* @param records Records to validate.
- *
* @return A new list containing only valid records.
*/
public static List