3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-28 00:50:13 +01:00

Always create ProtocolInfo, store mappings as int[]

Dieser Commit ist enthalten in:
KennyTV 2021-04-27 10:29:30 +02:00
Ursprung 30d122e7fa
Commit d4bc31d11e
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
11 geänderte Dateien mit 43 neuen und 54 gelöschten Zeilen

Datei anzeigen

@ -44,6 +44,8 @@ public interface ConnectionManager {
/** /**
* Frontend connections will have the UUID stored. Override this if your platform isn't always frontend. * Frontend connections will have the UUID stored. Override this if your platform isn't always frontend.
* UUIDs can't be duplicate between frontend connections. * UUIDs can't be duplicate between frontend connections.
*
* @return true if the user is a frontend connection
*/ */
boolean isFrontEnd(UserConnection connection); boolean isFrontEnd(UserConnection connection);
@ -55,6 +57,8 @@ public interface ConnectionManager {
* <p> * <p>
* Note that connections are removed as soon as their channel is closed, * Note that connections are removed as soon as their channel is closed,
* so avoid using this method during player quits for example. * so avoid using this method during player quits for example.
*
* @return frontend UserConnection of the player connected to this proxy server
*/ */
@Nullable UserConnection getConnectedClient(UUID clientIdentifier); @Nullable UserConnection getConnectedClient(UUID clientIdentifier);
@ -66,6 +70,8 @@ public interface ConnectionManager {
* <p> * <p>
* Note that connections are removed as soon as their channel is closed, * Note that connections are removed as soon as their channel is closed,
* so avoid using this method during player quits for example. * so avoid using this method during player quits for example.
*
* @return UUID of the frontend connection to this proxy server
*/ */
@Nullable UUID getConnectedClientId(UserConnection connection); @Nullable UUID getConnectedClientId(UserConnection connection);
@ -75,6 +81,8 @@ public interface ConnectionManager {
* May contain frontend, backend and/or client-sided connections. * May contain frontend, backend and/or client-sided connections.
* When ViaVersion is reloaded, this method may not return some players. * When ViaVersion is reloaded, this method may not return some players.
* May not contain ProtocolSupport players. * May not contain ProtocolSupport players.
*
* @return connected UserConnections
*/ */
Set<UserConnection> getConnections(); Set<UserConnection> getConnections();
@ -83,6 +91,8 @@ public interface ConnectionManager {
* Returns empty list when there isn't a server * Returns empty list when there isn't a server
* When ViaVersion is reloaded, this method may not return some players. * When ViaVersion is reloaded, this method may not return some players.
* May not contain ProtocolSupport players. * May not contain ProtocolSupport players.
*
* @return map containing the UUIDs and frontend UserConnections from players connected to this proxy server
*/ */
Map<UUID, UserConnection> getConnectedClients(); Map<UUID, UserConnection> getConnectedClients();

Datei anzeigen

@ -186,9 +186,7 @@ public interface UserConnection {
* *
* @return info containing the current protocol state and userdata * @return info containing the current protocol state and userdata
*/ */
@Nullable ProtocolInfo getProtocolInfo(); ProtocolInfo getProtocolInfo();
void setProtocolInfo(@Nullable ProtocolInfo protocolInfo);
/** /**
* Returns a map of stored objects. * Returns a map of stored objects.

Datei anzeigen

@ -139,11 +139,11 @@ public class MappingDataLoader {
} }
} }
public static void mapIdentifiers(short[] output, JsonObject oldIdentifiers, JsonObject newIdentifiers) { public static void mapIdentifiers(int[] output, JsonObject oldIdentifiers, JsonObject newIdentifiers) {
MappingDataLoader.mapIdentifiers(output, oldIdentifiers, newIdentifiers, null); MappingDataLoader.mapIdentifiers(output, oldIdentifiers, newIdentifiers, null);
} }
public static void mapIdentifiers(short[] output, JsonObject oldIdentifiers, JsonObject newIdentifiers, @Nullable JsonObject diffIdentifiers) { public static void mapIdentifiers(int[] output, JsonObject oldIdentifiers, JsonObject newIdentifiers, @Nullable JsonObject diffIdentifiers) {
Object2IntMap newIdentifierMap = MappingDataLoader.indexedObjectToMap(newIdentifiers); Object2IntMap newIdentifierMap = MappingDataLoader.indexedObjectToMap(newIdentifiers);
for (Map.Entry<String, JsonElement> entry : oldIdentifiers.entrySet()) { for (Map.Entry<String, JsonElement> entry : oldIdentifiers.entrySet()) {
int value = mapIdentifierEntry(entry, newIdentifierMap, diffIdentifiers); int value = mapIdentifierEntry(entry, newIdentifierMap, diffIdentifiers);
@ -173,11 +173,11 @@ public class MappingDataLoader {
return value; return value;
} }
public static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers, boolean warnOnMissing) { public static void mapIdentifiers(int[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers, boolean warnOnMissing) {
mapIdentifiers(output, oldIdentifiers, newIdentifiers, null, warnOnMissing); mapIdentifiers(output, oldIdentifiers, newIdentifiers, null, warnOnMissing);
} }
public static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers, @Nullable JsonObject diffIdentifiers, boolean warnOnMissing) { public static void mapIdentifiers(int[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers, @Nullable JsonObject diffIdentifiers, boolean warnOnMissing) {
Object2IntMap<String> newIdentifierMap = MappingDataLoader.arrayToMap(newIdentifiers); Object2IntMap<String> newIdentifierMap = MappingDataLoader.arrayToMap(newIdentifiers);
for (int i = 0; i < oldIdentifiers.size(); i++) { for (int i = 0; i < oldIdentifiers.size(); i++) {
JsonElement oldIdentifier = oldIdentifiers.get(i); JsonElement oldIdentifier = oldIdentifiers.get(i);

Datei anzeigen

@ -29,9 +29,9 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Arrays; import java.util.Arrays;
public class Mappings { public class Mappings {
protected final short[] oldToNew; protected final int[] oldToNew;
public Mappings(short[] oldToNew) { public Mappings(int[] oldToNew) {
this.oldToNew = oldToNew; this.oldToNew = oldToNew;
} }
@ -45,8 +45,8 @@ public class Mappings {
* @param diffMapping extra mappings that will be used/scanned when an entry cannot be found * @param diffMapping extra mappings that will be used/scanned when an entry cannot be found
*/ */
public Mappings(int size, JsonObject oldMapping, JsonObject newMapping, @Nullable JsonObject diffMapping) { public Mappings(int size, JsonObject oldMapping, JsonObject newMapping, @Nullable JsonObject diffMapping) {
oldToNew = new short[size]; oldToNew = new int[size];
Arrays.fill(oldToNew, (short) -1); Arrays.fill(oldToNew, -1);
MappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping, diffMapping); MappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping, diffMapping);
} }
@ -62,8 +62,8 @@ public class Mappings {
* @param newMapping mappings to map to * @param newMapping mappings to map to
*/ */
public Mappings(int size, JsonObject oldMapping, JsonObject newMapping) { public Mappings(int size, JsonObject oldMapping, JsonObject newMapping) {
oldToNew = new short[size]; oldToNew = new int[size];
Arrays.fill(oldToNew, (short) -1); Arrays.fill(oldToNew, -1);
MappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping); MappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping);
} }
@ -81,8 +81,8 @@ public class Mappings {
* @param warnOnMissing should "No key for x" be printed if there is no matching identifier * @param warnOnMissing should "No key for x" be printed if there is no matching identifier
*/ */
public Mappings(int size, JsonArray oldMapping, JsonArray newMapping, JsonObject diffMapping, boolean warnOnMissing) { public Mappings(int size, JsonArray oldMapping, JsonArray newMapping, JsonObject diffMapping, boolean warnOnMissing) {
oldToNew = new short[size]; oldToNew = new int[size];
Arrays.fill(oldToNew, (short) -1); Arrays.fill(oldToNew, -1);
MappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping, diffMapping, warnOnMissing); MappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping, diffMapping, warnOnMissing);
} }
@ -110,7 +110,7 @@ public class Mappings {
return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1; return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1;
} }
public short[] getOldToNew() { public int[] getOldToNew() {
return oldToNew; return oldToNew;
} }
} }

