mirror of
https://github.com/tribufu/node-gamedig
synced 2026-05-06 15:17:36 +00:00
Clean up reader.string
This commit is contained in:
parent
6189d2fa62
commit
fc5975bf0c
12 changed files with 58 additions and 61 deletions
|
|
@ -4,7 +4,7 @@ class Ase extends Core {
|
|||
async run(state) {
|
||||
const buffer = await this.udpSend('s',(buffer) => {
|
||||
const reader = this.reader(buffer);
|
||||
const header = reader.string({length: 4});
|
||||
const header = reader.string(4);
|
||||
if (header === 'EYE1') return reader.rest();
|
||||
});
|
||||
|
||||
|
|
@ -40,8 +40,7 @@ class Ase extends Core {
|
|||
}
|
||||
|
||||
readString(reader) {
|
||||
const len = reader.uint(1);
|
||||
return reader.string({length:len-1});
|
||||
return reader.pascalString(1, -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -153,8 +153,7 @@ class Battlefield extends Core {
|
|||
const paramCount = reader.uint(4);
|
||||
const params = [];
|
||||
for(let i = 0; i < paramCount; i++) {
|
||||
const len = reader.uint(4);
|
||||
params.push(reader.string({length:len}));
|
||||
params.push(reader.pascalString(4));
|
||||
const strNull = reader.uint(1);
|
||||
}
|
||||
return params;
|
||||
|
|
|
|||
|
|
@ -66,8 +66,7 @@ class Cs2d extends Core {
|
|||
}
|
||||
|
||||
readString(reader) {
|
||||
const length = reader.uint(1);
|
||||
return reader.string({length:length});
|
||||
return reader.pascalString(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,10 +16,10 @@ class Doom3 extends Core {
|
|||
if(header !== 0xffff) return;
|
||||
const header2 = reader.string();
|
||||
if(header2 !== 'infoResponse') return;
|
||||
const challengePart1 = reader.string({length:4});
|
||||
const challengePart1 = reader.string(4);
|
||||
if (challengePart1 !== "PiNG") return;
|
||||
// some doom3 implementations only return the first 4 bytes of the challenge
|
||||
const challengePart2 = reader.string({length:4});
|
||||
const challengePart2 = reader.string(4);
|
||||
if (challengePart2 !== 'PoNg') reader.skip(-4);
|
||||
return reader.rest();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ class Gamespy1 extends Core {
|
|||
|
||||
return await this.udpSend('\\'+type+'\\', buffer => {
|
||||
const reader = this.reader(buffer);
|
||||
const str = reader.string({length:buffer.length});
|
||||
const str = reader.string(buffer.length);
|
||||
const split = str.split('\\');
|
||||
split.shift();
|
||||
const data = {};
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ class M2mp extends Core {
|
|||
async run(state) {
|
||||
const body = await this.udpSend('M2MP',(buffer) => {
|
||||
const reader = this.reader(buffer);
|
||||
const header = reader.string({length: 4});
|
||||
const header = reader.string(4);
|
||||
if (header !== 'M2MP') return;
|
||||
return reader.rest();
|
||||
});
|
||||
|
|
@ -32,8 +32,7 @@ class M2mp extends Core {
|
|||
}
|
||||
|
||||
readString(reader) {
|
||||
const length = reader.uint(1);
|
||||
return reader.string({length:length-1});
|
||||
return reader.pascalString(1,-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class Quake2 extends Core {
|
|||
if (header !== '\xff\xff\xff\xff') return;
|
||||
let type;
|
||||
if (this.isQuake1) {
|
||||
type = reader.string({length: this.responseHeader.length});
|
||||
type = reader.string(this.responseHeader.length);
|
||||
} else {
|
||||
type = reader.string({encoding: 'latin1'});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ class Samp extends Core {
|
|||
state.password = !!reader.uint(1);
|
||||
state.raw.numplayers = reader.uint(2);
|
||||
state.maxplayers = reader.uint(2);
|
||||
state.name = this.readString(reader,4);
|
||||
state.raw.gamemode = this.readString(reader,4);
|
||||
state.raw.map = this.readString(reader,4);
|
||||
state.name = reader.pascalString(4);
|
||||
state.raw.gamemode = reader.pascalString(4);
|
||||
state.raw.map = reader.pascalString(4);
|
||||
}
|
||||
|
||||
// read rules
|
||||
|
|
@ -31,8 +31,8 @@ class Samp extends Core {
|
|||
const ruleCount = reader.uint(2);
|
||||
state.raw.rules = {};
|
||||
for(let i = 0; i < ruleCount; i++) {
|
||||
const key = this.readString(reader,1);
|
||||
const value = this.readString(reader,1);
|
||||
const key = reader.pascalString(1);
|
||||
const value = reader.pascalString(1);
|
||||
state.raw.rules[key] = value;
|
||||
}
|
||||
}
|
||||
|
|
@ -48,7 +48,7 @@ class Samp extends Core {
|
|||
const playerCount = reader.uint(2);
|
||||
for(let i = 0; i < playerCount; i++) {
|
||||
const player = {};
|
||||
player.name = this.readString(reader,1);
|
||||
player.name = reader.pascalString(1);
|
||||
state.players.push(player);
|
||||
}
|
||||
}
|
||||
|
|
@ -60,7 +60,7 @@ class Samp extends Core {
|
|||
for(let i = 0; i < playerCount; i++) {
|
||||
const player = {};
|
||||
player.id = reader.uint(1);
|
||||
player.name = this.readString(reader,1);
|
||||
player.name = reader.pascalString(1);
|
||||
player.score = reader.int(4);
|
||||
player.ping = reader.uint(4);
|
||||
state.players.push(player);
|
||||
|
|
@ -72,11 +72,6 @@ class Samp extends Core {
|
|||
state.players = state.raw.numplayers;
|
||||
}
|
||||
}
|
||||
readString(reader,lenBytes) {
|
||||
const length = reader.uint(lenBytes);
|
||||
if(!length) return '';
|
||||
return reader.string({length:length});
|
||||
}
|
||||
async sendPacket(type,allowTimeout) {
|
||||
const outBuffer = Buffer.alloc(11);
|
||||
outBuffer.write(this.magicHeader,0, 4);
|
||||
|
|
|
|||
|
|
@ -145,9 +145,7 @@ class Tribes1 extends Core {
|
|||
.map((a) => a.trim());
|
||||
}
|
||||
readString(reader) {
|
||||
const length = reader.uint(1);
|
||||
if(!length) return '';
|
||||
return reader.string({length:length});
|
||||
return reader.pascalString(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,9 +74,7 @@ class Tribes1Master extends Core {
|
|||
}
|
||||
}
|
||||
readString(reader) {
|
||||
const length = reader.uint(1);
|
||||
if(!length) return '';
|
||||
return reader.string({length:length});
|
||||
return reader.pascalString(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ class Unreal2 extends Core {
|
|||
let length = reader.uint(1);
|
||||
let out;
|
||||
if(length < 0x80) {
|
||||
//out = reader.string({length:length});
|
||||
//out = reader.string(length);
|
||||
out = '';
|
||||
if(length > 0) out = reader.string();
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue