1
0
Fork 0
mirror of https://github.com/demostf/demo.js synced 2026-06-04 09:04:13 +02:00

lint fixes

This commit is contained in:
Robin Appelman 2017-09-26 02:29:45 +02:00
commit 0aad1e874b
78 changed files with 879 additions and 851 deletions

View file

@ -1,20 +1,20 @@
import * as assert from 'assert';
import {readFileSync, createWriteStream, createReadStream} from 'fs';
import {Demo} from '../../Demo';
import {Packet} from '../../Data/Packet';
import {BitStream} from 'bit-buffer';
import {createReadStream, createWriteStream, readFileSync} from 'fs';
import * as split2 from 'split2';
import {createUnzip, createGunzip} from 'zlib';
import {PassThrough} from 'stream';
import {createGunzip, createUnzip} from 'zlib';
import {Packet} from '../../Data/Packet';
import {EntityId, PVS} from '../../Data/PacketEntity';
import {SendPropValue} from '../../Data/SendProp';
import {Demo} from '../../Demo';
interface ResultData {
tick: number,
serverClass: string,
id: EntityId,
props: {[propName: string]: SendPropValue},
pvs: PVS
tick: number;
serverClass: string;
id: EntityId;
props: {[propName: string]: SendPropValue};
pvs: PVS;
}
function writeEntities(name: string) {
@ -48,7 +48,7 @@ function* getResultData(packets: Iterable<Packet>): IterableIterator<ResultData>
entityProps[`${prop.definition.name}`] = prop.value;
}
yield {
tick: tick,
tick,
serverClass: entity.serverClass.name,
id: entity.entityIndex,
props: entityProps,
@ -82,7 +82,7 @@ function testEntities(name: string, entityCount: number) {
assert.equal(parsed, entityCount, 'unexpected number of entities');
resolve();
}).on('error', err => {
}).on('error', (err) => {
reject(err);
});
});

View file

