use of com.viaversion.fabric.common.platform.NativeVersionProvider in project ViaFabric by ViaVersion.
the class AbstractFabricPlatform method getDump.
@Override
public JsonObject getDump() {
JsonObject platformSpecific = new JsonObject();
JsonArray mods = new JsonArray();
FabricLoader.getInstance().getAllMods().stream().map((mod) -> {
JsonObject jsonMod = new JsonObject();
jsonMod.addProperty("id", mod.getMetadata().getId());
jsonMod.addProperty("name", mod.getMetadata().getName());
jsonMod.addProperty("version", mod.getMetadata().getVersion().getFriendlyString());
JsonArray authors = new JsonArray();
mod.getMetadata().getAuthors().stream().map(it -> {
JsonObject info = new JsonObject();
JsonObject contact = new JsonObject();
it.getContact().asMap().entrySet().forEach(c -> contact.addProperty(c.getKey(), c.getValue()));
if (contact.size() != 0) {
info.add("contact", contact);
}
info.addProperty("name", it.getName());
return info;
}).forEach(authors::add);
jsonMod.add("authors", authors);
return jsonMod;
}).forEach(mods::add);
platformSpecific.add("mods", mods);
NativeVersionProvider ver = Via.getManager().getProviders().get(NativeVersionProvider.class);
if (ver != null) {
platformSpecific.addProperty("native version", ver.getNativeServerVersion());
}
return platformSpecific;
}
use of com.viaversion.fabric.common.platform.NativeVersionProvider in project ViaFabric by ViaVersion.
the class AbstractFabricVersionProvider method getClosestServerProtocol.
@Override
public int getClosestServerProtocol(UserConnection connection) throws Exception {
if (connection.isClientSide()) {
ProtocolInfo info = Objects.requireNonNull(connection.getProtocolInfo());
if (!getConfig().isClientSideEnabled())
return info.getProtocolVersion();
int serverVer = getConfig().getClientSideVersion();
SocketAddress addr = connection.getChannel().remoteAddress();
if (addr instanceof InetSocketAddress) {
AddressParser parser = new AddressParser();
Integer addrVersion = parser.parse(((InetSocketAddress) addr).getHostName()).protocol;
if (addrVersion != null) {
serverVer = addrVersion;
}
try {
if (serverVer == -2) {
// Hope protocol was autodetected
ProtocolVersion autoVer = detectVersion((InetSocketAddress) addr).getNow(null);
if (autoVer != null) {
serverVer = autoVer.getVersion();
}
}
} catch (Exception e) {
getLogger().warning("Couldn't auto detect: " + e);
}
}
boolean blocked = checkAddressBlocked(addr);
boolean supported = ProtocolUtils.isSupported(serverVer, info.getProtocolVersion());
handleMulticonnectPing(connection, info, blocked, serverVer);
if (blocked || !supported)
serverVer = info.getProtocolVersion();
return serverVer;
}
NativeVersionProvider natProvider = Via.getManager().getProviders().get(NativeVersionProvider.class);
if (natProvider != null) {
return ProtocolVersion.getProtocol(natProvider.getNativeServerVersion()).getVersion();
}
return super.getClosestServerProtocol(connection);
}
Aggregations