Interface BanProvider

All Superinterfaces:
AccessProvider
All Known Implementing Classes:
HytaleBanProvider

public interface BanProvider extends AccessProvider
Holds the bans that the server applies when a player connects.

The server runs a HytaleBanProvider, which stores the bans in a file. To keep the bans somewhere else, such as a database that several servers share, implement this interface and install it with AccessControlModule.setBanProvider(BanProvider).

A method of this interface can block on the storage. Call it off the world thread.

  • Field Details

    • NO_REASON

      @Nonnull static final Optional<Message> NO_REASON
      Shared, because most players that connect have no ban.
    • UNDESCRIBED_BAN

      @Nonnull static final Optional<Message> UNDESCRIBED_BAN
      Shared, because a ban a provider cannot describe carries nothing about the player it denies.
  • Method Details

    • hasBan

      boolean hasBan(@Nonnull UUID uuid)
      A ban that has run out, as Ban.isInEffect() reports, counts as no ban.

      This asks whether the player is kept out, so it counts a ban the provider holds but cannot describe, which getBan(UUID) returns nothing for.

      Parameters:
      uuid - the UUID of the player to check
      Returns:
      true if the player has a ban, or an entry that denies them
    • getBan

      @Nullable Ban getBan(@Nonnull UUID uuid)
      A ban that has run out, as Ban.isInEffect() reports, counts as no ban.

      A provider that holds a ban it cannot describe returns null here and true from hasBan(UUID), so use that to ask whether a player is kept out.

      Parameters:
      uuid - the UUID of the player to look up
      Returns:
      the ban on the player, or null if the player has none this provider can read
    • addBan

      boolean addBan(@Nonnull Ban ban)
      Adds the ban and stores it. A player who already has a ban keeps it, unless that ban has run out, in which case the new ban replaces it.

      A return of true means the ban is stored. If the store fails, throw, and leave the provider as it was.

      Parameters:
      ban - the ban to add
      Returns:
      true if the ban was added
    • removeBan

      boolean removeBan(@Nonnull UUID uuid)
      Removes any ban on the player and stores the change.

      A return of true means the removal is stored. If the store fails, throw, and leave the provider as it was.

      Parameters:
      uuid - the UUID of the player to unban
      Returns:
      true if the player had a ban
    • getBans

      @Nonnull Collection<Ban> getBans()
      Returns:
      a snapshot of every ban that is in effect and that this provider can read
    • load

      default void load()
      Reads the bans from storage. The module calls this when the server starts, and again on a provider that replaces this one.
    • save

      default void save()
      Writes the bans to storage. The module calls this when the server stops, and again on this provider when another replaces it.

      This is a flush of state that is already stored, never the point at which a change becomes durable. A provider stores each change as that change is made, so it does not need to do anything here.

    • getDisconnectReason

      @Nonnull default CompletableFuture<Optional<Message>> getDisconnectReason(@Nonnull UUID uuid)
      Description copied from interface: AccessProvider
      Returns an Optional of type Message that provides a disconnect reason.

      If the Optional contains a Message, the connection will be terminated with that message as the reason. An empty Optional will be ignored and the connection proceeds.

      Specified by:
      getDisconnectReason in interface AccessProvider
      Parameters:
      uuid - The UUID of the player to check.
      Returns:
      the disconnect reason, Optional.empty() for no reason.