Merge pull request #212 from yuzumika/fix-selection-underflow #minor
NPCMoreTalkHandler: don't underflow selection
This commit is contained in:
@@ -22,6 +22,8 @@ public class ByteBufInPacket implements InPacket {
|
||||
public byte readByte() {
|
||||
return byteBuf.readByte();
|
||||
}
|
||||
@Override
|
||||
public short readUnsignedByte() { return byteBuf.readUnsignedByte(); }
|
||||
|
||||
@Override
|
||||
public short readShort() {
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.awt.*;
|
||||
|
||||
public interface InPacket extends Packet {
|
||||
byte readByte();
|
||||
short readUnsignedByte();
|
||||
short readShort();
|
||||
int readInt();
|
||||
long readLong();
|
||||
|
||||
@@ -59,7 +59,7 @@ public final class NPCMoreTalkHandler extends AbstractPacketHandler {
|
||||
if (p.available() >= 4) {
|
||||
selection = p.readInt();
|
||||
} else if (p.available() > 0) {
|
||||
selection = p.readByte();
|
||||
selection = p.readUnsignedByte();
|
||||
}
|
||||
if (c.getQM() != null) {
|
||||
if (c.getQM().isStart()) {
|
||||
|
||||
@@ -38,6 +38,36 @@ class ByteBufInPacketTest {
|
||||
assertEquals(writtenByte, readByte);
|
||||
}
|
||||
|
||||
@Test
|
||||
void readUnsignedByte() {
|
||||
final byte writtenByte = Byte.MAX_VALUE;
|
||||
byteBuf.writeByte(writtenByte);
|
||||
|
||||
short readUnsignedByte = inPacket.readUnsignedByte();
|
||||
|
||||
assertEquals(writtenByte, readUnsignedByte);
|
||||
}
|
||||
|
||||
@Test
|
||||
void readUnsignedByte_shouldBeNonnegative() {
|
||||
final byte writtenByte = Byte.MIN_VALUE;
|
||||
byteBuf.writeByte(writtenByte);
|
||||
|
||||
short readUnsignedByte = inPacket.readUnsignedByte();
|
||||
|
||||
assertEquals((short)writtenByte + 256, readUnsignedByte);
|
||||
}
|
||||
|
||||
@Test
|
||||
void readUnsignedByte_shouldBeNonnegative2() {
|
||||
final byte writtenByte = -1;
|
||||
byteBuf.writeByte(writtenByte);
|
||||
|
||||
short readUnsignedByte = inPacket.readUnsignedByte();
|
||||
|
||||
assertEquals((short)writtenByte + 256, readUnsignedByte);
|
||||
}
|
||||
|
||||
@Test
|
||||
void readShort() {
|
||||
final short writtenShort = 12_345;
|
||||
|
||||
Reference in New Issue
Block a user