add direction variable in createPacketBuffer

This commit is contained in:
Romain Beaumont 2015-09-12 21:56:33 +02:00
parent 188848b364
commit a62e7a2712

View File

@ -62,16 +62,17 @@ var packetStates = packetIndexes.packetStates;
// TODO : This does NOT contain the length prefix anymore. // TODO : This does NOT contain the length prefix anymore.
function createPacketBuffer(packetId, state, params, isServer) { function createPacketBuffer(packetId, state, params, isServer) {
var length = 0; var length = 0;
var direction=!isServer ? 'toServer' : 'toClient';
if(typeof packetId === 'string' && typeof state !== 'string' && !params) { if(typeof packetId === 'string' && typeof state !== 'string' && !params) {
// simplified two-argument usage, createPacketBuffer(name, params) // simplified two-argument usage, createPacketBuffer(name, params)
params = state; params = state;
state = packetStates[!isServer ? 'toServer' : 'toClient'][packetId]; state = packetStates[direction][packetId];
} }
if(typeof packetId === 'string') packetId = packetIds[state][!isServer ? 'toServer' : 'toClient'][packetId]; if(typeof packetId === 'string') packetId = packetIds[state][direction][packetId];
assert.notEqual(packetId, undefined); assert.notEqual(packetId, undefined);
var packet = get(packetId, state, !isServer); var packet = get(packetId, state, !isServer);
var packetName = packetNames[state][!isServer ? 'toServer' : 'toClient'][packetId]; var packetName = packetNames[state][direction][packetId];
assert.notEqual(packet, null); assert.notEqual(packet, null);
packet.forEach(function(fieldInfo) { packet.forEach(function(fieldInfo) {
tryCatch(() => { tryCatch(() => {