Example usage for io.netty.channel ChannelHandlerContext attr

List of usage examples for io.netty.channel ChannelHandlerContext attr

Introduction

In this page you can find the example usage for io.netty.channel ChannelHandlerContext attr.

Prototype

@Deprecated
@Override
<T> Attribute<T> attr(AttributeKey<T> key);

Source Link

Usage

From source file:tk.jomp16.rcon.internal.netty.RconNettyHandler.java

License:Open Source License

/**
 * This method just register and set the authenticated attribute to false
 *
 * @param ctx the client ChannelHandlerContext
 *///from   w  ww. ja va2 s. c o m
@Override
public void channelRegistered(final ChannelHandlerContext ctx) {
    ctx.attr(this.authenticatedAttribute).set(false);
}

From source file:tk.jomp16.rcon.internal.netty.RconNettyHandler.java

License:Open Source License

/**
 * This method just set the authenticated attribute to false
 *
 * @param ctx the client ChannelHandlerContext
 *//*from   ww  w .j a v a2 s  .c o m*/
@Override
public void channelUnregistered(final ChannelHandlerContext ctx) {
    ctx.attr(this.authenticatedAttribute).set(false);
}

From source file:tk.jomp16.rcon.internal.netty.RconNettyHandler.java

License:Open Source License

/**
 * Reads, and do a action depending of the type of request
 *
 * @param ctx the client ChannelHandlerContext
 * @param msg the RconRequest packet/* w w w.  j a va 2 s . c  o m*/
 * @see RconRequest
 */
@Override
public void channelRead(final ChannelHandlerContext ctx, final Object msg) {
    final RconRequest rconRequest = (RconRequest) msg;

    if (rconRequest.getType() == RconConstant.SERVERDATA_AUTH) {
        if (ctx.attr(this.authenticatedAttribute).get() || rconRequest.getBody().isEmpty()) {
            ctx.disconnect();

            return;
        }

        ctx.writeAndFlush(new RconResponse(rconRequest.getId(), RconConstant.SERVERDATA_RESPONSE_VALUE));
        ctx.writeAndFlush(new RconResponse(
                this.rconServer.getRconPassword().equals(rconRequest.getBody()) ? rconRequest.getId() : -1,
                RconConstant.SERVERDATA_AUTH_RESPONSE));

        ctx.attr(this.authenticatedAttribute).set(true);

        return;
    }

    this.rconServer.getRconEvents().parallelStream().forEach(rconEvent -> {
        try {
            rconEvent.handle(this.rconServer, ctx.channel(), rconRequest);
        } catch (final Exception e) {
            log.error("An error happened while handling Source RCON packet!", e);
        }
    });
}