From e79772ec187948c002a040b2f88b2cfc06a6dda0 Mon Sep 17 00:00:00 2001 From: Major- Date: Mon, 30 Dec 2013 09:39:46 +0000 Subject: [PATCH] Fix poor conventions from pull request. --- .../impl/PrivacyOptionEventHandler.java | 22 +- .../game/event/impl/PrivacyOptionEvent.java | 134 +++++------ src/org/apollo/game/model/Gender.java | 14 +- src/org/apollo/game/model/Npc.java | 2 +- src/org/apollo/game/model/Player.java | 214 +++++++----------- src/org/apollo/game/model/PrivacyState.java | 69 ++++++ .../io/player/impl/BinaryPlayerLoader.java | 13 +- .../io/player/impl/BinaryPlayerSaver.java | 6 +- .../r317/PrivacyOptionEventDecoder.java | 26 +-- .../r317/PrivacyOptionEventEncoder.java | 29 ++- .../apollo/net/release/r317/Release317.java | 1 - .../r377/PrivacyOptionEventDecoder.java | 27 +++ .../r377/PrivacyOptionEventEncoder.java | 27 +++ .../apollo/net/release/r377/Release377.java | 3 + 14 files changed, 311 insertions(+), 276 deletions(-) create mode 100644 src/org/apollo/game/model/PrivacyState.java create mode 100644 src/org/apollo/net/release/r377/PrivacyOptionEventDecoder.java create mode 100644 src/org/apollo/net/release/r377/PrivacyOptionEventEncoder.java diff --git a/src/org/apollo/game/event/handler/impl/PrivacyOptionEventHandler.java b/src/org/apollo/game/event/handler/impl/PrivacyOptionEventHandler.java index 7630f8e1..98bec28c 100644 --- a/src/org/apollo/game/event/handler/impl/PrivacyOptionEventHandler.java +++ b/src/org/apollo/game/event/handler/impl/PrivacyOptionEventHandler.java @@ -6,17 +6,17 @@ import org.apollo.game.event.impl.PrivacyOptionEvent; import org.apollo.game.model.Player; /** - * Handles {@link PrivacyOptionEvent} from the client to the server. - * + * Handles {@link PrivacyOptionEvent}s from the client. + * * @author Kyle Stevenson - * Date: 12/24/13 - * Time: 2:03 AM */ public class PrivacyOptionEventHandler extends EventHandler { - @Override - public void handle(final EventHandlerContext ctx, final Player player, final PrivacyOptionEvent event) { - player.setPrivacyPublicChat(event.getPrivacyPublicChat()); - player.setPrivacyPrivateChat(event.getPrivacyPrivateChat()); - player.setPrivacyTradeCompete(event.getPrivacyTradeCompete()); - } -} + + @Override + public void handle(EventHandlerContext ctx, Player player, PrivacyOptionEvent event) { + player.setPublicChatPrivacy(event.getPublicChatPrivacy()); + player.setPrivateChatPrivacy(event.getPrivateChatPrivacy()); + player.setTradeChatPrivacy(event.getTradeChatPrivacy()); + } + +} \ No newline at end of file diff --git a/src/org/apollo/game/event/impl/PrivacyOptionEvent.java b/src/org/apollo/game/event/impl/PrivacyOptionEvent.java index eafdb2ab..822674ca 100644 --- a/src/org/apollo/game/event/impl/PrivacyOptionEvent.java +++ b/src/org/apollo/game/event/impl/PrivacyOptionEvent.java @@ -1,98 +1,68 @@ package org.apollo.game.event.impl; import org.apollo.game.event.Event; -import org.apollo.game.model.Player; +import org.apollo.game.model.PrivacyState; /** - * An {@link Event} sent by the client or server to specify the options at the bottom of the game screen relating - * to the chat and trade privacy options. - *
- * See http://rswiki.moparisthebest.com/index.php?title=317:Privacy_options - * + * An {@link Event} sent by the client or server to update the chat and trade privacy state. + * * @author Kyle Stevenson - * Date: 12/24/13 - * Time: 1:38 AM */ public class PrivacyOptionEvent extends Event { - /** - * Public chat setting - */ - private final int publicChat; - /** - * Private chat setting - */ - private final int privateChat; + /** + * The privacy state of the player's public chat. + */ + private final PrivacyState publicChatState; - /** - * Trade/compete setting - */ - private final int tradeCompete; + /** + * The privacy state of the player's private chat. + */ + private final PrivacyState privateChatState; - /** - * Creates a privacy option event. - * - * @param publicChat The byte value of the public chat privacy option. - * @param privateChat The byte value of the private chat privacy option. - * @param tradeCompete The byte value of the trade/compete privacy option. - */ - public PrivacyOptionEvent(final int publicChat, final int privateChat, final int tradeCompete) { - this.publicChat = publicChat & 0xFF; - this.privateChat = privateChat & 0xFF; - this.tradeCompete = tradeCompete & 0xFF; - } + /** + * The privacy state of the player's trade chat. + */ + private final PrivacyState tradeChatState; - /** - * Public chat unsigned byte value. - * - * @return The public chat unsigned byte. - */ - public int getPublicChat() { - return publicChat; - } + /** + * Creates a privacy option event. + * + * @param publicChatState The privacy state of the player's public chat. + * @param privateChatState The privacy state of the player's private chat. + * @param tradeChatState The privacy state of the player's trade chat. + */ + public PrivacyOptionEvent(int publicChatState, int privateChatState, int tradeChatState) { + this.publicChatState = PrivacyState.valueOf(publicChatState); + this.privateChatState = PrivacyState.valueOf(privateChatState); + this.tradeChatState = PrivacyState.valueOf(tradeChatState); + } - /** - * Public chat privacy option. - * - * @return The public chat privacy option. - */ - public Player.PrivacyOption getPrivacyPublicChat() { - return Player.PrivacyOption.valueOf(publicChat); - } + /** + * Gets the public chat {@link PrivacyState}. + * + * @return The privacy option. + */ + public PrivacyState getPublicChatPrivacy() { + return publicChatState; + } - /** - * Private chat unsigned byte value. - * - * @return The private chat unsigned byte. - */ - public int getPrivateChat() { - return privateChat; - } + /** + * Gets the private chat {@link PrivacyState}. + * + * @return The privacy option. + */ + public PrivacyState getPrivateChatPrivacy() { + return privateChatState; + } - /** - * Private chat privacy option. - * - * @return The private chat privacy option. - */ - public Player.PrivacyOption getPrivacyPrivateChat() { - return Player.PrivacyOption.valueOf(privateChat); - } + /** + * Gets the trade chat {@link PrivacyState}. + * + * @return The privacy option. + */ + public PrivacyState getTradeChatPrivacy() { + return tradeChatState; + } - /** - * Trade/compete unsigned byte value. - * - * @return The trade/compete unsigned byte. - */ - public int getTradeCompete() { - return tradeCompete; - } - - /** - * Trade/compete privacy option. - * - * @return The trade/compete privacy option. - */ - public Player.PrivacyOption getPrivacyTradeCompete() { - return Player.PrivacyOption.valueOf(tradeCompete); - } -} +} \ No newline at end of file diff --git a/src/org/apollo/game/model/Gender.java b/src/org/apollo/game/model/Gender.java index a22c650e..e75e42bb 100644 --- a/src/org/apollo/game/model/Gender.java +++ b/src/org/apollo/game/model/Gender.java @@ -18,26 +18,26 @@ public enum Gender { FEMALE(1); /** - * An integer representation used by the client. + * The numerical value used by the client. */ - private final int intValue; + private final int value; /** * Creates the gender. * - * @param intValue The integer representation. + * @param value The numerical value. */ - private Gender(int intValue) { - this.intValue = intValue; + private Gender(int value) { + this.value = value; } /** * Converts this gender to an integer. * - * @return The integer representation used by the client. + * @return The numerical value used by the client. */ public int toInteger() { - return intValue; + return value; } } \ No newline at end of file diff --git a/src/org/apollo/game/model/Npc.java b/src/org/apollo/game/model/Npc.java index 6cd54223..8d9048e4 100644 --- a/src/org/apollo/game/model/Npc.java +++ b/src/org/apollo/game/model/Npc.java @@ -47,7 +47,7 @@ public final class Npc extends Mob { */ public void transform(int id) { if (id < 0 || id > NpcDefinition.count()) { - throw new IllegalArgumentException("id to transform to is out of bounds"); + throw new IllegalArgumentException("Id to transform to is out of bounds"); } definition = NpcDefinition.lookup(id); blockSet.add(SynchronizationBlock.createTransformBlock(id)); diff --git a/src/org/apollo/game/model/Player.java b/src/org/apollo/game/model/Player.java index 1584a0cb..dcb7b3d5 100644 --- a/src/org/apollo/game/model/Player.java +++ b/src/org/apollo/game/model/Player.java @@ -60,31 +60,30 @@ public final class Player extends Mob { /** * Gets the privilege level for the specified numerical level. * - * @param numericalLevel The numerical level. + * @param value The numerical level. * @return The privilege level. * @throws IllegalArgumentException If the numerical level is invalid. */ - public static PrivilegeLevel valueOf(int numericalLevel) { - for (PrivilegeLevel level : values()) { - if (level.numericalLevel == numericalLevel) { - return level; - } + public static PrivilegeLevel valueOf(int value) { + PrivilegeLevel[] values = values(); + if (value < 0 || value > values.length) { + throw new IndexOutOfBoundsException("Invalid privilege level integer value supplied"); } - throw new IllegalArgumentException("invalid numerical level"); + return values[value]; } /** * The numerical level used in the protocol. */ - private final int numericalLevel; + private final int value; /** - * Creates a privilege level. + * Creates the privilege level. * - * @param numericalLevel The numerical level. + * @param value The numerical level. */ - private PrivilegeLevel(int numericalLevel) { - this.numericalLevel = numericalLevel; + private PrivilegeLevel(int value) { + this.value = value; } /** @@ -93,85 +92,11 @@ public final class Player extends Mob { * @return The numerical level used in the protocol. */ public int toInteger() { - return numericalLevel; + return value; } } - /** - * An enumeration representing the different states for chat and trade options in the protocol. - * - * @author Kyle Stevenson - */ - public enum PrivacyOption { - - /** - * Represents the on-state which displays all messages. - */ - ON(0), - - /** - * Represents the friends-state which only displays messages from friends and staff members. - */ - FRIENDS(1), - - /** - * Represents the off-state which displays no messages except those of moderators and staff members. - */ - OFF(2), - - /** - * Represents the hidden-state which displays text over player's heads but not in the chat box. - * This only applies to the "public" option. - */ - HIDE(3); - - /** - * Gets the privacy option for the specified numerical value. - * - * @param numericalValue The numerical level. - * @return The privilege level. - * @throws IllegalArgumentException If the numerical level is invalid. - */ - public static PrivacyOption valueOf(final int numericalValue) { - for (final PrivacyOption option : values()) { - if (option.numericalOption == numericalValue) { - return option; - } - } - throw new IllegalArgumentException("invalid numerical level"); - } - - /** - * The numerical level used in the protocol. - */ - private final int numericalOption; - - /** - * Creates a privacy option. - * - * @param numericalValue The numerical value. - */ - private PrivacyOption(final int numericalValue) { - this.numericalOption = numericalValue; - } - - /** - * Gets the numerical option. - * - * @return The numerical option used in the protocol. - */ - public int toInteger() { - return numericalOption; - } - } - - private PrivacyOption privacyPublicChat = PrivacyOption.ON; - - private PrivacyOption privacyPrivateChat = PrivacyOption.ON; - - private PrivacyOption privacyTradeCompete = PrivacyOption.ON; - /** * The player's appearance. */ @@ -232,11 +157,21 @@ public final class Player extends Mob { */ private int prayerIcon = 0; + /** + * The privacy state of this player's private chat. + */ + private PrivacyState privateChatPrivacy = PrivacyState.ON; + /** * The privilege level. */ private PrivilegeLevel privilegeLevel = PrivilegeLevel.STANDARD; + /** + * The privacy state of this player's public chat. + */ + private PrivacyState publicChatPrivacy = PrivacyState.ON; + /** * A temporary queue of events sent during the login process. */ @@ -262,6 +197,11 @@ public final class Player extends Mob { */ private GameSession session; + /** + * The privacy state of this player's trade chat. + */ + private PrivacyState tradeChatPrivacy = PrivacyState.ON; + /** * The current maximum viewing distance of this player. */ @@ -421,32 +361,14 @@ public final class Player extends Mob { return prayerIcon; } - /** - * Gets the privacy option of private chat. - * - * @return The privacy option. - */ - public PrivacyOption getPrivacyPrivateChat() { - return privacyPrivateChat; - } - - /** - * Gets the privacy option of public chat. - * - * @return The privacy option. - */ - public PrivacyOption getPrivacyPublicChat() { - return privacyPublicChat; - } - - /** - * Gets the privacy option of trade/compete. - * - * @return The privacy option. - */ - public PrivacyOption getPrivacyTradeCompete() { - return privacyTradeCompete; - } + /** + * Gets this player's private chat privacy state. + * + * @return The privacy state. + */ + public PrivacyState getPrivateChatPrivacy() { + return privateChatPrivacy; + } /** * Gets the privilege level. @@ -457,6 +379,15 @@ public final class Player extends Mob { return privilegeLevel; } + /** + * Gets this player's public chat privacy state. + * + * @return The privacy state. + */ + public PrivacyState getPublicChatPrivacy() { + return publicChatPrivacy; + } + /** * Gets the player's run energy. * @@ -475,6 +406,15 @@ public final class Player extends Mob { return session; } + /** + * Gets this player's trade chat privacy state. + * + * @return The privacy state. + */ + public PrivacyState getTradeChatPrivacy() { + return tradeChatPrivacy; + } + /** * Gets this player's viewing distance. * @@ -766,32 +706,32 @@ public final class Player extends Mob { this.prayerIcon = prayerIcon; } - /** - * Sets the privacy option for private chat. - * - * @param privacyPrivateChat The privacy option. - */ - public void setPrivacyPrivateChat(final PrivacyOption privacyPrivateChat) { - this.privacyPrivateChat = privacyPrivateChat; - } + /** + * Sets the private chat {@link PrivacyState}. + * + * @param privateChatPrivacy The privacy state. + */ + public void setPrivateChatPrivacy(PrivacyState privateChatPrivacy) { + this.privateChatPrivacy = privateChatPrivacy; + } - /** - * Sets the privacy option for public chat. - * - * @param privacyPublicChat The privacy option. - */ - public void setPrivacyPublicChat(final PrivacyOption privacyPublicChat) { - this.privacyPublicChat = privacyPublicChat; - } + /** + * Sets the public chat {@link PrivacyState}. + * + * @param publicChatPrivacy The privacy state. + */ + public void setPublicChatPrivacy(PrivacyState publicChatPrivacy) { + this.publicChatPrivacy = publicChatPrivacy; + } - /** - * Sets the privacy option for trade/compete. - * - * @param privacyTradeCompete The privacy option. - */ - public void setPrivacyTradeCompete(final PrivacyOption privacyTradeCompete) { - this.privacyTradeCompete = privacyTradeCompete; - } + /** + * Sets the trade chat {@link PrivacyState}. + * + * @param tradeChatPrivacy The privacy state. + */ + public void setTradeChatPrivacy(PrivacyState tradeChatPrivacy) { + this.tradeChatPrivacy = tradeChatPrivacy; + } /** * Sets the privilege level. diff --git a/src/org/apollo/game/model/PrivacyState.java b/src/org/apollo/game/model/PrivacyState.java new file mode 100644 index 00000000..c4f24884 --- /dev/null +++ b/src/org/apollo/game/model/PrivacyState.java @@ -0,0 +1,69 @@ +package org.apollo.game.model; + +/** + * An enumeration representing the different privacy states for public, private and trade chat. + * + * @author Kyle Stevenson + */ +public enum PrivacyState { + + /** + * Represents the 'friends' state, when only messages from friends and moderators are displayed. + */ + FRIENDS(2), + + /** + * Represents the 'hidden' state, when all public chat text is displayed over the heads of players, but not in the + * chat interface. This state only applies to public chat. + */ + HIDE(1), + + /** + * Represents the 'off' state, when only messages from moderators are displayed. + */ + OFF(3), + + /** + * Represents the 'on' state, when all messages are displayed. + */ + ON(0); + + /** + * Gets the privacy state for the specified numerical value. + * + * @param value The numerical value. + * @return The privacy state. + * @throws IllegalArgumentException If the numerical value is invalid. + */ + public static PrivacyState valueOf(int value) { + PrivacyState[] values = values(); + if (value < 0 || value >= values.length) { + throw new IllegalArgumentException("Invalid privacy option integer value specified"); + } + return values[value]; + } + + /** + * The numerical value used by the client. + */ + private final int value; + + /** + * Creates the privacy state. + * + * @param value The numerical value. + */ + private PrivacyState(int value) { + this.value = value; + } + + /** + * Converts this privacy state to an integer. + * + * @return The numerical value used by the client. + */ + public int toInteger() { + return value; + } + +} \ No newline at end of file diff --git a/src/org/apollo/io/player/impl/BinaryPlayerLoader.java b/src/org/apollo/io/player/impl/BinaryPlayerLoader.java index 599160b8..1127ec51 100644 --- a/src/org/apollo/io/player/impl/BinaryPlayerLoader.java +++ b/src/org/apollo/io/player/impl/BinaryPlayerLoader.java @@ -12,6 +12,7 @@ import org.apollo.game.model.Item; import org.apollo.game.model.Player; import org.apollo.game.model.Player.PrivilegeLevel; import org.apollo.game.model.Position; +import org.apollo.game.model.PrivacyState; import org.apollo.game.model.Skill; import org.apollo.game.model.SkillSet; import org.apollo.io.player.PlayerLoader; @@ -54,9 +55,9 @@ public final class BinaryPlayerLoader implements PlayerLoader { boolean members = in.readBoolean(); // read settings - Player.PrivacyOption privacyPublicChat = Player.PrivacyOption.valueOf(in.readByte()); - Player.PrivacyOption privacyPrivateChat = Player.PrivacyOption.valueOf(in.readByte()); - Player.PrivacyOption privacyTradeCompete = Player.PrivacyOption.valueOf(in.readByte()); + PrivacyState privacyPublicChat = PrivacyState.valueOf(in.readByte()); + PrivacyState privacyPrivateChat = PrivacyState.valueOf(in.readByte()); + PrivacyState privacyTradeCompete = PrivacyState.valueOf(in.readByte()); // read position int x = in.readUnsignedShort(); @@ -80,9 +81,9 @@ public final class BinaryPlayerLoader implements PlayerLoader { Player player = new Player(credentials, new Position(x, y, height)); player.setPrivilegeLevel(privilegeLevel); player.setMembers(members); - player.setPrivacyPublicChat(privacyPublicChat); - player.setPrivacyPrivateChat(privacyPrivateChat); - player.setPrivacyTradeCompete(privacyTradeCompete); + player.setPublicChatPrivacy(privacyPublicChat); + player.setPrivateChatPrivacy(privacyPrivateChat); + player.setTradeChatPrivacy(privacyTradeCompete); player.setDesigned(designed); player.setAppearance(new Appearance(gender, style, colors)); diff --git a/src/org/apollo/io/player/impl/BinaryPlayerSaver.java b/src/org/apollo/io/player/impl/BinaryPlayerSaver.java index 9182b667..ad38d9df 100644 --- a/src/org/apollo/io/player/impl/BinaryPlayerSaver.java +++ b/src/org/apollo/io/player/impl/BinaryPlayerSaver.java @@ -34,9 +34,9 @@ public final class BinaryPlayerSaver implements PlayerSaver { out.writeBoolean(player.isMembers()); // write settings - out.writeByte(player.getPrivacyPublicChat().toInteger()); - out.writeByte(player.getPrivacyPrivateChat().toInteger()); - out.writeByte(player.getPrivacyTradeCompete().toInteger()); + out.writeByte(player.getPublicChatPrivacy().toInteger()); + out.writeByte(player.getPrivateChatPrivacy().toInteger()); + out.writeByte(player.getTradeChatPrivacy().toInteger()); // write position Position position = player.getPosition(); diff --git a/src/org/apollo/net/release/r317/PrivacyOptionEventDecoder.java b/src/org/apollo/net/release/r317/PrivacyOptionEventDecoder.java index 4f70275e..96d6499a 100644 --- a/src/org/apollo/net/release/r317/PrivacyOptionEventDecoder.java +++ b/src/org/apollo/net/release/r317/PrivacyOptionEventDecoder.java @@ -8,20 +8,20 @@ import org.apollo.net.release.EventDecoder; /** * An {@link EventDecoder} for the {@link PrivacyOptionEvent}. - * + * * @author Kyle Stevenson - * Date: 12/24/13 - * Time: 1:44 AM */ -public class PrivacyOptionEventDecoder extends EventDecoder { - @Override - public PrivacyOptionEvent decode(final GamePacket packet) { - final GamePacketReader reader = new GamePacketReader(packet); +public final class PrivacyOptionEventDecoder extends EventDecoder { - final int publicChat = (int) reader.getUnsigned(DataType.BYTE); - final int privateChat = (int) reader.getUnsigned(DataType.BYTE); - final int tradeCompete = (int) reader.getUnsigned(DataType.BYTE); + @Override + public PrivacyOptionEvent decode(GamePacket packet) { + final GamePacketReader reader = new GamePacketReader(packet); - return new PrivacyOptionEvent(publicChat, privateChat, tradeCompete); - } -} + final int publicChatState = (int) reader.getUnsigned(DataType.BYTE); + final int privateChatState = (int) reader.getUnsigned(DataType.BYTE); + final int tradeChatState = (int) reader.getUnsigned(DataType.BYTE); + + return new PrivacyOptionEvent(publicChatState, privateChatState, tradeChatState); + } + +} \ No newline at end of file diff --git a/src/org/apollo/net/release/r317/PrivacyOptionEventEncoder.java b/src/org/apollo/net/release/r317/PrivacyOptionEventEncoder.java index 9f75f321..cf554b43 100644 --- a/src/org/apollo/net/release/r317/PrivacyOptionEventEncoder.java +++ b/src/org/apollo/net/release/r317/PrivacyOptionEventEncoder.java @@ -4,25 +4,24 @@ import org.apollo.game.event.impl.PrivacyOptionEvent; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; import org.apollo.net.release.EventEncoder; /** - * An {@link org.apollo.net.release.EventEncoder} for the {@link PrivacyOptionEvent}. - * + * An {@link EventEncoder} for the {@link PrivacyOptionEvent}. + * * @author Kyle Stevenson - * Date: 12/24/13 - * Time: 1:44 AM */ -public class PrivacyOptionEventEncoder extends EventEncoder { - @Override - public GamePacket encode(final PrivacyOptionEvent event) { - final GamePacketBuilder builder = new GamePacketBuilder(206, PacketType.FIXED); +public final class PrivacyOptionEventEncoder extends EventEncoder { - builder.put(DataType.BYTE, event.getPublicChat()); - builder.put(DataType.BYTE, event.getPrivateChat()); - builder.put(DataType.BYTE, event.getTradeCompete()); + @Override + public GamePacket encode(final PrivacyOptionEvent event) { + final GamePacketBuilder builder = new GamePacketBuilder(206); - return builder.toGamePacket(); - } -} + builder.put(DataType.BYTE, event.getPublicChatPrivacy().ordinal()); + builder.put(DataType.BYTE, event.getPrivateChatPrivacy().ordinal()); + builder.put(DataType.BYTE, event.getTradeChatPrivacy().ordinal()); + + return builder.toGamePacket(); + } + +} \ No newline at end of file diff --git a/src/org/apollo/net/release/r317/Release317.java b/src/org/apollo/net/release/r317/Release317.java index 90e0ca0a..cb6182a8 100644 --- a/src/org/apollo/net/release/r317/Release317.java +++ b/src/org/apollo/net/release/r317/Release317.java @@ -116,7 +116,6 @@ public final class Release317 extends Release { register(3, new FocusUpdateEventDecoder()); register(241, new MouseClickEventDecoder()); register(86, new ArrowKeyEventDecoder()); - register(95, new PrivacyOptionEventDecoder()); SpamPacketEventDecoder spamEventDecoder = new SpamPacketEventDecoder(); diff --git a/src/org/apollo/net/release/r377/PrivacyOptionEventDecoder.java b/src/org/apollo/net/release/r377/PrivacyOptionEventDecoder.java new file mode 100644 index 00000000..a423d0c5 --- /dev/null +++ b/src/org/apollo/net/release/r377/PrivacyOptionEventDecoder.java @@ -0,0 +1,27 @@ +package org.apollo.net.release.r377; + +import org.apollo.game.event.impl.PrivacyOptionEvent; +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.EventDecoder; + +/** + * An {@link EventDecoder} for the {@link PrivacyOptionEvent}. + * + * @author Major + */ +public final class PrivacyOptionEventDecoder extends EventDecoder { + + @Override + public PrivacyOptionEvent decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int publicChatState = (int) reader.getUnsigned(DataType.BYTE); + int privateChatState = (int) reader.getUnsigned(DataType.BYTE); + int tradeChatState = (int) reader.getUnsigned(DataType.BYTE); + + return new PrivacyOptionEvent(publicChatState, privateChatState, tradeChatState); + } + +} \ No newline at end of file diff --git a/src/org/apollo/net/release/r377/PrivacyOptionEventEncoder.java b/src/org/apollo/net/release/r377/PrivacyOptionEventEncoder.java new file mode 100644 index 00000000..72c699d0 --- /dev/null +++ b/src/org/apollo/net/release/r377/PrivacyOptionEventEncoder.java @@ -0,0 +1,27 @@ +package org.apollo.net.release.r377; + +import org.apollo.game.event.impl.PrivacyOptionEvent; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.release.EventEncoder; + +/** + * An {@link EventEncoder} for the {@link PrivacyOptionEvent}. + * + * @author Major + */ +public final class PrivacyOptionEventEncoder extends EventEncoder { + + @Override + public GamePacket encode(final PrivacyOptionEvent event) { + GamePacketBuilder builder = new GamePacketBuilder(201); + + builder.put(DataType.BYTE, event.getPublicChatPrivacy().ordinal()); + builder.put(DataType.BYTE, event.getPrivateChatPrivacy().ordinal()); + builder.put(DataType.BYTE, event.getTradeChatPrivacy().ordinal()); + + return builder.toGamePacket(); + } + +} \ No newline at end of file diff --git a/src/org/apollo/net/release/r377/Release377.java b/src/org/apollo/net/release/r377/Release377.java index d2bc5d1c..8430d0c4 100644 --- a/src/org/apollo/net/release/r377/Release377.java +++ b/src/org/apollo/net/release/r377/Release377.java @@ -11,6 +11,7 @@ import org.apollo.game.event.impl.OpenInterfaceEvent; import org.apollo.game.event.impl.OpenInterfaceSidebarEvent; import org.apollo.game.event.impl.PlayerSynchronizationEvent; import org.apollo.game.event.impl.PositionEvent; +import org.apollo.game.event.impl.PrivacyOptionEvent; import org.apollo.game.event.impl.RegionChangeEvent; import org.apollo.game.event.impl.ServerMessageEvent; import org.apollo.game.event.impl.SetTileItemEvent; @@ -115,6 +116,7 @@ public final class Release377 extends Release { register(187, new FocusUpdateEventDecoder()); register(19, new MouseClickEventDecoder()); register(140, new ArrowKeyEventDecoder()); + register(176, new PrivacyOptionEventDecoder()); SpamPacketEventDecoder spamEventDecoder = new SpamPacketEventDecoder(); register(40, spamEventDecoder); @@ -151,6 +153,7 @@ public final class Release377 extends Release { register(SetTileItemEvent.class, new SetTileItemEventEncoder()); register(PositionEvent.class, new PositionEventEncoder()); register(UpdateRunEnergyEvent.class, new UpdateRunEnergyEventEncoder()); + register(PrivacyOptionEvent.class, new PrivacyOptionEventEncoder()); } } \ No newline at end of file