master #1

Merged
open-autonomous-connection merged 5 commits from master into dev 2025-12-08 09:40:06 +00:00
21 changed files with 248 additions and 112 deletions
Showing only changes of commit ca3bc2e2c5 - Show all commits

View File

@@ -13,6 +13,8 @@ import org.openautonomousconnection.protocol.packets.v1_0_0.beta.GetDestinationP
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.UnsupportedClassicPacket; import org.openautonomousconnection.protocol.packets.v1_0_0.beta.UnsupportedClassicPacket;
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.ValidateInfoNamePacket; import org.openautonomousconnection.protocol.packets.v1_0_0.beta.ValidateInfoNamePacket;
import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_DomainPacket; import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_DomainPacket;
import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_MessagePacket;
import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_PingPacket;
import org.openautonomousconnection.protocol.side.client.ProtocolClient; import org.openautonomousconnection.protocol.side.client.ProtocolClient;
import org.openautonomousconnection.protocol.side.ins.ProtocolINSServer; import org.openautonomousconnection.protocol.side.ins.ProtocolINSServer;
import org.openautonomousconnection.protocol.side.web.ProtocolWebServer; import org.openautonomousconnection.protocol.side.web.ProtocolWebServer;
@@ -179,8 +181,8 @@ public final class ProtocolBridge {
private void registerPackets() { private void registerPackets() {
// Classic packets // Classic packets
Classic_DomainPacket cDomainPacket = new Classic_DomainPacket(); Classic_DomainPacket cDomainPacket = new Classic_DomainPacket();
Classic_DomainPacket cMessagePacket = new Classic_DomainPacket(); Classic_MessagePacket cMessagePacket = new Classic_MessagePacket();
Classic_DomainPacket cPingPacket = new Classic_DomainPacket(); Classic_PingPacket cPingPacket = new Classic_PingPacket();
if (isPacketSupported(cDomainPacket)) protocolSettings.packetHandler.registerPacket(cDomainPacket); if (isPacketSupported(cDomainPacket)) protocolSettings.packetHandler.registerPacket(cDomainPacket);
if (isPacketSupported(cMessagePacket)) protocolSettings.packetHandler.registerPacket(cMessagePacket); if (isPacketSupported(cMessagePacket)) protocolSettings.packetHandler.registerPacket(cMessagePacket);
@@ -208,26 +210,36 @@ public final class ProtocolBridge {
*/ */
private void registerListeners() throws Exception { private void registerListeners() throws Exception {
// Classic listeners // Classic listeners
if (isClassicSupported()) protocolSettings.eventManager.registerListener(Classic_ClientListener.class); if (isClassicSupported()) {
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 // INS Listeners
if (isRunningAsINSServer()) { if (isRunningAsINSServer()) {
protocolSettings.eventManager.registerListener(INSServerListener.class); INSServerListener serverListener = new INSServerListener();
serverListener.setINSServer(protocolINSServer);
protocolSettings.eventManager.registerListener(serverListener.getClass());
protocolSettings.eventManager.unregisterListener(WebServerListener.class); protocolSettings.eventManager.unregisterListener(WebServerListener.class);
protocolSettings.eventManager.unregisterListener(ClientListener.class); protocolSettings.eventManager.unregisterListener(ClientListener.class);
} }
// Web Listeners // Web Listeners
if (isRunningAsWebServer()) { if (isRunningAsWebServer()) {
protocolSettings.eventManager.registerListener(WebServerListener.class); WebServerListener serverListener = new WebServerListener();
serverListener.setWebServer(protocolWebServer);
protocolSettings.eventManager.registerListener(serverListener.getClass());
protocolSettings.eventManager.unregisterListener(INSServerListener.class); protocolSettings.eventManager.unregisterListener(INSServerListener.class);
protocolSettings.eventManager.unregisterListener(ClientListener.class); protocolSettings.eventManager.unregisterListener(ClientListener.class);
} }
// Client Listeners // Client Listeners
if (isRunningAsClient()) { if (isRunningAsClient()) {
protocolSettings.eventManager.registerListener(ClientListener.class); ClientListener clientListener = new ClientListener();
clientListener.setClient(protocolClient);
protocolSettings.eventManager.registerListener(clientListener.getClass());
protocolSettings.eventManager.unregisterListener(INSServerListener.class); protocolSettings.eventManager.unregisterListener(INSServerListener.class);
protocolSettings.eventManager.unregisterListener(WebServerListener.class); protocolSettings.eventManager.unregisterListener(WebServerListener.class);
} }

View File

@@ -4,9 +4,11 @@ import dev.unlegitdqrk.unlegitlibrary.event.EventListener;
import dev.unlegitdqrk.unlegitlibrary.event.Listener; import dev.unlegitdqrk.unlegitlibrary.event.Listener;
import dev.unlegitdqrk.unlegitlibrary.network.system.client.events.ClientConnectedEvent; import dev.unlegitdqrk.unlegitlibrary.network.system.client.events.ClientConnectedEvent;
import dev.unlegitdqrk.unlegitlibrary.network.system.client.events.ClientDisconnectedEvent; import dev.unlegitdqrk.unlegitlibrary.network.system.client.events.ClientDisconnectedEvent;
import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge; import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo; import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.AuthPacket; import org.openautonomousconnection.protocol.packets.v1_0_0.beta.AuthPacket;
import org.openautonomousconnection.protocol.side.client.ProtocolClient;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
import java.io.IOException; import java.io.IOException;
@@ -17,6 +19,21 @@ import java.io.IOException;
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.CLIENT) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.CLIENT)
public final class ClientListener extends EventListener { public final class ClientListener extends EventListener {
/**
* The reference to the ProtocolClient object
*/
@Getter
private ProtocolClient client;
/**
* Sets the client variable
* @param client The Instance of the ProtocolClient
*/
public void setClient(ProtocolClient client) {
if (this.client != null) return;
this.client = client;
}
/** /**
* Handles the event when a client connects. * Handles the event when a client connects.
* Sends an authentication packet to the server. * Sends an authentication packet to the server.
@@ -26,7 +43,7 @@ public final class ClientListener extends EventListener {
@Listener @Listener
public void onConnect(ClientConnectedEvent event) { public void onConnect(ClientConnectedEvent event) {
try { try {
event.getClient().sendPacket(new AuthPacket(protocolBridge)); event.getClient().sendPacket(new AuthPacket(client.getProtocolBridge()));
} catch (IOException | ClassNotFoundException exception) { } catch (IOException | ClassNotFoundException exception) {
event.getClient().getLogger().exception("Failed to send auth packet", exception); event.getClient().getLogger().exception("Failed to send auth packet", exception);
event.getClient().disconnect(); event.getClient().disconnect();
@@ -41,7 +58,7 @@ public final class ClientListener extends EventListener {
*/ */
@Listener @Listener
public void onDisconnect(ClientDisconnectedEvent event) { public void onDisconnect(ClientDisconnectedEvent event) {
ProtocolBridge.getInstance().getProtocolClient().onINSDisconnect(event); client.onINSDisconnect(event);
} }
} }

View File

@@ -4,9 +4,12 @@ import dev.unlegitdqrk.unlegitlibrary.event.EventListener;
import dev.unlegitdqrk.unlegitlibrary.event.Listener; import dev.unlegitdqrk.unlegitlibrary.event.Listener;
import dev.unlegitdqrk.unlegitlibrary.network.system.server.events.ConnectionHandlerConnectedEvent; import dev.unlegitdqrk.unlegitlibrary.network.system.server.events.ConnectionHandlerConnectedEvent;
import dev.unlegitdqrk.unlegitlibrary.network.system.server.events.ConnectionHandlerDisconnectedEvent; import dev.unlegitdqrk.unlegitlibrary.network.system.server.events.ConnectionHandlerDisconnectedEvent;
import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge; import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo; 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.ConnectedProtocolClient;
import org.openautonomousconnection.protocol.side.ins.ProtocolINSServer;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
/** /**
@@ -15,6 +18,21 @@ import org.openautonomousconnection.protocol.versions.ProtocolVersion;
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS)
public final class INSServerListener extends EventListener { public final class INSServerListener extends EventListener {
/**
* The reference to the INSServer object
*/
@Getter
private ProtocolINSServer insServer;
/**
* Sets the insServer variable
* @param insServer The Instance of the INSServer
*/
public void setINSServer(ProtocolINSServer insServer) {
if (this.insServer != null) return;
this.insServer = insServer;
}
/** /**
* Handles the event when a connection handler connects to the INS server. * Handles the event when a connection handler connects to the INS server.
* Adds the connected client to the ProtocolBridge's INS server client list. * Adds the connected client to the ProtocolBridge's INS server client list.
@@ -23,7 +41,7 @@ public final class INSServerListener extends EventListener {
*/ */
@Listener @Listener
public void onConnect(ConnectionHandlerConnectedEvent event) { public void onConnect(ConnectionHandlerConnectedEvent event) {
ProtocolBridge.getInstance().getProtocolINSServer().getClients().add(new ConnectedProtocolClient(event.getConnectionHandler())); insServer.getClients().add(new ConnectedProtocolClient(event.getConnectionHandler(), insServer));
} }
/** /**
@@ -34,8 +52,7 @@ public final class INSServerListener extends EventListener {
*/ */
@Listener @Listener
public void onDisconnect(ConnectionHandlerDisconnectedEvent event) { public void onDisconnect(ConnectionHandlerDisconnectedEvent event) {
ProtocolBridge.getInstance().getProtocolINSServer().getClients().removeIf(client -> insServer.getClients().removeIf(client -> client.getConnectionHandler().getClientID() == -1);
client.getConnectionHandler().getClientID() == -1);
} }
} }

View File

@@ -4,9 +4,12 @@ import dev.unlegitdqrk.unlegitlibrary.event.EventListener;
import dev.unlegitdqrk.unlegitlibrary.event.Listener; import dev.unlegitdqrk.unlegitlibrary.event.Listener;
import dev.unlegitdqrk.unlegitlibrary.network.system.server.events.ConnectionHandlerConnectedEvent; import dev.unlegitdqrk.unlegitlibrary.network.system.server.events.ConnectionHandlerConnectedEvent;
import dev.unlegitdqrk.unlegitlibrary.network.system.server.events.ConnectionHandlerDisconnectedEvent; import dev.unlegitdqrk.unlegitlibrary.network.system.server.events.ConnectionHandlerDisconnectedEvent;
import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge; import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo; 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.ConnectedWebClient;
import org.openautonomousconnection.protocol.side.web.ProtocolWebServer;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
/** /**
@@ -15,6 +18,21 @@ import org.openautonomousconnection.protocol.versions.ProtocolVersion;
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.WEB) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.WEB)
public final class WebServerListener extends EventListener { public final class WebServerListener extends EventListener {
/**
* The reference to the ProtocolWebServer object
*/
@Getter
private ProtocolWebServer webServer;
/**
* Sets the webServer variable
* @param webServer The Instance of the ProtocolWebServer
*/
public void setWebServer(ProtocolWebServer webServer) {
if (this.webServer != null) return;
this.webServer = webServer;
}
/** /**
* Handles the event when a connection is established. * Handles the event when a connection is established.
* Adds the connected client to the protocol web server's client list. * Adds the connected client to the protocol web server's client list.
@@ -23,7 +41,7 @@ public final class WebServerListener extends EventListener {
*/ */
@Listener @Listener
public void onConnect(ConnectionHandlerConnectedEvent event) { public void onConnect(ConnectionHandlerConnectedEvent event) {
ProtocolBridge.getInstance().getProtocolWebServer().getClients().add(new ConnectedWebClient(event.getConnectionHandler())); webServer.getClients().add(new ConnectedWebClient(event.getConnectionHandler()));
} }
/** /**
@@ -34,7 +52,7 @@ public final class WebServerListener extends EventListener {
*/ */
@Listener @Listener
public void onDisconnect(ConnectionHandlerDisconnectedEvent event) { public void onDisconnect(ConnectionHandlerDisconnectedEvent event) {
ProtocolBridge.getInstance().getProtocolWebServer().getClients().removeIf(client -> client.getPipelineConnection().getClientID() == -1); webServer.getClients().removeIf(client -> client.getPipelineConnection().getClientID() == -1);
} }
} }

View File

@@ -129,7 +129,7 @@ public final class AuthPacket extends OACPacket {
} }
protocolBridge.getProtocolClient().setServerVersion(serverVersion); protocolBridge.getProtocolClient().setServerVersion(serverVersion);
protocolBridge.getProtocolSettings().eventManager.executeEvent(new ConnectedToProtocolINSServerEvent()); protocolBridge.getProtocolSettings().eventManager.executeEvent(new ConnectedToProtocolINSServerEvent(protocolBridge.getProtocolClient()));
} }
} }
} }