Datei anzeigen

@ -76,6 +76,11 @@ public interface ProtocolPipeline extends SimpleProtocol {
*/ */
boolean filter(Object o, List list) throws Exception; boolean filter(Object o, List list) throws Exception;
/**
* Returns the list of protocols this pipeline contains.
*
* @return list of protocols in this pipe
*/
List<Protocol> pipes(); List<Protocol> pipes();
/** /**

Datei anzeigen

@ -22,8 +22,6 @@
*/ */
package com.viaversion.viaversion.api.protocol.packet; package com.viaversion.viaversion.api.protocol.packet;
import com.viaversion.viaversion.api.protocol.packet.PacketType;
/** /**
* Interface to be implemented by server outgoing packet type enums, * Interface to be implemented by server outgoing packet type enums,
* representing PLAY state packets, ordered by their packet id. * representing PLAY state packets, ordered by their packet id.

Datei anzeigen

@ -22,8 +22,6 @@
*/ */
package com.viaversion.viaversion.api.protocol.packet; package com.viaversion.viaversion.api.protocol.packet;
import com.viaversion.viaversion.api.protocol.packet.PacketType;
/** /**
* Interface to be implemented by server incoming packet type enums, * Interface to be implemented by server incoming packet type enums,
* representing PLAY state packets, ordered by their packet id. * representing PLAY state packets, ordered by their packet id.

Datei anzeigen

@ -230,7 +230,6 @@ public class BungeeServerHandler implements Listener {
plMsg.setTag(channel); plMsg.setTag(channel);
} }
user.setProtocolInfo(info);
user.put(storage); user.put(storage);
user.setActive(protocolPath != null); user.setActive(protocolPath != null);

Datei anzeigen

@ -22,7 +22,6 @@
*/ */
package com.viaversion.viaversion.connection; package com.viaversion.viaversion.connection;
import com.google.common.base.Preconditions;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.ProtocolInfo; import com.viaversion.viaversion.api.connection.ProtocolInfo;
@ -58,9 +57,9 @@ public class UserConnectionImpl implements UserConnection {
private final Set<UUID> passthroughTokens = Collections.newSetFromMap(CacheBuilder.newBuilder() private final Set<UUID> passthroughTokens = Collections.newSetFromMap(CacheBuilder.newBuilder()
.expireAfterWrite(10, TimeUnit.SECONDS) .expireAfterWrite(10, TimeUnit.SECONDS)
.<UUID, Boolean>build().asMap()); .<UUID, Boolean>build().asMap());
private final ProtocolInfo protocolInfo = new ProtocolInfoImpl(this);
private final Channel channel; private final Channel channel;
private final boolean clientSide; private final boolean clientSide;
private ProtocolInfo protocolInfo;
private boolean active = true; private boolean active = true;
private boolean pendingDisconnect; private boolean pendingDisconnect;
@ -73,6 +72,7 @@ public class UserConnectionImpl implements UserConnection {
public UserConnectionImpl(@Nullable Channel channel, boolean clientSide) { public UserConnectionImpl(@Nullable Channel channel, boolean clientSide) {
this.channel = channel; this.channel = channel;
this.clientSide = clientSide; this.clientSide = clientSide;
storedObjects.put(ProtocolInfo.class, (StoredObject) protocolInfo);
} }
/** /**
@ -313,21 +313,10 @@ public class UserConnectionImpl implements UserConnection {
} }
@Override @Override
public @Nullable ProtocolInfo getProtocolInfo() { public ProtocolInfo getProtocolInfo() {
return protocolInfo; return protocolInfo;
} }
@Override
public void setProtocolInfo(@Nullable ProtocolInfo protocolInfo) {
Preconditions.checkArgument(protocolInfo instanceof StoredObject, "ProtocolInfo has to extend StoredObject!");
this.protocolInfo = protocolInfo;
if (protocolInfo != null) {
storedObjects.put(ProtocolInfo.class, (StoredObject) protocolInfo);
} else {
storedObjects.remove(ProtocolInfo.class);
}
}
@Override @Override
public Map<Class<?>, StoredObject> getStoredObjects() { public Map<Class<?>, StoredObject> getStoredObjects() {
return storedObjects; return storedObjects;

Datei anzeigen

@ -24,7 +24,6 @@ package com.viaversion.viaversion.protocol;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.ProtocolInfo;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.platform.ViaPlatform; import com.viaversion.viaversion.api.platform.ViaPlatform;
import com.viaversion.viaversion.api.protocol.AbstractSimpleProtocol; import com.viaversion.viaversion.api.protocol.AbstractSimpleProtocol;
@ -33,7 +32,6 @@ import com.viaversion.viaversion.api.protocol.base.Protocol;
import com.viaversion.viaversion.api.protocol.packet.Direction; import com.viaversion.viaversion.api.protocol.packet.Direction;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.connection.ProtocolInfoImpl;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
@ -42,14 +40,15 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Level; import java.util.logging.Level;
public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements ProtocolPipeline { public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements ProtocolPipeline {
private final UserConnection userConnection;
/** /**
* Protocol list ordered from client to server transforation with the base protocols at the end. * Protocol list ordered from client to server transforation with the base protocols at the end.
*/ */
private List<Protocol> protocolList; private List<Protocol> protocolList;
private UserConnection userConnection;
public ProtocolPipelineImpl(UserConnection userConnection) { public ProtocolPipelineImpl(UserConnection userConnection) {
init(userConnection); this.userConnection = userConnection;
userConnection.getProtocolInfo().setPipeline(this);
} }
@Override @Override
@ -61,17 +60,7 @@ public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements Prot
@Override @Override
public void init(UserConnection userConnection) { public void init(UserConnection userConnection) {
this.userConnection = userConnection; throw new UnsupportedOperationException("ProtocolPipeline can only be initialized once");
ProtocolInfo protocolInfo = new ProtocolInfoImpl(userConnection);
protocolInfo.setPipeline(this);
userConnection.setProtocolInfo(protocolInfo);
/* Init through all our pipes */
for (Protocol protocol : protocolList) {
protocol.init(userConnection);
}
} }
@Override @Override
@ -155,7 +144,9 @@ public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements Prot
@Override @Override
public boolean contains(Class<? extends Protocol> pipeClass) { public boolean contains(Class<? extends Protocol> pipeClass) {
for (Protocol protocol : protocolList) { for (Protocol protocol : protocolList) {
if (protocol.getClass().equals(pipeClass)) return true; if (protocol.getClass() == pipeClass) {
return true;
}
} }
return false; return false;
} }
@ -163,7 +154,9 @@ public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements Prot
@Override @Override
public @Nullable <P extends Protocol> P getProtocol(Class<P> pipeClass) { public @Nullable <P extends Protocol> P getProtocol(Class<P> pipeClass) {
for (Protocol protocol : protocolList) { for (Protocol protocol : protocolList) {
if (protocol.getClass() == pipeClass) return (P) protocol; if (protocol.getClass() == pipeClass) {
return (P) protocol;
}
} }
return null; return null;
} }
@ -187,7 +180,6 @@ public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements Prot
@Override @Override
public void cleanPipes() { public void cleanPipes() {
pipes().clear();
registerPackets(); registerPackets();
} }
} }

Datei anzeigen

@ -67,7 +67,7 @@ public class MappingData extends com.viaversion.viaversion.api.data.MappingData
// Remap infested blocks, as they are instantly breakabale in 1.13+ and can't be broken by those clients on older servers // Remap infested blocks, as they are instantly breakabale in 1.13+ and can't be broken by those clients on older servers
if (Via.getConfig().isInfestedBlocksFix()) { if (Via.getConfig().isInfestedBlocksFix()) {
short[] oldToNew = blockMappings.getOldToNew(); int[] oldToNew = blockMappings.getOldToNew();
oldToNew[1552] = 1; // stone oldToNew[1552] = 1; // stone
oldToNew[1553] = 14; // cobblestone oldToNew[1553] = 14; // cobblestone
oldToNew[1554] = 3983; // stone bricks oldToNew[1554] = 3983; // stone bricks