3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-04 23:30:24 +01:00

Expand unsupported software checks

Dieser Commit ist enthalten in:
KennyTV 2021-05-14 16:59:12 +02:00
Ursprung f17fb833a0
Commit 1538ff5201
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
7 geänderte Dateien mit 182 neuen und 59 gelöschten Zeilen

Datei anzeigen

@ -22,72 +22,26 @@
*/
package com.viaversion.viaversion.api.platform;
import java.util.Collections;
import java.util.List;
public final class UnsupportedSoftware {
private final String name;
private final List<String> classNames;
private final String reason;
public UnsupportedSoftware(String name, List<String> classNames, String reason) {
this.name = name;
this.classNames = Collections.unmodifiableList(classNames);
this.reason = reason;
}
public UnsupportedSoftware(String name, String className, String reason) {
this.name = name;
this.classNames = Collections.singletonList(className);
this.reason = reason;
}
public interface UnsupportedSoftware {
/**
* Returns the software name.
*
* @return software name
*/
public String getName() {
return name;
}
/**
* Returns an immutable list of the fully qualified class name.
*
* @return immutable list of fully qualified class name
*/
public List<String> getClassNames() {
return classNames;
}
String getName();
/**
* Returns the reason for being unsupported by Via.
*
* @return reason for being unsupported
*/
public String getReason() {
return reason;
}
String getReason();
/**
* Returns whether at least one of the held class names exists.
* Returns whether the unsupported software is present.
*
* @return true if at least one of the classes exists
* @return true if the unsupported software is found
*/
public boolean findMatch() {
for (String className : classNames) {
try {
Class.forName(className);
return true;
} catch (ClassNotFoundException ignored) {
}
}
return false;
}
public static final class Reason {
public static final String DANGEROUS_SERVER_SOFTWARE = "You are using server software that - outside of possibly breaking ViaVersion - can also cause severe damage to your server's integrity as a whole.";
}
boolean findMatch();
}

Datei anzeigen

@ -199,5 +199,5 @@ public interface ProtocolManager {
* @return new packet wrapper instance
* @see PacketWrapper#create(PacketType, ByteBuf, UserConnection)
*/
PacketWrapper createPacketWrapper(int packetId, ByteBuf buf, UserConnection connection);
PacketWrapper createPacketWrapper(int packetId, @Nullable ByteBuf buf, UserConnection connection);
}

Datei anzeigen

@ -30,13 +30,14 @@ import com.viaversion.viaversion.bukkit.classgenerator.ClassGenerator;
import com.viaversion.viaversion.bukkit.commands.BukkitCommandHandler;
import com.viaversion.viaversion.bukkit.commands.BukkitCommandSender;
import com.viaversion.viaversion.bukkit.listeners.ProtocolLibEnableListener;
import com.viaversion.viaversion.bukkit.platform.BukkitViaTask;
import com.viaversion.viaversion.bukkit.platform.BukkitViaAPI;
import com.viaversion.viaversion.bukkit.platform.BukkitViaConfig;
import com.viaversion.viaversion.bukkit.platform.BukkitViaInjector;
import com.viaversion.viaversion.bukkit.platform.BukkitViaLoader;
import com.viaversion.viaversion.bukkit.platform.BukkitViaTask;
import com.viaversion.viaversion.bukkit.util.NMSUtil;
import com.viaversion.viaversion.dump.PluginInfo;
import com.viaversion.viaversion.unsupported.UnsupportedSoftwareImpl;
import com.viaversion.viaversion.util.GsonUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -291,7 +292,11 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player>
@Override
public final Collection<UnsupportedSoftware> getUnsupportedSoftwareClasses() {
List<UnsupportedSoftware> list = new ArrayList<>(ViaPlatform.super.getUnsupportedSoftwareClasses());
list.add(new UnsupportedSoftware("Yatopia", "org.yatopiamc.yatopia.server.YatopiaConfig", UnsupportedSoftware.Reason.DANGEROUS_SERVER_SOFTWARE));
list.add(new UnsupportedSoftwareImpl.Builder().name("Yatopia").reason(UnsupportedSoftwareImpl.Reason.DANGEROUS_SERVER_SOFTWARE)
.addClassName("org.yatopiamc.yatopia.server.YatopiaConfig")
.addClassName("net.yatopia.api.event.PlayerAttackEntityEvent")
.addClassName("yatopiamc.org.yatopia.server.YatopiaConfig") // Only the best kind of software relocates its own classes to hide itself :tinfoilhat:
.addMethod("org.bukkit.Server", "getLastTickTime").build());
return Collections.unmodifiableList(list);
}

Datei anzeigen

@ -417,7 +417,7 @@ public class ProtocolManagerImpl implements ProtocolManager {
}
@Override
public PacketWrapper createPacketWrapper(int packetId, ByteBuf buf, UserConnection connection) {
public PacketWrapper createPacketWrapper(int packetId, @Nullable ByteBuf buf, UserConnection connection) {
return new PacketWrapperImpl(packetId, buf, connection);
}

Datei anzeigen

@ -34,6 +34,7 @@ import com.viaversion.viaversion.util.Pair;
import com.viaversion.viaversion.util.PipelineUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelFuture;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
import java.util.ArrayDeque;
@ -52,8 +53,8 @@ public class PacketWrapperImpl implements PacketWrapper {
private final Deque<Pair<Type, Object>> readableObjects = new ArrayDeque<>();
private final List<Pair<Type, Object>> packetValues = new ArrayList<>();
public PacketWrapperImpl(int packetID, ByteBuf inputBuffer, UserConnection userConnection) {
this.id = packetID;
public PacketWrapperImpl(int packetId, @Nullable ByteBuf inputBuffer, UserConnection userConnection) {
this.id = packetId;
this.inputBuffer = inputBuffer;
this.userConnection = userConnection;
}
@ -426,7 +427,8 @@ public class PacketWrapperImpl implements PacketWrapper {
public void setId(int id) {
this.id = id;
}
@Nullable
public ByteBuf getInputBuffer() {
return inputBuffer;
}

Datei anzeigen

@ -0,0 +1,49 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.unsupported;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.Set;
public final class UnsupportedMethods {
private final String className;
private final Set<String> methodNames;
public UnsupportedMethods(String className, Set<String> methodNames) {
this.className = className;
this.methodNames = Collections.unmodifiableSet(methodNames);
}
public String getClassName() {
return className;
}
public final boolean findMatch() {
try {
for (Method method : Class.forName(className).getDeclaredMethods()) {
if (methodNames.contains(method.getName())) {
return true;
}
}
} catch (ClassNotFoundException ignored) {
}
return false;
}
}

Datei anzeigen

@ -0,0 +1,113 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.unsupported;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.platform.UnsupportedSoftware;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
public final class UnsupportedSoftwareImpl implements UnsupportedSoftware {
private final String name;
private final List<String> classNames;
private final List<UnsupportedMethods> methods;
private final String reason;
public UnsupportedSoftwareImpl(String name, List<String> classNames, List<UnsupportedMethods> methods, String reason) {
this.name = name;
this.classNames = Collections.unmodifiableList(classNames);
this.methods = Collections.unmodifiableList(methods);
this.reason = reason;
}
@Override
public String getName() {
return name;
}
@Override
public String getReason() {
return reason;
}
@Override
public boolean findMatch() {
for (String className : classNames) {
try {
Class.forName(className);
return true;
} catch (ClassNotFoundException ignored) {
}
}
for (UnsupportedMethods method : methods) {
if (method.findMatch()) {
return true;
}
}
return false;
}
public static final class Builder {
private final List<String> classNames = new ArrayList<>();
private final List<UnsupportedMethods> methods = new ArrayList<>();
private String name;
private String reason;
public Builder name(String name) {
this.name = name;
return this;
}
public Builder reason(String reason) {
this.reason = reason;
return this;
}
public Builder addMethod(String className, String methodName) {
methods.add(new UnsupportedMethods(className, Collections.singleton(methodName)));
return this;
}
public Builder addMethods(String className, String... methodNames) {
methods.add(new UnsupportedMethods(className, new HashSet<>(Arrays.asList(methodNames))));
return this;
}
public Builder addClassName(String className) {
classNames.add(className);
return this;
}
public UnsupportedSoftware build() {
Preconditions.checkNotNull(name);
Preconditions.checkNotNull(reason);
return new UnsupportedSoftwareImpl(name, classNames, methods, reason);
}
}
public static final class Reason {
public static final String DANGEROUS_SERVER_SOFTWARE = "You are using server software that - outside of possibly breaking ViaVersion - can also cause severe damage to your server's integrity as a whole.";
}
}