Merge branch 'master' into fix-tools
# Conflicts: # pom.xml
This commit is contained in:
81
src/main/java/net/packet/ByteBufInPacket.java
Normal file
81
src/main/java/net/packet/ByteBufInPacket.java
Normal file
@@ -0,0 +1,81 @@
|
||||
package net.packet;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class ByteBufInPacket implements InPacket {
|
||||
private final ByteBuf byteBuf;
|
||||
|
||||
public ByteBufInPacket(ByteBuf byteBuf) {
|
||||
this.byteBuf = byteBuf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getBytes() {
|
||||
return ByteBufUtil.getBytes(byteBuf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte readByte() {
|
||||
return byteBuf.readByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public short readShort() {
|
||||
return byteBuf.readShortLE();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readInt() {
|
||||
return byteBuf.readIntLE();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long readLong() {
|
||||
return byteBuf.readLongLE();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point readPoint() {
|
||||
final short x = byteBuf.readShortLE();
|
||||
final short y = byteBuf.readShortLE();
|
||||
return new Point(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readString() {
|
||||
short length = readShort();
|
||||
byte[] stringBytes = new byte[length];
|
||||
byteBuf.readBytes(stringBytes);
|
||||
return new String(stringBytes, STRING_CHARSET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] readBytes(int numberOfBytes) {
|
||||
byte[] bytes = new byte[numberOfBytes];
|
||||
byteBuf.readBytes(bytes);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void skip(int numberOfBytes) {
|
||||
byteBuf.skipBytes(numberOfBytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int available() {
|
||||
return byteBuf.readableBytes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void seek(int byteOffset) {
|
||||
byteBuf.readerIndex(byteOffset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPosition() {
|
||||
return byteBuf.readerIndex();
|
||||
}
|
||||
}
|
||||
83
src/main/java/net/packet/ByteBufOutPacket.java
Normal file
83
src/main/java/net/packet/ByteBufOutPacket.java
Normal file
@@ -0,0 +1,83 @@
|
||||
package net.packet;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.jcip.annotations.NotThreadSafe;
|
||||
import net.opcodes.SendOpcode;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
@NotThreadSafe
|
||||
public class ByteBufOutPacket implements OutPacket {
|
||||
private final ByteBuf byteBuf;
|
||||
|
||||
public ByteBufOutPacket(SendOpcode op) {
|
||||
ByteBuf byteBuf = Unpooled.buffer();
|
||||
byteBuf.writeShortLE((short) op.getValue());
|
||||
this.byteBuf = byteBuf;
|
||||
}
|
||||
|
||||
public ByteBufOutPacket(SendOpcode op, int initialCapacity) {
|
||||
ByteBuf byteBuf = Unpooled.buffer(initialCapacity);
|
||||
byteBuf.writeShortLE((short) op.getValue());
|
||||
this.byteBuf = byteBuf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getBytes() {
|
||||
return ByteBufUtil.getBytes(byteBuf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeByte(byte value) {
|
||||
byteBuf.writeByte(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeByte(int value) {
|
||||
writeByte((byte) value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeBytes(byte[] value) {
|
||||
byteBuf.writeBytes(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeShort(int value) {
|
||||
byteBuf.writeShortLE(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeInt(int value) {
|
||||
byteBuf.writeIntLE(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeLong(long value) {
|
||||
byteBuf.writeLongLE(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeBoolean(boolean value) {
|
||||
byteBuf.writeByte(value ? 1 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeString(String value) {
|
||||
writeShort((short) value.length());
|
||||
writeBytes(value.getBytes(STRING_CHARSET));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writePoint(Point value) {
|
||||
writeShort((short) value.getX());
|
||||
writeShort((short) value.getY());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void skip(int numberOfBytes) {
|
||||
writeBytes(new byte[numberOfBytes]);
|
||||
}
|
||||
}
|
||||
17
src/main/java/net/packet/InPacket.java
Normal file
17
src/main/java/net/packet/InPacket.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package net.packet;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public interface InPacket extends Packet {
|
||||
byte readByte();
|
||||
short readShort();
|
||||
int readInt();
|
||||
long readLong();
|
||||
Point readPoint();
|
||||
String readString();
|
||||
byte[] readBytes(int numberOfBytes);
|
||||
void skip(int numberOfBytes);
|
||||
int available();
|
||||
void seek(int byteOffset);
|
||||
int getPosition();
|
||||
}
|
||||
16
src/main/java/net/packet/OutPacket.java
Normal file
16
src/main/java/net/packet/OutPacket.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package net.packet;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public interface OutPacket extends Packet {
|
||||
void writeByte(byte value);
|
||||
void writeByte(int value);
|
||||
void writeBytes(byte[] value);
|
||||
void writeShort(int value);
|
||||
void writeInt(int value);
|
||||
void writeLong(long value);
|
||||
void writeBoolean(boolean value);
|
||||
void writeString(String value);
|
||||
void writePoint(Point value);
|
||||
void skip(int numberOfBytes);
|
||||
}
|
||||
10
src/main/java/net/packet/Packet.java
Normal file
10
src/main/java/net/packet/Packet.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package net.packet;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public interface Packet {
|
||||
Charset STRING_CHARSET = StandardCharsets.US_ASCII;
|
||||
|
||||
byte[] getBytes();
|
||||
}
|
||||
@@ -65,6 +65,8 @@ public final class NPCTalkHandler extends AbstractMaplePacketHandler {
|
||||
NPCScriptManager.getInstance().start(c, npc.getId(), "gachapon", null);
|
||||
} else if (npc.getName().endsWith("Maple TV")) {
|
||||
NPCScriptManager.getInstance().start(c, npc.getId(), "mapleTV", null);
|
||||
} else if (YamlConfig.config.server.USE_REBIRTH_SYSTEM && npc.getId() == YamlConfig.config.server.REBIRTH_NPC_ID) {
|
||||
NPCScriptManager.getInstance().start(c, npc.getId(), "rebirth", null);
|
||||
} else {
|
||||
boolean hasNpcScript = NPCScriptManager.getInstance().start(c, npc.getId(), oid, null);
|
||||
if (!hasNpcScript) {
|
||||
|
||||
@@ -26,7 +26,6 @@ import client.inventory.*;
|
||||
import client.keybind.MapleKeyBinding;
|
||||
import config.YamlConfig;
|
||||
import constants.game.GameConstants;
|
||||
import constants.game.ScriptableNPCConstants;
|
||||
import net.AbstractMaplePacketHandler;
|
||||
import net.server.PlayerBuffValueHolder;
|
||||
import net.server.Server;
|
||||
@@ -55,6 +54,7 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
|
||||
|
||||
@@ -407,9 +407,23 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
|
||||
eim.registerPlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Tell the client to use the custom scripts available for the NPCs provided, instead of the WZ entries.
|
||||
if (YamlConfig.config.server.USE_NPCS_SCRIPTABLE) {
|
||||
c.announce(MaplePacketCreator.setNPCScriptable(ScriptableNPCConstants.SCRIPTABLE_NPCS));
|
||||
|
||||
// Create a copy to prevent always adding entries to the server's list.
|
||||
Map<Integer, String> npcsIds = YamlConfig.config.server.NPCS_SCRIPTABLE
|
||||
.entrySet().stream().collect(Collectors.toMap(
|
||||
entry -> Integer.parseInt(entry.getKey()),
|
||||
Entry::getValue
|
||||
));
|
||||
|
||||
// Any npc be specified as the rebirth npc. Allow the npc to use custom scripts explicitly.
|
||||
if (YamlConfig.config.server.USE_REBIRTH_SYSTEM) {
|
||||
npcsIds.put(YamlConfig.config.server.REBIRTH_NPC_ID, "Rebirth");
|
||||
}
|
||||
|
||||
c.announce(MaplePacketCreator.setNPCScriptable(npcsIds));
|
||||
}
|
||||
|
||||
if(newcomer) player.setLoginTime(System.currentTimeMillis());
|
||||
|
||||
Reference in New Issue
Block a user