Add ConnectionRequestEvent (#4533)

* Add ConnectionRequestEvent and implement it

* Add debug message and use InetSocketAddress instead of string

* Provide both proxy and real client ip

And add some minor javadocs

* Make ProxyIp nullable

* Apply changes from pr

Co-authored-by: rtm516 <rtm516@users.noreply.github.com>

* Apply changes from pr

Co-authored-by: rtm516 <rtm516@users.noreply.github.com>

* Apply changes from pr

Co-authored-by: rtm516 <rtm516@users.noreply.github.com>

* Bump API version

* Dont JiJ common on mod platforms

---------

Co-authored-by: rtm516 <rtm516@users.noreply.github.com>
Co-authored-by: Kas-tle <26531652+Kas-tle@users.noreply.github.com>
This commit is contained in:
Sage 2024-04-01 23:33:12 +02:00 committed by GitHub
parent c9ca4c82f7
commit fa441f1c7b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 101 additions and 2 deletions

View file

@ -49,6 +49,7 @@ import org.cloudburstmc.netty.handler.codec.raknet.server.RakServerOfflineHandle
import org.cloudburstmc.netty.handler.codec.raknet.server.RakServerRateLimiter;
import org.cloudburstmc.protocol.bedrock.BedrockPong;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.event.connection.ConnectionRequestEvent;
import org.geysermc.geyser.command.defaults.ConnectionTestCommand;
import org.geysermc.geyser.configuration.GeyserConfiguration;
import org.geysermc.geyser.event.type.GeyserBedrockPingEventImpl;
@ -261,6 +262,14 @@ public final class GeyserServer {
} else {
ip = "<IP address withheld>";
}
ConnectionRequestEvent requestEvent = new ConnectionRequestEvent(inetSocketAddress, this.proxiedAddresses.get(inetSocketAddress));
geyser.eventBus().fire(requestEvent);
if (requestEvent.isCancelled()) {
geyser.getLogger().debug("Connection request from " + ip + " was cancelled using the API!");
return false;
}
geyser.getLogger().info(GeyserLocale.getLocaleStringLog("geyser.network.attempt_connect", ip));
return true;
}