Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-12-24 23:30:26 +01:00
Clean up LoginPluginResponse and use DeferredByteBufHolder too
Dieser Commit ist enthalten in:
Ursprung
8bf9e0e829
Commit
2671590ad2
@ -1,6 +1,5 @@
|
|||||||
package com.velocitypowered.proxy.connection.backend;
|
package com.velocitypowered.proxy.connection.backend;
|
||||||
|
|
||||||
import com.velocitypowered.api.proxy.ConnectionRequestBuilder;
|
|
||||||
import com.velocitypowered.api.util.GameProfile;
|
import com.velocitypowered.api.util.GameProfile;
|
||||||
import com.velocitypowered.proxy.VelocityServer;
|
import com.velocitypowered.proxy.VelocityServer;
|
||||||
import com.velocitypowered.proxy.config.PlayerInfoForwarding;
|
import com.velocitypowered.proxy.config.PlayerInfoForwarding;
|
||||||
@ -56,23 +55,16 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
MinecraftConnection mc = serverConn.ensureConnected();
|
MinecraftConnection mc = serverConn.ensureConnected();
|
||||||
VelocityConfiguration configuration = server.getConfiguration();
|
VelocityConfiguration configuration = server.getConfiguration();
|
||||||
if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN && packet
|
if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN && packet
|
||||||
.getChannel()
|
.getChannel().equals(VelocityConstants.VELOCITY_IP_FORWARDING_CHANNEL)) {
|
||||||
.equals(VelocityConstants.VELOCITY_IP_FORWARDING_CHANNEL)) {
|
ByteBuf forwardingData = createForwardingData(configuration.getForwardingSecret(),
|
||||||
LoginPluginResponse response = new LoginPluginResponse();
|
|
||||||
response.setSuccess(true);
|
|
||||||
response.setId(packet.getId());
|
|
||||||
response.setData(createForwardingData(configuration.getForwardingSecret(),
|
|
||||||
serverConn.getPlayer().getRemoteAddress().getHostString(),
|
serverConn.getPlayer().getRemoteAddress().getHostString(),
|
||||||
serverConn.getPlayer().getGameProfile()));
|
serverConn.getPlayer().getGameProfile());
|
||||||
|
LoginPluginResponse response = new LoginPluginResponse(packet.getId(), true, forwardingData);
|
||||||
mc.write(response);
|
mc.write(response);
|
||||||
informationForwarded = true;
|
informationForwarded = true;
|
||||||
} else {
|
} else {
|
||||||
// Don't understand
|
// Don't understand
|
||||||
LoginPluginResponse response = new LoginPluginResponse();
|
mc.write(new LoginPluginResponse(packet.getId(), false, Unpooled.EMPTY_BUFFER));
|
||||||
response.setSuccess(false);
|
|
||||||
response.setId(packet.getId());
|
|
||||||
response.setData(Unpooled.EMPTY_BUFFER);
|
|
||||||
mc.write(response);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -4,14 +4,25 @@ import com.velocitypowered.api.network.ProtocolVersion;
|
|||||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||||
|
import com.velocitypowered.proxy.protocol.util.DeferredByteBufHolder;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
|
|
||||||
public class LoginPluginResponse implements MinecraftPacket {
|
public class LoginPluginResponse extends DeferredByteBufHolder implements MinecraftPacket {
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
private boolean success;
|
private boolean success;
|
||||||
private ByteBuf data = Unpooled.EMPTY_BUFFER;
|
|
||||||
|
public LoginPluginResponse() {
|
||||||
|
super(Unpooled.EMPTY_BUFFER);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LoginPluginResponse(int id, boolean success, @MonotonicNonNull ByteBuf buf) {
|
||||||
|
super(buf);
|
||||||
|
this.id = id;
|
||||||
|
this.success = success;
|
||||||
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
@ -29,20 +40,12 @@ public class LoginPluginResponse implements MinecraftPacket {
|
|||||||
this.success = success;
|
this.success = success;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ByteBuf getData() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setData(ByteBuf data) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "LoginPluginResponse{"
|
return "LoginPluginResponse{"
|
||||||
+ "id=" + id
|
+ "id=" + id
|
||||||
+ ", success=" + success
|
+ ", success=" + success
|
||||||
+ ", data=" + data
|
+ ", data=" + super.toString()
|
||||||
+ '}';
|
+ '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,9 +54,9 @@ public class LoginPluginResponse implements MinecraftPacket {
|
|||||||
this.id = ProtocolUtils.readVarInt(buf);
|
this.id = ProtocolUtils.readVarInt(buf);
|
||||||
this.success = buf.readBoolean();
|
this.success = buf.readBoolean();
|
||||||
if (buf.isReadable()) {
|
if (buf.isReadable()) {
|
||||||
this.data = buf.readSlice(buf.readableBytes());
|
this.replace(buf.readSlice(buf.readableBytes()));
|
||||||
} else {
|
} else {
|
||||||
this.data = Unpooled.EMPTY_BUFFER;
|
this.replace(Unpooled.EMPTY_BUFFER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +64,7 @@ public class LoginPluginResponse implements MinecraftPacket {
|
|||||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
||||||
ProtocolUtils.writeVarInt(buf, id);
|
ProtocolUtils.writeVarInt(buf, id);
|
||||||
buf.writeBoolean(success);
|
buf.writeBoolean(success);
|
||||||
buf.writeBytes(data);
|
buf.writeBytes(content());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren