InitialPacketHandler class
Пакет: com.hypixel.hytale.server.core.io.handlers
Файл: com/hypixel/hytale/server/core/io/handlers/InitialPacketHandler.java
extends: PacketHandler
Поля (34)
| Модификаторы | Тип | Имя |
|---|---|---|
final |
int |
MAX_REFERRAL_DATA_SIZE |
|
|
break |
|
|
break |
|
|
break |
|
|
return |
|
|
return |
|
|
return |
|
|
return |
|
|
return |
|
|
return |
|
String |
var1 |
|
QuicApplicationErrorCode |
var10 |
|
String |
var11 |
|
String |
var12 |
|
HytaleServerConfig.TimeoutProfile |
var13 |
|
Message |
var14 |
|
HytaleServerConfig.TimeoutProfile |
var2 |
|
ProtocolVersion |
var2 |
|
Options.AuthMode |
var2 |
|
UUID |
var2 |
|
String |
var3 |
|
|
var3 |
|
PlayerSkin |
var3 |
|
byte[] |
var3 |
|
boolean |
var4 |
|
byte[] |
var4 |
|
boolean |
var5 |
|
boolean |
var5 |
|
Options.AuthMode |
var6 |
|
PasswordPacketHandler.SetupHandlerSupplier |
var6 |
|
AuthenticationPacketHandler.AuthHandlerSupplier |
var7 |
|
PlayerAuthentication |
var7 |
|
int |
var8 |
|
int |
var9 |
Методы (25)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
private |
record |
PendingConnectDatarecord PendingConnectData(@Nonnull ClientType clientType,
@Nonnull String language,
@Nullable byte[] referralData,
@Nullable HostAddress referralSource,
@Nonnull ProtocolVersion protocolVersion) |
static |
byte[] |
generatePasswordChallengeIfNeededbyte[] generatePasswordChallengeIfNeeded(UUID var0) |
public |
void |
handlevoid handle(@Nonnull Connect var1) |
public |
void |
handlevoid handle(@Nonnull InsecurePlayerOptions var1) |
public |
void |
handlevoid handle(@Nonnull ClientDisconnect var1) |
|
|
if if(this.receivedConnect) |
|
|
if if(this.receivedConnect) |
|
|
if if(var1.protocolCrc != -423274174) |
|
|
if if(var3 == null) |
|
|
if if(var1.referralData != null && var1.referralData.length > 4096) |
|
|
if if(var1.referralData != null) |
|
|
if if(var1.referralSource == null) |
|
|
if if(var6 == Options.AuthMode.AUTHENTICATED && !var4) |
|
|
if if(var6 == Options.AuthMode.AUTHENTICATED) |
|
|
if if(var5 && var7 == null) |
|
|
if if(this.receivedConnect && !this.receivedInsecureOptions && this.connectData != null) |
|
|
if if(var2 == Options.AuthMode.AUTHENTICATED) |
|
|
if if(var3 != null) |
|
|
if if(var2 == Options.AuthMode.OFFLINE) |
|
|
if if(!Constants.SINGLEPLAYER) |
|
|
if if(this.connectData.referralData != null) |
|
|
if if(this.connectData.referralSource != null) |
|
|
if if(var3 != null) |
|
|
if if(Constants.SINGLEPLAYER) |
abstract |
|
super super(var1, null) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.io.handlers;
class="kw">import com.hypixel.hytale.common.util.java.ManifestUtil;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.protocol.FormattedMessage;
class="kw">import com.hypixel.hytale.protocol.HostAddress;
class="kw">import com.hypixel.hytale.protocol.PlayerSkin;
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.auth.ConnectAccept;
class="kw">import com.hypixel.hytale.protocol.packets.connection.ClientDisconnect;
class="kw">import com.hypixel.hytale.protocol.packets.connection.ClientType;
class="kw">import com.hypixel.hytale.protocol.packets.connection.Connect;
class="kw">import com.hypixel.hytale.protocol.packets.connection.InsecurePlayerOptions;
class="kw">import com.hypixel.hytale.protocol.packets.connection.QuicApplicationErrorCode;
class="kw">import com.hypixel.hytale.protocol.packets.connection.RequestInsecurePlayerOptions;
class="kw">import com.hypixel.hytale.server.core.Constants;
class="kw">import com.hypixel.hytale.server.core.HytaleServer;
class="kw">import com.hypixel.hytale.server.core.HytaleServerConfig;
class="kw">import com.hypixel.hytale.server.core.Message;
class="kw">import com.hypixel.hytale.server.core.Options;
class="kw">import com.hypixel.hytale.server.core.auth.PlayerAuthentication;
class="kw">import com.hypixel.hytale.server.core.cosmetics.CosmeticsModule;
class="kw">import com.hypixel.hytale.server.core.io.PacketHandler;
class="kw">import com.hypixel.hytale.server.core.io.ProtocolVersion;
class="kw">import com.hypixel.hytale.server.core.io.handlers.login.AuthenticationPacketHandler;
class="kw">import com.hypixel.hytale.server.core.io.handlers.login.PasswordPacketHandler;
class="kw">import com.hypixel.hytale.server.core.modules.singleplayer.SingleplayerModule;
class="kw">import java.security.SecureRandom;
class="kw">import java.util.UUID;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">public class InitialPacketHandler class="kw">extends PacketHandler {
class="kw">private class="kw">static class="kw">final int MAX_REFERRAL_DATA_SIZE = 4096;
@Nullable
class="kw">public class="kw">static AuthenticationPacketHandler.AuthHandlerSupplier EDITOR_PACKET_HANDLER_SUPPLIER;
class="kw">private boolean receivedConnect;
class="kw">private boolean receivedInsecureOptions;
@Nullable
class="kw">private InitialPacketHandler.PendingConnectData connectData;
class="kw">public InitialPacketHandler(@Nonnull ChannelConnection var1) {
super(var1, null);
}
@Nonnull
@Override
class="kw">public String getIdentifier() {
class="kw">return "{Initial(" + this.getChannel().formatRemoteAddress() + ")}";
}
@Override
class="kw">public void registered0(ConnectionHandler var1) {
HytaleServerConfig.TimeoutProfile var2 = HytaleServer.get().getConfig().getConnectionTimeouts();
this.initStage("initial", var2.getInitial(), () -> !this.registered);
this.getChannel().logConnectionTimings("Registered", Level.FINE);
}
@Override
class="kw">public void accept(@Nonnull ToServerPacket var1) {
class="kw">switch (var1.getId()) {
case 0:
this.handle((Connect)var1);
break;
case 1:
this.handle((ClientDisconnect)var1);
break;
case 363:
this.handle((InsecurePlayerOptions)var1);
break;
class="kw">default:
this.disconnect(Message.translation("client.general.disconnect.protocol.unexpectedPacket").param("packetId", var1.getId()));
}
}
@Override
class="kw">public void disconnect(@Nonnull FormattedMessage var1) {
if (this.receivedConnect) {
super.disconnect(var1);
} else {
HytaleLogger.getLogger().at(Level.INFO).log("Silently disconnecting %s because no Connect packet!", this.getChannel().formatRemoteAddress());
this.getChannel().closeConnection();
}
}
class="kw">public void handle(@Nonnull Connect var1) {
if (this.receivedConnect) {
this.disconnect(Message.translation("client.general.disconnect.protocol.unexpectedPacket"));
} else {
this.receivedConnect = true;
this.clearTimeout();
this.getChannel().logConnectionTimings("Connect", Level.FINE);
if (var1.protocolCrc != -423274174) {
int var8 = var1.protocolBuildNumber;
int var9 = 209;
QuicApplicationErrorCode var10 = var8 < var9 ? QuicApplicationErrorCode.ClientOutdated : QuicApplicationErrorCode.ServerOutdated;
String var11 = var10 == QuicApplicationErrorCode.ClientOutdated
? "client.general.disconnect.clientOutdated"
: "client.general.disconnect.serverOutdated";
String var12 = ManifestUtil.getImplementationVersion();
Message var14 = Message.translation(var11).param("version", var12 != null ? var12 : "unknown");
this.getChannel().closeApplicationConnection(var10, var14.getFormattedMessage());
} else if (HytaleServer.get().isShuttingDown()) {
this.disconnect(Message.translation("client.general.disconnect.serverShuttingDown"));
} else if (!HytaleServer.get().isBooted()) {
this.disconnect(Message.translation("client.general.disconnect.serverBooting"));
} else {
ProtocolVersion var2 = new ProtocolVersion(var1.protocolCrc);
String var3 = var1.language;
if (var3 == null) {
var3 = "en-US";
}
if (var1.referralData != null && var1.referralData.length > 4096) {
HytaleLogger.getLogger()
.at(Level.WARNING)
.log(
"Rejecting connection from %s - referral data too large: %d bytes (max: %d)",
this.getChannel().formatRemoteAddress(),
var1.referralData.length,
4096
);
this.disconnect(Message.translation("client.general.disconnect.referralDataTooLarge").param("maxSize", 4096));
} else {
if (var1.referralData != null) {
if (var1.referralSource == null) {
HytaleLogger.getLogger()
.at(Level.WARNING)
.log("Rejecting connection from %s - referral data provided without source address", this.getChannel().formatRemoteAddress());
this.disconnect(Message.translation("client.general.disconnect.referralMissingSource"));
class="kw">return;
}
if (var1.referralSource.host == null || var1.referralSource.host.isEmpty()) {
HytaleLogger.getLogger()
.at(Level.WARNING)
.log("Rejecting connection from %s - referral source has empty host", this.getChannel().formatRemoteAddress());
this.disconnect(Message.translation("client.general.disconnect.referralInvalidSource"));
class="kw">return;
}
}
boolean var4 = var1.identityToken != null && !var1.identityToken.isEmpty();
boolean var5 = var1.clientType == ClientType.Editor;
Options.AuthMode var6 = (Options.AuthMode)Options.getOptionSet().valueOf(Options.AUTH_MODE);
if (var6 == Options.AuthMode.AUTHENTICATED && !var4) {
HytaleLogger.getLogger()
.at(Level.WARNING)
.log(
"Rejecting development connection from %s - server requires authentication (auth-mode=%s)",
this.getChannel().formatRemoteAddress(),
var6
);
this.disconnect(Message.translation("client.general.disconnect.serverRequiresAuthentication"));
} else {
if (var6 == Options.AuthMode.AUTHENTICATED) {
AuthenticationPacketHandler.AuthHandlerSupplier var7 = var5 ? EDITOR_PACKET_HANDLER_SUPPLIER : SetupPacketHandler::new;
if (var5 && var7 == null) {
this.disconnect(Message.translation("client.general.disconnect.editorNotSupported"));
class="kw">return;
}
HytaleLogger.getLogger().at(Level.INFO).log("Starting authenticated flow from %s", this.getChannel().formatRemoteAddress());
this.getChannel()
.setChannelHandler(
new AuthenticationPacketHandler(
this.getChannel(), var2, var3, var7, var1.clientType, var1.identityToken, var1.referralData, var1.referralSource
)
);
} else {
this.connectData = new InitialPacketHandler.PendingConnectData(var1.clientType, var3, var1.referralData, var1.referralSource, var2);
this.write(new RequestInsecurePlayerOptions());
HytaleServerConfig.TimeoutProfile var13 = HytaleServer.get().getConfig().getConnectionTimeouts();
this.continueStage("initial:insecure-options", var13.getInitial(), () -> this.receivedInsecureOptions);
}
}
}
}
}
}
class="kw">public void handle(@Nonnull InsecurePlayerOptions var1) {
if (this.receivedConnect && !this.receivedInsecureOptions && this.connectData != null) {
this.receivedInsecureOptions = true;
Options.AuthMode var2 = (Options.AuthMode)Options.getOptionSet().valueOf(Options.AUTH_MODE);
if (var2 == Options.AuthMode.AUTHENTICATED) {
this.disconnect(Message.translation("client.general.disconnect.protocol.unexpectedPacket"));
} else if (var1.uuid == null) {
this.disconnect(Message.translation("client.general.disconnect.missingUuid"));
} else if (var1.username != null && !var1.username.isEmpty()) {
PlayerSkin var3 = var1.skin;
if (var3 != null) {
try {
CosmeticsModule.get().validateSkin(var3);
} catch (CosmeticsModule.InvalidSkinException var8) {
this.disconnect(Message.translation("client.general.disconnect.invalidSkin").param("details", var8.getMessage()));
class="kw">return;
}
}
if (var2 == Options.AuthMode.OFFLINE) {
if (!Constants.SINGLEPLAYER) {
HytaleLogger.getLogger()
.at(Level.WARNING)
.log("Rejecting connection from %s - offline mode is only valid in singleplayer", this.getChannel().formatRemoteAddress());
this.disconnect(Message.translation("client.general.disconnect.offlineModeSingleplayerOnly"));
class="kw">return;
}
if (!SingleplayerModule.isOwner(var1.uuid)) {
HytaleLogger.getLogger()
.at(Level.WARNING)
.log(
"Rejecting connection from %s (%s) - offline mode only allows the world owner (%s)",
var1.username,
var1.uuid,
SingleplayerModule.getUuid()
);
this.disconnect(Message.translation("client.general.disconnect.offlineModeOwnerOnly"));
class="kw">return;
}
}
HytaleLogger.getLogger()
.at(Level.INFO)
.log("Starting development flow for %s (%s) from %s", var1.username, var1.uuid, this.getChannel().formatRemoteAddress());
byte[] var4 = generatePasswordChallengeIfNeeded(var1.uuid);
this.write(new ConnectAccept(var4));
boolean var5 = this.connectData.clientType == ClientType.Editor;
PasswordPacketHandler.SetupHandlerSupplier var6 = var5 && EDITOR_PACKET_HANDLER_SUPPLIER != null
? (var0, var1x, var2x, var3x) -> EDITOR_PACKET_HANDLER_SUPPLIER.create(var0, var1x, var2x, var3x)
: SetupPacketHandler::new;
PlayerAuthentication var7 = new PlayerAuthentication(var1.uuid, var1.username);
if (this.connectData.referralData != null) {
var7.setReferralData(this.connectData.referralData);
}
if (this.connectData.referralSource != null) {
var7.setReferralSource(this.connectData.referralSource);
}
if (var3 != null) {
var7.setSkin(var3);
}
this.getChannel()
.setChannelHandler(new PasswordPacketHandler(this.getChannel(), this.connectData.protocolVersion, this.connectData.language, var7, var4, var6));
this.connectData = null;
} else {
this.disconnect(Message.translation("client.general.disconnect.missingUsername"));
}
} else {
this.disconnect(Message.translation("client.general.disconnect.protocol.unexpectedPacket"));
}
}
class="kw">private class="kw">static byte[] generatePasswordChallengeIfNeeded(UUID var0) {
String var1 = HytaleServer.get().getConfig().getPassword();
if (var1 != null && !var1.isEmpty()) {
if (Constants.SINGLEPLAYER) {
UUID var2 = SingleplayerModule.getUuid();
if (var2 != null && var2.equals(var0)) {
class="kw">return null;
}
}
byte[] var3 = new byte[32];
new SecureRandom().nextBytes(var3);
class="kw">return var3;
} else {
class="kw">return null;
}
}
class="kw">public void handle(@Nonnull ClientDisconnect var1) {
this.disconnectReason.setClientDisconnectType(var1.type);
HytaleLogger.getLogger().at(Level.WARNING).log("Disconnecting %s - Sent disconnect packet???", this.getChannel().formatRemoteAddress());
this.getChannel().closeApplicationConnection();
}
class="kw">private record PendingConnectData(
@Nonnull ClientType clientType,
@Nonnull String language,
@Nullable byte[] referralData,
@Nullable HostAddress referralSource,
@Nonnull ProtocolVersion protocolVersion
) {
class="kw">private PendingConnectData {
}
}
}