3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-08 17:20:24 +01:00

Merge pull request #1186 from creeper123123321/tabdelay

Tab delaying
Dieser Commit ist enthalten in:
Myles 2019-02-10 16:42:05 +00:00 committet von GitHub
Commit f1743e5912
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
9 geänderte Dateien mit 78 neuen und 15 gelöschten Zeilen

Datei anzeigen

@ -244,4 +244,9 @@ public class BukkitViaConfig extends Config implements ViaVersionConfig {
public boolean isSnowCollisionFix() { public boolean isSnowCollisionFix() {
return getBoolean("fix-low-snow-collision", false); return getBoolean("fix-low-snow-collision", false);
} }
@Override
public int get1_13TabCompleteDelay() {
return getInt("1_13-tab-complete-delay", 0);
}
} }

Datei anzeigen

@ -297,4 +297,9 @@ public class BungeeViaConfig extends Config implements ViaVersionConfig {
public boolean isSnowCollisionFix() { public boolean isSnowCollisionFix() {
return getBoolean("fix-low-snow-collision", false); return getBoolean("fix-low-snow-collision", false);
} }
@Override
public int get1_13TabCompleteDelay() {
return getInt("1_13-tab-complete-delay", 0);
}
} }

Datei anzeigen

@ -302,4 +302,10 @@ public interface ViaVersionConfig {
* @return True if enabled * @return True if enabled
*/ */
boolean isSnowCollisionFix(); boolean isSnowCollisionFix();
/**
* When greater than 0, enables tab complete request delaying by x ticks
* @return the delay in ticks
*/
int get1_13TabCompleteDelay();
} }

Datei anzeigen

@ -851,9 +851,15 @@ public class Protocol1_13To1_12_2 extends Protocol {
// Fake the end of the packet // Fake the end of the packet
create(new ValueCreator() { create(new ValueCreator() {
@Override @Override
public void write(PacketWrapper wrapper) { public void write(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.BOOLEAN, false); wrapper.write(Type.BOOLEAN, false);
wrapper.write(Type.OPTIONAL_POSITION, null); wrapper.write(Type.OPTIONAL_POSITION, null);
if (!wrapper.isCancelled() && Via.getConfig().get1_13TabCompleteDelay() > 0) {
TabCompleteTracker tracker = wrapper.user().get(TabCompleteTracker.class);
wrapper.cancel();
tracker.setTimeToSend(System.currentTimeMillis() + Via.getConfig().get1_13TabCompleteDelay() * 50);
tracker.setLastTabComplete(wrapper.get(Type.STRING, 0));
}
} }
}); });
} }
@ -1139,6 +1145,9 @@ public class Protocol1_13To1_12_2 extends Protocol {
userConnection.put(new BlockConnectionStorage(userConnection)); userConnection.put(new BlockConnectionStorage(userConnection));
} }
} }
if (Via.getConfig().get1_13TabCompleteDelay() > 0) {
Via.getPlatform().runRepeatingSync(new TabCompleteThread(), 1L);
}
} }
@Override @Override

Datei anzeigen

@ -0,0 +1,19 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.TabCompleteTracker;
public class TabCompleteThread implements Runnable {
@Override
public void run() {
for (UserConnection info : Via.getManager().getPortedPlayers().values()) {
if (info.has(ProtocolInfo.class) && info.get(ProtocolInfo.class).getPipeline().contains(Protocol1_13To1_12_2.class)) {
if (info.getChannel().isOpen()) {
info.get(TabCompleteTracker.class).sendPacketToServer();
}
}
}
}
}

Datei anzeigen

@ -1,29 +1,36 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage; package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage;
import lombok.Getter;
import lombok.Setter;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
@Getter
@Setter
public class TabCompleteTracker extends StoredObject { public class TabCompleteTracker extends StoredObject {
private int transactionId; private int transactionId;
private String input; private String input;
private String lastTabComplete;
private long timeToSend;
public TabCompleteTracker(UserConnection user) { public TabCompleteTracker(UserConnection user) {
super(user); super(user);
} }
public int getTransactionId() { public void sendPacketToServer() {
return transactionId; if (lastTabComplete == null || timeToSend > System.currentTimeMillis()) return;
PacketWrapper wrapper = new PacketWrapper(0x01, null, getUser());
wrapper.write(Type.STRING, lastTabComplete);
wrapper.write(Type.BOOLEAN, false);
wrapper.write(Type.OPTIONAL_POSITION, null);
try {
wrapper.sendToServer(Protocol1_13To1_12_2.class);
} catch (Exception e) {
e.printStackTrace();
} }
lastTabComplete = null;
public void setTransactionId(int transactionId) {
this.transactionId = transactionId;
}
public String getInput() {
return input;
}
public void setInput(String input) {
this.input = input;
} }
} }

Datei anzeigen

@ -114,6 +114,8 @@ team-colour-fix: true
suppress-1_13-conversion-errors: false suppress-1_13-conversion-errors: false
# 1.13 introduced new auto complete which can trigger "Kicked for spamming" for servers older than 1.13, the following option will disable it completely. # 1.13 introduced new auto complete which can trigger "Kicked for spamming" for servers older than 1.13, the following option will disable it completely.
disable-1_13-auto-complete: false disable-1_13-auto-complete: false
# The following option will delay the tab complete request in x ticks if greater than 0, if other tab-complete is received, the previous is cancelled
1_13-tab-complete-delay: 0
# For 1.13 clients the smallest (1 layer) snow doesn't have collision, this will send these as 2 snowlayers for 1.13+ clients to prevent them bugging through them # For 1.13 clients the smallest (1 layer) snow doesn't have collision, this will send these as 2 snowlayers for 1.13+ clients to prevent them bugging through them
fix-low-snow-collision: false fix-low-snow-collision: false
# #

Datei anzeigen

@ -250,4 +250,9 @@ public class SpongeViaConfig extends Config implements ViaVersionConfig {
public boolean isSnowCollisionFix() { public boolean isSnowCollisionFix() {
return getBoolean("fix-low-snow-collision", false); return getBoolean("fix-low-snow-collision", false);
} }
@Override
public int get1_13TabCompleteDelay() {
return getInt("1_13-tab-complete-delay", 0);
}
} }

Datei anzeigen

@ -302,4 +302,9 @@ public class VelocityViaConfig extends Config implements ViaVersionConfig {
public boolean isSnowCollisionFix() { public boolean isSnowCollisionFix() {
return getBoolean("fix-low-snow-collision", false); return getBoolean("fix-low-snow-collision", false);
} }
@Override
public int get1_13TabCompleteDelay() {
return getInt("1_13-tab-complete-delay", 0);
}
} }