@Override protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception { ByteBuf buffer = msg.content(); int seq = buffer.readUnsignedShort(); int msgid = buffer.readByte(); IMessage message = TF2weapons.network.messages[msgid].newInstance(); //buffer.discardReadBytes(); message.fromBytes(buffer); IMessageHandler<IMessage, IMessage> handler = TF2weapons.network.handlerList.get(message.getClass()); if(constr == null) { constr =MessageContext.class.getDeclaredConstructor(INetHandler.class, Side.class); constr.setAccessible(true); } MessageContext context = constr.newInstance(Minecraft.getMinecraft().player.connection, Side.CLIENT); handler.onMessage(message, context); System.out.println("PacketFrom: "+msg.sender().getAddress()+ " "+msg.sender().getPort()+" "); }
/** * Passes this Packet on to the NetHandler for processing. */ @Override public void processPacket(INetHandler inethandler) { this.netHandler = inethandler; EmbeddedChannel internalChannel = NetworkRegistry.INSTANCE.getChannel(this.channel, this.target); if (internalChannel != null) { internalChannel.attr(NetworkRegistry.NET_HANDLER).set(this.netHandler); try { if (internalChannel.writeInbound(this)) { badPackets.add(this.channel); if (badPackets.size() % packetCountWarning == 0) { FMLLog.severe("Detected ongoing potential memory leak. %d packets have leaked. Top offenders", badPackets.size()); int i = 0; for (Entry<String> s : Multisets.copyHighestCountFirst(badPackets).entrySet()) { if (i++ > 10) break; FMLLog.severe("\t %s : %d", s.getElement(), s.getCount()); } } } internalChannel.inboundMessages().clear(); } catch (FMLNetworkException ne) { FMLLog.log(Level.ERROR, ne, "There was a network exception handling a packet on channel %s", channel); dispatcher.rejectHandshake(ne.getMessage()); } catch (Throwable t) { FMLLog.log(Level.ERROR, t, "There was a critical exception handling a packet on channel %s", channel); dispatcher.rejectHandshake("A fatal error has occurred, this connection is terminated"); } } }
@Override protected void channelRead0(ChannelHandlerContext ctx, IPacket msg) throws Exception { INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); EntityPlayer player = GalacticraftCore.proxy.getPlayerFromNetHandler(netHandler); switch (FMLCommonHandler.instance().getEffectiveSide()) { case CLIENT: msg.handleClientSide(player); break; case SERVER: msg.handleServerSide(player); break; default: break; } }
@Override protected void channelRead0(ChannelHandlerContext ctx, IPacket msg) throws Exception { INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); EntityPlayer player = VivecraftForge.proxy.getPlayerFromNetHandler(netHandler); switch (FMLCommonHandler.instance().getEffectiveSide()) { case CLIENT: msg.handleClient(player); break; case SERVER: msg.handleServer(player); break; default: VivecraftForgeLog.severe("Impossible scenario encountered! Effective side is neither server nor client!"); break; } }
@SuppressWarnings( "unchecked" ) public void onPacketData( final FMLProxyPacket packet, final INetHandler handler, final EntityPlayerMP playerEntity ) { if ( playerEntity == null ) { return; } final PacketBuffer buffer = new PacketBuffer( packet.payload() ); final ModPacket innerPacket = parsePacket( buffer ); innerPacket.serverEntity = playerEntity; PacketThreadUtil.checkThreadAndEnqueue( innerPacket, handler, playerEntity.getServer() ); innerPacket.server( playerEntity ); }
@Override protected void channelRead0(ChannelHandlerContext ctx, PacketAbstract packet) throws Exception { INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); switch (FMLCommonHandler.instance().getEffectiveSide()) { case CLIENT: packet.handleClientSide(NovaMinecraft.proxy.getClientPlayer()); break; case SERVER: packet.handleServerSide(((NetHandlerPlayServer) netHandler).playerEntity); break; default: break; } }
@Override public void monitorIncoming( INetHandler net, net.minecraft.network.Packet packet ) { if ( !( net instanceof NetHandlerPlayServer ) || !( packet instanceof C0BPacketEntityAction ) ) { return; } NetHandlerPlayServer server = ( NetHandlerPlayServer ) net; C0BPacketEntityAction action = ( C0BPacketEntityAction ) packet; if ( action.func_149513_d() != 6 || !( server.playerEntity.ridingEntity instanceof PetEntity ) ) { return; } PetEntity pet = ( PetEntity ) server.playerEntity.ridingEntity; pet.setJumpingState( action.func_149512_e() ); }
@Redirect(method = "channelRead0", at = @At(value = "INVOKE", target = "net/minecraft/network/Packet.processPacket(Lnet/minecraft/network/INetHandler;)V")) @SuppressWarnings("unchecked") private void processPacket(Packet<?> packetIn, INetHandler handler) { PacketEvent event = new PacketEvent.Receive(packetIn); ClientAPI.EVENT_BUS.post(event); if (event.isCancelled()) return; ((Packet<INetHandler>) event.getPacket()).processPacket(handler); }
@Override protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception { ByteBuf buffer = msg.content(); int plid = buffer.readShort(); int seq = buffer.readUnsignedShort(); int msgid = buffer.readByte(); if(msgid == (byte)-128) { server.outboundTargets.put((short) plid, SocketUtils.socketAddress(msg.sender().getAddress().getHostAddress(),msg.sender().getPort())); } else { EntityPlayerMP player = server.playerList.get((short)plid); IMessage message = TF2weapons.network.messages[msgid].newInstance(); //buffer.discardReadBytes(); message.fromBytes(buffer); IMessageHandler<IMessage, IMessage> handler = TF2weapons.network.handlerList.get(message.getClass()); if(constr == null) { constr =MessageContext.class.getDeclaredConstructor(INetHandler.class, Side.class); constr.setAccessible(true); } MessageContext context = constr.newInstance(player.connection, Side.SERVER); handler.onMessage(message, context); } System.out.println("PacketFrom: "+msg.sender().getAddress()+ " "+msg.sender().getPort()+" "); }
@Override public IThreadListener getWorldThread(INetHandler net) { if (net instanceof INetHandlerPlayClient || net instanceof INetHandlerLoginClient || net instanceof INetHandlerStatusClient) return getClient(); if (net instanceof INetHandlerHandshakeServer || net instanceof INetHandlerLoginServer || net instanceof INetHandlerPlayServer || net instanceof INetHandlerStatusServer) return getServer(); throw new RuntimeException("Unknown INetHandler: " + net); }
@Override protected void channelRead0(ChannelHandlerContext ctx, REQ msg) throws Exception { INetHandler iNetHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); MessageContext context = new MessageContext(iNetHandler, side); REPLY result = messageHandler.onMessage(msg, context); if (result != null) { ctx.channel().attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.REPLY); ctx.writeAndFlush(result).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); } }
@Override public EntityPlayer getPlayerFromNetHandler(final INetHandler handler) { final EntityPlayer player = super.getPlayerFromNetHandler(handler); if (player == null) { return this.getClientPlayer(); } return player; }
@SideOnly(Side.CLIENT) @Override public void processPacket(INetHandler var1) { if (this.type != EnumSimplePacket.C_UPDATE_SPACESTATION_LIST && this.type != EnumSimplePacket.C_UPDATE_PLANETS_LIST && this.type != EnumSimplePacket.C_UPDATE_CONFIGS) { return; } if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) { this.handleClientSide(FMLClientHandler.instance().getClientPlayerEntity()); } }
public EntityPlayer getPlayerFromNetHandler(INetHandler handler) { if (handler instanceof NetHandlerPlayServer) { return ((NetHandlerPlayServer) handler).playerEntity; } else { return null; } }
@Override public EntityPlayer getPlayerFromNetHandler(INetHandler handler) { if (handler instanceof NetHandlerPlayServer) { return ((NetHandlerPlayServer) handler).playerEntity; } else { return FMLClientHandler.instance().getClientPlayerEntity(); } }
@Override public void handle(INetHandler netHandler, String channel, PacketCustom packet) throws Exception { if (netHandler instanceof INetHandlerPlayClient) handler.handlePacket(packet, Minecraft.getMinecraft(), (INetHandlerPlayClient) netHandler); else System.err.println("Invalid INetHandler for PacketCustom on channel: " + channel); }
@Override public void handle(INetHandler netHandler, String channel, PacketCustom packet) throws Exception { if (netHandler instanceof NetHandlerPlayServer) handler.handlePacket(packet, ((NetHandlerPlayServer) netHandler).playerEntity, (INetHandlerPlayServer) netHandler); else System.err.println("Invalid INetHandler for PacketCustom on channel: " + channel); }
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof NetworkHandshakeEstablished) { INetHandler netHandler = ((NetworkDispatcher) ctx.channel().attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).get()).getNetHandler(); if (netHandler instanceof NetHandlerPlayServer) handler.handshakeRecieved((NetHandlerPlayServer) netHandler); } else ctx.fireUserEventTriggered(evt); }
@Override public void func_148833_a(INetHandler inethandler) { this.netHandler = inethandler; EmbeddedChannel internalChannel = NetworkRegistry.INSTANCE.getChannel(this.channel, this.target); if (internalChannel != null) { internalChannel.attr(NetworkRegistry.NET_HANDLER).set(this.netHandler); try { if (internalChannel.writeInbound(this)) { badPackets.add(this.channel); if (badPackets.size() % packetCountWarning == 0) { FMLLog.severe("Detected ongoing potential memory leak. %d packets have leaked. Top offenders", badPackets.size()); int i = 0; for (Entry<String> s : Multisets.copyHighestCountFirst(badPackets).entrySet()) { if (i++ > 10) break; FMLLog.severe("\t %s : %d", s.getElement(), s.getCount()); } } } internalChannel.inboundMessages().clear(); } catch (FMLNetworkException ne) { FMLLog.log(Level.ERROR, ne, "There was a network exception handling a packet on channel %s", channel); dispatcher.rejectHandshake(ne.getMessage()); } catch (Throwable t) { FMLLog.log(Level.ERROR, t, "There was a critical exception handling a packet on channel %s", channel); dispatcher.rejectHandshake("A fatal error has occured, this connection is terminated"); } } }
@Override public EntityPlayer getPlayerFromNetHandler(INetHandler netHandler) { if (netHandler instanceof NetHandlerPlayServer) { return ((NetHandlerPlayServer)netHandler).playerEntity; } return FMLClientHandler.instance().getClientPlayerEntity(); }
@Override public void handle(final INetHandler netHandler, final String channel, final PacketCustom packet) { if (netHandler instanceof INetHandlerPlayClient) { Minecraft mc = Minecraft.getMinecraft(); if (!mc.isCallingFromMinecraftThread()) { mc.addScheduledTask(() -> handle(netHandler, channel, packet)); } else { handler.handlePacket(packet, mc, (INetHandlerPlayClient) netHandler); } } else { System.err.println("Invalid INetHandler for PacketCustom on channel: " + channel); } }
@Override public void handle(final INetHandler netHandler, final String channel, final PacketCustom packet) { if (netHandler instanceof NetHandlerPlayServer) { MinecraftServer mc = FMLCommonHandler.instance().getMinecraftServerInstance(); if (!mc.isCallingFromMinecraftThread()) { mc.addScheduledTask(() -> handle(netHandler, channel, packet)); } else { handler.handlePacket(packet, ((NetHandlerPlayServer) netHandler).player, (INetHandlerPlayServer) netHandler); } } else { System.err.println("Invalid INetHandler for PacketCustom on channel: " + channel); } }
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof NetworkHandshakeEstablished) { INetHandler netHandler = ((NetworkDispatcher) ctx.channel().attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).get()).getNetHandler(); if (netHandler instanceof NetHandlerPlayServer) { handler.handshakeReceived((NetHandlerPlayServer) netHandler); } } else { ctx.fireUserEventTriggered(evt); } }
@Override public EntityPlayer obtainPlayer(final INetHandler handler) { EntityPlayer player = super.obtainPlayer(handler); if (player == null) { player = (EntityPlayer)Minecraft.func_71410_x().field_71439_g; } return player; }
@Override protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception { ByteBuf payload = msg.payload(); byte discriminator = payload.readByte(); Class<? extends ARKMessage> clazz = packets.get(discriminator); if (clazz == null) { throw new NullPointerException("No packet registered for discriminator: " + discriminator); } ARKMessage pkt = clazz.newInstance(); pkt.decodeInto(ctx, payload.slice()); EntityPlayer player; switch (FMLCommonHandler.instance().getEffectiveSide()) { case CLIENT: player = getClientPlayer(); pkt.handleClientSide(player); break; case SERVER: INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); player = ((NetHandlerPlayServer) netHandler).playerEntity; pkt.handleServerSide(player); break; default: } out.add(pkt); }
@Override public void processPacket( final INetHandler handler ) { if ( serverEntity == null ) { client(); } else { server( serverEntity ); } }
@SuppressWarnings( "unchecked" ) public void onPacketData( final FMLProxyPacket packet, final INetHandler handler ) { final PacketBuffer buffer = new PacketBuffer( packet.payload() ); final ModPacket innerPacket = parsePacket( buffer ); PacketThreadUtil.checkThreadAndEnqueue( innerPacket, handler, Minecraft.getMinecraft() ); innerPacket.client(); }
@Override public EntityPlayer getPlayerFrom(INetHandler netHandler) { if (netHandler instanceof NetHandlerPlayClient) { if (real_player != null) return real_player; return mc.thePlayer; } return super.getPlayerFrom(netHandler); }
public EntityPlayer getPlayerFrom(INetHandler netHandler) { if (netHandler instanceof NetHandlerPlayServer) { NetHandlerPlayServer nh = (NetHandlerPlayServer) netHandler; return nh.playerEntity; } return null; }
@Override public boolean handlePacket(INetHandler netHandler, Packet<?> packet) { if (!this.lastRequestedStack.isEmpty() && packet instanceof SPacketSetSlot) { SPacketSetSlot setslot = (SPacketSetSlot) packet; ItemStack stack = setslot.getStack(); if (this.lastRequestedStack.isItemEqual(stack)) { this.pickSlot = true; } } return true; }
public EntityPlayer getPlayer(INetHandler handler) { if(handler instanceof NetHandlerPlayServer) { return ((NetHandlerPlayServer)handler).playerEntity; } return LogisticStorage.core.get().getPlayer(); }
protected EntityPlayer getPlayerFromNetHandler(INetHandler handler) { if (handler instanceof NetHandlerPlayServer) { return ((NetHandlerPlayServer) handler).playerEntity; } else { return null; } }
@SideOnly(Side.CLIENT) @Override public void processPacket(INetHandler var1) { /* if (this.type != EnumSimplePacket.C_UPDATE_SPACESTATION_LIST && this.type != EnumSimplePacket.C_UPDATE_PLANETS_LIST && this.type != EnumSimplePacket.C_UPDATE_CONFIGS) { return; } */ if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) { this.handleClientSide(FMLClientHandler.instance().getClientPlayerEntity()); }/**/ }
@Override protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception { ByteBuf payload = msg.payload(); byte discriminator = payload.readByte(); Class<? extends MMMessage> clazz = packets.get(discriminator); if (clazz == null) { throw new NullPointerException("No packet registered for discriminator: " + discriminator); } MMMessage pkt = clazz.newInstance(); pkt.decodeInto(ctx, payload.slice()); EntityPlayer player; switch (FMLCommonHandler.instance().getEffectiveSide()) { case CLIENT: player = getClientPlayer(); pkt.handleClientSide(player); break; case SERVER: INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); player = ((NetHandlerPlayServer) netHandler).playerEntity; pkt.handleServerSide(player); break; default: } out.add(pkt); }
@Override public EntityPlayer getPlayerFromHandler(INetHandler handler) { if (handler instanceof NetHandlerPlayServer) return ((NetHandlerPlayServer) handler).playerEntity; if (handler instanceof NetHandlerPlayClient) return getThePlayer(); return null; }
public static void intercept( INetHandler net, net.minecraft.network.Packet packet ) { //System.out.println("Incoming" ); Iterator< IPacketMonitor > it = monitors.iterator(); while ( it.hasNext() ) { IPacketMonitor mon = it.next(); mon.monitorIncoming( net, packet ); } }
public void mineBlock(World world, int x, int y, int z, int meta, EntityPlayer player, Block block) { // Workaround for dropping experience boolean silktouch = EnchantmentHelper.getSilkTouchModifier(player); int fortune = EnchantmentHelper.getFortuneModifier(player); int exp = block.getExpDrop(world, meta, fortune); block.onBlockHarvested(world, x, y, z, meta, player); if (block.removedByPlayer(world, player, x, y, z, true)) { block.onBlockDestroyedByPlayer(world, x, y, z, meta); block.harvestBlock(world, player, x, y, z, meta); // Workaround for dropping experience if (!silktouch) block.dropXpOnBlockBreak(world, x, y, z, exp); if (world.isRemote) { INetHandler handler = FMLClientHandler.instance().getClientPlayHandler(); if (handler != null && handler instanceof NetHandlerPlayClient) { NetHandlerPlayClient handlerClient = (NetHandlerPlayClient) handler; handlerClient.addToSendQueue(new C07PacketPlayerDigging(0, x, y, z, Minecraft.getMinecraft().objectMouseOver.sideHit)); handlerClient.addToSendQueue(new C07PacketPlayerDigging(2, x, y, z, Minecraft.getMinecraft().objectMouseOver.sideHit)); } } } }