3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

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
public boolean handle(ClientSettings 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
@ -164,8 +164,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
List<String> actuallyRegistered = new ArrayList<>();
List<String> channels = PluginMessageUtil.getChannels(packet);
for (String channel : channels) {
if (knownChannels.size() >= MAX_PLUGIN_CHANNELS &&
!knownChannels.contains(channel)) {
if (knownChannels.size() >= MAX_PLUGIN_CHANNELS && !knownChannels.contains(channel)) {
throw new IllegalStateException("Too many plugin message channels registered");
}
if (knownChannels.add(channel)) {

Datei anzeigen

@ -184,8 +184,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
connection.write(pkt);
return;
} else {
// Due to issues with action bar packets, we'll need to convert the text message into a legacy message
// and then inject the legacy text into a component... yuck!
// Due to issues with action bar packets, we'll need to convert the text message into a
// legacy message and then inject the legacy text into a component... yuck!
JsonObject object = new JsonObject();
object.addProperty("text", ComponentSerializers.LEGACY.serialize(component));
json = VelocityServer.GSON.toJson(object);
@ -396,49 +396,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
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) {
this.connectedServer = serverConnection;
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 final RegisteredServer server;
private final RegisteredServer toConnect;
ConnectionRequestBuilderImpl(RegisteredServer server) {
this.server = Preconditions.checkNotNull(server, "info");
ConnectionRequestBuilderImpl(RegisteredServer toConnect) {
this.toConnect = Preconditions.checkNotNull(toConnect, "info");
}
@Override
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
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
@ -536,7 +531,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
return connect()
.whenCompleteAsync((status, throwable) -> {
if (throwable != null) {
handleConnectionException(server, throwable);
handleConnectionException(toConnect, throwable);
return;
}
@ -551,7 +546,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
// Ignored; the plugin probably already handled this.
break;
case SERVER_DISCONNECTED:
handleConnectionException(server, Disconnect.create(status.getReason()
handleConnectionException(toConnect, Disconnect.create(status.getReason()
.orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR)));
break;
default:

Datei anzeigen

@ -95,22 +95,22 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
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");
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) {
connection.closeWith(Disconnect
.create(TextComponent.of("Running Velocity behind Velocity is unsupported.")));
return true;
}
// If the proxy is configured for modern forwarding, we must deny connections from 1.12.2 and lower,
// otherwise IP information will never get forwarded.
// If the proxy is configured for modern forwarding, we must deny connections from 1.12.2
// and lower, otherwise IP information will never get forwarded.
if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN
&& handshake.getProtocolVersion() <
ProtocolConstants.MINECRAFT_1_13) {
&& handshake.getProtocolVersion() < ProtocolConstants.MINECRAFT_1_13) {
connection.closeWith(Disconnect
.create(TextComponent.of("This server is only compatible with 1.13 and above.")));
return true;

Datei anzeigen

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

Datei anzeigen

@ -41,8 +41,8 @@ public class NettyHttpClient {
@Override
public void channelAcquired(Channel channel) throws Exception {
// We don't do anything special when acquiring channels. The channel handler cleans up after
// each connection is used.
// We don't do anything special when acquiring channels. The channel handler cleans up
// after each connection is used.
}
@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) {
String host = url.getHost();
int port = url.getPort();