- Implimented classic client code
This commit is contained in:
@@ -9,6 +9,7 @@ import github.openautonomousconnection.protocol.versions.v1_0_0.classic.ClassicH
|
|||||||
import github.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_DomainPacket;
|
import github.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_DomainPacket;
|
||||||
import github.openautonomousconnection.protocol.side.client.ProtocolClient;
|
import github.openautonomousconnection.protocol.side.client.ProtocolClient;
|
||||||
import github.openautonomousconnection.protocol.side.server.ProtocolServer;
|
import github.openautonomousconnection.protocol.side.server.ProtocolServer;
|
||||||
|
import github.openautonomousconnection.protocol.versions.v1_0_0.classic.Classic_ClientListener;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import me.finn.unlegitlibrary.utils.Logger;
|
import me.finn.unlegitlibrary.utils.Logger;
|
||||||
@@ -65,6 +66,18 @@ public class ProtocolBridge {
|
|||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isClassicSupported()) {
|
||||||
|
protocolSettings.eventManager.unregisterListener(new Classic_ClientListener());
|
||||||
|
|
||||||
|
Classic_DomainPacket cDomainPacket = new Classic_DomainPacket();
|
||||||
|
Classic_DomainPacket cMessagePacket = new Classic_DomainPacket();
|
||||||
|
Classic_DomainPacket cPingPacket = new Classic_DomainPacket();
|
||||||
|
|
||||||
|
if (isPacketSupported(cDomainPacket)) protocolSettings.packetHandler.registerPacket(cDomainPacket);
|
||||||
|
if (isPacketSupported(cMessagePacket)) protocolSettings.packetHandler.registerPacket(cMessagePacket);
|
||||||
|
if (isPacketSupported(cPingPacket)) protocolSettings.packetHandler.registerPacket(cPingPacket);
|
||||||
|
}
|
||||||
|
|
||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,6 +105,8 @@ public class ProtocolBridge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isClassicSupported()) {
|
if (isClassicSupported()) {
|
||||||
|
protocolSettings.eventManager.registerListener(new Classic_ClientListener());
|
||||||
|
|
||||||
Classic_DomainPacket cDomainPacket = new Classic_DomainPacket();
|
Classic_DomainPacket cDomainPacket = new Classic_DomainPacket();
|
||||||
Classic_DomainPacket cMessagePacket = new Classic_DomainPacket();
|
Classic_DomainPacket cMessagePacket = new Classic_DomainPacket();
|
||||||
Classic_DomainPacket cPingPacket = new Classic_DomainPacket();
|
Classic_DomainPacket cPingPacket = new Classic_DomainPacket();
|
||||||
|
@@ -1,15 +1,47 @@
|
|||||||
package github.openautonomousconnection.protocol.packets;
|
package github.openautonomousconnection.protocol.packets;
|
||||||
|
|
||||||
import github.openautonomousconnection.protocol.versions.ProtocolVersion;
|
import github.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||||
|
import github.openautonomousconnection.protocol.versions.v1_0_0.beta.DNSResponseCode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import me.finn.unlegitlibrary.network.system.packets.Packet;
|
import me.finn.unlegitlibrary.network.system.packets.Packet;
|
||||||
|
import me.finn.unlegitlibrary.network.system.packets.PacketHandler;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
|
||||||
public abstract class OACPacket extends Packet {
|
public abstract class OACPacket extends Packet {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final ProtocolVersion protocolVersion;
|
private final ProtocolVersion protocolVersion;
|
||||||
|
|
||||||
|
private DNSResponseCode responseCode = DNSResponseCode.RESPONSE_NOT_REQUIRED;
|
||||||
|
|
||||||
|
protected final void setResponseCode(DNSResponseCode responseCode) {
|
||||||
|
this.responseCode = responseCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final DNSResponseCode getResponseCode() {
|
||||||
|
return responseCode;
|
||||||
|
}
|
||||||
|
|
||||||
public OACPacket(int id, ProtocolVersion protocolVersion) {
|
public OACPacket(int id, ProtocolVersion protocolVersion) {
|
||||||
super(id);
|
super(id);
|
||||||
this.protocolVersion = protocolVersion;
|
this.protocolVersion = protocolVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void write(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
||||||
|
onWrite(packetHandler, objectOutputStream);
|
||||||
|
if (protocolVersion != ProtocolVersion.PV_1_0_0_CLASSIC) objectOutputStream.writeObject(responseCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void read(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||||
|
onRead(packetHandler, objectInputStream);
|
||||||
|
if (protocolVersion != ProtocolVersion.PV_1_0_0_CLASSIC) responseCode = (DNSResponseCode) objectInputStream.readObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException;
|
||||||
|
public abstract void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException;
|
||||||
}
|
}
|
||||||
|
@@ -6,6 +6,7 @@ import github.openautonomousconnection.protocol.side.client.events.ConnectedToPr
|
|||||||
import github.openautonomousconnection.protocol.side.server.ConnectedProtocolClient;
|
import github.openautonomousconnection.protocol.side.server.ConnectedProtocolClient;
|
||||||
import github.openautonomousconnection.protocol.side.server.events.ProtocolClientConnected;
|
import github.openautonomousconnection.protocol.side.server.events.ProtocolClientConnected;
|
||||||
import github.openautonomousconnection.protocol.versions.ProtocolVersion;
|
import github.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||||
|
import github.openautonomousconnection.protocol.versions.v1_0_0.beta.DNSResponseCode;
|
||||||
import me.finn.unlegitlibrary.network.system.packets.PacketHandler;
|
import me.finn.unlegitlibrary.network.system.packets.PacketHandler;
|
||||||
import me.finn.unlegitlibrary.network.system.server.ConnectionHandler;
|
import me.finn.unlegitlibrary.network.system.server.ConnectionHandler;
|
||||||
|
|
||||||
@@ -20,7 +21,7 @@ public class AuthPacket extends OACPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
||||||
if (ProtocolBridge.getInstance().isRunningAsServer()) objectOutputStream.writeObject(ProtocolBridge.getInstance().getProtocolVersion());
|
if (ProtocolBridge.getInstance().isRunningAsServer()) objectOutputStream.writeObject(ProtocolBridge.getInstance().getProtocolVersion());
|
||||||
else {
|
else {
|
||||||
objectOutputStream.writeInt(ProtocolBridge.getInstance().getProtocolClient().getNetworkClient().getClientID());
|
objectOutputStream.writeInt(ProtocolBridge.getInstance().getProtocolClient().getNetworkClient().getClientID());
|
||||||
@@ -29,14 +30,17 @@ public class AuthPacket extends OACPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||||
if (ProtocolBridge.getInstance().isRunningAsServer()) {
|
if (ProtocolBridge.getInstance().isRunningAsServer()) {
|
||||||
int clientID = objectInputStream.readInt();
|
int clientID = objectInputStream.readInt();
|
||||||
ProtocolVersion clientVersion = (ProtocolVersion) objectInputStream.readObject();
|
ProtocolVersion clientVersion = (ProtocolVersion) objectInputStream.readObject();
|
||||||
ConnectionHandler connectionHandler = ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID);
|
ConnectionHandler connectionHandler = ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID);
|
||||||
|
|
||||||
if (!ProtocolBridge.getInstance().isVersionSupported(clientVersion)) connectionHandler.disconnect();
|
if (!ProtocolBridge.getInstance().isVersionSupported(clientVersion)) {
|
||||||
else {
|
setResponseCode(DNSResponseCode.RESPONSE_AUTH_FAILED);
|
||||||
|
connectionHandler.disconnect();
|
||||||
|
} else {
|
||||||
|
setResponseCode(DNSResponseCode.RESPONSE_AUTH_SUCCESS);
|
||||||
ConnectedProtocolClient client = ProtocolBridge.getInstance().getProtocolServer().getClientByID(clientID);
|
ConnectedProtocolClient client = ProtocolBridge.getInstance().getProtocolServer().getClientByID(clientID);
|
||||||
client.setClientVersion(clientVersion);
|
client.setClientVersion(clientVersion);
|
||||||
ProtocolBridge.getInstance().getProtocolSettings().eventManager.executeEvent(new ProtocolClientConnected(client));
|
ProtocolBridge.getInstance().getProtocolSettings().eventManager.executeEvent(new ProtocolClientConnected(client));
|
||||||
@@ -44,8 +48,11 @@ public class AuthPacket extends OACPacket {
|
|||||||
} else {
|
} else {
|
||||||
ProtocolVersion serverVersion = (ProtocolVersion) objectInputStream.readObject();
|
ProtocolVersion serverVersion = (ProtocolVersion) objectInputStream.readObject();
|
||||||
|
|
||||||
if (!ProtocolBridge.getInstance().isVersionSupported(serverVersion)) ProtocolBridge.getInstance().getProtocolClient().getNetworkClient().disconnect();
|
if (!ProtocolBridge.getInstance().isVersionSupported(serverVersion)) {
|
||||||
else {
|
setResponseCode(DNSResponseCode.RESPONSE_AUTH_FAILED);
|
||||||
|
ProtocolBridge.getInstance().getProtocolClient().getNetworkClient().disconnect();
|
||||||
|
} else {
|
||||||
|
setResponseCode(DNSResponseCode.RESPONSE_AUTH_SUCCESS);
|
||||||
ProtocolBridge.getInstance().getProtocolClient().setServerVersion(serverVersion);
|
ProtocolBridge.getInstance().getProtocolClient().setServerVersion(serverVersion);
|
||||||
ProtocolBridge.getInstance().getProtocolSettings().eventManager.executeEvent(new ConnectedToProtocolServer());
|
ProtocolBridge.getInstance().getProtocolSettings().eventManager.executeEvent(new ConnectedToProtocolServer());
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@ package github.openautonomousconnection.protocol.packets.v1_0_0.beta;
|
|||||||
import github.openautonomousconnection.protocol.ProtocolBridge;
|
import github.openautonomousconnection.protocol.ProtocolBridge;
|
||||||
import github.openautonomousconnection.protocol.packets.OACPacket;
|
import github.openautonomousconnection.protocol.packets.OACPacket;
|
||||||
import github.openautonomousconnection.protocol.versions.ProtocolVersion;
|
import github.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||||
|
import github.openautonomousconnection.protocol.versions.v1_0_0.beta.DNSResponseCode;
|
||||||
import me.finn.unlegitlibrary.network.system.packets.Packet;
|
import me.finn.unlegitlibrary.network.system.packets.Packet;
|
||||||
import me.finn.unlegitlibrary.network.system.packets.PacketHandler;
|
import me.finn.unlegitlibrary.network.system.packets.PacketHandler;
|
||||||
|
|
||||||
@@ -25,14 +26,15 @@ public class UnsupportedClassicPacket extends OACPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
||||||
objectOutputStream.writeUTF(unsupportedClassicPacket.getName());
|
objectOutputStream.writeUTF(unsupportedClassicPacket.getName());
|
||||||
objectOutputStream.writeInt(content.length);
|
objectOutputStream.writeInt(content.length);
|
||||||
for (Object o : content) objectOutputStream.writeObject(o);
|
for (Object o : content) objectOutputStream.writeObject(o);
|
||||||
|
setResponseCode(DNSResponseCode.RESPONSE_NOT_REQUIRED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||||
String className = objectInputStream.readUTF();
|
String className = objectInputStream.readUTF();
|
||||||
int size = objectInputStream.readInt();
|
int size = objectInputStream.readInt();
|
||||||
content = new Object[size];
|
content = new Object[size];
|
||||||
|
@@ -34,29 +34,46 @@ public class Classic_DomainPacket extends OACPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
||||||
objectOutputStream.writeInt(clientID);
|
if (ProtocolBridge.getInstance().isRunningAsServer()) {
|
||||||
objectOutputStream.writeObject(requestDomain);
|
objectOutputStream.writeInt(clientID);
|
||||||
objectOutputStream.writeObject(domain);
|
objectOutputStream.writeObject(requestDomain);
|
||||||
|
objectOutputStream.writeObject(domain);
|
||||||
|
} else {
|
||||||
|
clientID = ProtocolBridge.getInstance().getProtocolClient().getNetworkClient().getClientID();
|
||||||
|
objectOutputStream.writeInt(clientID);
|
||||||
|
objectOutputStream.writeObject(requestDomain);
|
||||||
|
}
|
||||||
|
|
||||||
objectOutputStream.writeObject(Classic_ProtocolVersion.PV_1_0_0);
|
objectOutputStream.writeObject(Classic_ProtocolVersion.PV_1_0_0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||||
clientID = objectInputStream.readInt();
|
if (ProtocolBridge.getInstance().isRunningAsServer()) {
|
||||||
requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
|
clientID = objectInputStream.readInt();
|
||||||
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
|
requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
|
||||||
|
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
domain = ProtocolBridge.getInstance().getClassicHandlerServer().getDomain(requestDomain);
|
domain = ProtocolBridge.getInstance().getClassicHandlerServer().getDomain(requestDomain);
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getEventManager().executeEvent(new Classic_DomainPacketReceivedEvent(protocolVersion, domain, requestDomain, clientID));
|
||||||
|
|
||||||
|
if (ProtocolBridge.getInstance().getProtocolServer().getClientByID(clientID).clientSupportClassic())
|
||||||
|
ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new Classic_DomainPacket(clientID, requestDomain, domain));
|
||||||
|
else
|
||||||
|
ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{clientID, requestDomain, domain}));
|
||||||
|
} else {
|
||||||
|
clientID = objectInputStream.readInt();
|
||||||
|
requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
|
||||||
|
domain = (Classic_Domain) objectInputStream.readObject();
|
||||||
|
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
|
||||||
|
|
||||||
|
ProtocolBridge.getInstance().getProtocolClient().getNetworkClient().getEventManager().executeEvent(new Classic_DomainPacketReceivedEvent(protocolVersion, domain, requestDomain, clientID));
|
||||||
}
|
}
|
||||||
|
|
||||||
ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getEventManager().executeEvent(new Classic_DomainPacketReceivedEvent(protocolVersion, domain, requestDomain, clientID));
|
|
||||||
|
|
||||||
if (ProtocolBridge.getInstance().getProtocolServer().getClientByID(clientID).clientSupportClassic()) ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new Classic_DomainPacket(clientID, requestDomain, domain));
|
|
||||||
else ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[] {clientID, requestDomain, domain}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,19 +26,31 @@ public class Classic_MessagePacket extends OACPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
||||||
objectOutputStream.writeInt(clientID);
|
if (ProtocolBridge.getInstance().isRunningAsServer()) objectOutputStream.writeInt(clientID);
|
||||||
|
else {
|
||||||
|
clientID = ProtocolBridge.getInstance().getProtocolClient().getNetworkClient().getClientID();
|
||||||
|
objectOutputStream.writeInt(clientID);
|
||||||
|
}
|
||||||
|
|
||||||
objectOutputStream.writeUTF(message);
|
objectOutputStream.writeUTF(message);
|
||||||
objectOutputStream.writeObject(Classic_ProtocolVersion.PV_1_0_0);
|
objectOutputStream.writeObject(Classic_ProtocolVersion.PV_1_0_0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||||
int clientID = objectInputStream.readInt();
|
if (ProtocolBridge.getInstance().isRunningAsServer()) {
|
||||||
String message = objectInputStream.readUTF();
|
clientID = objectInputStream.readInt();
|
||||||
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
|
String message = objectInputStream.readUTF();
|
||||||
|
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
|
||||||
|
|
||||||
ProtocolBridge.getInstance().getClassicHandlerServer().handleMessage(ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID), message, protocolVersion);
|
ProtocolBridge.getInstance().getClassicHandlerServer().handleMessage(ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID), message, protocolVersion);
|
||||||
|
} else {
|
||||||
|
clientID = objectInputStream.readInt();
|
||||||
|
String message = objectInputStream.readUTF();
|
||||||
|
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
|
||||||
|
|
||||||
|
ProtocolBridge.getInstance().getClassicHandlerClient().handleMessage(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@ package github.openautonomousconnection.protocol.packets.v1_0_0.classic;
|
|||||||
import github.openautonomousconnection.protocol.ProtocolBridge;
|
import github.openautonomousconnection.protocol.ProtocolBridge;
|
||||||
import github.openautonomousconnection.protocol.packets.v1_0_0.beta.UnsupportedClassicPacket;
|
import github.openautonomousconnection.protocol.packets.v1_0_0.beta.UnsupportedClassicPacket;
|
||||||
import github.openautonomousconnection.protocol.versions.ProtocolVersion;
|
import github.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||||
|
import github.openautonomousconnection.protocol.versions.v1_0_0.beta.DNSResponseCode;
|
||||||
import github.openautonomousconnection.protocol.versions.v1_0_0.classic.Classic_Domain;
|
import github.openautonomousconnection.protocol.versions.v1_0_0.classic.Classic_Domain;
|
||||||
import github.openautonomousconnection.protocol.versions.v1_0_0.classic.Classic_PingPacketReceivedEvent;
|
import github.openautonomousconnection.protocol.versions.v1_0_0.classic.Classic_PingPacketReceivedEvent;
|
||||||
import github.openautonomousconnection.protocol.versions.v1_0_0.classic.Classic_ProtocolVersion;
|
import github.openautonomousconnection.protocol.versions.v1_0_0.classic.Classic_ProtocolVersion;
|
||||||
@@ -36,29 +37,48 @@ public class Classic_PingPacket extends OACPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
||||||
objectOutputStream.writeInt(clientID);
|
if (ProtocolBridge.getInstance().isRunningAsServer()) {
|
||||||
objectOutputStream.writeObject(requestDomain);
|
objectOutputStream.writeInt(clientID);
|
||||||
objectOutputStream.writeObject(domain);
|
objectOutputStream.writeObject(requestDomain);
|
||||||
objectOutputStream.writeBoolean(reachable);
|
objectOutputStream.writeObject(domain);
|
||||||
|
objectOutputStream.writeBoolean(reachable);
|
||||||
|
} else {
|
||||||
|
clientID = ProtocolBridge.getInstance().getProtocolClient().getNetworkClient().getClientID();
|
||||||
|
objectOutputStream.writeInt(clientID);
|
||||||
|
objectOutputStream.writeObject(requestDomain);
|
||||||
|
}
|
||||||
|
|
||||||
objectOutputStream.writeObject(protocolVersion);
|
objectOutputStream.writeObject(protocolVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||||
clientID = objectInputStream.readInt();
|
if (ProtocolBridge.getInstance().isRunningAsServer()) {
|
||||||
requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
|
clientID = objectInputStream.readInt();
|
||||||
protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
|
requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
|
||||||
|
protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
domain = ProtocolBridge.getInstance().getClassicHandlerServer().ping(requestDomain);
|
domain = ProtocolBridge.getInstance().getClassicHandlerServer().ping(requestDomain);
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
reachable = domain != null;
|
||||||
|
ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getEventManager().executeEvent(new Classic_PingPacketReceivedEvent(protocolVersion, domain, requestDomain, reachable, clientID));
|
||||||
|
if (ProtocolBridge.getInstance().getProtocolServer().getClientByID(clientID).clientSupportClassic())
|
||||||
|
ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new Classic_PingPacket(requestDomain, domain, reachable));
|
||||||
|
else
|
||||||
|
ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{requestDomain, domain, reachable}));
|
||||||
|
} else {
|
||||||
|
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().getNetworkClient().getEventManager().executeEvent(new Classic_PingPacketReceivedEvent(protocolVersion, domain, requestDomain, reachable, clientID));
|
||||||
}
|
}
|
||||||
|
|
||||||
reachable = domain != null;
|
|
||||||
ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getEventManager().executeEvent(new Classic_PingPacketReceivedEvent(protocolVersion, domain, requestDomain, reachable, clientID));
|
|
||||||
if (ProtocolBridge.getInstance().getProtocolServer().getClientByID(clientID).clientSupportClassic()) ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new Classic_PingPacket(requestDomain, domain, reachable));
|
|
||||||
else ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[] {requestDomain, domain, reachable}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,7 +6,6 @@ import github.openautonomousconnection.protocol.versions.ProtocolVersion;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import me.finn.unlegitlibrary.network.system.client.NetworkClient;
|
import me.finn.unlegitlibrary.network.system.client.NetworkClient;
|
||||||
import me.finn.unlegitlibrary.network.system.client.events.ClientDisconnectedEvent;
|
import me.finn.unlegitlibrary.network.system.client.events.ClientDisconnectedEvent;
|
||||||
import me.finn.unlegitlibrary.network.system.server.NetworkServer;
|
|
||||||
import me.finn.unlegitlibrary.utils.DefaultMethodsOverrider;
|
import me.finn.unlegitlibrary.utils.DefaultMethodsOverrider;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -17,11 +16,11 @@ public class ProtocolClient extends DefaultMethodsOverrider {
|
|||||||
@Getter
|
@Getter
|
||||||
private final NetworkClient networkClient;
|
private final NetworkClient networkClient;
|
||||||
|
|
||||||
public ProtocolVersion getServerVersion() {
|
public final ProtocolVersion getServerVersion() {
|
||||||
return serverVersion == null ? ProtocolVersion.PV_1_0_0_CLASSIC : serverVersion;
|
return serverVersion == null ? ProtocolVersion.PV_1_0_0_CLASSIC : serverVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setServerVersion(ProtocolVersion serverVersion) {
|
public final void setServerVersion(ProtocolVersion serverVersion) {
|
||||||
if (serverVersion == null) this.serverVersion = serverVersion;
|
if (serverVersion == null) this.serverVersion = serverVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,11 +28,11 @@ public class ProtocolClient extends DefaultMethodsOverrider {
|
|||||||
serverVersion = null;
|
serverVersion = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isStableServer() {
|
public final boolean isStableServer() {
|
||||||
return !isBetaServer() && !isClassicServer();
|
return !isBetaServer() && !isClassicServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean serverSupportStable() {
|
public final boolean serverSupportStable() {
|
||||||
boolean yes = false;
|
boolean yes = false;
|
||||||
for (ProtocolVersion compatibleVersion : getServerVersion().getCompatibleVersions()) {
|
for (ProtocolVersion compatibleVersion : getServerVersion().getCompatibleVersions()) {
|
||||||
yes = compatibleVersion.getProtocolType() == ProtocolVersion.ProtocolType.STABLE;
|
yes = compatibleVersion.getProtocolType() == ProtocolVersion.ProtocolType.STABLE;
|
||||||
@@ -43,11 +42,11 @@ public class ProtocolClient extends DefaultMethodsOverrider {
|
|||||||
return isStableServer() || yes;
|
return isStableServer() || yes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBetaServer() {
|
public final boolean isBetaServer() {
|
||||||
return getServerVersion().getProtocolType() == ProtocolVersion.ProtocolType.BETA;
|
return getServerVersion().getProtocolType() == ProtocolVersion.ProtocolType.BETA;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean serverSupportBeta() {
|
public final boolean serverSupportBeta() {
|
||||||
boolean yes = false;
|
boolean yes = false;
|
||||||
for (ProtocolVersion compatibleVersion : getServerVersion().getCompatibleVersions()) {
|
for (ProtocolVersion compatibleVersion : getServerVersion().getCompatibleVersions()) {
|
||||||
yes = compatibleVersion.getProtocolType() == ProtocolVersion.ProtocolType.BETA;
|
yes = compatibleVersion.getProtocolType() == ProtocolVersion.ProtocolType.BETA;
|
||||||
@@ -57,11 +56,11 @@ public class ProtocolClient extends DefaultMethodsOverrider {
|
|||||||
return isBetaServer() || yes;
|
return isBetaServer() || yes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isClassicServer() {
|
public final boolean isClassicServer() {
|
||||||
return getServerVersion().getProtocolType() == ProtocolVersion.ProtocolType.CLASSIC;
|
return getServerVersion().getProtocolType() == ProtocolVersion.ProtocolType.CLASSIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean serverSupportClassic() {
|
public final boolean serverSupportClassic() {
|
||||||
boolean yes = false;
|
boolean yes = false;
|
||||||
for (ProtocolVersion compatibleVersion : getServerVersion().getCompatibleVersions()) {
|
for (ProtocolVersion compatibleVersion : getServerVersion().getCompatibleVersions()) {
|
||||||
yes = compatibleVersion.getProtocolType() == ProtocolVersion.ProtocolType.CLASSIC;
|
yes = compatibleVersion.getProtocolType() == ProtocolVersion.ProtocolType.CLASSIC;
|
||||||
@@ -71,15 +70,19 @@ public class ProtocolClient extends DefaultMethodsOverrider {
|
|||||||
return isClassicServer() || yes;
|
return isClassicServer() || yes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPacketSupported(OACPacket packet) {
|
public final boolean isPacketSupported(OACPacket packet) {
|
||||||
return isVersionSupported(packet.getProtocolVersion());
|
return isVersionSupported(packet.getProtocolVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVersionSupported(ProtocolVersion targetVersion) {
|
public final boolean isVersionSupported(ProtocolVersion targetVersion) {
|
||||||
return getServerVersion() == targetVersion || getServerVersion().getCompatibleVersions().contains(targetVersion);
|
return getServerVersion() == targetVersion || getServerVersion().getCompatibleVersions().contains(targetVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProtocolClient(File caFolder, File certificatesClientFolder, File certificatesKeyFolder) {
|
public ProtocolClient(File caFolder, File certificatesClientFolder, File certificatesKeyFolder) {
|
||||||
|
if (!caFolder.exists()) caFolder.mkdirs();
|
||||||
|
if (!certificatesClientFolder.exists()) certificatesClientFolder.mkdirs();
|
||||||
|
if (!certificatesKeyFolder.exists()) certificatesKeyFolder.mkdirs();
|
||||||
|
|
||||||
networkClient = new NetworkClient.ClientBuilder().setLogger(ProtocolBridge.getInstance().getLogger()).
|
networkClient = new NetworkClient.ClientBuilder().setLogger(ProtocolBridge.getInstance().getLogger()).
|
||||||
setHost(ProtocolBridge.getInstance().getProtocolSettings().host).setPort(ProtocolBridge.getInstance().getProtocolSettings().port).
|
setHost(ProtocolBridge.getInstance().getProtocolSettings().host).setPort(ProtocolBridge.getInstance().getProtocolSettings().port).
|
||||||
setPacketHandler(ProtocolBridge.getInstance().getProtocolSettings().packetHandler).setEventManager(ProtocolBridge.getInstance().getProtocolSettings().eventManager).
|
setPacketHandler(ProtocolBridge.getInstance().getProtocolSettings().packetHandler).setEventManager(ProtocolBridge.getInstance().getProtocolSettings().eventManager).
|
||||||
|
@@ -1,26 +1,42 @@
|
|||||||
package github.openautonomousconnection.protocol.side.server;
|
package github.openautonomousconnection.protocol.side.server;
|
||||||
|
|
||||||
import github.openautonomousconnection.protocol.ProtocolBridge;
|
import github.openautonomousconnection.protocol.ProtocolBridge;
|
||||||
|
import github.openautonomousconnection.protocol.versions.v1_0_0.beta.Domain;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import me.finn.unlegitlibrary.file.ConfigurationManager;
|
||||||
import me.finn.unlegitlibrary.network.system.server.NetworkServer;
|
import me.finn.unlegitlibrary.network.system.server.NetworkServer;
|
||||||
|
import me.finn.unlegitlibrary.utils.DefaultMethodsOverrider;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class ProtocolServer {
|
public abstract class ProtocolServer extends DefaultMethodsOverrider {
|
||||||
@Getter
|
@Getter
|
||||||
private final NetworkServer networkServer;
|
private final NetworkServer networkServer;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private List<ConnectedProtocolClient> clients;
|
private List<ConnectedProtocolClient> clients;
|
||||||
|
|
||||||
public ConnectedProtocolClient getClientByID(int clientID) {
|
private ConfigurationManager configurationManager;
|
||||||
|
|
||||||
|
public final ConnectedProtocolClient getClientByID(int clientID) {
|
||||||
for (ConnectedProtocolClient client : clients) if (client.getConnectionHandler().getClientID() == clientID) return client;
|
for (ConnectedProtocolClient client : clients) if (client.getConnectionHandler().getClientID() == clientID) return client;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProtocolServer(File caFolder, File certFile, File keyFile) {
|
public ProtocolServer(File caFolder, File certFile, File keyFile, File configFile) throws IOException {
|
||||||
|
if (!caFolder.exists()) caFolder.mkdirs();
|
||||||
|
if (!certFile.exists() || !keyFile.exists()) throw new FileNotFoundException("Certificate or Key is missing!");
|
||||||
|
|
||||||
|
configurationManager = new ConfigurationManager(configFile);
|
||||||
|
configurationManager.loadProperties();
|
||||||
|
|
||||||
|
if (!configurationManager.isSet("server.site.info")) configurationManager.set("server.site.info", "DNS-SERVER INFO SITE IP");
|
||||||
|
if (!configurationManager.isSet("server.site.register")) configurationManager.set("server.site.register", "SERVER IP TO DNS-FRONTENT WEBSITE");
|
||||||
|
|
||||||
ProtocolBridge protocolBridge = ProtocolBridge.getInstance();
|
ProtocolBridge protocolBridge = ProtocolBridge.getInstance();
|
||||||
this.clients = new ArrayList<>();
|
this.clients = new ArrayList<>();
|
||||||
|
|
||||||
@@ -31,4 +47,17 @@ public abstract class ProtocolServer {
|
|||||||
setRequireClientCertificate(false).setRootCAFolder(caFolder).setServerCertificate(certFile, keyFile).
|
setRequireClientCertificate(false).setRootCAFolder(caFolder).setServerCertificate(certFile, keyFile).
|
||||||
build();
|
build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final String getDNSInfoSite() {
|
||||||
|
return configurationManager.getString("server.site.info");
|
||||||
|
}
|
||||||
|
|
||||||
|
public final String getDNSRegisterSite() {
|
||||||
|
return configurationManager.getString("server.site.register");
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract List<Domain> getDomains();
|
||||||
|
public abstract String getDomainDestination(Domain domain);
|
||||||
|
public abstract String getSubnameDestination(Domain domain, String subname);
|
||||||
|
public abstract String getTLNInfoSite(String topLevelName);
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,7 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public enum ProtocolVersion implements Serializable {
|
public enum ProtocolVersion implements Serializable {
|
||||||
PV_1_0_0_CLASSIC("1.0.0", ProtocolType.CLASSIC, ProtocolSide.SERVER),
|
PV_1_0_0_CLASSIC("1.0.0", ProtocolType.CLASSIC, ProtocolSide.BOTH),
|
||||||
PV_1_0_0_BETA("1.0.0", ProtocolType.BETA, ProtocolSide.BOTH, PV_1_0_0_CLASSIC)
|
PV_1_0_0_BETA("1.0.0", ProtocolType.BETA, ProtocolSide.BOTH, PV_1_0_0_CLASSIC)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@@ -0,0 +1,42 @@
|
|||||||
|
package github.openautonomousconnection.protocol.versions.v1_0_0.beta;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
public enum DNSResponseCode {
|
||||||
|
RESPONSE_NOT_REQUIRED(0, "Response code not required"),
|
||||||
|
|
||||||
|
RESPONSE_AUTH_SUCCESS(1, "Auth success"),
|
||||||
|
RESPONSE_AUTH_FAILED(2, "Auth failed"),
|
||||||
|
|
||||||
|
RESPONSE_DOMAIN_EXIST(100, "Domain exist"),
|
||||||
|
RESPONSE_DOMAIN_NOT_EXIST(101, "Domain does not exist"),
|
||||||
|
RESPONSE_DOMAIN_CREATED(105, "Domain created"),
|
||||||
|
RESPONSE_DOMAIN_DELETED(106, "Domain deleted"),
|
||||||
|
|
||||||
|
RESPONSE_DOMAIN_TLN_EXIST(110, "TopLevelName exist"),
|
||||||
|
RESPONSE_DOMAIN_TLN_NOT_EXIST(111, "TopLevelName does not exist"),
|
||||||
|
RESPONSE_DOMAIN_TLN_CREATED(115, "TopLevelName created"),
|
||||||
|
RESPONSE_DOMAIN_TLN_DELETED(116, "TopLevelName deleted"),
|
||||||
|
|
||||||
|
RESPONSE_DOMAIN_SUBNAME_EXIST(120, "Subname exist"),
|
||||||
|
RESPONSE_DOMAIN_SUBNAME_NOT_EXIST(121, "Subname does not exist"),
|
||||||
|
RESPONSE_DOMAIN_SUBNAME_CREATED(125, "Subname created"),
|
||||||
|
RESPONSE_DOMAIN_SUBNAME_DELETED(126, "Subname deleted"),
|
||||||
|
;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final int code;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final String description;
|
||||||
|
|
||||||
|
DNSResponseCode(int code, String description) {
|
||||||
|
this.code = code;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "{code=" + code + ";description=" + description +"}";
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,6 @@
|
|||||||
package github.openautonomousconnection.protocol.versions.v1_0_0.beta;
|
package github.openautonomousconnection.protocol.versions.v1_0_0.beta;
|
||||||
|
|
||||||
|
import github.openautonomousconnection.protocol.ProtocolBridge;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
@@ -7,6 +8,15 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Domain implements Serializable {
|
public class Domain implements Serializable {
|
||||||
|
public static class DefaultDomains {
|
||||||
|
public static final Domain DNS_INFO_SITE = new Domain("oac://about.oac/");
|
||||||
|
public static final Domain DNS_REGISTER_SITE = new Domain("oac://register.oac/");
|
||||||
|
|
||||||
|
public static Domain TLN_INFO_SITE(String topLevelName) {
|
||||||
|
return new Domain("oac://about." + topLevelName + "/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final String subname;
|
private final String subname;
|
||||||
@Getter
|
@Getter
|
||||||
@@ -14,18 +24,19 @@ public class Domain implements Serializable {
|
|||||||
@Getter
|
@Getter
|
||||||
private final String topLevelName;
|
private final String topLevelName;
|
||||||
@Getter
|
@Getter
|
||||||
private final String path;
|
private String path;
|
||||||
@Getter
|
@Getter
|
||||||
private final String query;
|
private String query;
|
||||||
@Getter
|
@Getter
|
||||||
private final String fragment;
|
private String fragment;
|
||||||
@Getter
|
@Getter
|
||||||
private final String protocol;
|
private String protocol;
|
||||||
|
|
||||||
public Domain(String fullDomain) {
|
public Domain(String fullDomain) {
|
||||||
// Remove protocol
|
// Remove protocol
|
||||||
String domainWithPath = fullDomain.contains("://") ? fullDomain.split("://", 2)[1] : fullDomain;
|
String domainWithPath = fullDomain.contains("://") ? fullDomain.split("://", 2)[1] : fullDomain;
|
||||||
this.protocol = fullDomain.contains("://") ? fullDomain.split("://", 2)[0] : "";
|
this.protocol = fullDomain.contains("://") ? fullDomain.split("://", 2)[0] : "";
|
||||||
|
if (this.protocol.endsWith("://")) this.protocol = this.protocol.substring(0, this.protocol.length() - "://".length());
|
||||||
|
|
||||||
// Cut path
|
// Cut path
|
||||||
String[] domainPartsAndPath = domainWithPath.split("/", 2);
|
String[] domainPartsAndPath = domainWithPath.split("/", 2);
|
||||||
@@ -36,9 +47,9 @@ public class Domain implements Serializable {
|
|||||||
List<String> labels = Arrays.asList(host.split("\\."));
|
List<String> labels = Arrays.asList(host.split("\\."));
|
||||||
if (labels.size() < 2) throw new IllegalArgumentException("Invalid domain: " + host);
|
if (labels.size() < 2) throw new IllegalArgumentException("Invalid domain: " + host);
|
||||||
|
|
||||||
this.topLevelName = labels.get(labels.size() - 1);
|
this.topLevelName = labels.getLast();
|
||||||
this.name = labels.get(labels.size() - 2);
|
this.name = labels.get(labels.size() - 2);
|
||||||
this.subname = labels.size() > 2 ? String.join(".", labels.subList(0, labels.size() - 2)) : "";
|
this.subname = labels.size() > 2 ? String.join(".", labels.subList(0, labels.size() - 2)) : null;
|
||||||
|
|
||||||
if (fullPath.contains("#")) {
|
if (fullPath.contains("#")) {
|
||||||
this.fragment = "#" + Arrays.stream(fullPath.split("#")).toList().getLast();
|
this.fragment = "#" + Arrays.stream(fullPath.split("#")).toList().getLast();
|
||||||
@@ -54,10 +65,32 @@ public class Domain implements Serializable {
|
|||||||
this.path = fullPath;
|
this.path = fullPath;
|
||||||
this.query = "";
|
this.query = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.path.startsWith("/")) this.path = this.path.substring(1);
|
||||||
|
if (this.path.endsWith("/")) this.path = this.path.substring(0, this.path.length() - 1);
|
||||||
|
|
||||||
|
if (this.query.startsWith("?")) this.query = this.query.substring(1);
|
||||||
|
if (this.fragment.startsWith("#")) this.fragment = this.fragment.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDestination() {
|
public final boolean hasSubname() {
|
||||||
return "404";
|
return subname != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final boolean equals(Object obj) {
|
||||||
|
if (!(obj instanceof Domain domain)) return false;
|
||||||
|
|
||||||
|
return domain.getSubname().equalsIgnoreCase(this.subname) && domain.getName().equalsIgnoreCase(this.name) &&
|
||||||
|
domain.getTopLevelName().equalsIgnoreCase(this.topLevelName) && domain.getProtocol().equalsIgnoreCase(this.protocol);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final String getDestination() {
|
||||||
|
if (this.equals(DefaultDomains.DNS_INFO_SITE)) return ProtocolBridge.getInstance().getProtocolServer().getDNSInfoSite();
|
||||||
|
if (this.equals(DefaultDomains.DNS_REGISTER_SITE)) return ProtocolBridge.getInstance().getProtocolServer().getDNSRegisterSite();
|
||||||
|
if (this.name.equalsIgnoreCase("about") && this.protocol.equalsIgnoreCase("oac")) return ProtocolBridge.getInstance().getProtocolServer().getTLNInfoSite(topLevelName);
|
||||||
|
|
||||||
|
return !hasSubname() ? ProtocolBridge.getInstance().getProtocolServer().getDomainDestination(this) : ProtocolBridge.getInstance().getProtocolServer().getSubnameDestination(this, subname);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +0,0 @@
|
|||||||
package github.openautonomousconnection.protocol.versions.v1_0_0.beta;
|
|
||||||
|
|
||||||
public class DomainTest {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
new Domain("hello.world.com/content/t/lookup.html?what=cooler+test#searchBox");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,5 +1,6 @@
|
|||||||
package github.openautonomousconnection.protocol.versions.v1_0_0.classic;
|
package github.openautonomousconnection.protocol.versions.v1_0_0.classic;
|
||||||
|
|
||||||
|
import github.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||||
import github.openautonomousconnection.protocol.versions.v1_0_0.beta.Domain;
|
import github.openautonomousconnection.protocol.versions.v1_0_0.beta.Domain;
|
||||||
|
|
||||||
public class ClassicConverter {
|
public class ClassicConverter {
|
||||||
@@ -12,4 +13,13 @@ public class ClassicConverter {
|
|||||||
return new Classic_Domain(newDomain.getName(), newDomain.getTopLevelName(), newDomain.getDestination(), newDomain.getPath());
|
return new Classic_Domain(newDomain.getName(), newDomain.getTopLevelName(), newDomain.getDestination(), newDomain.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ProtocolVersion classicProtocolVersionToNewProtocolVersion(Classic_ProtocolVersion classicProtocolVersion) {
|
||||||
|
if (classicProtocolVersion == Classic_ProtocolVersion.PV_1_0_0) return ProtocolVersion.PV_1_0_0_CLASSIC;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Classic_ProtocolVersion newProtocolVersionToClassicProtocolVersion(ProtocolVersion newProtocolVersion) {
|
||||||
|
return Classic_ProtocolVersion.PV_1_0_0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -5,5 +5,6 @@ import github.openautonomousconnection.protocol.packets.v1_0_0.beta.UnsupportedC
|
|||||||
public abstract class ClassicHandlerClient {
|
public abstract class ClassicHandlerClient {
|
||||||
|
|
||||||
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 handleMessage(String message);
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,76 @@
|
|||||||
|
package github.openautonomousconnection.protocol.versions.v1_0_0.classic;
|
||||||
|
|
||||||
|
import github.openautonomousconnection.protocol.ProtocolBridge;
|
||||||
|
import github.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_PingPacket;
|
||||||
|
import me.finn.unlegitlibrary.event.EventListener;
|
||||||
|
import me.finn.unlegitlibrary.event.Listener;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class Classic_ClientListener extends EventListener {
|
||||||
|
|
||||||
|
@Listener
|
||||||
|
public void onDomain(Classic_DomainPacketReceivedEvent event) {
|
||||||
|
boolean exists = event.domain != null;
|
||||||
|
|
||||||
|
if (exists) {
|
||||||
|
try {
|
||||||
|
if (!ProtocolBridge.getInstance().getProtocolClient().getNetworkClient().sendPacket(new Classic_PingPacket(event.requestDomain, event.domain, false))) {
|
||||||
|
ProtocolBridge.getInstance().getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-occurred", "html", ""),
|
||||||
|
Classic_WebsitesContent.ERROR_OCCURRED(event.domain.toString() + "/" + event.domain.path));
|
||||||
|
}
|
||||||
|
} catch (IOException | ClassNotFoundException e) {
|
||||||
|
ProtocolBridge.getInstance().getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-occurred", "html", ""),
|
||||||
|
Classic_WebsitesContent.ERROR_OCCURRED(event.domain.toString() + "/" + event.domain.path + ":\n" + e.getMessage()));
|
||||||
|
}
|
||||||
|
} else ProtocolBridge.getInstance().getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("domain-not-found", "html", ""), Classic_WebsitesContent.DOMAIN_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Listener
|
||||||
|
public void onPing(Classic_PingPacketReceivedEvent event) {
|
||||||
|
if (event.reachable) {
|
||||||
|
String destination = event.domain.getDomain().getDestination();
|
||||||
|
|
||||||
|
try {
|
||||||
|
URL url = new URL(destination);
|
||||||
|
HttpURLConnection connection2 = (HttpURLConnection) url.openConnection();
|
||||||
|
connection2.setRequestMethod("GET");
|
||||||
|
|
||||||
|
StringBuilder content = new StringBuilder();
|
||||||
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection2.getInputStream()))) {
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) content.append(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolBridge.getInstance().getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PUBLIC, event.domain, content.toString());
|
||||||
|
} catch (IOException exception) {
|
||||||
|
ProtocolBridge.getInstance().getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-occurred", "html", ""),
|
||||||
|
Classic_WebsitesContent.ERROR_OCCURRED(exception.getMessage().replace(event.domain.getDomain().getDestination(), event.domain.toString() + "/" + event.domain.path)));
|
||||||
|
}
|
||||||
|
} else ProtocolBridge.getInstance().getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-not-reached", "html", ""), Classic_WebsitesContent.DOMAIN_NOT_REACHABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final Object clone() throws CloneNotSupportedException {
|
||||||
|
return super.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final boolean equals(Object obj) {
|
||||||
|
return super.equals(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final String toString() {
|
||||||
|
return super.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final int hashCode() {
|
||||||
|
return super.hashCode();
|
||||||
|
}
|
||||||
|
}
|
@@ -1,9 +1,7 @@
|
|||||||
package github.openautonomousconnection.protocol.versions.v1_0_0.classic;
|
package github.openautonomousconnection.protocol.versions.v1_0_0.classic;
|
||||||
|
|
||||||
import github.openautonomousconnection.protocol.versions.v1_0_0.beta.Domain;
|
import github.openautonomousconnection.protocol.versions.v1_0_0.beta.Domain;
|
||||||
import github.openautonomousconnection.protocol.versions.v1_0_0.beta.DomainTest;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import me.finn.unlegitlibrary.string.StringUtils;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@@ -0,0 +1,68 @@
|
|||||||
|
package github.openautonomousconnection.protocol.versions.v1_0_0.classic;
|
||||||
|
|
||||||
|
import me.finn.unlegitlibrary.utils.DefaultMethodsOverrider;
|
||||||
|
|
||||||
|
public class Classic_WebsitesContent extends DefaultMethodsOverrider {
|
||||||
|
|
||||||
|
public static final String DOMAIN_NOT_FOUND = """
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>404 - Domain not found</title>
|
||||||
|
<meta content="UTF-8" name="charset"/>
|
||||||
|
<meta content="Open Autonomous Connection" name="author"/>
|
||||||
|
<meta content="Domain not found" name="description"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>404 - This domain was not found</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
""";
|
||||||
|
|
||||||
|
public static final String FILE_NOT_FOUND = """
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>404 - File not found</title>
|
||||||
|
<meta content="UTF-8" name="charset"/>
|
||||||
|
<meta content="Open Autonomous Connection" name="author"/>
|
||||||
|
<meta content="File not found" name="description"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>404 - This file was not found</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
""";
|
||||||
|
|
||||||
|
public static final String DOMAIN_NOT_REACHABLE = """
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>504 - Site not reachable</title>
|
||||||
|
<meta content="UTF-8" name="charset"/>
|
||||||
|
<meta content="Open Autonomous Connection" name="author"/>
|
||||||
|
<meta content="Site not reached" name="description"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>504 - This site is currently not reachable</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
""";
|
||||||
|
|
||||||
|
public static String ERROR_OCCURRED(String errorDetails) {
|
||||||
|
return """
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>500 - Error occurred</title>
|
||||||
|
<meta content="UTF-8" name="charset"/>
|
||||||
|
<meta content="Open Autonomous Connection" name="author"/>
|
||||||
|
<meta content="Site not reached" name="description"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>500 - Error occured while resolving domain!</h1>
|
||||||
|
<h4>Details:</h2>
|
||||||
|
<h5>""" + errorDetails + "</h5>" + """
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
""";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String ERROR_OCCURRED = ERROR_OCCURRED("No specified details!");
|
||||||
|
}
|
Reference in New Issue
Block a user