- Finished up with classic packets
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
package github.openautonomousconnection.protocol.side;
|
||||
|
||||
public class ProtocolClient {
|
||||
}
|
@@ -1,23 +0,0 @@
|
||||
package github.openautonomousconnection.protocol.side;
|
||||
|
||||
import github.openautonomousconnection.protocol.ProtocolBridge;
|
||||
import lombok.Getter;
|
||||
import me.finn.unlegitlibrary.network.system.server.NetworkServer;
|
||||
|
||||
public abstract class ProtocolServer {
|
||||
@Getter
|
||||
private final ProtocolBridge protocolBridge;
|
||||
|
||||
@Getter
|
||||
private NetworkServer networkServer;
|
||||
|
||||
public ProtocolServer(ProtocolBridge protocolBridge) {
|
||||
this.protocolBridge = protocolBridge;
|
||||
|
||||
this.networkServer = new NetworkServer.ServerBuilder().
|
||||
setEventManager(protocolBridge.getProtocolSettings().eventManager).
|
||||
setPacketHandler(protocolBridge.getProtocolSettings().packetHandler).
|
||||
setPort(protocolBridge.getProtocolSettings().port).
|
||||
build();
|
||||
}
|
||||
}
|
@@ -0,0 +1,89 @@
|
||||
package github.openautonomousconnection.protocol.side.client;
|
||||
|
||||
import github.openautonomousconnection.protocol.ProtocolBridge;
|
||||
import github.openautonomousconnection.protocol.packets.OACPacket;
|
||||
import github.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
import lombok.Getter;
|
||||
import me.finn.unlegitlibrary.network.system.client.NetworkClient;
|
||||
import me.finn.unlegitlibrary.network.system.client.events.ClientDisconnectedEvent;
|
||||
import me.finn.unlegitlibrary.network.system.server.NetworkServer;
|
||||
import me.finn.unlegitlibrary.utils.DefaultMethodsOverrider;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ProtocolClient extends DefaultMethodsOverrider {
|
||||
private ProtocolVersion serverVersion = null;
|
||||
|
||||
@Getter
|
||||
private final NetworkClient networkClient;
|
||||
|
||||
public ProtocolVersion getServerVersion() {
|
||||
return serverVersion == null ? ProtocolVersion.PV_1_0_0_CLASSIC : serverVersion;
|
||||
}
|
||||
|
||||
public void setServerVersion(ProtocolVersion serverVersion) {
|
||||
if (serverVersion == null) this.serverVersion = serverVersion;
|
||||
}
|
||||
|
||||
public final void onDisconnect(ClientDisconnectedEvent event) {
|
||||
serverVersion = null;
|
||||
}
|
||||
|
||||
public boolean isStableServer() {
|
||||
return !isBetaServer() && !isClassicServer();
|
||||
}
|
||||
|
||||
public boolean serverSupportStable() {
|
||||
boolean yes = false;
|
||||
for (ProtocolVersion compatibleVersion : getServerVersion().getCompatibleVersions()) {
|
||||
yes = compatibleVersion.getProtocolType() == ProtocolVersion.ProtocolType.STABLE;
|
||||
if (yes) break;
|
||||
}
|
||||
|
||||
return isStableServer() || yes;
|
||||
}
|
||||
|
||||
public boolean isBetaServer() {
|
||||
return getServerVersion().getProtocolType() == ProtocolVersion.ProtocolType.BETA;
|
||||
}
|
||||
|
||||
public boolean serverSupportBeta() {
|
||||
boolean yes = false;
|
||||
for (ProtocolVersion compatibleVersion : getServerVersion().getCompatibleVersions()) {
|
||||
yes = compatibleVersion.getProtocolType() == ProtocolVersion.ProtocolType.BETA;
|
||||
if (yes) break;
|
||||
}
|
||||
|
||||
return isBetaServer() || yes;
|
||||
}
|
||||
|
||||
public boolean isClassicServer() {
|
||||
return getServerVersion().getProtocolType() == ProtocolVersion.ProtocolType.CLASSIC;
|
||||
}
|
||||
|
||||
public boolean serverSupportClassic() {
|
||||
boolean yes = false;
|
||||
for (ProtocolVersion compatibleVersion : getServerVersion().getCompatibleVersions()) {
|
||||
yes = compatibleVersion.getProtocolType() == ProtocolVersion.ProtocolType.CLASSIC;
|
||||
if (yes) break;
|
||||
}
|
||||
|
||||
return isClassicServer() || yes;
|
||||
}
|
||||
|
||||
public boolean isPacketSupported(OACPacket packet) {
|
||||
return isVersionSupported(packet.getProtocolVersion());
|
||||
}
|
||||
|
||||
public boolean isVersionSupported(ProtocolVersion targetVersion) {
|
||||
return getServerVersion() == targetVersion || getServerVersion().getCompatibleVersions().contains(targetVersion);
|
||||
}
|
||||
|
||||
public ProtocolClient(File caFolder, File certificatesClientFolder, File certificatesKeyFolder) {
|
||||
networkClient = new NetworkClient.ClientBuilder().setLogger(ProtocolBridge.getInstance().getLogger()).
|
||||
setHost(ProtocolBridge.getInstance().getProtocolSettings().host).setPort(ProtocolBridge.getInstance().getProtocolSettings().port).
|
||||
setPacketHandler(ProtocolBridge.getInstance().getProtocolSettings().packetHandler).setEventManager(ProtocolBridge.getInstance().getProtocolSettings().eventManager).
|
||||
setRootCAFolder(caFolder).setClientCertificatesFolder(certificatesClientFolder, certificatesKeyFolder).
|
||||
build();
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
package github.openautonomousconnection.protocol.side.client.events;
|
||||
|
||||
import me.finn.unlegitlibrary.event.impl.Event;
|
||||
|
||||
public class ConnectedToProtocolServer extends Event {
|
||||
}
|
@@ -0,0 +1,76 @@
|
||||
package github.openautonomousconnection.protocol.side.server;
|
||||
|
||||
import github.openautonomousconnection.protocol.packets.OACPacket;
|
||||
import github.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
import lombok.Getter;
|
||||
import me.finn.unlegitlibrary.network.system.server.ConnectionHandler;
|
||||
|
||||
public class ConnectedProtocolClient {
|
||||
|
||||
@Getter
|
||||
private final ConnectionHandler connectionHandler;
|
||||
|
||||
private ProtocolVersion clientVersion = null;
|
||||
|
||||
public ProtocolVersion getClientVersion() {
|
||||
return clientVersion == null ? ProtocolVersion.PV_1_0_0_CLASSIC : clientVersion;
|
||||
}
|
||||
|
||||
public void setClientVersion(ProtocolVersion clientVersion) {
|
||||
if (clientVersion == null) this.clientVersion = clientVersion;
|
||||
}
|
||||
|
||||
public ConnectedProtocolClient(ConnectionHandler connectionHandler) {
|
||||
this.connectionHandler = connectionHandler;
|
||||
}
|
||||
|
||||
public boolean isStableClient() {
|
||||
return !isBetaClient() && !isClassicClient();
|
||||
}
|
||||
|
||||
public boolean clientSupportStable() {
|
||||
boolean yes = false;
|
||||
for (ProtocolVersion compatibleVersion : getClientVersion().getCompatibleVersions()) {
|
||||
yes = compatibleVersion.getProtocolType() == ProtocolVersion.ProtocolType.STABLE;
|
||||
if (yes) break;
|
||||
}
|
||||
|
||||
return isStableClient() || yes;
|
||||
}
|
||||
|
||||
public boolean isBetaClient() {
|
||||
return getClientVersion().getProtocolType() == ProtocolVersion.ProtocolType.BETA;
|
||||
}
|
||||
|
||||
public boolean clientSupportBeta() {
|
||||
boolean yes = false;
|
||||
for (ProtocolVersion compatibleVersion : getClientVersion().getCompatibleVersions()) {
|
||||
yes = compatibleVersion.getProtocolType() == ProtocolVersion.ProtocolType.BETA;
|
||||
if (yes) break;
|
||||
}
|
||||
|
||||
return isBetaClient() || yes;
|
||||
}
|
||||
|
||||
public boolean isClassicClient() {
|
||||
return getClientVersion().getProtocolType() == ProtocolVersion.ProtocolType.CLASSIC;
|
||||
}
|
||||
|
||||
public boolean clientSupportClassic() {
|
||||
boolean yes = false;
|
||||
for (ProtocolVersion compatibleVersion : getClientVersion().getCompatibleVersions()) {
|
||||
yes = compatibleVersion.getProtocolType() == ProtocolVersion.ProtocolType.CLASSIC;
|
||||
if (yes) break;
|
||||
}
|
||||
|
||||
return isClassicClient() || yes;
|
||||
}
|
||||
|
||||
public boolean isPacketSupported(OACPacket packet) {
|
||||
return isVersionSupported(packet.getProtocolVersion());
|
||||
}
|
||||
|
||||
public boolean isVersionSupported(ProtocolVersion targetVersion) {
|
||||
return getClientVersion() == targetVersion || getClientVersion().getCompatibleVersions().contains(targetVersion);
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
package github.openautonomousconnection.protocol.side.server;
|
||||
|
||||
import github.openautonomousconnection.protocol.ProtocolBridge;
|
||||
import lombok.Getter;
|
||||
import me.finn.unlegitlibrary.network.system.server.NetworkServer;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ProtocolServer {
|
||||
@Getter
|
||||
private final NetworkServer networkServer;
|
||||
|
||||
@Getter
|
||||
private List<ConnectedProtocolClient> clients;
|
||||
|
||||
public ConnectedProtocolClient getClientByID(int clientID) {
|
||||
for (ConnectedProtocolClient client : clients) if (client.getConnectionHandler().getClientID() == clientID) return client;
|
||||
return null;
|
||||
}
|
||||
|
||||
public ProtocolServer(File caFolder, File certFile, File keyFile) {
|
||||
ProtocolBridge protocolBridge = ProtocolBridge.getInstance();
|
||||
this.clients = new ArrayList<>();
|
||||
|
||||
this.networkServer = new NetworkServer.ServerBuilder().setLogger(protocolBridge.getLogger()).
|
||||
setEventManager(protocolBridge.getProtocolSettings().eventManager).
|
||||
setPacketHandler(protocolBridge.getProtocolSettings().packetHandler).
|
||||
setPort(protocolBridge.getProtocolSettings().port).
|
||||
setRequireClientCertificate(false).setRootCAFolder(caFolder).setServerCertificate(certFile, keyFile).
|
||||
build();
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
package github.openautonomousconnection.protocol.side.server.events;
|
||||
|
||||
import github.openautonomousconnection.protocol.side.server.ConnectedProtocolClient;
|
||||
import lombok.Getter;
|
||||
import me.finn.unlegitlibrary.event.impl.Event;
|
||||
|
||||
public class ProtocolClientConnected extends Event {
|
||||
|
||||
@Getter
|
||||
private final ConnectedProtocolClient protocolClient;
|
||||
|
||||
public ProtocolClientConnected(ConnectedProtocolClient protocolClient) {
|
||||
this.protocolClient = protocolClient;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user