mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 08:39:11 +00:00
Remove duplicate ByteBuffer utility class.
This commit is contained in:
@@ -4,7 +4,7 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.apollo.util.ByteBufferUtil;
|
||||
import org.apollo.util.BufferUtil;
|
||||
import org.apollo.util.CompressionUtil;
|
||||
|
||||
/**
|
||||
@@ -22,8 +22,8 @@ public final class Archive {
|
||||
* @throws IOException If an I/O error occurs.
|
||||
*/
|
||||
public static Archive decode(ByteBuffer buffer) throws IOException {
|
||||
int extractedSize = ByteBufferUtil.readUnsignedTriByte(buffer);
|
||||
int size = ByteBufferUtil.readUnsignedTriByte(buffer);
|
||||
int extractedSize = BufferUtil.readUnsignedTriByte(buffer);
|
||||
int size = BufferUtil.readUnsignedTriByte(buffer);
|
||||
boolean extracted = false;
|
||||
|
||||
if (size != extractedSize) {
|
||||
@@ -42,8 +42,8 @@ public final class Archive {
|
||||
|
||||
for (int i = 0; i < entries; i++) {
|
||||
identifiers[i] = buffer.getInt();
|
||||
extractedSizes[i] = ByteBufferUtil.readUnsignedTriByte(buffer);
|
||||
sizes[i] = ByteBufferUtil.readUnsignedTriByte(buffer);
|
||||
extractedSizes[i] = BufferUtil.readUnsignedTriByte(buffer);
|
||||
sizes[i] = BufferUtil.readUnsignedTriByte(buffer);
|
||||
}
|
||||
|
||||
ArchiveEntry[] entry = new ArchiveEntry[entries];
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.nio.ByteBuffer;
|
||||
import org.apollo.fs.IndexedFileSystem;
|
||||
import org.apollo.fs.archive.Archive;
|
||||
import org.apollo.game.model.def.ItemDefinition;
|
||||
import org.apollo.util.ByteBufferUtil;
|
||||
import org.apollo.util.BufferUtil;
|
||||
|
||||
/**
|
||||
* Decodes item data from the {@code obj.dat} file into {@link ItemDefinition}s.
|
||||
@@ -74,9 +74,9 @@ public final class ItemDefinitionDecoder {
|
||||
} else if (opcode == 1) {
|
||||
buffer.getShort();
|
||||
} else if (opcode == 2) {
|
||||
definition.setName(ByteBufferUtil.readString(buffer));
|
||||
definition.setName(BufferUtil.readString(buffer));
|
||||
} else if (opcode == 3) {
|
||||
definition.setDescription(ByteBufferUtil.readString(buffer));
|
||||
definition.setDescription(BufferUtil.readString(buffer));
|
||||
} else if (opcode == 4) {
|
||||
buffer.getShort();
|
||||
} else if (opcode == 5) {
|
||||
@@ -106,13 +106,13 @@ public final class ItemDefinitionDecoder {
|
||||
} else if (opcode == 26) {
|
||||
buffer.getShort();
|
||||
} else if (opcode >= 30 && opcode < 35) {
|
||||
String str = ByteBufferUtil.readString(buffer);
|
||||
String str = BufferUtil.readString(buffer);
|
||||
if (str.equalsIgnoreCase("hidden")) {
|
||||
str = null;
|
||||
}
|
||||
definition.setGroundAction(opcode - 30, str);
|
||||
} else if (opcode >= 35 && opcode < 40) {
|
||||
definition.setInventoryAction(opcode - 35, ByteBufferUtil.readString(buffer));
|
||||
definition.setInventoryAction(opcode - 35, BufferUtil.readString(buffer));
|
||||
} else if (opcode == 40) {
|
||||
int colourCount = buffer.get() & 0xFF;
|
||||
for (int i = 0; i < colourCount; i++) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.nio.ByteBuffer;
|
||||
import org.apollo.fs.IndexedFileSystem;
|
||||
import org.apollo.fs.archive.Archive;
|
||||
import org.apollo.game.model.def.NpcDefinition;
|
||||
import org.apollo.util.ByteBufferUtil;
|
||||
import org.apollo.util.BufferUtil;
|
||||
|
||||
/**
|
||||
* Decodes npc data from the {@code npc.dat} file into {@link NpcDefinition}s.
|
||||
@@ -78,9 +78,9 @@ public final class NpcDefinitionDecoder {
|
||||
npcModels[i] = buffer.getShort();
|
||||
}
|
||||
} else if (code == 2) {
|
||||
definition.setName(ByteBufferUtil.readString(buffer));
|
||||
definition.setName(BufferUtil.readString(buffer));
|
||||
} else if (code == 3) {
|
||||
definition.setDescription(ByteBufferUtil.readString(buffer));
|
||||
definition.setDescription(BufferUtil.readString(buffer));
|
||||
} else if (code == 12) {
|
||||
definition.setSize(buffer.get());
|
||||
} else if (code == 13) {
|
||||
@@ -91,7 +91,7 @@ public final class NpcDefinitionDecoder {
|
||||
definition
|
||||
.setWalkAnimations(buffer.getShort(), buffer.getShort(), buffer.getShort(), buffer.getShort());
|
||||
} else if (code >= 30 && code < 40) {
|
||||
String str = ByteBufferUtil.readString(buffer);
|
||||
String str = BufferUtil.readString(buffer);
|
||||
if (str.equals("hidden")) {
|
||||
str = null;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.nio.ByteBuffer;
|
||||
import org.apollo.fs.IndexedFileSystem;
|
||||
import org.apollo.fs.archive.Archive;
|
||||
import org.apollo.game.model.def.ObjectDefinition;
|
||||
import org.apollo.util.ByteBufferUtil;
|
||||
import org.apollo.util.BufferUtil;
|
||||
|
||||
/**
|
||||
* Decodes object data from the {@code loc.dat} file into {@link ObjectDefinition}s.
|
||||
@@ -78,9 +78,9 @@ public final class ObjectDefinitionDecoder {
|
||||
data.get(); // model position
|
||||
}
|
||||
} else if (opcode == 2) {
|
||||
definition.setName(ByteBufferUtil.readString(data));
|
||||
definition.setName(BufferUtil.readString(data));
|
||||
} else if (opcode == 3) {
|
||||
definition.setDescription(ByteBufferUtil.readString(data));
|
||||
definition.setDescription(BufferUtil.readString(data));
|
||||
} else if (opcode == 5) {
|
||||
int amount = data.get() & 0xFF;
|
||||
for (int i = 0; i < amount; i++) {
|
||||
@@ -113,7 +113,7 @@ public final class ObjectDefinitionDecoder {
|
||||
if (actions == null) {
|
||||
actions = new String[10];
|
||||
}
|
||||
String action = ByteBufferUtil.readString(data);
|
||||
String action = BufferUtil.readString(data);
|
||||
actions[opcode - 30] = action;
|
||||
definition.setMenuActions(actions);
|
||||
} else if (opcode == 39) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.apollo.fs.IndexedFileSystem;
|
||||
import org.apollo.fs.archive.Archive;
|
||||
import org.apollo.game.model.Position;
|
||||
import org.apollo.game.model.obj.StaticObject;
|
||||
import org.apollo.util.ByteBufferUtil;
|
||||
import org.apollo.util.BufferUtil;
|
||||
import org.apollo.util.CompressionUtil;
|
||||
|
||||
/**
|
||||
@@ -89,13 +89,13 @@ public final class StaticObjectDecoder {
|
||||
int id = -1;
|
||||
int idOffset;
|
||||
|
||||
while ((idOffset = ByteBufferUtil.readSmart(buffer)) != 0) {
|
||||
while ((idOffset = BufferUtil.readSmart(buffer)) != 0) {
|
||||
id += idOffset;
|
||||
|
||||
int position = 0;
|
||||
int positionOffset;
|
||||
|
||||
while ((positionOffset = ByteBufferUtil.readSmart(buffer)) != 0) {
|
||||
while ((positionOffset = BufferUtil.readSmart(buffer)) != 0) {
|
||||
position += positionOffset - 1;
|
||||
|
||||
int localX = position >> 6 & 0x3F;
|
||||
|
||||
@@ -7,8 +7,7 @@ import java.io.InputStream;
|
||||
import org.apollo.game.model.def.EquipmentDefinition;
|
||||
|
||||
/**
|
||||
* A class which parses the {@code data/equipment-[release].dat} file to create an array of {@link EquipmentDefinition}
|
||||
* s.
|
||||
* A class that parses the {@code data/equipment-[release].dat} file to create an array of {@link EquipmentDefinition}s.
|
||||
*
|
||||
* @author Graham
|
||||
*/
|
||||
|
||||
@@ -16,7 +16,7 @@ import org.apollo.util.xml.XmlParser;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* A class which parses the {@code events.xml} file to produce {@link EventHandlerChainGroup}s.
|
||||
* A class that parses the {@code events.xml} file to produce {@link EventHandlerChainGroup}s.
|
||||
*
|
||||
* @author Graham
|
||||
*/
|
||||
@@ -39,8 +39,8 @@ public final class EventHandlerChainParser {
|
||||
* @throws SAXException If a SAX error occurs.
|
||||
*/
|
||||
public EventHandlerChainParser(InputStream is) throws SAXException {
|
||||
parser = new XmlParser();
|
||||
this.is = is;
|
||||
parser = new XmlParser();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.apollo.util.xml.XmlParser;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* A class which parses {@code plugin.xml} files into {@link PluginMetaData} objects.
|
||||
* A class that parses {@code plugin.xml} files into {@link PluginMetaData} objects.
|
||||
*
|
||||
* @author Graham
|
||||
*/
|
||||
@@ -37,8 +37,8 @@ public final class PluginMetaDataParser {
|
||||
* @throws SAXException If a SAX error occurs.
|
||||
*/
|
||||
public PluginMetaDataParser(InputStream is) throws SAXException {
|
||||
parser = new XmlParser();
|
||||
this.is = is;
|
||||
parser = new XmlParser();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,8 +33,8 @@ public final class RsaKeyParser {
|
||||
* @throws SAXException If a SAX error occurs.
|
||||
*/
|
||||
public RsaKeyParser(InputStream is) throws SAXException {
|
||||
parser = new XmlParser();
|
||||
this.is = is;
|
||||
parser = new XmlParser();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,6 +13,16 @@ import org.apollo.net.session.Session;
|
||||
*/
|
||||
public final class NetworkConstants {
|
||||
|
||||
/**
|
||||
* The service port.
|
||||
*/
|
||||
public static final int SERVICE_PORT = 43594;
|
||||
|
||||
/**
|
||||
* The JAGGRAB port.
|
||||
*/
|
||||
public static final int JAGGRAB_PORT = 43595;
|
||||
|
||||
/**
|
||||
* The HTTP port.
|
||||
*/
|
||||
@@ -24,9 +34,9 @@ public final class NetworkConstants {
|
||||
public static final int IDLE_TIME = 15;
|
||||
|
||||
/**
|
||||
* The JAGGRAB port.
|
||||
* The terminator of a string.
|
||||
*/
|
||||
public static final int JAGGRAB_PORT = 43595;
|
||||
public static final int STRING_TERMINATOR = 10;
|
||||
|
||||
/**
|
||||
* The exponent used when decrypting the RSA block.
|
||||
@@ -38,21 +48,11 @@ public final class NetworkConstants {
|
||||
*/
|
||||
public static BigInteger RSA_MODULUS;
|
||||
|
||||
/**
|
||||
* The service port.
|
||||
*/
|
||||
public static final int SERVICE_PORT = 43594;
|
||||
|
||||
/**
|
||||
* The {@link Session} {@link AttributeKey}.
|
||||
*/
|
||||
public static final AttributeKey<Session> SESSION_KEY = AttributeKey.valueOf("session");
|
||||
|
||||
/**
|
||||
* The terminator of a string.
|
||||
*/
|
||||
public static final int STRING_TERMINATOR = 10;
|
||||
|
||||
/**
|
||||
* Default private constructor to prevent instantiation by other classes.
|
||||
*/
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.apollo.net.codec.game;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import org.apollo.util.ByteBufUtil;
|
||||
import org.apollo.util.BufferUtil;
|
||||
|
||||
/**
|
||||
* A utility class for reading {@link GamePacket}s.
|
||||
@@ -325,7 +325,7 @@ public final class GamePacketReader {
|
||||
*/
|
||||
public String getString() {
|
||||
checkByteAccess();
|
||||
return ByteBufUtil.readString(buffer);
|
||||
return BufferUtil.readString(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.apollo.fs.FileSystemConstants;
|
||||
import org.apollo.net.NetworkConstants;
|
||||
import org.apollo.security.IsaacRandomPair;
|
||||
import org.apollo.security.PlayerCredentials;
|
||||
import org.apollo.util.ByteBufUtil;
|
||||
import org.apollo.util.BufferUtil;
|
||||
import org.apollo.util.StatefulFrameDecoder;
|
||||
|
||||
/**
|
||||
@@ -178,8 +178,8 @@ public final class LoginDecoder extends StatefulFrameDecoder<LoginDecoderState>
|
||||
|
||||
int uid = securePayload.readInt();
|
||||
|
||||
String username = ByteBufUtil.readString(securePayload);
|
||||
String password = ByteBufUtil.readString(securePayload);
|
||||
String username = BufferUtil.readString(securePayload);
|
||||
String password = BufferUtil.readString(securePayload);
|
||||
|
||||
if (username.length() > 12 || password.length() > 20) {
|
||||
throw new Exception("Username or password too long.");
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
package org.apollo.util;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.apollo.net.NetworkConstants;
|
||||
|
||||
/**
|
||||
* A utility class which contains {@link ByteBuffer}-related methods.
|
||||
* A utility class which contains {@link ByteBuffer}-related utility methods.
|
||||
*
|
||||
* @author Graham
|
||||
*/
|
||||
public final class ByteBufferUtil {
|
||||
public final class BufferUtil {
|
||||
|
||||
/**
|
||||
* Reads a 'smart' (either a {@code byte} or {@code short} depending on the value) from the specified buffer.
|
||||
@@ -26,25 +28,40 @@ public final class ByteBufferUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a string from the specified buffer.
|
||||
* Reads a string from the specified {@link ByteBuffer}.
|
||||
*
|
||||
* @param buffer The buffer.
|
||||
* @return The string.
|
||||
*/
|
||||
public static String readString(ByteBuffer buffer) {
|
||||
StringBuilder bldr = new StringBuilder();
|
||||
char c;
|
||||
while ((c = (char) buffer.get()) != NetworkConstants.STRING_TERMINATOR) {
|
||||
bldr.append(c);
|
||||
char character;
|
||||
while ((character = (char) buffer.get()) != NetworkConstants.STRING_TERMINATOR) {
|
||||
bldr.append(character);
|
||||
}
|
||||
return bldr.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an unsigned tri byte from the specified buffer.
|
||||
* Reads a string from the specified {@link ByteBuf}.
|
||||
*
|
||||
* @param buffer The buffer.
|
||||
* @return The tri byte.
|
||||
* @return The string.
|
||||
*/
|
||||
public static String readString(ByteBuf buffer) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int character;
|
||||
while (buffer.isReadable() && (character = buffer.readUnsignedByte()) != NetworkConstants.STRING_TERMINATOR) {
|
||||
builder.append((char) character);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an unsigned tri-byte from the specified {@link ByteBuffer}.
|
||||
*
|
||||
* @param buffer The buffer.
|
||||
* @return The tri-byte.
|
||||
*/
|
||||
public static int readUnsignedTriByte(ByteBuffer buffer) {
|
||||
return (buffer.get() & 0xFF) << 16 | (buffer.get() & 0xFF) << 8 | buffer.get() & 0xFF;
|
||||
@@ -53,7 +70,7 @@ public final class ByteBufferUtil {
|
||||
/**
|
||||
* Default private constructor to prevent instantiation.
|
||||
*/
|
||||
private ByteBufferUtil() {
|
||||
private BufferUtil() {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
package org.apollo.util;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import org.apollo.net.NetworkConstants;
|
||||
|
||||
/**
|
||||
* A utility class which provides extra {@link ByteBuf}-related methods which deal with data types used in the protocol.
|
||||
*
|
||||
* @author Graham
|
||||
*/
|
||||
public final class ByteBufUtil {
|
||||
|
||||
/**
|
||||
* Reads a string from the specified buffer.
|
||||
*
|
||||
* @param buffer The buffer.
|
||||
* @return The string.
|
||||
*/
|
||||
public static String readString(ByteBuf buffer) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int character;
|
||||
while (buffer.isReadable() && (character = buffer.readUnsignedByte()) != NetworkConstants.STRING_TERMINATOR) {
|
||||
builder.append((char) character);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Default private constructor to prevent instantiation by other classes.
|
||||
*/
|
||||
private ByteBufUtil() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user