geforkt von Mirrors/Velocity
Extra clarity for server/MinecraftConnection naming
Dieser Commit ist enthalten in:
Ursprung
403fec13d8
Commit
63f22dc2de
@ -16,38 +16,38 @@ import io.netty.buffer.ByteBuf;
|
|||||||
|
|
||||||
public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
||||||
private final VelocityServer server;
|
private final VelocityServer server;
|
||||||
private final VelocityServerConnection connection;
|
private final VelocityServerConnection serverConn;
|
||||||
|
|
||||||
public BackendPlaySessionHandler(VelocityServer server, VelocityServerConnection connection) {
|
public BackendPlaySessionHandler(VelocityServer server, VelocityServerConnection serverConn) {
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.connection = connection;
|
this.serverConn = serverConn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void activated() {
|
public void activated() {
|
||||||
server.getEventManager().fireAndForget(new ServerConnectedEvent(connection.getPlayer(), connection.getServer()));
|
server.getEventManager().fireAndForget(new ServerConnectedEvent(serverConn.getPlayer(), serverConn.getServer()));
|
||||||
connection.getServer().addPlayer(connection.getPlayer());
|
serverConn.getServer().addPlayer(serverConn.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(MinecraftPacket packet) {
|
public void handle(MinecraftPacket packet) {
|
||||||
if (!connection.getPlayer().isActive()) {
|
if (!serverConn.getPlayer().isActive()) {
|
||||||
// Connection was left open accidentally. Close it so as to avoid "You logged in from another location"
|
// Connection was left open accidentally. Close it so as to avoid "You logged in from another location"
|
||||||
// errors.
|
// errors.
|
||||||
connection.disconnect();
|
serverConn.disconnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientPlaySessionHandler playerHandler =
|
ClientPlaySessionHandler playerHandler =
|
||||||
(ClientPlaySessionHandler) connection.getPlayer().getConnection().getSessionHandler();
|
(ClientPlaySessionHandler) serverConn.getPlayer().getConnection().getSessionHandler();
|
||||||
if (packet instanceof KeepAlive) {
|
if (packet instanceof KeepAlive) {
|
||||||
// Forward onto the player
|
// Forward onto the player
|
||||||
connection.setLastPingId(((KeepAlive) packet).getRandomId());
|
serverConn.setLastPingId(((KeepAlive) packet).getRandomId());
|
||||||
connection.getPlayer().getConnection().write(packet);
|
serverConn.getPlayer().getConnection().write(packet);
|
||||||
} else if (packet instanceof Disconnect) {
|
} else if (packet instanceof Disconnect) {
|
||||||
Disconnect original = (Disconnect) packet;
|
Disconnect original = (Disconnect) packet;
|
||||||
connection.disconnect();
|
serverConn.disconnect();
|
||||||
connection.getPlayer().handleConnectionException(connection.getServer(), original);
|
serverConn.getPlayer().handleConnectionException(serverConn.getServer(), original);
|
||||||
} else if (packet instanceof JoinGame) {
|
} else if (packet instanceof JoinGame) {
|
||||||
playerHandler.handleBackendJoinGame((JoinGame) packet);
|
playerHandler.handleBackendJoinGame((JoinGame) packet);
|
||||||
} else if (packet instanceof BossBar) {
|
} else if (packet instanceof BossBar) {
|
||||||
@ -60,7 +60,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
playerHandler.getServerBossBars().remove(bossBar.getUuid());
|
playerHandler.getServerBossBars().remove(bossBar.getUuid());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
connection.getPlayer().getConnection().write(packet);
|
serverConn.getPlayer().getConnection().write(packet);
|
||||||
} else if (packet instanceof PluginMessage) {
|
} else if (packet instanceof PluginMessage) {
|
||||||
PluginMessage pm = (PluginMessage) packet;
|
PluginMessage pm = (PluginMessage) packet;
|
||||||
if (!canForwardPluginMessage(pm)) {
|
if (!canForwardPluginMessage(pm)) {
|
||||||
@ -68,61 +68,61 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (PluginMessageUtil.isMCBrand(pm)) {
|
if (PluginMessageUtil.isMCBrand(pm)) {
|
||||||
connection.getPlayer().getConnection().write(PluginMessageUtil.rewriteMCBrand(pm));
|
serverConn.getPlayer().getConnection().write(PluginMessageUtil.rewriteMCBrand(pm));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!connection.hasCompletedJoin() && pm.getChannel().equals(VelocityConstants.FORGE_LEGACY_HANDSHAKE_CHANNEL)) {
|
if (!serverConn.hasCompletedJoin() && pm.getChannel().equals(VelocityConstants.FORGE_LEGACY_HANDSHAKE_CHANNEL)) {
|
||||||
if (!connection.isLegacyForge()) {
|
if (!serverConn.isLegacyForge()) {
|
||||||
connection.setLegacyForge(true);
|
serverConn.setLegacyForge(true);
|
||||||
|
|
||||||
// We must always reset the handshake before a modded connection is established if
|
// We must always reset the handshake before a modded connection is established if
|
||||||
// we haven't done so already.
|
// we haven't done so already.
|
||||||
connection.getPlayer().sendLegacyForgeHandshakeResetPacket();
|
serverConn.getPlayer().sendLegacyForgeHandshakeResetPacket();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always forward these messages during login
|
// Always forward these messages during login
|
||||||
connection.getPlayer().getConnection().write(pm);
|
serverConn.getPlayer().getConnection().write(pm);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChannelIdentifier id = server.getChannelRegistrar().getFromId(pm.getChannel());
|
ChannelIdentifier id = server.getChannelRegistrar().getFromId(pm.getChannel());
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
connection.getPlayer().getConnection().write(pm);
|
serverConn.getPlayer().getConnection().write(pm);
|
||||||
} else {
|
} else {
|
||||||
PluginMessageEvent event = new PluginMessageEvent(connection, connection.getPlayer(), id, pm.getData());
|
PluginMessageEvent event = new PluginMessageEvent(serverConn, serverConn.getPlayer(), id, pm.getData());
|
||||||
server.getEventManager().fire(event)
|
server.getEventManager().fire(event)
|
||||||
.thenAcceptAsync(pme -> {
|
.thenAcceptAsync(pme -> {
|
||||||
if (pme.getResult().isAllowed()) {
|
if (pme.getResult().isAllowed()) {
|
||||||
connection.getPlayer().getConnection().write(pm);
|
serverConn.getPlayer().getConnection().write(pm);
|
||||||
}
|
}
|
||||||
}, connection.getMinecraftConnection().getChannel().eventLoop());
|
}, serverConn.getConnection().getChannel().eventLoop());
|
||||||
}
|
}
|
||||||
} else if (packet instanceof TabCompleteResponse) {
|
} else if (packet instanceof TabCompleteResponse) {
|
||||||
playerHandler.handleTabCompleteResponse((TabCompleteResponse) packet);
|
playerHandler.handleTabCompleteResponse((TabCompleteResponse) packet);
|
||||||
} else if (connection.hasCompletedJoin()) {
|
} else if (serverConn.hasCompletedJoin()) {
|
||||||
// Just forward the packet on. We don't have anything to handle at this time.
|
// Just forward the packet on. We don't have anything to handle at this time.
|
||||||
connection.getPlayer().getConnection().write(packet);
|
serverConn.getPlayer().getConnection().write(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleUnknown(ByteBuf buf) {
|
public void handleUnknown(ByteBuf buf) {
|
||||||
if (!connection.getPlayer().isActive()) {
|
if (!serverConn.getPlayer().isActive()) {
|
||||||
// Connection was left open accidentally. Close it so as to avoid "You logged in from another location"
|
// Connection was left open accidentally. Close it so as to avoid "You logged in from another location"
|
||||||
// errors.
|
// errors.
|
||||||
connection.disconnect();
|
serverConn.disconnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connection.hasCompletedJoin()) {
|
if (serverConn.hasCompletedJoin()) {
|
||||||
connection.getPlayer().getConnection().write(buf.retain());
|
serverConn.getPlayer().getConnection().write(buf.retain());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exception(Throwable throwable) {
|
public void exception(Throwable throwable) {
|
||||||
connection.getPlayer().handleConnectionException(connection.getServer(), throwable);
|
serverConn.getPlayer().handleConnectionException(serverConn.getServer(), throwable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public VelocityServer getServer() {
|
public VelocityServer getServer() {
|
||||||
@ -131,18 +131,18 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disconnected() {
|
public void disconnected() {
|
||||||
connection.getServer().removePlayer(connection.getPlayer());
|
serverConn.getServer().removePlayer(serverConn.getPlayer());
|
||||||
if (!connection.isGracefulDisconnect()) {
|
if (!serverConn.isGracefulDisconnect()) {
|
||||||
connection.getPlayer().handleConnectionException(connection.getServer(), Disconnect.create(
|
serverConn.getPlayer().handleConnectionException(serverConn.getServer(), Disconnect.create(
|
||||||
ConnectionMessages.UNEXPECTED_DISCONNECT));
|
ConnectionMessages.UNEXPECTED_DISCONNECT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canForwardPluginMessage(PluginMessage message) {
|
private boolean canForwardPluginMessage(PluginMessage message) {
|
||||||
ClientPlaySessionHandler playerHandler =
|
ClientPlaySessionHandler playerHandler =
|
||||||
(ClientPlaySessionHandler) connection.getPlayer().getConnection().getSessionHandler();
|
(ClientPlaySessionHandler) serverConn.getPlayer().getConnection().getSessionHandler();
|
||||||
boolean isMCOrFMLMessage;
|
boolean isMCOrFMLMessage;
|
||||||
if (connection.getMinecraftConnection().getProtocolVersion() <= ProtocolConstants.MINECRAFT_1_12_2) {
|
if (serverConn.getConnection().getProtocolVersion() <= ProtocolConstants.MINECRAFT_1_12_2) {
|
||||||
String channel = message.getChannel();
|
String channel = message.getChannel();
|
||||||
isMCOrFMLMessage = channel.startsWith("MC|") || channel.startsWith(VelocityConstants.FORGE_LEGACY_HANDSHAKE_CHANNEL);
|
isMCOrFMLMessage = channel.startsWith("MC|") || channel.startsWith(VelocityConstants.FORGE_LEGACY_HANDSHAKE_CHANNEL);
|
||||||
} else {
|
} else {
|
||||||
|
@ -27,12 +27,12 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
|
|
||||||
public class LoginSessionHandler implements MinecraftSessionHandler {
|
public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||||
private final VelocityServer server;
|
private final VelocityServer server;
|
||||||
private final VelocityServerConnection connection;
|
private final VelocityServerConnection serverConn;
|
||||||
private boolean informationForwarded;
|
private boolean informationForwarded;
|
||||||
|
|
||||||
public LoginSessionHandler(VelocityServer server, VelocityServerConnection connection) {
|
public LoginSessionHandler(VelocityServer server, VelocityServerConnection serverConn) {
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.connection = connection;
|
this.serverConn = serverConn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -48,9 +48,9 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
response.setSuccess(true);
|
response.setSuccess(true);
|
||||||
response.setId(message.getId());
|
response.setId(message.getId());
|
||||||
response.setData(createForwardingData(configuration.getForwardingSecret(),
|
response.setData(createForwardingData(configuration.getForwardingSecret(),
|
||||||
connection.getPlayer().getRemoteAddress().getHostString(),
|
serverConn.getPlayer().getRemoteAddress().getHostString(),
|
||||||
connection.getPlayer().getProfile()));
|
serverConn.getPlayer().getProfile()));
|
||||||
connection.getMinecraftConnection().write(response);
|
serverConn.getConnection().write(response);
|
||||||
informationForwarded = true;
|
informationForwarded = true;
|
||||||
} else {
|
} else {
|
||||||
// Don't understand
|
// Don't understand
|
||||||
@ -58,48 +58,48 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
response.setSuccess(false);
|
response.setSuccess(false);
|
||||||
response.setId(message.getId());
|
response.setId(message.getId());
|
||||||
response.setData(Unpooled.EMPTY_BUFFER);
|
response.setData(Unpooled.EMPTY_BUFFER);
|
||||||
connection.getMinecraftConnection().write(response);
|
serverConn.getConnection().write(response);
|
||||||
}
|
}
|
||||||
} else if (packet instanceof Disconnect) {
|
} else if (packet instanceof Disconnect) {
|
||||||
Disconnect disconnect = (Disconnect) packet;
|
Disconnect disconnect = (Disconnect) packet;
|
||||||
// Do we have an outstanding notification? If so, fulfill it.
|
// Do we have an outstanding notification? If so, fulfill it.
|
||||||
doNotify(ConnectionRequestResults.forDisconnect(disconnect));
|
doNotify(ConnectionRequestResults.forDisconnect(disconnect));
|
||||||
connection.disconnect();
|
serverConn.disconnect();
|
||||||
} else if (packet instanceof SetCompression) {
|
} else if (packet instanceof SetCompression) {
|
||||||
SetCompression sc = (SetCompression) packet;
|
SetCompression sc = (SetCompression) packet;
|
||||||
connection.getMinecraftConnection().setCompressionThreshold(sc.getThreshold());
|
serverConn.getConnection().setCompressionThreshold(sc.getThreshold());
|
||||||
} else if (packet instanceof ServerLoginSuccess) {
|
} else if (packet instanceof ServerLoginSuccess) {
|
||||||
if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN && !informationForwarded) {
|
if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN && !informationForwarded) {
|
||||||
doNotify(ConnectionRequestResults.forDisconnect(
|
doNotify(ConnectionRequestResults.forDisconnect(
|
||||||
TextComponent.of("Your server did not send a forwarding request to the proxy. Is it set up correctly?")));
|
TextComponent.of("Your server did not send a forwarding request to the proxy. Is it set up correctly?")));
|
||||||
connection.disconnect();
|
serverConn.disconnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The player has been logged on to the backend server.
|
// The player has been logged on to the backend server.
|
||||||
connection.getMinecraftConnection().setState(StateRegistry.PLAY);
|
serverConn.getConnection().setState(StateRegistry.PLAY);
|
||||||
VelocityServerConnection existingConnection = connection.getPlayer().getConnectedServer();
|
VelocityServerConnection existingConnection = serverConn.getPlayer().getConnectedServer();
|
||||||
if (existingConnection == null) {
|
if (existingConnection == null) {
|
||||||
// Strap on the play session handler
|
// Strap on the play session handler
|
||||||
connection.getPlayer().getConnection().setSessionHandler(new ClientPlaySessionHandler(server, connection.getPlayer()));
|
serverConn.getPlayer().getConnection().setSessionHandler(new ClientPlaySessionHandler(server, serverConn.getPlayer()));
|
||||||
} else {
|
} else {
|
||||||
// The previous server connection should become obsolete.
|
// The previous server connection should become obsolete.
|
||||||
// Before we remove it, if the server we are departing is modded, we must always reset the client state.
|
// Before we remove it, if the server we are departing is modded, we must always reset the client state.
|
||||||
if (existingConnection.isLegacyForge()) {
|
if (existingConnection.isLegacyForge()) {
|
||||||
connection.getPlayer().sendLegacyForgeHandshakeResetPacket();
|
serverConn.getPlayer().sendLegacyForgeHandshakeResetPacket();
|
||||||
}
|
}
|
||||||
existingConnection.disconnect();
|
existingConnection.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
doNotify(ConnectionRequestResults.SUCCESSFUL);
|
doNotify(ConnectionRequestResults.SUCCESSFUL);
|
||||||
connection.getMinecraftConnection().setSessionHandler(new BackendPlaySessionHandler(server, connection));
|
serverConn.getConnection().setSessionHandler(new BackendPlaySessionHandler(server, serverConn));
|
||||||
connection.getPlayer().setConnectedServer(connection);
|
serverConn.getPlayer().setConnectedServer(serverConn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exception(Throwable throwable) {
|
public void exception(Throwable throwable) {
|
||||||
CompletableFuture<ConnectionRequestBuilder.Result> future = connection.getMinecraftConnection().getChannel()
|
CompletableFuture<ConnectionRequestBuilder.Result> future = serverConn.getConnection().getChannel()
|
||||||
.attr(VelocityServerConnection.CONNECTION_NOTIFIER).getAndSet(null);
|
.attr(VelocityServerConnection.CONNECTION_NOTIFIER).getAndSet(null);
|
||||||
if (future != null) {
|
if (future != null) {
|
||||||
future.completeExceptionally(throwable);
|
future.completeExceptionally(throwable);
|
||||||
@ -108,7 +108,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disconnected() {
|
public void disconnected() {
|
||||||
CompletableFuture<ConnectionRequestBuilder.Result> future = connection.getMinecraftConnection().getChannel()
|
CompletableFuture<ConnectionRequestBuilder.Result> future = serverConn.getConnection().getChannel()
|
||||||
.attr(VelocityServerConnection.CONNECTION_NOTIFIER).getAndSet(null);
|
.attr(VelocityServerConnection.CONNECTION_NOTIFIER).getAndSet(null);
|
||||||
if (future != null) {
|
if (future != null) {
|
||||||
future.completeExceptionally(new IOException("Unexpectedly disconnected from remote server"));
|
future.completeExceptionally(new IOException("Unexpectedly disconnected from remote server"));
|
||||||
@ -116,7 +116,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void doNotify(ConnectionRequestBuilder.Result result) {
|
private void doNotify(ConnectionRequestBuilder.Result result) {
|
||||||
CompletableFuture<ConnectionRequestBuilder.Result> future = connection.getMinecraftConnection().getChannel()
|
CompletableFuture<ConnectionRequestBuilder.Result> future = serverConn.getConnection().getChannel()
|
||||||
.attr(VelocityServerConnection.CONNECTION_NOTIFIER).getAndSet(null);
|
.attr(VelocityServerConnection.CONNECTION_NOTIFIER).getAndSet(null);
|
||||||
if (future != null) {
|
if (future != null) {
|
||||||
future.complete(result);
|
future.complete(result);
|
||||||
|
@ -40,7 +40,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
|||||||
private final VelocityRegisteredServer registeredServer;
|
private final VelocityRegisteredServer registeredServer;
|
||||||
private final ConnectedPlayer proxyPlayer;
|
private final ConnectedPlayer proxyPlayer;
|
||||||
private final VelocityServer server;
|
private final VelocityServer server;
|
||||||
private MinecraftConnection minecraftConnection;
|
private MinecraftConnection connection;
|
||||||
private boolean legacyForge = false;
|
private boolean legacyForge = false;
|
||||||
private boolean hasCompletedJoin = false;
|
private boolean hasCompletedJoin = false;
|
||||||
private boolean gracefulDisconnect = false;
|
private boolean gracefulDisconnect = false;
|
||||||
@ -78,10 +78,10 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
|||||||
@Override
|
@Override
|
||||||
public void operationComplete(ChannelFuture future) throws Exception {
|
public void operationComplete(ChannelFuture future) throws Exception {
|
||||||
if (future.isSuccess()) {
|
if (future.isSuccess()) {
|
||||||
minecraftConnection = future.channel().pipeline().get(MinecraftConnection.class);
|
connection = future.channel().pipeline().get(MinecraftConnection.class);
|
||||||
|
|
||||||
// Kick off the connection process
|
// Kick off the connection process
|
||||||
minecraftConnection.setSessionHandler(new LoginSessionHandler(server, VelocityServerConnection.this));
|
connection.setSessionHandler(new LoginSessionHandler(server, VelocityServerConnection.this));
|
||||||
startHandshake();
|
startHandshake();
|
||||||
} else {
|
} else {
|
||||||
result.completeExceptionally(future.cause());
|
result.completeExceptionally(future.cause());
|
||||||
@ -116,25 +116,25 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
|||||||
handshake.setServerAddress(registeredServer.getServerInfo().getAddress().getHostString());
|
handshake.setServerAddress(registeredServer.getServerInfo().getAddress().getHostString());
|
||||||
}
|
}
|
||||||
handshake.setPort(registeredServer.getServerInfo().getAddress().getPort());
|
handshake.setPort(registeredServer.getServerInfo().getAddress().getPort());
|
||||||
minecraftConnection.write(handshake);
|
connection.write(handshake);
|
||||||
|
|
||||||
int protocolVersion = proxyPlayer.getConnection().getProtocolVersion();
|
int protocolVersion = proxyPlayer.getConnection().getProtocolVersion();
|
||||||
minecraftConnection.setProtocolVersion(protocolVersion);
|
connection.setProtocolVersion(protocolVersion);
|
||||||
minecraftConnection.setState(StateRegistry.LOGIN);
|
connection.setState(StateRegistry.LOGIN);
|
||||||
|
|
||||||
ServerLogin login = new ServerLogin();
|
ServerLogin login = new ServerLogin();
|
||||||
login.setUsername(proxyPlayer.getUsername());
|
login.setUsername(proxyPlayer.getUsername());
|
||||||
minecraftConnection.write(login);
|
connection.write(login);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeIfJoined(PluginMessage message) {
|
public void writeIfJoined(PluginMessage message) {
|
||||||
if (hasCompletedJoin) {
|
if (hasCompletedJoin) {
|
||||||
minecraftConnection.write(message);
|
connection.write(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MinecraftConnection getMinecraftConnection() {
|
public MinecraftConnection getConnection() {
|
||||||
return minecraftConnection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -153,9 +153,9 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
if (minecraftConnection != null) {
|
if (connection != null) {
|
||||||
minecraftConnection.close();
|
connection.close();
|
||||||
minecraftConnection = null;
|
connection = null;
|
||||||
gracefulDisconnect = true;
|
gracefulDisconnect = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,7 +172,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
|||||||
PluginMessage message = new PluginMessage();
|
PluginMessage message = new PluginMessage();
|
||||||
message.setChannel(identifier.getId());
|
message.setChannel(identifier.getId());
|
||||||
message.setData(data);
|
message.setData(data);
|
||||||
minecraftConnection.write(message);
|
connection.write(message);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
player.setPing(System.currentTimeMillis() - serverConnection.getLastPingSent());
|
player.setPing(System.currentTimeMillis() - serverConnection.getLastPingSent());
|
||||||
serverConnection.getMinecraftConnection().write(packet);
|
serverConnection.getConnection().write(packet);
|
||||||
serverConnection.resetLastPingId();
|
serverConnection.resetLastPingId();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
if (msg.startsWith("/")) {
|
if (msg.startsWith("/")) {
|
||||||
try {
|
try {
|
||||||
if (!server.getCommandManager().execute(player, msg.substring(1))) {
|
if (!server.getCommandManager().execute(player, msg.substring(1))) {
|
||||||
player.getConnectedServer().getMinecraftConnection().write(chat);
|
player.getConnectedServer().getConnection().write(chat);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.info("Exception occurred while running command for {}", player.getProfile().getName(), e);
|
logger.info("Exception occurred while running command for {}", player.getProfile().getName(), e);
|
||||||
@ -98,11 +98,11 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
server.getEventManager().fire(event)
|
server.getEventManager().fire(event)
|
||||||
.thenAcceptAsync(pme -> {
|
.thenAcceptAsync(pme -> {
|
||||||
if (pme.getResult().equals(PlayerChatEvent.ChatResult.allowed())){
|
if (pme.getResult().equals(PlayerChatEvent.ChatResult.allowed())){
|
||||||
player.getConnectedServer().getMinecraftConnection().write(chat);
|
player.getConnectedServer().getConnection().write(chat);
|
||||||
} else if (pme.getResult().isAllowed() && pme.getResult().getMessage().isPresent()){
|
} else if (pme.getResult().isAllowed() && pme.getResult().getMessage().isPresent()){
|
||||||
player.getConnectedServer().getMinecraftConnection().write(Chat.createServerbound(pme.getResult().getMessage().get()));
|
player.getConnectedServer().getConnection().write(Chat.createServerbound(pme.getResult().getMessage().get()));
|
||||||
}
|
}
|
||||||
}, player.getConnectedServer().getMinecraftConnection().getChannel().eventLoop());
|
}, player.getConnectedServer().getConnection().getChannel().eventLoop());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -110,7 +110,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
if (packet instanceof TabCompleteRequest) {
|
if (packet instanceof TabCompleteRequest) {
|
||||||
// Record the request so that the outstanding request can be augmented later.
|
// Record the request so that the outstanding request can be augmented later.
|
||||||
outstandingTabComplete = (TabCompleteRequest) packet;
|
outstandingTabComplete = (TabCompleteRequest) packet;
|
||||||
serverConnection.getMinecraftConnection().write(packet);
|
serverConnection.getConnection().write(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packet instanceof PluginMessage) {
|
if (packet instanceof PluginMessage) {
|
||||||
@ -120,7 +120,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
|
|
||||||
// If we don't want to handle this packet, just forward it on.
|
// If we don't want to handle this packet, just forward it on.
|
||||||
if (serverConnection.hasCompletedJoin()) {
|
if (serverConnection.hasCompletedJoin()) {
|
||||||
serverConnection.getMinecraftConnection().write(packet);
|
serverConnection.getConnection().write(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (serverConnection.hasCompletedJoin()) {
|
if (serverConnection.hasCompletedJoin()) {
|
||||||
serverConnection.getMinecraftConnection().write(buf.retain());
|
serverConnection.getConnection().write(buf.retain());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +157,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
VelocityServerConnection server = player.getConnectedServer();
|
VelocityServerConnection server = player.getConnectedServer();
|
||||||
if (server != null) {
|
if (server != null) {
|
||||||
boolean writable = player.getConnection().getChannel().isWritable();
|
boolean writable = player.getConnection().getChannel().isWritable();
|
||||||
server.getMinecraftConnection().getChannel().config().setAutoRead(writable);
|
server.getConnection().getChannel().config().setAutoRead(writable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,14 +215,14 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
if (!toRegister.isEmpty()) {
|
if (!toRegister.isEmpty()) {
|
||||||
String channel = player.getConnection().getProtocolVersion() >= ProtocolConstants.MINECRAFT_1_13 ?
|
String channel = player.getConnection().getProtocolVersion() >= ProtocolConstants.MINECRAFT_1_13 ?
|
||||||
"minecraft:register" : "REGISTER";
|
"minecraft:register" : "REGISTER";
|
||||||
player.getConnectedServer().getMinecraftConnection().delayedWrite(PluginMessageUtil.constructChannelsPacket(
|
player.getConnectedServer().getConnection().delayedWrite(PluginMessageUtil.constructChannelsPacket(
|
||||||
channel, toRegister));
|
channel, toRegister));
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we had plugin messages queued during login/FML handshake, send them now.
|
// If we had plugin messages queued during login/FML handshake, send them now.
|
||||||
PluginMessage pm;
|
PluginMessage pm;
|
||||||
while ((pm = loginPluginMessages.poll()) != null) {
|
while ((pm = loginPluginMessages.poll()) != null) {
|
||||||
player.getConnectedServer().getMinecraftConnection().delayedWrite(pm);
|
player.getConnectedServer().getConnection().delayedWrite(pm);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear any title from the previous server.
|
// Clear any title from the previous server.
|
||||||
@ -230,7 +230,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
|
|
||||||
// Flush everything
|
// Flush everything
|
||||||
player.getConnection().flush();
|
player.getConnection().flush();
|
||||||
player.getConnectedServer().getMinecraftConnection().flush();
|
player.getConnectedServer().getConnection().flush();
|
||||||
player.getConnectedServer().setHasCompletedJoin(true);
|
player.getConnectedServer().setHasCompletedJoin(true);
|
||||||
if (player.getConnectedServer().isLegacyForge()) {
|
if (player.getConnectedServer().isLegacyForge()) {
|
||||||
// We only need to indicate we can send a reset packet if we complete a handshake, that is,
|
// We only need to indicate we can send a reset packet if we complete a handshake, that is,
|
||||||
@ -268,18 +268,18 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
|
|
||||||
if (actuallyRegistered.size() > 0) {
|
if (actuallyRegistered.size() > 0) {
|
||||||
PluginMessage newRegisterPacket = PluginMessageUtil.constructChannelsPacket(packet.getChannel(), actuallyRegistered);
|
PluginMessage newRegisterPacket = PluginMessageUtil.constructChannelsPacket(packet.getChannel(), actuallyRegistered);
|
||||||
player.getConnectedServer().getMinecraftConnection().write(newRegisterPacket);
|
player.getConnectedServer().getConnection().write(newRegisterPacket);
|
||||||
}
|
}
|
||||||
} else if (PluginMessageUtil.isMCUnregister(packet)) {
|
} else if (PluginMessageUtil.isMCUnregister(packet)) {
|
||||||
List<String> channels = PluginMessageUtil.getChannels(packet);
|
List<String> channels = PluginMessageUtil.getChannels(packet);
|
||||||
clientPluginMsgChannels.removeAll(channels);
|
clientPluginMsgChannels.removeAll(channels);
|
||||||
player.getConnectedServer().getMinecraftConnection().write(packet);
|
player.getConnectedServer().getConnection().write(packet);
|
||||||
} else if (PluginMessageUtil.isMCBrand(packet)) {
|
} else if (PluginMessageUtil.isMCBrand(packet)) {
|
||||||
player.getConnectedServer().getMinecraftConnection().write(PluginMessageUtil.rewriteMCBrand(packet));
|
player.getConnectedServer().getConnection().write(PluginMessageUtil.rewriteMCBrand(packet));
|
||||||
} else if (player.getConnectedServer().isLegacyForge() && !player.getConnectedServer().hasCompletedJoin()) {
|
} else if (player.getConnectedServer().isLegacyForge() && !player.getConnectedServer().hasCompletedJoin()) {
|
||||||
if (packet.getChannel().equals(VelocityConstants.FORGE_LEGACY_HANDSHAKE_CHANNEL)) {
|
if (packet.getChannel().equals(VelocityConstants.FORGE_LEGACY_HANDSHAKE_CHANNEL)) {
|
||||||
// Always forward the FML handshake to the remote server.
|
// Always forward the FML handshake to the remote server.
|
||||||
player.getConnectedServer().getMinecraftConnection().write(packet);
|
player.getConnectedServer().getConnection().write(packet);
|
||||||
} else {
|
} else {
|
||||||
// The client is trying to send messages too early. This is primarily caused by mods, but it's further
|
// The client is trying to send messages too early. This is primarily caused by mods, but it's further
|
||||||
// aggravated by Velocity. To work around these issues, we will queue any non-FML handshake messages to
|
// aggravated by Velocity. To work around these issues, we will queue any non-FML handshake messages to
|
||||||
@ -289,15 +289,15 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
} else {
|
} else {
|
||||||
ChannelIdentifier id = server.getChannelRegistrar().getFromId(packet.getChannel());
|
ChannelIdentifier id = server.getChannelRegistrar().getFromId(packet.getChannel());
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
player.getConnectedServer().getMinecraftConnection().write(packet);
|
player.getConnectedServer().getConnection().write(packet);
|
||||||
} else {
|
} else {
|
||||||
PluginMessageEvent event = new PluginMessageEvent(player, player.getConnectedServer(), id, packet.getData());
|
PluginMessageEvent event = new PluginMessageEvent(player, player.getConnectedServer(), id, packet.getData());
|
||||||
server.getEventManager().fire(event)
|
server.getEventManager().fire(event)
|
||||||
.thenAcceptAsync(pme -> {
|
.thenAcceptAsync(pme -> {
|
||||||
if (pme.getResult().isAllowed()) {
|
if (pme.getResult().isAllowed()) {
|
||||||
player.getConnectedServer().getMinecraftConnection().write(packet);
|
player.getConnectedServer().getConnection().write(packet);
|
||||||
}
|
}
|
||||||
}, player.getConnectedServer().getMinecraftConnection().getChannel().eventLoop());
|
}, player.getConnectedServer().getConnection().getChannel().eventLoop());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -420,7 +420,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
|||||||
@Override
|
@Override
|
||||||
public void spoofChatInput(String input) {
|
public void spoofChatInput(String input) {
|
||||||
Preconditions.checkArgument(input.length() <= Chat.MAX_SERVERBOUND_MESSAGE_LENGTH, "input cannot be greater than " + Chat.MAX_SERVERBOUND_MESSAGE_LENGTH + " characters in length");
|
Preconditions.checkArgument(input.length() <= Chat.MAX_SERVERBOUND_MESSAGE_LENGTH, "input cannot be greater than " + Chat.MAX_SERVERBOUND_MESSAGE_LENGTH + " characters in length");
|
||||||
connectedServer.getMinecraftConnection().write(Chat.createServerbound(input));
|
connectedServer.getConnection().write(Chat.createServerbound(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ConnectionRequestBuilderImpl implements ConnectionRequestBuilder {
|
private class ConnectionRequestBuilderImpl implements ConnectionRequestBuilder {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren