3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00

try to fix GoLilyPad servers (#2667)

Closes ViaVersion/ViaFabric#21
Dieser Commit ist enthalten in:
creeper123123321 2021-08-25 09:55:43 -03:00 committet von GitHub
Ursprung 47af0d634f
Commit 257eea5b04
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
3 geänderte Dateien mit 360 neuen und 252 gelöschten Zeilen

Datei anzeigen

@ -38,12 +38,7 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.packets.InventoryPac
import com.viaversion.viaversion.protocols.protocol1_9to1_8.packets.PlayerPackets; import com.viaversion.viaversion.protocols.protocol1_9to1_8.packets.PlayerPackets;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.packets.SpawnPackets; import com.viaversion.viaversion.protocols.protocol1_9to1_8.packets.SpawnPackets;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.packets.WorldPackets; import com.viaversion.viaversion.protocols.protocol1_9to1_8.packets.WorldPackets;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.BossBarProvider; import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.*;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.CommandBlockProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.EntityIdProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MainHandProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.ClientChunks; import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.ClientChunks;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.CommandBlockStorage; import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.CommandBlockStorage;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9; import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
@ -141,6 +136,7 @@ public class Protocol1_9To1_8 extends AbstractProtocol<ClientboundPackets1_8, Cl
providers.register(EntityIdProvider.class, new EntityIdProvider()); providers.register(EntityIdProvider.class, new EntityIdProvider());
providers.register(BossBarProvider.class, new BossBarProvider()); providers.register(BossBarProvider.class, new BossBarProvider());
providers.register(MainHandProvider.class, new MainHandProvider()); providers.register(MainHandProvider.class, new MainHandProvider());
providers.register(CompressionProvider.class, new CompressionProvider());
providers.require(MovementTransmitterProvider.class); providers.require(MovementTransmitterProvider.class);
} }

Datei anzeigen

