Beispiel #1
0
  private boolean handleClientSideCustomPacket(
      S3FPacketCustomPayload msg, ChannelHandlerContext context) {
    String channelName = msg.getChannelName();
    if ("FML|MP".equals(channelName)) {
      try {
        if (multipart == null) {
          multipart = new MultiPartCustomPayload(msg.getBufferData());
        } else {
          multipart.processPart(msg.getBufferData());
        }
      } catch (IOException e) {
        this.kickWithMessage(e.getMessage());
        multipart = null;
        return true;
      }

      if (multipart.isComplete()) {
        msg = multipart;
        channelName = msg.getChannelName();
        multipart = null;
      } else {
        return true; // Haven't received all so return till we have.
      }
    }
    if ("FML|HS".equals(channelName)
        || "REGISTER".equals(channelName)
        || "UNREGISTER".equals(channelName)) {
      FMLProxyPacket proxy = new FMLProxyPacket(msg);
      proxy.setDispatcher(this);
      handshakeChannel.writeInbound(proxy);
      // forward any messages into the regular channel
      for (Object push : handshakeChannel.inboundMessages()) {
        List<FMLProxyPacket> messageResult =
            FMLNetworkHandler.forwardHandshake(
                (FMLMessage.CompleteHandshake) push, this, Side.CLIENT);
        for (FMLProxyPacket result : messageResult) {
          result.setTarget(Side.CLIENT);
          result.payload().resetReaderIndex();
          context.fireChannelRead(result);
        }
      }
      handshakeChannel.inboundMessages().clear();
      return true;
    } else if (NetworkRegistry.INSTANCE.hasChannel(channelName, Side.CLIENT)) {
      FMLProxyPacket proxy = new FMLProxyPacket(msg);
      proxy.setDispatcher(this);
      context.fireChannelRead(proxy);
      return true;
    }
    return false;
  }
Beispiel #2
0
 private boolean handleServerSideCustomPacket(
     C17PacketCustomPayload msg, ChannelHandlerContext context) {
   if (state == ConnectionState.AWAITING_HANDSHAKE) {
     synchronized (this) { // guard from other threads changing the state on us
       if (state == ConnectionState.AWAITING_HANDSHAKE) {
         state = ConnectionState.HANDSHAKING;
       }
     }
   }
   String channelName = msg.getChannelName();
   if ("FML|HS".equals(channelName)
       || "REGISTER".equals(channelName)
       || "UNREGISTER".equals(channelName)) {
     FMLProxyPacket proxy = new FMLProxyPacket(msg);
     proxy.setDispatcher(this);
     handshakeChannel.writeInbound(proxy);
     for (Object push : handshakeChannel.inboundMessages()) {
       List<FMLProxyPacket> messageResult =
           FMLNetworkHandler.forwardHandshake(
               (FMLMessage.CompleteHandshake) push, this, Side.SERVER);
       for (FMLProxyPacket result : messageResult) {
         result.setTarget(Side.SERVER);
         result.payload().resetReaderIndex();
         context.fireChannelRead(result);
       }
     }
     handshakeChannel.inboundMessages().clear();
     return true;
   } else if (NetworkRegistry.INSTANCE.hasChannel(channelName, Side.SERVER)) {
     FMLProxyPacket proxy = new FMLProxyPacket(msg);
     proxy.setDispatcher(this);
     context.fireChannelRead(proxy);
     return true;
   }
   return false;
 }