NetHandlerLoginServer
Server login state machine (HELLO/KEY/AUTHENTICATING/READY): S01 encryption challenge, S02 success, S03 compression.
Updated 2026-09-12
Packets Referenced (4)
Related Vanilla Internals
Deep Analysis
Login-state machine HELLO>KEY>AUTHENTICATING>READY>ACCEPTED. Validates C00 start and C01 encryption, verifies Mojang session off-thread, then hands to ServerConfigurationManager or disconnects.
Key Methods in Depth (6)
Starts login or requests encryption.
processLoginStart handles C00 hello and branches online versus offline login. It validates state equals HELLO via Validate, throwing on duplicate hello. It stores the GameProfile from the packet. If online mode is enabled and the channel is not local, it moves to KEY state and sends S01 EncryptionRequest with empty serverId, server public key and four-byte verifyToken. Otherwise for offline or singleplayer it jumps directly to READY_TO_ACCEPT. No kick occurs here, errors throw IllegalStateException. The verifyToken nonce later proves the client holds the private key. Local channels skip encryption to reduce latency.
public void processLoginStart(C00PacketLoginStart packetIn)
{
Validate.validState(this.currentLoginState == NetHandlerLoginServer.LoginState.HELLO, "Unexpected hello packet", new Object[0]);
this.loginGameProfile = packetIn.getProfile();
if (this.server.isServerInOnlineMode() && !this.networkManager.isLocalChannel())
{
this.currentLoginState = NetHandlerLoginServer.LoginState.KEY;
this.networkManager.sendPacket(new S01PacketEncryptionRequest(this.serverId, this.server.getKeyPair().getPublic(), this.verifyToken));
}
else
{
this.currentLoginState = NetHandlerLoginServer.LoginState.READY_TO_ACCEPT;
}
}
Validate.validState enforces the HELLO to KEY to AUTH state machine and rejects replays. Storing loginGameProfile preserves the requested name for later Mojang verification. The online-mode plus not-local gate selects encrypted versus instant accept. S01PacketEncryptionRequest carries serverId, public key and verifyToken nonce. The else moves offline logins straight to READY_TO_ACCEPT for tryAcceptPlayer.
Verifies nonce and enables crypto.
processEncryptionResponse handles C01 key exchange in KEY state. It validates KEY state, fetches the server private key and compares the decrypted verifyToken with Arrays equals, throwing Invalid nonce on mismatch to block replay. On match it decrypts the shared secret, moves to AUTHENTICATING and enables encryption on the channel. It then spawns User Authenticator thread with incrementing ID to avoid blocking netty. That thread hashes serverId, public key and secret via CryptManager, calls hasJoinedServer to verify the Mojang session, and on success sets READY_TO_ACCEPT. Singleplayer fallback generates offline profiles when verification fails or auth servers are down, otherwise it closes with Failed to verify username. No S packets are sent here directly.
public void processEncryptionResponse(C01PacketEncryptionResponse packetIn)
{
Validate.validState(this.currentLoginState == NetHandlerLoginServer.LoginState.KEY, "Unexpected key packet", new Object[0]);
PrivateKey privatekey = this.server.getKeyPair().getPrivate();
if (!Arrays.equals(this.verifyToken, packetIn.getVerifyToken(privatekey)))
{
throw new IllegalStateException("Invalid nonce!");
}
else
{
this.secretKey = packetIn.getSecretKey(privatekey);
this.currentLoginState = NetHandlerLoginServer.LoginState.AUTHENTICATING;
this.networkManager.enableEncryption(this.secretKey);
(new Thread("User Authenticator #" + AUTHENTICATOR_THREAD_ID.incrementAndGet())
The KEY state check rejects out-of-order C01 packets. Decrypting verifyToken with the private key and comparing to stored nonce detects tampering. Throwing Invalid nonce aborts the login without a graceful S00. Storing secretKey, setting AUTHENTICATING and enabling encryption switch the channel to ciphered mode. Spawning the authenticator thread offloads the blocking Mojang HTTPS check.
Advances ready/delayed accept and timeout.
update ticks the login state machine and enforces the 600-tick timeout. If state is READY_TO_ACCEPT it calls tryAcceptPlayer immediately to apply bans and compression. If state is DELAY_ACCEPT it polls for the duplicate old player by UUID, and when null it flips to READY_TO_ACCEPT, initializes the new player and clears the pending reference. It increments connectionTimer every tick and closes with Took too long to log in via S00 Disconnect at exactly 600. DELAY_ACCEPT exists because createPlayerForUser kicks the old session but the logout needs ticks to complete. No PLAY packets are sent here, only login S00, S02 and S03 via helpers. Stuck AUTHENTICATING threads eventually hit the same timeout.
public void update()
{
if (this.currentLoginState == NetHandlerLoginServer.LoginState.READY_TO_ACCEPT)
{
this.tryAcceptPlayer();
}
else if (this.currentLoginState == NetHandlerLoginServer.LoginState.DELAY_ACCEPT)
{
EntityPlayerMP entityplayermp = this.server.getConfigurationManager().getPlayerByUUID(this.loginGameProfile.getId());
if (entityplayermp == null)
{
this.currentLoginState = NetHandlerLoginServer.LoginState.READY_TO_ACCEPT;
this.server.getConfigurationManager().initializeConnectionToPlayer(this.networkManager, this.player);
this.player = null;
}
}
if (this.connectionTimer++ == 600)
{
this.closeConnection("Took too long to log in");
}
}
The READY_TO_ACCEPT branch drives immediate accept without waiting for network events. The DELAY_ACCEPT branch looks up the old UUID entry to detect when the kicked duplicate has logged out. Null means safe to initializeConnectionToPlayer with the staged player object. The connectionTimer post-increment equals 600 gate sends S00 Took too long to log in. That timeout bounds Mojang outages and stalled encryption handshakes.
Applies bans, compression and success.
tryAcceptPlayer applies final login gates and switches to PLAY. It completes incomplete profiles with getOfflineProfile deriving OfflinePlayer UUIDs. It calls allowUserToConnect and closes with the ban, whitelist, IP or full reason when non-null. On success it sets ACCEPTED, and if compression threshold is non-negative on a remote channel it sends S03 EnableCompression then sets the threshold on future. It sends S02 LoginSuccess with the verified profile to trigger client PLAY switch. It checks for duplicate UUID sessions, staging a new player and entering DELAY_ACCEPT when found, otherwise initializing immediately via createPlayerForUser. No teleport occurs, the follow-up initializeConnectionToPlayer sends the S01 burst. Offline servers always take the instant path.
String s = this.server.getConfigurationManager().allowUserToConnect(this.networkManager.getRemoteAddress(), this.loginGameProfile);
if (s != null)
{
this.closeConnection(s);
}
else
{
this.currentLoginState = NetHandlerLoginServer.LoginState.ACCEPTED;
if (this.server.getNetworkCompressionTreshold() >= 0 && !this.networkManager.isLocalChannel())
{
this.networkManager.sendPacket(new S03PacketEnableCompression(this.server.getNetworkCompressionTreshold()), new ChannelFutureListener()
{
public void operationComplete(ChannelFuture p_operationComplete_1_) throws Exception
{
NetHandlerLoginServer.this.networkManager.setCompressionTreshold(NetHandlerLoginServer.this.server.getNetworkCompressionTreshold());
}
}, new GenericFutureListener[0]);
}
this.networkManager.sendPacket(new S02PacketLoginSuccess(this.loginGameProfile));
EntityPlayerMP entityplayermp = this.server.getConfigurationManager().getPlayerByUUID(this.loginGameProfile.getId());
if (entityplayermp != null)
{
this.currentLoginState = NetHandlerLoginServer.LoginState.DELAY_ACCEPT;
this.player = this.server.getConfigurationManager().createPlayerForUser(this.loginGameProfile);
}
else
{
this.server.getConfigurationManager().initializeConnectionToPlayer(this.networkManager, this.server.getConfigurationManager().createPlayerForUser(this.loginGameProfile));
}
allowUserToConnect returns null only when bans, whitelist, IP and capacity all pass. Non-null triggers closeConnection with S00 carrying that reason. Setting ACCEPTED plus S03 EnableCompression negotiates compression before LoginSuccess. S02PacketLoginSuccess carries the final UUID and name to switch the client to PLAY. The UUID duplicate check stages DELAY_ACCEPT versus immediate initializeConnectionToPlayer for overlap handling.
Sends kick and closes channel.
closeConnection terminates a login with S00 Disconnect and channel close. It logs the connection info plus reason for audit. It wraps the reason in ChatComponentText, sends S00PacketDisconnect, then closes the channel with the same component. Exceptions during send or close are caught and logged as Error whilst disconnecting player without rethrow. It is used for ban kicks, auth failures, duplicate handling and the 600-tick timeout. No PLAY packets are involved because the pipeline is still in LOGIN state. The client displays the text on the disconnected screen.
public void closeConnection(String reason)
{
try
{
logger.info("Disconnecting " + this.getConnectionInfo() + ": " + reason);
ChatComponentText chatcomponenttext = new ChatComponentText(reason);
this.networkManager.sendPacket(new S00PacketDisconnect(chatcomponenttext));
this.networkManager.closeChannel(chatcomponenttext);
}
catch (Exception exception)
{
logger.error((String)"Error whilst disconnecting player", (Throwable)exception);
}
}
The try block ensures logging and packet send happen atomically. getConnectionInfo includes profile and remote address for forensics. S00PacketDisconnect carries the human-readable kick reason to the client. closeChannel with the same component tears down the netty pipeline. The catch prevents disconnect-path exceptions from crashing the server tick.
Derives offline UUID profile.
getOfflineProfile derives deterministic offline UUIDs for cracked and singleplayer logins. It concatenates OfflinePlayer colon plus original name, encodes as UTF-8 bytes and hashes with nameUUIDFromBytes version three. It returns a new GameProfile with that UUID and the original name preserving case. It is called by tryAcceptPlayer for incomplete profiles and by the auth thread when Mojang verification fails on singleplayer or auth servers are down. Online verified logins never use this path. No packets are sent here, the UUID feeds allowUserToConnect and S02 LoginSuccess. The deterministic mapping lets offline servers keep consistent inventories by name.
protected GameProfile getOfflineProfile(GameProfile original)
{
UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + original.getName()).getBytes(Charsets.UTF_8));
return new GameProfile(uuid, original.getName());
}
static enum LoginState
{
HELLO,
KEY,
The OfflinePlayer prefix plus name string is the canonical offline seed. getBytes with UTF_8 ensures cross-platform UUID stability. nameUUIDFromBytes produces a version-three UUID from that seed. Returning a GameProfile with that UUID and original name lets bans and NBT key by stable id. The following LoginState enum defines HELLO, KEY and later states for the handshake.
Packet Usage
| Packet | Dir | Trigger |
|---|---|---|
| C00 | handled | Client hello with GameProfile |
| C01 | handled | Encrypted secret and verify token |
| S00 | sent | Login disconnect with reason |
| S01 | sent | Encryption request in online mode |
| S02 | sent | Login success before PLAY switch |
| S03 | sent | Enable compression if threshold set |
Internal State
Related Vanilla Internals
Full Source
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
Deobfuscated MCP 1.8.9 source of NetHandlerLoginServer from Marcelektro/MavenMCP-1.8.9 (net/minecraft/server/network/NetHandlerLoginServer.java), stored verbatim.