public void playCurrentSound() { if (selectedSound != null) { if (timeSoundFinishedPlaying < System.currentTimeMillis()) { if (SoundHandler.getSound(selectedSound.getSoundName()) != null) { lastSoundIdentifier = UUID.randomUUID().toString(); SoundsCool.proxy.getChannel().attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT); SoundsCool.proxy.getChannel().attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(new NetworkRegistry.TargetPoint(getWorldObj().provider.dimensionId, xCoord, yCoord, zCoord, 64)); SoundsCool.proxy.getChannel().writeOutbound(new ServerPlaySoundPacket(selectedSound.getSoundName(), lastSoundIdentifier, xCoord, yCoord, zCoord)); timeSoundFinishedPlaying = (long)(SoundHelper.getSoundLength(selectedSound.getSoundLocation())*1000) + System.currentTimeMillis(); } else { selectedSound = null; } } else { stopCurrentSound(); } } }
@Override public void processCommand(ICommandSender plr, String[] args) { if (!plr.getEntityWorld().isRemote) { if(args.length != 2){ plr.addChatMessage(new ChatComponentText("commands.nsod.usage")); return; } EntityPlayerMP vicitm = getPlayer(plr,args[0]); if(vicitm == null){ plr.addChatMessage(new ChatComponentText("commands.nsod.noexist").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED))); return; } Boolean value = Boolean.parseBoolean(args[1]); if(value == null){ plr.addChatMessage(new ChatComponentText("commands.nsod.usage")); } HackeryMod.channel.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER); HackeryMod.channel.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(vicitm); HackeryMod.channel.get(Side.SERVER).writeAndFlush(new setBSODPacket(value)); } }
@Override public void readBytes(ByteBuf bytes) { // System.out.println(String.format("Recieved %s", getClass().getCanonicalName())); message = Messages.values()[bytes.readInt()]; short len = bytes.readShort(); char[] str = new char[len]; for (short i = 0; i < len; i++) str[i] = bytes.readChar(); sender = new String(str); switch (message) { case REQUEST: for (String player : proxy.playerBodies.keySet()) { proxy.channel.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER); proxy.channel.get(Side.SERVER) .attr(FMLOutboundHandler.FML_MESSAGETARGETARGS) .set(MinecraftServer.getServer().getConfigurationManager().getPlayerForUsername(sender)); proxy.channel.get(Side.SERVER).writeOutbound(new PlayerDataPacket(player)); } break; } }
public static void sendPacketToPlayer(final XUPacketBase packet, final EntityPlayer player) { checkPacket(packet, Side.SERVER); if (XUHelper.isPlayerFake(player)) { return; } NetworkHandler.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER); NetworkHandler.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player); NetworkHandler.channels.get(Side.SERVER).writeOutbound(new Object[] { packet }); }
/** * Send this message to everyone within a certain range of a point. * <p/> * Adapted from CPW's code in * cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper * * @param message The message to send * @param point The * {@link cpw.mods.fml.common.network.NetworkRegistry.TargetPoint} * around which to send */ public void sendToAllAround(IPacket message, NetworkRegistry.TargetPoint point) { try { this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT); this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(point); this.channels.get(Side.SERVER).writeOutbound(message); } catch (Exception e) { GCLog.severe("Forge error when sending network packet to nearby players - this is not a Galacticraft bug, does another mod make fake players?"); e.printStackTrace(); } }
/** * Send this message to everyone within the supplied dimension. * <p/> * Adapted from CPW's code in * cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper * * @param message The message to send * @param dimensionId The dimension id to target */ public void sendToDimension(IPacket message, int dimensionId) { try { this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.DIMENSION); this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(dimensionId); this.channels.get(Side.SERVER).writeOutbound(message); } catch (Exception e) { GCLog.severe("Forge error when sending network packet to all players in dimension - this is not a Galacticraft bug, does another mod make fake players?"); e.printStackTrace(); } }
private void cleanAttributes(ChannelHandlerContext ctx) { ctx.channel().attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).remove(); ctx.channel().attr(NetworkRegistry.NET_HANDLER).remove(); ctx.channel().attr(NetworkDispatcher.FML_DISPATCHER).remove(); this.handshakeChannel.attr(FML_DISPATCHER).remove(); this.manager.channel().attr(FML_DISPATCHER).remove(); }
@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); } }
public static void makeEntitySpawnAdjustment(Entity entity, EntityPlayerMP player, int serverX, int serverY, int serverZ) { EmbeddedChannel embeddedChannel = channelPair.get(Side.SERVER); embeddedChannel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.PLAYER); embeddedChannel.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player); embeddedChannel.writeOutbound(new FMLMessage.EntityAdjustMessage(entity, serverX, serverY, serverZ)); }
public static void registerChannel(FMLContainer container, Side side) { channelPair = NetworkRegistry.INSTANCE.newChannel(container, "FML", new FMLRuntimeCodec(), new HandshakeCompletionHandler()); EmbeddedChannel embeddedChannel = channelPair.get(Side.SERVER); embeddedChannel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.NOWHERE); if (side == Side.CLIENT) { addClientHandlers(); } }
public static void registerChannel(ForgeModContainer forgeModContainer, Side side) { channelPair = NetworkRegistry.INSTANCE.newChannel(forgeModContainer, "FORGE", new ForgeRuntimeCodec()); if (side == Side.CLIENT) { addClientHandlers(); } FMLEmbeddedChannel serverChannel = channelPair.get(Side.SERVER); serverChannel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.NOWHERE); String handlerName = serverChannel.findChannelHandlerNameForType(ForgeRuntimeCodec.class); serverChannel.pipeline().addAfter(handlerName, "ServerToClientConnection", new ServerToClientConnectionEstablishedHandler()); }
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (!(msg instanceof FMLProxyPacket)) { ctx.write(msg); return; } final Channel channel = ctx.channel(); final IPacketTargetSelector target = channel.attr(MESSAGETARGET).get(); if (target == null) { ctx.write(msg); return; } final FMLProxyPacket pkt = (FMLProxyPacket)msg; final Side channelSide = channel.attr(NetworkRegistry.CHANNEL_SOURCE).get(); Preconditions.checkState(target.isAllowedOnSide(channelSide), "Packet not allowed on side"); final String channelName = channel.attr(NetworkRegistry.FML_CHANNEL).get(); Object arg = channel.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).get(); try { Collection<NetworkDispatcher> dispatchers = Lists.newArrayList(); target.listDispatchers(arg, dispatchers); for (NetworkDispatcher dispatcher : dispatchers) dispatcher.sendProxy(pkt); } catch (Throwable t) { throw new IllegalStateException(String.format( "Failed to select and send message (selector %s, arg: %s, channel: %s, side: %s)", target, arg, channelName, channelSide), t); } }
public void stopCurrentSound() { if (System.currentTimeMillis() < timeSoundFinishedPlaying) { SoundsCool.proxy.getChannel().attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT); SoundsCool.proxy.getChannel().attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(new NetworkRegistry.TargetPoint(getWorldObj().provider.dimensionId, xCoord, yCoord, zCoord, 64)); SoundsCool.proxy.getChannel().writeOutbound(new StopSoundPacket(lastSoundIdentifier)); timeSoundFinishedPlaying = 0; } }
public static void SendPacketToPlayerListExcept(AbstractPacket packet, EnumMap<Side, FMLEmbeddedChannel> channels, ArrayList<EntityPlayer> list, EntityPlayer pla){ for(EntityPlayer pl : list) { if(pl.getCommandSenderName().equalsIgnoreCase(pla.getCommandSenderName())) continue; channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER); channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(pl); channels.get(Side.SERVER).writeAndFlush(packet); } }
public static void SendPacketToPlayerList(AbstractPacket packet, EnumMap<Side, FMLEmbeddedChannel> channels, ArrayList<EntityPlayer> list){ for(EntityPlayer pl : list) { channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER); channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(pl); channels.get(Side.SERVER).writeAndFlush(packet); } }
public static void sendToPlayer(EntityPlayer ep, IPacket packet) { channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET) .set(FMLOutboundHandler.OutboundTarget.PLAYER); channels.get(Side.SERVER) .attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(ep); channels.get(Side.SERVER).writeOutbound(packet); }
@Override public void readBytes(ByteBuf bytes) { // System.out.println(String.format("Received: %s", getClass().getCanonicalName())); // System.out.println("Received packet of " + bytes.array().length + " bytes."); short len = bytes.readShort(); char[] chars = new char[len]; for (int i = 0; i < len; i++) chars[i] = bytes.readChar(); name = String.valueOf(chars); len = bytes.readShort(); byte[] compressedBody = new byte[len]; for (short i = 0; i < len; i++) compressedBody[i] = bytes.readByte(); try { ObjectInputStream obj = new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(compressedBody))); body = (Body) obj.readObject(); obj.close(); } catch (Exception e) { e.printStackTrace(); } if (proxy.playerBodies.containsKey(name)) proxy.playerBodies.remove(name); proxy.playerBodies.put(name, body); if (FMLCommonHandler.instance().getEffectiveSide().isServer()) { proxy.getServerChannel().attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALL); proxy.getServerChannel().writeOutbound(new PlayerDataPacket(name, body)); } }
public static void sendToAllPlayers(final XUPacketBase packet) { checkPacket(packet, Side.SERVER); NetworkHandler.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALL); NetworkHandler.channels.get(Side.SERVER).writeOutbound(new Object[] { packet }); }
public static void sendToAllAround(final XUPacketBase packet, final NetworkRegistry.TargetPoint point) { checkPacket(packet, Side.SERVER); NetworkHandler.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT); NetworkHandler.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(point); NetworkHandler.channels.get(Side.SERVER).writeAndFlush(packet).addListener((GenericFutureListener)ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); }
public static void sendPacketToServer(final XUPacketBase packet) { checkPacket(packet, Side.CLIENT); NetworkHandler.channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.TOSERVER); NetworkHandler.channels.get(Side.CLIENT).writeOutbound(new Object[] { packet }); }
public void sendToAll(IPacket message) { this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALL); this.channels.get(Side.SERVER).writeOutbound(message); }
public void sendToPlayer(IPacket message, EntityPlayerMP player) { this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER); this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player); this.channels.get(Side.SERVER).writeOutbound(message); }
public void sendToAllAround(IPacket message, NetworkRegistry.TargetPoint point) { this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT); this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(point); this.channels.get(Side.SERVER).writeOutbound(message); }
public void sendToDimension(IPacket message, int dimensionId) { this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.DIMENSION); this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(dimensionId); this.channels.get(Side.SERVER).writeOutbound(message); }