This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('node:path');
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const protobuf = require('protobufjs');
|
||||
|
||||
const proto = protobuf.loadSync(path.join(__dirname, '..', 'dota.proto'));
|
||||
|
||||
test('encodes Source 2 engine on the current CMsgClientHello field 7', () => {
|
||||
const Hello = proto.lookupType('CMsgClientHello');
|
||||
assert.deepEqual([...Hello.encode({ engine: 1 }).finish()], [0x38, 0x01]);
|
||||
});
|
||||
|
||||
test('round-trips a custom practice lobby creation request', () => {
|
||||
const Create = proto.lookupType('CMsgPracticeLobbyCreate');
|
||||
const payload = {
|
||||
passKey: 'secret',
|
||||
lobbyDetails: {
|
||||
gameName: 'Queue helper',
|
||||
serverRegion: 3,
|
||||
gameMode: 15,
|
||||
lan: false,
|
||||
customGameMode: 'addon',
|
||||
customMapName: 'map',
|
||||
customDifficulty: 0,
|
||||
customGameId: '123456789012345678',
|
||||
customMinPlayers: 2,
|
||||
customMaxPlayers: 10,
|
||||
visibility: 0,
|
||||
customGamePenalties: true,
|
||||
},
|
||||
};
|
||||
const decoded = Create.toObject(Create.decode(Create.encode(payload).finish()), { longs: String });
|
||||
assert.equal(decoded.passKey, 'secret');
|
||||
assert.equal(decoded.lobbyDetails.customGameId, '123456789012345678');
|
||||
assert.equal(decoded.lobbyDetails.gameMode, 15);
|
||||
assert.equal(decoded.lobbyDetails.lan, false);
|
||||
assert.equal(decoded.lobbyDetails.customDifficulty, 0);
|
||||
assert.equal(decoded.lobbyDetails.customMaxPlayers, 10);
|
||||
assert.equal(decoded.lobbyDetails.customGamePenalties, true);
|
||||
});
|
||||
|
||||
test('decodes CSODOTALobby type 2004 inside an SO multiple update', () => {
|
||||
const Lobby = proto.lookupType('CSODOTALobby');
|
||||
const Multiple = proto.lookupType('CMsgSOMultipleObjects');
|
||||
const lobbyBytes = Lobby.encode({
|
||||
lobbyId: '987654321012345678',
|
||||
state: 0,
|
||||
leaderId: '76561198000000001',
|
||||
allMembers: [
|
||||
{ id: '76561198000000001', team: 4, slot: 0 },
|
||||
{ id: '76561198000000002', team: 0, slot: 1 },
|
||||
],
|
||||
}).finish();
|
||||
const updateBytes = Multiple.encode({
|
||||
objectsModified: [{ typeId: 2004, objectData: lobbyBytes }],
|
||||
}).finish();
|
||||
const update = Multiple.decode(updateBytes);
|
||||
const decoded = Lobby.toObject(Lobby.decode(update.objectsModified[0].objectData), { longs: String });
|
||||
assert.equal(update.objectsModified[0].typeId, 2004);
|
||||
assert.equal(decoded.lobbyId, '987654321012345678');
|
||||
assert.equal(decoded.allMembers.length, 2);
|
||||
assert.equal(decoded.allMembers[1].id, '76561198000000002');
|
||||
});
|
||||
|
||||
test('decodes reusable custom-game build metadata from a joinable lobby', () => {
|
||||
const Response = proto.lookupType('CMsgJoinableCustomLobbiesResponse');
|
||||
const bytes = Response.encode({
|
||||
lobbies: [{
|
||||
lobbyId: '987654321012345678',
|
||||
customGameId: '2141071809',
|
||||
customMapName: 'duos',
|
||||
customGameTimestamp: 1785566685,
|
||||
customGameCrc: '123456789012345678',
|
||||
minPlayerCount: 2,
|
||||
maxPlayerCount: 12,
|
||||
}],
|
||||
}).finish();
|
||||
const decoded = Response.toObject(Response.decode(bytes), { longs: String });
|
||||
assert.equal(decoded.lobbies[0].customGameId, '2141071809');
|
||||
assert.equal(decoded.lobbies[0].customMapName, 'duos');
|
||||
assert.equal(decoded.lobbies[0].customGameCrc, '123456789012345678');
|
||||
assert.equal(decoded.lobbies[0].customGameTimestamp, 1785566685);
|
||||
});
|
||||
|
||||
test('decodes the internal addon name used to publish a practice lobby', () => {
|
||||
const Response = proto.lookupType('CMsgPracticeLobbyListResponse');
|
||||
const bytes = Response.encode({
|
||||
lobbies: [{
|
||||
id: '987654321012345678',
|
||||
name: 'CHC Duos',
|
||||
customGameMode: 'custom_hero_clash',
|
||||
customMapName: 'duos',
|
||||
maxPlayerCount: 12,
|
||||
serverRegion: 9,
|
||||
penaltiesEnabled: true,
|
||||
}],
|
||||
}).finish();
|
||||
const decoded = Response.toObject(Response.decode(bytes), { longs: String });
|
||||
assert.equal(decoded.lobbies[0].id, '987654321012345678');
|
||||
assert.equal(decoded.lobbies[0].customGameMode, 'custom_hero_clash');
|
||||
assert.equal(decoded.lobbies[0].customMapName, 'duos');
|
||||
});
|
||||
Reference in New Issue
Block a user