-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlocalize.js
31 lines (27 loc) · 949 Bytes
/
localize.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const identify = require('./identify.js');
const Packet = require('./packet.js');
const LoginSuccess = require('./packets/clientbound/loginSuccess.js');
const log = require('loglevel')
function localizeClientboundPacket(packet, x, z, eidTable) {
var packetType = identify.clientbound(packet)
return localize(packet, packetType, x, z, eidTable)
}
function localizeServerboundPacket(packet, x, z, eidTable) {
var packetType = identify.serverbound(packet)
return localize(packet, packetType, x, z, eidTable)
}
function localize(packet, packetType, x, z, eidTable) {
if(packetType == LoginSuccess) {
log.debug('Successfully logged into peer')
return null
} else if(packetType == null) {
return packet
}
var parsedPacket = Packet.read(packetType,packet)
parsedPacket.localize(x, z, eidTable)
return parsedPacket
}
module.exports = {
clientbound: localizeClientboundPacket,
serverbound: localizeServerboundPacket
}