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

encode for setConVar

This commit is contained in:
Robin Appelman 2017-08-12 15:36:23 +02:00
commit 3d0aee619e
5 changed files with 40 additions and 6 deletions

View file

@ -2,8 +2,8 @@ import {BitStream} from 'bit-buffer';
import {SetConVarPacket} from '../../Data/Packet';
export function ParseSetConVar(stream: BitStream): SetConVarPacket { // 5: setconvar
const count = stream.readBits(8);
const vars: {[key: string]: string} = {};
const count = stream.readUint8();
const vars: { [key: string]: string } = {};
for (let i = 0; i < count; i++) {
vars[stream.readUTF8String()] = stream.readUTF8String();
}
@ -12,3 +12,12 @@ export function ParseSetConVar(stream: BitStream): SetConVarPacket { // 5: setco
vars,
};
}
export function EncodeSetConVar(packet: SetConVarPacket, stream: BitStream) {
const keys = Object.keys(packet.vars);
stream.writeUint8(keys.length);
for (const key of keys) {
stream.writeUTF8String(key);
stream.writeUTF8String(packet.vars[key]);
}
}