From 1c4e060f79806060fc7de780484e923f4fa4f6a8 Mon Sep 17 00:00:00 2001 From: david Date: Tue, 22 Feb 2011 21:55:25 +0000 Subject: [PATCH] Don't randomly select the servers to show. Just show the ones at the top. Display the total number when limiting output. --- scripts/quake3-master-getservers.nse | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/scripts/quake3-master-getservers.nse b/scripts/quake3-master-getservers.nse index c7cfe3053..d04eb5cc5 100644 --- a/scripts/quake3-master-getservers.nse +++ b/scripts/quake3-master-getservers.nse @@ -120,28 +120,22 @@ local function getservers(host, port, q3protocol) end local function formatresult(servers, outputlimit, protocols) - math.randomseed(os.time()) - randomized = {} - while #servers > 0 do - local x = table.remove(servers, math.random(1, #servers)) - table.insert(randomized, x) - end if not outputlimit then - outputlimit = #randomized + outputlimit = #servers end local formatted = {} for i = 1, outputlimit do - if not randomized[i] then + if not servers[i] then break end - local node = randomized[i] + local node = servers[i] local protocol = node.protocol local ip = node.ip local portnum = node.port table.insert(formatted, string.format('%s:%d %s (%s)', ip, portnum, protocols[protocol], protocol)) end - if #formatted < #randomized then - table.insert(formatted, string.format('Only %d shown. Use --script-args %s.outputlimit=-1 to see all.', outputlimit, SCRIPT_NAME)) + if #formatted < #servers then + table.insert(formatted, string.format('Only %d/%d shown. Use --script-args %s.outputlimit=-1 to see all.', #formatted, #servers, SCRIPT_NAME)) end return formatted end