mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Add support for edited clients; Properly support chat filtering; Fix issue #11; Make certain Mining messages filterable.
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
require 'java'
|
||||
|
||||
java_import 'org.apollo.game.event.impl.ForwardPrivateMessageEvent'
|
||||
java_import 'org.apollo.game.model.World'
|
||||
java_import 'org.apollo.game.model.settings.PrivacyState'
|
||||
|
||||
on :command, :filter do |player, command|
|
||||
player.send_message('Your message filter is now ' + (player.toggle_message_filter ? 'enabled.' : 'disabled.'))
|
||||
end
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0"?>
|
||||
<plugin>
|
||||
<id>message-filter</id>
|
||||
<version>1</version>
|
||||
<name>Message Filter</name>
|
||||
<description>Adds support for a server-side message filter, for clients that have not been edited.</description>
|
||||
<authors>
|
||||
<author>Major</author>
|
||||
</authors>
|
||||
<scripts>
|
||||
<script>filter.rb</script>
|
||||
</scripts>
|
||||
<dependencies />
|
||||
</plugin>
|
||||
@@ -38,7 +38,7 @@ class MiningAction < DistancedAction
|
||||
# the ore
|
||||
def start_mine(pickaxe)
|
||||
@started = true
|
||||
mob.send_message "You swing your pick at the rock."
|
||||
mob.send_message("You swing your pick at the rock.", true)
|
||||
mob.turn_to @position
|
||||
mob.play_animation pickaxe.animation
|
||||
@counter = pickaxe.pulses
|
||||
@@ -51,14 +51,14 @@ class MiningAction < DistancedAction
|
||||
|
||||
# verify the mob can mine with their pickaxe
|
||||
if not (pickaxe != nil and level >= pickaxe.level)
|
||||
mob.send_message "You do not have a pickaxe for which you have the level to use."
|
||||
mob.send_message('You do not have a pickaxe for which you have the level to use.')
|
||||
stop
|
||||
return
|
||||
end
|
||||
|
||||
# verify the mob can mine the ore
|
||||
if ore.level > level
|
||||
mob.send_message "You do not have the required level to mine this rock."
|
||||
mob.send_message('You do not have the required level to mine this rock.')
|
||||
stop
|
||||
return
|
||||
end
|
||||
|
||||
@@ -66,6 +66,12 @@ public final class Player extends Mob {
|
||||
*/
|
||||
private transient Deque<Point> clicks = new ArrayDeque<Point>();
|
||||
|
||||
/**
|
||||
* The version of the client this player is using. This is not the same as the release number, instead denoting the
|
||||
* custom version.
|
||||
*/
|
||||
private transient int clientVersion;
|
||||
|
||||
/**
|
||||
* This player's credentials.
|
||||
*/
|
||||
@@ -181,6 +187,11 @@ public final class Player extends Mob {
|
||||
*/
|
||||
private transient int worldId = 1;
|
||||
|
||||
/**
|
||||
* Indicates whether this player has the message filter enabled.
|
||||
*/
|
||||
private boolean filteringMessages = false;
|
||||
|
||||
/**
|
||||
* Creates the {@link Player}.
|
||||
*
|
||||
@@ -290,6 +301,15 @@ public final class Player extends Mob {
|
||||
return clicks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value denoting the clients modified version (0 if it is an unmodified jagex client).
|
||||
*
|
||||
* @return The version.
|
||||
*/
|
||||
public int getClientVersion() {
|
||||
return clientVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player's credentials.
|
||||
*
|
||||
@@ -689,7 +709,7 @@ public final class Player extends Mob {
|
||||
* @param message The message.
|
||||
*/
|
||||
public void sendMessage(String message) {
|
||||
send(new ServerMessageEvent(message));
|
||||
sendMessage(message, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -698,7 +718,11 @@ public final class Player extends Mob {
|
||||
* @param message The message.
|
||||
*/
|
||||
public void sendMessage(String message, boolean filterable) {
|
||||
send(new ServerMessageEvent(message, filterable));
|
||||
if (clientVersion > 0) {
|
||||
send(new ServerMessageEvent(message, filterable));
|
||||
} else if (!filterable || !filteringMessages) {
|
||||
send(new ServerMessageEvent(message));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -752,6 +776,15 @@ public final class Player extends Mob {
|
||||
this.chatPrivacy = chatPrivacy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value denoting the client's modified version.
|
||||
*
|
||||
* @param clientVersion The client version.
|
||||
*/
|
||||
public void setClientVersion(int clientVersion) {
|
||||
this.clientVersion = clientVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the design flag.
|
||||
*
|
||||
@@ -906,6 +939,24 @@ public final class Player extends Mob {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the message filter.
|
||||
*
|
||||
* @return The new value of the filter.
|
||||
*/
|
||||
public boolean toggleMessageFilter() {
|
||||
return filteringMessages = !filteringMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the message filter is enabled.
|
||||
*
|
||||
* @return {@code true} if the filter is enabled, otherwise {@code false}.
|
||||
*/
|
||||
public boolean messageFilterEnabled() {
|
||||
return filteringMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles whether the player is running or not.
|
||||
*/
|
||||
|
||||
@@ -135,9 +135,7 @@ public final class LoginDecoder extends StatefulFrameDecoder<LoginDecoderState>
|
||||
private void decodePayload(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception {
|
||||
if (buffer.readableBytes() >= loginLength) {
|
||||
ByteBuf payload = buffer.readBytes(loginLength);
|
||||
if (payload.readUnsignedByte() != 0xFF) {
|
||||
throw new Exception("Invalid magic id.");
|
||||
}
|
||||
int clientVersion = 255 - payload.readUnsignedByte();
|
||||
|
||||
int releaseNumber = payload.readUnsignedShort();
|
||||
|
||||
@@ -195,13 +193,14 @@ public final class LoginDecoder extends StatefulFrameDecoder<LoginDecoderState>
|
||||
for (int i = 0; i < seed.length; i++) {
|
||||
seed[i] += 50;
|
||||
}
|
||||
|
||||
IsaacRandom encodingRandom = new IsaacRandom(seed);
|
||||
|
||||
PlayerCredentials credentials = new PlayerCredentials(username, password, usernameHash, uid);
|
||||
IsaacRandomPair randomPair = new IsaacRandomPair(encodingRandom, decodingRandom);
|
||||
|
||||
LoginRequest request = new LoginRequest(credentials, randomPair, reconnecting, lowMemory, releaseNumber,
|
||||
archiveCrcs);
|
||||
archiveCrcs, clientVersion);
|
||||
|
||||
out.add(request);
|
||||
if (buffer.isReadable()) {
|
||||
|
||||
@@ -15,6 +15,11 @@ public final class LoginRequest {
|
||||
*/
|
||||
private final int[] archiveCrcs;
|
||||
|
||||
/**
|
||||
* The version denoting whether the client has been modified or not.
|
||||
*/
|
||||
private final int clientVersion;
|
||||
|
||||
/**
|
||||
* The player's credentials.
|
||||
*/
|
||||
@@ -51,13 +56,14 @@ public final class LoginRequest {
|
||||
* @param archiveCrcs The archive CRCs.
|
||||
*/
|
||||
public LoginRequest(PlayerCredentials credentials, IsaacRandomPair randomPair, boolean lowMemory,
|
||||
boolean reconnecting, int releaseNumber, int[] archiveCrcs) {
|
||||
boolean reconnecting, int releaseNumber, int[] archiveCrcs, int clientVersion) {
|
||||
this.credentials = credentials;
|
||||
this.randomPair = randomPair;
|
||||
this.lowMemory = lowMemory;
|
||||
this.reconnecting = reconnecting;
|
||||
this.releaseNumber = releaseNumber;
|
||||
this.archiveCrcs = archiveCrcs;
|
||||
this.clientVersion = clientVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,6 +75,15 @@ public final class LoginRequest {
|
||||
return archiveCrcs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value denoting the client's (modified) version.
|
||||
*
|
||||
* @return The client version.
|
||||
*/
|
||||
public int getClientVersion() {
|
||||
return clientVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player's credentials.
|
||||
*
|
||||
|
||||
@@ -90,7 +90,7 @@ public final class LoginSession extends Session {
|
||||
Player player = response.getPlayer();
|
||||
int rights = player == null ? 0 : player.getPrivilegeLevel().toInteger();
|
||||
boolean log = false;
|
||||
|
||||
|
||||
if (player != null) {
|
||||
GameSession session = new GameSession(channel, serverContext, player);
|
||||
player.setSession(session, false /* TODO */);
|
||||
|
||||
Reference in New Issue
Block a user