use of org.dragonet.net.translator.BaseTranslator 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);
}
}
Aggregations