forked from GeyserMC/Geyser
Update to latest master
This commit is contained in:
commit
43c062c23c
12 changed files with 113 additions and 41 deletions
|
@ -58,6 +58,8 @@ import org.geysermc.connector.utils.DockerCheck;
|
|||
import org.geysermc.connector.utils.LanguageUtils;
|
||||
import org.geysermc.connector.utils.LocaleUtils;
|
||||
|
||||
import javax.naming.directory.Attribute;
|
||||
import javax.naming.directory.InitialDirContext;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
|
@ -77,6 +79,8 @@ public class GeyserConnector {
|
|||
public static final String NAME = "Geyser";
|
||||
public static final String VERSION = "DEV"; // A fallback for running in IDEs
|
||||
|
||||
private static final String IP_REGEX = "\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b";
|
||||
|
||||
private final List<GeyserSession> players = new ArrayList<>();
|
||||
|
||||
private static GeyserConnector instance;
|
||||
|
@ -135,8 +139,30 @@ public class GeyserConnector {
|
|||
if (platformType != PlatformType.STANDALONE) {
|
||||
DockerCheck.check(bootstrap);
|
||||
}
|
||||
String remoteAddress = config.getRemote().getAddress();
|
||||
int remotePort = config.getRemote().getPort();
|
||||
// Filters whether it is not an IP address or localhost, because otherwise it is not possible to find out an SRV entry.
|
||||
if ((config.isLegacyPingPassthrough() || platformType == PlatformType.STANDALONE) && !remoteAddress.matches(IP_REGEX) && !remoteAddress.equalsIgnoreCase("localhost")) {
|
||||
try {
|
||||
// Searches for a server address and a port from a SRV record of the specified host name
|
||||
InitialDirContext ctx = new InitialDirContext();
|
||||
Attribute attr = ctx.getAttributes("dns:///_minecraft._tcp." + remoteAddress, new String[]{"SRV"}).get("SRV");
|
||||
// size > 0 = SRV entry found
|
||||
if (attr != null && attr.size() > 0) {
|
||||
String[] record = ((String) attr.get(0)).split(" ");
|
||||
// Overwrites the existing address and port with that from the SRV record.
|
||||
config.getRemote().setAddress(remoteAddress = record[3]);
|
||||
config.getRemote().setPort(remotePort = Integer.parseInt(record[2]));
|
||||
logger.debug("Found SRV record \"" + remoteAddress + ":" + remotePort + "\"");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.debug("Exception while trying to find an SRV record for the remote host.");
|
||||
if (config.isDebugMode())
|
||||
ex.printStackTrace(); // Otherwise we can get a stack trace for any domain that doesn't have an SRV record
|
||||
}
|
||||
}
|
||||
|
||||
remoteServer = new RemoteServer(config.getRemote().getAddress(), config.getRemote().getPort());
|
||||
remoteServer = new RemoteServer(config.getRemote().getAddress(), remotePort);
|
||||
authType = AuthType.getByName(config.getRemote().getAuthType());
|
||||
|
||||
if (config.isAboveBedrockNetherBuilding())
|
||||
|
|
|
@ -92,6 +92,10 @@ public interface GeyserConfiguration {
|
|||
String getAddress();
|
||||
|
||||
int getPort();
|
||||
|
||||
void setAddress(String address);
|
||||
|
||||
void setPort(int port);
|
||||
|
||||
String getAuthType();
|
||||
}
|
||||
|
|
|
@ -59,7 +59,12 @@ public class WolfEntity extends TameableEntity {
|
|||
if (entityMetadata.getId() == 19 && !metadata.getFlags().getFlag(EntityFlag.ANGRY)) {
|
||||
metadata.put(EntityData.COLOR, (byte) (int) entityMetadata.getValue());
|
||||
}
|
||||
//TODO: Anger time int?
|
||||
|
||||
// Wolf anger (1.16+)
|
||||
if (entityMetadata.getId() == 20) {
|
||||
metadata.getFlags().setFlag(EntityFlag.ANGRY, (int) entityMetadata.getValue() != 0);
|
||||
}
|
||||
|
||||
super.updateBedrockMetadata(entityMetadata, session);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,12 +135,15 @@ public class BedrockInteractTranslator extends PacketTranslator<InteractPacket>
|
|||
}
|
||||
break;
|
||||
case OPEN_INVENTORY:
|
||||
ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket();
|
||||
containerOpenPacket.setId((byte) 0);
|
||||
containerOpenPacket.setType(ContainerType.INVENTORY);
|
||||
containerOpenPacket.setUniqueEntityId(-1);
|
||||
containerOpenPacket.setBlockPosition(entity.getPosition().toInt());
|
||||
session.sendUpstreamPacket(containerOpenPacket);
|
||||
if (!session.getInventory().isOpen()) {
|
||||
ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket();
|
||||
containerOpenPacket.setId((byte) 0);
|
||||
containerOpenPacket.setType(ContainerType.INVENTORY);
|
||||
containerOpenPacket.setUniqueEntityId(-1);
|
||||
containerOpenPacket.setBlockPosition(entity.getPosition().toInt());
|
||||
session.sendUpstreamPacket(containerOpenPacket);
|
||||
session.getInventory().setOpen(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,15 +60,23 @@ public class MerchantInventoryTranslator extends BaseInventoryTranslator {
|
|||
|
||||
@Override
|
||||
public int bedrockSlotToJava(InventoryActionData action) {
|
||||
if (action.getSource().getContainerId() == ContainerId.UI) {
|
||||
switch (action.getSlot()) {
|
||||
case 4:
|
||||
return 0;
|
||||
case 5:
|
||||
return 1;
|
||||
case 50:
|
||||
return 2;
|
||||
}
|
||||
switch (action.getSource().getContainerId()) {
|
||||
case ContainerId.UI:
|
||||
switch (action.getSlot()) {
|
||||
case 4:
|
||||
return 0;
|
||||
case 5:
|
||||
return 1;
|
||||
case 50:
|
||||
return 2;
|
||||
}
|
||||
break;
|
||||
case -28: // Trading 1?
|
||||
return 0;
|
||||
case -29: // Trading 2?
|
||||
return 1;
|
||||
case -30: // Trading Output?
|
||||
return 2;
|
||||
}
|
||||
return super.bedrockSlotToJava(action);
|
||||
}
|
||||
|
@ -109,10 +117,8 @@ public class MerchantInventoryTranslator extends BaseInventoryTranslator {
|
|||
|
||||
@Override
|
||||
public void translateActions(GeyserSession session, Inventory inventory, List<InventoryActionData> actions) {
|
||||
for (InventoryActionData action : actions) {
|
||||
if (action.getSource().getType() == InventorySource.Type.NON_IMPLEMENTED_TODO) {
|
||||
return;
|
||||
}
|
||||
if (actions.stream().anyMatch(a -> a.getSource().getContainerId() == -31)) {
|
||||
return;
|
||||
}
|
||||
|
||||
super.translateActions(session, inventory, actions);
|
||||
|
|
|
@ -62,7 +62,7 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator<Serve
|
|||
|
||||
RespawnPacket respawnPacket = new RespawnPacket();
|
||||
respawnPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||
respawnPacket.setPosition(pos);
|
||||
respawnPacket.setPosition(entity.getPosition());
|
||||
respawnPacket.setState(RespawnPacket.State.SERVER_READY);
|
||||
session.sendUpstreamPacket(respawnPacket);
|
||||
|
||||
|
@ -79,7 +79,7 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator<Serve
|
|||
|
||||
MovePlayerPacket movePlayerPacket = new MovePlayerPacket();
|
||||
movePlayerPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||
movePlayerPacket.setPosition(pos);
|
||||
movePlayerPacket.setPosition(entity.getPosition());
|
||||
movePlayerPacket.setRotation(Vector3f.from(packet.getPitch(), packet.getYaw(), 0));
|
||||
movePlayerPacket.setMode(MovePlayerPacket.Mode.RESPAWN); //TODO: PROBABLY RIGHT BUT STILL CHECK
|
||||
|
||||
|
|
|
@ -85,6 +85,7 @@ public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyCli
|
|||
playerFlags.add(AdventureSetting.MAY_FLY);
|
||||
playerFlags.add(AdventureSetting.NO_CLIP);
|
||||
playerFlags.add(AdventureSetting.FLYING);
|
||||
playerFlags.add(AdventureSetting.WORLD_IMMUTABLE);
|
||||
gameMode = GameMode.CREATIVE; // spectator doesnt exist on bedrock
|
||||
}
|
||||
|
||||
|
|
|
@ -79,15 +79,17 @@ public class GeyserLegacyPingPassthrough implements IGeyserPingPassthrough, Runn
|
|||
public void run() {
|
||||
try {
|
||||
Socket socket = new Socket();
|
||||
socket.connect(new InetSocketAddress(connector.getConfig().getRemote().getAddress(), connector.getConfig().getRemote().getPort()), 5000);
|
||||
String address = connector.getConfig().getRemote().getAddress();
|
||||
int port = connector.getConfig().getRemote().getPort();
|
||||
socket.connect(new InetSocketAddress(address, port), 5000);
|
||||
|
||||
ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
|
||||
DataOutputStream handshake = new DataOutputStream(byteArrayStream);
|
||||
handshake.write(0x0);
|
||||
VarInts.writeUnsignedInt(handshake, MinecraftConstants.PROTOCOL_VERSION);
|
||||
VarInts.writeUnsignedInt(handshake, socket.getInetAddress().getHostAddress().length());
|
||||
handshake.writeBytes(socket.getInetAddress().getHostAddress());
|
||||
handshake.writeShort(socket.getPort());
|
||||
VarInts.writeUnsignedInt(handshake, address.length());
|
||||
handshake.writeBytes(address);
|
||||
handshake.writeShort(port);
|
||||
VarInts.writeUnsignedInt(handshake, 1);
|
||||
|
||||
DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
|
||||
|
|
|
@ -56,7 +56,7 @@ public class InventoryUtils {
|
|||
translator.prepareInventory(session, inventory);
|
||||
//Ensure at least half a second passes between closing and opening a new window
|
||||
//The client will not open the new window if it is still closing the old one
|
||||
long delay = 500 - (System.currentTimeMillis() - session.getLastWindowCloseTime());
|
||||
long delay = 700 - (System.currentTimeMillis() - session.getLastWindowCloseTime());
|
||||
//TODO: find better way to handle double chest delay
|
||||
if (translator instanceof DoubleChestInventoryTranslator) {
|
||||
delay = Math.max(delay, 200);
|
||||
|
@ -87,6 +87,7 @@ public class InventoryUtils {
|
|||
}
|
||||
} else {
|
||||
Inventory inventory = session.getInventory();
|
||||
inventory.setOpen(false);
|
||||
InventoryTranslator translator = InventoryTranslator.INVENTORY_TRANSLATORS.get(inventory.getWindowType());
|
||||
translator.updateInventory(session, inventory);
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 8a62f3730bd1ae94262315ad1535b5d5523de189
|
||||
Subproject commit cd57d6029186293b3ca282243a90252db434714b
|
Loading…
Add table
Add a link
Reference in a new issue