Compare commits

...

2 Commits

Author SHA1 Message Date
Finn
d7e5d1fb61 Merge remote-tracking branch 'origin/master' 2025-12-08 10:44:34 +01:00
Finn
065fab868d Refactored using IntelliJ 2025-12-08 10:44:15 +01:00
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

@@ -214,8 +214,7 @@ public final class ProtocolBridge {
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) {

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

@@ -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);
@@ -336,6 +337,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
/**
* Set protocol bridge.
*
* @param protocolBridge The ProtocolBridge object.
*/
public void setProtocolBridge(ProtocolBridge protocolBridge) {

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,12 +45,6 @@ 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.
*
@@ -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) {
@@ -221,6 +223,7 @@ 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 client The connected protocol client.
* @param exception The exception that occurred during sending.
@@ -229,6 +232,7 @@ 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 validationResponse The INS response code from validation.

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;
@@ -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

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