(1.0.5) Fixed max_players config option in EaglerXBungee

This commit is contained in:
LAX1DUDE 2023-02-19 00:21:25 -08:00
parent 104abbbb83
commit fecc10c8b4
7 changed files with 72 additions and 4 deletions

View File

@ -1,6 +1,7 @@
package net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.handlers;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.logging.Level;
import org.apache.commons.codec.binary.Base64;
@ -19,6 +20,7 @@ import net.md_5.bungee.UserConnection;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.api.event.PostLoginEvent;
@ -71,6 +73,16 @@ public class EaglerPacketEventListener implements Listener {
event.getSender().disconnect(new TextComponent("Cannot send \"" + SkinService.CHANNEL + "\" on a non-eagler connection!"));
}
}
}else if(event.getSender() instanceof Server && event.getReceiver() instanceof UserConnection) {
UserConnection player = (UserConnection)event.getReceiver();
if("EAG|GetDomain".equals(event.getTag()) && player.getPendingConnection() instanceof EaglerInitialHandler) {
String domain = ((EaglerInitialHandler)player.getPendingConnection()).getOrigin();
if(domain == null) {
((Server)event.getSender()).sendData("EAG|Domain", new byte[] { 0 });
}else {
((Server)event.getSender()).sendData("EAG|Domain", domain.getBytes(StandardCharsets.UTF_8));
}
}
}
}

View File

@ -223,4 +223,8 @@ public class EaglerInitialHandler extends InitialHandler {
return eaglerUnsafe;
}
public String getOrigin() {
return origin;
}
}

View File

@ -5,6 +5,7 @@ import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.util.logging.Level;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelFuture;
@ -167,7 +168,7 @@ public class HttpHandshakeHandler extends ChannelInboundHandlerAdapter {
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if (ctx.channel().isActive()) {
EaglerXBungee.logger().severe("[" + ctx.channel().remoteAddress() + "]: Exception Caught: " + cause.toString());
EaglerXBungee.logger().log(Level.WARNING, "[Pre][" + ctx.channel().remoteAddress() + "]: Exception Caught: " + cause.toString(), cause);
ctx.close();
}
}

View File

@ -135,7 +135,7 @@ public class HttpWebSocketHandler extends ChannelInboundHandlerAdapter {
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if (ctx.channel().isActive()) {
EaglerXBungee.logger().warning("[" + ctx.channel().remoteAddress() + "]: Exception Caught: " + cause.toString());
EaglerXBungee.logger().warning("[Yee][" + ctx.channel().remoteAddress() + "]: Exception Caught: " + cause.toString());
}
}
@ -153,6 +153,31 @@ public class HttpWebSocketHandler extends ChannelInboundHandlerAdapter {
hasFirstPacket = true;
hasBinaryConnection = true;
BungeeCord bungus = BungeeCord.getInstance();
int limit = bungus.config.getPlayerLimit();
if (limit > 0 && bungus.getOnlineCount() >= limit) {
sendErrorCode(ctx, HandshakePacketTypes.SERVER_ERROR_CUSTOM_MESSAGE, bungus.getTranslation("proxy_full"))
.addListener(ChannelFutureListener.CLOSE);
connectionClosed = true;
return;
}
if(conf.getMaxPlayer() > 0) {
int i = 0;
for(ProxiedPlayer p : bungus.getPlayers()) {
if(p.getPendingConnection().getListener() == conf) {
++i;
}
}
if (i >= conf.getMaxPlayer()) {
sendErrorCode(ctx, HandshakePacketTypes.SERVER_ERROR_CUSTOM_MESSAGE, bungus.getTranslation("proxy_full"))
.addListener(ChannelFutureListener.CLOSE);
connectionClosed = true;
return;
}
}
SocketAddress localSocketAddr = ctx.channel().remoteAddress();
InetAddress addr = ctx.channel().attr(EaglerPipeline.REAL_ADDRESS).get();
@ -692,6 +717,32 @@ public class HttpWebSocketHandler extends ChannelInboundHandlerAdapter {
private void finish(final ChannelHandlerContext ctx) {
final BungeeCord bungee = BungeeCord.getInstance();
// verify player counts a second time after handshake just to be safe
int limit = bungee.config.getPlayerLimit();
if (limit > 0 && bungee.getOnlineCount() >= limit) {
sendErrorCode(ctx, HandshakePacketTypes.SERVER_ERROR_CUSTOM_MESSAGE, bungee.getTranslation("proxy_full"))
.addListener(ChannelFutureListener.CLOSE);
connectionClosed = true;
return;
}
if(conf.getMaxPlayer() > 0) {
int i = 0;
for(ProxiedPlayer p : bungee.getPlayers()) {
if(p.getPendingConnection().getListener() == conf) {
++i;
}
}
if (i >= conf.getMaxPlayer()) {
sendErrorCode(ctx, HandshakePacketTypes.SERVER_ERROR_CUSTOM_MESSAGE, bungee.getTranslation("proxy_full"))
.addListener(ChannelFutureListener.CLOSE);
connectionClosed = true;
return;
}
}
final String usernameStr = clientUsername.toString();
final ProxiedPlayer oldName = bungee.getPlayer(usernameStr);
if (oldName != null) {

View File

@ -1,5 +1,5 @@
name: EaglercraftXBungee
main: net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.EaglerXBungee
version: 1.0.4
version: 1.0.5
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

View File

@ -1 +1 @@
1.0.4
1.0.5