use of org.dragonet.net.packet.minecraft.LoginStatusPacket in project Dragonet-Legacy by DragonetMC.
the class PENetworkClient method handlePacket.
public void handlePacket(PEPacket packet) {
//System.out.println("Received Packet: " + packet.getClass().getSimpleName());
switch(packet.pid()) {
case PEPacketIDs.LOGIN_PACKET:
LoginPacket packetLogin = (LoginPacket) packet;
this.username = packetLogin.username;
BaseTranslator translator = TranslatorProvider.getByPEProtocolID(packetLogin.protocol1, packetLogin.protocol2);
if (!(translator instanceof BaseTranslator)) {
LoginStatusPacket pkLoginStatus = new LoginStatusPacket();
pkLoginStatus.status = LoginStatusPacket.LOGIN_FAILED_CLIENT;
this.sendPacket(pkLoginStatus);
this.disconnect("Unsupported game version! ");
break;
}
session = new MCPESession(inf.getSesMan().getServer(), this, translator);
LoginStatusPacket pkLoginStatus = new LoginStatusPacket();
pkLoginStatus.status = LoginStatusPacket.LOGIN_SUCCESS;
this.sendPacket(pkLoginStatus);
inf.getSesMan().getServer().getLogger().info("Accepted connection by [" + this.username + "]. ");
Matcher matcher = DragonetSession.PATTERN_USERNAME.matcher(this.username);
if (!matcher.matches()) {
this.disconnect("Bad username! ");
break;
}
session.setPlayer(new PlayerProfile(this.username, UUID.nameUUIDFromBytes(("OfflinePlayer:" + this.username).getBytes(StandardCharsets.UTF_8))));
break;
case PEPacketIDs.BATCH_PACKET:
BatchPacket packetBatch = (BatchPacket) packet;
if (packetBatch.packets == null || packetBatch.packets.isEmpty()) {
break;
}
for (PEPacket pk : packetBatch.packets) {
this.handlePacket(pk);
}
break;
default:
if (session == null) {
disconnect("Network error! ");
return;
}
session.onPacketReceived(packet);
}
}
use of org.dragonet.net.packet.minecraft.LoginStatusPacket in project Dragonet-Legacy by DragonetMC.
the class ClientChunkManager method onTick.
/**
* Trigger a chunk tick update
*/
public void onTick() {
if (this.getSession().getPlayer() == null) {
return;
}
if (this.ticksCountDown > 0) {
this.ticksCountDown--;
return;
} else {
this.ticksCountDown = 200;
}
if (this.lastWorld == null) {
this.lastWorld = this.getSession().getPlayer().getWorld().getName();
}
if (!this.lastWorld.equalsIgnoreCase(this.getSession().getPlayer().getWorld().getName())) {
/*
for (ChunkLocation loc : this.chunksLoaded) {
this.unloadChunk(loc.getX(), loc.getZ());
}
*/
this.chunksLoaded.clear();
this.chunksQueue.clear();
//System.out.println("Detected world change: " + this.lastWorld + " -> " + this.getSession().getPlayer().getWorld().getName());
this.lastWorld = this.getSession().getPlayer().getWorld().getName();
return;
}
this.autoPrepareChunks();
this.sendChunks();
if (spawned == false && this.chunksLoaded.size() > this.session.getDServer().getPlayerSpawnThreshold()) {
spawned = true;
LoginStatusPacket pk = new LoginStatusPacket();
pk.status = LoginStatusPacket.PLAYER_SPAWN;
this.session.send(pk);
}
}
Aggregations