@ -1,7 +1,7 @@
import * as assert from 'assert';
import {BitStream} from 'bit-buffer';
import {readFileSync} from 'fs';
import {Demo} from '../../Demo';
import {BitStream} from 'bit-buffer';
function testDemo(name: string, fastMode: boolean = false) {
const target = JSON.parse(readFileSync(`${__dirname}/../data/${name}.json`, 'utf8'));

View file

@ -1,39 +1,39 @@
import {PacketEntity, PVS} from '../../../Data/PacketEntity';
import {ServerClass} from '../../../Data/ServerClass';
import {hydrateEntity, propDataDefinition} from '../Parser/Packet/hydrate';
import {SendProp} from '../../../Data/SendProp';
import * as assert from 'assert';
import {readFileSync} from 'fs';
import {PacketEntity, PVS} from '../../../Data/PacketEntity';
import {SendProp} from '../../../Data/SendProp';
import {ServerClass} from '../../../Data/ServerClass';
import {hydrateEntity, propDataDefinition} from '../Parser/Packet/hydrate';
const serverClass = new ServerClass(241, 'CTFPlayer', 'DT_TFPlayer');
const playerBaseLineData = JSON.parse(readFileSync(__dirname + '/../../data/packetEntitiesPlayerBaseline.json', 'utf8'));
const playerEntityData = JSON.parse(readFileSync(__dirname + '/../../data/packetEntitiesPlayerEntity.json', 'utf8'));
const definition1 = propDataDefinition({
'type': 1,
'name': 'm_flDucktime',
'flags': 1032,
'excludeDTName': null,
'lowValue': 0,
'highValue': 2047.5,
'bitCount': 12,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_Local'
type: 1,
name: 'm_flDucktime',
flags: 1032,
excludeDTName: null,
lowValue: 0,
highValue: 2047.5,
bitCount: 12,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_Local'
});
const definition2 = propDataDefinition({
'type': 1,
'name': 'm_flFallVelocity',
'flags': 1024,
'excludeDTName': null,
'lowValue': -4096,
'highValue': 4096,
'bitCount': 17,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_Local'
type: 1,
name: 'm_flFallVelocity',
flags: 1024,
excludeDTName: null,
lowValue: -4096,
highValue: 4096,
bitCount: 17,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_Local'
});
suite('PacketEntity', () => {

View file

@ -1,8 +1,8 @@
import {BitStream} from 'bit-buffer';
import {assertEncoder} from '../Packet/PacketTest';
import {ConsoleCmdHandler} from '../../../../Parser/Message/ConsoleCmd';
import {ParserState} from '../../../../Data/ParserState';
import {MessageType} from '../../../../Data/Message';
import {ParserState} from '../../../../Data/ParserState';
import {ConsoleCmdHandler} from '../../../../Parser/Message/ConsoleCmd';
import {assertEncoder} from '../Packet/PacketTest';
function parse(stream) {
const result = ConsoleCmdHandler.parseMessage(stream, new ParserState());

View file

@ -1,21 +1,26 @@
import {BitStream} from 'bit-buffer';
import {assertEncoder, assertParser, getStream} from '../Packet/PacketTest';
import {readFileSync} from 'fs';
import {ParserState} from '../../../../Data/ParserState';
import {gunzipSync} from 'zlib';
import {DataTableHandler} from '../../../../Parser/Message/DataTable';
import {DataTablesMessage} from '../../../../Data/Message';
import {hydrateTable} from '../Packet/hydrate';
import {ServerClass} from '../../../../Data/ServerClass';
import * as assert from 'assert';
import {BitStream} from 'bit-buffer';
import {readFileSync} from 'fs';
import {gunzipSync} from 'zlib';
import {DataTablesMessage} from '../../../../Data/Message';
import {ParserState} from '../../../../Data/ParserState';
import {ServerClass} from '../../../../Data/ServerClass';
import {DataTableHandler} from '../../../../Parser/Message/DataTable';
import {hydrateTable} from '../Packet/hydrate';
import {assertEncoder, assertParser, getStream} from '../Packet/PacketTest';
const data = Array.from(readFileSync(__dirname + '/../../../data/dataTableData.bin').values());
const expectedRaw = JSON.parse(gunzipSync(readFileSync(__dirname + '/../../../data/dataTableResult.json.gz')).toString('utf8')) as DataTablesMessage;
const expectedRaw = JSON.parse(
gunzipSync(
readFileSync(__dirname + '/../../../data/dataTableResult.json.gz'
)
).toString('utf8')
) as DataTablesMessage;
const expected = {
type: expectedRaw.type,
tick: expectedRaw.tick,
serverClasses: expectedRaw.serverClasses.map(serverClass => new ServerClass(serverClass.id, serverClass.name, serverClass.dataTable)),
serverClasses: expectedRaw.serverClasses.map((serverClass) => new ServerClass(serverClass.id, serverClass.name, serverClass.dataTable)),
tables: expectedRaw.tables.map(hydrateTable)
};

View file

@ -1,9 +1,9 @@
import {BitStream} from 'bit-buffer';
import {assertEncoder, assertParser, getStream} from '../Packet/PacketTest';
import {readFileSync} from 'fs';
import {PacketMessageHandler} from '../../../../Parser/Message/Packet';
import {ParserState} from '../../../../Data/ParserState';
import {PacketTypeId} from '../../../../Data/Packet';
import {ParserState} from '../../../../Data/ParserState';
import {PacketMessageHandler} from '../../../../Parser/Message/Packet';
import {assertEncoder, assertParser, getStream} from '../Packet/PacketTest';
const data = Object.values(JSON.parse(readFileSync(__dirname + '/../../../data/packetMessageData.json', 'utf8')));
const expected = JSON.parse(readFileSync(__dirname + '/../../../data/packetMessageResult.json', 'utf8'));
@ -14,7 +14,7 @@ const getParserState = (fastMode) => {
state.skippedPackets = fastMode ? [
PacketTypeId.packetEntities,
PacketTypeId.tempEntities,
PacketTypeId.entityMessage,
PacketTypeId.entityMessage
] : [];
return state;
};

View file

@ -1,18 +1,18 @@
import {StringTable, StringTableEntry} from '../../../../Data/StringTable';
import {BitStream} from 'bit-buffer';
import {readFileSync} from 'fs';
import {ParserState} from '../../../../Data/ParserState';
import {StringTable, StringTableEntry} from '../../../../Data/StringTable';
import {StringTableHandler} from '../../../../Parser/Message/StringTable';
import {assertEncoder, assertParser, getStream} from '../Packet/PacketTest';
import {BitStream} from 'bit-buffer';
const encodeEntry = (entry: StringTableEntry) => {
const encodeEntry: any = {
text: entry.text,
const result: any = {
text: entry.text
};
if (entry.extraData) {
encodeEntry.extraData = Array.from(entry.extraData.readArrayBuffer(Math.ceil(entry.extraData.length / 8)).values());
result.extraData = Array.from(entry.extraData.readArrayBuffer(Math.ceil(entry.extraData.length / 8)).values());
}
return encodeEntry;
return result;
};
const encodeTables = (tables) => {
return tables.map((table) => {
@ -27,13 +27,13 @@ const encodeTables = (tables) => {
});
};
const decodeEntry = (entry) => {
const decodeEntry: any = {
text: entry.text,
const result: any = {
text: entry.text
};
if (entry.extraData) {
decodeEntry.extraData = getStream(entry.extraData);
result.extraData = getStream(entry.extraData);
}
return decodeEntry;
return result;
};
const decodeTables = (tables) => {
return tables.map((table) => {
@ -62,7 +62,6 @@ const expected = {
rawData: getStream('')
};
const getParserState = () => {
return new ParserState();
};

View file

@ -1,11 +1,11 @@
import {BitStream} from 'bit-buffer';
import {assertEncoder, assertParser, getStream} from './PacketTest';
import {
EncodeBSPDecal, encodeVecCoord, getVecCoord,
ParseBSPDecal
} from '../../../../Parser/Packet/BSPDecal';
import {SendPropParser} from '../../../../Parser/SendPropParser';
import {SendPropEncoder} from '../../../../Parser/SendPropEncoder';
import {SendPropParser} from '../../../../Parser/SendPropParser';
import {assertEncoder, assertParser, getStream} from './PacketTest';
const data = [239, 236, 208, 85, 33, 127, 128, 9, 8];

View file

@ -1,6 +1,6 @@
import {BitStream} from 'bit-buffer';
import {assertEncoder, assertParser, getStream} from './PacketTest';
import {EncodeClassInfo, ParseClassInfo} from '../../../../Parser/Packet/ClassInfo';
import {assertEncoder, assertParser, getStream} from './PacketTest';
suite('ClassInfo', () => {
test('Parse classInfo', () => {

View file

@ -1,6 +1,6 @@
import {BitStream} from 'bit-buffer';
import {assertEncoder, assertParser, getStream} from './PacketTest';
import {EncodeCreateStringTable, ParseCreateStringTable} from '../../../../Parser/Packet/CreateStringTable';
import {assertEncoder, assertParser, getStream} from './PacketTest';
const exampleData = [
100,
@ -80,7 +80,6 @@ const examplePacket2 = {
}
};
suite('CreateStringTable', () => {
test('Parse createStringTable', () => {
assertParser(ParseCreateStringTable, getStream(exampleData), examplePacket, 388);

View file

@ -1,15 +1,15 @@
import {BitStream} from 'bit-buffer';
import {assertEncoder, assertParser, getStream} from './PacketTest';
import {readFileSync} from 'fs';
import {encodeEntityUpdate, getEntityUpdate} from '../../../../Parser/EntityDecoder';
import {SendProp, SendPropValue} from '../../../../Data/SendProp';
import {SendPropType} from '../../../../Data/SendPropDefinition';
import {encodeEntityUpdate, getEntityUpdate} from '../../../../Parser/EntityDecoder';
import {SendPropEncoder} from '../../../../Parser/SendPropEncoder';
import {SendPropParser} from '../../../../Parser/SendPropParser';
import {hydrateEntity, hydrateTable} from './hydrate';
import {assertEncoder, assertParser, getStream} from './PacketTest';
const data = [
9, 128, 64, 64, 64, 64, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 36, 0, 64, 0, 1, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 136, 0, 128, 0, 0, 8, 0, 128, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 2, 64, 0, 32, 0, 16, 0, 32, 240, 255, 255, 255, 31, 0, 2, 32, 48, 0, 128, 0, 0, 4, 254, 255, 127, 224, 255, 255, 7, 254, 255, 127, 0, 8, 64, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 64, 64, 64, 64, 0, 32, 224, 136, 10, 248, 91, 2, 63, 18, 8, 40, 38, 3, 250, 163, 192, 126, 7, 2, 2, 0, 0, 0, 0, 1, 0, 0, 0, 128, 0, 0, 0, 224, 111, 0, 0, 0, 0, 32, 192, 129, 172, 140, 46, 44, 141, 237, 133, 172, 140, 46, 44, 141, 109, 14, 78, 46, 141, 174, 108, 238, 107, 46, 236, 174, 45, 141, 141, 45, 0];
// tslint:disable-next-line
const data = [9, 128, 64, 64, 64, 64, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 36, 0, 64, 0, 1, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 136, 0, 128, 0, 0, 8, 0, 128, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 2, 64, 0, 32, 0, 16, 0, 32, 240, 255, 255, 255, 31, 0, 2, 32, 48, 0, 128, 0, 0, 4, 254, 255, 127, 224, 255, 255, 7, 254, 255, 127, 0, 8, 64, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 64, 64, 64, 64, 0, 32, 224, 136, 10, 248, 91, 2, 63, 18, 8, 40, 38, 3, 250, 163, 192, 126, 7, 2, 2, 0, 0, 0, 0, 1, 0, 0, 0, 128, 0, 0, 0, 224, 111, 0, 0, 0, 0, 32, 192, 129, 172, 140, 46, 44, 141, 237, 133, 172, 140, 46, 44, 141, 109, 14, 78, 46, 141, 174, 108, 238, 107, 46, 236, 174, 45, 141, 141, 45, 0];
const entityData = JSON.parse(readFileSync(__dirname + '/../../../data/worldEntity.json', 'utf8'));
const sendTableData = JSON.parse(readFileSync(__dirname + '/../../../data/sendTableDTWorld.json', 'utf8'));
@ -24,15 +24,14 @@ export function encodeUpdate(props: SendProp[], stream: BitStream) {
encodeEntityUpdate(props, sendTable, stream);
}
function encodeProp(prop: SendProp) {
return function (value: SendPropValue, stream: BitStream) {
return (value: SendPropValue, stream: BitStream) => {
return SendPropEncoder.encode(value, prop.definition, stream);
};
}
function decodeProp(prop: SendProp) {
return function (stream: BitStream) {
return (stream: BitStream) => {
return SendPropParser.decode(prop.definition, stream);
};
}
@ -41,7 +40,7 @@ suite('Entity Decoder', () => {
test('Encode sendProps', () => {
for (const prop of entity.props) {
if (prop.value !== null) {
assertEncoder(decodeProp(prop), encodeProp(prop), prop.value, 0, ` for ${SendPropType[prop.definition.type]} with flags ${prop.definition.allFlags}`);
assertEncoder(decodeProp(prop), encodeProp(prop), prop.value, 0);
}
}
});

View file

@ -1,9 +1,9 @@
import {BitStream} from 'bit-buffer';
import {assertEncoder, assertParser, getStream} from './PacketTest';
import {readFileSync} from 'fs';
import {EncodeGameEventList, ParseGameEventList} from '../../../../Parser/Packet/GameEventList';
import {GameEventListPacket} from '../../../../Data/Packet';
import {GameEvent} from '../../../../Data/GameEventTypes';
import {GameEventListPacket} from '../../../../Data/Packet';
import {EncodeGameEventList, ParseGameEventList} from '../../../../Parser/Packet/GameEventList';
import {assertEncoder, assertParser, getStream} from './PacketTest';
const data = JSON.parse(readFileSync(__dirname + '/../../../data/gameEventListData.json', 'utf8'));
const expectedSource = JSON.parse(readFileSync(__dirname + '/../../../data/gameEventList.json', 'utf8'));
@ -14,71 +14,71 @@ const expected = {
};
const eventList: GameEventListPacket = {
'packetType': 'gameEventList',
'eventList': new Map([
packetType: 'gameEventList',
eventList: new Map([
[0, {
'id': 0,
'name': 'server_spawn' as GameEvent['name'],
'entries': [
id: 0,
name: 'server_spawn' as GameEvent['name'],
entries: [
{
'type': 1,
'name': 'hostname'
type: 1,
name: 'hostname'
},
{
'type': 1,
'name': 'address'
type: 1,
name: 'address'
},
{
'type': 3,
'name': 'ip'
type: 3,
name: 'ip'
},
{
'type': 4,
'name': 'port'
type: 4,
name: 'port'
},
{
'type': 1,
'name': 'game'
type: 1,
name: 'game'
},
{
'type': 1,
'name': 'mapname'
type: 1,
name: 'mapname'
},
{
'type': 3,
'name': 'maxplayers'
type: 3,
name: 'maxplayers'
},
{
'type': 1,
'name': 'os'
type: 1,
name: 'os'
},
{
'type': 6,
'name': 'dedicated'
type: 6,
name: 'dedicated'
},
{
'type': 6,
'name': 'password'
type: 6,
name: 'password'
}
]
}],
[1, {
'id': 1,
'name': 'server_changelevel_failed' as GameEvent['name'],
'entries': [
id: 1,
name: 'server_changelevel_failed' as GameEvent['name'],
entries: [
{
'type': 1,
'name': 'levelname'
type: 1,
name: 'levelname'
}
]
}],
[2, {
'id': 2,
'name': 'server_shutdown' as GameEvent['name'],
'entries': [
id: 2,
name: 'server_shutdown' as GameEvent['name'],
entries: [
{
'type': 1,
'name': 'reason'
type: 1,
name: 'reason'
}
]
}]

View file

@ -1,9 +1,9 @@
import {BitStream} from 'bit-buffer';
import {assertEncoder, assertParser, getStream} from './PacketTest';
import {EncodeGameEvent, ParseGameEvent} from '../../../../Parser/Packet/GameEvent';
import {GameEventPacket} from '../../../../Data/Packet';
import {GameEventValueType} from '../../../../Data/GameEvent';
import {GameEventPacket} from '../../../../Data/Packet';
import {createParserState} from '../../../../Data/ParserState';
import {EncodeGameEvent, ParseGameEvent} from '../../../../Parser/Packet/GameEvent';
import {assertEncoder, assertParser, getStream} from './PacketTest';
const data = [25, 240, 149, 0, 0];
const expected = {

View file

@ -1,20 +1,20 @@
import * as assert from 'assert';
import {BitStream} from 'bit-buffer';
import {assertEncoder, assertParser, getStream} from './PacketTest';
import {hydrateEntity, hydrateTable} from './hydrate';
import {ServerClass} from '../../../../Data/ServerClass';
import {PacketEntitiesPacket} from '../../../../Data/Packet';
import {readFileSync} from 'fs';
import {gunzipSync} from 'zlib';
import {EncodePacketEntities, ParsePacketEntities} from '../../../../Parser/Packet/PacketEntities';
import * as assert from 'assert';
import {deepEqual} from '../../deepEqual';
import {PacketEntitiesPacket} from '../../../../Data/Packet';
import {createParserState} from '../../../../Data/ParserState';
import {ServerClass} from '../../../../Data/ServerClass';
import {EncodePacketEntities, ParsePacketEntities} from '../../../../Parser/Packet/PacketEntities';
import {deepEqual} from '../../deepEqual';
import {hydrateEntity, hydrateTable} from './hydrate';
import {assertEncoder, assertParser, getStream} from './PacketTest';
const data = JSON.parse(readFileSync(__dirname + '/../../../data/packetEntitiesData.json', 'utf8'));
const packetData = JSON.parse(gunzipSync(readFileSync(__dirname + '/../../../data/packetEntitiesResult.json.gz')).toString('utf8'));
const sendTableData = JSON.parse(gunzipSync(readFileSync(__dirname + '/../../../data/packetEntitiesSendTables.json.gz')).toString('utf8'));
const serverClassesData = JSON.parse(readFileSync(__dirname + '/../../../data/packetEntitiesServerClasses.json', 'utf8'));
const baselineData: [number, number[]][] = JSON.parse(readFileSync(__dirname + '/../../../data/packetEntityBaseLines.json', 'utf8'));
const baselineData: Array<[number, number[]]> = JSON.parse(readFileSync(__dirname + '/../../../data/packetEntityBaseLines.json', 'utf8'));
const playerEntityData = JSON.parse(readFileSync(__dirname + '/../../../data/packetEntitiesPlayerEntity.json', 'utf8'));
const expected: PacketEntitiesPacket = {
@ -58,69 +58,69 @@ function encode(value: PacketEntitiesPacket, stream: BitStream) {
}
const sunEntityData = {
'serverClass': {
'id': 123,
'name': 'CSun',
'dataTable': 'DT_Sun'
serverClass: {
id: 123,
name: 'CSun',
dataTable: 'DT_Sun'
},
'entityIndex': 403,
'props': [
entityIndex: 403,
props: [
{
'definition': {
'type': 0,
'name': 'm_clrRender',
'flags': 1,
'excludeDTName': null,
'lowValue': 0,
'highValue': 0,
'bitCount': 32,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_Sun'
definition: {
type: 0,
name: 'm_clrRender',
flags: 1,
excludeDTName: null,
lowValue: 0,
highValue: 0,
bitCount: 32,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_Sun'
},
'value': 4276271871
value: 4276271871
},
{
'definition': {
'type': 0,
'name': 'm_clrOverlay',
'flags': 1,
'excludeDTName': null,
'lowValue': 0,
'highValue': 0,
'bitCount': 32,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_Sun'
definition: {
type: 0,
name: 'm_clrOverlay',
flags: 1,
excludeDTName: null,
lowValue: 0,
highValue: 0,
bitCount: 32,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_Sun'
},
'value': 0
value: 0
},
{
'definition': {
'type': 2,
'name': 'm_vDirection',
'flags': 32,
'excludeDTName': null,
'lowValue': 0,
'highValue': -121121.125,
'bitCount': 0,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_Sun'
definition: {
type: 2,
name: 'm_vDirection',
flags: 32,
excludeDTName: null,
lowValue: 0,
highValue: -121121.125,
bitCount: 0,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_Sun'
},
'value': {
'x': -0.6453346360527601,
'y': -0.504152418172936,
'z': 0.1880801172447484
value: {
x: -0.6453346360527601,
y: -0.504152418172936,
z: 0.1880801172447484
}
}
],
'inPVS': true,
'pvs': 1,
'serialNumber': 664
inPVS: true,
pvs: 1,
serialNumber: 664
};
suite('PacketEntities', () => {
@ -129,7 +129,11 @@ suite('PacketEntities', () => {
const stream = getStream(data);
const start = stream.index;
const resultPacket = parse(stream);
assert.equal(stream.index - start, length, 'Unexpected number of bits consumed from stream');
assert.equal(
stream.index - start,
length,
'Unexpected number of bits consumed from stream'
);
for (let i = 0; i < resultPacket.entities.length; i++) {
const resultEntity = resultPacket.entities[i];
@ -138,9 +142,12 @@ suite('PacketEntities', () => {
assert.equal(expectedEntity.serialNumber, resultEntity.serialNumber);
assert.equal(expectedEntity.entityIndex, resultEntity.entityIndex);
if (!deepEqual(resultEntity, expectedEntity)) {
for (let i = 0; i < expectedEntity.props.length; i++) {
console.log(resultEntity.getPropByDefinition(expectedEntity.props[i].definition),expectedEntity.props[i].definition);
assert.deepEqual(resultEntity.getPropByDefinition(expectedEntity.props[i].definition), expectedEntity.props[i], `invalid property #${i} for ${resultEntity.serverClass.name}`);
for (let j = 0; j < expectedEntity.props.length; j++) {
assert.deepEqual(
resultEntity.getPropByDefinition(expectedEntity.props[j].definition),
expectedEntity.props[j],
`invalid property #${j} for ${resultEntity.serverClass.name}`
);
}
assert.equal(resultEntity.props.length, expectedEntity.props.length, `Unexpected number of props for ${resultEntity.serverClass.name}`);
assert(false, 'Invalid entity ' + resultEntity.serverClass.name);
@ -153,7 +160,6 @@ suite('PacketEntities', () => {
assertEncoder(parse, encode, toEncode, 0);
});
test('Encode small packetEntities', () => {
assertEncoder(parse, encode, {
packetType: 'packetEntities',
@ -172,7 +178,7 @@ suite('PacketEntities', () => {
removedEntities: [10, 11],
updatedBaseLine: false,
baseLine: 0,
delta: 0,
delta: 1,
maxEntries: 16,
entities: [hydrateEntity(sunEntityData)]
}, 181);
@ -184,7 +190,7 @@ suite('PacketEntities', () => {
removedEntities: [10, 11],
updatedBaseLine: false,
baseLine: 0,
delta: 0,
delta: 1,
maxEntries: 16,
entities: []
}, 102);

View file

@ -1,9 +1,9 @@
import * as assert from 'assert';
import {BitStream} from 'bit-buffer';
import {Packet} from '../../../../Data/Packet';
import {deepEqual} from '../../deepEqual';
import {isObject} from 'util';
import {Packet} from '../../../../Data/Packet';
import {ParserState} from '../../../../Data/ParserState';
import {deepEqual} from '../../deepEqual';
export function getStream(data: string | number[]) {
if (typeof data === 'string') {

View file

@ -1,6 +1,6 @@
import {BitStream} from 'bit-buffer';
import {assertEncoder, assertParser, getStream} from './PacketTest';
import {EncodeParseSounds, ParseParseSounds} from '../../../../Parser/Packet/ParseSounds';
import {assertEncoder, assertParser, getStream} from './PacketTest';
const data = [
18,

View file

@ -1,5 +1,5 @@
import {make} from '../../../../Parser/Packet/ParserGenerator';
import {BitStream} from 'bit-buffer';
import {make} from '../../../../Parser/Packet/ParserGenerator';
import {assertEncoder, assertParser, getStream} from './PacketTest';
function assertGeneratedParser(definition: string, stream: BitStream, expected: any, length: number) {

View file

@ -1,6 +1,6 @@
import {BitStream} from 'bit-buffer';
import {assertEncoder, assertParser, getStream} from './PacketTest';
import {EncodeSetConVar, ParseSetConVar} from '../../../../Parser/Packet/SetConVar';
import {assertEncoder, assertParser, getStream} from './PacketTest';
suite('SetConVar', () => {
test('Parse setConVar', () => {

View file

@ -1,11 +1,11 @@
import {BitStream} from 'bit-buffer';
import {assertEncoder, assertParser, getStream} from './PacketTest';
import {readFileSync} from 'fs';
import {TempEntitiesPacket} from '../../../../Data/Packet';
import {createParserState} from '../../../../Data/ParserState';
import {ServerClass} from '../../../../Data/ServerClass';
import {EncodeTempEntities, ParseTempEntities} from '../../../../Parser/Packet/TempEntities';
import {hydrateEntity, hydrateTable} from './hydrate';
import {ServerClass} from '../../../../Data/ServerClass';
import {TempEntitiesPacket} from '../../../../Data/Packet';
import {readFileSync} from 'fs';
import {createParserState} from '../../../../Data/ParserState';
import {assertEncoder, assertParser, getStream} from './PacketTest';
const data = [
2,
@ -32,332 +32,332 @@ const data = [
const entityData = JSON.parse(readFileSync(__dirname + '/../../../data/tempEntitiesResult.json', 'utf8'));
const sendTableData = {
'name': 'DT_TEPlayerAnimEvent',
'props': [
name: 'DT_TEPlayerAnimEvent',
props: [
{
'type': 0,
'name': 'm_iPlayerIndex',
'flags': 1,
'excludeDTName': null,
'lowValue': 0,
'highValue': 0,
'bitCount': 7,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_TEPlayerAnimEvent'
type: 0,
name: 'm_iPlayerIndex',
flags: 1,
excludeDTName: null,
lowValue: 0,
highValue: 0,
bitCount: 7,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_TEPlayerAnimEvent'
},
{
'type': 0,
'name': 'm_iEvent',
'flags': 1,
'excludeDTName': null,
'lowValue': 0,
'highValue': 0,
'bitCount': 6,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_TEPlayerAnimEvent'
type: 0,
name: 'm_iEvent',
flags: 1,
excludeDTName: null,
lowValue: 0,
highValue: 0,
bitCount: 6,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_TEPlayerAnimEvent'
},
{
'type': 0,
'name': 'm_nData',
'flags': 0,
'excludeDTName': null,
'lowValue': 0,
'highValue': 0,
'bitCount': 12,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_TEPlayerAnimEvent'
type: 0,
name: 'm_nData',
flags: 0,
excludeDTName: null,
lowValue: 0,
highValue: 0,
bitCount: 12,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_TEPlayerAnimEvent'
}
],
'cachedFlattenedProps': []
cachedFlattenedProps: []
};
const sendTableData2 = {
'name': 'DT_TETFParticleEffect',
'props': [
name: 'DT_TETFParticleEffect',
props: [
{
'type': 6,
'name': 'baseclass',
'flags': 4096,
'excludeDTName': null,
'lowValue': 0,
'highValue': 0,
'bitCount': 0,
'table': {
'name': 'DT_BaseTempEntity',
'props': [],
'cachedFlattenedProps': []
type: 6,
name: 'baseclass',
flags: 4096,
excludeDTName: null,
lowValue: 0,
highValue: 0,
bitCount: 0,
table: {
name: 'DT_BaseTempEntity',
props: [],
cachedFlattenedProps: []
},
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_TETFParticleEffect'
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_TETFParticleEffect'
},
{
'type': 1,
'name': 'm_vecOrigin[0]',
'flags': 32772,
'excludeDTName': null,
'lowValue': 0,
'highValue': 0,
'bitCount': 32,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_TETFParticleEffect'
type: 1,
name: 'm_vecOrigin[0]',
flags: 32772,
excludeDTName: null,
lowValue: 0,
highValue: 0,
bitCount: 32,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_TETFParticleEffect'
},
{
'type': 1,
'name': 'm_vecOrigin[1]',
'flags': 32772,
'excludeDTName': null,
'lowValue': 0,
'highValue': 0,
'bitCount': 32,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_TETFParticleEffect'
type: 1,
name: 'm_vecOrigin[1]',
flags: 32772,
excludeDTName: null,
lowValue: 0,
highValue: 0,
bitCount: 32,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_TETFParticleEffect'
},
{
'type': 1,
'name': 'm_vecOrigin[2]',
'flags': 32772,
'excludeDTName': null,
'lowValue': 0,
'highValue': 0,
'bitCount': 32,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_TETFParticleEffect'
type: 1,
name: 'm_vecOrigin[2]',
flags: 32772,
excludeDTName: null,
lowValue: 0,
highValue: 0,
bitCount: 32,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_TETFParticleEffect'
},
{
'type': 1,
'name': 'm_vecStart[0]',
'flags': 32772,
'excludeDTName': null,
'lowValue': 0,
'highValue': 0,
'bitCount': 32,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_TETFParticleEffect'
type: 1,
name: 'm_vecStart[0]',
flags: 32772,
excludeDTName: null,
lowValue: 0,
highValue: 0,
bitCount: 32,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_TETFParticleEffect'
},
{
'type': 1,
'name': 'm_vecStart[1]',
'flags': 32772,
'excludeDTName': null,
'lowValue': 0,
'highValue': 0,
'bitCount': 32,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_TETFParticleEffect'
type: 1,
name: 'm_vecStart[1]',
flags: 32772,
excludeDTName: null,
lowValue: 0,
highValue: 0,
bitCount: 32,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_TETFParticleEffect'
},
{
'type': 1,
'name': 'm_vecStart[2]',
'flags': 32772,
'excludeDTName': null,
'lowValue': 0,
'highValue': 0,
'bitCount': 32,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_TETFParticleEffect'
type: 1,
name: 'm_vecStart[2]',
flags: 32772,
excludeDTName: null,
lowValue: 0,
highValue: 0,
bitCount: 32,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_TETFParticleEffect'
},
{
'type': 2,
'name': 'm_vecAngles',
'flags': 0,
'excludeDTName': null,
'lowValue': 0,
'highValue': 360,
'bitCount': 7,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_TETFParticleEffect'
type: 2,
name: 'm_vecAngles',
flags: 0,
excludeDTName: null,
lowValue: 0,
highValue: 360,
bitCount: 7,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_TETFParticleEffect'
},
{
'type': 0,
'name': 'm_iParticleSystemIndex',
'flags': 1,
'excludeDTName': null,
'lowValue': 0,
'highValue': 0,
'bitCount': 16,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_TETFParticleEffect'
type: 0,
name: 'm_iParticleSystemIndex',
flags: 1,
excludeDTName: null,
lowValue: 0,
highValue: 0,
bitCount: 16,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_TETFParticleEffect'
},
{
'type': 0,
'name': 'entindex',
'flags': 1,
'excludeDTName': null,
'lowValue': 0,
'highValue': 0,
'bitCount': 11,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_TETFParticleEffect'
type: 0,
name: 'entindex',
flags: 1,
excludeDTName: null,
lowValue: 0,
highValue: 0,
bitCount: 11,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_TETFParticleEffect'
},
{
'type': 0,
'name': 'm_iAttachType',
'flags': 1,
'excludeDTName': null,
'lowValue': 0,
'highValue': 0,
'bitCount': 5,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_TETFParticleEffect'
type: 0,
name: 'm_iAttachType',
flags: 1,
excludeDTName: null,
lowValue: 0,
highValue: 0,
bitCount: 5,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_TETFParticleEffect'
},
{
'type': 0,
'name': 'm_iAttachmentPointIndex',
'flags': 0,
'excludeDTName': null,
'lowValue': 0,
'highValue': 0,
'bitCount': 32,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_TETFParticleEffect'
type: 0,
name: 'm_iAttachmentPointIndex',
flags: 0,
excludeDTName: null,
lowValue: 0,
highValue: 0,
bitCount: 32,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_TETFParticleEffect'
},
{
'type': 0,
'name': 'm_bResetParticles',
'flags': 1,
'excludeDTName': null,
'lowValue': 0,
'highValue': 0,
'bitCount': 1,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_TETFParticleEffect'
type: 0,
name: 'm_bResetParticles',
flags: 1,
excludeDTName: null,
lowValue: 0,
highValue: 0,
bitCount: 1,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_TETFParticleEffect'
},
{
'type': 0,
'name': 'm_bCustomColors',
'flags': 1,
'excludeDTName': null,
'lowValue': 0,
'highValue': 0,
'bitCount': 1,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_TETFParticleEffect'
type: 0,
name: 'm_bCustomColors',
flags: 1,
excludeDTName: null,
lowValue: 0,
highValue: 0,
bitCount: 1,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_TETFParticleEffect'
},
{
'type': 2,
'name': 'm_CustomColors.m_vecColor1',
'flags': 0,
'excludeDTName': null,
'lowValue': 0,
'highValue': 1,
'bitCount': 8,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_TETFParticleEffect'
type: 2,
name: 'm_CustomColors.m_vecColor1',
flags: 0,
excludeDTName: null,
lowValue: 0,
highValue: 1,
bitCount: 8,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_TETFParticleEffect'
},
{
'type': 2,
'name': 'm_CustomColors.m_vecColor2',
'flags': 0,
'excludeDTName': null,
'lowValue': 0,
'highValue': 1,
'bitCount': 8,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_TETFParticleEffect'
type: 2,
name: 'm_CustomColors.m_vecColor2',
flags: 0,
excludeDTName: null,
lowValue: 0,
highValue: 1,
bitCount: 8,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_TETFParticleEffect'
},
{
'type': 0,
'name': 'm_bControlPoint1',
'flags': 1,
'excludeDTName': null,
'lowValue': 0,
'highValue': 0,
'bitCount': 1,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_TETFParticleEffect'
type: 0,
name: 'm_bControlPoint1',
flags: 1,
excludeDTName: null,
lowValue: 0,
highValue: 0,
bitCount: 1,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_TETFParticleEffect'
},
{
'type': 0,
'name': 'm_ControlPoint1.m_eParticleAttachment',
'flags': 1,
'excludeDTName': null,
'lowValue': 0,
'highValue': 0,
'bitCount': 5,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_TETFParticleEffect'
type: 0,
name: 'm_ControlPoint1.m_eParticleAttachment',
flags: 1,
excludeDTName: null,
lowValue: 0,
highValue: 0,
bitCount: 5,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_TETFParticleEffect'
},
{
'type': 1,
'name': 'm_ControlPoint1.m_vecOffset[0]',
'flags': 8196,
'excludeDTName': null,
'lowValue': 0,
'highValue': 0,
'bitCount': 32,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_TETFParticleEffect'
type: 1,
name: 'm_ControlPoint1.m_vecOffset[0]',
flags: 8196,
excludeDTName: null,
lowValue: 0,
highValue: 0,
bitCount: 32,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_TETFParticleEffect'
},
{
'type': 1,
'name': 'm_ControlPoint1.m_vecOffset[1]',
'flags': 8196,
'excludeDTName': null,
'lowValue': 0,
'highValue': 0,
'bitCount': 32,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_TETFParticleEffect'
type: 1,
name: 'm_ControlPoint1.m_vecOffset[1]',
flags: 8196,
excludeDTName: null,
lowValue: 0,
highValue: 0,
bitCount: 32,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_TETFParticleEffect'
},
{
'type': 1,
'name': 'm_ControlPoint1.m_vecOffset[2]',
'flags': 8196,
'excludeDTName': null,
'lowValue': 0,
'highValue': 0,
'bitCount': 32,
'table': null,
'numElements': 0,
'arrayProperty': null,
'ownerTableName': 'DT_TETFParticleEffect'
type: 1,
name: 'm_ControlPoint1.m_vecOffset[2]',
flags: 8196,
excludeDTName: null,
lowValue: 0,
highValue: 0,
bitCount: 32,
table: null,
numElements: 0,
arrayProperty: null,
ownerTableName: 'DT_TETFParticleEffect'
}
],
'cachedFlattenedProps': []
cachedFlattenedProps: []
};
const sendTable = hydrateTable(sendTableData);
const sendTable2 = hydrateTable(sendTableData2);

View file

@ -1,9 +1,9 @@
import {BitStream} from 'bit-buffer';
import {assertEncoder, assertParser, getStream} from './PacketTest';
import {EncodeUpdateStringTable, ParseUpdateStringTable} from '../../../../Parser/Packet/UpdateStringTable';
import {StringTable} from '../../../../Data/StringTable';
import {UpdateStringTablePacket} from '../../../../Data/Packet';
import {createParserState} from '../../../../Data/ParserState';
import {StringTable} from '../../../../Data/StringTable';
import {EncodeUpdateStringTable, ParseUpdateStringTable} from '../../../../Parser/Packet/UpdateStringTable';
import {assertEncoder, assertParser, getStream} from './PacketTest';
const exampleData = [200, 3, 0, 48, 130, 53];
@ -36,7 +36,6 @@ examplePacket.entries[70] = {
)
};
const examplePacket2: UpdateStringTablePacket = {
packetType: 'updateStringTable',
entries: [

View file

@ -1,7 +1,7 @@
import {BitStream} from 'bit-buffer';
import {assertEncoder, assertParser, getStream} from './PacketTest';
import {EncodeUserMessage, ParseUserMessage} from '../../../../Parser/Packet/UserMessage';
import {HudTextLocation} from '../../../../Data/UserMessage';
import {EncodeUserMessage, ParseUserMessage} from '../../../../Parser/Packet/UserMessage';
import {assertEncoder, assertParser, getStream} from './PacketTest';
const data = [
5,
@ -40,7 +40,7 @@ const expected = {
substitute1: 'sekr',
substitute2: '',
substitute3: '',
substitute4: '',
substitute4: ''
};
suite('UserMessage', () => {

View file

@ -1,6 +1,6 @@
import {BitStream} from 'bit-buffer';
import {assertEncoder, assertParser, getStream} from './PacketTest';
import {EncodeVoiceData, ParseVoiceData} from '../../../../Parser/Packet/VoiceData';
import {assertEncoder, assertParser, getStream} from './PacketTest';
const data = [5, 18, 24, 0, 123, 219, 1];

View file

@ -1,6 +1,6 @@
import {BitStream} from 'bit-buffer';
import {assertEncoder, assertParser, getStream} from './PacketTest';
import {EncodeVoiceInit, ParseVoiceInit} from '../../../../Parser/Packet/VoiceInit';
import {assertEncoder, assertParser, getStream} from './PacketTest';
const data = [118, 97, 117, 100, 105, 111, 95, 99, 101, 108, 116, 0, 255, 34, 86];

View file

@ -1,12 +1,12 @@
import {SendProp, SendPropValue} from '../../../../Data/SendProp';
import {PacketEntity} from '../../../../Data/PacketEntity';
import {SendProp, SendPropValue} from '../../../../Data/SendProp';
import {SendPropDefinition, SendPropType} from '../../../../Data/SendPropDefinition';
import {Vector} from '../../../../Data/Vector';
import {SendTable} from '../../../../Data/SendTable';
import {Vector} from '../../../../Data/Vector';
export function hydrateEntity(entityData): PacketEntity {
const entity = new PacketEntity(entityData.serverClass, entityData.entityIndex, entityData.pvs);
entity.props = entityData.props.map(propData => {
entity.props = entityData.props.map((propData) => {
const prop = new SendProp(propDataDefinition(propData.definition));
prop.value = hydrateProp(propData.value, prop.definition);
return prop;
@ -27,7 +27,7 @@ function hydrateProp(value: any, definition: SendPropDefinition): SendPropValue
if (arrayProp === null) {
throw new Error('arrayProperty not set for array property');
}
return value.map(arrayValue => hydrateProp(arrayValue, arrayProp)) as SendPropValue;
return value.map((arrayValue) => hydrateProp(arrayValue, arrayProp)) as SendPropValue;
} else if (definition.type === SendPropType.DPT_Vector || definition.type === SendPropType.DPT_VectorXY) {
return new Vector(value.x, value.y, value.z);
} else {

View file

@ -1,9 +1,9 @@
import {BitStream} from 'bit-buffer';
import {assertEncoder, assertParser, getStream} from './Packet/PacketTest';
import {readBitVar, readVarInt, writeBitVar, writeVarInt} from '../../../Parser/readBitVar';
import {SendPropParser} from '../../../Parser/SendPropParser';
import {SendPropDefinition, SendPropFlag, SendPropType} from '../../../Data/SendPropDefinition';
import {readBitVar, readVarInt, writeBitVar, writeVarInt} from '../../../Parser/readBitVar';
import {SendPropEncoder} from '../../../Parser/SendPropEncoder';
import {SendPropParser} from '../../../Parser/SendPropParser';
import {assertEncoder, assertParser, getStream} from './Packet/PacketTest';
function basicIntReader(bitCount: number, signed: boolean) {
return (stream: BitStream) => {

View file

@ -1,6 +1,6 @@
import {BitStream} from 'bit-buffer';
import {assertEncoder, assertParser, getStream} from '../Packet/PacketTest';
import {EncodeSayText2, ParseSayText2} from '../../../../Parser/UserMessage/SayText2';
import {assertEncoder, assertParser, getStream} from '../Packet/PacketTest';
const data = [
3,

View file

@ -1,6 +1,6 @@
import {BitStream} from 'bit-buffer';
import {assertEncoder, assertParser, getStream} from './Packet/PacketTest';
import {readBitVar, readVarInt, writeBitVar, writeVarInt} from '../../../Parser/readBitVar';
import {assertEncoder, assertParser, getStream} from './Packet/PacketTest';
function readVarIntSigned(stream: BitStream) {
return readVarInt(stream, true);

View file

@ -1,5 +1,5 @@
import {BitStream} from 'bit-buffer';
import * as assert from 'assert';
import {BitStream} from 'bit-buffer';
export interface EqualOpts {
strict?: boolean;
@ -15,7 +15,8 @@ export function deepEqual(actual, expected, opts: EqualOpts = {}) {
// 7.3. Other pairs that do not both pass typeof value == 'object',
// equivalence is determined by ==.
} else if (!actual || !expected || typeof actual != 'object' && typeof expected != 'object') {
} else if (!actual || !expected || typeof actual !== 'object' && typeof expected !== 'object') {
// tslint:disable-next-line
return opts.strict ? actual === expected : actual == expected;
// 7.4. For all other Object pairs, including Array objects, equivalence is
@ -34,7 +35,9 @@ function isUndefinedOrNull(value) {
}
function isBuffer(x): x is Buffer {
if (!x || typeof x !== 'object' || typeof x.length !== 'number') return false;
if (!x || typeof x !== 'object' || typeof x.length !== 'number') {
return false;
}
if (typeof x.copy !== 'function' || typeof x.slice !== 'function') {
return false;
}
@ -46,14 +49,16 @@ function isStream(stream): stream is BitStream {
}
function objEquiv(a, b, opts) {
let i, key;
if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
let i;
let key;
if (isUndefinedOrNull(a) || isUndefinedOrNull(b)) {
return false;
}
// an identical 'prototype' property.
if (a.prototype !== b.prototype) {
return false;
}
//~~~I've managed to break Object.keys through screwy arguments passing.
// ~~~I've managed to break Object.keys through screwy arguments passing.
// Converting to array solves the problem.
if (isBuffer(a)) {
if (!isBuffer(b)) {
@ -95,24 +100,28 @@ function objEquiv(a, b, opts) {
// having the same number of owned properties (keys incorporates
// hasOwnProperty)
if (ka.length != kb.length)
if (ka.length !== kb.length) {
return false;
//the same set of keys (although not necessarily the same order),
}
// the same set of keys (although not necessarily the same order),
ka.sort();
kb.sort();
//~~~cheap key test
// ~~~cheap key test
for (i = ka.length - 1; i >= 0; i--) {
if (ka[i] != kb[i])
if (ka[i] !== kb[i]) {
return false;
}
}
//equivalent values for every corresponding key, and
//~~~possibly expensive deep test
// equivalent values for every corresponding key, and
// ~~~possibly expensive deep test
for (i = ka.length - 1; i >= 0; i--) {
key = ka[i];
if (!deepEqual(a[key], b[key], opts)) return false;
if (!deepEqual(a[key], b[key], opts)) {
return false;
}
}
return typeof a === typeof b;
} catch (e) {//happens when one is a string literal and the other isn't
} catch (e) {// happens when one is a string literal and the other isn't
return false;
}
}