finalize network improvements

can now disable zstd stream compression via config, peer-to-peer uses stream compression now, also made the server commands script a bit nicer
This commit is contained in:
Kae 2024-07-27 20:04:34 +10:00
parent 372921abde
commit e1be2ab429
2 changed files with 29 additions and 12 deletions

View File

@ -3,41 +3,57 @@ local logHelp = "Available OpenStarbound server commands:\n"
local userHelp = logHelp .. "^cyan;" local userHelp = logHelp .. "^cyan;"
local adminHelp = userHelp local adminHelp = userHelp
local function cmd(name, description, permission, func) local function cmd(meta, func)
local first = next(commands) == nil local first = next(commands) == nil
logHelp = logHelp .. (first and name or ", " .. name) local name = meta.name
userHelp = userHelp .. (first and name or ", ^cyan;" .. name) local description = meta.description
adminHelp = adminHelp .. (first and name or ", ^cyan;" .. name) local permission = meta.permission
if not meta.hidden then
logHelp = logHelp .. (first and name or ", " .. name)
userHelp = userHelp .. (first and name or ", ^cyan;" .. name)
adminHelp = adminHelp .. (first and name or ", ^cyan;" .. name)
end
local keyName = name:lower() local keyName = name:lower()
if permission == "tell" then if permission == "tell" then
commands[keyName] = function(connectionId, ...) commands[keyName] = {meta = meta, func = function(connectionId, ...)
return func(universe.isAdmin(connectionId), connectionId, ...) return func(universe.isAdmin(connectionId), connectionId, ...)
end end}
elseif permission == "admin" then elseif permission == "admin" then
commands[keyName] = function(connectionId, ...) commands[keyName] = {meta = meta, func = function(connectionId, ...)
local error = CommandProcessor.adminCheck(connectionId, description:sub(1, 1):lower() .. description:sub(2)) local error = CommandProcessor.adminCheck(connectionId, description:sub(1, 1):lower() .. description:sub(2))
if error then if error then
return error return error
else else
return func(connectionId, ...) return func(connectionId, ...)
end end
end end}
elseif permission == "user" then elseif permission == "user" then
commands[keyName] = func commands[keyName] = {meta = meta, func = func}
else else
error(string.format("Command '%s' has invalid permission", name)) error(string.format("Command '%s' has invalid permission", name))
end end
end end
cmd("openhelp", "Get help", "tell", function(isAdmin, connectionId) cmd({
name = "openhelp",
description = "Get help",
permission = "tell"
},
function(isAdmin, connectionId)
return isAdmin and adminHelp or userHelp return isAdmin and adminHelp or userHelp
end) end)
do do
local objects = nil local objects = nil
cmd("packetTest", "Do science", "admin", function(connectionId) cmd({
name = "packetTest",
description = "Do science",
permission = "admin",
hidden = true
},
function(connectionId)
if not objects then if not objects then
objects = {} objects = {}
local paths = root.assetsByExtension("object") local paths = root.assetsByExtension("object")
@ -69,7 +85,7 @@ function command(commandName, connectionId, args)
local command = commands[commandName:lower()] local command = commands[commandName:lower()]
if command then if command then
local success, ret = pcall(command, connectionId, table.unpack(args)) local success, ret = pcall(command.func, connectionId, table.unpack(args))
if not success then if not success then
sb.logError("Error in OpenStarbound server command /%s: %s", commandName, ret) sb.logError("Error in OpenStarbound server command /%s: %s", commandName, ret)
return "command error: " .. ret return "command error: " .. ret

View File

@ -467,6 +467,7 @@ bool P2PPacketSocket::writeData() {
if (m_socket) { if (m_socket) {
while (!m_outputMessages.empty()) { while (!m_outputMessages.empty()) {
if (m_socket->sendMessage(m_outputMessages.first())) { if (m_socket->sendMessage(m_outputMessages.first())) {
m_outgoingStats.mix(m_outputMessages.first().size());
m_outputMessages.removeFirst(); m_outputMessages.removeFirst();
workDone = true; workDone = true;
} else { } else {