Updated to latest UnlegitLibrary version and implemented UDP

This commit is contained in:
Finn
2026-01-18 21:48:43 +01:00
parent da254a6c8e
commit 50cd7b57ac
40 changed files with 172 additions and 1503 deletions

View File

@@ -8,7 +8,7 @@ import org.openautonomousconnection.protocol.versions.ProtocolVersion;
public abstract class CustomConnectedClient {
@Getter
private final ConnectionHandler pipelineConnection;
private final ConnectionHandler connection;
@Getter
private final ProtocolCustomServer server;
@@ -18,8 +18,8 @@ public abstract class CustomConnectedClient {
@Getter
private boolean clientVersionLoaded = false;
public CustomConnectedClient(ConnectionHandler pipelineConnection, ProtocolCustomServer protocolServer) {
this.pipelineConnection = pipelineConnection;
public CustomConnectedClient(ConnectionHandler connection, ProtocolCustomServer protocolServer) {
this.connection = connection;
this.server = protocolServer;
}
@@ -29,7 +29,7 @@ public abstract class CustomConnectedClient {
} catch (Exception ignored) {
}
try {
pipelineConnection.disconnect();
connection.disconnect();
} catch (Exception ignored) {
}
}

View File

@@ -1,6 +1,8 @@
package org.openautonomousconnection.protocol.side.server;
import dev.unlegitdqrk.unlegitlibrary.network.system.server.NetworkServer;
import dev.unlegitdqrk.unlegitlibrary.network.system.utils.ClientID;
import dev.unlegitdqrk.unlegitlibrary.network.system.utils.TransportPolicy;
import dev.unlegitdqrk.unlegitlibrary.network.utils.NetworkUtils;
import lombok.Getter;
import lombok.Setter;
@@ -50,17 +52,26 @@ public abstract class ProtocolCustomServer {
* The network server handling pipeline connections.
*/
@Getter
private NetworkServer pipelineServer;
private NetworkServer network;
@Getter
private int tcpPort;
@Getter
private int udpPort;
/**
* Initializes the web server with the given configuration, authentication, and rules files.
*
* @throws Exception If an error occurs during initialization.
*/
public ProtocolCustomServer(String caPrefix, String certPrefix) throws Exception {
public ProtocolCustomServer(String caPrefix, String certPrefix, int tcpPort, int udpPort) throws Exception {
// Initialize the list of connected clients
this.clients = new ArrayList<>();
this.tcpPort = tcpPort;
this.udpPort = udpPort;
// Set up folder structure for certificates
folderStructure = new ServerCertificateFolderStructure(caPrefix, certPrefix);
@@ -91,10 +102,11 @@ public abstract class ProtocolCustomServer {
* Initialize the pipeline server
*/
private void createNetworkServer() {
pipelineServer = new NetworkServer.ServerBuilder().
setPort(protocolBridge.getProtocolSettings().port).setTimeout(0).
setPacketHandler(protocolBridge.getProtocolSettings().packetHandler).setEventManager(protocolBridge.getProtocolSettings().eventManager).
setLogger(protocolBridge.getLogger()).
network = new NetworkServer.ServerBuilder().
setTcpPort(tcpPort).setUdpPort(udpPort).setTransportPolicy(TransportPolicy.bothRequired()).
setTimeout(0).
setPacketHandler(protocolBridge.getProtocolValues().packetHandler).
setEventManager(protocolBridge.getProtocolValues().eventManager).setLogger(protocolBridge.getLogger()).
setServerCertificate(certFile, keyFile).setRootCAFolder(folderStructure.publicCAFolder).
build();
}
@@ -105,9 +117,9 @@ public abstract class ProtocolCustomServer {
* @param clientID The client ID to search for.
* @return The connected web client with the specified ID, or null if not found.
*/
public final <T extends CustomConnectedClient> T getClientByID(int clientID) {
public final <T extends CustomConnectedClient> T getClientByID(ClientID clientID) {
for (CustomConnectedClient client : clients)
if (client.getPipelineConnection().getClientID() == clientID) return (T) client;
if (client.getConnection().getClientId() == clientID) return (T) client;
return null;
}
@@ -176,8 +188,8 @@ public abstract class ProtocolCustomServer {
private String certPrefix = "cert_server_";
public ServerCertificateFolderStructure(String caPrefix, String certPrefix) {
this.caPrefix = caPrefix;
this.certPrefix = certPrefix;
this.caPrefix = "ca_" + caPrefix + "_";
this.certPrefix = "cert_" + certPrefix + "_";
certificatesFolder = new File("certificates");