View File

@@ -16,21 +16,24 @@ public final class GetDestinationPacket extends OACPacket {
private int clientID; private int clientID;
private INSResponseCode validationResponse; private INSResponseCode validationResponse;
private String destination; private String destination;
private ProtocolBridge protocolBridge;
// INS-Server Constructor // INS-Server Constructor
public GetDestinationPacket(InfoName infoName, INSResponseCode validationResponse, String destination) { public GetDestinationPacket(InfoName infoName, INSResponseCode validationResponse, String destination, ProtocolBridge protocolBridge) {
this(); this();
this.infoName = infoName; this.infoName = infoName;
this.validationResponse = validationResponse; this.validationResponse = validationResponse;
this.destination = destination; this.destination = destination;
this.protocolBridge = protocolBridge;
} }
// Client Constructor // Client Constructor
public GetDestinationPacket(InfoName infoName, INSResponseCode validationResponse) { public GetDestinationPacket(InfoName infoName, INSResponseCode validationResponse, ProtocolBridge protocolBridge) {
this(); this();
this.infoName = infoName; this.infoName = infoName;
this.validationResponse = validationResponse; this.validationResponse = validationResponse;
this.destination = destination; this.destination = destination;
this.protocolBridge = protocolBridge;
} }
// Registration Constructor // Registration Constructor
@@ -40,13 +43,13 @@ public final class GetDestinationPacket extends OACPacket {
@Override @Override
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException { public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
if (ProtocolBridge.getInstance().isRunningAsClient()) { if (protocolBridge.isRunningAsClient()) {
if (validationResponse != INSResponseCode.RESPONSE_INFONAME_FULLY_EXIST) return; if (validationResponse != INSResponseCode.RESPONSE_INFONAME_FULLY_EXIST) return;
objectOutputStream.writeInt(ProtocolBridge.getInstance().getProtocolClient().getClientINSConnection().getClientID()); objectOutputStream.writeInt(protocolBridge.getProtocolClient().getClientINSConnection().getClientID());
objectOutputStream.writeObject(infoName); objectOutputStream.writeObject(infoName);
objectOutputStream.writeObject(validationResponse); objectOutputStream.writeObject(validationResponse);
} else if (ProtocolBridge.getInstance().isRunningAsINSServer()) { } else if (protocolBridge.isRunningAsINSServer()) {
objectOutputStream.writeObject(infoName); objectOutputStream.writeObject(infoName);
objectOutputStream.writeObject(validationResponse); objectOutputStream.writeObject(validationResponse);
objectOutputStream.writeUTF(destination); objectOutputStream.writeUTF(destination);
@@ -55,16 +58,16 @@ public final class GetDestinationPacket extends OACPacket {
@Override @Override
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
if (ProtocolBridge.getInstance().isRunningAsINServer()) { if (protocolBridge.isRunningAsINSServer()) {
clientID = objectInputStream.readInt(); clientID = objectInputStream.readInt();
infoName = (InfoName) objectInputStream.readObject(); infoName = (InfoName) objectInputStream.readObject();
validationResponse = (INSResponseCode) objectInputStream.readObject(); validationResponse = (INSResponseCode) objectInputStream.readObject();
} else if (ProtocolBridge.getInstance().isRunningAsClient()) { } else if (protocolBridge.isRunningAsClient()) {
infoName = (InfoName) objectInputStream.readObject(); infoName = (InfoName) objectInputStream.readObject();
validationResponse = (INSResponseCode) objectInputStream.readObject(); validationResponse = (INSResponseCode) objectInputStream.readObject();
destination = objectInputStream.readUTF(); destination = objectInputStream.readUTF();
ProtocolBridge.getInstance().getProtocolClient().getDestinationCompleted(infoName, destination, validationResponse); protocolBridge.getProtocolClient().getDestinationCompleted(infoName, destination, validationResponse);
} }
} }
@@ -72,14 +75,14 @@ public final class GetDestinationPacket extends OACPacket {
protected void onResponseCodeRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) { protected void onResponseCodeRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) {
super.onResponseCodeRead(packetHandler, objectInputStream); super.onResponseCodeRead(packetHandler, objectInputStream);
if (ProtocolBridge.getInstance().isRunningAsINSServer()) { if (protocolBridge.isRunningAsINSServer()) {
if (validationResponse != INSResponseCode.RESPONSE_INFONAME_FULLY_EXIST) return; if (validationResponse != INSResponseCode.RESPONSE_INFONAME_FULLY_EXIST) return;
destination = infoName.getDestination(); destination = infoName.getDestination(protocolBridge);
try { try {
ProtocolBridge.getInstance().getProtocolINSServer().getClientByID(clientID).getConnectionHandler().sendPacket(new GetDestinationPacket(infoName, validationResponse, destination)); protocolBridge.getProtocolINSServer().getClientByID(clientID).getConnectionHandler().sendPacket(new GetDestinationPacket(infoName, validationResponse, destination, protocolBridge));
} catch (IOException | ClassNotFoundException exception) { } catch (IOException | ClassNotFoundException exception) {
ProtocolBridge.getInstance().getProtocolINSServer().infoNameDestinationPacketFailedSend(ProtocolBridge.getInstance().getProtocolINSServer().getClientByID(clientID), infoName, validationResponse, exception); protocolBridge.getProtocolINSServer().infoNameDestinationPacketFailedSend(protocolBridge.getProtocolINSServer().getClientByID(clientID), infoName, validationResponse, exception);
} }
} }
} }

View File

@@ -13,12 +13,14 @@ import java.io.ObjectOutputStream;
public final class UnsupportedClassicPacket extends OACPacket { public final class UnsupportedClassicPacket extends OACPacket {
private Class<? extends OACPacket> unsupportedClassicPacket; private Class<? extends OACPacket> unsupportedClassicPacket;
private Object[] content; private Object[] content;
private ProtocolBridge protocolBridge;
// Constructor with more information // Constructor with more information
public UnsupportedClassicPacket(Class<? extends OACPacket> unsupportedClassicPacket, Object[] content) { public UnsupportedClassicPacket(Class<? extends OACPacket> unsupportedClassicPacket, Object[] content, ProtocolBridge protocolBridge) {
this(); this();
this.unsupportedClassicPacket = unsupportedClassicPacket; this.unsupportedClassicPacket = unsupportedClassicPacket;
this.content = content; this.content = content;
this.protocolBridge = protocolBridge;
} }
// Registration Constructor // Registration Constructor
@@ -28,8 +30,8 @@ public final class UnsupportedClassicPacket extends OACPacket {
@Override @Override
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException { public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
if (ProtocolBridge.getInstance().isRunningAsClient()) if (protocolBridge.isRunningAsClient())
objectOutputStream.writeInt(ProtocolBridge.getInstance().getProtocolClient().getClientINSConnection().getClientID()); objectOutputStream.writeInt(protocolBridge.getProtocolClient().getClientINSConnection().getClientID());
objectOutputStream.writeUTF(unsupportedClassicPacket.getName()); objectOutputStream.writeUTF(unsupportedClassicPacket.getName());
objectOutputStream.writeInt(content.length); objectOutputStream.writeInt(content.length);
@@ -40,7 +42,7 @@ public final class UnsupportedClassicPacket extends OACPacket {
@Override @Override
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
int clientID = 0; int clientID = 0;
if (ProtocolBridge.getInstance().isRunningAsINSServer()) clientID = objectInputStream.readInt(); if (protocolBridge.isRunningAsINSServer()) clientID = objectInputStream.readInt();
String className = objectInputStream.readUTF(); String className = objectInputStream.readUTF();
int size = objectInputStream.readInt(); int size = objectInputStream.readInt();
content = new Object[size]; content = new Object[size];
@@ -49,12 +51,12 @@ public final class UnsupportedClassicPacket extends OACPacket {
content[i] = objectInputStream.readObject(); content[i] = objectInputStream.readObject();
} }
if (ProtocolBridge.getInstance().isRunningAsINSServer()) if (protocolBridge.isRunningAsINSServer())
ProtocolBridge.getInstance().getClassicHandlerINSServer().unsupportedClassicPacket(className, content, ProtocolBridge.getInstance().getProtocolINSServer().getClientByID(clientID)); protocolBridge.getClassicHandlerINSServer().unsupportedClassicPacket(className, content, protocolBridge.getProtocolINSServer().getClientByID(clientID));
else if (ProtocolBridge.getInstance().isRunningAsClient()) else if (protocolBridge.isRunningAsClient())
ProtocolBridge.getInstance().getClassicHandlerClient().unsupportedClassicPacket(className, content); protocolBridge.getClassicHandlerClient().unsupportedClassicPacket(className, content);
else if (ProtocolBridge.getInstance().isRunningAsWebServer()) else if (protocolBridge.isRunningAsWebServer())
ProtocolBridge.getInstance().getClassicHandlerWebServer().unsupportedClassicPacket(className, content, ProtocolBridge.getInstance().getProtocolINSServer().getClientByID(clientID)); protocolBridge.getClassicHandlerWebServer().unsupportedClassicPacket(className, content, protocolBridge.getProtocolINSServer().getClientByID(clientID));
} }
} }

View File

@@ -19,10 +19,12 @@ public final class Classic_DomainPacket extends OACPacket {
private Classic_RequestDomain requestDomain; private Classic_RequestDomain requestDomain;
private Classic_Domain domain; private Classic_Domain domain;
private int clientID; private int clientID;
private ProtocolBridge bridge;
public Classic_DomainPacket(int toClient, Classic_RequestDomain requestDomain, Classic_Domain domain) { public Classic_DomainPacket(int toClient, Classic_RequestDomain requestDomain, Classic_Domain domain, ProtocolBridge protocolBridge) {
this(); this();
this.clientID = toClient; this.clientID = toClient;
this.bridge = protocolBridge;
this.requestDomain = requestDomain; this.requestDomain = requestDomain;
this.domain = domain; this.domain = domain;
@@ -35,12 +37,12 @@ public final class Classic_DomainPacket extends OACPacket {
@Override @Override
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException { public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
if (ProtocolBridge.getInstance().isRunningAsINSServer()) { if (bridge.isRunningAsINSServer()) {
objectOutputStream.writeInt(clientID); objectOutputStream.writeInt(clientID);
objectOutputStream.writeObject(requestDomain); objectOutputStream.writeObject(requestDomain);
objectOutputStream.writeObject(domain); objectOutputStream.writeObject(domain);
} else if (ProtocolBridge.getInstance().isRunningAsClient()) { } else if (bridge.isRunningAsClient()) {
clientID = ProtocolBridge.getInstance().getProtocolClient().getClientINSConnection().getClientID(); clientID = bridge.getProtocolClient().getClientINSConnection().getClientID();
objectOutputStream.writeInt(clientID); objectOutputStream.writeInt(clientID);
objectOutputStream.writeObject(requestDomain); objectOutputStream.writeObject(requestDomain);
} }
@@ -50,36 +52,36 @@ public final class Classic_DomainPacket extends OACPacket {
@Override @Override
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
if (ProtocolBridge.getInstance().isRunningAsINSServer()) { if (bridge.isRunningAsINSServer()) {
clientID = objectInputStream.readInt(); clientID = objectInputStream.readInt();
requestDomain = (Classic_RequestDomain) objectInputStream.readObject(); requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject(); Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
try { try {
domain = ProtocolBridge.getInstance().getClassicHandlerINSServer().getDomain(requestDomain); domain = bridge.getClassicHandlerINSServer().getDomain(requestDomain);
} catch (SQLException exception) { } catch (SQLException exception) {
exception.printStackTrace(); exception.printStackTrace();
} }
ProtocolBridge.getInstance().getProtocolINSServer().getNetworkServer().getEventManager().executeEvent(new Classic_DomainPacketReceivedEvent(protocolVersion, domain, requestDomain, clientID)); bridge.getProtocolINSServer().getNetworkServer().getEventManager().executeEvent(new Classic_DomainPacketReceivedEvent(protocolVersion, domain, requestDomain, clientID));
if (ProtocolBridge.getInstance().getProtocolINSServer().getClientByID(clientID).supportClientClassic()) if (bridge.getProtocolINSServer().getClientByID(clientID).supportClientClassic())
ProtocolBridge.getInstance().getProtocolINSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new Classic_DomainPacket(clientID, requestDomain, domain)); bridge.getProtocolINSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new Classic_DomainPacket(clientID, requestDomain, domain, bridge));
else else
ProtocolBridge.getInstance().getProtocolINSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{clientID, requestDomain, domain})); bridge.getProtocolINSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{clientID, requestDomain, domain}, bridge));
} else if (ProtocolBridge.getInstance().isRunningAsClient()) { } else if (bridge.isRunningAsClient()) {
clientID = objectInputStream.readInt(); clientID = objectInputStream.readInt();
requestDomain = (Classic_RequestDomain) objectInputStream.readObject(); requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
domain = (Classic_Domain) objectInputStream.readObject(); domain = (Classic_Domain) objectInputStream.readObject();
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject(); Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
ProtocolBridge.getInstance().getProtocolClient().getClientINSConnection().getEventManager().executeEvent(new Classic_DomainPacketReceivedEvent(protocolVersion, domain, requestDomain, clientID)); bridge.getProtocolClient().getClientINSConnection().getEventManager().executeEvent(new Classic_DomainPacketReceivedEvent(protocolVersion, domain, requestDomain, clientID));
} else if (ProtocolBridge.getInstance().isRunningAsWebServer()) { } else if (bridge.isRunningAsWebServer()) {
clientID = objectInputStream.readInt(); clientID = objectInputStream.readInt();
requestDomain = (Classic_RequestDomain) objectInputStream.readObject(); requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject(); Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
ProtocolBridge.getInstance().getProtocolWebServer().getPipelineServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{clientID, requestDomain, domain})); bridge.getProtocolWebServer().getPipelineServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{clientID, requestDomain, domain}, bridge));
} }
} }
} }

