예제 #1
0
  @Override
  public void parseCommand(String[] message, ChannelHandlerContext ctx) {
    String password = message[0];

    if (password.equals("cometServer")) {
      String command = message[1];

      switch (command) {
        default:
          {
            ctx.channel().writeAndFlush("response||You're connected!");
            break;
          }

        case "stats":
          {
            ctx.channel()
                .writeAndFlush("response||" + JsonFactory.getInstance().toJson(CometStats.get()));
            break;
          }
      }
    } else {
      ctx.disconnect();
    }
  }
예제 #2
0
 @Override
 public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
   if (side == Side.CLIENT) {
     FMLCommonHandler.instance()
         .bus()
         .post(new FMLNetworkEvent.ClientDisconnectionFromServerEvent(manager));
   } else {
     FMLCommonHandler.instance()
         .bus()
         .post(new FMLNetworkEvent.ServerDisconnectionFromClientEvent(manager));
   }
   cleanAttributes(ctx);
   ctx.disconnect(promise);
 }
예제 #3
0
  private void closeOutboundAndChannel(
      final ChannelHandlerContext ctx, final ChannelFuture future, boolean disconnect)
      throws Exception {
    if (!ctx.channel().isActive()) {
      if (disconnect) {
        ctx.disconnect(future);
      } else {
        ctx.close(future);
      }
      return;
    }

    engine.closeOutbound();

    ChannelFuture closeNotifyFuture = ctx.newFuture();
    flush(ctx, closeNotifyFuture);
    safeClose(ctx, closeNotifyFuture, future);
  }
예제 #4
0
  private void closeOutboundAndChannel(
      final ChannelHandlerContext ctx, final ChannelPromise promise, boolean disconnect)
      throws Exception {
    if (!ctx.channel().isActive()) {
      if (disconnect) {
        ctx.disconnect(promise);
      } else {
        ctx.close(promise);
      }
      return;
    }

    engine.closeOutbound();

    ChannelPromise closeNotifyFuture = ctx.newPromise();
    write(ctx, Unpooled.EMPTY_BUFFER, closeNotifyFuture);
    flush(ctx);
    safeClose(ctx, closeNotifyFuture, promise);
  }
예제 #5
0
 @Override
 public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
   ctx.disconnect(promise);
 }