2011-02-05 19:15:04 +01:00
package net.minecraft.server ;
import java.net.Socket ;
import java.util.Random ;
import java.util.logging.Logger ;
public class NetLoginHandler extends NetHandler {
public static Logger a = Logger . getLogger ( " Minecraft " ) ;
private static Random d = new Random ( ) ;
2011-04-20 19:05:14 +02:00
public NetworkManager networkManager ;
2011-02-05 19:15:04 +01:00
public boolean c = false ;
2011-04-20 19:05:14 +02:00
private MinecraftServer server ;
2011-02-05 19:15:04 +01:00
private int f = 0 ;
private String g = null ;
private Packet1Login h = null ;
private String i = " " ;
public NetLoginHandler ( MinecraftServer minecraftserver , Socket socket , String s ) {
2011-04-20 19:05:14 +02:00
this . server = minecraftserver ;
this . networkManager = new NetworkManager ( socket , s , this ) ;
2011-05-26 14:48:22 +02:00
this . networkManager . f = 0 ;
2011-02-05 19:15:04 +01:00
}
2011-04-20 19:05:14 +02:00
2011-04-16 12:08:13 +02:00
// CraftBukkit start
public Socket getSocket ( ) {
2011-04-20 19:05:14 +02:00
return networkManager . socket ;
2011-04-16 12:08:13 +02:00
}
// CraftBukkit end
2011-02-05 19:15:04 +01:00
public void a ( ) {
if ( this . h ! = null ) {
this . b ( this . h ) ;
this . h = null ;
}
if ( this . f + + = = 600 ) {
2011-04-20 19:05:14 +02:00
this . disconnect ( " Took too long to log in " ) ;
2011-02-05 19:15:04 +01:00
} else {
2011-05-26 14:48:22 +02:00
this . networkManager . b ( ) ;
2011-02-05 19:15:04 +01:00
}
}
2011-04-20 19:05:14 +02:00
public void disconnect ( String s ) {
2011-02-05 19:15:04 +01:00
try {
a . info ( " Disconnecting " + this . b ( ) + " : " + s ) ;
2011-04-20 19:05:14 +02:00
this . networkManager . a ( ( Packet ) ( new Packet255KickDisconnect ( s ) ) ) ;
2011-05-26 14:48:22 +02:00
this . networkManager . d ( ) ;
2011-02-05 19:15:04 +01:00
this . c = true ;
} catch ( Exception exception ) {
exception . printStackTrace ( ) ;
}
}
public void a ( Packet2Handshake packet2handshake ) {
2011-04-20 19:05:14 +02:00
if ( this . server . onlineMode ) {
2011-02-05 19:15:04 +01:00
this . i = Long . toHexString ( d . nextLong ( ) ) ;
2011-04-20 19:05:14 +02:00
this . networkManager . a ( ( Packet ) ( new Packet2Handshake ( this . i ) ) ) ;
2011-02-05 19:15:04 +01:00
} else {
2011-04-20 19:05:14 +02:00
this . networkManager . a ( ( Packet ) ( new Packet2Handshake ( " - " ) ) ) ;
2011-02-05 19:15:04 +01:00
}
}
public void a ( Packet1Login packet1login ) {
2011-04-20 19:05:14 +02:00
this . g = packet1login . name ;
2011-05-26 14:48:22 +02:00
if ( packet1login . a ! = 13 ) {
if ( packet1login . a > 13 ) {
2011-04-20 19:05:14 +02:00
this . disconnect ( " Outdated server! " ) ;
2011-02-05 19:15:04 +01:00
} else {
2011-04-20 19:05:14 +02:00
this . disconnect ( " Outdated client! " ) ;
2011-02-05 19:15:04 +01:00
}
} else {
2011-04-20 19:05:14 +02:00
if ( ! this . server . onlineMode ) {
2011-02-05 19:15:04 +01:00
this . b ( packet1login ) ;
} else {
2011-04-20 22:47:26 +02:00
( new ThreadLoginVerifier ( this , packet1login , this . server . server ) ) . start ( ) ; // CraftBukkit
2011-02-05 19:15:04 +01:00
}
}
}
public void b ( Packet1Login packet1login ) {
2011-04-20 22:47:26 +02:00
EntityPlayer entityplayer = this . server . serverConfigurationManager . a ( this , packet1login . name ) ;
2011-02-05 19:15:04 +01:00
if ( entityplayer ! = null ) {
2011-05-26 14:48:22 +02:00
this . server . serverConfigurationManager . b ( entityplayer ) ;
2011-06-08 19:40:40 +02:00
// entityplayer.a((World) this.server.a(entityplayer.dimension)); // CraftBukkit - set by Entity
2011-05-14 16:29:42 +02:00
a . info ( this . b ( ) + " logged in with entity id " + entityplayer . id + " at ( " + entityplayer . locX + " , " + entityplayer . locY + " , " + entityplayer . locZ + " ) " ) ;
2011-06-08 19:40:40 +02:00
WorldServer worldserver = ( WorldServer ) entityplayer . world ; // CraftBukkit
2011-05-26 14:48:22 +02:00
ChunkCoordinates chunkcoordinates = worldserver . getSpawn ( ) ;
2011-04-20 19:05:14 +02:00
NetServerHandler netserverhandler = new NetServerHandler ( this . server , this . networkManager , entityplayer ) ;
2011-02-05 19:15:04 +01:00
2011-05-26 14:48:22 +02:00
netserverhandler . sendPacket ( new Packet1Login ( " " , entityplayer . id , worldserver . getSeed ( ) , ( byte ) worldserver . worldProvider . dimension ) ) ;
2011-04-20 19:05:14 +02:00
netserverhandler . sendPacket ( new Packet6SpawnPosition ( chunkcoordinates . x , chunkcoordinates . y , chunkcoordinates . z ) ) ;
2011-05-26 14:48:22 +02:00
this . server . serverConfigurationManager . a ( entityplayer , worldserver ) ;
2011-04-20 19:05:14 +02:00
// this.server.serverConfigurationManager.sendAll(new Packet3Chat("\u00A7e" + entityplayer.name + " joined the game.")); // CraftBukkit - message moved to join event
2011-05-26 14:48:22 +02:00
this . server . serverConfigurationManager . c ( entityplayer ) ;
2011-04-20 19:05:14 +02:00
netserverhandler . a ( entityplayer . locX , entityplayer . locY , entityplayer . locZ , entityplayer . yaw , entityplayer . pitch ) ;
this . server . networkListenThread . a ( netserverhandler ) ;
2011-05-26 14:48:22 +02:00
netserverhandler . sendPacket ( new Packet4UpdateTime ( worldserver . getTime ( ) ) ) ;
2011-04-20 19:05:14 +02:00
entityplayer . syncInventory ( ) ;
2011-02-05 19:15:04 +01:00
}
this . c = true ;
}
public void a ( String s , Object [ ] aobject ) {
a . info ( this . b ( ) + " lost connection " ) ;
this . c = true ;
}
public void a ( Packet packet ) {
2011-04-20 19:05:14 +02:00
this . disconnect ( " Protocol error " ) ;
2011-02-05 19:15:04 +01:00
}
public String b ( ) {
2011-04-20 19:05:14 +02:00
return this . g ! = null ? this . g + " [ " + this . networkManager . getSocketAddress ( ) . toString ( ) + " ] " : this . networkManager . getSocketAddress ( ) . toString ( ) ;
2011-02-05 19:15:04 +01:00
}
2011-04-20 22:47:26 +02:00
public boolean c ( ) {
return true ;
}
2011-02-05 19:15:04 +01:00
static String a ( NetLoginHandler netloginhandler ) {
return netloginhandler . i ;
}
static Packet1Login a ( NetLoginHandler netloginhandler , Packet1Login packet1login ) {
return netloginhandler . h = packet1login ;
}
}