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:
parent
628f23b216
commit
3d0aee619e
5 changed files with 40 additions and 6 deletions
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue