diff --git a/src/org/apollo/fs/archive/Archive.java b/src/org/apollo/fs/archive/Archive.java index 233fc6e3..c99cc17f 100644 --- a/src/org/apollo/fs/archive/Archive.java +++ b/src/org/apollo/fs/archive/Archive.java @@ -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]; diff --git a/src/org/apollo/fs/decoder/ItemDefinitionDecoder.java b/src/org/apollo/fs/decoder/ItemDefinitionDecoder.java index 1183311c..ba32efc4 100644 --- a/src/org/apollo/fs/decoder/ItemDefinitionDecoder.java +++ b/src/org/apollo/fs/decoder/ItemDefinitionDecoder.java @@ -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++) { diff --git a/src/org/apollo/fs/decoder/NpcDefinitionDecoder.java b/src/org/apollo/fs/decoder/NpcDefinitionDecoder.java index 1ad4a0eb..272b910e 100644 --- a/src/org/apollo/fs/decoder/NpcDefinitionDecoder.java +++ b/src/org/apollo/fs/decoder/NpcDefinitionDecoder.java @@ -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; } diff --git a/src/org/apollo/fs/decoder/ObjectDefinitionDecoder.java b/src/org/apollo/fs/decoder/ObjectDefinitionDecoder.java index 31158dbf..233231d8 100644 --- a/src/org/apollo/fs/decoder/ObjectDefinitionDecoder.java +++ b/src/org/apollo/fs/decoder/ObjectDefinitionDecoder.java @@ -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) { diff --git a/src/org/apollo/fs/decoder/StaticObjectDecoder.java b/src/org/apollo/fs/decoder/StaticObjectDecoder.java index b3457011..ff74cc9e 100644 --- a/src/org/apollo/fs/decoder/StaticObjectDecoder.java +++ b/src/org/apollo/fs/decoder/StaticObjectDecoder.java @@ -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; diff --git a/src/org/apollo/io/EquipmentDefinitionParser.java b/src/org/apollo/io/EquipmentDefinitionParser.java index 2e738fb3..e1f9333f 100644 --- a/src/org/apollo/io/EquipmentDefinitionParser.java +++ b/src/org/apollo/io/EquipmentDefinitionParser.java @@ -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 */ diff --git a/src/org/apollo/io/EventHandlerChainParser.java b/src/org/apollo/io/EventHandlerChainParser.java index 24373f78..b4c246c1 100644 --- a/src/org/apollo/io/EventHandlerChainParser.java +++ b/src/org/apollo/io/EventHandlerChainParser.java @@ -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(); } /** diff --git a/src/org/apollo/io/PluginMetaDataParser.java b/src/org/apollo/io/PluginMetaDataParser.java index 46059168..be9089d3 100644 --- a/src/org/apollo/io/PluginMetaDataParser.java +++ b/src/org/apollo/io/PluginMetaDataParser.java @@ -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(); } /** diff --git a/src/org/apollo/io/RsaKeyParser.java b/src/org/apollo/io/RsaKeyParser.java index 6eeeb9c9..450203e1 100644 --- a/src/org/apollo/io/RsaKeyParser.java +++ b/src/org/apollo/io/RsaKeyParser.java @@ -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(); } /** diff --git a/src/org/apollo/net/NetworkConstants.java b/src/org/apollo/net/NetworkConstants.java index d51010d1..0c13c117 100644 --- a/src/org/apollo/net/NetworkConstants.java +++ b/src/org/apollo/net/NetworkConstants.java @@ -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_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. */ diff --git a/src/org/apollo/net/codec/game/GamePacketReader.java b/src/org/apollo/net/codec/game/GamePacketReader.java index 12e8974f..22d94d12 100644 --- a/src/org/apollo/net/codec/game/GamePacketReader.java +++ b/src/org/apollo/net/codec/game/GamePacketReader.java @@ -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); } /** diff --git a/src/org/apollo/net/codec/login/LoginDecoder.java b/src/org/apollo/net/codec/login/LoginDecoder.java index 9049be2c..6b3193e3 100644 --- a/src/org/apollo/net/codec/login/LoginDecoder.java +++ b/src/org/apollo/net/codec/login/LoginDecoder.java @@ -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 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."); diff --git a/src/org/apollo/util/ByteBufferUtil.java b/src/org/apollo/util/BufferUtil.java similarity index 53% rename from src/org/apollo/util/ByteBufferUtil.java rename to src/org/apollo/util/BufferUtil.java index fa65e621..c5c10f65 100644 --- a/src/org/apollo/util/ByteBufferUtil.java +++ b/src/org/apollo/util/BufferUtil.java @@ -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() { } diff --git a/src/org/apollo/util/ByteBufUtil.java b/src/org/apollo/util/ByteBufUtil.java deleted file mode 100644 index 6873118c..00000000 --- a/src/org/apollo/util/ByteBufUtil.java +++ /dev/null @@ -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() { - - } - -} \ No newline at end of file