use of org.dragonet.raknet.protocol.packet.CLIENT_HANDSHAKE_DataPacket in project Dragonet-Legacy by DragonetMC.
the class Session method handleEncapsulatedPacketRoute.
private void handleEncapsulatedPacketRoute(EncapsulatedPacket packet) throws Exception {
if (this.sessionManager == null) {
return;
}
if (packet.hasSplit) {
if (this.state == STATE_CONNECTED) {
this.handleSplit(packet);
}
return;
}
byte id = packet.buffer[0];
if ((id & 0xff) < 0x80) {
//internal data packet
if (state == STATE_CONNECTING_2) {
if (id == CLIENT_CONNECT_DataPacket.ID) {
CLIENT_CONNECT_DataPacket dataPacket = new CLIENT_CONNECT_DataPacket();
dataPacket.buffer = packet.buffer;
dataPacket.decode();
SERVER_HANDSHAKE_DataPacket pk = new SERVER_HANDSHAKE_DataPacket();
pk.address = this.address;
pk.port = this.port;
pk.sendPing = dataPacket.sendPing;
pk.sendPong = dataPacket.sendPing + 1000L;
pk.encode();
EncapsulatedPacket sendPacket = new EncapsulatedPacket();
sendPacket.reliability = 0;
sendPacket.buffer = pk.buffer;
this.addToQueue(sendPacket, RakNet.PRIORITY_IMMEDIATE);
} else if (id == CLIENT_HANDSHAKE_DataPacket.ID) {
CLIENT_HANDSHAKE_DataPacket dataPacket = new CLIENT_HANDSHAKE_DataPacket();
dataPacket.buffer = packet.buffer;
dataPacket.decode();
if (dataPacket.port == this.sessionManager.getPort() || !this.sessionManager.portChecking) {
//FINALLY!
this.state = STATE_CONNECTED;
this.isTemporal = false;
this.sessionManager.openSession(this);
}
}
} else if (id == CLIENT_DISCONNECT_DataPacket.ID) {
disconnect("client disconnect");
} else if (id == PING_DataPacket.ID) {
PING_DataPacket dataPacket = new PING_DataPacket();
dataPacket.buffer = packet.buffer;
dataPacket.decode();
PONG_DataPacket pk = new PONG_DataPacket();
pk.pingID = dataPacket.pingID;
pk.encode();
EncapsulatedPacket sendPacket = new EncapsulatedPacket();
sendPacket.reliability = 0;
sendPacket.buffer = pk.buffer;
this.addToQueue(sendPacket);
//TODO: add PING/PONG (0x00/0x03) automatic latency measure
}
} else if (state == STATE_CONNECTED) {
this.sessionManager.streamEncapsulated(this, packet);
//TODO: stream channels
} else {
//this.sessionManager.getLogger().notice("Received packet before connection: "+Binary.bytesToHexString(packet.buffer));
}
}
Aggregations