-
-
Notifications
You must be signed in to change notification settings - Fork 950
Feature: per-server info forwarding mode #1655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev/3.0.0
Are you sure you want to change the base?
Changes from 2 commits
2188381
e2deb78
7f74964
37f27aa
f18b92c
7c0abf9
7b64eae
3cdb05b
915bf50
015e3c7
dfddfaa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Copyright (C) 2018-2021 Velocity Contributors | ||
| * | ||
| * The Velocity API is licensed under the terms of the MIT License. For more details, | ||
| * reference the LICENSE file in the api top-level directory. | ||
| */ | ||
|
|
||
| package com.velocitypowered.api.proxy.config; | ||
|
|
||
| import com.velocitypowered.api.proxy.server.ServerInfoForwardingMode; | ||
|
|
||
| /** | ||
| * Exposes server configuration information that plugins may use. | ||
| */ | ||
| public interface BackendServerConfig { | ||
|
|
||
| /** | ||
| * Get the address of the backend server. | ||
| * | ||
| * @return the address formatted as address:port | ||
| */ | ||
| String getAddress(); | ||
|
|
||
| /** | ||
| * Get the info forwarding mode of the server<br><br> | ||
| * <b>What's this?</b><br> | ||
| * The server can use a different mode to obtain and forward player info.<br> | ||
| * For instance, if you are running a 1.12 (or lower version) server on a velocity proxy with MODERN player info forwarding | ||
| * the server doesn't support MODERN forwarding. So you need to set LEGACY forwarding mode for that server | ||
| * and velocity will use ONLY FOR THAT SERVER the legacy forwarding mode.<br><br> | ||
| * <i><b>TIP:</b> If you need to set this value when creating dynamic servers in your plugins you can do that by adding | ||
| * the ServerInfoForwardingMode value as the last parameter while creating a new server info.</i> | ||
| * | ||
| * @return the server info forwarding mode | ||
| */ | ||
|
|
||
| ServerInfoForwardingMode getForwardingMode(); | ||
|
|
||
| /** | ||
| * Set the address of the backend server. | ||
| */ | ||
| void setAddress(String address); | ||
|
|
||
| /** | ||
| * Set the forwarding mode of the backend server. | ||
| */ | ||
| void setForwardingMode(ServerInfoForwardingMode forwardingMode); | ||
|
4drian3d marked this conversation as resolved.
Outdated
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /* | ||
| * Copyright (C) 2018-2021 Velocity Contributors | ||
|
MarcoLvr marked this conversation as resolved.
Outdated
|
||
| * | ||
| * The Velocity API is licensed under the terms of the MIT License. For more details, | ||
| * reference the LICENSE file in the api top-level directory. | ||
| */ | ||
|
|
||
| package com.velocitypowered.api.proxy.server; | ||
|
|
||
| /** | ||
| * Supported server info forwarding methods. | ||
| */ | ||
| public enum ServerInfoForwardingMode { | ||
|
4drian3d marked this conversation as resolved.
|
||
| /** | ||
| * This type will follow the value of the player-info-forwarding-mode in the velocity configuration. | ||
| */ | ||
| FOLLOWUP, | ||
|
4drian3d marked this conversation as resolved.
Outdated
MarcoLvr marked this conversation as resolved.
Outdated
|
||
| MODERN, | ||
| BUNGEEGUARD, | ||
| LEGACY, | ||
| NONE | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,13 +24,16 @@ | |||||||||||||||||||||||
| import com.google.common.collect.ImmutableList; | ||||||||||||||||||||||||
| import com.google.common.collect.ImmutableMap; | ||||||||||||||||||||||||
| import com.google.gson.annotations.Expose; | ||||||||||||||||||||||||
| import com.velocitypowered.api.proxy.config.BackendServerConfig; | ||||||||||||||||||||||||
| import com.velocitypowered.api.proxy.config.ProxyConfig; | ||||||||||||||||||||||||
| import com.velocitypowered.api.proxy.server.ServerInfoForwardingMode; | ||||||||||||||||||||||||
| import com.velocitypowered.api.util.Favicon; | ||||||||||||||||||||||||
| import com.velocitypowered.proxy.config.migration.ConfigurationMigration; | ||||||||||||||||||||||||
| import com.velocitypowered.proxy.config.migration.ForwardingMigration; | ||||||||||||||||||||||||
| import com.velocitypowered.proxy.config.migration.KeyAuthenticationMigration; | ||||||||||||||||||||||||
| import com.velocitypowered.proxy.config.migration.MotdMigration; | ||||||||||||||||||||||||
| import com.velocitypowered.proxy.config.migration.TransferIntegrationMigration; | ||||||||||||||||||||||||
| import com.velocitypowered.proxy.config.server.BackendServerConfigImpl; | ||||||||||||||||||||||||
| import com.velocitypowered.proxy.util.AddressUtil; | ||||||||||||||||||||||||
| import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||||||||||||||||||||||||
| import java.io.IOException; | ||||||||||||||||||||||||
|
|
@@ -175,9 +178,9 @@ public boolean validate() { | |||||||||||||||||||||||
| logger.warn("You don't have any servers configured."); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| for (Map.Entry<String, String> entry : servers.getServers().entrySet()) { | ||||||||||||||||||||||||
| for (Map.Entry<String, BackendServerConfig> entry : servers.getBackendServers().entrySet()) { | ||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||
| AddressUtil.parseAddress(entry.getValue()); | ||||||||||||||||||||||||
| AddressUtil.parseAddress(entry.getValue().getAddress()); | ||||||||||||||||||||||||
| } catch (IllegalArgumentException e) { | ||||||||||||||||||||||||
| logger.error("Server {} does not have a valid IP address.", entry.getKey(), e); | ||||||||||||||||||||||||
| valid = false; | ||||||||||||||||||||||||
|
|
@@ -315,6 +318,11 @@ public Map<String, String> getServers() { | |||||||||||||||||||||||
| return servers.getServers(); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||
| public Map<String, BackendServerConfig> getBackendServers() { | ||||||||||||||||||||||||
| return servers.getBackendServers(); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||
| public List<String> getAttemptConnectionOrder() { | ||||||||||||||||||||||||
| return servers.getAttemptConnectionOrder(); | ||||||||||||||||||||||||
|
|
@@ -611,10 +619,10 @@ public boolean isOnlineModeKickExistingPlayers() { | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| private static class Servers { | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| private Map<String, String> servers = ImmutableMap.of( | ||||||||||||||||||||||||
| "lobby", "127.0.0.1:30066", | ||||||||||||||||||||||||
| "factions", "127.0.0.1:30067", | ||||||||||||||||||||||||
| "minigames", "127.0.0.1:30068" | ||||||||||||||||||||||||
| private Map<String, BackendServerConfig> servers = ImmutableMap.of( | ||||||||||||||||||||||||
| "lobby", new BackendServerConfigImpl("127.0.0.1:30066"), | ||||||||||||||||||||||||
| "factions", new BackendServerConfigImpl("127.0.0.1:30067", ServerInfoForwardingMode.MODERN), | ||||||||||||||||||||||||
| "minigames", new BackendServerConfigImpl("127.0.0.1:30068", ServerInfoForwardingMode.LEGACY) | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
| private List<String> attemptConnectionOrder = ImmutableList.of("lobby"); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -623,14 +631,31 @@ private Servers() { | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| private Servers(CommentedConfig config) { | ||||||||||||||||||||||||
| if (config != null) { | ||||||||||||||||||||||||
| Map<String, String> servers = new HashMap<>(); | ||||||||||||||||||||||||
| Map<String, BackendServerConfig> servers = new HashMap<>(); | ||||||||||||||||||||||||
| for (UnmodifiableConfig.Entry entry : config.entrySet()) { | ||||||||||||||||||||||||
| if (entry.getValue() instanceof String) { | ||||||||||||||||||||||||
| servers.put(cleanServerName(entry.getKey()), entry.getValue()); | ||||||||||||||||||||||||
| if (entry.getValue() instanceof com.electronwill.nightconfig.core.CommentedConfig c) { | ||||||||||||||||||||||||
|
MarcoLvr marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||||
| String address = null; | ||||||||||||||||||||||||
| ServerInfoForwardingMode forwardingMode = ServerInfoForwardingMode.FOLLOWUP; | ||||||||||||||||||||||||
| for (UnmodifiableConfig.Entry entry2 : c.entrySet()) { | ||||||||||||||||||||||||
| if (entry2.getKey().equalsIgnoreCase("address")) { | ||||||||||||||||||||||||
| address = entry2.getValue(); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| if (entry2.getKey().equalsIgnoreCase("forwarding-mode")) { | ||||||||||||||||||||||||
| forwardingMode = ServerInfoForwardingMode.valueOf(ServerInfoForwardingMode.class, entry2.getValue()); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
| forwardingMode = ServerInfoForwardingMode.valueOf(ServerInfoForwardingMode.class, entry2.getValue()); | |
| Object rawValue = entry2.getValue(); | |
| if (rawValue != null) { | |
| String modeValue = rawValue.toString().toUpperCase(); | |
| try { | |
| forwardingMode = ServerInfoForwardingMode.valueOf(modeValue); | |
| } catch (IllegalArgumentException ex) { | |
| throw new IllegalArgumentException( | |
| "Invalid forwarding-mode '" + rawValue + "' for server '" + entry.getKey() + "'", ex); | |
| } | |
| } |
Uh oh!
There was an error while loading. Please reload this page.