@ -33,6 +33,7 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.ServerboundPackets1_
import com.viaversion.viaversion.protocols.protocol1_9to1_8.chat.ChatRewriter; import com.viaversion.viaversion.protocols.protocol1_9to1_8.chat.ChatRewriter;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.chat.GameMode; import com.viaversion.viaversion.protocols.protocol1_9to1_8.chat.GameMode;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.CommandBlockProvider; import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.CommandBlockProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.CompressionProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MainHandProvider; import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MainHandProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.ClientChunks; import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.ClientChunks;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9; import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
@ -45,15 +46,12 @@ public class PlayerPackets {
map(Type.STRING, Protocol1_9To1_8.FIX_JSON); // 0 - Chat Message (json) map(Type.STRING, Protocol1_9To1_8.FIX_JSON); // 0 - Chat Message (json)
map(Type.BYTE); // 1 - Chat Positon map(Type.BYTE); // 1 - Chat Positon
handler(new PacketHandler() { handler(wrapper -> {
@Override try {
public void handle(PacketWrapper wrapper) throws Exception { JsonObject obj = (JsonObject) wrapper.get(Type.COMPONENT, 0);
try { ChatRewriter.toClient(obj, wrapper.user());
JsonObject obj = (JsonObject) wrapper.get(Type.COMPONENT, 0); } catch (Exception e) {
ChatRewriter.toClient(obj, wrapper.user()); e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
} }
}); });
} }
@ -79,13 +77,10 @@ public class PlayerPackets {
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); // 0 - Action map(Type.VAR_INT); // 0 - Action
// We only handle if the title or subtitle is set then just write through. // We only handle if the title or subtitle is set then just write through.
handler(new PacketHandler() { handler(wrapper -> {
@Override int action = wrapper.get(Type.VAR_INT, 0);
public void handle(PacketWrapper wrapper) throws Exception { if (action == 0 || action == 1) {
int action = wrapper.get(Type.VAR_INT, 0); Protocol1_9To1_8.FIX_JSON.write(wrapper, wrapper.read(Type.STRING));
if (action == 0 || action == 1) {
Protocol1_9To1_8.FIX_JSON.write(wrapper, wrapper.read(Type.STRING));
}
} }
}); });
// Everything else is handled. // Everything else is handled.
@ -104,11 +99,8 @@ public class PlayerPackets {
map(Type.BYTE); // 5 - Player Flags map(Type.BYTE); // 5 - Player Flags
handler(new PacketHandler() { handler(wrapper -> {
@Override wrapper.write(Type.VAR_INT, 0); // 6 - Teleport ID was added
public void handle(PacketWrapper wrapper) {
wrapper.write(Type.VAR_INT, 0); // 6 - Teleport ID was added
}
}); });
} }
}); });
@ -118,59 +110,56 @@ public class PlayerPackets {
public void registerMap() { public void registerMap() {
map(Type.STRING); // 0 - Team Name map(Type.STRING); // 0 - Team Name
map(Type.BYTE); // 1 - Mode map(Type.BYTE); // 1 - Mode
handler(new PacketHandler() { handler(wrapper -> {
@Override byte mode = wrapper.get(Type.BYTE, 0); // Mode
public void handle(PacketWrapper wrapper) throws Exception { if (mode == 0 || mode == 2) {
byte mode = wrapper.get(Type.BYTE, 0); // Mode wrapper.passthrough(Type.STRING); // Display Name
if (mode == 0 || mode == 2) { wrapper.passthrough(Type.STRING); // Prefix
wrapper.passthrough(Type.STRING); // Display Name wrapper.passthrough(Type.STRING); // Suffix
wrapper.passthrough(Type.STRING); // Prefix
wrapper.passthrough(Type.STRING); // Suffix
wrapper.passthrough(Type.BYTE); // Friendly Fire wrapper.passthrough(Type.BYTE); // Friendly Fire
wrapper.passthrough(Type.STRING); // Name tag visibility wrapper.passthrough(Type.STRING); // Name tag visibility
wrapper.write(Type.STRING, Via.getConfig().isPreventCollision() ? "never" : ""); wrapper.write(Type.STRING, Via.getConfig().isPreventCollision() ? "never" : "");
wrapper.passthrough(Type.BYTE); // Colour wrapper.passthrough(Type.BYTE); // Colour
} }
if (mode == 0 || mode == 3 || mode == 4) { if (mode == 0 || mode == 3 || mode == 4) {
String[] players = wrapper.passthrough(Type.STRING_ARRAY); // Players String[] players = wrapper.passthrough(Type.STRING_ARRAY); // Players
final EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class); final EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
String myName = wrapper.user().getProtocolInfo().getUsername(); String myName = wrapper.user().getProtocolInfo().getUsername();
String teamName = wrapper.get(Type.STRING, 0); String teamName = wrapper.get(Type.STRING, 0);
for (String player : players) { for (String player : players) {
if (entityTracker.isAutoTeam() && player.equalsIgnoreCase(myName)) { if (entityTracker.isAutoTeam() && player.equalsIgnoreCase(myName)) {
if (mode == 4) { if (mode == 4) {
// since removing add to auto team // since removing add to auto team
// Workaround for packet order issue // Workaround for packet order issue
wrapper.send(Protocol1_9To1_8.class); wrapper.send(Protocol1_9To1_8.class);
wrapper.cancel(); wrapper.cancel();
entityTracker.sendTeamPacket(true, true); entityTracker.sendTeamPacket(true, true);
entityTracker.setCurrentTeam("viaversion"); entityTracker.setCurrentTeam("viaversion");
} else { } else {
// since adding remove from auto team // since adding remove from auto team
entityTracker.sendTeamPacket(false, true); entityTracker.sendTeamPacket(false, true);
entityTracker.setCurrentTeam(teamName); entityTracker.setCurrentTeam(teamName);
}
} }
} }
} }
}
if (mode == 1) { // Remove team if (mode == 1) { // Remove team
final EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class); final EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
String teamName = wrapper.get(Type.STRING, 0); String teamName = wrapper.get(Type.STRING, 0);
if (entityTracker.isAutoTeam() if (entityTracker.isAutoTeam()
&& teamName.equals(entityTracker.getCurrentTeam())) { && teamName.equals(entityTracker.getCurrentTeam())) {
// team was removed // team was removed
// Workaround for packet order issue // Workaround for packet order issue
wrapper.send(Protocol1_9To1_8.class); wrapper.send(Protocol1_9To1_8.class);
wrapper.cancel(); wrapper.cancel();
entityTracker.sendTeamPacket(true, true); entityTracker.sendTeamPacket(true, true);
entityTracker.setCurrentTeam("viaversion"); entityTracker.setCurrentTeam("viaversion");
}
} }
} }
}); });
@ -182,14 +171,11 @@ public class PlayerPackets {
public void registerMap() { public void registerMap() {
map(Type.INT); // 0 - Player ID map(Type.INT); // 0 - Player ID
// Parse this info // Parse this info
handler(new PacketHandler() { handler(wrapper -> {
@Override int entityId = wrapper.get(Type.INT, 0);
public void handle(PacketWrapper wrapper) throws Exception { EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
int entityId = wrapper.get(Type.INT, 0); tracker.addEntity(entityId, Entity1_10Types.EntityType.PLAYER);
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class); tracker.setClientEntityId(entityId);
tracker.addEntity(entityId, Entity1_10Types.EntityType.PLAYER);
tracker.setClientEntityId(entityId);
}
}); });
map(Type.UNSIGNED_BYTE); // 1 - Player Gamemode map(Type.UNSIGNED_BYTE); // 1 - Player Gamemode
map(Type.BYTE); // 2 - Player Dimension map(Type.BYTE); // 2 - Player Dimension
@ -198,39 +184,30 @@ public class PlayerPackets {
map(Type.STRING); // 5 - Level Type map(Type.STRING); // 5 - Level Type
map(Type.BOOLEAN); // 6 - Reduced Debug info map(Type.BOOLEAN); // 6 - Reduced Debug info
handler(new PacketHandler() { handler(wrapper -> {
@Override EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
public void handle(PacketWrapper wrapper) throws Exception { tracker.setGameMode(GameMode.getById(wrapper.get(Type.UNSIGNED_BYTE, 0))); //Set player gamemode
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
tracker.setGameMode(GameMode.getById(wrapper.get(Type.UNSIGNED_BYTE, 0))); //Set player gamemode
}
}); });
// Gotta fake their op // Gotta fake their op
handler(new PacketHandler() { handler(wrapper -> {
@Override CommandBlockProvider provider = Via.getManager().getProviders().get(CommandBlockProvider.class);
public void handle(PacketWrapper wrapper) throws Exception { provider.sendPermission(wrapper.user());
CommandBlockProvider provider = Via.getManager().getProviders().get(CommandBlockProvider.class); }
provider.sendPermission(wrapper.user());
}
}
); );
// Scoreboard will be cleared when join game is received // Scoreboard will be cleared when join game is received
handler(new PacketHandler() { handler(wrapper -> {
@Override EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
public void handle(PacketWrapper wrapper) throws Exception { if (Via.getConfig().isAutoTeam()) {
EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class); entityTracker.setAutoTeam(true);
if (Via.getConfig().isAutoTeam()) { // Workaround for packet order issue
entityTracker.setAutoTeam(true); wrapper.send(Protocol1_9To1_8.class);
// Workaround for packet order issue wrapper.cancel();
wrapper.send(Protocol1_9To1_8.class); entityTracker.sendTeamPacket(true, true);
wrapper.cancel(); entityTracker.setCurrentTeam("viaversion");
entityTracker.sendTeamPacket(true, true); } else {
entityTracker.setCurrentTeam("viaversion"); entityTracker.setAutoTeam(false);
} else {
entityTracker.setAutoTeam(false);
}
} }
}); });
} }
@ -243,45 +220,41 @@ public class PlayerPackets {
map(Type.VAR_INT); // 1 - Player Count map(Type.VAR_INT); // 1 - Player Count
// Due to this being a complex data structure we just use a handler. // Due to this being a complex data structure we just use a handler.
handler(new PacketHandler() { handler(wrapper -> {
int action = wrapper.get(Type.VAR_INT, 0);
int count = wrapper.get(Type.VAR_INT, 1);
for (int i = 0; i < count; i++) {
wrapper.passthrough(Type.UUID); // Player UUID
if (action == 0) { // add player
wrapper.passthrough(Type.STRING); // Player Name
@Override int properties = wrapper.passthrough(Type.VAR_INT);
public void handle(PacketWrapper wrapper) throws Exception {
int action = wrapper.get(Type.VAR_INT, 0);
int count = wrapper.get(Type.VAR_INT, 1);
for (int i = 0; i < count; i++) {
wrapper.passthrough(Type.UUID); // Player UUID
if (action == 0) { // add player
wrapper.passthrough(Type.STRING); // Player Name
int properties = wrapper.passthrough(Type.VAR_INT); // loop through properties
for (int j = 0; j < properties; j++) {
// loop through properties wrapper.passthrough(Type.STRING); // name
for (int j = 0; j < properties; j++) { wrapper.passthrough(Type.STRING); // value
wrapper.passthrough(Type.STRING); // name boolean isSigned = wrapper.passthrough(Type.BOOLEAN);
wrapper.passthrough(Type.STRING); // value if (isSigned) {
boolean isSigned = wrapper.passthrough(Type.BOOLEAN); wrapper.passthrough(Type.STRING); // signature
if (isSigned) {
wrapper.passthrough(Type.STRING); // signature
}
} }
wrapper.passthrough(Type.VAR_INT); // gamemode
wrapper.passthrough(Type.VAR_INT); // ping
boolean hasDisplayName = wrapper.passthrough(Type.BOOLEAN);
if (hasDisplayName) {
Protocol1_9To1_8.FIX_JSON.write(wrapper, wrapper.read(Type.STRING)); // display name
}
} else if ((action == 1) || (action == 2)) { // update gamemode || update latency
wrapper.passthrough(Type.VAR_INT);
} else if (action == 3) { // update display name
boolean hasDisplayName = wrapper.passthrough(Type.BOOLEAN);
if (hasDisplayName) {
Protocol1_9To1_8.FIX_JSON.write(wrapper, wrapper.read(Type.STRING)); // display name
}
} else if (action == 4) { // remove player
// no fields
} }
wrapper.passthrough(Type.VAR_INT); // gamemode
wrapper.passthrough(Type.VAR_INT); // ping
boolean hasDisplayName = wrapper.passthrough(Type.BOOLEAN);
if (hasDisplayName) {
Protocol1_9To1_8.FIX_JSON.write(wrapper, wrapper.read(Type.STRING)); // display name
}
} else if ((action == 1) || (action == 2)) { // update gamemode || update latency
wrapper.passthrough(Type.VAR_INT);
} else if (action == 3) { // update display name
boolean hasDisplayName = wrapper.passthrough(Type.BOOLEAN);
if (hasDisplayName) {
Protocol1_9To1_8.FIX_JSON.write(wrapper, wrapper.read(Type.STRING)); // display name
}
} else if (action == 4) { // remove player
// no fields
} }
} }
}); });
@ -292,38 +265,35 @@ public class PlayerPackets {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.STRING); // 0 - Channel Name map(Type.STRING); // 0 - Channel Name
handler(new PacketHandler() { handler(wrapper -> {
@Override String name = wrapper.get(Type.STRING, 0);
public void handle(PacketWrapper wrapper) throws Exception { if (name.equalsIgnoreCase("MC|BOpen")) {
String name = wrapper.get(Type.STRING, 0); wrapper.read(Type.REMAINING_BYTES); // Not used anymore
if (name.equalsIgnoreCase("MC|BOpen")) { wrapper.write(Type.VAR_INT, 0);
wrapper.read(Type.REMAINING_BYTES); // Not used anymore }
wrapper.write(Type.VAR_INT, 0); if (name.equalsIgnoreCase("MC|TrList")) {
} wrapper.passthrough(Type.INT); // ID
if (name.equalsIgnoreCase("MC|TrList")) {
wrapper.passthrough(Type.INT); // ID
Short size = wrapper.passthrough(Type.UNSIGNED_BYTE); Short size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; ++i) { for (int i = 0; i < size; ++i) {
Item item1 = wrapper.passthrough(Type.ITEM); Item item1 = wrapper.passthrough(Type.ITEM);
ItemRewriter.toClient(item1); ItemRewriter.toClient(item1);
Item item2 = wrapper.passthrough(Type.ITEM); Item item2 = wrapper.passthrough(Type.ITEM);
ItemRewriter.toClient(item2); ItemRewriter.toClient(item2);
boolean present = wrapper.passthrough(Type.BOOLEAN); boolean present = wrapper.passthrough(Type.BOOLEAN);
if (present) { if (present) {
Item item3 = wrapper.passthrough(Type.ITEM); Item item3 = wrapper.passthrough(Type.ITEM);
ItemRewriter.toClient(item3); ItemRewriter.toClient(item3);
}
wrapper.passthrough(Type.BOOLEAN);
wrapper.passthrough(Type.INT);
wrapper.passthrough(Type.INT);
} }
wrapper.passthrough(Type.BOOLEAN);
wrapper.passthrough(Type.INT);
wrapper.passthrough(Type.INT);
} }
} }
}); });
@ -334,16 +304,13 @@ public class PlayerPackets {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.FLOAT); // 0 - Health map(Type.FLOAT); // 0 - Health
handler(new PacketHandler() { handler(wrapper -> {
@Override float health = wrapper.get(Type.FLOAT, 0);
public void handle(PacketWrapper wrapper) throws Exception { if (health <= 0) {
float health = wrapper.get(Type.FLOAT, 0); // Client unloads chunks on respawn, take note
if (health <= 0) { ClientChunks cc = wrapper.user().get(ClientChunks.class);
// Client unloads chunks on respawn, take note cc.getBulkChunks().clear();
ClientChunks cc = wrapper.user().get(ClientChunks.class); cc.getLoadedChunks().clear();
cc.getBulkChunks().clear();
cc.getLoadedChunks().clear();
}
} }
}); });
} }
@ -357,28 +324,22 @@ public class PlayerPackets {
map(Type.UNSIGNED_BYTE); // 2 - GameMode map(Type.UNSIGNED_BYTE); // 2 - GameMode
map(Type.STRING); // 3 - Level Type map(Type.STRING); // 3 - Level Type
handler(new PacketHandler() { handler(wrapper -> {
@Override // Client unloads chunks on respawn, take note
public void handle(PacketWrapper wrapper) throws Exception { ClientChunks cc = wrapper.user().get(ClientChunks.class);
// Client unloads chunks on respawn, take note cc.getBulkChunks().clear();
ClientChunks cc = wrapper.user().get(ClientChunks.class); cc.getLoadedChunks().clear();
cc.getBulkChunks().clear();
cc.getLoadedChunks().clear();
int gamemode = wrapper.get(Type.UNSIGNED_BYTE, 0); int gamemode = wrapper.get(Type.UNSIGNED_BYTE, 0);
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
tracker.setGameMode(GameMode.getById(gamemode)); tracker.setGameMode(GameMode.getById(gamemode));
}
}); });
// Fake permissions to get Commandblocks working // Fake permissions to get Commandblocks working
handler(new PacketHandler() { handler(wrapper -> {
@Override CommandBlockProvider provider = Via.getManager().getProviders().get(CommandBlockProvider.class);
public void handle(PacketWrapper wrapper) throws Exception { provider.sendPermission(wrapper.user());
CommandBlockProvider provider = Via.getManager().getProviders().get(CommandBlockProvider.class); provider.unloadChunks(wrapper.user());
provider.sendPermission(wrapper.user());
provider.unloadChunks(wrapper.user());
}
}); });
} }
}); });
@ -389,21 +350,28 @@ public class PlayerPackets {
map(Type.UNSIGNED_BYTE); //0 - Reason map(Type.UNSIGNED_BYTE); //0 - Reason
map(Type.FLOAT); //1 - Value map(Type.FLOAT); //1 - Value
handler(new PacketHandler() { handler(wrapper -> {
@Override if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 3) { //Change gamemode
public void handle(PacketWrapper wrapper) throws Exception { int gamemode = wrapper.get(Type.FLOAT, 0).intValue();
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 3) { //Change gamemode EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
int gamemode = wrapper.get(Type.FLOAT, 0).intValue(); tracker.setGameMode(GameMode.getById(gamemode));
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
tracker.setGameMode(GameMode.getById(gamemode));
}
} }
}); });
} }
}); });
/* Removed packets */ /* Removed packets */
protocol.cancelClientbound(ClientboundPackets1_8.SET_COMPRESSION); protocol.registerClientbound(ClientboundPackets1_8.SET_COMPRESSION, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.cancel();
CompressionProvider provider = Via.getManager().getProviders().get(CompressionProvider.class);
provider.handlePlayCompression(wrapper.user(), wrapper.read(Type.VAR_INT));
});
}
});
/* Incoming Packets */ /* Incoming Packets */
@ -424,21 +392,18 @@ public class PlayerPackets {
map(Type.BOOLEAN); // 3 - If Chat Colours on map(Type.BOOLEAN); // 3 - If Chat Colours on
map(Type.UNSIGNED_BYTE); // 4 - Skin Parts map(Type.UNSIGNED_BYTE); // 4 - Skin Parts
handler(new PacketHandler() { handler(wrapper -> {
@Override int hand = wrapper.read(Type.VAR_INT);
public void handle(PacketWrapper wrapper) throws Exception {
int hand = wrapper.read(Type.VAR_INT);
if (Via.getConfig().isLeftHandedHandling()) { if (Via.getConfig().isLeftHandedHandling()) {
// Add 0x80 if left handed // Add 0x80 if left handed
if (hand == 0) wrapper.set(Type.UNSIGNED_BYTE, 0, if (hand == 0) wrapper.set(Type.UNSIGNED_BYTE, 0,
(short) (wrapper.get(Type.UNSIGNED_BYTE, 0).intValue() | 0x80) (short) (wrapper.get(Type.UNSIGNED_BYTE, 0).intValue() | 0x80)
); );
}
wrapper.sendToServer(Protocol1_9To1_8.class);
wrapper.cancel();
Via.getManager().getProviders().get(MainHandProvider.class).setMainHand(wrapper.user(), hand);
} }
wrapper.sendToServer(Protocol1_9To1_8.class);
wrapper.cancel();
Via.getManager().getProviders().get(MainHandProvider.class).setMainHand(wrapper.user(), hand);
}); });
} }
}); });
@ -458,31 +423,28 @@ public class PlayerPackets {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.STRING); // 0 - Channel Name map(Type.STRING); // 0 - Channel Name
handler(new PacketHandler() { handler(wrapper -> {
@Override String name = wrapper.get(Type.STRING, 0);
public void handle(PacketWrapper wrapper) throws Exception { if (name.equalsIgnoreCase("MC|BSign")) {
String name = wrapper.get(Type.STRING, 0); Item item = wrapper.passthrough(Type.ITEM);
if (name.equalsIgnoreCase("MC|BSign")) { if (item != null) {
Item item = wrapper.passthrough(Type.ITEM); item.setIdentifier(387); // Written Book
if (item != null) { ItemRewriter.rewriteBookToServer(item);
item.setIdentifier(387); // Written Book
ItemRewriter.rewriteBookToServer(item);
}
}
if (name.equalsIgnoreCase("MC|AutoCmd")) {
wrapper.set(Type.STRING, 0, "MC|AdvCdm");
wrapper.write(Type.BYTE, (byte) 0);
wrapper.passthrough(Type.INT); // X
wrapper.passthrough(Type.INT); // Y
wrapper.passthrough(Type.INT); // Z
wrapper.passthrough(Type.STRING); // Command
wrapper.passthrough(Type.BOOLEAN); // Flag
wrapper.clearInputBuffer();
}
if (name.equalsIgnoreCase("MC|AdvCmd")) {
wrapper.set(Type.STRING, 0, "MC|AdvCdm");
} }
} }
if (name.equalsIgnoreCase("MC|AutoCmd")) {
wrapper.set(Type.STRING, 0, "MC|AdvCdm");
wrapper.write(Type.BYTE, (byte) 0);
wrapper.passthrough(Type.INT); // X
wrapper.passthrough(Type.INT); // Y
wrapper.passthrough(Type.INT); // Z
wrapper.passthrough(Type.STRING); // Command
wrapper.passthrough(Type.BOOLEAN); // Flag
wrapper.clearInputBuffer();
}
if (name.equalsIgnoreCase("MC|AdvCmd")) {
wrapper.set(Type.STRING, 0, "MC|AdvCdm");
}
}); });
} }
}); });
@ -491,19 +453,16 @@ public class PlayerPackets {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); // 0 - Action ID map(Type.VAR_INT); // 0 - Action ID
handler(new PacketHandler() { handler(wrapper -> {
@Override int action = wrapper.get(Type.VAR_INT, 0);
public void handle(PacketWrapper wrapper) throws Exception { if (action == 2) {
int action = wrapper.get(Type.VAR_INT, 0); // cancel any blocking >.>
if (action == 2) { EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
// cancel any blocking >.> if (tracker.isBlocking()) {
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class); if (!Via.getConfig().isShowShieldWhenSwordInHand()) {
if (tracker.isBlocking()) { tracker.setSecondHand(null);
if (!Via.getConfig().isShowShieldWhenSwordInHand()) {
tracker.setSecondHand(null);
}
tracker.setBlocking(false);
} }
tracker.setBlocking(false);
} }
} }
}); });

