Remove remaining uses of MaplePacketLittleEndianWriter

This commit is contained in:
P0nk
2021-08-22 21:03:51 +02:00
parent 8f6860d7d7
commit b3d422a6c5
7 changed files with 78 additions and 94 deletions
+1 -1
View File
@@ -1221,7 +1221,7 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
} }
public void broadcastStance() { public void broadcastStance() {
map.broadcastMessage(this, PacketCreator.movePlayer(id, this.getIdleMovement(), getIdleMovementDataLength()), false); map.broadcastMessage(this, PacketCreator.movePlayer(id, this.getIdleMovement(), AbstractAnimatedMapleMapObject.IDLE_MOVEMENT_PACKET_LENGTH), false);
} }
public MapleMap getWarpMap(int map) { public MapleMap getWarpMap(int map) {
@@ -28,12 +28,13 @@ import client.MapleClient;
import client.command.Command; import client.command.Command;
import net.MaplePacketHandler; import net.MaplePacketHandler;
import net.PacketProcessor; import net.PacketProcessor;
import net.packet.ByteBufOutPacket;
import net.packet.OutPacket;
import tools.FilePrinter; import tools.FilePrinter;
import tools.HexTool; import tools.HexTool;
import tools.data.input.ByteArrayByteStream; import tools.data.input.ByteArrayByteStream;
import tools.data.input.GenericSeekableLittleEndianAccessor; import tools.data.input.GenericSeekableLittleEndianAccessor;
import tools.data.input.SeekableLittleEndianAccessor; import tools.data.input.SeekableLittleEndianAccessor;
import tools.data.output.MaplePacketLittleEndianWriter;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
@@ -61,9 +62,9 @@ public class PeCommand extends Command {
return; return;
} }
MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter(); OutPacket p = new ByteBufOutPacket();
mplew.write(HexTool.getByteArrayFromHexString(packet)); p.writeBytes(HexTool.getByteArrayFromHexString(packet));
SeekableLittleEndianAccessor slea = new GenericSeekableLittleEndianAccessor(new ByteArrayByteStream(mplew.getPacket())); SeekableLittleEndianAccessor slea = new GenericSeekableLittleEndianAccessor(new ByteArrayByteStream(p.getBytes()));
short packetId = slea.readShort(); short packetId = slea.readShort();
final MaplePacketHandler packetHandler = PacketProcessor.getProcessor(0, c.getChannel()).getHandler(packetId); final MaplePacketHandler packetHandler = PacketProcessor.getProcessor(0, c.getChannel()).getHandler(packetId);
if (packetHandler != null && packetHandler.validateState(c)) { if (packetHandler != null && packetHandler.validateState(c)) {
@@ -24,9 +24,6 @@ package net.server.channel.handlers;
import client.MapleCharacter; import client.MapleCharacter;
import client.MapleClient; import client.MapleClient;
import net.AbstractMaplePacketHandler; import net.AbstractMaplePacketHandler;
import net.opcodes.SendOpcode;
import net.packet.OutPacket;
import net.packet.Packet;
import net.server.Server; import net.server.Server;
import net.server.guild.GuildPackets; import net.server.guild.GuildPackets;
import net.server.guild.MapleAlliance; import net.server.guild.MapleAlliance;
@@ -34,7 +31,6 @@ import net.server.guild.MapleGuild;
import net.server.guild.MapleGuildCharacter; import net.server.guild.MapleGuildCharacter;
import tools.PacketCreator; import tools.PacketCreator;
import tools.data.input.SeekableLittleEndianAccessor; import tools.data.input.SeekableLittleEndianAccessor;
import tools.data.output.MaplePacketLittleEndianWriter;
/** /**
* *
@@ -78,7 +74,7 @@ public final class AllianceOperationHandler extends AbstractMaplePacketHandler {
// "alliance" is only null at case 0x04 // "alliance" is only null at case 0x04
switch (b) { switch (b) {
case 0x01: case 0x01:
Server.getInstance().allianceMessage(alliance.getId(), sendShowInfo(chr.getGuild().getAllianceId(), chr.getId()), -1, -1); Server.getInstance().allianceMessage(alliance.getId(), GuildPackets.sendShowInfo(chr.getGuild().getAllianceId(), chr.getId()), -1, -1);
break; break;
case 0x02: { // Leave Alliance case 0x02: { // Leave Alliance
if (chr.getGuild().getAllianceId() == 0 || chr.getGuildId() < 1 || chr.getGuildRank() != 1) { if (chr.getGuild().getAllianceId() == 0 || chr.getGuildId() < 1 || chr.getGuildRank() != 1) {
@@ -228,53 +224,4 @@ public final class AllianceOperationHandler extends AbstractMaplePacketHandler {
alliance.dropMessage("'" + chr.getName() + "' has been reassigned to '" + alliance.getRankTitle(newRank) + "' in this Alliance."); alliance.dropMessage("'" + chr.getName() + "' has been reassigned to '" + alliance.getRankTitle(newRank) + "' in this Alliance.");
} }
private static Packet sendShowInfo(int allianceid, int playerid) {
OutPacket p = OutPacket.create(SendOpcode.ALLIANCE_OPERATION);
p.writeByte(0x02);
p.writeInt(allianceid);
p.writeInt(playerid);
return p;
}
private static byte[] sendInvitation(int allianceid, int playerid, final String guildname) {
MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
mplew.writeShort(SendOpcode.ALLIANCE_OPERATION.getValue());
mplew.write(0x05);
mplew.writeInt(allianceid);
mplew.writeInt(playerid);
mplew.writeMapleAsciiString(guildname);
return mplew.getPacket();
}
private static byte[] sendChangeGuild(int allianceid, int playerid, int guildid, int option) {
MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
mplew.writeShort(SendOpcode.ALLIANCE_OPERATION.getValue());
mplew.write(0x07);
mplew.writeInt(allianceid);
mplew.writeInt(guildid);
mplew.writeInt(playerid);
mplew.write(option);
return mplew.getPacket();
}
private static byte[] sendChangeLeader(int allianceid, int playerid, int victim) {
MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
mplew.writeShort(SendOpcode.ALLIANCE_OPERATION.getValue());
mplew.write(0x08);
mplew.writeInt(allianceid);
mplew.writeInt(playerid);
mplew.writeInt(victim);
return mplew.getPacket();
}
private static byte[] sendChangeRank(int allianceid, int playerid, int int1, byte byte1) {
MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
mplew.writeShort(SendOpcode.ALLIANCE_OPERATION.getValue());
mplew.write(0x09);
mplew.writeInt(allianceid);
mplew.writeInt(playerid);
mplew.writeInt(int1);
mplew.writeInt(byte1);
return mplew.getPacket();
}
} }
@@ -540,4 +540,51 @@ public class GuildPackets {
p.writeByte(guild.getLogoColor()); p.writeByte(guild.getLogoColor());
return p; return p;
} }
public static Packet sendShowInfo(int allianceid, int playerid) {
OutPacket p = OutPacket.create(SendOpcode.ALLIANCE_OPERATION);
p.writeByte(0x02);
p.writeInt(allianceid);
p.writeInt(playerid);
return p;
}
public static Packet sendInvitation(int allianceid, int playerid, final String guildname) {
OutPacket p = OutPacket.create(SendOpcode.ALLIANCE_OPERATION);
p.writeByte(0x05);
p.writeInt(allianceid);
p.writeInt(playerid);
p.writeString(guildname);
return p;
}
public static Packet sendChangeGuild(int allianceid, int playerid, int guildid, int option) {
OutPacket p = OutPacket.create(SendOpcode.ALLIANCE_OPERATION);
p.writeByte(0x07);
p.writeInt(allianceid);
p.writeInt(guildid);
p.writeInt(playerid);
p.writeByte(option);
return p;
}
public static Packet sendChangeLeader(int allianceid, int playerid, int victim) {
OutPacket p = OutPacket.create(SendOpcode.ALLIANCE_OPERATION);
p.writeByte(0x08);
p.writeInt(allianceid);
p.writeInt(playerid);
p.writeInt(victim);
return p;
}
public static Packet sendChangeRank(int allianceid, int playerid, int int1, byte byte1) {
OutPacket p = OutPacket.create(SendOpcode.ALLIANCE_OPERATION);
p.writeByte(0x09);
p.writeInt(allianceid);
p.writeInt(playerid);
p.writeInt(int1);
p.writeInt(byte1);
return p;
}
} }
+2 -1
View File
@@ -45,6 +45,7 @@ import server.MapleStatEffect;
import server.TimerManager; import server.TimerManager;
import server.life.MapleLifeFactory.BanishInfo; import server.life.MapleLifeFactory.BanishInfo;
import server.loot.MapleLootManager; import server.loot.MapleLootManager;
import server.maps.AbstractAnimatedMapleMapObject;
import server.maps.MapleMap; import server.maps.MapleMap;
import server.maps.MapleMapObjectType; import server.maps.MapleMapObjectType;
import server.maps.MapleSummon; import server.maps.MapleSummon;
@@ -1324,7 +1325,7 @@ public class MapleMonster extends AbstractLoadedMapleLife {
aggroRemoveController(); aggroRemoveController();
setPosition(newPoint); setPosition(newPoint);
map.broadcastMessage(PacketCreator.moveMonster(this.getObjectId(), false, -1, 0, 0, 0, this.getPosition(), this.getIdleMovement(), getIdleMovementDataLength())); map.broadcastMessage(PacketCreator.moveMonster(this.getObjectId(), false, -1, 0, 0, 0, this.getPosition(), this.getIdleMovement(), AbstractAnimatedMapleMapObject.IDLE_MOVEMENT_PACKET_LENGTH));
map.moveMonster(this, this.getPosition()); map.moveMonster(this, this.getPosition());
aggroUpdateController(); aggroUpdateController();
@@ -23,29 +23,17 @@ package server.maps;
import java.util.Arrays; import java.util.Arrays;
import net.packet.ByteBufOutPacket;
import net.packet.OutPacket;
import net.packet.Packet;
import tools.data.input.ByteArrayByteStream; import tools.data.input.ByteArrayByteStream;
import tools.data.input.GenericSeekableLittleEndianAccessor; import tools.data.input.GenericSeekableLittleEndianAccessor;
import tools.data.input.SeekableLittleEndianAccessor; import tools.data.input.SeekableLittleEndianAccessor;
import tools.data.output.MaplePacketLittleEndianWriter;
public abstract class AbstractAnimatedMapleMapObject extends AbstractMapleMapObject implements AnimatedMapleMapObject { public abstract class AbstractAnimatedMapleMapObject extends AbstractMapleMapObject implements AnimatedMapleMapObject {
public static final int IDLE_MOVEMENT_PACKET_LENGTH = 15;
static { private static final Packet IDLE_MOVEMENT_PACKET = createIdleMovementPacket();
MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter((int) getIdleMovementDataLength());
mplew.write(1); //movement command count
mplew.write(0);
mplew.writeShort(-1); //x
mplew.writeShort(-1); //y
mplew.writeShort(0); //xwobble
mplew.writeShort(0); //ywobble
mplew.writeShort(0); //fh
mplew.write(-1); //stance
mplew.writeShort(0); //duration
idleMovementPacketData = mplew.getPacket();
}
private static final byte[] idleMovementPacketData;
private int stance; private int stance;
@Override @Override
@@ -64,7 +52,8 @@ public abstract class AbstractAnimatedMapleMapObject extends AbstractMapleMapObj
} }
public SeekableLittleEndianAccessor getIdleMovement() { public SeekableLittleEndianAccessor getIdleMovement() {
byte[] movementData = Arrays.copyOf(idleMovementPacketData, idleMovementPacketData.length); final byte[] idleMovementBytes = IDLE_MOVEMENT_PACKET.getBytes();
byte[] movementData = Arrays.copyOf(idleMovementBytes, idleMovementBytes.length);
//seems wasteful to create a whole packet writer when only a few values are changed //seems wasteful to create a whole packet writer when only a few values are changed
int x = getPosition().x; int x = getPosition().x;
int y = getPosition().y; int y = getPosition().y;
@@ -75,8 +64,18 @@ public abstract class AbstractAnimatedMapleMapObject extends AbstractMapleMapObj
movementData[12] = (byte) (getStance() & 0xFF); movementData[12] = (byte) (getStance() & 0xFF);
return new GenericSeekableLittleEndianAccessor(new ByteArrayByteStream(movementData)); return new GenericSeekableLittleEndianAccessor(new ByteArrayByteStream(movementData));
} }
public static long getIdleMovementDataLength() { private static Packet createIdleMovementPacket() {
return 15; OutPacket p = new ByteBufOutPacket();
} p.writeByte(1); //movement command count
p.writeByte(0);
p.writeShort(-1); //x
p.writeShort(-1); //y
p.writeShort(0); //xwobble
p.writeShort(0); //ywobble
p.writeShort(0); //fh
p.writeByte(-1); //stance
p.writeShort(0); //duration
return p;
}
} }
@@ -28,14 +28,12 @@ import client.inventory.MapleInventory;
import client.inventory.MapleInventoryType; import client.inventory.MapleInventoryType;
import client.inventory.manipulator.MapleInventoryManipulator; import client.inventory.manipulator.MapleInventoryManipulator;
import client.inventory.manipulator.MapleKarmaManipulator; import client.inventory.manipulator.MapleKarmaManipulator;
import net.opcodes.SendOpcode;
import net.packet.Packet; import net.packet.Packet;
import net.server.audit.locks.MonitoredLockType; import net.server.audit.locks.MonitoredLockType;
import net.server.audit.locks.factory.MonitoredReentrantLockFactory; import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
import server.MapleTrade; import server.MapleTrade;
import tools.PacketCreator; import tools.PacketCreator;
import tools.Pair; import tools.Pair;
import tools.data.output.MaplePacketLittleEndianWriter;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@@ -377,15 +375,6 @@ public class MaplePlayerShop extends AbstractMapleMapObject {
} }
} }
public static byte[] shopErrorMessage(int error, int type) {
MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
mplew.writeShort(SendOpcode.PLAYER_INTERACTION.getValue());
mplew.write(0x0A);
mplew.write(type);
mplew.write(error);
return mplew.getPacket();
}
public void broadcast(Packet packet) { public void broadcast(Packet packet) {
MapleClient client = owner.getClient(); MapleClient client = owner.getClient();
if (client != null) { if (client != null) {