SpigotMC / BungeeCord

BungeeCord, the 6th in a generation of server portal suites. Efficiently proxies and maintains connections and transport between multiple Minecraft servers.
https://www.spigotmc.org/go/bungeecord
Other
1.56k stars 1.1k forks source link

Event for exceptions that get caugth #3545

Open Outfluencer opened 11 months ago

Outfluencer commented 11 months ago

Feature description

I want an event that is called if a connection caugth an exception, that would be usefull for layer7 firewalling with iptables or something.

I want to archiv something like this, but with an nice clean event without any fork

image

In this sample i already added an Event for test reasons, but i am not sure if its valid and how i could provide it for public

As my connection is an AbstractPacketHandler object so i can impl it for all exception() methods in all handler so i can get bassicly every exception

Goal of the feature

Adding an Event for all caugth throwables by the Connection or PacketHandler i dont know how we should implement it

Unfitting alternatives

I have done it with a fork because there is no other good way, but reflections and injecting into the pipeline

Checking

Outfluencer commented 11 months ago

I wanted to do an event like this

package net.md_5.bungee.api.event;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import net.md_5.bungee.api.connection.Connection;
import net.md_5.bungee.api.plugin.Event;

/**
 * Called when a packet handler caught an Exception
 */
@Data
@ToString(callSuper = false)
@EqualsAndHashCode(callSuper = false)
public class ConnectionExceptionEvent extends Event
{

    /**
     * Handler that caught the Exception
     */
    private final Connection connection;

    /**
     * The exception that got caught
     */
    private final Throwable exception;
}

The problem in this case is that some PacketHandler impls can cauth exceptions but are not implementing net.md_5.bungee.api.connection.Connection and dont have a field like UserConnection that is implementing it.

I am not sure if we should let all handler implement net.md_5.bungee.api.connection.Connection or if we should make the event use the AbstractPacketHandler like this

 * Called when a packet handler caught an Exception
 */
@Data
@ToString(callSuper = false)
@EqualsAndHashCode(callSuper = false)
public class ConnectionExceptionEvent extends Event
{

    /**
     * Handler that caught the Exception
     */
    private final net.md_5.bungee.protocol.AbstractPacketHandler packetHandler;

    /**
     * The exception that got caught
     */
    private final Throwable exception;
}
Outfluencer commented 11 months ago

For my specific case an PendingConnectionException Event would be enoutgh but i am not sure if this is the best for all

bob7l commented 11 months ago

Why not just put your own channel handler to handle the exceptions? Seems strange to add an event that isn't really bound to the API in any way.

Outfluencer commented 11 months ago

you can't access the pipeline via api and i don't want to do it with reflections

Outfluencer commented 11 months ago

Also the channelinitilzer Fields are final, and i think in newer java versions you cant do much about it with reflections so i could not inject into initial connection

bob7l commented 11 months ago

you can't access the pipeline via api and i don't want to do it with reflections

Yeah Bungee's taken a strong encapsulation approach like Bukkit sadly. Not sure if that'll ever change, but plugins like Floodgate need to do a lot of hacks to get things working which is a shame. Would be extremely useful to have some API wrapping common pipeline functions

You can still modify final's with Unsafe on new java versions

Outfluencer commented 11 months ago

Yes but i dont like use the Unsafe class