Skip to content

Commit 147a1a1

Browse files
committed
refactor: fix types for generic interaction packet readers
1 parent cc4460e commit 147a1a1

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/engine/net/inbound-packets/npc-interaction.packet.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { logger } from '@runejs/common';
2-
import { DataType, Endianness, Signedness } from '@runejs/common';
32

43
import { PacketData } from '@engine/net';
54
import { activeWorld, World } from '@engine/world';
@@ -8,14 +7,14 @@ import { Player } from '@engine/world/actor';
87
const npcInteractionPacket = (player: Player, packet: PacketData) => {
98
const { buffer, packetId } = packet;
109

11-
const args: { [key: number]: [ DataType, Signedness?, Endianness? ] } = {
12-
63: [ 'short', 'u', 'le' ],
13-
116: [ 'short', 'u', 'le' ],
14-
57: [ 'short', 'u' ],
10+
const packetReaders: Record<number, () => number> = {
11+
63: () => buffer.get('short', 'u', 'le'),
12+
116: () => buffer.get('short', 'u', 'le'),
13+
57: () => buffer.get('short', 'u'),
1514
/*42: 'readUnsignedShortLE',
1615
8: 'readUnsignedShortLE'*/
1716
};
18-
const npcIndex = buffer.get(...args[packetId]);
17+
const npcIndex = packetReaders[packetId]();
1918

2019
if (npcIndex < 0 || npcIndex > World.MAX_NPCS - 1) {
2120
return;

src/engine/net/inbound-packets/player-interaction.packet.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ import { logger } from '@runejs/common';
33
import { activeWorld, World } from '@engine/world';
44
import { Player, playerOptions } from '@engine/world/actor';
55
import { PacketData } from '@engine/net';
6-
import { DataType, Endianness, Signedness } from '@runejs/common';
76

87
const playerInteractionPacket = (player: Player, packet: PacketData) => {
98
const { buffer, packetId } = packet;
10-
const args: { [key: number]: [ DataType, Signedness?, Endianness? ] } = {
11-
68: [ 'short', 'u', 'le' ],
12-
211: [ 'short', 'u', 'le' ]
9+
10+
const packetReaders: Record<number, () => number> = {
11+
68: () => buffer.get('short', 'u', 'le'),
12+
211: () => buffer.get('short', 'u', 'le'),
1313
};
14-
const playerIndex = buffer.get(...args[packetId]) - 1;
14+
15+
const playerIndex = packetReaders[packetId]() - 1;
1516

1617
if(playerIndex < 0 || playerIndex > World.MAX_PLAYERS - 1) {
1718
return;

0 commit comments

Comments
 (0)