use of com.github.dirtpowered.dirtmv.network.versions.ProtocolStateHandler in project DirtMultiversion by DirtPowered.
the class TranslatorRegistry method findProtocol.
/**
* Returns all protocols translators between client and server version
*
* @param data User data
* @param versionTo Server version
* @return {@link List<ServerProtocol> List} with ordered protocol pipeline classes
*/
public List<ServerProtocol> findProtocol(UserData data, MinecraftVersion versionTo) {
List<ServerProtocol> serverProtocols = new LinkedList<>();
MinecraftVersion from = data.getClientVersion();
Configuration c = main.getConfiguration();
GlobalProtocolHandler globalProtocolHandler = new GlobalProtocolHandler(from, versionTo);
// check if translating is needed
if (from == c.getServerVersion()) {
ServerProtocol serverProtocol;
// starting from r1.3 the whole connections is encrypted
if (from.getRegistryId() >= MinecraftVersion.R1_3_1.getRegistryId() && !from.isNettyProtocol()) {
serverProtocol = new ProtocolPassthroughEncrypted(from, versionTo);
} else if (from.isNettyProtocol()) {
serverProtocol = new ProtocolStateHandler(from, versionTo);
} else {
serverProtocol = new ProtocolPassthrough(from, versionTo);
}
return Arrays.asList(serverProtocol, globalProtocolHandler);
} else {
if (from.getRegistryId() < 39) {
serverProtocols.add(new ProtocolPassthrough(from, versionTo));
}
if ((from.getRegistryId() >= 39 && c.getServerVersion().getRegistryId() >= 39) && !from.isNettyProtocol()) {
// add encryption translators to pipeline
serverProtocols.add(new ProtocolPassthroughEncrypted(from, versionTo));
}
}
int clientProtocol = from.getRegistryId();
int serverProtocol = versionTo.getRegistryId();
for (int i = serverProtocol; i <= clientProtocol; i++) {
if (MinecraftVersion.fromRegistryId(i) != null) {
ServerProtocol target = protocols.get(i);
if (target != null && !(i <= serverProtocol)) {
serverProtocols.add(target);
}
}
}
if (from.isNettyProtocol()) {
serverProtocols.add(new ProtocolStateHandler(from, versionTo));
}
// track packets in all protocols
serverProtocols.add(globalProtocolHandler);
return serverProtocols;
}
Aggregations