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