mirror of
https://github.com/2006-Scape/2006Scape.git
synced 2026-07-03 00:31:51 +00:00
Network cleanup (#552)
* Replaced packetType/Size with packet * Replace Instream with Packet Read data directly from packet to ease future network upgrade * Update Packet.java Removed unused methods to ease netty migration and network rewrite. * Moved packet sizes. * Removed unused stream methods * Added readhex method for buttons * preparing to replace mina * Packet->GamePacket for refactoring * Netty 3.6.6 * formatting * formatting * Apollo core * Update net.xml Added variables for 2006scape * Netty 4 migration. Jagcached replaced with Apollo Core * Porting network into apollo * WIP Packet Changes Do not merge. This is broken. * Packet read methods converted to netty buffer * Replacing game network and login with apollo * Netty 4 * Cleanup * Same port for update and game server. * Cleanup login for integration with apollo * Login works. fixing packets * Running on apollo netcode. * Server runs * Update apollo-core.jar * Disable encoder. write outstream directly to channel. * Update RS2ProtocolDecoder.java Added apollo decoder * Add constant * Synchronization not needed * Update apollo-core.jar * Better performance. * Commit pre PR * Update apollo-core.jar * Fixup Port Binding Based On World * Apollo files * Additional Commit --------- Co-authored-by: Dark98 <darkaidz98@gmail.com>
This commit is contained in:
@@ -13,10 +13,10 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.apollo.jagcached.FileServer;
|
||||
|
||||
import com.rs2.game.bots.BotHandler;
|
||||
import org.apache.mina.common.IoAcceptor;
|
||||
import org.apache.mina.transport.socket.nio.SocketAcceptor;
|
||||
import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.rs2.event.CycleEventHandler;
|
||||
import com.rs2.game.content.minigames.FightCaves;
|
||||
import com.rs2.game.content.minigames.FightPits;
|
||||
@@ -37,8 +37,6 @@ import com.rs2.integrations.PlayersOnlineWebsite;
|
||||
import com.rs2.integrations.RegisteredAccsWebsite;
|
||||
import com.rs2.integrations.discord.DiscordActivity;
|
||||
import com.rs2.integrations.discord.JavaCord;
|
||||
import com.rs2.net.ConnectionHandler;
|
||||
import com.rs2.net.ConnectionThrottleFilter;
|
||||
import com.rs2.tick.Scheduler;
|
||||
import com.rs2.tick.Tick;
|
||||
import com.rs2.util.HostBlacklist;
|
||||
@@ -48,7 +46,9 @@ import com.rs2.world.ObjectHandler;
|
||||
import com.rs2.world.ObjectManager;
|
||||
import com.rs2.world.clip.ObjectDefinition;
|
||||
import com.rs2.world.clip.RegionFactory;
|
||||
import org.apollo.jagcached.FileServer;
|
||||
|
||||
import io.netty.util.ResourceLeakDetector;
|
||||
import io.netty.util.ResourceLeakDetector.Level;
|
||||
|
||||
/**
|
||||
* Server.java
|
||||
@@ -111,13 +111,9 @@ public class GameEngine {
|
||||
public static boolean sleeping;
|
||||
public static boolean updateServer = false;
|
||||
public static long lastMassSave = System.currentTimeMillis();
|
||||
private static IoAcceptor acceptor;
|
||||
private static ConnectionHandler connectionHandler;
|
||||
private static ConnectionThrottleFilter throttleFilter;
|
||||
public static boolean shutdownServer = false;
|
||||
public static int garbageCollectDelay = 40;
|
||||
public static boolean shutdownClientHandler;
|
||||
private static int serverlistenerPort;
|
||||
public static ItemHandler itemHandler = new ItemHandler();
|
||||
public static PlayerHandler playerHandler = new PlayerHandler();
|
||||
public static NpcHandler npcHandler = new NpcHandler();
|
||||
@@ -152,7 +148,6 @@ public class GameEngine {
|
||||
}
|
||||
}
|
||||
}
|
||||
serverlistenerPort = (GameConstants.WORLD == 1) ? 43594 : 43596 + GameConstants.WORLD;
|
||||
|
||||
System.out.println("Starting game engine..");
|
||||
if (GameConstants.SERVER_DEBUG) {
|
||||
@@ -177,18 +172,6 @@ public class GameEngine {
|
||||
*/
|
||||
System.out.println("Launching " + GameConstants.SERVER_NAME + " World: " + GameConstants.WORLD + "...");
|
||||
|
||||
/**
|
||||
* Starts The File Server If Enabled In GameConstants
|
||||
*/
|
||||
if (GameConstants.FILE_SERVER) {
|
||||
FileServer fs = new FileServer();
|
||||
try {
|
||||
fs.start();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start Integration Services
|
||||
**/
|
||||
@@ -198,17 +181,15 @@ public class GameEngine {
|
||||
/**
|
||||
* Accepting Connections
|
||||
*/
|
||||
acceptor = new SocketAcceptor();
|
||||
connectionHandler = new ConnectionHandler();
|
||||
|
||||
SocketAcceptorConfig sac = new SocketAcceptorConfig();
|
||||
sac.getSessionConfig().setTcpNoDelay(false);
|
||||
sac.setReuseAddress(true);
|
||||
sac.setBacklog(100);
|
||||
|
||||
throttleFilter = new ConnectionThrottleFilter(GameConstants.CONNECTION_DELAY);
|
||||
sac.getFilterChain().addFirst("throttleFilter", throttleFilter);
|
||||
acceptor.bind(new InetSocketAddress(serverlistenerPort), connectionHandler, sac);
|
||||
//TODO debug ResourceLeakDetector.setLevel(Level.PARANOID);
|
||||
ResourceLeakDetector.setLevel(Level.DISABLED);
|
||||
FileServer fs = new FileServer();
|
||||
try {
|
||||
fs.start();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise Handlers
|
||||
@@ -232,7 +213,7 @@ public class GameEngine {
|
||||
/**
|
||||
* Server Successfully Loaded
|
||||
*/
|
||||
System.out.println("Server listening on port " + serverlistenerPort);
|
||||
System.out.println("World Server listening on " + fs.service.toString());
|
||||
|
||||
/**
|
||||
* Main Server Tick
|
||||
@@ -245,6 +226,7 @@ public class GameEngine {
|
||||
*/
|
||||
scheduler.scheduleAtFixedRate(new Runnable() {
|
||||
public void run() {
|
||||
//TODO debug Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
/**
|
||||
* Main Server Tick
|
||||
*/
|
||||
@@ -298,6 +280,7 @@ public class GameEngine {
|
||||
}
|
||||
scheduler.shutdown(); // Kills the tickloop thread if Exception is thrown.
|
||||
}
|
||||
//TODO debug System.out.println("Cycle took " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms.");
|
||||
}
|
||||
}, 0, GameConstants.CYCLE_TIME, TimeUnit.MILLISECONDS);
|
||||
|
||||
@@ -316,9 +299,6 @@ public class GameEngine {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
acceptor = null;
|
||||
connectionHandler = null;
|
||||
sac = null;
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,19 +5,23 @@ import static com.rs2.game.players.PlayerSave.loadPlayerInfo;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
|
||||
import com.rs2.GameConstants;
|
||||
import com.rs2.GameEngine;
|
||||
import com.rs2.game.items.ItemAssistant;
|
||||
import com.rs2.game.players.Client;
|
||||
import com.rs2.util.Misc;
|
||||
import com.rs2.util.Stream;
|
||||
|
||||
public class Bot {
|
||||
|
||||
private Client botClient;
|
||||
static Timer timer = new Timer();
|
||||
|
||||
private Stream inStream;
|
||||
|
||||
public Bot(String username, Integer x, Integer y, Integer z) {
|
||||
botClient = new Client(null);
|
||||
|
||||
inStream = new Stream(new byte[GameConstants.BUFFER_SIZE]);
|
||||
inStream.currentOffset = 0;
|
||||
botClient.playerName = username;
|
||||
botClient.playerName2 = botClient.playerName;
|
||||
botClient.properName = Character.toUpperCase(username.charAt(1)) + username.substring(2);
|
||||
@@ -78,10 +82,10 @@ public class Bot {
|
||||
// Normal chat from here down:
|
||||
botClient.setChatTextColor(Misc.random(11));
|
||||
botClient.setChatTextEffects(Misc.random(5));
|
||||
Misc.textPack(botClient.inStream, _message);
|
||||
botClient.setChatTextSize((byte) botClient.inStream.currentOffset);
|
||||
botClient.setChatText(botClient.inStream.buffer);
|
||||
botClient.inStream.currentOffset = 0;
|
||||
Misc.textPack(inStream, _message);
|
||||
botClient.setChatTextSize((byte) inStream.currentOffset);
|
||||
botClient.setChatText(inStream.buffer);
|
||||
inStream.currentOffset = 0;
|
||||
botClient.setChatTextUpdateRequired(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.rs2.game.dialogues;
|
||||
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
|
||||
/**
|
||||
@@ -10,7 +11,7 @@ import com.rs2.net.packets.PacketType;
|
||||
public class Dialogue implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player c, int packetType, int packetSize) {
|
||||
public void processPacket(Player c, Packet packet) {
|
||||
if (c.nextChat > 0) {
|
||||
c.getDialogueHandler().sendDialogues(c.nextChat, c.talkingNpc);
|
||||
} else {
|
||||
|
||||
@@ -1,30 +1,32 @@
|
||||
package com.rs2.game.players;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
import org.apollo.game.session.GameSession;
|
||||
|
||||
import com.rs2.GameConstants;
|
||||
import com.rs2.util.Stream;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
|
||||
public class Client extends Player {
|
||||
|
||||
public Client(IoSession s, int _playerId) {
|
||||
public Client(GameSession s, int _playerId) {
|
||||
super(_playerId);
|
||||
session = s;
|
||||
outStream = new Stream(new byte[GameConstants.BUFFER_SIZE]);
|
||||
outStream.currentOffset = 0;
|
||||
inStream = new Stream(new byte[GameConstants.BUFFER_SIZE]);
|
||||
inStream.currentOffset = 0;
|
||||
buffer = new byte[GameConstants.BUFFER_SIZE];
|
||||
}
|
||||
|
||||
//bots
|
||||
public Client(IoSession s) {
|
||||
public Client(GameSession s) {
|
||||
super(-1);
|
||||
isBot = true;
|
||||
session = null;
|
||||
inStream = new Stream(new byte[GameConstants.BUFFER_SIZE]);
|
||||
inStream.currentOffset = 0;
|
||||
buffer = new byte[GameConstants.BUFFER_SIZE];
|
||||
}
|
||||
|
||||
public void setSession(GameSession session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,21 +51,26 @@ import com.rs2.game.npcs.NpcHandler;
|
||||
import com.rs2.game.npcs.impl.Pets;
|
||||
import com.rs2.game.objects.ObjectsActions;
|
||||
import com.rs2.game.shops.ShopAssistant;
|
||||
import com.rs2.net.HostList;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.Packet.Type;
|
||||
import com.rs2.net.PacketSender;
|
||||
import com.rs2.net.StaticPacketBuilder;
|
||||
import com.rs2.net.packets.PacketHandler;
|
||||
import com.rs2.net.packets.impl.ChallengePlayer;
|
||||
import com.rs2.plugin.PluginService;
|
||||
import com.rs2.util.ISAACRandomGen;
|
||||
import com.rs2.util.Misc;
|
||||
import com.rs2.util.Stream;
|
||||
import com.rs2.world.Boundary;
|
||||
import com.rs2.world.ObjectManager;
|
||||
import org.apache.mina.common.IoSession;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
||||
import org.apollo.game.session.GameSession;
|
||||
import org.apollo.util.security.IsaacRandom;
|
||||
|
||||
public abstract class Player {
|
||||
|
||||
@@ -85,8 +90,8 @@ public abstract class Player {
|
||||
private SpecialPlantOne specialPlantOne = new SpecialPlantOne(this);
|
||||
private SpecialPlantTwo specialPlantTwo = new SpecialPlantTwo(this);
|
||||
private ToolLeprechaun toolLeprechaun = new ToolLeprechaun(this);
|
||||
public Stream inStream = null, outStream = null;
|
||||
public IoSession session;
|
||||
public Stream outStream = null;
|
||||
public GameSession session;
|
||||
private final ItemAssistant itemAssistant = new ItemAssistant(this);
|
||||
private final ShopAssistant shopAssistant = new ShopAssistant(this);
|
||||
private final MageTrainingArena mageArena = new MageTrainingArena(this);
|
||||
@@ -96,7 +101,7 @@ public abstract class Player {
|
||||
private final CombatAssistant combatAssistant = new CombatAssistant(this);
|
||||
private final ObjectsActions actionHandler = new ObjectsActions(this);
|
||||
private final NpcActions npcs = new NpcActions(this);
|
||||
private final Queue<Packet> queuedPackets = new LinkedList<Packet>();
|
||||
private final BlockingQueue<Packet> queuedPackets = new ArrayBlockingQueue<Packet>(25);
|
||||
private final Potions potions = new Potions(this);
|
||||
private final PotionMixing potionMixing = new PotionMixing(this);
|
||||
private final EmoteHandler emoteHandler = new EmoteHandler(this);
|
||||
@@ -356,18 +361,6 @@ public abstract class Player {
|
||||
return bankPin;
|
||||
}
|
||||
|
||||
public synchronized Stream getInStream() {
|
||||
return inStream;
|
||||
}
|
||||
|
||||
public synchronized int getPacketType() {
|
||||
return packetType;
|
||||
}
|
||||
|
||||
public synchronized int getPacketSize() {
|
||||
return packetSize;
|
||||
}
|
||||
|
||||
public synchronized Stream getOutStream() {
|
||||
return outStream;
|
||||
}
|
||||
@@ -412,7 +405,7 @@ public abstract class Player {
|
||||
return npcs;
|
||||
}
|
||||
|
||||
public IoSession getSession() {
|
||||
public GameSession getSession() {
|
||||
return session;
|
||||
}
|
||||
|
||||
@@ -534,17 +527,21 @@ public abstract class Player {
|
||||
}
|
||||
|
||||
public void flushOutStream() {
|
||||
if (disconnected || outStream == null || outStream.currentOffset == 0) {
|
||||
if (!session.isActive() || disconnected || outStream == null || outStream.currentOffset == 0) {
|
||||
return;
|
||||
}
|
||||
synchronized (this) {
|
||||
StaticPacketBuilder out = new StaticPacketBuilder().setBare(true);
|
||||
byte[] temp = new byte[outStream.currentOffset];
|
||||
System.arraycopy(outStream.buffer, 0, temp, 0, temp.length);
|
||||
out.addBytes(temp);
|
||||
session.write(out.toPacket());
|
||||
|
||||
// Packet packet = new Packet(-1, Type.FIXED, Unpooled.wrappedBuffer(temp));
|
||||
// session.write(packet);
|
||||
session.write(Unpooled.buffer().writeBytes(temp));
|
||||
outStream.currentOffset = 0;
|
||||
}
|
||||
|
||||
|
||||
// ByteBuf buffer = Unpooled.buffer();
|
||||
// buffer.writeBytes(temp);
|
||||
|
||||
}
|
||||
|
||||
public void sendClan(String name, String message, String clan, int rights) {
|
||||
@@ -558,34 +555,6 @@ public abstract class Player {
|
||||
}
|
||||
}
|
||||
|
||||
public static final int PACKET_SIZES[] = { 0, 0, 0, 1, -1, 0, 0, 0, 0, 0, // 0
|
||||
0, 0, 0, 0, 8, 0, 6, 2, 2, 0, // 10
|
||||
0, 2, 0, 6, 0, 12, 0, 0, 0, 0, // 20
|
||||
0, 0, 0, 0, 0, 8, 4, 0, 0, 2, // 30
|
||||
2, 6, 0, 6, 0, -1, 0, 0, 0, 0, // 40
|
||||
0, 0, 0, 12, 0, 0, 0, 8, 8, 12, // 50
|
||||
8, 8, 0, 0, 0, 0, 0, 0, 0, 0, // 60
|
||||
6, 0, 2, 2, 8, 6, 0, -1, 0, 6, // 70
|
||||
0, 0, 0, 0, 0, 1, 4, 6, 0, 0, // 80
|
||||
0, 0, 0, 0, 0, 3, 0, 0, -1, 0, // 90
|
||||
0, 13, 0, -1, 0, 0, 0, 0, 0, 0,// 100
|
||||
0, 0, 0, 0, 0, 0, 0, 6, 0, 0, // 110
|
||||
1, 0, 6, 0, 0, 0, -1, 0, 2, 6, // 120
|
||||
0, 4, 6, 8, 0, 6, 0, 0, 0, 2, // 130
|
||||
0, 0, 0, 0, 0, 6, 0, 0, 0, 0, // 140
|
||||
0, 0, 1, 2, 0, 2, 6, 0, 0, 0, // 150
|
||||
0, 0, 0, 0, -1, -1, 0, 0, 0, 0,// 160
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 170
|
||||
0, 8, 0, 3, 0, 2, 0, 0, 8, 1, // 180
|
||||
0, 0, 12, 0, 0, 0, 0, 0, 0, 0, // 190
|
||||
2, 0, 0, 0, 0, 0, 0, 0, 4, 0, // 200
|
||||
4, 0, 0, 0, 7, 8, 0, 0, 10, 0, // 210
|
||||
0, 0, 0, 0, 0, 0, -1, 0, 6, 0, // 220
|
||||
1, 0, 0, 0, 6, 0, 6, 8, 1, 0, // 230
|
||||
0, 4, 0, 0, 0, 0, -1, 0, -1, 4,// 240
|
||||
0, 0, 6, 6, 0, 0, 0 // 250
|
||||
};
|
||||
|
||||
public void destruct() {
|
||||
if (session == null) {
|
||||
return;
|
||||
@@ -636,12 +605,11 @@ public abstract class Player {
|
||||
}
|
||||
|
||||
Misc.println("[DEREGISTERED]: " + playerName + "");
|
||||
HostList.getHostList().remove(session);
|
||||
// HostList.getHostList().remove(session);
|
||||
CycleEventHandler.getSingleton().stopEvents(this);
|
||||
disconnected = true;
|
||||
session.close();
|
||||
session = null;
|
||||
inStream = null;
|
||||
outStream = null;
|
||||
isActive = false;
|
||||
buffer = null;
|
||||
@@ -787,7 +755,6 @@ public abstract class Player {
|
||||
return eventProvider;
|
||||
}
|
||||
|
||||
public int packetSize = 0, packetType = -1;
|
||||
public boolean wildernessWarning;
|
||||
public int axeAnimation = -1;
|
||||
|
||||
@@ -1099,42 +1066,18 @@ public abstract class Player {
|
||||
}
|
||||
|
||||
public void queueMessage(Packet arg1) {
|
||||
queuedPackets.add(arg1);
|
||||
if (queuedPackets.size() < 25) {
|
||||
queuedPackets.add(arg1);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized boolean processQueuedPackets() {
|
||||
Packet p = null;
|
||||
synchronized (queuedPackets) {
|
||||
p = queuedPackets.poll();
|
||||
}
|
||||
if (p == null) {
|
||||
return false;
|
||||
}
|
||||
inStream.currentOffset = 0;
|
||||
packetType = p.getId();
|
||||
packetSize = p.getLength();
|
||||
inStream.buffer = p.getData();
|
||||
if (packetType > 0) {
|
||||
PacketHandler.processPacket(this, packetType, packetSize);
|
||||
}
|
||||
timeOutCounter = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
public synchronized boolean processPacket(Packet p) {
|
||||
synchronized (this) {
|
||||
if (p == null) {
|
||||
return false;
|
||||
}
|
||||
inStream.currentOffset = 0;
|
||||
packetType = p.getId();
|
||||
packetSize = p.getLength();
|
||||
inStream.buffer = p.getData();
|
||||
if (packetType > 0) {
|
||||
PacketHandler.processPacket(this, packetType, packetSize);
|
||||
public void processQueuedPackets() {
|
||||
while (!queuedPackets.isEmpty()) {
|
||||
Packet p = queuedPackets.poll();
|
||||
if (p.getOpcode() > 0) {
|
||||
PacketHandler.processPacket(this, p);
|
||||
}
|
||||
timeOutCounter = 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3140,11 +3083,11 @@ public abstract class Player {
|
||||
return newWalkCmdIsRunning;
|
||||
}
|
||||
|
||||
public void setInStreamDecryption(ISAACRandomGen inStreamDecryption) {
|
||||
public void setInStreamDecryption(IsaacRandom inStreamDecryption) {
|
||||
|
||||
}
|
||||
|
||||
public void setOutStreamDecryption(ISAACRandomGen outStreamDecryption) {
|
||||
public void setOutStreamDecryption(IsaacRandom outStreamDecryption) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +110,6 @@ public class PlayerHandler {
|
||||
}
|
||||
|
||||
public void process() {
|
||||
// synchronized (PlayerHandler.players) {
|
||||
updatePlayerNames();
|
||||
if (kickAllPlayers) {
|
||||
for (int i = 0; i < PlayerHandler.players.length; i++) {
|
||||
@@ -182,9 +181,7 @@ public class PlayerHandler {
|
||||
}
|
||||
|
||||
|
||||
while (players[i].processQueuedPackets()) {
|
||||
;
|
||||
}
|
||||
players[i].processQueuedPackets();
|
||||
|
||||
players[i].process();
|
||||
players[i].postProcessing();
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.rs2.net;
|
||||
|
||||
import org.apache.mina.filter.codec.ProtocolCodecFactory;
|
||||
import org.apache.mina.filter.codec.ProtocolDecoder;
|
||||
import org.apache.mina.filter.codec.ProtocolEncoder;
|
||||
|
||||
/**
|
||||
* Provides access to the encoders and decoders for the 508 protocol.
|
||||
*
|
||||
* @author Graham
|
||||
*/
|
||||
public class CodecFactory implements ProtocolCodecFactory {
|
||||
|
||||
/**
|
||||
* The encoder.
|
||||
*/
|
||||
private final ProtocolEncoder encoder = new RS2ProtocolEncoder();
|
||||
|
||||
/**
|
||||
* The decoder.
|
||||
*/
|
||||
private final ProtocolDecoder decoder = new RS2LoginProtocolDecoder();
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Get the encoder.
|
||||
*/
|
||||
public ProtocolEncoder getEncoder() throws Exception {
|
||||
return encoder;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Get the decoder.
|
||||
*/
|
||||
public ProtocolDecoder getDecoder() throws Exception {
|
||||
return decoder;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,63 +1,76 @@
|
||||
package com.rs2.net;
|
||||
|
||||
import org.apache.mina.common.IdleStatus;
|
||||
import org.apache.mina.common.IoHandler;
|
||||
import org.apache.mina.common.IoSession;
|
||||
import org.apache.mina.filter.codec.ProtocolCodecFilter;
|
||||
|
||||
import com.rs2.game.players.Client;
|
||||
|
||||
public class ConnectionHandler implements IoHandler {
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(IoSession arg0, Throwable arg1)
|
||||
throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageReceived(IoSession arg0, Object arg1) throws Exception {
|
||||
if (arg0.getAttachment() != null) {
|
||||
Client plr = (Client) arg0.getAttachment();
|
||||
plr.queueMessage((Packet) arg1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageSent(IoSession arg0, Object arg1) throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sessionClosed(IoSession arg0) throws Exception {
|
||||
if (arg0.getAttachment() != null) {
|
||||
Client plr = (Client) arg0.getAttachment();
|
||||
plr.disconnected = true;
|
||||
}
|
||||
HostList.getHostList().remove(arg0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sessionCreated(IoSession arg0) throws Exception {
|
||||
if (!HostList.getHostList().add(arg0)) {
|
||||
arg0.close();
|
||||
} else {
|
||||
arg0.setAttribute("inList", Boolean.TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sessionIdle(IoSession arg0, IdleStatus arg1) throws Exception {
|
||||
arg0.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sessionOpened(IoSession arg0) throws Exception {
|
||||
arg0.setIdleTime(IdleStatus.BOTH_IDLE, 60);
|
||||
arg0.getFilterChain().addLast("protocolFilter",
|
||||
new ProtocolCodecFilter(new CodecFactory()));
|
||||
}
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
|
||||
/**
|
||||
* Old class that was used with netty 4 impl. This is no longer needed but will be a reference for re-adding the HostList stuff into the ApolloHandler.
|
||||
* @author Advocatus
|
||||
*
|
||||
*/
|
||||
public class ConnectionHandler extends ChannelInboundHandlerAdapter {
|
||||
|
||||
//// public static final AttributeKey<Session> SESSION_KEY = AttributeKey.valueOf("session");
|
||||
//
|
||||
// private Session session = null;
|
||||
//
|
||||
//// @Override
|
||||
//// public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) {
|
||||
//// if (session == null) {
|
||||
//// session = new Session(ctx.getChannel());
|
||||
//// if (!HostList.getHostList().add(session)) {
|
||||
//// ctx.getChannel().close();
|
||||
//// } else {
|
||||
//// session.setInList(true);
|
||||
//// }
|
||||
//// }
|
||||
//// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public void channelInactive(ChannelHandlerContext ctx) {
|
||||
// if (session != null) {
|
||||
// // HostList.getHostList().remove(session);
|
||||
// Client client = session.getClient();
|
||||
// if (client != null) {
|
||||
// client.disconnected = true;
|
||||
// }
|
||||
// session = null;
|
||||
// }
|
||||
// Channel channel = ctx.channel();
|
||||
// channel.close();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void exceptionCaught(ChannelHandlerContext ctx, Throwable e) {
|
||||
// if (!e.getMessage().contains("An existing connection was forcibly closed by the remote host")) {
|
||||
// e.printStackTrace();
|
||||
// // logger.log(Level.WARNING, "Exception occured for channel: " + ctx.channel() + ", closing...", e);
|
||||
// }
|
||||
// ctx.channel().close();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void channelRead(ChannelHandlerContext ctx, Object message) throws Exception {
|
||||
//// System.out.println(message.getClass());
|
||||
// if (session == null) {
|
||||
// session = new Session(ctx.channel());
|
||||
//// if (!HostList.getHostList().add(session)) {
|
||||
//// ctx.channel().close();
|
||||
//// } else {
|
||||
//// session.setInList(true);
|
||||
//// }
|
||||
// }
|
||||
// if (message instanceof Client) {
|
||||
// session.setClient((Client) message);
|
||||
// } else if (message instanceof Packet) {
|
||||
// if (session.getClient() != null) {
|
||||
// session.getClient().queueMessage((Packet) message);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void channelReadComplete(ChannelHandlerContext ctx) {
|
||||
// ctx.flush();
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
package com.rs2.net;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.mina.common.IoFilter;
|
||||
import org.apache.mina.common.IoFilterAdapter;
|
||||
import org.apache.mina.common.IoSession;
|
||||
|
||||
/**
|
||||
* A {@link IoFilter} which blocks connections from connecting at a rate faster
|
||||
* than the specified interval.
|
||||
*
|
||||
* @author The Apache MINA Project (dev@mina.apache.org)
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
public class ConnectionThrottleFilter extends IoFilterAdapter {
|
||||
|
||||
private long allowedInterval;
|
||||
private final Map<InetAddress, Long> clients;
|
||||
private final Map<InetAddress, Integer> counts;
|
||||
private final Set<InetAddress> connectedAddresses;
|
||||
|
||||
/**
|
||||
* Constructor that takes in a specified wait time.
|
||||
*
|
||||
* @param allowedInterval
|
||||
* The number of milliseconds a client is allowed to wait before
|
||||
* making another successful connection
|
||||
*/
|
||||
public ConnectionThrottleFilter(long allowedInterval) {
|
||||
this.allowedInterval = allowedInterval;
|
||||
clients = Collections.synchronizedMap(new HashMap<InetAddress, Long>());
|
||||
counts = Collections
|
||||
.synchronizedMap(new HashMap<InetAddress, Integer>());
|
||||
connectedAddresses = new HashSet<InetAddress>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the interval between connections from a client. This value is
|
||||
* measured in milliseconds.
|
||||
*
|
||||
* @param allowedInterval
|
||||
* The number of milliseconds a client is allowed to wait before
|
||||
* making another successful connection
|
||||
*/
|
||||
public void setAllowedInterval(long allowedInterval) {
|
||||
this.allowedInterval = allowedInterval;
|
||||
}
|
||||
|
||||
public void delayClient(IoSession session, int delay) {
|
||||
long d = System.currentTimeMillis() - delay;
|
||||
clients.put(getAddress(session), d);
|
||||
}
|
||||
|
||||
private InetAddress getAddress(IoSession io) {
|
||||
return ((InetSocketAddress) io.getRemoteAddress()).getAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method responsible for deciding if a connection is OK to continue
|
||||
*
|
||||
* @param session
|
||||
* The new session that will be verified
|
||||
* @return True if the session meets the criteria, otherwise false
|
||||
*/
|
||||
public boolean isConnectionOk(IoSession session) {
|
||||
InetAddress addr = getAddress(session);
|
||||
long now = System.currentTimeMillis();
|
||||
if (clients.containsKey(addr)) {
|
||||
long lastConnTime = clients.get(addr);
|
||||
|
||||
if (now - lastConnTime < allowedInterval) {
|
||||
int c = 0;
|
||||
if (!counts.containsKey(addr)) {
|
||||
counts.put(addr, 0);
|
||||
} else {
|
||||
c = counts.get(addr) + 1;
|
||||
}
|
||||
if (c >= 350) {
|
||||
|
||||
c = 0;
|
||||
}
|
||||
counts.put(addr, c);
|
||||
// Logger.err("["+host+"] Session dropped (delay="+(now-lastConnTime)+"ms)");
|
||||
return false;
|
||||
} else {
|
||||
clients.put(addr, now);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
clients.put(addr, now);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void closedSession(IoSession io) {
|
||||
connectedAddresses.remove(getAddress(io));
|
||||
}
|
||||
|
||||
public void acceptedLogin(IoSession io) {
|
||||
connectedAddresses.add(getAddress(io));
|
||||
}
|
||||
|
||||
public boolean isConnected(IoSession io) {
|
||||
return connectedAddresses.contains(getAddress(io));
|
||||
}
|
||||
|
||||
public int[] getSizes() {
|
||||
return new int[] { clients.size(), counts.size(),
|
||||
connectedAddresses.size() };
|
||||
}
|
||||
|
||||
public void connectionOk(IoSession io) {
|
||||
counts.remove(getAddress(io));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sessionCreated(NextFilter nextFilter, IoSession session)
|
||||
throws Exception {
|
||||
if (!isConnectionOk(session)) {
|
||||
session.close();
|
||||
return;
|
||||
}
|
||||
nextFilter.sessionCreated(session);
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package com.rs2.net;
|
||||
|
||||
import org.apache.mina.filter.codec.ProtocolCodecFactory;
|
||||
import org.apache.mina.filter.codec.ProtocolDecoder;
|
||||
import org.apache.mina.filter.codec.ProtocolEncoder;
|
||||
|
||||
import com.rs2.util.ISAACRandomGen;
|
||||
|
||||
/**
|
||||
* Provides access to the encoders and decoders for the 508 protocol.
|
||||
*
|
||||
* @author Graham
|
||||
*/
|
||||
public class GameCodecFactory implements ProtocolCodecFactory {
|
||||
|
||||
/**
|
||||
* The encoder.
|
||||
*/
|
||||
private final ProtocolEncoder encoder = new RS2ProtocolEncoder();
|
||||
|
||||
/**
|
||||
* The decoder.
|
||||
*/
|
||||
private final ProtocolDecoder decoder;
|
||||
|
||||
public GameCodecFactory(ISAACRandomGen inC) {
|
||||
decoder = new RS2ProtocolDecoder(inC);
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Get the encoder.
|
||||
*/
|
||||
public ProtocolEncoder getEncoder() throws Exception {
|
||||
return encoder;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Get the decoder.
|
||||
*/
|
||||
public ProtocolDecoder getDecoder() throws Exception {
|
||||
return decoder;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.rs2.net;
|
||||
|
||||
/**
|
||||
* An enumeration with the different states the {@link GamePacketDecoder} can be in.
|
||||
*
|
||||
* @author Graham
|
||||
*/
|
||||
public enum GameDecoderState {
|
||||
|
||||
/**
|
||||
* The game length state waits for the packet length. Once it has been received, it sets the state to the payload
|
||||
* state.
|
||||
*/
|
||||
GAME_LENGTH,
|
||||
|
||||
/**
|
||||
* The game opcode state waits for an encrypted opcode. It decrypts it, and will either set the next state to the
|
||||
* length (if the packet is variably- sized) or the payload (if it is not variably-sized) state.
|
||||
*/
|
||||
GAME_OPCODE,
|
||||
|
||||
/**
|
||||
* The payload state will wait for the whole packet to be received. Then, it will pass a {@link GamePacket} object
|
||||
* to Netty and reset the state back to the game opcode state, ready for the next packet.
|
||||
*/
|
||||
GAME_PAYLOAD;
|
||||
|
||||
}
|
||||
@@ -1,57 +1,90 @@
|
||||
package com.rs2.net;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
|
||||
import com.rs2.Connection;
|
||||
import com.rs2.GameConstants;
|
||||
|
||||
public class HostList {
|
||||
|
||||
private static HostList list = new HostList();
|
||||
|
||||
public static HostList getHostList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
private final Map<String, Integer> connections = new HashMap<String, Integer>();
|
||||
|
||||
public synchronized boolean add(IoSession session) {
|
||||
String addr = ((InetSocketAddress) session.getRemoteAddress())
|
||||
.getAddress().getHostAddress();
|
||||
Integer amt = connections.get(addr);
|
||||
if (amt == null) {
|
||||
amt = 1;
|
||||
} else {
|
||||
amt += 1;
|
||||
}
|
||||
if (amt > GameConstants.IPS_ALLOWED || Connection.isIpBanned(addr)) {
|
||||
return false;
|
||||
} else {
|
||||
connections.put(addr, amt);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void remove(IoSession session) {
|
||||
if (session.getAttribute("inList") != Boolean.TRUE) {
|
||||
return;
|
||||
}
|
||||
String addr = ((InetSocketAddress) session.getRemoteAddress())
|
||||
.getAddress().getHostAddress();
|
||||
Integer amt = connections.get(addr);
|
||||
if (amt == null) {
|
||||
return;
|
||||
}
|
||||
amt -= 1;
|
||||
if (amt <= 0) {
|
||||
connections.remove(addr);
|
||||
} else {
|
||||
connections.put(addr, amt);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// private final Map<InetAddress, Long> clients;
|
||||
//
|
||||
// private HostList() {
|
||||
// clients = Collections.synchronizedMap(new HashMap<InetAddress, Long>());
|
||||
// }
|
||||
//
|
||||
// private static HostList list = new HostList();
|
||||
//
|
||||
// public static HostList getHostList() {
|
||||
// return list;
|
||||
// }
|
||||
//
|
||||
// private final Map<String, Integer> connections = new HashMap<String, Integer>();
|
||||
//
|
||||
// public synchronized boolean add(Session session) {
|
||||
// if(!isConnectionOk(session)) {
|
||||
// return false;
|
||||
// }
|
||||
// String addr = ((InetSocketAddress) session.getChannel().remoteAddress()).getAddress().getHostAddress();
|
||||
// Integer amt = connections.get(addr);
|
||||
// if (amt == null) {
|
||||
// amt = 1;
|
||||
// } else {
|
||||
// amt += 1;
|
||||
// }
|
||||
// if (amt > GameConstants.IPS_ALLOWED || Connection.isIpBanned(addr)) {
|
||||
// return false;
|
||||
// } else {
|
||||
// connections.put(addr, amt);
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public synchronized void remove(Session session) {
|
||||
// if (!session.isInList()) {
|
||||
// return;
|
||||
// }
|
||||
// String addr = ((InetSocketAddress) session.getChannel().remoteAddress())
|
||||
// .getAddress().getHostAddress();
|
||||
// Integer amt = connections.get(addr);
|
||||
// if (amt == null) {
|
||||
// return;
|
||||
// }
|
||||
// amt -= 1;
|
||||
// if (amt <= 0) {
|
||||
// connections.remove(addr);
|
||||
// } else {
|
||||
// connections.put(addr, amt);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private InetAddress getAddress(Session io) {
|
||||
// return ((InetSocketAddress) io.getChannel().remoteAddress()).getAddress();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Method responsible for deciding if a connection is OK to continue
|
||||
// *
|
||||
// * @param session
|
||||
// * The new session that will be verified
|
||||
// * @return True if the session meets the criteria, otherwise false
|
||||
// */
|
||||
// private boolean isConnectionOk(Session session) {
|
||||
// InetAddress addr = getAddress(session);
|
||||
// long now = System.currentTimeMillis();
|
||||
// if (clients.containsKey(addr)) {
|
||||
// long lastConnTime = clients.get(addr);
|
||||
//
|
||||
// if (now - lastConnTime < GameConstants.CONNECTION_DELAY) {
|
||||
// System.out.println("["+addr+"] Session dropped (delay="+(now-lastConnTime)+"ms)");
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// clients.put(addr, now);
|
||||
// return true;
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -1,304 +1,472 @@
|
||||
package com.rs2.net;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
/**
|
||||
* Immutable packet object.
|
||||
* Represents a single packet.
|
||||
*
|
||||
* @author Graham Edgecombe
|
||||
*
|
||||
* @author Graham
|
||||
*/
|
||||
public final class Packet {
|
||||
|
||||
public static enum Size {
|
||||
Fixed, VariableByte, VariableShort
|
||||
};
|
||||
public class Packet {
|
||||
|
||||
/**
|
||||
* The associated IO session
|
||||
*/
|
||||
private final IoSession session;
|
||||
/**
|
||||
* The ID of the packet
|
||||
*/
|
||||
private final int pID;
|
||||
/**
|
||||
* The length of the payload
|
||||
*/
|
||||
private final int pLength;
|
||||
/**
|
||||
* The payload
|
||||
*/
|
||||
private final byte[] pData;
|
||||
/**
|
||||
* The current index into the payload buffer for reading
|
||||
*/
|
||||
private int caret = 0;
|
||||
/**
|
||||
* Whether this packet is without the standard packet header
|
||||
*/
|
||||
private final boolean bare;
|
||||
private Size size = Size.Fixed;
|
||||
|
||||
public Packet(IoSession session, int pID, byte[] pData, boolean bare, Size s) {
|
||||
this.session = session;
|
||||
this.pID = pID;
|
||||
this.pData = pData;
|
||||
pLength = pData.length;
|
||||
this.bare = bare;
|
||||
size = s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new packet with the specified parameters.
|
||||
* The type of packet.
|
||||
*
|
||||
* @author Graham Edgecombe
|
||||
*
|
||||
* @param session
|
||||
* The session to associate with the packet
|
||||
* @param pID
|
||||
* The ID of the packet
|
||||
* @param pData
|
||||
* The payload of the packet
|
||||
* @param bare
|
||||
* Whether this packet is bare, which means that it does not
|
||||
* include the standard packet header
|
||||
*/
|
||||
public Packet(IoSession session, int pID, byte[] pData, boolean bare) {
|
||||
this(session, pID, pData, bare, Size.Fixed);
|
||||
public enum Type {
|
||||
|
||||
/**
|
||||
* A fixed size packet where the size never changes.
|
||||
*/
|
||||
FIXED,
|
||||
|
||||
/**
|
||||
* A variable packet where the size is described by a byte.
|
||||
*/
|
||||
VARIABLE,
|
||||
|
||||
/**
|
||||
* A variable packet where the size is described by a word.
|
||||
*/
|
||||
VARIABLE_SHORT;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new packet with the specified parameters. The packet is
|
||||
* considered not to be a bare packet.
|
||||
*
|
||||
* @param session
|
||||
* The session to associate with the packet
|
||||
* @param pID
|
||||
* The ID of the packet
|
||||
* @param pData
|
||||
* The payload the packet
|
||||
* The opcode.
|
||||
*/
|
||||
public Packet(IoSession session, int pID, byte[] pData) {
|
||||
this(session, pID, pData, false);
|
||||
private final int opcode;
|
||||
|
||||
/**
|
||||
* The type.
|
||||
*/
|
||||
private final Type type;
|
||||
|
||||
/**
|
||||
* The payload.
|
||||
*/
|
||||
private final ByteBuf payload;
|
||||
|
||||
/**
|
||||
* Creates a packet.
|
||||
*
|
||||
* @param opcode The opcode.
|
||||
* @param type The type.
|
||||
* @param payload The payload.
|
||||
*/
|
||||
public Packet(final int opcode, final Type type, final ByteBuf payload) {
|
||||
this.opcode = opcode;
|
||||
this.type = type;
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the IO session associated with the packet, if any.
|
||||
* Checks if this packet is raw. A raw packet does not have the usual headers
|
||||
* such as opcode or size.
|
||||
*
|
||||
* @return The <code>IoSession</code> object, or <code>null</code> if none.
|
||||
* @return <code>true</code> if so, <code>false</code> if not.
|
||||
*/
|
||||
public IoSession getSession() {
|
||||
return session;
|
||||
public boolean isRaw() {
|
||||
return opcode == -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this packet is considered to be a bare packet, which means that
|
||||
* it does not include the standard packet header (ID and length values).
|
||||
* Gets the opcode.
|
||||
*
|
||||
* @return Whether this packet is a bare packet
|
||||
* @return The opcode.
|
||||
*/
|
||||
public boolean isBare() {
|
||||
return bare;
|
||||
}
|
||||
|
||||
public Size getSize() {
|
||||
return size;
|
||||
public int getOpcode() {
|
||||
return opcode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the packet ID.
|
||||
* Gets the type.
|
||||
*
|
||||
* @return The packet ID
|
||||
* @return The type.
|
||||
*/
|
||||
public int getId() {
|
||||
return pID;
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of the payload of this packet.
|
||||
* Gets the payload.
|
||||
*
|
||||
* @return The length of the packet's payload
|
||||
* @return The payload.
|
||||
*/
|
||||
public ByteBuf getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the length.
|
||||
*
|
||||
* @return The length.
|
||||
*/
|
||||
public int getLength() {
|
||||
return pLength;
|
||||
return payload.capacity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entire payload data of this packet.
|
||||
* Reads a single byte.
|
||||
*
|
||||
* @return The payload <code>byte</code> array
|
||||
* @return A single byte.
|
||||
*/
|
||||
public byte[] getData() {
|
||||
return pData;
|
||||
public byte get() {
|
||||
return payload.readByte();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the remaining payload data of this packet.
|
||||
* Reads several bytes.
|
||||
*
|
||||
* @return The payload <code>byte</code> array
|
||||
* @param b The target array.
|
||||
*/
|
||||
public byte[] getRemainingData() {
|
||||
byte[] data = new byte[pLength - caret];
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
data[i] = pData[i + caret];
|
||||
}
|
||||
caret += data.length;
|
||||
return data;
|
||||
|
||||
public void get(final byte[] b) {
|
||||
payload.readBytes(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the next <code>byte</code> from the payload.
|
||||
* Reads a byte.
|
||||
*
|
||||
* @return A <code>byte</code>
|
||||
* @return A single byte.
|
||||
*/
|
||||
public byte readByte() {
|
||||
return pData[caret++];
|
||||
public byte getByte() {
|
||||
return get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the next <code>short</code> from the payload.
|
||||
* Reads an unsigned byte.
|
||||
*
|
||||
* @return A <code>short</code>
|
||||
* @return An unsigned byte.
|
||||
*/
|
||||
public short readShort() {
|
||||
return (short) ((short) ((pData[caret++] & 0xff) << 8) | (short) (pData[caret++] & 0xff));
|
||||
public int getUnsignedByte() {
|
||||
return payload.readByte() & 0xff;
|
||||
}
|
||||
|
||||
public int readLEShortA() {
|
||||
int i = (pData[caret++] - 128 & 0xff) + ((pData[caret++] & 0xff) << 8);
|
||||
if (i > 32767) {
|
||||
/**
|
||||
* Reads a short.
|
||||
*
|
||||
* @return A short.
|
||||
*/
|
||||
public short getShort() {
|
||||
return payload.readShort();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an unsigned short.
|
||||
*
|
||||
* @return An unsigned short.
|
||||
*/
|
||||
public int getUnsignedShort() {
|
||||
int value = 0;
|
||||
value |= (get() & 0xff) << 8;
|
||||
value |= (get() & 0xff);
|
||||
return value;
|
||||
}
|
||||
|
||||
public int getUnsignedShortA() {
|
||||
int value = 0;
|
||||
value |= (get() & 0xff) << 8;
|
||||
value |= ((get() - 128) & 0xff);
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an integer.
|
||||
*
|
||||
* @return An integer.
|
||||
*/
|
||||
public int getInt() {
|
||||
return payload.readInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a long.
|
||||
*
|
||||
* @return A long.
|
||||
*/
|
||||
public long getLong() {
|
||||
return payload.readLong();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a type C byte.
|
||||
*
|
||||
* @return A type C byte.
|
||||
*/
|
||||
public byte getByteC() {
|
||||
return (byte) (-get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a type S byte.
|
||||
*
|
||||
* @return A type S byte.
|
||||
*/
|
||||
public byte getByteS() {
|
||||
return (byte) (128 - get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a little-endian type A short.
|
||||
*
|
||||
* @return A little-endian type A short.
|
||||
*/
|
||||
public short getLEShortA() {
|
||||
int i = (get() - 128 & 0xFF) | ((get() & 0xFF) << 8);
|
||||
if (i > 32767)
|
||||
i -= 0x10000;
|
||||
}
|
||||
return i;
|
||||
return (short) i;
|
||||
}
|
||||
|
||||
public int readLEShort() {
|
||||
int i = (pData[caret++] & 0xff) + ((pData[caret++] & 0xff) << 8);
|
||||
if (i > 32767) {
|
||||
/**
|
||||
* Reads a little-endian short.
|
||||
*
|
||||
* @return A little-endian short.
|
||||
*/
|
||||
public short getLEShort() {
|
||||
int i = (get() & 0xFF) | ((get() & 0xFF) << 8);
|
||||
if (i > 32767)
|
||||
i -= 0x10000;
|
||||
return (short) i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a V1 integer.
|
||||
*
|
||||
* @return A V1 integer.
|
||||
*/
|
||||
public int getInt1() {
|
||||
final byte b1 = get();
|
||||
final byte b2 = get();
|
||||
final byte b3 = get();
|
||||
final byte b4 = get();
|
||||
return ((b3 << 24) & 0xFF) | ((b4 << 16) & 0xFF) | ((b1 << 8) & 0xFF) | (b2 & 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a V2 integer.
|
||||
*
|
||||
* @return A V2 integer.
|
||||
*/
|
||||
public int getInt2() {
|
||||
final int b1 = get() & 0xFF;
|
||||
final int b2 = get() & 0xFF;
|
||||
final int b3 = get() & 0xFF;
|
||||
final int b4 = get() & 0xFF;
|
||||
return ((b2 << 24) & 0xFF) | ((b1 << 16) & 0xFF) | ((b4 << 8) & 0xFF) | (b3 & 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a 3-byte integer.
|
||||
*
|
||||
* @return The 3-byte integer.
|
||||
*/
|
||||
public int getTriByte() {
|
||||
return ((get() << 16) & 0xFF) | ((get() << 8) & 0xFF) | (get() & 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a type A byte.
|
||||
*
|
||||
* @return A type A byte.
|
||||
*/
|
||||
public byte getByteA() {
|
||||
return (byte) (get() - 128);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a RuneScape string.
|
||||
*
|
||||
* @return The string.
|
||||
*/
|
||||
public String getRS2String() {
|
||||
byte temp;
|
||||
StringBuilder b = new StringBuilder();
|
||||
while ((temp = payload.readByte()) != 10) {
|
||||
b.append((char) temp);
|
||||
}
|
||||
return i;
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the next <code>int</code> from the payload.
|
||||
* Reads a type A short.
|
||||
*
|
||||
* @return An <code>int</code>
|
||||
* @return A type A short.
|
||||
*/
|
||||
public int readInt() {
|
||||
return (pData[caret++] & 0xff) << 24 | (pData[caret++] & 0xff) << 16
|
||||
| (pData[caret++] & 0xff) << 8 | pData[caret++] & 0xff;
|
||||
}
|
||||
|
||||
public int readLEInt() {
|
||||
return pData[caret++] & 0xff | (pData[caret++] & 0xff) << 8
|
||||
| (pData[caret++] & 0xff) << 16 | (pData[caret++] & 0xff) << 24;
|
||||
public short getShortA() {
|
||||
int i = ((get() & 0xFF) << 8) | (get() - 128 & 0xFF);
|
||||
if (i > 32767)
|
||||
i -= 0x10000;
|
||||
return (short) i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the next <code>long</code> from the payload.
|
||||
* Reads a series of bytes in reverse.
|
||||
*
|
||||
* @return A <code>long</code>
|
||||
* @param is The target byte array.
|
||||
* @param offset The offset.
|
||||
* @param length The length.
|
||||
*/
|
||||
public long readLong() {
|
||||
return (long) (pData[caret++] & 0xff) << 56
|
||||
| (long) (pData[caret++] & 0xff) << 48
|
||||
| (long) (pData[caret++] & 0xff) << 40
|
||||
| (long) (pData[caret++] & 0xff) << 32
|
||||
| (long) (pData[caret++] & 0xff) << 24
|
||||
| (long) (pData[caret++] & 0xff) << 16
|
||||
| (long) (pData[caret++] & 0xff) << 8 | pData[caret++] & 0xff;
|
||||
public void getReverse(final byte[] is, final int offset, final int length) {
|
||||
for (int i = (offset + length - 1); i >= offset; i--)
|
||||
is[i] = get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the string which is formed by the unread portion of the payload.
|
||||
* Reads a series of type A bytes in reverse.
|
||||
*
|
||||
* @return A <code>String</code>
|
||||
* @param is The target byte array.
|
||||
* @param offset The offset.
|
||||
* @param length The length.
|
||||
*/
|
||||
public void getReverseA(final byte[] is, final int offset, final int length) {
|
||||
for (int i = (offset + length - 1); i >= offset; i--)
|
||||
is[i] = getByteA();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a series of bytes.
|
||||
*
|
||||
* @param is The target byte array.
|
||||
* @param offset The offset.
|
||||
* @param length The length.
|
||||
*/
|
||||
public void get(final byte[] is, final int offset, final int length) {
|
||||
for (int i = 0; i < length; i++)
|
||||
is[offset + i] = get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a smart.
|
||||
*
|
||||
* @return The smart.
|
||||
*/
|
||||
public int getSmart() {
|
||||
final int peek = payload.getByte(payload.readerIndex());
|
||||
if (peek < 128)
|
||||
return (get() & 0xFF);
|
||||
else
|
||||
return (getShort() & 0xFFFF) - 32768;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a signed smart.
|
||||
*
|
||||
* @return The signed smart.
|
||||
*/
|
||||
public int getSignedSmart() {
|
||||
final int peek = payload.getByte(payload.readerIndex());
|
||||
if (peek < 128)
|
||||
return ((get() & 0xFF) - 64);
|
||||
else
|
||||
return ((getShort() & 0xFFFF) - 49152);
|
||||
}
|
||||
|
||||
/* Legacy methods here */
|
||||
|
||||
public int readUnsignedByte() {
|
||||
return get() & 0xff;
|
||||
}
|
||||
|
||||
public byte readSignedByte() {
|
||||
return get();
|
||||
}
|
||||
|
||||
public byte readSignedByteC() {
|
||||
return (byte) -get();
|
||||
}
|
||||
|
||||
public int readUnsignedByteS() {
|
||||
return 128 - get() & 0xff;
|
||||
}
|
||||
|
||||
public int readHex() {
|
||||
return ((get() & 0xFF) * 1000) + (get() & 0xFF);
|
||||
}
|
||||
|
||||
public void readBytes(byte abyte0[], int length, int offset) {
|
||||
for (int i = 0; i < length; i++)
|
||||
abyte0[offset + i] = get();
|
||||
}
|
||||
|
||||
public void readBytes_reverseA(byte abyte0[], int length, int offset) {
|
||||
for (int i = (offset + length - 1); i >= offset; i--)
|
||||
abyte0[i] = getByteA();
|
||||
}
|
||||
|
||||
public String readString() {
|
||||
return readString(pLength - caret);
|
||||
}
|
||||
|
||||
public String readRS2String() {
|
||||
int start = caret;
|
||||
while (pData[caret++] != 0) {
|
||||
;
|
||||
byte temp;
|
||||
StringBuilder b = new StringBuilder();
|
||||
while ((temp = payload.readByte()) != 10) {
|
||||
b.append((char) temp);
|
||||
}
|
||||
return new String(pData, start, caret - start - 1);
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
public void readBytes(byte[] buf, int off, int len) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
buf[off + i] = pData[caret++];
|
||||
public int readDWord() {
|
||||
return ((readUnsignedByte()) << 24) + ((readUnsignedByte()) << 16) + ((readUnsignedByte()) << 8) + (readUnsignedByte());
|
||||
}
|
||||
|
||||
public long readQWord() {
|
||||
long l = readDWord() & 0xffffffffL;
|
||||
long l1 = readDWord() & 0xffffffffL;
|
||||
return (l << 32) + l1;
|
||||
}
|
||||
|
||||
public long readQWord2() {
|
||||
final long l = readDWord() & 0xffffffffL;
|
||||
final long l1 = readDWord() & 0xffffffffL;
|
||||
return (l << 32) + l1;
|
||||
}
|
||||
|
||||
public int readSignedWordA() {
|
||||
int i = ((readUnsignedByte()) << 8) + (get() - 128 & 0xff);
|
||||
if (i > 32767) {
|
||||
i -= 0x10000;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a string of the specified length from the payload.
|
||||
*
|
||||
* @param length
|
||||
* The length of the string to be read
|
||||
* @return A <code>String</code>
|
||||
*/
|
||||
public String readString(int length) {
|
||||
String rv = new String(pData, caret, length);
|
||||
caret += length;
|
||||
return rv;
|
||||
public int readUnsignedWordA() {
|
||||
return ((readUnsignedByte()) << 8) + (get() - 128 & 0xff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips the specified number of bytes in the payload.
|
||||
*
|
||||
* @param x
|
||||
* The number of bytes to be skipped
|
||||
*/
|
||||
public void skip(int x) {
|
||||
caret += x;
|
||||
public int readUnsignedWord() {
|
||||
return ((readUnsignedByte()) << 8) + (readUnsignedByte());
|
||||
}
|
||||
|
||||
public int remaining() {
|
||||
return pData.length - caret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this packet in string form.
|
||||
*
|
||||
* @return A <code>String</code> representing this packet
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("[id=" + pID + ",len=" + pLength + ",data=0x");
|
||||
for (int x = 0; x < pLength; x++) {
|
||||
sb.append(byteToHex(pData[x], true));
|
||||
public int readSignedWord() {
|
||||
int i = ((readUnsignedByte()) << 8) + (readUnsignedByte());
|
||||
if (i > 32767) {
|
||||
i -= 0x10000;
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
return i;
|
||||
}
|
||||
|
||||
private static String byteToHex(byte b, boolean forceLeadingZero) {
|
||||
StringBuilder out = new StringBuilder();
|
||||
int ub = b & 0xff;
|
||||
if (ub / 16 > 0 || forceLeadingZero) {
|
||||
out.append(hex[ub / 16]);
|
||||
public int readSignedWordBigEndian() {
|
||||
int i = (readUnsignedByte()) + ((readUnsignedByte()) << 8);
|
||||
if (i > 32767) {
|
||||
i -= 0x10000;
|
||||
}
|
||||
out.append(hex[ub % 16]);
|
||||
return out.toString();
|
||||
return i;
|
||||
}
|
||||
|
||||
private static final char[] hex = "0123456789ABCDEF".toCharArray();
|
||||
|
||||
public int readShortA() {
|
||||
caret += 2;
|
||||
return ((pData[caret - 2] & 0xFF) << 8)
|
||||
+ (pData[caret - 1] - 128 & 0xFF);
|
||||
public int readSignedWordBigEndianA() {
|
||||
int i = (get() - 128 & 0xff) + ((readUnsignedByte()) << 8);
|
||||
if (i > 32767) {
|
||||
i -= 0x10000;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public byte readByteC() {
|
||||
return (byte) -readByte();
|
||||
public int readUnsignedWordBigEndian() {
|
||||
return (readUnsignedByte()) + ((readUnsignedByte()) << 8);
|
||||
}
|
||||
|
||||
public byte readByteS() {
|
||||
return (byte) (128 - readByte());
|
||||
public int readUnsignedWordBigEndianA() {
|
||||
return (get() - 128 & 0xff) + ((readUnsignedByte()) << 8);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
package com.rs2.net;
|
||||
|
||||
/**
|
||||
* Represents a packet buffer.
|
||||
*
|
||||
* @author Ultimate1
|
||||
* @author blakeman8192
|
||||
*/
|
||||
|
||||
public class PacketBuffer {
|
||||
|
||||
private int caret;
|
||||
private byte[] buffer;
|
||||
|
||||
public PacketBuffer(int capcity) {
|
||||
buffer = new byte[capcity];
|
||||
caret = 0;
|
||||
}
|
||||
|
||||
public void setBuffer(byte[] buffer) {
|
||||
this.buffer = buffer;
|
||||
caret = 0;
|
||||
}
|
||||
|
||||
public PacketBuffer setOpcode(int opcode) {
|
||||
return addByte(opcode);
|
||||
}
|
||||
|
||||
public PacketBuffer addByte(int i) {
|
||||
buffer[caret++] = (byte) i;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getByte() {
|
||||
return buffer[caret++] & 0xff;
|
||||
}
|
||||
|
||||
public PacketBuffer addBoolean(boolean val) {
|
||||
return addByte(val ? 1 : 0);
|
||||
}
|
||||
|
||||
public boolean getBoolean() {
|
||||
return getByte() == 1;
|
||||
}
|
||||
|
||||
public PacketBuffer addShort(int i) {
|
||||
return addByte(i >> 8).addByte(i);
|
||||
}
|
||||
|
||||
public int getShort() {
|
||||
return getByte() << 8 | getByte();
|
||||
}
|
||||
|
||||
public PacketBuffer addInt(int i) {
|
||||
return addShort(i >> 16).addShort(i);
|
||||
}
|
||||
|
||||
public int getInt() {
|
||||
return getShort() << 16 | getShort();
|
||||
}
|
||||
|
||||
public PacketBuffer addLong(long i) {
|
||||
return addInt((int) (i >> 32)).addInt((int) i);
|
||||
}
|
||||
|
||||
public long getLong() {
|
||||
return (long) getInt() << 32L | getInt();
|
||||
}
|
||||
|
||||
public PacketBuffer addString(String s) {
|
||||
for (byte b : s.getBytes()) {
|
||||
addByte(b);
|
||||
}
|
||||
return addByte('\n');
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
int c;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
while ((c = getByte()) != '\n') {
|
||||
builder.append((char) c);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public byte[] getBuffer() {
|
||||
byte[] newBuffer = new byte[caret + 1];
|
||||
newBuffer[0] = (byte) caret;
|
||||
System.arraycopy(buffer, 0, newBuffer, 1, caret);
|
||||
return newBuffer;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return buffer.length;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
caret = 0;
|
||||
for (int i = 0; i < buffer.length; i++) {
|
||||
buffer[i] = 0;
|
||||
}
|
||||
buffer = null;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.rs2.net;
|
||||
|
||||
/**
|
||||
* Packet builder interface
|
||||
*
|
||||
* @author Graham
|
||||
*/
|
||||
public interface PacketBuilder {
|
||||
|
||||
}
|
||||
@@ -336,7 +336,8 @@ public class PacketSender {
|
||||
player.getOutStream().writeWordA(id);
|
||||
player.getOutStream().endFrameVarSizeWord();
|
||||
player.flushOutStream();
|
||||
}
|
||||
}//send(new SetWidgetTextMessage(id, s));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,305 +0,0 @@
|
||||
package com.rs2.net;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import org.apache.mina.common.ByteBuffer;
|
||||
import org.apache.mina.common.IoFuture;
|
||||
import org.apache.mina.common.IoFutureListener;
|
||||
import org.apache.mina.common.IoSession;
|
||||
import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
|
||||
import org.apache.mina.filter.codec.ProtocolCodecFilter;
|
||||
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
|
||||
|
||||
import com.rs2.Connection;
|
||||
import com.rs2.GameConstants;
|
||||
import com.rs2.GameEngine;
|
||||
import com.rs2.game.players.Client;
|
||||
import com.rs2.game.players.PlayerHandler;
|
||||
import com.rs2.game.players.PlayerSave;
|
||||
import com.rs2.util.HostBlacklist;
|
||||
import com.rs2.util.ISAACRandomGen;
|
||||
|
||||
/**
|
||||
* Login protocol decoder.
|
||||
*
|
||||
* @author Graham
|
||||
* @author Ryan / Lmctruck30 <- login Protocol fixes
|
||||
*/
|
||||
|
||||
public class RS2LoginProtocolDecoder extends CumulativeProtocolDecoder {
|
||||
|
||||
private static final BigInteger RSA_MODULUS = new BigInteger("91553247461173033466542043374346300088148707506479543786501537350363031301992107112953015516557748875487935404852620239974482067336878286174236183516364787082711186740254168914127361643305190640280157664988536979163450791820893999053469529344247707567448479470137716627440246788713008490213212272520901741443");
|
||||
private static final BigInteger RSA_EXPONENT = new BigInteger("33280025241734061313051117678670856264399753710527826596057587687835856000539511539311834363046145710983857746766009612538140077973762171163294453513440619295457626227183742315140865830778841533445402605660729039310637444146319289077374748018792349647460850308384280105990607337322160553135806205784213241305");
|
||||
|
||||
|
||||
/**
|
||||
* Parses the data in the provided byte buffer and writes it to
|
||||
* <code>out</code> as a <code>Packet</code>.
|
||||
*
|
||||
* @param session
|
||||
* The IoSession the data was read from
|
||||
* @param in
|
||||
* The buffer
|
||||
* @param out
|
||||
* The decoder output stream to which to write the
|
||||
* <code>Packet</code>
|
||||
* @return Whether enough data was available to create a packet
|
||||
*/
|
||||
@Override
|
||||
public boolean doDecode(IoSession session, ByteBuffer in,
|
||||
ProtocolDecoderOutput out) {
|
||||
synchronized (session) {
|
||||
Object loginStageObj = session.getAttribute("LOGIN_STAGE");
|
||||
int loginStage = 0;
|
||||
if (loginStageObj != null) {
|
||||
loginStage = (Integer) loginStageObj;
|
||||
}
|
||||
// Logger.log("recv login packet, stage: "+loginStage);
|
||||
switch (loginStage) {
|
||||
case 0:
|
||||
if (2 <= in.remaining()) {
|
||||
int protocol = in.get() & 0xff;
|
||||
@SuppressWarnings("unused")
|
||||
int nameHash = in.get() & 0xff;
|
||||
if (protocol == 14) {
|
||||
long serverSessionKey = ((long) (java.lang.Math
|
||||
.random() * 99999999D) << 32)
|
||||
+ (long) (java.lang.Math.random() * 99999999D);
|
||||
StaticPacketBuilder s1Response = new StaticPacketBuilder();
|
||||
s1Response
|
||||
.setBare(true)
|
||||
.addBytes(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 })
|
||||
.addByte((byte) 0).addLong(serverSessionKey);
|
||||
session.setAttribute("SERVER_SESSION_KEY",
|
||||
serverSessionKey);
|
||||
session.write(s1Response.toPacket());
|
||||
session.setAttribute("LOGIN_STAGE", 1);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
in.rewind();
|
||||
return false;
|
||||
}
|
||||
case 1:
|
||||
@SuppressWarnings("unused")
|
||||
int loginType = -1,
|
||||
loginPacketSize = -1,
|
||||
loginEncryptPacketSize = -1;
|
||||
if (2 <= in.remaining()) {
|
||||
loginType = in.get() & 0xff; // should be 16 or 18
|
||||
loginPacketSize = in.get() & 0xff;
|
||||
loginEncryptPacketSize = loginPacketSize - (36 + 1 + 1 + 2);
|
||||
if (loginPacketSize <= 0 || loginEncryptPacketSize <= 0) {
|
||||
System.out.println("Zero or negative login size.");
|
||||
session.close();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
in.rewind();
|
||||
return false;
|
||||
}
|
||||
if (loginPacketSize <= in.remaining()) {
|
||||
int magic = in.get() & 0xff;
|
||||
int version = in.getUnsignedShort();
|
||||
if (magic != 255) {
|
||||
// System.out.println("Wrong magic id.");
|
||||
session.close();
|
||||
return false;
|
||||
}
|
||||
if (version != 1) {
|
||||
// Dont Add Anything
|
||||
}
|
||||
@SuppressWarnings("unused")
|
||||
int lowMem = in.get() & 0xff;
|
||||
for (int i = 0; i < 9; i++) {
|
||||
in.getInt();
|
||||
}
|
||||
loginEncryptPacketSize--;
|
||||
if(loginEncryptPacketSize != (in.get() & 0xff)) {
|
||||
System.out.println("Encrypted size mismatch.");
|
||||
session.close();
|
||||
return false;
|
||||
}
|
||||
byte[] encryptionBytes = new byte[loginEncryptPacketSize];
|
||||
in.get(encryptionBytes);
|
||||
ByteBuffer rsaBuffer = ByteBuffer.wrap(new BigInteger(encryptionBytes).modPow(RSA_EXPONENT, RSA_MODULUS).toByteArray());
|
||||
if((rsaBuffer.get() & 0xff) != 10) {
|
||||
System.out.println("Encrypted id != 10.");
|
||||
session.close();
|
||||
return false;
|
||||
}
|
||||
long clientSessionKey = rsaBuffer.getLong();
|
||||
long serverSessionKey = rsaBuffer.getLong();
|
||||
int uid = rsaBuffer.getInt();
|
||||
if(uid != 314268572) {
|
||||
session.close();
|
||||
return false;
|
||||
}
|
||||
String name = readRS2String(rsaBuffer);
|
||||
String pass = readRS2String(rsaBuffer);
|
||||
int sessionKey[] = new int[4];
|
||||
sessionKey[0] = (int) (clientSessionKey >> 32);
|
||||
sessionKey[1] = (int) clientSessionKey;
|
||||
sessionKey[2] = (int) (serverSessionKey >> 32);
|
||||
sessionKey[3] = (int) serverSessionKey;
|
||||
ISAACRandomGen inC = new ISAACRandomGen(sessionKey);
|
||||
for (int i = 0; i < 4; i++)
|
||||
sessionKey[i] += 50;
|
||||
ISAACRandomGen outC = new ISAACRandomGen(sessionKey);
|
||||
load(session, uid, name, pass, inC, outC, version);
|
||||
session.getFilterChain().remove("protocolFilter");
|
||||
session.getFilterChain().addLast("protocolFilter", new ProtocolCodecFilter(new GameCodecFactory(inC)));
|
||||
return true;
|
||||
} else {
|
||||
in.rewind();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private synchronized void load(final IoSession session, final int uid,
|
||||
String name, String pass, final ISAACRandomGen inC,
|
||||
ISAACRandomGen outC, int version) {
|
||||
session.setAttribute("opcode", -1);
|
||||
session.setAttribute("size", -1);
|
||||
int returnCode = 2;
|
||||
|
||||
name = name.trim();
|
||||
name = name.toLowerCase();
|
||||
// pass = pass.toLowerCase();
|
||||
|
||||
String hostName = ((InetSocketAddress) session.getRemoteAddress())
|
||||
.getAddress().getHostName();
|
||||
|
||||
//if (version != 1) {
|
||||
//returnCode = 31;
|
||||
//d}
|
||||
|
||||
if (HostBlacklist.isBlocked(hostName)) {
|
||||
returnCode = 11;
|
||||
}
|
||||
|
||||
if (!name.matches("[A-Za-z0-9 ]+")) {
|
||||
returnCode = 4;
|
||||
}
|
||||
|
||||
if (name.length() > 12) {
|
||||
returnCode = 8;
|
||||
}
|
||||
|
||||
if (pass.length() == 0) {
|
||||
returnCode = 4;
|
||||
}
|
||||
|
||||
Client cl = new Client(session, -1);
|
||||
cl.playerName = name;
|
||||
cl.playerName2 = cl.playerName;
|
||||
cl.playerPass = pass;
|
||||
|
||||
cl.setInStreamDecryption(inC);
|
||||
cl.setOutStreamDecryption(outC);
|
||||
cl.outStream.packetEncryption = outC;
|
||||
cl.saveCharacter = false;
|
||||
char first = name.charAt(0);
|
||||
cl.properName = Character.toUpperCase(first)
|
||||
+ name.substring(1, name.length());
|
||||
|
||||
if (Connection.isNamedBanned(cl.playerName)) {
|
||||
returnCode = 4;
|
||||
}
|
||||
|
||||
|
||||
if (PlayerHandler.isPlayerOn(name)) {
|
||||
returnCode = 5;
|
||||
}
|
||||
|
||||
if (PlayerHandler.playerCount >= GameConstants.MAX_PLAYERS) {
|
||||
returnCode = 7;
|
||||
}
|
||||
|
||||
if (GameEngine.updateServer) {
|
||||
returnCode = 14;
|
||||
}
|
||||
|
||||
if (returnCode == 2) {
|
||||
int load = PlayerSave.loadGame(cl, cl.playerName, cl.playerPass);
|
||||
if (load == 0) {
|
||||
cl.addStarter = true;
|
||||
}
|
||||
if (load == 3) {
|
||||
returnCode = 3;
|
||||
cl.saveFile = false;
|
||||
} else {
|
||||
for (int i = 0; i < cl.playerEquipment.length; i++) {
|
||||
if (cl.playerEquipment[i] == 0) {
|
||||
cl.playerEquipment[i] = -1;
|
||||
cl.playerEquipmentN[i] = 0;
|
||||
}
|
||||
}
|
||||
if (!GameEngine.playerHandler.newPlayerClient(cl)) {
|
||||
returnCode = 7;
|
||||
cl.saveFile = false;
|
||||
} else {
|
||||
cl.saveFile = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cl.packetType = -1;
|
||||
cl.packetSize = 0;
|
||||
|
||||
StaticPacketBuilder bldr = new StaticPacketBuilder();
|
||||
bldr.setBare(true);
|
||||
bldr.addByte((byte) returnCode);
|
||||
if (returnCode == 2) {
|
||||
cl.saveCharacter = true;
|
||||
if (cl.playerRights == 3) {
|
||||
bldr.addByte((byte) 2);
|
||||
} else {
|
||||
bldr.addByte((byte) cl.playerRights);
|
||||
}
|
||||
} else {
|
||||
bldr.addByte((byte) 0);
|
||||
}
|
||||
bldr.addByte((byte) 0);
|
||||
cl.isActive = true;
|
||||
Packet pkt = bldr.toPacket();
|
||||
session.setAttachment(cl);
|
||||
session.write(pkt).addListener(new IoFutureListener() {
|
||||
|
||||
@Override
|
||||
public void operationComplete(IoFuture arg0) {
|
||||
session.getFilterChain().remove("protocolFilter");
|
||||
session.getFilterChain().addFirst("protocolFilter",
|
||||
new ProtocolCodecFilter(new GameCodecFactory(inC)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private synchronized String readRS2String(ByteBuffer in) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
byte b;
|
||||
while ((b = in.get()) != 10) {
|
||||
sb.append((char) b);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases the buffer used by the given session.
|
||||
*
|
||||
* @param session
|
||||
* The session for which to release the buffer
|
||||
* @throws Exception
|
||||
* if failed to dispose all resources
|
||||
*/
|
||||
@Override
|
||||
public void dispose(IoSession session) throws Exception {
|
||||
super.dispose(session);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,145 +1,210 @@
|
||||
package com.rs2.net;
|
||||
|
||||
import org.apache.mina.common.ByteBuffer;
|
||||
import org.apache.mina.common.IoSession;
|
||||
import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
|
||||
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||
|
||||
import com.rs2.game.players.Client;
|
||||
import com.rs2.util.ISAACRandomGen;
|
||||
import java.util.List;
|
||||
|
||||
public class RS2ProtocolDecoder extends CumulativeProtocolDecoder {
|
||||
import org.apollo.util.StatefulFrameDecoder;
|
||||
import org.apollo.util.security.IsaacRandom;
|
||||
|
||||
private final ISAACRandomGen isaac;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.rs2.net.Packet.Type;
|
||||
|
||||
public class RS2ProtocolDecoder extends StatefulFrameDecoder<GameDecoderState> {
|
||||
|
||||
private int opcode = -1;
|
||||
private int length = -1;
|
||||
private final IsaacRandom random;
|
||||
public static final int PACKET_SIZES[] = { 0, 0, 0, 1, -1, 0, 0, 0, 0, 0, // 0
|
||||
0, 0, 0, 0, 8, 0, 6, 2, 2, 0, // 10
|
||||
0, 2, 0, 6, 0, 12, 0, 0, 0, 0, // 20
|
||||
0, 0, 0, 0, 0, 8, 4, 0, 0, 2, // 30
|
||||
2, 6, 0, 6, 0, -1, 0, 0, 0, 0, // 40
|
||||
0, 0, 0, 12, 0, 0, 0, 8, 8, 12, // 50
|
||||
8, 8, 0, 0, 0, 0, 0, 0, 0, 0, // 60
|
||||
6, 0, 2, 2, 8, 6, 0, -1, 0, 6, // 70
|
||||
0, 0, 0, 0, 0, 1, 4, 6, 0, 0, // 80
|
||||
0, 0, 0, 0, 0, 3, 0, 0, -1, 0, // 90
|
||||
0, 13, 0, -1, 0, 0, 0, 0, 0, 0,// 100
|
||||
0, 0, 0, 0, 0, 0, 0, 6, 0, 0, // 110
|
||||
1, 0, 6, 0, 0, 0, -1, 0, 2, 6, // 120
|
||||
0, 4, 6, 8, 0, 6, 0, 0, 0, 2, // 130
|
||||
0, 0, 0, 0, 0, 6, 0, 0, 0, 0, // 140
|
||||
0, 0, 1, 2, 0, 2, 6, 0, 0, 0, // 150
|
||||
0, 0, 0, 0, -1, -1, 0, 0, 0, 0,// 160
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 170
|
||||
0, 8, 0, 3, 0, 2, 0, 0, 8, 1, // 180
|
||||
0, 0, 12, 0, 0, 0, 0, 0, 0, 0, // 190
|
||||
2, 0, 0, 0, 0, 0, 0, 0, 4, 0, // 200
|
||||
4, 0, 0, 0, 7, 8, 0, 0, 10, 0, // 210
|
||||
0, 0, 0, 0, 0, 0, -1, 0, 6, 0, // 220
|
||||
1, 0, 0, 0, 6, 0, 6, 8, 1, 0, // 230
|
||||
0, 4, 0, 0, 0, 0, -1, 0, -1, 4,// 240
|
||||
0, 0, 6, 6, 0, 0, 0 // 250
|
||||
};
|
||||
|
||||
/**
|
||||
* To make sure only the CodecFactory can initialise us.
|
||||
*/
|
||||
protected RS2ProtocolDecoder(ISAACRandomGen isaac) {
|
||||
this.isaac = isaac;
|
||||
public RS2ProtocolDecoder(IsaacRandom isaac) {
|
||||
super(GameDecoderState.GAME_OPCODE);
|
||||
this.random = isaac;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Decodes a message.
|
||||
// *
|
||||
// * @param session
|
||||
// * @param in
|
||||
// * @param out
|
||||
// * @return
|
||||
// */
|
||||
// @Override
|
||||
// protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||
// /*
|
||||
// * If the opcode is not present.
|
||||
// */
|
||||
// if (opcode == -1) {
|
||||
// /*
|
||||
// * Check if it can be read.
|
||||
// */
|
||||
// if (in.readableBytes() >= 1) {
|
||||
// /*
|
||||
// * Read and decrypt the opcode.
|
||||
// */
|
||||
// opcode = in.readByte() & 0xFF;
|
||||
// opcode = (opcode - random.nextInt()) & 0xFF;
|
||||
// /*
|
||||
// * Find the packet size.
|
||||
// */
|
||||
// length = PACKET_SIZES[opcode];
|
||||
// } else {
|
||||
// /*
|
||||
// * We need to wait for more data.
|
||||
// */
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /*
|
||||
// * If the packet is variable-length.
|
||||
// */
|
||||
// if (length == -1) {
|
||||
// /*
|
||||
// * Check if the size can be read.
|
||||
// */
|
||||
// if (in.readableBytes() >= 1) {
|
||||
// /*
|
||||
// * Read the packet size and cache it.
|
||||
// */
|
||||
// length = in.readByte() & 0xFF;
|
||||
// } else {
|
||||
// /*
|
||||
// * We need to wait for more data.
|
||||
// */
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /*
|
||||
// * If the packet payload (data) can be read.
|
||||
// */
|
||||
// if (in.readableBytes() >= length) {
|
||||
// /*
|
||||
// * Read it.
|
||||
// */
|
||||
// ByteBuf payload = in.readBytes(length);
|
||||
// /*
|
||||
// * Produce and write the packet object.
|
||||
// */
|
||||
// out.add(new Packet(opcode, Type.FIXED, payload));
|
||||
// opcode = -1;
|
||||
// length = -1;
|
||||
// }
|
||||
//
|
||||
// /*
|
||||
// * We need to wait for more data.
|
||||
// */
|
||||
// return;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Decodes a message.
|
||||
*
|
||||
* @param session
|
||||
* @param in
|
||||
* @param out
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected boolean doDecode(IoSession session, ByteBuffer in,
|
||||
ProtocolDecoderOutput out) throws Exception {
|
||||
synchronized (session) {
|
||||
/*
|
||||
* Fetch the ISAAC cipher for this session.
|
||||
*/
|
||||
// ISAACRandomGen inCipher = ((Player)
|
||||
// session.getAttribute("player")).getInStreamDecryption();
|
||||
|
||||
/*
|
||||
* Fetch any cached opcodes and sizes, reset to -1 if not present.
|
||||
*/
|
||||
int opcode = (Integer) session.getAttribute("opcode");
|
||||
int size = (Integer) session.getAttribute("size");
|
||||
|
||||
/*
|
||||
* If the opcode is not present.
|
||||
*/
|
||||
if (opcode == -1) {
|
||||
/*
|
||||
* Check if it can be read.
|
||||
*/
|
||||
if (in.remaining() >= 1) {
|
||||
/*
|
||||
* Read and decrypt the opcode.
|
||||
*/
|
||||
opcode = in.get() & 0xFF;
|
||||
opcode = opcode - isaac.getNextKey() & 0xFF;
|
||||
|
||||
/*
|
||||
* Find the packet size.
|
||||
*/
|
||||
size = Client.PACKET_SIZES[opcode];
|
||||
|
||||
/*
|
||||
* Set the cached opcode and size.
|
||||
*/
|
||||
session.setAttribute("opcode", opcode);
|
||||
session.setAttribute("size", size);
|
||||
} else {
|
||||
/*
|
||||
* We need to wait for more data.
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If the packet is variable-length.
|
||||
*/
|
||||
if (size == -1) {
|
||||
/*
|
||||
* Check if the size can be read.
|
||||
*/
|
||||
if (in.remaining() >= 1) {
|
||||
/*
|
||||
* Read the packet size and cache it.
|
||||
*/
|
||||
size = in.get() & 0xFF;
|
||||
session.setAttribute("size", size);
|
||||
} else {
|
||||
/*
|
||||
* We need to wait for more data.
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If the packet payload (data) can be read.
|
||||
*/
|
||||
if (in.remaining() >= size) {
|
||||
/*
|
||||
* Read it.
|
||||
*/
|
||||
byte[] data = new byte[size];
|
||||
in.get(data);
|
||||
ByteBuffer payload = ByteBuffer.allocate(data.length);
|
||||
payload.put(data);
|
||||
payload.flip();
|
||||
|
||||
/*
|
||||
* Produce and write the packet object.
|
||||
*/
|
||||
out.write(new Packet(session, opcode, data));
|
||||
|
||||
/*
|
||||
* Reset the cached opcode and sizes.
|
||||
*/
|
||||
session.setAttribute("opcode", -1);
|
||||
session.setAttribute("size", -1);
|
||||
|
||||
/*
|
||||
* Indicate we are ready to read another packet.
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* We need to wait for more data.
|
||||
*/
|
||||
return false;
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out, GameDecoderState state) {
|
||||
switch (state) {
|
||||
case GAME_OPCODE:
|
||||
decodeOpcode(in, out);
|
||||
break;
|
||||
case GAME_LENGTH:
|
||||
decodeLength(in);
|
||||
break;
|
||||
case GAME_PAYLOAD:
|
||||
decodePayload(in, out);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Invalid game decoder state.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Releases resources used by this decoder.
|
||||
* @param session
|
||||
* Decodes the length state.
|
||||
*
|
||||
* @param buffer The buffer.
|
||||
*/
|
||||
public void dispose(IoSession session) throws Exception {
|
||||
super.dispose(session);
|
||||
private void decodeLength(ByteBuf buffer) {
|
||||
if (buffer.isReadable()) {
|
||||
length = buffer.readUnsignedByte();
|
||||
if (length != 0) {
|
||||
setState(GameDecoderState.GAME_PAYLOAD);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes the opcode state.
|
||||
*
|
||||
* @param buffer The buffer.
|
||||
* @param out The {@link List} of objects to be passed along the pipeline.
|
||||
*/
|
||||
private void decodeOpcode(ByteBuf buffer, List<Object> out) {
|
||||
if (buffer.isReadable()) {
|
||||
int encryptedOpcode = buffer.readUnsignedByte();
|
||||
opcode = encryptedOpcode - random.nextInt() & 0xFF;
|
||||
|
||||
int s = PACKET_SIZES[opcode];
|
||||
|
||||
switch (s) {
|
||||
default:
|
||||
length = s;
|
||||
if (length == 0) {
|
||||
setState(GameDecoderState.GAME_OPCODE);
|
||||
out.add(new Packet(opcode, Type.FIXED, Unpooled.EMPTY_BUFFER));
|
||||
} else {
|
||||
setState(GameDecoderState.GAME_PAYLOAD);
|
||||
}
|
||||
break;
|
||||
case -1:
|
||||
setState(GameDecoderState.GAME_LENGTH);
|
||||
break;
|
||||
// default:
|
||||
// throw new IllegalStateException("Illegal packet type: " + type + ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes the payload state.
|
||||
*
|
||||
* @param buffer The buffer.
|
||||
* @param out The {@link List} of objects to be passed along the pipeline.
|
||||
*/
|
||||
private void decodePayload(ByteBuf buffer, List<Object> out) {
|
||||
if (buffer.readableBytes() >= length) {
|
||||
ByteBuf payload = buffer.readBytes(length);
|
||||
setState(GameDecoderState.GAME_OPCODE);
|
||||
out.add(new Packet(opcode, Type.FIXED, payload));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,82 +1,26 @@
|
||||
package com.rs2.net;
|
||||
|
||||
import org.apache.mina.common.ByteBuffer;
|
||||
import org.apache.mina.common.IoSession;
|
||||
import org.apache.mina.filter.codec.ProtocolEncoder;
|
||||
import org.apache.mina.filter.codec.ProtocolEncoderOutput;
|
||||
|
||||
public class RS2ProtocolEncoder implements ProtocolEncoder {
|
||||
|
||||
/**
|
||||
* Only CodecFactory can create us.
|
||||
*/
|
||||
protected RS2ProtocolEncoder() {
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Encodes a message.
|
||||
* @param session
|
||||
* @param message
|
||||
* @param out
|
||||
*/
|
||||
public void encode(IoSession session, Object message,
|
||||
ProtocolEncoderOutput out) throws Exception {
|
||||
try {
|
||||
synchronized (session) {
|
||||
Packet p = (Packet) message;
|
||||
byte[] data = p.getData();
|
||||
int dataLength = p.getLength();
|
||||
ByteBuffer buffer;
|
||||
if (!p.isBare()) {
|
||||
buffer = ByteBuffer.allocate(dataLength + 3);
|
||||
int id = p.getId();
|
||||
buffer.put((byte) id);
|
||||
if (p.getSize() != Packet.Size.Fixed) { // variable length
|
||||
// Logger.log("variable length: id="+id+",dataLength="+dataLength);
|
||||
if (p.getSize() == Packet.Size.VariableByte) {
|
||||
if (dataLength > 255) {
|
||||
// then we can represent
|
||||
// with 8 bits!
|
||||
throw new IllegalArgumentException(
|
||||
"Tried to send packet length "
|
||||
+ dataLength
|
||||
+ " in 8 bits [pid="
|
||||
+ p.getId() + "]");
|
||||
}
|
||||
buffer.put((byte) dataLength);
|
||||
} else if (p.getSize() == Packet.Size.VariableShort) {
|
||||
if (dataLength > 65535) {
|
||||
// then we can represent
|
||||
// with 16 bits!
|
||||
throw new IllegalArgumentException(
|
||||
"Tried to send packet length "
|
||||
+ dataLength
|
||||
+ " in 16 bits [pid="
|
||||
+ p.getId() + "]");
|
||||
}
|
||||
buffer.put((byte) (dataLength >> 8));
|
||||
buffer.put((byte) dataLength);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
buffer = ByteBuffer.allocate(dataLength);
|
||||
}
|
||||
buffer.put(data, 0, dataLength);
|
||||
buffer.flip();
|
||||
out.write(buffer);
|
||||
}
|
||||
} catch (Exception err) {
|
||||
err.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Releases resources used by this encoder.
|
||||
* @param session
|
||||
*/
|
||||
public void dispose(IoSession session) throws Exception {
|
||||
}
|
||||
|
||||
}
|
||||
//package com.rs2.net;
|
||||
//
|
||||
//import io.netty.buffer.ByteBuf;
|
||||
//import io.netty.channel.ChannelHandlerContext;
|
||||
//import io.netty.handler.codec.MessageToByteEncoder;
|
||||
//
|
||||
//public class RS2ProtocolEncoder extends MessageToByteEncoder<Packet> {
|
||||
//
|
||||
// /**
|
||||
// * Only CodecFactory can create us.
|
||||
// */
|
||||
// public RS2ProtocolEncoder() {
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// /**
|
||||
// * Encodes a message.
|
||||
// * @param session
|
||||
// * @param message
|
||||
// * @param out
|
||||
// */
|
||||
// protected void encode(ChannelHandlerContext ctx, Packet msg, ByteBuf out) throws Exception {
|
||||
// out.writeBytes(msg.getPayload());//return ((Packet) object).getPayload(); Do we need to go bldr->packet?
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
@@ -1,385 +0,0 @@
|
||||
package com.rs2.net;
|
||||
|
||||
/**
|
||||
* A mutable sequence of bytes used to construct the immutable
|
||||
* <code>Packet</code> objects. By default, methods use big endian byte
|
||||
* ordering.
|
||||
*/
|
||||
public class StaticPacketBuilder implements PacketBuilder {
|
||||
|
||||
/**
|
||||
* Default capacity
|
||||
*/
|
||||
private static final int DEFAULT_SIZE = 32;
|
||||
/**
|
||||
* The payload buffer
|
||||
*/
|
||||
private byte[] payload;
|
||||
/**
|
||||
* Current number of bytes used in the buffer
|
||||
*/
|
||||
private int curLength;
|
||||
/**
|
||||
* ID of the packet
|
||||
*/
|
||||
private int id;
|
||||
/**
|
||||
* Current index into the buffer by bits
|
||||
*/
|
||||
private int bitPosition = 0;
|
||||
private Packet.Size size = Packet.Size.Fixed;
|
||||
/**
|
||||
* Whether this packet does not use the standard packet header
|
||||
*/
|
||||
private boolean bare = false;
|
||||
|
||||
/**
|
||||
* Bitmasks for <code>addBits()</code>
|
||||
*/
|
||||
private static int bitmasks[] = { 0, 0x1, 0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f,
|
||||
0xff, 0x1ff, 0x3ff, 0x7ff, 0xfff, 0x1fff, 0x3fff, 0x7fff, 0xffff,
|
||||
0x1ffff, 0x3ffff, 0x7ffff, 0xfffff, 0x1fffff, 0x3fffff, 0x7fffff,
|
||||
0xffffff, 0x1ffffff, 0x3ffffff, 0x7ffffff, 0xfffffff, 0x1fffffff,
|
||||
0x3fffffff, 0x7fffffff, -1 };
|
||||
|
||||
/**
|
||||
* Constructs a packet builder with no data and an initial capacity of
|
||||
* <code>DEFAULT_SIZE</code>.
|
||||
*
|
||||
* @see DEFAULT_SIZE
|
||||
*/
|
||||
public StaticPacketBuilder() {
|
||||
this(DEFAULT_SIZE);
|
||||
}
|
||||
|
||||
public byte[] getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a packet builder with no data and an initial capacity of
|
||||
* <code>capacity</code>.
|
||||
*
|
||||
* @param capacity
|
||||
* The initial capacity of the buffer
|
||||
*/
|
||||
public StaticPacketBuilder(int capacity) {
|
||||
payload = new byte[capacity];
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that the buffer is at least <code>minimumBytes</code> bytes.
|
||||
*
|
||||
* @param minimumCapacity
|
||||
* The size needed
|
||||
*/
|
||||
private void ensureCapacity(int minimumCapacity) {
|
||||
if (minimumCapacity >= payload.length) {
|
||||
expandCapacity(minimumCapacity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Expands the buffer to the specified size.
|
||||
*
|
||||
* @param minimumCapacity
|
||||
* The minimum capacity to which to expand
|
||||
* @see java.lang.AbstractStringBuilder#expandCapacity(int)
|
||||
*/
|
||||
private void expandCapacity(int minimumCapacity) {
|
||||
int newCapacity = (payload.length + 1) * 2;
|
||||
if (newCapacity < 0) {
|
||||
newCapacity = Integer.MAX_VALUE;
|
||||
} else if (minimumCapacity > newCapacity) {
|
||||
newCapacity = minimumCapacity;
|
||||
}
|
||||
byte[] newPayload = new byte[newCapacity];
|
||||
try {
|
||||
while (curLength > payload.length) {
|
||||
curLength--;
|
||||
}
|
||||
System.arraycopy(payload, 0, newPayload, 0, curLength);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
payload = newPayload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this packet as bare. A bare packet will contain only the payload
|
||||
* data, rather than having the standard packet header prepended.
|
||||
*
|
||||
* @param bare
|
||||
* Whether this packet is to be sent bare
|
||||
*/
|
||||
public StaticPacketBuilder setBare(boolean bare) {
|
||||
this.bare = bare;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the ID for this packet.
|
||||
*
|
||||
* @param id
|
||||
* The ID of the packet
|
||||
*/
|
||||
public StaticPacketBuilder setId(int id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public StaticPacketBuilder setSize(Packet.Size s) {
|
||||
size = s;
|
||||
return this;
|
||||
}
|
||||
|
||||
public StaticPacketBuilder initBitAccess() {
|
||||
bitPosition = curLength * 8;
|
||||
return this;
|
||||
}
|
||||
|
||||
public StaticPacketBuilder finishBitAccess() {
|
||||
curLength = (bitPosition + 7) / 8;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO needs a proper description.
|
||||
*/
|
||||
public StaticPacketBuilder addBits(int numBits, int value) {
|
||||
int bytePos = bitPosition >> 3;
|
||||
int bitOffset = 8 - (bitPosition & 7);
|
||||
bitPosition += numBits;
|
||||
curLength = (bitPosition + 7) / 8;
|
||||
ensureCapacity(curLength);
|
||||
for (; numBits > bitOffset; bitOffset = 8) {
|
||||
payload[bytePos] &= ~bitmasks[bitOffset]; // mask out the desired
|
||||
// area
|
||||
payload[bytePos++] |= value >> numBits - bitOffset
|
||||
& bitmasks[bitOffset];
|
||||
|
||||
numBits -= bitOffset;
|
||||
}
|
||||
if (numBits == bitOffset) {
|
||||
payload[bytePos] &= ~bitmasks[bitOffset];
|
||||
payload[bytePos] |= value & bitmasks[bitOffset];
|
||||
} else {
|
||||
payload[bytePos] &= ~(bitmasks[numBits] << bitOffset - numBits);
|
||||
payload[bytePos] |= (value & bitmasks[numBits]) << bitOffset
|
||||
- numBits;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the contents of <code>byte</code> array <code>data</code> to the
|
||||
* packet. The size of this packet will grow by the length of the provided
|
||||
* array.
|
||||
*
|
||||
* @param data
|
||||
* The bytes to add to this packet
|
||||
* @return A reference to this object
|
||||
*/
|
||||
public StaticPacketBuilder addBytes(byte[] data) {
|
||||
return addBytes(data, 0, data.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the contents of <code>byte</code> array <code>data</code>, starting
|
||||
* at index <code>offset</code>. The size of this packet will grow by
|
||||
* <code>len</code> bytes.
|
||||
*
|
||||
* @param data
|
||||
* The bytes to add to this packet
|
||||
* @param offset
|
||||
* The index of the first byte to append
|
||||
* @param len
|
||||
* The number of bytes to append
|
||||
* @return A reference to this object
|
||||
*/
|
||||
public StaticPacketBuilder addBytes(byte[] data, int offset, int len) {
|
||||
int newLength = curLength + len;
|
||||
ensureCapacity(newLength);
|
||||
System.arraycopy(data, offset, payload, curLength, len);
|
||||
curLength = newLength;
|
||||
return this;
|
||||
}
|
||||
|
||||
public StaticPacketBuilder addLEShortA(int i) {
|
||||
ensureCapacity(curLength + 2);
|
||||
addByte((byte) (i + 128), false);
|
||||
addByte((byte) (i >> 8), false);
|
||||
return this;
|
||||
}
|
||||
|
||||
public StaticPacketBuilder addShortA(int i) {
|
||||
ensureCapacity(curLength + 2);
|
||||
addByte((byte) (i >> 8), false);
|
||||
addByte((byte) (i + 128), false);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a <code>byte</code> to the data buffer. The size of this packet will
|
||||
* grow by one byte.
|
||||
*
|
||||
* @param val
|
||||
* The <code>byte</code> value to add
|
||||
* @return A reference to this object
|
||||
*/
|
||||
public StaticPacketBuilder addByte(byte val) {
|
||||
return addByte(val, true);
|
||||
}
|
||||
|
||||
public StaticPacketBuilder addByteA(int i) {
|
||||
return addByte((byte) (i + 128), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a <code>byte</code> to the data buffer. The size of this packet will
|
||||
* grow by one byte.
|
||||
*
|
||||
* @param val
|
||||
* The <code>byte</code> value to add
|
||||
* @param checkCapacity
|
||||
* Whether the buffer capacity should be checked
|
||||
* @return A reference to this object
|
||||
*/
|
||||
private StaticPacketBuilder addByte(byte val, boolean checkCapacity) {
|
||||
if (checkCapacity) {
|
||||
ensureCapacity(curLength + 1);
|
||||
}
|
||||
payload[curLength++] = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a <code>short</code> to the data stream. The size of this packet
|
||||
* will grow by two bytes.
|
||||
*
|
||||
* @param val
|
||||
* The <code>short</code> value to add
|
||||
* @return A reference to this object
|
||||
*/
|
||||
public StaticPacketBuilder addShort(int val) {
|
||||
ensureCapacity(curLength + 2);
|
||||
addByte((byte) (val >> 8), false);
|
||||
addByte((byte) val, false);
|
||||
return this;
|
||||
}
|
||||
|
||||
public StaticPacketBuilder addLEShort(int val) {
|
||||
ensureCapacity(curLength + 2);
|
||||
addByte((byte) val, false);
|
||||
addByte((byte) (val >> 8), false);
|
||||
return this;
|
||||
}
|
||||
|
||||
public StaticPacketBuilder setShort(int val, int offset) {
|
||||
payload[offset++] = (byte) (val >> 8);
|
||||
payload[offset++] = (byte) val;
|
||||
if (curLength < offset + 2) {
|
||||
curLength += 2;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a <code>int</code> to the data stream. The size of this packet will
|
||||
* grow by four bytes.
|
||||
*
|
||||
* @param val
|
||||
* The <code>int</code> value to add
|
||||
* @return A reference to this object
|
||||
*/
|
||||
public StaticPacketBuilder addInt(int val) {
|
||||
ensureCapacity(curLength + 4);
|
||||
addByte((byte) (val >> 24), false);
|
||||
addByte((byte) (val >> 16), false);
|
||||
addByte((byte) (val >> 8), false);
|
||||
addByte((byte) val, false);
|
||||
return this;
|
||||
}
|
||||
|
||||
public StaticPacketBuilder addInt1(int val) {
|
||||
ensureCapacity(curLength + 4);
|
||||
addByte((byte) (val >> 8), false);
|
||||
addByte((byte) val, false);
|
||||
addByte((byte) (val >> 24), false);
|
||||
addByte((byte) (val >> 16), false);
|
||||
return this;
|
||||
}
|
||||
|
||||
public StaticPacketBuilder addInt2(int val) {
|
||||
ensureCapacity(curLength + 4);
|
||||
addByte((byte) (val >> 16), false);
|
||||
addByte((byte) (val >> 24), false);
|
||||
addByte((byte) val, false);
|
||||
addByte((byte) (val >> 8), false);
|
||||
return this;
|
||||
}
|
||||
|
||||
public StaticPacketBuilder addLEInt(int val) {
|
||||
ensureCapacity(curLength + 4);
|
||||
addByte((byte) val, false);
|
||||
addByte((byte) (val >> 8), false);
|
||||
addByte((byte) (val >> 16), false);
|
||||
addByte((byte) (val >> 24), false);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a <code>long</code> to the data stream. The size of this packet will
|
||||
* grow by eight bytes.
|
||||
*
|
||||
* @param val
|
||||
* The <code>long</code> value to add
|
||||
* @return A reference to this object
|
||||
*/
|
||||
public StaticPacketBuilder addLong(long val) {
|
||||
addInt((int) (val >> 32));
|
||||
addInt((int) (val & -1L));
|
||||
return this;
|
||||
}
|
||||
|
||||
public StaticPacketBuilder addLELong(long val) {
|
||||
addLEInt((int) (val & -1L));
|
||||
addLEInt((int) (val >> 32));
|
||||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public StaticPacketBuilder addString(String s) {
|
||||
ensureCapacity(curLength + s.length() + 1);
|
||||
s.getBytes(0, s.length(), payload, curLength);
|
||||
curLength += s.length();
|
||||
payload[curLength++] = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return curLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a <code>Packet</code> object for the data contained in this
|
||||
* builder.
|
||||
*
|
||||
* @return A <code>Packet</code> object
|
||||
*/
|
||||
public Packet toPacket() {
|
||||
byte[] data = new byte[curLength];
|
||||
System.arraycopy(payload, 0, data, 0, curLength);
|
||||
return new Packet(null, id, data, bare, size);
|
||||
}
|
||||
|
||||
public StaticPacketBuilder addByteC(int val) {
|
||||
addByte((byte) -val);
|
||||
return this;
|
||||
}
|
||||
|
||||
public StaticPacketBuilder addByteS(int val) {
|
||||
addByte((byte) (128 - val));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.rs2.net.packets;
|
||||
import com.rs2.GameConstants;
|
||||
import com.rs2.game.dialogues.Dialogue;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.impl.AttackPlayer;
|
||||
import com.rs2.net.packets.impl.Bank10;
|
||||
import com.rs2.net.packets.impl.Bank5;
|
||||
@@ -156,14 +157,16 @@ public class PacketHandler {
|
||||
}
|
||||
}*/
|
||||
|
||||
public static void processPacket(Player player, int packetType, int packetSize) {
|
||||
public static void processPacket(Player player, Packet packet) {
|
||||
int packetType = packet.getOpcode();
|
||||
int packetSize = packet.getLength();
|
||||
PacketType p = packetId[packetType];
|
||||
if(p != null && packetType > 0 && packetType < 257 && packetType == player.packetType && packetSize == player.packetSize) {
|
||||
if(p != null && packetType > 0 && packetType < 257) {
|
||||
if (GameConstants.sendServerPackets && player.playerRights == 3) {
|
||||
player.getPacketSender().sendMessage("PacketType: " + packetType + ". PacketSize: " + packetSize + ".");
|
||||
}
|
||||
try {
|
||||
p.processPacket(player, packetType, packetSize);
|
||||
p.processPacket(player, packet);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.rs2.net.packets;
|
||||
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
|
||||
public interface PacketType {
|
||||
|
||||
public void processPacket(Player player, int packetType, int packetSize);
|
||||
public void processPacket(Player player, Packet packet);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.rs2.game.content.combat.range.RangeData;
|
||||
import com.rs2.game.items.ItemAssistant;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.game.players.PlayerHandler;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
|
||||
public class AttackPlayer implements PacketType {
|
||||
@@ -15,23 +16,23 @@ public class AttackPlayer implements PacketType {
|
||||
public static final int ATTACK_PLAYER = 73, MAGE_PLAYER = 249;
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
player.endCurrentTask();
|
||||
player.playerIndex = 0;
|
||||
player.npcIndex = 0;
|
||||
switch (packetType) {
|
||||
switch (packet.getOpcode()) {
|
||||
|
||||
/**
|
||||
* Attack player
|
||||
**/
|
||||
case ATTACK_PLAYER:
|
||||
player.playerIndex = player.getInStream().readSignedWordBigEndian();
|
||||
player.playerIndex = packet.readSignedWordBigEndian();
|
||||
if (PlayerHandler.players[player.playerIndex] == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (player.inDuelArena() && !player.duelingArena()) {
|
||||
player.getChallengePlayer().processPacket(player, packetType, packetSize);
|
||||
player.getChallengePlayer().processPacket(player, null);
|
||||
}
|
||||
|
||||
if (player.respawnTimer > 0) {
|
||||
@@ -149,8 +150,8 @@ public class AttackPlayer implements PacketType {
|
||||
break;
|
||||
}
|
||||
|
||||
player.playerIndex = player.getInStream().readSignedWordA();
|
||||
int castingSpellId = player.getInStream().readSignedWordBigEndian();
|
||||
player.playerIndex = packet.readSignedWordA();
|
||||
int castingSpellId = packet.readSignedWordBigEndian();
|
||||
player.castingSpellId = castingSpellId;
|
||||
player.usingMagic = false;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.rs2.GameConstants;
|
||||
import com.rs2.game.content.random.PartyRoom;
|
||||
import com.rs2.game.content.skills.crafting.JewelryMaking;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
import com.rs2.world.Boundary;
|
||||
|
||||
@@ -13,10 +14,10 @@ import com.rs2.world.Boundary;
|
||||
public class Bank10 implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
int interfaceId = player.getInStream().readUnsignedWordBigEndian();
|
||||
int removeId = player.getInStream().readUnsignedWordA();
|
||||
int removeSlot = player.getInStream().readUnsignedWordA();
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
int interfaceId = packet.readUnsignedWordBigEndian();
|
||||
int removeId = packet.readUnsignedWordA();
|
||||
int removeSlot = packet.readUnsignedWordA();
|
||||
player.endCurrentTask();
|
||||
switch (interfaceId) {
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.rs2.GameConstants;
|
||||
import com.rs2.game.content.random.PartyRoom;
|
||||
import com.rs2.game.content.skills.crafting.JewelryMaking;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
import com.rs2.world.Boundary;
|
||||
|
||||
@@ -13,10 +14,10 @@ import com.rs2.world.Boundary;
|
||||
public class Bank5 implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
int interfaceId = player.getInStream().readSignedWordBigEndianA();
|
||||
int removeId = player.getInStream().readSignedWordBigEndianA();
|
||||
int removeSlot = player.getInStream().readSignedWordBigEndian();
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
int interfaceId = packet.readSignedWordBigEndianA();
|
||||
int removeId = packet.readSignedWordBigEndianA();
|
||||
int removeSlot = packet.readSignedWordBigEndian();
|
||||
player.endCurrentTask();
|
||||
switch (interfaceId) {
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.rs2.game.content.random.PartyRoom;
|
||||
import com.rs2.game.items.GameItem;
|
||||
import com.rs2.game.items.ItemData;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
import com.rs2.world.Boundary;
|
||||
|
||||
@@ -13,10 +14,10 @@ import com.rs2.world.Boundary;
|
||||
public class BankAll implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
int removeSlot = player.getInStream().readUnsignedWordA();
|
||||
int interfaceId = player.getInStream().readUnsignedWord();
|
||||
int removeId = player.getInStream().readUnsignedWordA();
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
int removeSlot = packet.readUnsignedWordA();
|
||||
int interfaceId = packet.readUnsignedWord();
|
||||
int removeId = packet.readUnsignedWordA();
|
||||
player.endCurrentTask();
|
||||
switch (interfaceId) {
|
||||
case 2274:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.rs2.net.packets.impl;
|
||||
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
|
||||
/**
|
||||
@@ -13,19 +14,19 @@ public class BankX1 implements PacketType {
|
||||
public int XremoveSlot, XinterfaceID, XremoveID, Xamount;
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
player.endCurrentTask();
|
||||
if (packetType == 135) {
|
||||
player.xRemoveSlot = player.getInStream().readSignedWordBigEndian();
|
||||
player.xInterfaceId = player.getInStream().readUnsignedWordA();
|
||||
player.xRemoveId = player.getInStream().readSignedWordBigEndian();
|
||||
if (packet.getOpcode() == 135) {
|
||||
player.xRemoveSlot = packet.readSignedWordBigEndian();
|
||||
player.xInterfaceId = packet.readUnsignedWordA();
|
||||
player.xRemoveId = packet.readSignedWordBigEndian();
|
||||
} else {
|
||||
if (player.xInterfaceId == 7423) {
|
||||
player.getItemAssistant().bankItem(player.xRemoveId, player.xRemoveSlot, Xamount);// Depo 1
|
||||
player.getItemAssistant().resetItems(7423);
|
||||
}
|
||||
}
|
||||
if (packetType == PART1) {
|
||||
if (packet.getOpcode() == PART1) {
|
||||
synchronized (player) {
|
||||
player.getOutStream().createFrame(27);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.rs2.net.packets.impl;
|
||||
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.game.players.PlayerHandler;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
|
||||
/**
|
||||
@@ -10,10 +11,10 @@ import com.rs2.net.packets.PacketType;
|
||||
public class ChallengePlayer implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
switch (packetType) {
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
switch (packet.getOpcode()) {
|
||||
case 128:
|
||||
int answerPlayer = player.getInStream().readUnsignedWord();
|
||||
int answerPlayer = packet.readUnsignedWord();
|
||||
if(PlayerHandler.players[answerPlayer] == null || answerPlayer == player.playerId)
|
||||
return;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.rs2.net.packets.impl;
|
||||
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
|
||||
/**
|
||||
@@ -35,8 +36,8 @@ public class ChangeAppearance implements PacketType {
|
||||
};
|
||||
|
||||
@Override
|
||||
public void processPacket(final Player player, final int packetType, final int packetSize) {
|
||||
final int gender = player.getInStream().readSignedByte();
|
||||
public void processPacket(final Player player, Packet packet) {
|
||||
final int gender = packet.readSignedByte();
|
||||
|
||||
if (gender != 0 && gender != 1) {
|
||||
return;
|
||||
@@ -44,7 +45,7 @@ public class ChangeAppearance implements PacketType {
|
||||
|
||||
final int[] apperances = new int[MALE_VALUES.length]; // appearance values check
|
||||
for (int i = 0; i < apperances.length; i++) {
|
||||
int value = player.getInStream().readSignedByte();
|
||||
int value = packet.readSignedByte();
|
||||
if (value < (gender == 0 ? MALE_VALUES[i][0] : FEMALE_VALUES[i][0])
|
||||
|| value > (gender == 0 ? MALE_VALUES[i][1]
|
||||
: FEMALE_VALUES[i][1])) {
|
||||
@@ -55,7 +56,7 @@ public class ChangeAppearance implements PacketType {
|
||||
|
||||
final int[] colors = new int[ALLOWED_COLORS.length]; // color value check
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
int value = player.getInStream().readSignedByte();
|
||||
int value = packet.readSignedByte();
|
||||
if (value < ALLOWED_COLORS[i][0] || value > ALLOWED_COLORS[i][1]) {
|
||||
value = ALLOWED_COLORS[i][0];
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.rs2.GameEngine;
|
||||
import com.rs2.game.content.music.Music;
|
||||
import com.rs2.game.globalworldobjects.Doors;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
import com.rs2.world.GlobalDropsHandler;
|
||||
|
||||
@@ -14,7 +15,7 @@ import com.rs2.world.GlobalDropsHandler;
|
||||
public class ChangeRegions implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
if (GameConstants.SOUND && player.musicOn) {
|
||||
Music.playMusic(player);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.rs2.net.packets.impl;
|
||||
import com.rs2.Connection;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.game.players.antimacro.AntiSpam;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
import com.rs2.util.Misc;
|
||||
|
||||
@@ -12,13 +13,13 @@ import com.rs2.util.Misc;
|
||||
public class Chat implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
player.setChatTextEffects(player.getInStream().readUnsignedByteS());
|
||||
player.setChatTextColor(player.getInStream().readUnsignedByteS());
|
||||
player.setChatTextSize((byte) (player.packetSize - 2));
|
||||
player.inStream.readBytes_reverseA(player.getChatText(), player.getChatTextSize(), 0);
|
||||
ReportHandler.addText(player.playerName, player.getChatText(), packetSize - 2);
|
||||
String word = Misc.textUnpack(player.getChatText(), player.packetSize - 2).toLowerCase();
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
player.setChatTextEffects(packet.readUnsignedByteS());
|
||||
player.setChatTextColor(packet.readUnsignedByteS());
|
||||
player.setChatTextSize((byte) (packet.getLength() - 2));
|
||||
packet.readBytes_reverseA(player.getChatText(), player.getChatTextSize(), 0);
|
||||
ReportHandler.addText(player.playerName, player.getChatText(), packet.getLength() - 2);
|
||||
String word = Misc.textUnpack(player.getChatText(), packet.getLength() - 2).toLowerCase();
|
||||
if (AntiSpam.blockedWords(player, word, true) && !Connection.isMuted(player)) {
|
||||
player.setChatTextUpdateRequired(true);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.rs2.game.items.impl.ExperienceLamp;
|
||||
import com.rs2.game.items.impl.Flowers;
|
||||
import com.rs2.game.items.impl.GodBooks;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
import com.rs2.util.GameLogger;
|
||||
import com.rs2.util.Misc;
|
||||
@@ -27,11 +28,11 @@ import com.rs2.util.Misc;
|
||||
public class ClickItem implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
player.endCurrentTask();
|
||||
player.getInStream().readSignedWordBigEndianA();
|
||||
int itemSlot = player.getInStream().readUnsignedWordA();
|
||||
int itemId = player.getInStream().readUnsignedWordBigEndian();
|
||||
packet.readSignedWordBigEndianA();
|
||||
int itemSlot = packet.readUnsignedWordA();
|
||||
int itemId = packet.readUnsignedWordBigEndian();
|
||||
if (itemId != player.playerItems[itemSlot] - 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.rs2.game.content.combat.range.RangeData;
|
||||
import com.rs2.game.items.ItemAssistant;
|
||||
import com.rs2.game.npcs.NpcHandler;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
|
||||
/**
|
||||
@@ -23,7 +24,7 @@ public class ClickNPC implements PacketType {
|
||||
SECOND_CLICK = 17, THIRD_CLICK = 21;
|
||||
|
||||
@Override
|
||||
public void processPacket(final Player player, int packetType, int packetSize) {
|
||||
public void processPacket(final Player player, Packet packet) {
|
||||
player.npcIndex = 0;
|
||||
player.npcClickIndex = 0;
|
||||
player.playerIndex = 0;
|
||||
@@ -32,7 +33,7 @@ public class ClickNPC implements PacketType {
|
||||
player.getCombatAssistant().resetPlayerAttack();
|
||||
player.getPlayerAssistant().requestUpdates();
|
||||
player.endCurrentTask();
|
||||
switch (packetType) {
|
||||
switch (packet.getOpcode()) {
|
||||
|
||||
/**
|
||||
* Attack npc melee or range
|
||||
@@ -61,7 +62,7 @@ public class ClickNPC implements PacketType {
|
||||
player.getPacketSender().sendMessage("I can't reach that.");
|
||||
break;
|
||||
}
|
||||
player.npcIndex = player.getInStream().readUnsignedWordA();
|
||||
player.npcIndex = packet.readUnsignedWordA();
|
||||
if (NpcHandler.npcs[player.npcIndex] == null) {
|
||||
player.npcIndex = 0;
|
||||
break;
|
||||
@@ -188,8 +189,8 @@ public class ClickNPC implements PacketType {
|
||||
// c.usingSpecial = false;
|
||||
// c.getItems().updateSpecialBar();
|
||||
|
||||
player.npcIndex = player.getInStream().readSignedWordBigEndianA();
|
||||
int castingSpellId = player.getInStream().readSignedWordA();
|
||||
player.npcIndex = packet.readSignedWordBigEndianA();
|
||||
int castingSpellId = packet.readSignedWordA();
|
||||
player.usingMagic = false;
|
||||
|
||||
if (NpcHandler.npcs[player.npcIndex] == null) {
|
||||
@@ -230,7 +231,7 @@ public class ClickNPC implements PacketType {
|
||||
break;
|
||||
|
||||
case FIRST_CLICK:
|
||||
player.npcClickIndex = player.inStream.readSignedWordBigEndian();
|
||||
player.npcClickIndex = packet.readSignedWordBigEndian();
|
||||
player.npcType = NpcHandler.npcs[player.npcClickIndex].npcType;
|
||||
|
||||
if (player.goodDistance(NpcHandler.npcs[player.npcClickIndex].getX(),
|
||||
@@ -274,7 +275,7 @@ public class ClickNPC implements PacketType {
|
||||
}
|
||||
break;
|
||||
case SECOND_CLICK:
|
||||
player.npcClickIndex = player.inStream.readUnsignedWordBigEndianA();
|
||||
player.npcClickIndex = packet.readUnsignedWordBigEndianA();
|
||||
player.npcType = NpcHandler.npcs[player.npcClickIndex].npcType;
|
||||
if (player.goodDistance(NpcHandler.npcs[player.npcClickIndex].getX(),
|
||||
NpcHandler.npcs[player.npcClickIndex].getY(), player.getX(),
|
||||
@@ -318,7 +319,7 @@ public class ClickNPC implements PacketType {
|
||||
break;
|
||||
|
||||
case THIRD_CLICK:
|
||||
player.npcClickIndex = player.inStream.readSignedWord();
|
||||
player.npcClickIndex = packet.readSignedWord();
|
||||
player.npcType = NpcHandler.npcs[player.npcClickIndex].npcType;
|
||||
if (player.goodDistance(NpcHandler.npcs[player.npcClickIndex].getX(),
|
||||
NpcHandler.npcs[player.npcClickIndex].getY(), player.getX(),
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.rs2.game.globalworldobjects.Doors;
|
||||
import com.rs2.game.npcs.NpcHandler;
|
||||
import com.rs2.game.objects.Objects;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
import com.rs2.world.clip.Region;
|
||||
|
||||
@@ -78,40 +79,40 @@ public class ClickObject implements PacketType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processPacket(final Player player, int packetType, int packetSize) {
|
||||
public void processPacket(final Player player, Packet packet) {
|
||||
player.clickObjectType = player.objectX = player.objectId = player.objectY = 0;
|
||||
player.getPlayerAssistant().resetFollow();
|
||||
player.getCombatAssistant().resetPlayerAttack();
|
||||
player.getPlayerAssistant().requestUpdates();
|
||||
player.endCurrentTask();
|
||||
switch (packetType) {
|
||||
switch (packet.getOpcode()) {
|
||||
|
||||
case FIRST_CLICK:
|
||||
player.objectX = player.getInStream().readSignedWordBigEndianA();
|
||||
player.objectId = player.getInStream().readUnsignedWord();
|
||||
player.objectY = player.getInStream().readUnsignedWordA();
|
||||
player.objectX = packet.readSignedWordBigEndianA();
|
||||
player.objectId = packet.readUnsignedWord();
|
||||
player.objectY = packet.readUnsignedWordA();
|
||||
onObjectReached(player, (p) -> completeObjectClick(p, 1));
|
||||
break;
|
||||
|
||||
case SECOND_CLICK:
|
||||
player.objectId = player.getInStream().readUnsignedWordBigEndianA();
|
||||
player.objectY = player.getInStream().readSignedWordBigEndian();
|
||||
player.objectX = player.getInStream().readUnsignedWordA();
|
||||
player.objectId = packet.readUnsignedWordBigEndianA();
|
||||
player.objectY = packet.readSignedWordBigEndian();
|
||||
player.objectX = packet.readUnsignedWordA();
|
||||
onObjectReached(player, (p) -> completeObjectClick(p, 2));
|
||||
break;
|
||||
|
||||
case THIRD_CLICK: // 'F'
|
||||
player.objectX = player.getInStream().readSignedWordBigEndian();
|
||||
player.objectY = player.getInStream().readUnsignedWord();
|
||||
player.objectId = player.getInStream().readUnsignedWordBigEndianA();
|
||||
player.objectX = packet.readSignedWordBigEndian();
|
||||
player.objectY = packet.readUnsignedWord();
|
||||
player.objectId = packet.readUnsignedWordBigEndianA();
|
||||
onObjectReached(player, (p) -> completeObjectClick(p, 3));
|
||||
break;
|
||||
|
||||
|
||||
case FOURTH_CLICK:
|
||||
player.objectX = player.getInStream().readSignedWordBigEndianA();
|
||||
player.objectId = player.getInStream().readUnsignedWordA();
|
||||
player.objectY = player.getInStream().readUnsignedWordBigEndianA();
|
||||
player.objectX = packet.readSignedWordBigEndianA();
|
||||
player.objectId = packet.readUnsignedWordA();
|
||||
player.objectY = packet.readUnsignedWordBigEndianA();
|
||||
onObjectReached(player, (p) -> completeObjectClick(p, 4));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -2,13 +2,14 @@ package com.rs2.net.packets.impl;
|
||||
|
||||
import com.rs2.game.items.ItemAssistant;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
|
||||
public class ClickTab implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(final Player player, int packetType, int packetSize) {
|
||||
switch (packetSize) {
|
||||
public void processPacket(final Player player, Packet packet) {
|
||||
switch (packet.getLength()) {
|
||||
case 1:// first part.
|
||||
if (player.tutorialProgress == 0) { // wrench
|
||||
player.getPacketSender().chatbox(6180);
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.rs2.game.objects.impl.Climbing;
|
||||
import com.rs2.game.players.Client;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.game.players.PlayerHandler;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
import com.rs2.util.Misc;
|
||||
import com.rs2.world.Boundary;
|
||||
@@ -44,8 +45,8 @@ import com.rs2.world.Boundary;
|
||||
public class ClickingButtons implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(final Player player, int packetType, int packetSize) {
|
||||
int actionButtonId = Misc.hexToInt(player.getInStream().buffer, 0, packetSize);
|
||||
public void processPacket(final Player player, Packet packet) {
|
||||
int actionButtonId = packet.readHex();
|
||||
player.getGlassBlowing().handleActionButtin(actionButtonId);
|
||||
GnomeGlider.flightButtons(player, actionButtonId);
|
||||
player.getEmoteHandler().startEmote(actionButtonId);
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.rs2.net.packets.impl;
|
||||
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
|
||||
public class ClickingInGame implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.rs2.net.packets.impl;
|
||||
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.game.players.PlayerHandler;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
import com.rs2.util.Misc;
|
||||
|
||||
@@ -11,7 +12,7 @@ import com.rs2.util.Misc;
|
||||
public class ClickingStuff implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
if (player.playerIsBusy()) {
|
||||
player.playerIsBusy = false;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.rs2.game.bots.BotHandler;
|
||||
import com.rs2.game.npcs.NpcHandler;
|
||||
import com.rs2.game.players.*;
|
||||
import com.rs2.game.players.antimacro.AntiSpam;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
import com.rs2.util.Misc;
|
||||
import com.rs2.world.clip.Region;
|
||||
@@ -21,8 +22,8 @@ import java.util.GregorianCalendar;
|
||||
public class Commands implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
String[] messageArr = player.getInStream().readString().split(" ");
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
String[] messageArr = packet.readString().split(" ");
|
||||
String playerCommand = messageArr[0];
|
||||
String[] commandArguments = Arrays.copyOfRange(messageArr, 1, messageArr.length);
|
||||
if ((playerCommand.startsWith("ban") || playerCommand.startsWith("ip") || playerCommand.startsWith("mute") || playerCommand.startsWith("un")) && player.playerRights > 0 && player.playerRights < 4) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.rs2.game.items.ItemConstants;
|
||||
import com.rs2.game.items.impl.RareProtection;
|
||||
import com.rs2.game.npcs.impl.Pets;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
|
||||
/**
|
||||
@@ -18,11 +19,11 @@ import com.rs2.net.packets.PacketType;
|
||||
public class DropItem implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
int itemId = player.getInStream().readUnsignedWordA();
|
||||
player.getInStream().readUnsignedByte();
|
||||
player.getInStream().readUnsignedByte();
|
||||
int slot = player.getInStream().readUnsignedWordA();
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
int itemId = packet.readUnsignedWordA();
|
||||
packet.readUnsignedByte();
|
||||
packet.readUnsignedByte();
|
||||
int slot = packet.readUnsignedWordA();
|
||||
if (!player.getItemAssistant().playerHasItem(itemId) || !RareProtection.removeItemOtherActions(player, itemId) || System.currentTimeMillis() - player.alchDelay < 1800 || player.stopPlayerPacket || System.currentTimeMillis() - player.buryDelay < 1800 || !CastleWars.deleteCastleWarsItems(player, itemId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2,13 +2,14 @@ package com.rs2.net.packets.impl;
|
||||
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.game.players.PlayerHandler;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
|
||||
public class FollowPlayer implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
int followPlayer = player.getInStream().readUnsignedWordBigEndian();
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
int followPlayer = packet.readUnsignedWordBigEndian();
|
||||
if (PlayerHandler.players[followPlayer] == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.rs2.net.packets.impl;
|
||||
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
|
||||
/**
|
||||
@@ -10,7 +11,7 @@ import com.rs2.net.packets.PacketType;
|
||||
public class IdleLogout implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
if (player.underAttackBy > 0 || player.underAttackBy2 > 0 || player.isBot) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4,15 +4,16 @@ import com.rs2.game.content.random.PartyRoom;
|
||||
import com.rs2.game.content.skills.cooking.Cooking;
|
||||
import com.rs2.game.content.skills.smithing.Smelting;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
import com.rs2.world.Boundary;
|
||||
|
||||
public class InterfaceX implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
player.endCurrentTask();
|
||||
int Xamount = player.getInStream().readDWord();
|
||||
int Xamount = packet.readDWord();
|
||||
if (Xamount < 0) {
|
||||
Xamount = player.getItemAssistant().getItemAmount(player.xRemoveId);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.rs2.net.packets.impl;
|
||||
import com.rs2.event.impl.ItemSecondClickEvent;
|
||||
import com.rs2.game.items.impl.HandleEmpty;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
|
||||
/**
|
||||
@@ -13,8 +14,8 @@ import com.rs2.net.packets.PacketType;
|
||||
public class ItemClick2 implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
int itemId = player.getInStream().readSignedWordA();
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
int itemId = packet.readSignedWordA();
|
||||
|
||||
if (!player.getItemAssistant().playerHasItem(itemId, 1)) {
|
||||
return;
|
||||
|
||||
@@ -3,15 +3,16 @@ package com.rs2.net.packets.impl;
|
||||
import com.rs2.game.content.skills.firemaking.Firemaking;
|
||||
import com.rs2.game.content.skills.firemaking.LogData;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
|
||||
public class ItemClick2OnGroundItem implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
final int itemX = player.getInStream().readSignedWordBigEndian();
|
||||
final int itemY = player.getInStream().readSignedWordBigEndianA();
|
||||
final int itemId = player.getInStream().readUnsignedWordA();
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
final int itemX = packet.readSignedWordBigEndian();
|
||||
final int itemY = packet.readSignedWordBigEndianA();
|
||||
final int itemId = packet.readUnsignedWordA();
|
||||
System.out.println("ItemClick2OnGroundItem - " + player.playerName + " - " + itemId + " - " + itemX + " - " + itemY);
|
||||
// Reset position for the telekinetic guardian statue
|
||||
if (itemId == 6888) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.rs2.game.content.skills.runecrafting.Runecrafting;
|
||||
import com.rs2.game.items.impl.HandleEmpty;
|
||||
import com.rs2.game.items.impl.Teles;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
import com.rs2.util.Misc;
|
||||
|
||||
@@ -17,10 +18,10 @@ import com.rs2.util.Misc;
|
||||
public class ItemClick3 implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
int itemId11 = player.getInStream().readSignedWordBigEndianA();
|
||||
int itemId1 = player.getInStream().readSignedWordA();
|
||||
int itemId = player.getInStream().readSignedWordA();
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
int itemId11 = packet.readSignedWordBigEndianA();
|
||||
int itemId1 = packet.readSignedWordA();
|
||||
int itemId = packet.readSignedWordA();
|
||||
if (!player.getItemAssistant().playerHasItem(itemId, 1)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3,19 +3,20 @@ package com.rs2.net.packets.impl;
|
||||
import com.rs2.GameEngine;
|
||||
import com.rs2.game.content.skills.firemaking.Firemaking;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
import com.rs2.util.Misc;
|
||||
|
||||
public class ItemOnGroundItem implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
player.getInStream().readSignedWordBigEndian();
|
||||
int itemUsed = player.getInStream().readSignedWordA();
|
||||
int groundItem = player.getInStream().readUnsignedWord();
|
||||
int gItemY = player.getInStream().readSignedWordA();
|
||||
int itemUsedSlot = player.getInStream().readSignedWordBigEndianA();
|
||||
int gItemX = player.getInStream().readUnsignedWord();
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
packet.readSignedWordBigEndian();
|
||||
int itemUsed = packet.readSignedWordA();
|
||||
int groundItem = packet.readUnsignedWord();
|
||||
int gItemY = packet.readSignedWordA();
|
||||
int itemUsedSlot = packet.readSignedWordBigEndianA();
|
||||
int gItemX = packet.readUnsignedWord();
|
||||
if (!player.getItemAssistant().playerHasItem(itemUsed, 1, itemUsedSlot)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2,14 +2,15 @@ package com.rs2.net.packets.impl;
|
||||
|
||||
import com.rs2.game.items.UseItem;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
|
||||
public class ItemOnItem implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
int usedWithSlot = player.getInStream().readUnsignedWord();
|
||||
int itemUsedSlot = player.getInStream().readUnsignedWordA();
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
int usedWithSlot = packet.readUnsignedWord();
|
||||
int itemUsedSlot = packet.readUnsignedWordA();
|
||||
int useWith = player.playerItems[usedWithSlot] - 1;
|
||||
int itemUsed = player.playerItems[itemUsedSlot] - 1;
|
||||
if (!player.getItemAssistant().playerHasItem(useWith, 1, usedWithSlot)|| !player.getItemAssistant().playerHasItem(itemUsed, 1, itemUsedSlot)) {
|
||||
|
||||
@@ -5,15 +5,16 @@ import com.rs2.game.content.skills.SkillHandler;
|
||||
import com.rs2.game.items.UseItem;
|
||||
import com.rs2.game.npcs.NpcHandler;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
|
||||
public class ItemOnNpc implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(final Player player, int packetType, int packetSize) {
|
||||
final int itemId = player.getInStream().readSignedWordA();
|
||||
final int i = player.getInStream().readSignedWordA();
|
||||
final int slot = player.getInStream().readSignedWordBigEndian();
|
||||
public void processPacket(final Player player, Packet packet) {
|
||||
final int itemId = packet.readSignedWordA();
|
||||
final int i = packet.readSignedWordA();
|
||||
final int slot = packet.readSignedWordBigEndian();
|
||||
final int npcId = NpcHandler.npcs[i].npcType;
|
||||
SkillHandler.resetItemOnNpc(player);
|
||||
player.endCurrentTask();
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.rs2.game.content.skills.prayer.Ectofuntus;
|
||||
import com.rs2.game.items.UseItem;
|
||||
import com.rs2.game.items.impl.Fillables;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
import com.rs2.world.Boundary;
|
||||
import com.rs2.world.clip.Region;
|
||||
@@ -19,13 +20,13 @@ import com.rs2.world.clip.Region;
|
||||
public class ItemOnObject implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
player.getInStream().readUnsignedWord();
|
||||
int objectId = player.getInStream().readSignedWordBigEndian();
|
||||
int objectY = player.getInStream().readSignedWordBigEndianA();
|
||||
player.getInStream().readUnsignedWord();
|
||||
int objectX = player.getInStream().readSignedWordBigEndianA();
|
||||
int itemId = player.getInStream().readUnsignedWord();
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
packet.readUnsignedWord();
|
||||
int objectId = packet.readSignedWordBigEndian();
|
||||
int objectY = packet.readSignedWordBigEndianA();
|
||||
packet.readUnsignedWord();
|
||||
int objectX = packet.readSignedWordBigEndianA();
|
||||
int itemId = packet.readUnsignedWord();
|
||||
player.turnPlayerTo(objectX, objectY);
|
||||
player.objectX = objectX;
|
||||
player.objectY = objectY;
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.rs2.net.packets.impl;
|
||||
import com.rs2.game.items.impl.RareProtection;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.game.players.PlayerHandler;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
import com.rs2.util.Misc;
|
||||
|
||||
@@ -13,9 +14,9 @@ import com.rs2.util.Misc;
|
||||
public class ItemOnPlayer implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
int playerId = player.inStream.readUnsignedWord();
|
||||
int itemId = player.playerItems[player.inStream.readSignedWordBigEndian()] - 1;
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
int playerId = packet.readUnsignedWord();
|
||||
int itemId = player.playerItems[packet.readSignedWordBigEndian()] - 1;
|
||||
player.endCurrentTask();
|
||||
switch (itemId) {
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.rs2.event.CycleEventContainer;
|
||||
import com.rs2.event.CycleEventHandler;
|
||||
import com.rs2.game.content.combat.magic.MagicData;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
import com.rs2.world.GlobalDropsHandler;
|
||||
import com.rs2.world.clip.PathFinder;
|
||||
@@ -18,11 +19,11 @@ import com.rs2.world.clip.PathFinder;
|
||||
public class MagicOnFloorItems implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(final Player player, int packetType, int packetSize) {
|
||||
final int itemY = player.getInStream().readSignedWordBigEndian();
|
||||
int itemId = player.getInStream().readUnsignedWord();
|
||||
final int itemX = player.getInStream().readSignedWordBigEndian();
|
||||
player.getInStream().readUnsignedWordA();
|
||||
public void processPacket(final Player player, Packet packet) {
|
||||
final int itemY = packet.readSignedWordBigEndian();
|
||||
int itemId = packet.readUnsignedWord();
|
||||
final int itemX = packet.readSignedWordBigEndian();
|
||||
packet.readUnsignedWordA();
|
||||
player.stopMovement();
|
||||
|
||||
if (!GameEngine.itemHandler.itemExists(itemId, itemX, itemY)) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.rs2.net.packets.impl;
|
||||
|
||||
import com.rs2.event.impl.MagicOnItemEvent;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
|
||||
/**
|
||||
@@ -11,11 +12,11 @@ import com.rs2.net.packets.PacketType;
|
||||
public class MagicOnItems implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
int slot = player.getInStream().readSignedWord();
|
||||
int itemId = player.getInStream().readSignedWordA();
|
||||
player.getInStream().readSignedWord();
|
||||
int spellId = player.getInStream().readSignedWordA();
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
int slot = packet.readSignedWord();
|
||||
int itemId = packet.readSignedWordA();
|
||||
packet.readSignedWord();
|
||||
int spellId = packet.readSignedWordA();
|
||||
player.endCurrentTask();
|
||||
if(!player.getItemAssistant().playerHasItem(itemId, 1, slot)) {
|
||||
return;
|
||||
|
||||
@@ -2,16 +2,17 @@ package com.rs2.net.packets.impl;
|
||||
|
||||
import com.rs2.game.content.skills.crafting.OrbCharging;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
|
||||
public class MagicOnObject implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
int x = player.getInStream().readSignedWordBigEndian();
|
||||
int magicId = player.getInStream().readUnsignedWord();
|
||||
int y = player.getInStream().readUnsignedWordA();
|
||||
int objectId = player.getInStream().readSignedWordBigEndian();
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
int x = packet.readSignedWordBigEndian();
|
||||
int magicId = packet.readUnsignedWord();
|
||||
int y = packet.readUnsignedWordA();
|
||||
int objectId = packet.readSignedWordBigEndian();
|
||||
|
||||
player.turnPlayerTo(x, y);
|
||||
switch (objectId) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.rs2.net.packets.impl;
|
||||
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
|
||||
/**
|
||||
@@ -9,11 +10,11 @@ import com.rs2.net.packets.PacketType;
|
||||
public class MoveItems implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
int interfaceId = player.getInStream().readSignedWordBigEndianA();
|
||||
boolean insertMode = player.getInStream().readSignedByteC() == 1;
|
||||
int from = player.getInStream().readSignedWordBigEndianA();
|
||||
int to = player.getInStream().readSignedWordBigEndian();
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
int interfaceId = packet.readSignedWordBigEndianA();
|
||||
boolean insertMode = packet.readSignedByteC() == 1;
|
||||
int from = packet.readSignedWordBigEndianA();
|
||||
int to = packet.readSignedWordBigEndian();
|
||||
if (player.inTrade) {
|
||||
player.getTrading().declineTrade();
|
||||
return;
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.rs2.game.content.skills.firemaking.LogData;
|
||||
import com.rs2.game.items.ItemAssistant;
|
||||
import com.rs2.game.items.impl.RareProtection;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
import com.rs2.util.GameLogger;
|
||||
import com.rs2.world.Boundary;
|
||||
@@ -24,10 +25,10 @@ public class PickupItem implements PacketType {
|
||||
|
||||
|
||||
@Override
|
||||
public void processPacket(final Player player, int packetType, int packetSize) {
|
||||
player.pItemY = player.getInStream().readSignedWordBigEndian();
|
||||
player.pItemId = player.getInStream().readUnsignedWord();
|
||||
player.pItemX = player.getInStream().readSignedWordBigEndian();
|
||||
public void processPacket(final Player player, Packet packet) {
|
||||
player.pItemY = packet.readSignedWordBigEndian();
|
||||
player.pItemId = packet.readUnsignedWord();
|
||||
player.pItemX = packet.readSignedWordBigEndian();
|
||||
// Cannot pickup the telekinetic guardian statue, should show overview of current maze
|
||||
if (player.pItemId == 6888) {
|
||||
player.getMageTrainingArena().telekinetic.observeStatue(player.pItemX, player.pItemY);
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.rs2.game.players.Client;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.game.players.PlayerHandler;
|
||||
import com.rs2.game.players.antimacro.AntiSpam;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
import com.rs2.util.GameLogger;
|
||||
import com.rs2.util.Misc;
|
||||
@@ -19,12 +20,12 @@ public class PrivateMessaging implements PacketType {
|
||||
CHANGE_PM_STATUS = 95, REMOVE_IGNORE = 59, ADD_IGNORE = 133;
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
switch (packetType) {
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
switch (packet.getOpcode()) {
|
||||
|
||||
case ADD_FRIEND:
|
||||
player.friendUpdate = true;
|
||||
long friendToAdd = player.getInStream().readQWord();
|
||||
long friendToAdd = packet.readQWord();
|
||||
boolean canAdd = true;
|
||||
|
||||
for (long friend : player.friends) {
|
||||
@@ -55,13 +56,13 @@ public class PrivateMessaging implements PacketType {
|
||||
break;
|
||||
|
||||
case SEND_PM:
|
||||
long sendMessageToFriendId = player.getInStream().readQWord();
|
||||
long sendMessageToFriendId = packet.readQWord();
|
||||
byte pmchatText[] = new byte[100];
|
||||
int pmchatTextSize = (byte) (packetSize - 8);
|
||||
player.getInStream().readBytes(pmchatText, pmchatTextSize, 0);
|
||||
String word = Misc.textUnpack(pmchatText, player.packetSize - 2).toLowerCase();// used
|
||||
int pmchatTextSize = (byte) (packet.getLength() - 8);
|
||||
packet.readBytes(pmchatText, pmchatTextSize, 0);
|
||||
String word = Misc.textUnpack(pmchatText, packet.getLength() - 2).toLowerCase();// used
|
||||
if (player.getPlayerAssistant().isPlayer()) {
|
||||
GameLogger.writeLog(player.playerName, "pmsent", player.playerName + " said " + Misc.textUnpack(pmchatText, packetSize - 8) + "");
|
||||
GameLogger.writeLog(player.playerName, "pmsent", player.playerName + " said " + Misc.textUnpack(pmchatText, packet.getLength() - 8) + "");
|
||||
}
|
||||
if (!AntiSpam.blockedWords(player, word, false) || Connection.isMuted(player)) {
|
||||
return;
|
||||
@@ -78,7 +79,7 @@ public class PrivateMessaging implements PacketType {
|
||||
if (friend == sendMessageToFriendId) {
|
||||
o.getPacketSender().sendPM(Misc.playerNameToInt64(player.playerName), player.playerRights, pmchatText, pmchatTextSize);
|
||||
if (player.getPlayerAssistant().isPlayer()) {
|
||||
GameLogger.writeLog(o.playerName, "pmrecieved", player.playerName + " said to " + o.playerName + " " + Misc.textUnpack(pmchatText, packetSize - 8) + "");
|
||||
GameLogger.writeLog(o.playerName, "pmrecieved", player.playerName + " said to " + o.playerName + " " + Misc.textUnpack(pmchatText, packet.getLength() - 8) + "");
|
||||
}
|
||||
pmSent = true;
|
||||
}
|
||||
@@ -97,7 +98,7 @@ public class PrivateMessaging implements PacketType {
|
||||
|
||||
case REMOVE_FRIEND:
|
||||
player.friendUpdate = true;
|
||||
long friendToRemove = player.getInStream().readQWord();
|
||||
long friendToRemove = packet.readQWord();
|
||||
|
||||
for (int i1 = 0; i1 < player.friends.length; i1++) {
|
||||
if (player.friends[i1] == friendToRemove) {
|
||||
@@ -118,7 +119,7 @@ public class PrivateMessaging implements PacketType {
|
||||
|
||||
case REMOVE_IGNORE:
|
||||
player.friendUpdate = true;
|
||||
long ignore = player.getInStream().readQWord();
|
||||
long ignore = packet.readQWord();
|
||||
|
||||
for (int i = 0; i < player.ignores.length; i++) {
|
||||
if (player.ignores[i] == ignore) {
|
||||
@@ -129,7 +130,7 @@ public class PrivateMessaging implements PacketType {
|
||||
break;
|
||||
|
||||
case CHANGE_PM_STATUS:
|
||||
player.privateChat = player.getInStream().readUnsignedByte();
|
||||
player.privateChat = packet.readUnsignedByte();
|
||||
for (int i1 = 1; i1 < PlayerHandler.players.length; i1++) {
|
||||
if (PlayerHandler.players[i1] != null
|
||||
&& PlayerHandler.players[i1].isActive) {
|
||||
@@ -143,7 +144,7 @@ public class PrivateMessaging implements PacketType {
|
||||
|
||||
case ADD_IGNORE:
|
||||
player.friendUpdate = true;
|
||||
long ignoreAdd = player.getInStream().readQWord();
|
||||
long ignoreAdd = packet.readQWord();
|
||||
for (int i = 0; i < player.ignores.length; i++) {
|
||||
if (player.ignores[i] == 0) {
|
||||
player.ignores[i] = ignoreAdd;
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.rs2.game.content.skills.crafting.JewelryMaking;
|
||||
import com.rs2.game.items.Weight;
|
||||
import com.rs2.game.items.impl.RareProtection;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
import com.rs2.world.Boundary;
|
||||
|
||||
@@ -15,10 +16,10 @@ import com.rs2.world.Boundary;
|
||||
public class RemoveItem implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
int interfaceId = player.getInStream().readUnsignedWordA();
|
||||
int removeSlot = player.getInStream().readUnsignedWordA();
|
||||
int removeId = player.getInStream().readUnsignedWordA();
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
int interfaceId = packet.readUnsignedWordA();
|
||||
int removeSlot = packet.readUnsignedWordA();
|
||||
int removeId = packet.readUnsignedWordA();
|
||||
if (!RareProtection.removeItem(player, removeId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package com.rs2.net.packets.impl;
|
||||
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
|
||||
public class Report implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
try {
|
||||
ReportHandler.handleReport(player);
|
||||
ReportHandler.handleReport(player, packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.util.Misc;
|
||||
|
||||
public class ReportHandler {
|
||||
@@ -59,11 +60,11 @@ public class ReportHandler {
|
||||
* ex
|
||||
*/
|
||||
|
||||
public static void handleReport(Player c) throws Exception {
|
||||
String player = Misc.longToReportPlayerName(c.inStream.readQWord2());
|
||||
public static void handleReport(Player c, Packet packet) throws Exception {
|
||||
String player = Misc.longToReportPlayerName(packet.readQWord2());
|
||||
player = player.replaceAll("_", " ");
|
||||
byte rule = (byte) c.inStream.readUnsignedByte();
|
||||
int mute = c.getInStream().readUnsignedByte();
|
||||
byte rule = (byte) packet.readUnsignedByte();
|
||||
int mute = packet.readUnsignedByte();
|
||||
|
||||
if (c.lastReported.equalsIgnoreCase(player) && System.currentTimeMillis() - c.lastReport < 60000) {
|
||||
c.getPacketSender().sendMessage("You can only report a player once every 60 seconds.");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.rs2.net.packets.impl;
|
||||
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
|
||||
/**
|
||||
@@ -9,7 +10,7 @@ import com.rs2.net.packets.PacketType;
|
||||
public class SilentPacket implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.rs2.net.packets.impl;
|
||||
|
||||
import com.rs2.GameConstants;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
|
||||
/**
|
||||
@@ -11,8 +12,8 @@ import com.rs2.net.packets.PacketType;
|
||||
public class Trade implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
int tradeId = player.getInStream().readSignedWordBigEndian();
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
int tradeId = packet.readSignedWordBigEndian();
|
||||
player.getPlayerAssistant().resetFollow();
|
||||
player.endCurrentTask();
|
||||
if (player.disconnected) {
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.rs2.game.items.impl.Greegree.MonkeyData;
|
||||
import com.rs2.game.players.Client;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.game.players.PlayerHandler;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
|
||||
/**
|
||||
@@ -19,7 +20,7 @@ import com.rs2.net.packets.PacketType;
|
||||
public class Walking implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
player.getDueling().checkDuelWalk();
|
||||
if (player.playerIsBusy()) {
|
||||
player.playerIsBusy = false;
|
||||
@@ -87,7 +88,7 @@ public class Walking implements PacketType {
|
||||
if (player.getPlayerAction().checkWalking() == false) {
|
||||
return;
|
||||
}
|
||||
if (packetType == 248 || packetType == 164) {
|
||||
if (packet.getOpcode() == 248 || packet.getOpcode() == 164) {
|
||||
player.faceUpdate(0);
|
||||
player.npcIndex = 0;
|
||||
player.playerIndex = 0;
|
||||
@@ -118,12 +119,12 @@ public class Walking implements PacketType {
|
||||
if (player.goodDistance(player.getX(), player.getY(),
|
||||
PlayerHandler.players[player.playerIndex].getX(),
|
||||
PlayerHandler.players[player.playerIndex].getY(), 1)
|
||||
&& packetType != 98) {
|
||||
&& packet.getOpcode() != 98) {
|
||||
player.playerIndex = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (packetType != 98) {
|
||||
if (packet.getOpcode() != 98) {
|
||||
player.getPacketSender().sendMessage("A magical force stops you from moving.");
|
||||
player.playerIndex = 0;
|
||||
}
|
||||
@@ -136,7 +137,7 @@ public class Walking implements PacketType {
|
||||
return;
|
||||
}
|
||||
|
||||
if (packetType == 98) {
|
||||
if (packet.getOpcode() == 98) {
|
||||
player.mageAllowed = true;
|
||||
}
|
||||
|
||||
@@ -170,8 +171,8 @@ public class Walking implements PacketType {
|
||||
}
|
||||
|
||||
player.endCurrentTask();
|
||||
|
||||
if (packetType == 248) {
|
||||
int packetSize = packet.getLength();
|
||||
if (packet.getOpcode() == 248) {
|
||||
packetSize -= 14;
|
||||
}
|
||||
//
|
||||
@@ -234,20 +235,20 @@ public class Walking implements PacketType {
|
||||
int realY = 0;
|
||||
|
||||
if (player.clickToTele) {
|
||||
firstStepX = player.getInStream().readSignedWordBigEndianA();
|
||||
firstStepX = packet.readSignedWordBigEndianA();
|
||||
} else {
|
||||
realX = player.getInStream().readSignedWordBigEndianA();
|
||||
realX = packet.readSignedWordBigEndianA();
|
||||
firstStepX = realX - player.getMapRegionX() * 8;
|
||||
}
|
||||
for (int i = 1; i < player.newWalkCmdSteps; i++) {
|
||||
player.getNewWalkCmdX()[i] = player.getInStream().readSignedByte();
|
||||
player.getNewWalkCmdY()[i] = player.getInStream().readSignedByte();
|
||||
player.getNewWalkCmdX()[i] = packet.readSignedByte();
|
||||
player.getNewWalkCmdY()[i] = packet.readSignedByte();
|
||||
}
|
||||
|
||||
if (player.clickToTele) {
|
||||
firstStepY = player.getInStream().readSignedWordBigEndian();
|
||||
firstStepY = packet.readSignedWordBigEndian();
|
||||
} else {
|
||||
realY = player.getInStream().readSignedWordBigEndian();
|
||||
realY = packet.readSignedWordBigEndian();
|
||||
firstStepY = realY - player.getMapRegionY() * 8;
|
||||
}
|
||||
|
||||
@@ -257,7 +258,7 @@ public class Walking implements PacketType {
|
||||
}
|
||||
}
|
||||
|
||||
player.setNewWalkCmdIsRunning(player.getInStream().readSignedByteC() == 1 && player.playerEnergy > 0);
|
||||
player.setNewWalkCmdIsRunning(packet.readSignedByteC() == 1 && player.playerEnergy > 0);
|
||||
for (int i1 = 0; i1 < player.newWalkCmdSteps; i1++) {
|
||||
if (player.clickToTele)
|
||||
player.getPlayerAssistant().movePlayer(player.getNewWalkCmdX()[i1] + firstStepX, player.getNewWalkCmdY()[i1] + firstStepY, player.heightLevel);
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.rs2.GameConstants;
|
||||
import com.rs2.game.items.Weight;
|
||||
import com.rs2.game.items.impl.RareProtection;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.net.Packet;
|
||||
import com.rs2.net.packets.PacketType;
|
||||
import com.rs2.util.Misc;
|
||||
|
||||
@@ -13,10 +14,10 @@ import com.rs2.util.Misc;
|
||||
public class WearItem implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Player player, int packetType, int packetSize) {
|
||||
player.wearId = player.getInStream().readUnsignedWord();
|
||||
player.wearSlot = player.getInStream().readUnsignedWordA();
|
||||
player.interfaceId = player.getInStream().readUnsignedWordA();
|
||||
public void processPacket(Player player, Packet packet) {
|
||||
player.wearId = packet.readUnsignedWord();
|
||||
player.wearSlot = packet.readUnsignedWordA();
|
||||
player.interfaceId = packet.readUnsignedWordA();
|
||||
Weight.updateWeight(player);
|
||||
if (!RareProtection.equipItem(player)) {
|
||||
return;
|
||||
|
||||
@@ -1,175 +0,0 @@
|
||||
package com.rs2.util;
|
||||
|
||||
public class ISAACRandomGen {
|
||||
|
||||
public int count;
|
||||
public int[] results;
|
||||
public int[] memory;
|
||||
public int accumulator;
|
||||
public int lastResult;
|
||||
public int counter;
|
||||
|
||||
public ISAACRandomGen(int[] seed) {
|
||||
memory = new int[256];
|
||||
results = new int[256];
|
||||
System.arraycopy(seed, 0, results, 0, seed.length);
|
||||
initializeKeySet();
|
||||
}
|
||||
|
||||
public int getNextKey() {
|
||||
// Server.add(Thread.currentThread().getName());
|
||||
// System.out.println(Thread.currentThread().getName());
|
||||
if (count-- == 0) {
|
||||
generateNextKeySet();
|
||||
count = 255;
|
||||
}
|
||||
return results[count];
|
||||
}
|
||||
|
||||
public void generateNextKeySet() {
|
||||
lastResult += ++counter;
|
||||
for (int i = 0; i < 256; i++) {
|
||||
int j = memory[i];
|
||||
if ((i & 3) == 0) {
|
||||
accumulator ^= accumulator << 13;
|
||||
} else if ((i & 3) == 1) {
|
||||
accumulator ^= accumulator >>> 6;
|
||||
} else if ((i & 3) == 2) {
|
||||
accumulator ^= accumulator << 2;
|
||||
} else if ((i & 3) == 3) {
|
||||
accumulator ^= accumulator >>> 16;
|
||||
}
|
||||
accumulator += memory[i + 128 & 0xff];
|
||||
int k;
|
||||
memory[i] = k = memory[(j & 0x3fc) >> 2] + accumulator + lastResult;
|
||||
results[i] = lastResult = memory[(k >> 8 & 0x3fc) >> 2] + j;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void initializeKeySet() {
|
||||
int i1;
|
||||
int j1;
|
||||
int k1;
|
||||
int l1;
|
||||
int i2;
|
||||
int j2;
|
||||
int k2;
|
||||
int l = i1 = j1 = k1 = l1 = i2 = j2 = k2 = 0x9e3779b9;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
l ^= i1 << 11;
|
||||
k1 += l;
|
||||
i1 += j1;
|
||||
i1 ^= j1 >>> 2;
|
||||
l1 += i1;
|
||||
j1 += k1;
|
||||
j1 ^= k1 << 8;
|
||||
i2 += j1;
|
||||
k1 += l1;
|
||||
k1 ^= l1 >>> 16;
|
||||
j2 += k1;
|
||||
l1 += i2;
|
||||
l1 ^= i2 << 10;
|
||||
k2 += l1;
|
||||
i2 += j2;
|
||||
i2 ^= j2 >>> 4;
|
||||
l += i2;
|
||||
j2 += k2;
|
||||
j2 ^= k2 << 8;
|
||||
i1 += j2;
|
||||
k2 += l;
|
||||
k2 ^= l >>> 9;
|
||||
j1 += k2;
|
||||
l += i1;
|
||||
}
|
||||
|
||||
for (int j = 0; j < 256; j += 8) {
|
||||
l += results[j];
|
||||
i1 += results[j + 1];
|
||||
j1 += results[j + 2];
|
||||
k1 += results[j + 3];
|
||||
l1 += results[j + 4];
|
||||
i2 += results[j + 5];
|
||||
j2 += results[j + 6];
|
||||
k2 += results[j + 7];
|
||||
l ^= i1 << 11;
|
||||
k1 += l;
|
||||
i1 += j1;
|
||||
i1 ^= j1 >>> 2;
|
||||
l1 += i1;
|
||||
j1 += k1;
|
||||
j1 ^= k1 << 8;
|
||||
i2 += j1;
|
||||
k1 += l1;
|
||||
k1 ^= l1 >>> 16;
|
||||
j2 += k1;
|
||||
l1 += i2;
|
||||
l1 ^= i2 << 10;
|
||||
k2 += l1;
|
||||
i2 += j2;
|
||||
i2 ^= j2 >>> 4;
|
||||
l += i2;
|
||||
j2 += k2;
|
||||
j2 ^= k2 << 8;
|
||||
i1 += j2;
|
||||
k2 += l;
|
||||
k2 ^= l >>> 9;
|
||||
j1 += k2;
|
||||
l += i1;
|
||||
memory[j] = l;
|
||||
memory[j + 1] = i1;
|
||||
memory[j + 2] = j1;
|
||||
memory[j + 3] = k1;
|
||||
memory[j + 4] = l1;
|
||||
memory[j + 5] = i2;
|
||||
memory[j + 6] = j2;
|
||||
memory[j + 7] = k2;
|
||||
}
|
||||
|
||||
for (int k = 0; k < 256; k += 8) {
|
||||
l += memory[k];
|
||||
i1 += memory[k + 1];
|
||||
j1 += memory[k + 2];
|
||||
k1 += memory[k + 3];
|
||||
l1 += memory[k + 4];
|
||||
i2 += memory[k + 5];
|
||||
j2 += memory[k + 6];
|
||||
k2 += memory[k + 7];
|
||||
l ^= i1 << 11;
|
||||
k1 += l;
|
||||
i1 += j1;
|
||||
i1 ^= j1 >>> 2;
|
||||
l1 += i1;
|
||||
j1 += k1;
|
||||
j1 ^= k1 << 8;
|
||||
i2 += j1;
|
||||
k1 += l1;
|
||||
k1 ^= l1 >>> 16;
|
||||
j2 += k1;
|
||||
l1 += i2;
|
||||
l1 ^= i2 << 10;
|
||||
k2 += l1;
|
||||
i2 += j2;
|
||||
i2 ^= j2 >>> 4;
|
||||
l += i2;
|
||||
j2 += k2;
|
||||
j2 ^= k2 << 8;
|
||||
i1 += j2;
|
||||
k2 += l;
|
||||
k2 ^= l >>> 9;
|
||||
j1 += k2;
|
||||
l += i1;
|
||||
memory[k] = l;
|
||||
memory[k + 1] = i1;
|
||||
memory[k + 2] = j1;
|
||||
memory[k + 3] = k1;
|
||||
memory[k + 4] = l1;
|
||||
memory[k + 5] = i2;
|
||||
memory[k + 6] = j2;
|
||||
memory[k + 7] = k2;
|
||||
}
|
||||
|
||||
generateNextKeySet();
|
||||
count = 256;
|
||||
}
|
||||
}
|
||||
@@ -124,20 +124,7 @@ public class Misc {
|
||||
}
|
||||
return temp.toUpperCase().trim();
|
||||
}
|
||||
|
||||
public static int hexToInt(byte data[], int offset, int len) {
|
||||
int temp = 0;
|
||||
int i = 1000;
|
||||
for (int cntr = 0; cntr < len; cntr++) {
|
||||
int num = (data[offset + cntr] & 0xFF) * i;
|
||||
temp += num;
|
||||
if (i > 1) {
|
||||
i = i / 1000;
|
||||
}
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
public static int random2(int range) {
|
||||
return (int) (java.lang.Math.random() * range + 1);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.rs2.util;
|
||||
|
||||
import org.apollo.util.security.IsaacRandom;
|
||||
|
||||
import com.rs2.GameConstants;
|
||||
|
||||
public class Stream {
|
||||
@@ -12,36 +14,6 @@ public class Stream {
|
||||
currentOffset = 0;
|
||||
}
|
||||
|
||||
public long readQWord2() {
|
||||
final long l = readDWord() & 0xffffffffL;
|
||||
final long l1 = readDWord() & 0xffffffffL;
|
||||
return (l << 32) + l1;
|
||||
}
|
||||
|
||||
public byte readSignedByteA() {
|
||||
return (byte) (buffer[currentOffset++] - 128);
|
||||
}
|
||||
|
||||
public byte readSignedByteC() {
|
||||
return (byte) -buffer[currentOffset++];
|
||||
}
|
||||
|
||||
public byte readSignedByteS() {
|
||||
return (byte) (128 - buffer[currentOffset++]);
|
||||
}
|
||||
|
||||
public int readUnsignedByteA() {
|
||||
return buffer[currentOffset++] - 128 & 0xff;
|
||||
}
|
||||
|
||||
public int readUnsignedByteC() {
|
||||
return -buffer[currentOffset++] & 0xff;
|
||||
}
|
||||
|
||||
public int readUnsignedByteS() {
|
||||
return 128 - buffer[currentOffset++] & 0xff;
|
||||
}
|
||||
|
||||
public void writeByteA(int i) {
|
||||
ensureCapacity(1);
|
||||
buffer[currentOffset++] = (byte) (i + 128);
|
||||
@@ -56,49 +28,7 @@ public class Stream {
|
||||
ensureCapacity(1);
|
||||
buffer[currentOffset++] = (byte) -i;
|
||||
}
|
||||
|
||||
public int readSignedWordBigEndian() {
|
||||
currentOffset += 2;
|
||||
int i = ((buffer[currentOffset - 1] & 0xff) << 8) + (buffer[currentOffset - 2] & 0xff);
|
||||
if (i > 32767) {
|
||||
i -= 0x10000;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public int readSignedWordA() {
|
||||
currentOffset += 2;
|
||||
int i = ((buffer[currentOffset - 2] & 0xff) << 8) + (buffer[currentOffset - 1] - 128 & 0xff);
|
||||
if (i > 32767) {
|
||||
i -= 0x10000;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public int readSignedWordBigEndianA() {
|
||||
currentOffset += 2;
|
||||
int i = ((buffer[currentOffset - 1] & 0xff) << 8) + (buffer[currentOffset - 2] - 128 & 0xff);
|
||||
if (i > 32767) {
|
||||
i -= 0x10000;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public int readUnsignedWordBigEndian() {
|
||||
currentOffset += 2;
|
||||
return ((buffer[currentOffset - 1] & 0xff) << 8) + (buffer[currentOffset - 2] & 0xff);
|
||||
}
|
||||
|
||||
public int readUnsignedWordA() {
|
||||
currentOffset += 2;
|
||||
return ((buffer[currentOffset - 2] & 0xff) << 8) + (buffer[currentOffset - 1] - 128 & 0xff);
|
||||
}
|
||||
|
||||
public int readUnsignedWordBigEndianA() {
|
||||
currentOffset += 2;
|
||||
return ((buffer[currentOffset - 1] & 0xff) << 8) + (buffer[currentOffset - 2] - 128 & 0xff);
|
||||
}
|
||||
|
||||
|
||||
public void writeWordBigEndianA(int i) {
|
||||
ensureCapacity(2);
|
||||
buffer[currentOffset++] = (byte) (i + 128);
|
||||
@@ -149,13 +79,6 @@ public class Stream {
|
||||
buffer[currentOffset++] = (byte) (i >> 8);
|
||||
}
|
||||
|
||||
public void readBytes_reverse(byte abyte0[], int i, int j) {
|
||||
for (int k = j + i - 1; k >= j; k--) {
|
||||
abyte0[k] = buffer[currentOffset++];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void writeBytes_reverse(byte abyte0[], int i, int j) {
|
||||
ensureCapacity(i);
|
||||
for (int k = j + i - 1; k >= j; k--) {
|
||||
@@ -163,14 +86,6 @@ public class Stream {
|
||||
}
|
||||
}
|
||||
|
||||
public void readBytes_reverseA(byte abyte0[], int i, int j) {
|
||||
ensureCapacity(i);
|
||||
for (int k = j + i - 1; k >= j; k--) {
|
||||
abyte0[k] = (byte) (buffer[currentOffset++] - 128);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void writeBytes_reverseA(byte abyte0[], int i, int j) {
|
||||
ensureCapacity(i);
|
||||
for (int k = j + i - 1; k >= j; k--) {
|
||||
@@ -181,7 +96,7 @@ public class Stream {
|
||||
|
||||
public void createFrame(int id) {
|
||||
ensureCapacity(1);
|
||||
buffer[currentOffset++] = (byte) (id + packetEncryption.getNextKey());
|
||||
buffer[currentOffset++] = (byte) (id + packetEncryption.nextInt());
|
||||
}
|
||||
|
||||
private static final int frameStackSize = 10;
|
||||
@@ -190,7 +105,7 @@ public class Stream {
|
||||
|
||||
public void createFrameVarSize(int id) {
|
||||
ensureCapacity(3);
|
||||
buffer[currentOffset++] = (byte) (id + packetEncryption.getNextKey());
|
||||
buffer[currentOffset++] = (byte) (id + packetEncryption.nextInt());
|
||||
buffer[currentOffset++] = 0;
|
||||
if (frameStackPtr >= frameStackSize - 1) {
|
||||
throw new RuntimeException("Stack overflow");
|
||||
@@ -201,7 +116,7 @@ public class Stream {
|
||||
|
||||
public void createFrameVarSizeWord(int id) {
|
||||
ensureCapacity(2);
|
||||
buffer[currentOffset++] = (byte) (id + packetEncryption.getNextKey());
|
||||
buffer[currentOffset++] = (byte) (id + packetEncryption.nextInt());
|
||||
writeWord(0);
|
||||
if (frameStackPtr >= frameStackSize - 1) {
|
||||
throw new RuntimeException("Stack overflow");
|
||||
@@ -301,57 +216,6 @@ public class Stream {
|
||||
buffer[currentOffset - i - 1] = (byte) i;
|
||||
}
|
||||
|
||||
public int readUnsignedByte() {
|
||||
return buffer[currentOffset++] & 0xff;
|
||||
}
|
||||
|
||||
public byte readSignedByte() {
|
||||
return buffer[currentOffset++];
|
||||
}
|
||||
|
||||
public int readUnsignedWord() {
|
||||
currentOffset += 2;
|
||||
return ((buffer[currentOffset - 2] & 0xff) << 8) + (buffer[currentOffset - 1] & 0xff);
|
||||
}
|
||||
|
||||
public int readSignedWord() {
|
||||
currentOffset += 2;
|
||||
int i = ((buffer[currentOffset - 2] & 0xff) << 8) + (buffer[currentOffset - 1] & 0xff);
|
||||
if (i > 32767) {
|
||||
i -= 0x10000;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public int readDWord() {
|
||||
currentOffset += 4;
|
||||
return ((buffer[currentOffset - 4] & 0xff) << 24)
|
||||
+ ((buffer[currentOffset - 3] & 0xff) << 16)
|
||||
+ ((buffer[currentOffset - 2] & 0xff) << 8)
|
||||
+ (buffer[currentOffset - 1] & 0xff);
|
||||
}
|
||||
|
||||
public long readQWord() {
|
||||
long l = readDWord() & 0xffffffffL;
|
||||
long l1 = readDWord() & 0xffffffffL;
|
||||
return (l << 32) + l1;
|
||||
}
|
||||
|
||||
public java.lang.String readString() {
|
||||
int i = currentOffset;
|
||||
while (buffer[currentOffset++] != 10) {
|
||||
;
|
||||
}
|
||||
return new String(buffer, i, currentOffset - i - 1);
|
||||
}
|
||||
|
||||
public void readBytes(byte abyte0[], int i, int j) {
|
||||
for (int k = j; k < j + i; k++) {
|
||||
abyte0[k] = buffer[currentOffset++];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void initBitAccess() {
|
||||
bitPosition = currentOffset * 8;
|
||||
}
|
||||
@@ -414,6 +278,6 @@ public class Stream {
|
||||
}
|
||||
}
|
||||
|
||||
public ISAACRandomGen packetEncryption = null;
|
||||
public IsaacRandom packetEncryption = null;
|
||||
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ package com.rs2.world.clip;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.apollo.archive.Archive;
|
||||
import org.apollo.jagcached.fs.IndexedFileSystem;
|
||||
import org.apollo.cache.IndexedFileSystem;
|
||||
import org.apollo.cache.archive.Archive;
|
||||
|
||||
public final class ObjectDefinition {
|
||||
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
package com.rs2.world.clip;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.apollo.archive.Archive;
|
||||
import org.apollo.archive.ArchiveEntry;
|
||||
import org.apollo.archive.CompressionUtil;
|
||||
import org.apollo.cache.IndexedFileSystem;
|
||||
import org.apollo.cache.archive.Archive;
|
||||
import org.apollo.cache.archive.ArchiveEntry;
|
||||
import org.apollo.jagcached.Constants;
|
||||
import org.apollo.jagcached.fs.IndexedFileSystem;
|
||||
import org.apollo.util.CompressionUtil;
|
||||
|
||||
public class RegionFactory {
|
||||
|
||||
@@ -22,7 +20,7 @@ public class RegionFactory {
|
||||
public static void load() {
|
||||
//GameEngine.getLogger(Region.class).info("Loading region configurations...");
|
||||
try {
|
||||
IndexedFileSystem fs = new IndexedFileSystem(new File(Constants.FILE_SYSTEM_DIR), true);
|
||||
IndexedFileSystem fs = new IndexedFileSystem(Paths.get(Constants.FILE_SYSTEM_DIR), true);
|
||||
ObjectDefinition.loadConfig(fs);
|
||||
|
||||
Archive archive = Archive.decode(fs.getFile(0, 5));
|
||||
@@ -56,8 +54,8 @@ public class RegionFactory {
|
||||
for (int i = 0; i < size; i++) {
|
||||
//GameEngine.getLogger(Region.class).info("Region: " + i + " RegionId: " + regionIds[i] + " ObjectsId: " + mapObjectsFileIds[i]
|
||||
// + " ClippingsId: " + mapGroundFileIds[i]);
|
||||
byte[] file1 = CompressionUtil.degzip(fs.getFileBytes(4, mapObjectsFileIds[i]));
|
||||
byte[] file2 = CompressionUtil.degzip(fs.getFileBytes(4, mapGroundFileIds[i]));
|
||||
byte[] file1 = CompressionUtil.degzip(fs.getFile(4, mapObjectsFileIds[i]));
|
||||
byte[] file2 = CompressionUtil.degzip(fs.getFile(4, mapGroundFileIds[i]));
|
||||
if (file1 == null || file2 == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user