fix many bugs in 1.8 (also in compression), more 1.8 wip

This commit is contained in:
Bixilon 2020-06-22 20:05:04 +02:00
parent 0bdc2d0bb3
commit f3dbd8b927
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
32 changed files with 147 additions and 73 deletions

View File

@ -27,10 +27,9 @@ public class Arrow extends EntityObject implements ObjectInterface {
this.shooter = additionalInt;
}
public Arrow(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity, EntityMetaData metaData) {
public Arrow(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
this.shooter = additionalInt;
this.metaData = (ArrowMetaData) metaData;
}
@Override

View File

@ -26,9 +26,8 @@ public class Boat extends EntityObject implements ObjectInterface {
// boat does not have any additional info
}
public Boat(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity, EntityMetaData metaData) {
public Boat(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
this.metaData = (BoatMetaData) metaData;
}
@Override

View File

@ -26,10 +26,9 @@ public class Egg extends EntityObject implements ObjectInterface {
this.thrower = additionalInt;
}
public Egg(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity, EntityMetaData metaData) {
public Egg(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
this.thrower = additionalInt;
this.metaData = metaData;
}
@Override

View File

@ -25,9 +25,8 @@ public class EnderCrystal extends EntityObject implements ObjectInterface {
// objects do not spawn with metadata... reading additional info from the following int
}
public EnderCrystal(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity, EntityMetaData metaData) {
public EnderCrystal(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
this.metaData = (EnderCrystalMetaData) metaData;
}
@Override

View File

@ -24,9 +24,8 @@ public class Enderpearl extends EntityObject implements ObjectInterface {
// objects do not spawn with metadata... reading additional info from the following int
}
public Enderpearl(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity, EntityMetaData metaData) {
public Enderpearl(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
this.metaData = metaData;
}
@Override

View File

@ -24,9 +24,8 @@ public class EyeOfEnder extends EntityObject implements ObjectInterface {
// objects do not spawn with metadata... reading additional info from the following int
}
public EyeOfEnder(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity, EntityMetaData metaData) {
public EyeOfEnder(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
this.metaData = metaData;
}
@Override

View File

@ -27,10 +27,9 @@ public class FallingBlock extends EntityObject implements ObjectInterface {
block = Blocks.byLegacy(additionalInt & 0xFFF, additionalInt >> 12);
}
public FallingBlock(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity, EntityMetaData metaData) {
public FallingBlock(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
block = Blocks.byLegacy(additionalInt & 0xFFF, additionalInt >> 12);
this.metaData = metaData;
}
@Override

View File

@ -24,9 +24,8 @@ public class FallingDragonEgg extends EntityObject implements ObjectInterface {
// objects do not spawn with metadata... reading additional info from the following int
}
public FallingDragonEgg(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity, EntityMetaData metaData) {
public FallingDragonEgg(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
this.metaData = metaData;
}
@Override

View File

@ -26,10 +26,9 @@ public class FireBall extends EntityObject implements ObjectInterface {
this.thrower = additionalInt;
}
public FireBall(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity, EntityMetaData metaData) {
public FireBall(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
this.thrower = additionalInt;
this.metaData = metaData;
}
@Override

View File

@ -26,10 +26,9 @@ public class FireCharge extends EntityObject implements ObjectInterface {
this.thrower = additionalInt;
}
public FireCharge(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity, EntityMetaData metaData) {
public FireCharge(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
this.thrower = additionalInt;
this.metaData = metaData;
}
@Override

View File

@ -25,9 +25,8 @@ public class Firework extends EntityObject implements ObjectInterface {
// objects do not spawn with metadata... reading additional info from the following int
}
public Firework(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity, EntityMetaData metaData) {
public Firework(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
this.metaData = (FireworkMetaData) metaData;
}
@Override

View File

@ -26,10 +26,9 @@ public class FishingFloat extends EntityObject implements ObjectInterface {
this.owner = additionalInt;
}
public FishingFloat(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity, EntityMetaData metaData) {
public FishingFloat(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
this.owner = additionalInt;
this.metaData = metaData;
}
@Override

View File

@ -27,10 +27,9 @@ public class ItemFrame extends EntityObject implements ObjectInterface {
direction = FrameDirection.byId(additionalInt);
}
public ItemFrame(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity, EntityMetaData metaData) {
public ItemFrame(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
direction = FrameDirection.byId(additionalInt);
this.metaData = (ItemFrameMetaData) metaData;
}
@Override

View File

@ -25,9 +25,8 @@ public class ItemStack extends EntityObject implements ObjectInterface {
// objects do not spawn with metadata... reading additional info from the following int
}
public ItemStack(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity, EntityMetaData metaData) {
public ItemStack(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
this.metaData = (ItemMetaData) metaData;
}
@Override

View File

@ -24,9 +24,8 @@ public class LeashKnot extends EntityObject implements ObjectInterface {
// objects do not spawn with metadata... reading additional info from the following int
}
public LeashKnot(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity, EntityMetaData metaData) {
public LeashKnot(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
this.metaData = metaData;
}
@Override

View File

@ -26,10 +26,9 @@ public class Minecart extends EntityObject implements ObjectInterface {
type = MinecartType.byType(additionalInt);
}
public Minecart(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity, EntityMetaData metaData) {
public Minecart(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
type = MinecartType.byType(additionalInt);
this.metaData = (MinecartMetaData) metaData;
}
@Override

View File

@ -24,9 +24,8 @@ public class PrimedTNT extends EntityObject implements ObjectInterface {
// objects do not spawn with metadata... reading additional info from the following int
}
public PrimedTNT(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity, EntityMetaData metaData) {
public PrimedTNT(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
this.metaData = metaData;
}
@Override

View File

@ -26,10 +26,9 @@ public class Snowball extends EntityObject implements ObjectInterface {
this.thrower = additionalInt;
}
public Snowball(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity, EntityMetaData metaData) {
public Snowball(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
this.thrower = additionalInt;
this.metaData = metaData;
}
@Override

View File

@ -24,9 +24,8 @@ public class ThrownExpBottle extends EntityObject implements ObjectInterface {
// objects do not spawn with metadata... reading additional info from the following int
}
public ThrownExpBottle(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity, EntityMetaData metaData) {
public ThrownExpBottle(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
this.metaData = metaData;
}
@Override

View File

@ -26,10 +26,9 @@ public class ThrownPotion extends EntityObject implements ObjectInterface {
this.potion = additionalInt;
}
public ThrownPotion(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity, EntityMetaData metaData) {
public ThrownPotion(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
this.potion = additionalInt;
this.metaData = metaData;
}
@Override

View File

@ -26,10 +26,9 @@ public class WitherSkull extends EntityObject implements ObjectInterface {
this.thrower = additionalInt;
}
public WitherSkull(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity, EntityMetaData metaData) {
public WitherSkull(int id, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(id, location, yaw, pitch, velocity);
this.thrower = additionalInt;
this.metaData = metaData;
}
@Override

View File

@ -17,6 +17,7 @@ import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketPluginMessageSending;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.protocol.protocol.OutByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
@ -91,6 +92,10 @@ public class PluginChannelHandler {
connection.sendPacket(new PacketPluginMessageSending(channel, data));
}
public void sendRawData(String channel, OutByteBuffer buffer) {
connection.sendPacket(new PacketPluginMessageSending(channel, buffer.getOutBytes()));
}
public void registerServerChannel(String name) {
if (DefaultPluginChannels.byName(name) != null) {
// channel is a default channel, can not register

View File

@ -26,10 +26,7 @@ import de.bixilon.minosoft.protocol.packets.serverbound.login.PacketLoginStart;
import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketChatMessage;
import de.bixilon.minosoft.protocol.packets.serverbound.status.PacketStatusPing;
import de.bixilon.minosoft.protocol.packets.serverbound.status.PacketStatusRequest;
import de.bixilon.minosoft.protocol.protocol.ConnectionReason;
import de.bixilon.minosoft.protocol.protocol.ConnectionState;
import de.bixilon.minosoft.protocol.protocol.PacketHandler;
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
import de.bixilon.minosoft.protocol.protocol.*;
import java.util.ArrayList;
@ -192,9 +189,21 @@ public class Connection {
public void registerDefaultChannels() {
// MC|Brand
getPluginChannelHandler().registerClientHandler(DefaultPluginChannels.MC_BRAND.getName(), (handler, buffer) -> {
Log.info(String.format("Server is running %s on version %s", new String(buffer.readBytes(buffer.getBytesLeft())), getVersion().getName()));
String serverVersion;
String clientVersion = (Minosoft.getConfig().getBoolean(GameConfiguration.NETWORK_FAKE_CLIENT_BRAND) ? "vanilla" : "Minosoft");
OutByteBuffer toSend = new OutByteBuffer();
if (getVersion() == ProtocolVersion.VERSION_1_7_10) {
// no length prefix
serverVersion = new String(buffer.readBytes(buffer.getBytesLeft()));
toSend.writeBytes(clientVersion.getBytes());
} else {
// length prefix
serverVersion = buffer.readString();
toSend.writeString(clientVersion);
}
Log.info(String.format("Server is running %s, connected with %s", serverVersion, getVersion().getName()));
getPluginChannelHandler().sendRawData(DefaultPluginChannels.MC_BRAND.getName(), (Minosoft.getConfig().getBoolean(GameConfiguration.NETWORK_FAKE_CLIENT_BRAND) ? "vanilla" : "Minosoft").getBytes());
getPluginChannelHandler().sendRawData(DefaultPluginChannels.MC_BRAND.getName(), toSend);
});
}

View File

@ -155,7 +155,12 @@ public class Network {
outRawBuffer.writeBytes(data);
}
data = outRawBuffer.getOutBytes();
} else {
// append packet length
OutByteBuffer bufferWithLengthPrefix = new OutByteBuffer();
bufferWithLengthPrefix.writeVarInt(data.length);
bufferWithLengthPrefix.writeBytes(data);
data = bufferWithLengthPrefix.getOutBytes();
}

View File

@ -32,7 +32,7 @@ public class PacketPlayerAbilitiesReceiving implements ClientboundPacket {
@Override
public void read(InPacketBuffer buffer, ProtocolVersion v) {
switch (v) {
case VERSION_1_7_10:
case VERSION_1_7_10: {
byte flags = buffer.readByte();
creative = BitByte.isBitSet(flags, 0);
flying = BitByte.isBitSet(flags, 1);
@ -41,9 +41,17 @@ public class PacketPlayerAbilitiesReceiving implements ClientboundPacket {
flyingSpeed = buffer.readFloat();
walkingSpeed = buffer.readFloat();
break;
case VERSION_1_8:
//ToDo
}
case VERSION_1_8: {
byte flags = buffer.readByte();
godMode = BitByte.isBitSet(flags, 0);
flying = BitByte.isBitSet(flags, 1);
canFly = BitByte.isBitSet(flags, 2);
creative = BitByte.isBitSet(flags, 3);
flyingSpeed = buffer.readFloat();
// ToDo Entity Properties
break;
}
}
}

View File

@ -44,15 +44,9 @@ public class PacketScoreboardTeams implements ClientboundPacket {
prefix = buffer.readString();
suffix = buffer.readString();
friendlyFire = ScoreboardFriendlyFire.byId(buffer.readByte());
if (v.getVersion() >= ProtocolVersion.VERSION_1_8.getVersion()) {
// color and nametag
nameTagVisibility = ScoreboardNameTagVisibility.byName(buffer.readString());
color = TextComponent.ChatAttributes.byColor(ChatColor.byId(buffer.readByte()));
} else {
// default values
nameTagVisibility = ScoreboardNameTagVisibility.ALWAYS;
color = TextComponent.ChatAttributes.WHITE;
}
// default values
nameTagVisibility = ScoreboardNameTagVisibility.ALWAYS;
color = TextComponent.ChatAttributes.WHITE;
}
if (action == ScoreboardTeamAction.CREATE || action == ScoreboardTeamAction.PLAYER_ADD || action == ScoreboardTeamAction.PLAYER_REMOVE) {
short playerCount = buffer.readShort();
@ -62,6 +56,25 @@ public class PacketScoreboardTeams implements ClientboundPacket {
}
}
break;
case VERSION_1_8:
name = buffer.readString();
action = ScoreboardTeamAction.byId(buffer.readByte());
if (action == ScoreboardTeamAction.CREATE || action == ScoreboardTeamAction.INFORMATION_UPDATE) {
displayName = buffer.readString();
prefix = buffer.readString();
suffix = buffer.readString();
friendlyFire = ScoreboardFriendlyFire.byId(buffer.readByte());
nameTagVisibility = ScoreboardNameTagVisibility.byName(buffer.readString());
color = TextComponent.ChatAttributes.byColor(ChatColor.byId(buffer.readByte()));
}
if (action == ScoreboardTeamAction.CREATE || action == ScoreboardTeamAction.PLAYER_ADD || action == ScoreboardTeamAction.PLAYER_REMOVE) {
int playerCount = buffer.readVarInt();
playerNames = new String[playerCount];
for (int i = 0; i < playerCount; i++) {
playerNames[i] = buffer.readString();
}
}
break;
}
}

View File

@ -0,0 +1,49 @@
/*
* Codename Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* 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 <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.clientbound.play;
import de.bixilon.minosoft.game.datatypes.Difficulty;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
import de.bixilon.minosoft.protocol.protocol.InPacketBuffer;
import de.bixilon.minosoft.protocol.protocol.PacketHandler;
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
public class PacketServerDifficulty implements ClientboundPacket {
Difficulty difficulty;
@Override
public void read(InPacketBuffer buffer, ProtocolVersion v) {
switch (v) {
case VERSION_1_8:
difficulty = Difficulty.byId(buffer.readByte());
break;
}
}
@Override
public void log() {
Log.protocol(String.format("Received server difficulty (difficulty=%s)", difficulty.name()));
}
@Override
public void handle(PacketHandler h) {
h.handle(this);
}
public Difficulty getDifficulty() {
return difficulty;
}
}

View File

@ -57,21 +57,26 @@ public class PacketSpawnObject implements ClientboundPacket {
public void read(InPacketBuffer buffer, ProtocolVersion v) {
switch (v) {
case VERSION_1_7_10:
case VERSION_1_8:
int entityId = buffer.readVarInt();
Objects type = Objects.byType(buffer.readByte());
Location location = new Location(buffer.readFixedPointNumberInteger(), buffer.readFixedPointNumberInteger(), buffer.readFixedPointNumberInteger());
short pitch = buffer.readAngle();
short yaw = buffer.readAngle();
int data = buffer.readInteger();
try {
if (v.getVersion() >= ProtocolVersion.VERSION_1_8.getVersion()) {
// velocity present AND metadata
Velocity velocity = new Velocity(buffer.readShort(), buffer.readShort(), buffer.readShort());
EntityMetaData metaData = getEntityData(object.getMetaDataClass(), buffer, v);
object = type.getClazz().getConstructor(int.class, Location.class, short.class, short.class, int.class, Velocity.class, EntityMetaData.class).newInstance(entityId, location, yaw, pitch, buffer.readInteger(), velocity, metaData);
Velocity velocity = null;
if (data != 0) {
velocity = new Velocity(buffer.readShort(), buffer.readShort(), buffer.readShort());
}
object = type.getClazz().getConstructor(int.class, Location.class, short.class, short.class, int.class, Velocity.class).newInstance(entityId, location, yaw, pitch, data, velocity);
} else {
object = type.getClazz().getConstructor(int.class, Location.class, short.class, short.class, int.class).newInstance(entityId, location, yaw, pitch, buffer.readInteger());
object = type.getClazz().getConstructor(int.class, Location.class, short.class, short.class, int.class).newInstance(entityId, location, yaw, pitch, data);
}
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();

View File

@ -44,13 +44,14 @@ public class PacketPlayerAbilitiesSending implements ServerboundPacket {
this.godMode = false;
this.flyingSpeed = 0.05F;
this.walkingSpeed = 0.1F;
log();
}
@Override
public OutPacketBuffer write(ProtocolVersion v) {
OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_CLIENT_SETTINGS));
OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_PLAYER_ABILITIES));
switch (v) {
case VERSION_1_7_10:
case VERSION_1_8:

View File

@ -30,19 +30,15 @@ public class OutPacketBuffer extends OutByteBuffer {
@Override
public byte[] getOutBytes() {
// ToDo: compression
List<Byte> before = getBytes();
List<Byte> after = new ArrayList<>();
List<Byte> last = new ArrayList<>();
writeVarInt(getCommand(), after); // second: command
after.addAll(before); // rest ist raw data
writeVarInt(after.size(), last); // first var int: length
last.addAll(after); // rest ist raw data
byte[] ret = new byte[last.size()];
for (int i = 0; i < last.size(); i++) {
ret[i] = last.get(i);
byte[] ret = new byte[after.size()];
for (int i = 0; i < after.size(); i++) {
ret[i] = after.get(i);
}
return ret;
}

View File

@ -436,4 +436,7 @@ public class PacketHandler {
public void handle(PacketLoginSetCompression pkg) {
}
public void handle(PacketServerDifficulty pkg) {
}
}

View File

@ -113,6 +113,7 @@ public abstract class Protocol implements ProtocolInterface {
packetClassMapping.put(Packets.Clientbound.PLAY_TEAMS, PacketScoreboardTeams.class);
packetClassMapping.put(Packets.Clientbound.PLAY_DISPLAY_SCOREBOARD, PacketScoreboardDisplayScoreboard.class);
packetClassMapping.put(Packets.Clientbound.PLAY_MAP_DATA, PacketMapData.class);
packetClassMapping.put(Packets.Clientbound.PLAY_SERVER_DIFFICULTY, PacketServerDifficulty.class);
}
public static ProtocolVersion getLowestVersionSupported() {