Complete rename of 'PrivateMessageMessage' to 'PrivateChatMessage', rename 'TextUtil.uncompress' to 'TextUtil.decompress'.

This commit is contained in:
Major-
2015-02-13 16:46:04 +00:00
parent b2e8e27d70
commit 8b31333e23
10 changed files with 120 additions and 120 deletions
@@ -0,0 +1,67 @@
package org.apollo.game.message.impl;
import org.apollo.game.message.Message;
/**
* A {@link Message} sent by the client to send private chat to another player.
*
* @author Major
*/
public final class PrivateChatMessage extends Message {
/**
* The chat string being sent.
*/
private final String chat;
/**
* The compressed chat string.
*/
private final byte[] compressedChat;
/**
* The username this message is being sent to.
*/
private final String username;
/**
* Creates a new private chat message.
*
* @param username The username of the player the message is being sent to.
* @param chat The chat string.
* @param compressedChat The chat string, in a compressed form.
*/
public PrivateChatMessage(String username, String chat, byte[] compressedChat) {
this.username = username;
this.chat = chat;
this.compressedChat = compressedChat.clone();
}
/**
* Gets the chat string being sent.
*
* @return The chat string.
*/
public String getChat() {
return chat;
}
/**
* Gets the compressed chat string.
*
* @return The compressed chat string.
*/
public byte[] getCompressedChat() {
return compressedChat.clone();
}
/**
* Gets the username of the player the chat string is being sent to.
*
* @return The username.
*/
public String getUsername() {
return username;
}
}
@@ -1,67 +0,0 @@
package org.apollo.game.message.impl;
import org.apollo.game.message.Message;
/**
* A {@link Message} sent by the client to send a private message to another player.
*
* @author Major
*/
public final class PrivateMessageMessage extends Message {
/**
* The username this message is being sent to.
*/
private final String username;
/**
* The message being sent.
*/
private final String message;
/**
* The compressed message.
*/
private final byte[] compressedMessage;
/**
* Creates a new private message message.
*
* @param username The username of the player the message is being sent to.
* @param message The message.
* @param compressedMessage The message, in a compressed form.
*/
public PrivateMessageMessage(String username, String message, byte[] compressedMessage) {
this.username = username;
this.message = message;
this.compressedMessage = compressedMessage;
}
/**
* Gets the username of the player the message is being sent to.
*
* @return The username.
*/
public String getUsername() {
return username;
}
/**
* Gets the message being sent.
*
* @return The message.
*/
public String getMessage() {
return message;
}
/**
* Gets the compressed message.
*
* @return The compressed message.
*/
public byte[] getCompressedMessage() {
return compressedMessage;
}
}
@@ -26,7 +26,7 @@ public final class ChatMessageDecoder extends MessageDecoder<ChatMessage> {
byte[] originalCompressed = new byte[length];
reader.getBytesReverse(DataTransformation.ADD, originalCompressed);
String uncompressed = TextUtil.uncompress(originalCompressed, length);
String uncompressed = TextUtil.decompress(originalCompressed, length);
uncompressed = TextUtil.filterInvalidCharacters(uncompressed);
uncompressed = TextUtil.capitalize(uncompressed);
@@ -0,0 +1,38 @@
package org.apollo.net.release.r317;
import org.apollo.game.message.impl.PrivateChatMessage;
import org.apollo.net.codec.game.DataType;
import org.apollo.net.codec.game.GamePacket;
import org.apollo.net.codec.game.GamePacketReader;
import org.apollo.net.release.MessageDecoder;
import org.apollo.util.NameUtil;
import org.apollo.util.TextUtil;
/**
* A {@link MessageDecoder} for the {@link PrivateChatMessage}.
*
* @author Major
*/
public final class PrivateChatMessageDecoder extends MessageDecoder<PrivateChatMessage> {
@Override
public PrivateChatMessage decode(GamePacket packet) {
GamePacketReader reader = new GamePacketReader(packet);
String username = NameUtil.decodeBase37(reader.getSigned(DataType.LONG));
int length = packet.getLength() - Long.BYTES;
byte[] originalCompressed = new byte[length];
reader.getBytes(originalCompressed);
String decompressed = TextUtil.decompress(originalCompressed, length);
decompressed = TextUtil.filterInvalidCharacters(decompressed);
decompressed = TextUtil.capitalize(decompressed);
byte[] recompressed = new byte[length];
TextUtil.compress(decompressed, recompressed);
return new PrivateChatMessage(username, new String(decompressed), recompressed);
}
}
@@ -1,38 +0,0 @@
package org.apollo.net.release.r317;
import org.apollo.game.message.impl.PrivateMessageMessage;
import org.apollo.net.codec.game.DataType;
import org.apollo.net.codec.game.GamePacket;
import org.apollo.net.codec.game.GamePacketReader;
import org.apollo.net.release.MessageDecoder;
import org.apollo.util.NameUtil;
import org.apollo.util.TextUtil;
/**
* A {@link MessageDecoder} for the {@link PrivateMessageMessage}.
*
* @author Major
*/
public final class PrivateMessageMessageDecoder extends MessageDecoder<PrivateMessageMessage> {
@Override
public PrivateMessageMessage decode(GamePacket packet) {
GamePacketReader reader = new GamePacketReader(packet);
String username = NameUtil.decodeBase37(reader.getSigned(DataType.LONG));
int length = packet.getLength() - 8;
byte[] originalCompressed = new byte[length];
reader.getBytes(originalCompressed);
String uncompressed = TextUtil.uncompress(originalCompressed, length);
uncompressed = TextUtil.filterInvalidCharacters(uncompressed);
uncompressed = TextUtil.capitalize(uncompressed);
byte[] recompressed = new byte[length];
TextUtil.compress(uncompressed, recompressed);
return new PrivateMessageMessage(username, new String(uncompressed), recompressed);
}
}
@@ -158,7 +158,7 @@ public final class Release317 extends Release {
register(133, new AddIgnoreMessageDecoder());
register(215, new RemoveFriendMessageDecoder());
register(74, new RemoveIgnoreMessageDecoder());
register(126, new PrivateMessageMessageDecoder());
register(126, new PrivateChatMessageDecoder());
// register encoders
register(IdAssignmentMessage.class, new IdAssignmentMessageEncoder());
@@ -27,7 +27,7 @@ public final class ChatMessageDecoder extends MessageDecoder<ChatMessage> {
byte[] originalCompressed = new byte[length];
reader.getBytes(originalCompressed);
String uncompressed = TextUtil.uncompress(originalCompressed, length);
String uncompressed = TextUtil.decompress(originalCompressed, length);
uncompressed = TextUtil.filterInvalidCharacters(uncompressed);
uncompressed = TextUtil.capitalize(uncompressed);
@@ -1,6 +1,6 @@
package org.apollo.net.release.r377;
import org.apollo.game.message.impl.PrivateMessageMessage;
import org.apollo.game.message.impl.PrivateChatMessage;
import org.apollo.net.codec.game.DataType;
import org.apollo.net.codec.game.GamePacket;
import org.apollo.net.codec.game.GamePacketReader;
@@ -9,30 +9,30 @@ import org.apollo.util.NameUtil;
import org.apollo.util.TextUtil;
/**
* A {@link MessageDecoder} for the {@link PrivateMessageMessage}.
* A {@link MessageDecoder} for the {@link PrivateChatMessage}.
*
* @author Major
*/
public final class PrivateChatMessageDecoder extends MessageDecoder<PrivateMessageMessage> {
public final class PrivateChatMessageDecoder extends MessageDecoder<PrivateChatMessage> {
@Override
public PrivateMessageMessage decode(GamePacket packet) {
public PrivateChatMessage decode(GamePacket packet) {
GamePacketReader reader = new GamePacketReader(packet);
String username = NameUtil.decodeBase37(reader.getSigned(DataType.LONG));
int length = packet.getLength() - 8;
int length = packet.getLength() - Long.BYTES;
byte[] originalCompressed = new byte[length];
reader.getBytes(originalCompressed);
String uncompressed = TextUtil.uncompress(originalCompressed, length);
uncompressed = TextUtil.filterInvalidCharacters(uncompressed);
uncompressed = TextUtil.capitalize(uncompressed);
String decompressed = TextUtil.decompress(originalCompressed, length);
decompressed = TextUtil.filterInvalidCharacters(decompressed);
decompressed = TextUtil.capitalize(decompressed);
byte[] recompressed = new byte[length];
TextUtil.compress(uncompressed, recompressed);
TextUtil.compress(decompressed, recompressed);
return new PrivateMessageMessage(username, new String(uncompressed), recompressed);
return new PrivateChatMessage(username, new String(decompressed), recompressed);
}
}
+1 -1
View File
@@ -120,7 +120,7 @@ public final class TextUtil {
* @param len The length.
* @return The uncompressed {@link String}.
*/
public static String uncompress(byte[] in, int len) {
public static String decompress(byte[] in, int len) {
byte[] out = new byte[4096];
int outPos = 0;
int carry = -1;