Removed ProtocolBridge#getInstance
This commit is contained in:
@@ -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.ValidateInfoNamePacket;
|
||||
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.ins.ProtocolINSServer;
|
||||
import org.openautonomousconnection.protocol.side.web.ProtocolWebServer;
|
||||
@@ -179,8 +181,8 @@ public final class ProtocolBridge {
|
||||
private void registerPackets() {
|
||||
// Classic packets
|
||||
Classic_DomainPacket cDomainPacket = new Classic_DomainPacket();
|
||||
Classic_DomainPacket cMessagePacket = new Classic_DomainPacket();
|
||||
Classic_DomainPacket cPingPacket = new Classic_DomainPacket();
|
||||
Classic_MessagePacket cMessagePacket = new Classic_MessagePacket();
|
||||
Classic_PingPacket cPingPacket = new Classic_PingPacket();
|
||||
|
||||
if (isPacketSupported(cDomainPacket)) protocolSettings.packetHandler.registerPacket(cDomainPacket);
|
||||
if (isPacketSupported(cMessagePacket)) protocolSettings.packetHandler.registerPacket(cMessagePacket);
|
||||
@@ -208,26 +210,36 @@ public final class ProtocolBridge {
|
||||
*/
|
||||
private void registerListeners() throws Exception {
|
||||
// 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);
|
||||
|
||||
// INS Listeners
|
||||
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(ClientListener.class);
|
||||
}
|
||||
|
||||
// Web Listeners
|
||||
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(ClientListener.class);
|
||||
}
|
||||
|
||||
// Client Listeners
|
||||
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(WebServerListener.class);
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@ import dev.unlegitdqrk.unlegitlibrary.event.EventListener;
|
||||
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;
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -17,6 +19,21 @@ import java.io.IOException;
|
||||
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.CLIENT)
|
||||
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.
|
||||
* Sends an authentication packet to the server.
|
||||
@@ -26,7 +43,7 @@ public final class ClientListener extends EventListener {
|
||||
@Listener
|
||||
public void onConnect(ClientConnectedEvent event) {
|
||||
try {
|
||||
event.getClient().sendPacket(new AuthPacket(protocolBridge));
|
||||
event.getClient().sendPacket(new AuthPacket(client.getProtocolBridge()));
|
||||
} catch (IOException | ClassNotFoundException exception) {
|
||||
event.getClient().getLogger().exception("Failed to send auth packet", exception);
|
||||
event.getClient().disconnect();
|
||||
@@ -41,7 +58,7 @@ public final class ClientListener extends EventListener {
|
||||
*/
|
||||
@Listener
|
||||
public void onDisconnect(ClientDisconnectedEvent event) {
|
||||
ProtocolBridge.getInstance().getProtocolClient().onINSDisconnect(event);
|
||||
client.onINSDisconnect(event);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,12 @@ import dev.unlegitdqrk.unlegitlibrary.event.EventListener;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -15,6 +18,21 @@ import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS)
|
||||
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.
|
||||
* Adds the connected client to the ProtocolBridge's INS server client list.
|
||||
@@ -23,7 +41,7 @@ public final class INSServerListener extends EventListener {
|
||||
*/
|
||||
@Listener
|
||||
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
|
||||
public void onDisconnect(ConnectionHandlerDisconnectedEvent event) {
|
||||
ProtocolBridge.getInstance().getProtocolINSServer().getClients().removeIf(client ->
|
||||
client.getConnectionHandler().getClientID() == -1);
|
||||
insServer.getClients().removeIf(client -> client.getConnectionHandler().getClientID() == -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,12 @@ import dev.unlegitdqrk.unlegitlibrary.event.EventListener;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -15,6 +18,21 @@ import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.WEB)
|
||||
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.
|
||||
* Adds the connected client to the protocol web server's client list.
|
||||
@@ -23,7 +41,7 @@ public final class WebServerListener extends EventListener {
|
||||
*/
|
||||
@Listener
|
||||
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
|
||||
public void onDisconnect(ConnectionHandlerDisconnectedEvent event) {
|
||||
ProtocolBridge.getInstance().getProtocolWebServer().getClients().removeIf(client -> client.getPipelineConnection().getClientID() == -1);
|
||||
webServer.getClients().removeIf(client -> client.getPipelineConnection().getClientID() == -1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -129,7 +129,7 @@ public final class AuthPacket extends OACPacket {
|
||||
}
|
||||
|
||||
protocolBridge.getProtocolClient().setServerVersion(serverVersion);
|
||||
protocolBridge.getProtocolSettings().eventManager.executeEvent(new ConnectedToProtocolINSServerEvent());
|
||||
protocolBridge.getProtocolSettings().eventManager.executeEvent(new ConnectedToProtocolINSServerEvent(protocolBridge.getProtocolClient()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,21 +16,24 @@ public final class GetDestinationPacket extends OACPacket {
|
||||
private int clientID;
|
||||
private INSResponseCode validationResponse;
|
||||
private String destination;
|
||||
private ProtocolBridge protocolBridge;
|
||||
|
||||
// INS-Server Constructor
|
||||
public GetDestinationPacket(InfoName infoName, INSResponseCode validationResponse, String destination) {
|
||||
public GetDestinationPacket(InfoName infoName, INSResponseCode validationResponse, String destination, ProtocolBridge protocolBridge) {
|
||||
this();
|
||||
this.infoName = infoName;
|
||||
this.validationResponse = validationResponse;
|
||||
this.destination = destination;
|
||||
this.protocolBridge = protocolBridge;
|
||||
}
|
||||
|
||||
// Client Constructor
|
||||
public GetDestinationPacket(InfoName infoName, INSResponseCode validationResponse) {
|
||||
public GetDestinationPacket(InfoName infoName, INSResponseCode validationResponse, ProtocolBridge protocolBridge) {
|
||||
this();
|
||||
this.infoName = infoName;
|
||||
this.validationResponse = validationResponse;
|
||||
this.destination = destination;
|
||||
this.protocolBridge = protocolBridge;
|
||||
}
|
||||
|
||||
// Registration Constructor
|
||||
@@ -40,13 +43,13 @@ public final class GetDestinationPacket extends OACPacket {
|
||||
|
||||
@Override
|
||||
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;
|
||||
|
||||
objectOutputStream.writeInt(ProtocolBridge.getInstance().getProtocolClient().getClientINSConnection().getClientID());
|
||||
objectOutputStream.writeInt(protocolBridge.getProtocolClient().getClientINSConnection().getClientID());
|
||||
objectOutputStream.writeObject(infoName);
|
||||
objectOutputStream.writeObject(validationResponse);
|
||||
} else if (ProtocolBridge.getInstance().isRunningAsINSServer()) {
|
||||
} else if (protocolBridge.isRunningAsINSServer()) {
|
||||
objectOutputStream.writeObject(infoName);
|
||||
objectOutputStream.writeObject(validationResponse);
|
||||
objectOutputStream.writeUTF(destination);
|
||||
@@ -55,16 +58,16 @@ public final class GetDestinationPacket extends OACPacket {
|
||||
|
||||
@Override
|
||||
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||
if (ProtocolBridge.getInstance().isRunningAsINServer()) {
|
||||
if (protocolBridge.isRunningAsINSServer()) {
|
||||
clientID = objectInputStream.readInt();
|
||||
infoName = (InfoName) objectInputStream.readObject();
|
||||
validationResponse = (INSResponseCode) objectInputStream.readObject();
|
||||
} else if (ProtocolBridge.getInstance().isRunningAsClient()) {
|
||||
} else if (protocolBridge.isRunningAsClient()) {
|
||||
infoName = (InfoName) objectInputStream.readObject();
|
||||
validationResponse = (INSResponseCode) objectInputStream.readObject();
|
||||
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) {
|
||||
super.onResponseCodeRead(packetHandler, objectInputStream);
|
||||
|
||||
if (ProtocolBridge.getInstance().isRunningAsINSServer()) {
|
||||
if (protocolBridge.isRunningAsINSServer()) {
|
||||
if (validationResponse != INSResponseCode.RESPONSE_INFONAME_FULLY_EXIST) return;
|
||||
destination = infoName.getDestination();
|
||||
destination = infoName.getDestination(protocolBridge);
|
||||
|
||||
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) {
|
||||
ProtocolBridge.getInstance().getProtocolINSServer().infoNameDestinationPacketFailedSend(ProtocolBridge.getInstance().getProtocolINSServer().getClientByID(clientID), infoName, validationResponse, exception);
|
||||
protocolBridge.getProtocolINSServer().infoNameDestinationPacketFailedSend(protocolBridge.getProtocolINSServer().getClientByID(clientID), infoName, validationResponse, exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,14 @@ import java.io.ObjectOutputStream;
|
||||
public final class UnsupportedClassicPacket extends OACPacket {
|
||||
private Class<? extends OACPacket> unsupportedClassicPacket;
|
||||
private Object[] content;
|
||||
private ProtocolBridge protocolBridge;
|
||||
|
||||
// Constructor with more information
|
||||
public UnsupportedClassicPacket(Class<? extends OACPacket> unsupportedClassicPacket, Object[] content) {
|
||||
public UnsupportedClassicPacket(Class<? extends OACPacket> unsupportedClassicPacket, Object[] content, ProtocolBridge protocolBridge) {
|
||||
this();
|
||||
this.unsupportedClassicPacket = unsupportedClassicPacket;
|
||||
this.content = content;
|
||||
this.protocolBridge = protocolBridge;
|
||||
}
|
||||
|
||||
// Registration Constructor
|
||||
@@ -28,8 +30,8 @@ public final class UnsupportedClassicPacket extends OACPacket {
|
||||
|
||||
@Override
|
||||
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
||||
if (ProtocolBridge.getInstance().isRunningAsClient())
|
||||
objectOutputStream.writeInt(ProtocolBridge.getInstance().getProtocolClient().getClientINSConnection().getClientID());
|
||||
if (protocolBridge.isRunningAsClient())
|
||||
objectOutputStream.writeInt(protocolBridge.getProtocolClient().getClientINSConnection().getClientID());
|
||||
|
||||
objectOutputStream.writeUTF(unsupportedClassicPacket.getName());
|
||||
objectOutputStream.writeInt(content.length);
|
||||
@@ -40,7 +42,7 @@ public final class UnsupportedClassicPacket extends OACPacket {
|
||||
@Override
|
||||
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||
int clientID = 0;
|
||||
if (ProtocolBridge.getInstance().isRunningAsINSServer()) clientID = objectInputStream.readInt();
|
||||
if (protocolBridge.isRunningAsINSServer()) clientID = objectInputStream.readInt();
|
||||
String className = objectInputStream.readUTF();
|
||||
int size = objectInputStream.readInt();
|
||||
content = new Object[size];
|
||||
@@ -49,12 +51,12 @@ public final class UnsupportedClassicPacket extends OACPacket {
|
||||
content[i] = objectInputStream.readObject();
|
||||
}
|
||||
|
||||
if (ProtocolBridge.getInstance().isRunningAsINSServer())
|
||||
ProtocolBridge.getInstance().getClassicHandlerINSServer().unsupportedClassicPacket(className, content, ProtocolBridge.getInstance().getProtocolINSServer().getClientByID(clientID));
|
||||
else if (ProtocolBridge.getInstance().isRunningAsClient())
|
||||
ProtocolBridge.getInstance().getClassicHandlerClient().unsupportedClassicPacket(className, content);
|
||||
else if (ProtocolBridge.getInstance().isRunningAsWebServer())
|
||||
ProtocolBridge.getInstance().getClassicHandlerWebServer().unsupportedClassicPacket(className, content, ProtocolBridge.getInstance().getProtocolINSServer().getClientByID(clientID));
|
||||
if (protocolBridge.isRunningAsINSServer())
|
||||
protocolBridge.getClassicHandlerINSServer().unsupportedClassicPacket(className, content, protocolBridge.getProtocolINSServer().getClientByID(clientID));
|
||||
else if (protocolBridge.isRunningAsClient())
|
||||
protocolBridge.getClassicHandlerClient().unsupportedClassicPacket(className, content);
|
||||
else if (protocolBridge.isRunningAsWebServer())
|
||||
protocolBridge.getClassicHandlerWebServer().unsupportedClassicPacket(className, content, protocolBridge.getProtocolINSServer().getClientByID(clientID));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,12 @@ public final class Classic_DomainPacket extends OACPacket {
|
||||
private Classic_RequestDomain requestDomain;
|
||||
private Classic_Domain domain;
|
||||
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.clientID = toClient;
|
||||
this.bridge = protocolBridge;
|
||||
|
||||
this.requestDomain = requestDomain;
|
||||
this.domain = domain;
|
||||
@@ -35,12 +37,12 @@ public final class Classic_DomainPacket extends OACPacket {
|
||||
|
||||
@Override
|
||||
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
||||
if (ProtocolBridge.getInstance().isRunningAsINSServer()) {
|
||||
if (bridge.isRunningAsINSServer()) {
|
||||
objectOutputStream.writeInt(clientID);
|
||||
objectOutputStream.writeObject(requestDomain);
|
||||
objectOutputStream.writeObject(domain);
|
||||
} else if (ProtocolBridge.getInstance().isRunningAsClient()) {
|
||||
clientID = ProtocolBridge.getInstance().getProtocolClient().getClientINSConnection().getClientID();
|
||||
} else if (bridge.isRunningAsClient()) {
|
||||
clientID = bridge.getProtocolClient().getClientINSConnection().getClientID();
|
||||
objectOutputStream.writeInt(clientID);
|
||||
objectOutputStream.writeObject(requestDomain);
|
||||
}
|
||||
@@ -50,36 +52,36 @@ public final class Classic_DomainPacket extends OACPacket {
|
||||
|
||||
@Override
|
||||
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||
if (ProtocolBridge.getInstance().isRunningAsINSServer()) {
|
||||
if (bridge.isRunningAsINSServer()) {
|
||||
clientID = objectInputStream.readInt();
|
||||
requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
|
||||
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
|
||||
|
||||
try {
|
||||
domain = ProtocolBridge.getInstance().getClassicHandlerINSServer().getDomain(requestDomain);
|
||||
domain = bridge.getClassicHandlerINSServer().getDomain(requestDomain);
|
||||
} catch (SQLException exception) {
|
||||
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())
|
||||
ProtocolBridge.getInstance().getProtocolINSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new Classic_DomainPacket(clientID, requestDomain, domain));
|
||||
if (bridge.getProtocolINSServer().getClientByID(clientID).supportClientClassic())
|
||||
bridge.getProtocolINSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new Classic_DomainPacket(clientID, requestDomain, domain, bridge));
|
||||
else
|
||||
ProtocolBridge.getInstance().getProtocolINSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{clientID, requestDomain, domain}));
|
||||
} else if (ProtocolBridge.getInstance().isRunningAsClient()) {
|
||||
bridge.getProtocolINSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{clientID, requestDomain, domain}, bridge));
|
||||
} else if (bridge.isRunningAsClient()) {
|
||||
clientID = objectInputStream.readInt();
|
||||
requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
|
||||
domain = (Classic_Domain) objectInputStream.readObject();
|
||||
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
|
||||
|
||||
ProtocolBridge.getInstance().getProtocolClient().getClientINSConnection().getEventManager().executeEvent(new Classic_DomainPacketReceivedEvent(protocolVersion, domain, requestDomain, clientID));
|
||||
} else if (ProtocolBridge.getInstance().isRunningAsWebServer()) {
|
||||
bridge.getProtocolClient().getClientINSConnection().getEventManager().executeEvent(new Classic_DomainPacketReceivedEvent(protocolVersion, domain, requestDomain, clientID));
|
||||
} else if (bridge.isRunningAsWebServer()) {
|
||||
clientID = objectInputStream.readInt();
|
||||
requestDomain = (Classic_RequestDomain) 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,14 @@ import java.io.ObjectOutputStream;
|
||||
public final class Classic_MessagePacket extends OACPacket {
|
||||
private String message;
|
||||
private int clientID;
|
||||
private ProtocolBridge bridge;
|
||||
|
||||
// Constructor with message and client id
|
||||
public Classic_MessagePacket(String message, int toClient) {
|
||||
public Classic_MessagePacket(String message, int toClient, ProtocolBridge bridge) {
|
||||
this();
|
||||
this.message = message;
|
||||
this.clientID = toClient;
|
||||
this.bridge = bridge;
|
||||
}
|
||||
|
||||
public Classic_MessagePacket() {
|
||||
@@ -27,10 +29,10 @@ public final class Classic_MessagePacket extends OACPacket {
|
||||
|
||||
@Override
|
||||
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);
|
||||
else if (ProtocolBridge.getInstance().isRunningAsClient()) {
|
||||
clientID = ProtocolBridge.getInstance().getProtocolClient().getClientINSConnection().getClientID();
|
||||
else if (bridge.isRunningAsClient()) {
|
||||
clientID = bridge.getProtocolClient().getClientINSConnection().getClientID();
|
||||
objectOutputStream.writeInt(clientID);
|
||||
}
|
||||
|
||||
@@ -40,24 +42,24 @@ public final class Classic_MessagePacket extends OACPacket {
|
||||
|
||||
@Override
|
||||
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||
if (ProtocolBridge.getInstance().isRunningAsINSServer()) {
|
||||
if (bridge.isRunningAsINSServer()) {
|
||||
clientID = objectInputStream.readInt();
|
||||
String message = objectInputStream.readUTF();
|
||||
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
|
||||
|
||||
ProtocolBridge.getInstance().getClassicHandlerINSServer().handleMessage(ProtocolBridge.getInstance().getProtocolINSServer().getClientByID(clientID), message, protocolVersion);
|
||||
} else if (ProtocolBridge.getInstance().isRunningAsClient()) {
|
||||
bridge.getClassicHandlerINSServer().handleMessage(bridge.getProtocolINSServer().getClientByID(clientID), message, protocolVersion);
|
||||
} else if (bridge.isRunningAsClient()) {
|
||||
clientID = objectInputStream.readInt();
|
||||
String message = objectInputStream.readUTF();
|
||||
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
|
||||
|
||||
ProtocolBridge.getInstance().getClassicHandlerClient().handleMessage(message, protocolVersion);
|
||||
} else if (ProtocolBridge.getInstance().isRunningAsWebServer()) {
|
||||
bridge.getClassicHandlerClient().handleMessage(message, protocolVersion);
|
||||
} else if (bridge.isRunningAsWebServer()) {
|
||||
clientID = objectInputStream.readInt();
|
||||
String message = objectInputStream.readUTF();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,9 +22,11 @@ public final class Classic_PingPacket extends OACPacket {
|
||||
private int clientID;
|
||||
private boolean reachable;
|
||||
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.bridge = bridge;
|
||||
|
||||
this.requestDomain = requestDomain;
|
||||
this.domain = domain;
|
||||
@@ -38,13 +40,13 @@ public final class Classic_PingPacket extends OACPacket {
|
||||
|
||||
@Override
|
||||
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
||||
if (ProtocolBridge.getInstance().isRunningAsINSServer()) {
|
||||
if (bridge.isRunningAsINSServer()) {
|
||||
objectOutputStream.writeInt(clientID);
|
||||
objectOutputStream.writeObject(requestDomain);
|
||||
objectOutputStream.writeObject(domain);
|
||||
objectOutputStream.writeBoolean(reachable);
|
||||
} else if (ProtocolBridge.getInstance().isRunningAsClient()) {
|
||||
clientID = ProtocolBridge.getInstance().getProtocolClient().getClientINSConnection().getClientID();
|
||||
} else if (bridge.isRunningAsClient()) {
|
||||
clientID = bridge.getProtocolClient().getClientINSConnection().getClientID();
|
||||
objectOutputStream.writeInt(clientID);
|
||||
objectOutputStream.writeObject(requestDomain);
|
||||
}
|
||||
@@ -54,38 +56,38 @@ public final class Classic_PingPacket extends OACPacket {
|
||||
|
||||
@Override
|
||||
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||
if (ProtocolBridge.getInstance().isRunningAsINSServer()) {
|
||||
if (bridge.isRunningAsINSServer()) {
|
||||
clientID = objectInputStream.readInt();
|
||||
requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
|
||||
protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
|
||||
|
||||
try {
|
||||
domain = ProtocolBridge.getInstance().getClassicHandlerINSServer().ping(requestDomain);
|
||||
domain = bridge.getClassicHandlerINSServer().ping(requestDomain);
|
||||
} catch (SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
reachable = domain != null;
|
||||
ProtocolBridge.getInstance().getProtocolINSServer().getNetworkServer().getEventManager().executeEvent(new Classic_PingPacketReceivedEvent(protocolVersion, domain, requestDomain, reachable, clientID));
|
||||
if (ProtocolBridge.getInstance().getProtocolINSServer().getClientByID(clientID).supportClientClassic())
|
||||
ProtocolBridge.getInstance().getProtocolINSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new Classic_PingPacket(requestDomain, domain, reachable));
|
||||
bridge.getProtocolINSServer().getNetworkServer().getEventManager().executeEvent(new Classic_PingPacketReceivedEvent(protocolVersion, domain, requestDomain, reachable, clientID));
|
||||
if (bridge.getProtocolINSServer().getClientByID(clientID).supportClientClassic())
|
||||
bridge.getProtocolINSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new Classic_PingPacket(requestDomain, domain, reachable, bridge));
|
||||
else
|
||||
ProtocolBridge.getInstance().getProtocolINSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{requestDomain, domain, reachable}));
|
||||
} else if (ProtocolBridge.getInstance().isRunningAsClient()) {
|
||||
bridge.getProtocolINSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{requestDomain, domain, reachable}, bridge));
|
||||
} else if (bridge.isRunningAsClient()) {
|
||||
clientID = objectInputStream.readInt();
|
||||
requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
|
||||
domain = (Classic_Domain) objectInputStream.readObject();
|
||||
boolean reachable = objectInputStream.readBoolean();
|
||||
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);
|
||||
ProtocolBridge.getInstance().getProtocolClient().getClientINSConnection().getEventManager().executeEvent(new Classic_PingPacketReceivedEvent(protocolVersion, domain, requestDomain, reachable, clientID));
|
||||
} else if (ProtocolBridge.getInstance().isRunningAsWebServer()) {
|
||||
bridge.getProtocolClient().validationCompleted(domain.getInfoName(), reachable ? INSResponseCode.RESPONSE_INFONAME_FULLY_EXIST : INSResponseCode.RESPONSE_INFONAME_FULLY_NOT_EXIST);
|
||||
bridge.getProtocolClient().getClientINSConnection().getEventManager().executeEvent(new Classic_PingPacketReceivedEvent(protocolVersion, domain, requestDomain, reachable, clientID));
|
||||
} else if (bridge.isRunningAsWebServer()) {
|
||||
clientID = objectInputStream.readInt();
|
||||
requestDomain = (Classic_RequestDomain) 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,7 +310,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
*/
|
||||
public final void validateInfoName(InfoName infoName) throws IOException, ClassNotFoundException {
|
||||
// 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);
|
||||
|
||||
// Send ValidateInfoNamePacket
|
||||
@@ -327,16 +327,16 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
*/
|
||||
public final void requestInfoName(InfoName infoName, INSResponseCode responseCode) throws IOException, ClassNotFoundException {
|
||||
// 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);
|
||||
|
||||
// Send GetDestinationPacket
|
||||
clientToINS.sendPacket(new GetDestinationPacket(infoName, responseCode));
|
||||
clientToINS.sendPacket(new GetDestinationPacket(infoName, responseCode, protocolBridge));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set protocol bridge
|
||||
* @param protocolBridge The ProtocolBridge object
|
||||
* Set protocol bridge.
|
||||
* @param protocolBridge The ProtocolBridge object.
|
||||
*/
|
||||
public void setProtocolBridge(ProtocolBridge protocolBridge) {
|
||||
if (this.protocolBridge == null) this.protocolBridge = protocolBridge;
|
||||
|
||||
@@ -2,6 +2,7 @@ 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;
|
||||
@@ -65,7 +66,7 @@ public final class WebClient {
|
||||
// Set logger from ProtocolBridge
|
||||
setLogger(protocolClient.getProtocolBridge().getLogger()).
|
||||
// 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
|
||||
setPacketHandler(protocolClient.getProtocolBridge().getProtocolSettings().packetHandler).
|
||||
@@ -107,10 +108,10 @@ public final class WebClient {
|
||||
// Create raw socket and wrap it in SSL socket
|
||||
if (proxy != null) {
|
||||
Socket rawSocket = new Socket(proxy);
|
||||
rawSocket.connect(new InetSocketAddress(infoName.getDestination(), webPort), 0);
|
||||
tempSocket = (SSLSocket) sslSocketFactory.createSocket(rawSocket, infoName.getDestination(), webPort, true);
|
||||
rawSocket.connect(new InetSocketAddress(infoName.getDestination(protocolClient.getProtocolBridge()), webPort), 0);
|
||||
tempSocket = (SSLSocket) sslSocketFactory.createSocket(rawSocket, infoName.getDestination(protocolClient.getProtocolBridge()), webPort, true);
|
||||
} else {
|
||||
tempSocket = (SSLSocket) sslSocketFactory.createSocket(infoName.getDestination(), webPort);
|
||||
tempSocket = (SSLSocket) sslSocketFactory.createSocket(infoName.getDestination(protocolClient.getProtocolBridge()), webPort);
|
||||
}
|
||||
|
||||
clientToWebServer = tempSocket;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package org.openautonomousconnection.protocol.side.client.events;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.event.impl.Event;
|
||||
import lombok.Getter;
|
||||
import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
|
||||
import org.openautonomousconnection.protocol.side.client.ProtocolClient;
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
|
||||
/**
|
||||
@@ -9,4 +11,15 @@ import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
*/
|
||||
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS)
|
||||
public final class ConnectedToProtocolINSServerEvent extends Event {
|
||||
|
||||
/**
|
||||
* Reference to the ProtocolClient object.
|
||||
*/
|
||||
@Getter
|
||||
private final ProtocolClient client;
|
||||
|
||||
public ConnectedToProtocolINSServerEvent(ProtocolClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
|
||||
/**
|
||||
* @param infoName The InfoName to look up.
|
||||
* @return The destination associated with the InfoName.
|
||||
* @see InfoName#getDestination()
|
||||
* @see InfoName#getDestination(ProtocolBridge)
|
||||
* Abstract method to get the destination for a given InfoName.
|
||||
*/
|
||||
public abstract String getInfoNameDestination(InfoName infoName);
|
||||
@@ -198,7 +198,7 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
|
||||
* @param infoName The parent InfoName.
|
||||
* @param subname The subname to look up.
|
||||
* @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.
|
||||
*/
|
||||
public abstract String getSubnameDestination(InfoName infoName, String subname);
|
||||
@@ -206,7 +206,7 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
|
||||
/**
|
||||
* @param topLevelName The 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.
|
||||
*/
|
||||
public abstract String getTLNInfoSite(String topLevelName);
|
||||
|
||||
@@ -140,21 +140,21 @@ public final class InfoName implements Serializable {
|
||||
* @return the destination as a string.
|
||||
*/
|
||||
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS)
|
||||
public String getDestination() {
|
||||
public String getDestination(ProtocolBridge protocolBridge) {
|
||||
// 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();
|
||||
|
||||
// Handle special default InfoNames
|
||||
if (this.equals(DefaultInfoNames.INS_INFO_SITE))
|
||||
return ProtocolBridge.getInstance().getProtocolINSServer().getINSInfoSite();
|
||||
return protocolBridge.getProtocolINSServer().getINSInfoSite();
|
||||
if (this.equals(DefaultInfoNames.INS_REGISTER_SITE))
|
||||
return ProtocolBridge.getInstance().getProtocolINSServer().getINSRegisterSite();
|
||||
return protocolBridge.getProtocolINSServer().getINSRegisterSite();
|
||||
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 !hasSubname() ? ProtocolBridge.getInstance().getProtocolINSServer().getInfoNameDestination(this) : ProtocolBridge.getInstance().getProtocolINSServer().getSubnameDestination(this, subname);
|
||||
return !hasSubname() ? protocolBridge.getProtocolINSServer().getInfoNameDestination(this) : protocolBridge.getProtocolINSServer().getSubnameDestination(this, subname);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
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;
|
||||
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.site.Classic_SiteType;
|
||||
@@ -16,6 +18,21 @@ import java.io.IOException;
|
||||
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.CLIENT)
|
||||
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 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 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()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.InfoName;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -38,23 +39,30 @@ public class Classic_Domain implements Serializable {
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
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.
|
||||
*/
|
||||
@Getter
|
||||
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.name = infoName.getName();
|
||||
this.topLevelDomain = infoName.getTopLevelName();
|
||||
this.destination = infoName.getDestination();
|
||||
this.destination = infoName.getDestination(bridge);
|
||||
this.path = infoName.getPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final Object clone() throws CloneNotSupportedException {
|
||||
return new Classic_Domain(name, topLevelDomain, destination, path);
|
||||
return new Classic_Domain(name, topLevelDomain, destination, path, protocolBridge);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects;
|
||||
|
||||
import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||
|
||||
/**
|
||||
* Class representing a local domain in the Classic protocol.
|
||||
* This class extends Classic_Domain and is used for local domain representation.
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public final class Classic_LocalDomain extends Classic_Domain {
|
||||
public Classic_LocalDomain(String name, String endName, String path) {
|
||||
super(name, endName, null, path);
|
||||
public Classic_LocalDomain(String name, String endName, String path, ProtocolBridge protocolBridge) {
|
||||
super(name, endName, null, path, protocolBridge);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects;
|
||||
|
||||
import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
@@ -9,7 +11,7 @@ import java.io.Serializable;
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public final class Classic_RequestDomain extends Classic_Domain implements Serializable {
|
||||
|
||||
public Classic_RequestDomain(String name, String topLevelDomain, String path) {
|
||||
super(name, topLevelDomain, null, path);
|
||||
public Classic_RequestDomain(String name, String topLevelDomain, String path, ProtocolBridge protocolBridge) {
|
||||
super(name, topLevelDomain, null, path, protocolBridge);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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.v1_0_0.beta.InfoName;
|
||||
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.
|
||||
*
|
||||
* @param newInfoName the InfoName object to convert
|
||||
* @param protocolBridge The reference to the ProtocolBridge object.
|
||||
* @return the converted Classic_Domain object
|
||||
*/
|
||||
@SuppressWarnings(value = "deprecation")
|
||||
public static Classic_Domain infoNameToClassicDomain(InfoName newInfoName) {
|
||||
return new Classic_Domain(newInfoName.getName(), newInfoName.getTopLevelName(), newInfoName.getDestination(), newInfoName.getPath());
|
||||
public static Classic_Domain infoNameToClassicDomain(InfoName newInfoName, ProtocolBridge protocolBridge) {
|
||||
return new Classic_Domain(newInfoName.getName(), newInfoName.getTopLevelName(), newInfoName.getDestination(protocolBridge), newInfoName.getPath(), protocolBridge);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.Listener;
|
||||
import lombok.Getter;
|
||||
import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_PingPacket;
|
||||
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")
|
||||
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.
|
||||
* 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) {
|
||||
try {
|
||||
// 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
|
||||
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));
|
||||
}
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
// 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()));
|
||||
}
|
||||
} else
|
||||
// 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) {
|
||||
// If the domain is reachable, fetch the HTML content
|
||||
if (event.reachable) {
|
||||
String destination = event.domain.getInfoName().getDestination();
|
||||
String destination = event.domain.getInfoName().getDestination(protocolBridge);
|
||||
|
||||
try {
|
||||
// Create a URL object
|
||||
@@ -81,15 +97,15 @@ public final class Classic_ClientListener extends EventListener {
|
||||
}
|
||||
|
||||
// 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) {
|
||||
// Handle any exceptions that occur during the process
|
||||
ProtocolBridge.getInstance().getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-occurred", "html", ""),
|
||||
Classic_WebsitesContent.ERROR_OCCURRED(exception.getMessage().replace(event.domain.getInfoName().getDestination(), event.domain + "/" + event.domain.path)));
|
||||
protocolBridge.getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-occurred", "html", "", protocolBridge),
|
||||
Classic_WebsitesContent.ERROR_OCCURRED(exception.getMessage().replace(event.domain.getInfoName().getDestination(protocolBridge), event.domain + "/" + event.domain.path)));
|
||||
}
|
||||
} else
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user