@EventHandler public void handleChannel(PluginMessageEvent pluginMessageEvent) { if(!(pluginMessageEvent.getReceiver() instanceof ProxiedPlayer)) return; if(pluginMessageEvent.getTag().equalsIgnoreCase("CloudNet")) { ByteArrayDataInput byteArrayDataInput = ByteStreams.newDataInput(pluginMessageEvent.getData()); switch (byteArrayDataInput.readUTF().toLowerCase()) { case "connect": List<String> servers = CloudProxy.getInstance().getServers(byteArrayDataInput.readUTF()); if(servers.size() == 0) return; ((ProxiedPlayer)pluginMessageEvent.getReceiver()).connect(ProxyServer.getInstance().getServerInfo(servers.get(NetworkUtils.RANDOM.nextInt(servers.size())))); break; case "fallback": ((ProxiedPlayer)pluginMessageEvent.getReceiver()).connect(ProxyServer.getInstance() .getServerInfo(CloudProxy.getInstance() .fallback(((ProxiedPlayer)pluginMessageEvent.getReceiver())))); break; case "command": ProxyServer.getInstance().getPluginManager().dispatchCommand(((ProxiedPlayer)pluginMessageEvent.getReceiver()), byteArrayDataInput.readUTF()); break; } } }
public void onPluginMessageReceived(String channel, Player player, byte[] message) { if (!channel.equals("BungeeCord")) { return; } ByteArrayDataInput in = ByteStreams.newDataInput(message); String subchannel = in.readUTF(); if (subchannel.equals("SkyWarsReloadedRequest")) { short len = in.readShort(); byte[] msgbytes = new byte[len]; in.readFully(msgbytes); Game game = gc.getGame(1); if (game != null) { BungeeUtil.sendSignUpdateRequest(game); } else { System.out.println("Game " + game + " couldn't be found, please fix your setup."); } } }
@Override public void onPluginMessageReceived(String channel, Player player, byte[] message) { if (!channel.equals("BungeeCord")) { return; } final ByteArrayDataInput in = ByteStreams.newDataInput(message); final String type = in.readUTF(); if (type.equals("ServerIP")) { final String serverName = in.readUTF(); final String ip = in.readUTF(); final short port = in.readShort(); this.plugin.getServer().getScheduler().runTaskAsynchronously(this.plugin, () -> { final String data = BungeeCordProvider.this.receiveResultFromServer(serverName, ip, port); BungeeCordProvider.this.parseData(serverName, data); }); } }
@EventHandler public void onPluginMessage(PluginMessageEvent e) { if (!e.getTag().equals(CHANNEL)) { return; } e.setCancelled(true); if (e.getSender() instanceof ProxiedPlayer) { return; } ByteArrayDataInput in = ByteStreams.newDataInput(e.getData()); String msg = in.readUTF(); onMessage(msg, u -> { // Forward to other servers this.plugin.getScheduler().doAsync(() -> sendMessage(u)); }); }
/** * Reads a constant value at the given index, which must be one of CONSTANT_String_info, * CONSTANT_Integer_info, CONSTANT_Float_info, CONSTANT_Long_info, or CONSTANT_Double_info. */ Const.Value constant(int index) { ByteArrayDataInput reader = byteReader.seek(constantPool[index - 1]); byte tag = reader.readByte(); switch (tag) { case CONSTANT_LONG: return new Const.LongValue(reader.readLong()); case CONSTANT_FLOAT: return new Const.FloatValue(reader.readFloat()); case CONSTANT_DOUBLE: return new Const.DoubleValue(reader.readDouble()); case CONSTANT_INTEGER: return new Const.IntValue(reader.readInt()); case CONSTANT_STRING: return new Const.StringValue(utf8(reader.readUnsignedShort())); default: throw new AssertionError(String.format("bad tag: %x", tag)); } }
@Override public void onPluginMessageReceived(String channel, Player p, byte[] message) { if (channel.equals(incomingChannel)) { ByteArrayDataInput in = ByteStreams.newDataInput(message); String subchannel = in.readUTF(); if (subchannel.equals("AutoLogin")) { Player player = Bukkit.getPlayer(in.readUTF()); if (player != null) { if (!xauth.getPlayerManager().getPlayer(player.getName()).isAuthenticated()) { xauth.getPlayerManager().doLogin(xauth.getPlayerManager().getPlayer(player)); if (!autoLoginMessage.isEmpty()) player.sendMessage(autoLoginMessage); } } } } }
@Override public void onPluginMessageReceived(String channel, Player p, byte[] message) { if (channel.equals(incomingChannel)) { ByteArrayDataInput in = ByteStreams.newDataInput(message); String subchannel = in.readUTF(); if (subchannel.equals("AutoLogin")) { Player player = Bukkit.getPlayer(in.readUTF()); if (player != null) { if (!fr.xephi.authme.api.NewAPI.getInstance().isAuthenticated(player)) { fr.xephi.authme.api.NewAPI.getInstance().forceLogin(player); if (!autoLoginMessage.isEmpty()) player.sendMessage(autoLoginMessage); } } } } }
@Override public Tuple getNext() throws IOException { try { if (reader.nextKeyValue()) { Key key = (Key) reader.getCurrentKey(); org.apache.accumulo.core.data.Value value = (org.apache.accumulo.core.data.Value) reader.getCurrentValue(); ByteArrayDataInput input = ByteStreams.newDataInput(key.getRow().getBytes()); RyaStatement ryaStatement = ryaContext.deserializeTriple(layout, new TripleRow(key.getRow().getBytes(), key.getColumnFamily().getBytes(), key.getColumnQualifier().getBytes())); Tuple tuple = TupleFactory.getInstance().newTuple(7); tuple.set(0, ryaStatement.getSubject().getData()); tuple.set(1, ryaStatement.getPredicate().getData()); tuple.set(2, ryaStatement.getObject().getData()); tuple.set(3, (ryaStatement.getContext() != null) ? (ryaStatement.getContext().getData()) : (null)); tuple.set(4, ryaStatement.getSubject().getDataType()); tuple.set(5, ryaStatement.getPredicate().getDataType()); tuple.set(6, ryaStatement.getObject().getDataType()); return tuple; } } catch (Exception e) { throw new IOException(e); } return null; }
@Test public void testSerialization() throws Exception { Range<Token> full = new Range<>(tok(-1), tok(-1)); // populate and validate the tree mt.maxsize(256); mt.init(); for (TreeRange range : mt.invalids()) range.addAll(new HIterator(range.right)); byte[] initialhash = mt.hash(full); DataOutputBuffer out = new DataOutputBuffer(); MerkleTree.serializer.serialize(mt, out, MessagingService.current_version); byte[] serialized = out.toByteArray(); ByteArrayDataInput in = ByteStreams.newDataInput(serialized); MerkleTree restored = MerkleTree.serializer.deserialize(in, MessagingService.current_version); assertHashEquals(initialhash, restored.hash(full)); }
@Test public void testSerialization() throws Exception { Range<Token> full = new Range<>(tok(-1), tok(-1)); // populate and validate the tree mt.maxsize(256); mt.init(); for (TreeRange range : mt.invalids()) range.addAll(new HIterator(range.right)); byte[] initialhash = mt.hash(full); ByteArrayDataOutput out = ByteStreams.newDataOutput(); MerkleTree.serializer.serialize(mt, out, MessagingService.current_version); byte[] serialized = out.toByteArray(); ByteArrayDataInput in = ByteStreams.newDataInput(serialized); MerkleTree restored = MerkleTree.serializer.deserialize(in, MessagingService.current_version); assertHashEquals(initialhash, restored.hash(full)); }
/** * Reads a permission request. */ public static PermissionRequest readPermissionRequest( Player player, byte[] data) { ByteArrayDataInput input = ByteStreams.newDataInput(data); String requestReason = input.readUTF(); Map<String, String> requestedPerms = new HashMap<>(); int numRequests = input.readInt(); for (int i = 0; i < numRequests; i++) { String key = input.readUTF(); String value = input.readUTF(); requestedPerms.put(key, value); } List<ProtectionRange> rangeRequests = new ArrayList<>(); int numRangeRequests = input.readInt(); for (int i = 0; i < numRangeRequests; i++) { rangeRequests.add(readProtectionRange(input)); } return new PermissionRequest(player, requestReason, requestedPerms, rangeRequests); }
/** * Calls when the plugin received a message from a bungee-server */ @Override public void onPluginMessageReceived(String channel, Player player, byte[] message) { if(!channel.equals(Main.BUNGEE_CHANNEL_NAME)) { return; } ByteArrayDataInput in = ByteStreams.newDataInput(message); String subchannel = in.readUTF(); if (subchannel.equals(Subchannel.UPDATE_RECEIVE)) { String game = in.readUTF(); String serverName = in.readUTF(); String firstLine = in.readUTF(); String secondLine = in.readUTF(); String thirdLine = in.readUTF(); String fourthLine = in.readUTF(); SignUpdateInformation info = new SignUpdateInformation(firstLine, secondLine, thirdLine, fourthLine); this.signManager.updateJoinSign(game, serverName, info); } }
@Override public void recievePacket(ByteArrayDataInput data) { posX = data.readDouble(); posY = data.readDouble(); posZ = data.readDouble(); motionX = data.readDouble(); motionY = data.readDouble(); motionZ = data.readDouble(); rotationPitch = (float)data.readDouble(); rotationYaw = (float)data.readDouble(); prevRotationPitch = (float)data.readDouble(); prevRotationYaw = (float)data.readDouble(); }
@Override public FMLPacket consumePacket(byte[] data) { ByteArrayDataInput dat = ByteStreams.newDataInput(data); int versionListSize = dat.readInt(); modVersions = Maps.newHashMapWithExpectedSize(versionListSize); for (int i = 0; i < versionListSize; i++) { String modName = dat.readUTF(); String modVersion = dat.readUTF(); modVersions.put(modName, modVersion); } int missingModSize = dat.readInt(); missingMods = Lists.newArrayListWithExpectedSize(missingModSize); for (int i = 0; i < missingModSize; i++) { missingMods.add(dat.readUTF()); } return this; }
@Override public void handleNetworkMessage(NetHandler source, boolean isClient, ByteArrayDataInput data) { if (isClient) return; int x = data.readInt(); int y = data.readInt(); int z = data.readInt(); String sound = data.readUTF(); World world = MiscPeripherals.proxy.getClientWorld(); for (int i = 0; i < 50; i++) { MiscPeripherals.proxy.spawnSmoke(x + 0.5D + world.rand.nextFloat() - world.rand.nextFloat(), y + world.rand.nextFloat() - world.rand.nextFloat(), z + 0.5D + world.rand.nextFloat() - world.rand.nextFloat(), 0.0D, 0.0D, 0.0D); } world.playSoundEffect(x + 0.5D, y + 0.5D, z + 0.5D, sound, 0.8F, world.rand.nextFloat() * 0.2F + 0.9F); }
@Override public void read(ByteArrayDataInput in) { windowId = in.readInt(); int marketCount = in.readInt(); for (int i = 0; i < marketCount; i++) { int itemCount = in.readInt(); List<ItemStack> cart = new ArrayList<ItemStack>(); carts.add(cart); for (int j = 0; j < itemCount; j++) { int itemId = in.readInt(); int stackSize = in.readInt(); int damage = in.readInt(); Item item = (Item)Item.itemRegistry.getObjectById(itemId); cart.add(new ItemStack(item, stackSize, damage)); } } }
@Override public void decodeInto(ChannelHandlerContext ctx, ByteBuf source, PacketBase msg) { ByteArrayDataInput input = ByteStreams.newDataInput(source.array()); // the discriminator input.skipBytes(1); try { msg.decode(input); } catch (IOException e) { Throwables.propagate(e); } if (FMLCommonHandler.instance().getEffectiveSide().isClient()) { actionClient(msg); } else { actionServer(ctx, msg); } }
@Override public FMLPacket consumePacket(byte[] data) { sentModList = Lists.newArrayList(); ByteArrayDataInput in = ByteStreams.newDataInput(data); int listSize = in.readInt(); for (int i = 0; i < listSize; i++) { sentModList.add(in.readUTF()); } try { compatibilityLevel = in.readByte(); } catch (IllegalStateException e) { FMLLog.fine("No compatibility byte found - the server is too old"); } return this; }
@Test public void testAddEmptyKey() throws Exception { IPartitioner p = new RandomPartitioner(); IndexSummaryBuilder builder = new IndexSummaryBuilder(1); builder.maybeAddEntry(p.decorateKey(ByteBufferUtil.EMPTY_BYTE_BUFFER), 0); IndexSummary summary = builder.build(p); assertEquals(1, summary.size()); assertEquals(0, summary.getPosition(0)); assertArrayEquals(new byte[0], summary.getKey(0)); ByteArrayDataOutput bout = ByteStreams.newDataOutput(); IndexSummary.serializer.serialize(summary, bout); ByteArrayDataInput bin = ByteStreams.newDataInput(bout.toByteArray()); IndexSummary loaded = IndexSummary.serializer.deserialize(bin, p); assertEquals(1, loaded.size()); assertEquals(summary.getPosition(0), loaded.getPosition(0)); assertArrayEquals(summary.getKey(0), summary.getKey(0)); }
@Override public FMLPacket consumePacket(byte[] data) { ByteArrayDataInput bdi = ByteStreams.newDataInput(data); int chunkIdx = UnsignedBytes.toInt(bdi.readByte()); int chunkTotal = UnsignedBytes.toInt(bdi.readByte()); int chunkLength = bdi.readInt(); if (partials == null) { partials = new byte[chunkTotal][]; } partials[chunkIdx] = new byte[chunkLength]; bdi.readFully(partials[chunkIdx]); for (int i = 0; i < partials.length; i++) { if (partials[i] == null) { return null; } } return this; }
@Override public void read(ByteArrayDataInput in) { super.read(in); orientation = in.readInt(); validMultiblock = in.readBoolean(); selectedModule = in.readUTF(); selectedChipset = in.readUTF(); armorId = in.readInt(); progressing = in.readBoolean(); progress = in.readInt(); if (in.readBoolean()) { energyPos = new Vector3(in.readInt(), in.readInt(), in.readInt()); } }
@Override public boolean accept(Player receiver, ByteArrayDataInput in) { String ip = in.readUTF(); int port = in.readInt(); callback.accept(Maps.immutableEntry(ip, port)); return true; }
@Override public boolean accept(Player receiver, ByteArrayDataInput in) { in.readUTF(); int count = in.readInt(); callback.accept(count); return true; }
@Override public boolean accept(Player receiver, ByteArrayDataInput in) { in.readUTF(); String csv = in.readUTF(); if (csv.isEmpty()) { callback.accept(ImmutableList.of()); return true; } callback.accept(ImmutableList.copyOf(Splitter.on(", ").splitToList(csv))); return true; }
@Override public boolean accept(Player receiver, ByteArrayDataInput in) { String csv = in.readUTF(); if (csv.isEmpty()) { callback.accept(ImmutableList.of()); return true; } callback.accept(ImmutableList.copyOf(Splitter.on(", ").splitToList(csv))); return true; }
@Override public boolean accept(Player receiver, ByteArrayDataInput in) { in.readUTF(); String uuid = in.readUTF(); callback.accept(java.util.UUID.fromString(uuid)); return true; }
@Override public boolean accept(Player receiver, ByteArrayDataInput in) { in.readUTF(); String ip = in.readUTF(); int port = in.readInt(); callback.accept(Maps.immutableEntry(ip, port)); return true; }
@Override public boolean accept(Player receiver, ByteArrayDataInput in) { short len = in.readShort(); byte[] data = new byte[len]; in.readFully(data); return callback.test(data); }
@Override public void onPluginMessageReceived(String channel, Player player, byte[] message) { if (!channel.equals(CHANNEL_BUNGEE)) return; ByteArrayDataInput in = ByteStreams.newDataInput(message); String subchannel = in.readUTF(); if (!subchannel.equals(GET_SERVERS)) return; this.plugin.setServers(in.readUTF().split(", ")); }
public static InputSplit deserializeInputSplit(String base64, String className) throws IOException, ReflectiveOperationException{ Constructor<?> constructor = Class.forName(className).getDeclaredConstructor(); if (constructor == null) { throw new ReflectiveOperationException("Class " + className + " does not implement a default constructor."); } constructor.setAccessible(true); InputSplit split = (InputSplit) constructor.newInstance(); ByteArrayDataInput byteArrayDataInput = ByteStreams.newDataInput(Base64.decodeBase64(base64)); split.readFields(byteArrayDataInput); return split; }
@SuppressWarnings("deprecation") @Override public void onPluginMessageReceived(String channel, Player player, byte[] message) { if (!channel.equals(BungeeSayNoToMcLeaks.CHANNEL)) return; ByteArrayDataInput in = ByteStreams.newDataInput(message); String subchannel = in.readUTF(); if (subchannel.equals(BungeeSayNoToMcLeaks.SUBCHANNEL)) { final String name = in.readUTF(); final boolean result = in.readBoolean(); // S'il est déjà connu if (this.caches.getIfPresent(name) != null) return; this.caches.put(name, result); // Si les 2 IP correspondent if (result) { this.plugin.debug("The player " + name + " doesn't use alt account."); // Les 2 IP ne correspondent pas } else { // Si le joueur est déjà connecté if (this.plugin.getServer().getPlayer(name) != null) { this.executeCommands(name, 100); } } } }
private ClassPatch readPatch(JarEntry patchEntry, JarInputStream jis) { if (DEBUG) FMLRelaunchLog.finer("Reading patch data from %s", patchEntry.getName()); ByteArrayDataInput input; try { input = ByteStreams.newDataInput(ByteStreams.toByteArray(jis)); } catch (IOException e) { FMLRelaunchLog.log(Level.WARN, e, "Unable to read binpatch file %s - ignoring", patchEntry.getName()); return null; } String name = input.readUTF(); String sourceClassName = input.readUTF(); String targetClassName = input.readUTF(); boolean exists = input.readBoolean(); int inputChecksum = 0; if (exists) { inputChecksum = input.readInt(); } int patchLength = input.readInt(); byte[] patchBytes = new byte[patchLength]; input.readFully(patchBytes); return new ClassPatch(name, sourceClassName, targetClassName, exists, inputChecksum, patchBytes); }
/** * @return the set of clusterIds that have consumed the mutation */ public List<UUID> getClusterIds() { List<UUID> clusterIds = new ArrayList<UUID>(); byte[] bytes = getAttribute(CONSUMED_CLUSTER_IDS); if(bytes != null) { ByteArrayDataInput in = ByteStreams.newDataInput(bytes); int numClusters = in.readInt(); for(int i=0; i<numClusters; i++){ clusterIds.add(new UUID(in.readLong(), in.readLong())); } } return clusterIds; }
@Override public void read(ByteArrayDataInput stream) { this.friends.clear(); int size = stream.readInt(); for (int i = 0; i < size; i++) { this.friends.add(stream.readUTF()); } }
@Override public void onPluginMessageReceived(String channel, Player player, byte[] message) { this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> { ByteArrayDataInput input = ByteStreams.newDataInput(message); String subchannel = input.readUTF(); if (!subchannel.equals("MCraft")) return; short len = input.readShort(); byte[] messagebytes = new byte[len]; input.readFully(messagebytes); DataInputStream messagestream = new DataInputStream(new ByteArrayInputStream(messagebytes)); try { String[] commandData = messagestream.readUTF().split("#"); // HERE WE READ A FULL COMMAND String command = commandData[0]; String playerName = commandData[1]; Server server = plugin.getServer(); if (player.getName().equals(playerName)) { // Finally let's execute command! if (command.charAt(command.length() - 2) == '@') { command = command.substring(0, command.length() - 2); player.performCommand(command); } else { server.dispatchCommand(server.getConsoleSender(), command.replace("{PLAYER}", playerName)); } } else { plugin.messages.put(playerName, command); plugin.logger.log(Level.INFO, "New PM data put for: " + playerName + ", with command: " + command); } } catch (IOException e) { e.printStackTrace(); } }, 5L); }