@@ -141,8 +141,6 @@ public class Player extends EntityHuman implements CommandSender, InventoryHolde
141141 private boolean loginPacketReceived ;
142142 protected boolean networkSettingsRequested ;
143143 public int gamemode ;
144- protected long randomClientId ;
145- private String unverifiedUsername = "" ;
146144
147145 protected final BiMap <Inventory , Integer > windows = HashBiMap .create ();
148146 protected final BiMap <Integer , Inventory > windowIndex = windows .inverse ();
@@ -430,7 +428,7 @@ public String getClientSecret() {
430428 */
431429 @ Deprecated
432430 public Long getClientId () {
433- return randomClientId ;
431+ return loginChainData . getClientId () ;
434432 }
435433
436434 @ Override
@@ -2945,7 +2943,7 @@ public void handleDataPacket(DataPacket packet) {
29452943 this .networkSettingsRequested = true ;
29462944
29472945 if (this .getNetworkSession ().getCompression () != CompressionProvider .NONE ) {
2948- this .getServer ().getLogger ().debug (( this .username == null ? this . unverifiedUsername : this . username ) +
2946+ this .getServer ().getLogger ().debug (this .username +
29492947 ": got a RequestNetworkSettingsPacket but compression is already set" );
29502948 return ;
29512949 }
@@ -2978,7 +2976,6 @@ public void handleDataPacket(DataPacket packet) {
29782976 this .loginPacketReceived = true ;
29792977
29802978 LoginPacket loginPacket = (LoginPacket ) packet ;
2981- this .unverifiedUsername = TextFormat .clean (loginPacket .username );
29822979
29832980 if (!this .networkSettingsRequested ) {
29842981 this .close ("" , "Invalid login sequence: login packet before network settings" );
@@ -2997,50 +2994,33 @@ public void handleDataPacket(DataPacket packet) {
29972994 return ;
29982995 }
29992996
3000- if (loginPacket .skin == null ) {
3001- this .close ("" , "disconnectionScreen.invalidSkin" );
3002- return ;
3003- }
3004-
3005- if (this .server .getOnlinePlayersCount () >= this .server .getMaxPlayers () && this .kick (PlayerKickEvent .Reason .SERVER_FULL , "disconnectionScreen.serverFull" , false )) {
3006- return ;
3007- }
3008-
30092997 try {
3010- // TODO: Why do we read this separately?
30112998 this .loginChainData = ClientChainData .read (loginPacket );
30122999 } catch (ClientChainData .TooBigSkinException ex ) {
30133000 this .close ("" , "disconnectionScreen.invalidSkin" );
30143001 return ;
3002+ } catch (Exception ex ) {
3003+ getServer ().getLogger ().logException (ex );
3004+ this .close ("" , "disconnectionScreen.noReason" );
3005+ return ;
30153006 }
30163007
3017- server .getLogger ().debug ("Name: " + this . unverifiedUsername + " Protocol: " + loginPacket . getProtocol () + " Version: " + loginChainData .getGameVersion ());
3008+ server .getLogger ().debug ("Name: " + loginChainData . getUsername () + " Version: " + loginChainData .getGameVersion ());
30183009
30193010 if (!loginChainData .isXboxAuthed () && server .xboxAuth ) {
30203011 this .close ("" , "disconnectionScreen.notAuthenticated" );
30213012 return ;
30223013 }
30233014
3024- // Do not set username before the user is authenticated
3025- this .username = this .unverifiedUsername ;
3026- this .unverifiedUsername = null ;
3027- this .displayName = this .username ;
3028- this .iusername = this .username .toLowerCase (Locale .ROOT );
3029- this .setDataProperty (new StringEntityData (DATA_NAMETAG , this .username ), false );
3030-
3031- this .randomClientId = loginPacket .clientId ;
3032- this .uuid = loginPacket .clientUUID ;
3033- this .rawUUID = Binary .writeUUID (this .uuid );
3034-
30353015 boolean valid = true ;
3036- int len = loginPacket . username .length ();
3037- if (len > 16 || len < 3 || loginPacket . username .trim ().isEmpty ()) {
3016+ int len = loginChainData . getUsername () .length ();
3017+ if (len > 16 || len < 3 || loginChainData . getUsername () .trim ().isEmpty ()) {
30383018 valid = false ;
30393019 }
30403020
30413021 if (valid ) {
30423022 for (int i = 0 ; i < len ; i ++) {
3043- char c = loginPacket . username .charAt (i );
3023+ char c = loginChainData . getUsername () .charAt (i );
30443024 if ((c >= 'a' && c <= 'z' ) ||
30453025 (c >= 'A' && c <= 'Z' ) ||
30463026 (c >= '0' && c <= '9' ) ||
@@ -3054,13 +3034,27 @@ public void handleDataPacket(DataPacket packet) {
30543034 }
30553035 }
30563036
3057- if (!valid || Objects .equals (this .iusername , "rcon" ) || Objects .equals (this .iusername , "console" )) {
3037+ String lowerCaseName = loginChainData .getUsername ().toLowerCase (Locale .ROOT );
3038+ if (!valid || Objects .equals (lowerCaseName , "rcon" ) || Objects .equals (lowerCaseName , "console" )) {
30583039 this .close ("" , "disconnectionScreen.invalidName" );
30593040 return ;
30603041 }
30613042
3062- Skin skin = loginPacket .skin ;
3063- if (!skin .isValid ()) {
3043+ // Do not set username before the user is authenticated
3044+ this .username = loginChainData .getUsername ();
3045+ this .displayName = this .username ;
3046+ this .iusername = lowerCaseName ;
3047+ this .setDataProperty (new StringEntityData (DATA_NAMETAG , this .username ), false );
3048+
3049+ this .uuid = loginChainData .getClientUUID ();
3050+ this .rawUUID = Binary .writeUUID (this .uuid );
3051+
3052+ if (this .server .getOnlinePlayersCount () >= this .server .getMaxPlayers () && this .kick (PlayerKickEvent .Reason .SERVER_FULL , "disconnectionScreen.serverFull" , false )) {
3053+ return ;
3054+ }
3055+
3056+ Skin skin = loginChainData .getSkin ();
3057+ if (skin == null || !skin .isValid ()) {
30643058 this .close ("" , "disconnectionScreen.invalidSkin" );
30653059 return ;
30663060 }
@@ -5416,7 +5410,7 @@ public void close(TextContainer message, String reason, boolean notify) {
54165410 this .server .getPluginManager ().unsubscribeFromPermission (Server .BROADCAST_CHANNEL_USERS , this );
54175411 this .spawned = false ;
54185412 this .server .getLogger ().info (this .getServer ().getLanguage ().translateString ("nukkit.player.logOut" ,
5419- TextFormat .AQUA + ( this .username == null ? this . unverifiedUsername : this . username ) + TextFormat .WHITE ,
5413+ TextFormat .AQUA + this .username + TextFormat .WHITE ,
54205414 this .getAddress (),
54215415 String .valueOf (this .getPort ()),
54225416 this .getServer ().getLanguage ().translateString (reason )));
@@ -5444,7 +5438,7 @@ public void close(TextContainer message, String reason, boolean notify) {
54445438 this .server .removePlayer (this );
54455439
54465440 if (this .loggedIn ) {
5447- this .server .getLogger ().warning ("Player is still logged in: " + ( this .username == null ? this . unverifiedUsername : this . username ) );
5441+ this .server .getLogger ().warning ("Player is still logged in: " + this .username );
54485442 this .interfaz .close (this , notify ? reason : "" );
54495443 this .server .removeOnlinePlayer (this );
54505444 this .loggedIn = false ;
0 commit comments