13
0
geforkt von Mirrors/Velocity

Fix up some more code style issues.

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-11-03 01:54:26 -04:00
Ursprung e2389d96e9
Commit 89e51bbcb9
5 geänderte Dateien mit 65 neuen und 67 gelöschten Zeilen

Datei anzeigen

@ -86,7 +86,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
@Override @Override
public boolean handle(ClientSettings packet) { public boolean handle(ClientSettings packet) {
player.setPlayerSettings(packet); player.setPlayerSettings(packet);
return false; // will forward onto the handleGeneric below, which will write the packet to the remote server return false; // will forward onto the server
} }
@Override @Override
@ -164,8 +164,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
List<String> actuallyRegistered = new ArrayList<>(); List<String> actuallyRegistered = new ArrayList<>();
List<String> channels = PluginMessageUtil.getChannels(packet); List<String> channels = PluginMessageUtil.getChannels(packet);
for (String channel : channels) { for (String channel : channels) {
if (knownChannels.size() >= MAX_PLUGIN_CHANNELS && if (knownChannels.size() >= MAX_PLUGIN_CHANNELS && !knownChannels.contains(channel)) {
!knownChannels.contains(channel)) {
throw new IllegalStateException("Too many plugin message channels registered"); throw new IllegalStateException("Too many plugin message channels registered");
} }
if (knownChannels.add(channel)) { if (knownChannels.add(channel)) {

Datei anzeigen

@ -184,8 +184,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
connection.write(pkt); connection.write(pkt);
return; return;
} else { } else {
// Due to issues with action bar packets, we'll need to convert the text message into a legacy message // Due to issues with action bar packets, we'll need to convert the text message into a
// and then inject the legacy text into a component... yuck! // legacy message and then inject the legacy text into a component... yuck!
JsonObject object = new JsonObject(); JsonObject object = new JsonObject();
object.addProperty("text", ComponentSerializers.LEGACY.serialize(component)); object.addProperty("text", ComponentSerializers.LEGACY.serialize(component));
json = VelocityServer.GSON.toJson(object); json = VelocityServer.GSON.toJson(object);
@ -396,49 +396,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
return server.getServer(toTryName); return server.getServer(toTryName);
} }
private Optional<ConnectionRequestBuilder.Status> checkServer(RegisteredServer server) {
Preconditions
.checkState(server instanceof VelocityRegisteredServer, "Not a valid Velocity server.");
if (connectionInFlight != null) {
return Optional.of(ConnectionRequestBuilder.Status.CONNECTION_IN_PROGRESS);
}
if (connectedServer != null && connectedServer.getServer().equals(server)) {
return Optional.of(ConnectionRequestBuilder.Status.ALREADY_CONNECTED);
}
return Optional.empty();
}
private CompletableFuture<ConnectionRequestBuilder.Result> connect(
ConnectionRequestBuilderImpl request) {
Optional<ConnectionRequestBuilder.Status> initialCheck = checkServer(request.getServer());
if (initialCheck.isPresent()) {
return CompletableFuture
.completedFuture(ConnectionRequestResults.plainResult(initialCheck.get()));
}
// Otherwise, initiate the connection.
ServerPreConnectEvent event = new ServerPreConnectEvent(this, request.getServer());
return server.getEventManager().fire(event)
.thenCompose(newEvent -> {
Optional<RegisteredServer> connectTo = newEvent.getResult().getServer();
if (!connectTo.isPresent()) {
return CompletableFuture.completedFuture(
ConnectionRequestResults
.plainResult(ConnectionRequestBuilder.Status.CONNECTION_CANCELLED)
);
}
RegisteredServer rs = connectTo.get();
Optional<ConnectionRequestBuilder.Status> lastCheck = checkServer(rs);
if (lastCheck.isPresent()) {
return CompletableFuture
.completedFuture(ConnectionRequestResults.plainResult(lastCheck.get()));
}
return new VelocityServerConnection((VelocityRegisteredServer) rs, this, server)
.connect();
});
}
public void setConnectedServer(@Nullable VelocityServerConnection serverConnection) { public void setConnectedServer(@Nullable VelocityServerConnection serverConnection) {
this.connectedServer = serverConnection; this.connectedServer = serverConnection;
this.tryIndex = 0; // reset since we got connected to a server this.tryIndex = 0; // reset since we got connected to a server
@ -515,20 +472,58 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
private class ConnectionRequestBuilderImpl implements ConnectionRequestBuilder { private class ConnectionRequestBuilderImpl implements ConnectionRequestBuilder {
private final RegisteredServer server; private final RegisteredServer toConnect;
ConnectionRequestBuilderImpl(RegisteredServer server) { ConnectionRequestBuilderImpl(RegisteredServer toConnect) {
this.server = Preconditions.checkNotNull(server, "info"); this.toConnect = Preconditions.checkNotNull(toConnect, "info");
} }
@Override @Override
public RegisteredServer getServer() { public RegisteredServer getServer() {
return server; return toConnect;
}
private Optional<ConnectionRequestBuilder.Status> checkServer(RegisteredServer server) {
Preconditions
.checkState(server instanceof VelocityRegisteredServer, "Not a valid Velocity server.");
if (connectionInFlight != null) {
return Optional.of(ConnectionRequestBuilder.Status.CONNECTION_IN_PROGRESS);
}
if (connectedServer != null && connectedServer.getServer().equals(server)) {
return Optional.of(ConnectionRequestBuilder.Status.ALREADY_CONNECTED);
}
return Optional.empty();
} }
@Override @Override
public CompletableFuture<Result> connect() { public CompletableFuture<Result> connect() {
return ConnectedPlayer.this.connect(this); Optional<ConnectionRequestBuilder.Status> initialCheck = checkServer(toConnect);
if (initialCheck.isPresent()) {
return CompletableFuture
.completedFuture(ConnectionRequestResults.plainResult(initialCheck.get()));
}
// Otherwise, initiate the connection.
ServerPreConnectEvent event = new ServerPreConnectEvent(ConnectedPlayer.this, toConnect);
return server.getEventManager().fire(event)
.thenCompose(newEvent -> {
Optional<RegisteredServer> connectTo = newEvent.getResult().getServer();
if (!connectTo.isPresent()) {
return CompletableFuture.completedFuture(
ConnectionRequestResults
.plainResult(ConnectionRequestBuilder.Status.CONNECTION_CANCELLED)
);
}
RegisteredServer rs = connectTo.get();
Optional<ConnectionRequestBuilder.Status> lastCheck = checkServer(rs);
if (lastCheck.isPresent()) {
return CompletableFuture
.completedFuture(ConnectionRequestResults.plainResult(lastCheck.get()));
}
return new VelocityServerConnection((VelocityRegisteredServer) toConnect,
ConnectedPlayer.this, server).connect();
});
} }
@Override @Override
@ -536,7 +531,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
return connect() return connect()
.whenCompleteAsync((status, throwable) -> { .whenCompleteAsync((status, throwable) -> {
if (throwable != null) { if (throwable != null) {
handleConnectionException(server, throwable); handleConnectionException(toConnect, throwable);
return; return;
} }
@ -551,7 +546,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
// Ignored; the plugin probably already handled this. // Ignored; the plugin probably already handled this.
break; break;
case SERVER_DISCONNECTED: case SERVER_DISCONNECTED:
handleConnectionException(server, Disconnect.create(status.getReason() handleConnectionException(toConnect, Disconnect.create(status.getReason()
.orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR))); .orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR)));
break; break;
default: default:

Datei anzeigen

@ -95,22 +95,22 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
return true; return true;
} }
// Determine if we're using Forge (1.8 to 1.12, may not be the case in 1.13) and store that in the connection // Determine if we're using Forge (1.8 to 1.12, may not be the case in 1.13).
boolean isForge = handshake.getServerAddress().endsWith("\0FML\0"); boolean isForge = handshake.getServerAddress().endsWith("\0FML\0");
connection.setLegacyForge(isForge); connection.setLegacyForge(isForge);
// Make sure legacy forwarding is not in use on this connection. Make sure that we do _not_ reject Forge // Make sure legacy forwarding is not in use on this connection. Make sure that we do _not_
// reject Forge.
if (handshake.getServerAddress().contains("\0") && !isForge) { if (handshake.getServerAddress().contains("\0") && !isForge) {
connection.closeWith(Disconnect connection.closeWith(Disconnect
.create(TextComponent.of("Running Velocity behind Velocity is unsupported."))); .create(TextComponent.of("Running Velocity behind Velocity is unsupported.")));
return true; return true;
} }
// If the proxy is configured for modern forwarding, we must deny connections from 1.12.2 and lower, // If the proxy is configured for modern forwarding, we must deny connections from 1.12.2
// otherwise IP information will never get forwarded. // and lower, otherwise IP information will never get forwarded.
if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN
&& handshake.getProtocolVersion() < && handshake.getProtocolVersion() < ProtocolConstants.MINECRAFT_1_13) {
ProtocolConstants.MINECRAFT_1_13) {
connection.closeWith(Disconnect connection.closeWith(Disconnect
.create(TextComponent.of("This server is only compatible with 1.13 and above."))); .create(TextComponent.of("This server is only compatible with 1.13 and above.")));
return true; return true;

Datei anzeigen

@ -133,8 +133,8 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
return; return;
} }
// Go ahead and enable encryption. Once the client sends EncryptionResponse, encryption is // Go ahead and enable encryption. Once the client sends EncryptionResponse, encryption
// enabled. // is enabled.
try { try {
inbound.enableEncryption(decryptedSharedSecret); inbound.enableEncryption(decryptedSharedSecret);
} catch (GeneralSecurityException e) { } catch (GeneralSecurityException e) {
@ -146,8 +146,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
initializePlayer( initializePlayer(
VelocityServer.GSON.fromJson(profileResponse.getBody(), GameProfile.class), true); VelocityServer.GSON.fromJson(profileResponse.getBody(), GameProfile.class), true);
} else if (profileResponse.getCode() == 204) { } else if (profileResponse.getCode() == 204) {
// Apparently an offline-mode user logged onto this online-mode proxy. The client has enabled // Apparently an offline-mode user logged onto this online-mode proxy.
// encryption, so we need to do that as well.
logger.warn("An offline-mode client ({} from {}) tried to connect!", logger.warn("An offline-mode client ({} from {}) tried to connect!",
login.getUsername(), playerIp); login.getUsername(), playerIp);
inbound.closeWith(Disconnect.create(TextComponent inbound.closeWith(Disconnect.create(TextComponent

Datei anzeigen

@ -41,8 +41,8 @@ public class NettyHttpClient {
@Override @Override
public void channelAcquired(Channel channel) throws Exception { public void channelAcquired(Channel channel) throws Exception {
// We don't do anything special when acquiring channels. The channel handler cleans up after // We don't do anything special when acquiring channels. The channel handler cleans up
// each connection is used. // after each connection is used.
} }
@Override @Override
@ -59,6 +59,11 @@ public class NettyHttpClient {
}; };
} }
/**
* Attempts an HTTP GET request to the specified URL.
* @param url the URL to fetch
* @return a future representing the response
*/
public CompletableFuture<SimpleHttpResponse> get(URL url) { public CompletableFuture<SimpleHttpResponse> get(URL url) {
String host = url.getHost(); String host = url.getHost();
int port = url.getPort(); int port = url.getPort();