Skip to content

Commit

Permalink
Resolve Cookie API serverbound error
Browse files Browse the repository at this point in the history
  • Loading branch information
R00tB33rMan committed Jun 17, 2024
1 parent e60e206 commit af7cb7a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.velocitypowered.natives.encryption.VelocityCipherFactory;
import com.velocitypowered.natives.util.Natives;
import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.connection.client.HandshakeSessionHandler;
import com.velocitypowered.proxy.connection.client.InitialLoginSessionHandler;
import com.velocitypowered.proxy.connection.client.StatusSessionHandler;
Expand Down Expand Up @@ -391,6 +392,10 @@ public void setState(StateRegistry state) {
this.channel.pipeline().remove(Connections.PLAY_PACKET_QUEUE_INBOUND);
}
}

if (this.association instanceof ConnectedPlayer player) {
player.updateState(state);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import static java.util.concurrent.CompletableFuture.completedFuture;

import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gson.JsonObject;
import com.velocitypowered.api.event.connection.DisconnectEvent;
import com.velocitypowered.api.event.connection.DisconnectEvent.LoginStatus;
Expand Down Expand Up @@ -102,12 +104,15 @@
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Queue;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Consumer;
import net.kyori.adventure.audience.MessageType;
import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.identity.Identity;
Expand All @@ -130,6 +135,7 @@
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.ApiStatus.Internal;
import org.jetbrains.annotations.NotNull;

/**
Expand Down Expand Up @@ -184,6 +190,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
private @Nullable ClientSettingsPacket clientSettingsPacket;
private final ChatQueue chatQueue;
private final ChatBuilderFactory chatBuilderFactory;
private final Map<StateRegistry, Queue<Consumer<Player>>> stateListeners = Maps.newHashMap();

ConnectedPlayer(VelocityServer server, GameProfile profile, MinecraftConnection connection,
@Nullable InetSocketAddress virtualHost, boolean onlineMode,
Expand Down Expand Up @@ -598,12 +605,40 @@ public InternalTabList getTabList() {
return tabList;
}

/**
* Updates the state for listeners that cannot be ran at the current connection phase.
*/
@Internal
public void updateState(@NotNull StateRegistry state) {
final Queue<Consumer<Player>> queue = this.stateListeners.get(state);

if (queue == null) {
return;
}

for (final Consumer<Player> consumer : queue) {
consumer.accept(this);
}
}

@Override
public void disconnect(Component reason) {
if (connection.eventLoop().inEventLoop()) {
disconnect0(reason, false);
if (this.connection.eventLoop().inEventLoop()) {
this.disconnect0(reason, false);
} else {
connection.eventLoop().execute(() -> disconnect0(reason, false));
final boolean duringLogin = this.connection.getState() == StateRegistry.LOGIN;

if (duringLogin) {
this.stateListeners.computeIfAbsent(StateRegistry.PLAY, key -> Lists.newLinkedList())
.add(player -> {
if (player != null) {
player.disconnect(reason);
}
});
return;
}

this.connection.eventLoop().execute(() -> this.disconnect0(reason, duringLogin));
}
}

Expand Down

0 comments on commit af7cb7a

Please sign in to comment.