Datei anzeigen

@ -0,0 +1,153 @@
package com.viaversion.viaversion.protocols.protocol1_9to1_8.providers;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.platform.providers.Provider;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.DecoderException;
import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.handler.codec.MessageToMessageDecoder;
import java.util.List;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
public class CompressionProvider implements Provider {
public void handlePlayCompression(UserConnection user, int threshold) {
if (!user.isClientSide()) throw new IllegalStateException("PLAY state Compression packet is unsupported");
ChannelPipeline pipe = user.getChannel().pipeline();
if (threshold < 0) {
if (pipe.get("compress") != null) {
pipe.remove("compress");
pipe.remove("decompress");
}
} else {
if (pipe.get("compress") == null) {
pipe.addBefore(Via.getManager().getInjector().getEncoderName(), "compress", getEncoder(threshold));
pipe.addBefore(Via.getManager().getInjector().getDecoderName(), "decompress", getDecoder(threshold));
} else {
((CompressionHandler) pipe.get("compress")).setCompressionThreshold(threshold);
((CompressionHandler) pipe.get("decompress")).setCompressionThreshold(threshold);
}
}
}
protected CompressionHandler getEncoder(int threshold) {
return new Compressor(threshold);
}
protected CompressionHandler getDecoder(int threshold) {
return new Decompressor(threshold);
}
public interface CompressionHandler extends ChannelHandler {
void setCompressionThreshold(int threshold);
}
private static class Decompressor extends MessageToMessageDecoder<ByteBuf> implements CompressionHandler {
// https://github.com/Gerrygames/ClientViaVersion/blob/master/src/main/java/de/gerrygames/the5zig/clientviaversion/netty/CompressionEncoder.java
private final Inflater inflater;
private int threshold;
public Decompressor(int var1) {
this.threshold = var1;
this.inflater = new Inflater();
}
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if (!in.isReadable()) return;
int outLength = Type.VAR_INT.readPrimitive(in);
if (outLength == 0) {
out.add(in.readBytes(in.readableBytes()));
return;
}
if (outLength < this.threshold) {
throw new DecoderException("Badly compressed packet - size of " + outLength + " is below server threshold of " + this.threshold);
} else if (outLength > 2097152) {
throw new DecoderException("Badly compressed packet - size of " + outLength + " is larger than protocol maximum of " + 2097152);
}
ByteBuf temp = in;
if (!in.hasArray()) {
temp = ctx.alloc().heapBuffer().writeBytes(in);
} else {
in.retain();
}
ByteBuf output = ctx.alloc().heapBuffer(outLength, outLength);
try {
this.inflater.setInput(temp.array(), temp.arrayOffset() + temp.readerIndex(), temp.readableBytes());
output.writerIndex(output.writerIndex() + this.inflater.inflate(
output.array(), output.arrayOffset(), outLength));
out.add(output.retain());
} finally {
output.release();
temp.release();
this.inflater.reset();
}
}
@Override
public void setCompressionThreshold(int threshold) {
this.threshold = threshold;
}
}
private static class Compressor extends MessageToByteEncoder<ByteBuf> implements CompressionHandler {
// https://github.com/Gerrygames/ClientViaVersion/blob/master/src/main/java/de/gerrygames/the5zig/clientviaversion/netty/CompressionEncoder.java
private final Deflater deflater;
private int threshold;
public Compressor(int var1) {
this.threshold = var1;
this.deflater = new Deflater();
}
protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception {
int frameLength = in.readableBytes();
if (frameLength < this.threshold) {
out.writeByte(0); // varint
out.writeBytes(in);
return;
}
Type.VAR_INT.writePrimitive(out, frameLength);
ByteBuf temp = in;
if (!in.hasArray()) {
temp = ctx.alloc().heapBuffer().writeBytes(in);
} else {
in.retain();
}
ByteBuf output = ctx.alloc().heapBuffer();
try {
this.deflater.setInput(temp.array(), temp.arrayOffset() + temp.readerIndex(), temp.readableBytes());
deflater.finish();
while (!deflater.finished()) {
output.ensureWritable(4096);
output.writerIndex(output.writerIndex() + this.deflater.deflate(output.array(),
output.arrayOffset() + output.writerIndex(), output.writableBytes()));
}
out.writeBytes(output);
} finally {
output.release();
temp.release();
this.deflater.reset();
}
}
@Override
public void setCompressionThreshold(int threshold) {
this.threshold = threshold;
}
}
}