- Finished classic

This commit is contained in:
2025-09-19 20:46:57 +02:00
parent 88bed841ef
commit 392ea4935d
5 changed files with 48 additions and 23 deletions

View File

@@ -1,6 +1,9 @@
package github.openautonomousconnection.protocol; package github.openautonomousconnection.protocol;
import github.openautonomousconnection.protocol.handle.ClassicHandlerServer; import github.openautonomousconnection.protocol.handle.ClassicHandlerServer;
import github.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_DomainPacket;
import github.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_MessagePacket;
import github.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_PingPacket;
import github.openautonomousconnection.protocol.side.ProtocolClient; import github.openautonomousconnection.protocol.side.ProtocolClient;
import github.openautonomousconnection.protocol.side.ProtocolServer; import github.openautonomousconnection.protocol.side.ProtocolServer;
import lombok.Getter; import lombok.Getter;
@@ -30,6 +33,9 @@ public class ProtocolBridge {
@Getter @Setter @Getter @Setter
private ClassicHandlerServer classicHandlerServer; private ClassicHandlerServer classicHandlerServer;
@Getter
private static ProtocolBridge instance;
public ProtocolBridge(ProtocolServer protocolServer, ProtocolSettings protocolSettings, ProtocolVersion protocolVersion, File logFolder) { public ProtocolBridge(ProtocolServer protocolServer, ProtocolSettings protocolSettings, ProtocolVersion protocolVersion, File logFolder) {
this.protocolServer = protocolServer; this.protocolServer = protocolServer;
this.protocolSettings = protocolSettings; this.protocolSettings = protocolSettings;
@@ -50,6 +56,8 @@ public class ProtocolBridge {
this.logger.error("Invalid protocol version '" + protocolVersion.toString() + "'!"); this.logger.error("Invalid protocol version '" + protocolVersion.toString() + "'!");
System.exit(1); System.exit(1);
} }
instance = this;
} }
public ProtocolBridge(ProtocolClient protocolClient, ProtocolSettings protocolSettings, ProtocolVersion protocolVersion, File logFolder) { public ProtocolBridge(ProtocolClient protocolClient, ProtocolSettings protocolSettings, ProtocolVersion protocolVersion, File logFolder) {
@@ -72,9 +80,17 @@ public class ProtocolBridge {
this.logger.error("Invalid protocol version '" + protocolVersion.toString() + "'!"); this.logger.error("Invalid protocol version '" + protocolVersion.toString() + "'!");
System.exit(1); System.exit(1);
} }
if (isClassicSupported()) {
protocolSettings.packetHandler.registerPacket(new Classic_DomainPacket());
protocolSettings.packetHandler.registerPacket(new Classic_MessagePacket());
protocolSettings.packetHandler.registerPacket(new Classic_PingPacket());
}
instance = this;
} }
private boolean isClassic() { public boolean isClassicSupported() {
boolean yes = false; boolean yes = false;
for (ProtocolVersion compatibleVersion : protocolVersion.getCompatibleVersions()) { for (ProtocolVersion compatibleVersion : protocolVersion.getCompatibleVersions()) {
yes = compatibleVersion.getProtocolType() == ProtocolVersion.ProtocolType.CLASSIC; yes = compatibleVersion.getProtocolType() == ProtocolVersion.ProtocolType.CLASSIC;

View File

@@ -8,12 +8,9 @@ import me.finn.unlegitlibrary.network.system.packets.Packet;
public abstract class OACPacket extends Packet { public abstract class OACPacket extends Packet {
@Getter @Getter
private final ProtocolVersion.ProtocolType packetType; private final ProtocolVersion.ProtocolType packetType;
@Getter
private final ProtocolBridge protocolBridge;
public OACPacket(int id, ProtocolVersion.ProtocolType packetType, ProtocolBridge protocolBridge) { public OACPacket(int id, ProtocolVersion.ProtocolType packetType) {
super(id); super(id);
this.packetType = packetType; this.packetType = packetType;
this.protocolBridge = protocolBridge;
} }
} }

View File

@@ -15,18 +15,22 @@ import java.io.ObjectOutputStream;
import java.sql.SQLException; import java.sql.SQLException;
// ProtocolVersion 1.0.0-CLASSIC is ProtocolSide Server only // ProtocolVersion 1.0.0-CLASSIC is ProtocolSide Server only
public class DomainPacket extends OACPacket { public class Classic_DomainPacket extends OACPacket {
private Classic_RequestDomain requestDomain; private Classic_RequestDomain requestDomain;
private Classic_Domain domain; private Classic_Domain domain;
private int clientID; private int clientID;
public DomainPacket(ProtocolBridge protocolBridge, int toClient, Classic_RequestDomain requestDomain, Classic_Domain domain) { public Classic_DomainPacket(int toClient, Classic_RequestDomain requestDomain, Classic_Domain domain) {
super(2, ProtocolVersion.ProtocolType.CLASSIC, protocolBridge); this();
this.clientID = toClient; this.clientID = toClient;
this.requestDomain = requestDomain; this.requestDomain = requestDomain;
this.domain = domain; this.domain = domain;
} }
public Classic_DomainPacket() {
super(2, ProtocolVersion.ProtocolType.CLASSIC);
}
@Override @Override
public void write(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException { public void write(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
objectOutputStream.writeInt(clientID); objectOutputStream.writeInt(clientID);
@@ -43,12 +47,12 @@ public class DomainPacket extends OACPacket {
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject(); Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
try { try {
domain = getProtocolBridge().getClassicHandlerServer().getDomain(requestDomain); domain = ProtocolBridge.getInstance().getClassicHandlerServer().getDomain(requestDomain);
} catch (SQLException exception) { } catch (SQLException exception) {
exception.printStackTrace(); exception.printStackTrace();
} }
getProtocolBridge().getProtocolServer().getNetworkServer().getEventManager().executeEvent(new Classic_DomainPacketReceivedEvent(protocolVersion, domain, requestDomain, clientID)); ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getEventManager().executeEvent(new Classic_DomainPacketReceivedEvent(protocolVersion, domain, requestDomain, clientID));
getProtocolBridge().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new DomainPacket(getProtocolBridge(), clientID, requestDomain, domain)); ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new Classic_DomainPacket(clientID, requestDomain, domain));
} }
} }

View File

@@ -11,16 +11,20 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
// ProtocolVersion 1.0.0-CLASSIC is ProtocolSide Server only // ProtocolVersion 1.0.0-CLASSIC is ProtocolSide Server only
public class MessagePacket extends OACPacket { public class Classic_MessagePacket extends OACPacket {
private final String message; private String message;
private final int clientID; private int clientID;
public MessagePacket(String message, int toClient, ProtocolBridge protocolBridge) { public Classic_MessagePacket(String message, int toClient) {
super(3, ProtocolVersion.ProtocolType.CLASSIC, protocolBridge); this();
this.message = message; this.message = message;
this.clientID = toClient; this.clientID = toClient;
} }
public Classic_MessagePacket() {
super(3, ProtocolVersion.ProtocolType.CLASSIC);
}
@Override @Override
public void write(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException { public void write(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
objectOutputStream.writeInt(clientID); objectOutputStream.writeInt(clientID);
@@ -35,6 +39,6 @@ public class MessagePacket extends OACPacket {
String message = objectInputStream.readUTF(); String message = objectInputStream.readUTF();
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject(); Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
getProtocolBridge().getClassicHandlerServer().handleMessage(getProtocolBridge().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID), message); ProtocolBridge.getInstance().getClassicHandlerServer().handleMessage(ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID), message);
} }
} }

View File

@@ -14,15 +14,15 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.sql.SQLException; import java.sql.SQLException;
public class PingPacket extends OACPacket { public class Classic_PingPacket extends OACPacket {
private Classic_RequestDomain requestDomain; private Classic_RequestDomain requestDomain;
private Classic_Domain domain; private Classic_Domain domain;
private int clientID; private int clientID;
private boolean reachable; private boolean reachable;
private Classic_ProtocolVersion protocolVersion; private Classic_ProtocolVersion protocolVersion;
public PingPacket(ProtocolBridge protocolBridge, Classic_RequestDomain requestDomain, Classic_Domain domain, boolean reachable) { public Classic_PingPacket(Classic_RequestDomain requestDomain, Classic_Domain domain, boolean reachable) {
super(1, ProtocolVersion.ProtocolType.CLASSIC, protocolBridge); this();
this.requestDomain = requestDomain; this.requestDomain = requestDomain;
this.domain = domain; this.domain = domain;
@@ -30,6 +30,10 @@ public class PingPacket extends OACPacket {
this.protocolVersion = Classic_ProtocolVersion.PV_1_0_0; this.protocolVersion = Classic_ProtocolVersion.PV_1_0_0;
} }
public Classic_PingPacket() {
super(1, ProtocolVersion.ProtocolType.CLASSIC);
}
@Override @Override
public void write(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException { public void write(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
objectOutputStream.writeInt(clientID); objectOutputStream.writeInt(clientID);
@@ -46,13 +50,13 @@ public class PingPacket extends OACPacket {
protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject(); protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
try { try {
domain = getProtocolBridge().getClassicHandlerServer().ping(requestDomain); domain = ProtocolBridge.getInstance().getClassicHandlerServer().ping(requestDomain);
} catch (SQLException exception) { } catch (SQLException exception) {
exception.printStackTrace(); exception.printStackTrace();
} }
reachable = domain != null; reachable = domain != null;
getProtocolBridge().getProtocolServer().getNetworkServer().getEventManager().executeEvent(new Classic_PingPacketReceivedEvent(protocolVersion, domain, requestDomain, reachable, clientID)); ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getEventManager().executeEvent(new Classic_PingPacketReceivedEvent(protocolVersion, domain, requestDomain, reachable, clientID));
getProtocolBridge().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new PingPacket(getProtocolBridge(), requestDomain, domain, reachable)); ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new Classic_PingPacket(requestDomain, domain, reachable));
} }
} }