PendingStreamConnectionHandler class
Пакет: com.hypixel.hytale.server.core.io.stream
Файл: com/hypixel/hytale/server/core/io/stream/PendingStreamConnectionHandler.java
implements: ConnectionHandler
Поля (5)
| Модификаторы | Тип | Имя |
|---|---|---|
final |
HytaleLogger |
LOGGER |
|
StreamType |
var3 |
|
ChannelConnection |
var4 |
|
ConnectionHandler |
var5 |
|
QuicStreamPriority |
var6 |
Методы (4)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
|
|
if if(this.handled) |
|
|
if if(var4 != null) |
|
|
if if(var5 == null) |
private |
void |
rejectAndClosevoid rejectAndClose(@Nonnull StreamType var1, @Nonnull String var2) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.io.stream;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.protocol.NetworkChannel;
class="kw">import com.hypixel.hytale.protocol.ToServerPacket;
class="kw">import com.hypixel.hytale.protocol.io.ChannelConnection;
class="kw">import com.hypixel.hytale.protocol.io.ConnectionHandler;
class="kw">import com.hypixel.hytale.protocol.packets.stream.StreamOpen;
class="kw">import com.hypixel.hytale.protocol.packets.stream.StreamOpenResponse;
class="kw">import com.hypixel.hytale.protocol.packets.stream.StreamType;
class="kw">import com.hypixel.hytale.server.core.io.PacketHandler;
class="kw">import io.netty.handler.codec.quic.QuicStreamPriority;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">public class PendingStreamConnectionHandler class="kw">implements ConnectionHandler {
class="kw">private class="kw">static class="kw">final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass();
class="kw">private class="kw">static class="kw">final int MAX_AUXILIARY_STREAMS = 4;
class="kw">private class="kw">final PacketHandler packetHandler;
class="kw">private class="kw">final StreamManager streamManager;
class="kw">private class="kw">final ChannelConnection channel;
class="kw">private boolean handled;
class="kw">public PendingStreamConnectionHandler(@Nonnull PacketHandler var1, @Nonnull ChannelConnection var2) {
this(var1, StreamManager.getInstance(), var2);
}
class="kw">public PendingStreamConnectionHandler(@Nonnull PacketHandler var1, @Nonnull StreamManager var2, @Nonnull ChannelConnection var3) {
this.packetHandler = var1;
this.streamManager = var2;
this.channel = var3;
}
@Override
class="kw">public void handle(@Nonnull ToServerPacket var1) {
if (this.handled) {
LOGGER.at(Level.WARNING)
.log("Received packet after StreamOpen on pending stream from %s: %s", this.packetHandler.getIdentifier(), var1.getClass().getSimpleName());
} else if (var1 class="kw">instanceof StreamOpen var2) {
this.handled = true;
StreamType var3 = var2.type;
if (this.packetHandler.getAuth() == null) {
LOGGER.at(Level.WARNING).log("Rejecting auxiliary stream from unauthenticated connection %s", this.packetHandler.getIdentifier());
this.rejectAndClose(var3, "Authentication required");
} else if (this.packetHandler.checkStreamOpenRateLimit()) {
LOGGER.at(Level.WARNING).log("Stream open rate limited for %s requesting %s", this.packetHandler.getIdentifier(), var3.name());
this.rejectAndClose(var3, "Rate limited - try again later");
} else if (var3 == StreamType.Game) {
LOGGER.at(Level.WARNING).log("Cannot open Game stream - stream 0 is already the game stream, from %s", this.packetHandler.getIdentifier());
this.rejectAndClose(var3, "Game stream cannot be opened explicitly");
} else if (!this.streamManager.isSupported(var3)) {
LOGGER.at(Level.INFO).log("Unsupported stream type %s from %s", var3.name(), this.packetHandler.getIdentifier());
this.rejectAndClose(var3, "Stream type not supported");
} else {
ChannelConnection var4 = this.packetHandler.getChannel(var3);
if (var4 != null) {
LOGGER.at(Level.INFO)
.log("Replacing stale %s stream for %s (old channel active=%s)", var3.name(), this.packetHandler.getIdentifier(), var4.isActive());
this.packetHandler.compareAndSetChannel(var3, var4, null);
var4.closeConnection();
}
if (this.packetHandler.getAuxiliaryChannelCount() >= 4) {
LOGGER.at(Level.WARNING).log("Maximum auxiliary streams exceeded for %s requesting %s", this.packetHandler.getIdentifier(), var3.name());
this.rejectAndClose(var3, "Maximum auxiliary streams exceeded");
} else {
ConnectionHandler var5 = this.streamManager.createHandler(var3, this.packetHandler, this.channel);
if (var5 == null) {
LOGGER.at(Level.SEVERE).log("Failed to create handler for stream type %s from %s", var3.name(), this.packetHandler.getIdentifier());
this.rejectAndClose(var3, "Internal error");
} else {
LOGGER.at(Level.INFO).log("Opening %s stream for %s", var3.name(), this.packetHandler.getIdentifier());
QuicStreamPriority var6 = this.streamManager.getStreamPriority(var3);
this.channel.updateStreamPriority(var6.urgency(), var6.isIncremental());
this.channel.clearPacketTimeout();
this.channel.setChannelHandler(var5);
this.channel.writeAndFlush(new StreamOpenResponse(var3, true, null));
}
}
}
} else {
LOGGER.at(Level.WARNING).log("Auxiliary stream first packet was not StreamOpen, closing: %s", var1.getClass().getSimpleName());
this.channel.closeConnection();
}
}
class="kw">private void rejectAndClose(@Nonnull StreamType var1, @Nonnull String var2) {
this.channel.writeAndFlush(new StreamOpenResponse(var1, false, var2));
this.channel.closeConnection();
}
@Override
class="kw">public void closed(@Nullable NetworkChannel var1) {
}
@Override
class="kw">public void registered(@Nullable ConnectionHandler var1) {
}
@Override
class="kw">public void unregistered(@Nullable ConnectionHandler var1) {
}
@Override
class="kw">public void logCloseMessage() {
}
}