@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()+" "); }
/** * Registers an {@link AbstractMessage} to the appropriate side(s) */ private static final <T extends AbstractMessage<T> & IMessageHandler<T, IMessage>> void registerMessage(Class<T> clazz) { // We can tell by the message class which side to register it on by using #isAssignableFrom (google it) // Also, one can see the convenience of using a static counter 'packetId' to keep // track of the current index, rather than hard-coding them all, plus it's one less // parameter to pass. if (AbstractMessage.AbstractClientMessage.class.isAssignableFrom(clazz)) { PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.CLIENT); } else if (AbstractMessage.AbstractServerMessage.class.isAssignableFrom(clazz)) { PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER); } else { // hopefully you didn't forget to extend the right class, or you will get registered on both sides PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId, Side.CLIENT); PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER); } }
/** * Registers an {@link AbstractMessage} to the appropriate side(s) */ public static final <T extends AbstractMessage<T> & IMessageHandler<T, IMessage>> void registerMessage(Class<T> clazz) { // We can tell by the message class which side to register it on by using #isAssignableFrom (google it) // Also, one can see the convenience of using a static counter 'packetId' to keep // track of the current index, rather than hard-coding them all, plus it's one less // parameter to pass. if (AbstractMessage.AbstractClientMessage.class.isAssignableFrom(clazz)) { PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.CLIENT); } else if (AbstractMessage.AbstractServerMessage.class.isAssignableFrom(clazz)) { PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER); } else { // hopefully you didn't forget to extend the right class, or you will get registered on both sides PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId, Side.CLIENT); PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER); } }
public static <REQ extends IMessage, REPLY extends IMessage> void registerPacket(SimpleNetworkWrapper network, Class<REQ> requestMessageType, Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Side side) { String packetPackageName = requestMessageType.getPackage().getName(); Iterator<String> iterator = packetByteDiscriminators.keySet().iterator(); byte discriminator = -1; while(iterator.hasNext()) { String pack = iterator.next(); if(pack.contains(packetPackageName)) { packetByteDiscriminators.get(packetPackageName); } } if(discriminator == -1) { packetByteDiscriminators.put(packetPackageName, (byte) 0); } network.registerMessage(messageHandler, requestMessageType, packetByteDiscriminators.get(packetPackageName), side); }
public static HandlersInfo getHandlers(Class message) { Class[] handlerCandidates = message.getDeclaredClasses(); Class clientHandler = null, serverHandler = null; for (int x = 0; x < handlerCandidates.length; x++) { if (IMessageHandler.class.isAssignableFrom(handlerCandidates[x])) { if (ClientHandler.class.isAssignableFrom(handlerCandidates[x])) { clientHandler = handlerCandidates[x]; } if (ServerHandler.class.isAssignableFrom(handlerCandidates[x])) { serverHandler = handlerCandidates[x]; } if (serverHandler != null && clientHandler != null) break; } } HandlersInfo info = new HandlersInfo(); info.client = clientHandler; info.server = serverHandler; return info; }
public static <T extends IMessage> boolean checkThreadAndEnqueue(final T message, final IMessageHandler<T, IMessage> handler, final MessageContext ctx, IThreadListener listener) { if (!listener.isCallingFromMinecraftThread()) { listener.addScheduledTask(() -> handler.onMessage(message, ctx)); return true; } return false; }
@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()+" "); }
public <REQ extends IMessage, REPLY extends IMessage> void registerMessage(Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType, int discriminator, Side side, boolean useUdp) { try { registerMessage(messageHandler.newInstance(), requestMessageType, discriminator, side, useUdp); } catch (Exception e) { } }
public <REQ extends IMessage, REPLY extends IMessage> void registerMessage(IMessageHandler<? super REQ, ? extends REPLY> messageHandler, Class<REQ> requestMessageType, int discriminator, Side side, boolean useUdp) { super.registerMessage(messageHandler, requestMessageType, discriminator, side); if(useUdp) { handlerList.put(requestMessageType, (IMessageHandler<IMessage, IMessage>) messageHandler); messages[discriminator] = requestMessageType; discriminators.put(requestMessageType, (byte)discriminator); } }
public <REQ extends IMessage, REPLY extends IMessage> void addNetworkPacket( Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType, int discriminator, Side side) { if (netChannel == null) netChannel = NetworkRegistry.INSTANCE.newSimpleChannel(modId); netChannel.registerMessage(messageHandler, requestMessageType, discriminator, side); }
private static <T extends MessageBase<T> & IMessageHandler<T, IMessage>>void registerMessage(Class<T> clazz) { if(ClientMessageBase.class.isAssignableFrom(clazz)) { CHANNEL.registerMessage(clazz, clazz, ID++, Side.CLIENT); return; } if(ServerMessageBase.class.isAssignableFrom(clazz)) { CHANNEL.registerMessage(clazz, clazz, ID++, Side.SERVER); return; } CHANNEL.registerMessage(clazz, clazz, ID, Side.CLIENT); CHANNEL.registerMessage(clazz, clazz, ID++, Side.SERVER); }
/** Helper for registering server -> client packets. */ private static <REQ extends IMessage, REPLY extends IMessage> void cPacket(Class<? extends IMessageHandler<REQ, REPLY>> handler, Class<REQ> packet) { NETWORK.registerMessage(handler, packet, packetID++, Side.CLIENT); }
/** Helper for registering client -> server packets. */ private static <REQ extends IMessage, REPLY extends IMessage> void sPacket(Class<? extends IMessageHandler<REQ, REPLY>> handler, Class<REQ> packet) { NETWORK.registerMessage(handler, packet, packetID++, Side.SERVER); }
private static <T extends AbstractMessage<T> & IMessageHandler<T, IMessage>> void registerMessage (Class<T> clazz) { if (AbstractMessage.AbstractClientMessage.class.isAssignableFrom(clazz)) PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.CLIENT); else if (AbstractMessage.AbstractServerMessage.class.isAssignableFrom(clazz)) PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER); else { PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId, Side.CLIENT); PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER); } }
private static final <T extends AbstractMessage<T> & IMessageHandler<T, IMessage>> void registerMessage (Class<T> clazz) { if (AbstractMessage.AbstractClientMessage.class.isAssignableFrom(clazz)) PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.CLIENT); else if (AbstractMessage.AbstractServerMessage.class.isAssignableFrom(clazz)) PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER); else { PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId, Side.CLIENT); PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER); } }
public static final <T extends AbstractMessage<T> & IMessageHandler<T, IMessage>> void registerMessage(Class<T> registee){ if(AbstractMessage.AbstractClientMessage.class.isAssignableFrom(registee)){ MessageDispatcher.INSTANCE.registerMessage(registee, registee, packetid++, Side.CLIENT); }else if (AbstractMessage.AbstractServerMessage.class.isAssignableFrom(registee)){ MessageDispatcher.INSTANCE.registerMessage(registee,registee,packetid++,Side.SERVER); }else{ MessageDispatcher.INSTANCE.registerMessage(registee,registee,packetid++,Side.CLIENT); MessageDispatcher.INSTANCE.registerMessage(registee,registee,packetid++,Side.SERVER); } }
/** * Registers an {@link AbstractMessage} to the appropriate side(s) */ private static final <T extends AbstractMessage<T> & IMessageHandler<T, IMessage>> void registerMessage(Class<T> clazz) { // We can tell by the message class which side to register it on by using #isAssignableFrom (google it) if (AbstractMessage.AbstractClientMessage.class.isAssignableFrom(clazz)) PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.CLIENT); else if (AbstractMessage.AbstractServerMessage.class.isAssignableFrom(clazz)) PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER); else { PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId, Side.CLIENT); PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER); } }
/** * Registers an {@link AbstractMessage} to the appropriate side(s) */ private static final <T extends AbstractMessage<T> & IMessageHandler<T, IMessage>> void registerMessage(Class<T> clazz) { if (AbstractMessage.AbstractClientMessage.class.isAssignableFrom(clazz)) { PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.CLIENT); } else if (AbstractMessage.AbstractServerMessage.class.isAssignableFrom(clazz)) { PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER); } else { PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId, Side.CLIENT); PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER); } }
public static <REQ extends IMessage, REPLY extends IMessage> void registerMessage(Class<? extends IMessageHandler<REQ, REPLY>> handler, Class<REQ> message, Side side) { RezolvePacketHandler.INSTANCE.registerMessage(handler, message, nextPacketID++, side); }
private static <REQ extends IMessage, REPLY extends IMessage> void registerMessage( Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType, Side side) { instance.registerMessage(messageHandler, requestMessageType, nextID++, side); }
private static <H extends IMessageHandler<M, IMessage>, M extends IMessage> void register(Class<H> handler, Class<M> message, Side side) { NETWORK.registerMessage(handler, message, id++, side); }
private static <REQ extends IMessage, REPLY extends IMessage> void register(Class<REQ> message, Class<? extends IMessageHandler<REQ, REPLY>> handler, Side side) { DISPATCHER.registerMessage(handler, message, PACKET_ID++, side); }
private static <REQ extends IMessage, REPLY extends IMessage> void registerMessage(Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType, Side receivingSide) { AquaRegia.network.registerMessage(messageHandler, requestMessageType, messageID++, receivingSide); }
/** * Register given message with given message handler on a given side */ public static <REQ extends IMessage, REPLY extends IMessage> void register(Class<REQ> message, Class<? extends IMessageHandler<REQ, REPLY>> handler, Side side) { DISPATCHER.registerMessage(handler, message, PACKET_ID++, side); }
private static <REQ extends IMessage, REPLY extends IMessage> void register(Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType, Side side, int id) { CoreInit.log.info("Registering Message {} with id {}", messageHandler.getName(), id); INSTANCE.registerMessage(messageHandler, requestMessageType, id, side); }
private static <T extends IMessage & IMessageHandler<T, IMessage>> void registerMessage(Class<T> clazz, Side side) { network_wrapper.registerMessage(clazz, clazz, next(), side); AlchemyInitHook.push_event(clazz); }
public static <T extends IMessage & IMessageHandler<T, IMessage>> void registerMessage(INetworkMessage.Client<T> handle) { network_wrapper.registerMessage(Tool.instance(handle.getClientMessageClass()), handle.getClientMessageClass(), next(), Side.CLIENT); }
public static <T extends IMessage & IMessageHandler<T, IMessage>> void registerMessage(INetworkMessage.Server<T> handle) { network_wrapper.registerMessage(Tool.instance(handle.getServerMessageClass()), handle.getServerMessageClass(), next(), Side.SERVER); }
public static <T extends IMessage & IMessageHandler<T, IMessage>> void init() { AlchemyModLoader.checkInvokePermissions(); AlchemyModLoader.checkState(); for (Entry<Class<?>, Side> entry : message_mapping.entrySet()) registerMessage((Class<T>) entry.getKey(), entry.getValue()); }
private static <T extends BaseMessage<T> & IMessageHandler<T, IMessage>> void registerMessage(Class<T> message, Side... sides) { for (Side side : sides) { NETWORK_WRAPPER.registerMessage(message, message, messageID++, side); } }
private static <REQ extends IMessage, REPLY extends IMessage> void register(Class<? extends IMessageHandler<REQ, REPLY>> handler, Class<REQ> packet, Side side){ network.registerMessage(handler, packet, discriminator, side); discriminator++; }
private static <REQ extends IMessage, REPLY extends IMessage> void registerMessage(Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType, Side side) { INSTANCE.registerMessage(messageHandler, requestMessageType, messageID++, side); }
private static <REQ extends IMessage, REPLY extends IMessage> void registerMessageHandler( Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType, int discriminator, Side side) { NETWORK_WRAPPER.registerMessage(messageHandler, requestMessageType, discriminator, side); }
public static <REQ extends IMessage> void registerMessageHandler(IMessageHandler<? super REQ, ? extends IMessage> messageHandler, Class<REQ> requestMessageType, Side side) { CHANNEL.registerMessage(messageHandler, requestMessageType, discriminationByte++, side); }
public static <REQ extends IMessage, REPLY extends IMessage> void registerMessageHandler( Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType, Side side) { CHANNEL.registerMessage(messageHandler, requestMessageType, discriminationByte++, side); }