Archiviert
13
0

Restore backwards compatibility, restructure poms

Dieser Commit ist enthalten in:
Dan Mulloy 2017-05-18 12:02:47 -04:00
Ursprung b00ae2ff15
Commit f99b977888
10 geänderte Dateien mit 109 neuen und 132 gelöschten Zeilen

Datei anzeigen

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>ProtocolLib-API</artifactId> <artifactId>ProtocolLib-API</artifactId>
<name>ProtocolLib-API</name> <name>ProtocolLib-API</name>
<version>4.3.0-SNAPSHOT</version> <version>${minorVersion}</version>
<description>Provides read/write access to the Minecraft protocol.</description> <description>Provides read/write access to the Minecraft protocol.</description>
<url>http://www.spigotmc.org/resources/protocollib.1997/</url> <url>http://www.spigotmc.org/resources/protocollib.1997/</url>
@ -20,6 +20,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.number></project.build.number> <project.build.number></project.build.number>
<project.fullVersion>${project.version}</project.fullVersion> <project.fullVersion>${project.version}</project.fullVersion>
<spigotVersion>1.12-pre2-SNAPSHOT</spigotVersion>
</properties> </properties>
<build> <build>
@ -191,62 +192,4 @@
<timezone>1</timezone> <timezone>1</timezone>
</developer> </developer>
</developers> </developers>
<dependencies>
<!-- Included with Minecraft
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.0.23.Final</version>
</dependency>
-->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>${spigotVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>${spigotVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.2.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.comphenix.executors</groupId>
<artifactId>BukkitExecutors</artifactId>
<version>1.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.5</version>
<scope>test</scope>
</dependency>
</dependencies>
</project> </project>

Datei anzeigen

@ -45,6 +45,7 @@ import com.google.common.io.ByteStreams;
* all indexing in the byte buffer. * all indexing in the byte buffer.
* @author Kristian * @author Kristian
*/ */
@SuppressWarnings("unused")
public class NettyByteBufAdapter extends AbstractByteBuf { public class NettyByteBufAdapter extends AbstractByteBuf {
private DataInputStream input; private DataInputStream input;
private DataOutputStream output; private DataOutputStream output;

Datei anzeigen

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>ProtocolLib</artifactId> <artifactId>ProtocolLib</artifactId>
<name>ProtocolLib</name> <name>ProtocolLib</name>
<version>4.3.0-SNAPSHOT</version> <version>${minorVersion}</version>
<description>Provides read/write access to the Minecraft protocol.</description> <description>Provides read/write access to the Minecraft protocol.</description>
<url>http://www.spigotmc.org/resources/protocollib.1997/</url> <url>http://www.spigotmc.org/resources/protocollib.1997/</url>
@ -63,6 +63,7 @@
<exclude>org.spigotmc:spigot</exclude> <exclude>org.spigotmc:spigot</exclude>
<exclude>org.spigotmc:spigot-api</exclude> <exclude>org.spigotmc:spigot-api</exclude>
<exclude>junit:junit</exclude> <exclude>junit:junit</exclude>
<exclude>io.netty:*</exclude>
</excludes> </excludes>
</artifactSet> </artifactSet>
</configuration> </configuration>
@ -230,38 +231,10 @@
<groupId>com.comphenix.protocol</groupId> <groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib-API</artifactId> <artifactId>ProtocolLib-API</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency>
<!-- Included with Minecraft
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.0.23.Final</version>
</dependency>
-->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>${spigotVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>${spigotVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.2.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.comphenix.executors</groupId>
<artifactId>BukkitExecutors</artifactId>
<version>1.1-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<!-- Testing dependencies -->
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>

Datei anzeigen

@ -66,6 +66,7 @@ import io.netty.channel.ChannelPromise;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder; import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.util.AttributeKey;
import io.netty.util.concurrent.GenericFutureListener; import io.netty.util.concurrent.GenericFutureListener;
import io.netty.util.internal.TypeParameterMatcher; import io.netty.util.internal.TypeParameterMatcher;
@ -89,6 +90,10 @@ public class ChannelInjector extends ByteToMessageDecoder implements Injector {
private static Class<?> PACKET_LOGIN_CLIENT = null; private static Class<?> PACKET_LOGIN_CLIENT = null;
private static FieldAccessor LOGIN_GAME_PROFILE = null; private static FieldAccessor LOGIN_GAME_PROFILE = null;
// Versioning
private static Class<?> PACKET_SET_PROTOCOL = null;
private static AttributeKey<Integer> PROTOCOL_KEY = AttributeKey.valueOf("PROTOCOL");
// Saved accessors // Saved accessors
private static MethodAccessor DECODE_BUFFER; private static MethodAccessor DECODE_BUFFER;
private static MethodAccessor ENCODE_BUFFER; private static MethodAccessor ENCODE_BUFFER;
@ -97,9 +102,6 @@ public class ChannelInjector extends ByteToMessageDecoder implements Injector {
// For retrieving the protocol // For retrieving the protocol
private static FieldAccessor PROTOCOL_ACCESSOR; private static FieldAccessor PROTOCOL_ACCESSOR;
// For retrieving the protocol version
private static MethodAccessor PROTOCOL_VERSION;
// The factory that created this injector // The factory that created this injector
private InjectionFactory factory; private InjectionFactory factory;
@ -184,19 +186,8 @@ public class ChannelInjector extends ByteToMessageDecoder implements Injector {
*/ */
@Override @Override
public int getProtocolVersion() { public int getProtocolVersion() {
MethodAccessor accessor = PROTOCOL_VERSION; Integer value = originalChannel.attr(PROTOCOL_KEY).get();
if (accessor == null) { return value != null ? value : MinecraftProtocolVersion.getCurrentVersion();
try {
accessor = Accessors.getMethodAccessor(networkManager.getClass(), "getVersion");
} catch (Throwable ex) {
}
}
if (accessor != null) {
return (Integer) accessor.invoke(networkManager);
} else {
return MinecraftProtocolVersion.getCurrentVersion();
}
} }
@Override @Override
@ -279,6 +270,7 @@ public class ChannelInjector extends ByteToMessageDecoder implements Injector {
originalChannel.pipeline().addBefore("protocol_lib_decoder", "protocol_lib_finish", finishHandler); originalChannel.pipeline().addBefore("protocol_lib_decoder", "protocol_lib_finish", finishHandler);
originalChannel.pipeline().addAfter("encoder", "protocol_lib_encoder", protocolEncoder); originalChannel.pipeline().addAfter("encoder", "protocol_lib_encoder", protocolEncoder);
try {
// Intercept all write methods // Intercept all write methods
channelField.setValue(new ChannelProxy(originalChannel, MinecraftReflection.getPacketClass()) { channelField.setValue(new ChannelProxy(originalChannel, MinecraftReflection.getPacketClass()) {
// Compatibility with Spigot 1.8 // Compatibility with Spigot 1.8
@ -370,6 +362,9 @@ public class ChannelInjector extends ByteToMessageDecoder implements Injector {
return event != null ? event : BYPASSED_PACKET; return event != null ? event : BYPASSED_PACKET;
} }
}); });
} catch (Throwable ex) {
throw new RuntimeException("Failed to overwrite channel field", ex);
}
injected = true; injected = true;
return true; return true;
@ -602,6 +597,26 @@ public class ChannelInjector extends ByteToMessageDecoder implements Injector {
// Save the channel injector // Save the channel injector
factory.cacheInjector(profile.getName(), this); factory.cacheInjector(profile.getName(), this);
} }
if (PACKET_SET_PROTOCOL == null) {
try {
PACKET_SET_PROTOCOL = PacketType.Handshake.Client.SET_PROTOCOL.getPacketClass();
} catch (Throwable ex) {
ex.printStackTrace(); // TODO debug
PACKET_SET_PROTOCOL = getClass(); // If we can't find it don't worry about it
}
}
if (PACKET_SET_PROTOCOL.equals(packetClass)) {
FuzzyReflection fuzzy = FuzzyReflection.fromObject(packet);
try {
int protocol = (int) fuzzy.invokeMethod(packet, "getProtocol", int.class);
System.out.println("Determined protocol " + protocol);
originalChannel.attr(PROTOCOL_KEY).set(protocol);
} catch (Throwable ex) {
ex.printStackTrace(); // TODO debug
}
}
} }
@Override @Override

Datei anzeigen

@ -16,19 +16,6 @@
*/ */
package com.comphenix.protocol.injector.netty; package com.comphenix.protocol.injector.netty;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.Channel;
import io.netty.channel.ChannelConfig;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelId;
import io.netty.channel.ChannelMetadata;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelProgressivePromise;
import io.netty.channel.ChannelPromise;
import io.netty.channel.EventLoop;
import io.netty.util.Attribute;
import io.netty.util.AttributeKey;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.util.Map; import java.util.Map;
@ -38,6 +25,18 @@ import com.comphenix.protocol.reflect.accessors.Accessors;
import com.comphenix.protocol.reflect.accessors.FieldAccessor; import com.comphenix.protocol.reflect.accessors.FieldAccessor;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.Channel;
import io.netty.channel.ChannelConfig;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelMetadata;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelProgressivePromise;
import io.netty.channel.ChannelPromise;
import io.netty.channel.EventLoop;
import io.netty.util.Attribute;
import io.netty.util.AttributeKey;
public abstract class ChannelProxy implements Channel { public abstract class ChannelProxy implements Channel {
// Mark that a certain object does not contain a message field // Mark that a certain object does not contain a message field
private static final FieldAccessor MARK_NO_MESSAGE = new FieldAccessor() { private static final FieldAccessor MARK_NO_MESSAGE = new FieldAccessor() {
@ -333,6 +332,7 @@ public abstract class ChannelProxy implements Channel {
return delegate.compareTo(o); return delegate.compareTo(o);
} }
/* Added in Netty 4.1, seem to be unused
public long bytesBeforeUnwritable() { public long bytesBeforeUnwritable() {
return delegate.bytesBeforeUnwritable(); return delegate.bytesBeforeUnwritable();
} }
@ -348,4 +348,5 @@ public abstract class ChannelProxy implements Channel {
public <T> boolean hasAttr(AttributeKey<T> key) { public <T> boolean hasAttr(AttributeKey<T> key) {
return delegate.hasAttr(key); return delegate.hasAttr(key);
} }
*/
} }

Datei anzeigen

@ -257,7 +257,9 @@ abstract class EventLoopProxy implements EventLoop {
return getDelegate().shutdownNow(); return getDelegate().shutdownNow();
} }
/*
public ChannelFuture register(ChannelPromise promise) { public ChannelFuture register(ChannelPromise promise) {
return getDelegate().register(promise); return getDelegate().register(promise);
} }
*/
} }

Datei anzeigen

@ -16,21 +16,20 @@
*/ */
package com.comphenix.protocol.injector.netty; package com.comphenix.protocol.injector.netty;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelProgressivePromise;
import io.netty.channel.ChannelPromise;
import io.netty.util.concurrent.EventExecutorGroup;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelPromise;
import io.netty.util.concurrent.EventExecutorGroup;
/** /**
* A pipeline proxy. * A pipeline proxy.
* @author Kristian * @author Kristian
@ -370,6 +369,7 @@ public class PipelineProxy implements ChannelPipeline {
return pipeline.writeAndFlush(arg0); return pipeline.writeAndFlush(arg0);
} }
/* Added in Netty 4.1, seem to be unused
public ChannelFuture newFailedFuture(Throwable ex) { public ChannelFuture newFailedFuture(Throwable ex) {
return pipeline.newFailedFuture(ex); return pipeline.newFailedFuture(ex);
} }
@ -389,4 +389,5 @@ public class PipelineProxy implements ChannelPipeline {
public ChannelPromise voidPromise() { public ChannelPromise voidPromise() {
return pipeline.voidPromise(); return pipeline.voidPromise();
} }
*/
} }

Datei anzeigen

@ -48,6 +48,7 @@ import com.comphenix.protocol.injector.spigot.AbstractPlayerHandler;
import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.reflect.FuzzyReflection;
import com.comphenix.protocol.reflect.VolatileField; import com.comphenix.protocol.reflect.VolatileField;
import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftReflection;
import com.comphenix.protocol.utility.MinecraftVersion;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import io.netty.channel.Channel; import io.netty.channel.Channel;
@ -142,10 +143,15 @@ public class ProtocolInjector implements ChannelListener {
@Override @Override
protected void initChannel(final Channel channel) throws Exception { protected void initChannel(final Channel channel) throws Exception {
try { try {
// TODO I don't like this
synchronized (networkManagers) { synchronized (networkManagers) {
channel.eventLoop().submit(() -> // For some reason it needs to be delayed on 1.12, but the delay breaks 1.11 and below
injectionFactory.fromChannel(channel, ProtocolInjector.this, playerFactory).inject()); // TODO I see this more as a temporary hotfix than a permanent solution
if (MinecraftVersion.getCurrentVersion().getMinor() >= 12) {
channel.eventLoop().submit(() ->
injectionFactory.fromChannel(channel, ProtocolInjector.this, playerFactory).inject());
} else {
injectionFactory.fromChannel(channel, ProtocolInjector.this, playerFactory).inject();
}
} }
} catch (Exception e) { } catch (Exception e) {
reporter.reportDetailed(ProtocolInjector.this, Report.newBuilder(REPORT_CANNOT_INJECT_INCOMING_CHANNEL).messageParam(channel).error(e)); reporter.reportDetailed(ProtocolInjector.this, Report.newBuilder(REPORT_CANNOT_INJECT_INCOMING_CHANNEL).messageParam(channel).error(e));

Datei anzeigen

@ -63,7 +63,7 @@ public class BukkitInitialization {
packaged = true; packaged = true;
MinecraftReflection.setMinecraftPackage(Constants.NMS, Constants.OBC); MinecraftReflection.setMinecraftPackage(Constants.NMS, Constants.OBC);
MinecraftVersion.setCurrentVersion(MinecraftVersion.FROSTBURN_UPDATE); MinecraftVersion.setCurrentVersion(MinecraftVersion.COLOR_UPDATE);
} }
} }
} }

35
pom.xml
Datei anzeigen

@ -8,6 +8,7 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<minorVersion>4.3.0-SNAPSHOT</minorVersion>
<spigotVersion>1.12-pre2-SNAPSHOT</spigotVersion> <spigotVersion>1.12-pre2-SNAPSHOT</spigotVersion>
</properties> </properties>
@ -42,6 +43,40 @@
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url> <url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository> </repository>
</repositories> </repositories>
<dependencies>
<!-- Compile with the old version of Netty -->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.0.23.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>${spigotVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>${spigotVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.2.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.comphenix.executors</groupId>
<artifactId>BukkitExecutors</artifactId>
<version>1.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build> <build>
<defaultGoal>clean package install</defaultGoal> <defaultGoal>clean package install</defaultGoal>