Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 00:22:51 +01:00
Expand unsupported software checks
Dieser Commit ist enthalten in:
Ursprung
f17fb833a0
Commit
1538ff5201
@ -22,72 +22,26 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.api.platform;
|
package com.viaversion.viaversion.api.platform;
|
||||||
|
|
||||||
import java.util.Collections;
|
public interface UnsupportedSoftware {
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the software name.
|
* Returns the software name.
|
||||||
*
|
*
|
||||||
* @return software name
|
* @return software name
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the reason for being unsupported by Via.
|
* Returns the reason for being unsupported by Via.
|
||||||
*
|
*
|
||||||
* @return reason for being unsupported
|
* @return reason for being unsupported
|
||||||
*/
|
*/
|
||||||
public String getReason() {
|
String getReason();
|
||||||
return reason;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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() {
|
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.";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -199,5 +199,5 @@ public interface ProtocolManager {
|
|||||||
* @return new packet wrapper instance
|
* @return new packet wrapper instance
|
||||||
* @see PacketWrapper#create(PacketType, ByteBuf, UserConnection)
|
* @see PacketWrapper#create(PacketType, ByteBuf, UserConnection)
|
||||||
*/
|
*/
|
||||||
PacketWrapper createPacketWrapper(int packetId, ByteBuf buf, UserConnection connection);
|
PacketWrapper createPacketWrapper(int packetId, @Nullable ByteBuf buf, UserConnection connection);
|
||||||
}
|
}
|
||||||
|
@ -30,13 +30,14 @@ import com.viaversion.viaversion.bukkit.classgenerator.ClassGenerator;
|
|||||||
import com.viaversion.viaversion.bukkit.commands.BukkitCommandHandler;
|
import com.viaversion.viaversion.bukkit.commands.BukkitCommandHandler;
|
||||||
import com.viaversion.viaversion.bukkit.commands.BukkitCommandSender;
|
import com.viaversion.viaversion.bukkit.commands.BukkitCommandSender;
|
||||||
import com.viaversion.viaversion.bukkit.listeners.ProtocolLibEnableListener;
|
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.BukkitViaAPI;
|
||||||
import com.viaversion.viaversion.bukkit.platform.BukkitViaConfig;
|
import com.viaversion.viaversion.bukkit.platform.BukkitViaConfig;
|
||||||
import com.viaversion.viaversion.bukkit.platform.BukkitViaInjector;
|
import com.viaversion.viaversion.bukkit.platform.BukkitViaInjector;
|
||||||
import com.viaversion.viaversion.bukkit.platform.BukkitViaLoader;
|
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.bukkit.util.NMSUtil;
|
||||||
import com.viaversion.viaversion.dump.PluginInfo;
|
import com.viaversion.viaversion.dump.PluginInfo;
|
||||||
|
import com.viaversion.viaversion.unsupported.UnsupportedSoftwareImpl;
|
||||||
import com.viaversion.viaversion.util.GsonUtil;
|
import com.viaversion.viaversion.util.GsonUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -291,7 +292,11 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player>
|
|||||||
@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 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);
|
return Collections.unmodifiableList(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,7 +417,7 @@ public class ProtocolManagerImpl implements ProtocolManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
return new PacketWrapperImpl(packetId, buf, connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ import com.viaversion.viaversion.util.Pair;
|
|||||||
import com.viaversion.viaversion.util.PipelineUtil;
|
import com.viaversion.viaversion.util.PipelineUtil;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
@ -52,8 +53,8 @@ public class PacketWrapperImpl implements PacketWrapper {
|
|||||||
private final Deque<Pair<Type, Object>> readableObjects = new ArrayDeque<>();
|
private final Deque<Pair<Type, Object>> readableObjects = new ArrayDeque<>();
|
||||||
private final List<Pair<Type, Object>> packetValues = new ArrayList<>();
|
private final List<Pair<Type, Object>> packetValues = new ArrayList<>();
|
||||||
|
|
||||||
public PacketWrapperImpl(int packetID, ByteBuf inputBuffer, UserConnection userConnection) {
|
public PacketWrapperImpl(int packetId, @Nullable ByteBuf inputBuffer, UserConnection userConnection) {
|
||||||
this.id = packetID;
|
this.id = packetId;
|
||||||
this.inputBuffer = inputBuffer;
|
this.inputBuffer = inputBuffer;
|
||||||
this.userConnection = userConnection;
|
this.userConnection = userConnection;
|
||||||
}
|
}
|
||||||
@ -426,7 +427,8 @@ public class PacketWrapperImpl implements PacketWrapper {
|
|||||||
public void setId(int id) {
|
public void setId(int id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public ByteBuf getInputBuffer() {
|
public ByteBuf getInputBuffer() {
|
||||||
return inputBuffer;
|
return inputBuffer;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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.";
|
||||||
|
}
|
||||||
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren