3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-17 21:40:08 +01:00
Paper/src/main/java/net/minecraft/server/NetLoginHandler.java

173 Zeilen
6.9 KiB
Java

package net.minecraft.server;
import java.net.Socket;
2011-09-15 02:23:52 +02:00
import java.util.Iterator;
import java.util.Random;
import java.util.logging.Logger;
2011-09-27 00:32:05 +02:00
// CraftBukkit start
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.event.server.ServerListPingEvent;
// CraftBukkit end
public class NetLoginHandler extends NetHandler {
public static Logger a = Logger.getLogger("Minecraft");
private static Random d = new Random();
public NetworkManager networkManager;
public boolean c = false;
private MinecraftServer server;
private int f = 0;
private String g = null;
private Packet1Login h = null;
2011-11-20 09:01:14 +01:00
private String i = Long.toString(d.nextLong(), 16); // CraftBukkit -- Thanks Jens! :D
public NetLoginHandler(MinecraftServer minecraftserver, Socket socket, String s) {
this.server = minecraftserver;
this.networkManager = new NetworkManager(socket, s, this);
2011-05-26 14:48:22 +02:00
this.networkManager.f = 0;
}
// CraftBukkit start
public Socket getSocket() {
return this.networkManager.socket;
}
// CraftBukkit end
public void a() {
if (this.h != null) {
this.b(this.h);
this.h = null;
}
if (this.f++ == 600) {
this.disconnect("Took too long to log in");
} else {
2011-05-26 14:48:22 +02:00
this.networkManager.b();
}
}
public void disconnect(String s) {
try {
a.info("Disconnecting " + this.b() + ": " + s);
this.networkManager.queue(new Packet255KickDisconnect(s));
2011-05-26 14:48:22 +02:00
this.networkManager.d();
this.c = true;
} catch (Exception exception) {
exception.printStackTrace();
}
}
public void a(Packet2Handshake packet2handshake) {
if (this.server.onlineMode) {
// this.i = Long.toHexString(d.nextLong()); // CraftBukkit
this.networkManager.queue(new Packet2Handshake(this.i));
} else {
this.networkManager.queue(new Packet2Handshake("-"));
}
}
public void a(Packet1Login packet1login) {
this.g = packet1login.name;
2011-11-20 09:01:14 +01:00
if (packet1login.a != 22) {
if (packet1login.a > 22) {
this.disconnect("Outdated server!");
} else {
this.disconnect("Outdated client!");
}
} else {
if (!this.server.onlineMode) {
this.b(packet1login);
} else {
2011-04-20 22:47:26 +02:00
(new ThreadLoginVerifier(this, packet1login, this.server.server)).start(); // CraftBukkit
}
}
}
public void b(Packet1Login packet1login) {
2011-04-20 22:47:26 +02:00
EntityPlayer entityplayer = this.server.serverConfigurationManager.a(this, packet1login.name);
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-09-15 02:23:52 +02:00
entityplayer.itemInWorldManager.a((WorldServer) entityplayer.world);
2011-11-20 09:01:14 +01:00
// CraftBukkit - add world and location to 'logged in' message.
a.info(this.b() + " logged in with entity id " + entityplayer.id + " at ([" + entityplayer.world.worldData.name + "] " + 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-09-15 02:23:52 +02:00
2011-11-20 09:01:14 +01:00
entityplayer.itemInWorldManager.b(worldserver.r().getGameType());
NetServerHandler netserverhandler = new NetServerHandler(this.server, this.networkManager, entityplayer);
// CraftBukkit start -- Don't send a higher than 60 MaxPlayer size, otherwise the PlayerInfo window won't render correctly.
2011-11-20 09:01:14 +01:00
int maxPlayers = this.server.serverConfigurationManager.k();
if (maxPlayers > 60) {
maxPlayers = 60;
}
2011-11-20 09:01:14 +01:00
netserverhandler.sendPacket(new Packet1Login("", entityplayer.id, worldserver.getSeed(), entityplayer.itemInWorldManager.a(), (byte) worldserver.worldProvider.dimension, (byte) worldserver.difficulty, (byte) worldserver.height, (byte) maxPlayers));
// CraftBukkit end
2011-09-15 02:23:52 +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);
// 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);
netserverhandler.a(entityplayer.locX, entityplayer.locY, entityplayer.locZ, entityplayer.yaw, entityplayer.pitch);
this.server.networkListenThread.a(netserverhandler);
netserverhandler.sendPacket(new Packet4UpdateTime(entityplayer.getPlayerTime())); // CraftBukkit - add support for player specific time
Iterator iterator = entityplayer.getEffects().iterator();
2011-09-15 02:23:52 +02:00
while (iterator.hasNext()) {
MobEffect mobeffect = (MobEffect) iterator.next();
netserverhandler.sendPacket(new Packet41MobEffect(entityplayer.id, mobeffect));
}
entityplayer.syncInventory();
}
this.c = true;
}
public void a(String s, Object[] aobject) {
a.info(this.b() + " lost connection");
this.c = true;
}
2011-09-15 02:23:52 +02:00
public void a(Packet254GetInfo packet254getinfo) {
if (this.networkManager.f() == null) return; // CraftBukkit - fix NPE when a client queries a server that is unable to handle it.
2011-09-15 02:23:52 +02:00
try {
2011-09-27 00:32:05 +02:00
// CraftBukkit start
2011-11-20 09:01:14 +01:00
ServerListPingEvent pingEvent = CraftEventFactory.callServerListPingEvent(this.server.server, getSocket().getInetAddress(), this.server.r, this.server.serverConfigurationManager.j(), this.server.serverConfigurationManager.k());
String s = pingEvent.getMotd() + "\u00A7" + this.server.serverConfigurationManager.j() + "\u00A7" + pingEvent.getMaxPlayers();
2011-09-27 00:32:05 +02:00
// CraftBukkit end
2011-09-15 02:23:52 +02:00
this.networkManager.queue(new Packet255KickDisconnect(s));
this.networkManager.d();
this.server.networkListenThread.a(this.networkManager.f());
this.c = true;
} catch (Exception exception) {
exception.printStackTrace();
}
}
public void a(Packet packet) {
this.disconnect("Protocol error");
}
public String b() {
return this.g != null ? this.g + " [" + this.networkManager.getSocketAddress().toString() + "]" : this.networkManager.getSocketAddress().toString();
}
2011-04-20 22:47:26 +02:00
public boolean c() {
return true;
}
static String a(NetLoginHandler netloginhandler) {
return netloginhandler.i;
}
static Packet1Login a(NetLoginHandler netloginhandler, Packet1Login packet1login) {
return netloginhandler.h = packet1login;
}
}