Removed ProtocolBridge#getInstance
This commit is contained in:
@@ -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