Java Code Examples for com.google.common.io.ByteArrayDataInput#readFully()

The following examples show how to use com.google.common.io.ByteArrayDataInput#readFully() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RendererPacket.java    From bartworks with MIT License 6 votes vote down vote up
@Override
public GT_Packet decode(ByteArrayDataInput dataInput) {

    byte[] buffer = new byte[19];
    dataInput.readFully(buffer);

    this.coords = new Coords(ByteBuffer.wrap(buffer).getInt(0), ByteBuffer.wrap(buffer).getShort(4), ByteBuffer.wrap(buffer).getInt(6), ByteBuffer.wrap(buffer).getInt(10));
    int[] rgb = {ByteBuffer.wrap(buffer).get(14) - Byte.MIN_VALUE, ByteBuffer.wrap(buffer).get(15) - Byte.MIN_VALUE, ByteBuffer.wrap(buffer).get(16) - Byte.MIN_VALUE};
    this.integer = BW_ColorUtil.getColorFromRGBArray(rgb);
    this.removal = ByteBuffer.wrap(buffer).get(17);

    byte checksum = (byte) (this.coords.x % 25 + this.coords.y % 25 + this.coords.z % 25 + this.coords.wID % 25 + this.integer % 25 + this.removal);

    if (checksum != ByteBuffer.wrap(buffer).get(18)) {
        MainMod.LOGGER.error("BW Packet was corrupted or modified!");
        return null;
    }

    return new RendererPacket(this.coords, this.integer, this.removal == 1);
}
 
Example 2
Source File: MetaBlockPacket.java    From bartworks with MIT License 6 votes vote down vote up
@Override
public GT_Packet decode(ByteArrayDataInput byteArrayDataInput) {
    byte[] tmp = new byte[16];
    byteArrayDataInput.readFully(tmp);
    ByteBuffer buff = ByteBuffer.wrap(tmp);
    this.x = buff.getInt();
    this.z = buff.getInt();
    this.y = buff.getShort();
    this.meta = buff.getShort();
    MetaBlockPacket todecode = new MetaBlockPacket(this.x, this.y, this.z, this.meta);
    if (buff.getInt() != MurmurHash3.murmurhash3_x86_32(ByteBuffer.allocate(12).putInt(this.x).putInt(this.z).putShort(this.y).putShort(this.meta).array(), 0, 12, 31)) {
        MainMod.LOGGER.error("PACKET HASH DOES NOT MATCH!");
        return null;
    }
    return todecode;
}
 
Example 3
Source File: PlayerDataHelper.java    From PlayerSQL with GNU General Public License v2.0 6 votes vote down vote up
@SneakyThrows
public static PlayerData decode(byte[] buf) {
    ByteArrayDataInput input = ByteStreams.newDataInput(buf);// DECOMPRESS STREAM
    int uncompressedLen = (int) VarInt.readUnsignedVarInt(input);
    int compressedLen = (int) VarInt.readUnsignedVarInt(input);
    byte[] compressed = new byte[compressedLen];
    input.readFully(compressed);
    byte[] decompressed = LZ4.decompress(compressed, uncompressedLen);
    input = ByteStreams.newDataInput(decompressed);
    PlayerData dat = new PlayerData();// PARSER PLAYER DATA
    dat.setUuid(new UUID(input.readLong(), input.readLong()));
    dat.setHealth(input.readDouble());
    dat.setFood(input.readInt());
    dat.setHand(input.readInt());
    dat.setExp(input.readInt());
    dat.setInventory(readString(input));
    dat.setArmor(readString(input));
    dat.setChest(readString(input));
    dat.setEffect(readString(input));
    return dat;
}
 
Example 4
Source File: BungeeCordImpl.java    From helper with MIT License 5 votes vote down vote up
@Override
public boolean acceptResponse(Player receiver, ByteArrayDataInput in) {
    short len = in.readShort();
    byte[] data = new byte[len];
    in.readFully(data);

    return this.callback.test(data);
}
 
Example 5
Source File: SkyWarsReloaded.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
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("GetServer")) {
    	servername = in.readUTF();
    }
    
    if (subchannel.equals("SWRMessaging")) {
    	short len = in.readShort();
    	byte[] msgbytes = new byte[len];
    	in.readFully(msgbytes);

    	DataInputStream msgin = new DataInputStream(new ByteArrayInputStream(msgbytes));
    	try {
			String header = msgin.readUTF();
			if (header.equalsIgnoreCase("RequestUpdate")) {
				String sendToServer = msgin.readUTF();
				String playerCount = "" + GameMap.getMaps().get(0).getAlivePlayers().size();
				String maxPlayers = "" + GameMap.getMaps().get(0).getMaxPlayers();
				String gameStarted = "" + GameMap.getMaps().get(0).getMatchState().toString();
				ArrayList<String> messages = new ArrayList<>();
				messages.add("ServerUpdate");
				messages.add(servername);
				messages.add(playerCount);
				messages.add(maxPlayers);
				messages.add(gameStarted);
				sendSWRMessage(player, sendToServer, messages);					
			}
		} catch (IOException e) {
			e.printStackTrace();
		} 
    }
}
 
Example 6
Source File: PlayerSqlProtocol.java    From PlayerSQL with GNU General Public License v2.0 5 votes vote down vote up
public PlayerSqlProtocol decode(ByteArrayDataInput input) {
    DataSupply pk = new DataSupply();
    pk.setId(new UUID(input.readLong(), input.readLong()));
    pk.setGroup(input.readUTF());
    byte[] buf = new byte[input.readInt()];
    input.readFully(buf);
    pk.setBuf(buf);
    return pk;
}
 
Example 7
Source File: BungeeReceiver.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Processes the given data input and attempts to translate it to a message for the "AuthMe.v2.Broadcast" channel.
 *
 * @param in the input to handle
 */
private void handleBroadcast(final ByteArrayDataInput in) {
    // Read data byte array
    final short dataLength = in.readShort();
    final byte[] dataBytes = new byte[dataLength];
    in.readFully(dataBytes);
    final ByteArrayDataInput dataIn = ByteStreams.newDataInput(dataBytes);

    // Parse type
    final String typeId = dataIn.readUTF();
    final Optional<MessageType> type = MessageType.fromId(typeId);
    if (!type.isPresent()) {
        logger.debug("Received unsupported forwarded bungeecord message type! ({0})", typeId);
        return;
    }

    // Parse argument
    final String argument;
    try {
        argument = dataIn.readUTF();
    } catch (IllegalStateException e) {
        logger.warning("Received invalid forwarded plugin message of type " + type.get().name()
            + ": argument is missing!");
        return;
    }

    // Handle type
    switch (type.get()) {
        case UNREGISTER:
            dataSource.invalidateCache(argument);
            break;
        case REFRESH_PASSWORD:
        case REFRESH_QUITLOC:
        case REFRESH_EMAIL:
        case REFRESH:
            dataSource.refreshCache(argument);
            break;
        default:
    }
}
 
Example 8
Source File: CircuitProgrammerPacket.java    From bartworks with MIT License 4 votes vote down vote up
@Override
public GT_Packet decode(ByteArrayDataInput byteArrayDataInput) {
    byte[] ret = new byte[9];
    byteArrayDataInput.readFully(ret);
    return new CircuitProgrammerPacket(ByteBuffer.wrap(ret).getInt(0), ByteBuffer.wrap(ret).getInt(4), ByteBuffer.wrap(ret).get(8) > -1, ByteBuffer.wrap(ret).get(8));
}