@SubscribeEvent public void clientConnectedtoServer(FMLNetworkEvent.ServerConnectionFromClientEvent event) { if (!CreeperHost.instance.active) return; MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance(); if (server == null || server.isSinglePlayer() || discoverMode != Discoverability.PUBLIC) return; INetHandlerPlayServer handler = event.handler; if (handler instanceof NetHandlerPlayServer) { EntityPlayerMP entity = ((NetHandlerPlayServer) handler).playerEntity; playersJoined.add(entity.getUniqueID()); } }
@SubscribeEvent public void connectionOpened( FMLNetworkEvent.ClientConnectedToServerEvent event ) { if( !event.isLocal ) { SocketAddress socketAddress = event.manager.getSocketAddress(); if( socketAddress != null && socketAddress instanceof InetSocketAddress ) { InetSocketAddress internet = (InetSocketAddress)socketAddress; String hostString = null; try { Method getHostString = InetSocketAddress.class.getDeclaredMethod( "getHostString", new Class[]{} ); getHostString.setAccessible( true ); hostString = getHostString.invoke( internet ).toString(); } catch( Exception e ) { hostString = internet.getHostName(); } QCraft.setCurrentServerAddress( hostString + ":" + internet.getPort() ); return; } } QCraft.setCurrentServerAddress( null ); }
@SideOnly(Side.CLIENT) @SubscribeEvent public void onReceiveClient(FMLNetworkEvent.ClientCustomPacketEvent evt) { World world = Minecraft.getMinecraft().theWorld; EntityPlayer entityPlayer = Minecraft.getMinecraft().thePlayer; try { ByteBufInputStream in = new ByteBufInputStream(evt.packet.payload()); // Read the container PlayBlockPayload container = new PlayBlockPayload(); container.read(in); // Figure out what we are containing switch (container.getType()) { case TILE_ENTITY: handleTilePayload(world, entityPlayer, in); break; case TILE_ENTITY_NBT: handleNetworkedNBT(world, evt.packet.payload()); } } catch (IOException e) { PlayBlock.log(Level.WARN, "Failed to read packet data from " + entityPlayer.getDisplayName(), e); } }
@SubscribeEvent public void connectionReceived(FMLNetworkEvent.ServerConnectionFromClientEvent event) { if (!event.isLocal && Pay2Spawn.getConfig().forceP2S) { final String username = ((NetHandlerPlayServer) event.handler).playerEntity.getCommandSenderName(); new Timer().schedule(new TimerTask() { @Override public void run() { if (!StatusMessage.doesPlayerHaveValidConfig(username)) MinecraftServer.getServer().getConfigurationManager().getPlayerForUsername(username).playerNetServerHandler.kickPlayerFromServer("Pay2Spawn is required on this server.\nIt needs to be configured properly."); } }, 5 * 1000); } }
@SubscribeEvent @SideOnly(Side.CLIENT) public void onPacketData(FMLNetworkEvent.ClientCustomPacketEvent event) { FMLProxyPacket pkt = event.packet; onFMLProxyPacketData(event.manager, pkt, Minecraft.getMinecraft().thePlayer); }
@SubscribeEvent public void onPacketData(FMLNetworkEvent.ServerCustomPacketEvent event) { FMLProxyPacket pkt = event.packet; onFMLProxyPacketData(event.manager, pkt, ((NetHandlerPlayServer)event.handler).playerEntity); }
@Override public void fireNetRegistrationEvent(EventBus bus, NetworkManager manager, Set<String> channelSet, String channel, Side side) { if (side == Side.CLIENT) { waitForPlayClient(); bus.post(new FMLNetworkEvent.CustomPacketRegistrationEvent<NetHandlerPlayClient>(manager, channelSet, channel, side, NetHandlerPlayClient.class)); } else { bus.post(new FMLNetworkEvent.CustomPacketRegistrationEvent<NetHandlerPlayServer>(manager, channelSet, channel, side, NetHandlerPlayServer.class)); } }
private void completeClientSideConnection(ConnectionType type) { this.connectionType = type; FMLLog.info("[%s] Client side %s connection established", Thread.currentThread().getName(), this.connectionType.name().toLowerCase(Locale.ENGLISH)); this.state = ConnectionState.CONNECTED; FMLCommonHandler.instance().bus().post(new FMLNetworkEvent.ClientConnectedToServerEvent(manager, this.connectionType.name())); }
private void completeServerSideConnection(ConnectionType type) { this.connectionType = type; FMLLog.info("[%s] Server side %s connection established", Thread.currentThread().getName(), this.connectionType.name().toLowerCase(Locale.ENGLISH)); this.state = ConnectionState.CONNECTED; FMLCommonHandler.instance().bus().post(new FMLNetworkEvent.ServerConnectionFromClientEvent(manager)); scm.func_72355_a(manager, player, serverHandler); }
@Override public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { if (side == Side.CLIENT) { FMLCommonHandler.instance().bus().post(new FMLNetworkEvent.ClientDisconnectionFromServerEvent(manager)); } else { FMLCommonHandler.instance().bus().post(new FMLNetworkEvent.ServerDisconnectionFromClientEvent(manager)); } cleanAttributes(ctx); ctx.disconnect(promise); }
@Override public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { if (side == Side.CLIENT) { FMLCommonHandler.instance().bus().post(new FMLNetworkEvent.ClientDisconnectionFromServerEvent(manager)); } else { FMLCommonHandler.instance().bus().post(new FMLNetworkEvent.ServerDisconnectionFromClientEvent(manager)); } cleanAttributes(ctx); ctx.close(promise); }
private void completeServerSideConnection(ConnectionType type) { this.connectionType = type; FMLLog.info("[%s] Server side %s connection established", Thread.currentThread().getName(), this.connectionType.name().toLowerCase(Locale.ENGLISH)); this.state = ConnectionState.CONNECTED; FMLCommonHandler.instance().bus().post(new FMLNetworkEvent.ServerConnectionFromClientEvent(manager)); scm.initializeConnectionToPlayer(manager, player, serverHandler); }
@SubscribeEvent public void onClientPacket( FMLNetworkEvent.ClientCustomPacketEvent event ) { try { QCraftPacket packet = new QCraftPacket(); packet.fromBytes( event.packet.payload() ); QCraft.handleClientPacket( packet ); } catch( Exception e ) { // Something failed, ignore it e.printStackTrace(); } }
@SubscribeEvent public void onServerPacket( FMLNetworkEvent.ServerCustomPacketEvent event ) { try { QCraftPacket packet = new QCraftPacket(); packet.fromBytes( event.packet.payload() ); QCraft.handleServerPacket( packet, ((NetHandlerPlayServer)event.handler).playerEntity ); } catch( Exception e ) { // Something failed, ignore it e.printStackTrace(); } }
@SubscribeEvent public void onReceiveServer(FMLNetworkEvent.ServerCustomPacketEvent evt) { EntityPlayer entityPlayer = ((NetHandlerPlayServer) evt.handler).playerEntity; World world; // Get the world if (entityPlayer != null) { world = entityPlayer.worldObj; } else { PlayBlock.log(Level.WARN, "Received an update packet from an invalid player!"); return; } try { ByteBufInputStream in = new ByteBufInputStream(evt.packet.payload()); // Read the container PlayBlockPayload container = new PlayBlockPayload(); container.read(in); // Figure out what we are containing switch (container.getType()) { case TILE_ENTITY: handleTilePayload(world, entityPlayer, in); break; case TILE_ENTITY_NBT: handleNetworkedNBT(world, evt.packet.payload()); } } catch (IOException e) { PlayBlock.log(Level.WARN, "Failed to read packet data from " + entityPlayer.getDisplayName(), e); } }
@SubscribeEvent public void onClientConnectedToServerEvent(FMLNetworkEvent.ClientConnectedToServerEvent event) { if (event.isLocal) { final CommonAddonManager addonManager = (CommonAddonManager) game.getAddonManager(); final CommonFileSystem fileSystem = (CommonFileSystem) game.getFileSystem(); final CommonMessagePipeline messagePipeline = (CommonMessagePipeline) game.getPipeline(); // Load addons addonManager.loadAddons(CommonFileSystem.ADDONS_PATH); // Initialize addons addonManager.initialize(); // Register our language map into Forge ((CommonLanguageManager) game.getLanguages()).register(); // Refresh for addon additions in initialize Minecraft.getMinecraft().refreshResources(); // Lock filesystem fileSystem.lockFileSystem(); // Lock message pipeline messagePipeline.lockPipeline(); // Enable addons addonManager.enable(); } }
@SubscribeEvent public void clientConnect(FMLNetworkEvent.ClientConnectedToServerEvent event) { proxy.getClientChannel().attr(FML_MESSAGETARGET).set(TOSERVER); String player = getMinecraft().thePlayer.func_146103_bH().getName(); proxy.getClientChannel().writeOutbound(new PlayerDataPacket(player)); proxy.getClientChannel().writeOutbound(new ClientDataPacket(player, ClientDataPacket.Messages.REQUEST)); }
@SubscribeEvent public void disconnect(FMLNetworkEvent.ClientDisconnectionFromServerEvent event) { Pay2Spawn.reloadDB(); StatusMessage.resetServerStatus(); new Timer().schedule(new TimerTask() { @Override public void run() { if (!StatusMessage.doesServerHaveMod()) Helper.msg(EnumChatFormatting.RED + NAME + " isn't on the server. No rewards will spawn!"); } }, 5 * 1000); }