Recoded client phases and fixed FORGE - FORGE switch
This commit is contained in:
parent
550328863a
commit
6dfbdecfaf
|
|
@ -5,7 +5,7 @@ plugins {
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "org.adde0109"
|
group = "org.adde0109"
|
||||||
version = "1.4.3-beta"
|
version = "1.5.0-beta"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_19;
|
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_19;
|
||||||
import static com.velocitypowered.proxy.protocol.packet.brigadier.ArgumentIdentifier.mapSet;
|
import static com.velocitypowered.proxy.protocol.packet.brigadier.ArgumentIdentifier.mapSet;
|
||||||
|
|
||||||
@Plugin(id = "ambassador", name = "Ambassador", version = "1.4.3-beta", authors = {"adde0109"})
|
@Plugin(id = "ambassador", name = "Ambassador", version = "1.5.0-beta", authors = {"adde0109"})
|
||||||
public class Ambassador {
|
public class Ambassador {
|
||||||
|
|
||||||
//Don't forget to update checkCompatibleVersion() when changing this value
|
//Don't forget to update checkCompatibleVersion() when changing this value
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,8 @@ import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
|
||||||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||||
import com.velocitypowered.proxy.network.Connections;
|
import com.velocitypowered.proxy.network.Connections;
|
||||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
|
||||||
import com.velocitypowered.proxy.protocol.packet.AvailableCommandsPacket;
|
import com.velocitypowered.proxy.protocol.packet.AvailableCommandsPacket;
|
||||||
import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket;
|
import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket;
|
||||||
import net.kyori.adventure.identity.Identity;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.adde0109.ambassador.Ambassador;
|
import org.adde0109.ambassador.Ambassador;
|
||||||
import org.adde0109.ambassador.forge.packet.*;
|
import org.adde0109.ambassador.forge.packet.*;
|
||||||
|
|
@ -69,32 +67,13 @@ public enum VelocityForgeBackendConnectionPhase implements BackendConnectionPhas
|
||||||
|
|
||||||
server.setConnectionPhase(newPhase);
|
server.setConnectionPhase(newPhase);
|
||||||
|
|
||||||
if (player.getPhase() == VelocityForgeClientConnectionPhase.NOT_STARTED ||
|
|
||||||
player.getPhase() == VelocityForgeClientConnectionPhase.IN_PROGRESS) {
|
|
||||||
//Initial Forge
|
|
||||||
player.getConnection().write(message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Forge -> Forge
|
//Forge -> Forge
|
||||||
|
|
||||||
//Reset client if not ready to receive new handshake
|
|
||||||
VelocityForgeClientConnectionPhase clientPhase = (VelocityForgeClientConnectionPhase) player.getPhase();
|
VelocityForgeClientConnectionPhase clientPhase = (VelocityForgeClientConnectionPhase) player.getPhase();
|
||||||
if (clientPhase.getResetType() == VelocityForgeClientConnectionPhase.clientResetType.CRP ||
|
|
||||||
clientPhase.getResetType() == VelocityForgeClientConnectionPhase.clientResetType.SR) {
|
|
||||||
clientPhase.resetConnectionPhase(player);
|
|
||||||
player.getConnection().write(message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//STILL WIP
|
if (!clientPhase.consideredComplete()) {
|
||||||
if (!Ambassador.getInstance().config.isDebugMode()) {
|
//Initial Forge
|
||||||
server.disconnect();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (clientPhase.getResetType() == VelocityForgeClientConnectionPhase.clientResetType.NONE) {
|
|
||||||
if (message instanceof ModListPacket modListPacket) {
|
if (message instanceof ModListPacket modListPacket) {
|
||||||
clientPhase.forgeHandshake = new ForgeHandshake();
|
clientPhase.forgeHandshake = new ForgeHandshake();
|
||||||
}
|
}
|
||||||
|
|
@ -103,6 +82,14 @@ public enum VelocityForgeBackendConnectionPhase implements BackendConnectionPhas
|
||||||
}
|
}
|
||||||
player.getConnection().write(message);
|
player.getConnection().write(message);
|
||||||
} else {
|
} else {
|
||||||
|
//Reset client if not ready to receive new handshake
|
||||||
|
if (clientPhase.getResetType() == VelocityForgeClientConnectionPhase.ClientResetType.CRP ||
|
||||||
|
clientPhase.getResetType() == VelocityForgeClientConnectionPhase.ClientResetType.SR) {
|
||||||
|
clientPhase.resetConnectionPhase(player);
|
||||||
|
player.getConnection().write(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (message instanceof ModListPacket modListPacket) {
|
if (message instanceof ModListPacket modListPacket) {
|
||||||
remainingRegistries = new CountDownLatch(modListPacket.getRegistries().size());
|
remainingRegistries = new CountDownLatch(modListPacket.getRegistries().size());
|
||||||
|
|
||||||
|
|
@ -120,9 +107,9 @@ public enum VelocityForgeBackendConnectionPhase implements BackendConnectionPhas
|
||||||
}).thenAcceptAsync((v) -> {
|
}).thenAcceptAsync((v) -> {
|
||||||
|
|
||||||
if(Ambassador.getInstance().config.isDebugMode()) {
|
if(Ambassador.getInstance().config.isDebugMode()) {
|
||||||
player.sendMessage(Component.text("Handshake took: " + (System.currentTimeMillis()-time)/1000 + " seconds"));
|
player.sendMessage(Component.text("Handshake took: " + (System.currentTimeMillis()-time) + " ms"));
|
||||||
player.sendMessage(Component.text("Avg packet time" +
|
player.sendMessage(Component.text("Avg packet time" +
|
||||||
((System.currentTimeMillis()-time)/1000)/modListPacket.getRegistries().size() + " seconds"));
|
(System.currentTimeMillis()-time)/modListPacket.getRegistries().size() + " ms"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ambassador.getInstance().config.isBypassRegistryCheck() ||
|
if (Ambassador.getInstance().config.isBypassRegistryCheck() ||
|
||||||
|
|
|
||||||
|
|
@ -37,17 +37,12 @@ public enum VelocityForgeClientConnectionPhase implements ClientConnectionPhase
|
||||||
public void complete(ConnectedPlayer player) {
|
public void complete(ConnectedPlayer player) {
|
||||||
//When no handshake has taken place.
|
//When no handshake has taken place.
|
||||||
//Test if the client supports CRP.
|
//Test if the client supports CRP.
|
||||||
clientResetType.CRP.doReset(player);
|
ClientResetType.CRP.doReset(player);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean consideredComplete() {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
IN_PROGRESS {
|
IN_PROGRESS {
|
||||||
},
|
},
|
||||||
WAITING_RESET {
|
WAITING_RESET() {
|
||||||
@Override
|
@Override
|
||||||
void onTransitionToNewPhase(ConnectedPlayer player) {
|
void onTransitionToNewPhase(ConnectedPlayer player) {
|
||||||
//We unregister so no plugin sees this client while the client is being reset.
|
//We unregister so no plugin sees this client while the client is being reset.
|
||||||
|
|
@ -70,7 +65,7 @@ public enum VelocityForgeClientConnectionPhase implements ClientConnectionPhase
|
||||||
|
|
||||||
if (!(server.getConnection().getType() instanceof ForgeFMLConnectionType)) {
|
if (!(server.getConnection().getType() instanceof ForgeFMLConnectionType)) {
|
||||||
// -> vanilla
|
// -> vanilla
|
||||||
complete(player, ((Context.ClientContext) msg.getContext()).success() ? clientResetType.CRP : clientResetType.UNKNOWN);
|
complete(player, ((Context.ClientContext) msg.getContext()).success() ? ClientResetType.CRP : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.getConnectionInFlight() != null) {
|
if (player.getConnectionInFlight() != null) {
|
||||||
|
|
@ -84,8 +79,15 @@ public enum VelocityForgeClientConnectionPhase implements ClientConnectionPhase
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
COMPLETE {
|
COMPLETE {
|
||||||
|
|
||||||
|
private ClientResetType resetType = ClientResetType.UNKNOWN;
|
||||||
@Override
|
@Override
|
||||||
void onTransitionToNewPhase(ConnectedPlayer player) {
|
void onTransitionToNewPhase(ConnectedPlayer player) {
|
||||||
|
//Send Login Success to client
|
||||||
|
MinecraftConnection connection = player.getConnection();
|
||||||
|
((OutboundSuccessHolder) connection.getChannel().pipeline().get(ForgeConstants.SERVER_SUCCESS_LISTENER))
|
||||||
|
.sendPacket();
|
||||||
|
connection.setState(StateRegistry.PLAY);
|
||||||
//Plugins may now send packets to client
|
//Plugins may now send packets to client
|
||||||
player.getConnection().getChannel().pipeline().remove(ForgeConstants.PLUGIN_PACKET_QUEUE);
|
player.getConnection().getChannel().pipeline().remove(ForgeConstants.PLUGIN_PACKET_QUEUE);
|
||||||
((VelocityServer) Ambassador.getInstance().server).registerConnection(player);
|
((VelocityServer) Ambassador.getInstance().server).registerConnection(player);
|
||||||
|
|
@ -102,19 +104,29 @@ public enum VelocityForgeClientConnectionPhase implements ClientConnectionPhase
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void complete(ConnectedPlayer player, clientResetType resetType) {
|
public void complete(ConnectedPlayer player) {
|
||||||
if (Ambassador.getInstance().config.isDebugMode()) {
|
if (Ambassador.getInstance().config.isDebugMode()) {
|
||||||
player.sendMessage(Component.text("Forge -> Vanilla - Not resetting"));
|
player.sendMessage(Component.text("Not resetting"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void setResetType(ConnectedPlayer player, ClientResetType resetType) {
|
||||||
|
this.resetType = resetType;
|
||||||
|
if (Ambassador.getInstance().config.isDebugMode()) {
|
||||||
|
player.sendMessage(Component.text("Reset type: " + this.resetType.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClientResetType getResetType() {
|
||||||
|
return resetType;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//TODO: Make a new class that's linked to each player with these fields instead of having them in this phase class
|
//TODO: Make a new class that's linked to each player with these fields instead of having them in this phase class
|
||||||
public ForgeHandshake forgeHandshake = new ForgeHandshake();
|
public ForgeHandshake forgeHandshake = new ForgeHandshake();
|
||||||
|
|
||||||
private clientResetType resetType = clientResetType.UNKNOWN;
|
|
||||||
|
|
||||||
public boolean handle(ConnectedPlayer player, IForgeLoginWrapperPacket<Context.ClientContext> msg, VelocityServerConnection server) {
|
public boolean handle(ConnectedPlayer player, IForgeLoginWrapperPacket<Context.ClientContext> msg, VelocityServerConnection server) {
|
||||||
|
|
||||||
if (msg instanceof ModListReplyPacket replyPacket) {
|
if (msg instanceof ModListReplyPacket replyPacket) {
|
||||||
|
|
@ -137,47 +149,24 @@ public enum VelocityForgeClientConnectionPhase implements ClientConnectionPhase
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void complete(ConnectedPlayer player) {
|
public void complete(ConnectedPlayer player) {
|
||||||
complete(player, getResetType(player));
|
complete(player, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void complete(ConnectedPlayer player, clientResetType resetType) {
|
public void complete(ConnectedPlayer player, ClientResetType resetType) {
|
||||||
MinecraftConnection connection = player.getConnection();
|
|
||||||
//Send Login Success to client
|
|
||||||
((OutboundSuccessHolder) connection.getChannel().pipeline().get(ForgeConstants.SERVER_SUCCESS_LISTENER))
|
|
||||||
.sendPacket();
|
|
||||||
connection.setState(StateRegistry.PLAY);
|
|
||||||
|
|
||||||
//Change phase to COMPLETE
|
//Change phase to COMPLETE
|
||||||
player.setPhase(COMPLETE);
|
player.setPhase(COMPLETE);
|
||||||
COMPLETE.resetType = resetType;
|
|
||||||
COMPLETE.onTransitionToNewPhase(player);
|
COMPLETE.onTransitionToNewPhase(player);
|
||||||
COMPLETE.forgeHandshake = forgeHandshake;
|
COMPLETE.forgeHandshake = forgeHandshake;
|
||||||
|
if (resetType != null) {
|
||||||
|
COMPLETE.setResetType(player, resetType);
|
||||||
|
}
|
||||||
|
|
||||||
if (Ambassador.getInstance().config.isDebugMode()) {
|
if (Ambassador.getInstance().config.isDebugMode()) {
|
||||||
player.sendMessage(Component.text("Forge handshake complete"));
|
player.sendMessage(Component.text("Forge handshake complete"));
|
||||||
player.sendMessage(Component.text("Reset type: " + resetType.toString()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private clientResetType getResetType(ConnectedPlayer player) {
|
|
||||||
if (Ambassador.getInstance().config.isDebugMode()) {
|
|
||||||
player.sendMessage(Component.text("Scanning modlist for client reset mods"));
|
|
||||||
}
|
|
||||||
if (player.getModInfo().isPresent()) {
|
|
||||||
if (player.getModInfo().get().getMods().stream().anyMatch((mod -> mod.getId().equals("clientresetpacket")))) {
|
|
||||||
return clientResetType.CRP;
|
|
||||||
} else if (Ambassador.getInstance().config.getServerSwitchCancellationTime() >= 0 &&
|
|
||||||
player.getModInfo().get().getMods().stream().anyMatch((mod -> mod.getId().equals("serverredirect")
|
|
||||||
|| mod.getId().equals("srvredirect:red")))
|
|
||||||
&& player.getVirtualHost().isPresent()) {
|
|
||||||
return clientResetType.SR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return clientResetType.NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void onTransitionToNewPhase(ConnectedPlayer player) {
|
void onTransitionToNewPhase(ConnectedPlayer player) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -191,10 +180,35 @@ public enum VelocityForgeClientConnectionPhase implements ClientConnectionPhase
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public clientResetType getResetType() {
|
public ClientResetType getResetType() {
|
||||||
return resetType;
|
return COMPLETE.getResetType();
|
||||||
}
|
}
|
||||||
enum clientResetType {
|
|
||||||
|
private ClientResetType getResetType(ConnectedPlayer player) {
|
||||||
|
if (Ambassador.getInstance().config.isDebugMode()) {
|
||||||
|
player.sendMessage(Component.text("Scanning modlist for client reset mods"));
|
||||||
|
}
|
||||||
|
if (player.getModInfo().isPresent()) {
|
||||||
|
if (player.getModInfo().get().getMods().stream().anyMatch((mod -> mod.getId().equals("clientresetpacket")))) {
|
||||||
|
return ClientResetType.CRP;
|
||||||
|
} else if (Ambassador.getInstance().config.getServerSwitchCancellationTime() >= 0 &&
|
||||||
|
player.getModInfo().get().getMods().stream().anyMatch((mod -> mod.getId().equals("serverredirect")
|
||||||
|
|| mod.getId().equals("srvredirect:red")))
|
||||||
|
&& player.getVirtualHost().isPresent()) {
|
||||||
|
return ClientResetType.SR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ClientResetType.NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setResetType(ConnectedPlayer player, ClientResetType resetType) {
|
||||||
|
COMPLETE.setResetType(player, resetType);
|
||||||
|
}
|
||||||
|
public void updateResetType(ConnectedPlayer player) {
|
||||||
|
COMPLETE.setResetType(player, getResetType(player));
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ClientResetType {
|
||||||
UNKNOWN,
|
UNKNOWN,
|
||||||
NONE,
|
NONE,
|
||||||
CRP {
|
CRP {
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,12 @@ public class VelocityEventHandler {
|
||||||
player.setModInfo(new ModInfo("Channels", event.getChannels().stream().map((id) -> {
|
player.setModInfo(new ModInfo("Channels", event.getChannels().stream().map((id) -> {
|
||||||
return new ModInfo.Mod(id.getId(), "");
|
return new ModInfo.Mod(id.getId(), "");
|
||||||
}).toList()));
|
}).toList()));
|
||||||
|
|
||||||
|
VelocityForgeClientConnectionPhase clientPhase = (VelocityForgeClientConnectionPhase) player.getPhase();
|
||||||
|
//If reset typ is still unknown, set it!
|
||||||
|
if (clientPhase.getResetType() == VelocityForgeClientConnectionPhase.ClientResetType.UNKNOWN) {
|
||||||
|
clientPhase.updateResetType(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,8 @@ public class ForgeLoginSessionHandler implements MinecraftSessionHandler {
|
||||||
if (serverConnection.getConnection() != null) {
|
if (serverConnection.getConnection() != null) {
|
||||||
ConnectedPlayer player = serverConnection.getPlayer();
|
ConnectedPlayer player = serverConnection.getPlayer();
|
||||||
|
|
||||||
((VelocityForgeClientConnectionPhase) player.getPhase()).complete(player);
|
VelocityForgeClientConnectionPhase clientPhase = (VelocityForgeClientConnectionPhase) player.getPhase();
|
||||||
|
clientPhase.complete(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user