View File

@@ -13,12 +13,14 @@ import java.io.ObjectOutputStream;
public final class Classic_MessagePacket extends OACPacket { public final class Classic_MessagePacket extends OACPacket {
private String message; private String message;
private int clientID; private int clientID;
private ProtocolBridge bridge;
// Constructor with message and client id // Constructor with message and client id
public Classic_MessagePacket(String message, int toClient) { public Classic_MessagePacket(String message, int toClient, ProtocolBridge bridge) {
this(); this();
this.message = message; this.message = message;
this.clientID = toClient; this.clientID = toClient;
this.bridge = bridge;
} }
public Classic_MessagePacket() { public Classic_MessagePacket() {
@@ -27,10 +29,10 @@ public final class Classic_MessagePacket extends OACPacket {
@Override @Override
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException { public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
if (ProtocolBridge.getInstance().isRunningAsINSServer() || ProtocolBridge.getInstance().isRunningAsWebServer()) if (bridge.isRunningAsINSServer() || bridge.isRunningAsWebServer())
objectOutputStream.writeInt(clientID); objectOutputStream.writeInt(clientID);
else if (ProtocolBridge.getInstance().isRunningAsClient()) { else if (bridge.isRunningAsClient()) {
clientID = ProtocolBridge.getInstance().getProtocolClient().getClientINSConnection().getClientID(); clientID = bridge.getProtocolClient().getClientINSConnection().getClientID();
objectOutputStream.writeInt(clientID); objectOutputStream.writeInt(clientID);
} }
@@ -40,24 +42,24 @@ public final class Classic_MessagePacket extends OACPacket {
@Override @Override
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
if (ProtocolBridge.getInstance().isRunningAsINSServer()) { if (bridge.isRunningAsINSServer()) {
clientID = objectInputStream.readInt(); clientID = objectInputStream.readInt();
String message = objectInputStream.readUTF(); String message = objectInputStream.readUTF();
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject(); Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
ProtocolBridge.getInstance().getClassicHandlerINSServer().handleMessage(ProtocolBridge.getInstance().getProtocolINSServer().getClientByID(clientID), message, protocolVersion); bridge.getClassicHandlerINSServer().handleMessage(bridge.getProtocolINSServer().getClientByID(clientID), message, protocolVersion);
} else if (ProtocolBridge.getInstance().isRunningAsClient()) { } else if (bridge.isRunningAsClient()) {
clientID = objectInputStream.readInt(); clientID = objectInputStream.readInt();
String message = objectInputStream.readUTF(); String message = objectInputStream.readUTF();
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject(); Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
ProtocolBridge.getInstance().getClassicHandlerClient().handleMessage(message, protocolVersion); bridge.getClassicHandlerClient().handleMessage(message, protocolVersion);
} else if (ProtocolBridge.getInstance().isRunningAsWebServer()) { } else if (bridge.isRunningAsWebServer()) {
clientID = objectInputStream.readInt(); clientID = objectInputStream.readInt();
String message = objectInputStream.readUTF(); String message = objectInputStream.readUTF();
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject(); Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
ProtocolBridge.getInstance().getClassicHandlerWebServer().handleMessage(ProtocolBridge.getInstance().getProtocolINSServer().getClientByID(clientID), message, protocolVersion); bridge.getClassicHandlerWebServer().handleMessage(bridge.getProtocolINSServer().getClientByID(clientID), message, protocolVersion);
} }
} }
} }

View File

@@ -22,9 +22,11 @@ public final class Classic_PingPacket extends OACPacket {
private int clientID; private int clientID;
private boolean reachable; private boolean reachable;
private Classic_ProtocolVersion protocolVersion; private Classic_ProtocolVersion protocolVersion;
private ProtocolBridge bridge;
public Classic_PingPacket(Classic_RequestDomain requestDomain, Classic_Domain domain, boolean reachable) { public Classic_PingPacket(Classic_RequestDomain requestDomain, Classic_Domain domain, boolean reachable, ProtocolBridge bridge) {
this(); this();
this.bridge = bridge;
this.requestDomain = requestDomain; this.requestDomain = requestDomain;
this.domain = domain; this.domain = domain;
@@ -38,13 +40,13 @@ public final class Classic_PingPacket extends OACPacket {
@Override @Override
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException { public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
if (ProtocolBridge.getInstance().isRunningAsINSServer()) { if (bridge.isRunningAsINSServer()) {
objectOutputStream.writeInt(clientID); objectOutputStream.writeInt(clientID);
objectOutputStream.writeObject(requestDomain); objectOutputStream.writeObject(requestDomain);
objectOutputStream.writeObject(domain); objectOutputStream.writeObject(domain);
objectOutputStream.writeBoolean(reachable); objectOutputStream.writeBoolean(reachable);
} else if (ProtocolBridge.getInstance().isRunningAsClient()) { } else if (bridge.isRunningAsClient()) {
clientID = ProtocolBridge.getInstance().getProtocolClient().getClientINSConnection().getClientID(); clientID = bridge.getProtocolClient().getClientINSConnection().getClientID();
objectOutputStream.writeInt(clientID); objectOutputStream.writeInt(clientID);
objectOutputStream.writeObject(requestDomain); objectOutputStream.writeObject(requestDomain);
} }
@@ -54,38 +56,38 @@ public final class Classic_PingPacket extends OACPacket {
@Override @Override
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
if (ProtocolBridge.getInstance().isRunningAsINSServer()) { if (bridge.isRunningAsINSServer()) {
clientID = objectInputStream.readInt(); clientID = objectInputStream.readInt();
requestDomain = (Classic_RequestDomain) objectInputStream.readObject(); requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject(); protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
try { try {
domain = ProtocolBridge.getInstance().getClassicHandlerINSServer().ping(requestDomain); domain = bridge.getClassicHandlerINSServer().ping(requestDomain);
} catch (SQLException exception) { } catch (SQLException exception) {
exception.printStackTrace(); exception.printStackTrace();
} }
reachable = domain != null; reachable = domain != null;
ProtocolBridge.getInstance().getProtocolINSServer().getNetworkServer().getEventManager().executeEvent(new Classic_PingPacketReceivedEvent(protocolVersion, domain, requestDomain, reachable, clientID)); bridge.getProtocolINSServer().getNetworkServer().getEventManager().executeEvent(new Classic_PingPacketReceivedEvent(protocolVersion, domain, requestDomain, reachable, clientID));
if (ProtocolBridge.getInstance().getProtocolINSServer().getClientByID(clientID).supportClientClassic()) if (bridge.getProtocolINSServer().getClientByID(clientID).supportClientClassic())
ProtocolBridge.getInstance().getProtocolINSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new Classic_PingPacket(requestDomain, domain, reachable)); bridge.getProtocolINSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new Classic_PingPacket(requestDomain, domain, reachable, bridge));
else else
ProtocolBridge.getInstance().getProtocolINSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{requestDomain, domain, reachable})); bridge.getProtocolINSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{requestDomain, domain, reachable}, bridge));
} else if (ProtocolBridge.getInstance().isRunningAsClient()) { } else if (bridge.isRunningAsClient()) {
clientID = objectInputStream.readInt(); clientID = objectInputStream.readInt();
requestDomain = (Classic_RequestDomain) objectInputStream.readObject(); requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
domain = (Classic_Domain) objectInputStream.readObject(); domain = (Classic_Domain) objectInputStream.readObject();
boolean reachable = objectInputStream.readBoolean(); boolean reachable = objectInputStream.readBoolean();
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject(); Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
ProtocolBridge.getInstance().getProtocolClient().validationCompleted(domain.getInfoName(), reachable ? INSResponseCode.RESPONSE_INFONAME_FULLY_EXIST : INSResponseCode.RESPONSE_INFONAME_FULLY_NOT_EXIST); bridge.getProtocolClient().validationCompleted(domain.getInfoName(), reachable ? INSResponseCode.RESPONSE_INFONAME_FULLY_EXIST : INSResponseCode.RESPONSE_INFONAME_FULLY_NOT_EXIST);
ProtocolBridge.getInstance().getProtocolClient().getClientINSConnection().getEventManager().executeEvent(new Classic_PingPacketReceivedEvent(protocolVersion, domain, requestDomain, reachable, clientID)); bridge.getProtocolClient().getClientINSConnection().getEventManager().executeEvent(new Classic_PingPacketReceivedEvent(protocolVersion, domain, requestDomain, reachable, clientID));
} else if (ProtocolBridge.getInstance().isRunningAsWebServer()) { } else if (bridge.isRunningAsWebServer()) {
clientID = objectInputStream.readInt(); clientID = objectInputStream.readInt();
requestDomain = (Classic_RequestDomain) objectInputStream.readObject(); requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject(); protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
ProtocolBridge.getInstance().getProtocolWebServer().getPipelineServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{requestDomain})); bridge.getProtocolWebServer().getPipelineServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{requestDomain}, bridge));
} }
} }
} }

View File

@@ -310,7 +310,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
*/ */
public final void validateInfoName(InfoName infoName) throws IOException, ClassNotFoundException { public final void validateInfoName(InfoName infoName) throws IOException, ClassNotFoundException {
// Send Classic_PingPacket if classic protocol is supported // Send Classic_PingPacket if classic protocol is supported
Classic_PingPacket cPingPacket = new Classic_PingPacket(new Classic_RequestDomain(infoName.getName(), infoName.getTopLevelName(), infoName.getPath()), null, false); Classic_PingPacket cPingPacket = new Classic_PingPacket(new Classic_RequestDomain(infoName.getName(), infoName.getTopLevelName(), infoName.getPath(), protocolBridge), null, false, protocolBridge);
if (protocolBridge.isClassicSupported()) clientToINS.sendPacket(cPingPacket); if (protocolBridge.isClassicSupported()) clientToINS.sendPacket(cPingPacket);
// Send ValidateInfoNamePacket // Send ValidateInfoNamePacket
@@ -327,16 +327,16 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
*/ */
public final void requestInfoName(InfoName infoName, INSResponseCode responseCode) throws IOException, ClassNotFoundException { public final void requestInfoName(InfoName infoName, INSResponseCode responseCode) throws IOException, ClassNotFoundException {
// Send Classic_DomainPacket if classic protocol is supported // Send Classic_DomainPacket if classic protocol is supported
Classic_DomainPacket cDomainPacket = new Classic_DomainPacket(0, new Classic_RequestDomain(infoName.getName(), infoName.getTopLevelName(), infoName.getPath()), null); Classic_DomainPacket cDomainPacket = new Classic_DomainPacket(0, new Classic_RequestDomain(infoName.getName(), infoName.getTopLevelName(), infoName.getPath(), protocolBridge), null, protocolBridge);
if (protocolBridge.isClassicSupported()) clientToINS.sendPacket(cDomainPacket); if (protocolBridge.isClassicSupported()) clientToINS.sendPacket(cDomainPacket);
// Send GetDestinationPacket // Send GetDestinationPacket
clientToINS.sendPacket(new GetDestinationPacket(infoName, responseCode)); clientToINS.sendPacket(new GetDestinationPacket(infoName, responseCode, protocolBridge));
} }
/** /**
* Set protocol bridge * Set protocol bridge.
* @param protocolBridge The ProtocolBridge object * @param protocolBridge The ProtocolBridge object.
*/ */
public void setProtocolBridge(ProtocolBridge protocolBridge) { public void setProtocolBridge(ProtocolBridge protocolBridge) {
if (this.protocolBridge == null) this.protocolBridge = protocolBridge; if (this.protocolBridge == null) this.protocolBridge = protocolBridge;

View File

@@ -2,6 +2,7 @@ package org.openautonomousconnection.protocol.side.client;
import dev.unlegitdqrk.unlegitlibrary.network.system.client.NetworkClient; import dev.unlegitdqrk.unlegitlibrary.network.system.client.NetworkClient;
import lombok.Getter; import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo; import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.InfoName; import org.openautonomousconnection.protocol.versions.v1_0_0.beta.InfoName;
@@ -65,7 +66,7 @@ public final class WebClient {
// Set logger from ProtocolBridge // Set logger from ProtocolBridge
setLogger(protocolClient.getProtocolBridge().getLogger()). setLogger(protocolClient.getProtocolBridge().getLogger()).
// Set the destination and port for the pipeline connection // Set the destination and port for the pipeline connection
setHost(infoName.getDestination()).setPort(pipelinePort). setHost(infoName.getDestination(protocolClient.getProtocolBridge())).setPort(pipelinePort).
// Configure packet handler and event manager // Configure packet handler and event manager
setPacketHandler(protocolClient.getProtocolBridge().getProtocolSettings().packetHandler). setPacketHandler(protocolClient.getProtocolBridge().getProtocolSettings().packetHandler).
@@ -107,10 +108,10 @@ public final class WebClient {
// Create raw socket and wrap it in SSL socket // Create raw socket and wrap it in SSL socket
if (proxy != null) { if (proxy != null) {
Socket rawSocket = new Socket(proxy); Socket rawSocket = new Socket(proxy);
rawSocket.connect(new InetSocketAddress(infoName.getDestination(), webPort), 0); rawSocket.connect(new InetSocketAddress(infoName.getDestination(protocolClient.getProtocolBridge()), webPort), 0);
tempSocket = (SSLSocket) sslSocketFactory.createSocket(rawSocket, infoName.getDestination(), webPort, true); tempSocket = (SSLSocket) sslSocketFactory.createSocket(rawSocket, infoName.getDestination(protocolClient.getProtocolBridge()), webPort, true);
} else { } else {
tempSocket = (SSLSocket) sslSocketFactory.createSocket(infoName.getDestination(), webPort); tempSocket = (SSLSocket) sslSocketFactory.createSocket(infoName.getDestination(protocolClient.getProtocolBridge()), webPort);
} }
clientToWebServer = tempSocket; clientToWebServer = tempSocket;

View File

@@ -1,7 +1,9 @@
package org.openautonomousconnection.protocol.side.client.events; package org.openautonomousconnection.protocol.side.client.events;
import dev.unlegitdqrk.unlegitlibrary.event.impl.Event; import dev.unlegitdqrk.unlegitlibrary.event.impl.Event;
import lombok.Getter;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo; import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.side.client.ProtocolClient;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
/** /**
@@ -9,4 +11,15 @@ import org.openautonomousconnection.protocol.versions.ProtocolVersion;
*/ */
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS)
public final class ConnectedToProtocolINSServerEvent extends Event { public final class ConnectedToProtocolINSServerEvent extends Event {
/**
* Reference to the ProtocolClient object.
*/
@Getter
private final ProtocolClient client;
public ConnectedToProtocolINSServerEvent(ProtocolClient client) {
this.client = client;
}
} }

View File

@@ -189,7 +189,7 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
/** /**
* @param infoName The InfoName to look up. * @param infoName The InfoName to look up.
* @return The destination associated with the InfoName. * @return The destination associated with the InfoName.
* @see InfoName#getDestination() * @see InfoName#getDestination(ProtocolBridge)
* Abstract method to get the destination for a given InfoName. * Abstract method to get the destination for a given InfoName.
*/ */
public abstract String getInfoNameDestination(InfoName infoName); public abstract String getInfoNameDestination(InfoName infoName);
@@ -198,7 +198,7 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
* @param infoName The parent InfoName. * @param infoName The parent InfoName.
* @param subname The subname to look up. * @param subname The subname to look up.
* @return The destination associated with the subname. * @return The destination associated with the subname.
* @see InfoName#getDestination() * @see InfoName#getDestination(ProtocolBridge)
* Abstract method to get the destination for a given subname under a specific InfoName. * Abstract method to get the destination for a given subname under a specific InfoName.
*/ */
public abstract String getSubnameDestination(InfoName infoName, String subname); public abstract String getSubnameDestination(InfoName infoName, String subname);
@@ -206,7 +206,7 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
/** /**
* @param topLevelName The top-level name. * @param topLevelName The top-level name.
* @return The information site URL for the specified top-level name. * @return The information site URL for the specified top-level name.
* @see InfoName#getDestination() * @see InfoName#getDestination(ProtocolBridge)
* Abstract method to get the top-level name information site URL. * Abstract method to get the top-level name information site URL.
*/ */
public abstract String getTLNInfoSite(String topLevelName); public abstract String getTLNInfoSite(String topLevelName);

View File

@@ -140,21 +140,21 @@ public final class InfoName implements Serializable {
* @return the destination as a string. * @return the destination as a string.
*/ */
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS)
public String getDestination() { public String getDestination(ProtocolBridge protocolBridge) {
// If running as client or web server, return invalid request // If running as client or web server, return invalid request
if (ProtocolBridge.getInstance().isRunningAsClient() || ProtocolBridge.getInstance().isRunningAsWebServer()) if (protocolBridge.isRunningAsClient() || protocolBridge.isRunningAsWebServer())
return INSResponseCode.RESPONSE_INVALID_REQUEST.toString(); return INSResponseCode.RESPONSE_INVALID_REQUEST.toString();
// Handle special default InfoNames // Handle special default InfoNames
if (this.equals(DefaultInfoNames.INS_INFO_SITE)) if (this.equals(DefaultInfoNames.INS_INFO_SITE))
return ProtocolBridge.getInstance().getProtocolINSServer().getINSInfoSite(); return protocolBridge.getProtocolINSServer().getINSInfoSite();
if (this.equals(DefaultInfoNames.INS_REGISTER_SITE)) if (this.equals(DefaultInfoNames.INS_REGISTER_SITE))
return ProtocolBridge.getInstance().getProtocolINSServer().getINSRegisterSite(); return protocolBridge.getProtocolINSServer().getINSRegisterSite();
if (this.equals(DefaultInfoNames.TLN_INFO_SITE(topLevelName))) if (this.equals(DefaultInfoNames.TLN_INFO_SITE(topLevelName)))
return ProtocolBridge.getInstance().getProtocolINSServer().getTLNInfoSite(topLevelName); return protocolBridge.getProtocolINSServer().getTLNInfoSite(topLevelName);
// Return destination based on whether subname exists // Return destination based on whether subname exists
return !hasSubname() ? ProtocolBridge.getInstance().getProtocolINSServer().getInfoNameDestination(this) : ProtocolBridge.getInstance().getProtocolINSServer().getSubnameDestination(this, subname); return !hasSubname() ? protocolBridge.getProtocolINSServer().getInfoNameDestination(this) : protocolBridge.getProtocolINSServer().getSubnameDestination(this, subname);
} }
/** /**

View File

@@ -1,8 +1,10 @@
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers; package org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers;
import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge; import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo; import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_MessagePacket; import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_MessagePacket;
import org.openautonomousconnection.protocol.side.client.ProtocolClient;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.site.Classic_SiteType; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.site.Classic_SiteType;
@@ -16,6 +18,21 @@ import java.io.IOException;
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.CLIENT) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.CLIENT)
public abstract class ClassicHandlerClient { public abstract class ClassicHandlerClient {
/**
* Reference to the ProtocolClient
*/
@Getter
private final ProtocolClient client;
/**
* Sets the client variable
*
* @param client The ProtocolClient Object
*/
public ClassicHandlerClient(ProtocolClient client) {
this.client = client;
}
public abstract void unsupportedClassicPacket(String classicPacketClassName, Object[] content); public abstract void unsupportedClassicPacket(String classicPacketClassName, Object[] content);
public abstract void handleHTMLContent(Classic_SiteType siteType, Classic_Domain domain, String html); public abstract void handleHTMLContent(Classic_SiteType siteType, Classic_Domain domain, String html);
@@ -23,6 +40,6 @@ public abstract class ClassicHandlerClient {
public abstract void handleMessage(String message, Classic_ProtocolVersion protocolVersion); public abstract void handleMessage(String message, Classic_ProtocolVersion protocolVersion);
public final void sendMessage(String message) throws IOException, ClassNotFoundException { public final void sendMessage(String message) throws IOException, ClassNotFoundException {
ProtocolBridge.getInstance().getProtocolClient().getClientINSConnection().sendPacket(new Classic_MessagePacket(message, 0)); client.getClientINSConnection().sendPacket(new Classic_MessagePacket(message, 0, client.getProtocolBridge()));
} }
} }

View File

@@ -1,6 +1,7 @@
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects; package org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects;
import lombok.Getter; import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.InfoName; import org.openautonomousconnection.protocol.versions.v1_0_0.beta.InfoName;
import java.io.Serializable; import java.io.Serializable;
@@ -38,23 +39,30 @@ public class Classic_Domain implements Serializable {
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3") @Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
private final String destination; private final String destination;
/**
* The ProtocolBridge reference.
*/
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
private final ProtocolBridge protocolBridge;
/** /**
* The encapsulated Domain object for modern usage. * The encapsulated Domain object for modern usage.
*/ */
@Getter @Getter
private final InfoName infoName; private final InfoName infoName;
public Classic_Domain(String name, String topLevelDomain, String destination, String path) { public Classic_Domain(String name, String topLevelDomain, String destination, String path, ProtocolBridge bridge) {
this.protocolBridge = bridge;
this.infoName = new InfoName(name + "." + topLevelDomain + "/" + (path.startsWith("/") ? path : "/" + path)); this.infoName = new InfoName(name + "." + topLevelDomain + "/" + (path.startsWith("/") ? path : "/" + path));
this.name = infoName.getName(); this.name = infoName.getName();
this.topLevelDomain = infoName.getTopLevelName(); this.topLevelDomain = infoName.getTopLevelName();
this.destination = infoName.getDestination(); this.destination = infoName.getDestination(bridge);
this.path = infoName.getPath(); this.path = infoName.getPath();
} }
@Override @Override
protected final Object clone() throws CloneNotSupportedException { protected final Object clone() throws CloneNotSupportedException {
return new Classic_Domain(name, topLevelDomain, destination, path); return new Classic_Domain(name, topLevelDomain, destination, path, protocolBridge);
} }
@Override @Override

View File

@@ -1,12 +1,14 @@
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects; package org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects;
import org.openautonomousconnection.protocol.ProtocolBridge;
/** /**
* Class representing a local domain in the Classic protocol. * Class representing a local domain in the Classic protocol.
* This class extends Classic_Domain and is used for local domain representation. * This class extends Classic_Domain and is used for local domain representation.
*/ */
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3") @Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
public final class Classic_LocalDomain extends Classic_Domain { public final class Classic_LocalDomain extends Classic_Domain {
public Classic_LocalDomain(String name, String endName, String path) { public Classic_LocalDomain(String name, String endName, String path, ProtocolBridge protocolBridge) {
super(name, endName, null, path); super(name, endName, null, path, protocolBridge);
} }
} }

View File

@@ -1,5 +1,7 @@
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects; package org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects;
import org.openautonomousconnection.protocol.ProtocolBridge;
import java.io.Serializable; import java.io.Serializable;
/** /**
@@ -9,7 +11,7 @@ import java.io.Serializable;
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3") @Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
public final class Classic_RequestDomain extends Classic_Domain implements Serializable { public final class Classic_RequestDomain extends Classic_Domain implements Serializable {
public Classic_RequestDomain(String name, String topLevelDomain, String path) { public Classic_RequestDomain(String name, String topLevelDomain, String path, ProtocolBridge protocolBridge) {
super(name, topLevelDomain, null, path); super(name, topLevelDomain, null, path, protocolBridge);
} }
} }

View File

@@ -1,5 +1,6 @@
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils; package org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils;
import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.InfoName; import org.openautonomousconnection.protocol.versions.v1_0_0.beta.InfoName;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain;
@@ -24,11 +25,12 @@ public final class ClassicConverter {
* Converts a InfoName object to a Classic_Domain object. * 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 * @return the converted Classic_Domain object
*/ */
@SuppressWarnings(value = "deprecation") @SuppressWarnings(value = "deprecation")
public static Classic_Domain infoNameToClassicDomain(InfoName newInfoName) { public static Classic_Domain infoNameToClassicDomain(InfoName newInfoName, ProtocolBridge protocolBridge) {
return new Classic_Domain(newInfoName.getName(), newInfoName.getTopLevelName(), newInfoName.getDestination(), newInfoName.getPath()); return new Classic_Domain(newInfoName.getName(), newInfoName.getTopLevelName(), newInfoName.getDestination(protocolBridge), newInfoName.getPath(), protocolBridge);
} }
/** /**

View File

@@ -2,6 +2,7 @@ package org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils;
import dev.unlegitdqrk.unlegitlibrary.event.EventListener; import dev.unlegitdqrk.unlegitlibrary.event.EventListener;
import dev.unlegitdqrk.unlegitlibrary.event.Listener; import dev.unlegitdqrk.unlegitlibrary.event.Listener;
import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge; import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_PingPacket; import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_PingPacket;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.events.Classic_DomainPacketReceivedEvent; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.events.Classic_DomainPacketReceivedEvent;
@@ -24,6 +25,21 @@ import java.net.URL;
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3") @Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
public final class Classic_ClientListener extends EventListener { public final class Classic_ClientListener extends EventListener {
/**
* Reference to the ProtocolBridge
*/
@Getter
private ProtocolBridge protocolBridge;
/**
* Set protocol bridge
* @param protocolBridge The ProtocolBridge object
*/
public void setProtocolBridge(ProtocolBridge protocolBridge) {
if (this.protocolBridge != null) return;
this.protocolBridge = protocolBridge;
}
/** /**
* Handles the event when a domain packet is received. * Handles the event when a domain packet is received.
* It checks if the domain exists and sends a ping request to the INS server. * It checks if the domain exists and sends a ping request to the INS server.
@@ -39,19 +55,19 @@ public final class Classic_ClientListener extends EventListener {
if (exists) { if (exists) {
try { try {
// Send a ping request to the INS server // Send a ping request to the INS server
if (!ProtocolBridge.getInstance().getProtocolClient().getClientINSConnection().sendPacket(new Classic_PingPacket(event.requestDomain, event.domain, false))) { if (!protocolBridge.getProtocolClient().getClientINSConnection().sendPacket(new Classic_PingPacket(event.requestDomain, event.domain, false, protocolBridge))) {
// If sending the packet fails, handle the error // If sending the packet fails, handle the error
ProtocolBridge.getInstance().getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-occurred", "html", ""), protocolBridge.getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-occurred", "html", "", protocolBridge),
Classic_WebsitesContent.ERROR_OCCURRED(event.domain + "/" + event.domain.path)); Classic_WebsitesContent.ERROR_OCCURRED(event.domain + "/" + event.domain.path));
} }
} catch (IOException | ClassNotFoundException e) { } catch (IOException | ClassNotFoundException e) {
// Handle any exceptions that occur during the process // Handle any exceptions that occur during the process
ProtocolBridge.getInstance().getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-occurred", "html", ""), protocolBridge.getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-occurred", "html", "", protocolBridge),
Classic_WebsitesContent.ERROR_OCCURRED(event.domain + "/" + event.domain.path + ":\n" + e.getMessage())); Classic_WebsitesContent.ERROR_OCCURRED(event.domain + "/" + event.domain.path + ":\n" + e.getMessage()));
} }
} else } else
// If the domain does not exist, handle the error // If the domain does not exist, handle the error
ProtocolBridge.getInstance().getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("domain-not-found", "html", ""), Classic_WebsitesContent.DOMAIN_NOT_FOUND); protocolBridge.getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("domain-not-found", "html", "", protocolBridge), Classic_WebsitesContent.DOMAIN_NOT_FOUND);
} }
/** /**
@@ -65,7 +81,7 @@ public final class Classic_ClientListener extends EventListener {
public void onPing(Classic_PingPacketReceivedEvent event) { public void onPing(Classic_PingPacketReceivedEvent event) {
// If the domain is reachable, fetch the HTML content // If the domain is reachable, fetch the HTML content
if (event.reachable) { if (event.reachable) {
String destination = event.domain.getInfoName().getDestination(); String destination = event.domain.getInfoName().getDestination(protocolBridge);
try { try {
// Create a URL object // Create a URL object
@@ -81,15 +97,15 @@ public final class Classic_ClientListener extends EventListener {
} }
// Handle the HTML content // Handle the HTML content
ProtocolBridge.getInstance().getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PUBLIC, event.domain, content.toString()); protocolBridge.getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PUBLIC, event.domain, content.toString());
} catch (IOException exception) { } catch (IOException exception) {
// Handle any exceptions that occur during the process // Handle any exceptions that occur during the process
ProtocolBridge.getInstance().getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-occurred", "html", ""), protocolBridge.getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-occurred", "html", "", protocolBridge),
Classic_WebsitesContent.ERROR_OCCURRED(exception.getMessage().replace(event.domain.getInfoName().getDestination(), event.domain + "/" + event.domain.path))); Classic_WebsitesContent.ERROR_OCCURRED(exception.getMessage().replace(event.domain.getInfoName().getDestination(protocolBridge), event.domain + "/" + event.domain.path)));
} }
} else } else
// If the domain is not reachable, handle the error // If the domain is not reachable, handle the error
ProtocolBridge.getInstance().getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-not-reached", "html", ""), Classic_WebsitesContent.DOMAIN_NOT_REACHABLE); protocolBridge.getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-not-reached", "html", "", protocolBridge), Classic_WebsitesContent.DOMAIN_NOT_REACHABLE);
} }
@Override @Override