private void a(ServerPing serverping) { File file1 = this.d("server-icon.png"); if (file1.isFile()) { ByteBuf bytebuf = Unpooled.buffer(); try { BufferedImage bufferedimage = ImageIO.read(file1); Validate.validState(bufferedimage.getWidth() == 64, "Must be 64 pixels wide", new Object[0]); Validate.validState(bufferedimage.getHeight() == 64, "Must be 64 pixels high", new Object[0]); ImageIO.write(bufferedimage, "PNG", new ByteBufOutputStream(bytebuf)); ByteBuf bytebuf1 = Base64.encode(bytebuf); serverping.setFavicon("data:image/png;base64," + bytebuf1.toString(Charsets.UTF_8)); } catch (Exception exception) { i.error("Couldn\'t load server icon", exception); } finally { bytebuf.release(); } } }
protected void a(ChannelHandlerContext channelhandlercontext, Packet packet, ByteBuf bytebuf) throws IOException { Integer integer = (Integer) ((BiMap) channelhandlercontext.channel().attr(NetworkManager.f).get()).inverse().get(packet.getClass()); if (a.isDebugEnabled()) { a.debug(b, "OUT: [{}:{}] {}[{}]", new Object[] { channelhandlercontext.channel().attr(NetworkManager.d).get(), integer, packet.getClass().getName(), packet.b()}); } if (integer == null) { throw new IOException("Can\'t serialize unregistered packet"); } else { PacketDataSerializer packetdataserializer = new PacketDataSerializer(bytebuf, NetworkManager.getVersion(channelhandlercontext.channel())); // Spigot packetdataserializer.b(integer.intValue()); packet.b(packetdataserializer); this.c.b(integer.intValue(), (long) packetdataserializer.readableBytes()); } }
@Override public void fromBytes(ByteBuf buf) { int count = buf.readInt(); System.out.println("Client Details: Tweaker Count [" + count + "]."); if (count > 0) { names = Sets.newHashSet(); for (int i = 0; i < count; i++) { names.add(PacketUtil.readUTF8String(buf)); } } count = buf.readInt(); System.out.println("Client Details: Mod Count [" + count + "]"); if (count > 0) { modNames = Sets.newHashSet(); for (int i = 0; i < count; i++) { modNames.add(PacketUtil.readUTF8String(buf)); } } }
public static int readVarInt(ByteBuf buf, int maxSize) { int i = 0; int j = 0; byte b0; do { b0 = buf.readByte(); i |= (b0 & 127) << j++ * 7; if (j > maxSize) { throw new RuntimeException("VarInt too big"); } } while ((b0 & 128) == 128); return i; }
static CraftIconCache loadServerIcon0(BufferedImage image) throws Exception { ByteBuf bytebuf = Unpooled.buffer(); Validate.isTrue(image.getWidth() == 64, "Must be 64 pixels wide"); Validate.isTrue(image.getHeight() == 64, "Must be 64 pixels high"); ImageIO.write(image, "PNG", new ByteBufOutputStream(bytebuf)); ByteBuf bytebuf1 = Base64.encode(bytebuf); return new CraftIconCache("data:image/png;base64," + bytebuf1.toString(Charsets.UTF_8)); }
public static byte[] a(ByteBuf bytebuf) throws IOException { // CraftBukkit - added throws short short1 = bytebuf.readShort(); if (short1 < 0) { throw new IOException("Key was smaller than nothing! Weird key!"); } else { byte[] abyte = new byte[short1]; bytebuf.readBytes(abyte); return abyte; } }
public void savePacket(char side, ByteBuf buf) { int size = buf.readableBytes(); long delta = (new Date().getTime()) - joined; String header = String.format("%012d%012d%c", delta, size, side); try { stream.write(header.getBytes()); buf.getBytes(0, stream, buf.readableBytes()); } catch (IOException e) { e.printStackTrace(); } }
public static void sendAdditionalWorldInfo(Player player, String worldName, int currentPlayers, int maxPlayers) { final ByteBuf buf = PacketUtil.createPacketBuffer(PacketUtil.DISCRIMINATOR_ADDITIONAL_WORLD_INFORMATION); PacketUtil.writeUTF8String(buf, getFormattedWorldName(worldName)); PacketUtil.writeUTF8String(buf, worldName); buf.writeInt(currentPlayers); buf.writeInt(maxPlayers); buf.writeInt(TitleUtil.permissionsLevel(player)); player.sendPluginMessage(BridgePlugin.getInstance(), PacketUtil.CHANNEL, buf.array()); }
public static void openGui(Player player, int guiId, int defaultButton) { final ByteBuf buf = PacketUtil.createPacketBuffer(PacketUtil.DISCRIMINATOR_GUI_CONTROLLER); buf.writeInt(guiId); buf.writeInt(defaultButton); PacketUtil.writeUTF8String(buf, player.getName()); player.sendPluginMessage(BridgePlugin.getInstance(), PacketUtil.CHANNEL, buf.array()); }
private void requestPlayerCount(String serverName) { if (ServerUtil.getOnlinePlayers().size() == 0) { return; // No players online; we can't send this request yet. } ByteBuf buf = Unpooled.buffer(); MiscUtil.writePrefixedString(buf, "PlayerCount"); MiscUtil.writePrefixedString(buf, serverName); byte[] bytes = new byte[buf.readableBytes()]; buf.readBytes(bytes); ServerUtil.getOnlinePlayer(0).sendPluginMessage(plugin, "BungeeCord", bytes); buf.release(); }
@Override public void run() { if (ServerUtil.getOnlinePlayers().size() == 0) { return; } ByteBuf buf = Unpooled.buffer(); MiscUtil.writePrefixedString(buf, "GetServers"); byte[] bytes = new byte[buf.readableBytes()]; buf.readBytes(bytes); ServerUtil.getOnlinePlayer(0).sendPluginMessage(plugin, "BungeeCord", bytes); buf.release(); }
public static String readPrefixedString(ByteBuf buf) { int length = buf.readShort(); byte[] bytes = new byte[length]; buf.readBytes(bytes); return new String(bytes, Charset.forName("UTF8")); }
@Override public void fromBytes(ByteBuf buf) { acceptsRespawnPenalty = buf.readBoolean(); this.x = buf.readInt(); this.y = buf.readInt(); this.z = buf.readInt(); this.world = PacketUtil.readUTF8String(buf); }
public static void writeVarInt(ByteBuf to, int toWrite, int maxSize) { while ((toWrite & -128) != 0) { to.writeByte(toWrite & 127 | 128); toWrite >>>= 7; } to.writeByte(toWrite); }
public static void a(ByteBuf bytebuf, byte[] abyte) { bytebuf.writeShort(abyte.length); bytebuf.writeBytes(abyte); }
public PacketDataSerializer(ByteBuf bytebuf) { this.a = bytebuf; }
public ByteBuf capacity(int i) { return this.a.capacity(i); }
public ByteBuf order(ByteOrder byteorder) { return this.a.order(byteorder); }
public ByteBuf unwrap() { return this.a.unwrap(); }
public ByteBuf readerIndex(int i) { return this.a.readerIndex(i); }
public ByteBuf writerIndex(int i) { return this.a.writerIndex(i); }
public ByteBuf setIndex(int i, int j) { return this.a.setIndex(i, j); }
public ByteBuf clear() { return this.a.clear(); }
public ByteBuf markReaderIndex() { return this.a.markReaderIndex(); }
public ByteBuf resetReaderIndex() { return this.a.resetReaderIndex(); }
public ByteBuf markWriterIndex() { return this.a.markWriterIndex(); }
public ByteBuf resetWriterIndex() { return this.a.resetWriterIndex(); }
public ByteBuf discardReadBytes() { return this.a.discardReadBytes(); }
public ByteBuf discardSomeReadBytes() { return this.a.discardSomeReadBytes(); }
public ByteBuf ensureWritable(int i) { return this.a.ensureWritable(i); }
public ByteBuf getBytes(int i, ByteBuf bytebuf) { return this.a.getBytes(i, bytebuf); }
public ByteBuf getBytes(int i, ByteBuf bytebuf, int j) { return this.a.getBytes(i, bytebuf, j); }
public ByteBuf getBytes(int i, ByteBuf bytebuf, int j, int k) { return this.a.getBytes(i, bytebuf, j, k); }
public ByteBuf getBytes(int i, byte[] abyte) { return this.a.getBytes(i, abyte); }
public ByteBuf getBytes(int i, byte[] abyte, int j, int k) { return this.a.getBytes(i, abyte, j, k); }