Refactor send logic to use senderPlayerIndex and optimize content chunking
This commit is contained in:
@@ -31,26 +31,38 @@ function GetPlayerKills()
|
||||
end
|
||||
return table.concat(killParts, "\n")
|
||||
end
|
||||
|
||||
function SendPlayerEntityStats()
|
||||
local entityParts = {}
|
||||
entityParts[#entityParts + 1] = "---player-build-stats---"
|
||||
local resultParts = {}
|
||||
-- Localize for speed
|
||||
local insert = table.insert
|
||||
|
||||
local prof = game.create_profiler()
|
||||
|
||||
insert(resultParts, "---player-build-stats---")
|
||||
|
||||
-- Process Constructed
|
||||
for playerIndex, items in pairs(storage.constructedEntites) do
|
||||
local playerName = game.players[playerIndex].name
|
||||
local prefix = playerIndex .. ":" .. playerName .. ":c:"
|
||||
|
||||
for itemName, itemCount in pairs(items) do
|
||||
entityParts[#entityParts + 1] = ("%s:%s:constructed:%s:%s"):format(playerIndex, playerName, itemName, itemCount)
|
||||
insert(resultParts, prefix .. itemName .. ":" .. itemCount)
|
||||
end
|
||||
end
|
||||
SendChunked("---player-build-stats---\n" .. table.concat(entityParts,"\n"))
|
||||
entityParts = {}
|
||||
entityParts[#entityParts + 1] = "---player-build-stats---"
|
||||
|
||||
-- Process Deconstructed
|
||||
for playerIndex, items in pairs(storage.deconstructedEntities) do
|
||||
local playerName = game.players[playerIndex].name
|
||||
local prefix = playerIndex .. ":" .. playerName .. ":d:"
|
||||
|
||||
for itemName, itemCount in pairs(items) do
|
||||
entityParts[#entityParts + 1] = ("%s:%s:deconstructed:%s:%s"):format(playerIndex, playerName, itemName, itemCount)
|
||||
insert(resultParts, prefix .. itemName .. ":" .. itemCount)
|
||||
end
|
||||
end
|
||||
SendChunked("---player-build-stats---\n" .. table.concat(entityParts,"\n"))
|
||||
|
||||
prof.stop()
|
||||
game.print(prof)
|
||||
SendChunked(table.concat(resultParts, "\n"))
|
||||
end
|
||||
|
||||
function GetMapSeed()
|
||||
@@ -65,24 +77,24 @@ end
|
||||
---Takes all players that ever visited the server into account
|
||||
---@return string
|
||||
function GetPlayerTime()
|
||||
local timeParts = {}
|
||||
timeParts[#timeParts + 1] = "---player-times---\n"
|
||||
local resultParts = {}
|
||||
resultParts[#resultParts + 1] = "---player-times---\n"
|
||||
for _, player in pairs(game.players) do
|
||||
timeParts[#timeParts + 1] = ("%s:%d:%d"):format(player.name, player.index, player.online_time)
|
||||
resultParts[#resultParts + 1] = ("%s:%d:%d"):format(player.name, player.index, player.online_time)
|
||||
end
|
||||
return table.concat(timeParts, "\n")
|
||||
return table.concat(resultParts, "\n")
|
||||
end
|
||||
|
||||
---comment
|
||||
---@return string
|
||||
function GetPlayerDeaths()
|
||||
local deathParts = {}
|
||||
deathParts[#deathParts + 1] = "---player-deaths---\n"
|
||||
local resultParts = {}
|
||||
resultParts[#resultParts + 1] = "---player-deaths---\n"
|
||||
for _, player in pairs(game.players) do
|
||||
deathParts[#deathParts + 1] = ("%s:%d:%d"):format(player.name, player.index,
|
||||
resultParts[#resultParts + 1] = ("%s:%d:%d"):format(player.name, player.index,
|
||||
storage.playerDeathCount[player.index] or 0)
|
||||
end
|
||||
return table.concat(deathParts, "\n")
|
||||
return table.concat(resultParts, "\n")
|
||||
end
|
||||
|
||||
function onPlayerDeath(event)
|
||||
@@ -90,15 +102,15 @@ function onPlayerDeath(event)
|
||||
end
|
||||
|
||||
function GetPlayerDeathCauses()
|
||||
local deathParts = {}
|
||||
deathParts[#deathParts + 1] = "---player-death-cause---\n"
|
||||
local resultParts = {}
|
||||
resultParts[#resultParts + 1] = "---player-death-cause---\n"
|
||||
for playerIndex, deathCauses in pairs(storage.playerDeathCause) do
|
||||
for causeName, causeCount in pairs(deathCauses) do
|
||||
deathParts[#deathParts + 1] = ("%s:%d:%s:%d"):format(game.players[playerIndex].name, playerIndex, causeName,
|
||||
resultParts[#resultParts + 1] = ("%s:%d:%s:%d"):format(game.players[playerIndex].name, playerIndex, causeName,
|
||||
causeCount)
|
||||
end
|
||||
end
|
||||
return table.concat(deathParts, "\n")
|
||||
return table.concat(resultParts, "\n")
|
||||
end
|
||||
|
||||
function GetTotalPlayTime()
|
||||
|
||||
Reference in New Issue
Block a user