@Override
FMLNetworkEvent.CustomPacketEvent<?> make(FMLProxyPacket msg)
{
FMLNetworkEvent.CustomPacketEvent<?> event = null;
if (msg.handler() instanceof NetHandlerPlayClient)
{
NetHandlerPlayClient client = (NetHandlerPlayClient) msg.handler();
event = new FMLNetworkEvent.ClientCustomPacketEvent(client.getNetworkManager(), msg);
}
else if (msg.handler() instanceof NetHandlerPlayServer)
{
NetHandlerPlayServer server = (NetHandlerPlayServer) msg.handler();
event = new FMLNetworkEvent.ServerCustomPacketEvent(server.getNetworkManager(), msg);
}
return event;
}
java类net.minecraftforge.fml.common.network.internal.FMLProxyPacket的实例源码
FMLEventChannel.java 文件源码
项目:CustomWorldGen
阅读 27
收藏 0
点赞 0
评论 0
NetworkDispatcher.java 文件源码
项目:CustomWorldGen
阅读 24
收藏 0
点赞 0
评论 0
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception
{
if (msg instanceof FMLProxyPacket)
{
if (side == Side.CLIENT)
{
//Client to server large packets are not supported to prevent client being bad.
ctx.write(((FMLProxyPacket) msg).toC17Packet(), promise);
}
else
{
List<Packet<INetHandlerPlayClient>> parts = ((FMLProxyPacket)msg).toS3FPackets();
for (Packet<INetHandlerPlayClient> pkt : parts)
{
ctx.write(pkt, promise);
}
}
}
else
{
ctx.write(msg, promise);
}
}
ChannelRegistrationHandler.java 文件源码
项目:CustomWorldGen
阅读 18
收藏 0
点赞 0
评论 0
@Override
protected void channelRead0(ChannelHandlerContext ctx, FMLProxyPacket msg) throws Exception
{
Side side = msg.getTarget();
NetworkManager manager = msg.getOrigin();
if (msg.channel().equals("REGISTER") || msg.channel().equals("UNREGISTER"))
{
byte[] data = new byte[msg.payload().readableBytes()];
msg.payload().readBytes(data);
String channels = new String(data,Charsets.UTF_8);
String[] split = channels.split("\0");
Set<String> channelSet = ImmutableSet.copyOf(split);
FMLCommonHandler.instance().fireNetRegistrationEvent(manager, channelSet, msg.channel(), side);
}
else
{
ctx.fireChannelRead(msg);
}
}
FMLOutboundHandler.java 文件源码
项目:CustomWorldGen
阅读 21
收藏 0
点赞 0
评论 0
@Override
public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet)
{
int dimension = (Integer)args;
ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.builder();
for (EntityPlayerMP player : FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerList())
{
if (dimension == player.dimension)
{
NetworkDispatcher dispatcher = player.connection.netManager.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
// Null dispatchers may exist for fake players - skip them
if (dispatcher != null) builder.add(dispatcher);
}
}
return builder.build();
}
FMLOutboundHandler.java 文件源码
项目:CustomWorldGen
阅读 25
收藏 0
点赞 0
评论 0
@Override
public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet)
{
TargetPoint tp = (TargetPoint)args;
ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.builder();
for (EntityPlayerMP player : FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerList())
{
if (player.dimension == tp.dimension)
{
double d4 = tp.x - player.posX;
double d5 = tp.y - player.posY;
double d6 = tp.z - player.posZ;
if (d4 * d4 + d5 * d5 + d6 * d6 < tp.range * tp.range)
{
NetworkDispatcher dispatcher = player.connection.netManager.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
if (dispatcher != null) builder.add(dispatcher);
}
}
}
return builder.build();
}
FMLIndexedMessageToMessageCodec.java 文件源码
项目:CustomWorldGen
阅读 22
收藏 0
点赞 0
评论 0
@Override
protected final void encode(ChannelHandlerContext ctx, A msg, List<Object> out) throws Exception
{
PacketBuffer buffer = new PacketBuffer(Unpooled.buffer());
byte discriminator = types.get(msg.getClass());
buffer.writeByte(discriminator);
encodeInto(ctx, msg, buffer);
FMLProxyPacket proxy = new FMLProxyPacket(buffer/*.copy()*/, ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
WeakReference<FMLProxyPacket> ref = ctx.attr(INBOUNDPACKETTRACKER).get().get();
FMLProxyPacket old = ref == null ? null : ref.get();
if (old != null)
{
proxy.setDispatcher(old.getDispatcher());
}
out.add(proxy);
}
FMLIndexedMessageToMessageCodec.java 文件源码
项目:CustomWorldGen
阅读 18
收藏 0
点赞 0
评论 0
@Override
protected final void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception
{
testMessageValidity(msg);
ByteBuf payload = msg.payload().duplicate();
if (payload.readableBytes() < 1)
{
FMLLog.log(Level.ERROR, "The FMLIndexedCodec has received an empty buffer on channel %s, likely a result of a LAN server issue. Pipeline parts : %s", ctx.channel().attr(NetworkRegistry.FML_CHANNEL), ctx.pipeline().toString());
}
byte discriminator = payload.readByte();
Class<? extends A> clazz = discriminators.get(discriminator);
if(clazz == null)
{
throw new NullPointerException("Undefined message for discriminator " + discriminator + " in channel " + msg.channel());
}
A newMsg = clazz.newInstance();
ctx.attr(INBOUNDPACKETTRACKER).get().set(new WeakReference<FMLProxyPacket>(msg));
decodeInto(ctx, payload.slice(), newMsg);
out.add(newMsg);
}
NetworkRouter.java 文件源码
项目:Ambidextrous
阅读 27
收藏 0
点赞 0
评论 0
@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 );
}
DimensionSliceEntity.java 文件源码
项目:Factorization
阅读 15
收藏 0
点赞 0
评论 0
void shareTransforms() {
boolean needSync = (transformSynced.getGrandUnifiedDistance(transform) != 0 || velocitySynced.getGrandUnifiedDistance(velocity) != 0) && !hasOrders();
if (!needSync) return;
try {
ByteBuf output = Unpooled.buffer();
Core.network.prefixEntityPacket(output, this, SyncMessages.TRANSFORMS);
putTransforms(new DataOutByteBuf(output, Side.SERVER));
FMLProxyPacket toSend = Core.network.entityPacket(output);
Core.network.broadcastPacket(null, new Coord(this), toSend);
} catch (IOException e) {
e.printStackTrace();
return;
}
transformSynced = transform.copy();
velocitySynced = velocity.copy();
}
TileEntityCommon.java 文件源码
项目:Factorization
阅读 19
收藏 0
点赞 0
评论 0
@Override
public FMLProxyPacket getDescriptionPacket() {
ByteBuf buf = Unpooled.buffer();
DataOutByteBuf data = new DataOutByteBuf(buf, Side.SERVER);
try {
NetworkFactorization.writeMessage(buf, FzNetEventHandler.TO_BLOCK, StandardMessageType.TileFzType);
buf.writeInt(pos.getX());
buf.writeInt(pos.getY());
buf.writeInt(pos.getZ());
int ftId = getFactoryType().md;
buf.writeByte(ftId);
putData(data);
return FzNetDispatch.generate(buf);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
BlockFactorization.java 文件源码
项目:Factorization
阅读 18
收藏 0
点赞 0
评论 0
@Override
public boolean removedByPlayer(World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
Coord here = new Coord(world, pos);
TileEntityCommon tec = here.getTE(TileEntityCommon.class);
if (tec == null) {
if (!world.isRemote) {
new Notice(here, "There was no TileEntity!").send(player);
}
return world.setBlockToAir(pos);
}
boolean ret = tec.removedByPlayer(player, willHarvest);
if (!world.isRemote && !ret) {
FMLProxyPacket description = tec.getDescriptionPacket();
Core.network.broadcastPacket(player, here, description);
here.sendRedraw();
}
return ret;
}
MiscellaneousNonsense.java 文件源码
项目:Factorization
阅读 23
收藏 0
点赞 0
评论 0
@SubscribeEvent
public void tickServer(TickEvent.ServerTickEvent event) {
if (event.phase != TickEvent.Phase.START) return;
MinecraftServer ms = MinecraftServer.getServer();
if (ms.getTickCounter() < ms.tickTimeArray.length) {
//Ignore startup
return;
}
if (measurements++ != FzConfig.tps_reporting_interval) {
return;
}
measurements = 0;
float tps = getTpsRatio();
if (tps != last_tps) {
FMLProxyPacket packet = MiscellaneousNonsense.net.makeTpsReportPacket(getTpsRatio());
MiscNet.channel.sendToAll(packet);
last_tps = tps;
}
}
PacketPipeline.java 文件源码
项目:vintagetg
阅读 22
收藏 0
点赞 0
评论 0
@Override
protected void encode (ChannelHandlerContext ctx, AbstractPacket msg, List<Object> out) throws Exception
{
ByteBuf buffer = Unpooled.buffer();
Class<? extends AbstractPacket> clazz = msg.getClass();
if (!this.packets.contains(msg.getClass()))
{
throw new NullPointerException("No Packet Registered for: " + msg.getClass().getCanonicalName());
}
byte discriminator = (byte) this.packets.indexOf(clazz);
buffer.writeByte(discriminator);
msg.encodeInto(ctx, buffer);
FMLProxyPacket proxyPacket = new FMLProxyPacket(new PacketBuffer(buffer.copy()), ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
out.add(proxyPacket);
}
PacketPipeline.java 文件源码
项目:NordMod
阅读 21
收藏 0
点赞 0
评论 0
@Override
protected void encode(ChannelHandlerContext ctx, PacketAbstract msg,
List<Object> out) throws Exception {
ByteBuf buffer = Unpooled.buffer();
Class<? extends PacketAbstract> clazz = msg.getClass();
if (!packets.contains(msg.getClass())) {
throw new NullPointerException("No Packet Registered for: "
+ msg.getClass().getCanonicalName());
}
byte discriminator = (byte) this.packets.indexOf(clazz);
buffer.writeByte(discriminator);
msg.encodeInto(ctx, buffer);
FMLProxyPacket proxyPacket = new FMLProxyPacket((PacketBuffer) buffer.copy(), ctx
.channel().attr(NetworkRegistry.FML_CHANNEL).get());
out.add(proxyPacket);
}
PacketDispatcher.java 文件源码
项目:SasaLib
阅读 24
收藏 0
点赞 0
评论 0
@Override
protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception
{
ByteBuf buf = msg.payload();
int packetId = buf.readByte();
Class pktCls = packets.get(packetId);
SasaPacketBase pkt = (SasaPacketBase)pktCls.newInstance();
pkt.fromByteBuf(ctx, buf);
if(FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
{
pkt.receiveClient(getClientPlayer());
}
else if(FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
{
INetHandler localINetHandler = (INetHandler)ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
EntityPlayer ep = ((NetHandlerPlayServer)localINetHandler).playerEntity;
pkt.receiveServer(ep);
}
}
ARKMessagePipeline.java 文件源码
项目:ARKCraft-Code
阅读 20
收藏 0
点赞 0
评论 0
@Override
protected void encode(ChannelHandlerContext ctx, ARKMessage msg, List<Object> out) throws Exception
{
ByteBuf buffer = Unpooled.buffer();
Class<? extends ARKMessage> clazz = msg.getClass();
if (!packets.contains(msg.getClass()))
{
throw new NullPointerException("No Packet Registered for: " + msg.getClass().getCanonicalName());
}
byte discriminator = (byte) packets.indexOf(clazz);
buffer.writeByte(discriminator);
msg.encodeInto(ctx, buffer);
FMLProxyPacket proxyPacket = new FMLProxyPacket((PacketBuffer) buffer, ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
out.add(proxyPacket);
}
PacketChannel.java 文件源码
项目:mcplus_mods
阅读 22
收藏 0
点赞 0
评论 0
@Override
protected void encode(ChannelHandlerContext ctx, Packet msg, List<Object> out) throws Exception
{
ByteBuf buffer = Unpooled.buffer();
Class<? extends Packet> msgClass = msg.getClass();
if (!this.packets.contains(msg.getClass()))
{
throw new NullPointerException("No Packet Registered for: " + msg.getClass().getCanonicalName());
}
byte discriminator = (byte) this.packets.indexOf(msgClass);
buffer.writeByte(discriminator);
msg.encode(ctx, buffer);
FMLProxyPacket proxyPacket = new FMLProxyPacket((PacketBuffer) buffer.copy(), ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
out.add(proxyPacket);
}
ClientProxy.java 文件源码
项目:Battlegear2
阅读 20
收藏 0
点赞 0
评论 0
@Override
public void doSpecialAction(EntityPlayer entityPlayer, ItemStack itemStack) {
FMLProxyPacket p;
if(itemStack.getItem() instanceof IShield){
RayTraceResult mop = getMouseOver(4);
if(mop != null && mop.entityHit instanceof EntityLivingBase){
p = new SpecialActionPacket(entityPlayer, mop.entityHit).generatePacket();
if(mop.entityHit instanceof EntityPlayerMP){
Battlegear.packetHandler.sendPacketToPlayer(p, (EntityPlayerMP) mop.entityHit);
}
Battlegear.packetHandler.sendPacketToServer(p);
}
}
else{
p = new SpecialActionPacket(entityPlayer, null).generatePacket();
Battlegear.packetHandler.sendPacketToServer(p);
}
}
CLLPacketHandler.java 文件源码
项目:Combustible-Lemon-Launcher
阅读 15
收藏 0
点赞 0
评论 0
@Override
protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception {
ByteBuf packetPayload = msg.payload();
byte indexOfClass = packetPayload.readByte();
ByteBufInputStream bbis = new ByteBufInputStream(packetPayload.slice());
Class<? extends CLLPacket> packetClass = registeredPackets.get(indexOfClass);
if(packetClass != null){
CLLPacket packetCLL = packetClass.newInstance();
packetCLL.readDataFrom(bbis);
switch(FMLCommonHandler.instance().getEffectiveSide()){
case CLIENT:
handleClient(packetCLL);
break;
case SERVER:
packetCLL.handleServerSide(((NetHandlerPlayServer)ctx.channel().attr(NetworkRegistry.NET_HANDLER).get()).player);
break;
}
bbis.close();
out.add(packetCLL);
}
}
RpcCallCodec.java 文件源码
项目:OpenModsLib
阅读 15
收藏 0
点赞 0
评论 0
@Override
protected void encode(ChannelHandlerContext ctx, RpcCall call, List<Object> out) throws Exception {
final PacketBuffer output = new PacketBuffer(Unpooled.buffer());
{
final IRpcTarget targetWrapper = call.target;
int targetId = CommonRegistryCallbacks.mapObjectToId(targetRegistry, targetWrapper.getClass());
output.writeVarInt(targetId);
targetWrapper.writeToStream(output);
}
{
final BiMap<MethodEntry, Integer> eventIdMap = CommonRegistryCallbacks.getEntryIdMap(methodRegistry);
int methodId = eventIdMap.get(call.method);
output.writeVarInt(methodId);
MethodParamsCodec paramsCodec = call.method.paramsCodec;
paramsCodec.writeArgs(output, call.args);
}
FMLProxyPacket packet = new FMLProxyPacket(output, RpcCallDispatcher.CHANNEL_NAME);
out.add(packet);
}
NetworkEventCodec.java 文件源码
项目:OpenModsLib
阅读 15
收藏 0
点赞 0
评论 0
@Override
protected void encode(ChannelHandlerContext ctx, NetworkEvent msg, List<Object> out) throws IOException {
final Channel channel = ctx.channel();
final Side side = channel.attr(NetworkRegistry.CHANNEL_SOURCE).get();
final NetworkEventEntry entry = CommonRegistryCallbacks.getObjectToEntryMap(registry).get(msg.getClass());
Preconditions.checkState(entry != null, "Can't find registration for class %s", msg.getClass());
final int id = CommonRegistryCallbacks.getEntryIdMap(registry).get(entry);
final EventDirection validator = entry.getDirection();
Preconditions.checkState(validator != null && validator.validateSend(side),
"Invalid direction: sending packet %s on side %s", msg.getClass(), side);
final PacketBuffer buf = new PacketBuffer(Unpooled.buffer());
buf.writeVarInt(id);
msg.writeToStream(buf);
final FMLProxyPacket packet = new FMLProxyPacket(buf, NetworkEventDispatcher.CHANNEL_NAME);
packet.setDispatcher(msg.dispatcher);
out.add(packet);
}
DescPacketHandler.java 文件源码
项目:pnc-repressurized
阅读 15
收藏 0
点赞 0
评论 0
@Override
protected void channelRead0(ChannelHandlerContext ctx, FMLProxyPacket msg) throws Exception {
final PacketDescription packet = new PacketDescription();
packet.fromBytes(msg.payload());
PneumaticCraftRepressurized.proxy.addScheduledTask(new Runnable() {
@Override
public void run() {
packet.handleClientSide(packet, PneumaticCraftRepressurized.proxy.getPlayer());
}
}, false);
}
FMLEventChannel.java 文件源码
项目:CustomWorldGen
阅读 16
收藏 0
点赞 0
评论 0
@Override
FMLNetworkEvent.CustomPacketEvent<?> make(FMLProxyPacket msg)
{
FMLNetworkEvent.CustomPacketEvent<?> event = null;
if (msg.handler() instanceof NetHandlerPlayServer)
{
NetHandlerPlayServer server = (NetHandlerPlayServer) msg.handler();
event = new FMLNetworkEvent.ServerCustomPacketEvent(server.getNetworkManager(), msg);
}
return event;
}
FMLEventChannel.java 文件源码
项目:CustomWorldGen
阅读 30
收藏 0
点赞 0
评论 0
void fireRead(FMLProxyPacket msg, ChannelHandlerContext ctx)
{
FMLNetworkEvent.CustomPacketEvent<?> event = factory.make(msg);
if (event != null)
{
this.eventBus.post(event);
if (event.getReply() != null)
{
ctx.channel().attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.REPLY);
ctx.writeAndFlush(event.getReply()).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
}
}
}
FMLEventChannel.java 文件源码
项目:CustomWorldGen
阅读 16
收藏 0
点赞 0
评论 0
/**
* Send to a specific player
*
* @param pkt
* @param player
*/
public void sendTo(FMLProxyPacket pkt, EntityPlayerMP player)
{
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER);
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player);
channels.get(Side.SERVER).writeAndFlush(pkt).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
}
FMLEventChannel.java 文件源码
项目:CustomWorldGen
阅读 24
收藏 0
点赞 0
评论 0
/**
* Send to all around a point
* @param pkt
* @param point
*/
public void sendToAllAround(FMLProxyPacket pkt, NetworkRegistry.TargetPoint point)
{
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT);
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(point);
channels.get(Side.SERVER).writeAndFlush(pkt).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
}
FMLEventChannel.java 文件源码
项目:CustomWorldGen
阅读 19
收藏 0
点赞 0
评论 0
/**
* Send to all in a dimension
* @param pkt
* @param dimensionId
*/
public void sendToDimension(FMLProxyPacket pkt, int dimensionId)
{
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.DIMENSION);
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(dimensionId);
channels.get(Side.SERVER).writeAndFlush(pkt).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
}
NetworkDispatcher.java 文件源码
项目:CustomWorldGen
阅读 30
收藏 0
点赞 0
评论 0
private MultiPartCustomPayload(PacketBuffer preamble) throws IOException
{
channel = preamble.readStringFromBuffer(20);
part_count = preamble.readUnsignedByte();
int length = preamble.readInt();
if (length <= 0 || length >= FMLProxyPacket.MAX_LENGTH)
{
throw new IOException("The received FML MultiPart packet outside of valid length bounds, Max: " + FMLProxyPacket.MAX_LENGTH + ", Received: " + length);
}
data = new byte[length];
data_buf = new PacketBuffer(Unpooled.wrappedBuffer(data));
}
HandshakeInjector.java 文件源码
项目:CustomWorldGen
阅读 21
收藏 0
点赞 0
评论 0
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception
{
if (msg instanceof FMLProxyPacket)
{
this.dispatcher.sendProxy((FMLProxyPacket) msg);
}
}
FMLOutboundHandler.java 文件源码
项目:CustomWorldGen
阅读 26
收藏 0
点赞 0
评论 0
@Override
public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet)
{
EntityPlayerMP player = (EntityPlayerMP) args;
NetworkDispatcher dispatcher = (player == null || player instanceof FakePlayer) ? null : player.connection.netManager.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
return dispatcher == null ? ImmutableList.<NetworkDispatcher>of() : ImmutableList.of(dispatcher);
}