mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-14 16:14:53 +09:00
Reports were the last legacy control module, kept in the lua state of each instance. They are now an exp_reports plugin which stores them on the controller: a report is immutable and holds the reported player, who made it, the reason, the instance name and when it was made, and the only operations are get, list, create and delete. In game nothing is stored. The lua module sends each request over ipc, the instance plugin asks the controller and hands the answer back with rcon, and the module prints it to whoever asked if they are still online. Answers are dropped if the instance stopped meanwhile. The module raises on_player_reported with the count and reporters of every report against the player, which report_jail and discord_alerts use, and the commands and player list button call into it. The web ui gets a /reports page: a table with search on the player, reporter and reason, a filter on the instance, delete per row and a create form which reports in the name of the web user. New reports are posted to two optional webhooks configured on the controller, a Discord channel hook as an embed and a generic JSON hook. Failures are logged rather than failing the report. Tests cover the messages, the controller against a real Controller, the instance plugin against a real Instance, and the lua module through the shared harness.
103 lines
4.6 KiB
Lua
103 lines
4.6 KiB
Lua
local Suite = ... --- @type Suite<ExpReports.TestEnv>
|
|
|
|
Suite.test("receive_created() tells everyone and raises on_player_reported", function(env)
|
|
env.add_player("alice", true, true)
|
|
local bob = env.add_player("bob")
|
|
env.add_player("carol")
|
|
local report = env.report("bob", "alice")
|
|
env.Reports.receive_created{ report = report, reports = { report, env.report("bob", "carol") } }
|
|
|
|
Suite.eq(env.printed, {
|
|
{ to = "alice", { "exp-reports.created-admin", "bob", "alice", "griefing" } },
|
|
{ to = "bob", { "exp-reports.created", "bob", "griefing" } },
|
|
{ to = "carol", { "exp-reports.created", "bob", "griefing" } },
|
|
}, "admins see who reported, everyone else only the reason")
|
|
Suite.eq(env.events, {
|
|
{
|
|
name = env.Reports.on_player_reported,
|
|
tick = 1,
|
|
player_index = bob.index,
|
|
by_player_name = "alice",
|
|
reason = "griefing",
|
|
report_count = 2,
|
|
by_player_names = { "alice", "carol" },
|
|
},
|
|
}, "the event carries every report against the player")
|
|
end)
|
|
|
|
Suite.test("receive_created() raises nothing when the reported player has left", function(env)
|
|
env.add_player("alice")
|
|
env.add_player("bob", false)
|
|
local report = env.report("bob", "alice")
|
|
env.Reports.receive_created{ report = report, reports = { report } }
|
|
Suite.eq(env.printed, { { to = "alice", { "exp-reports.created", "bob", "griefing" } } }, "the report is still announced")
|
|
Suite.empty(env.events, "there is nobody to act on")
|
|
end)
|
|
|
|
Suite.test("receive_list() prints the reports against a player to the caller", function(env)
|
|
env.add_player("alice")
|
|
env.Reports.receive_list{
|
|
caller = "alice",
|
|
player_name = "bob",
|
|
reports = { env.report("bob", "carol", "spam"), env.report("bob", "dave", "griefing") },
|
|
}
|
|
Suite.eq(env.printed, {
|
|
{ to = "alice", { "exp-reports.list-title", "bob", 2 } },
|
|
{ to = "alice", { "exp-reports.list-entry", "carol", "spam" } },
|
|
{ to = "alice", { "exp-reports.list-entry", "dave", "griefing" } },
|
|
}, "the title is followed by one line per report")
|
|
end)
|
|
|
|
Suite.test("receive_list() prints how many reports each player has", function(env)
|
|
env.add_player("alice")
|
|
env.Reports.receive_list{
|
|
caller = "alice",
|
|
reports = { env.report("dave", "alice"), env.report("bob", "carol"), env.report("dave", "carol") },
|
|
}
|
|
Suite.eq(env.printed, {
|
|
{ to = "alice", { "exp-reports.list-all-title" } },
|
|
{ to = "alice", { "exp-reports.list-all-entry", "bob", 1 } },
|
|
{ to = "alice", { "exp-reports.list-all-entry", "dave", 2 } },
|
|
}, "players are listed by name with their count")
|
|
end)
|
|
|
|
Suite.test("receive_list() says when nobody is reported", function(env)
|
|
env.add_player("alice")
|
|
env.Reports.receive_list{ caller = "alice", reports = {} }
|
|
Suite.eq(env.printed, { { to = "alice", { "exp-reports.list-all-none" } } }, "the caller is told there are none")
|
|
end)
|
|
|
|
Suite.test("receive_list() prints nothing once the caller has left", function(env)
|
|
env.add_player("alice", false)
|
|
env.Reports.receive_list{ caller = "alice", reports = { env.report("bob", "carol") } }
|
|
Suite.empty(env.printed, "nothing is printed")
|
|
end)
|
|
|
|
Suite.test("receive_deleted() announces the deletion and raises on_reports_deleted", function(env)
|
|
env.add_player("alice")
|
|
local bob = env.add_player("bob")
|
|
env.Reports.receive_deleted{ caller = "alice", player_name = "bob", count = 2 }
|
|
Suite.eq(env.printed, { { "exp-reports.deleted", "bob", 2, "alice" } }, "everyone is told")
|
|
Suite.eq(env.events, {
|
|
{ name = env.Reports.on_reports_deleted, tick = 1, player_index = bob.index, by_player_name = "alice", count = 2 },
|
|
}, "the event names who deleted how many")
|
|
end)
|
|
|
|
Suite.test("receive_deleted() tells the caller when there was nothing to delete", function(env)
|
|
env.add_player("alice")
|
|
env.add_player("bob")
|
|
env.Reports.receive_deleted{ caller = "alice", player_name = "bob", count = 0 }
|
|
Suite.eq(env.printed, { { to = "alice", { "exp-reports.deleted-none", "bob" } } }, "only the caller is told")
|
|
Suite.empty(env.events, "nothing was deleted")
|
|
end)
|
|
|
|
Suite.test("receive_error() prints the refusal to the caller while they are online", function(env)
|
|
env.add_player("alice")
|
|
env.add_player("bob", false)
|
|
env.Reports.receive_error{ caller = "alice", message = "alice has already reported bob" }
|
|
env.Reports.receive_error{ caller = "bob", message = "gone" }
|
|
Suite.eq(env.printed, { { to = "alice", "alice has already reported bob" } }, "the offline player is skipped")
|
|
end)
|
|
|
|
return Suite.run()
|