From 82084ad38e28511f4bbea4d9744c97efde0f57ee Mon Sep 17 00:00:00 2001 From: mmorrison Date: Mon, 4 Feb 2019 01:16:30 -0600 Subject: [PATCH] Improve null splitting on rfactor --- protocols/rfactor.js | 3 ++- protocols/samp.js | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/protocols/rfactor.js b/protocols/rfactor.js index 7d4b58c..1716a12 100644 --- a/protocols/rfactor.js +++ b/protocols/rfactor.js @@ -68,7 +68,8 @@ class Rfactor extends Core { // Consumes bytesToConsume, but only returns string up to the first null readString(reader, bytesToConsume) { - return reader.string(bytesToConsume).replace(/\0.*$/g,''); + const consumed = reader.part(bytesToConsume); + return this.reader(consumed).string(); } } diff --git a/protocols/samp.js b/protocols/samp.js index 8af3c99..34a8b77 100644 --- a/protocols/samp.js +++ b/protocols/samp.js @@ -14,9 +14,8 @@ class Samp extends Core { { const reader = await this.sendPacket('i'); if (this.isVcmp) { - let version = reader.string(12); - version = version.replace(/\0.*$/g,''); - state.raw.version = version; + const consumed = reader.part(12); + state.raw.version = this.reader(consumed).string(); } state.password = !!reader.uint(1); state.raw.numplayers = reader.uint(2);