skynet/cmds.lua

274 lines
7.6 KiB
Lua

local tk = require("tracking")
local ch = require("chat")
local cfg = require("cfg")
local cmds = {}
local function q(v)
return tostring(v or "??")
end
cmds.loc = {
alias = { "locate", "location", "l", "where", "whereis",
"whereisplayer", "dox", "doxplayer", "doxplayerlocation",
"doxplayerloc", "doxplrloc", "doxplr",
"addressof", "find", "findplayer", "findplr" },
desc = "locate a player",
args = {
{ match = "player", desc = "target" }
},
proc = function(unm, tg)
tk:refreshOne(tg)
local p = tk.plrs[tg]
if not p then
ch.send(unm, "couldn't locate target", "loc")
return
end
ch.send(unm, ("user: %s xyz:[%s, %s, %s] dim=%s"):format(tg, q(p.x), q(p.y), q(p.z), q(p.dimension)))
end,
}
cmds.rpt = {
alias = { "report", "r", "list", "listall", "whereall", "findall", "doxall" },
desc = "show coordinate report",
args = {},
proc = function(unm)
tk:refresh()
local ins = table.insert
local mparts = {}
ins(mparts, { text = "finished generating report!\n" })
for i, v in pairs(tk.plrs) do
local line = ("user: %s xyz:[%s, %s, %s] dim=%s"):format(i, q(v.x), q(v.y), q(v.z), q(v.dimension))
ins(mparts, { text = "\n[" })
ins(mparts, { text = "s", color = "aqua" })
ins(mparts, { text = "] " .. line })
end
ch.send(unm, mparts, "rpt")
end,
}
cmds.dims = {
alias = { "dimensions" },
desc = "show dimension report",
args = {},
allowLimitedUser = true,
proc = function(unm)
tk:refresh()
local ins = table.insert
local mparts = {}
ins(mparts, { text = "finished generating dimension report!" })
for i, v in pairs(tk.plrs) do
local line = ("user: %s dim=%s"):format(i, q(v.dimension))
ins(mparts, { text = "\n[" })
ins(mparts, { text = "s", color = "aqua" })
ins(mparts, { text = "] " .. line })
end
ch.send(unm, mparts, "rpt")
end,
}
cmds.sublog = {
alias = { "subscribelog", "logsub", "logsubscribe", "addlog", "log+" },
desc = "subscribe to log",
args = {},
proc = function(unm)
if cfg.users[unm].subscribeLog then
ch.send(unm, "you're already subscribed!", "users")
ch.reportLog("user " .. unm .. " tries log sub, but already there")
else
cfg.users[unm].subscribeLog = true
ch.reportLog("user " .. unm .. " subscribes to log")
end
end
}
cmds.unsublog = {
alias = { "unsubscribelog", "logunsub", "logunsubscribe",
"dellog", "rmlog", "log-" },
desc = "unsubscribe from log",
args = {},
proc = function(unm)
if not cfg.users[unm].subscribeLog then
ch.send(unm, "you're already aren't subscribed!", "users")
ch.reportLog("user " .. unm .. " tries log unsub, but they weren't there")
else
cfg.users[unm].subscribeLog = false
ch.reportLog("user " .. unm .. " unsubscribes from log")
end
end
}
cmds.allow = {
alias = { "wl" },
desc = "add someone to skynet",
args = {
{ match = "player", desc = "who" }
},
proc = function(unm, tg)
if cfg.users[tg] ~= nil then
ch.send(unm, "They're already allowed!!", "users")
ch.reportLog("user " .. unm .. " tries to allow " .. tg .. ", but they already are")
else
cfg.users[tg] = {}
ch.reportLog("user " .. unm .. " allows " .. tg)
ch.send(tg, "You were added to skynet, welcome!! // try $help for list of commands", "users")
end
end,
}
cmds.disallow = {
alias = { "unwl" },
desc = "remove someone from skynet",
args = {
{ match = "player", desc = "who" }
},
proc = function(unm, tg)
if cfg.users[tg] == nil then
ch.send(unm, "That person is already disallowed", "users")
ch.reportLog("user " .. unm .. " tries to disallow " .. tg .. ", but they already are")
else
cfg.users[tg] = nil
ch.reportLog("user " .. unm .. " disallows " .. tg)
end
end,
}
cmds.ping = {
alias = { "pong" },
desc = "alive???",
args = {},
allowLimitedUser = true,
proc = function(unm)
ch.send(unm, "Alive!!!!")
end,
}
cmds.shutdown = {
alias = { "meltdown", "sd" },
desc = "no more sky net turnitoff",
args = {},
requireAdminPrivilege = true,
proc = function(unm)
ch.reportLog("system shutdown requested by " .. unm)
ch.userBc("Shutting down..")
return true
end,
}
cmds.say = {
alias = {},
desc = "send an unlabeled message to chat",
args = {
{ match = "rest", desc = "what to say" }
},
allowLimitedUser = true,
proc = function(unm, msg)
ch.say(msg)
end,
}
cmds.sayas = {
alias = {},
desc = "say a message as another person",
args = {
{ match = "block", desc = "who says" },
{ match = "rest", desc = "what do they say" }
},
allowLimitedUser = true,
proc = function(unm, who, what)
ch.sayas(who, what)
end,
}
cmds.sayserver = {
alias = { "saysrv" },
desc = "say a message as server",
args = {
{ match = "rest", desc = "what it will say" }
},
allowLimitedUser = true,
proc = function(unm, what)
ch.sayserver(what)
end,
}
cmds.faketpa = {
alias = { "ftpa" },
desc = "send a fake teleport request",
args = {
{ match = "player", desc = "to who" },
{ match = "block", desc = "from who fake" },
{ match = "block", desc = "from who carrier" },
{ match = "block", desc = "carrier says what" },
},
allowLimitedUser = true,
proc = function(unm, tgt, fromwho, carrierwho, carrierwhat)
ch.faketpa(tgt, fromwho, carrierwho, carrierwhat)
end,
}
cmds.help = {
alias = {},
desc = "help with how to use",
args = {
{ match = "number", desc = "page", optional = true }
},
allowLimitedUser = true,
proc = function(unm, page)
page = (page or 1) - 1
local ins = table.insert
local cmdnames = {}
for i, _ in next, cmds do
table.insert(cmdnames, i)
end
table.sort(cmdnames)
local eachpage = 8
local start = page * eachpage + 1
local stop = (page + 1) * eachpage
if start > #cmdnames then
start = #cmdnames - eachpage + 1
end
stop = math.min(stop, #cmdnames)
cmdnames = { table.unpack(cmdnames, start, stop) }
local mparts = {}
ins(mparts, { text = ("help for %d commands (%d-%d) //"):format(#cmdnames, start, stop) })
for _, name in next, cmdnames do
local cmd = cmds[name]
local line = "$" .. name
for _, arg in next, cmd.args do
local br1, br2 = "<", ">"
if arg.optional then
br1, br2 = "[", "]"
end
line = line .. " " .. br1 .. arg.desc .. br2
end
line = line .. " - " .. cmd.desc
ins(mparts, { text = "\n[" })
ins(mparts, { text = "s", color = "aqua" })
ins(mparts, { text = "] " .. line })
end
ch.send(unm, mparts)
end,
}
return cmds