Merge pull request #4 from kylestev/master.

Merge in IntelliJ + Maven support (mainly gitignore stuff) and Privacy Option packet implementation.
This commit is contained in:
Major-
2013-12-29 17:53:55 -08:00
11 changed files with 368 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
target/*
.idea/*
*.iml
data/fs/*
data/savedGames/*
+6
View File
@@ -1,4 +1,10 @@
<events>
<event>
<type>org.apollo.game.event.impl.PrivacyOptionEvent</type>
<chain>
<handler>org.apollo.game.event.handler.impl.PrivacyOptionEventHandler</handler>
</chain>
</event>
<event>
<type>org.apollo.game.event.impl.KeepAliveEvent</type>
<chain />
+37
View File
@@ -0,0 +1,37 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>apollo</artifactId>
<version>1.0</version>
<groupId>apollo-rsps</groupId>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-complete</artifactId>
<version>1.7.9</version>
</dependency>
<dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId> <!-- Use 'netty-all' for 4.0 or above -->
<version>3.3.0.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
</project>
@@ -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<PrivacyOptionEvent> {
@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());
}
}
@@ -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.
* <br />
* 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);
}
}
+128
View File
@@ -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.
*
@@ -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));
@@ -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());
@@ -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<PrivacyOptionEvent> {
@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);
}
}
@@ -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<PrivacyOptionEvent> {
@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();
}
}
@@ -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());
}
}