(1.2.1) Fixed various incompetent mistakes with the plugin
This commit is contained in:
parent
c6ac781036
commit
b25d4f0670
Binary file not shown.
|
@ -61,6 +61,8 @@ public class EaglerInitialHandler extends InitialHandler {
|
|||
private final int gameProtocolVersion;
|
||||
private final String username;
|
||||
private final UUID playerUUID;
|
||||
private final UUID playerUUIDOffline;
|
||||
private final UUID playerUUIDRewrite;
|
||||
private LoginResult loginResult;
|
||||
private final InetSocketAddress eaglerAddress;
|
||||
private final InetSocketAddress virtualHost;
|
||||
|
@ -79,12 +81,14 @@ public class EaglerInitialHandler extends InitialHandler {
|
|||
private static final Property[] NO_PROPERTIES = new Property[0];
|
||||
|
||||
public EaglerInitialHandler(BungeeCord bungee, EaglerListenerConfig listener, final ChannelWrapper ch,
|
||||
int gameProtocolVersion, String username, UUID playerUUID, InetSocketAddress address, String host,
|
||||
String origin, ClientCertificateHolder clientCertificate) {
|
||||
int gameProtocolVersion, String username, UUID playerUUID, UUID offlineUUID, InetSocketAddress address,
|
||||
String host, String origin, ClientCertificateHolder clientCertificate) {
|
||||
super(bungee, listener);
|
||||
this.gameProtocolVersion = gameProtocolVersion;
|
||||
this.username = username;
|
||||
this.playerUUID = playerUUID;
|
||||
this.playerUUIDOffline = offlineUUID;
|
||||
this.playerUUIDRewrite = bungee.config.isIpForward() ? playerUUID : offlineUUID;
|
||||
this.eaglerAddress = address;
|
||||
this.origin = origin;
|
||||
this.skinLookupRateLimiter = new SimpleRateLimiter();
|
||||
|
@ -127,6 +131,14 @@ public class EaglerInitialHandler extends InitialHandler {
|
|||
}
|
||||
}
|
||||
|
||||
public static UUID generateOfflineUUID(byte[] username) {
|
||||
String offlinePlayerStr = "OfflinePlayer:";
|
||||
byte[] uuidHashGenerator = new byte[offlinePlayerStr.length() + username.length];
|
||||
System.arraycopy(offlinePlayerStr.getBytes(StandardCharsets.US_ASCII), 0, uuidHashGenerator, 0, offlinePlayerStr.length());
|
||||
System.arraycopy(username, 0, uuidHashGenerator, offlinePlayerStr.length(), username.length);
|
||||
return UUID.nameUUIDFromBytes(uuidHashGenerator);
|
||||
}
|
||||
|
||||
void setLoginProfile(LoginResult obj) {
|
||||
this.loginResult = obj;
|
||||
try {
|
||||
|
@ -231,12 +243,12 @@ public class EaglerInitialHandler extends InitialHandler {
|
|||
|
||||
@Override
|
||||
public UUID getOfflineId() {
|
||||
return playerUUID;
|
||||
return playerUUIDOffline;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getRewriteId() {
|
||||
return playerUUID;
|
||||
return playerUUIDRewrite;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,7 +27,7 @@ public class EaglerMinecraftByteBufEncoder extends MessageToMessageEncoder<ByteB
|
|||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext var1, ByteBuf var2, List<Object> var3) throws Exception {
|
||||
var3.add(new BinaryWebSocketFrame(Unpooled.copiedBuffer(var2)));
|
||||
var3.add(new BinaryWebSocketFrame(var2.retain()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
|
|||
import io.netty.handler.codec.http.websocketx.PingWebSocketFrame;
|
||||
import io.netty.handler.codec.http.websocketx.PongWebSocketFrame;
|
||||
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.EaglerXBungee;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.server.bungeeprotocol.EaglerBungeeProtocol;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.server.bungeeprotocol.EaglerProtocolAccessProxy;
|
||||
|
@ -50,6 +51,7 @@ public class EaglerMinecraftDecoder extends MessageToMessageDecoder<WebSocketFra
|
|||
if(frame instanceof BinaryWebSocketFrame) {
|
||||
BinaryWebSocketFrame in = (BinaryWebSocketFrame) frame;
|
||||
ByteBuf buf = in.content();
|
||||
buf.markReaderIndex();
|
||||
int pktId = DefinedPacket.readVarInt(buf);
|
||||
DefinedPacket pkt = EaglerProtocolAccessProxy.createPacket(protocol, protocolVersion, pktId, server);
|
||||
Protocol bungeeProtocol = null;
|
||||
|
@ -72,9 +74,11 @@ public class EaglerMinecraftDecoder extends MessageToMessageDecoder<WebSocketFra
|
|||
EaglerXBungee.logger().severe("[DECODER][" + ctx.channel().remoteAddress() + "] Packet " +
|
||||
pkt.getClass().getSimpleName() + " had extra bytes! (" + buf.readableBytes() + ")");
|
||||
}else {
|
||||
buf.resetReaderIndex();
|
||||
out.add(this.wrapPacket(pkt, buf, bungeeProtocol));
|
||||
}
|
||||
}else {
|
||||
buf.resetReaderIndex();
|
||||
out.add(this.wrapPacket(null, buf, bungeeProtocol));
|
||||
}
|
||||
}else if(frame instanceof PingWebSocketFrame) {
|
||||
|
@ -103,46 +107,31 @@ public class EaglerMinecraftDecoder extends MessageToMessageDecoder<WebSocketFra
|
|||
this.protocolVersion = protocolVersion;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private PacketWrapper wrapPacket(DefinedPacket packet, ByteBuf buf, Protocol protocol) {
|
||||
ByteBuf cbuf = null;
|
||||
|
||||
PacketWrapper var7;
|
||||
try {
|
||||
cbuf = buf.copy(0, buf.writerIndex());
|
||||
PacketWrapper pkt;
|
||||
if (packetWrapperConstructor != null) {
|
||||
try {
|
||||
pkt = packetWrapperConstructor.newInstance(packet, cbuf);
|
||||
cbuf = null;
|
||||
return pkt;
|
||||
} catch (IllegalAccessException | InvocationTargetException | InstantiationException var14) {
|
||||
throw new RuntimeException(var14);
|
||||
}
|
||||
}
|
||||
|
||||
PacketWrapper pkt;
|
||||
if (packetWrapperConstructor != null) {
|
||||
try {
|
||||
pkt = new PacketWrapper(packet, cbuf, protocol);
|
||||
cbuf = null;
|
||||
pkt = packetWrapperConstructor.newInstance(packet, buf);
|
||||
buf.retain();
|
||||
return pkt;
|
||||
} catch (NoSuchMethodError var15) {
|
||||
try {
|
||||
packetWrapperConstructor = PacketWrapper.class.getDeclaredConstructor(DefinedPacket.class, ByteBuf.class);
|
||||
pkt = packetWrapperConstructor.newInstance(packet, cbuf);
|
||||
cbuf = null;
|
||||
var7 = pkt;
|
||||
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | InstantiationException var13) {
|
||||
throw new RuntimeException(var13);
|
||||
}
|
||||
} catch (IllegalAccessException | InvocationTargetException | InstantiationException var14) {
|
||||
throw new RuntimeException(var14);
|
||||
}
|
||||
} finally {
|
||||
if (cbuf != null) {
|
||||
cbuf.release();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return var7;
|
||||
try {
|
||||
pkt = new PacketWrapper(packet, buf, protocol);
|
||||
buf.retain();
|
||||
return pkt;
|
||||
} catch (NoSuchMethodError var15) {
|
||||
try {
|
||||
packetWrapperConstructor = PacketWrapper.class.getDeclaredConstructor(DefinedPacket.class, ByteBuf.class);
|
||||
pkt = packetWrapperConstructor.newInstance(packet, buf);
|
||||
buf.retain();
|
||||
return pkt;
|
||||
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | InstantiationException var13) {
|
||||
throw new RuntimeException(var13);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.lang.reflect.Method;
|
|||
import java.util.List;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToMessageEncoder;
|
||||
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
|
||||
|
@ -52,7 +51,7 @@ public class EaglerMinecraftEncoder extends MessageToMessageEncoder<DefinedPacke
|
|||
case STATUS:
|
||||
bungeeProtocol = Protocol.STATUS;
|
||||
}
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
ByteBuf buf = ctx.alloc().buffer();
|
||||
int pk = EaglerProtocolAccessProxy.getPacketId(protocol, protocolVersion, msg, server);
|
||||
DefinedPacket.writeVarInt(pk, buf);
|
||||
try {
|
||||
|
@ -65,11 +64,11 @@ public class EaglerMinecraftEncoder extends MessageToMessageEncoder<DefinedPacke
|
|||
meth.invoke(msg, buf, server ? Direction.TO_CLIENT : Direction.TO_SERVER, protocolVersion);
|
||||
} catch (Exception e1) {
|
||||
buf.release();
|
||||
buf = Unpooled.EMPTY_BUFFER;
|
||||
throw new RuntimeException("Could not call DefinedPacket write method!", e1);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
buf.release();
|
||||
buf = Unpooled.EMPTY_BUFFER;
|
||||
throw new RuntimeException("Could not call DefinedPacket write method!", e);
|
||||
}
|
||||
out.add(new BinaryWebSocketFrame(buf));
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import io.netty.handler.codec.http.HttpVersion;
|
|||
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
||||
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker;
|
||||
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.EaglerXBungee;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.config.EaglerListenerConfig;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.config.EaglerRateLimiter;
|
||||
|
@ -54,116 +55,120 @@ public class HttpHandshakeHandler extends ChannelInboundHandlerAdapter {
|
|||
}
|
||||
|
||||
public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
if (msg instanceof HttpRequest) {
|
||||
EaglerConnectionInstance pingTracker = ctx.channel().attr(EaglerPipeline.CONNECTION_INSTANCE).get();
|
||||
HttpRequest req = (HttpRequest) msg;
|
||||
HttpHeaders headers = req.headers();
|
||||
|
||||
String rateLimitHost = null;
|
||||
|
||||
if(conf.isForwardIp()) {
|
||||
String str = headers.get(conf.getForwardIpHeader());
|
||||
if(str != null) {
|
||||
rateLimitHost = str.split(",", 2)[0];
|
||||
try {
|
||||
ctx.channel().attr(EaglerPipeline.REAL_ADDRESS).set(InetAddress.getByName(rateLimitHost));
|
||||
}catch(UnknownHostException ex) {
|
||||
EaglerXBungee.logger().warning("[" + ctx.channel().remoteAddress() + "]: Connected with an invalid '" + conf.getForwardIpHeader() + "' header, disconnecting...");
|
||||
try {
|
||||
if (msg instanceof HttpRequest) {
|
||||
EaglerConnectionInstance pingTracker = ctx.channel().attr(EaglerPipeline.CONNECTION_INSTANCE).get();
|
||||
HttpRequest req = (HttpRequest) msg;
|
||||
HttpHeaders headers = req.headers();
|
||||
|
||||
String rateLimitHost = null;
|
||||
|
||||
if(conf.isForwardIp()) {
|
||||
String str = headers.get(conf.getForwardIpHeader());
|
||||
if(str != null) {
|
||||
rateLimitHost = str.split(",", 2)[0];
|
||||
try {
|
||||
ctx.channel().attr(EaglerPipeline.REAL_ADDRESS).set(InetAddress.getByName(rateLimitHost));
|
||||
}catch(UnknownHostException ex) {
|
||||
EaglerXBungee.logger().warning("[" + ctx.channel().remoteAddress() + "]: Connected with an invalid '" + conf.getForwardIpHeader() + "' header, disconnecting...");
|
||||
ctx.close();
|
||||
return;
|
||||
}
|
||||
}else {
|
||||
EaglerXBungee.logger().warning("[" + ctx.channel().remoteAddress() + "]: Connected without a '" + conf.getForwardIpHeader() + "' header, disconnecting...");
|
||||
ctx.close();
|
||||
return;
|
||||
}
|
||||
}else {
|
||||
SocketAddress addr = ctx.channel().remoteAddress();
|
||||
if(addr instanceof InetSocketAddress) {
|
||||
rateLimitHost = ((InetSocketAddress) addr).getAddress().getHostAddress();
|
||||
}
|
||||
}
|
||||
|
||||
EaglerRateLimiter ipRateLimiter = conf.getRatelimitIp();
|
||||
RateLimitStatus ipRateLimit = RateLimitStatus.OK;
|
||||
|
||||
if(ipRateLimiter != null && rateLimitHost != null) {
|
||||
ipRateLimit = ipRateLimiter.rateLimit(rateLimitHost);
|
||||
}
|
||||
|
||||
if(ipRateLimit == RateLimitStatus.LOCKED_OUT) {
|
||||
ctx.close();
|
||||
return;
|
||||
}
|
||||
}else {
|
||||
EaglerXBungee.logger().warning("[" + ctx.channel().remoteAddress() + "]: Connected without a '" + conf.getForwardIpHeader() + "' header, disconnecting...");
|
||||
ctx.close();
|
||||
return;
|
||||
}
|
||||
}else {
|
||||
SocketAddress addr = ctx.channel().remoteAddress();
|
||||
if(addr instanceof InetSocketAddress) {
|
||||
rateLimitHost = ((InetSocketAddress) addr).getAddress().getHostAddress();
|
||||
}
|
||||
}
|
||||
|
||||
EaglerRateLimiter ipRateLimiter = conf.getRatelimitIp();
|
||||
RateLimitStatus ipRateLimit = RateLimitStatus.OK;
|
||||
|
||||
if(ipRateLimiter != null && rateLimitHost != null) {
|
||||
ipRateLimit = ipRateLimiter.rateLimit(rateLimitHost);
|
||||
}
|
||||
|
||||
if(ipRateLimit == RateLimitStatus.LOCKED_OUT) {
|
||||
ctx.close();
|
||||
return;
|
||||
}
|
||||
|
||||
if(headers.get(HttpHeaderNames.CONNECTION) != null && headers.get(HttpHeaderNames.CONNECTION).toLowerCase().contains("upgrade") &&
|
||||
"websocket".equalsIgnoreCase(headers.get(HttpHeaderNames.UPGRADE))) {
|
||||
|
||||
String origin = headers.get(HttpHeaderNames.ORIGIN);
|
||||
if(origin != null) {
|
||||
ctx.channel().attr(EaglerPipeline.ORIGIN).set(origin);
|
||||
}
|
||||
|
||||
//TODO: origin blacklist
|
||||
|
||||
if(ipRateLimit == RateLimitStatus.OK) {
|
||||
ctx.channel().attr(EaglerPipeline.HOST).set(headers.get(HttpHeaderNames.HOST));
|
||||
ctx.pipeline().replace(this, "HttpWebSocketHandler", new HttpWebSocketHandler(conf));
|
||||
}
|
||||
|
||||
WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(
|
||||
"ws://" + headers.get(HttpHeaderNames.HOST) + req.uri(), null, true, 0xFFFFF);
|
||||
WebSocketServerHandshaker hs = wsFactory.newHandshaker(req);
|
||||
if(hs != null) {
|
||||
pingTracker.isWebSocket = true;
|
||||
ChannelFuture future = hs.handshake(ctx.channel(), req);
|
||||
if(ipRateLimit != RateLimitStatus.OK) {
|
||||
final RateLimitStatus rateLimitTypeFinal = ipRateLimit;
|
||||
future.addListener(new ChannelFutureListener() {
|
||||
@Override
|
||||
public void operationComplete(ChannelFuture paramF) throws Exception {
|
||||
ctx.writeAndFlush(new TextWebSocketFrame(
|
||||
rateLimitTypeFinal == RateLimitStatus.LIMITED_NOW_LOCKED_OUT ? "LOCKED" : "BLOCKED"))
|
||||
.addListener(ChannelFutureListener.CLOSE);
|
||||
|
||||
if(headers.get(HttpHeaderNames.CONNECTION) != null && headers.get(HttpHeaderNames.CONNECTION).toLowerCase().contains("upgrade") &&
|
||||
"websocket".equalsIgnoreCase(headers.get(HttpHeaderNames.UPGRADE))) {
|
||||
|
||||
String origin = headers.get(HttpHeaderNames.ORIGIN);
|
||||
if(origin != null) {
|
||||
ctx.channel().attr(EaglerPipeline.ORIGIN).set(origin);
|
||||
}
|
||||
|
||||
//TODO: origin blacklist
|
||||
|
||||
if(ipRateLimit == RateLimitStatus.OK) {
|
||||
ctx.channel().attr(EaglerPipeline.HOST).set(headers.get(HttpHeaderNames.HOST));
|
||||
ctx.pipeline().replace(this, "HttpWebSocketHandler", new HttpWebSocketHandler(conf));
|
||||
}
|
||||
|
||||
WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(
|
||||
"ws://" + headers.get(HttpHeaderNames.HOST) + req.uri(), null, true, 0xFFFFF);
|
||||
WebSocketServerHandshaker hs = wsFactory.newHandshaker(req);
|
||||
if(hs != null) {
|
||||
pingTracker.isWebSocket = true;
|
||||
ChannelFuture future = hs.handshake(ctx.channel(), req);
|
||||
if(ipRateLimit != RateLimitStatus.OK) {
|
||||
final RateLimitStatus rateLimitTypeFinal = ipRateLimit;
|
||||
future.addListener(new ChannelFutureListener() {
|
||||
@Override
|
||||
public void operationComplete(ChannelFuture paramF) throws Exception {
|
||||
ctx.writeAndFlush(new TextWebSocketFrame(
|
||||
rateLimitTypeFinal == RateLimitStatus.LIMITED_NOW_LOCKED_OUT ? "LOCKED" : "BLOCKED"))
|
||||
.addListener(ChannelFutureListener.CLOSE);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}else {
|
||||
WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel()).addListener(ChannelFutureListener.CLOSE);
|
||||
}
|
||||
}else {
|
||||
if(ipRateLimit != RateLimitStatus.OK) {
|
||||
ByteBuf error429Buffer = ctx.alloc().buffer(error429Bytes.length, error429Bytes.length);
|
||||
error429Buffer.writeBytes(error429Bytes);
|
||||
DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.TOO_MANY_REQUESTS, error429Buffer);
|
||||
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
|
||||
return;
|
||||
}
|
||||
pingTracker.isRegularHttp = true;
|
||||
HttpWebServer srv = conf.getWebServer();
|
||||
if(srv != null) {
|
||||
String uri = req.uri();
|
||||
if(uri.startsWith("/")) {
|
||||
uri = uri.substring(1);
|
||||
}
|
||||
int j = uri.indexOf('?');
|
||||
if(j != -1) {
|
||||
uri = uri.substring(0, j);
|
||||
}
|
||||
HttpMemoryCache ch = srv.retrieveFile(uri);
|
||||
if(ch != null) {
|
||||
ctx.writeAndFlush(ch.createHTTPResponse()).addListener(ChannelFutureListener.CLOSE);
|
||||
}else {
|
||||
WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel()).addListener(ChannelFutureListener.CLOSE);
|
||||
}
|
||||
}else {
|
||||
ctx.writeAndFlush(HttpWebServer.getWebSocket404().createHTTPResponse(HttpResponseStatus.NOT_FOUND))
|
||||
.addListener(ChannelFutureListener.CLOSE);
|
||||
if(ipRateLimit != RateLimitStatus.OK) {
|
||||
ByteBuf error429Buffer = ctx.alloc().buffer(error429Bytes.length, error429Bytes.length);
|
||||
error429Buffer.writeBytes(error429Bytes);
|
||||
DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.TOO_MANY_REQUESTS, error429Buffer);
|
||||
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
|
||||
return;
|
||||
}
|
||||
pingTracker.isRegularHttp = true;
|
||||
HttpWebServer srv = conf.getWebServer();
|
||||
if(srv != null) {
|
||||
String uri = req.uri();
|
||||
if(uri.startsWith("/")) {
|
||||
uri = uri.substring(1);
|
||||
}
|
||||
int j = uri.indexOf('?');
|
||||
if(j != -1) {
|
||||
uri = uri.substring(0, j);
|
||||
}
|
||||
HttpMemoryCache ch = srv.retrieveFile(uri);
|
||||
if(ch != null) {
|
||||
ctx.writeAndFlush(ch.createHTTPResponse()).addListener(ChannelFutureListener.CLOSE);
|
||||
}else {
|
||||
ctx.writeAndFlush(HttpWebServer.getWebSocket404().createHTTPResponse(HttpResponseStatus.NOT_FOUND))
|
||||
.addListener(ChannelFutureListener.CLOSE);
|
||||
}
|
||||
}else {
|
||||
ctx.writeAndFlush(HttpWebServer.getWebSocket404().createHTTPResponse(HttpResponseStatus.NOT_FOUND))
|
||||
.addListener(ChannelFutureListener.CLOSE);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
ctx.writeAndFlush(HttpWebServer.getWebSocket404().createHTTPResponse(HttpResponseStatus.NOT_FOUND))
|
||||
.addListener(ChannelFutureListener.CLOSE);
|
||||
}
|
||||
}else {
|
||||
ctx.close();
|
||||
}
|
||||
}else {
|
||||
ctx.close();
|
||||
}finally {
|
||||
ReferenceCountUtil.release(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import io.netty.handler.codec.http.websocketx.PingWebSocketFrame;
|
|||
import io.netty.handler.codec.http.websocketx.PongWebSocketFrame;
|
||||
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
||||
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.EaglerXBungee;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.config.EaglerListenerConfig;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.server.query.QueryManager;
|
||||
|
@ -123,18 +124,22 @@ public abstract class HttpServerQueryHandler extends ChannelInboundHandlerAdapte
|
|||
}
|
||||
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
if(msg instanceof WebSocketFrame) {
|
||||
if(msg instanceof BinaryWebSocketFrame) {
|
||||
handleBinary(ctx, ((BinaryWebSocketFrame)msg).content());
|
||||
}else if(msg instanceof TextWebSocketFrame) {
|
||||
handleText(ctx, ((TextWebSocketFrame)msg).text());
|
||||
}else if(msg instanceof PingWebSocketFrame) {
|
||||
ctx.writeAndFlush(new PongWebSocketFrame());
|
||||
}else if(msg instanceof CloseWebSocketFrame) {
|
||||
ctx.close();
|
||||
try {
|
||||
if(msg instanceof WebSocketFrame) {
|
||||
if(msg instanceof BinaryWebSocketFrame) {
|
||||
handleBinary(ctx, ((BinaryWebSocketFrame)msg).content());
|
||||
}else if(msg instanceof TextWebSocketFrame) {
|
||||
handleText(ctx, ((TextWebSocketFrame)msg).text());
|
||||
}else if(msg instanceof PingWebSocketFrame) {
|
||||
ctx.writeAndFlush(new PongWebSocketFrame());
|
||||
}else if(msg instanceof CloseWebSocketFrame) {
|
||||
ctx.close();
|
||||
}
|
||||
}else {
|
||||
EaglerXBungee.logger().severe("Unexpected Packet: " + msg.getClass().getSimpleName());
|
||||
}
|
||||
}else {
|
||||
EaglerXBungee.logger().severe("Unexpected Packet: " + msg.getClass().getSimpleName());
|
||||
}finally {
|
||||
ReferenceCountUtil.release(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,15 +205,11 @@ public abstract class HttpServerQueryHandler extends ChannelInboundHandlerAdapte
|
|||
}
|
||||
|
||||
public void sendBinaryResponse(byte[] bytes) {
|
||||
ByteBuf buf = Unpooled.buffer(bytes.length, bytes.length);
|
||||
buf.writeBytes(bytes);
|
||||
context.writeAndFlush(new BinaryWebSocketFrame(buf));
|
||||
context.writeAndFlush(new BinaryWebSocketFrame(Unpooled.wrappedBuffer(bytes)));
|
||||
}
|
||||
|
||||
public void sendBinaryResponseAndClose(byte[] bytes) {
|
||||
ByteBuf buf = Unpooled.buffer(bytes.length, bytes.length);
|
||||
buf.writeBytes(bytes);
|
||||
context.writeAndFlush(new BinaryWebSocketFrame(buf)).addListener(ChannelFutureListener.CLOSE);
|
||||
context.writeAndFlush(new BinaryWebSocketFrame(Unpooled.wrappedBuffer(bytes))).addListener(ChannelFutureListener.CLOSE);
|
||||
}
|
||||
|
||||
public void setKeepAlive(boolean enable) {
|
||||
|
|
|
@ -35,6 +35,7 @@ import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
|||
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
|
||||
import io.netty.handler.timeout.ReadTimeoutHandler;
|
||||
import io.netty.handler.timeout.WriteTimeoutHandler;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.concurrent.GenericFutureListener;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.EaglerXBungee;
|
||||
|
@ -106,6 +107,7 @@ public class HttpWebSocketHandler extends ChannelInboundHandlerAdapter {
|
|||
private CharSequence clientVersionString;
|
||||
private CharSequence clientUsername;
|
||||
private UUID clientUUID;
|
||||
private UUID offlineUUID;
|
||||
private CharSequence clientRequestedServer;
|
||||
private boolean clientAuth;
|
||||
private byte[] clientAuthUsername;
|
||||
|
@ -125,18 +127,22 @@ public class HttpWebSocketHandler extends ChannelInboundHandlerAdapter {
|
|||
}
|
||||
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
if(msg instanceof WebSocketFrame) {
|
||||
if(msg instanceof BinaryWebSocketFrame) {
|
||||
handleBinary(ctx, ((BinaryWebSocketFrame)msg).content());
|
||||
}else if(msg instanceof TextWebSocketFrame) {
|
||||
handleText(ctx, ((TextWebSocketFrame)msg).text());
|
||||
}else if(msg instanceof PingWebSocketFrame) {
|
||||
ctx.writeAndFlush(new PongWebSocketFrame());
|
||||
}else if(msg instanceof CloseWebSocketFrame) {
|
||||
ctx.close();
|
||||
try {
|
||||
if(msg instanceof WebSocketFrame) {
|
||||
if(msg instanceof BinaryWebSocketFrame) {
|
||||
handleBinary(ctx, ((BinaryWebSocketFrame)msg).content());
|
||||
}else if(msg instanceof TextWebSocketFrame) {
|
||||
handleText(ctx, ((TextWebSocketFrame)msg).text());
|
||||
}else if(msg instanceof PingWebSocketFrame) {
|
||||
ctx.writeAndFlush(new PongWebSocketFrame());
|
||||
}else if(msg instanceof CloseWebSocketFrame) {
|
||||
ctx.close();
|
||||
}
|
||||
}else {
|
||||
EaglerXBungee.logger().severe("Unexpected Packet: " + msg.getClass().getSimpleName());
|
||||
}
|
||||
}else {
|
||||
EaglerXBungee.logger().severe("Unexpected Packet: " + msg.getClass().getSimpleName());
|
||||
}finally {
|
||||
ReferenceCountUtil.release(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -557,11 +563,7 @@ public class HttpWebSocketHandler extends ChannelInboundHandlerAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
String offlinePlayerStr = "OfflinePlayer:";
|
||||
byte[] uuidHashGenerator = new byte[offlinePlayerStr.length() + clientAuthUsername.length];
|
||||
System.arraycopy(offlinePlayerStr.getBytes(StandardCharsets.US_ASCII), 0, uuidHashGenerator, 0, offlinePlayerStr.length());
|
||||
System.arraycopy(clientAuthUsername, 0, uuidHashGenerator, offlinePlayerStr.length(), clientAuthUsername.length);
|
||||
clientUUID = UUID.nameUUIDFromBytes(uuidHashGenerator);
|
||||
clientUUID = offlineUUID = EaglerInitialHandler.generateOfflineUUID(clientAuthUsername);
|
||||
|
||||
strlen = buffer.readUnsignedByte();
|
||||
clientRequestedServer = buffer.readCharSequence(strlen, StandardCharsets.US_ASCII);
|
||||
|
@ -775,7 +777,7 @@ public class HttpWebSocketHandler extends ChannelInboundHandlerAdapter {
|
|||
}
|
||||
}
|
||||
final EaglerInitialHandler initialHandler = new EaglerInitialHandler(bungee, conf, ch, gameProtocolVersion,
|
||||
usernameStr, clientUUID, baseAddress, ctx.channel().attr(EaglerPipeline.HOST).get(),
|
||||
usernameStr, clientUUID, offlineUUID, baseAddress, ctx.channel().attr(EaglerPipeline.HOST).get(),
|
||||
ctx.channel().attr(EaglerPipeline.ORIGIN).get(), cert);
|
||||
if(!blockUpdate) {
|
||||
List<ClientCertificateHolder> set = EaglerUpdateSvc.getCertList();
|
||||
|
|
|
@ -65,7 +65,7 @@ public class HttpMemoryCache {
|
|||
}
|
||||
|
||||
public DefaultFullHttpResponse createHTTPResponse(HttpResponseStatus code) {
|
||||
DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, code, Unpooled.copiedBuffer(fileData));
|
||||
DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, code, Unpooled.wrappedBuffer(fileData.retain()));
|
||||
HttpHeaders responseHeaders = response.headers();
|
||||
Date d = new Date();
|
||||
responseHeaders.add(HttpHeaderNames.CONTENT_TYPE, contentType.httpHeader);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: EaglercraftXBungee
|
||||
main: net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.EaglerXBungee
|
||||
version: 1.2.0
|
||||
version: 1.2.1
|
||||
description: Plugin to allow EaglercraftX 1.8 players to join your network, or allow EaglercraftX 1.8 players to use your network as a proxy to join other networks
|
||||
author: lax1dude
|
|
@ -1 +1 @@
|
|||
1.2.0
|
||||
1.2.1
|
Loading…
Reference in New Issue
Block a user