Skip to content

Commit

Permalink
Remove Players Set Num
Browse files Browse the repository at this point in the history
  • Loading branch information
CosminPerRam committed Oct 23, 2023
1 parent 25f7926 commit 05b2c93
Show file tree
Hide file tree
Showing 13 changed files with 14 additions and 22 deletions.
10 changes: 0 additions & 10 deletions lib/Results.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@ export class Player {
}

export class Players extends Array {
setNum (num) {
// If the server specified some ridiculous number of players (billions), we don't want to
// run out of ram allocating these objects.
num = Math.min(num, 10000)

while (this.length < num) {
this.push({})
}
}

push (data) {
super.push(new Player(data))
}
Expand Down
1 change: 1 addition & 0 deletions protocols/battlefield.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export default class battlefield extends Core {
}
state.players.push(player)
}
state.numplayers = numplayers
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion protocols/geneshift.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class geneshift extends Core {
state.raw.country = found[1]
state.name = found[4]
state.map = found[5]
state.players.setNum(parseInt(found[6]))
state.numplayers = parseInt(found[6])
state.maxplayers = parseInt(found[7])
// fields[8] is unknown?
state.raw.rules = found[9]
Expand Down
4 changes: 2 additions & 2 deletions protocols/jc2mp.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export default class jc2mp extends gamespy3 {
this.useOnlySingleSplit = true
this.isJc2mp = true
this.encoding = 'utf8'
}
}

async run (state) {
await super.run(state)
if (!state.players.length && parseInt(state.raw.numplayers)) {
state.players.setNum(parseInt(state.raw.numplayers))
state.numplayers = parseInt(state.raw.numplayers);
}
}
}
2 changes: 1 addition & 1 deletion protocols/minecraft.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default class minecraft extends Core {
if (gamespyState.name) state.name = gamespyState.name
if (gamespyState.maxplayers) state.maxplayers = gamespyState.maxplayers
if (gamespyState.players.length) state.players = gamespyState.players
else if (gamespyState.raw.numplayers) state.players.setNum(parseInt(gamespyState.raw.numplayers))
else if (gamespyState.raw.numplayers) state.numplayers = parseInt(gamespyState.raw.numplayers)
if (gamespyState.ping) this.registerRtt(gamespyState.ping)
}
if (bedrockState) {
Expand Down
2 changes: 1 addition & 1 deletion protocols/minecraftbedrock.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class minecraftbedrock extends Core {
state.name = split.shift()
state.raw.protocolVersion = split.shift()
state.raw.mcVersion = split.shift()
state.players.setNum(parseInt(split.shift()))
state.numplayers = parseInt(split.shift())
state.maxplayers = parseInt(split.shift())
if (split.length) state.raw.serverId = split.shift()
if (split.length) state.map = split.shift()
Expand Down
2 changes: 1 addition & 1 deletion protocols/mumbleping.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class mumbleping extends Core {
state.raw.versionMinor = reader.uint(1)
state.raw.versionPatch = reader.uint(1)
reader.skip(8)
state.players.setNum(reader.uint(4))
state.numplayers = reader.uint(4)
state.maxplayers = reader.uint(4)
state.raw.allowedbandwidth = reader.uint(4)
}
Expand Down
2 changes: 1 addition & 1 deletion protocols/openttd.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class openttd extends Core {

state.password = !!reader.uint(1)
state.maxplayers = reader.uint(1)
state.players.setNum(reader.uint(1))
state.numplayers = reader.uint(1)
state.raw.numspectators = reader.uint(1)
state.map = reader.string()
state.raw.map_width = reader.uint(2)
Expand Down
2 changes: 1 addition & 1 deletion protocols/rfactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class rfactor extends Core {
state.raw.ping = reader.uint(2)
state.raw.packedFlags = reader.uint(1)
state.raw.rate = reader.uint(1)
state.players.setNum(reader.uint(1))
state.numplayers = reader.uint(1)
state.maxplayers = reader.uint(1)
state.raw.bots = reader.uint(1)
state.raw.packedSpecial = reader.uint(1)
Expand Down
4 changes: 2 additions & 2 deletions protocols/samp.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ export default class samp extends Core {
}
}
if (!gotPlayerData) {
state.players.setNum(state.raw.numplayers)
state.numplayers = state.raw.numplayers
}
}
}

async sendPacket (type, allowTimeout) {
const outBuffer = Buffer.alloc(11)
Expand Down
2 changes: 1 addition & 1 deletion protocols/savage2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default class savage2 extends Core {

reader.skip(12)
state.name = this.stripColorCodes(reader.string())
state.players.setNum(reader.uint(1))
state.numplayers = reader.uint(1)
state.maxplayers = reader.uint(1)
state.raw.time = reader.string()
state.map = reader.string()
Expand Down
2 changes: 1 addition & 1 deletion protocols/starmade.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class starmade extends Core {
if (typeof data[2] === 'string') state.name = data[2]
if (typeof data[3] === 'string') state.raw.description = data[3]
if (typeof data[4] === 'number') state.raw.startTime = data[4]
if (typeof data[5] === 'number') state.players.setNum(data[5])
if (typeof data[5] === 'number') state.numplayers = data[5]
if (typeof data[6] === 'number') state.maxplayers = data[6]
}
}
1 change: 1 addition & 0 deletions protocols/valve.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ export default class valve extends Core {
if (sortedPlayers.length) state.players.push(sortedPlayers.pop())
else state.players.push({})
}
state.numplayers = numPlayers
}

/**
Expand Down

0 comments on commit 05b2c93

Please sign in to comment.