|
| 1 | +/* |
| 2 | + * Copyright (c) 2019-2024 GeyserMC. http://geysermc.org |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | + * of this software and associated documentation files (the "Software"), to deal |
| 6 | + * in the Software without restriction, including without limitation the rights |
| 7 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | + * copies of the Software, and to permit persons to whom the Software is |
| 9 | + * furnished to do so, subject to the following conditions: |
| 10 | + * |
| 11 | + * The above copyright notice and this permission notice shall be included in |
| 12 | + * all copies or substantial portions of the Software. |
| 13 | + * |
| 14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 | + * THE SOFTWARE. |
| 21 | + * |
| 22 | + * @author GeyserMC |
| 23 | + * @link https://github.com/GeyserMC/Geyser |
| 24 | + */ |
| 25 | + |
| 26 | +package org.geysermc.geyser.api.event.connection; |
| 27 | + |
| 28 | +import org.checkerframework.checker.nullness.qual.NonNull; |
| 29 | +import org.checkerframework.checker.nullness.qual.Nullable; |
| 30 | +import org.geysermc.event.Cancellable; |
| 31 | +import org.geysermc.event.Event; |
| 32 | + |
| 33 | +import java.net.InetSocketAddress; |
| 34 | + |
| 35 | +/** |
| 36 | + * Called whenever a client attempts to connect to the server, before the connection is accepted. |
| 37 | + */ |
| 38 | +public final class ConnectionRequestEvent implements Event, Cancellable { |
| 39 | + |
| 40 | + private boolean cancelled; |
| 41 | + private final InetSocketAddress ip; |
| 42 | + private final InetSocketAddress proxyIp; |
| 43 | + |
| 44 | + public ConnectionRequestEvent(@NonNull InetSocketAddress ip, @Nullable InetSocketAddress proxyIp) { |
| 45 | + this.ip = ip; |
| 46 | + this.proxyIp = proxyIp; |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * The IP address of the client attempting to connect |
| 51 | + * |
| 52 | + * @return the IP address of the client attempting to connect |
| 53 | + */ |
| 54 | + @NonNull |
| 55 | + public InetSocketAddress getInetSocketAddress() { |
| 56 | + return ip; |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * The IP address of the proxy handling the connection. It will return null if there is no proxy. |
| 61 | + * |
| 62 | + * @return the IP address of the proxy handling the connection |
| 63 | + */ |
| 64 | + @Nullable |
| 65 | + public InetSocketAddress getProxyIp() { |
| 66 | + return proxyIp; |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * The cancel status of this event. If this event is cancelled, the connection will be rejected. |
| 71 | + * |
| 72 | + * @return the cancel status of this event |
| 73 | + */ |
| 74 | + @Override |
| 75 | + public boolean isCancelled() { |
| 76 | + return cancelled; |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Sets the cancel status of this event. If this event is canceled, the connection will be rejected. |
| 81 | + * |
| 82 | + * @param cancelled the cancel status of this event. |
| 83 | + */ |
| 84 | + @Override |
| 85 | + public void setCancelled(boolean cancelled) { |
| 86 | + this.cancelled = cancelled; |
| 87 | + } |
| 88 | +} |
0 commit comments