- Finished with Classic
- Updated dependencies
This commit is contained in:
4
pom.xml
4
pom.xml
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>github.openautonomousconnection</groupId>
|
||||
<artifactId>protocol</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>23</maven.compiler.source>
|
||||
@@ -36,7 +36,7 @@
|
||||
<dependency>
|
||||
<groupId>me.finn.unlegitlibrary</groupId>
|
||||
<artifactId>unlegitlibrary</artifactId>
|
||||
<version>1.5.13</version>
|
||||
<version>1.5.15</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package github.openautonomousconnection.protocol;
|
||||
|
||||
import github.openautonomousconnection.protocol.handle.ClassicHandler;
|
||||
import github.openautonomousconnection.protocol.handle.ClassicHandlerServer;
|
||||
import github.openautonomousconnection.protocol.side.ProtocolClient;
|
||||
import github.openautonomousconnection.protocol.side.ProtocolServer;
|
||||
import lombok.Getter;
|
||||
@@ -28,7 +28,7 @@ public class ProtocolBridge {
|
||||
private final Logger logger;
|
||||
|
||||
@Getter @Setter
|
||||
private ClassicHandler classicHandler;
|
||||
private ClassicHandlerServer classicHandlerServer;
|
||||
|
||||
public ProtocolBridge(ProtocolServer protocolServer, ProtocolSettings protocolSettings, ProtocolVersion protocolVersion, File logFolder) {
|
||||
this.protocolServer = protocolServer;
|
||||
@@ -74,6 +74,16 @@ public class ProtocolBridge {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isClassic() {
|
||||
boolean yes = false;
|
||||
for (ProtocolVersion compatibleVersion : protocolVersion.getCompatibleVersions()) {
|
||||
yes = compatibleVersion.getProtocolType() == ProtocolVersion.ProtocolType.CLASSIC;
|
||||
if (yes) break;
|
||||
}
|
||||
|
||||
return protocolVersion.getProtocolType() == ProtocolVersion.ProtocolType.CLASSIC || yes;
|
||||
}
|
||||
|
||||
public boolean isRunningAsServer() {
|
||||
return protocolServer != null;
|
||||
}
|
||||
|
@@ -0,0 +1,39 @@
|
||||
package github.openautonomousconnection.protocol.classic;
|
||||
|
||||
import github.openautonomousconnection.protocol.ProtocolVersion;
|
||||
import me.finn.unlegitlibrary.event.impl.Event;
|
||||
|
||||
public class Classic_DomainPacketReceivedEvent extends Event {
|
||||
|
||||
public final Classic_ProtocolVersion protocolVersion;
|
||||
public final Classic_Domain domain;
|
||||
public final Classic_RequestDomain requestDomain;
|
||||
public final int clientID;
|
||||
|
||||
public Classic_DomainPacketReceivedEvent(Classic_ProtocolVersion protocolVersion, Classic_Domain domain, Classic_RequestDomain requestDomain, int clientID) {
|
||||
this.protocolVersion = protocolVersion;
|
||||
this.domain = domain;
|
||||
this.requestDomain = requestDomain;
|
||||
this.clientID = clientID;
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
package github.openautonomousconnection.protocol.classic;
|
||||
|
||||
import me.finn.unlegitlibrary.event.impl.Event;
|
||||
|
||||
public class Classic_PingPacketReceivedEvent extends Event {
|
||||
|
||||
public final Classic_ProtocolVersion protocolVersion;
|
||||
public final Classic_Domain domain;
|
||||
public final Classic_RequestDomain requestDomain;
|
||||
public final boolean reachable;
|
||||
public final int clientID;
|
||||
|
||||
public Classic_PingPacketReceivedEvent(Classic_ProtocolVersion protocolVersion, Classic_Domain domain, Classic_RequestDomain requestDomain, boolean reachable, int clientID) {
|
||||
this.protocolVersion = protocolVersion;
|
||||
this.domain = domain;
|
||||
this.requestDomain = requestDomain;
|
||||
this.reachable = reachable;
|
||||
this.clientID = clientID;
|
||||
}
|
||||
|
||||
@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 +0,0 @@
|
||||
package github.openautonomousconnection.protocol.handle;
|
||||
|
||||
import me.finn.unlegitlibrary.network.system.server.ConnectionHandler;
|
||||
|
||||
public abstract class ClassicHandler {
|
||||
|
||||
public abstract void handleMessage(ConnectionHandler connectionHandler, String message);
|
||||
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
package github.openautonomousconnection.protocol.handle;
|
||||
|
||||
import github.openautonomousconnection.protocol.classic.Classic_Domain;
|
||||
import github.openautonomousconnection.protocol.classic.Classic_RequestDomain;
|
||||
import me.finn.unlegitlibrary.network.system.server.ConnectionHandler;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
public abstract class ClassicHandlerServer {
|
||||
public abstract void handleMessage(ConnectionHandler connectionHandler, String message);
|
||||
public abstract Classic_Domain getDomain(Classic_RequestDomain requestDomain) throws SQLException;
|
||||
public abstract Classic_Domain ping(Classic_RequestDomain requestDomain) throws SQLException;
|
||||
}
|
@@ -3,21 +3,22 @@ package github.openautonomousconnection.protocol.packets.v1_0_0.classic;
|
||||
import github.openautonomousconnection.protocol.ProtocolBridge;
|
||||
import github.openautonomousconnection.protocol.ProtocolVersion;
|
||||
import github.openautonomousconnection.protocol.classic.Classic_Domain;
|
||||
import github.openautonomousconnection.protocol.classic.Classic_DomainPacketReceivedEvent;
|
||||
import github.openautonomousconnection.protocol.classic.Classic_ProtocolVersion;
|
||||
import github.openautonomousconnection.protocol.classic.Classic_RequestDomain;
|
||||
import github.openautonomousconnection.protocol.packets.OACPacket;
|
||||
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;
|
||||
import java.sql.SQLException;
|
||||
|
||||
// ProtocolVersion 1.0.0-CLASSIC is ProtocolSide Server only
|
||||
public class DomainPacket extends OACPacket {
|
||||
private final Classic_RequestDomain requestDomain;
|
||||
private final Classic_Domain domain;
|
||||
private final int clientID;
|
||||
private Classic_RequestDomain requestDomain;
|
||||
private Classic_Domain domain;
|
||||
private int clientID;
|
||||
|
||||
public DomainPacket(ProtocolBridge protocolBridge, int toClient, Classic_RequestDomain requestDomain, Classic_Domain domain) {
|
||||
super(2, ProtocolVersion.ProtocolType.CLASSIC, protocolBridge);
|
||||
@@ -37,6 +38,17 @@ public class DomainPacket extends OACPacket {
|
||||
|
||||
@Override
|
||||
public void read(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||
clientID = objectInputStream.readInt();
|
||||
requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
|
||||
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
|
||||
|
||||
try {
|
||||
domain = getProtocolBridge().getClassicHandlerServer().getDomain(requestDomain);
|
||||
} catch (SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
getProtocolBridge().getProtocolServer().getNetworkServer().getEventManager().executeEvent(new Classic_DomainPacketReceivedEvent(protocolVersion, domain, requestDomain, clientID));
|
||||
getProtocolBridge().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new DomainPacket(getProtocolBridge(), clientID, requestDomain, domain));
|
||||
}
|
||||
}
|
||||
|
@@ -4,7 +4,6 @@ import github.openautonomousconnection.protocol.ProtocolBridge;
|
||||
import github.openautonomousconnection.protocol.ProtocolVersion;
|
||||
import github.openautonomousconnection.protocol.classic.Classic_ProtocolVersion;
|
||||
import github.openautonomousconnection.protocol.packets.OACPacket;
|
||||
import github.openautonomousconnection.protocol.side.ProtocolClient;
|
||||
import me.finn.unlegitlibrary.network.system.packets.PacketHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -14,7 +13,6 @@ import java.io.ObjectOutputStream;
|
||||
// ProtocolVersion 1.0.0-CLASSIC is ProtocolSide Server only
|
||||
public class MessagePacket extends OACPacket {
|
||||
private final String message;
|
||||
private Classic_ProtocolVersion protocolVersion;
|
||||
private final int clientID;
|
||||
|
||||
public MessagePacket(String message, int toClient, ProtocolBridge protocolBridge) {
|
||||
@@ -35,8 +33,8 @@ public class MessagePacket extends OACPacket {
|
||||
public void read(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||
int clientID = objectInputStream.readInt();
|
||||
String message = objectInputStream.readUTF();
|
||||
protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
|
||||
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
|
||||
|
||||
getProtocolBridge().getClassicHandler().handleMessage(getProtocolBridge().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID), message);
|
||||
getProtocolBridge().getClassicHandlerServer().handleMessage(getProtocolBridge().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID), message);
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,58 @@
|
||||
package github.openautonomousconnection.protocol.packets.v1_0_0.classic;
|
||||
|
||||
public class PingPacket {
|
||||
import github.openautonomousconnection.protocol.ProtocolBridge;
|
||||
import github.openautonomousconnection.protocol.ProtocolVersion;
|
||||
import github.openautonomousconnection.protocol.classic.Classic_Domain;
|
||||
import github.openautonomousconnection.protocol.classic.Classic_PingPacketReceivedEvent;
|
||||
import github.openautonomousconnection.protocol.classic.Classic_ProtocolVersion;
|
||||
import github.openautonomousconnection.protocol.classic.Classic_RequestDomain;
|
||||
import github.openautonomousconnection.protocol.packets.OACPacket;
|
||||
import me.finn.unlegitlibrary.network.system.packets.PacketHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class PingPacket extends OACPacket {
|
||||
private Classic_RequestDomain requestDomain;
|
||||
private Classic_Domain domain;
|
||||
private int clientID;
|
||||
private boolean reachable;
|
||||
private Classic_ProtocolVersion protocolVersion;
|
||||
|
||||
public PingPacket(ProtocolBridge protocolBridge, Classic_RequestDomain requestDomain, Classic_Domain domain, boolean reachable) {
|
||||
super(1, ProtocolVersion.ProtocolType.CLASSIC, protocolBridge);
|
||||
|
||||
this.requestDomain = requestDomain;
|
||||
this.domain = domain;
|
||||
this.reachable = reachable;
|
||||
this.protocolVersion = Classic_ProtocolVersion.PV_1_0_0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
||||
objectOutputStream.writeInt(clientID);
|
||||
objectOutputStream.writeObject(requestDomain);
|
||||
objectOutputStream.writeObject(domain);
|
||||
objectOutputStream.writeBoolean(reachable);
|
||||
objectOutputStream.writeObject(protocolVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||
clientID = objectInputStream.readInt();
|
||||
requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
|
||||
protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
|
||||
|
||||
try {
|
||||
domain = getProtocolBridge().getClassicHandlerServer().ping(requestDomain);
|
||||
} catch (SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
reachable = domain != null;
|
||||
getProtocolBridge().getProtocolServer().getNetworkServer().getEventManager().executeEvent(new Classic_PingPacketReceivedEvent(protocolVersion, domain, requestDomain, reachable, clientID));
|
||||
getProtocolBridge().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new PingPacket(getProtocolBridge(), requestDomain, domain, reachable));
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package github.openautonomousconnection.protocol.side;
|
||||
|
||||
import github.openautonomousconnection.protocol.ProtocolBridge;
|
||||
import github.openautonomousconnection.protocol.handle.ClassicHandler;
|
||||
import lombok.Getter;
|
||||
import me.finn.unlegitlibrary.network.system.server.NetworkServer;
|
||||
|
||||
|
Reference in New Issue
Block a user