Search in sources :

Example 1 with SERVER_HANDSHAKE_DataPacket

use of org.dragonet.raknet.protocol.packet.SERVER_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));
    }
}
Also used : CLIENT_CONNECT_DataPacket(org.dragonet.raknet.protocol.packet.CLIENT_CONNECT_DataPacket) PING_DataPacket(org.dragonet.raknet.protocol.packet.PING_DataPacket) PONG_DataPacket(org.dragonet.raknet.protocol.packet.PONG_DataPacket) CLIENT_HANDSHAKE_DataPacket(org.dragonet.raknet.protocol.packet.CLIENT_HANDSHAKE_DataPacket) SERVER_HANDSHAKE_DataPacket(org.dragonet.raknet.protocol.packet.SERVER_HANDSHAKE_DataPacket) EncapsulatedPacket(org.dragonet.raknet.protocol.EncapsulatedPacket)

Aggregations

EncapsulatedPacket (org.dragonet.raknet.protocol.EncapsulatedPacket)1 CLIENT_CONNECT_DataPacket (org.dragonet.raknet.protocol.packet.CLIENT_CONNECT_DataPacket)1 CLIENT_HANDSHAKE_DataPacket (org.dragonet.raknet.protocol.packet.CLIENT_HANDSHAKE_DataPacket)1 PING_DataPacket (org.dragonet.raknet.protocol.packet.PING_DataPacket)1 PONG_DataPacket (org.dragonet.raknet.protocol.packet.PONG_DataPacket)1 SERVER_HANDSHAKE_DataPacket (org.dragonet.raknet.protocol.packet.SERVER_HANDSHAKE_DataPacket)1