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);
}
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());
}
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);
}
Aggregations