Search in sources :

Example 1 with UpdatePingPacket

use of io.gomint.proxprox.network.tcp.protocol.UpdatePingPacket in project ProxProx by GoMint.

the class UpstreamConnection method update.

public void update() {
    if (this.disconnect != null && !this.disconnectNotified) {
        // Delay closing connection so the client has enough time to react
        ProxProx.instance.getSyncTaskManager().addTask(new SyncScheduledTask(() -> {
            UpstreamConnection.this.connection.disconnect(UpstreamConnection.this.disconnect);
        }, 5, -1, TimeUnit.SECONDS));
        this.disconnectNotified = true;
        if (this.pendingDownStream != null) {
            this.pendingDownStream.disconnect(this.disconnect);
            this.pendingDownStream = null;
        }
        if (this.currentDownStream != null) {
            this.currentDownStream.disconnect(this.disconnect);
            this.currentDownStream = null;
        }
    }
    // Update downstream ping
    if (this.proxProx.getConfig().isUseTCP() && this.currentDownStream != null) {
        UpdatePingPacket pingPacket = new UpdatePingPacket();
        pingPacket.setPing((int) this.connection.getPing());
        this.currentDownStream.getTcpConnection().send(pingPacket);
    }
}
Also used : UpdatePingPacket(io.gomint.proxprox.network.tcp.protocol.UpdatePingPacket) SyncScheduledTask(io.gomint.proxprox.scheduler.SyncScheduledTask)

Example 2 with UpdatePingPacket

use of io.gomint.proxprox.network.tcp.protocol.UpdatePingPacket in project ProxProx by GoMint.

the class Decoder method decode.

@Override
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf buf, List<Object> objects) throws Exception {
    if (buf instanceof EmptyByteBuf) {
        // The Channel has disconnected and this is the last message we got. R.I.P. connection
        return;
    }
    byte packetId = buf.readByte();
    switch(packetId) {
        case 1:
            WrappedMCPEPacket wrappedMCPEPacket = new WrappedMCPEPacket();
            wrappedMCPEPacket.read(buf);
            objects.add(wrappedMCPEPacket);
            break;
        case 2:
            UpdatePingPacket updatePingPacket = new UpdatePingPacket();
            updatePingPacket.read(buf);
            objects.add(updatePingPacket);
            break;
        case 3:
            SendPlayerToServerPacket sendPlayerToServerPacket = new SendPlayerToServerPacket();
            sendPlayerToServerPacket.read(buf);
            objects.add(sendPlayerToServerPacket);
            break;
        default:
            break;
    }
}
Also used : SendPlayerToServerPacket(io.gomint.proxprox.network.tcp.protocol.SendPlayerToServerPacket) UpdatePingPacket(io.gomint.proxprox.network.tcp.protocol.UpdatePingPacket) EmptyByteBuf(io.netty.buffer.EmptyByteBuf) WrappedMCPEPacket(io.gomint.proxprox.network.tcp.protocol.WrappedMCPEPacket)

Aggregations

UpdatePingPacket (io.gomint.proxprox.network.tcp.protocol.UpdatePingPacket)2 SendPlayerToServerPacket (io.gomint.proxprox.network.tcp.protocol.SendPlayerToServerPacket)1 WrappedMCPEPacket (io.gomint.proxprox.network.tcp.protocol.WrappedMCPEPacket)1 SyncScheduledTask (io.gomint.proxprox.scheduler.SyncScheduledTask)1 EmptyByteBuf (io.netty.buffer.EmptyByteBuf)1