use of org.dragonet.net.packet.minecraft.BatchPacket 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.BatchPacket in project Dragonet-Legacy by DragonetMC.
the class RakNetInterface method sendPacket.
public void sendPacket(String identifier, PEPacket packet, boolean needACK, boolean immediate) {
packet.encode();
byte[] buffer = packet.getData();
if (buffer.length > 1024 && !BatchPacket.class.isAssignableFrom(packet.getClass())) {
BatchPacket batch = new BatchPacket();
batch.packets.add(packet);
sendPacket(identifier, batch, needACK, immediate);
return;
}
EncapsulatedPacket encapsulated = new EncapsulatedPacket();
encapsulated.buffer = buffer;
encapsulated.needACK = needACK;
encapsulated.reliability = needACK ? (byte) 2 : (byte) 3;
encapsulated.messageIndex = 0;
this.handler.sendEncapsulated(identifier, encapsulated, (needACK ? RakNet.FLAG_NEED_ACK : 0) | (immediate ? RakNet.PRIORITY_IMMEDIATE : RakNet.PRIORITY_NORMAL));
}
Aggregations