diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..f5f7ab5e --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +target/* +.idea/* +*.iml +data/fs/* +data/savedGames/* diff --git a/data/events.xml b/data/events.xml index f539d808..742f42d4 100644 --- a/data/events.xml +++ b/data/events.xml @@ -1,4 +1,10 @@ + + org.apollo.game.event.impl.PrivacyOptionEvent + + org.apollo.game.event.handler.impl.PrivacyOptionEventHandler + + org.apollo.game.event.impl.KeepAliveEvent diff --git a/pom.xml b/pom.xml new file mode 100644 index 00000000..22a1daf2 --- /dev/null +++ b/pom.xml @@ -0,0 +1,37 @@ + + 4.0.0 + apollo + 1.0 + apollo-rsps + + + org.apache.commons + commons-compress + 1.1 + + + org.jruby + jruby-complete + 1.7.9 + + + com.google.collections + google-collections + 1.0 + + + io.netty + netty + 3.3.0.Final + compile + + + junit + junit + 4.11 + + + \ No newline at end of file diff --git a/src/org/apollo/game/event/handler/impl/PrivacyOptionEventHandler.java b/src/org/apollo/game/event/handler/impl/PrivacyOptionEventHandler.java new file mode 100644 index 00000000..7630f8e1 --- /dev/null +++ b/src/org/apollo/game/event/handler/impl/PrivacyOptionEventHandler.java @@ -0,0 +1,22 @@ +package org.apollo.game.event.handler.impl; + +import org.apollo.game.event.handler.EventHandler; +import org.apollo.game.event.handler.EventHandlerContext; +import org.apollo.game.event.impl.PrivacyOptionEvent; +import org.apollo.game.model.Player; + +/** + * Handles {@link PrivacyOptionEvent} from the client to the server. + * + * @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()); + } +} diff --git a/src/org/apollo/game/event/impl/PrivacyOptionEvent.java b/src/org/apollo/game/event/impl/PrivacyOptionEvent.java new file mode 100644 index 00000000..eafdb2ab --- /dev/null +++ b/src/org/apollo/game/event/impl/PrivacyOptionEvent.java @@ -0,0 +1,98 @@ +package org.apollo.game.event.impl; + +import org.apollo.game.event.Event; +import org.apollo.game.model.Player; + +/** + * 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 + * + * @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; + + /** + * Trade/compete setting + */ + private final int tradeCompete; + + /** + * 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; + } + + /** + * Public chat unsigned byte value. + * + * @return The public chat unsigned byte. + */ + public int getPublicChat() { + return publicChat; + } + + /** + * Public chat privacy option. + * + * @return The public chat privacy option. + */ + public Player.PrivacyOption getPrivacyPublicChat() { + return Player.PrivacyOption.valueOf(publicChat); + } + + /** + * Private chat unsigned byte value. + * + * @return The private chat unsigned byte. + */ + public int getPrivateChat() { + return privateChat; + } + + /** + * Private chat privacy option. + * + * @return The private chat privacy option. + */ + public Player.PrivacyOption getPrivacyPrivateChat() { + return Player.PrivacyOption.valueOf(privateChat); + } + + /** + * 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); + } +} diff --git a/src/org/apollo/game/model/Player.java b/src/org/apollo/game/model/Player.java index 5c8bf896..949e6026 100644 --- a/src/org/apollo/game/model/Player.java +++ b/src/org/apollo/game/model/Player.java @@ -98,6 +98,80 @@ public final class Player extends Mob { } + /** + * 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. */ @@ -347,6 +421,33 @@ 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 the privilege level. * @@ -665,6 +766,33 @@ 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 privacy option for public chat. + * + * @param privacyPublicChat The privacy option. + */ + public void setPrivacyPublicChat(final PrivacyOption privacyPublicChat) { + this.privacyPublicChat = privacyPublicChat; + } + + /** + * Sets the privacy option for trade/compete. + * + * @param privacyTradeCompete The privacy option. + */ + public void setPrivacyTradeCompete(final PrivacyOption privacyTradeCompete) { + this.privacyTradeCompete = privacyTradeCompete; + } + /** * Sets the privilege level. * diff --git a/src/org/apollo/io/player/impl/BinaryPlayerLoader.java b/src/org/apollo/io/player/impl/BinaryPlayerLoader.java index 8fdd4a9d..599160b8 100644 --- a/src/org/apollo/io/player/impl/BinaryPlayerLoader.java +++ b/src/org/apollo/io/player/impl/BinaryPlayerLoader.java @@ -53,6 +53,11 @@ public final class BinaryPlayerLoader implements PlayerLoader { PrivilegeLevel privilegeLevel = PrivilegeLevel.valueOf(in.readByte()); 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()); + // read position int x = in.readUnsignedShort(); int y = in.readUnsignedShort(); @@ -75,6 +80,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.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 05420ca6..9182b667 100644 --- a/src/org/apollo/io/player/impl/BinaryPlayerSaver.java +++ b/src/org/apollo/io/player/impl/BinaryPlayerSaver.java @@ -33,6 +33,11 @@ public final class BinaryPlayerSaver implements PlayerSaver { out.writeByte(player.getPrivilegeLevel().toInteger()); out.writeBoolean(player.isMembers()); + // write settings + out.writeByte(player.getPrivacyPublicChat().toInteger()); + out.writeByte(player.getPrivacyPrivateChat().toInteger()); + out.writeByte(player.getPrivacyTradeCompete().toInteger()); + // write position Position position = player.getPosition(); out.writeShort(position.getX()); diff --git a/src/org/apollo/net/release/r317/PrivacyOptionEventDecoder.java b/src/org/apollo/net/release/r317/PrivacyOptionEventDecoder.java new file mode 100644 index 00000000..4f70275e --- /dev/null +++ b/src/org/apollo/net/release/r317/PrivacyOptionEventDecoder.java @@ -0,0 +1,27 @@ +package org.apollo.net.release.r317; + +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 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); + + final int publicChat = (int) reader.getUnsigned(DataType.BYTE); + final int privateChat = (int) reader.getUnsigned(DataType.BYTE); + final int tradeCompete = (int) reader.getUnsigned(DataType.BYTE); + + return new PrivacyOptionEvent(publicChat, privateChat, tradeCompete); + } +} diff --git a/src/org/apollo/net/release/r317/PrivacyOptionEventEncoder.java b/src/org/apollo/net/release/r317/PrivacyOptionEventEncoder.java new file mode 100644 index 00000000..9f75f321 --- /dev/null +++ b/src/org/apollo/net/release/r317/PrivacyOptionEventEncoder.java @@ -0,0 +1,28 @@ +package org.apollo.net.release.r317; + +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}. + * + * @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); + + builder.put(DataType.BYTE, event.getPublicChat()); + builder.put(DataType.BYTE, event.getPrivateChat()); + builder.put(DataType.BYTE, event.getTradeCompete()); + + return builder.toGamePacket(); + } +} diff --git a/src/org/apollo/net/release/r317/Release317.java b/src/org/apollo/net/release/r317/Release317.java index 9a903a67..90e0ca0a 100644 --- a/src/org/apollo/net/release/r317/Release317.java +++ b/src/org/apollo/net/release/r317/Release317.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; @@ -116,6 +117,8 @@ public final class Release317 extends Release { register(241, new MouseClickEventDecoder()); register(86, new ArrowKeyEventDecoder()); + register(95, new PrivacyOptionEventDecoder()); + SpamPacketEventDecoder spamEventDecoder = new SpamPacketEventDecoder(); register(77, spamEventDecoder); register(78, spamEventDecoder); @@ -154,6 +157,7 @@ public final class Release317 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