Refactored using IntelliJ

This commit is contained in:
Finn
2025-12-08 10:44:15 +01:00
parent ca3bc2e2c5
commit 065fab868d
15 changed files with 73 additions and 135 deletions

View File

@@ -7,20 +7,31 @@ Feel free to join our Discord.
## License Notice
This project (OAC) is licensed under the [Open Autonomous Public License (OAPL)](https://repo.open-autonomous-connection.org/open-autonomous-connection/OAPL/).
This project (OAC) is licensed under
the [Open Autonomous Public License (OAPL)](https://repo.open-autonomous-connection.org/open-autonomous-connection/OAPL/).
**Third-party components:**
- *UnlegitLibrary* is authored by the same copyright holder and is used here under a special agreement:
While [UnlegitLibrary](https://repo.unlegitdqrk.dev/UnlegitDqrk/unlegitlibrary/) is generally distributed under the [GNU GPLv3](https://repo.unlegitdqrk.dev/UnlegitDqrk/unlegitlibrary/src/branch/master/LICENSE),
While [UnlegitLibrary](https://repo.unlegitdqrk.dev/UnlegitDqrk/unlegitlibrary/) is generally distributed under
the [GNU GPLv3](https://repo.unlegitdqrk.dev/UnlegitDqrk/unlegitlibrary/src/branch/master/LICENSE),
it is additionally licensed under OAPL **exclusively for the OAC project**.
Therefore, within OAC, the OAPL terms apply to UnlegitLibrary as well.
# Bugs/Problems
- Project not tested yet
# In progress
- WebServer
# TODO
- Finishing WebServer
- Writing INS Backend and Frontend
- Writing WebClient
- Writing WebServer
- Documentation / Wiki
# Maven
### pom.xml
```
<dependency>
<groupId>org.openautonomousconnection</groupId>
@@ -30,6 +41,7 @@ This project (OAC) is licensed under the [Open Autonomous Public License (OAPL)]
```
### Repository:
```
<repository>
<id>oac</id>
@@ -39,78 +51,3 @@ This project (OAC) is licensed under the [Open Autonomous Public License (OAPL)]
</snapshots>
</repository>
```
# Examples
#### Note: These examples are very basic
### Server
```java
import dev.unlegitdqrk.unlegitlibrary.network.system.server.ConnectionHandler;
import me.openautonomousconnection.protocol.ProtocolBridge;
import me.openautonomousconnection.protocol.ProtocolSettings;
import me.openautonomousconnection.protocol.ProtocolVersion;
import me.openautonomousconnection.protocol.side.ProtocolServer;
public class Server extends ProtocolServer {
public Server() throws IOException, InterruptedException {
super(10);
}
public static void main(String[] args) {
try {
ProtocolBridge protocolBridge = new ProtocolBridge(ProtocolVersion.PV_1_0_0, new ProtocolSettings(), new Server());
protocolBridge.getProtocolServer().setProtocolBridge(protocolBridge);
protocolBridge.getProtocolServer().startServer();
} catch (IOException | InterruptedException | InvocationTargetException | InstantiationException |
IllegalAccessException | NoSuchMethodException exception) {
exception.printStackTrace();
}
}
@Override
public List<Domain> getDomains() throws SQLException {
return List.of(); // Your method here to get all registered domains
}
@Override
public void handleMessage(ConnectionHandler connectionHandler, String message) {
System.out.println("Received message: " + message + " from client: " + connectionHandler.getClientID());
}
}
```
### Client
```java
import me.openautonomousconnection.protocol.ProtocolBridge;
import me.openautonomousconnection.protocol.ProtocolSettings;
import me.openautonomousconnection.protocol.ProtocolVersion;
import me.openautonomousconnection.protocol.infoName.Domain;
import me.openautonomousconnection.protocol.side.ProtocolClient;
import me.openautonomousconnection.protocol.utils.SiteType;
public class Client extends ProtocolClient {
public static void main(String[] args) {
try {
ProtocolBridge protocolBridge = new ProtocolBridge(ProtocolVersion.PV_1_0_0, new ProtocolSettings(), new Client());
protocolBridge.getProtocolClient().setProtocolBridge(protocolBridge);
protocolBridge.getProtocolServer().startClient();
} catch (IOException | InterruptedException | InvocationTargetException | InstantiationException |
IllegalAccessException | NoSuchMethodException exception) {
exception.printStackTrace();
}
}
@Override
public void handleHTMLContent(SiteType siteType, Domain infoName, String htmlContent) {
System.out.println("Website html content received. This site is " + siteType.name);
System.out.println(htmlContent); // Render content in a webview for example
}
@Override
public void handleMessage(String message) {
System.out.println("Received message: " + message);
}
}
```

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

View File

@@ -211,11 +211,10 @@ public final class ProtocolBridge {
private void registerListeners() throws Exception {
// Classic listeners
if (isClassicSupported()) {
Classic_ClientListener classicListener = new Classic_ClientListener();
Classic_ClientListener classicListener = new Classic_ClientListener();
classicListener.setProtocolBridge(this);
protocolSettings.eventManager.registerListener(classicListener.getClass());
}
else protocolSettings.eventManager.unregisterListener(Classic_ClientListener.class);
} else protocolSettings.eventManager.unregisterListener(Classic_ClientListener.class);
// INS Listeners
if (isRunningAsINSServer()) {

View File

@@ -5,7 +5,6 @@ import dev.unlegitdqrk.unlegitlibrary.event.Listener;
import dev.unlegitdqrk.unlegitlibrary.network.system.client.events.ClientConnectedEvent;
import dev.unlegitdqrk.unlegitlibrary.network.system.client.events.ClientDisconnectedEvent;
import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.AuthPacket;
import org.openautonomousconnection.protocol.side.client.ProtocolClient;
@@ -27,6 +26,7 @@ public final class ClientListener extends EventListener {
/**
* Sets the client variable
*
* @param client The Instance of the ProtocolClient
*/
public void setClient(ProtocolClient client) {
@@ -58,7 +58,7 @@ public final class ClientListener extends EventListener {
*/
@Listener
public void onDisconnect(ClientDisconnectedEvent event) {
client.onINSDisconnect(event);
client.onINSDisconnect(event);
}
}

View File

@@ -5,9 +5,7 @@ import dev.unlegitdqrk.unlegitlibrary.event.Listener;
import dev.unlegitdqrk.unlegitlibrary.network.system.server.events.ConnectionHandlerConnectedEvent;
import dev.unlegitdqrk.unlegitlibrary.network.system.server.events.ConnectionHandlerDisconnectedEvent;
import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.side.client.ProtocolClient;
import org.openautonomousconnection.protocol.side.ins.ConnectedProtocolClient;
import org.openautonomousconnection.protocol.side.ins.ProtocolINSServer;
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
@@ -26,6 +24,7 @@ public final class INSServerListener extends EventListener {
/**
* Sets the insServer variable
*
* @param insServer The Instance of the INSServer
*/
public void setINSServer(ProtocolINSServer insServer) {

View File

@@ -5,9 +5,7 @@ import dev.unlegitdqrk.unlegitlibrary.event.Listener;
import dev.unlegitdqrk.unlegitlibrary.network.system.server.events.ConnectionHandlerConnectedEvent;
import dev.unlegitdqrk.unlegitlibrary.network.system.server.events.ConnectionHandlerDisconnectedEvent;
import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.side.client.ProtocolClient;
import org.openautonomousconnection.protocol.side.web.ConnectedWebClient;
import org.openautonomousconnection.protocol.side.web.ProtocolWebServer;
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
@@ -26,6 +24,7 @@ public final class WebServerListener extends EventListener {
/**
* Sets the webServer variable
*
* @param webServer The Instance of the ProtocolWebServer
*/
public void setWebServer(ProtocolWebServer webServer) {

View File

@@ -86,7 +86,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
/**
* Creates a web connection to the specified InfoName and ports.
*
* @param infoName the target InfoName for the web connection.
* @param infoName the target InfoName for the web connection.
* @param pipelinePort the port used for the pipeline connection.
* @param webPort the port used for the web connection.
* @throws Exception if there are issues creating the web connection or if the protocol is unsupported.
@@ -133,7 +133,8 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
// Validate each file in the folder
for (File file : files) {
if (!file.getName().startsWith(prefix)) throw new CertificateException(file.getAbsolutePath() + " is not valid");
if (!file.getName().startsWith(prefix))
throw new CertificateException(file.getAbsolutePath() + " is not valid");
// Check for specific files
if (!found) found = file.getName().equalsIgnoreCase(prefix + NetworkUtils.getPublicIPAddress() + extension);
@@ -320,8 +321,8 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
/**
* Requests the destination for the specified InfoName from the INS server.
*
* @param infoName the InfoName for which to request the destination.
* @param responseCode the expected INSResponseCode for the request.
* @param infoName the InfoName for which to request the destination.
* @param responseCode the expected INSResponseCode for the request.
* @throws IOException if there are I/O issues during the request process.
* @throws ClassNotFoundException if there are issues with class loading during packet handling.
*/
@@ -336,6 +337,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
/**
* Set protocol bridge.
*
* @param protocolBridge The ProtocolBridge object.
*/
public void setProtocolBridge(ProtocolBridge protocolBridge) {
@@ -345,7 +347,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
/**
* Callback method invoked when InfoName validation is completed.
*
* @param infoName the InfoName that was validated.
* @param infoName the InfoName that was validated.
* @param responseCode the INSResponseCode resulting from the validation.
*/
public abstract void validationCompleted(InfoName infoName, INSResponseCode responseCode);
@@ -353,7 +355,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
/**
* Callback method invoked when the destination retrieval is completed.
*
* @param infoName the InfoName for which the destination was requested.
* @param infoName the InfoName for which the destination was requested.
* @param destination the retrieved destination as a string.
* @param validationResponse the INSResponseCode resulting from the destination retrieval.
*/

View File

@@ -2,7 +2,6 @@ package org.openautonomousconnection.protocol.side.client;
import dev.unlegitdqrk.unlegitlibrary.network.system.client.NetworkClient;
import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.InfoName;
@@ -28,12 +27,15 @@ public final class WebClient {
* NetworkClient instance for managing the pipeline connection to the web server.
*/
private final NetworkClient clientToWebPipeline;
/**
* The Protocol Client associated with this protocol client.
*/
@Getter
private final ProtocolClient protocolClient;
/**
* SSLSocket for secure communication with the web server.
*/
private SSLSocket clientToWebServer;
/**
* Streams for object serialization over the SSL connection.
*/
@@ -43,18 +45,12 @@ public final class WebClient {
*/
private ObjectInputStream inputStream;
/**
* The Protocol Client associated with this protocol client.
*/
@Getter
private final ProtocolClient protocolClient;
/**
* Constructs a WebClient instance and establishes a secure connection to the web server.
*
* @param infoName The InfoName information for the web server.
* @param pipelinePort The port for the pipeline connection.
* @param webPort The port for the web server connection.
* @param pipelinePort The port for the pipeline connection.
* @param webPort The port for the web server connection.
* @param protocolClient The Protocol Client associated with this protocol client.
* @throws Exception If an error occurs during connection setup.
*/
@@ -154,10 +150,7 @@ public final class WebClient {
*/
public NetworkClient getClientPipelineConnection() {
return clientToWebPipeline;
} /**
* Thread for receiving data from the web server.
*/
private final Thread receiveThread = new Thread(this::receive);
}
/**
* Gets the SSLSocket used for communication with the web server.
@@ -166,7 +159,10 @@ public final class WebClient {
*/
public SSLSocket getClientWebConnection() {
return clientToWebServer;
}
} /**
* Thread for receiving data from the web server.
*/
private final Thread receiveThread = new Thread(this::receive);
/**
* Checks if the WebClient is currently connected to the web server.

View File

@@ -131,7 +131,8 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
// Validate each file in the folder
for (File file : files) {
if (!file.getName().startsWith(prefix)) throw new CertificateException(file.getAbsolutePath() + " is not valid");
if (!file.getName().startsWith(prefix))
throw new CertificateException(file.getAbsolutePath() + " is not valid");
// Check if the file matches the expected naming convention
if (!found) found = file.getName().equalsIgnoreCase(prefix + NetworkUtils.getPublicIPAddress() + extension);
@@ -155,6 +156,7 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
/**
* Set protocol bridge
*
* @param protocolBridge The ProtocolBridge object
*/
public void setProtocolBridge(ProtocolBridge protocolBridge) {
@@ -195,8 +197,8 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
public abstract String getInfoNameDestination(InfoName infoName);
/**
* @param infoName The parent InfoName.
* @param subname The subname to look up.
* @param infoName The parent InfoName.
* @param subname The subname to look up.
* @return The destination associated with the subname.
* @see InfoName#getDestination(ProtocolBridge)
* Abstract method to get the destination for a given subname under a specific InfoName.
@@ -221,7 +223,8 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
/**
* Abstract method called when a validation packet fails to send.
* @param infoName The InfoName associated with the validation.
*
* @param infoName The InfoName associated with the validation.
* @param client The connected protocol client.
* @param exception The exception that occurred during sending.
*/
@@ -229,8 +232,9 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
/**
* Abstract method called when a InfoName destination packet fails to send.
*
* @param client The connected protocol client.
* @param infoName The InfoName associated with the packet.
* @param infoName The InfoName associated with the packet.
* @param validationResponse The INS response code from validation.
* @param exception The exception that occurred during sending.
*/

View File

@@ -2,7 +2,6 @@ package org.openautonomousconnection.protocol.side.web;
import dev.unlegitdqrk.unlegitlibrary.network.system.server.ConnectionHandler;
import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.packets.OACPacket;
import org.openautonomousconnection.protocol.side.web.managers.AuthManager;
@@ -56,6 +55,12 @@ public final class ConnectedWebClient {
*/
@Getter
private boolean clientVersionLoaded = false;
/**
* The reference to the ProtocolWebServer Object
*/
@Getter
private ProtocolWebServer protocolWebServer;
/**
* Constructs a ConnectedWebClient with the given connection handler.
*
@@ -68,12 +73,6 @@ public final class ConnectedWebClient {
*/
private final Thread receiveThread = new Thread(this::receive);
/**
* The reference to the ProtocolWebServer Object
*/
@Getter
private ProtocolWebServer protocolWebServer;
/**
* Sends an HTTP redirect response to the client.
*
@@ -709,6 +708,7 @@ public final class ConnectedWebClient {
/**
* Set protocol bridge
*
* @param protocolWebServer The ProtocolWebServer object
*/
public void setProtocolWebServer(ProtocolWebServer protocolWebServer) {

View File

@@ -185,6 +185,7 @@ public final class ProtocolWebServer {
/**
* Set protocol bridge
*
* @param protocolBridge The ProtocolBridge object
*/
public void setProtocolBridge(ProtocolBridge protocolBridge) {
@@ -270,7 +271,7 @@ public final class ProtocolWebServer {
* @throws CertificateException If a required certificate file is missing or invalid.
* @throws IOException If an I/O error occurs while checking the files.
*/
private final void checkFileExists(File folder, String prefix, String extension) throws CertificateException, IOException {
private void checkFileExists(File folder, String prefix, String extension) throws CertificateException, IOException {
boolean found = false;
// Ensure the folder exists
@@ -283,7 +284,8 @@ public final class ProtocolWebServer {
// Check for the required certificate file
for (File file : files) {
if (!file.getName().startsWith(prefix)) throw new CertificateException(file.getAbsolutePath() + " is not valid");
if (!file.getName().startsWith(prefix))
throw new CertificateException(file.getAbsolutePath() + " is not valid");
// Check for file matching the public IP address
if (!found) found = file.getName().equalsIgnoreCase(prefix + NetworkUtils.getPublicIPAddress() + extension);

View File

@@ -1,7 +1,6 @@
package org.openautonomousconnection.protocol.side.web.managers;
import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.side.web.ProtocolWebServer;
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
@@ -32,9 +31,9 @@ public final class SessionManager {
/**
* Creates a new session for the given user.
*
* @param login The username associated with the session.
* @param ip The IP address of the client.
* @param userAgent The User-Agent string of the client.
* @param login The username associated with the session.
* @param ip The IP address of the client.
* @param userAgent The User-Agent string of the client.
* @param protocolWebServer The Protocol WebServer for the unique Session
* @return The generated session ID.
* @throws IOException If an I/O error occurs.
@@ -55,9 +54,9 @@ public final class SessionManager {
/**
* Validates a session ID against the provided IP and User-Agent.
*
* @param sessionId The session ID to validate.
* @param ip The IP address of the client.
* @param userAgent The User-Agent string of the client.
* @param sessionId The session ID to validate.
* @param ip The IP address of the client.
* @param userAgent The User-Agent string of the client.
* @param protocolWebServer The Protocol WebServer to get the config for refreshing
* @return True if the session is valid, false otherwise.
* @throws IOException If an I/O error occurs.
@@ -154,6 +153,7 @@ public final class SessionManager {
/**
* Refreshes the session's expiration time.
*
* @param protocolWebServer The Protocol WebServer to get the Config setting
* @throws IOException If an I/O error occurs.
*/

View File

@@ -1,7 +1,6 @@
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers;
import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_MessagePacket;
import org.openautonomousconnection.protocol.side.client.ProtocolClient;

View File

@@ -24,7 +24,7 @@ public final class ClassicConverter {
/**
* Converts a InfoName object to a Classic_Domain object.
*
* @param newInfoName the InfoName object to convert
* @param newInfoName the InfoName object to convert
* @param protocolBridge The reference to the ProtocolBridge object.
* @return the converted Classic_Domain object
*/

View File

@@ -33,6 +33,7 @@ public final class Classic_ClientListener extends EventListener {
/**
* Set protocol bridge
*
* @param protocolBridge The ProtocolBridge object
*/
public void setProtocolBridge(ProtocolBridge protocolBridge) {