Skip to content

Commit f76cb61

Browse files
committed
Introduce ignore-anonymous-player-request config option
1 parent deae837 commit f76cb61

4 files changed

Lines changed: 47 additions & 2 deletions

File tree

proxy/src/main/java/com/velocityctd/proxy/util/SamplePlayersPlaceholderResolver.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class SamplePlayersPlaceholderResolver implements PlaceholderSubstitutor.
1616
private final String defaultEmpty;
1717
private final String defaultPrefix;
1818
private final String defaultSeparator;
19+
private final boolean ignoreAnonymousPlayerRequest;
1920

2021
private SamplePlayersPlaceholderResolver(Builder builder) {
2122
this.samplePlayersPicker = builder.samplePlayersPicker;
@@ -25,6 +26,7 @@ private SamplePlayersPlaceholderResolver(Builder builder) {
2526
this.defaultEmpty = builder.defaultEmpty;
2627
this.defaultPrefix = builder.defaultPrefix;
2728
this.defaultSeparator = builder.defaultSeparator;
29+
this.ignoreAnonymousPlayerRequest = builder.ignoreAnonymousPlayerRequest;
2830
}
2931

3032
public static Builder builder(SamplePlayersPicker samplePlayersPicker) {
@@ -38,7 +40,8 @@ public Builder toBuilder() {
3840
.defaultOrdering(defaultOrdering)
3941
.defaultEmpty(defaultEmpty)
4042
.defaultPrefix(defaultPrefix)
41-
.defaultSeparator(defaultSeparator);
43+
.defaultSeparator(defaultSeparator)
44+
.ignoreAnonymousPlayerRequest(ignoreAnonymousPlayerRequest);
4245
}
4346

4447
@Override
@@ -68,7 +71,7 @@ private String samplePlayers(int max, int maxPerLine, SamplePlayersPicker.Orderi
6871
VelocityClusterPlayer player = sample.get(i);
6972

7073
String name;
71-
if (!player.isClientListingAllowed()) {
74+
if (!ignoreAnonymousPlayerRequest && !player.isClientListingAllowed()) {
7275
name = ServerPing.SamplePlayer.ANONYMOUS.getName();
7376
} else {
7477
name = player.getUsername();
@@ -116,6 +119,7 @@ public static class Builder {
116119
private String defaultEmpty = "None";
117120
private String defaultPrefix = "";
118121
private String defaultSeparator = ", ";
122+
private boolean ignoreAnonymousPlayerRequest = false;
119123

120124
private Builder(SamplePlayersPicker samplePlayersPicker) {
121125
this.samplePlayersPicker = samplePlayersPicker;
@@ -151,6 +155,11 @@ public Builder defaultSeparator(String defaultSeparator) {
151155
return this;
152156
}
153157

158+
public Builder ignoreAnonymousPlayerRequest(boolean ignoreAnonymousPlayerRequest) {
159+
this.ignoreAnonymousPlayerRequest = ignoreAnonymousPlayerRequest;
160+
return this;
161+
}
162+
154163
public SamplePlayersPlaceholderResolver build() {
155164
return new SamplePlayersPlaceholderResolver(this);
156165
}

proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,19 @@ public String getBackendBrandCustom() {
878878
return advanced.getBackendBrandCustom();
879879
}
880880

881+
/**
882+
* Returns whether a client's request to be anonymized in the server list ping should be ignored.
883+
*
884+
* <p>When a player disables "Allow Server Listings" in their client options, they are normally
885+
* shown as "Anonymous Player" in the {@code {players}} sample. When this returns {@code true},
886+
* their real username is shown regardless.
887+
*
888+
* @return {@code true} if the client's anonymization request should be ignored
889+
*/
890+
public boolean isIgnoreAnonymousPlayerRequest() {
891+
return advanced.isIgnoreAnonymousPlayerRequest();
892+
}
893+
881894
/**
882895
* Gets the dynamic fallback filter mode configured for server selection.
883896
*
@@ -2048,6 +2061,15 @@ private static final class Advanced {
20482061
@Expose
20492062
private String backendBrandCustom = "Paper";
20502063

2064+
/**
2065+
* Whether to ignore a client's request to be anonymized in the server list ping. When a player
2066+
* disables "Allow Server Listings" in their client options, they normally show up as
2067+
* "Anonymous Player" in the {@code {players}} sample. Enabling this displays their real username
2068+
* regardless.
2069+
*/
2070+
@Expose
2071+
private boolean ignoreAnonymousPlayerRequest = false;
2072+
20512073
private Advanced() {
20522074
}
20532075

@@ -2086,6 +2108,7 @@ private Advanced(CommentedConfig config) {
20862108
this.alwaysFallBackPing = config.getOrElse("always-fallback-ping", false);
20872109
this.proxyBrandCustom = config.getOrElse("custom-brand-proxy", "Velocity-CTD");
20882110
this.backendBrandCustom = config.getOrElse("custom-brand-backend", "Paper");
2111+
this.ignoreAnonymousPlayerRequest = config.getOrElse("ignore-anonymous-player-request", false);
20892112
}
20902113
}
20912114

@@ -2197,6 +2220,10 @@ public String getBackendBrandCustom() {
21972220
return backendBrandCustom;
21982221
}
21992222

2223+
public boolean isIgnoreAnonymousPlayerRequest() {
2224+
return ignoreAnonymousPlayerRequest;
2225+
}
2226+
22002227
@Override
22012228
public String toString() {
22022229
return MoreObjects.toStringHelper(this)
@@ -2226,6 +2253,7 @@ public String toString() {
22262253
.add("alwaysFallBackPing", alwaysFallBackPing)
22272254
.add("proxyBrandCustom", proxyBrandCustom)
22282255
.add("backendBrandCustom", backendBrandCustom)
2256+
.add("ignoreAnonymousPlayerRequest", ignoreAnonymousPlayerRequest)
22292257
.toString();
22302258
}
22312259

proxy/src/main/java/com/velocitypowered/proxy/connection/util/ServerListPingHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ private ServerPing constructLocalPing(ProtocolVersion clientVersion) {
9696
.defaultMax(8)
9797
.defaultMaxPerLine(4)
9898
.defaultSeparator(", ")
99+
.ignoreAnonymousPlayerRequest(configuration.isIgnoreAnonymousPlayerRequest())
99100
.build());
100101

101102
List<String> motdHover = PlaceholderSubstitutor.substitute(
@@ -105,6 +106,7 @@ private ServerPing constructLocalPing(ProtocolVersion clientVersion) {
105106
.defaultMax(12)
106107
.defaultMaxPerLine(1)
107108
.defaultSeparator("")
109+
.ignoreAnonymousPlayerRequest(configuration.isIgnoreAnonymousPlayerRequest())
108110
.build());
109111

110112
String versionName = PlaceholderSubstitutor.substitute(
@@ -114,6 +116,7 @@ private ServerPing constructLocalPing(ProtocolVersion clientVersion) {
114116
.defaultMax(2)
115117
.defaultMaxPerLine(Integer.MAX_VALUE)
116118
.defaultSeparator(", ")
119+
.ignoreAnonymousPlayerRequest(configuration.isIgnoreAnonymousPlayerRequest())
117120
.build());
118121

119122
return new ServerPing(

proxy/src/main/resources/default-velocity.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,11 @@ custom-brand-proxy = "Velocity-CTD"
385385
# Replaces what is returned as the server brand for the user's client.
386386
custom-brand-backend = "Paper"
387387

388+
# When a player disables "Allow Server Listings" in their client options, they are shown as
389+
# "Anonymous Player" in the {players} sample of the server list ping. Set this to true to ignore
390+
# that request and always show their real username.
391+
ignore-anonymous-player-request = false
392+
388393
[slash-servers]
389394
# Defines "/<name>" aliases for servers - here "/faction" and "/factions" would both send you to the server named
390395
# "factions", for example.

0 commit comments

Comments
 (0)