Remove ncr warn (#206)

* Remove warning for NoChatReports, fix typo
The warning is due to an old vulnerability of NCR

* fix some space issue
This commit is contained in:
creeper123123321 2022-10-21 06:11:18 -03:00 committed by GitHub
parent 8e61509140
commit 7622f73a74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 154 additions and 154 deletions

4
.editorconfig Normal file
View File

@ -0,0 +1,4 @@
root = true
[*.java]
indent_style = space

View File

@ -38,187 +38,183 @@ import java.util.concurrent.TimeUnit;
import java.util.logging.Logger; import java.util.logging.Logger;
public abstract class AbstractFabricPlatform implements ViaPlatform<UUID> { public abstract class AbstractFabricPlatform implements ViaPlatform<UUID> {
private final Logger logger = new JLoggerToLog4j(LogManager.getLogger("ViaVersion")); private final Logger logger = new JLoggerToLog4j(LogManager.getLogger("ViaVersion"));
private FabricViaConfig config; private FabricViaConfig config;
private File dataFolder; private File dataFolder;
private final ViaAPI<UUID> api; private final ViaAPI<UUID> api;
{ {
api = new FabricViaAPI(); api = new FabricViaAPI();
} }
public void init() { public void init() {
// We'll use it early for ViaInjector // We'll use it early for ViaInjector
installNativeVersionProvider(); installNativeVersionProvider();
Path configDir = FabricLoader.getInstance().getConfigDir().resolve("ViaFabric"); Path configDir = FabricLoader.getInstance().getConfigDir().resolve("ViaFabric");
dataFolder = configDir.toFile(); dataFolder = configDir.toFile();
config = new FabricViaConfig(configDir.resolve("viaversion.yml").toFile()); config = new FabricViaConfig(configDir.resolve("viaversion.yml").toFile());
} }
protected abstract void installNativeVersionProvider(); protected abstract void installNativeVersionProvider();
protected abstract ExecutorService asyncService(); protected abstract ExecutorService asyncService();
protected abstract EventLoop eventLoop(); protected abstract EventLoop eventLoop();
protected FutureTaskId runEventLoop(Runnable runnable) { protected FutureTaskId runEventLoop(Runnable runnable) {
return new FutureTaskId(eventLoop().submit(runnable).addListener(errorLogger())); return new FutureTaskId(eventLoop().submit(runnable).addListener(errorLogger()));
} }
@Override @Override
public FutureTaskId runAsync(Runnable runnable) { public FutureTaskId runAsync(Runnable runnable) {
return new FutureTaskId(CompletableFuture.runAsync(runnable, asyncService()) return new FutureTaskId(CompletableFuture.runAsync(runnable, asyncService())
.exceptionally(throwable -> { .exceptionally(throwable -> {
if (!(throwable instanceof CancellationException)) { if (!(throwable instanceof CancellationException)) {
throwable.printStackTrace(); throwable.printStackTrace();
} }
return null; return null;
})); }));
} }
@Override @Override
public FutureTaskId runSync(Runnable runnable, long ticks) { public FutureTaskId runSync(Runnable runnable, long ticks) {
// ViaVersion seems to not need to run delayed tasks on main thread // ViaVersion seems to not need to run delayed tasks on main thread
return new FutureTaskId(eventLoop() return new FutureTaskId(eventLoop()
.schedule(() -> runSync(runnable), ticks * 50, TimeUnit.MILLISECONDS) .schedule(() -> runSync(runnable), ticks * 50, TimeUnit.MILLISECONDS)
.addListener(errorLogger()) .addListener(errorLogger())
); );
} }
@Override @Override
public FutureTaskId runRepeatingSync(Runnable runnable, long ticks) { public FutureTaskId runRepeatingSync(Runnable runnable, long ticks) {
// ViaVersion seems to not need to run repeating tasks on main thread // ViaVersion seems to not need to run repeating tasks on main thread
return new FutureTaskId(eventLoop() return new FutureTaskId(eventLoop()
.scheduleAtFixedRate(() -> runSync(runnable), 0, ticks * 50, TimeUnit.MILLISECONDS) .scheduleAtFixedRate(() -> runSync(runnable), 0, ticks * 50, TimeUnit.MILLISECONDS)
.addListener(errorLogger()) .addListener(errorLogger())
); );
} }
protected <T extends Future<?>> GenericFutureListener<T> errorLogger() { protected <T extends Future<?>> GenericFutureListener<T> errorLogger() {
return future -> { return future -> {
if (!future.isCancelled() && future.cause() != null) { if (!future.isCancelled() && future.cause() != null) {
future.cause().printStackTrace(); future.cause().printStackTrace();
} }
}; };
} }
@Override @Override
public boolean isProxy() { public boolean isProxy() {
// We kinda of have all server versions // We kinda of have all server versions
return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT; return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT;
} }
@Override @Override
public void onReload() { public void onReload() {
} }
@Override @Override
public Logger getLogger() { public Logger getLogger() {
return logger; return logger;
} }
@Override @Override
public ViaVersionConfig getConf() { public ViaVersionConfig getConf() {
return config; return config;
} }
@Override @Override
public ViaAPI<UUID> getApi() { public ViaAPI<UUID> getApi() {
return api; return api;
} }
@Override @Override
public File getDataFolder() { public File getDataFolder() {
return dataFolder; return dataFolder;
} }
@Override @Override
public String getPluginVersion() { public String getPluginVersion() {
return FabricLoader.getInstance().getModContainer("viaversion").map(ModContainer::getMetadata) return FabricLoader.getInstance().getModContainer("viaversion").map(ModContainer::getMetadata)
.map(ModMetadata::getVersion).map(Version::getFriendlyString).orElse("UNKNOWN"); .map(ModMetadata::getVersion).map(Version::getFriendlyString).orElse("UNKNOWN");
} }
@Override @Override
public String getPlatformName() { public String getPlatformName() {
return "ViaFabric"; return "ViaFabric";
} }
@Override @Override
public String getPlatformVersion() { public String getPlatformVersion() {
return FabricLoader.getInstance().getModContainer("viafabric") return FabricLoader.getInstance().getModContainer("viafabric")
.get().getMetadata().getVersion().getFriendlyString(); .get().getMetadata().getVersion().getFriendlyString();
} }
@Override @Override
public boolean isPluginEnabled() { public boolean isPluginEnabled() {
return true; return true;
} }
@Override @Override
public ConfigurationProvider getConfigurationProvider() { public ConfigurationProvider getConfigurationProvider() {
return config; return config;
} }
@Override @Override
public boolean isOldClientsAllowed() { public boolean isOldClientsAllowed() {
return true; return true;
} }
@Override @Override
public JsonObject getDump() { public JsonObject getDump() {
JsonObject platformSpecific = new JsonObject(); JsonObject platformSpecific = new JsonObject();
JsonArray mods = new JsonArray(); JsonArray mods = new JsonArray();
FabricLoader.getInstance().getAllMods().stream().map((mod) -> { FabricLoader.getInstance().getAllMods().stream().map((mod) -> {
JsonObject jsonMod = new JsonObject(); JsonObject jsonMod = new JsonObject();
jsonMod.addProperty("id", mod.getMetadata().getId()); jsonMod.addProperty("id", mod.getMetadata().getId());
jsonMod.addProperty("name", mod.getMetadata().getName()); jsonMod.addProperty("name", mod.getMetadata().getName());
jsonMod.addProperty("version", mod.getMetadata().getVersion().getFriendlyString()); jsonMod.addProperty("version", mod.getMetadata().getVersion().getFriendlyString());
JsonArray authors = new JsonArray(); JsonArray authors = new JsonArray();
mod.getMetadata().getAuthors().stream().map(it -> { mod.getMetadata().getAuthors().stream().map(it -> {
JsonObject info = new JsonObject(); JsonObject info = new JsonObject();
JsonObject contact = new JsonObject(); JsonObject contact = new JsonObject();
it.getContact().asMap().entrySet() it.getContact().asMap().entrySet()
.forEach(c -> contact.addProperty(c.getKey(), c.getValue())); .forEach(c -> contact.addProperty(c.getKey(), c.getValue()));
if (contact.size() != 0) { if (contact.size() != 0) {
info.add("contact", contact); info.add("contact", contact);
} }
info.addProperty("name", it.getName()); info.addProperty("name", it.getName());
return info; return info;
}).forEach(authors::add); }).forEach(authors::add);
jsonMod.add("authors", authors); jsonMod.add("authors", authors);
return jsonMod; return jsonMod;
}).forEach(mods::add); }).forEach(mods::add);
platformSpecific.add("mods", mods); platformSpecific.add("mods", mods);
NativeVersionProvider ver = Via.getManager().getProviders().get(NativeVersionProvider.class); NativeVersionProvider ver = Via.getManager().getProviders().get(NativeVersionProvider.class);
if (ver != null) { if (ver != null) {
platformSpecific.addProperty("native version", ver.getNativeServerVersion()); platformSpecific.addProperty("native version", ver.getNativeServerVersion());
} }
return platformSpecific; return platformSpecific;
} }
@Override @Override
public final Collection<UnsupportedSoftware> getUnsupportedSoftwareClasses() { public final Collection<UnsupportedSoftware> getUnsupportedSoftwareClasses() {
List<UnsupportedSoftware> list = new ArrayList<>(ViaPlatform.super.getUnsupportedSoftwareClasses()); List<UnsupportedSoftware> list = new ArrayList<>(ViaPlatform.super.getUnsupportedSoftwareClasses());
list.add(new UnsupportedPlugin.Builder().name("gaslight/guardian").reason(UnsupportedSoftwareReasons.SELF_INCRIMINATION) list.add(new UnsupportedPlugin.Builder().name("gaslight/guardian").reason(UnsupportedSoftwareReasons.SELF_INCRIMINATION)
.addPlugin("guardian").addPlugin("gaslight").build()); .addPlugin("guardian").addPlugin("gaslight").build());
list.add(new UnsupportedPlugin.Builder().name("NoChatReports").reason(UnsupportedSoftwareReasons.NCR) return Collections.unmodifiableList(list);
.addPlugin("nochatreports").build()); }
return Collections.unmodifiableList(list);
}
@Override @Override
public final boolean hasPlugin(String name) { public final boolean hasPlugin(String name) {
return FabricLoader.getInstance().isModLoaded(name); return FabricLoader.getInstance().isModLoaded(name);
} }
private static final class UnsupportedSoftwareReasons { private static final class UnsupportedSoftwareReasons {
private static final String SELF_INCRIMINATION = "By using these proof-of-concept TESTING mods, " +
private static final String SELF_INCRIMINATION = "By using these kind of mods, at best you create fishy context or silly reports, " + "at best you create fishy context or silly reports, " +
"at worst you end up incrimating yourself when writing messages or reporting another player."; "at worst you end up incriminating yourself when writing messages or reporting another player.";
private static final String NCR = "Due to a history of breaking message formatting and creating other issues related to chat handling " + }
"(some still present), we suggest you find alternatives to this mod.";
}
} }