Search in sources :

Example 1 with PublicChatMessage

use of org.apollo.game.message.impl.PublicChatMessage in project apollo by apollo-rsps.

the class PublicChatMessageDecoder method decode.

@Override
public PublicChatMessage decode(GamePacket packet) {
    GamePacketReader reader = new GamePacketReader(packet);
    int effects = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.SUBTRACT);
    int color = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.SUBTRACT);
    int length = packet.getLength() - 2;
    byte[] originalCompressed = new byte[length];
    reader.getBytesReverse(DataTransformation.ADD, originalCompressed);
    String uncompressed = TextUtil.decompress(originalCompressed, length);
    uncompressed = TextUtil.filterInvalidCharacters(uncompressed);
    uncompressed = TextUtil.capitalize(uncompressed);
    byte[] recompressed = new byte[length];
    TextUtil.compress(uncompressed, recompressed);
    return new PublicChatMessage(uncompressed, recompressed, color, effects);
}
Also used : GamePacketReader(org.apollo.net.codec.game.GamePacketReader) PublicChatMessage(org.apollo.game.message.impl.PublicChatMessage)

Example 2 with PublicChatMessage

use of org.apollo.game.message.impl.PublicChatMessage in project apollo by apollo-rsps.

the class PublicChatMessageHandlerTests method terminateIfMuted.

@Test
public void terminateIfMuted() throws Exception {
    Player player = PowerMockito.mock(Player.class);
    when(player.isMuted()).thenReturn(true);
    PublicChatMessage publicChatMessage = new PublicChatMessage("Test", "Test".getBytes(), 0, 0);
    handler.handle(player, publicChatMessage);
    assertTrue("PublicChatMessageHandler: player can send messages when muted", publicChatMessage.terminated());
}
Also used : Player(org.apollo.game.model.entity.Player) PublicChatMessage(org.apollo.game.message.impl.PublicChatMessage) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with PublicChatMessage

use of org.apollo.game.message.impl.PublicChatMessage in project apollo by apollo-rsps.

the class PublicChatMessageDecoder method decode.

@Override
public PublicChatMessage decode(GamePacket packet) {
    GamePacketReader reader = new GamePacketReader(packet);
    int color = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.NEGATE);
    int effects = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.ADD);
    int length = packet.getLength() - 2;
    byte[] originalCompressed = new byte[length];
    reader.getBytes(originalCompressed);
    String uncompressed = TextUtil.decompress(originalCompressed, length);
    uncompressed = TextUtil.filterInvalidCharacters(uncompressed);
    uncompressed = TextUtil.capitalize(uncompressed);
    byte[] recompressed = new byte[length];
    // in case invalid data gets sent, this effectively verifies it
    TextUtil.compress(uncompressed, recompressed);
    return new PublicChatMessage(uncompressed, recompressed, color, effects);
}
Also used : GamePacketReader(org.apollo.net.codec.game.GamePacketReader) PublicChatMessage(org.apollo.game.message.impl.PublicChatMessage)

Aggregations

PublicChatMessage (org.apollo.game.message.impl.PublicChatMessage)3 GamePacketReader (org.apollo.net.codec.game.GamePacketReader)2 Player (org.apollo.game.model.entity.Player)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1